busAdminController.go 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  1. /*
  2. * @Author: lilig
  3. * @Date: 2023-10-10 15:22:58
  4. * @LastEditors: lilifor
  5. * @LastEditTime: 2023-10-10 15:22:58
  6. * @FilePath: \SCD\controllers\TaskController.go
  7. * @Description:
  8. *
  9. * Copyright (c) 2023 by lilig/jujutong, All Rights Reserved.
  10. */
  11. package controllers
  12. import (
  13. "encoding/json"
  14. "fmt"
  15. "scd_check_tools/models/bo"
  16. "scd_check_tools/tools"
  17. "strconv"
  18. "strings"
  19. "github.com/astaxie/beego/orm"
  20. )
  21. //业务管理服务
  22. type BusAdminController struct {
  23. BaseController
  24. }
  25. func init() {
  26. }
  27. // @Summary 创建新的接线方式
  28. // @Description 创建新的接线方式
  29. // @Tags 业务管理服务
  30. // @Accept x-www-form-urlencoded
  31. // @Produce json
  32. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  33. // @Param name formData string true "任务名称"
  34. // @Param vol_id formData int true "电压等级ID"
  35. // @Param pic formData string false "接线图地址"
  36. // @Success 200 {object} ResultOK 成功
  37. // @Failure 500 {object} ResultError 失败
  38. // @router /admin/linkstyle/save [post]
  39. func (c *BusAdminController) SaveLinkStyleInfo() {
  40. id, _ := c.GetInt("id")
  41. obj := new(bo.LinkStyleMgr)
  42. obj.SetUserInfo(c.GetCurrentUserInfo())
  43. obj.Model = bo.T_data_link_style{Id: id}
  44. obj.Model.Name = c.GetString("name")
  45. obj.Model.VolLevelId, _ = c.GetInt("vol_id")
  46. obj.Model.Pic = c.GetString("pic")
  47. if obj.Model.Name == "" {
  48. c.Data["json"] = c.ResultError("名称不能为空")
  49. c.ServeJSON()
  50. return
  51. }
  52. if obj.Model.VolLevelId == 0 {
  53. c.Data["json"] = c.ResultError("电压等级不能为空")
  54. c.ServeJSON()
  55. return
  56. }
  57. err := obj.Save()
  58. if err != nil {
  59. c.Data["json"] = c.ResultError(err.Error())
  60. c.ServeJSON()
  61. return
  62. }
  63. c.Data["json"] = c.ResultOK("", 0)
  64. c.ServeJSON()
  65. }
  66. // @Summary 删除指定的接线方式
  67. // @Description 删除指定的接线方式
  68. // @Tags 业务管理服务
  69. // @Accept x-www-form-urlencoded
  70. // @Produce json
  71. // @Param id formData int true "接线方式ID"
  72. // @Success 200 {object} ResultOK 成功
  73. // @Failure 500 {object} ResultError 失败
  74. // @router /admin/linkstyle/delete [post]
  75. func (c *BusAdminController) DeleteLinkStyleByID() {
  76. id, _ := c.GetInt("id")
  77. if id == 0 {
  78. c.Data["json"] = c.ResultError("id不能为空!")
  79. c.ServeJSON()
  80. return
  81. }
  82. obj := new(bo.LinkStyleMgr)
  83. obj.SetUserInfo(c.GetCurrentUserInfo())
  84. obj.Model = bo.T_data_link_style{}
  85. obj.Model.Id = id
  86. err := obj.Delete()
  87. if err != nil {
  88. c.Data["json"] = c.ResultError(err.Error())
  89. c.ServeJSON()
  90. return
  91. }
  92. c.Data["json"] = c.ResultOK("", 0)
  93. c.ServeJSON()
  94. }
  95. // @Summary 查询接线方式
  96. // @Description 查询接线方式。支持名称、电压等级等过滤条件
  97. // @Tags 检测任务服务接口
  98. // @Accept x-www-form-urlencoded
  99. // @Produce json
  100. // @Param pageno query int true "当前页码。默认为1"
  101. // @Param pagesize query int true "每页显示数据数。默认为20"
  102. // @Param id query int false "ID"
  103. // @Param vol_id query int false "电压ID"
  104. // @Param name query string false "名称"
  105. // @Success 200 {object} ResultOK 成功
  106. // @Failure 500 {object} ResultError 失败
  107. // @router /admin/linkstyle/list [get]
  108. func (c *BusAdminController) GetLinkStyleList() {
  109. obj := new(bo.LinkStyleMgr)
  110. obj.SetUserInfo(c.GetCurrentUserInfo())
  111. obj.Model = bo.T_data_link_style{}
  112. obj.Model.Id, _ = c.GetInt("id")
  113. obj.Model.VolLevelId, _ = c.GetInt("vol_id")
  114. obj.Model.Name = c.GetString("name")
  115. pi, _ := c.GetInt("pagesize", 20)
  116. po, _ := c.GetInt("pageno", 0)
  117. if po == 0 {
  118. po, _ = c.GetInt("pageindex", 0)
  119. }
  120. if po == 0 {
  121. po = 1
  122. }
  123. lst, cnt, err := obj.List(po, pi)
  124. if err != nil {
  125. c.Data["json"] = c.ResultError(err.Error())
  126. c.ServeJSON()
  127. return
  128. }
  129. c.Data["json"] = c.ResultOK(lst, cnt)
  130. c.ServeJSON()
  131. }
  132. // @Summary 添加接线方式的模型
  133. // @Description 添加接线方式的模型
  134. // @Tags 业务管理服务
  135. // @Accept x-www-form-urlencoded
  136. // @Produce json
  137. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  138. // @Param linkstyle_id formData int true "接线方式ID"
  139. // @Param model_id formData int true "内置模型id"
  140. // @Success 200 {object} ResultOK 成功
  141. // @Failure 500 {object} ResultError 失败
  142. // @router /admin/linkstyle-model/save [post]
  143. func (c *BusAdminController) SaveLinkStyleModelInfo() {
  144. id, _ := c.GetInt("id")
  145. obj := new(bo.LinkStyleModelMgr)
  146. obj.SetUserInfo(c.GetCurrentUserInfo())
  147. obj.Model = bo.T_data_link_style_model{Id: id}
  148. obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id")
  149. obj.Model.ModelId, _ = c.GetInt("model_id")
  150. if obj.Model.LinkstyleId == 0 {
  151. c.Data["json"] = c.ResultError("接线方式不能为空")
  152. c.ServeJSON()
  153. return
  154. }
  155. if obj.Model.ModelId == 0 {
  156. c.Data["json"] = c.ResultError("模型ID不能为空")
  157. c.ServeJSON()
  158. return
  159. }
  160. err := obj.Save()
  161. if err != nil {
  162. c.Data["json"] = c.ResultError(err.Error())
  163. c.ServeJSON()
  164. return
  165. }
  166. c.Data["json"] = c.ResultOK("", 0)
  167. c.ServeJSON()
  168. }
  169. // @Summary 删除指定接线方式下属的模型
  170. // @Description 删除指定接线方式下属的模型
  171. // @Tags 业务管理服务
  172. // @Accept x-www-form-urlencoded
  173. // @Produce json
  174. // @Param id formData int true "接线方式ID"
  175. // @Param model_id formData int true "模型ID"
  176. // @Success 200 {object} ResultOK 成功
  177. // @Failure 500 {object} ResultError 失败
  178. // @router /admin/linkstyle-model/delete [post]
  179. func (c *BusAdminController) DeleteLinkStyleModelByID() {
  180. id, _ := c.GetInt("id")
  181. if id == 0 {
  182. c.Data["json"] = c.ResultError("id不能为空!")
  183. c.ServeJSON()
  184. return
  185. }
  186. model_id, _ := c.GetInt("model_id")
  187. if model_id == 0 {
  188. c.Data["json"] = c.ResultError("模型id不能为空!")
  189. c.ServeJSON()
  190. return
  191. }
  192. obj := new(bo.LinkStyleModelMgr)
  193. obj.SetUserInfo(c.GetCurrentUserInfo())
  194. obj.Model = bo.T_data_link_style_model{}
  195. obj.Model.LinkstyleId = id
  196. obj.Model.Id = model_id
  197. err := obj.Delete()
  198. if err != nil {
  199. c.Data["json"] = c.ResultError(err.Error())
  200. c.ServeJSON()
  201. return
  202. }
  203. c.Data["json"] = c.ResultOK("", 0)
  204. c.ServeJSON()
  205. }
  206. // @Summary 查询接线方式下模型列表
  207. // @Description 查询接线方式下模型列表
  208. // @Tags 检测任务服务接口
  209. // @Accept x-www-form-urlencoded
  210. // @Produce json
  211. // @Param pageno query int true "当前页码。默认为1"
  212. // @Param pagesize query int true "每页显示数据数。默认为20"
  213. // @Param id query int false "ID"
  214. // @Param linkstyle_id query int false "接线方式ID"
  215. // @Success 200 {object} ResultOK 成功
  216. // @Failure 500 {object} ResultError 失败
  217. // @router /admin/linkstyle-model/list [get]
  218. func (c *BusAdminController) GetLinkStyleModelList() {
  219. obj := new(bo.LinkStyleModelMgr)
  220. obj.SetUserInfo(c.GetCurrentUserInfo())
  221. obj.Model = bo.T_data_link_style_model{}
  222. obj.Model.Id, _ = c.GetInt("id")
  223. obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id")
  224. pi, _ := c.GetInt("pagesize", 20)
  225. po, _ := c.GetInt("pageno", 0)
  226. if po == 0 {
  227. po, _ = c.GetInt("pageindex", 0)
  228. }
  229. if po == 0 {
  230. po = 1
  231. }
  232. lst, cnt, err := obj.List(po, pi)
  233. if err != nil {
  234. c.Data["json"] = c.ResultError(err.Error())
  235. c.ServeJSON()
  236. return
  237. }
  238. c.Data["json"] = c.ResultOK(lst, cnt)
  239. c.ServeJSON()
  240. }
  241. // @Summary 创建或编辑新的内置模型
  242. // @Description 创建新的内置模型
  243. // @Tags 业务管理服务
  244. // @Accept x-www-form-urlencoded
  245. // @Produce json
  246. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  247. // @Param model_name formData string true "模型名称"
  248. // @Param vol_id formData int true "电压等级ID"
  249. // @Param line_link_style formData int true "接线方式ID"
  250. // @Param ied_types formData string false "包含的装置类型,关联代码:ied_type。多个类型之间使用逗号分隔。"
  251. // @Param relation_json formData string false "模型定义内容。svg源代码(xml格式)。"
  252. // @Param area_type formData string false "间隔类型。关联代码:area_type"
  253. // @Success 200 {object} ResultOK 成功
  254. // @Failure 500 {object} ResultError 失败
  255. // @router /admin/sysmodel/save [post]
  256. func (c *BusAdminController) SaveSysModelInfo() {
  257. id, _ := c.GetInt("id")
  258. obj := new(bo.SysCheckModelMgr)
  259. obj.SetUserInfo(c.GetCurrentUserInfo())
  260. obj.Model = bo.T_data_model_defualt{Id: id}
  261. obj.Model.ModelName = c.GetString("model_name")
  262. obj.Model.AreaType, _ = c.GetInt("area_type")
  263. obj.Model.IedTypes = c.GetString("ied_types")
  264. obj.Model.VolId, _ = c.GetInt("vol_id")
  265. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  266. obj.Model.RelationJson = c.GetString("relation_json")
  267. if id == 0 && obj.Model.ModelName == "" {
  268. c.Data["json"] = c.ResultError("模型名称不能为空")
  269. c.ServeJSON()
  270. return
  271. }
  272. if id == 0 && obj.Model.VolId == 0 {
  273. c.Data["json"] = c.ResultError("电压等级不能为空")
  274. c.ServeJSON()
  275. return
  276. }
  277. if id == 0 && obj.Model.LineLinkStyle == 0 {
  278. c.Data["json"] = c.ResultError("接线方式不能为空")
  279. c.ServeJSON()
  280. return
  281. }
  282. if id == 0 && obj.Model.AreaType == 0 {
  283. c.Data["json"] = c.ResultError("间隔类型不能为空")
  284. c.ServeJSON()
  285. return
  286. }
  287. model, err := obj.Save()
  288. if err != nil {
  289. c.Data["json"] = c.ResultError(err.Error())
  290. c.ServeJSON()
  291. return
  292. }
  293. c.Data["json"] = c.ResultOK(model, 0)
  294. c.ServeJSON()
  295. }
  296. // @Summary 复制并保存指定的内置检测模型为自定义模型
  297. // @Description 复制并保存指定的内置检测模型为自定义模型
  298. // @Tags 业务管理服务
  299. // @Accept x-www-form-urlencoded
  300. // @Produce json
  301. // @Param id formData int true "被复制模型的ID"
  302. // @Param newname formData string true "新模型名称"
  303. // @Param vol_id formData int false "目标电压等级ID"
  304. // @Param link_style_id formData int false "目标接线方式ID"
  305. // @Success 200 {object} ResultOK 成功
  306. // @Failure 500 {object} ResultError 失败
  307. // @router /admin/sysmodel/saveas [post]
  308. func (c *BusAdminController) CopySysModelByID() {
  309. id, _ := c.GetInt("id")
  310. if id == 0 {
  311. c.Data["json"] = c.ResultError("id不能为空!")
  312. c.ServeJSON()
  313. return
  314. }
  315. new_name := c.GetString("newname")
  316. obj := new(bo.SysCheckModelMgr)
  317. obj.SetUserInfo(c.GetCurrentUserInfo())
  318. obj.Model = bo.T_data_model_defualt{Id: id}
  319. obj.Model.Id = id
  320. obj.Model.ModelName = new_name
  321. //判断名称是否已存在
  322. h, _ := obj.ExistName(new_name)
  323. if h {
  324. c.Data["json"] = c.ResultError("当前的模型名称已存在")
  325. c.ServeJSON()
  326. return
  327. }
  328. volid, _ := c.GetInt("vol_id")
  329. linkid, _ := c.GetInt("link_style_id")
  330. if volid > 0 {
  331. obj.Model.VolId = volid
  332. }
  333. if linkid > 0 {
  334. obj.Model.LineLinkStyle = linkid
  335. }
  336. obj.Model.IsSys = 1
  337. err, newid := obj.Copy(id)
  338. if err != nil {
  339. c.Data["json"] = c.ResultError(err.Error())
  340. c.ServeJSON()
  341. return
  342. }
  343. c.Data["json"] = c.ResultOK(newid, 0)
  344. c.ServeJSON()
  345. }
  346. // @Summary 删除指定的检测模型
  347. // @Description 删除指定的检测模型
  348. // @Tags 业务管理服务
  349. // @Accept x-www-form-urlencoded
  350. // @Produce json
  351. // @Param id formData int true "模型ID"
  352. // @Success 200 {object} ResultOK 成功
  353. // @Failure 500 {object} ResultError 失败
  354. // @router /admin/sysmodel/delete [post]
  355. func (c *BusAdminController) DeleteSysModelByID() {
  356. id, _ := c.GetInt("id")
  357. if id == 0 {
  358. c.Data["json"] = c.ResultError("id不能为空!")
  359. c.ServeJSON()
  360. return
  361. }
  362. obj := new(bo.SysCheckModelMgr)
  363. obj.SetUserInfo(c.GetCurrentUserInfo())
  364. obj.Model = bo.T_data_model_defualt{Id: id}
  365. obj.Model.Id = id
  366. err := obj.Delete()
  367. if err != nil {
  368. c.Data["json"] = c.ResultError(err.Error())
  369. c.ServeJSON()
  370. return
  371. }
  372. c.Data["json"] = c.ResultOK("", 0)
  373. c.ServeJSON()
  374. }
  375. // @Summary 更新检测模型指定装置的类型编码
  376. // @Description 更新检测模型指定装置的类型编码
  377. // @Tags 业务管理服务
  378. // @Accept x-www-form-urlencoded
  379. // @Produce json
  380. // @Param id formData int true "模型ID"
  381. // @Param old_iedtype formData string true "装置原编码"
  382. // @Param new_iedtype formData string true "装置新编码"
  383. // @Success 200 {object} ResultOK 成功
  384. // @Failure 500 {object} ResultError 失败
  385. // @router /admin/sysmodel/update/iedtype [post]
  386. func (c *BusAdminController) UPdateSysModelIedType() {
  387. id, _ := c.GetInt("id")
  388. if id == 0 {
  389. c.Data["json"] = c.ResultError("模型编号不能为空!")
  390. c.ServeJSON()
  391. return
  392. }
  393. oldtype := c.GetString("old_iedtype")
  394. newtype := c.GetString("new_iedtype")
  395. if oldtype == "" {
  396. c.Data["json"] = c.ResultError("装置类型编码不能为空!")
  397. c.ServeJSON()
  398. return
  399. }
  400. obj := new(bo.SysCheckModelMgr)
  401. obj.SetUserInfo(c.GetCurrentUserInfo())
  402. obj.Model = bo.T_data_model_defualt{Id: id}
  403. err := obj.UpdateIedType(oldtype, newtype)
  404. if err != nil {
  405. c.Data["json"] = c.ResultError(err.Error())
  406. c.ServeJSON()
  407. return
  408. }
  409. c.Data["json"] = c.ResultOK("", 0)
  410. c.ServeJSON()
  411. }
  412. // @Summary 获取检测模型指定装置的自定义类型编码
  413. // @Description 获取检测模型指定装置的自定义类型编码
  414. // @Tags 业务管理服务
  415. // @Accept x-www-form-urlencoded
  416. // @Produce json
  417. // @Param id formData int true "模型ID"
  418. // @Param ied_type formData string true "装置原编码"
  419. // @Success 200 {object} ResultOK 成功
  420. // @Failure 500 {object} ResultError 失败
  421. // @router /admin/sysmodel/get/iedtype [get]
  422. func (c *BusAdminController) GetSysModelIedTypeMapping() {
  423. id, _ := c.GetInt("id")
  424. if id == 0 {
  425. c.Data["json"] = c.ResultError("模型编号不能为空!")
  426. c.ServeJSON()
  427. return
  428. }
  429. oldtype := c.GetString("ied_type")
  430. if oldtype == "" {
  431. c.Data["json"] = c.ResultError("装置类型编码不能为空!")
  432. c.ServeJSON()
  433. return
  434. }
  435. obj := new(bo.SysCheckModelMgr)
  436. obj.SetUserInfo(c.GetCurrentUserInfo())
  437. obj.Model = bo.T_data_model_defualt{Id: id}
  438. r := obj.GetIedtypeMapping(oldtype)
  439. c.Data["json"] = c.ResultOK(r, 0)
  440. c.ServeJSON()
  441. }
  442. // @Summary 查询检测模型列表
  443. // @Description 查询检测模型列表。支持名称、电压等级等过滤条件
  444. // @Tags 检测任务服务接口
  445. // @Accept x-www-form-urlencoded
  446. // @Produce json
  447. // @Param pageno query int true "当前页码。默认为1"
  448. // @Param pagesize query int true "每页显示数据数。默认为20"
  449. // @Param id query int false "ID"
  450. // @Param vol_id query int false "电压等级ID"
  451. // @Param model_name query string false "名称"
  452. // @Param line_link_style query int false "接线方式"
  453. // @Param area_type query int false "间隔类型"
  454. // @Param is_sys query int false "模型类型。1 内置模型 2 自定义模型"
  455. // @Success 200 {object} ResultOK 成功
  456. // @Failure 500 {object} ResultError 失败
  457. // @router /admin/sysmodel/list [get]
  458. func (c *BusAdminController) GetSysModelList() {
  459. obj := new(bo.SysCheckModelMgr)
  460. obj.SetUserInfo(c.GetCurrentUserInfo())
  461. obj.Model = bo.T_data_model_defualt{}
  462. obj.Model.Id, _ = c.GetInt("id")
  463. obj.Model.IsSys, _ = c.GetInt("is_sys", 1) //默认查询系统内置模型
  464. obj.Model.VolId, _ = c.GetInt("vol_id")
  465. obj.Model.ModelName = c.GetString("model_name")
  466. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  467. obj.Model.AreaType, _ = c.GetInt("area_type")
  468. pi, _ := c.GetInt("pagesize", 20)
  469. po, _ := c.GetInt("pageno", 0)
  470. if po == 0 {
  471. po, _ = c.GetInt("pageindex", 0)
  472. }
  473. if po == 0 {
  474. po = 1
  475. }
  476. lst, cnt, err := obj.List(po, pi)
  477. if err != nil {
  478. c.Data["json"] = c.ResultError(err.Error())
  479. c.ServeJSON()
  480. return
  481. }
  482. //如果是获取指定模型信息时,附加模型的标准装置类型信息
  483. if obj.Model.Id > 0 {
  484. //间隔类型id
  485. syscode := new(bo.Global)
  486. codeinfo := syscode.GetCodeInfoByID(tools.IsEmpty(lst[0]["area_type"]))
  487. if codeinfo != nil {
  488. code := "area_type_" + tools.IsEmpty(codeinfo["code"])
  489. codeinfo = syscode.GetCodeInfoByCode("area_ied_type", code)
  490. codes := strings.Split(tools.IsEmpty(codeinfo["name"]), ",")
  491. ccrows := []orm.Params{}
  492. for _, item := range codes {
  493. tmp := syscode.GetCodeInfoByCode("ied_type", item)
  494. if tmp == nil {
  495. ccrows = append(ccrows, orm.Params{"code": item, "name": item})
  496. } else {
  497. ccrows = append(ccrows, tmp)
  498. }
  499. }
  500. lst[0]["ied_type"] = ccrows
  501. }
  502. }
  503. c.Data["json"] = c.ResultOK(lst, cnt)
  504. c.ServeJSON()
  505. }
  506. // @Summary 重新分析指定的SCD检测模型间隔
  507. // @Description 重新分析指定的SCD检测模型间隔
  508. // @Tags 业务管理服务
  509. // @Accept x-www-form-urlencoded
  510. // @Produce json
  511. // @Param scd_id formData int true "SCD文件ID"
  512. // @Success 200 {object} ResultOK 成功
  513. // @Failure 500 {object} ResultError 失败
  514. // @router /admin/parse/check_area [post]
  515. func (c *BusAdminController) ResetCheckAreaByID() {
  516. id, _ := c.GetInt64("scd_id")
  517. if id == 0 {
  518. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  519. c.ServeJSON()
  520. return
  521. }
  522. obj := new(bo.CheckAreaMgr)
  523. obj.SetUserInfo(c.GetCurrentUserInfo())
  524. obj.ScdId = id
  525. err := obj.Reset()
  526. if err != nil {
  527. c.Data["json"] = c.ResultError(err.Error())
  528. c.ServeJSON()
  529. return
  530. }
  531. c.Data["json"] = c.ResultOK("", 0)
  532. c.ServeJSON()
  533. }
  534. // @Summary 添加一个新间隔
  535. // @Description 添加一个新间隔
  536. // @Tags 业务管理服务
  537. // @Accept x-www-form-urlencoded
  538. // @Produce json
  539. // @Param scd_id formData int true "SCD文件ID"
  540. // @Param model_id formData int true "间隔所属模型ID。从当前任务已选择模型中选择"
  541. // @Param area_type formData string true "检测间隔类型。关联系统代码:area_type"
  542. // @Param area_name formData string true "检测间隔名称"
  543. // @Success 200 {object} ResultOK 成功
  544. // @Failure 500 {object} ResultError 失败
  545. // @router /admin/new/check_area [post]
  546. func (c *BusAdminController) AddCheckArea() {
  547. id, _ := c.GetInt64("scd_id")
  548. if id == 0 {
  549. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  550. c.ServeJSON()
  551. return
  552. }
  553. model_id, _ := c.GetInt("model_id")
  554. //area_type := c.GetString("area_type")
  555. area_name := c.GetString("area_name")
  556. if model_id == 0 || area_name == "" {
  557. c.Data["json"] = c.ResultError("参数不能为空!")
  558. c.ServeJSON()
  559. return
  560. }
  561. obj := new(bo.CheckAreaMgr)
  562. obj.SetUserInfo(c.GetCurrentUserInfo())
  563. obj.ScdId = id
  564. lst, err := obj.Save(model_id, area_name)
  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 scd_id formData int true "SCD文件ID"
  579. // @Param area_id formData int true "间隔ID"
  580. // @Success 200 {object} ResultOK 成功
  581. // @Failure 500 {object} ResultError 失败
  582. // @router /admin/del/check_area [post]
  583. func (c *BusAdminController) DelCheckArea() {
  584. id, _ := c.GetInt64("scd_id")
  585. if id == 0 {
  586. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  587. c.ServeJSON()
  588. return
  589. }
  590. area_id, _ := c.GetInt("area_id")
  591. if area_id == 0 {
  592. c.Data["json"] = c.ResultError("参数不能为空!")
  593. c.ServeJSON()
  594. return
  595. }
  596. obj := new(bo.CheckAreaMgr)
  597. obj.SetUserInfo(c.GetCurrentUserInfo())
  598. obj.ScdId = id
  599. err := obj.Del(area_id)
  600. if err != nil {
  601. c.Data["json"] = c.ResultError(err.Error())
  602. c.ServeJSON()
  603. return
  604. }
  605. c.Data["json"] = c.ResultOK("", 0)
  606. c.ServeJSON()
  607. }
  608. // @Summary 查询指定电压等级及接线方式下的检测间隔分析结果
  609. // @Description 查询指定电压等级及接线方式下的检测间隔分析结果
  610. // @Tags 业务管理服务
  611. // @Accept x-www-form-urlencoded
  612. // @Produce json
  613. // @Param scd_id formData int true "SCD文件ID"
  614. // @Param vol_id formData int false "电压等级ID"
  615. // @Param link_style_id formData int false "接线方式ID"
  616. // @Success 200 {object} ResultOK 成功
  617. // @Failure 500 {object} ResultError 失败
  618. // @router /admin/get/check_area [get]
  619. func (c *BusAdminController) GetCheckAreaByVolID() {
  620. id, _ := c.GetInt64("scd_id")
  621. if id == 0 {
  622. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  623. c.ServeJSON()
  624. return
  625. }
  626. volid, _ := c.GetInt("vol_id")
  627. lsid, _ := c.GetInt("link_style_id")
  628. obj := new(bo.CheckAreaMgr)
  629. obj.SetUserInfo(c.GetCurrentUserInfo())
  630. obj.ScdId = id
  631. lst, err := obj.GetAreaListByVol(id, volid, lsid)
  632. if err != nil {
  633. c.Data["json"] = c.ResultError(err.Error())
  634. c.ServeJSON()
  635. return
  636. }
  637. if lst == nil || len(lst) == 0 {
  638. //新分析
  639. err = obj.Reset()
  640. if err != nil {
  641. c.Data["json"] = c.ResultError(err.Error())
  642. c.ServeJSON()
  643. return
  644. }
  645. lst, _ = obj.GetAreaListByVol(id, volid, lsid)
  646. }
  647. //获取每个间隔下的ied列表同步返回
  648. if lst != nil {
  649. for i, row := range lst {
  650. area_id, _ := strconv.Atoi(tools.IsEmpty(row["area_id"]))
  651. iedlst, _ := obj.GetIedList(id, area_id)
  652. if iedlst == nil {
  653. lst[i]["ieds"] = []orm.Params{}
  654. } else {
  655. lst[i]["ieds"] = iedlst
  656. }
  657. }
  658. }
  659. c.Data["json"] = c.ResultOK(lst, 0)
  660. c.ServeJSON()
  661. }
  662. // @Summary 查询指定检测间隔下的IED装置列表
  663. // @Description 查询指定检测间隔下的IED装置列表
  664. // @Tags 业务管理服务
  665. // @Accept x-www-form-urlencoded
  666. // @Produce json
  667. // @Param scd_id formData int true "SCD文件ID"
  668. // @Param area_id formData int true "检测间隔ID"
  669. // @Success 200 {object} ResultOK 成功
  670. // @Failure 500 {object} ResultError 失败
  671. // @router /admin/get/check_area/ied [get]
  672. func (c *BusAdminController) GetCheckAreaIedByAreaID() {
  673. id, _ := c.GetInt64("scd_id")
  674. if id == 0 {
  675. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  676. c.ServeJSON()
  677. return
  678. }
  679. area_id, _ := c.GetInt("area_id")
  680. obj := new(bo.CheckAreaMgr)
  681. obj.SetUserInfo(c.GetCurrentUserInfo())
  682. obj.ScdId = id
  683. lst, err := obj.GetIedList(id, area_id)
  684. if err != nil {
  685. c.Data["json"] = c.ResultError(err.Error())
  686. c.ServeJSON()
  687. return
  688. }
  689. c.Data["json"] = c.ResultOK(lst, 0)
  690. c.ServeJSON()
  691. }
  692. // @Summary 修改并保存指定检测间隔下的IED装置列表
  693. // @Description 修改并保存指定检测间隔下的IED装置列表
  694. // @Tags 业务管理服务
  695. // @Accept x-www-form-urlencoded
  696. // @Produce json
  697. // @Param scd_id formData int true "SCD文件ID"
  698. // @Param area_id formData int true "检测间隔ID"
  699. // @Param ied_ids formData string true "IED装置name列表,多个ied采用逗号分隔。如:PT1001,PL1001,..."
  700. // @Success 200 {object} ResultOK 成功
  701. // @Failure 500 {object} ResultError 失败
  702. // @router /admin/update/check_area/ied [post]
  703. func (c *BusAdminController) SaveCheckAreaIedByAreaID() {
  704. id, _ := c.GetInt64("scd_id")
  705. if id == 0 {
  706. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  707. c.ServeJSON()
  708. return
  709. }
  710. area_id, _ := c.GetInt("area_id")
  711. ieds := c.GetString("ied_ids")
  712. if area_id == 0 {
  713. c.Data["json"] = c.ResultError("检测间隔ID不能为空!")
  714. c.ServeJSON()
  715. return
  716. }
  717. if ieds == "" {
  718. c.Data["json"] = c.ResultError("检测间隔装置列表不能为空!")
  719. c.ServeJSON()
  720. return
  721. }
  722. obj := new(bo.CheckAreaMgr)
  723. obj.SetUserInfo(c.GetCurrentUserInfo())
  724. obj.ScdId = id
  725. err := obj.UpdateIeds(id, area_id, ieds)
  726. if err != nil {
  727. c.Data["json"] = c.ResultError(err.Error())
  728. c.ServeJSON()
  729. return
  730. }
  731. c.Data["json"] = c.ResultOK("", 0)
  732. c.ServeJSON()
  733. }
  734. // @Summary 设置间隔下指定装置的端子编号
  735. // @Description 设置间隔下指定装置的端子编号。该编号只有在端子匹配表达式中存在{no}标识时才会使用
  736. // @Tags 业务管理服务
  737. // @Accept x-www-form-urlencoded
  738. // @Produce json
  739. // @Param area_id formData int true "间隔ID"
  740. // @Param ied_name formData string true "IED装置名称"
  741. // @Param ied_no formData string true "IED装置在特定间隔内,端子间使用的编号"
  742. // @Success 200 {object} ResultOK 成功
  743. // @Failure 500 {object} ResultError 失败
  744. // @router /admin/update/check_area/iedno [post]
  745. func (c *BusAdminController) SaveCheckAreaIedNoByAreaID() {
  746. area_id, _ := c.GetInt("area_id")
  747. ied_name := c.GetString("ied_name")
  748. if area_id == 0 {
  749. c.Data["json"] = c.ResultError("间隔ID不能为空!")
  750. c.ServeJSON()
  751. return
  752. }
  753. if ied_name == "" {
  754. c.Data["json"] = c.ResultError("装置名称不能为空!(如果是追加装置需要先保存后再设置)")
  755. c.ServeJSON()
  756. return
  757. }
  758. obj := new(bo.CheckAreaMgr)
  759. obj.SetUserInfo(c.GetCurrentUserInfo())
  760. err := obj.SetIedNo(area_id, ied_name, c.GetString("ied_no"))
  761. if err != nil {
  762. c.Data["json"] = c.ResultError(err.Error())
  763. c.ServeJSON()
  764. return
  765. }
  766. c.Data["json"] = c.ResultOK("", 0)
  767. c.ServeJSON()
  768. }
  769. // @Summary 获取指定模型和装置类型的功能列表
  770. // @Description 获取指定模型和装置类型的功能列表
  771. // @Tags 业务管理服务
  772. // @Accept x-www-form-urlencoded
  773. // @Produce json
  774. // @Param model_id formData int true "模型ID"
  775. // @Param ied_type formData string true "装置类型"
  776. // @Success 200 {object} ResultOK 成功
  777. // @Failure 500 {object} ResultError 失败
  778. // @router /admin/model/function/list [get]
  779. func (c *BusAdminController) GetFuncListByIedType() {
  780. modelid, _ := c.GetInt("model_id")
  781. if modelid == 0 {
  782. c.Data["json"] = c.ResultError("模型ID不能为空!")
  783. c.ServeJSON()
  784. return
  785. }
  786. ied_type := c.GetString("ied_type")
  787. if ied_type == "" {
  788. c.Data["json"] = c.ResultError("装置类型不能为空!")
  789. c.ServeJSON()
  790. return
  791. }
  792. obj := new(bo.SysCheckModelIedFuncMgr)
  793. obj.SetUserInfo(c.GetCurrentUserInfo())
  794. lst, err := obj.GetList(modelid, ied_type)
  795. if err != nil {
  796. c.Data["json"] = c.ResultError(err.Error())
  797. c.ServeJSON()
  798. return
  799. }
  800. c.Data["json"] = c.ResultOK(lst, 0)
  801. c.ServeJSON()
  802. }
  803. // @Summary 保存按装置配置的虚端子检测关系
  804. // @Description 保存按装置配置的虚端子检测关系
  805. // @Tags 业务管理服务
  806. // @Accept x-www-form-urlencoded
  807. // @Produce json
  808. // @Param station_id formData int64 true "变电站ID"
  809. // @Param area_id formData string false "指定的间隔"
  810. // @Param datalist formData string false "DOI关系配置。"
  811. // @Success 200 {object} ResultOK 成功
  812. // @Failure 500 {object} ResultError 失败
  813. // @router /admin/doi/mapping/save [post]
  814. func (c *BusAdminController) SaveDoiMapping() {
  815. station_id, _ := c.GetInt("station_id", -1)
  816. if station_id == -1 {
  817. c.Data["json"] = c.ResultError("station_id不能为空!")
  818. c.ServeJSON()
  819. return
  820. }
  821. areaids, _ := c.GetInt("area_id")
  822. datalist := c.GetString("datalist")
  823. if len(datalist) == 0 {
  824. c.Data["json"] = c.ResultError("DOI关系不能为空!")
  825. c.ServeJSON()
  826. return
  827. }
  828. dois := []map[string]interface{}{}
  829. err := json.Unmarshal([]byte(datalist), &dois)
  830. if err != nil {
  831. c.Data["json"] = c.ResultError(err.Error())
  832. c.ServeJSON()
  833. return
  834. }
  835. obj := new(bo.CheckAreaMgr)
  836. err = obj.SaveDoiMapping(station_id, areaids, dois)
  837. if err != nil {
  838. c.Data["json"] = c.ResultError(err.Error())
  839. c.ServeJSON()
  840. return
  841. }
  842. c.Data["json"] = c.ResultOK("", 0)
  843. c.ServeJSON()
  844. }
  845. // @Summary 获取按装置配置的虚端子检测关系
  846. // @Description 获取按装置配置的虚端子检测关系
  847. // @Tags 业务管理服务
  848. // @Accept x-www-form-urlencoded
  849. // @Produce json
  850. // @Param station_id formData int64 true "变电站ID"
  851. // @Param area_id formData string false "指定的间隔"
  852. // @Param ied_name formData string false "指定的装置名称。可以不指定。"
  853. // @Success 200 {object} ResultOK 成功
  854. // @Failure 500 {object} ResultError 失败
  855. // @router /admin/doi/mapping/list [get]
  856. func (c *BusAdminController) GetDoiMappingList() {
  857. station_id, _ := c.GetInt("station_id", -1)
  858. if station_id == -1 {
  859. c.Data["json"] = c.ResultError("station_id不能为空!")
  860. c.ServeJSON()
  861. return
  862. }
  863. areaids, _ := c.GetInt("area_id")
  864. obj := new(bo.CheckAreaMgr)
  865. lst, err := obj.GetDoiMapping(station_id, areaids, c.GetString("ied_name"))
  866. if err != nil {
  867. c.Data["json"] = c.ResultError(err.Error())
  868. c.ServeJSON()
  869. return
  870. }
  871. c.Data["json"] = c.ResultOK(lst, len(lst))
  872. c.ServeJSON()
  873. }
  874. // @Summary 获取SCD中装置实际配置的虚端子关系
  875. // @Description 获取SCD中装置实际配置的虚端子关系
  876. // @Tags 业务管理服务
  877. // @Accept x-www-form-urlencoded
  878. // @Produce json
  879. // @Param scd_id formData int64 true "SCD文件ID"
  880. // @Param area_ids formData string false "指定的间隔列表,多个间隔使用逗号分隔。可以不指定,不指定时则生成全站所有装置的端子关系表"
  881. // @Param ied_name formData string false "指定的装置名称。可以不指定。"
  882. // @Success 200 {object} ResultOK 成功
  883. // @Failure 500 {object} ResultError 失败
  884. // @router /admin/scd/fcda/list [get]
  885. func (c *BusAdminController) GetScdIedFcdaList() {
  886. scd_id, _ := c.GetInt64("scd_id")
  887. if scd_id == 0 {
  888. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  889. c.ServeJSON()
  890. return
  891. }
  892. areaids := c.GetString("area_ids")
  893. areaLst := []string{}
  894. if areaids != "" {
  895. areaLst = strings.Split(areaids, ",")
  896. }
  897. obj := new(bo.CheckAreaMgr)
  898. lst, err := obj.MakeExtrefReport(scd_id, areaLst, c.GetString("ied_name"))
  899. if err != nil {
  900. c.Data["json"] = c.ResultError(err.Error())
  901. c.ServeJSON()
  902. return
  903. }
  904. c.Data["json"] = c.ResultOK(lst, len(lst))
  905. c.ServeJSON()
  906. }
  907. // @Summary 获取指定模型和装置类型的端子列表
  908. // @Description 获取指定模型和装置类型的端子列表
  909. // @Tags 业务管理服务
  910. // @Accept x-www-form-urlencoded
  911. // @Produce json
  912. // @Param model_id formData int true "模型ID"
  913. // @Param ied_type formData string true "查询的装置类型"
  914. // @Param ref_ied_type formData string true "对侧关联装置类型"
  915. // @Param sv_or_goose formData string true "信号类型。仅支持:SV或GOOSE"
  916. // @Param in_or_out formData string true "信号方向。仅支持:'输出'或'接收'"
  917. // @Success 200 {object} ResultOK 成功
  918. // @Failure 500 {object} ResultError 失败
  919. // @router /admin/model/function/fcda/list [get]
  920. func (c *BusAdminController) GetFuncFcdaList() {
  921. modelid, _ := c.GetInt("model_id")
  922. if modelid == 0 {
  923. c.Data["json"] = c.ResultError("模型ID不能为空!")
  924. c.ServeJSON()
  925. return
  926. }
  927. ied_type := c.GetString("ied_type")
  928. if ied_type == "" {
  929. c.Data["json"] = c.ResultError("查询的装置类型不能为空!")
  930. c.ServeJSON()
  931. return
  932. }
  933. ref_ied_type := c.GetString("ref_ied_type")
  934. if ied_type == "" {
  935. c.Data["json"] = c.ResultError("对侧关联装置类型不能为空!")
  936. c.ServeJSON()
  937. return
  938. }
  939. obj := new(bo.SysCheckModelIedFuncMgr)
  940. obj.SetUserInfo(c.GetCurrentUserInfo())
  941. lst, err := obj.GetList(modelid, ied_type)
  942. if err != nil {
  943. c.Data["json"] = c.ResultError(err.Error())
  944. c.ServeJSON()
  945. return
  946. }
  947. if len(lst) == 0 {
  948. c.Data["json"] = c.ResultOK("", 0)
  949. c.ServeJSON()
  950. return
  951. }
  952. funcids := []string{}
  953. for _, row := range lst {
  954. funcids = append(funcids, tools.IsEmpty(row["id"]))
  955. }
  956. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  957. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  958. fcdaMgr.Model.ModelId = modelid
  959. fcdaMgr.Model.Svorgoose = strings.ToUpper(c.GetString("sv_or_goose"))
  960. fcdaMgr.Model.Inorout = c.GetString("in_or_out")
  961. fcdaList, err := fcdaMgr.GetList(ref_ied_type, funcids)
  962. if err != nil {
  963. c.Data["json"] = c.ResultError(err.Error())
  964. c.ServeJSON()
  965. return
  966. }
  967. c.Data["json"] = c.ResultOK(fcdaList, len(fcdaList))
  968. c.ServeJSON()
  969. }
  970. // @Summary 保存模型装置功能及端子信息
  971. // @Description 保存装置功能及端子信息
  972. // @Tags 业务管理服务
  973. // @Accept x-www-form-urlencoded
  974. // @Produce json
  975. // @Param model_id formData int true "模型ID"
  976. // @Param ied_type formData string true "装置类型代码"
  977. // @Param func_id formData int false "功能ID。编辑时必传。"
  978. // @Param func_name formData string true "功能名称。必传。"
  979. // @Param fcda_id formData int false "端子ID。编辑时必传。"
  980. // @Param fcda_name formData string true "端子名称。必传。"
  981. // @Param fcda_match_exp formData string true "端子匹配表达式。必传。"
  982. // @Param sv_or_goose formData string true "端子信号类型。必传。仅支持SV或GOOSE"
  983. // @Param in_or_out formData string true "端子信号输入输出方向。必传。仅支持中文的'接收'或'输出'"
  984. // @Success 200 {object} ResultOK 成功
  985. // @Failure 500 {object} ResultError 失败
  986. // @router /admin/model/function/fcda/save [post]
  987. func (c *BusAdminController) SaveFuncFcda() {
  988. modelid, _ := c.GetInt("model_id")
  989. if modelid == 0 {
  990. c.Data["json"] = c.ResultError("模型ID不能为空!")
  991. c.ServeJSON()
  992. return
  993. }
  994. ied_type := c.GetString("ied_type")
  995. func_name := c.GetString("func_name")
  996. fcda_name := c.GetString("fcda_name")
  997. fcda_match_exp := c.GetString("fcda_match_exp")
  998. func_id, _ := c.GetInt("func_id")
  999. fcda_id, _ := c.GetInt("fcda_id")
  1000. svorgoose := c.GetString("sv_or_goose")
  1001. inorout := c.GetString("in_or_out")
  1002. if func_name == "" {
  1003. c.Data["json"] = c.ResultError("功能名称不能为空!")
  1004. c.ServeJSON()
  1005. return
  1006. }
  1007. if fcda_name == "" {
  1008. c.Data["json"] = c.ResultError("端子设计名称不能为空!")
  1009. c.ServeJSON()
  1010. return
  1011. }
  1012. if fcda_match_exp == "" {
  1013. c.Data["json"] = c.ResultError("端子匹配关键词不能为空!")
  1014. c.ServeJSON()
  1015. return
  1016. }
  1017. if svorgoose == "" {
  1018. c.Data["json"] = c.ResultError("端子信号类型不能为空!")
  1019. c.ServeJSON()
  1020. return
  1021. }
  1022. if inorout == "" {
  1023. c.Data["json"] = c.ResultError("端子信号方向不能为空!")
  1024. c.ServeJSON()
  1025. return
  1026. }
  1027. mod := bo.T_data_model_func_def{}
  1028. mod.Id = func_id
  1029. mod.ModelId = modelid
  1030. mod.IedType = ied_type
  1031. mod.FuncFcdaId = fcda_id
  1032. mod.FuncName = func_name
  1033. mod.FcdaName = fcda_name
  1034. mod.FcdaMatchExp = fcda_match_exp
  1035. mod.Svorgoose = svorgoose
  1036. mod.Inorout = inorout
  1037. mgr := new(bo.SysCheckModelIedFuncMgr)
  1038. mgr.SetUserInfo(c.GetCurrentUserInfo())
  1039. mgr.Model = mod
  1040. _, _, err := mgr.Save()
  1041. if err != nil {
  1042. c.Data["json"] = c.ResultError(err.Error())
  1043. c.ServeJSON()
  1044. return
  1045. }
  1046. c.Data["json"] = c.ResultOK("", 0)
  1047. c.ServeJSON()
  1048. }
  1049. // @Summary 删除指定模型所有的装置端子
  1050. // @Description 删除指定模型所有的装置端子
  1051. // @Tags 业务管理服务
  1052. // @Accept x-www-form-urlencoded
  1053. // @Produce json
  1054. // @Param model_id formData int true "模型ID"
  1055. // @Success 200 {object} ResultOK 成功
  1056. // @Failure 500 {object} ResultError 失败
  1057. // @router /admin/model/fcda/delall [post]
  1058. func (c *BusAdminController) DelAllFuncFcda() {
  1059. modelid, _ := c.GetInt("model_id")
  1060. if modelid == 0 {
  1061. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1062. c.ServeJSON()
  1063. return
  1064. }
  1065. fcdaMgr := new(bo.SysCheckModelIedFuncMgr)
  1066. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1067. fcdaMgr.Model = bo.T_data_model_func_def{}
  1068. fcdaMgr.Model.ModelId = modelid
  1069. err := fcdaMgr.Delete()
  1070. if err != nil {
  1071. c.Data["json"] = c.ResultError(err.Error())
  1072. c.ServeJSON()
  1073. return
  1074. }
  1075. c.Data["json"] = c.ResultOK("", 0)
  1076. c.ServeJSON()
  1077. }
  1078. // @Summary 删除装置端子
  1079. // @Description 删除装置端子
  1080. // @Tags 业务管理服务
  1081. // @Accept x-www-form-urlencoded
  1082. // @Produce json
  1083. // @Param model_id formData int true "模型ID"
  1084. // @Param fcda_id formData int true "端子ID"
  1085. // @Success 200 {object} ResultOK 成功
  1086. // @Failure 500 {object} ResultError 失败
  1087. // @router /admin/model/function/fcda/del [post]
  1088. func (c *BusAdminController) DelFuncFcda() {
  1089. modelid, _ := c.GetInt("model_id")
  1090. if modelid == 0 {
  1091. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1092. c.ServeJSON()
  1093. return
  1094. }
  1095. fcda_id, _ := c.GetInt("fcda_id")
  1096. if fcda_id == 0 {
  1097. c.Data["json"] = c.ResultError("端子ID不能为空!")
  1098. c.ServeJSON()
  1099. return
  1100. }
  1101. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  1102. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1103. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  1104. fcdaMgr.Model.ModelId = modelid
  1105. fcdaMgr.Model.Id = fcda_id
  1106. err := fcdaMgr.Delete()
  1107. if err != nil {
  1108. c.Data["json"] = c.ResultError(err.Error())
  1109. c.ServeJSON()
  1110. return
  1111. }
  1112. c.Data["json"] = c.ResultOK("", 0)
  1113. c.ServeJSON()
  1114. }
  1115. // @Summary 获取模型装置端子已关联的接收端子
  1116. // @Description 获取模型装置端子已关联的接收端子
  1117. // @Tags 业务管理服务
  1118. // @Accept x-www-form-urlencoded
  1119. // @Produce json
  1120. // @Param model_id formData int true "模型ID"
  1121. // @Param from_fcda_id formData int true "输出装置端子ID"
  1122. // @Param to_ied_type formData string false "输入装置类型"
  1123. // @Param goosesv formData string false "信号类型。GOOSE|SV"
  1124. // @Success 200 {object} ResultOK 成功
  1125. // @Failure 500 {object} ResultError 失败
  1126. // @router /admin/model/function/fcda-ref/list [get]
  1127. func (c *BusAdminController) GetFuncFcdaRef() {
  1128. modelid, _ := c.GetInt("model_id")
  1129. if modelid == 0 {
  1130. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1131. c.ServeJSON()
  1132. return
  1133. }
  1134. fcda_id, _ := c.GetInt("from_fcda_id")
  1135. if fcda_id == 0 {
  1136. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  1137. c.ServeJSON()
  1138. return
  1139. }
  1140. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  1141. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1142. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  1143. fcdaMgr.Model.ModelId = modelid
  1144. fcdaMgr.Model.FromFcdaId = fcda_id
  1145. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  1146. fcdaMgr.Model.Goosesv = c.GetString("goosesv")
  1147. lst, err := fcdaMgr.GetList()
  1148. if err != nil {
  1149. c.Data["json"] = c.ResultError(err.Error())
  1150. c.ServeJSON()
  1151. return
  1152. }
  1153. c.Data["json"] = c.ResultOK(lst, len(lst))
  1154. c.ServeJSON()
  1155. }
  1156. // @Summary 保存模型装置端子间关联关系
  1157. // @Description 保存模型装置端子间关联关系
  1158. // @Tags 业务管理服务
  1159. // @Accept x-www-form-urlencoded
  1160. // @Produce json
  1161. // @Param model_id formData int true "模型ID"
  1162. // @Param from_ied_type formData string true "输出装置类型"
  1163. // @Param to_ied_type formData string true "输入装置类型"
  1164. // @Param from_fcda_id formData int false "输出装置端子ID"
  1165. // @Param to_fcda_ids formData string false "输入装置端子ID"
  1166. // @Param batch_fcda_ids formData json-string true "批量保存端子关系。类型为序列化的二维数组字符串。数组元素为:[[fromfcdaid,tofcdaid],...]"
  1167. // @Param goosesv formData string true "信号类型。值范围:GOOSE|SV"
  1168. // @Success 200 {object} ResultOK 成功
  1169. // @Failure 500 {object} ResultError 失败
  1170. // @router /admin/model/function/fcda-ref/save [post]
  1171. func (c *BusAdminController) SaveFuncFcdaRef() {
  1172. modelid, _ := c.GetInt("model_id")
  1173. if modelid == 0 {
  1174. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1175. c.ServeJSON()
  1176. return
  1177. }
  1178. fcda_id, _ := c.GetInt("from_fcda_id")
  1179. if fcda_id == 0 {
  1180. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  1181. c.ServeJSON()
  1182. return
  1183. }
  1184. fcda_in_ids := c.GetString("to_fcda_ids")
  1185. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  1186. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1187. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  1188. fcdaMgr.Model.ModelId = modelid
  1189. fcdaMgr.Model.FromFcdaId = fcda_id
  1190. fcdaMgr.Model.FromIedCode = c.GetString("from_ied_type")
  1191. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  1192. fcdaMgr.Model.Goosesv = strings.ToUpper(c.GetString("goosesv"))
  1193. if fcdaMgr.Model.FromIedCode == "" || fcdaMgr.Model.ToIedCode == "" {
  1194. c.Data["json"] = c.ResultError("输入和输出装置类型不能为空!")
  1195. c.ServeJSON()
  1196. return
  1197. }
  1198. if fcdaMgr.Model.Goosesv == "" {
  1199. c.Data["json"] = c.ResultError("信号类型不能为空!")
  1200. c.ServeJSON()
  1201. return
  1202. }
  1203. if fcdaMgr.Model.Goosesv != "GOOSE" && fcdaMgr.Model.Goosesv != "SV" {
  1204. c.Data["json"] = c.ResultError("信号类型不正确。只能为GOOSE或SV")
  1205. c.ServeJSON()
  1206. return
  1207. }
  1208. batch_fcda_ids := c.GetString("batch_fcda_ids")
  1209. if batch_fcda_ids != "" {
  1210. //批量保存
  1211. fcdalist := [][]int{}
  1212. err := json.Unmarshal([]byte(batch_fcda_ids), &fcdalist)
  1213. if err != nil {
  1214. c.Data["json"] = c.ResultError("无效的批量端子关系数据")
  1215. c.ServeJSON()
  1216. return
  1217. }
  1218. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  1219. for _, item := range fcdalist {
  1220. fcdainf, err := obj.One(item[0])
  1221. if err != nil {
  1222. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[0]))
  1223. c.ServeJSON()
  1224. return
  1225. }
  1226. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  1227. fcdaMgr.Model.FromFcdaId = item[0]
  1228. fcdainf, err = obj.One(item[1])
  1229. if err != nil {
  1230. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[1]))
  1231. c.ServeJSON()
  1232. return
  1233. }
  1234. fcdaMgr.Model.ToFcdaId = item[1]
  1235. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  1236. err = fcdaMgr.Save()
  1237. if err != nil {
  1238. c.Data["json"] = c.ResultError(err.Error())
  1239. c.ServeJSON()
  1240. return
  1241. }
  1242. }
  1243. c.Data["json"] = c.ResultOK("", 0)
  1244. c.ServeJSON()
  1245. return
  1246. }
  1247. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  1248. fcdainf, er := obj.One(fcdaMgr.Model.FromFcdaId)
  1249. if er != nil {
  1250. c.Data["json"] = c.ResultError("无效的输出端子ID")
  1251. c.ServeJSON()
  1252. return
  1253. }
  1254. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  1255. //清除输出端子的原关系
  1256. err := fcdaMgr.Delete()
  1257. if err != nil {
  1258. c.Data["json"] = c.ResultError(err.Error())
  1259. c.ServeJSON()
  1260. return
  1261. }
  1262. if fcda_in_ids != "" {
  1263. fcda_in_ids_1 := strings.Split(fcda_in_ids, ",")
  1264. for _, k := range fcda_in_ids_1 {
  1265. fcdaMgr.Model.ToFcdaId, _ = strconv.Atoi(k) //设置接收端子id
  1266. fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId)
  1267. if er != nil {
  1268. c.Data["json"] = c.ResultError("无效的接收端子ID")
  1269. c.ServeJSON()
  1270. return
  1271. }
  1272. //清除接收端子的原关系
  1273. fcdaMgr.Model.FromFcdaId = 0
  1274. fcdaMgr.Delete()
  1275. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  1276. //建立新的端子关系
  1277. fcdaMgr.Model.FromFcdaId = fcda_id //还原输出端子id
  1278. err := fcdaMgr.Save()
  1279. if err != nil {
  1280. c.Data["json"] = c.ResultError(err.Error())
  1281. c.ServeJSON()
  1282. return
  1283. }
  1284. }
  1285. }
  1286. c.Data["json"] = c.ResultOK("", 0)
  1287. c.ServeJSON()
  1288. }
  1289. // @Summary 删除端子之间的关联关系
  1290. // @Description 删除端子之间的关联关系
  1291. // @Tags 业务管理服务
  1292. // @Accept x-www-form-urlencoded
  1293. // @Produce json
  1294. // @Param model_id formData int true "模型ID"
  1295. // @Param from_fcda_id formData int true "输入端子ID"
  1296. // @Param to_fcda_id formData int true "输出端子ID"
  1297. // @Success 200 {object} ResultOK 成功
  1298. // @Failure 500 {object} ResultError 失败
  1299. // @router /admin/model/function/fcda-ref/del [post]
  1300. func (c *BusAdminController) DelFuncFcdaRef() {
  1301. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  1302. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1303. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  1304. fcdaMgr.Model.ModelId, _ = c.GetInt("model_id", 0)
  1305. fcdaMgr.Model.FromFcdaId, _ = c.GetInt("from_fcda_id", 0)
  1306. fcdaMgr.Model.ToFcdaId, _ = c.GetInt("to_fcda_id")
  1307. if fcdaMgr.Model.ModelId == 0 {
  1308. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1309. c.ServeJSON()
  1310. return
  1311. }
  1312. if fcdaMgr.Model.FromFcdaId == 0 {
  1313. c.Data["json"] = c.ResultError("输入端子ID不能为空!")
  1314. c.ServeJSON()
  1315. return
  1316. }
  1317. if fcdaMgr.Model.ToFcdaId == 0 {
  1318. c.Data["json"] = c.ResultError("接收端子ID不能为空")
  1319. c.ServeJSON()
  1320. return
  1321. }
  1322. //清除原关系
  1323. err := fcdaMgr.Delete()
  1324. if err != nil {
  1325. c.Data["json"] = c.ResultError(err.Error())
  1326. c.ServeJSON()
  1327. return
  1328. }
  1329. c.Data["json"] = c.ResultOK("", 0)
  1330. c.ServeJSON()
  1331. }