|
@@ -13,9 +13,7 @@ import (
|
|
|
)
|
|
|
|
|
|
// GetMixedTableCellData 获取混合表格数据
|
|
|
-func GetMixedTableCellData(cellRelationConf string, config [][]request.MixedTableCellDataReq) (newMixedTableCellDataList [][]request.MixedTableCellDataReq, err error) {
|
|
|
- newMixedTableCellDataList = config
|
|
|
-
|
|
|
+func GetMixedTableCellData(cellRelationConf string, config [][]request.MixedTableCellDataReq) (newMixedTableCellDataList [][]request.MixedTableCellDataReq, err error, errMsg string) {
|
|
|
// 单元格关系配置x信息
|
|
|
cellRelationConfMap := make(map[string]request.CellRelationConf)
|
|
|
cellRelationConfList := make([]request.CellRelationConf, 0)
|
|
@@ -31,8 +29,9 @@ func GetMixedTableCellData(cellRelationConf string, config [][]request.MixedTabl
|
|
|
}
|
|
|
|
|
|
// 找出所有的关联指标id
|
|
|
- config, edbInfoIdList, _ := handleConfig(config)
|
|
|
+ config, edbInfoIdList, _, err, errMsg := handleConfig(config)
|
|
|
|
|
|
+ // 查询所有关联的指标信息
|
|
|
edbInfoList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -72,13 +71,30 @@ func GetMixedTableCellData(cellRelationConf string, config [][]request.MixedTabl
|
|
|
edbMonthDataListMap[edbInfo.EdbInfoId] = monthValMap
|
|
|
}
|
|
|
|
|
|
- for k, row := range newMixedTableCellDataList {
|
|
|
+ // 处理指定指标的日期
|
|
|
+ for k, row := range config {
|
|
|
+ for i, cell := range row {
|
|
|
+ // 单元格是日期类型,且是日导入指标日期(指标库的最新日期)
|
|
|
+ if cell.DataType == request.DateDT && cell.DataTimeType == request.EdbDateDT {
|
|
|
+ if edbInfo, ok := edbInfoMap[cell.EdbInfoId]; ok {
|
|
|
+ cell.ShowValue = edbInfo.EndDate
|
|
|
+ cell.DataTime = edbInfo.EndDate
|
|
|
+ config[k][i] = cell
|
|
|
+ }
|
|
|
+ }
|
|
|
+ row[i] = cell
|
|
|
+ }
|
|
|
+ config[k] = row
|
|
|
+ }
|
|
|
+
|
|
|
+ for k, row := range config {
|
|
|
for i, cell := range row {
|
|
|
- if cell.DataType == request.EdbDT {
|
|
|
+ switch cell.DataType {
|
|
|
+ case request.EdbDT: // 指标类型
|
|
|
if edbInfo, ok := edbInfoMap[cell.EdbInfoId]; ok {
|
|
|
cell.ShowValue = edbInfo.EdbName
|
|
|
}
|
|
|
- } else if utils.InArrayByInt([]int{request.InsertDataDT, request.PopInsertDataDT}, cell.DataType) {
|
|
|
+ case request.InsertDataDT, request.PopInsertDataDT: // 数据类型
|
|
|
tmpDateList := strings.Split(cell.DataTime, "-")
|
|
|
tmpDateValMap := make(map[string]float64)
|
|
|
if len(tmpDateList) == 2 {
|
|
@@ -101,34 +117,70 @@ func GetMixedTableCellData(cellRelationConf string, config [][]request.MixedTabl
|
|
|
|
|
|
row[i] = cell
|
|
|
}
|
|
|
- newMixedTableCellDataList[k] = row
|
|
|
+ config[k] = row
|
|
|
}
|
|
|
|
|
|
+ newMixedTableCellDataList = config
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func handleConfig(config [][]request.MixedTableCellDataReq) ([][]request.MixedTableCellDataReq, []int, []int) {
|
|
|
- edbInfoIdList := make([]int, 0)
|
|
|
- dataEdbInfoIdList := make([]int, 0)
|
|
|
- for _, row := range config {
|
|
|
- for _, cell := range row {
|
|
|
+func handleConfig(configList [][]request.MixedTableCellDataReq) (newConfig [][]request.MixedTableCellDataReq, edbInfoIdList []int, dataEdbInfoIdList []int, err error, errMsg string) {
|
|
|
+ edbInfoIdList = make([]int, 0)
|
|
|
+ dataEdbInfoIdList = make([]int, 0)
|
|
|
+
|
|
|
+ for ck, rowList := range configList {
|
|
|
+ for rk, cell := range rowList {
|
|
|
switch cell.DataType {
|
|
|
case request.EdbDT: // 指标信息
|
|
|
edbInfoIdList = append(edbInfoIdList, cell.EdbInfoId)
|
|
|
case request.InsertDataDT, request.PopInsertDataDT: // 插值、弹框插值
|
|
|
dataEdbInfoIdList = append(dataEdbInfoIdList, cell.EdbInfoId)
|
|
|
case request.DateDT: // 日期类型
|
|
|
+ if cell.DataTimeType == request.EdbDateDT {
|
|
|
+ edbInfoIdList = append(edbInfoIdList, cell.EdbInfoId)
|
|
|
+ } else {
|
|
|
+ date, tmpErr, tmpErrMsg := handleDate(cell.DataTimeType, cell.Value)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ errMsg = tmpErrMsg
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rowList[rk].DataTime = date
|
|
|
+ rowList[rk].ShowValue = date
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ configList[ck] = rowList
|
|
|
}
|
|
|
|
|
|
- return config, edbInfoIdList, dataEdbInfoIdList
|
|
|
+ newConfig = configList
|
|
|
+
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
+// HandleDate
|
|
|
+// @Description: 日期处理
|
|
|
+// @author: Roc
|
|
|
+// @datetime2023-10-27 09:37:02
|
|
|
+// @param dataTimeType int
|
|
|
+// @param val string
|
|
|
+// @return date string
|
|
|
+// @return err error
|
|
|
+// @return errMsg string
|
|
|
func HandleDate(dataTimeType int, val string) (date string, err error, errMsg string) {
|
|
|
return handleDate(dataTimeType, val)
|
|
|
}
|
|
|
|
|
|
+// handleDate
|
|
|
+// @Description: 日期处理
|
|
|
+// @author: Roc
|
|
|
+// @datetime2023-10-27 09:36:49
|
|
|
+// @param dataTimeType int
|
|
|
+// @param val string
|
|
|
+// @return date string
|
|
|
+// @return err error
|
|
|
+// @return errMsg string
|
|
|
func handleDate(dataTimeType int, val string) (date string, err error, errMsg string) {
|
|
|
if val == `` {
|
|
|
errMsg = "错误的日期数据"
|
|
@@ -139,11 +191,7 @@ func handleDate(dataTimeType int, val string) (date string, err error, errMsg st
|
|
|
case request.CustomDateT: //手动输入日期
|
|
|
date = val
|
|
|
case request.SystemDateT: // 系统日期
|
|
|
- date = time.Now().Format(utils.FormatDate)
|
|
|
- case request.SystemCalculateDateT: // 系统日期计算后的日期
|
|
|
- date, err, errMsg = handleSystemCalculateDateT(val)
|
|
|
- case request.SystemAppointDateT: // 处理系统日期相关的指定频率(所在周/旬/月/季/半年/年的最后/最早一天)
|
|
|
- date, err, errMsg = handleSystemAppointDateT(val)
|
|
|
+ date, err, errMsg = handleSystemDateT(val)
|
|
|
case request.EdbDateDT: // 导入指标日期(指标库的最新日期)
|
|
|
default:
|
|
|
errMsg = "错误的日期类型"
|
|
@@ -154,30 +202,60 @@ func handleDate(dataTimeType int, val string) (date string, err error, errMsg st
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// handleSystemCalculateDateT
|
|
|
-// @Description: 处理系统日期计算后的日期
|
|
|
-// @author: Roc
|
|
|
-// @datetime2023-10-26 11:12:56
|
|
|
-// @param val string
|
|
|
-// @return date string
|
|
|
-// @return err error
|
|
|
-// @return errMsg string
|
|
|
-func handleSystemCalculateDateT(val string) (date string, err error, errMsg string) {
|
|
|
+// handleSystemDateT
|
|
|
+// @Description: 处理导入系统日期
|
|
|
+// @author: Roc
|
|
|
+// @datetime2023-10-27 09:36:21
|
|
|
+// @param confStr string
|
|
|
+// @return date string
|
|
|
+// @return err error
|
|
|
+// @return errMsg string
|
|
|
+func handleSystemDateT(confStr string) (date string, err error, errMsg string) {
|
|
|
+ var config request.SystemDateConf
|
|
|
+ err = json.Unmarshal([]byte(confStr), &config)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
type SystemCalculateVal struct {
|
|
|
+ Source int `description:"类型,"`
|
|
|
Num int
|
|
|
Frequency string
|
|
|
}
|
|
|
- var config SystemCalculateVal
|
|
|
- err = json.Unmarshal([]byte(val), &config)
|
|
|
+ switch config.Source {
|
|
|
+ case request.SystemCurrDateT:
|
|
|
+ date = time.Now().Format(utils.FormatDate)
|
|
|
+ case request.SystemCalculateDateT:
|
|
|
+ date, err, errMsg = handleSystemCalculateDateT(config.CalculateNum, config.CalculateFrequency)
|
|
|
+ case request.SystemFrequencyDateT: // 处理系统日期相关的指定频率(所在周/旬/月/季/半年/年的最后/最早一天)
|
|
|
+ date, err, errMsg = handleSystemAppointDateT(config.Day, config.Frequency)
|
|
|
+ default:
|
|
|
+ errMsg = "错误的日期日期导入方式"
|
|
|
+ err = errors.New(fmt.Sprint("错误的日期日期导入方式:", config.Source))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// handleSystemCalculateDateT
|
|
|
+// @Description: 处理系统日期计算后的日期
|
|
|
+// @author: Roc
|
|
|
+// @datetime2023-10-27 09:31:22
|
|
|
+// @param num int
|
|
|
+// @param frequency string
|
|
|
+// @return date string
|
|
|
+// @return err error
|
|
|
+// @return errMsg string
|
|
|
+func handleSystemCalculateDateT(num int, frequency string) (date string, err error, errMsg string) {
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
currDate := time.Now()
|
|
|
- switch config.Frequency {
|
|
|
+ switch frequency {
|
|
|
case "", "日":
|
|
|
- date = currDate.AddDate(0, 0, config.Num).Format(utils.FormatDate)
|
|
|
+ date = currDate.AddDate(0, 0, num).Format(utils.FormatDate)
|
|
|
default:
|
|
|
- errMsg = "错误的日期频度:" + config.Frequency
|
|
|
+ errMsg = "错误的日期频度:" + frequency
|
|
|
err = errors.New(errMsg)
|
|
|
return
|
|
|
}
|
|
@@ -185,30 +263,25 @@ func handleSystemCalculateDateT(val string) (date string, err error, errMsg stri
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// handleSystemAppointDateT
|
|
|
-// @Description: 处理系统日期相关的指定频率(所在周/旬/月/季/半年/年的最后/最早一天)
|
|
|
-// @author: Roc
|
|
|
-// @datetime2023-10-26 11:13:52
|
|
|
-// @param val string
|
|
|
-// @return date string
|
|
|
-// @return err error
|
|
|
-// @return errMsg string
|
|
|
-func handleSystemAppointDateT(val string) (date string, err error, errMsg string) {
|
|
|
- type SystemCalculateVal struct {
|
|
|
- Frequency string
|
|
|
- Day string
|
|
|
- }
|
|
|
- var config SystemCalculateVal
|
|
|
- err = json.Unmarshal([]byte(val), &config)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+// handleSystemAppointDateT
|
|
|
+// @Description: 处理系统日期相关的指定频率(所在周/旬/月/季/半年/年的最后/最早一天)
|
|
|
+// @author: Roc
|
|
|
+// @datetime2023-10-27 09:31:35
|
|
|
+// @param Frequency string
|
|
|
+// @param Day string
|
|
|
+// @return date string
|
|
|
+// @return err error
|
|
|
+// @return errMsg string
|
|
|
+func handleSystemAppointDateT(appointDay, frequency string) (date string, err error, errMsg string) {
|
|
|
currDate := time.Now()
|
|
|
- switch config.Frequency {
|
|
|
+ switch frequency {
|
|
|
case "本周":
|
|
|
- day := currDate.Day()
|
|
|
+ day := int(currDate.Weekday())
|
|
|
+ if day == 0 { // 周日
|
|
|
+ day = 7
|
|
|
+ }
|
|
|
num := 0
|
|
|
- switch config.Day {
|
|
|
+ switch appointDay {
|
|
|
case "周一":
|
|
|
num = 1
|
|
|
case "周二":
|
|
@@ -222,11 +295,69 @@ func handleSystemAppointDateT(val string) (date string, err error, errMsg string
|
|
|
case "周六":
|
|
|
num = 6
|
|
|
case "周日":
|
|
|
- num = 0
|
|
|
+ num = 7
|
|
|
+ }
|
|
|
+ day = num - day
|
|
|
+ date = currDate.AddDate(0, 0, day).Format(utils.FormatDate)
|
|
|
+ case "本旬":
|
|
|
+ day := currDate.Day()
|
|
|
+ var tmpDate time.Time
|
|
|
+ switch appointDay {
|
|
|
+ case "第一天":
|
|
|
+ if day <= 10 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if day <= 20 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 11, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 21, 0, 0, 0, 0, currDate.Location())
|
|
|
+ }
|
|
|
+ case "最后一天":
|
|
|
+ if day <= 10 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 10, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if day <= 20 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 20, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else {
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month()+1, 1, 0, 0, 0, 0, currDate.Location()).AddDate(0, 0, -1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
+ case "本月":
|
|
|
+ var tmpDate time.Time
|
|
|
+ switch appointDay {
|
|
|
+ case "第一天":
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ case "最后一天":
|
|
|
+ tmpDate = time.Date(currDate.Year(), currDate.Month()+1, 1, 0, 0, 0, 0, currDate.Location()).AddDate(0, 0, -1)
|
|
|
+ }
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
+ case "本季":
|
|
|
+ month := currDate.Month()
|
|
|
+ var tmpDate time.Time
|
|
|
+ switch appointDay {
|
|
|
+ case "第一天":
|
|
|
+ if month <= 3 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if month <= 6 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 4, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if month <= 9 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 7, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 10, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
+ }
|
|
|
+ case "最后一天":
|
|
|
+ if month <= 3 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 3, 31, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if month <= 6 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 6, 30, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else if month <= 9 {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 9, 30, 0, 0, 0, 0, currDate.Location())
|
|
|
+ } else {
|
|
|
+ tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
|
|
|
+ }
|
|
|
}
|
|
|
- day = day - num
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
default:
|
|
|
- errMsg = "错误的日期频度:" + config.Frequency
|
|
|
+ errMsg = "错误的日期频度:" + frequency
|
|
|
err = errors.New(errMsg)
|
|
|
return
|
|
|
}
|