residual_analysis_controller.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. package residual_analysis
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/residual_analysis_model"
  7. "eta/eta_api/services/residual_analysis_service"
  8. )
  9. // ResidualAnalysisController 残差分析
  10. type ResidualAnalysisController struct {
  11. controllers.BaseAuthController
  12. }
  13. // ResidualAnalysisPreview
  14. // @Title 残差分析预览
  15. // @Description 残差分析预览
  16. // @Success 200 {object} residual_analysis_model.ResidualAnalysisResp
  17. // @router /residual/analysis/preview [post]
  18. func (this *ResidualAnalysisController) ResidualAnalysisPreview() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. sysUser := this.SysUser
  25. if sysUser == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,SysUser Is Empty"
  28. br.Ret = 408
  29. return
  30. }
  31. var req residual_analysis_model.ResidualAnalysisReq
  32. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  33. if err != nil {
  34. br.Msg = "参数解析异常!"
  35. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  36. return
  37. }
  38. if req.EdbInfoIdA == req.EdbInfoIdB {
  39. br.Msg = "自变量指标和因变量指标不能相同"
  40. br.ErrMsg = "自变量指标和因变量指标不能相同"
  41. return
  42. }
  43. resp, err := residual_analysis_service.ResidualAnalysisPreview(req)
  44. if err != nil {
  45. br.Ret = 403
  46. br.Msg = "获取失败"
  47. br.ErrMsg = err.Error()
  48. return
  49. }
  50. br.Ret = 200
  51. br.Success = true
  52. br.Msg = "获取成功"
  53. br.Data = resp
  54. }
  55. // ContrastPreview
  56. // @Title 对比指标预览
  57. // @Description 对比指标预览
  58. // @Success 200 {object} residual_analysis_model.ResidualAnalysisChartEdbInfoMapping
  59. // @router /contrast/preview [get]
  60. func (this *ResidualAnalysisController) ContrastPreview() {
  61. br := new(models.BaseResponse).Init()
  62. defer func() {
  63. this.Data["json"] = br
  64. this.ServeJSON()
  65. }()
  66. sysUser := this.SysUser
  67. if sysUser == nil {
  68. br.Msg = "请登录"
  69. br.ErrMsg = "请登录,SysUser Is Empty"
  70. br.Ret = 408
  71. return
  72. }
  73. indexCode := this.GetString("IndexCode")
  74. if indexCode == "" {
  75. br.Ret = 403
  76. br.Msg = "IndexCode不能为空"
  77. br.ErrMsg = "IndexCode不能为空"
  78. return
  79. }
  80. startTime := this.GetString("StartTime")
  81. endTime := this.GetString("EndTime")
  82. resp, err := residual_analysis_service.ContrastPreview(indexCode, startTime, endTime)
  83. if err != nil {
  84. return
  85. }
  86. br.Ret = 200
  87. br.Success = true
  88. br.Msg = "获取成功"
  89. br.Data = resp
  90. }
  91. // SaveResidualAnalysis
  92. // @Title 保存残差分析指标
  93. // @Description 保存残差分析指标
  94. // @Success 200
  95. // @router /save/residual/analysis [post]
  96. func (this *ResidualAnalysisController) SaveResidualAnalysis() {
  97. br := new(models.BaseResponse).Init()
  98. defer func() {
  99. this.Data["json"] = br
  100. this.ServeJSON()
  101. }()
  102. sysUser := this.SysUser
  103. if sysUser == nil {
  104. br.Msg = "请登录"
  105. br.ErrMsg = "请登录,SysUser Is Empty"
  106. br.Ret = 408
  107. return
  108. }
  109. var req residual_analysis_model.ResidualAnalysisIndexSaveReq
  110. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  111. if err != nil {
  112. br.Msg = "参数解析异常!"
  113. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  114. return
  115. }
  116. if req.ClassifyId == 0 {
  117. br.Msg = "分类id不能为空"
  118. br.ErrMsg = "分类id不能为空"
  119. return
  120. }
  121. if req.Source == 0 {
  122. br.Msg = "来源不能为空"
  123. br.ErrMsg = "来源不能为空"
  124. return
  125. }
  126. err = residual_analysis_service.SaveResidualAnalysis(req, sysUser)
  127. if err != nil {
  128. br.Ret = 403
  129. br.Msg = err.Error()
  130. br.ErrMsg = err.Error()
  131. return
  132. }
  133. br.Ret = 200
  134. br.Success = true
  135. br.Msg = "添加成功"
  136. }
  137. // SaveResidualAnalysisConfig
  138. // @Title 保存残差指标配置
  139. // @Description 保存残差指标配置
  140. // @Success 200
  141. // @router /save/residual/analysis/config [post]
  142. func (this *ResidualAnalysisController) SaveResidualAnalysisConfig() {
  143. br := new(models.BaseResponse).Init()
  144. defer func() {
  145. this.Data["json"] = br
  146. this.ServeJSON()
  147. }()
  148. sysUser := this.SysUser
  149. if sysUser == nil {
  150. br.Msg = "请登录"
  151. br.ErrMsg = "请登录,SysUser Is Empty"
  152. br.Ret = 408
  153. return
  154. }
  155. var req residual_analysis_model.ResidualAnalysisReq
  156. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  157. if err != nil {
  158. br.Msg = "参数解析异常!"
  159. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  160. return
  161. }
  162. configId, err := residual_analysis_service.SaveResidualAnalysisConfig(req, sysUser)
  163. if err != nil {
  164. br.Ret = 403
  165. br.Msg = "保存失败"
  166. br.ErrMsg = err.Error()
  167. return
  168. }
  169. br.Ret = 200
  170. br.Success = true
  171. br.Msg = "添加成功"
  172. br.Data = configId
  173. }
  174. // ResidualAnalysisDetail
  175. // @Title 残差分析指标详情
  176. // @Description 残差分析指标详情
  177. // @Success 200 {object} []*data_manage.EdbInfoList
  178. // @router /residual/analysis/detail [get]
  179. func (this *ResidualAnalysisController) ResidualAnalysisDetail() {
  180. br := new(models.BaseResponse).Init()
  181. defer func() {
  182. this.Data["json"] = br
  183. this.ServeJSON()
  184. }()
  185. sysUser := this.SysUser
  186. if sysUser == nil {
  187. br.Msg = "请登录"
  188. br.ErrMsg = "请登录,SysUser Is Empty"
  189. br.Ret = 408
  190. return
  191. }
  192. EdbInfoId, err := this.GetInt("EdbInfoId")
  193. if err != nil {
  194. br.Msg = "EdbInfoId参数异常!"
  195. br.ErrMsg = "EdbInfoId参数解析失败,Err:" + err.Error()
  196. }
  197. if EdbInfoId <= 0 {
  198. br.Msg = "EdbInfoId参数异常!"
  199. br.ErrMsg = "EdbInfoId参数异常!"
  200. }
  201. resp, err := residual_analysis_service.ResidualAnalysisDetail(EdbInfoId)
  202. if err != nil {
  203. br.Msg = "获取失败"
  204. br.ErrMsg = err.Error()
  205. br.Ret = 403
  206. return
  207. }
  208. br.Ret = 200
  209. br.Success = true
  210. br.Msg = "获取成功"
  211. br.Data = resp
  212. }
  213. // CheckResidualAnalysisExist
  214. // @Title 校验残差指标是否存在
  215. // @Description 校验残差指标是否存在
  216. // @Success 200 {object}
  217. // @router /check/residual/analysis/exist [get]
  218. func (this *ResidualAnalysisController) CheckResidualAnalysisExist() {
  219. br := new(models.BaseResponse).Init()
  220. defer func() {
  221. this.Data["json"] = br
  222. this.ServeJSON()
  223. }()
  224. sysUser := this.SysUser
  225. if sysUser == nil {
  226. br.Msg = "请登录"
  227. br.ErrMsg = "请登录,SysUser Is Empty"
  228. br.Ret = 408
  229. return
  230. }
  231. configId, err := this.GetInt("ConfigId")
  232. if err != nil {
  233. br.Msg = "EdbInfoId参数异常!"
  234. br.ErrMsg = "EdbInfoId参数解析失败,Err:" + err.Error()
  235. }
  236. if configId <= 0 {
  237. br.Msg = "ConfigId参数异常!"
  238. br.ErrMsg = "ConfigId参数异常!"
  239. }
  240. resp, err := residual_analysis_service.CheckResidualAnalysisExist(configId)
  241. if err != nil {
  242. br.Msg = "获取失败"
  243. br.ErrMsg = err.Error()
  244. br.Ret = 403
  245. return
  246. }
  247. br.Ret = 200
  248. br.Success = true
  249. br.Msg = "获取成功"
  250. br.Data = resp
  251. }