busAdminController.go 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  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_type == "" || 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_type, 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 获取SCD中装置实际配置的虚端子关系
  804. // @Description 获取SCD中装置实际配置的虚端子关系
  805. // @Tags 业务管理服务
  806. // @Accept x-www-form-urlencoded
  807. // @Produce json
  808. // @Param scd_id formData int64 true "SCD文件ID"
  809. // @Param area_ids formData string false "指定的间隔列表,多个间隔使用逗号分隔。可以不指定,不指定时则生成全站所有装置的端子关系表"
  810. // @Param ied_name formData string false "指定的装置名称。可以不指定。"
  811. // @Success 200 {object} ResultOK 成功
  812. // @Failure 500 {object} ResultError 失败
  813. // @router /admin/scd/fcda/list [get]
  814. func (c *BusAdminController) GetScdIedFcdaList() {
  815. scd_id, _ := c.GetInt64("scd_id")
  816. if scd_id == 0 {
  817. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  818. c.ServeJSON()
  819. return
  820. }
  821. areaids := c.GetString("area_ids")
  822. areaLst := []string{}
  823. if areaids != "" {
  824. areaLst = strings.Split(areaids, ",")
  825. }
  826. obj := new(bo.CheckAreaMgr)
  827. lst, err := obj.MakeExtrefReport(scd_id, areaLst, c.GetString("ied_name"))
  828. if err != nil {
  829. c.Data["json"] = c.ResultError(err.Error())
  830. c.ServeJSON()
  831. return
  832. }
  833. c.Data["json"] = c.ResultOK(lst, len(lst))
  834. c.ServeJSON()
  835. }
  836. // @Summary 获取指定模型和装置类型的端子列表
  837. // @Description 获取指定模型和装置类型的端子列表
  838. // @Tags 业务管理服务
  839. // @Accept x-www-form-urlencoded
  840. // @Produce json
  841. // @Param model_id formData int true "模型ID"
  842. // @Param ied_type formData string true "查询的装置类型"
  843. // @Param ref_ied_type formData string true "对侧关联装置类型"
  844. // @Param sv_or_goose formData string true "信号类型。仅支持:SV或GOOSE"
  845. // @Param in_or_out formData string true "信号方向。仅支持:'输出'或'接收'"
  846. // @Success 200 {object} ResultOK 成功
  847. // @Failure 500 {object} ResultError 失败
  848. // @router /admin/model/function/fcda/list [get]
  849. func (c *BusAdminController) GetFuncFcdaList() {
  850. modelid, _ := c.GetInt("model_id")
  851. if modelid == 0 {
  852. c.Data["json"] = c.ResultError("模型ID不能为空!")
  853. c.ServeJSON()
  854. return
  855. }
  856. ied_type := c.GetString("ied_type")
  857. if ied_type == "" {
  858. c.Data["json"] = c.ResultError("查询的装置类型不能为空!")
  859. c.ServeJSON()
  860. return
  861. }
  862. ref_ied_type := c.GetString("ref_ied_type")
  863. if ied_type == "" {
  864. c.Data["json"] = c.ResultError("对侧关联装置类型不能为空!")
  865. c.ServeJSON()
  866. return
  867. }
  868. obj := new(bo.SysCheckModelIedFuncMgr)
  869. obj.SetUserInfo(c.GetCurrentUserInfo())
  870. lst, err := obj.GetList(modelid, ied_type)
  871. if err != nil {
  872. c.Data["json"] = c.ResultError(err.Error())
  873. c.ServeJSON()
  874. return
  875. }
  876. if len(lst) == 0 {
  877. c.Data["json"] = c.ResultOK("", 0)
  878. c.ServeJSON()
  879. return
  880. }
  881. funcids := []string{}
  882. for _, row := range lst {
  883. funcids = append(funcids, tools.IsEmpty(row["id"]))
  884. }
  885. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  886. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  887. fcdaMgr.Model.ModelId = modelid
  888. fcdaMgr.Model.Svorgoose = strings.ToUpper(c.GetString("sv_or_goose"))
  889. fcdaMgr.Model.Inorout = c.GetString("in_or_out")
  890. fcdaList, err := fcdaMgr.GetList(ref_ied_type, funcids)
  891. if err != nil {
  892. c.Data["json"] = c.ResultError(err.Error())
  893. c.ServeJSON()
  894. return
  895. }
  896. c.Data["json"] = c.ResultOK(fcdaList, len(fcdaList))
  897. c.ServeJSON()
  898. }
  899. // @Summary 保存模型装置功能及端子信息
  900. // @Description 保存装置功能及端子信息
  901. // @Tags 业务管理服务
  902. // @Accept x-www-form-urlencoded
  903. // @Produce json
  904. // @Param model_id formData int true "模型ID"
  905. // @Param ied_type formData string true "装置类型代码"
  906. // @Param func_id formData int false "功能ID。编辑时必传。"
  907. // @Param func_name formData string true "功能名称。必传。"
  908. // @Param fcda_id formData int false "端子ID。编辑时必传。"
  909. // @Param fcda_name formData string true "端子名称。必传。"
  910. // @Param fcda_match_exp formData string true "端子匹配表达式。必传。"
  911. // @Param sv_or_goose formData string true "端子信号类型。必传。仅支持SV或GOOSE"
  912. // @Param in_or_out formData string true "端子信号输入输出方向。必传。仅支持中文的'接收'或'输出'"
  913. // @Success 200 {object} ResultOK 成功
  914. // @Failure 500 {object} ResultError 失败
  915. // @router /admin/model/function/fcda/save [post]
  916. func (c *BusAdminController) SaveFuncFcda() {
  917. modelid, _ := c.GetInt("model_id")
  918. if modelid == 0 {
  919. c.Data["json"] = c.ResultError("模型ID不能为空!")
  920. c.ServeJSON()
  921. return
  922. }
  923. ied_type := c.GetString("ied_type")
  924. func_name := c.GetString("func_name")
  925. fcda_name := c.GetString("fcda_name")
  926. fcda_match_exp := c.GetString("fcda_match_exp")
  927. func_id, _ := c.GetInt("func_id")
  928. fcda_id, _ := c.GetInt("fcda_id")
  929. svorgoose := c.GetString("sv_or_goose")
  930. inorout := c.GetString("in_or_out")
  931. if func_name == "" {
  932. c.Data["json"] = c.ResultError("功能名称不能为空!")
  933. c.ServeJSON()
  934. return
  935. }
  936. if fcda_name == "" {
  937. c.Data["json"] = c.ResultError("端子设计名称不能为空!")
  938. c.ServeJSON()
  939. return
  940. }
  941. if fcda_match_exp == "" {
  942. c.Data["json"] = c.ResultError("端子匹配关键词不能为空!")
  943. c.ServeJSON()
  944. return
  945. }
  946. if svorgoose == "" {
  947. c.Data["json"] = c.ResultError("端子信号类型不能为空!")
  948. c.ServeJSON()
  949. return
  950. }
  951. if inorout == "" {
  952. c.Data["json"] = c.ResultError("端子信号方向不能为空!")
  953. c.ServeJSON()
  954. return
  955. }
  956. mod := bo.T_data_model_func_def{}
  957. mod.Id = func_id
  958. mod.ModelId = modelid
  959. mod.IedType = ied_type
  960. mod.FuncFcdaId = fcda_id
  961. mod.FuncName = func_name
  962. mod.FcdaName = fcda_name
  963. mod.FcdaMatchExp = fcda_match_exp
  964. mod.Svorgoose = svorgoose
  965. mod.Inorout = inorout
  966. mgr := new(bo.SysCheckModelIedFuncMgr)
  967. mgr.SetUserInfo(c.GetCurrentUserInfo())
  968. mgr.Model = mod
  969. _, _, err := mgr.Save()
  970. if err != nil {
  971. c.Data["json"] = c.ResultError(err.Error())
  972. c.ServeJSON()
  973. return
  974. }
  975. c.Data["json"] = c.ResultOK("", 0)
  976. c.ServeJSON()
  977. }
  978. // @Summary 删除指定模型所有的装置端子
  979. // @Description 删除指定模型所有的装置端子
  980. // @Tags 业务管理服务
  981. // @Accept x-www-form-urlencoded
  982. // @Produce json
  983. // @Param model_id formData int true "模型ID"
  984. // @Success 200 {object} ResultOK 成功
  985. // @Failure 500 {object} ResultError 失败
  986. // @router /admin/model/fcda/delall [post]
  987. func (c *BusAdminController) DelAllFuncFcda() {
  988. modelid, _ := c.GetInt("model_id")
  989. if modelid == 0 {
  990. c.Data["json"] = c.ResultError("模型ID不能为空!")
  991. c.ServeJSON()
  992. return
  993. }
  994. fcdaMgr := new(bo.SysCheckModelIedFuncMgr)
  995. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  996. fcdaMgr.Model = bo.T_data_model_func_def{}
  997. fcdaMgr.Model.ModelId = modelid
  998. err := fcdaMgr.Delete()
  999. if err != nil {
  1000. c.Data["json"] = c.ResultError(err.Error())
  1001. c.ServeJSON()
  1002. return
  1003. }
  1004. c.Data["json"] = c.ResultOK("", 0)
  1005. c.ServeJSON()
  1006. }
  1007. // @Summary 删除装置端子
  1008. // @Description 删除装置端子
  1009. // @Tags 业务管理服务
  1010. // @Accept x-www-form-urlencoded
  1011. // @Produce json
  1012. // @Param model_id formData int true "模型ID"
  1013. // @Param fcda_id formData int true "端子ID"
  1014. // @Success 200 {object} ResultOK 成功
  1015. // @Failure 500 {object} ResultError 失败
  1016. // @router /admin/model/function/fcda/del [post]
  1017. func (c *BusAdminController) DelFuncFcda() {
  1018. modelid, _ := c.GetInt("model_id")
  1019. if modelid == 0 {
  1020. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1021. c.ServeJSON()
  1022. return
  1023. }
  1024. fcda_id, _ := c.GetInt("fcda_id")
  1025. if fcda_id == 0 {
  1026. c.Data["json"] = c.ResultError("端子ID不能为空!")
  1027. c.ServeJSON()
  1028. return
  1029. }
  1030. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  1031. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1032. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  1033. fcdaMgr.Model.ModelId = modelid
  1034. fcdaMgr.Model.Id = fcda_id
  1035. err := fcdaMgr.Delete()
  1036. if err != nil {
  1037. c.Data["json"] = c.ResultError(err.Error())
  1038. c.ServeJSON()
  1039. return
  1040. }
  1041. c.Data["json"] = c.ResultOK("", 0)
  1042. c.ServeJSON()
  1043. }
  1044. // @Summary 获取模型装置端子已关联的接收端子
  1045. // @Description 获取模型装置端子已关联的接收端子
  1046. // @Tags 业务管理服务
  1047. // @Accept x-www-form-urlencoded
  1048. // @Produce json
  1049. // @Param model_id formData int true "模型ID"
  1050. // @Param from_fcda_id formData int true "输出装置端子ID"
  1051. // @Param to_ied_type formData string false "输入装置类型"
  1052. // @Param goosesv formData string false "信号类型。GOOSE|SV"
  1053. // @Success 200 {object} ResultOK 成功
  1054. // @Failure 500 {object} ResultError 失败
  1055. // @router /admin/model/function/fcda-ref/list [get]
  1056. func (c *BusAdminController) GetFuncFcdaRef() {
  1057. modelid, _ := c.GetInt("model_id")
  1058. if modelid == 0 {
  1059. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1060. c.ServeJSON()
  1061. return
  1062. }
  1063. fcda_id, _ := c.GetInt("from_fcda_id")
  1064. if fcda_id == 0 {
  1065. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  1066. c.ServeJSON()
  1067. return
  1068. }
  1069. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  1070. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1071. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  1072. fcdaMgr.Model.ModelId = modelid
  1073. fcdaMgr.Model.FromFcdaId = fcda_id
  1074. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  1075. fcdaMgr.Model.Goosesv = c.GetString("goosesv")
  1076. lst, err := fcdaMgr.GetList()
  1077. if err != nil {
  1078. c.Data["json"] = c.ResultError(err.Error())
  1079. c.ServeJSON()
  1080. return
  1081. }
  1082. c.Data["json"] = c.ResultOK(lst, len(lst))
  1083. c.ServeJSON()
  1084. }
  1085. // @Summary 保存模型装置端子间关联关系
  1086. // @Description 保存模型装置端子间关联关系
  1087. // @Tags 业务管理服务
  1088. // @Accept x-www-form-urlencoded
  1089. // @Produce json
  1090. // @Param model_id formData int true "模型ID"
  1091. // @Param from_ied_type formData string true "输出装置类型"
  1092. // @Param to_ied_type formData string true "输入装置类型"
  1093. // @Param from_fcda_id formData int false "输出装置端子ID"
  1094. // @Param to_fcda_ids formData string false "输入装置端子ID"
  1095. // @Param batch_fcda_ids formData json-string true "批量保存端子关系。类型为序列化的二维数组字符串。数组元素为:[[fromfcdaid,tofcdaid],...]"
  1096. // @Param goosesv formData string true "信号类型。值范围:GOOSE|SV"
  1097. // @Success 200 {object} ResultOK 成功
  1098. // @Failure 500 {object} ResultError 失败
  1099. // @router /admin/model/function/fcda-ref/save [post]
  1100. func (c *BusAdminController) SaveFuncFcdaRef() {
  1101. modelid, _ := c.GetInt("model_id")
  1102. if modelid == 0 {
  1103. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1104. c.ServeJSON()
  1105. return
  1106. }
  1107. fcda_id, _ := c.GetInt("from_fcda_id")
  1108. if fcda_id == 0 {
  1109. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  1110. c.ServeJSON()
  1111. return
  1112. }
  1113. fcda_in_ids := c.GetString("to_fcda_ids")
  1114. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  1115. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1116. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  1117. fcdaMgr.Model.ModelId = modelid
  1118. fcdaMgr.Model.FromFcdaId = fcda_id
  1119. fcdaMgr.Model.FromIedCode = c.GetString("from_ied_type")
  1120. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  1121. fcdaMgr.Model.Goosesv = strings.ToUpper(c.GetString("goosesv"))
  1122. if fcdaMgr.Model.FromIedCode == "" || fcdaMgr.Model.ToIedCode == "" {
  1123. c.Data["json"] = c.ResultError("输入和输出装置类型不能为空!")
  1124. c.ServeJSON()
  1125. return
  1126. }
  1127. if fcdaMgr.Model.Goosesv == "" {
  1128. c.Data["json"] = c.ResultError("信号类型不能为空!")
  1129. c.ServeJSON()
  1130. return
  1131. }
  1132. if fcdaMgr.Model.Goosesv != "GOOSE" && fcdaMgr.Model.Goosesv != "SV" {
  1133. c.Data["json"] = c.ResultError("信号类型不正确。只能为GOOSE或SV")
  1134. c.ServeJSON()
  1135. return
  1136. }
  1137. batch_fcda_ids := c.GetString("batch_fcda_ids")
  1138. if batch_fcda_ids != "" {
  1139. //批量保存
  1140. fcdalist := [][]int{}
  1141. err := json.Unmarshal([]byte(batch_fcda_ids), &fcdalist)
  1142. if err != nil {
  1143. c.Data["json"] = c.ResultError("无效的批量端子关系数据")
  1144. c.ServeJSON()
  1145. return
  1146. }
  1147. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  1148. for _, item := range fcdalist {
  1149. fcdainf, err := obj.One(item[0])
  1150. if err != nil {
  1151. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[0]))
  1152. c.ServeJSON()
  1153. return
  1154. }
  1155. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  1156. fcdaMgr.Model.FromFcdaId = item[0]
  1157. fcdainf, err = obj.One(item[1])
  1158. if err != nil {
  1159. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[1]))
  1160. c.ServeJSON()
  1161. return
  1162. }
  1163. fcdaMgr.Model.ToFcdaId = item[1]
  1164. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  1165. err = fcdaMgr.Save()
  1166. if err != nil {
  1167. c.Data["json"] = c.ResultError(err.Error())
  1168. c.ServeJSON()
  1169. return
  1170. }
  1171. }
  1172. c.Data["json"] = c.ResultOK("", 0)
  1173. c.ServeJSON()
  1174. return
  1175. }
  1176. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  1177. fcdainf, er := obj.One(fcdaMgr.Model.FromFcdaId)
  1178. if er != nil {
  1179. c.Data["json"] = c.ResultError("无效的输出端子ID")
  1180. c.ServeJSON()
  1181. return
  1182. }
  1183. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  1184. //清除输出端子的原关系
  1185. err := fcdaMgr.Delete()
  1186. if err != nil {
  1187. c.Data["json"] = c.ResultError(err.Error())
  1188. c.ServeJSON()
  1189. return
  1190. }
  1191. if fcda_in_ids != "" {
  1192. fcda_in_ids_1 := strings.Split(fcda_in_ids, ",")
  1193. for _, k := range fcda_in_ids_1 {
  1194. fcdaMgr.Model.ToFcdaId, _ = strconv.Atoi(k) //设置接收端子id
  1195. fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId)
  1196. if er != nil {
  1197. c.Data["json"] = c.ResultError("无效的接收端子ID")
  1198. c.ServeJSON()
  1199. return
  1200. }
  1201. //清除接收端子的原关系
  1202. fcdaMgr.Model.FromFcdaId = 0
  1203. fcdaMgr.Delete()
  1204. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  1205. //建立新的端子关系
  1206. fcdaMgr.Model.FromFcdaId = fcda_id //还原输出端子id
  1207. err := fcdaMgr.Save()
  1208. if err != nil {
  1209. c.Data["json"] = c.ResultError(err.Error())
  1210. c.ServeJSON()
  1211. return
  1212. }
  1213. }
  1214. }
  1215. c.Data["json"] = c.ResultOK("", 0)
  1216. c.ServeJSON()
  1217. }
  1218. // @Summary 删除端子之间的关联关系
  1219. // @Description 删除端子之间的关联关系
  1220. // @Tags 业务管理服务
  1221. // @Accept x-www-form-urlencoded
  1222. // @Produce json
  1223. // @Param model_id formData int true "模型ID"
  1224. // @Param from_fcda_id formData int true "输入端子ID"
  1225. // @Param to_fcda_id formData int true "输出端子ID"
  1226. // @Success 200 {object} ResultOK 成功
  1227. // @Failure 500 {object} ResultError 失败
  1228. // @router /admin/model/function/fcda-ref/del [post]
  1229. func (c *BusAdminController) DelFuncFcdaRef() {
  1230. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  1231. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  1232. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  1233. fcdaMgr.Model.ModelId, _ = c.GetInt("model_id", 0)
  1234. fcdaMgr.Model.FromFcdaId, _ = c.GetInt("from_fcda_id", 0)
  1235. fcdaMgr.Model.ToFcdaId, _ = c.GetInt("to_fcda_id")
  1236. if fcdaMgr.Model.ModelId == 0 {
  1237. c.Data["json"] = c.ResultError("模型ID不能为空!")
  1238. c.ServeJSON()
  1239. return
  1240. }
  1241. if fcdaMgr.Model.FromFcdaId == 0 {
  1242. c.Data["json"] = c.ResultError("输入端子ID不能为空!")
  1243. c.ServeJSON()
  1244. return
  1245. }
  1246. if fcdaMgr.Model.ToFcdaId == 0 {
  1247. c.Data["json"] = c.ResultError("接收端子ID不能为空")
  1248. c.ServeJSON()
  1249. return
  1250. }
  1251. //清除原关系
  1252. err := fcdaMgr.Delete()
  1253. if err != nil {
  1254. c.Data["json"] = c.ResultError(err.Error())
  1255. c.ServeJSON()
  1256. return
  1257. }
  1258. c.Data["json"] = c.ResultOK("", 0)
  1259. c.ServeJSON()
  1260. }