busAdminController.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. )
  15. //业务管理服务
  16. type BusAdminController struct {
  17. BaseController
  18. }
  19. func init() {
  20. }
  21. // @Summary 创建新的接线方式
  22. // @Description 创建新的接线方式
  23. // @Tags 业务管理服务
  24. // @Accept x-www-form-urlencoded
  25. // @Produce json
  26. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  27. // @Param name formData string true "任务名称"
  28. // @Param vol_id formData int true "电压等级ID"
  29. // @Param pic formData string false "接线图地址"
  30. // @Success 200 {object} ResultOK 成功
  31. // @Failure 500 {object} ResultError 失败
  32. // @router /admin/linkstyle/save [post]
  33. func (c *BusAdminController) SaveLinkStyleInfo() {
  34. id, _ := c.GetInt("id")
  35. obj := new(bo.LinkStyleMgr)
  36. obj.SetUserInfo(c.GetCurrentUserInfo())
  37. obj.Model = bo.T_data_link_style{Id: id}
  38. obj.Model.Name = c.GetString("name")
  39. obj.Model.VolLevelId, _ = c.GetInt("vol_id")
  40. obj.Model.Pic = c.GetString("pic")
  41. if obj.Model.Name == "" {
  42. c.Data["json"] = c.ResultError("名称不能为空")
  43. c.ServeJSON()
  44. return
  45. }
  46. if obj.Model.VolLevelId == 0 {
  47. c.Data["json"] = c.ResultError("电压等级不能为空")
  48. c.ServeJSON()
  49. return
  50. }
  51. err := obj.Save()
  52. if err != nil {
  53. c.Data["json"] = c.ResultError(err.Error())
  54. c.ServeJSON()
  55. return
  56. }
  57. c.Data["json"] = c.ResultOK("", 0)
  58. c.ServeJSON()
  59. }
  60. // @Summary 删除指定的接线方式
  61. // @Description 删除指定的接线方式
  62. // @Tags 业务管理服务
  63. // @Accept x-www-form-urlencoded
  64. // @Produce json
  65. // @Param id formData int true "接线方式ID"
  66. // @Success 200 {object} ResultOK 成功
  67. // @Failure 500 {object} ResultError 失败
  68. // @router /admin/linkstyle/delete [post]
  69. func (c *BusAdminController) DeleteLinkStyleByID() {
  70. id, _ := c.GetInt("id")
  71. if id == 0 {
  72. c.Data["json"] = c.ResultError("id不能为空!")
  73. c.ServeJSON()
  74. return
  75. }
  76. obj := new(bo.LinkStyleMgr)
  77. obj.SetUserInfo(c.GetCurrentUserInfo())
  78. obj.Model = bo.T_data_link_style{}
  79. obj.Model.Id = id
  80. err := obj.Delete()
  81. if err != nil {
  82. c.Data["json"] = c.ResultError(err.Error())
  83. c.ServeJSON()
  84. return
  85. }
  86. c.Data["json"] = c.ResultOK("", 0)
  87. c.ServeJSON()
  88. }
  89. // @Summary 查询接线方式
  90. // @Description 查询接线方式。支持名称、电压等级等过滤条件
  91. // @Tags 检测任务服务接口
  92. // @Accept x-www-form-urlencoded
  93. // @Produce json
  94. // @Param pageno query int true "当前页码。默认为1"
  95. // @Param pagesize query int true "每页显示数据数。默认为20"
  96. // @Param id query int false "ID"
  97. // @Param vol_id query int false "电压ID"
  98. // @Param name query string false "名称"
  99. // @Success 200 {object} ResultOK 成功
  100. // @Failure 500 {object} ResultError 失败
  101. // @router /admin/linkstyle/list [get]
  102. func (c *BusAdminController) GetLinkStyleList() {
  103. obj := new(bo.LinkStyleMgr)
  104. obj.SetUserInfo(c.GetCurrentUserInfo())
  105. obj.Model = bo.T_data_link_style{}
  106. obj.Model.Id, _ = c.GetInt("id")
  107. obj.Model.VolLevelId, _ = c.GetInt("vol_id")
  108. obj.Model.Name = c.GetString("name")
  109. pi, _ := c.GetInt("pagesize", 20)
  110. po, _ := c.GetInt("pageno", 0)
  111. if po == 0 {
  112. po, _ = c.GetInt("pageindex", 0)
  113. }
  114. if po == 0 {
  115. po = 1
  116. }
  117. lst, cnt, err := obj.List(po, pi)
  118. if err != nil {
  119. c.Data["json"] = c.ResultError(err.Error())
  120. c.ServeJSON()
  121. return
  122. }
  123. c.Data["json"] = c.ResultOK(lst, cnt)
  124. c.ServeJSON()
  125. }
  126. // @Summary 添加接线方式的模型
  127. // @Description 添加接线方式的模型
  128. // @Tags 业务管理服务
  129. // @Accept x-www-form-urlencoded
  130. // @Produce json
  131. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  132. // @Param linkstyle_id formData int true "接线方式ID"
  133. // @Param model_id formData int true "内置模型id"
  134. // @Success 200 {object} ResultOK 成功
  135. // @Failure 500 {object} ResultError 失败
  136. // @router /admin/linkstyle-model/save [post]
  137. func (c *BusAdminController) SaveLinkStyleModelInfo() {
  138. id, _ := c.GetInt("id")
  139. obj := new(bo.LinkStyleModelMgr)
  140. obj.SetUserInfo(c.GetCurrentUserInfo())
  141. obj.Model = bo.T_data_link_style_model{Id: id}
  142. obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id")
  143. obj.Model.ModelId, _ = c.GetInt("model_id")
  144. if obj.Model.LinkstyleId == 0 {
  145. c.Data["json"] = c.ResultError("接线方式不能为空")
  146. c.ServeJSON()
  147. return
  148. }
  149. if obj.Model.ModelId == 0 {
  150. c.Data["json"] = c.ResultError("模型ID不能为空")
  151. c.ServeJSON()
  152. return
  153. }
  154. err := obj.Save()
  155. if err != nil {
  156. c.Data["json"] = c.ResultError(err.Error())
  157. c.ServeJSON()
  158. return
  159. }
  160. c.Data["json"] = c.ResultOK("", 0)
  161. c.ServeJSON()
  162. }
  163. // @Summary 删除指定接线方式下属的模型
  164. // @Description 删除指定接线方式下属的模型
  165. // @Tags 业务管理服务
  166. // @Accept x-www-form-urlencoded
  167. // @Produce json
  168. // @Param id formData int true "接线方式ID"
  169. // @Param model_id formData int true "模型ID"
  170. // @Success 200 {object} ResultOK 成功
  171. // @Failure 500 {object} ResultError 失败
  172. // @router /admin/linkstyle-model/delete [post]
  173. func (c *BusAdminController) DeleteLinkStyleModelByID() {
  174. id, _ := c.GetInt("id")
  175. if id == 0 {
  176. c.Data["json"] = c.ResultError("id不能为空!")
  177. c.ServeJSON()
  178. return
  179. }
  180. model_id, _ := c.GetInt("model_id")
  181. if model_id == 0 {
  182. c.Data["json"] = c.ResultError("模型id不能为空!")
  183. c.ServeJSON()
  184. return
  185. }
  186. obj := new(bo.LinkStyleModelMgr)
  187. obj.SetUserInfo(c.GetCurrentUserInfo())
  188. obj.Model = bo.T_data_link_style_model{}
  189. obj.Model.LinkstyleId = id
  190. obj.Model.Id = model_id
  191. err := obj.Delete()
  192. if err != nil {
  193. c.Data["json"] = c.ResultError(err.Error())
  194. c.ServeJSON()
  195. return
  196. }
  197. c.Data["json"] = c.ResultOK("", 0)
  198. c.ServeJSON()
  199. }
  200. // @Summary 查询接线方式下模型列表
  201. // @Description 查询接线方式下模型列表
  202. // @Tags 检测任务服务接口
  203. // @Accept x-www-form-urlencoded
  204. // @Produce json
  205. // @Param pageno query int true "当前页码。默认为1"
  206. // @Param pagesize query int true "每页显示数据数。默认为20"
  207. // @Param id query int false "ID"
  208. // @Param linkstyle_id query int false "接线方式ID"
  209. // @Success 200 {object} ResultOK 成功
  210. // @Failure 500 {object} ResultError 失败
  211. // @router /admin/linkstyle-model/list [get]
  212. func (c *BusAdminController) GetLinkStyleModelList() {
  213. obj := new(bo.LinkStyleModelMgr)
  214. obj.SetUserInfo(c.GetCurrentUserInfo())
  215. obj.Model = bo.T_data_link_style_model{}
  216. obj.Model.Id, _ = c.GetInt("id")
  217. obj.Model.LinkstyleId, _ = c.GetInt("linkstyle_id")
  218. pi, _ := c.GetInt("pagesize", 20)
  219. po, _ := c.GetInt("pageno", 0)
  220. if po == 0 {
  221. po, _ = c.GetInt("pageindex", 0)
  222. }
  223. if po == 0 {
  224. po = 1
  225. }
  226. lst, cnt, err := obj.List(po, pi)
  227. if err != nil {
  228. c.Data["json"] = c.ResultError(err.Error())
  229. c.ServeJSON()
  230. return
  231. }
  232. c.Data["json"] = c.ResultOK(lst, cnt)
  233. c.ServeJSON()
  234. }
  235. // @Summary 创建或编辑新的内置模型
  236. // @Description 创建新的内置模型
  237. // @Tags 业务管理服务
  238. // @Accept x-www-form-urlencoded
  239. // @Produce json
  240. // @Param id formData int false "数据ID。指定id值大于0时为编辑操作;否则为新增操作"
  241. // @Param model_name formData string true "模型名称"
  242. // @Param vol_id formData int true "电压等级ID"
  243. // @Param line_link_style formData int true "接线方式ID"
  244. // @Param ied_types formData string false "包含的装置类型,关联代码:ied_type。多个类型之间使用逗号分隔。"
  245. // @Param relation_json formData string false "模型定义内容。svg源代码(xml格式)。"
  246. // @Param area_type formData string false "间隔类型。关联代码:area_type"
  247. // @Success 200 {object} ResultOK 成功
  248. // @Failure 500 {object} ResultError 失败
  249. // @router /admin/sysmodel/save [post]
  250. func (c *BusAdminController) SaveSysModelInfo() {
  251. id, _ := c.GetInt("id")
  252. obj := new(bo.SysCheckModelMgr)
  253. obj.SetUserInfo(c.GetCurrentUserInfo())
  254. obj.Model = bo.T_data_model_defualt{Id: id, IsSys: 1}
  255. obj.Model.ModelName = c.GetString("model_name")
  256. obj.Model.AreaType, _ = c.GetInt("area_type")
  257. obj.Model.IedTypes = c.GetString("ied_types")
  258. obj.Model.VolId, _ = c.GetInt("vol_id")
  259. obj.Model.LineLinkStyle, _ = c.GetInt("line_link_style")
  260. obj.Model.RelationJson = c.GetString("relation_json")
  261. if id == 0 && obj.Model.ModelName == "" {
  262. c.Data["json"] = c.ResultError("模型名称不能为空")
  263. c.ServeJSON()
  264. return
  265. }
  266. if id == 0 && obj.Model.VolId == 0 {
  267. c.Data["json"] = c.ResultError("电压等级不能为空")
  268. c.ServeJSON()
  269. return
  270. }
  271. if id == 0 && obj.Model.LineLinkStyle == 0 {
  272. c.Data["json"] = c.ResultError("接线方式不能为空")
  273. c.ServeJSON()
  274. return
  275. }
  276. if id == 0 && obj.Model.AreaType == 0 {
  277. c.Data["json"] = c.ResultError("间隔类型不能为空")
  278. c.ServeJSON()
  279. return
  280. }
  281. err := obj.Save()
  282. if err != nil {
  283. c.Data["json"] = c.ResultError(err.Error())
  284. c.ServeJSON()
  285. return
  286. }
  287. c.Data["json"] = c.ResultOK("", 0)
  288. c.ServeJSON()
  289. }
  290. // @Summary 复制并保存指定的内置检测模型为自定义模型
  291. // @Description 复制并保存指定的内置检测模型为自定义模型
  292. // @Tags 业务管理服务
  293. // @Accept x-www-form-urlencoded
  294. // @Produce json
  295. // @Param id formData int true "模型ID"
  296. // @Param newname formData string true "新模型名称"
  297. // @Success 200 {object} ResultOK 成功
  298. // @Failure 500 {object} ResultError 失败
  299. // @router /admin/sysmodel/saveas [post]
  300. func (c *BusAdminController) CopySysModelByID() {
  301. id, _ := c.GetInt("id")
  302. if id == 0 {
  303. c.Data["json"] = c.ResultError("id不能为空!")
  304. c.ServeJSON()
  305. return
  306. }
  307. new_name := c.GetString("newname")
  308. if new_name == "" {
  309. c.Data["json"] = c.ResultError("新模型名称不能为空!")
  310. c.ServeJSON()
  311. return
  312. }
  313. obj := new(bo.SysCheckModelMgr)
  314. obj.SetUserInfo(c.GetCurrentUserInfo())
  315. obj.Model = bo.T_data_model_defualt{Id: id}
  316. obj.Model.Id = id
  317. err, newid := obj.Copy(new_name)
  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")
  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. c.Data["json"] = c.ResultOK(lst, cnt)
  396. c.ServeJSON()
  397. }
  398. // @Summary 重新分析指定的SCD检测模型间隔
  399. // @Description 重新分析指定的SCD检测模型间隔
  400. // @Tags 业务管理服务
  401. // @Accept x-www-form-urlencoded
  402. // @Produce json
  403. // @Param scd_id formData int true "SCD文件ID"
  404. // @Success 200 {object} ResultOK 成功
  405. // @Failure 500 {object} ResultError 失败
  406. // @router /admin/parse/check_area [post]
  407. func (c *BusAdminController) ResetCheckAreaByID() {
  408. id, _ := c.GetInt64("scd_id")
  409. if id == 0 {
  410. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  411. c.ServeJSON()
  412. return
  413. }
  414. obj := new(bo.CheckAreaMgr)
  415. obj.SetUserInfo(c.GetCurrentUserInfo())
  416. obj.ScdId = id
  417. err := obj.Reset()
  418. if err != nil {
  419. c.Data["json"] = c.ResultError(err.Error())
  420. c.ServeJSON()
  421. return
  422. }
  423. c.Data["json"] = c.ResultOK("", 0)
  424. c.ServeJSON()
  425. }
  426. // @Summary 查询指定电压等级及接线方式下的检测间隔分析结果
  427. // @Description 查询指定电压等级及接线方式下的检测间隔分析结果
  428. // @Tags 业务管理服务
  429. // @Accept x-www-form-urlencoded
  430. // @Produce json
  431. // @Param scd_id formData int true "SCD文件ID"
  432. // @Param vol_id formData int false "电压等级ID"
  433. // @Param link_style_id formData int false "接线方式ID"
  434. // @Success 200 {object} ResultOK 成功
  435. // @Failure 500 {object} ResultError 失败
  436. // @router /admin/get/check_area [get]
  437. func (c *BusAdminController) GetCheckAreaByVolID() {
  438. id, _ := c.GetInt64("scd_id")
  439. if id == 0 {
  440. c.Data["json"] = c.ResultError("SCD文件ID不能为空!")
  441. c.ServeJSON()
  442. return
  443. }
  444. volid, _ := c.GetInt("vol_id")
  445. lsid, _ := c.GetInt("link_style_id")
  446. obj := new(bo.CheckAreaMgr)
  447. obj.SetUserInfo(c.GetCurrentUserInfo())
  448. obj.ScdId = id
  449. lst, err := obj.GetAreaListByVol(id, volid, lsid)
  450. if err != nil {
  451. c.Data["json"] = c.ResultError(err.Error())
  452. c.ServeJSON()
  453. return
  454. }
  455. c.Data["json"] = c.ResultOK(lst, 0)
  456. c.ServeJSON()
  457. }