Browse Source

Merge branch 'feature/eta1.5.6_excel' into debug

xyxie 1 year ago
parent
commit
058d7c3a82

+ 47 - 86
controllers/data_manage/edb_info.go

@@ -6,11 +6,13 @@ import (
 	"eta/eta_api/models"
 	"eta/eta_api/models/company"
 	"eta/eta_api/models/data_manage"
+	request2 "eta/eta_api/models/data_manage/excel/request"
 	"eta/eta_api/models/data_manage/request"
 	"eta/eta_api/models/data_manage/response"
 	"eta/eta_api/models/system"
 	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/services/data"
+	excel2 "eta/eta_api/services/data/excel"
 	"eta/eta_api/services/data_stat"
 	"eta/eta_api/services/elastic"
 	etaTrialService "eta/eta_api/services/eta_trial"
@@ -4584,7 +4586,7 @@ func (this *EdbInfoController) GetEdbDateData() {
 // @Param   Date   query   string  false       "日期"
 // @Param   Num   query   int  false       "前后几期数据"
 // @Success 200 {object} data_manage.EdbInfoList
-// @router /edb_info/date_data/before_after [get]
+// @router /edb_info/date_data/before_after [post]
 func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
@@ -4592,9 +4594,17 @@ func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
 		this.ServeJSON()
 	}()
 
-	edbInfoId, _ := this.GetInt("EdbInfoId")
-	date := this.GetString("Date")
-	num, _ := this.GetInt("Num")
+	requestBody := string(this.Ctx.Input.RequestBody)
+	var req request2.DateDataBeforeAfterReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	edbInfoId := req.EdbInfoId
+	currDate := req.Date
+	num := req.Num
 
 	// 默认2期数据
 	if num <= 0 {
@@ -4613,100 +4623,51 @@ func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
 		return
 	}
 
-	// 当前日期
-	var currDate string
-	// 是否查找之后的数据
-	isFindAfter := true
-	if date == `` {
-		currDate = edbInfo.EndDate
-		isFindAfter = false
-		if num <= 0 {
-			num = 4 //默认获取前面的几期数据
-		}
-	}
-
 	dataList := make([]*data_manage.EdbDataList, 0)
-
-	startDate := date
-	// 指定日期的类型
-	dateType := "day"
-	//如果填写的是月度日期
-	if strings.Count(date, "-") == 1 {
-		startDate = date + "-01"
-		dateType = "month"
-	}
-
-	resp := data_manage.BeforeAndAfterDateDataResp{
-		List: dataList,
-		Date: "",
-	}
-	// 后面的数据
-	afterList := make([]*data_manage.EdbDataList, 0)
-	if isFindAfter {
-		afterList, err = data.GetEdbBeforeAndAfterDateData(edbInfo, startDate, "", 2, num)
+	switch edbInfo.EdbInfoType {
+	case 0:
+		dataList, _ = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, ``, ``)
+	case 1:
+		_, dataList, _, _, _, _ = data.GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, ``, ``, false)
+	default:
+		br.Msg = "指标类型异常!"
+		br.ErrMsg = "指标类型异常,Err:" + strconv.Itoa(edbInfo.EdbInfoType)
+		return
+	}
+	if currDate == `` {
+		currDate, err = excel2.GetEdbDateByMoveForward(requestBody, dataList)
 		if err != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
+			br.Msg = "日期前移失败"
+			br.ErrMsg = "日期前移失败,Err:" + err.Error()
 			return
 		}
-
-		lenBeforeList := len(afterList)
-		if lenBeforeList <= 0 {
-			br.Ret = 200
-			br.Success = true
-			br.Msg = "所选指标所选日期无值"
-			br.Data = resp
-			return
-		} else {
-			var dateTimeStr string
-			switch dateType {
-			case "month":
-				dateTime, _ := time.ParseInLocation(utils.FormatDate, afterList[0].DataTime, time.Local)
-				dateTimeStr = dateTime.Format(utils.FormatYearMonthDate)
-			case "day":
-				dateTimeStr = afterList[0].DataTime
-			}
-			currDate = afterList[0].DataTime
-			// 如果对应日期找不到,那么就直接返回吧
-			if dateTimeStr != date {
-				br.Ret = 200
-				br.Success = true
-				br.Msg = "所选指标所选日期无值"
-				br.Data = resp
-				return
-			}
+	} else {
+		if strings.Count(currDate, "-") == 1 {
+			currDate = currDate + "-01"
+			//dateType = "month"
+		} else if strings.Count(currDate, "-") == 0 {
+			currDate = currDate + "-01-01"
 		}
 	}
