stl.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package stl
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/services/data/stl"
  7. "eta/eta_api/utils"
  8. "eta/eta_api/models/data_manage/stl/request"
  9. "eta/eta_api/models/data_manage/stl/response"
  10. )
  11. type STLController struct {
  12. controllers.BaseAuthController
  13. }
  14. // Preview
  15. // @Title STL分解预览
  16. // @Description STL分解预览
  17. // @Success 200 {object} request.STLReq
  18. // @router /chart_info/preview [post]
  19. func (c *STLController) Preview() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. c.Data["json"] = br
  23. c.ServeJSON()
  24. }()
  25. sysUser := c.SysUser
  26. if sysUser == nil {
  27. br.Msg = "请登录"
  28. br.ErrMsg = "请登录,SysUser Is Empty"
  29. br.Ret = 408
  30. return
  31. }
  32. var req *request.StlConfigReq
  33. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  34. br.Msg = "请求参数错误"
  35. br.ErrMsg = err.Error()
  36. return
  37. }
  38. resp, msg, err := stl.GenerateStlEdbData(req, sysUser.AdminId)
  39. if err != nil {
  40. if msg == "" {
  41. msg = "预览异常"
  42. }
  43. br.Msg = msg
  44. br.ErrMsg = err.Error()
  45. return
  46. }
  47. br.Data = resp
  48. br.Msg = "预览成功"
  49. br.Ret = 200
  50. br.Success = true
  51. return
  52. }
  53. // SaveConf
  54. // @Title STL分解配置保存
  55. // @Description STL分解配置保存
  56. // @Success 200 {object} request.STLReq
  57. // @router /config/save [post]
  58. func (c *STLController) SaveConf() {
  59. br := new(models.BaseResponse).Init()
  60. defer func() {
  61. c.Data["json"] = br
  62. c.ServeJSON()
  63. }()
  64. sysUser := c.SysUser
  65. if sysUser == nil {
  66. br.Msg = "请登录"
  67. br.ErrMsg = "请登录,SysUser Is Empty"
  68. br.Ret = 408
  69. return
  70. }
  71. var req *request.StlConfigReq
  72. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  73. br.Msg = "请求参数错误"
  74. br.ErrMsg = err.Error()
  75. return
  76. }
  77. configId, msg, err := stl.SaveStlConfig(req, sysUser.AdminId)
  78. if err != nil {
  79. if msg == "" {
  80. msg = "保存异常"
  81. }
  82. br.Msg = msg
  83. br.ErrMsg = "保存失败,err:" + err.Error()
  84. return
  85. }
  86. resp := new(response.SaveStlConfigResp)
  87. resp.CalculateStlConfigId = configId
  88. br.Data = resp
  89. br.Msg = "保存成功"
  90. br.Ret = 200
  91. br.Success = true
  92. }
  93. // ConfigDetail
  94. // @Title STL分解配置保存
  95. // @Description STL分解配置保存
  96. // @Success 200 {object} request.STLReq
  97. // @router /config/detail [get]
  98. func (c *STLController) ConfigDetail() {
  99. br := new(models.BaseResponse).Init()
  100. defer func() {
  101. c.Data["json"] = br
  102. c.ServeJSON()
  103. }()
  104. sysUser := c.SysUser
  105. if sysUser == nil {
  106. br.Msg = "请登录"
  107. br.ErrMsg = "请登录,SysUser Is Empty"
  108. br.Ret = 408
  109. return
  110. }
  111. edbInfoId, err := c.GetInt("EdbInfoId")
  112. if err != nil {
  113. br.Msg = "请求参数错误"
  114. br.ErrMsg = err.Error()
  115. return
  116. }
  117. resp, msg, err := stl.GetStlConfig(edbInfoId)
  118. if err != nil {
  119. if msg == "" {
  120. msg = "获取异常"
  121. }
  122. br.Msg = msg
  123. br.ErrMsg = err.Error()
  124. return
  125. }
  126. br.Ret = 200
  127. br.Success = true
  128. br.Msg = "获取成功"
  129. br.Data = resp
  130. }
  131. // SaveStlEdbInfo
  132. // @Title STL分解指标保存到指标库
  133. // @Description STL分解指标保存到指标库
  134. // @Success 200 {object} request.STLReq
  135. // @router /edb_info/save [post]
  136. func (c *STLController) SaveStlEdbInfo() {
  137. br := new(models.BaseResponse).Init()
  138. defer func() {
  139. c.Data["json"] = br
  140. c.ServeJSON()
  141. }()
  142. var req *request.SaveStlEdbInfoReq
  143. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  144. br.Msg = "请求参数错误"
  145. br.ErrMsg = err.Error()
  146. return
  147. }
  148. sysUser := c.SysUser
  149. edbInfoId, IsSendEmail, msg, err := stl.SaveStlEdbInfo(req, sysUser.AdminId, sysUser.RealName, c.Lang)
  150. if err != nil {
  151. if msg == "" {
  152. msg = "保存异常"
  153. }
  154. br.Msg = msg
  155. br.ErrMsg = err.Error()
  156. return
  157. }
  158. resp := new(response.SaveStlEdbInfoResp)
  159. resp.EdbInfoId = edbInfoId
  160. br.Data = resp
  161. br.Ret = 200
  162. br.Success = true
  163. br.Msg = "保存成功"
  164. br.IsSendEmail = IsSendEmail
  165. }
  166. // EdbInfoFilterByEs
  167. // @Title 指标筛选接口
  168. // @Description 指标筛选接口
  169. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  170. // @Param PageSize query int true "每页数据条数"
  171. // @Param CurrentIndex query int true "当前页页码,从1开始"
  172. // @Success 200 {object} data_manage.EdbInfoList
  173. // @router /edb_info/search [get]
  174. func (this *STLController) EdbInfoFilterByEs() {
  175. br := new(models.BaseResponse).Init()
  176. defer func() {
  177. this.Data["json"] = br
  178. this.ServeJSON()
  179. }()
  180. pageSize, _ := this.GetInt("PageSize")
  181. currentIndex, _ := this.GetInt("CurrentIndex")
  182. keyWord := this.GetString("KeyWord")
  183. if pageSize <= 0 {
  184. pageSize = utils.PageSize20
  185. }
  186. if currentIndex <= 0 {
  187. currentIndex = 1
  188. }
  189. resp, msg, err := stl.SearchEdbInfoWithStl(this.SysUser.AdminId, keyWord, currentIndex, pageSize)
  190. if err != nil {
  191. if msg == "" {
  192. msg = "获取异常"
  193. }
  194. br.Msg = msg
  195. br.ErrMsg = err.Error()
  196. return
  197. }
  198. br.Ret = 200
  199. br.Success = true
  200. br.Msg = "获取成功"
  201. br.Data = resp
  202. }