busAdminController.go 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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, IsSys: 1}
  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. 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("", 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. // @Success 200 {object} ResultOK 成功
  304. // @Failure 500 {object} ResultError 失败
  305. // @router /admin/sysmodel/saveas [post]
  306. func (c *BusAdminController) CopySysModelByID() {
  307. id, _ := c.GetInt("id")
  308. if id == 0 {
  309. c.Data["json"] = c.ResultError("id不能为空!")
  310. c.ServeJSON()
  311. return
  312. }
  313. new_name := c.GetString("newname")
  314. obj := new(bo.SysCheckModelMgr)
  315. obj.SetUserInfo(c.GetCurrentUserInfo())
  316. obj.Model = bo.T_data_model_defualt{Id: id}
  317. obj.Model.Id = id
  318. obj.Model.ModelName = new_name
  319. err, newid := obj.Copy(id)
  320. if err != nil {
  321. c.Data["json"] = c.ResultError(err.Error())
  322. c.ServeJSON()
  323. return
  324. }
  325. c.Data["json"] = c.ResultOK(newid, 0)
  326. c.ServeJSON()
  327. }
  328. // @Summary 删除指定的检测模型
  329. // @Description 删除指定的检测模型
  330. // @Tags 业务管理服务
  331. // @Accept x-www-form-urlencoded
  332. // @Produce json
  333. // @Param id formData int true "模型ID"
  334. // @Success 200 {object} ResultOK 成功
  335. // @Failure 500 {object} ResultError 失败
  336. // @router /admin/sysmodel/delete [post]
  337. func (c *BusAdminController) DeleteSysModelByID() {
  338. id, _ := c.GetInt("id")
  339. if id == 0 {
  340. c.Data["json"] = c.ResultError("id不能为空!")
  341. c.ServeJSON()
  342. return
  343. }
  344. obj := new(bo.SysCheckModelMgr)
  345. obj.SetUserInfo(c.GetCurrentUserInfo())
  346. obj.Model = bo.T_data_model_defualt{Id: id}
  347. obj.Model.Id = id
  348. err := obj.Delete()
  349. if err != nil {
  350. c.Data["json"] = c.ResultError(err.Error())
  351. c.ServeJSON()
  352. return
  353. }
  354. c.Data["json"] = c.ResultOK("", 0)
  355. c.ServeJSON()
  356. }
  357. // @Summary 查询检测模型列表
  358. // @Description 查询检测模型列表。支持名称、电压等级等过滤条件
  359. // @Tags 检测任务服务接口
  360. // @Accept x-www-form-urlencoded
  361. // @Produce json
  362. // @Param pageno query int true "当前页码。默认为1"
  363. // @Param pagesize query int true "每页显示数据数。默认为20"
  364. // @Param id query int false "ID"
  365. // @Param vol_id query int false "电压等级ID"
  366. // @Param model_name query string false "名称"
  367. // @Param line_link_style query int false "接线方式"
  368. // @Param area_type query int false "间隔类型"
  369. // @Param is_sys query int false "模型类型。1 内置模型 2 自定义模型"
  370. // @Success 200 {object} ResultOK 成功
  371. // @Failure 500 {object} ResultError 失败
  372. // @router /admin/sysmodel/list [get]
  373. func (c *BusAdminController) GetSysModelList() {
  374. obj := new(bo.SysCheckModelMgr)
  375. obj.SetUserInfo(c.GetCurrentUserInfo())
  376. obj.Model = bo.T_data_model_defualt{}
  377. obj.Model.Id, _ = c.GetInt("id")
  378. obj.Model.IsSys, _ = c.GetInt("is_sys", 1) //默认查询系统内置模型
  379. obj.Model.VolId, _ = c.GetInt("vol_id")
  380. obj.Model.ModelName = c.GetString("model_name")
  381. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  382. obj.Model.AreaType, _ = c.GetInt("area_type")
  383. pi, _ := c.GetInt("pagesize", 20)
  384. po, _ := c.GetInt("pageno", 0)
  385. if po == 0 {
  386. po, _ = c.GetInt("pageindex", 0)
  387. }
  388. if po == 0 {
  389. po = 1
  390. }
  391. lst, cnt, err := obj.List(po, pi)
  392. if err != nil {
  393. c.Data["json"] = c.ResultError(err.Error())
  394. c.ServeJSON()
  395. return
  396. }
  397. //如果是获取指定模型信息时,附加模型的标准装置类型信息
  398. if obj.Model.Id > 0 {
  399. //间隔类型id
  400. syscode := new(bo.Global)
  401. codeinfo := syscode.GetCodeInfoByID(tools.IsEmpty(lst[0]["area_type"]))
  402. if codeinfo != nil {
  403. code := "area_type_" + tools.IsEmpty(codeinfo["code"])
  404. codeinfo = syscode.GetCodeInfoByCode("area_ied_type", code)
  405. codes := strings.Split(tools.IsEmpty(codeinfo["name"]), ",")
  406. ccrows := []orm.Params{}
  407. for _, item := range codes {
  408. tmp := syscode.GetCodeInfoByCode("ied_type", item)
  409. if tmp == nil {
  410. ccrows = append(ccrows, orm.Params{"code": item, "name": item})
  411. } else {
  412. ccrows = append(ccrows, tmp)
  413. }
  414. }
  415. lst[0]["ied_type"] = ccrows
  416. }
  417. }
  418. c.Data["json"] = c.ResultOK(lst, cnt)
  419. c.ServeJSON()
  420. }
  421. // @Summary 重新分析指定的SCD检测模型间隔
  422. // @Description 重新分析指定的SCD检测模型间隔
  423. // @Tags 业务管理服务
  424. // @Accept x-www-form-urlencoded
  425. // @Produce json
  426. // @Param scd_id formData int true "SCD文件ID"
  427. // @Success 200 {object} ResultOK 成功
  428. // @Failure 500 {object} ResultError 失败
  429. // @router /admin/parse/check_area [post]
  430. func (c *BusAdminController) ResetCheckAreaByID() {
  431. id, _ := c.GetInt64("scd_id")
  432. if id == 0 {
  433. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  434. c.ServeJSON()
  435. return
  436. }
  437. obj := new(bo.CheckAreaMgr)
  438. obj.SetUserInfo(c.GetCurrentUserInfo())
  439. obj.ScdId = id
  440. err := obj.Reset()
  441. if err != nil {
  442. c.Data["json"] = c.ResultError(err.Error())
  443. c.ServeJSON()
  444. return
  445. }
  446. c.Data["json"] = c.ResultOK("", 0)
  447. c.ServeJSON()
  448. }
  449. // @Summary 查询指定电压等级及接线方式下的检测间隔分析结果
  450. // @Description 查询指定电压等级及接线方式下的检测间隔分析结果
  451. // @Tags 业务管理服务
  452. // @Accept x-www-form-urlencoded
  453. // @Produce json
  454. // @Param scd_id formData int true "SCD文件ID"
  455. // @Param vol_id formData int false "电压等级ID"
  456. // @Param link_style_id formData int false "接线方式ID"
  457. // @Success 200 {object} ResultOK 成功
  458. // @Failure 500 {object} ResultError 失败
  459. // @router /admin/get/check_area [get]
  460. func (c *BusAdminController) GetCheckAreaByVolID() {
  461. id, _ := c.GetInt64("scd_id")
  462. if id == 0 {
  463. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  464. c.ServeJSON()
  465. return
  466. }
  467. volid, _ := c.GetInt("vol_id")
  468. lsid, _ := c.GetInt("link_style_id")
  469. obj := new(bo.CheckAreaMgr)
  470. obj.SetUserInfo(c.GetCurrentUserInfo())
  471. obj.ScdId = id
  472. lst, err := obj.GetAreaListByVol(id, volid, lsid)
  473. if err != nil {
  474. c.Data["json"] = c.ResultError(err.Error())
  475. c.ServeJSON()
  476. return
  477. }
  478. if lst == nil || len(lst) == 0 {
  479. //新分析
  480. err = obj.Reset()
  481. if err != nil {
  482. c.Data["json"] = c.ResultError(err.Error())
  483. c.ServeJSON()
  484. return
  485. }
  486. lst, _ = obj.GetAreaListByVol(id, volid, lsid)
  487. }
  488. c.Data["json"] = c.ResultOK(lst, 0)
  489. c.ServeJSON()
  490. }
  491. // @Summary 查询指定检测间隔下的IED装置列表
  492. // @Description 查询指定检测间隔下的IED装置列表
  493. // @Tags 业务管理服务
  494. // @Accept x-www-form-urlencoded
  495. // @Produce json
  496. // @Param scd_id formData int true "SCD文件ID"
  497. // @Param area_id formData int true "检测间隔ID"
  498. // @Success 200 {object} ResultOK 成功
  499. // @Failure 500 {object} ResultError 失败
  500. // @router /admin/get/check_area/ied [get]
  501. func (c *BusAdminController) GetCheckAreaIedByAreaID() {
  502. id, _ := c.GetInt64("scd_id")
  503. if id == 0 {
  504. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  505. c.ServeJSON()
  506. return
  507. }
  508. area_id, _ := c.GetInt("area_id")
  509. obj := new(bo.CheckAreaMgr)
  510. obj.SetUserInfo(c.GetCurrentUserInfo())
  511. obj.ScdId = id
  512. lst, err := obj.GetIedList(id, area_id)
  513. if err != nil {
  514. c.Data["json"] = c.ResultError(err.Error())
  515. c.ServeJSON()
  516. return
  517. }
  518. c.Data["json"] = c.ResultOK(lst, 0)
  519. c.ServeJSON()
  520. }
  521. // @Summary 修改并保存指定检测间隔下的IED装置列表
  522. // @Description 修改并保存指定检测间隔下的IED装置列表
  523. // @Tags 业务管理服务
  524. // @Accept x-www-form-urlencoded
  525. // @Produce json
  526. // @Param scd_id formData int true "SCD文件ID"
  527. // @Param area_id formData int true "检测间隔ID"
  528. // @Param ied_ids formData string true "IED装置name列表,多个ied采用逗号分隔。如:PT1001,PL1001,..."
  529. // @Success 200 {object} ResultOK 成功
  530. // @Failure 500 {object} ResultError 失败
  531. // @router /admin/update/check_area/ied [post]
  532. func (c *BusAdminController) SaveCheckAreaIedByAreaID() {
  533. id, _ := c.GetInt64("scd_id")
  534. if id == 0 {
  535. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  536. c.ServeJSON()
  537. return
  538. }
  539. area_id, _ := c.GetInt("area_id")
  540. ieds := c.GetString("ied_ids")
  541. if area_id == 0 {
  542. c.Data["json"] = c.ResultError("检测间隔ID不能为空!")
  543. c.ServeJSON()
  544. return
  545. }
  546. if ieds == "" {
  547. c.Data["json"] = c.ResultError("检测间隔装置列表不能为空!")
  548. c.ServeJSON()
  549. return
  550. }
  551. obj := new(bo.CheckAreaMgr)
  552. obj.SetUserInfo(c.GetCurrentUserInfo())
  553. obj.ScdId = id
  554. err := obj.UpdateIeds(id, area_id, ieds)
  555. if err != nil {
  556. c.Data["json"] = c.ResultError(err.Error())
  557. c.ServeJSON()
  558. return
  559. }
  560. c.Data["json"] = c.ResultOK("", 0)
  561. c.ServeJSON()
  562. }
  563. // @Summary 获取指定模型和装置类型的功能列表
  564. // @Description 获取指定模型和装置类型的功能列表
  565. // @Tags 业务管理服务
  566. // @Accept x-www-form-urlencoded
  567. // @Produce json
  568. // @Param model_id formData int true "模型ID"
  569. // @Param ied_type formData string true "装置类型"
  570. // @Success 200 {object} ResultOK 成功
  571. // @Failure 500 {object} ResultError 失败
  572. // @router /admin/model/function/list [get]
  573. func (c *BusAdminController) GetFuncListByIedType() {
  574. modelid, _ := c.GetInt("model_id")
  575. if modelid == 0 {
  576. c.Data["json"] = c.ResultError("模型ID不能为空!")
  577. c.ServeJSON()
  578. return
  579. }
  580. ied_type := c.GetString("ied_type")
  581. if ied_type == "" {
  582. c.Data["json"] = c.ResultError("装置类型不能为空!")
  583. c.ServeJSON()
  584. return
  585. }
  586. obj := new(bo.SysCheckModelIedFuncMgr)
  587. obj.SetUserInfo(c.GetCurrentUserInfo())
  588. lst, err := obj.GetList(modelid, ied_type)
  589. if err != nil {
  590. c.Data["json"] = c.ResultError(err.Error())
  591. c.ServeJSON()
  592. return
  593. }
  594. c.Data["json"] = c.ResultOK(lst, 0)
  595. c.ServeJSON()
  596. }
  597. // @Summary 获取指定模型和装置类型的端子列表
  598. // @Description 获取指定模型和装置类型的端子列表
  599. // @Tags 业务管理服务
  600. // @Accept x-www-form-urlencoded
  601. // @Produce json
  602. // @Param model_id formData int true "模型ID"
  603. // @Param ied_type formData string true "装置类型"
  604. // @Param sv_or_goose formData string true "信号类型。仅支持:SV或GOOSE"
  605. // @Param in_or_out formData string true "信号方向。仅支持:'输出'或'接收'"
  606. // @Success 200 {object} ResultOK 成功
  607. // @Failure 500 {object} ResultError 失败
  608. // @router /admin/model/function/fcda/list [get]
  609. func (c *BusAdminController) GetFuncFcdaList() {
  610. modelid, _ := c.GetInt("model_id")
  611. if modelid == 0 {
  612. c.Data["json"] = c.ResultError("模型ID不能为空!")
  613. c.ServeJSON()
  614. return
  615. }
  616. ied_type := c.GetString("ied_type")
  617. if ied_type == "" {
  618. c.Data["json"] = c.ResultError("装置类型不能为空!")
  619. c.ServeJSON()
  620. return
  621. }
  622. obj := new(bo.SysCheckModelIedFuncMgr)
  623. obj.SetUserInfo(c.GetCurrentUserInfo())
  624. lst, err := obj.GetList(modelid, ied_type)
  625. if err != nil {
  626. c.Data["json"] = c.ResultError(err.Error())
  627. c.ServeJSON()
  628. return
  629. }
  630. funcids := []string{}
  631. for _, row := range lst {
  632. funcids = append(funcids, tools.IsEmpty(row["id"]))
  633. }
  634. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  635. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  636. fcdaMgr.Model.ModelId = modelid
  637. fcdaMgr.Model.Svorgoose = strings.ToUpper(c.GetString("sv_or_goose"))
  638. fcdaMgr.Model.Inorout = c.GetString("in_or_out")
  639. fcdaList, err := fcdaMgr.GetList(funcids)
  640. if err != nil {
  641. c.Data["json"] = c.ResultError(err.Error())
  642. c.ServeJSON()
  643. return
  644. }
  645. c.Data["json"] = c.ResultOK(fcdaList, len(fcdaList))
  646. c.ServeJSON()
  647. }
  648. // @Summary 保存模型装置功能及端子信息
  649. // @Description 保存装置功能及端子信息
  650. // @Tags 业务管理服务
  651. // @Accept x-www-form-urlencoded
  652. // @Produce json
  653. // @Param model_id formData int true "模型ID"
  654. // @Param ied_type formData string true "装置类型代码"
  655. // @Param func_id formData int false "功能ID。编辑时必传。"
  656. // @Param func_name formData string true "功能名称。必传。"
  657. // @Param fcda_id formData int false "端子ID。编辑时必传。"
  658. // @Param fcda_name formData string true "端子名称。必传。"
  659. // @Param fcda_match_exp formData string true "端子匹配表达式。必传。"
  660. // @Param sv_or_goose formData string true "端子信号类型。必传。仅支持SV或GOOSE"
  661. // @Param in_or_out formData string true "端子信号输入输出方向。必传。仅支持中文的'接收'或'输出'"
  662. // @Success 200 {object} ResultOK 成功
  663. // @Failure 500 {object} ResultError 失败
  664. // @router /admin/model/function/fcda/save [post]
  665. func (c *BusAdminController) SaveFuncFcda() {
  666. modelid, _ := c.GetInt("model_id")
  667. if modelid == 0 {
  668. c.Data["json"] = c.ResultError("模型ID不能为空!")
  669. c.ServeJSON()
  670. return
  671. }
  672. ied_type := c.GetString("ied_type")
  673. func_name := c.GetString("func_name")
  674. fcda_name := c.GetString("fcda_name")
  675. fcda_match_exp := c.GetString("fcda_match_exp")
  676. func_id, _ := c.GetInt("func_id")
  677. fcda_id, _ := c.GetInt("fcda_id")
  678. svorgoose := c.GetString("sv_or_goose")
  679. inorout := c.GetString("in_or_out")
  680. if func_name == "" {
  681. c.Data["json"] = c.ResultError("功能名称不能为空!")
  682. c.ServeJSON()
  683. return
  684. }
  685. if fcda_name == "" {
  686. c.Data["json"] = c.ResultError("端子设计名称不能为空!")
  687. c.ServeJSON()
  688. return
  689. }
  690. if fcda_match_exp == "" {
  691. c.Data["json"] = c.ResultError("端子匹配关键词不能为空!")
  692. c.ServeJSON()
  693. return
  694. }
  695. if svorgoose == "" {
  696. c.Data["json"] = c.ResultError("端子信号类型不能为空!")
  697. c.ServeJSON()
  698. return
  699. }
  700. if inorout == "" {
  701. c.Data["json"] = c.ResultError("端子信号方向不能为空!")
  702. c.ServeJSON()
  703. return
  704. }
  705. mod := bo.T_data_model_func_def{}
  706. mod.Id = func_id
  707. mod.ModelId = modelid
  708. mod.IedType = ied_type
  709. mod.FuncFcdaId = fcda_id
  710. mod.FuncName = func_name
  711. mod.FcdaName = fcda_name
  712. mod.FcdaMatchExp = fcda_match_exp
  713. mod.Svorgoose = svorgoose
  714. mod.Inorout = inorout
  715. mgr := new(bo.SysCheckModelIedFuncMgr)
  716. mgr.SetUserInfo(c.GetCurrentUserInfo())
  717. mgr.Model = mod
  718. err := mgr.Save()
  719. if err != nil {
  720. c.Data["json"] = c.ResultError(err.Error())
  721. c.ServeJSON()
  722. return
  723. }
  724. c.Data["json"] = c.ResultOK("", 0)
  725. c.ServeJSON()
  726. }
  727. // @Summary 删除指定模型所有的装置端子
  728. // @Description 删除指定模型所有的装置端子
  729. // @Tags 业务管理服务
  730. // @Accept x-www-form-urlencoded
  731. // @Produce json
  732. // @Param model_id formData int true "模型ID"
  733. // @Success 200 {object} ResultOK 成功
  734. // @Failure 500 {object} ResultError 失败
  735. // @router /admin/model/fcda/delall [post]
  736. func (c *BusAdminController) DelAllFuncFcda() {
  737. modelid, _ := c.GetInt("model_id")
  738. if modelid == 0 {
  739. c.Data["json"] = c.ResultError("模型ID不能为空!")
  740. c.ServeJSON()
  741. return
  742. }
  743. fcdaMgr := new(bo.SysCheckModelIedFuncMgr)
  744. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  745. fcdaMgr.Model = bo.T_data_model_func_def{}
  746. fcdaMgr.Model.ModelId = modelid
  747. err := fcdaMgr.Delete()
  748. if err != nil {
  749. c.Data["json"] = c.ResultError(err.Error())
  750. c.ServeJSON()
  751. return
  752. }
  753. c.Data["json"] = c.ResultOK("", 0)
  754. c.ServeJSON()
  755. }
  756. // @Summary 删除装置端子
  757. // @Description 删除装置端子
  758. // @Tags 业务管理服务
  759. // @Accept x-www-form-urlencoded
  760. // @Produce json
  761. // @Param model_id formData int true "模型ID"
  762. // @Param fcda_id formData int true "端子ID"
  763. // @Success 200 {object} ResultOK 成功
  764. // @Failure 500 {object} ResultError 失败
  765. // @router /admin/model/function/fcda/del [post]
  766. func (c *BusAdminController) DelFuncFcda() {
  767. modelid, _ := c.GetInt("model_id")
  768. if modelid == 0 {
  769. c.Data["json"] = c.ResultError("模型ID不能为空!")
  770. c.ServeJSON()
  771. return
  772. }
  773. fcda_id, _ := c.GetInt("fcda_id")
  774. if fcda_id == 0 {
  775. c.Data["json"] = c.ResultError("端子ID不能为空!")
  776. c.ServeJSON()
  777. return
  778. }
  779. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  780. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  781. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  782. fcdaMgr.Model.ModelId = modelid
  783. fcdaMgr.Model.Id = fcda_id
  784. err := fcdaMgr.Delete()
  785. if err != nil {
  786. c.Data["json"] = c.ResultError(err.Error())
  787. c.ServeJSON()
  788. return
  789. }
  790. c.Data["json"] = c.ResultOK("", 0)
  791. c.ServeJSON()
  792. }
  793. // @Summary 获取模型装置端子已关联的接收端子
  794. // @Description 获取模型装置端子已关联的接收端子
  795. // @Tags 业务管理服务
  796. // @Accept x-www-form-urlencoded
  797. // @Produce json
  798. // @Param model_id formData int true "模型ID"
  799. // @Param from_fcda_id formData int true "输出装置端子ID"
  800. // @Param to_ied_type formData string false "输入装置类型"
  801. // @Param goosesv formData string false "信号类型。GOOSE|SV"
  802. // @Success 200 {object} ResultOK 成功
  803. // @Failure 500 {object} ResultError 失败
  804. // @router /admin/model/function/fcda-ref/list [get]
  805. func (c *BusAdminController) GetFuncFcdaRef() {
  806. modelid, _ := c.GetInt("model_id")
  807. if modelid == 0 {
  808. c.Data["json"] = c.ResultError("模型ID不能为空!")
  809. c.ServeJSON()
  810. return
  811. }
  812. fcda_id, _ := c.GetInt("from_fcda_id")
  813. if fcda_id == 0 {
  814. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  815. c.ServeJSON()
  816. return
  817. }
  818. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  819. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  820. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  821. fcdaMgr.Model.ModelId = modelid
  822. fcdaMgr.Model.FromFcdaId = fcda_id
  823. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  824. fcdaMgr.Model.Goosesv = c.GetString("goosesv")
  825. lst, err := fcdaMgr.GetList()
  826. if err != nil {
  827. c.Data["json"] = c.ResultError(err.Error())
  828. c.ServeJSON()
  829. return
  830. }
  831. c.Data["json"] = c.ResultOK(lst, len(lst))
  832. c.ServeJSON()
  833. }
  834. // @Summary 保存模型装置端子间关联关系
  835. // @Description 保存模型装置端子间关联关系
  836. // @Tags 业务管理服务
  837. // @Accept x-www-form-urlencoded
  838. // @Produce json
  839. // @Param model_id formData int true "模型ID"
  840. // @Param from_ied_type formData string true "输出装置类型"
  841. // @Param to_ied_type formData string true "输入装置类型"
  842. // @Param from_fcda_id formData int false "输出装置端子ID"
  843. // @Param to_fcda_ids formData string false "输入装置端子ID"
  844. // @Param batch_fcda_ids formData json-string true "批量保存端子关系。类型为序列化的二维数组字符串。数组元素为:[[fromfcdaid,tofcdaid],...]"
  845. // @Param goosesv formData string true "信号类型。值范围:GOOSE|SV"
  846. // @Success 200 {object} ResultOK 成功
  847. // @Failure 500 {object} ResultError 失败
  848. // @router /admin/model/function/fcda-ref/save [post]
  849. func (c *BusAdminController) SaveFuncFcdaRef() {
  850. modelid, _ := c.GetInt("model_id")
  851. if modelid == 0 {
  852. c.Data["json"] = c.ResultError("模型ID不能为空!")
  853. c.ServeJSON()
  854. return
  855. }
  856. fcda_id, _ := c.GetInt("from_fcda_id")
  857. if fcda_id == 0 {
  858. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  859. c.ServeJSON()
  860. return
  861. }
  862. fcda_in_ids := c.GetString("to_fcda_ids")
  863. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  864. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  865. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  866. fcdaMgr.Model.ModelId = modelid
  867. fcdaMgr.Model.FromFcdaId = fcda_id
  868. fcdaMgr.Model.FromIedCode = c.GetString("from_ied_type")
  869. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  870. fcdaMgr.Model.Goosesv = strings.ToUpper(c.GetString("goosesv"))
  871. if fcdaMgr.Model.FromIedCode == "" || fcdaMgr.Model.ToIedCode == "" {
  872. c.Data["json"] = c.ResultError("输入和输出装置类型不能为空!")
  873. c.ServeJSON()
  874. return
  875. }
  876. if fcdaMgr.Model.Goosesv == "" {
  877. c.Data["json"] = c.ResultError("信号类型不能为空!")
  878. c.ServeJSON()
  879. return
  880. }
  881. if fcdaMgr.Model.Goosesv != "GOOSE" && fcdaMgr.Model.Goosesv != "SV" {
  882. c.Data["json"] = c.ResultError("信号类型不正确。只能为GOOSE或SV")
  883. c.ServeJSON()
  884. return
  885. }
  886. batch_fcda_ids := c.GetString("batch_fcda_ids")
  887. if batch_fcda_ids != "" {
  888. //批量保存
  889. fcdalist := [][]int{}
  890. err := json.Unmarshal([]byte(batch_fcda_ids), &fcdalist)
  891. if err != nil {
  892. c.Data["json"] = c.ResultError("无效的批量端子关系数据")
  893. c.ServeJSON()
  894. return
  895. }
  896. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  897. for _, item := range fcdalist {
  898. fcdainf, err := obj.One(item[0])
  899. if err != nil {
  900. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[0]))
  901. c.ServeJSON()
  902. return
  903. }
  904. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  905. fcdaMgr.Model.FromFcdaId = item[0]
  906. fcdainf, err = obj.One(item[1])
  907. if err != nil {
  908. c.Data["json"] = c.ResultError(fmt.Sprintf("无效的端子ID:%d", item[1]))
  909. c.ServeJSON()
  910. return
  911. }
  912. fcdaMgr.Model.ToFcdaId = item[1]
  913. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  914. err = fcdaMgr.Save()
  915. if err != nil {
  916. c.Data["json"] = c.ResultError(err.Error())
  917. c.ServeJSON()
  918. return
  919. }
  920. }
  921. c.Data["json"] = c.ResultOK("", 0)
  922. c.ServeJSON()
  923. return
  924. }
  925. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  926. fcdainf, er := obj.One(fcdaMgr.Model.FromFcdaId)
  927. if er != nil {
  928. c.Data["json"] = c.ResultError("无效的输出端子ID")
  929. c.ServeJSON()
  930. return
  931. }
  932. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  933. //清除原关系
  934. err := fcdaMgr.Delete()
  935. if err != nil {
  936. c.Data["json"] = c.ResultError(err.Error())
  937. c.ServeJSON()
  938. return
  939. }
  940. if fcda_in_ids != "" {
  941. fcda_in_ids_1 := strings.Split(fcda_in_ids, ",")
  942. for _, k := range fcda_in_ids_1 {
  943. fcdaMgr.Model.ToFcdaId, _ = strconv.Atoi(k)
  944. fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId)
  945. if er != nil {
  946. c.Data["json"] = c.ResultError("无效的输入端子ID")
  947. c.ServeJSON()
  948. return
  949. }
  950. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  951. err := fcdaMgr.Save()
  952. if err != nil {
  953. c.Data["json"] = c.ResultError(err.Error())
  954. c.ServeJSON()
  955. return
  956. }
  957. }
  958. }
  959. c.Data["json"] = c.ResultOK("", 0)
  960. c.ServeJSON()
  961. }
  962. // @Summary 删除端子之间的关联关系
  963. // @Description 删除端子之间的关联关系
  964. // @Tags 业务管理服务
  965. // @Accept x-www-form-urlencoded
  966. // @Produce json
  967. // @Param model_id formData int true "模型ID"
  968. // @Param from_fcda_id formData int true "输入端子ID"
  969. // @Param to_fcda_id formData int true "输出端子ID"
  970. // @Success 200 {object} ResultOK 成功
  971. // @Failure 500 {object} ResultError 失败
  972. // @router /admin/model/function/fcda-ref/del [post]
  973. func (c *BusAdminController) DelFuncFcdaRef() {
  974. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  975. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  976. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  977. fcdaMgr.Model.ModelId, _ = c.GetInt("model_id", 0)
  978. fcdaMgr.Model.FromFcdaId, _ = c.GetInt("from_fcda_id", 0)
  979. fcdaMgr.Model.ToFcdaId, _ = c.GetInt("to_fcda_id")
  980. if fcdaMgr.Model.ModelId == 0 {
  981. c.Data["json"] = c.ResultError("模型ID不能为空!")
  982. c.ServeJSON()
  983. return
  984. }
  985. if fcdaMgr.Model.FromFcdaId == 0 {
  986. c.Data["json"] = c.ResultError("输入端子ID不能为空!")
  987. c.ServeJSON()
  988. return
  989. }
  990. if fcdaMgr.Model.ToFcdaId == 0 {
  991. c.Data["json"] = c.ResultError("接收端子ID不能为空")
  992. c.ServeJSON()
  993. return
  994. }
  995. //清除原关系
  996. err := fcdaMgr.Delete()
  997. if err != nil {
  998. c.Data["json"] = c.ResultError(err.Error())
  999. c.ServeJSON()
  1000. return
  1001. }
  1002. c.Data["json"] = c.ResultOK("", 0)
  1003. c.ServeJSON()
  1004. }