custom_analysis_edb.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package excel
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. excelModel "eta/eta_api/models/data_manage/excel"
  6. "eta/eta_api/models/data_manage/excel/request"
  7. "eta/eta_api/models/data_manage/excel/response"
  8. "eta/eta_api/services/data/excel"
  9. "eta/eta_api/utils"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. // AddEdb
  15. // @Title 新增指标接口
  16. // @Description 新增指标接口
  17. // @Param request body request.AddExcelInfoReq true "type json string"
  18. // @Success 200 {object} response.AddExcelInfoResp
  19. // @router /edb/add [post]
  20. func (c *CustomAnalysisController) AddEdb() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. c.Data["json"] = br
  24. c.ServeJSON()
  25. }()
  26. sysUser := c.SysUser
  27. if sysUser == nil {
  28. br.Msg = "请登录"
  29. br.ErrMsg = "请登录,SysUser Is Empty"
  30. br.Ret = 408
  31. return
  32. }
  33. deleteCache := true
  34. cacheKey := "CACHE_EXCEL_TABLE_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  35. defer func() {
  36. if deleteCache {
  37. _ = utils.Rc.Delete(cacheKey)
  38. }
  39. }()
  40. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  41. deleteCache = false
  42. br.Msg = "系统处理中,请稍后重试!"
  43. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  44. return
  45. }
  46. var req request.AddEdb
  47. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  48. if err != nil {
  49. br.Msg = "参数解析异常!"
  50. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  51. return
  52. }
  53. req.EdbName = strings.Trim(req.EdbName, " ")
  54. if req.EdbName == "" {
  55. br.Msg = "请填写指标名称!"
  56. br.IsSendEmail = false
  57. return
  58. }
  59. if req.ExcelInfoId <= 0 {
  60. br.Msg = "请选择excel!"
  61. br.IsSendEmail = false
  62. return
  63. }
  64. if req.ClassifyId <= 0 {
  65. br.Msg = "请选择指标分类!"
  66. br.IsSendEmail = false
  67. return
  68. }
  69. excelInfo, err := excelModel.GetExcelInfoById(req.ExcelInfoId)
  70. if err != nil {
  71. br.Msg = "找不到该EXCEL!"
  72. br.ErrMsg = "找不到该EXCEL!err:" + err.Error()
  73. return
  74. }
  75. if excelInfo.Source != utils.CUSTOM_ANALYSIS_TABLE {
  76. br.Msg = "EXCEL异常!"
  77. br.IsSendEmail = false
  78. return
  79. }
  80. excel.GetCustomAnalysisExcelData(excelInfo)
  81. //err, errMsg, isSendEmail := excel.SaveCustomAnalysisTable(excelInfo, utils.TrimLRStr(req.ExcelName), req.Content, req.ExcelImage, req.ExcelClassifyId, req.OpSheetList)
  82. //if err != nil {
  83. // br.Msg = "保存失败"
  84. // if errMsg != `` {
  85. // br.Msg = errMsg
  86. // }
  87. // br.ErrMsg = "保存失败,Err:" + err.Error()
  88. // br.IsSendEmail = isSendEmail
  89. // return
  90. //}
  91. // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
  92. //if req.Source == 1 {
  93. // go UpdateExcelInfoFileUrl(excelInfo)
  94. //}
  95. //
  96. resp := new(response.AddExcelInfoResp)
  97. resp.ExcelInfoId = excelInfo.ExcelInfoId
  98. resp.UniqueCode = excelInfo.UniqueCode
  99. //新增操作日志
  100. //{
  101. // excelLog := &data_manage.ExcelInfoLog{
  102. // //ExcelInfoLogId: 0,
  103. // ExcelInfoId: excelInfo.ExcelInfoId,
  104. // ExcelName: req.ExcelName,
  105. // ExcelClassifyId: req.ExcelClassifyId,
  106. // SysUserId: sysUser.AdminId,
  107. // SysUserRealName: sysUser.RealName,
  108. // UniqueCode: excelInfo.UniqueCode,
  109. // CreateTime: time.Now(),
  110. // Content: string(c.Ctx.Input.RequestBody),
  111. // Status: "新增表格",
  112. // Method: c.Ctx.Input.URI(),
  113. // }
  114. // go data_manage.AddExcelInfoLog(excelLog)
  115. //}
  116. br.Ret = 200
  117. br.Success = true
  118. br.Msg = "保存成功"
  119. br.Data = resp
  120. br.IsAddLog = false //数据量太大了,不写入日志吧
  121. }
  122. //func init() {
  123. // excelInfo, err := excelModel.GetExcelInfoById(160)
  124. // if err != nil {
  125. // fmt.Println("查找excel失败:", err)
  126. // return
  127. // }
  128. // _, err, _ = excel.GenerateExcelCustomAnalysisExcel(excelInfo)
  129. // if err != nil {
  130. // fmt.Println("生成excel失败:", err)
  131. // return
  132. // }
  133. //}