busAdminController.go 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  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 设置间隔下指定装置的端子编号。该编号只有在端子匹配表达式中存在{no}标识时才会使用
  662. // @Tags 业务管理服务
  663. // @Accept x-www-form-urlencoded
  664. // @Produce json
  665. // @Param area_id formData int true "间隔ID"
  666. // @Param ied_name formData string true "IED装置名称"
  667. // @Param ied_no formData string true "IED装置在特定间隔内,端子间使用的编号"
  668. // @Success 200 {object} ResultOK 成功
  669. // @Failure 500 {object} ResultError 失败
  670. // @router /admin/update/check_area/iedno [post]
  671. func (c *BusAdminController) SaveCheckAreaIedNoByAreaID() {
  672. area_id, _ := c.GetInt("area_id")
  673. ied_name := c.GetString("ied_name")
  674. if area_id == 0 {
  675. c.Data["json"] = c.ResultError("间隔ID不能为空!")
  676. c.ServeJSON()
  677. return
  678. }
  679. if ied_name == "" {
  680. c.Data["json"] = c.ResultError("装置名称不能为空!")
  681. c.ServeJSON()
  682. return
  683. }
  684. obj := new(bo.CheckAreaMgr)
  685. obj.SetUserInfo(c.GetCurrentUserInfo())
  686. err := obj.SetIedNo(area_id, ied_name, c.GetString("ied_no"))
  687. if err != nil {
  688. c.Data["json"] = c.ResultError(err.Error())
  689. c.ServeJSON()
  690. return
  691. }
  692. c.Data["json"] = c.ResultOK("", 0)
  693. c.ServeJSON()
  694. }
  695. // @Summary 获取指定模型和装置类型的功能列表
  696. // @Description 获取指定模型和装置类型的功能列表
  697. // @Tags 业务管理服务
  698. // @Accept x-www-form-urlencoded
  699. // @Produce json
  700. // @Param model_id formData int true "模型ID"
  701. // @Param ied_type formData string true "装置类型"
  702. // @Success 200 {object} ResultOK 成功
  703. // @Failure 500 {object} ResultError 失败
  704. // @router /admin/model/function/list [get]
  705. func (c *BusAdminController) GetFuncListByIedType() {
  706. modelid, _ := c.GetInt("model_id")
  707. if modelid == 0 {
  708. c.Data["json"] = c.ResultError("模型ID不能为空!")
  709. c.ServeJSON()
  710. return
  711. }
  712. ied_type := c.GetString("ied_type")
  713. if ied_type == "" {
  714. c.Data["json"] = c.ResultError("装置类型不能为空!")
  715. c.ServeJSON()
  716. return
  717. }
  718. obj := new(bo.SysCheckModelIedFuncMgr)
  719. obj.SetUserInfo(c.GetCurrentUserInfo())
  720. lst, err := obj.GetList(modelid, ied_type)
  721. if err != nil {
  722. c.Data["json"] = c.ResultError(err.Error())
  723. c.ServeJSON()
  724. return
  725. }
  726. c.Data["json"] = c.ResultOK(lst, 0)
  727. c.ServeJSON()
  728. }
  729. // @Summary 获取指定模型和装置类型的端子列表
  730. // @Description 获取指定模型和装置类型的端子列表
  731. // @Tags 业务管理服务
  732. // @Accept x-www-form-urlencoded
  733. // @Produce json
  734. // @Param model_id formData int true "模型ID"
  735. // @Param ied_type formData string true "查询的装置类型"
  736. // @Param ref_ied_type formData string true "对侧关联装置类型"
  737. // @Param sv_or_goose formData string true "信号类型。仅支持:SV或GOOSE"
  738. // @Param in_or_out formData string true "信号方向。仅支持:'输出'或'接收'"
  739. // @Success 200 {object} ResultOK 成功
  740. // @Failure 500 {object} ResultError 失败
  741. // @router /admin/model/function/fcda/list [get]
  742. func (c *BusAdminController) GetFuncFcdaList() {
  743. modelid, _ := c.GetInt("model_id")
  744. if modelid == 0 {
  745. c.Data["json"] = c.ResultError("模型ID不能为空!")
  746. c.ServeJSON()
  747. return
  748. }
  749. ied_type := c.GetString("ied_type")
  750. if ied_type == "" {
  751. c.Data["json"] = c.ResultError("查询的装置类型不能为空!")
  752. c.ServeJSON()
  753. return
  754. }
  755. ref_ied_type := c.GetString("ref_ied_type")
  756. if ied_type == "" {
  757. c.Data["json"] = c.ResultError("对侧关联装置类型不能为空!")
  758. c.ServeJSON()
  759. return
  760. }
  761. obj := new(bo.SysCheckModelIedFuncMgr)
  762. obj.SetUserInfo(c.GetCurrentUserInfo())
  763. lst, err := obj.GetList(modelid, ied_type)
  764. if err != nil {
  765. c.Data["json"] = c.ResultError(err.Error())
  766. c.ServeJSON()
  767. return
  768. }
  769. if len(lst) == 0 {
  770. c.Data["json"] = c.ResultOK("", 0)
  771. c.ServeJSON()
  772. return
  773. }
  774. funcids := []string{}
  775. for _, row := range lst {
  776. funcids = append(funcids, tools.IsEmpty(row["id"]))
  777. }
  778. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  779. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  780. fcdaMgr.Model.ModelId = modelid
  781. fcdaMgr.Model.Svorgoose = strings.ToUpper(c.GetString("sv_or_goose"))
  782. fcdaMgr.Model.Inorout = c.GetString("in_or_out")
  783. fcdaList, err := fcdaMgr.GetList(ref_ied_type, funcids)
  784. if err != nil {
  785. c.Data["json"] = c.ResultError(err.Error())
  786. c.ServeJSON()
  787. return
  788. }
  789. c.Data["json"] = c.ResultOK(fcdaList, len(fcdaList))
  790. c.ServeJSON()
  791. }
  792. // @Summary 保存模型装置功能及端子信息
  793. // @Description 保存装置功能及端子信息
  794. // @Tags 业务管理服务
  795. // @Accept x-www-form-urlencoded
  796. // @Produce json
  797. // @Param model_id formData int true "模型ID"
  798. // @Param ied_type formData string true "装置类型代码"
  799. // @Param func_id formData int false "功能ID。编辑时必传。"
  800. // @Param func_name formData string true "功能名称。必传。"
  801. // @Param fcda_id formData int false "端子ID。编辑时必传。"
  802. // @Param fcda_name formData string true "端子名称。必传。"
  803. // @Param fcda_match_exp formData string true "端子匹配表达式。必传。"
  804. // @Param sv_or_goose formData string true "端子信号类型。必传。仅支持SV或GOOSE"
  805. // @Param in_or_out formData string true "端子信号输入输出方向。必传。仅支持中文的'接收'或'输出'"
  806. // @Success 200 {object} ResultOK 成功
  807. // @Failure 500 {object} ResultError 失败
  808. // @router /admin/model/function/fcda/save [post]
  809. func (c *BusAdminController) SaveFuncFcda() {
  810. modelid, _ := c.GetInt("model_id")
  811. if modelid == 0 {
  812. c.Data["json"] = c.ResultError("模型ID不能为空!")
  813. c.ServeJSON()
  814. return
  815. }
  816. ied_type := c.GetString("ied_type")
  817. func_name := c.GetString("func_name")
  818. fcda_name := c.GetString("fcda_name")
  819. fcda_match_exp := c.GetString("fcda_match_exp")
  820. func_id, _ := c.GetInt("func_id")
  821. fcda_id, _ := c.GetInt("fcda_id")
  822. svorgoose := c.GetString("sv_or_goose")
  823. inorout := c.GetString("in_or_out")
  824. if func_name == "" {
  825. c.Data["json"] = c.ResultError("功能名称不能为空!")
  826. c.ServeJSON()
  827. return
  828. }
  829. if fcda_name == "" {
  830. c.Data["json"] = c.ResultError("端子设计名称不能为空!")
  831. c.ServeJSON()
  832. return
  833. }
  834. if fcda_match_exp == "" {
  835. c.Data["json"] = c.ResultError("端子匹配关键词不能为空!")
  836. c.ServeJSON()
  837. return
  838. }
  839. if svorgoose == "" {
  840. c.Data["json"] = c.ResultError("端子信号类型不能为空!")
  841. c.ServeJSON()
  842. return
  843. }
  844. if inorout == "" {
  845. c.Data["json"] = c.ResultError("端子信号方向不能为空!")
  846. c.ServeJSON()
  847. return
  848. }
  849. mod := bo.T_data_model_func_def{}
  850. mod.Id = func_id
  851. mod.ModelId = modelid
  852. mod.IedType = ied_type
  853. mod.FuncFcdaId = fcda_id
  854. mod.FuncName = func_name
  855. mod.FcdaName = fcda_name
  856. mod.FcdaMatchExp = fcda_match_exp
  857. mod.Svorgoose = svorgoose
  858. mod.Inorout = inorout
  859. mgr := new(bo.SysCheckModelIedFuncMgr)
  860. mgr.SetUserInfo(c.GetCurrentUserInfo())
  861. mgr.Model = mod
  862. _, _, err := mgr.Save()
  863. if err != nil {
  864. c.Data["json"] = c.ResultError(err.Error())
  865. c.ServeJSON()
  866. return
  867. }
  868. c.Data["json"] = c.ResultOK("", 0)
  869. c.ServeJSON()
  870. }
  871. // @Summary 删除指定模型所有的装置端子
  872. // @Description 删除指定模型所有的装置端子
  873. // @Tags 业务管理服务
  874. // @Accept x-www-form-urlencoded
  875. // @Produce json
  876. // @Param model_id formData int true "模型ID"
  877. // @Success 200 {object} ResultOK 成功
  878. // @Failure 500 {object} ResultError 失败
  879. // @router /admin/model/fcda/delall [post]
  880. func (c *BusAdminController) DelAllFuncFcda() {
  881. modelid, _ := c.GetInt("model_id")
  882. if modelid == 0 {
  883. c.Data["json"] = c.ResultError("模型ID不能为空!")
  884. c.ServeJSON()
  885. return
  886. }
  887. fcdaMgr := new(bo.SysCheckModelIedFuncMgr)
  888. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  889. fcdaMgr.Model = bo.T_data_model_func_def{}
  890. fcdaMgr.Model.ModelId = modelid
  891. err := fcdaMgr.Delete()
  892. if err != nil {
  893. c.Data["json"] = c.ResultError(err.Error())
  894. c.ServeJSON()
  895. return
  896. }
  897. c.Data["json"] = c.ResultOK("", 0)
  898. c.ServeJSON()
  899. }
  900. // @Summary 删除装置端子
  901. // @Description 删除装置端子
  902. // @Tags 业务管理服务
  903. // @Accept x-www-form-urlencoded
  904. // @Produce json
  905. // @Param model_id formData int true "模型ID"
  906. // @Param fcda_id formData int true "端子ID"
  907. // @Success 200 {object} ResultOK 成功
  908. // @Failure 500 {object} ResultError 失败
  909. // @router /admin/model/function/fcda/del [post]
  910. func (c *BusAdminController) DelFuncFcda() {
  911. modelid, _ := c.GetInt("model_id")
  912. if modelid == 0 {
  913. c.Data["json"] = c.ResultError("模型ID不能为空!")
  914. c.ServeJSON()
  915. return
  916. }
  917. fcda_id, _ := c.GetInt("fcda_id")
  918. if fcda_id == 0 {
  919. c.Data["json"] = c.ResultError("端子ID不能为空!")
  920. c.ServeJSON()
  921. return
  922. }
  923. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  924. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  925. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  926. fcdaMgr.Model.ModelId = modelid
  927. fcdaMgr.Model.Id = fcda_id
  928. err := fcdaMgr.Delete()
  929. if err != nil {
  930. c.Data["json"] = c.ResultError(err.Error())
  931. c.ServeJSON()
  932. return
  933. }
  934. c.Data["json"] = c.ResultOK("", 0)
  935. c.ServeJSON()
  936. }
  937. // @Summary 获取模型装置端子已关联的接收端子
  938. // @Description 获取模型装置端子已关联的接收端子
  939. // @Tags 业务管理服务
  940. // @Accept x-www-form-urlencoded
  941. // @Produce json
  942. // @Param model_id formData int true "模型ID"
  943. // @Param from_fcda_id formData int true "输出装置端子ID"
  944. // @Param to_ied_type formData string false "输入装置类型"
  945. // @Param goosesv formData string false "信号类型。GOOSE|SV"
  946. // @Success 200 {object} ResultOK 成功
  947. // @Failure 500 {object} ResultError 失败
  948. // @router /admin/model/function/fcda-ref/list [get]
  949. func (c *BusAdminController) GetFuncFcdaRef() {
  950. modelid, _ := c.GetInt("model_id")
  951. if modelid == 0 {
  952. c.Data["json"] = c.ResultError("模型ID不能为空!")
  953. c.ServeJSON()
  954. return
  955. }
  956. fcda_id, _ := c.GetInt("from_fcda_id")
  957. if fcda_id == 0 {
  958. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  959. c.ServeJSON()
  960. return
  961. }
  962. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  963. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  964. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  965. fcdaMgr.Model.ModelId = modelid
  966. fcdaMgr.Model.FromFcdaId = fcda_id
  967. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  968. fcdaMgr.Model.Goosesv = c.GetString("goosesv")
  969. lst, err := fcdaMgr.GetList()
  970. if err != nil {
  971. c.Data["json"] = c.ResultError(err.Error())
  972. c.ServeJSON()
  973. return
  974. }
  975. c.Data["json"] = c.ResultOK(lst, len(lst))
  976. c.ServeJSON()
  977. }
  978. // @Summary 保存模型装置端子间关联关系
  979. // @Description 保存模型装置端子间关联关系
  980. // @Tags 业务管理服务
  981. // @Accept x-www-form-urlencoded
  982. // @Produce json
  983. // @Param model_id formData int true "模型ID"
  984. // @Param from_ied_type formData string true "输出装置类型"
  985. // @Param to_ied_type formData string true "输入装置类型"
  986. // @Param from_fcda_id formData int false "输出装置端子ID"
  987. // @Param to_fcda_ids formData string false "输入装置端子ID"
  988. // @Param batch_fcda_ids formData json-string true "批量保存端子关系。类型为序列化的二维数组字符串。数组元素为:[[fromfcdaid,tofcdaid],...]"
  989. // @Param goosesv formData string true "信号类型。值范围:GOOSE|SV"
  990. // @Success 200 {object} ResultOK 成功
  991. // @Failure 500 {object} ResultError 失败
  992. // @router /admin/model/function/fcda-ref/save [post]
  993. func (c *BusAdminController) SaveFuncFcdaRef() {
  994. modelid, _ := c.GetInt("model_id")
  995. if modelid == 0 {
  996. c.Data["json"] = c.ResultError("模型ID不能为空!")
  997. c.ServeJSON()
  998. return
  999. }
  1000. fcda_id, _ := c.GetInt("from_fcda_id")
  1001. if fcda_id == 0 {
  1002. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  1003. c.ServeJSON()
  1004. return
  1005. }
  1006. fcda_in_ids := c.GetString("to_fcda_ids")
  1007. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  1008. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1009. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  1010. fcdaMgr.Model.ModelId = modelid
  1011. fcdaMgr.Model.FromFcdaId = fcda_id
  1012. fcdaMgr.Model.FromIedCode = c.GetString("from_ied_type")
  1013. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  1014. fcdaMgr.Model.Goosesv = strings.ToUpper(c.GetString("goosesv"))
  1015. if fcdaMgr.Model.FromIedCode == "" || fcdaMgr.Model.ToIedCode == "" {
  1016. c.Data["json"] = c.ResultError("输入和输出装置类型不能为空!")
  1017. c.ServeJSON()
  1018. return
  1019. }
  1020. if fcdaMgr.Model.Goosesv == "" {
  1021. c.Data["json"] = c.ResultError("信号类型不能为空!")
  1022. c.ServeJSON()
  1023. return
  1024. }
  1025. if fcdaMgr.Model.Goosesv != "GOOSE" && fcdaMgr.Model.Goosesv != "SV" {
  1026. c.Data["json"] = c.ResultError("信号类型不正确。只能为GOOSE或SV")
  1027. c.ServeJSON()
  1028. return
  1029. }
  1030. batch_fcda_ids := c.GetString("batch_fcda_ids")
  1031. if batch_fcda_ids != "" {
  1032. //批量保存
  1033. fcdalist := [][]int{}
  1034. err := json.Unmarshal([]byte(batch_fcda_ids), &fcdalist)
  1035. if err != nil {
  1036. c.Data["json"] = c.ResultError("无效的批量端子关系数据")
  1037. c.ServeJSON()
  1038. return
  1039. }
  1040. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  1041. for _, item := range fcdalist {
  1042. fcdainf, err := obj.One(item[0])
  1043. if err != nil {
  1044. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[0]))
  1045. c.ServeJSON()
  1046. return
  1047. }
  1048. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  1049. fcdaMgr.Model.FromFcdaId = item[0]
  1050. fcdainf, err = obj.One(item[1])
  1051. if err != nil {
  1052. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[1]))
  1053. c.ServeJSON()
  1054. return
  1055. }
  1056. fcdaMgr.Model.ToFcdaId = item[1]
  1057. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  1058. err = fcdaMgr.Save()
  1059. if err != nil {
  1060. c.Data["json"] = c.ResultError(err.Error())
  1061. c.ServeJSON()
  1062. return
  1063. }
  1064. }
  1065. c.Data["json"] = c.ResultOK("", 0)
  1066. c.ServeJSON()
  1067. return
  1068. }
  1069. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  1070. fcdainf, er := obj.One(fcdaMgr.Model.FromFcdaId)
  1071. if er != nil {
  1072. c.Data["json"] = c.ResultError("无效的输出端子ID")
  1073. c.ServeJSON()
  1074. return
  1075. }
  1076. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  1077. //清除输出端子的原关系
  1078. err := fcdaMgr.Delete()
  1079. if err != nil {
  1080. c.Data["json"] = c.ResultError(err.Error())
  1081. c.ServeJSON()
  1082. return
  1083. }
  1084. if fcda_in_ids != "" {
  1085. fcda_in_ids_1 := strings.Split(fcda_in_ids, ",")
  1086. for _, k := range fcda_in_ids_1 {
  1087. fcdaMgr.Model.ToFcdaId, _ = strconv.Atoi(k) //设置接收端子id
  1088. fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId)
  1089. if er != nil {
  1090. c.Data["json"] = c.ResultError("无效的接收端子ID")
  1091. c.ServeJSON()
  1092. return
  1093. }
  1094. //清除接收端子的原关系
  1095. fcdaMgr.Model.FromFcdaId = 0
  1096. fcdaMgr.Delete()
  1097. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  1098. //建立新的端子关系
  1099. fcdaMgr.Model.FromFcdaId = fcda_id //还原输出端子id
  1100. err := fcdaMgr.Save()
  1101. if err != nil {
  1102. c.Data["json"] = c.ResultError(err.Error())
  1103. c.ServeJSON()
  1104. return
  1105. }
  1106. }
  1107. }
  1108. c.Data["json"] = c.ResultOK("", 0)
  1109. c.ServeJSON()
  1110. }
  1111. // @Summary 删除端子之间的关联关系
  1112. // @Description 删除端子之间的关联关系
  1113. // @Tags 业务管理服务
  1114. // @Accept x-www-form-urlencoded
  1115. // @Produce json
  1116. // @Param model_id formData int true "模型ID"
  1117. // @Param from_fcda_id formData int true "输入端子ID"
  1118. // @Param to_fcda_id formData int true "输出端子ID"
  1119. // @Success 200 {object} ResultOK 成功
  1120. // @Failure 500 {object} ResultError 失败
  1121. // @router /admin/model/function/fcda-ref/del [post]
  1122. func (c *BusAdminController) DelFuncFcdaRef() {
  1123. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  1124. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1125. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  1126. fcdaMgr.Model.ModelId, _ = c.GetInt("model_id", 0)
  1127. fcdaMgr.Model.FromFcdaId, _ = c.GetInt("from_fcda_id", 0)
  1128. fcdaMgr.Model.ToFcdaId, _ = c.GetInt("to_fcda_id")
  1129. if fcdaMgr.Model.ModelId == 0 {
  1130. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1131. c.ServeJSON()
  1132. return
  1133. }
  1134. if fcdaMgr.Model.FromFcdaId == 0 {
  1135. c.Data["json"] = c.ResultError("输入端子ID不能为空!")
  1136. c.ServeJSON()
  1137. return
  1138. }
  1139. if fcdaMgr.Model.ToFcdaId == 0 {
  1140. c.Data["json"] = c.ResultError("接收端子ID不能为空")
  1141. c.ServeJSON()
  1142. return
  1143. }
  1144. //清除原关系
  1145. err := fcdaMgr.Delete()
  1146. if err != nil {
  1147. c.Data["json"] = c.ResultError(err.Error())
  1148. c.ServeJSON()
  1149. return
  1150. }
  1151. c.Data["json"] = c.ResultOK("", 0)
  1152. c.ServeJSON()
  1153. }