residual_analysis_controller.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. resp, err := residual_analysis_service.ContrastPreview(IndexCode)
  81. if err != nil {
  82. return
  83. }
  84. br.Ret = 200
  85. br.Success = true
  86. br.Msg = "获取成功"
  87. br.Data = resp
  88. }
  89. // SaveResidualAnalysis
  90. // @Title 保存残差分析指标
  91. // @Description 保存残差分析指标
  92. // @Success 200
  93. // @router /save/residual/analysis [post]
  94. func (this *ResidualAnalysisController) SaveResidualAnalysis() {
  95. br := new(models.BaseResponse).Init()
  96. defer func() {
  97. this.Data["json"] = br
  98. this.ServeJSON()
  99. }()
  100. sysUser := this.SysUser
  101. if sysUser == nil {
  102. br.Msg = "请登录"
  103. br.ErrMsg = "请登录,SysUser Is Empty"
  104. br.Ret = 408
  105. return
  106. }
  107. var req residual_analysis_model.ResidualAnalysisIndexSaveReq
  108. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  109. if err != nil {
  110. br.Msg = "参数解析异常!"
  111. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  112. return
  113. }
  114. if req.ClassifyId == 0 {
  115. br.Msg = "分类id不能为空"
  116. br.ErrMsg = "分类id不能为空"
  117. return
  118. }
  119. if req.Source == 0 {
  120. br.Msg = "来源不能为空"
  121. br.ErrMsg = "来源不能为空"
  122. return
  123. }
  124. err = residual_analysis_service.SaveResidualAnalysis(req, sysUser)
  125. if err != nil {
  126. br.Ret = 403
  127. br.Msg = err.Error()
  128. br.ErrMsg = err.Error()
  129. return
  130. }
  131. br.Ret = 200
  132. br.Success = true
  133. br.Msg = "添加成功"
  134. }
  135. // SaveResidualAnalysisConfig
  136. // @Title 保存残差指标配置
  137. // @Description 保存残差指标配置
  138. // @Success 200
  139. // @router /save/residual/analysis/config [post]
  140. func (this *ResidualAnalysisController) SaveResidualAnalysisConfig() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. sysUser := this.SysUser
  147. if sysUser == nil {
  148. br.Msg = "请登录"
  149. br.ErrMsg = "请登录,SysUser Is Empty"
  150. br.Ret = 408
  151. return
  152. }
  153. var req residual_analysis_model.ResidualAnalysisReq
  154. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  155. if err != nil {
  156. br.Msg = "参数解析异常!"
  157. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  158. return
  159. }
  160. configId, err := residual_analysis_service.SaveResidualAnalysisConfig(req, sysUser)
  161. if err != nil {
  162. br.Ret = 403
  163. br.Msg = "保存失败"
  164. br.ErrMsg = err.Error()
  165. return
  166. }
  167. br.Ret = 200
  168. br.Success = true
  169. br.Msg = "添加成功"
  170. br.Data = configId
  171. }
  172. // ResidualAnalysisDetail
  173. // @Title 残差分析指标详情
  174. // @Description 残差分析指标详情
  175. // @Success 200 {object} []*data_manage.EdbInfoList
  176. // @router /residual/analysis/detail [get]
  177. func (this *ResidualAnalysisController) ResidualAnalysisDetail() {
  178. br := new(models.BaseResponse).Init()
  179. defer func() {
  180. this.Data["json"] = br
  181. this.ServeJSON()
  182. }()
  183. sysUser := this.SysUser
  184. if sysUser == nil {
  185. br.Msg = "请登录"
  186. br.ErrMsg = "请登录,SysUser Is Empty"
  187. br.Ret = 408
  188. return
  189. }
  190. EdbInfoId, err := this.GetInt("EdbInfoId")
  191. if err != nil {
  192. br.Msg = "EdbInfoId参数异常!"
  193. br.ErrMsg = "EdbInfoId参数解析失败,Err:" + err.Error()
  194. }
  195. if EdbInfoId <= 0 {
  196. br.Msg = "EdbInfoId参数异常!"
  197. br.ErrMsg = "EdbInfoId参数异常!"
  198. }
  199. resp, err := residual_analysis_service.ResidualAnalysisDetail(EdbInfoId)
  200. if err != nil {
  201. br.Msg = "获取失败"
  202. br.ErrMsg = err.Error()
  203. br.Ret = 403
  204. return
  205. }
  206. br.Ret = 200
  207. br.Success = true
  208. br.Msg = "获取成功"
  209. br.Data = resp
  210. }
  211. // CheckResidualAnalysisExist
  212. // @Title 校验残差指标是否存在
  213. // @Description 校验残差指标是否存在
  214. // @Success 200 {object}
  215. // @router /check/residual/analysis/exist [get]
  216. func (this *ResidualAnalysisController) CheckResidualAnalysisExist() {
  217. br := new(models.BaseResponse).Init()
  218. defer func() {
  219. this.Data["json"] = br
  220. this.ServeJSON()
  221. }()
  222. sysUser := this.SysUser
  223. if sysUser == nil {
  224. br.Msg = "请登录"
  225. br.ErrMsg = "请登录,SysUser Is Empty"
  226. br.Ret = 408
  227. return
  228. }
  229. configId, err := this.GetInt("ConfigId")
  230. if err != nil {
  231. br.Msg = "EdbInfoId参数异常!"
  232. br.ErrMsg = "EdbInfoId参数解析失败,Err:" + err.Error()
  233. }
  234. if configId <= 0 {
  235. br.Msg = "ConfigId参数异常!"
  236. br.ErrMsg = "ConfigId参数异常!"
  237. }
  238. resp, err := residual_analysis_service.CheckResidualAnalysisExist(configId)
  239. if err != nil {
  240. br.Msg = "获取失败"
  241. br.ErrMsg = err.Error()
  242. br.Ret = 403
  243. return
  244. }
  245. br.Ret = 200
  246. br.Success = true
  247. br.Msg = "获取成功"
  248. br.Data = resp
  249. }