edb_inspection.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. list, err, errMsg, isSendEmail := data.GetConfigList(source, terminalCode)
  47. if err != nil {
  48. br.Msg = errMsg
  49. br.ErrMsg = "获取失败,Err:" + err.Error()
  50. br.IsSendEmail = isSendEmail
  51. return
  52. }
  53. br.Ret = 200
  54. br.Success = true
  55. br.Msg = "获取成功"
  56. br.Data = list
  57. }
  58. // SaveInspectionConfig
  59. // @Title 设置巡检配置接口
  60. // @Description 设置巡检配置接口
  61. // @Param request body edb_inspection.EdbInspectionConfigAddReq true "type json string"
  62. // @Success Ret=200 保存成功
  63. // @router /edb_inspection/config/save [post]
  64. func (c *EdbInspectionController) SaveInspectionConfig() {
  65. br := new(models.BaseResponse).Init()
  66. defer func() {
  67. c.Data["json"] = br
  68. c.ServeJSON()
  69. }()
  70. var req edb_inspection.EdbInspectionConfigAddReq
  71. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  72. if err != nil {
  73. br.Msg = "参数解析异常!"
  74. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  75. return
  76. }
  77. // 保存
  78. err, errMsg, isSendEmail := data.SaveEdbInspectionConfig(&req)
  79. if err != nil {
  80. br.Msg = errMsg
  81. br.ErrMsg = "保存失败,Err:" + err.Error()
  82. br.IsSendEmail = isSendEmail
  83. return
  84. }
  85. br.Ret = 200
  86. br.Success = true
  87. br.Msg = "保存成功"
  88. }
  89. // UpdateInspectionConfigStatus
  90. // @Title 更新巡检配置状态接口
  91. // @Description 更新巡检配置状态接口
  92. // @Param ConfigId query int64 true "配置ID"
  93. // @Param Status query int8 true "状态"
  94. // @Success Ret=200 更新成功
  95. // @router /edb_inspection/config/status/update [post]
  96. func (c *EdbInspectionController) UpdateInspectionConfigStatus() {
  97. br := new(models.BaseResponse).Init()
  98. defer func() {
  99. c.Data["json"] = br
  100. c.ServeJSON()
  101. }()
  102. var req edb_inspection.EdbInspectionConfigStatusReq
  103. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  104. if err != nil {
  105. br.Msg = "参数解析异常!"
  106. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  107. return
  108. }
  109. configId := req.ConfigId
  110. status := req.Status
  111. if status != 1 && status != 0 {
  112. br.Msg = "状态错误"
  113. br.ErrMsg = "状态错误,请输入1或0"
  114. br.IsSendEmail = false
  115. return
  116. }
  117. if configId <= 0 {
  118. br.Msg = "配置ID不能为空"
  119. br.IsSendEmail = false
  120. return
  121. }
  122. config := &edb_inspection.EdbInspectionConfig{
  123. ConfigId: configId,
  124. }
  125. err = config.UpdateStatus(status)
  126. if err != nil {
  127. br.Msg = "更新失败"
  128. br.ErrMsg = "更新失败,Err:" + err.Error()
  129. return
  130. }
  131. br.Ret = 200
  132. br.Success = true
  133. br.Msg = "更新成功"
  134. }
  135. // DeleteInspectionConfig
  136. // @Title 删除巡检配置接口
  137. // @Description 删除巡检配置接口
  138. // @Param ConfigId query int64 true "配置ID"
  139. // @Success Ret=200 删除成功
  140. // @router /edb_inspection/config/delete [post]
  141. func (c *EdbInspectionController) DeleteInspectionConfig() {
  142. br := new(models.BaseResponse).Init()
  143. defer func() {
  144. c.Data["json"] = br
  145. c.ServeJSON()
  146. }()
  147. var req edb_inspection.EdbInspectionConfigDeleteReq
  148. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  149. if err != nil {
  150. br.Msg = "参数解析异常!"
  151. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  152. return
  153. }
  154. configId := req.ConfigId
  155. if configId <= 0 {
  156. br.Msg = "配置ID不能为空"
  157. br.IsSendEmail = false
  158. return
  159. }
  160. config := &edb_inspection.EdbInspectionConfig{
  161. ConfigId: configId,
  162. }
  163. err = config.Delete()
  164. if err != nil {
  165. br.Msg = "删除失败"
  166. br.ErrMsg = "删除失败,Err:" + err.Error()
  167. return
  168. }
  169. _ = edb_inspection.DeleteEdbInspectionDateConfigByConfigId(configId)
  170. br.Ret = 200
  171. br.Success = true
  172. br.Msg = "删除成功"
  173. }
  174. // GetInspectionConfigDetail
  175. // @Title 获取巡检配置详情接口
  176. // @Description 获取巡检配置详情接口
  177. // @Param ConfigId query int64 true "配置ID"
  178. // @Success Ret=200 获取成功
  179. // @router /edb_inspection/config/detail [get]
  180. func (c *EdbInspectionController) GetInspectionConfigDetail() {
  181. br := new(models.BaseResponse).Init()
  182. defer func() {
  183. c.Data["json"] = br
  184. c.ServeJSON()
  185. }()
  186. configId, _ := c.GetInt64("ConfigId")
  187. if configId <= 0 {
  188. br.Msg = "配置ID不能为空"
  189. br.IsSendEmail = false
  190. return
  191. }
  192. detail, err := data.GetConfigDetail(configId)
  193. if err != nil {
  194. br.Msg = "获取失败"
  195. br.ErrMsg = "获取失败,Err:" + err.Error()
  196. return
  197. }
  198. br.Ret = 200
  199. br.Success = true
  200. br.Msg = "获取成功"
  201. br.Data = detail
  202. }