busAdminController.go 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  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. // @Success 200 {object} ResultOK 成功
  304. // @Failure 500 {object} ResultError 失败
  305. // @router /admin/sysmodel/saveas [post]
  306. func (c *BusAdminController) CopySysModelByID() {
  307. id, _ := c.GetInt("id")
  308. if id == 0 {
  309. c.Data["json"] = c.ResultError("id不能为空!")
  310. c.ServeJSON()
  311. return
  312. }
  313. new_name := c.GetString("newname")
  314. obj := new(bo.SysCheckModelMgr)
  315. obj.SetUserInfo(c.GetCurrentUserInfo())
  316. obj.Model = bo.T_data_model_defualt{Id: id}
  317. obj.Model.Id = id
  318. obj.Model.ModelName = new_name
  319. err, newid := obj.Copy(id)
  320. if err != nil {
  321. c.Data["json"] = c.ResultError(err.Error())
  322. c.ServeJSON()
  323. return
  324. }
  325. c.Data["json"] = c.ResultOK(newid, 0)
  326. c.ServeJSON()
  327. }
  328. // @Summary 删除指定的检测模型
  329. // @Description 删除指定的检测模型
  330. // @Tags 业务管理服务
  331. // @Accept x-www-form-urlencoded
  332. // @Produce json
  333. // @Param id formData int true "模型ID"
  334. // @Success 200 {object} ResultOK 成功
  335. // @Failure 500 {object} ResultError 失败
  336. // @router /admin/sysmodel/delete [post]
  337. func (c *BusAdminController) DeleteSysModelByID() {
  338. id, _ := c.GetInt("id")
  339. if id == 0 {
  340. c.Data["json"] = c.ResultError("id不能为空!")
  341. c.ServeJSON()
  342. return
  343. }
  344. obj := new(bo.SysCheckModelMgr)
  345. obj.SetUserInfo(c.GetCurrentUserInfo())
  346. obj.Model = bo.T_data_model_defualt{Id: id}
  347. obj.Model.Id = id
  348. err := obj.Delete()
  349. if err != nil {
  350. c.Data["json"] = c.ResultError(err.Error())
  351. c.ServeJSON()
  352. return
  353. }
  354. c.Data["json"] = c.ResultOK("", 0)
  355. c.ServeJSON()
  356. }
  357. // @Summary 更新检测模型指定装置的类型编码
  358. // @Description 更新检测模型指定装置的类型编码
  359. // @Tags 业务管理服务
  360. // @Accept x-www-form-urlencoded
  361. // @Produce json
  362. // @Param id formData int true "模型ID"
  363. // @Param old_iedtype formData string true "装置原编码"
  364. // @Param new_iedtype formData string true "装置新编码"
  365. // @Success 200 {object} ResultOK 成功
  366. // @Failure 500 {object} ResultError 失败
  367. // @router /admin/sysmodel/update/iedtype [post]
  368. func (c *BusAdminController) UPdateSysModelIedType() {
  369. id, _ := c.GetInt("id")
  370. if id == 0 {
  371. c.Data["json"] = c.ResultError("模型编号不能为空!")
  372. c.ServeJSON()
  373. return
  374. }
  375. oldtype := c.GetString("old_iedtype")
  376. newtype := c.GetString("new_iedtype")
  377. if oldtype == "" {
  378. c.Data["json"] = c.ResultError("装置类型编码不能为空!")
  379. c.ServeJSON()
  380. return
  381. }
  382. obj := new(bo.SysCheckModelMgr)
  383. obj.SetUserInfo(c.GetCurrentUserInfo())
  384. obj.Model = bo.T_data_model_defualt{Id: id}
  385. err := obj.UpdateIedType(oldtype, newtype)
  386. if err != nil {
  387. c.Data["json"] = c.ResultError(err.Error())
  388. c.ServeJSON()
  389. return
  390. }
  391. c.Data["json"] = c.ResultOK("", 0)
  392. c.ServeJSON()
  393. }
  394. // @Summary 获取检测模型指定装置的自定义类型编码
  395. // @Description 获取检测模型指定装置的自定义类型编码
  396. // @Tags 业务管理服务
  397. // @Accept x-www-form-urlencoded
  398. // @Produce json
  399. // @Param id formData int true "模型ID"
  400. // @Param ied_type formData string true "装置原编码"
  401. // @Success 200 {object} ResultOK 成功
  402. // @Failure 500 {object} ResultError 失败
  403. // @router /admin/sysmodel/get/iedtype [get]
  404. func (c *BusAdminController) GetSysModelIedTypeMapping() {
  405. id, _ := c.GetInt("id")
  406. if id == 0 {
  407. c.Data["json"] = c.ResultError("模型编号不能为空!")
  408. c.ServeJSON()
  409. return
  410. }
  411. oldtype := c.GetString("ied_type")
  412. if oldtype == "" {
  413. c.Data["json"] = c.ResultError("装置类型编码不能为空!")
  414. c.ServeJSON()
  415. return
  416. }
  417. obj := new(bo.SysCheckModelMgr)
  418. obj.SetUserInfo(c.GetCurrentUserInfo())
  419. obj.Model = bo.T_data_model_defualt{Id: id}
  420. r := obj.GetIedtypeMapping(oldtype)
  421. c.Data["json"] = c.ResultOK(r, 0)
  422. c.ServeJSON()
  423. }
  424. // @Summary 查询检测模型列表
  425. // @Description 查询检测模型列表。支持名称、电压等级等过滤条件
  426. // @Tags 检测任务服务接口
  427. // @Accept x-www-form-urlencoded
  428. // @Produce json
  429. // @Param pageno query int true "当前页码。默认为1"
  430. // @Param pagesize query int true "每页显示数据数。默认为20"
  431. // @Param id query int false "ID"
  432. // @Param vol_id query int false "电压等级ID"
  433. // @Param model_name query string false "名称"
  434. // @Param line_link_style query int false "接线方式"
  435. // @Param area_type query int false "间隔类型"
  436. // @Param is_sys query int false "模型类型。1 内置模型 2 自定义模型"
  437. // @Success 200 {object} ResultOK 成功
  438. // @Failure 500 {object} ResultError 失败
  439. // @router /admin/sysmodel/list [get]
  440. func (c *BusAdminController) GetSysModelList() {
  441. obj := new(bo.SysCheckModelMgr)
  442. obj.SetUserInfo(c.GetCurrentUserInfo())
  443. obj.Model = bo.T_data_model_defualt{}
  444. obj.Model.Id, _ = c.GetInt("id")
  445. obj.Model.IsSys, _ = c.GetInt("is_sys", 1) //默认查询系统内置模型
  446. obj.Model.VolId, _ = c.GetInt("vol_id")
  447. obj.Model.ModelName = c.GetString("model_name")
  448. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  449. obj.Model.AreaType, _ = c.GetInt("area_type")
  450. pi, _ := c.GetInt("pagesize", 20)
  451. po, _ := c.GetInt("pageno", 0)
  452. if po == 0 {
  453. po, _ = c.GetInt("pageindex", 0)
  454. }
  455. if po == 0 {
  456. po = 1
  457. }
  458. lst, cnt, err := obj.List(po, pi)
  459. if err != nil {
  460. c.Data["json"] = c.ResultError(err.Error())
  461. c.ServeJSON()
  462. return
  463. }
  464. //如果是获取指定模型信息时,附加模型的标准装置类型信息
  465. if obj.Model.Id > 0 {
  466. //间隔类型id
  467. syscode := new(bo.Global)
  468. codeinfo := syscode.GetCodeInfoByID(tools.IsEmpty(lst[0]["area_type"]))
  469. if codeinfo != nil {
  470. code := "area_type_" + tools.IsEmpty(codeinfo["code"])
  471. codeinfo = syscode.GetCodeInfoByCode("area_ied_type", code)
  472. codes := strings.Split(tools.IsEmpty(codeinfo["name"]), ",")
  473. ccrows := []orm.Params{}
  474. for _, item := range codes {
  475. tmp := syscode.GetCodeInfoByCode("ied_type", item)
  476. if tmp == nil {
  477. ccrows = append(ccrows, orm.Params{"code": item, "name": item})
  478. } else {
  479. ccrows = append(ccrows, tmp)
  480. }
  481. }
  482. lst[0]["ied_type"] = ccrows
  483. }
  484. }
  485. c.Data["json"] = c.ResultOK(lst, cnt)
  486. c.ServeJSON()
  487. }
  488. // @Summary 重新分析指定的SCD检测模型间隔
  489. // @Description 重新分析指定的SCD检测模型间隔
  490. // @Tags 业务管理服务
  491. // @Accept x-www-form-urlencoded
  492. // @Produce json
  493. // @Param scd_id formData int true "SCD文件ID"
  494. // @Success 200 {object} ResultOK 成功
  495. // @Failure 500 {object} ResultError 失败
  496. // @router /admin/parse/check_area [post]
  497. func (c *BusAdminController) ResetCheckAreaByID() {
  498. id, _ := c.GetInt64("scd_id")
  499. if id == 0 {
  500. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  501. c.ServeJSON()
  502. return
  503. }
  504. obj := new(bo.CheckAreaMgr)
  505. obj.SetUserInfo(c.GetCurrentUserInfo())
  506. obj.ScdId = id
  507. err := obj.Reset()
  508. if err != nil {
  509. c.Data["json"] = c.ResultError(err.Error())
  510. c.ServeJSON()
  511. return
  512. }
  513. c.Data["json"] = c.ResultOK("", 0)
  514. c.ServeJSON()
  515. }
  516. // @Summary 查询指定电压等级及接线方式下的检测间隔分析结果
  517. // @Description 查询指定电压等级及接线方式下的检测间隔分析结果
  518. // @Tags 业务管理服务
  519. // @Accept x-www-form-urlencoded
  520. // @Produce json
  521. // @Param scd_id formData int true "SCD文件ID"
  522. // @Param vol_id formData int false "电压等级ID"
  523. // @Param link_style_id formData int false "接线方式ID"
  524. // @Success 200 {object} ResultOK 成功
  525. // @Failure 500 {object} ResultError 失败
  526. // @router /admin/get/check_area [get]
  527. func (c *BusAdminController) GetCheckAreaByVolID() {
  528. id, _ := c.GetInt64("scd_id")
  529. if id == 0 {
  530. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  531. c.ServeJSON()
  532. return
  533. }
  534. volid, _ := c.GetInt("vol_id")
  535. lsid, _ := c.GetInt("link_style_id")
  536. obj := new(bo.CheckAreaMgr)
  537. obj.SetUserInfo(c.GetCurrentUserInfo())
  538. obj.ScdId = id
  539. lst, err := obj.GetAreaListByVol(id, volid, lsid)
  540. if err != nil {
  541. c.Data["json"] = c.ResultError(err.Error())
  542. c.ServeJSON()
  543. return
  544. }
  545. if lst == nil || len(lst) == 0 {
  546. //新分析
  547. err = obj.Reset()
  548. if err != nil {
  549. c.Data["json"] = c.ResultError(err.Error())
  550. c.ServeJSON()
  551. return
  552. }
  553. lst, _ = obj.GetAreaListByVol(id, volid, lsid)
  554. }
  555. //获取每个间隔下的ied列表同步返回
  556. if lst != nil {
  557. for i, row := range lst {
  558. area_id, _ := strconv.Atoi(tools.IsEmpty(row["area_id"]))
  559. iedlst, _ := obj.GetIedList(id, area_id)
  560. if iedlst == nil {
  561. lst[i]["ieds"] = []orm.Params{}
  562. } else {
  563. lst[i]["ieds"] = iedlst
  564. }
  565. }
  566. }
  567. c.Data["json"] = c.ResultOK(lst, 0)
  568. c.ServeJSON()
  569. }
  570. // @Summary 查询指定检测间隔下的IED装置列表
  571. // @Description 查询指定检测间隔下的IED装置列表
  572. // @Tags 业务管理服务
  573. // @Accept x-www-form-urlencoded
  574. // @Produce json
  575. // @Param scd_id formData int true "SCD文件ID"
  576. // @Param area_id formData int true "检测间隔ID"
  577. // @Success 200 {object} ResultOK 成功
  578. // @Failure 500 {object} ResultError 失败
  579. // @router /admin/get/check_area/ied [get]
  580. func (c *BusAdminController) GetCheckAreaIedByAreaID() {
  581. id, _ := c.GetInt64("scd_id")
  582. if id == 0 {
  583. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  584. c.ServeJSON()
  585. return
  586. }
  587. area_id, _ := c.GetInt("area_id")
  588. obj := new(bo.CheckAreaMgr)
  589. obj.SetUserInfo(c.GetCurrentUserInfo())
  590. obj.ScdId = id
  591. lst, err := obj.GetIedList(id, area_id)
  592. if err != nil {
  593. c.Data["json"] = c.ResultError(err.Error())
  594. c.ServeJSON()
  595. return
  596. }
  597. c.Data["json"] = c.ResultOK(lst, 0)
  598. c.ServeJSON()
  599. }
  600. // @Summary 修改并保存指定检测间隔下的IED装置列表
  601. // @Description 修改并保存指定检测间隔下的IED装置列表
  602. // @Tags 业务管理服务
  603. // @Accept x-www-form-urlencoded
  604. // @Produce json
  605. // @Param scd_id formData int true "SCD文件ID"
  606. // @Param area_id formData int true "检测间隔ID"
  607. // @Param ied_ids formData string true "IED装置name列表,多个ied采用逗号分隔。如:PT1001,PL1001,..."
  608. // @Success 200 {object} ResultOK 成功
  609. // @Failure 500 {object} ResultError 失败
  610. // @router /admin/update/check_area/ied [post]
  611. func (c *BusAdminController) SaveCheckAreaIedByAreaID() {
  612. id, _ := c.GetInt64("scd_id")
  613. if id == 0 {
  614. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  615. c.ServeJSON()
  616. return
  617. }
  618. area_id, _ := c.GetInt("area_id")
  619. ieds := c.GetString("ied_ids")
  620. if area_id == 0 {
  621. c.Data["json"] = c.ResultError("检测间隔ID不能为空!")
  622. c.ServeJSON()
  623. return
  624. }
  625. if ieds == "" {
  626. c.Data["json"] = c.ResultError("检测间隔装置列表不能为空!")
  627. c.ServeJSON()
  628. return
  629. }
  630. obj := new(bo.CheckAreaMgr)
  631. obj.SetUserInfo(c.GetCurrentUserInfo())
  632. obj.ScdId = id
  633. err := obj.UpdateIeds(id, area_id, ieds)
  634. if err != nil {
  635. c.Data["json"] = c.ResultError(err.Error())
  636. c.ServeJSON()
  637. return
  638. }
  639. c.Data["json"] = c.ResultOK("", 0)
  640. c.ServeJSON()
  641. }
  642. // @Summary 获取指定模型和装置类型的功能列表
  643. // @Description 获取指定模型和装置类型的功能列表
  644. // @Tags 业务管理服务
  645. // @Accept x-www-form-urlencoded
  646. // @Produce json
  647. // @Param model_id formData int true "模型ID"
  648. // @Param ied_type formData string true "装置类型"
  649. // @Success 200 {object} ResultOK 成功
  650. // @Failure 500 {object} ResultError 失败
  651. // @router /admin/model/function/list [get]
  652. func (c *BusAdminController) GetFuncListByIedType() {
  653. modelid, _ := c.GetInt("model_id")
  654. if modelid == 0 {
  655. c.Data["json"] = c.ResultError("模型ID不能为空!")
  656. c.ServeJSON()
  657. return
  658. }
  659. ied_type := c.GetString("ied_type")
  660. if ied_type == "" {
  661. c.Data["json"] = c.ResultError("装置类型不能为空!")
  662. c.ServeJSON()
  663. return
  664. }
  665. obj := new(bo.SysCheckModelIedFuncMgr)
  666. obj.SetUserInfo(c.GetCurrentUserInfo())
  667. lst, err := obj.GetList(modelid, ied_type)
  668. if err != nil {
  669. c.Data["json"] = c.ResultError(err.Error())
  670. c.ServeJSON()
  671. return
  672. }
  673. c.Data["json"] = c.ResultOK(lst, 0)
  674. c.ServeJSON()
  675. }
  676. // @Summary 获取指定模型和装置类型的端子列表
  677. // @Description 获取指定模型和装置类型的端子列表
  678. // @Tags 业务管理服务
  679. // @Accept x-www-form-urlencoded
  680. // @Produce json
  681. // @Param model_id formData int true "模型ID"
  682. // @Param ied_type formData string true "查询的装置类型"
  683. // @Param ref_ied_type formData string true "对侧关联装置类型"
  684. // @Param sv_or_goose formData string true "信号类型。仅支持:SV或GOOSE"
  685. // @Param in_or_out formData string true "信号方向。仅支持:'输出'或'接收'"
  686. // @Success 200 {object} ResultOK 成功
  687. // @Failure 500 {object} ResultError 失败
  688. // @router /admin/model/function/fcda/list [get]
  689. func (c *BusAdminController) GetFuncFcdaList() {
  690. modelid, _ := c.GetInt("model_id")
  691. if modelid == 0 {
  692. c.Data["json"] = c.ResultError("模型ID不能为空!")
  693. c.ServeJSON()
  694. return
  695. }
  696. ied_type := c.GetString("ied_type")
  697. if ied_type == "" {
  698. c.Data["json"] = c.ResultError("查询的装置类型不能为空!")
  699. c.ServeJSON()
  700. return
  701. }
  702. ref_ied_type := c.GetString("ref_ied_type")
  703. if ied_type == "" {
  704. c.Data["json"] = c.ResultError("对侧关联装置类型不能为空!")
  705. c.ServeJSON()
  706. return
  707. }
  708. obj := new(bo.SysCheckModelIedFuncMgr)
  709. obj.SetUserInfo(c.GetCurrentUserInfo())
  710. lst, err := obj.GetList(modelid, ied_type)
  711. if err != nil {
  712. c.Data["json"] = c.ResultError(err.Error())
  713. c.ServeJSON()
  714. return
  715. }
  716. if len(lst) == 0 {
  717. c.Data["json"] = c.ResultOK("", 0)
  718. c.ServeJSON()
  719. return
  720. }
  721. funcids := []string{}
  722. for _, row := range lst {
  723. funcids = append(funcids, tools.IsEmpty(row["id"]))
  724. }
  725. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  726. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  727. fcdaMgr.Model.ModelId = modelid
  728. fcdaMgr.Model.Svorgoose = strings.ToUpper(c.GetString("sv_or_goose"))
  729. fcdaMgr.Model.Inorout = c.GetString("in_or_out")
  730. fcdaList, err := fcdaMgr.GetList(ref_ied_type, funcids)
  731. if err != nil {
  732. c.Data["json"] = c.ResultError(err.Error())
  733. c.ServeJSON()
  734. return
  735. }
  736. c.Data["json"] = c.ResultOK(fcdaList, len(fcdaList))
  737. c.ServeJSON()
  738. }
  739. // @Summary 保存模型装置功能及端子信息
  740. // @Description 保存装置功能及端子信息
  741. // @Tags 业务管理服务
  742. // @Accept x-www-form-urlencoded
  743. // @Produce json
  744. // @Param model_id formData int true "模型ID"
  745. // @Param ied_type formData string true "装置类型代码"
  746. // @Param func_id formData int false "功能ID。编辑时必传。"
  747. // @Param func_name formData string true "功能名称。必传。"
  748. // @Param fcda_id formData int false "端子ID。编辑时必传。"
  749. // @Param fcda_name formData string true "端子名称。必传。"
  750. // @Param fcda_match_exp formData string true "端子匹配表达式。必传。"
  751. // @Param sv_or_goose formData string true "端子信号类型。必传。仅支持SV或GOOSE"
  752. // @Param in_or_out formData string true "端子信号输入输出方向。必传。仅支持中文的'接收'或'输出'"
  753. // @Success 200 {object} ResultOK 成功
  754. // @Failure 500 {object} ResultError 失败
  755. // @router /admin/model/function/fcda/save [post]
  756. func (c *BusAdminController) SaveFuncFcda() {
  757. modelid, _ := c.GetInt("model_id")
  758. if modelid == 0 {
  759. c.Data["json"] = c.ResultError("模型ID不能为空!")
  760. c.ServeJSON()
  761. return
  762. }
  763. ied_type := c.GetString("ied_type")
  764. func_name := c.GetString("func_name")
  765. fcda_name := c.GetString("fcda_name")
  766. fcda_match_exp := c.GetString("fcda_match_exp")
  767. func_id, _ := c.GetInt("func_id")
  768. fcda_id, _ := c.GetInt("fcda_id")
  769. svorgoose := c.GetString("sv_or_goose")
  770. inorout := c.GetString("in_or_out")
  771. if func_name == "" {
  772. c.Data["json"] = c.ResultError("功能名称不能为空!")
  773. c.ServeJSON()
  774. return
  775. }
  776. if fcda_name == "" {
  777. c.Data["json"] = c.ResultError("端子设计名称不能为空!")
  778. c.ServeJSON()
  779. return
  780. }
  781. if fcda_match_exp == "" {
  782. c.Data["json"] = c.ResultError("端子匹配关键词不能为空!")
  783. c.ServeJSON()
  784. return
  785. }
  786. if svorgoose == "" {
  787. c.Data["json"] = c.ResultError("端子信号类型不能为空!")
  788. c.ServeJSON()
  789. return
  790. }
  791. if inorout == "" {
  792. c.Data["json"] = c.ResultError("端子信号方向不能为空!")
  793. c.ServeJSON()
  794. return
  795. }
  796. mod := bo.T_data_model_func_def{}
  797. mod.Id = func_id
  798. mod.ModelId = modelid
  799. mod.IedType = ied_type
  800. mod.FuncFcdaId = fcda_id
  801. mod.FuncName = func_name
  802. mod.FcdaName = fcda_name
  803. mod.FcdaMatchExp = fcda_match_exp
  804. mod.Svorgoose = svorgoose
  805. mod.Inorout = inorout
  806. mgr := new(bo.SysCheckModelIedFuncMgr)
  807. mgr.SetUserInfo(c.GetCurrentUserInfo())
  808. mgr.Model = mod
  809. _, _, err := mgr.Save()
  810. if err != nil {
  811. c.Data["json"] = c.ResultError(err.Error())
  812. c.ServeJSON()
  813. return
  814. }
  815. c.Data["json"] = c.ResultOK("", 0)
  816. c.ServeJSON()
  817. }
  818. // @Summary 删除指定模型所有的装置端子
  819. // @Description 删除指定模型所有的装置端子
  820. // @Tags 业务管理服务
  821. // @Accept x-www-form-urlencoded
  822. // @Produce json
  823. // @Param model_id formData int true "模型ID"
  824. // @Success 200 {object} ResultOK 成功
  825. // @Failure 500 {object} ResultError 失败
  826. // @router /admin/model/fcda/delall [post]
  827. func (c *BusAdminController) DelAllFuncFcda() {
  828. modelid, _ := c.GetInt("model_id")
  829. if modelid == 0 {
  830. c.Data["json"] = c.ResultError("模型ID不能为空!")
  831. c.ServeJSON()
  832. return
  833. }
  834. fcdaMgr := new(bo.SysCheckModelIedFuncMgr)
  835. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  836. fcdaMgr.Model = bo.T_data_model_func_def{}
  837. fcdaMgr.Model.ModelId = modelid
  838. err := fcdaMgr.Delete()
  839. if err != nil {
  840. c.Data["json"] = c.ResultError(err.Error())
  841. c.ServeJSON()
  842. return
  843. }
  844. c.Data["json"] = c.ResultOK("", 0)
  845. c.ServeJSON()
  846. }
  847. // @Summary 删除装置端子
  848. // @Description 删除装置端子
  849. // @Tags 业务管理服务
  850. // @Accept x-www-form-urlencoded
  851. // @Produce json
  852. // @Param model_id formData int true "模型ID"
  853. // @Param fcda_id formData int true "端子ID"
  854. // @Success 200 {object} ResultOK 成功
  855. // @Failure 500 {object} ResultError 失败
  856. // @router /admin/model/function/fcda/del [post]
  857. func (c *BusAdminController) DelFuncFcda() {
  858. modelid, _ := c.GetInt("model_id")
  859. if modelid == 0 {
  860. c.Data["json"] = c.ResultError("模型ID不能为空!")
  861. c.ServeJSON()
  862. return
  863. }
  864. fcda_id, _ := c.GetInt("fcda_id")
  865. if fcda_id == 0 {
  866. c.Data["json"] = c.ResultError("端子ID不能为空!")
  867. c.ServeJSON()
  868. return
  869. }
  870. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  871. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  872. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  873. fcdaMgr.Model.ModelId = modelid
  874. fcdaMgr.Model.Id = fcda_id
  875. err := fcdaMgr.Delete()
  876. if err != nil {
  877. c.Data["json"] = c.ResultError(err.Error())
  878. c.ServeJSON()
  879. return
  880. }
  881. c.Data["json"] = c.ResultOK("", 0)
  882. c.ServeJSON()
  883. }
  884. // @Summary 获取模型装置端子已关联的接收端子
  885. // @Description 获取模型装置端子已关联的接收端子
  886. // @Tags 业务管理服务
  887. // @Accept x-www-form-urlencoded
  888. // @Produce json
  889. // @Param model_id formData int true "模型ID"
  890. // @Param from_fcda_id formData int true "输出装置端子ID"
  891. // @Param to_ied_type formData string false "输入装置类型"
  892. // @Param goosesv formData string false "信号类型。GOOSE|SV"
  893. // @Success 200 {object} ResultOK 成功
  894. // @Failure 500 {object} ResultError 失败
  895. // @router /admin/model/function/fcda-ref/list [get]
  896. func (c *BusAdminController) GetFuncFcdaRef() {
  897. modelid, _ := c.GetInt("model_id")
  898. if modelid == 0 {
  899. c.Data["json"] = c.ResultError("模型ID不能为空!")
  900. c.ServeJSON()
  901. return
  902. }
  903. fcda_id, _ := c.GetInt("from_fcda_id")
  904. if fcda_id == 0 {
  905. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  906. c.ServeJSON()
  907. return
  908. }
  909. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  910. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  911. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  912. fcdaMgr.Model.ModelId = modelid
  913. fcdaMgr.Model.FromFcdaId = fcda_id
  914. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  915. fcdaMgr.Model.Goosesv = c.GetString("goosesv")
  916. lst, err := fcdaMgr.GetList()
  917. if err != nil {
  918. c.Data["json"] = c.ResultError(err.Error())
  919. c.ServeJSON()
  920. return
  921. }
  922. c.Data["json"] = c.ResultOK(lst, len(lst))
  923. c.ServeJSON()
  924. }
  925. // @Summary 保存模型装置端子间关联关系
  926. // @Description 保存模型装置端子间关联关系
  927. // @Tags 业务管理服务
  928. // @Accept x-www-form-urlencoded
  929. // @Produce json
  930. // @Param model_id formData int true "模型ID"
  931. // @Param from_ied_type formData string true "输出装置类型"
  932. // @Param to_ied_type formData string true "输入装置类型"
  933. // @Param from_fcda_id formData int false "输出装置端子ID"
  934. // @Param to_fcda_ids formData string false "输入装置端子ID"
  935. // @Param batch_fcda_ids formData json-string true "批量保存端子关系。类型为序列化的二维数组字符串。数组元素为:[[fromfcdaid,tofcdaid],...]"
  936. // @Param goosesv formData string true "信号类型。值范围:GOOSE|SV"
  937. // @Success 200 {object} ResultOK 成功
  938. // @Failure 500 {object} ResultError 失败
  939. // @router /admin/model/function/fcda-ref/save [post]
  940. func (c *BusAdminController) SaveFuncFcdaRef() {
  941. modelid, _ := c.GetInt("model_id")
  942. if modelid == 0 {
  943. c.Data["json"] = c.ResultError("模型ID不能为空!")
  944. c.ServeJSON()
  945. return
  946. }
  947. fcda_id, _ := c.GetInt("from_fcda_id")
  948. if fcda_id == 0 {
  949. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  950. c.ServeJSON()
  951. return
  952. }
  953. fcda_in_ids := c.GetString("to_fcda_ids")
  954. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  955. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  956. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  957. fcdaMgr.Model.ModelId = modelid
  958. fcdaMgr.Model.FromFcdaId = fcda_id
  959. fcdaMgr.Model.FromIedCode = c.GetString("from_ied_type")
  960. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  961. fcdaMgr.Model.Goosesv = strings.ToUpper(c.GetString("goosesv"))
  962. if fcdaMgr.Model.FromIedCode == "" || fcdaMgr.Model.ToIedCode == "" {
  963. c.Data["json"] = c.ResultError("输入和输出装置类型不能为空!")
  964. c.ServeJSON()
  965. return
  966. }
  967. if fcdaMgr.Model.Goosesv == "" {
  968. c.Data["json"] = c.ResultError("信号类型不能为空!")
  969. c.ServeJSON()
  970. return
  971. }
  972. if fcdaMgr.Model.Goosesv != "GOOSE" && fcdaMgr.Model.Goosesv != "SV" {
  973. c.Data["json"] = c.ResultError("信号类型不正确。只能为GOOSE或SV")
  974. c.ServeJSON()
  975. return
  976. }
  977. batch_fcda_ids := c.GetString("batch_fcda_ids")
  978. if batch_fcda_ids != "" {
  979. //批量保存
  980. fcdalist := [][]int{}
  981. err := json.Unmarshal([]byte(batch_fcda_ids), &fcdalist)
  982. if err != nil {
  983. c.Data["json"] = c.ResultError("无效的批量端子关系数据")
  984. c.ServeJSON()
  985. return
  986. }
  987. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  988. for _, item := range fcdalist {
  989. fcdainf, err := obj.One(item[0])
  990. if err != nil {
  991. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[0]))
  992. c.ServeJSON()
  993. return
  994. }
  995. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  996. fcdaMgr.Model.FromFcdaId = item[0]
  997. fcdainf, err = obj.One(item[1])
  998. if err != nil {
  999. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[1]))
  1000. c.ServeJSON()
  1001. return
  1002. }
  1003. fcdaMgr.Model.ToFcdaId = item[1]
  1004. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  1005. err = fcdaMgr.Save()
  1006. if err != nil {
  1007. c.Data["json"] = c.ResultError(err.Error())
  1008. c.ServeJSON()
  1009. return
  1010. }
  1011. }
  1012. c.Data["json"] = c.ResultOK("", 0)
  1013. c.ServeJSON()
  1014. return
  1015. }
  1016. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  1017. fcdainf, er := obj.One(fcdaMgr.Model.FromFcdaId)
  1018. if er != nil {
  1019. c.Data["json"] = c.ResultError("无效的输出端子ID")
  1020. c.ServeJSON()
  1021. return
  1022. }
  1023. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  1024. //清除输出端子的原关系
  1025. err := fcdaMgr.Delete()
  1026. if err != nil {
  1027. c.Data["json"] = c.ResultError(err.Error())
  1028. c.ServeJSON()
  1029. return
  1030. }
  1031. if fcda_in_ids != "" {
  1032. fcda_in_ids_1 := strings.Split(fcda_in_ids, ",")
  1033. for _, k := range fcda_in_ids_1 {
  1034. fcdaMgr.Model.ToFcdaId, _ = strconv.Atoi(k) //设置接收端子id
  1035. fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId)
  1036. if er != nil {
  1037. c.Data["json"] = c.ResultError("无效的接收端子ID")
  1038. c.ServeJSON()
  1039. return
  1040. }
  1041. //清除接收端子的原关系
  1042. fcdaMgr.Model.FromFcdaId = 0
  1043. fcdaMgr.Delete()
  1044. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  1045. //建立新的端子关系
  1046. fcdaMgr.Model.FromFcdaId = fcda_id //还原输出端子id
  1047. err := fcdaMgr.Save()
  1048. if err != nil {
  1049. c.Data["json"] = c.ResultError(err.Error())
  1050. c.ServeJSON()
  1051. return
  1052. }
  1053. }
  1054. }
  1055. c.Data["json"] = c.ResultOK("", 0)
  1056. c.ServeJSON()
  1057. }
  1058. // @Summary 删除端子之间的关联关系
  1059. // @Description 删除端子之间的关联关系
  1060. // @Tags 业务管理服务
  1061. // @Accept x-www-form-urlencoded
  1062. // @Produce json
  1063. // @Param model_id formData int true "模型ID"
  1064. // @Param from_fcda_id formData int true "输入端子ID"
  1065. // @Param to_fcda_id formData int true "输出端子ID"
  1066. // @Success 200 {object} ResultOK 成功
  1067. // @Failure 500 {object} ResultError 失败
  1068. // @router /admin/model/function/fcda-ref/del [post]
  1069. func (c *BusAdminController) DelFuncFcdaRef() {
  1070. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  1071. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1072. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  1073. fcdaMgr.Model.ModelId, _ = c.GetInt("model_id", 0)
  1074. fcdaMgr.Model.FromFcdaId, _ = c.GetInt("from_fcda_id", 0)
  1075. fcdaMgr.Model.ToFcdaId, _ = c.GetInt("to_fcda_id")
  1076. if fcdaMgr.Model.ModelId == 0 {
  1077. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1078. c.ServeJSON()
  1079. return
  1080. }
  1081. if fcdaMgr.Model.FromFcdaId == 0 {
  1082. c.Data["json"] = c.ResultError("输入端子ID不能为空!")
  1083. c.ServeJSON()
  1084. return
  1085. }
  1086. if fcdaMgr.Model.ToFcdaId == 0 {
  1087. c.Data["json"] = c.ResultError("接收端子ID不能为空")
  1088. c.ServeJSON()
  1089. return
  1090. }
  1091. //清除原关系
  1092. err := fcdaMgr.Delete()
  1093. if err != nil {
  1094. c.Data["json"] = c.ResultError(err.Error())
  1095. c.ServeJSON()
  1096. return
  1097. }
  1098. c.Data["json"] = c.ResultOK("", 0)
  1099. c.ServeJSON()
  1100. }