busAdminController.go 39 KB

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