|
@@ -3,9 +3,10 @@ package excel
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"eta/eta_api/models"
|
|
|
+ "eta/eta_api/models/data_manage"
|
|
|
excelModel "eta/eta_api/models/data_manage/excel"
|
|
|
"eta/eta_api/models/data_manage/excel/request"
|
|
|
- "eta/eta_api/models/data_manage/excel/response"
|
|
|
+ "eta/eta_api/services/data"
|
|
|
"eta/eta_api/services/data/excel"
|
|
|
"eta/eta_api/utils"
|
|
|
"strconv"
|
|
@@ -16,8 +17,8 @@ import (
|
|
|
// AddEdb
|
|
|
// @Title 新增指标接口
|
|
|
// @Description 新增指标接口
|
|
|
-// @Param request body request.AddExcelInfoReq true "type json string"
|
|
|
-// @Success 200 {object} response.AddExcelInfoResp
|
|
|
+// @Param request body request.AddEdb true "type json string"
|
|
|
+// @Success 200 {object} data_manage.AddEdbInfoResp
|
|
|
// @router /edb/add [post]
|
|
|
func (c *CustomAnalysisController) AddEdb() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
@@ -34,7 +35,7 @@ func (c *CustomAnalysisController) AddEdb() {
|
|
|
return
|
|
|
}
|
|
|
deleteCache := true
|
|
|
- cacheKey := "CACHE_EXCEL_TABLE_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
|
|
|
+ cacheKey := "CACHE_EXCEL_TABLE_INFO_ADD_EDB_" + strconv.Itoa(sysUser.AdminId)
|
|
|
defer func() {
|
|
|
if deleteCache {
|
|
|
_ = utils.Rc.Delete(cacheKey)
|
|
@@ -85,45 +86,251 @@ func (c *CustomAnalysisController) AddEdb() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- excel.GetCustomAnalysisExcelData(excelInfo)
|
|
|
-
|
|
|
- //err, errMsg, isSendEmail := excel.SaveCustomAnalysisTable(excelInfo, utils.TrimLRStr(req.ExcelName), req.Content, req.ExcelImage, req.ExcelClassifyId, req.OpSheetList)
|
|
|
- //if err != nil {
|
|
|
- // br.Msg = "保存失败"
|
|
|
- // if errMsg != `` {
|
|
|
- // br.Msg = errMsg
|
|
|
- // }
|
|
|
- // br.ErrMsg = "保存失败,Err:" + err.Error()
|
|
|
- // br.IsSendEmail = isSendEmail
|
|
|
- // return
|
|
|
- //}
|
|
|
-
|
|
|
- // 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
|
|
|
- //if req.Source == 1 {
|
|
|
- // go UpdateExcelInfoFileUrl(excelInfo)
|
|
|
- //}
|
|
|
- //
|
|
|
- resp := new(response.AddExcelInfoResp)
|
|
|
- resp.ExcelInfoId = excelInfo.ExcelInfoId
|
|
|
- resp.UniqueCode = excelInfo.UniqueCode
|
|
|
-
|
|
|
- //新增操作日志
|
|
|
- //{
|
|
|
- // excelLog := &data_manage.ExcelInfoLog{
|
|
|
- // //ExcelInfoLogId: 0,
|
|
|
- // ExcelInfoId: excelInfo.ExcelInfoId,
|
|
|
- // ExcelName: req.ExcelName,
|
|
|
- // ExcelClassifyId: req.ExcelClassifyId,
|
|
|
- // SysUserId: sysUser.AdminId,
|
|
|
- // SysUserRealName: sysUser.RealName,
|
|
|
- // UniqueCode: excelInfo.UniqueCode,
|
|
|
- // CreateTime: time.Now(),
|
|
|
- // Content: string(c.Ctx.Input.RequestBody),
|
|
|
- // Status: "新增表格",
|
|
|
- // Method: c.Ctx.Input.URI(),
|
|
|
- // }
|
|
|
- // go data_manage.AddExcelInfoLog(excelLog)
|
|
|
- //}
|
|
|
+ //excel.GetCustomAnalysisExcelData(excelInfo)
|
|
|
+
|
|
|
+ dateList, dataList, err, errMsg := excel.HandleEdbSequenceVal(req.DateSequenceVal, req.DataSequenceVal)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "时间序列或数据序列异常!"
|
|
|
+ if errMsg != `` {
|
|
|
+ br.Msg = errMsg
|
|
|
+ }
|
|
|
+ br.ErrMsg = "时间序列或数据序列处理异常!err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ type CustomAnalysisData struct {
|
|
|
+ ExcelInfoId int `description:"excel的id"`
|
|
|
+ DateList []string
|
|
|
+ DataList []float64
|
|
|
+ }
|
|
|
+
|
|
|
+ type Formula struct {
|
|
|
+ DateSequenceStr string `description:"日期序列"`
|
|
|
+ DataSequenceStr string `description:"数据序列"`
|
|
|
+ }
|
|
|
+
|
|
|
+ formulaByte, err := json.Marshal(Formula{
|
|
|
+ DateSequenceStr: req.DateSequenceStr,
|
|
|
+ DataSequenceStr: req.DataSequenceStr,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "时间序列或数据序列配置异常!"
|
|
|
+ br.ErrMsg = "json序列化时间序列或数据序列异常!err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ req2 := &data_manage.EdbInfoCalculateBatchSaveReqByEdbLib{
|
|
|
+ AdminId: sysUser.AdminId,
|
|
|
+ AdminName: sysUser.RealName,
|
|
|
+ EdbName: req.EdbName,
|
|
|
+ Frequency: req.Frequency,
|
|
|
+ Unit: req.Unit,
|
|
|
+ ClassifyId: req.ClassifyId,
|
|
|
+ Formula: string(formulaByte), //公式
|
|
|
+ Source: utils.DATA_SOURCE_CALCULATE_ZDYFX,
|
|
|
+ Data: CustomAnalysisData{
|
|
|
+ ExcelInfoId: req.ExcelInfoId,
|
|
|
+ DateList: dateList,
|
|
|
+ DataList: dataList,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用指标库去更新
|
|
|
+ reqJson, err := json.Marshal(req2)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ respItem, err := data.BatchSaveEdbCalculateData(string(reqJson))
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "新增失败"
|
|
|
+ br.ErrMsg = "新增失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if respItem.Ret != 200 {
|
|
|
+ br.Msg = respItem.Msg
|
|
|
+ br.ErrMsg = respItem.ErrMsg
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := respItem.Data
|
|
|
+
|
|
|
+ //添加es
|
|
|
+ data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "保存成功"
|
|
|
+ br.Data = resp
|
|
|
+ br.IsAddLog = false //数据量太大了,不写入日志吧
|
|
|
+}
|
|
|
+
|
|
|
+// EditEdb
|
|
|
+// @Title 编辑指标接口
|
|
|
+// @Description 编辑指标接口
|
|
|
+// @Param request body request.EditEdb true "type json string"
|
|
|
+// @Success 200 {object} data_manage.AddEdbInfoResp
|
|
|
+// @router /edb/edit [post]
|
|
|
+func (c *CustomAnalysisController) EditEdb() {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ deleteCache := true
|
|
|
+ cacheKey := "CACHE_EXCEL_TABLE_INFO_ADD_EDB_" + 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(c.Ctx.Input.RequestBody)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req request.EditEdb
|
|
|
+ err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ req.EdbName = strings.Trim(req.EdbName, " ")
|
|
|
+ if req.EdbName == "" {
|
|
|
+ br.Msg = "请填写指标名称!"
|
|
|
+ br.IsSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.ExcelInfoId <= 0 {
|
|
|
+ br.Msg = "请选择excel!"
|
|
|
+ br.IsSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.EdbInfoId <= 0 {
|
|
|
+ br.Msg = "请选择指标!"
|
|
|
+ br.IsSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.ClassifyId <= 0 {
|
|
|
+ br.Msg = "请选择指标分类!"
|
|
|
+ br.IsSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ excelInfo, err := excelModel.GetExcelInfoById(req.ExcelInfoId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "找不到该EXCEL!"
|
|
|
+ br.ErrMsg = "找不到该EXCEL!err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if excelInfo.Source != utils.CUSTOM_ANALYSIS_TABLE {
|
|
|
+ br.Msg = "EXCEL异常!"
|
|
|
+ br.IsSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "指标已被删除,请刷新页面"
|
|
|
+ br.ErrMsg = "指标已被删除,请刷新页面:Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "获取指标信息失败"
|
|
|
+ br.ErrMsg = "获取指标信息失败:Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //excel.GetCustomAnalysisExcelData(excelInfo)
|
|
|
+
|
|
|
+ dateList, dataList, err, errMsg := excel.HandleEdbSequenceVal(req.DateSequenceVal, req.DataSequenceVal)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "时间序列或数据序列异常!"
|
|
|
+ if errMsg != `` {
|
|
|
+ br.Msg = errMsg
|
|
|
+ }
|
|
|
+ br.ErrMsg = "时间序列或数据序列处理异常!err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ type CustomAnalysisData struct {
|
|
|
+ ExcelInfoId int `description:"excel的id"`
|
|
|
+ DateList []string
|
|
|
+ DataList []float64
|
|
|
+ }
|
|
|
+
|
|
|
+ type Formula struct {
|
|
|
+ DateSequenceStr string `description:"日期序列"`
|
|
|
+ DataSequenceStr string `description:"数据序列"`
|
|
|
+ }
|
|
|
+
|
|
|
+ formulaByte, err := json.Marshal(Formula{
|
|
|
+ DateSequenceStr: req.DateSequenceStr,
|
|
|
+ DataSequenceStr: req.DataSequenceStr,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "时间序列或数据序列配置异常!"
|
|
|
+ br.ErrMsg = "json序列化时间序列或数据序列异常!err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构造请求
|
|
|
+ req2 := &data_manage.EdbInfoCalculateBatchEditReqByEdbLib{
|
|
|
+ EdbInfoId: req.EdbInfoId,
|
|
|
+ EdbName: req.EdbName,
|
|
|
+ Frequency: req.Frequency,
|
|
|
+ Unit: req.Unit,
|
|
|
+ ClassifyId: req.ClassifyId,
|
|
|
+ Formula: string(formulaByte), //公式
|
|
|
+ Source: utils.DATA_SOURCE_CALCULATE_ZDYFX,
|
|
|
+ Data: CustomAnalysisData{
|
|
|
+ ExcelInfoId: req.ExcelInfoId,
|
|
|
+ DateList: dateList,
|
|
|
+ DataList: dataList,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用指标库去更新
|
|
|
+ reqJson, err := json.Marshal(req2)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ respItem, err := data.BatchEditEdbCalculateData(string(reqJson))
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "编辑失败"
|
|
|
+ br.ErrMsg = "编辑失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if respItem.Ret != 200 {
|
|
|
+ br.Msg = respItem.Msg
|
|
|
+ br.ErrMsg = respItem.ErrMsg
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := respItem.Data
|
|
|
+
|
|
|
+ //添加es
|
|
|
+ data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
|
|
|
+
|
|
|
+ // 修改关联的预测指标基础信息
|
|
|
+ go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo)
|
|
|
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|