busAdminController.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. /*
  2. * @Author: lilig
  3. * @Date: 2023-10-10 15:22:58
  4. * @LastEditors: lilifor
  5. * @LastEditTime: 2023-10-10 15:22:58
  6. * @FilePath: \SCD\controllers\TaskController.go
  7. * @Description:
  8. *
  9. * Copyright (c) 2023 by lilig/jujutong, All Rights Reserved.
  10. */
  11. package controllers
  12. import (
  13. "scd_check_tools/models/bo"
  14. "scd_check_tools/tools"
  15. "strconv"
  16. "strings"
  17. "github.com/astaxie/beego/orm"
  18. )
  19. //业务管理服务
  20. type BusAdminController struct {
  21. BaseController
  22. }
  23. func init() {
  24. }
  25. // @Summary 创建新的接线方式
  26. // @Description 创建新的接线方式
  27. // @Tags 业务管理服务
  28. // @Accept x-www-form-urlencoded
  29. // @Produce json
  30. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  31. // @Param name formData string true "任务名称"
  32. // @Param vol_id formData int true "电压等级ID"
  33. // @Param pic formData string false "接线图地址"
  34. // @Success 200 {object} ResultOK 成功
  35. // @Failure 500 {object} ResultError 失败
  36. // @router /admin/linkstyle/save [post]
  37. func (c *BusAdminController) SaveLinkStyleInfo() {
  38. id, _ := c.GetInt("id")
  39. obj := new(bo.LinkStyleMgr)
  40. obj.SetUserInfo(c.GetCurrentUserInfo())
  41. obj.Model = bo.T_data_link_style{Id: id}
  42. obj.Model.Name = c.GetString("name")
  43. obj.Model.VolLevelId, _ = c.GetInt("vol_id")
  44. obj.Model.Pic = c.GetString("pic")
  45. if obj.Model.Name == "" {
  46. c.Data["json"] = c.ResultError("名称不能为空")
  47. c.ServeJSON()
  48. return
  49. }
  50. if obj.Model.VolLevelId == 0 {
  51. c.Data["json"] = c.ResultError("电压等级不能为空")
  52. c.ServeJSON()
  53. return
  54. }
  55. err := obj.Save()
  56. if err != nil {
  57. c.Data["json"] = c.ResultError(err.Error())
  58. c.ServeJSON()
  59. return
  60. }
  61. c.Data["json"] = c.ResultOK("", 0)
  62. c.ServeJSON()
  63. }
  64. // @Summary 删除指定的接线方式
  65. // @Description 删除指定的接线方式
  66. // @Tags 业务管理服务
  67. // @Accept x-www-form-urlencoded
  68. // @Produce json
  69. // @Param id formData int true "接线方式ID"
  70. // @Success 200 {object} ResultOK 成功
  71. // @Failure 500 {object} ResultError 失败
  72. // @router /admin/linkstyle/delete [post]
  73. func (c *BusAdminController) DeleteLinkStyleByID() {
  74. id, _ := c.GetInt("id")
  75. if id == 0 {
  76. c.Data["json"] = c.ResultError("id不能为空!")
  77. c.ServeJSON()
  78. return
  79. }
  80. obj := new(bo.LinkStyleMgr)
  81. obj.SetUserInfo(c.GetCurrentUserInfo())
  82. obj.Model = bo.T_data_link_style{}
  83. obj.Model.Id = id
  84. err := obj.Delete()
  85. if err != nil {
  86. c.Data["json"] = c.ResultError(err.Error())
  87. c.ServeJSON()
  88. return
  89. }
  90. c.Data["json"] = c.ResultOK("", 0)
  91. c.ServeJSON()
  92. }
  93. // @Summary 查询接线方式
  94. // @Description 查询接线方式。支持名称、电压等级等过滤条件
  95. // @Tags 检测任务服务接口
  96. // @Accept x-www-form-urlencoded
  97. // @Produce json
  98. // @Param pageno query int true "当前页码。默认为1"
  99. // @Param pagesize query int true "每页显示数据数。默认为20"
  100. // @Param id query int false "ID"
  101. // @Param vol_id query int false "电压ID"
  102. // @Param name query string false "名称"
  103. // @Success 200 {object} ResultOK 成功
  104. // @Failure 500 {object} ResultError 失败
  105. // @router /admin/linkstyle/list [get]
  106. func (c *BusAdminController) GetLinkStyleList() {
  107. obj := new(bo.LinkStyleMgr)
  108. obj.SetUserInfo(c.GetCurrentUserInfo())
  109. obj.Model = bo.T_data_link_style{}
  110. obj.Model.Id, _ = c.GetInt("id")
  111. obj.Model.VolLevelId, _ = c.GetInt("vol_id")
  112. obj.Model.Name = c.GetString("name")
  113. pi, _ := c.GetInt("pagesize", 20)
  114. po, _ := c.GetInt("pageno", 0)
  115. if po == 0 {
  116. po, _ = c.GetInt("pageindex", 0)
  117. }
  118. if po == 0 {
  119. po = 1
  120. }
  121. lst, cnt, err := obj.List(po, pi)
  122. if err != nil {
  123. c.Data["json"] = c.ResultError(err.Error())
  124. c.ServeJSON()
  125. return
  126. }
  127. c.Data["json"] = c.ResultOK(lst, cnt)
  128. c.ServeJSON()
  129. }
  130. // @Summary 添加接线方式的模型
  131. // @Description 添加接线方式的模型
  132. // @Tags 业务管理服务
  133. // @Accept x-www-form-urlencoded
  134. // @Produce json
  135. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  136. // @Param linkstyle_id formData int true "接线方式ID"
  137. // @Param model_id formData int true "内置模型id"
  138. // @Success 200 {object} ResultOK 成功
  139. // @Failure 500 {object} ResultError 失败
  140. // @router /admin/linkstyle-model/save [post]
  141. func (c *BusAdminController) SaveLinkStyleModelInfo() {
  142. id, _ := c.GetInt("id")
  143. obj := new(bo.LinkStyleModelMgr)
  144. obj.SetUserInfo(c.GetCurrentUserInfo())
  145. obj.Model = bo.T_data_link_style_model{Id: id}
  146. obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id")
  147. obj.Model.ModelId, _ = c.GetInt("model_id")
  148. if obj.Model.LinkstyleId == 0 {
  149. c.Data["json"] = c.ResultError("接线方式不能为空")
  150. c.ServeJSON()
  151. return
  152. }
  153. if obj.Model.ModelId == 0 {
  154. c.Data["json"] = c.ResultError("模型ID不能为空")
  155. c.ServeJSON()
  156. return
  157. }
  158. err := obj.Save()
  159. if err != nil {
  160. c.Data["json"] = c.ResultError(err.Error())
  161. c.ServeJSON()
  162. return
  163. }
  164. c.Data["json"] = c.ResultOK("", 0)
  165. c.ServeJSON()
  166. }
  167. // @Summary 删除指定接线方式下属的模型
  168. // @Description 删除指定接线方式下属的模型
  169. // @Tags 业务管理服务
  170. // @Accept x-www-form-urlencoded
  171. // @Produce json
  172. // @Param id formData int true "接线方式ID"
  173. // @Param model_id formData int true "模型ID"
  174. // @Success 200 {object} ResultOK 成功
  175. // @Failure 500 {object} ResultError 失败
  176. // @router /admin/linkstyle-model/delete [post]
  177. func (c *BusAdminController) DeleteLinkStyleModelByID() {
  178. id, _ := c.GetInt("id")
  179. if id == 0 {
  180. c.Data["json"] = c.ResultError("id不能为空!")
  181. c.ServeJSON()
  182. return
  183. }
  184. model_id, _ := c.GetInt("model_id")
  185. if model_id == 0 {
  186. c.Data["json"] = c.ResultError("模型id不能为空!")
  187. c.ServeJSON()
  188. return
  189. }
  190. obj := new(bo.LinkStyleModelMgr)
  191. obj.SetUserInfo(c.GetCurrentUserInfo())
  192. obj.Model = bo.T_data_link_style_model{}
  193. obj.Model.LinkstyleId = id
  194. obj.Model.Id = model_id
  195. err := obj.Delete()
  196. if err != nil {
  197. c.Data["json"] = c.ResultError(err.Error())
  198. c.ServeJSON()
  199. return
  200. }
  201. c.Data["json"] = c.ResultOK("", 0)
  202. c.ServeJSON()
  203. }
  204. // @Summary 查询接线方式下模型列表
  205. // @Description 查询接线方式下模型列表
  206. // @Tags 检测任务服务接口
  207. // @Accept x-www-form-urlencoded
  208. // @Produce json
  209. // @Param pageno query int true "当前页码。默认为1"
  210. // @Param pagesize query int true "每页显示数据数。默认为20"
  211. // @Param id query int false "ID"
  212. // @Param linkstyle_id query int false "接线方式ID"
  213. // @Success 200 {object} ResultOK 成功
  214. // @Failure 500 {object} ResultError 失败
  215. // @router /admin/linkstyle-model/list [get]
  216. func (c *BusAdminController) GetLinkStyleModelList() {
  217. obj := new(bo.LinkStyleModelMgr)
  218. obj.SetUserInfo(c.GetCurrentUserInfo())
  219. obj.Model = bo.T_data_link_style_model{}
  220. obj.Model.Id, _ = c.GetInt("id")
  221. obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id")
  222. pi, _ := c.GetInt("pagesize", 20)
  223. po, _ := c.GetInt("pageno", 0)
  224. if po == 0 {
  225. po, _ = c.GetInt("pageindex", 0)
  226. }
  227. if po == 0 {
  228. po = 1
  229. }
  230. lst, cnt, err := obj.List(po, pi)
  231. if err != nil {
  232. c.Data["json"] = c.ResultError(err.Error())
  233. c.ServeJSON()
  234. return
  235. }
  236. c.Data["json"] = c.ResultOK(lst, cnt)
  237. c.ServeJSON()
  238. }
  239. // @Summary 创建或编辑新的内置模型
  240. // @Description 创建新的内置模型
  241. // @Tags 业务管理服务
  242. // @Accept x-www-form-urlencoded
  243. // @Produce json
  244. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  245. // @Param model_name formData string true "模型名称"
  246. // @Param vol_id formData int true "电压等级ID"
  247. // @Param line_link_style formData int true "接线方式ID"
  248. // @Param ied_types formData string false "包含的装置类型,关联代码:ied_type。多个类型之间使用逗号分隔。"
  249. // @Param relation_json formData string false "模型定义内容。svg源代码(xml格式)。"
  250. // @Param area_type formData string false "间隔类型。关联代码:area_type"
  251. // @Success 200 {object} ResultOK 成功
  252. // @Failure 500 {object} ResultError 失败
  253. // @router /admin/sysmodel/save [post]
  254. func (c *BusAdminController) SaveSysModelInfo() {
  255. id, _ := c.GetInt("id")
  256. obj := new(bo.SysCheckModelMgr)
  257. obj.SetUserInfo(c.GetCurrentUserInfo())
  258. obj.Model = bo.T_data_model_defualt{Id: id, IsSys: 1}
  259. obj.Model.ModelName = c.GetString("model_name")
  260. obj.Model.AreaType, _ = c.GetInt("area_type")
  261. obj.Model.IedTypes = c.GetString("ied_types")
  262. obj.Model.VolId, _ = c.GetInt("vol_id")
  263. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  264. obj.Model.RelationJson = c.GetString("relation_json")
  265. if id == 0 && obj.Model.ModelName == "" {
  266. c.Data["json"] = c.ResultError("模型名称不能为空")
  267. c.ServeJSON()
  268. return
  269. }
  270. if id == 0 && obj.Model.VolId == 0 {
  271. c.Data["json"] = c.ResultError("电压等级不能为空")
  272. c.ServeJSON()
  273. return
  274. }
  275. if id == 0 && obj.Model.LineLinkStyle == 0 {
  276. c.Data["json"] = c.ResultError("接线方式不能为空")
  277. c.ServeJSON()
  278. return
  279. }
  280. if id == 0 && obj.Model.AreaType == 0 {
  281. c.Data["json"] = c.ResultError("间隔类型不能为空")
  282. c.ServeJSON()
  283. return
  284. }
  285. err := obj.Save()
  286. if err != nil {
  287. c.Data["json"] = c.ResultError(err.Error())
  288. c.ServeJSON()
  289. return
  290. }
  291. c.Data["json"] = c.ResultOK("", 0)
  292. c.ServeJSON()
  293. }
  294. // @Summary 复制并保存指定的内置检测模型为自定义模型
  295. // @Description 复制并保存指定的内置检测模型为自定义模型
  296. // @Tags 业务管理服务
  297. // @Accept x-www-form-urlencoded
  298. // @Produce json
  299. // @Param id formData int true "模型ID"
  300. // @Param newname formData string true "新模型名称"
  301. // @Success 200 {object} ResultOK 成功
  302. // @Failure 500 {object} ResultError 失败
  303. // @router /admin/sysmodel/saveas [post]
  304. func (c *BusAdminController) CopySysModelByID() {
  305. id, _ := c.GetInt("id")
  306. if id == 0 {
  307. c.Data["json"] = c.ResultError("id不能为空!")
  308. c.ServeJSON()
  309. return
  310. }
  311. new_name := c.GetString("newname")
  312. obj := new(bo.SysCheckModelMgr)
  313. obj.SetUserInfo(c.GetCurrentUserInfo())
  314. obj.Model = bo.T_data_model_defualt{Id: id}
  315. obj.Model.Id = id
  316. obj.Model.ModelName = new_name
  317. err, newid := obj.Copy(id)
  318. if err != nil {
  319. c.Data["json"] = c.ResultError(err.Error())
  320. c.ServeJSON()
  321. return
  322. }
  323. c.Data["json"] = c.ResultOK(newid, 0)
  324. c.ServeJSON()
  325. }
  326. // @Summary 删除指定的检测模型
  327. // @Description 删除指定的检测模型
  328. // @Tags 业务管理服务
  329. // @Accept x-www-form-urlencoded
  330. // @Produce json
  331. // @Param id formData int true "模型ID"
  332. // @Success 200 {object} ResultOK 成功
  333. // @Failure 500 {object} ResultError 失败
  334. // @router /admin/sysmodel/delete [post]
  335. func (c *BusAdminController) DeleteSysModelByID() {
  336. id, _ := c.GetInt("id")
  337. if id == 0 {
  338. c.Data["json"] = c.ResultError("id不能为空!")
  339. c.ServeJSON()
  340. return
  341. }
  342. obj := new(bo.SysCheckModelMgr)
  343. obj.SetUserInfo(c.GetCurrentUserInfo())
  344. obj.Model = bo.T_data_model_defualt{Id: id}
  345. obj.Model.Id = id
  346. err := obj.Delete()
  347. if err != nil {
  348. c.Data["json"] = c.ResultError(err.Error())
  349. c.ServeJSON()
  350. return
  351. }
  352. c.Data["json"] = c.ResultOK("", 0)
  353. c.ServeJSON()
  354. }
  355. // @Summary 查询检测模型列表
  356. // @Description 查询检测模型列表。支持名称、电压等级等过滤条件
  357. // @Tags 检测任务服务接口
  358. // @Accept x-www-form-urlencoded
  359. // @Produce json
  360. // @Param pageno query int true "当前页码。默认为1"
  361. // @Param pagesize query int true "每页显示数据数。默认为20"
  362. // @Param id query int false "ID"
  363. // @Param vol_id query int false "电压等级ID"
  364. // @Param model_name query string false "名称"
  365. // @Param line_link_style query int false "接线方式"
  366. // @Param area_type query int false "间隔类型"
  367. // @Param is_sys query int false "模型类型。1 内置模型 2 自定义模型"
  368. // @Success 200 {object} ResultOK 成功
  369. // @Failure 500 {object} ResultError 失败
  370. // @router /admin/sysmodel/list [get]
  371. func (c *BusAdminController) GetSysModelList() {
  372. obj := new(bo.SysCheckModelMgr)
  373. obj.SetUserInfo(c.GetCurrentUserInfo())
  374. obj.Model = bo.T_data_model_defualt{}
  375. obj.Model.Id, _ = c.GetInt("id")
  376. obj.Model.IsSys, _ = c.GetInt("is_sys", 1) //默认查询系统内置模型
  377. obj.Model.VolId, _ = c.GetInt("vol_id")
  378. obj.Model.ModelName = c.GetString("model_name")
  379. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  380. obj.Model.AreaType, _ = c.GetInt("area_type")
  381. pi, _ := c.GetInt("pagesize", 20)
  382. po, _ := c.GetInt("pageno", 0)
  383. if po == 0 {
  384. po, _ = c.GetInt("pageindex", 0)
  385. }
  386. if po == 0 {
  387. po = 1
  388. }
  389. lst, cnt, err := obj.List(po, pi)
  390. if err != nil {
  391. c.Data["json"] = c.ResultError(err.Error())
  392. c.ServeJSON()
  393. return
  394. }
  395. //如果是获取指定模型信息时,附加模型的标准装置类型信息
  396. if obj.Model.Id > 0 {
  397. //间隔类型id
  398. syscode := new(bo.Global)
  399. codeinfo := syscode.GetCodeInfoByID(tools.IsEmpty(lst[0]["area_type"]))
  400. if codeinfo != nil {
  401. code := "area_type_" + tools.IsEmpty(codeinfo["code"])
  402. codeinfo = syscode.GetCodeInfoByCode("area_ied_type", code)
  403. codes := strings.Split(tools.IsEmpty(codeinfo["name"]), ",")
  404. ccrows := []orm.Params{}
  405. for _, item := range codes {
  406. tmp := syscode.GetCodeInfoByCode("ied_type", item)
  407. if tmp == nil {
  408. ccrows = append(ccrows, orm.Params{"code": item, "name": item})
  409. } else {
  410. ccrows = append(ccrows, tmp)
  411. }
  412. }
  413. lst[0]["ied_type"] = ccrows
  414. }
  415. }
  416. c.Data["json"] = c.ResultOK(lst, cnt)
  417. c.ServeJSON()
  418. }
  419. // @Summary 重新分析指定的SCD检测模型间隔
  420. // @Description 重新分析指定的SCD检测模型间隔
  421. // @Tags 业务管理服务
  422. // @Accept x-www-form-urlencoded
  423. // @Produce json
  424. // @Param scd_id formData int true "SCD文件ID"
  425. // @Success 200 {object} ResultOK 成功
  426. // @Failure 500 {object} ResultError 失败
  427. // @router /admin/parse/check_area [post]
  428. func (c *BusAdminController) ResetCheckAreaByID() {
  429. id, _ := c.GetInt64("scd_id")
  430. if id == 0 {
  431. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  432. c.ServeJSON()
  433. return
  434. }
  435. obj := new(bo.CheckAreaMgr)
  436. obj.SetUserInfo(c.GetCurrentUserInfo())
  437. obj.ScdId = id
  438. err := obj.Reset()
  439. if err != nil {
  440. c.Data["json"] = c.ResultError(err.Error())
  441. c.ServeJSON()
  442. return
  443. }
  444. c.Data["json"] = c.ResultOK("", 0)
  445. c.ServeJSON()
  446. }
  447. // @Summary 查询指定电压等级及接线方式下的检测间隔分析结果
  448. // @Description 查询指定电压等级及接线方式下的检测间隔分析结果
  449. // @Tags 业务管理服务
  450. // @Accept x-www-form-urlencoded
  451. // @Produce json
  452. // @Param scd_id formData int true "SCD文件ID"
  453. // @Param vol_id formData int false "电压等级ID"
  454. // @Param link_style_id formData int false "接线方式ID"
  455. // @Success 200 {object} ResultOK 成功
  456. // @Failure 500 {object} ResultError 失败
  457. // @router /admin/get/check_area [get]
  458. func (c *BusAdminController) GetCheckAreaByVolID() {
  459. id, _ := c.GetInt64("scd_id")
  460. if id == 0 {
  461. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  462. c.ServeJSON()
  463. return
  464. }
  465. volid, _ := c.GetInt("vol_id")
  466. lsid, _ := c.GetInt("link_style_id")
  467. obj := new(bo.CheckAreaMgr)
  468. obj.SetUserInfo(c.GetCurrentUserInfo())
  469. obj.ScdId = id
  470. lst, err := obj.GetAreaListByVol(id, volid, lsid)
  471. if err != nil {
  472. c.Data["json"] = c.ResultError(err.Error())
  473. c.ServeJSON()
  474. return
  475. }
  476. if lst == nil || len(lst) == 0 {
  477. //新分析
  478. err = obj.Reset()
  479. if err != nil {
  480. c.Data["json"] = c.ResultError(err.Error())
  481. c.ServeJSON()
  482. return
  483. }
  484. lst, _ = obj.GetAreaListByVol(id, volid, lsid)
  485. }
  486. c.Data["json"] = c.ResultOK(lst, 0)
  487. c.ServeJSON()
  488. }
  489. // @Summary 查询指定检测间隔下的IED装置列表
  490. // @Description 查询指定检测间隔下的IED装置列表
  491. // @Tags 业务管理服务
  492. // @Accept x-www-form-urlencoded
  493. // @Produce json
  494. // @Param scd_id formData int true "SCD文件ID"
  495. // @Param area_id formData int true "检测间隔ID"
  496. // @Success 200 {object} ResultOK 成功
  497. // @Failure 500 {object} ResultError 失败
  498. // @router /admin/get/check_area/ied [get]
  499. func (c *BusAdminController) GetCheckAreaIedByAreaID() {
  500. id, _ := c.GetInt64("scd_id")
  501. if id == 0 {
  502. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  503. c.ServeJSON()
  504. return
  505. }
  506. area_id, _ := c.GetInt("area_id")
  507. obj := new(bo.CheckAreaMgr)
  508. obj.SetUserInfo(c.GetCurrentUserInfo())
  509. obj.ScdId = id
  510. lst, err := obj.GetIedList(id, area_id)
  511. if err != nil {
  512. c.Data["json"] = c.ResultError(err.Error())
  513. c.ServeJSON()
  514. return
  515. }
  516. c.Data["json"] = c.ResultOK(lst, 0)
  517. c.ServeJSON()
  518. }
  519. // @Summary 修改并保存指定检测间隔下的IED装置列表
  520. // @Description 修改并保存指定检测间隔下的IED装置列表
  521. // @Tags 业务管理服务
  522. // @Accept x-www-form-urlencoded
  523. // @Produce json
  524. // @Param scd_id formData int true "SCD文件ID"
  525. // @Param area_id formData int true "检测间隔ID"
  526. // @Param ied_ids formData string true "IED装置name列表,多个ied采用逗号分隔。如:PT1001,PL1001,..."
  527. // @Success 200 {object} ResultOK 成功
  528. // @Failure 500 {object} ResultError 失败
  529. // @router /admin/update/check_area/ied [post]
  530. func (c *BusAdminController) SaveCheckAreaIedByAreaID() {
  531. id, _ := c.GetInt64("scd_id")
  532. if id == 0 {
  533. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  534. c.ServeJSON()
  535. return
  536. }
  537. area_id, _ := c.GetInt("area_id")
  538. ieds := c.GetString("ied_ids")
  539. if area_id == 0 {
  540. c.Data["json"] = c.ResultError("检测间隔ID不能为空!")
  541. c.ServeJSON()
  542. return
  543. }
  544. if ieds == "" {
  545. c.Data["json"] = c.ResultError("检测间隔装置列表不能为空!")
  546. c.ServeJSON()
  547. return
  548. }
  549. obj := new(bo.CheckAreaMgr)
  550. obj.SetUserInfo(c.GetCurrentUserInfo())
  551. obj.ScdId = id
  552. err := obj.UpdateIeds(id, area_id, ieds)
  553. if err != nil {
  554. c.Data["json"] = c.ResultError(err.Error())
  555. c.ServeJSON()
  556. return
  557. }
  558. c.Data["json"] = c.ResultOK("", 0)
  559. c.ServeJSON()
  560. }
  561. // @Summary 获取指定模型和装置类型的功能列表
  562. // @Description 获取指定模型和装置类型的功能列表
  563. // @Tags 业务管理服务
  564. // @Accept x-www-form-urlencoded
  565. // @Produce json
  566. // @Param model_id formData int true "模型ID"
  567. // @Param ied_type formData string true "装置类型"
  568. // @Success 200 {object} ResultOK 成功
  569. // @Failure 500 {object} ResultError 失败
  570. // @router /admin/model/function/list [get]
  571. func (c *BusAdminController) GetFuncListByIedType() {
  572. modelid, _ := c.GetInt("model_id")
  573. if modelid == 0 {
  574. c.Data["json"] = c.ResultError("模型ID不能为空!")
  575. c.ServeJSON()
  576. return
  577. }
  578. ied_type := c.GetString("ied_type")
  579. if ied_type == "" {
  580. c.Data["json"] = c.ResultError("装置类型不能为空!")
  581. c.ServeJSON()
  582. return
  583. }
  584. obj := new(bo.SysCheckModelIedFuncMgr)
  585. obj.SetUserInfo(c.GetCurrentUserInfo())
  586. lst, err := obj.GetList(modelid, ied_type)
  587. if err != nil {
  588. c.Data["json"] = c.ResultError(err.Error())
  589. c.ServeJSON()
  590. return
  591. }
  592. c.Data["json"] = c.ResultOK(lst, 0)
  593. c.ServeJSON()
  594. }
  595. // @Summary 获取指定模型和装置类型的端子列表
  596. // @Description 获取指定模型和装置类型的端子列表
  597. // @Tags 业务管理服务
  598. // @Accept x-www-form-urlencoded
  599. // @Produce json
  600. // @Param model_id formData int true "模型ID"
  601. // @Param ied_type formData string true "装置类型"
  602. // @Success 200 {object} ResultOK 成功
  603. // @Failure 500 {object} ResultError 失败
  604. // @router /admin/model/function/fcda/list [get]
  605. func (c *BusAdminController) GetFuncFcdaList() {
  606. modelid, _ := c.GetInt("model_id")
  607. if modelid == 0 {
  608. c.Data["json"] = c.ResultError("模型ID不能为空!")
  609. c.ServeJSON()
  610. return
  611. }
  612. ied_type := c.GetString("ied_type")
  613. if ied_type == "" {
  614. c.Data["json"] = c.ResultError("装置类型不能为空!")
  615. c.ServeJSON()
  616. return
  617. }
  618. obj := new(bo.SysCheckModelIedFuncMgr)
  619. obj.SetUserInfo(c.GetCurrentUserInfo())
  620. lst, err := obj.GetList(modelid, ied_type)
  621. if err != nil {
  622. c.Data["json"] = c.ResultError(err.Error())
  623. c.ServeJSON()
  624. return
  625. }
  626. fcdaList := []interface{}{}
  627. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  628. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  629. fcdaMgr.Model.ModelId = modelid
  630. for _, row := range lst {
  631. fcdaMgr.Model.FuncId, _ = strconv.Atoi(tools.IsEmpty(row["id"]))
  632. tmpLst, err := fcdaMgr.GetList()
  633. if err != nil {
  634. c.Data["json"] = c.ResultError(err.Error())
  635. c.ServeJSON()
  636. return
  637. }
  638. for _, r := range tmpLst {
  639. fcdaList = append(fcdaList, r)
  640. }
  641. }
  642. c.Data["json"] = c.ResultOK(fcdaList, 0)
  643. c.ServeJSON()
  644. }
  645. // @Summary 保存模型装置功能及端子信息
  646. // @Description 保存装置功能及端子信息
  647. // @Tags 业务管理服务
  648. // @Accept x-www-form-urlencoded
  649. // @Produce json
  650. // @Param model_id formData int true "模型ID"
  651. // @Param ied_type formData string true "装置类型代码"
  652. // @Param func_id formData int false "功能ID。编辑时必传。"
  653. // @Param func_name formData string true "功能名称。必传。"
  654. // @Param fcda_id formData int false "端子ID。编辑时必传。"
  655. // @Param fcda_name formData string true "端子名称。必传。"
  656. // @Param fcda_match_exp formData string true "端子匹配表达式。必传。"
  657. // @Param sv_or_goose formData string true "端子信号类型。必传。仅支持SV或GOOSE"
  658. // @Param in_or_out formData string true "端子信号输入输出方向。必传。仅支持中文的'接收'或'输出'"
  659. // @Success 200 {object} ResultOK 成功
  660. // @Failure 500 {object} ResultError 失败
  661. // @router /admin/model/function/fcda/save [post]
  662. func (c *BusAdminController) SaveFuncFcda() {
  663. modelid, _ := c.GetInt("model_id")
  664. if modelid == 0 {
  665. c.Data["json"] = c.ResultError("模型ID不能为空!")
  666. c.ServeJSON()
  667. return
  668. }
  669. ied_type := c.GetString("ied_type")
  670. func_name := c.GetString("func_name")
  671. fcda_name := c.GetString("fcda_name")
  672. fcda_match_exp := c.GetString("fcda_match_exp")
  673. func_id, _ := c.GetInt("func_id")
  674. fcda_id, _ := c.GetInt("fcda_id")
  675. svorgoose := c.GetString("sv_or_goose")
  676. inorout := c.GetString("in_or_out")
  677. if func_name == "" {
  678. c.Data["json"] = c.ResultError("功能名称不能为空!")
  679. c.ServeJSON()
  680. return
  681. }
  682. if fcda_name == "" {
  683. c.Data["json"] = c.ResultError("端子设计名称不能为空!")
  684. c.ServeJSON()
  685. return
  686. }
  687. if fcda_match_exp == "" {
  688. c.Data["json"] = c.ResultError("端子匹配关键词不能为空!")
  689. c.ServeJSON()
  690. return
  691. }
  692. if svorgoose == "" {
  693. c.Data["json"] = c.ResultError("端子信号类型不能为空!")
  694. c.ServeJSON()
  695. return
  696. }
  697. if inorout == "" {
  698. c.Data["json"] = c.ResultError("端子信号方向不能为空!")
  699. c.ServeJSON()
  700. return
  701. }
  702. mod := bo.T_data_model_func_def{}
  703. mod.Id = func_id
  704. mod.ModelId = modelid
  705. mod.IedType = ied_type
  706. mod.FuncFcdaId = fcda_id
  707. mod.FuncName = func_name
  708. mod.FcdaName = fcda_name
  709. mod.FcdaMatchExp = fcda_match_exp
  710. mod.Svorgoose = svorgoose
  711. mod.Inorout = inorout
  712. mgr := new(bo.SysCheckModelIedFuncMgr)
  713. mgr.SetUserInfo(c.GetCurrentUserInfo())
  714. mgr.Model = mod
  715. err := mgr.Save()
  716. if err != nil {
  717. c.Data["json"] = c.ResultError(err.Error())
  718. c.ServeJSON()
  719. return
  720. }
  721. c.Data["json"] = c.ResultOK("", 0)
  722. c.ServeJSON()
  723. }
  724. // @Summary 删除装置端子
  725. // @Description 删除装置端子
  726. // @Tags 业务管理服务
  727. // @Accept x-www-form-urlencoded
  728. // @Produce json
  729. // @Param model_id formData int true "模型ID"
  730. // @Param fcda_id formData int true "端子ID"
  731. // @Success 200 {object} ResultOK 成功
  732. // @Failure 500 {object} ResultError 失败
  733. // @router /admin/model/function/fcda/del [post]
  734. func (c *BusAdminController) DelFuncFcda() {
  735. modelid, _ := c.GetInt("model_id")
  736. if modelid == 0 {
  737. c.Data["json"] = c.ResultError("模型ID不能为空!")
  738. c.ServeJSON()
  739. return
  740. }
  741. fcda_id, _ := c.GetInt("fcda_id")
  742. if fcda_id == 0 {
  743. c.Data["json"] = c.ResultError("端子ID不能为空!")
  744. c.ServeJSON()
  745. return
  746. }
  747. fcdaMgr := new(bo.SysCheckModelIedFuncFcdaMgr)
  748. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  749. fcdaMgr.Model = bo.T_data_model_func_fcda{}
  750. fcdaMgr.Model.ModelId = modelid
  751. fcdaMgr.Model.Id = fcda_id
  752. err := fcdaMgr.Delete()
  753. if err != nil {
  754. c.Data["json"] = c.ResultError(err.Error())
  755. c.ServeJSON()
  756. return
  757. }
  758. c.Data["json"] = c.ResultOK("", 0)
  759. c.ServeJSON()
  760. }
  761. // @Summary 获取模型装置端子已关联的接收端子
  762. // @Description 获取模型装置端子已关联的接收端子
  763. // @Tags 业务管理服务
  764. // @Accept x-www-form-urlencoded
  765. // @Produce json
  766. // @Param model_id formData int true "模型ID"
  767. // @Param from_fcda_id formData int true "输出装置端子ID"
  768. // @Param to_ied_type formData string false "输入装置类型"
  769. // @Param goosesv formData string false "信号类型。GOOSE|SV"
  770. // @Success 200 {object} ResultOK 成功
  771. // @Failure 500 {object} ResultError 失败
  772. // @router /admin/model/function/fcda-ref/list [get]
  773. func (c *BusAdminController) GetFuncFcdaRef() {
  774. modelid, _ := c.GetInt("model_id")
  775. if modelid == 0 {
  776. c.Data["json"] = c.ResultError("模型ID不能为空!")
  777. c.ServeJSON()
  778. return
  779. }
  780. fcda_id, _ := c.GetInt("from_fcda_id")
  781. if fcda_id == 0 {
  782. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  783. c.ServeJSON()
  784. return
  785. }
  786. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  787. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  788. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  789. fcdaMgr.Model.ModelId = modelid
  790. fcdaMgr.Model.FromFcdaId = fcda_id
  791. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  792. fcdaMgr.Model.Goosesv = c.GetString("goosesv")
  793. lst, err := fcdaMgr.GetList()
  794. if err != nil {
  795. c.Data["json"] = c.ResultError(err.Error())
  796. c.ServeJSON()
  797. return
  798. }
  799. c.Data["json"] = c.ResultOK(lst, len(lst))
  800. c.ServeJSON()
  801. }
  802. // @Summary 保存模型装置端子间关联关系
  803. // @Description 保存模型装置端子间关联关系
  804. // @Tags 业务管理服务
  805. // @Accept x-www-form-urlencoded
  806. // @Produce json
  807. // @Param model_id formData int true "模型ID"
  808. // @Param from_ied_type formData string true "输出装置类型"
  809. // @Param to_ied_type formData string true "输入装置类型"
  810. // @Param from_fcda_id formData int true "输出装置端子ID"
  811. // @Param to_fcda_ids formData string true "输入装置端子ID列表。多个ID间使用逗号分隔"
  812. // @Param goosesv formData string true "信号类型。值范围:GOOSE|SV"
  813. // @Success 200 {object} ResultOK 成功
  814. // @Failure 500 {object} ResultError 失败
  815. // @router /admin/model/function/fcda-ref/save [post]
  816. func (c *BusAdminController) SaveFuncFcdaRef() {
  817. modelid, _ := c.GetInt("model_id")
  818. if modelid == 0 {
  819. c.Data["json"] = c.ResultError("模型ID不能为空!")
  820. c.ServeJSON()
  821. return
  822. }
  823. fcda_id, _ := c.GetInt("from_fcda_id")
  824. if fcda_id == 0 {
  825. c.Data["json"] = c.ResultError("输出装置端子ID不能为空!")
  826. c.ServeJSON()
  827. return
  828. }
  829. fcda_in_ids := c.GetString("to_fcda_ids")
  830. fcdaMgr := new(bo.SysCheckModelFcdaRalationMgr)
  831. fcdaMgr.SetUserInfo(c.GetCurrentUserInfo())
  832. fcdaMgr.Model = bo.T_data_model_fcda_ref{}
  833. fcdaMgr.Model.ModelId = modelid
  834. fcdaMgr.Model.FromFcdaId = fcda_id
  835. fcdaMgr.Model.FromIedCode = c.GetString("from_ied_type")
  836. fcdaMgr.Model.ToIedCode = c.GetString("to_ied_type")
  837. fcdaMgr.Model.Goosesv = strings.ToUpper(c.GetString("goosesv"))
  838. if fcdaMgr.Model.FromIedCode == "" || fcdaMgr.Model.ToIedCode == "" {
  839. c.Data["json"] = c.ResultError("输入和输出装置类型不能为空!")
  840. c.ServeJSON()
  841. return
  842. }
  843. if fcdaMgr.Model.Goosesv == "" {
  844. c.Data["json"] = c.ResultError("信号类型不能为空!")
  845. c.ServeJSON()
  846. return
  847. }
  848. if fcdaMgr.Model.Goosesv != "GOOSE" && fcdaMgr.Model.Goosesv != "SV" {
  849. c.Data["json"] = c.ResultError("信号类型不正确。只能为GOOSE或SV")
  850. c.ServeJSON()
  851. return
  852. }
  853. obj := new(bo.SysCheckModelIedFuncFcdaMgr)
  854. fcdainf, er := obj.One(fcdaMgr.Model.FromFcdaId)
  855. if er != nil {
  856. c.Data["json"] = c.ResultError("无效的输出端子ID")
  857. c.ServeJSON()
  858. return
  859. }
  860. fcdaMgr.Model.FromFuncId = fcdainf.FuncId
  861. //清除原关系
  862. err := fcdaMgr.Delete()
  863. if err != nil {
  864. c.Data["json"] = c.ResultError(err.Error())
  865. c.ServeJSON()
  866. return
  867. }
  868. if fcda_in_ids != "" {
  869. fcda_in_ids_1 := strings.Split(fcda_in_ids, ",")
  870. for _, k := range fcda_in_ids_1 {
  871. fcdaMgr.Model.ToFcdaId, _ = strconv.Atoi(k)
  872. fcdainf, er = obj.One(fcdaMgr.Model.ToFcdaId)
  873. if er != nil {
  874. c.Data["json"] = c.ResultError("无效的输入端子ID")
  875. c.ServeJSON()
  876. return
  877. }
  878. fcdaMgr.Model.ToFuncId = fcdainf.FuncId
  879. err := fcdaMgr.Save()
  880. if err != nil {
  881. c.Data["json"] = c.ResultError(err.Error())
  882. c.ServeJSON()
  883. return
  884. }
  885. }
  886. }
  887. c.Data["json"] = c.ResultOK("", 0)
  888. c.ServeJSON()
  889. }