busAdminController.go 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. /*
  2. * @Author: lilig
  3. * @Date: 2023-10-10 15:22:58
  4. * @LastEditors: lilifor
  5. * @LastEditTime: 2023-10-10 15:22:58
  6. * @FilePath: \SCD\controllers\TaskController.go
  7. * @Description:
  8. *
  9. * Copyright (c) 2023 by lilig/jujutong, All Rights Reserved.
  10. */
  11. package controllers
  12. import (
  13. "encoding/json"
  14. "fmt"
  15. "scd_check_tools/models/bo"
  16. "scd_check_tools/tools"
  17. "strconv"
  18. "strings"
  19. "github.com/astaxie/beego/orm"
  20. )
  21. //业务管理服务
  22. type BusAdminController struct {
  23. BaseController
  24. }
  25. func init() {
  26. }
  27. // @Summary 创建新的接线方式
  28. // @Description 创建新的接线方式
  29. // @Tags 业务管理服务
  30. // @Accept x-www-form-urlencoded
  31. // @Produce json
  32. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  33. // @Param name formData string true "任务名称"
  34. // @Param vol_id formData int true "电压等级ID"
  35. // @Param pic formData string false "接线图地址"
  36. // @Success 200 {object} ResultOK 成功
  37. // @Failure 500 {object} ResultError 失败
  38. // @router /admin/linkstyle/save [post]
  39. func (c *BusAdminController) SaveLinkStyleInfo() {
  40. id, _ := c.GetInt("id")
  41. obj := new(bo.LinkStyleMgr)
  42. obj.SetUserInfo(c.GetCurrentUserInfo())
  43. obj.Model = bo.T_data_link_style{Id: id}
  44. obj.Model.Name = c.GetString("name")
  45. obj.Model.VolLevelId, _ = c.GetInt("vol_id")
  46. obj.Model.Pic = c.GetString("pic")
  47. if obj.Model.Name == "" {
  48. c.Data["json"] = c.ResultError("名称不能为空")
  49. c.ServeJSON()
  50. return
  51. }
  52. if obj.Model.VolLevelId == 0 {
  53. c.Data["json"] = c.ResultError("电压等级不能为空")
  54. c.ServeJSON()
  55. return
  56. }
  57. err := obj.Save()
  58. if err != nil {
  59. c.Data["json"] = c.ResultError(err.Error())
  60. c.ServeJSON()
  61. return
  62. }
  63. c.Data["json"] = c.ResultOK("", 0)
  64. c.ServeJSON()
  65. }
  66. // @Summary 删除指定的接线方式
  67. // @Description 删除指定的接线方式
  68. // @Tags 业务管理服务
  69. // @Accept x-www-form-urlencoded
  70. // @Produce json
  71. // @Param id formData int true "接线方式ID"
  72. // @Success 200 {object} ResultOK 成功
  73. // @Failure 500 {object} ResultError 失败
  74. // @router /admin/linkstyle/delete [post]
  75. func (c *BusAdminController) DeleteLinkStyleByID() {
  76. id, _ := c.GetInt("id")
  77. if id == 0 {
  78. c.Data["json"] = c.ResultError("id不能为空!")
  79. c.ServeJSON()
  80. return
  81. }
  82. obj := new(bo.LinkStyleMgr)
  83. obj.SetUserInfo(c.GetCurrentUserInfo())
  84. obj.Model = bo.T_data_link_style{}
  85. obj.Model.Id = id
  86. err := obj.Delete()
  87. if err != nil {
  88. c.Data["json"] = c.ResultError(err.Error())
  89. c.ServeJSON()
  90. return
  91. }
  92. c.Data["json"] = c.ResultOK("", 0)
  93. c.ServeJSON()
  94. }
  95. // @Summary 查询接线方式
  96. // @Description 查询接线方式。支持名称、电压等级等过滤条件
  97. // @Tags 检测任务服务接口
  98. // @Accept x-www-form-urlencoded
  99. // @Produce json
  100. // @Param pageno query int true "当前页码。默认为1"
  101. // @Param pagesize query int true "每页显示数据数。默认为20"
  102. // @Param id query int false "ID"
  103. // @Param vol_id query int false "电压ID"
  104. // @Param name query string false "名称"
  105. // @Success 200 {object} ResultOK 成功
  106. // @Failure 500 {object} ResultError 失败
  107. // @router /admin/linkstyle/list [get]
  108. func (c *BusAdminController) GetLinkStyleList() {
  109. obj := new(bo.LinkStyleMgr)
  110. obj.SetUserInfo(c.GetCurrentUserInfo())
  111. obj.Model = bo.T_data_link_style{}
  112. obj.Model.Id, _ = c.GetInt("id")
  113. obj.Model.VolLevelId, _ = c.GetInt("vol_id")
  114. obj.Model.Name = c.GetString("name")
  115. pi, _ := c.GetInt("pagesize", 20)
  116. po, _ := c.GetInt("pageno", 0)
  117. if po == 0 {
  118. po, _ = c.GetInt("pageindex", 0)
  119. }
  120. if po == 0 {
  121. po = 1
  122. }
  123. lst, cnt, err := obj.List(po, pi)
  124. if err != nil {
  125. c.Data["json"] = c.ResultError(err.Error())
  126. c.ServeJSON()
  127. return
  128. }
  129. c.Data["json"] = c.ResultOK(lst, cnt)
  130. c.ServeJSON()
  131. }
  132. // @Summary 添加接线方式的模型
  133. // @Description 添加接线方式的模型
  134. // @Tags 业务管理服务
  135. // @Accept x-www-form-urlencoded
  136. // @Produce json
  137. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  138. // @Param linkstyle_id formData int true "接线方式ID"
  139. // @Param model_id formData int true "内置模型id"
  140. // @Success 200 {object} ResultOK 成功
  141. // @Failure 500 {object} ResultError 失败
  142. // @router /admin/linkstyle-model/save [post]
  143. func (c *BusAdminController) SaveLinkStyleModelInfo() {
  144. id, _ := c.GetInt("id")
  145. obj := new(bo.LinkStyleModelMgr)
  146. obj.SetUserInfo(c.GetCurrentUserInfo())
  147. obj.Model = bo.T_data_link_style_model{Id: id}
  148. obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id")
  149. obj.Model.ModelId, _ = c.GetInt("model_id")
  150. if obj.Model.LinkstyleId == 0 {
  151. c.Data["json"] = c.ResultError("接线方式不能为空")
  152. c.ServeJSON()
  153. return
  154. }
  155. if obj.Model.ModelId == 0 {
  156. c.Data["json"] = c.ResultError("模型ID不能为空")
  157. c.ServeJSON()
  158. return
  159. }
  160. err := obj.Save()
  161. if err != nil {
  162. c.Data["json"] = c.ResultError(err.Error())
  163. c.ServeJSON()
  164. return
  165. }
  166. c.Data["json"] = c.ResultOK("", 0)
  167. c.ServeJSON()
  168. }
  169. // @Summary 删除指定接线方式下属的模型
  170. // @Description 删除指定接线方式下属的模型
  171. // @Tags 业务管理服务
  172. // @Accept x-www-form-urlencoded
  173. // @Produce json
  174. // @Param id formData int true "接线方式ID"
  175. // @Param model_id formData int true "模型ID"
  176. // @Success 200 {object} ResultOK 成功
  177. // @Failure 500 {object} ResultError 失败
  178. // @router /admin/linkstyle-model/delete [post]
  179. func (c *BusAdminController) DeleteLinkStyleModelByID() {
  180. id, _ := c.GetInt("id")
  181. if id == 0 {
  182. c.Data["json"] = c.ResultError("id不能为空!")
  183. c.ServeJSON()
  184. return
  185. }
  186. model_id, _ := c.GetInt("model_id")
  187. if model_id == 0 {
  188. c.Data["json"] = c.ResultError("模型id不能为空!")
  189. c.ServeJSON()
  190. return
  191. }
  192. obj := new(bo.LinkStyleModelMgr)
  193. obj.SetUserInfo(c.GetCurrentUserInfo())
  194. obj.Model = bo.T_data_link_style_model{}
  195. obj.Model.LinkstyleId = id
  196. obj.Model.Id = model_id
  197. err := obj.Delete()
  198. if err != nil {
  199. c.Data["json"] = c.ResultError(err.Error())
  200. c.ServeJSON()
  201. return
  202. }
  203. c.Data["json"] = c.ResultOK("", 0)
  204. c.ServeJSON()
  205. }
  206. // @Summary 查询接线方式下模型列表
  207. // @Description 查询接线方式下模型列表
  208. // @Tags 检测任务服务接口
  209. // @Accept x-www-form-urlencoded
  210. // @Produce json
  211. // @Param pageno query int true "当前页码。默认为1"
  212. // @Param pagesize query int true "每页显示数据数。默认为20"
  213. // @Param id query int false "ID"
  214. // @Param linkstyle_id query int false "接线方式ID"
  215. // @Success 200 {object} ResultOK 成功
  216. // @Failure 500 {object} ResultError 失败
  217. // @router /admin/linkstyle-model/list [get]
  218. func (c *BusAdminController) GetLinkStyleModelList() {
  219. obj := new(bo.LinkStyleModelMgr)
  220. obj.SetUserInfo(c.GetCurrentUserInfo())
  221. obj.Model = bo.T_data_link_style_model{}
  222. obj.Model.Id, _ = c.GetInt("id")
  223. obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id")
  224. pi, _ := c.GetInt("pagesize", 20)
  225. po, _ := c.GetInt("pageno", 0)
  226. if po == 0 {
  227. po, _ = c.GetInt("pageindex", 0)
  228. }
  229. if po == 0 {
  230. po = 1
  231. }
  232. lst, cnt, err := obj.List(po, pi)
  233. if err != nil {
  234. c.Data["json"] = c.ResultError(err.Error())
  235. c.ServeJSON()
  236. return
  237. }
  238. c.Data["json"] = c.ResultOK(lst, cnt)
  239. c.ServeJSON()
  240. }
  241. // @Summary 创建或编辑新的内置模型
  242. // @Description 创建新的内置模型
  243. // @Tags 业务管理服务
  244. // @Accept x-www-form-urlencoded
  245. // @Produce json
  246. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  247. // @Param model_name formData string true "模型名称"
  248. // @Param vol_id formData int true "电压等级ID"
  249. // @Param line_link_style formData int true "接线方式ID"
  250. // @Param ied_types formData string false "包含的装置类型,关联代码:ied_type。多个类型之间使用逗号分隔。"
  251. // @Param relation_json formData string false "模型定义内容。svg源代码(xml格式)。"
  252. // @Param area_type formData string false "间隔类型。关联代码:area_type"
  253. // @Success 200 {object} ResultOK 成功
  254. // @Failure 500 {object} ResultError 失败
  255. // @router /admin/sysmodel/save [post]
  256. func (c *BusAdminController) SaveSysModelInfo() {
  257. id, _ := c.GetInt("id")
  258. obj := new(bo.SysCheckModelMgr)
  259. obj.SetUserInfo(c.GetCurrentUserInfo())
  260. obj.Model = bo.T_data_model_defualt{Id: id}
  261. obj.Model.ModelName = c.GetString("model_name")
  262. obj.Model.AreaType, _ = c.GetInt("area_type")
  263. obj.Model.IedTypes = c.GetString("ied_types")
  264. obj.Model.VolId, _ = c.GetInt("vol_id")
  265. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  266. obj.Model.RelationJson = c.GetString("relation_json")
  267. if id == 0 && obj.Model.ModelName == "" {
  268. c.Data["json"] = c.ResultError("模型名称不能为空")
  269. c.ServeJSON()
  270. return
  271. }
  272. if id == 0 && obj.Model.VolId == 0 {
  273. c.Data["json"] = c.ResultError("电压等级不能为空")
  274. c.ServeJSON()
  275. return
  276. }
  277. if id == 0 && obj.Model.LineLinkStyle == 0 {
  278. c.Data["json"] = c.ResultError("接线方式不能为空")
  279. c.ServeJSON()
  280. return
  281. }
  282. if id == 0 && obj.Model.AreaType == 0 {
  283. c.Data["json"] = c.ResultError("间隔类型不能为空")
  284. c.ServeJSON()
  285. return
  286. }
  287. model, err := obj.Save()
  288. if err != nil {
  289. c.Data["json"] = c.ResultError(err.Error())
  290. c.ServeJSON()
  291. return
  292. }
  293. c.Data["json"] = c.ResultOK(model, 0)
  294. c.ServeJSON()
  295. }
  296. // @Summary 复制并保存指定的内置检测模型为自定义模型
  297. // @Description 复制并保存指定的内置检测模型为自定义模型
  298. // @Tags 业务管理服务
  299. // @Accept x-www-form-urlencoded
  300. // @Produce json
  301. // @Param id formData int true "被复制模型的ID"
  302. // @Param newname formData string true "新模型名称"
  303. // @Param vol_id formData int false "目标电压等级ID"
  304. // @Param link_style_id formData int false "目标接线方式ID"
  305. // @Success 200 {object} ResultOK 成功
  306. // @Failure 500 {object} ResultError 失败
  307. // @router /admin/sysmodel/saveas [post]
  308. func (c *BusAdminController) CopySysModelByID() {
  309. id, _ := c.GetInt("id")
  310. if id == 0 {
  311. c.Data["json"] = c.ResultError("id不能为空!")
  312. c.ServeJSON()
  313. return
  314. }
  315. new_name := c.GetString("newname")
  316. obj := new(bo.SysCheckModelMgr)
  317. obj.SetUserInfo(c.GetCurrentUserInfo())
  318. obj.Model = bo.T_data_model_defualt{Id: id}
  319. obj.Model.Id = id
  320. obj.Model.ModelName = new_name
  321. //判断名称是否已存在
  322. h, _ := obj.ExistName(new_name)
  323. if h {
  324. c.Data["json"] = c.ResultError("当前的模型名称已存在")
  325. c.ServeJSON()
  326. return
  327. }
  328. volid, _ := c.GetInt("vol_id")
  329. linkid, _ := c.GetInt("link_style_id")
  330. if volid > 0 {
  331. obj.Model.VolId = volid
  332. }
  333. if linkid > 0 {
  334. obj.Model.LineLinkStyle = linkid
  335. }
  336. obj.Model.IsSys = 1
  337. err, newid := obj.Copy(id)
  338. if err != nil {
  339. c.Data["json"] = c.ResultError(err.Error())
  340. c.ServeJSON()
  341. return
  342. }
  343. c.Data["json"] = c.ResultOK(newid, 0)
  344. c.ServeJSON()
  345. }
  346. // @Summary 删除指定的检测模型
  347. // @Description 删除指定的检测模型
  348. // @Tags 业务管理服务
  349. // @Accept x-www-form-urlencoded
  350. // @Produce json
  351. // @Param id formData int true "模型ID"
  352. // @Success 200 {object} ResultOK 成功
  353. // @Failure 500 {object} ResultError 失败
  354. // @router /admin/sysmodel/delete [post]
  355. func (c *BusAdminController) DeleteSysModelByID() {
  356. id, _ := c.GetInt("id")
  357. if id == 0 {
  358. c.Data["json"] = c.ResultError("id不能为空!")
  359. c.ServeJSON()
  360. return
  361. }
  362. obj := new(bo.SysCheckModelMgr)
  363. obj.SetUserInfo(c.GetCurrentUserInfo())
  364. obj.Model = bo.T_data_model_defualt{Id: id}
  365. obj.Model.Id = id
  366. err := obj.Delete()
  367. if err != nil {
  368. c.Data["json"] = c.ResultError(err.Error())
  369. c.ServeJSON()
  370. return
  371. }
  372. c.Data["json"] = c.ResultOK("", 0)
  373. c.ServeJSON()
  374. }
  375. // @Summary 更新检测模型指定装置的类型编码
  376. // @Description 更新检测模型指定装置的类型编码
  377. // @Tags 业务管理服务
  378. // @Accept x-www-form-urlencoded
  379. // @Produce json
  380. // @Param id formData int true "模型ID"
  381. // @Param old_iedtype formData string true "装置原编码"
  382. // @Param new_iedtype formData string true "装置新编码"
  383. // @Success 200 {object} ResultOK 成功
  384. // @Failure 500 {object} ResultError 失败
  385. // @router /admin/sysmodel/update/iedtype [post]
  386. func (c *BusAdminController) UPdateSysModelIedType() {
  387. id, _ := c.GetInt("id")
  388. if id == 0 {
  389. c.Data["json"] = c.ResultError("模型编号不能为空!")
  390. c.ServeJSON()
  391. return
  392. }
  393. oldtype := c.GetString("old_iedtype")
  394. newtype := c.GetString("new_iedtype")
  395. if oldtype == "" {
  396. c.Data["json"] = c.ResultError("装置类型编码不能为空!")
  397. c.ServeJSON()
  398. return
  399. }
  400. obj := new(bo.SysCheckModelMgr)
  401. obj.SetUserInfo(c.GetCurrentUserInfo())
  402. obj.Model = bo.T_data_model_defualt{Id: id}
  403. err := obj.UpdateIedType(oldtype, newtype)
  404. if err != nil {
  405. c.Data["json"] = c.ResultError(err.Error())
  406. c.ServeJSON()
  407. return
  408. }
  409. c.Data["json"] = c.ResultOK("", 0)
  410. c.ServeJSON()
  411. }
  412. // @Summary 获取检测模型指定装置的自定义类型编码
  413. // @Description 获取检测模型指定装置的自定义类型编码
  414. // @Tags 业务管理服务
  415. // @Accept x-www-form-urlencoded
  416. // @Produce json
  417. // @Param id formData int true "模型ID"
  418. // @Param ied_type formData string true "装置原编码"
  419. // @Success 200 {object} ResultOK 成功
  420. // @Failure 500 {object} ResultError 失败
  421. // @router /admin/sysmodel/get/iedtype [get]
  422. func (c *BusAdminController) GetSysModelIedTypeMapping() {
  423. id, _ := c.GetInt("id")
  424. if id == 0 {
  425. c.Data["json"] = c.ResultError("模型编号不能为空!")
  426. c.ServeJSON()
  427. return
  428. }
  429. oldtype := c.GetString("ied_type")
  430. if oldtype == "" {
  431. c.Data["json"] = c.ResultError("装置类型编码不能为空!")
  432. c.ServeJSON()
  433. return
  434. }
  435. obj := new(bo.SysCheckModelMgr)
  436. obj.SetUserInfo(c.GetCurrentUserInfo())
  437. obj.Model = bo.T_data_model_defualt{Id: id}
  438. r := obj.GetIedtypeMapping(oldtype)
  439. c.Data["json"] = c.ResultOK(r, 0)
  440. c.ServeJSON()
  441. }
  442. // @Summary 查询检测模型列表
  443. // @Description 查询检测模型列表。支持名称、电压等级等过滤条件
  444. // @Tags 检测任务服务接口
  445. // @Accept x-www-form-urlencoded
  446. // @Produce json
  447. // @Param pageno query int true "当前页码。默认为1"
  448. // @Param pagesize query int true "每页显示数据数。默认为20"
  449. // @Param id query int false "ID"
  450. // @Param vol_id query int false "电压等级ID"
  451. // @Param model_name query string false "名称"
  452. // @Param line_link_style query int false "接线方式"
  453. // @Param area_type query int false "间隔类型"
  454. // @Param is_sys query int false "模型类型。1 内置模型 2 自定义模型"
  455. // @Success 200 {object} ResultOK 成功
  456. // @Failure 500 {object} ResultError 失败
  457. // @router /admin/sysmodel/list [get]
  458. func (c *BusAdminController) GetSysModelList() {
  459. obj := new(bo.SysCheckModelMgr)
  460. obj.SetUserInfo(c.GetCurrentUserInfo())
  461. obj.Model = bo.T_data_model_defualt{}
  462. obj.Model.Id, _ = c.GetInt("id")
  463. obj.Model.IsSys, _ = c.GetInt("is_sys", 1) //默认查询系统内置模型
  464. obj.Model.VolId, _ = c.GetInt("vol_id")
  465. obj.Model.ModelName = c.GetString("model_name")
  466. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  467. obj.Model.AreaType, _ = c.GetInt("area_type")
  468. pi, _ := c.GetInt("pagesize", 20)
  469. po, _ := c.GetInt("pageno", 0)
  470. if po == 0 {
  471. po, _ = c.GetInt("pageindex", 0)
  472. }
  473. if po == 0 {
  474. po = 1
  475. }
  476. lst, cnt, err := obj.List(po, pi)
  477. if err != nil {
  478. c.Data["json"] = c.ResultError(err.Error())
  479. c.ServeJSON()
  480. return
  481. }
  482. //如果是获取指定模型信息时,附加模型的标准装置类型信息
  483. if obj.Model.Id > 0 {
  484. //间隔类型id
  485. syscode := new(bo.Global)
  486. codeinfo := syscode.GetCodeInfoByID(tools.IsEmpty(lst[0]["area_type"]))
  487. if codeinfo != nil {
  488. code := "area_type_" + tools.IsEmpty(codeinfo["code"])
  489. codeinfo = syscode.GetCodeInfoByCode("area_ied_type", code)
  490. codes := strings.Split(tools.IsEmpty(codeinfo["name"]), ",")
  491. ccrows := []orm.Params{}
  492. for _, item := range codes {
  493. tmp := syscode.GetCodeInfoByCode("ied_type", item)
  494. if tmp == nil {
  495. ccrows = append(ccrows, orm.Params{"code": item, "name": item})
  496. } else {
  497. ccrows = append(ccrows, tmp)
  498. }
  499. }
  500. lst[0]["ied_type"] = ccrows
  501. }
  502. }
  503. c.Data["json"] = c.ResultOK(lst, cnt)
  504. c.ServeJSON()
  505. }
  506. // @Summary 重新分析指定的SCD检测模型间隔
  507. // @Description 重新分析指定的SCD检测模型间隔
  508. // @Tags 业务管理服务
  509. // @Accept x-www-form-urlencoded
  510. // @Produce json
  511. // @Param scd_id formData int true "SCD文件ID"
  512. // @Success 200 {object} ResultOK 成功
  513. // @Failure 500 {object} ResultError 失败
  514. // @router /admin/parse/check_area [post]
  515. func (c *BusAdminController) ResetCheckAreaByID() {
  516. id, _ := c.GetInt64("scd_id")
  517. if id == 0 {
  518. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  519. c.ServeJSON()
  520. return
  521. }
  522. obj := new(bo.CheckAreaMgr)
  523. obj.SetUserInfo(c.GetCurrentUserInfo())
  524. obj.ScdId = id
  525. err := obj.Reset()
  526. if err != nil {
  527. c.Data["json"] = c.ResultError(err.Error())
  528. c.ServeJSON()
  529. return
  530. }
  531. c.Data["json"] = c.ResultOK("", 0)
  532. c.ServeJSON()
  533. }
  534. // @Summary 查询指定电压等级及接线方式下的检测间隔分析结果
  535. // @Description 查询指定电压等级及接线方式下的检测间隔分析结果
  536. // @Tags 业务管理服务
  537. // @Accept x-www-form-urlencoded
  538. // @Produce json
  539. // @Param scd_id formData int true "SCD文件ID"
  540. // @Param vol_id formData int false "电压等级ID"
  541. // @Param link_style_id formData int false "接线方式ID"
  542. // @Success 200 {object} ResultOK 成功
  543. // @Failure 500 {object} ResultError 失败
  544. // @router /admin/get/check_area [get]
  545. func (c *BusAdminController) GetCheckAreaByVolID() {
  546. id, _ := c.GetInt64("scd_id")
  547. if id == 0 {
  548. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  549. c.ServeJSON()
  550. return
  551. }
  552. volid, _ := c.GetInt("vol_id")
  553. lsid, _ := c.GetInt("link_style_id")
  554. obj := new(bo.CheckAreaMgr)
  555. obj.SetUserInfo(c.GetCurrentUserInfo())
  556. obj.ScdId = id
  557. lst, err := obj.GetAreaListByVol(id, volid, lsid)
  558. if err != nil {
  559. c.Data["json"] = c.ResultError(err.Error())
  560. c.ServeJSON()
  561. return
  562. }
  563. if lst == nil || len(lst) == 0 {
  564. //新分析
  565. err = obj.Reset()
  566. if err != nil {
  567. c.Data["json"] = c.ResultError(err.Error())
  568. c.ServeJSON()
  569. return
  570. }
  571. lst, _ = obj.GetAreaListByVol(id, volid, lsid)
  572. }
  573. //获取每个间隔下的ied列表同步返回
  574. if lst != nil {
  575. for i, row := range lst {
  576. area_id, _ := strconv.Atoi(tools.IsEmpty(row["area_id"]))
  577. iedlst, _ := obj.GetIedList(id, area_id)
  578. if iedlst == nil {
  579. lst[i]["ieds"] = []orm.Params{}
  580. } else {
  581. lst[i]["ieds"] = iedlst
  582. }
  583. }
  584. }
  585. c.Data["json"] = c.ResultOK(lst, 0)
  586. c.ServeJSON()
  587. }
  588. // @Summary 查询指定检测间隔下的IED装置列表
  589. // @Description 查询指定检测间隔下的IED装置列表
  590. // @Tags 业务管理服务
  591. // @Accept x-www-form-urlencoded
  592. // @Produce json
  593. // @Param scd_id formData int true "SCD文件ID"
  594. // @Param area_id formData int true "检测间隔ID"
  595. // @Success 200 {object} ResultOK 成功
  596. // @Failure 500 {object} ResultError 失败
  597. // @router /admin/get/check_area/ied [get]
  598. func (c *BusAdminController) GetCheckAreaIedByAreaID() {
  599. id, _ := c.GetInt64("scd_id")
  600. if id == 0 {
  601. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  602. c.ServeJSON()
  603. return
  604. }
  605. area_id, _ := c.GetInt("area_id")
  606. obj := new(bo.CheckAreaMgr)
  607. obj.SetUserInfo(c.GetCurrentUserInfo())
  608. obj.ScdId = id
  609. lst, err := obj.GetIedList(id, area_id)
  610. if err != nil {
  611. c.Data["json"] = c.ResultError(err.Error())
  612. c.ServeJSON()
  613. return
  614. }
  615. c.Data["json"] = c.ResultOK(lst, 0)
  616. c.ServeJSON()
  617. }
  618. // @Summary 修改并保存指定检测间隔下的IED装置列表
  619. // @Description 修改并保存指定检测间隔下的IED装置列表
  620. // @Tags 业务管理服务
  621. // @Accept x-www-form-urlencoded
  622. // @Produce json
  623. // @Param scd_id formData int true "SCD文件ID"
  624. // @Param area_id formData int true "检测间隔ID"
  625. // @Param ied_ids formData string true "IED装置name列表,多个ied采用逗号分隔。如:PT1001,PL1001,..."
  626. // @Success 200 {object} ResultOK 成功
  627. // @Failure 500 {object} ResultError 失败
  628. // @router /admin/update/check_area/ied [post]
  629. func (c *BusAdminController) SaveCheckAreaIedByAreaID() {
  630. id, _ := c.GetInt64("scd_id")
  631. if id == 0 {
  632. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  633. c.ServeJSON()
  634. return
  635. }
  636. area_id, _ := c.GetInt("area_id")
  637. ieds := c.GetString("ied_ids")
  638. if area_id == 0 {
  639. c.Data["json"] = c.ResultError("检测间隔ID不能为空!")
  640. c.ServeJSON()
  641. return
  642. }
  643. if ieds == "" {
  644. c.Data["json"] = c.ResultError("检测间隔装置列表不能为空!")
  645. c.ServeJSON()
  646. return
  647. }
  648. obj := new(bo.CheckAreaMgr)
  649. obj.SetUserInfo(c.GetCurrentUserInfo())
  650. obj.ScdId = id
  651. err := obj.UpdateIeds(id, area_id, ieds)
  652. if err != nil {
  653. c.Data["json"] = c.ResultError(err.Error())
  654. c.ServeJSON()
  655. return
  656. }
  657. c.Data["json"] = c.ResultOK("", 0)
  658. c.ServeJSON()
  659. }
  660. // @Summary 获取指定模型和装置类型的功能列表
  661. // @Description 获取指定模型和装置类型的功能列表
  662. // @Tags 业务管理服务
  663. // @Accept x-www-form-urlencoded
  664. // @Produce json
  665. // @Param model_id formData int true "模型ID"
  666. // @Param ied_type formData string true "装置类型"
  667. // @Success 200 {object} ResultOK 成功
  668. // @Failure 500 {object} ResultError 失败
  669. // @router /admin/model/function/list [get]
  670. func (c *BusAdminController) GetFuncListByIedType() {
  671. modelid, _ := c.GetInt("model_id")
  672. if modelid == 0 {
  673. c.Data["json"] = c.ResultError("模型ID不能为空!")
  674. c.ServeJSON()
  675. return
  676. }
  677. ied_type := c.GetString("ied_type")
  678. if ied_type == "" {
  679. c.Data["json"] = c.ResultError("装置类型不能为空!")
  680. c.ServeJSON()
  681. return
  682. }
  683. obj := new(bo.SysCheckModelIedFuncMgr)
  684. obj.SetUserInfo(c.GetCurrentUserInfo())
  685. lst, err := obj.GetList(modelid, ied_type)
  686. if err != nil {
  687. c.Data["json"] = c.ResultError(err.Error())
  688. c.ServeJSON()
  689. return
  690. }
  691. c.Data["json"] = c.ResultOK(lst, 0)
  692. c.ServeJSON()
  693. }
  694. // @Summary 获取指定模型和装置类型的端子列表
  695. // @Description 获取指定模型和装置类型的端子列表
  696. // @Tags 业务管理服务
  697. // @Accept x-www-form-urlencoded
  698. // @Produce json
  699. // @Param model_id formData int true "模型ID"
  700. // @Param ied_type formData string true "查询的装置类型"
  701. // @Param ref_ied_type formData string true "对侧关联装置类型"
  702. // @Param sv_or_goose formData string true "信号类型。仅支持:SV或GOOSE"
  703. // @Param in_or_out formData string true "信号方向。仅支持:'输出'或'接收'"
  704. // @Success 200 {object} ResultOK 成功
  705. // @Failure 500 {object} ResultError 失败
  706. // @router /admin/model/function/fcda/list [get]
  707. func (c *BusAdminController) GetFuncFcdaList() {
  708. modelid, _ := c.GetInt("model_id")
  709. if modelid == 0 {
  710. c.Data["json"] = c.ResultError("模型ID不能为空!")
  711. c.ServeJSON()
  712. return
  713. }
  714. ied_type := c.GetString("ied_type")
  715. if ied_type == "" {
  716. c.Data["json"] = c.ResultError("查询的装置类型不能为空!")
  717. c.ServeJSON()
  718. return
  719. }
  720. ref_ied_type := c.GetString("ref_ied_type")
  721. if ied_type == "" {
  722. c.Data["json"] = c.ResultError("对侧关联装置类型不能为空!")
  723. c.ServeJSON()
  724. return
  725. }
  726. obj := new(bo.SysCheckModelIedFuncMgr)
  727. obj.SetUserInfo(c.GetCurrentUserInfo())
  728. lst, err := obj.GetList(modelid, ied_type)
  729. if err != nil {
  730. c.Data["json"] = c.ResultError(err.Error())
  731. c.ServeJSON()
  732. return
  733. }
  734. if len(lst) == 0 {
  735. c.Data["json"] = c.ResultOK("", 0)
  736. c.ServeJSON()
  737. return
  738. }
  739. funcids := []string{}
  740. for _, row := range lst {
  741. funcids = append(funcids, tools.IsEmpty(row["id"]))
  742. }
  743. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  744. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  745. fcdaMgr.Model.ModelId = modelid
  746. fcdaMgr.Model.Svorgoose = strings.ToUpper(c.GetString("sv_or_goose"))
  747. fcdaMgr.Model.Inorout = c.GetString("in_or_out")
  748. fcdaList, err := fcdaMgr.GetList(ref_ied_type, funcids)
  749. if err != nil {
  750. c.Data["json"] = c.ResultError(err.Error())
  751. c.ServeJSON()
  752. return
  753. }
  754. c.Data["json"] = c.ResultOK(fcdaList, len(fcdaList))
  755. c.ServeJSON()
  756. }
  757. // @Summary 保存模型装置功能及端子信息
  758. // @Description 保存装置功能及端子信息
  759. // @Tags 业务管理服务
  760. // @Accept x-www-form-urlencoded
  761. // @Produce json
  762. // @Param model_id formData int true "模型ID"
  763. // @Param ied_type formData string true "装置类型代码"
  764. // @Param func_id formData int false "功能ID。编辑时必传。"
  765. // @Param func_name formData string true "功能名称。必传。"
  766. // @Param fcda_id formData int false "端子ID。编辑时必传。"
  767. // @Param fcda_name formData string true "端子名称。必传。"
  768. // @Param fcda_match_exp formData string true "端子匹配表达式。必传。"
  769. // @Param sv_or_goose formData string true "端子信号类型。必传。仅支持SV或GOOSE"
  770. // @Param in_or_out formData string true "端子信号输入输出方向。必传。仅支持中文的'接收'或'输出'"
  771. // @Success 200 {object} ResultOK 成功
  772. // @Failure 500 {object} ResultError 失败
  773. // @router /admin/model/function/fcda/save [post]
  774. func (c *BusAdminController) SaveFuncFcda() {
  775. modelid, _ := c.GetInt("model_id")
  776. if modelid == 0 {
  777. c.Data["json"] = c.ResultError("模型ID不能为空!")
  778. c.ServeJSON()
  779. return
  780. }
  781. ied_type := c.GetString("ied_type")
  782. func_name := c.GetString("func_name")
  783. fcda_name := c.GetString("fcda_name")
  784. fcda_match_exp := c.GetString("fcda_match_exp")
  785. func_id, _ := c.GetInt("func_id")
  786. fcda_id, _ := c.GetInt("fcda_id")
  787. svorgoose := c.GetString("sv_or_goose")
  788. inorout := c.GetString("in_or_out")
  789. if func_name == "" {
  790. c.Data["json"] = c.ResultError("功能名称不能为空!")
  791. c.ServeJSON()
  792. return
  793. }
  794. if fcda_name == "" {
  795. c.Data["json"] = c.ResultError("端子设计名称不能为空!")
  796. c.ServeJSON()
  797. return
  798. }
  799. if fcda_match_exp == "" {
  800. c.Data["json"] = c.ResultError("端子匹配关键词不能为空!")
  801. c.ServeJSON()
  802. return
  803. }
  804. if svorgoose == "" {
  805. c.Data["json"] = c.ResultError("端子信号类型不能为空!")
  806. c.ServeJSON()
  807. return
  808. }
  809. if inorout == "" {
  810. c.Data["json"] = c.ResultError("端子信号方向不能为空!")
  811. c.ServeJSON()
  812. return
  813. }
  814. mod := bo.T_data_model_func_def{}
  815. mod.Id = func_id
  816. mod.ModelId = modelid
  817. mod.IedType = ied_type
  818. mod.FuncFcdaId = fcda_id
  819. mod.FuncName = func_name
  820. mod.FcdaName = fcda_name
  821. mod.FcdaMatchExp = fcda_match_exp
  822. mod.Svorgoose = svorgoose
  823. mod.Inorout = inorout
  824. mgr := new(bo.SysCheckModelIedFuncMgr)
  825. mgr.SetUserInfo(c.GetCurrentUserInfo())
  826. mgr.Model = mod
  827. _, _, err := mgr.Save()
  828. if err != nil {
  829. c.Data["json"] = c.ResultError(err.Error())
  830. c.ServeJSON()
  831. return
  832. }
  833. c.Data["json"] = c.ResultOK("", 0)
  834. c.ServeJSON()
  835. }
  836. // @Summary 删除指定模型所有的装置端子
  837. // @Description 删除指定模型所有的装置端子
  838. // @Tags 业务管理服务
  839. // @Accept x-www-form-urlencoded
  840. // @Produce json
  841. // @Param model_id formData int true "模型ID"
  842. // @Success 200 {object} ResultOK 成功
  843. // @Failure 500 {object} ResultError 失败
  844. // @router /admin/model/fcda/delall [post]
  845. func (c *BusAdminController) DelAllFuncFcda() {
  846. modelid, _ := c.GetInt("model_id")
  847. if modelid == 0 {
  848. c.Data["json"] = c.ResultError("模型ID不能为空!")
  849. c.ServeJSON()
  850. return
  851. }
  852. fcdaMgr := new(bo.SysCheckModelIedFuncMgr)
  853. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  854. fcdaMgr.Model = bo.T_data_model_func_def{}
  855. fcdaMgr.Model.ModelId = modelid
  856. err := fcdaMgr.Delete()
  857. if err != nil {
  858. c.Data["json"] = c.ResultError(err.Error())
  859. c.ServeJSON()
  860. return
  861. }
  862. c.Data["json"] = c.ResultOK("", 0)
  863. c.ServeJSON()
  864. }
  865. // @Summary 删除装置端子
  866. // @Description 删除装置端子
  867. // @Tags 业务管理服务
  868. // @Accept x-www-form-urlencoded
  869. // @Produce json
  870. // @Param model_id formData int true "模型ID"
  871. // @Param fcda_id formData int true "端子ID"
  872. // @Success 200 {object} ResultOK 成功
  873. // @Failure 500 {object} ResultError 失败
  874. // @router /admin/model/function/fcda/del [post]
  875. func (c *BusAdminController) DelFuncFcda() {
  876. modelid, _ := c.GetInt("model_id")
  877. if modelid == 0 {
  878. c.Data["json"] = c.ResultError("模型ID不能为空!")
  879. c.ServeJSON()
  880. return
  881. }
  882. fcda_id, _ := c.GetInt("fcda_id")
  883. if fcda_id == 0 {
  884. c.Data["json"] = c.ResultError("端子ID不能为空!")
  885. c.ServeJSON()
  886. return
  887. }
  888. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  889. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  890. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  891. fcdaMgr.Model.ModelId = modelid
  892. fcdaMgr.Model.Id = fcda_id
  893. err := fcdaMgr.Delete()
  894. if err != nil {
  895. c.Data["json"] = c.ResultError(err.Error())
  896. c.ServeJSON()
  897. return
  898. }
  899. c.Data["json"] = c.ResultOK("", 0)
  900. c.ServeJSON()
  901. }
  902. // @Summary 获取模型装置端子已关联的接收端子
  903. // @Description 获取模型装置端子已关联的接收端子
  904. // @Tags 业务管理服务
  905. // @Accept x-www-form-urlencoded
  906. // @Produce json
  907. // @Param model_id formData int true "模型ID"
  908. // @Param from_fcda_id formData int true "输出装置端子ID"
  909. // @Param to_ied_type formData string false "输入装置类型"
  910. // @Param goosesv formData string false "信号类型。GOOSE|SV"
  911. // @Success 200 {object} ResultOK 成功
  912. // @Failure 500 {object} ResultError 失败
  913. // @router /admin/model/function/fcda-ref/list [get]
  914. func (c *BusAdminController) GetFuncFcdaRef() {
  915. modelid, _ := c.GetInt("model_id")
  916. if modelid == 0 {
  917. c.Data["json"] = c.ResultError("模型ID不能为空!")
  918. c.ServeJSON()
  919. return
  920. }
  921. fcda_id, _ := c.GetInt("from_fcda_id")
  922. if fcda_id == 0 {
  923. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  924. c.ServeJSON()
  925. return
  926. }
  927. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  928. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  929. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  930. fcdaMgr.Model.ModelId = modelid
  931. fcdaMgr.Model.FromFcdaId = fcda_id
  932. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  933. fcdaMgr.Model.Goosesv = c.GetString("goosesv")
  934. lst, err := fcdaMgr.GetList()
  935. if err != nil {
  936. c.Data["json"] = c.ResultError(err.Error())
  937. c.ServeJSON()
  938. return
  939. }
  940. c.Data["json"] = c.ResultOK(lst, len(lst))
  941. c.ServeJSON()
  942. }
  943. // @Summary 保存模型装置端子间关联关系
  944. // @Description 保存模型装置端子间关联关系
  945. // @Tags 业务管理服务
  946. // @Accept x-www-form-urlencoded
  947. // @Produce json
  948. // @Param model_id formData int true "模型ID"
  949. // @Param from_ied_type formData string true "输出装置类型"
  950. // @Param to_ied_type formData string true "输入装置类型"
  951. // @Param from_fcda_id formData int false "输出装置端子ID"
  952. // @Param to_fcda_ids formData string false "输入装置端子ID"
  953. // @Param batch_fcda_ids formData json-string true "批量保存端子关系。类型为序列化的二维数组字符串。数组元素为:[[fromfcdaid,tofcdaid],...]"
  954. // @Param goosesv formData string true "信号类型。值范围:GOOSE|SV"
  955. // @Success 200 {object} ResultOK 成功
  956. // @Failure 500 {object} ResultError 失败
  957. // @router /admin/model/function/fcda-ref/save [post]
  958. func (c *BusAdminController) SaveFuncFcdaRef() {
  959. modelid, _ := c.GetInt("model_id")
  960. if modelid == 0 {
  961. c.Data["json"] = c.ResultError("模型ID不能为空!")
  962. c.ServeJSON()
  963. return
  964. }
  965. fcda_id, _ := c.GetInt("from_fcda_id")
  966. if fcda_id == 0 {
  967. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  968. c.ServeJSON()
  969. return
  970. }
  971. fcda_in_ids := c.GetString("to_fcda_ids")
  972. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  973. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  974. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  975. fcdaMgr.Model.ModelId = modelid
  976. fcdaMgr.Model.FromFcdaId = fcda_id
  977. fcdaMgr.Model.FromIedCode = c.GetString("from_ied_type")
  978. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  979. fcdaMgr.Model.Goosesv = strings.ToUpper(c.GetString("goosesv"))
  980. if fcdaMgr.Model.FromIedCode == "" || fcdaMgr.Model.ToIedCode == "" {
  981. c.Data["json"] = c.ResultError("输入和输出装置类型不能为空!")
  982. c.ServeJSON()
  983. return
  984. }
  985. if fcdaMgr.Model.Goosesv == "" {
  986. c.Data["json"] = c.ResultError("信号类型不能为空!")
  987. c.ServeJSON()
  988. return
  989. }
  990. if fcdaMgr.Model.Goosesv != "GOOSE" && fcdaMgr.Model.Goosesv != "SV" {
  991. c.Data["json"] = c.ResultError("信号类型不正确。只能为GOOSE或SV")
  992. c.ServeJSON()
  993. return
  994. }
  995. batch_fcda_ids := c.GetString("batch_fcda_ids")
  996. if batch_fcda_ids != "" {
  997. //批量保存
  998. fcdalist := [][]int{}
  999. err := json.Unmarshal([]byte(batch_fcda_ids), &fcdalist)
  1000. if err != nil {
  1001. c.Data["json"] = c.ResultError("无效的批量端子关系数据")
  1002. c.ServeJSON()
  1003. return
  1004. }
  1005. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  1006. for _, item := range fcdalist {
  1007. fcdainf, err := obj.One(item[0])
  1008. if err != nil {
  1009. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[0]))
  1010. c.ServeJSON()
  1011. return
  1012. }
  1013. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  1014. fcdaMgr.Model.FromFcdaId = item[0]
  1015. fcdainf, err = obj.One(item[1])
  1016. if err != nil {
  1017. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[1]))
  1018. c.ServeJSON()
  1019. return
  1020. }
  1021. fcdaMgr.Model.ToFcdaId = item[1]
  1022. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  1023. err = fcdaMgr.Save()
  1024. if err != nil {
  1025. c.Data["json"] = c.ResultError(err.Error())
  1026. c.ServeJSON()
  1027. return
  1028. }
  1029. }
  1030. c.Data["json"] = c.ResultOK("", 0)
  1031. c.ServeJSON()
  1032. return
  1033. }
  1034. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  1035. fcdainf, er := obj.One(fcdaMgr.Model.FromFcdaId)
  1036. if er != nil {
  1037. c.Data["json"] = c.ResultError("无效的输出端子ID")
  1038. c.ServeJSON()
  1039. return
  1040. }
  1041. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  1042. //清除输出端子的原关系
  1043. err := fcdaMgr.Delete()
  1044. if err != nil {
  1045. c.Data["json"] = c.ResultError(err.Error())
  1046. c.ServeJSON()
  1047. return
  1048. }
  1049. if fcda_in_ids != "" {
  1050. fcda_in_ids_1 := strings.Split(fcda_in_ids, ",")
  1051. for _, k := range fcda_in_ids_1 {
  1052. fcdaMgr.Model.ToFcdaId, _ = strconv.Atoi(k) //设置接收端子id
  1053. fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId)
  1054. if er != nil {
  1055. c.Data["json"] = c.ResultError("无效的接收端子ID")
  1056. c.ServeJSON()
  1057. return
  1058. }
  1059. //清除接收端子的原关系
  1060. fcdaMgr.Model.FromFcdaId = 0
  1061. fcdaMgr.Delete()
  1062. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  1063. //建立新的端子关系
  1064. fcdaMgr.Model.FromFcdaId = fcda_id //还原输出端子id
  1065. err := fcdaMgr.Save()
  1066. if err != nil {
  1067. c.Data["json"] = c.ResultError(err.Error())
  1068. c.ServeJSON()
  1069. return
  1070. }
  1071. }
  1072. }
  1073. c.Data["json"] = c.ResultOK("", 0)
  1074. c.ServeJSON()
  1075. }
  1076. // @Summary 删除端子之间的关联关系
  1077. // @Description 删除端子之间的关联关系
  1078. // @Tags 业务管理服务
  1079. // @Accept x-www-form-urlencoded
  1080. // @Produce json
  1081. // @Param model_id formData int true "模型ID"
  1082. // @Param from_fcda_id formData int true "输入端子ID"
  1083. // @Param to_fcda_id formData int true "输出端子ID"
  1084. // @Success 200 {object} ResultOK 成功
  1085. // @Failure 500 {object} ResultError 失败
  1086. // @router /admin/model/function/fcda-ref/del [post]
  1087. func (c *BusAdminController) DelFuncFcdaRef() {
  1088. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  1089. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1090. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  1091. fcdaMgr.Model.ModelId, _ = c.GetInt("model_id", 0)
  1092. fcdaMgr.Model.FromFcdaId, _ = c.GetInt("from_fcda_id", 0)
  1093. fcdaMgr.Model.ToFcdaId, _ = c.GetInt("to_fcda_id")
  1094. if fcdaMgr.Model.ModelId == 0 {
  1095. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1096. c.ServeJSON()
  1097. return
  1098. }
  1099. if fcdaMgr.Model.FromFcdaId == 0 {
  1100. c.Data["json"] = c.ResultError("输入端子ID不能为空!")
  1101. c.ServeJSON()
  1102. return
  1103. }
  1104. if fcdaMgr.Model.ToFcdaId == 0 {
  1105. c.Data["json"] = c.ResultError("接收端子ID不能为空")
  1106. c.ServeJSON()
  1107. return
  1108. }
  1109. //清除原关系
  1110. err := fcdaMgr.Delete()
  1111. if err != nil {
  1112. c.Data["json"] = c.ResultError(err.Error())
  1113. c.ServeJSON()
  1114. return
  1115. }
  1116. c.Data["json"] = c.ResultOK("", 0)
  1117. c.ServeJSON()
  1118. }