123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_forum_hub/models"
- "eta/eta_forum_hub/services"
- "eta/eta_forum_hub/utils"
- "strings"
- "time"
- )
- type ChartInfoController struct {
- BaseAuthController
- }
- // Update
- // @Title 图表-更新
- // @Description 图表-更新
- // @Param request body data_manage.AddChartReq true "type json string"
- // @Success 200 {object} data_manage.AddChartInfoResp
- // @router /update [post]
- func (this *ChartInfoController) Update() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- /*deleteCache := true
- cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }*/
- var req models.AddChartReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartInfo == nil {
- br.Msg = "请选择图表"
- return
- }
- if req.ChartInfo.ChartInfoId <= 0 {
- br.Msg = "请选择图表"
- return
- }
- //校验图表名称是否重复
- req.ChartInfo.ChartName = strings.Trim(req.ChartInfo.ChartName, " ")
- if req.ChartInfo.ChartName == "" {
- br.Msg = "请填写图表名称!"
- return
- }
- if len(req.EdbInfoList) <= 0 {
- br.Msg = "指标信息不能为空"
- return
- }
- for _, edbInfo := range req.EdbInfoList {
- if edbInfo.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- }
- if len(req.ChartEdbMapping) <= 0 {
- br.Msg = "图表指标映射不能为空"
- return
- }
- chartInfo, err, errMsg, _ := services.UpdateChartInfoAndEdbInfo(&req, 0, "")
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = models.AddChartInfoResp{
- ChartInfoId: chartInfo.ChartInfoId,
- UniqueCode: chartInfo.UniqueCode,
- ChartType: chartInfo.ChartType,
- }
- return
- }
- // Save
- // @Title 图表-保存
- // @Description 图表-保存
- // @Param request body data_manage.AddChartReq true "type json string"
- // @Success 200 {object} data_manage.AddChartInfoResp
- // @router /save [post]
- func (this *ChartInfoController) Save() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.AddChartReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartInfo == nil {
- br.Msg = "请选择图表"
- return
- }
- //校验图表名称是否重复
- req.ChartInfo.ChartName = strings.Trim(req.ChartInfo.ChartName, " ")
- if req.ChartInfo.ChartName == "" {
- br.Msg = "请填写图表名称!"
- return
- }
- if len(req.EdbInfoList) <= 0 {
- br.Msg = "指标信息不能为空"
- return
- }
- for _, edbInfo := range req.EdbInfoList {
- if edbInfo.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- }
- if len(req.ChartEdbMapping) <= 0 {
- br.Msg = "图表指标映射不能为空"
- return
- }
- deleteCache := true
- cacheKey := "eta_forum_hub:CACHE_CHART_INFO_ADD:" + req.ChartInfo.ChartName
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!;data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- chartInfo, err, errMsg, _ := services.AddChartInfo(&req, 0, "")
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = models.AddChartInfoResp{
- ChartInfoId: chartInfo.ChartInfoId,
- UniqueCode: chartInfo.UniqueCode,
- ChartType: chartInfo.ChartType,
- }
- return
- }
- // Delete
- // @Title 图表-删除
- // @Description 图表-删除
- // @Param request body data_manage.DeleteChartReq true "type json string"
- // @Success 200 {object}
- // @router /delete [post]
- func (this *ChartInfoController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DeleteChartReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.ChartInfoId <= 0 {
- br.Msg = "请选择图表"
- return
- }
- err, errMsg := services.DeleteChart(req.ChartInfoId)
- if err != nil {
- br.Msg = errMsg
- br.ErrMsg = err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
|