edb_inspection.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage/edb_inspection"
  6. "eta/eta_api/services/data"
  7. "eta/eta_api/controllers"
  8. )
  9. type EdbInspectionController struct {
  10. controllers.BaseAuthController
  11. }
  12. // InspectionSourceList
  13. // @Title 获取巡检配置的来源接口
  14. // @Description 获取巡检配置的来源接口
  15. // @Success Ret=200 获取成功
  16. // @router /edb_inspection/source_list [get]
  17. func (c *EdbInspectionController) InspectionSourceList() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. c.Data["json"] = br
  21. c.ServeJSON()
  22. }()
  23. // 这里可以添加获取巡检来源的逻辑
  24. // 目前暂时返回空列表
  25. list := make([]interface{}, 0)
  26. br.Ret = 200
  27. br.Success = true
  28. br.Msg = "获取成功"
  29. br.Data = list
  30. }
  31. // InspectionConfigList
  32. // @Title 获取巡检配置列表接口
  33. // @Description 获取巡检配置列表接口
  34. // @Param Source query int true "来源"
  35. // @Param TerminalCode query string false "终端编码"
  36. // @Success Ret=200 获取成功
  37. // @router /edb_inspection/config/list [get]
  38. func (c *EdbInspectionController) InspectionConfigList() {
  39. br := new(models.BaseResponse).Init()
  40. defer func() {
  41. c.Data["json"] = br
  42. c.ServeJSON()
  43. }()
  44. source, _ := c.GetInt("Source")
  45. terminalCode := c.GetString("TerminalCode")
  46. if source <= 0 {
  47. br.Msg = "来源不能为空"
  48. br.IsSendEmail = false
  49. return
  50. }
  51. list, err, errMsg, isSendEmail := data.GetConfigList(source, terminalCode)
  52. if err != nil {
  53. br.Msg = errMsg
  54. br.ErrMsg = "获取失败,Err:" + err.Error()
  55. br.IsSendEmail = isSendEmail
  56. return
  57. }
  58. br.Ret = 200
  59. br.Success = true
  60. br.Msg = "获取成功"
  61. br.Data = list
  62. }
  63. // SaveInspectionConfig
  64. // @Title 设置巡检配置接口
  65. // @Description 设置巡检配置接口
  66. // @Param request body edb_inspection.EdbInspectionConfigAddReq true "type json string"
  67. // @Success Ret=200 保存成功
  68. // @router /edb_inspection/config/save [post]
  69. func (c *EdbInspectionController) SaveInspectionConfig() {
  70. br := new(models.BaseResponse).Init()
  71. defer func() {
  72. c.Data["json"] = br
  73. c.ServeJSON()
  74. }()
  75. var req edb_inspection.EdbInspectionConfigAddReq
  76. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  77. if err != nil {
  78. br.Msg = "参数解析异常!"
  79. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  80. return
  81. }
  82. // 保存
  83. err, errMsg, isSendEmail := data.SaveEdbInspectionConfig(&req)
  84. if err != nil {
  85. br.Msg = errMsg
  86. br.ErrMsg = "保存失败,Err:" + err.Error()
  87. br.IsSendEmail = isSendEmail
  88. return
  89. }
  90. br.Ret = 200
  91. br.Success = true
  92. br.Msg = "保存成功"
  93. }
  94. // UpdateInspectionConfigStatus
  95. // @Title 更新巡检配置状态接口
  96. // @Description 更新巡检配置状态接口
  97. // @Param ConfigId query int64 true "配置ID"
  98. // @Param Status query int8 true "状态"
  99. // @Success Ret=200 更新成功
  100. // @router /edb_inspection/config/status/update [post]
  101. func (c *EdbInspectionController) UpdateInspectionConfigStatus() {
  102. br := new(models.BaseResponse).Init()
  103. defer func() {
  104. c.Data["json"] = br
  105. c.ServeJSON()
  106. }()
  107. var req edb_inspection.EdbInspectionConfigStatusReq
  108. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  109. if err != nil {
  110. br.Msg = "参数解析异常!"
  111. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  112. return
  113. }
  114. configId := req.ConfigId
  115. status := req.Status
  116. if status != 1 && status != 0 {
  117. br.Msg = "状态错误"
  118. br.ErrMsg = "状态错误,请输入1或0"
  119. br.IsSendEmail = false
  120. return
  121. }
  122. if configId <= 0 {
  123. br.Msg = "配置ID不能为空"
  124. br.IsSendEmail = false
  125. return
  126. }
  127. config := &edb_inspection.EdbInspectionConfig{
  128. ConfigId: configId,
  129. }
  130. err = config.UpdateStatus(status)
  131. if err != nil {
  132. br.Msg = "更新失败"
  133. br.ErrMsg = "更新失败,Err:" + err.Error()
  134. return
  135. }
  136. br.Ret = 200
  137. br.Success = true
  138. br.Msg = "更新成功"
  139. }
  140. // DeleteInspectionConfig
  141. // @Title 删除巡检配置接口
  142. // @Description 删除巡检配置接口
  143. // @Param ConfigId query int64 true "配置ID"
  144. // @Success Ret=200 删除成功
  145. // @router /edb_inspection/config/delete [post]
  146. func (c *EdbInspectionController) DeleteInspectionConfig() {
  147. br := new(models.BaseResponse).Init()
  148. defer func() {
  149. c.Data["json"] = br
  150. c.ServeJSON()
  151. }()
  152. var req edb_inspection.EdbInspectionConfigDeleteReq
  153. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  154. if err != nil {
  155. br.Msg = "参数解析异常!"
  156. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  157. return
  158. }
  159. configId := req.ConfigId
  160. if configId <= 0 {
  161. br.Msg = "配置ID不能为空"
  162. br.IsSendEmail = false
  163. return
  164. }
  165. config := &edb_inspection.EdbInspectionConfig{
  166. ConfigId: configId,
  167. }
  168. err = config.Delete()
  169. if err != nil {
  170. br.Msg = "删除失败"
  171. br.ErrMsg = "删除失败,Err:" + err.Error()
  172. return
  173. }
  174. _ = edb_inspection.DeleteEdbInspectionDateConfigByConfigId(configId)
  175. br.Ret = 200
  176. br.Success = true
  177. br.Msg = "删除成功"
  178. }
  179. // GetInspectionConfigDetail
  180. // @Title 获取巡检配置详情接口
  181. // @Description 获取巡检配置详情接口
  182. // @Param ConfigId query int64 true "配置ID"
  183. // @Success Ret=200 获取成功
  184. // @router /edb_inspection/config/detail [get]
  185. func (c *EdbInspectionController) GetInspectionConfigDetail() {
  186. br := new(models.BaseResponse).Init()
  187. defer func() {
  188. c.Data["json"] = br
  189. c.ServeJSON()
  190. }()
  191. configId, _ := c.GetInt64("ConfigId")
  192. if configId <= 0 {
  193. br.Msg = "配置ID不能为空"
  194. br.IsSendEmail = false
  195. return
  196. }
  197. detail, err := data.GetConfigDetail(configId)
  198. if err != nil {
  199. br.Msg = "获取失败"
  200. br.ErrMsg = "获取失败,Err:" + err.Error()
  201. return
  202. }
  203. br.Ret = 200
  204. br.Success = true
  205. br.Msg = "获取成功"
  206. br.Data = detail
  207. }