123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- package stl
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/services/data/stl"
- "eta/eta_api/utils"
- "eta/eta_api/models/data_manage/stl/request"
- "eta/eta_api/models/data_manage/stl/response"
- )
- type STLController struct {
- controllers.BaseAuthController
- }
- // Preview
- // @Title STL分解预览
- // @Description STL分解预览
- // @Success 200 {object} request.STLReq
- // @router /chart_info/preview [post]
- func (c *STLController) Preview() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req *request.StlConfigReq
- if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "请求参数错误"
- br.ErrMsg = err.Error()
- return
- }
- resp, msg, err := stl.GenerateStlEdbData(req, sysUser.AdminId)
- if err != nil {
- if msg == "" {
- msg = "预览异常"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Data = resp
- br.Msg = "预览成功"
- br.Ret = 200
- br.Success = true
- return
- }
- // SaveConf
- // @Title STL分解配置保存
- // @Description STL分解配置保存
- // @Success 200 {object} request.STLReq
- // @router /config/save [post]
- func (c *STLController) SaveConf() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req *request.StlConfigReq
- if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "请求参数错误"
- br.ErrMsg = err.Error()
- return
- }
- configId, msg, err := stl.SaveStlConfig(req, sysUser.AdminId)
- if err != nil {
- if msg == "" {
- msg = "保存异常"
- }
- br.Msg = msg
- br.ErrMsg = "保存失败,err:" + err.Error()
- return
- }
- resp := new(response.SaveStlConfigResp)
- resp.CalculateStlConfigId = configId
- br.Data = resp
- br.Msg = "保存成功"
- br.Ret = 200
- br.Success = true
- }
- // ConfigDetail
- // @Title STL分解配置保存
- // @Description STL分解配置保存
- // @Success 200 {object} request.STLReq
- // @router /config/detail [get]
- func (c *STLController) ConfigDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, err := c.GetInt("EdbInfoId")
- if err != nil {
- br.Msg = "请求参数错误"
- br.ErrMsg = err.Error()
- return
- }
- resp, msg, err := stl.GetStlConfig(edbInfoId)
- if err != nil {
- if msg == "" {
- msg = "获取异常"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // SaveStlEdbInfo
- // @Title STL分解指标保存到指标库
- // @Description STL分解指标保存到指标库
- // @Success 200 {object} request.STLReq
- // @router /edb_info/save [post]
- func (c *STLController) SaveStlEdbInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- c.Data["json"] = br
- c.ServeJSON()
- }()
- var req *request.SaveStlEdbInfoReq
- if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "请求参数错误"
- br.ErrMsg = err.Error()
- return
- }
- sysUser := c.SysUser
- edbInfoId, IsSendEmail, msg, err := stl.SaveStlEdbInfo(req, sysUser.AdminId, sysUser.RealName, c.Lang)
- if err != nil {
- if msg == "" {
- msg = "保存异常"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- resp := new(response.SaveStlEdbInfoResp)
- resp.EdbInfoId = edbInfoId
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsSendEmail = IsSendEmail
- }
- // EdbInfoFilterByEs
- // @Title 指标筛选接口
- // @Description 指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/search [get]
- func (this *STLController) EdbInfoFilterByEs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- resp, msg, err := stl.SearchEdbInfoWithStl(this.SysUser.AdminId, keyWord, currentIndex, pageSize)
- if err != nil {
- if msg == "" {
- msg = "获取异常"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|