busAdminController.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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. "scd_check_tools/models/bo"
  14. "scd_check_tools/tools"
  15. "strconv"
  16. "strings"
  17. )
  18. //业务管理服务
  19. type BusAdminController struct {
  20. BaseController
  21. }
  22. func init() {
  23. }
  24. // @Summary 创建新的接线方式
  25. // @Description 创建新的接线方式
  26. // @Tags 业务管理服务
  27. // @Accept x-www-form-urlencoded
  28. // @Produce json
  29. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  30. // @Param name formData string true "任务名称"
  31. // @Param vol_id formData int true "电压等级ID"
  32. // @Param pic formData string false "接线图地址"
  33. // @Success 200 {object} ResultOK 成功
  34. // @Failure 500 {object} ResultError 失败
  35. // @router /admin/linkstyle/save [post]
  36. func (c *BusAdminController) SaveLinkStyleInfo() {
  37. id, _ := c.GetInt("id")
  38. obj := new(bo.LinkStyleMgr)
  39. obj.SetUserInfo(c.GetCurrentUserInfo())
  40. obj.Model = bo.T_data_link_style{Id: id}
  41. obj.Model.Name = c.GetString("name")
  42. obj.Model.VolLevelId, _ = c.GetInt("vol_id")
  43. obj.Model.Pic = c.GetString("pic")
  44. if obj.Model.Name == "" {
  45. c.Data["json"] = c.ResultError("名称不能为空")
  46. c.ServeJSON()
  47. return
  48. }
  49. if obj.Model.VolLevelId == 0 {
  50. c.Data["json"] = c.ResultError("电压等级不能为空")
  51. c.ServeJSON()
  52. return
  53. }
  54. err := obj.Save()
  55. if err != nil {
  56. c.Data["json"] = c.ResultError(err.Error())
  57. c.ServeJSON()
  58. return
  59. }
  60. c.Data["json"] = c.ResultOK("", 0)
  61. c.ServeJSON()
  62. }
  63. // @Summary 删除指定的接线方式
  64. // @Description 删除指定的接线方式
  65. // @Tags 业务管理服务
  66. // @Accept x-www-form-urlencoded
  67. // @Produce json
  68. // @Param id formData int true "接线方式ID"
  69. // @Success 200 {object} ResultOK 成功
  70. // @Failure 500 {object} ResultError 失败
  71. // @router /admin/linkstyle/delete [post]
  72. func (c *BusAdminController) DeleteLinkStyleByID() {
  73. id, _ := c.GetInt("id")
  74. if id == 0 {
  75. c.Data["json"] = c.ResultError("id不能为空!")
  76. c.ServeJSON()
  77. return
  78. }
  79. obj := new(bo.LinkStyleMgr)
  80. obj.SetUserInfo(c.GetCurrentUserInfo())
  81. obj.Model = bo.T_data_link_style{}
  82. obj.Model.Id = id
  83. err := obj.Delete()
  84. if err != nil {
  85. c.Data["json"] = c.ResultError(err.Error())
  86. c.ServeJSON()
  87. return
  88. }
  89. c.Data["json"] = c.ResultOK("", 0)
  90. c.ServeJSON()
  91. }
  92. // @Summary 查询接线方式
  93. // @Description 查询接线方式。支持名称、电压等级等过滤条件
  94. // @Tags 检测任务服务接口
  95. // @Accept x-www-form-urlencoded
  96. // @Produce json
  97. // @Param pageno query int true "当前页码。默认为1"
  98. // @Param pagesize query int true "每页显示数据数。默认为20"
  99. // @Param id query int false "ID"
  100. // @Param vol_id query int false "电压ID"
  101. // @Param name query string false "名称"
  102. // @Success 200 {object} ResultOK 成功
  103. // @Failure 500 {object} ResultError 失败
  104. // @router /admin/linkstyle/list [get]
  105. func (c *BusAdminController) GetLinkStyleList() {
  106. obj := new(bo.LinkStyleMgr)
  107. obj.SetUserInfo(c.GetCurrentUserInfo())
  108. obj.Model = bo.T_data_link_style{}
  109. obj.Model.Id, _ = c.GetInt("id")
  110. obj.Model.VolLevelId, _ = c.GetInt("vol_id")
  111. obj.Model.Name = c.GetString("name")
  112. pi, _ := c.GetInt("pagesize", 20)
  113. po, _ := c.GetInt("pageno", 0)
  114. if po == 0 {
  115. po, _ = c.GetInt("pageindex", 0)
  116. }
  117. if po == 0 {
  118. po = 1
  119. }
  120. lst, cnt, err := obj.List(po, pi)
  121. if err != nil {
  122. c.Data["json"] = c.ResultError(err.Error())
  123. c.ServeJSON()
  124. return
  125. }
  126. c.Data["json"] = c.ResultOK(lst, cnt)
  127. c.ServeJSON()
  128. }
  129. // @Summary 添加接线方式的模型
  130. // @Description 添加接线方式的模型
  131. // @Tags 业务管理服务
  132. // @Accept x-www-form-urlencoded
  133. // @Produce json
  134. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  135. // @Param linkstyle_id formData int true "接线方式ID"
  136. // @Param model_id formData int true "内置模型id"
  137. // @Success 200 {object} ResultOK 成功
  138. // @Failure 500 {object} ResultError 失败
  139. // @router /admin/linkstyle-model/save [post]
  140. func (c *BusAdminController) SaveLinkStyleModelInfo() {
  141. id, _ := c.GetInt("id")
  142. obj := new(bo.LinkStyleModelMgr)
  143. obj.SetUserInfo(c.GetCurrentUserInfo())
  144. obj.Model = bo.T_data_link_style_model{Id: id}
  145. obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id")
  146. obj.Model.ModelId, _ = c.GetInt("model_id")
  147. if obj.Model.LinkstyleId == 0 {
  148. c.Data["json"] = c.ResultError("接线方式不能为空")
  149. c.ServeJSON()
  150. return
  151. }
  152. if obj.Model.ModelId == 0 {
  153. c.Data["json"] = c.ResultError("模型ID不能为空")
  154. c.ServeJSON()
  155. return
  156. }
  157. err := obj.Save()
  158. if err != nil {
  159. c.Data["json"] = c.ResultError(err.Error())
  160. c.ServeJSON()
  161. return
  162. }
  163. c.Data["json"] = c.ResultOK("", 0)
  164. c.ServeJSON()
  165. }
  166. // @Summary 删除指定接线方式下属的模型
  167. // @Description 删除指定接线方式下属的模型
  168. // @Tags 业务管理服务
  169. // @Accept x-www-form-urlencoded
  170. // @Produce json
  171. // @Param id formData int true "接线方式ID"
  172. // @Param model_id formData int true "模型ID"
  173. // @Success 200 {object} ResultOK 成功
  174. // @Failure 500 {object} ResultError 失败
  175. // @router /admin/linkstyle-model/delete [post]
  176. func (c *BusAdminController) DeleteLinkStyleModelByID() {
  177. id, _ := c.GetInt("id")
  178. if id == 0 {
  179. c.Data["json"] = c.ResultError("id不能为空!")
  180. c.ServeJSON()
  181. return
  182. }
  183. model_id, _ := c.GetInt("model_id")
  184. if model_id == 0 {
  185. c.Data["json"] = c.ResultError("模型id不能为空!")
  186. c.ServeJSON()
  187. return
  188. }
  189. obj := new(bo.LinkStyleModelMgr)
  190. obj.SetUserInfo(c.GetCurrentUserInfo())
  191. obj.Model = bo.T_data_link_style_model{}
  192. obj.Model.LinkstyleId = id
  193. obj.Model.Id = model_id
  194. err := obj.Delete()
  195. if err != nil {
  196. c.Data["json"] = c.ResultError(err.Error())
  197. c.ServeJSON()
  198. return
  199. }
  200. c.Data["json"] = c.ResultOK("", 0)
  201. c.ServeJSON()
  202. }
  203. // @Summary 查询接线方式下模型列表
  204. // @Description 查询接线方式下模型列表
  205. // @Tags 检测任务服务接口
  206. // @Accept x-www-form-urlencoded
  207. // @Produce json
  208. // @Param pageno query int true "当前页码。默认为1"
  209. // @Param pagesize query int true "每页显示数据数。默认为20"
  210. // @Param id query int false "ID"
  211. // @Param linkstyle_id query int false "接线方式ID"
  212. // @Success 200 {object} ResultOK 成功
  213. // @Failure 500 {object} ResultError 失败
  214. // @router /admin/linkstyle-model/list [get]
  215. func (c *BusAdminController) GetLinkStyleModelList() {
  216. obj := new(bo.LinkStyleModelMgr)
  217. obj.SetUserInfo(c.GetCurrentUserInfo())
  218. obj.Model = bo.T_data_link_style_model{}
  219. obj.Model.Id, _ = c.GetInt("id")
  220. obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id")
  221. pi, _ := c.GetInt("pagesize", 20)
  222. po, _ := c.GetInt("pageno", 0)
  223. if po == 0 {
  224. po, _ = c.GetInt("pageindex", 0)
  225. }
  226. if po == 0 {
  227. po = 1
  228. }
  229. lst, cnt, err := obj.List(po, pi)
  230. if err != nil {
  231. c.Data["json"] = c.ResultError(err.Error())
  232. c.ServeJSON()
  233. return
  234. }
  235. c.Data["json"] = c.ResultOK(lst, cnt)
  236. c.ServeJSON()
  237. }
  238. // @Summary 创建或编辑新的内置模型
  239. // @Description 创建新的内置模型
  240. // @Tags 业务管理服务
  241. // @Accept x-www-form-urlencoded
  242. // @Produce json
  243. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  244. // @Param model_name formData string true "模型名称"
  245. // @Param vol_id formData int true "电压等级ID"
  246. // @Param line_link_style formData int true "接线方式ID"
  247. // @Param ied_types formData string false "包含的装置类型,关联代码:ied_type。多个类型之间使用逗号分隔。"
  248. // @Param relation_json formData string false "模型定义内容。svg源代码(xml格式)。"
  249. // @Param area_type formData string false "间隔类型。关联代码:area_type"
  250. // @Success 200 {object} ResultOK 成功
  251. // @Failure 500 {object} ResultError 失败
  252. // @router /admin/sysmodel/save [post]
  253. func (c *BusAdminController) SaveSysModelInfo() {
  254. id, _ := c.GetInt("id")
  255. obj := new(bo.SysCheckModelMgr)
  256. obj.SetUserInfo(c.GetCurrentUserInfo())
  257. obj.Model = bo.T_data_model_defualt{Id: id, IsSys: 1}
  258. obj.Model.ModelName = c.GetString("model_name")
  259. obj.Model.AreaType, _ = c.GetInt("area_type")
  260. obj.Model.IedTypes = c.GetString("ied_types")
  261. obj.Model.VolId, _ = c.GetInt("vol_id")
  262. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  263. obj.Model.RelationJson = c.GetString("relation_json")
  264. if id == 0 && obj.Model.ModelName == "" {
  265. c.Data["json"] = c.ResultError("模型名称不能为空")
  266. c.ServeJSON()
  267. return
  268. }
  269. if id == 0 && obj.Model.VolId == 0 {
  270. c.Data["json"] = c.ResultError("电压等级不能为空")
  271. c.ServeJSON()
  272. return
  273. }
  274. if id == 0 && obj.Model.LineLinkStyle == 0 {
  275. c.Data["json"] = c.ResultError("接线方式不能为空")
  276. c.ServeJSON()
  277. return
  278. }
  279. if id == 0 && obj.Model.AreaType == 0 {
  280. c.Data["json"] = c.ResultError("间隔类型不能为空")
  281. c.ServeJSON()
  282. return
  283. }
  284. err := obj.Save()
  285. if err != nil {
  286. c.Data["json"] = c.ResultError(err.Error())
  287. c.ServeJSON()
  288. return
  289. }
  290. c.Data["json"] = c.ResultOK("", 0)
  291. c.ServeJSON()
  292. }
  293. // @Summary 复制并保存指定的内置检测模型为自定义模型
  294. // @Description 复制并保存指定的内置检测模型为自定义模型
  295. // @Tags 业务管理服务
  296. // @Accept x-www-form-urlencoded
  297. // @Produce json
  298. // @Param id formData int true "模型ID"
  299. // @Param newname formData string true "新模型名称"
  300. // @Success 200 {object} ResultOK 成功
  301. // @Failure 500 {object} ResultError 失败
  302. // @router /admin/sysmodel/saveas [post]
  303. func (c *BusAdminController) CopySysModelByID() {
  304. id, _ := c.GetInt("id")
  305. if id == 0 {
  306. c.Data["json"] = c.ResultError("id不能为空!")
  307. c.ServeJSON()
  308. return
  309. }
  310. new_name := c.GetString("newname")
  311. if new_name == "" {
  312. c.Data["json"] = c.ResultError("新模型名称不能为空!")
  313. c.ServeJSON()
  314. return
  315. }
  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. err, newid := obj.Copy(new_name)
  321. if err != nil {
  322. c.Data["json"] = c.ResultError(err.Error())
  323. c.ServeJSON()
  324. return
  325. }
  326. c.Data["json"] = c.ResultOK(newid, 0)
  327. c.ServeJSON()
  328. }
  329. // @Summary 删除指定的检测模型
  330. // @Description 删除指定的检测模型
  331. // @Tags 业务管理服务
  332. // @Accept x-www-form-urlencoded
  333. // @Produce json
  334. // @Param id formData int true "模型ID"
  335. // @Success 200 {object} ResultOK 成功
  336. // @Failure 500 {object} ResultError 失败
  337. // @router /admin/sysmodel/delete [post]
  338. func (c *BusAdminController) DeleteSysModelByID() {
  339. id, _ := c.GetInt("id")
  340. if id == 0 {
  341. c.Data["json"] = c.ResultError("id不能为空!")
  342. c.ServeJSON()
  343. return
  344. }
  345. obj := new(bo.SysCheckModelMgr)
  346. obj.SetUserInfo(c.GetCurrentUserInfo())
  347. obj.Model = bo.T_data_model_defualt{Id: id}
  348. obj.Model.Id = id
  349. err := obj.Delete()
  350. if err != nil {
  351. c.Data["json"] = c.ResultError(err.Error())
  352. c.ServeJSON()
  353. return
  354. }
  355. c.Data["json"] = c.ResultOK("", 0)
  356. c.ServeJSON()
  357. }
  358. // @Summary 查询检测模型列表
  359. // @Description 查询检测模型列表。支持名称、电压等级等过滤条件
  360. // @Tags 检测任务服务接口
  361. // @Accept x-www-form-urlencoded
  362. // @Produce json
  363. // @Param pageno query int true "当前页码。默认为1"
  364. // @Param pagesize query int true "每页显示数据数。默认为20"
  365. // @Param id query int false "ID"
  366. // @Param vol_id query int false "电压等级ID"
  367. // @Param model_name query string false "名称"
  368. // @Param line_link_style query int false "接线方式"
  369. // @Param area_type query int false "间隔类型"
  370. // @Param is_sys query int false "模型类型。1 内置模型 2 自定义模型"
  371. // @Success 200 {object} ResultOK 成功
  372. // @Failure 500 {object} ResultError 失败
  373. // @router /admin/sysmodel/list [get]
  374. func (c *BusAdminController) GetSysModelList() {
  375. obj := new(bo.SysCheckModelMgr)
  376. obj.SetUserInfo(c.GetCurrentUserInfo())
  377. obj.Model = bo.T_data_model_defualt{}
  378. obj.Model.Id, _ = c.GetInt("id")
  379. obj.Model.IsSys, _ = c.GetInt("is_sys")
  380. obj.Model.VolId, _ = c.GetInt("vol_id")
  381. obj.Model.ModelName = c.GetString("model_name")
  382. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  383. obj.Model.AreaType, _ = c.GetInt("area_type")
  384. pi, _ := c.GetInt("pagesize", 20)
  385. po, _ := c.GetInt("pageno", 0)
  386. if po == 0 {
  387. po, _ = c.GetInt("pageindex", 0)
  388. }
  389. if po == 0 {
  390. po = 1
  391. }
  392. lst, cnt, err := obj.List(po, pi)
  393. if err != nil {
  394. c.Data["json"] = c.ResultError(err.Error())
  395. c.ServeJSON()
  396. return
  397. }
  398. c.Data["json"] = c.ResultOK(lst, cnt)
  399. c.ServeJSON()
  400. }
  401. // @Summary 重新分析指定的SCD检测模型间隔
  402. // @Description 重新分析指定的SCD检测模型间隔
  403. // @Tags 业务管理服务
  404. // @Accept x-www-form-urlencoded
  405. // @Produce json
  406. // @Param scd_id formData int true "SCD文件ID"
  407. // @Success 200 {object} ResultOK 成功
  408. // @Failure 500 {object} ResultError 失败
  409. // @router /admin/parse/check_area [post]
  410. func (c *BusAdminController) ResetCheckAreaByID() {
  411. id, _ := c.GetInt64("scd_id")
  412. if id == 0 {
  413. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  414. c.ServeJSON()
  415. return
  416. }
  417. obj := new(bo.CheckAreaMgr)
  418. obj.SetUserInfo(c.GetCurrentUserInfo())
  419. obj.ScdId = id
  420. err := obj.Reset()
  421. if err != nil {
  422. c.Data["json"] = c.ResultError(err.Error())
  423. c.ServeJSON()
  424. return
  425. }
  426. c.Data["json"] = c.ResultOK("", 0)
  427. c.ServeJSON()
  428. }
  429. // @Summary 查询指定电压等级及接线方式下的检测间隔分析结果
  430. // @Description 查询指定电压等级及接线方式下的检测间隔分析结果
  431. // @Tags 业务管理服务
  432. // @Accept x-www-form-urlencoded
  433. // @Produce json
  434. // @Param scd_id formData int true "SCD文件ID"
  435. // @Param vol_id formData int false "电压等级ID"
  436. // @Param link_style_id formData int false "接线方式ID"
  437. // @Success 200 {object} ResultOK 成功
  438. // @Failure 500 {object} ResultError 失败
  439. // @router /admin/get/check_area [get]
  440. func (c *BusAdminController) GetCheckAreaByVolID() {
  441. id, _ := c.GetInt64("scd_id")
  442. if id == 0 {
  443. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  444. c.ServeJSON()
  445. return
  446. }
  447. volid, _ := c.GetInt("vol_id")
  448. lsid, _ := c.GetInt("link_style_id")
  449. obj := new(bo.CheckAreaMgr)
  450. obj.SetUserInfo(c.GetCurrentUserInfo())
  451. obj.ScdId = id
  452. lst, err := obj.GetAreaListByVol(id, volid, lsid)
  453. if err != nil {
  454. c.Data["json"] = c.ResultError(err.Error())
  455. c.ServeJSON()
  456. return
  457. }
  458. if lst == nil || len(lst) == 0 {
  459. //新分析
  460. err = obj.Reset()
  461. if err != nil {
  462. c.Data["json"] = c.ResultError(err.Error())
  463. c.ServeJSON()
  464. return
  465. }
  466. lst, _ = obj.GetAreaListByVol(id, volid, lsid)
  467. }
  468. c.Data["json"] = c.ResultOK(lst, 0)
  469. c.ServeJSON()
  470. }
  471. // @Summary 查询指定检测间隔下的IED装置列表
  472. // @Description 查询指定检测间隔下的IED装置列表
  473. // @Tags 业务管理服务
  474. // @Accept x-www-form-urlencoded
  475. // @Produce json
  476. // @Param scd_id formData int true "SCD文件ID"
  477. // @Param area_id formData int true "检测间隔ID"
  478. // @Success 200 {object} ResultOK 成功
  479. // @Failure 500 {object} ResultError 失败
  480. // @router /admin/get/check_area/ied [get]
  481. func (c *BusAdminController) GetCheckAreaIedByAreaID() {
  482. id, _ := c.GetInt64("scd_id")
  483. if id == 0 {
  484. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  485. c.ServeJSON()
  486. return
  487. }
  488. area_id, _ := c.GetInt("area_id")
  489. obj := new(bo.CheckAreaMgr)
  490. obj.SetUserInfo(c.GetCurrentUserInfo())
  491. obj.ScdId = id
  492. lst, err := obj.GetIedList(id, area_id)
  493. if err != nil {
  494. c.Data["json"] = c.ResultError(err.Error())
  495. c.ServeJSON()
  496. return
  497. }
  498. c.Data["json"] = c.ResultOK(lst, 0)
  499. c.ServeJSON()
  500. }
  501. // @Summary 修改并保存指定检测间隔下的IED装置列表
  502. // @Description 修改并保存指定检测间隔下的IED装置列表
  503. // @Tags 业务管理服务
  504. // @Accept x-www-form-urlencoded
  505. // @Produce json
  506. // @Param scd_id formData int true "SCD文件ID"
  507. // @Param area_id formData int true "检测间隔ID"
  508. // @Param ied_ids formData string true "IED装置name列表,多个ied采用逗号分隔。如:PT1001,PL1001,..."
  509. // @Success 200 {object} ResultOK 成功
  510. // @Failure 500 {object} ResultError 失败
  511. // @router /admin/update/check_area/ied [post]
  512. func (c *BusAdminController) SaveCheckAreaIedByAreaID() {
  513. id, _ := c.GetInt64("scd_id")
  514. if id == 0 {
  515. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  516. c.ServeJSON()
  517. return
  518. }
  519. area_id, _ := c.GetInt("area_id")
  520. ieds := c.GetString("ied_ids")
  521. if area_id == 0 {
  522. c.Data["json"] = c.ResultError("检测间隔ID不能为空!")
  523. c.ServeJSON()
  524. return
  525. }
  526. if ieds == "" {
  527. c.Data["json"] = c.ResultError("检测间隔装置列表不能为空!")
  528. c.ServeJSON()
  529. return
  530. }
  531. obj := new(bo.CheckAreaMgr)
  532. obj.SetUserInfo(c.GetCurrentUserInfo())
  533. obj.ScdId = id
  534. err := obj.UpdateIeds(id, area_id, ieds)
  535. if err != nil {
  536. c.Data["json"] = c.ResultError(err.Error())
  537. c.ServeJSON()
  538. return
  539. }
  540. c.Data["json"] = c.ResultOK("", 0)
  541. c.ServeJSON()
  542. }
  543. // @Summary 获取指定模型和装置类型的功能列表
  544. // @Description 获取指定模型和装置类型的功能列表
  545. // @Tags 业务管理服务
  546. // @Accept x-www-form-urlencoded
  547. // @Produce json
  548. // @Param model_id formData int true "模型ID"
  549. // @Param ied_type formData string true "装置类型"
  550. // @Success 200 {object} ResultOK 成功
  551. // @Failure 500 {object} ResultError 失败
  552. // @router /admin/model/function/list [get]
  553. func (c *BusAdminController) GetFuncListByIedType() {
  554. modelid, _ := c.GetInt("model_id")
  555. if modelid == 0 {
  556. c.Data["json"] = c.ResultError("模型ID不能为空!")
  557. c.ServeJSON()
  558. return
  559. }
  560. ied_type := c.GetString("ied_type")
  561. if ied_type == "" {
  562. c.Data["json"] = c.ResultError("装置类型不能为空!")
  563. c.ServeJSON()
  564. return
  565. }
  566. obj := new(bo.SysCheckModelIedFuncMgr)
  567. obj.SetUserInfo(c.GetCurrentUserInfo())
  568. lst, err := obj.GetList(modelid, ied_type)
  569. if err != nil {
  570. c.Data["json"] = c.ResultError(err.Error())
  571. c.ServeJSON()
  572. return
  573. }
  574. c.Data["json"] = c.ResultOK(lst, 0)
  575. c.ServeJSON()
  576. }
  577. // @Summary 获取指定模型和装置类型的端子列表
  578. // @Description 获取指定模型和装置类型的端子列表
  579. // @Tags 业务管理服务
  580. // @Accept x-www-form-urlencoded
  581. // @Produce json
  582. // @Param model_id formData int true "模型ID"
  583. // @Param ied_type formData string true "装置类型"
  584. // @Success 200 {object} ResultOK 成功
  585. // @Failure 500 {object} ResultError 失败
  586. // @router /admin/model/function/fcda/list [get]
  587. func (c *BusAdminController) GetFuncFcdaList() {
  588. modelid, _ := c.GetInt("model_id")
  589. if modelid == 0 {
  590. c.Data["json"] = c.ResultError("模型ID不能为空!")
  591. c.ServeJSON()
  592. return
  593. }
  594. ied_type := c.GetString("ied_type")
  595. if ied_type == "" {
  596. c.Data["json"] = c.ResultError("装置类型不能为空!")
  597. c.ServeJSON()
  598. return
  599. }
  600. obj := new(bo.SysCheckModelIedFuncMgr)
  601. obj.SetUserInfo(c.GetCurrentUserInfo())
  602. lst, err := obj.GetList(modelid, ied_type)
  603. if err != nil {
  604. c.Data["json"] = c.ResultError(err.Error())
  605. c.ServeJSON()
  606. return
  607. }
  608. fcdaList := []interface{}{}
  609. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  610. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  611. fcdaMgr.Model.ModelId = modelid
  612. for _, row := range lst {
  613. fcdaMgr.Model.FuncId, _ = strconv.Atoi(tools.IsEmpty(row["id"]))
  614. tmpLst, err := fcdaMgr.GetList()
  615. if err != nil {
  616. c.Data["json"] = c.ResultError(err.Error())
  617. c.ServeJSON()
  618. return
  619. }
  620. for _, r := range tmpLst {
  621. fcdaList = append(fcdaList, r)
  622. }
  623. }
  624. c.Data["json"] = c.ResultOK(fcdaList, 0)
  625. c.ServeJSON()
  626. }
  627. // @Summary 保存模型装置功能及端子信息
  628. // @Description 保存装置功能及端子信息
  629. // @Tags 业务管理服务
  630. // @Accept x-www-form-urlencoded
  631. // @Produce json
  632. // @Param model_id formData int true "模型ID"
  633. // @Param ied_type formData string true "装置类型代码"
  634. // @Param func_id formData int false "功能ID。编辑时必传。"
  635. // @Param func_name formData string true "功能名称。必传。"
  636. // @Param fcda_id formData int false "端子ID。编辑时必传。"
  637. // @Param fcda_name formData string true "功能名称。必传。"
  638. // @Param fcda_match_exp formData string true "端子匹配表达式。必传。"
  639. // @Success 200 {object} ResultOK 成功
  640. // @Failure 500 {object} ResultError 失败
  641. // @router /admin/model/function/fcda/save [post]
  642. func (c *BusAdminController) SaveFuncFcda() {
  643. modelid, _ := c.GetInt("model_id")
  644. if modelid == 0 {
  645. c.Data["json"] = c.ResultError("模型ID不能为空!")
  646. c.ServeJSON()
  647. return
  648. }
  649. ied_type := c.GetString("ied_type")
  650. func_name := c.GetString("func_name")
  651. fcda_name := c.GetString("fcda_name")
  652. fcda_match_exp := c.GetString("fcda_match_exp")
  653. func_id, _ := c.GetInt("func_id")
  654. fcda_id, _ := c.GetInt("fcda_id")
  655. if func_name == "" {
  656. c.Data["json"] = c.ResultError("功能名称不能为空!")
  657. c.ServeJSON()
  658. return
  659. }
  660. if fcda_name == "" {
  661. c.Data["json"] = c.ResultError("端子设计名称不能为空!")
  662. c.ServeJSON()
  663. return
  664. }
  665. if fcda_match_exp == "" {
  666. c.Data["json"] = c.ResultError("端子匹配关键词不能为空!")
  667. c.ServeJSON()
  668. return
  669. }
  670. mod := bo.T_data_model_func_def{}
  671. mod.Id = func_id
  672. mod.ModelId = modelid
  673. mod.IedType = ied_type
  674. mod.FuncFcdaId = fcda_id
  675. mod.FuncName = func_name
  676. mod.FcdaName = fcda_name
  677. mod.FcdaMatchExp = fcda_match_exp
  678. mgr := new(bo.SysCheckModelIedFuncMgr)
  679. mgr.SetUserInfo(c.GetCurrentUserInfo())
  680. err := mgr.Save()
  681. if err != nil {
  682. c.Data["json"] = c.ResultError(err.Error())
  683. c.ServeJSON()
  684. return
  685. }
  686. c.Data["json"] = c.ResultOK("", 0)
  687. c.ServeJSON()
  688. }
  689. // @Summary 删除装置端子
  690. // @Description 删除装置端子
  691. // @Tags 业务管理服务
  692. // @Accept x-www-form-urlencoded
  693. // @Produce json
  694. // @Param model_id formData int true "模型ID"
  695. // @Param fcda_id formData int true "端子ID"
  696. // @Success 200 {object} ResultOK 成功
  697. // @Failure 500 {object} ResultError 失败
  698. // @router /admin/model/function/fcda/del [post]
  699. func (c *BusAdminController) DelFuncFcda() {
  700. modelid, _ := c.GetInt("model_id")
  701. if modelid == 0 {
  702. c.Data["json"] = c.ResultError("模型ID不能为空!")
  703. c.ServeJSON()
  704. return
  705. }
  706. fcda_id, _ := c.GetInt("fcda_id")
  707. if fcda_id == 0 {
  708. c.Data["json"] = c.ResultError("端子ID不能为空!")
  709. c.ServeJSON()
  710. return
  711. }
  712. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  713. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  714. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  715. fcdaMgr.Model.ModelId = modelid
  716. fcdaMgr.Model.Id = fcda_id
  717. err := fcdaMgr.Delete()
  718. if err != nil {
  719. c.Data["json"] = c.ResultError(err.Error())
  720. c.ServeJSON()
  721. return
  722. }
  723. c.Data["json"] = c.ResultOK("", 0)
  724. c.ServeJSON()
  725. }
  726. // @Summary 获取模型装置端子已关联的接收端子
  727. // @Description 获取模型装置端子已关联的接收端子
  728. // @Tags 业务管理服务
  729. // @Accept x-www-form-urlencoded
  730. // @Produce json
  731. // @Param model_id formData int true "模型ID"
  732. // @Param from_fcda_id formData int true "输出装置端子ID"
  733. // @Success 200 {object} ResultOK 成功
  734. // @Failure 500 {object} ResultError 失败
  735. // @router /admin/model/function/fcda-ref/list [get]
  736. func (c *BusAdminController) GetFuncFcdaRef() {
  737. modelid, _ := c.GetInt("model_id")
  738. if modelid == 0 {
  739. c.Data["json"] = c.ResultError("模型ID不能为空!")
  740. c.ServeJSON()
  741. return
  742. }
  743. fcda_id, _ := c.GetInt("from_fcda_id")
  744. if fcda_id == 0 {
  745. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  746. c.ServeJSON()
  747. return
  748. }
  749. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  750. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  751. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  752. fcdaMgr.Model.ModelId = modelid
  753. fcdaMgr.Model.FromFcdaId = fcda_id
  754. lst, err := fcdaMgr.GetList()
  755. if err != nil {
  756. c.Data["json"] = c.ResultError(err.Error())
  757. c.ServeJSON()
  758. return
  759. }
  760. c.Data["json"] = c.ResultOK(lst, len(lst))
  761. c.ServeJSON()
  762. }
  763. // @Summary 保存模型装置端子间关联关系
  764. // @Description 保存模型装置端子间关联关系
  765. // @Tags 业务管理服务
  766. // @Accept x-www-form-urlencoded
  767. // @Produce json
  768. // @Param model_id formData int true "模型ID"
  769. // @Param from_ied_type formData string true "输出装置类型"
  770. // @Param to_ied_type formData string true "输入装置类型"
  771. // @Param from_fcda_id formData int true "输出装置端子ID"
  772. // @Param to_fcda_ids formData string true "输入装置端子ID列表。多个ID间使用逗号分隔"
  773. // @Param goosesv formData string true "信号类型。值范围:GOOSE|SV"
  774. // @Success 200 {object} ResultOK 成功
  775. // @Failure 500 {object} ResultError 失败
  776. // @router /admin/model/function/fcda-ref/save [post]
  777. func (c *BusAdminController) SaveFuncFcdaRef() {
  778. modelid, _ := c.GetInt("model_id")
  779. if modelid == 0 {
  780. c.Data["json"] = c.ResultError("模型ID不能为空!")
  781. c.ServeJSON()
  782. return
  783. }
  784. fcda_id, _ := c.GetInt("from_fcda_id")
  785. if fcda_id == 0 {
  786. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  787. c.ServeJSON()
  788. return
  789. }
  790. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  791. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  792. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  793. fcdaMgr.Model.ModelId = modelid
  794. fcdaMgr.Model.FromFcdaId = fcda_id
  795. fcdaMgr.Model.FromIedCode = c.GetString("from_ied_type")
  796. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  797. fcdaMgr.Model.Goosesv = strings.ToUpper(c.GetString("goosesv"))
  798. if fcdaMgr.Model.FromIedCode == "" || fcdaMgr.Model.ToIedCode == "" {
  799. c.Data["json"] = c.ResultError("输入和输出装置类型不能为空!")
  800. c.ServeJSON()
  801. return
  802. }
  803. if fcdaMgr.Model.Goosesv == "" {
  804. c.Data["json"] = c.ResultError("信号类型不能为空!")
  805. c.ServeJSON()
  806. return
  807. }
  808. if fcdaMgr.Model.Goosesv != "GOOSE" && fcdaMgr.Model.Goosesv != "SV" {
  809. c.Data["json"] = c.ResultError("信号类型不正确。只能为GOOSE或SV")
  810. c.ServeJSON()
  811. return
  812. }
  813. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  814. fcdainf, er := obj.One(fcdaMgr.Model.FromFcdaId)
  815. if er != nil {
  816. c.Data["json"] = c.ResultError(er.Error())
  817. c.ServeJSON()
  818. return
  819. }
  820. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  821. fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId)
  822. if er != nil {
  823. c.Data["json"] = c.ResultError(er.Error())
  824. c.ServeJSON()
  825. return
  826. }
  827. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  828. err := fcdaMgr.Save()
  829. if err != nil {
  830. c.Data["json"] = c.ResultError(err.Error())
  831. c.ServeJSON()
  832. return
  833. }
  834. c.Data["json"] = c.ResultOK("", 0)
  835. c.ServeJSON()
  836. }