-
-	// 前面的数据
-	beforeList, err := data.GetEdbBeforeAndAfterDateData(edbInfo, "", currDate, 1, num)
+	currDate, err = excel2.HandleMixTableDateChange(currDate, requestBody)
 	if err != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = fmt.Sprint("获取前面的指数据失败,Err:", err.Error())
+		br.Msg = "日期变换失败"
+		br.ErrMsg = "日期变换失败,Err:" + err.Error()
 		return
 	}
+	list := make([]*data_manage.EdbDataList, 5)
 
-	dataList = append(dataList, beforeList...)
-	// 后面的数据
-	if len(afterList) > 0 {
-		if len(beforeList) > 0 {
-			dataList = append(dataList, afterList[1:]...)
-		} else {
-			dataList = append(dataList, afterList...)
-		}
-	}
-
-	// 数据翻转
-	for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
-		dataList[i], dataList[j] = dataList[j], dataList[i]
+	list, err = data.GetEdbBeforeAndAfterDateData(currDate, dataList)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
+		return
 	}
-
-	resp.List = dataList
-	// 前端不传入日期的时候,这个J皮不让返回这个字段,要不然他会颜色标记
-	if date != `` {
-		resp.Date = currDate
+	// todo 如果list 是空值,是否默认返回最新的记录
+	resp := data_manage.BeforeAndAfterDateDataResp{
+		List: list,
+		Date: currDate,
 	}
-
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 65 - 1
controllers/data_manage/excel/mixed_table.go

@@ -187,7 +187,8 @@ func (c *ExcelInfoController) CalculateData() {
 	}
 	respItem, tmpErr := data.BaseCalculate(string(reqJson))
 	if tmpErr != nil {
-		err = tmpErr
+		br.Msg = "计算指标失败"
+		br.ErrMsg = tmpErr.Error()
 		return
 	}
 	if respItem.Ret != 200 {
@@ -368,3 +369,66 @@ func (c *ExcelInfoController) GetMixDateCalculate() {
 		ShowValue: showValue,
 	}
 }
+
+// GetBaseEdbInfo
+// @Title 获取指标的基本信息
+// @Description 获取指标的基本信息
+// @Param	EdbInfoIds	string  "指标ID用英文逗号分割"
+// @router /excel_info/base_edb_info [get]
+func (c *ExcelInfoController) GetBaseEdbInfo() {
+	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
+	}
+	edbInfoIds := c.GetString("EdbInfoIds")
+	if edbInfoIds == "" {
+		br.Msg = "请输入指标ID"
+		return
+	}
+	ids := strings.Split(edbInfoIds, ",")
+	edbIds := make([]int, 0)
+	for _, v := range ids {
+		id, err := strconv.Atoi(v)
+		if err != nil {
+			br.Msg = "指标ID格式错误"
+			return
+		}
+		edbIds = append(edbIds, id)
+	}
+	edbInfoList, err := data_manage.GetEdbInfoByIdList(edbIds)
+	if err != nil {
+		br.Msg = "获取指标信息失败!"
+		br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
+		return
+	}
+	list := make([]*data_manage.BaseEdbInfo, 0)
+	for _, v := range edbInfoList {
+		tmp := new(data_manage.BaseEdbInfo)
+
+		tmp.EdbInfoId = v.EdbInfoId
+		tmp.EdbInfoType = v.EdbInfoType
+		tmp.EdbCode = v.EdbCode
+		tmp.EdbName = v.EdbName
+		tmp.Source = v.Source
+		tmp.SourceName = v.SourceName
+		tmp.Frequency = v.Frequency
+		tmp.Unit = v.Unit
+		list = append(list, tmp)
+	}
+	resp := data_manage.BaseEdbInfoResp{
+		List: list,
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "查询成功"
+	br.Data = resp
+}

+ 13 - 4
models/data_manage/edb_info.go

@@ -71,10 +71,19 @@ func AddEdbInfo(item *EdbInfo) (lastId int64, err error) {
 	return
 }
 
-type EdbInfoItem struct {
-	EdbInfoId  int    `description:"指标id"`
-	EdbName    string `description:"指标名称"`
-	ClassifyId int    `description:"指标分类"`
+type BaseEdbInfo struct {
+	EdbInfoId   int    `description:"指标id"`
+	EdbInfoType int    `description:"指标类型,0:普通指标,1:预测指标"`
+	SourceName  string `description:"来源名称"`
+	Source      int    `description:"来源id"`
+	EdbCode     string `description:"指标编码"`
+	EdbName     string `description:"指标名称"`
+	Frequency   string `description:"频率"`
+	Unit        string `description:"单位"`
+}
+
+type BaseEdbInfoResp struct {
+	List []*BaseEdbInfo
 }
 
 // GetEdbInfoAll 用于分类展示

+ 8 - 0
models/data_manage/excel/request/mixed_table.go

@@ -131,6 +131,14 @@ type MixNumberShowStyle struct {
 	IsPercent   int `description:"是否是百分比1 是,0否, 将选中的单元格的样式设置成百分比"`
 }
 
+type DateDataBeforeAfterReq struct {
+	EdbInfoId   int
+	Date        string
+	Num         int
+	MoveForward int `description:"前移的期数"`
+	DateChange  []*EdbDateConfDateChange
+}
+
 // CalculateConf
 // @Description: 计算公式
 type CalculateConf struct {

+ 10 - 1
routers/commentsRouter.go

@@ -637,6 +637,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:ExcelInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:ExcelInfoController"],
+        beego.ControllerComments{
+            Method: "GetBaseEdbInfo",
+            Router: `/excel_info/base_edb_info`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:ExcelInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage/excel:ExcelInfoController"],
         beego.ControllerComments{
             Method: "Copy",
@@ -2819,7 +2828,7 @@ func init() {
         beego.ControllerComments{
             Method: "GetEdbBeforeAndAfterDateData",
             Router: `/edb_info/date_data/before_after`,
-            AllowHTTPMethods: []string{"get"},
+            AllowHTTPMethods: []string{"post"},
             MethodParams: param.Make(),
             Filters: nil,
             Params: nil})

+ 24 - 38
services/data/edb_data.go

@@ -358,49 +358,35 @@ func GetDateData(edbInfo *data_manage.EdbInfo, startDate, endDate string) (item
 }
 
 // GetEdbBeforeAndAfterDateData 获取指标的单个日期的值
-func GetEdbBeforeAndAfterDateData(edbInfo *data_manage.EdbInfo, startDate, endDate string, dataType, num int) (list []*data_manage.EdbDataList, err error) {
-	var dataList []*data_manage.EdbDataList
-	switch edbInfo.EdbInfoType {
-	case 0:
-		dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, startDate, endDate)
-	case 1:
-		_, dataList, _, _, err, _ = GetPredictDataListByPredictEdbInfoId(edbInfo.EdbInfoId, startDate, endDate, true)
-	default:
-		err = errors.New(fmt.Sprint("获取失败,指标类型异常", edbInfo.EdbInfoType))
-
-	}
-	if err != nil {
-		return
-	}
-
+func GetEdbBeforeAndAfterDateData(targetDate string, dataList []*data_manage.EdbDataList) (list []*data_manage.EdbDataList, err error) {
 	lenDataList := len(dataList)
 	if lenDataList <= 0 {
 		return
 	}
-
-	switch dataType {
-	case 1: // 取前面的数据
-		if lenDataList <= 1 { // 如果只有一个,那么也返回,因为自己不算
-			return
-		}
-		if lenDataList <= num {
-			num = lenDataList - 1
-		}
-
-		for i := num; i >= 0; i-- {
-			list = append(list, dataList[lenDataList-1-i])
-		}
-
-	case 2: // 取后面的数据
-		num = num + 1
-		if lenDataList < num {
-			num = lenDataList
-		}
-
-		for i := 0; i < num; i++ {
-			list = append(list, dataList[i])
+	// 数组按照日期从小到大排序
+	maxIndex := lenDataList - 1
+	startIndex := 0
+	endIndex := 0
+	for index, v := range dataList {
+		if v.DataTime >= targetDate {
+			if index+2 > maxIndex {
+				endIndex = maxIndex
+			} else if index+1 > maxIndex {
+				endIndex = maxIndex
+			} else {
+				endIndex = index + 2
+			}
+			startIndex = endIndex - 4
+			if startIndex < 0 {
+				startIndex = 0
+			}
+			if endIndex == maxIndex {
+				list = dataList[startIndex:]
+			} else {
+				list = dataList[startIndex : endIndex+1]
+			}
+			break
 		}
 	}
-
 	return
 }

+ 1 - 0
services/data/excel/mixed_table.go

@@ -732,6 +732,7 @@ func HandleMixTableDateChange(date, conf string) (newDate string, err error) {
 // @return err error
 // @return errMsg string
 func handleOldSystemDateT(confStr string) (newConf string, err error, errMsg string) {
+	newConf = confStr
 	var config request.SystemDateConf
 	err = json.Unmarshal([]byte(confStr), &config)
 	if err != nil {