busAdminController.go 28 KB

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