|
@@ -5,8 +5,11 @@ import (
|
|
"errors"
|
|
"errors"
|
|
"eta/eta_api/models/data_manage"
|
|
"eta/eta_api/models/data_manage"
|
|
"eta/eta_api/services/google"
|
|
"eta/eta_api/services/google"
|
|
|
|
+ "eta/eta_api/utils"
|
|
|
|
+ "fmt"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
|
|
+ "time"
|
|
)
|
|
)
|
|
|
|
|
|
func HandleExtraConfig(chartType int, extraConfigStr string) (newExtraConfigStr string, err error, errMsg string) {
|
|
func HandleExtraConfig(chartType int, extraConfigStr string) (newExtraConfigStr string, err error, errMsg string) {
|
|
@@ -197,3 +200,318 @@ func GetEnNameMapByCnNameList(cnNameList []string) (contentEnMap map[string]stri
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetChartSectionCombineData 截面组合图的数据处理
|
|
|
|
+func GetChartSectionCombineData(chartInfoId int, mappingList []*data_manage.ChartEdbInfoMapping, edbDataListMap map[int][]*data_manage.EdbDataList, extraConfig data_manage.ChartSectionAllExtraConf) (edbIdList []int, chartDataResp data_manage.SectionScatterInfoResp, err error) {
|
|
|
|
+ // 指标数据数组(10086:{"2022-12-02":100.01,"2022-12-01":102.3})
|
|
|
|
+ edbDataMap := make(map[int]map[string]float64)
|
|
|
|
+ for edbInfoId, edbDataList := range edbDataListMap {
|
|
|
|
+ edbDateData := make(map[string]float64)
|
|
|
|
+ for _, edbData := range edbDataList {
|
|
|
|
+ edbDateData[edbData.DataTime] = edbData.Value
|
|
|
|
+ }
|
|
|
|
+ edbDataMap[edbInfoId] = edbDateData
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // edbIdList 指标展示顺序;x轴的指标顺序
|
|
|
|
+ edbIdList = make([]int, 0)
|
|
|
|
+ edbMappingMap := make(map[int]*data_manage.ChartEdbInfoMapping)
|
|
|
|
+ for _, v := range mappingList {
|
|
|
|
+ edbIdList = append(edbIdList, v.EdbInfoId)
|
|
|
|
+ edbMappingMap[v.EdbInfoId] = v
|
|
|
|
+ }
|
|
|
|
+ // 确定好截面散点图返回的数据格式
|
|
|
|
+ // 获取所有的引用日期设置
|
|
|
|
+ DateConfListMap := make(map[string]*data_manage.ChartSectionDateConfItem)
|
|
|
|
+ for _, v := range extraConfig.DateConfList {
|
|
|
|
+ DateConfListMap[v.DateConfName] = v
|
|
|
|
+ }
|
|
|
|
+ // 遍历每个系列
|
|
|
|
+ // 遍历每个指标,根据选中的日期,进行日期变换得到最终的日期,根据最终的日期获取对应的值
|
|
|
|
+ // 组装数据
|
|
|
|
+ dataListResp := new(data_manage.ChartSectionCombineDataResp) //y轴的数据列表
|
|
|
|
+
|
|
|
|
+ for _, seriesItem := range extraConfig.SeriesList {
|
|
|
|
+ var maxDate time.Time
|
|
|
|
+ var minVal, maxVal float64
|
|
|
|
+ noDataEdbIdList := make([]int, 0)
|
|
|
|
+ dataList := make([]float64, len(seriesItem.EdbInfoList))
|
|
|
|
+ for index, edbConf := range seriesItem.EdbInfoList {
|
|
|
|
+ edbInfoId := edbConf.EdbInfoId //X轴的指标
|
|
|
|
+ _, ok := edbMappingMap[edbInfoId]
|
|
|
|
+ if !ok {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ edbDataList, ok3 := edbDataListMap[edbInfoId]
|
|
|
|
+ if !ok3 {
|
|
|
|
+ err = fmt.Errorf("指标%d的日期数据不存在", edbInfoId)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ /*dataList := edbDataListMap[edbInfoId] //指标的所有数据值
|
|
|
|
+ if len(dataList) <= 0 {
|
|
|
|
+ // 没有数据的指标id
|
|
|
|
+ //findDataList = append(findDataList, 0)
|
|
|
|
+ continue
|
|
|
|
+ }*/
|
|
|
|
+ //日期变换处理,判断用指标的最新日期还是,直接获取引用日期
|
|
|
|
+ var findDate string
|
|
|
|
+ if edbConf.DateConfName == "" {
|
|
|
|
+ findDate, err = GetChartSectionSeriesDateByDateChange(edbInfoId, edbDataList, edbConf.DateConf.DateChange, edbConf.DateConf.MoveForward)
|
|
|
|
+ } else {
|
|
|
|
+ // 获取日期配置
|
|
|
|
+ dateConfItem, ok1 := DateConfListMap[edbConf.DateConfName]
|
|
|
|
+ if !ok1 {
|
|
|
|
+ err = fmt.Errorf("引用日期配置不存在")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ // todo 根据日期变换得到最终日期
|
|
|
|
+ edbDataListTmp := make([]*data_manage.EdbDataList, 0)
|
|
|
|
+ if dateConfItem.EdbInfoId > 0 {
|
|
|
|
+ edbDataListTmp, ok1 = edbDataListMap[dateConfItem.EdbInfoId]
|
|
|
|
+ if !ok1 {
|
|
|
|
+ err = fmt.Errorf("指标%d的日期数据不存在", dateConfItem.EdbInfoId)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ findDate, err = GetChartSectionSeriesDateByDateChange(dateConfItem.EdbInfoId, edbDataListTmp, dateConfItem.DateChange, dateConfItem.MoveForward)
|
|
|
|
+ }
|
|
|
|
+ findDateTime, _ := time.ParseInLocation(utils.FormatDate, findDate, time.Local)
|
|
|
|
+ if maxDate.IsZero() {
|
|
|
|
+ maxDate = findDateTime
|
|
|
|
+ } else {
|
|
|
|
+ if findDateTime.After(maxDate) {
|
|
|
|
+ maxDate = findDateTime
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if tmpValue, ok := edbDataMap[edbInfoId][findDate]; ok {
|
|
|
|
+ dataList[index] = tmpValue
|
|
|
|
+ if index == 0 {
|
|
|
|
+ minVal = tmpValue
|
|
|
|
+ maxVal = tmpValue
|
|
|
|
+ } else {
|
|
|
|
+ if tmpValue < minVal {
|
|
|
|
+ minVal = tmpValue
|
|
|
|
+ }
|
|
|
|
+ if tmpValue > maxVal {
|
|
|
|
+ maxVal = tmpValue
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ noDataEdbIdList = append(noDataEdbIdList, edbInfoId)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ seriesItem.DataList = dataList
|
|
|
|
+ seriesItem.MinData = minVal
|
|
|
|
+ seriesItem.MaxData = maxVal
|
|
|
|
+ seriesItem.NoDataEdbIdList = noDataEdbIdList
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dataListResp.XDataList = extraConfig.XDataList
|
|
|
|
+ dataListResp.SeriesList = extraConfig.SeriesList
|
|
|
|
+ dataListResp.DateConfList = extraConfig.DateConfList
|
|
|
|
+ dataListResp.BaseChartSeriesName = extraConfig.BaseChartSeriesName
|
|
|
|
+ dataListResp.UnitList = extraConfig.UnitList
|
|
|
|
+ dataListResp.IsHeap = extraConfig.IsHeap
|
|
|
|
+ dataListResp.SortType = extraConfig.SortType
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// GetChartSectionSeriesDateByDateChange 获取日期变换后的日期edbInfoId 1指标日期,2 系统日期
|
|
|
|
+func GetChartSectionSeriesDateByDateChange(edbInfoId int, dataList []*data_manage.EdbDataList, dateChange []*data_manage.ChartSectionDateChange, moveForward int) (newDate string, err error) {
|
|
|
|
+ if edbInfoId > 0 { //指标日期
|
|
|
|
+ newDate = GetEdbDateByMoveForward(moveForward, dataList)
|
|
|
|
+ } else {
|
|
|
|
+ //系统日期
|
|
|
|
+ newDate = time.Now().Format(utils.FormatDate)
|
|
|
|
+ }
|
|
|
|
+ if newDate != "" && len(dateChange) > 0 {
|
|
|
|
+ newDate, err = HandleChartSectionSeriesDateChange(newDate, dateChange)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetEdbDateByMoveForward(moveForward int, edbDataList []*data_manage.EdbDataList) (date string) {
|
|
|
|
+ dateList := make([]string, 0)
|
|
|
|
+ for _, v := range edbDataList {
|
|
|
|
+ dateList = append(dateList, v.DataTime)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ date = GetEdbDateByMoveForwardByDateList(moveForward, dateList)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetEdbDateByMoveForwardByDateList(moveForward int, dateList []string) (date string) {
|
|
|
|
+ // 根据日期进行排序
|
|
|
|
+ index := len(dateList) - 1 - moveForward
|
|
|
|
+ for k, v := range dateList {
|
|
|
|
+ if k == index {
|
|
|
|
+ date = v
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// HandleChartSectionSeriesDateChange 处理日期变换
|
|
|
|
+func HandleChartSectionSeriesDateChange(date string, dateChange []*data_manage.ChartSectionDateChange) (newDate string, err error) {
|
|
|
|
+ newDate = date
|
|
|
|
+ if newDate != "" {
|
|
|
|
+ if len(dateChange) > 0 {
|
|
|
|
+ var dateTime time.Time
|
|
|
|
+ dateTime, err = time.ParseInLocation(utils.FormatDate, newDate, time.Local)
|
|
|
|
+ if err != nil {
|
|
|
|
+ err = fmt.Errorf("日期解析失败: %s", err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, v := range dateChange {
|
|
|
|
+ if v.ChangeType == 1 {
|
|
|
|
+ dateTime = dateTime.AddDate(v.Year, v.Month, v.Day)
|
|
|
|
+ newDate = dateTime.Format(utils.FormatDate)
|
|
|
|
+ } else if v.ChangeType == 2 {
|
|
|
|
+ newDate, err, _ = handleSystemAppointDateT(dateTime, v.FrequencyDay, v.Frequency)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ dateTime, err = time.ParseInLocation(utils.FormatDate, newDate, time.Local)
|
|
|
|
+ if err != nil {
|
|
|
|
+ err = fmt.Errorf("日期解析失败: %s", err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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(currDate time.Time, appointDay, frequency string) (date string, err error, errMsg string) {
|
|
|
|
+ //currDate := time.Now()
|
|
|
|
+ switch frequency {
|
|
|
|
+ case "本周":
|
|
|
|
+ day := int(currDate.Weekday())
|
|
|
|
+ if day == 0 { // 周日
|
|
|
|
+ day = 7
|
|
|
|
+ }
|
|
|
|
+ num := 0
|
|
|
|
+ switch appointDay {
|
|
|
|
+ case "周一":
|
|
|
|
+ num = 1
|
|
|
|
+ case "周二":
|
|
|
|
+ num = 2
|
|
|
|
+ case "周三":
|
|
|
|
+ num = 3
|
|
|
|
+ case "周四":
|
|
|
|
+ num = 4
|
|
|
|
+ case "周五":
|
|
|
|
+ num = 5
|
|
|
|
+ case "周六":
|
|
|
|
+ num = 6
|
|
|
|
+ case "周日":
|
|
|
|
+ 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())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
|
+ case "本半年":
|
|
|
|
+ month := currDate.Month()
|
|
|
|
+ var tmpDate time.Time
|
|
|
|
+ switch appointDay {
|
|
|
|
+ case "第一天":
|
|
|
|
+ if month <= 6 {
|
|
|
|
+ tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
|
+ } else {
|
|
|
|
+ tmpDate = time.Date(currDate.Year(), 7, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
|
+ }
|
|
|
|
+ case "最后一天":
|
|
|
|
+ if month <= 6 {
|
|
|
|
+ tmpDate = time.Date(currDate.Year(), 6, 30, 0, 0, 0, 0, currDate.Location())
|
|
|
|
+ } else {
|
|
|
|
+ tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
|
+ case "本年":
|
|
|
|
+ var tmpDate time.Time
|
|
|
|
+ switch appointDay {
|
|
|
|
+ case "第一天":
|
|
|
|
+ tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
|
|
|
|
+ case "最后一天":
|
|
|
|
+ tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
|
|
|
|
+ }
|
|
|
|
+ date = tmpDate.Format(utils.FormatDate)
|
|
|
|
+ default:
|
|
|
|
+ errMsg = "错误的日期频度:" + frequency
|
|
|
|
+ err = errors.New(errMsg)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return
|
|
|
|
+}
|