Przeglądaj źródła

Merge remote-tracking branch 'origin/eta/1.0.2' into debug

# Conflicts:
#	go.sum
#	routers/router.go
Roc 1 rok temu
rodzic
commit
33d6250642

+ 250 - 43
controllers/data_manage/excel/custom_analysis_edb.go

@@ -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

+ 1 - 1
go.mod

@@ -12,6 +12,7 @@ require (
 	github.com/alibabacloud-go/tea-utils/v2 v2.0.1
 	github.com/aliyun/alibaba-cloud-sdk-go v1.61.1656
 	github.com/aliyun/aliyun-oss-go-sdk v2.2.0+incompatible
+	github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
 	github.com/beego/bee/v2 v2.0.4
 	github.com/beego/beego/v2 v2.0.7
 	github.com/beevik/etree v1.2.0
@@ -50,7 +51,6 @@ require (
 	github.com/aliyun/credentials-go v1.1.2 // indirect
 	github.com/andybalholm/cascadia v1.3.1 // indirect
 	github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211218165449-dd623ecc2f02 // indirect
-	github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
 	github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
 	github.com/beorn7/perks v1.0.1 // indirect
 	github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d // indirect

+ 3 - 0
go.sum

@@ -70,6 +70,8 @@ github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEq
 github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211218165449-dd623ecc2f02 h1:o2oaBQGTzO+xNh12e7xWkphNe7H2DTiWv1ml9a2P9PQ=
 github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211218165449-dd623ecc2f02/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
 github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
+github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA=
+github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
 github.com/astaxie/beego v1.12.3/go.mod h1:p3qIm0Ryx7zeBHLljmd7omloyca1s4yu1a8kM1FkpIA=
 github.com/aws/aws-sdk-go v1.42.23/go.mod h1:gyRszuZ/icHmHAVE4gc/r+cfCmhA1AD+vqfWbgI+eHs=
 github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA=
@@ -264,6 +266,7 @@ github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
 github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
 github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
+github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
 github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
 github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=

+ 2 - 0
models/data_manage/edb_data_base.go

@@ -152,6 +152,8 @@ func GetEdbDataTableName(source int) (tableName string) {
 		tableName = "edb_data_calculate_zsxy" // 指数修匀->72
 	case utils.DATA_SOURCE_PREDICT_CALCULATE_ZSXY:
 		tableName = "edb_data_predict_calculate_zsxy" // 预测指数修匀->73
+	case utils.DATA_SOURCE_CALCULATE_ZDYFX:
+		tableName = "edb_data_calculate_zdyfx" // 自定义分析->74
 	default:
 		tableName = ""
 	}

+ 3 - 1
models/data_manage/edb_info_calculate.go

@@ -199,9 +199,10 @@ type EdbInfoCalculateBatchSaveReqByEdbLib struct {
 	MoveType         int              `description:"移动方式:1:领先(默认),2:滞后"`
 	MoveFrequency    string           `description:"移动频度:天/周/月/季/年"`
 	Calendar         string           `description:"公历/农历"`
+	Data             interface{}      `description:"数据列"`
 }
 
-// EdbInfoCalculateBatchEditReq 编辑计算指标的请求参数
+// EdbInfoCalculateBatchEditReqByEdbLib 编辑计算指标的请求参数
 type EdbInfoCalculateBatchEditReqByEdbLib struct {
 	EdbName       string `description:"指标名称"`
 	Frequency     string `description:"频度"`
@@ -215,6 +216,7 @@ type EdbInfoCalculateBatchEditReqByEdbLib struct {
 	MoveFrequency string `description:"移动频度:天/周/月/季/年"`
 	Calendar      string `description:"公历/农历"`
 	EdbInfoIdArr  []EdbInfoFromTag
+	Data          interface{} `description:"数据列"`
 }
 
 func GetEdbInfoCalculateMap(edbInfoId, source int) (list []*EdbInfo, err error) {

+ 13 - 0
models/data_manage/excel/request/excel.go

@@ -42,3 +42,16 @@ type AddEdb struct {
 	Frequency       string   `description:"频率"`
 	Unit            string   `description:"单位"`
 }
+
+type EditEdb struct {
+	ExcelInfoId     int      `description:"表格ID"`
+	EdbInfoId       int      `description:"指标ID"`
+	DateSequenceStr string   `description:"日期序列"`
+	DateSequenceVal []string `description:"日期序列的值列表"`
+	DataSequenceStr string   `description:"数据序列"`
+	DataSequenceVal []string `description:"数据序列的值列表"`
+	EdbName         string   `description:"指标名称"`
+	ClassifyId      int      `description:"分类id"`
+	Frequency       string   `description:"频率"`
+	Unit            string   `description:"单位"`
+}

+ 9 - 0
routers/commentsRouter.go

@@ -196,6 +196,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"],
+        beego.ControllerComments{
+            Method: "EditEdb",
+            Router: `/edb/edit`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:CustomAnalysisController"],
         beego.ControllerComments{
             Method: "BaseExcelDetail",

+ 8 - 2
routers/router.go

@@ -267,6 +267,11 @@ func init() {
 				&trade_analysis.TradeAnalysisController{},
 			),
 		),
+		web.NSNamespace("/custom_analysis",
+			web.NSInclude(
+				&excel.CustomAnalysisController{},
+			),
+		),
 		web.NSNamespace("/out_link",
 			web.NSInclude(
 				&controllers.OutLinkController{},
@@ -283,9 +288,10 @@ func init() {
 				&eta_trial.EtaTrialController{},
 			),
 		),
-		web.NSNamespace("/custom_analysis",
+		web.NSNamespace("/user_login",
 			web.NSInclude(
-				&excel.CustomAnalysisController{},
+				&controllers.UserLoginController{},
+				&controllers.UserLoginAuthController{},
 			),
 		),
 	)

+ 1 - 1
services/data/excel/custom_analysis.go

@@ -396,7 +396,7 @@ type LuckySheet struct {
 	//} `json:"config"`
 	Config           interface{}
 	Index            string               `json:"index"`
-	Order            string               `json:"order"`
+	Order            int                  `json:"order"`
 	ZoomRatio        int                  `json:"zoomRatio"`
 	ShowGridLines    string               `json:"showGridLines"`
 	DefaultColWidth  int                  `json:"defaultColWidth"`

+ 27 - 2
services/data/excel/custom_analysis_edb.go

@@ -86,8 +86,11 @@ func GenerateExcelCustomAnalysisExcel(excelInfo *excel.ExcelInfo) (downloadFileP
 	return
 }
 
-// HandleEdbSequenceVal 处理日期集和数据集
-func HandleEdbSequenceVal(dateSequenceVal, dataSequenceVal []string) {
+// HandleEdbSequenceVal 处理日期集和数据集(获取可用的日期、数据集)
+func HandleEdbSequenceVal(dateSequenceVal, dataSequenceVal []string) (newDateList []string, newDataList []float64, err error, errMsg string) {
+	newDateList = make([]string, 0)
+	newDataList = make([]float64, 0)
+
 	// 数据集
 	type dataStruct struct {
 		Value float64
@@ -150,5 +153,27 @@ func HandleEdbSequenceVal(dateSequenceVal, dataSequenceVal []string) {
 		}
 	}
 
+	lenData := len(dataList)
+	lenDate := len(dateList)
+
+	// 最小个数
+	num := lenDate
+	if num > lenData {
+		num = lenData
+	}
+
+	for i := 0; i < num; i++ {
+		date := dateList[i]
+		data := dataList[i]
+
+		// 日期为空、数据为空
+		if !data.Ok || date == `` {
+			continue
+		}
+
+		newDateList = append(newDateList, date)
+		newDataList = append(newDataList, data.Value)
+	}
+
 	return
 }

+ 1 - 0
utils/constants.go

@@ -162,6 +162,7 @@ const (
 	DATA_SOURCE_FUBAO                                           //富宝->71
 	DATA_SOURCE_CALCULATE_ZSXY                                  // 指数修匀->72
 	DATA_SOURCE_PREDICT_CALCULATE_ZSXY                          // 预测指数修匀->73
+	DATA_SOURCE_CALCULATE_ZDYFX                                 // 自定义分析->74
 )
 
 // 数据刷新频率