busAdminController.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  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. obj := new(bo.SysCheckModelMgr)
  312. obj.SetUserInfo(c.GetCurrentUserInfo())
  313. obj.Model = bo.T_data_model_defualt{Id: id}
  314. obj.Model.Id = id
  315. obj.Model.ModelName = new_name
  316. err, newid := obj.Copy(id)
  317. if err != nil {
  318. c.Data["json"] = c.ResultError(err.Error())
  319. c.ServeJSON()
  320. return
  321. }
  322. c.Data["json"] = c.ResultOK(newid, 0)
  323. c.ServeJSON()
  324. }
  325. // @Summary 删除指定的检测模型
  326. // @Description 删除指定的检测模型
  327. // @Tags 业务管理服务
  328. // @Accept x-www-form-urlencoded
  329. // @Produce json
  330. // @Param id formData int true "模型ID"
  331. // @Success 200 {object} ResultOK 成功
  332. // @Failure 500 {object} ResultError 失败
  333. // @router /admin/sysmodel/delete [post]
  334. func (c *BusAdminController) DeleteSysModelByID() {
  335. id, _ := c.GetInt("id")
  336. if id == 0 {
  337. c.Data["json"] = c.ResultError("id不能为空!")
  338. c.ServeJSON()
  339. return
  340. }
  341. obj := new(bo.SysCheckModelMgr)
  342. obj.SetUserInfo(c.GetCurrentUserInfo())
  343. obj.Model = bo.T_data_model_defualt{Id: id}
  344. obj.Model.Id = id
  345. err := obj.Delete()
  346. if err != nil {
  347. c.Data["json"] = c.ResultError(err.Error())
  348. c.ServeJSON()
  349. return
  350. }
  351. c.Data["json"] = c.ResultOK("", 0)
  352. c.ServeJSON()
  353. }
  354. // @Summary 查询检测模型列表
  355. // @Description 查询检测模型列表。支持名称、电压等级等过滤条件
  356. // @Tags 检测任务服务接口
  357. // @Accept x-www-form-urlencoded
  358. // @Produce json
  359. // @Param pageno query int true "当前页码。默认为1"
  360. // @Param pagesize query int true "每页显示数据数。默认为20"
  361. // @Param id query int false "ID"
  362. // @Param vol_id query int false "电压等级ID"
  363. // @Param model_name query string false "名称"
  364. // @Param line_link_style query int false "接线方式"
  365. // @Param area_type query int false "间隔类型"
  366. // @Param is_sys query int false "模型类型。1 内置模型 2 自定义模型"
  367. // @Success 200 {object} ResultOK 成功
  368. // @Failure 500 {object} ResultError 失败
  369. // @router /admin/sysmodel/list [get]
  370. func (c *BusAdminController) GetSysModelList() {
  371. obj := new(bo.SysCheckModelMgr)
  372. obj.SetUserInfo(c.GetCurrentUserInfo())
  373. obj.Model = bo.T_data_model_defualt{}
  374. obj.Model.Id, _ = c.GetInt("id")
  375. obj.Model.IsSys, _ = c.GetInt("is_sys", 1) //默认查询系统内置模型
  376. obj.Model.VolId, _ = c.GetInt("vol_id")
  377. obj.Model.ModelName = c.GetString("model_name")
  378. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  379. obj.Model.AreaType, _ = c.GetInt("area_type")
  380. pi, _ := c.GetInt("pagesize", 20)
  381. po, _ := c.GetInt("pageno", 0)
  382. if po == 0 {
  383. po, _ = c.GetInt("pageindex", 0)
  384. }
  385. if po == 0 {
  386. po = 1
  387. }
  388. lst, cnt, err := obj.List(po, pi)
  389. if err != nil {
  390. c.Data["json"] = c.ResultError(err.Error())
  391. c.ServeJSON()
  392. return
  393. }
  394. c.Data["json"] = c.ResultOK(lst, cnt)
  395. c.ServeJSON()
  396. }
  397. // @Summary 重新分析指定的SCD检测模型间隔
  398. // @Description 重新分析指定的SCD检测模型间隔
  399. // @Tags 业务管理服务
  400. // @Accept x-www-form-urlencoded
  401. // @Produce json
  402. // @Param scd_id formData int true "SCD文件ID"
  403. // @Success 200 {object} ResultOK 成功
  404. // @Failure 500 {object} ResultError 失败
  405. // @router /admin/parse/check_area [post]
  406. func (c *BusAdminController) ResetCheckAreaByID() {
  407. id, _ := c.GetInt64("scd_id")
  408. if id == 0 {
  409. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  410. c.ServeJSON()
  411. return
  412. }
  413. obj := new(bo.CheckAreaMgr)
  414. obj.SetUserInfo(c.GetCurrentUserInfo())
  415. obj.ScdId = id
  416. err := obj.Reset()
  417. if err != nil {
  418. c.Data["json"] = c.ResultError(err.Error())
  419. c.ServeJSON()
  420. return
  421. }
  422. c.Data["json"] = c.ResultOK("", 0)
  423. c.ServeJSON()
  424. }
  425. // @Summary 查询指定电压等级及接线方式下的检测间隔分析结果
  426. // @Description 查询指定电压等级及接线方式下的检测间隔分析结果
  427. // @Tags 业务管理服务
  428. // @Accept x-www-form-urlencoded
  429. // @Produce json
  430. // @Param scd_id formData int true "SCD文件ID"
  431. // @Param vol_id formData int false "电压等级ID"
  432. // @Param link_style_id formData int false "接线方式ID"
  433. // @Success 200 {object} ResultOK 成功
  434. // @Failure 500 {object} ResultError 失败
  435. // @router /admin/get/check_area [get]
  436. func (c *BusAdminController) GetCheckAreaByVolID() {
  437. id, _ := c.GetInt64("scd_id")
  438. if id == 0 {
  439. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  440. c.ServeJSON()
  441. return
  442. }
  443. volid, _ := c.GetInt("vol_id")
  444. lsid, _ := c.GetInt("link_style_id")
  445. obj := new(bo.CheckAreaMgr)
  446. obj.SetUserInfo(c.GetCurrentUserInfo())
  447. obj.ScdId = id
  448. lst, err := obj.GetAreaListByVol(id, volid, lsid)
  449. if err != nil {
  450. c.Data["json"] = c.ResultError(err.Error())
  451. c.ServeJSON()
  452. return
  453. }
  454. if lst == nil || len(lst) == 0 {
  455. //新分析
  456. err = obj.Reset()
  457. if err != nil {
  458. c.Data["json"] = c.ResultError(err.Error())
  459. c.ServeJSON()
  460. return
  461. }
  462. lst, _ = obj.GetAreaListByVol(id, volid, lsid)
  463. }
  464. c.Data["json"] = c.ResultOK(lst, 0)
  465. c.ServeJSON()
  466. }
  467. // @Summary 查询指定检测间隔下的IED装置列表
  468. // @Description 查询指定检测间隔下的IED装置列表
  469. // @Tags 业务管理服务
  470. // @Accept x-www-form-urlencoded
  471. // @Produce json
  472. // @Param scd_id formData int true "SCD文件ID"
  473. // @Param area_id formData int true "检测间隔ID"
  474. // @Success 200 {object} ResultOK 成功
  475. // @Failure 500 {object} ResultError 失败
  476. // @router /admin/get/check_area/ied [get]
  477. func (c *BusAdminController) GetCheckAreaIedByAreaID() {
  478. id, _ := c.GetInt64("scd_id")
  479. if id == 0 {
  480. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  481. c.ServeJSON()
  482. return
  483. }
  484. area_id, _ := c.GetInt("area_id")
  485. obj := new(bo.CheckAreaMgr)
  486. obj.SetUserInfo(c.GetCurrentUserInfo())
  487. obj.ScdId = id
  488. lst, err := obj.GetIedList(id, area_id)
  489. if err != nil {
  490. c.Data["json"] = c.ResultError(err.Error())
  491. c.ServeJSON()
  492. return
  493. }
  494. c.Data["json"] = c.ResultOK(lst, 0)
  495. c.ServeJSON()
  496. }
  497. // @Summary 修改并保存指定检测间隔下的IED装置列表
  498. // @Description 修改并保存指定检测间隔下的IED装置列表
  499. // @Tags 业务管理服务
  500. // @Accept x-www-form-urlencoded
  501. // @Produce json
  502. // @Param scd_id formData int true "SCD文件ID"
  503. // @Param area_id formData int true "检测间隔ID"
  504. // @Param ied_ids formData string true "IED装置name列表,多个ied采用逗号分隔。如:PT1001,PL1001,..."
  505. // @Success 200 {object} ResultOK 成功
  506. // @Failure 500 {object} ResultError 失败
  507. // @router /admin/update/check_area/ied [post]
  508. func (c *BusAdminController) SaveCheckAreaIedByAreaID() {
  509. id, _ := c.GetInt64("scd_id")
  510. if id == 0 {
  511. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  512. c.ServeJSON()
  513. return
  514. }
  515. area_id, _ := c.GetInt("area_id")
  516. ieds := c.GetString("ied_ids")
  517. if area_id == 0 {
  518. c.Data["json"] = c.ResultError("检测间隔ID不能为空!")
  519. c.ServeJSON()
  520. return
  521. }
  522. if ieds == "" {
  523. c.Data["json"] = c.ResultError("检测间隔装置列表不能为空!")
  524. c.ServeJSON()
  525. return
  526. }
  527. obj := new(bo.CheckAreaMgr)
  528. obj.SetUserInfo(c.GetCurrentUserInfo())
  529. obj.ScdId = id
  530. err := obj.UpdateIeds(id, area_id, ieds)
  531. if err != nil {
  532. c.Data["json"] = c.ResultError(err.Error())
  533. c.ServeJSON()
  534. return
  535. }
  536. c.Data["json"] = c.ResultOK("", 0)
  537. c.ServeJSON()
  538. }
  539. // @Summary 获取指定模型和装置类型的功能列表
  540. // @Description 获取指定模型和装置类型的功能列表
  541. // @Tags 业务管理服务
  542. // @Accept x-www-form-urlencoded
  543. // @Produce json
  544. // @Param model_id formData int true "模型ID"
  545. // @Param ied_type formData string true "装置类型"
  546. // @Success 200 {object} ResultOK 成功
  547. // @Failure 500 {object} ResultError 失败
  548. // @router /admin/model/function/list [get]
  549. func (c *BusAdminController) GetFuncListByIedType() {
  550. modelid, _ := c.GetInt("model_id")
  551. if modelid == 0 {
  552. c.Data["json"] = c.ResultError("模型ID不能为空!")
  553. c.ServeJSON()
  554. return
  555. }
  556. ied_type := c.GetString("ied_type")
  557. if ied_type == "" {
  558. c.Data["json"] = c.ResultError("装置类型不能为空!")
  559. c.ServeJSON()
  560. return
  561. }
  562. obj := new(bo.SysCheckModelIedFuncMgr)
  563. obj.SetUserInfo(c.GetCurrentUserInfo())
  564. lst, err := obj.GetList(modelid, ied_type)
  565. if err != nil {
  566. c.Data["json"] = c.ResultError(err.Error())
  567. c.ServeJSON()
  568. return
  569. }
  570. c.Data["json"] = c.ResultOK(lst, 0)
  571. c.ServeJSON()
  572. }
  573. // @Summary 获取指定模型和装置类型的端子列表
  574. // @Description 获取指定模型和装置类型的端子列表
  575. // @Tags 业务管理服务
  576. // @Accept x-www-form-urlencoded
  577. // @Produce json
  578. // @Param model_id formData int true "模型ID"
  579. // @Param ied_type formData string true "装置类型"
  580. // @Success 200 {object} ResultOK 成功
  581. // @Failure 500 {object} ResultError 失败
  582. // @router /admin/model/function/fcda/list [get]
  583. func (c *BusAdminController) GetFuncFcdaList() {
  584. modelid, _ := c.GetInt("model_id")
  585. if modelid == 0 {
  586. c.Data["json"] = c.ResultError("模型ID不能为空!")
  587. c.ServeJSON()
  588. return
  589. }
  590. ied_type := c.GetString("ied_type")
  591. if ied_type == "" {
  592. c.Data["json"] = c.ResultError("装置类型不能为空!")
  593. c.ServeJSON()
  594. return
  595. }
  596. obj := new(bo.SysCheckModelIedFuncMgr)
  597. obj.SetUserInfo(c.GetCurrentUserInfo())
  598. lst, err := obj.GetList(modelid, ied_type)
  599. if err != nil {
  600. c.Data["json"] = c.ResultError(err.Error())
  601. c.ServeJSON()
  602. return
  603. }
  604. fcdaList := []interface{}{}
  605. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  606. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  607. fcdaMgr.Model.ModelId = modelid
  608. for _, row := range lst {
  609. fcdaMgr.Model.FuncId, _ = strconv.Atoi(tools.IsEmpty(row["id"]))
  610. tmpLst, err := fcdaMgr.GetList()
  611. if err != nil {
  612. c.Data["json"] = c.ResultError(err.Error())
  613. c.ServeJSON()
  614. return
  615. }
  616. for _, r := range tmpLst {
  617. fcdaList = append(fcdaList, r)
  618. }
  619. }
  620. c.Data["json"] = c.ResultOK(fcdaList, 0)
  621. c.ServeJSON()
  622. }
  623. // @Summary 保存模型装置功能及端子信息
  624. // @Description 保存装置功能及端子信息
  625. // @Tags 业务管理服务
  626. // @Accept x-www-form-urlencoded
  627. // @Produce json
  628. // @Param model_id formData int true "模型ID"
  629. // @Param ied_type formData string true "装置类型代码"
  630. // @Param func_id formData int false "功能ID。编辑时必传。"
  631. // @Param func_name formData string true "功能名称。必传。"
  632. // @Param fcda_id formData int false "端子ID。编辑时必传。"
  633. // @Param fcda_name formData string true "端子名称。必传。"
  634. // @Param fcda_match_exp formData string true "端子匹配表达式。必传。"
  635. // @Success 200 {object} ResultOK 成功
  636. // @Failure 500 {object} ResultError 失败
  637. // @router /admin/model/function/fcda/save [post]
  638. func (c *BusAdminController) SaveFuncFcda() {
  639. modelid, _ := c.GetInt("model_id")
  640. if modelid == 0 {
  641. c.Data["json"] = c.ResultError("模型ID不能为空!")
  642. c.ServeJSON()
  643. return
  644. }
  645. ied_type := c.GetString("ied_type")
  646. func_name := c.GetString("func_name")
  647. fcda_name := c.GetString("fcda_name")
  648. fcda_match_exp := c.GetString("fcda_match_exp")
  649. func_id, _ := c.GetInt("func_id")
  650. fcda_id, _ := c.GetInt("fcda_id")
  651. if func_name == "" {
  652. c.Data["json"] = c.ResultError("功能名称不能为空!")
  653. c.ServeJSON()
  654. return
  655. }
  656. if fcda_name == "" {
  657. c.Data["json"] = c.ResultError("端子设计名称不能为空!")
  658. c.ServeJSON()
  659. return
  660. }
  661. if fcda_match_exp == "" {
  662. c.Data["json"] = c.ResultError("端子匹配关键词不能为空!")
  663. c.ServeJSON()
  664. return
  665. }
  666. mod := bo.T_data_model_func_def{}
  667. mod.Id = func_id
  668. mod.ModelId = modelid
  669. mod.IedType = ied_type
  670. mod.FuncFcdaId = fcda_id
  671. mod.FuncName = func_name
  672. mod.FcdaName = fcda_name
  673. mod.FcdaMatchExp = fcda_match_exp
  674. mgr := new(bo.SysCheckModelIedFuncMgr)
  675. mgr.SetUserInfo(c.GetCurrentUserInfo())
  676. mgr.Model = mod
  677. err := mgr.Save()
  678. if err != nil {
  679. c.Data["json"] = c.ResultError(err.Error())
  680. c.ServeJSON()
  681. return
  682. }
  683. c.Data["json"] = c.ResultOK("", 0)
  684. c.ServeJSON()
  685. }
  686. // @Summary 删除装置端子
  687. // @Description 删除装置端子
  688. // @Tags 业务管理服务
  689. // @Accept x-www-form-urlencoded
  690. // @Produce json
  691. // @Param model_id formData int true "模型ID"
  692. // @Param fcda_id formData int true "端子ID"
  693. // @Success 200 {object} ResultOK 成功
  694. // @Failure 500 {object} ResultError 失败
  695. // @router /admin/model/function/fcda/del [post]
  696. func (c *BusAdminController) DelFuncFcda() {
  697. modelid, _ := c.GetInt("model_id")
  698. if modelid == 0 {
  699. c.Data["json"] = c.ResultError("模型ID不能为空!")
  700. c.ServeJSON()
  701. return
  702. }
  703. fcda_id, _ := c.GetInt("fcda_id")
  704. if fcda_id == 0 {
  705. c.Data["json"] = c.ResultError("端子ID不能为空!")
  706. c.ServeJSON()
  707. return
  708. }
  709. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  710. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  711. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  712. fcdaMgr.Model.ModelId = modelid
  713. fcdaMgr.Model.Id = fcda_id
  714. err := fcdaMgr.Delete()
  715. if err != nil {
  716. c.Data["json"] = c.ResultError(err.Error())
  717. c.ServeJSON()
  718. return
  719. }
  720. c.Data["json"] = c.ResultOK("", 0)
  721. c.ServeJSON()
  722. }
  723. // @Summary 获取模型装置端子已关联的接收端子
  724. // @Description 获取模型装置端子已关联的接收端子
  725. // @Tags 业务管理服务
  726. // @Accept x-www-form-urlencoded
  727. // @Produce json
  728. // @Param model_id formData int true "模型ID"
  729. // @Param from_fcda_id formData int true "输出装置端子ID"
  730. // @Param to_ied_type formData string false "输入装置类型"
  731. // @Param goosesv formData string false "信号类型。GOOSE|SV"
  732. // @Success 200 {object} ResultOK 成功
  733. // @Failure 500 {object} ResultError 失败
  734. // @router /admin/model/function/fcda-ref/list [get]
  735. func (c *BusAdminController) GetFuncFcdaRef() {
  736. modelid, _ := c.GetInt("model_id")
  737. if modelid == 0 {
  738. c.Data["json"] = c.ResultError("模型ID不能为空!")
  739. c.ServeJSON()
  740. return
  741. }
  742. fcda_id, _ := c.GetInt("from_fcda_id")
  743. if fcda_id == 0 {
  744. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  745. c.ServeJSON()
  746. return
  747. }
  748. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  749. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  750. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  751. fcdaMgr.Model.ModelId = modelid
  752. fcdaMgr.Model.FromFcdaId = fcda_id
  753. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  754. fcdaMgr.Model.Goosesv = c.GetString("goosesv")
  755. lst, err := fcdaMgr.GetList()
  756. if err != nil {
  757. c.Data["json"] = c.ResultError(err.Error())
  758. c.ServeJSON()
  759. return
  760. }
  761. c.Data["json"] = c.ResultOK(lst, len(lst))
  762. c.ServeJSON()
  763. }
  764. // @Summary 保存模型装置端子间关联关系
  765. // @Description 保存模型装置端子间关联关系
  766. // @Tags 业务管理服务
  767. // @Accept x-www-form-urlencoded
  768. // @Produce json
  769. // @Param model_id formData int true "模型ID"
  770. // @Param from_ied_type formData string true "输出装置类型"
  771. // @Param to_ied_type formData string true "输入装置类型"
  772. // @Param from_fcda_id formData int true "输出装置端子ID"
  773. // @Param to_fcda_ids formData string true "输入装置端子ID列表。多个ID间使用逗号分隔"
  774. // @Param goosesv formData string true "信号类型。值范围:GOOSE|SV"
  775. // @Success 200 {object} ResultOK 成功
  776. // @Failure 500 {object} ResultError 失败
  777. // @router /admin/model/function/fcda-ref/save [post]
  778. func (c *BusAdminController) SaveFuncFcdaRef() {
  779. modelid, _ := c.GetInt("model_id")
  780. if modelid == 0 {
  781. c.Data["json"] = c.ResultError("模型ID不能为空!")
  782. c.ServeJSON()
  783. return
  784. }
  785. fcda_id, _ := c.GetInt("from_fcda_id")
  786. if fcda_id == 0 {
  787. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  788. c.ServeJSON()
  789. return
  790. }
  791. fcda_in_ids := c.GetString("to_fcda_ids")
  792. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  793. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  794. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  795. fcdaMgr.Model.ModelId = modelid
  796. fcdaMgr.Model.FromFcdaId = fcda_id
  797. fcdaMgr.Model.FromIedCode = c.GetString("from_ied_type")
  798. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  799. fcdaMgr.Model.Goosesv = strings.ToUpper(c.GetString("goosesv"))
  800. if fcdaMgr.Model.FromIedCode == "" || fcdaMgr.Model.ToIedCode == "" {
  801. c.Data["json"] = c.ResultError("输入和输出装置类型不能为空!")
  802. c.ServeJSON()
  803. return
  804. }
  805. if fcdaMgr.Model.Goosesv == "" {
  806. c.Data["json"] = c.ResultError("信号类型不能为空!")
  807. c.ServeJSON()
  808. return
  809. }
  810. if fcdaMgr.Model.Goosesv != "GOOSE" && fcdaMgr.Model.Goosesv != "SV" {
  811. c.Data["json"] = c.ResultError("信号类型不正确。只能为GOOSE或SV")
  812. c.ServeJSON()
  813. return
  814. }
  815. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  816. fcdainf, er := obj.One(fcdaMgr.Model.FromFcdaId)
  817. if er != nil {
  818. c.Data["json"] = c.ResultError("无效的输出端子ID")
  819. c.ServeJSON()
  820. return
  821. }
  822. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  823. //清除原关系
  824. err := fcdaMgr.Delete()
  825. if err != nil {
  826. c.Data["json"] = c.ResultError(err.Error())
  827. c.ServeJSON()
  828. return
  829. }
  830. if fcda_in_ids != "" {
  831. fcda_in_ids_1 := strings.Split(fcda_in_ids, ",")
  832. for _, k := range fcda_in_ids_1 {
  833. fcdaMgr.Model.ToFcdaId, _ = strconv.Atoi(k)
  834. fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId)
  835. if er != nil {
  836. c.Data["json"] = c.ResultError("无效的输入端子ID")
  837. c.ServeJSON()
  838. return
  839. }
  840. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  841. err := fcdaMgr.Save()
  842. if err != nil {
  843. c.Data["json"] = c.ResultError(err.Error())
  844. c.ServeJSON()
  845. return
  846. }
  847. }
  848. }
  849. c.Data["json"] = c.ResultOK("", 0)
  850. c.ServeJSON()
  851. }