|
@@ -501,7 +501,7 @@ func CheckOpChartPermission(sysUser *system.Admin, createUserId int) (ok bool) {
|
|
|
}
|
|
|
|
|
|
// GetChartEdbData 获取图表的指标数据
|
|
|
-func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping, extraConfigStr string) (edbList []*data_manage.ChartEdbInfoMapping, xEdbIdValue []int, yDataList []data_manage.YData, dataResp interface{}, err error, errMsg string) {
|
|
|
+func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping, extraConfigStr string, seasonExtraConfig string) (edbList []*data_manage.ChartEdbInfoMapping, xEdbIdValue []int, yDataList []data_manage.YData, dataResp interface{}, err error, errMsg string) {
|
|
|
edbList = make([]*data_manage.ChartEdbInfoMapping, 0)
|
|
|
xEdbIdValue = make([]int, 0)
|
|
|
yDataList = make([]data_manage.YData, 0)
|
|
@@ -535,14 +535,16 @@ func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate st
|
|
|
err = errors.New(errMsg)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
extraConfig = tmpExtraConfig
|
|
|
+
|
|
|
default:
|
|
|
xEdbIdValue = make([]int, 0)
|
|
|
yDataList = make([]data_manage.YData, 0)
|
|
|
}
|
|
|
|
|
|
// 指标对应的所有数据
|
|
|
- edbDataListMap, edbList, err := getEdbDataMapList(chartInfoId, chartType, calendar, startDate, endDate, mappingList)
|
|
|
+ edbDataListMap, edbList, err := getEdbDataMapList(chartInfoId, chartType, calendar, startDate, endDate, mappingList, seasonExtraConfig)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -570,7 +572,20 @@ func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate st
|
|
|
}
|
|
|
case 10: // 截面散点图
|
|
|
sectionScatterConf := extraConfig.(data_manage.SectionScatterReq)
|
|
|
- xEdbIdValue, dataResp, err = GetSectionScatterChartData(mappingList, edbDataListMap, sectionScatterConf)
|
|
|
+ xEdbIdValue, dataResp, err = GetSectionScatterChartData(chartInfoId, mappingList, edbDataListMap, sectionScatterConf)
|
|
|
+
|
|
|
+ var tmpExtraConfig data_manage.SectionScatterReq
|
|
|
+ if extraConfigStr == `` {
|
|
|
+ errMsg = "截面散点图未配置"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = json.Unmarshal([]byte(extraConfigStr), &tmpExtraConfig)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "截面散点配置异常"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
// 这个数据没有必要返回给前端
|
|
|
for _, v := range edbList {
|
|
@@ -582,13 +597,13 @@ func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate st
|
|
|
}
|
|
|
|
|
|
// GetEdbDataMapList 获取指标最后的基础数据
|
|
|
-func GetEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping) (edbDataListMap map[int][]*data_manage.EdbDataList, edbList []*data_manage.ChartEdbInfoMapping, err error) {
|
|
|
- edbDataListMap, edbList, err = getEdbDataMapList(chartInfoId, chartType, calendar, startDate, endDate, mappingList)
|
|
|
+func GetEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping, seasonExtra string) (edbDataListMap map[int][]*data_manage.EdbDataList, edbList []*data_manage.ChartEdbInfoMapping, err error) {
|
|
|
+ edbDataListMap, edbList, err = getEdbDataMapList(chartInfoId, chartType, calendar, startDate, endDate, mappingList, seasonExtra)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// getEdbDataMapList 获取指标最后的基础数据
|
|
|
-func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping) (edbDataListMap map[int][]*data_manage.EdbDataList, edbList []*data_manage.ChartEdbInfoMapping, err error) {
|
|
|
+func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping, seasonExtraConfig string) (edbDataListMap map[int][]*data_manage.EdbDataList, edbList []*data_manage.ChartEdbInfoMapping, err error) {
|
|
|
// 指标对应的所有数据
|
|
|
edbDataListMap = make(map[int][]*data_manage.EdbDataList)
|
|
|
|
|
@@ -706,7 +721,7 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
|
|
|
}
|
|
|
dataList := make([]*data_manage.EdbDataList, 0)
|
|
|
//fmt.Println("chart:", v.Source, v.EdbInfoId, startDateReal, endDate)
|
|
|
-
|
|
|
+ fmt.Println("calendarPreYear:", calendarPreYear)
|
|
|
//var newEdbInfo *data_manage.EdbInfo
|
|
|
switch v.EdbInfoCategoryType {
|
|
|
case 0:
|
|
@@ -729,7 +744,6 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
|
|
|
}
|
|
|
|
|
|
if chartType == 2 {
|
|
|
- latestDateStr := v.LatestDate //实际数据的截止日期
|
|
|
latestDate, tmpErr := time.Parse(utils.FormatDate, v.LatestDate)
|
|
|
if tmpErr != nil {
|
|
|
//item.DataList = dataList
|
|
@@ -739,7 +753,6 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
|
|
|
err = errors.New(fmt.Sprint("获取最后实际数据的日期失败,Err:" + tmpErr.Error() + ";LatestDate:" + v.LatestDate))
|
|
|
return
|
|
|
}
|
|
|
- latestDateYear := latestDate.Year() //实际数据截止年份
|
|
|
|
|
|
if calendar == "农历" {
|
|
|
if len(dataList) <= 0 {
|
|
@@ -751,101 +764,470 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
|
|
|
err = errors.New("获取农历数据失败,Err:" + tmpErr.Error())
|
|
|
return
|
|
|
}
|
|
|
+ quarterDataList, tErr := GetSeasonEdbInfoDataListByXDateNong(result, latestDate, seasonExtraConfig, calendarPreYear)
|
|
|
+ if tErr != nil {
|
|
|
+ err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item.DataList = quarterDataList
|
|
|
+ }
|
|
|
|
|
|
- // 处理季节图的截止日期
|
|
|
- for k, edbDataItems := range result.List {
|
|
|
- var cuttingDataTimestamp int64
|
|
|
+ } else {
|
|
|
+ quarterDataList, tErr := GetSeasonEdbInfoDataListByXDate(dataList, latestDate, seasonExtraConfig)
|
|
|
+ if tErr != nil {
|
|
|
+ err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item.DataList = quarterDataList
|
|
|
+ }
|
|
|
+ } else if chartType == 7 { //柱方图
|
|
|
+ //item.DataList = dataList
|
|
|
+ } else {
|
|
|
+ item.DataList = dataList
|
|
|
+ }
|
|
|
+ edbList = append(edbList, item)
|
|
|
+ }
|
|
|
|
|
|
- // 切割的日期时间字符串
|
|
|
- cuttingDataTimeStr := latestDate.AddDate(0, 0, edbDataItems.BetweenDay).Format(utils.FormatDate)
|
|
|
- //如果等于最后的实际日期,那么遍历找到该日期对应的时间戳,并将其赋值为 切割时间戳
|
|
|
- if edbDataItems.Year >= latestDateYear {
|
|
|
- for _, tmpData := range edbDataItems.Items {
|
|
|
- if tmpData.DataTime == cuttingDataTimeStr {
|
|
|
- cuttingDataTimestamp = tmpData.DataTimestamp
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- edbDataItems.CuttingDataTimestamp = cuttingDataTimestamp
|
|
|
- result.List[k] = edbDataItems
|
|
|
- }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetSeasonEdbInfoDataListByXDate 季节性图的指标数据根据横轴展示
|
|
|
+func GetSeasonEdbInfoDataListByXDate(dataList []*data_manage.EdbDataList, latestDate time.Time, seasonExtraConfig string) (quarterDataListSort data_manage.QuarterDataList, err error) {
|
|
|
+ xStartDate := "01-01"
|
|
|
+ xEndDate := "12-31"
|
|
|
+ jumpYear := 0
|
|
|
+ legends := make([]data_manage.SeasonChartLegend, 0)
|
|
|
+ var seasonExtra data_manage.SeasonExtraItem
|
|
|
+ if seasonExtraConfig != "" {
|
|
|
+ err = json.Unmarshal([]byte(seasonExtraConfig), &seasonExtra)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if seasonExtra.XStartDate != "" {
|
|
|
+ xStartDate = seasonExtra.XStartDate
|
|
|
+ xEndDate = seasonExtra.XEndDate
|
|
|
+ jumpYear = seasonExtra.JumpYear
|
|
|
+ legends = seasonExtra.ChartLegend
|
|
|
+ }
|
|
|
+
|
|
|
+ length := len(dataList)
|
|
|
+ if length == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ legendMap := make(map[string]string, 0)
|
|
|
+ if len(legends) > 0 {
|
|
|
+ for _, v := range legends {
|
|
|
+ legendMap[v.Name] = v.Value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ latestDateStr := latestDate.Format(utils.FormatDate)
|
|
|
+
|
|
|
+ //判断横轴的两个时间之间是不是跨年了,如果跨年了,则横轴截止年份比起始年份+1,如果不跨年,截止年份等于起始年份
|
|
|
+ //根据数据确定最早的年份,和最近年份
|
|
|
+ //根据横轴的日期,汇总所有的年份
|
|
|
+ startDate := dataList[0].DataTime
|
|
|
+ startDateT, tmpErr := time.Parse(utils.FormatDate, startDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ startYear := startDateT.Year()
|
|
|
+ //获取数据的最新日期
|
|
|
+ lastDate := dataList[length-1].DataTime
|
|
|
+ lastDateT, tmpErr := time.Parse(utils.FormatDate, lastDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ endYear := lastDateT.Year()
|
|
|
+ nowYear := time.Now().Year()
|
|
|
+ dataMap := make(map[string]data_manage.QuarterXDateItem, 0)
|
|
|
+
|
|
|
+ quarterDataList := make([]*data_manage.QuarterData, 0)
|
|
|
+ quarterMap := make(map[string][]*data_manage.EdbDataList, 0)
|
|
|
+
|
|
|
+ //整理出日期
|
|
|
+ idx := 1
|
|
|
+ chartLegendMap := make(map[string]int, 0)
|
|
|
+ for currentStartYear := startYear; currentStartYear <= endYear; currentStartYear++ {
|
|
|
+ startStr := fmt.Sprintf("%d-%s", currentStartYear, xStartDate)
|
|
|
+ currentEndYear := currentStartYear
|
|
|
+ if jumpYear == 1 {
|
|
|
+ currentEndYear = currentStartYear + 1
|
|
|
+ }
|
|
|
+ endStr := fmt.Sprintf("%d-%s", currentEndYear, xEndDate)
|
|
|
+ name := fmt.Sprintf("%s_%s", startStr, endStr)
|
|
|
+ showName := fmt.Sprintf("%d_%d", currentStartYear, currentEndYear)
|
|
|
+
|
|
|
+ startT, tEr := time.Parse(utils.FormatDate, startStr)
|
|
|
+ if tEr != nil {
|
|
|
+ err = tEr
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- if result.List[0].Year != calendarPreYear {
|
|
|
- itemList := make([]*data_manage.EdbDataList, 0)
|
|
|
- items := new(data_manage.EdbDataItems)
|
|
|
- //items.Year = calendarPreYear
|
|
|
- items.Items = itemList
|
|
|
+ endT, tEr := time.Parse(utils.FormatDate, endStr)
|
|
|
+ if tEr != nil {
|
|
|
+ err = tEr
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- newResult := new(data_manage.EdbDataResult)
|
|
|
- newResult.List = append(newResult.List, items)
|
|
|
- newResult.List = append(newResult.List, result.List...)
|
|
|
- item.DataList = newResult
|
|
|
+ if lastDateT.Before(startT) {
|
|
|
+ //如果最新的日期在起始日之前,则跳出循环
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ if endT.Year() > nowYear {
|
|
|
+ //如果最新的日期比真实年份要大,则数据全部按照最大的年份补齐
|
|
|
+ nowYear = endT.Year()
|
|
|
+ }
|
|
|
+
|
|
|
+ item := data_manage.QuarterXDateItem{
|
|
|
+ StartDate: startT,
|
|
|
+ EndDate: endT,
|
|
|
+ ShowName: showName,
|
|
|
+ }
|
|
|
+ dataMap[name] = item
|
|
|
+ chartLegendMap[name] = idx
|
|
|
+ idx++
|
|
|
+ if lastDateT.Before(endT) {
|
|
|
+ //如果最新的日期在起始日之前,则跳出循环
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lenYear := len(dataMap)
|
|
|
+ for k, v := range dataMap {
|
|
|
+ if i, ok := chartLegendMap[k]; ok {
|
|
|
+ v.ChartLegend = strconv.Itoa(endYear - lenYear + i)
|
|
|
+ }
|
|
|
+ dataMap[k] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range dataList {
|
|
|
+ dataTimeT, _ := time.Parse(utils.FormatDate, v.DataTime)
|
|
|
+ year := dataTimeT.Year()
|
|
|
+ newItemDate := dataTimeT.AddDate(nowYear-year, 0, 0)
|
|
|
+ for k, dateItem := range dataMap {
|
|
|
+ tmpVal := data_manage.EdbDataList{
|
|
|
+ EdbDataId: v.EdbDataId,
|
|
|
+ EdbInfoId: v.EdbInfoId,
|
|
|
+ DataTime: v.DataTime,
|
|
|
+ DataTimestamp: v.DataTimestamp,
|
|
|
+ Value: v.Value,
|
|
|
+ }
|
|
|
+ if (dateItem.StartDate.Before(dataTimeT) && dateItem.EndDate.After(dataTimeT)) || dateItem.StartDate == dataTimeT || dateItem.EndDate == dataTimeT {
|
|
|
+ if jumpYear == 1 {
|
|
|
+ //计算前一年最大的日期, 只补齐数据到去年
|
|
|
+ beforeYearMaxDate := fmt.Sprintf("%d-12-31", dateItem.StartDate.Year())
|
|
|
+ beforeYearMaxDateT, _ := time.Parse(utils.FormatDate, beforeYearMaxDate)
|
|
|
+ if dataTimeT.Before(beforeYearMaxDateT) || dataTimeT == beforeYearMaxDateT {
|
|
|
+ newItemDate = dataTimeT.AddDate(nowYear-year-1, 0, 0)
|
|
|
} else {
|
|
|
- item.DataList = result
|
|
|
+ newItemDate = dataTimeT.AddDate(nowYear-year, 0, 0)
|
|
|
}
|
|
|
+ } else {
|
|
|
+ newItemDate = dataTimeT.AddDate(nowYear-year, 0, 0)
|
|
|
+ }
|
|
|
+ timestamp := newItemDate.UnixNano() / 1e6
|
|
|
+ tmpVal.DataTimestamp = timestamp
|
|
|
+ tmpV := &tmpVal
|
|
|
+ if findVal, ok := quarterMap[k]; !ok {
|
|
|
+ findVal = append(findVal, tmpV)
|
|
|
+ quarterMap[k] = findVal
|
|
|
+ } else {
|
|
|
+ findVal = append(findVal, tmpV)
|
|
|
+ quarterMap[k] = findVal
|
|
|
}
|
|
|
|
|
|
- } else {
|
|
|
- currentYear := time.Now().Year()
|
|
|
+ if v.DataTime == latestDateStr {
|
|
|
+ dateItem.CuttingDataTimestamp = timestamp
|
|
|
+ dataMap[k] = dateItem
|
|
|
+ }
|
|
|
+ //break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for k, v := range dataMap {
|
|
|
+ itemList := quarterMap[k]
|
|
|
+ quarterItem := new(data_manage.QuarterData)
|
|
|
+ quarterItem.Years = v.ShowName
|
|
|
+ quarterItem.ChartLegend = v.ChartLegend
|
|
|
+ if le, ok := legendMap[v.ShowName]; ok {
|
|
|
+ if le != strconv.Itoa(v.StartDate.Year()) && le != strconv.Itoa(v.EndDate.Year()) {
|
|
|
+ quarterItem.ChartLegend = le
|
|
|
+ }
|
|
|
+ }
|
|
|
+ quarterItem.DataList = itemList
|
|
|
+ quarterItem.CuttingDataTimestamp = v.CuttingDataTimestamp
|
|
|
+
|
|
|
+ //如果等于最后的实际日期,那么将切割时间戳记录
|
|
|
+ if quarterItem.CuttingDataTimestamp == 0 {
|
|
|
+ //如果大于最后的实际日期,那么第一个点就是切割的时间戳
|
|
|
+ if latestDate.Before(v.StartDate) && len(itemList) > 0 {
|
|
|
+ quarterItem.CuttingDataTimestamp = itemList[0].DataTimestamp - 100
|
|
|
+ }
|
|
|
+ }
|
|
|
+ quarterDataList = append(quarterDataList, quarterItem)
|
|
|
+ }
|
|
|
|
|
|
- quarterDataList := make([]*data_manage.QuarterData, 0)
|
|
|
- quarterMap := make(map[int][]*data_manage.EdbDataList)
|
|
|
- var quarterArr []int
|
|
|
+ if len(quarterDataList) > 0 {
|
|
|
+ quarterDataListSort = quarterDataList
|
|
|
+ sort.Sort(quarterDataListSort)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
|
|
|
- for _, v := range dataList {
|
|
|
- itemDate, tmpErr := time.Parse(utils.FormatDate, v.DataTime)
|
|
|
- if tmpErr != nil {
|
|
|
- err = errors.New("季度指标日期转换,Err:" + tmpErr.Error() + ";DataTime:" + v.DataTime)
|
|
|
- return
|
|
|
+// GetSeasonEdbInfoDataListByXDateNong 季节性图的指标数据根据横轴选择农历时展示
|
|
|
+func GetSeasonEdbInfoDataListByXDateNong(result *data_manage.EdbDataResult, latestDate time.Time, seasonExtraConfig string, calendarPreYear int) (quarterDataListSort data_manage.QuarterDataList, err error) {
|
|
|
+ xStartDate := "01-01"
|
|
|
+ xEndDate := "12-31"
|
|
|
+ jumpYear := 0
|
|
|
+ legends := make([]data_manage.SeasonChartLegend, 0)
|
|
|
+ var seasonExtra data_manage.SeasonExtraItem
|
|
|
+ if seasonExtraConfig != "" {
|
|
|
+ err = json.Unmarshal([]byte(seasonExtraConfig), &seasonExtra)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if seasonExtra.XStartDate != "" {
|
|
|
+ xStartDate = seasonExtra.XStartDate
|
|
|
+ xEndDate = seasonExtra.XEndDate
|
|
|
+ jumpYear = seasonExtra.JumpYear
|
|
|
+ legends = seasonExtra.ChartLegend
|
|
|
+ }
|
|
|
+
|
|
|
+ length := len(result.List)
|
|
|
+ if length == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ legendMap := make(map[string]string, 0)
|
|
|
+ if len(legends) > 0 {
|
|
|
+ for _, v := range legends {
|
|
|
+ legendMap[v.Name] = v.Value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ latestDateYear := latestDate.Year()
|
|
|
+ //判断横轴的两个时间之间是不是跨年了,如果跨年了,则横轴截止年份比起始年份+1,如果不跨年,截止年份等于起始年份
|
|
|
+ //根据数据确定最早的年份,和最近年份
|
|
|
+ //根据横轴的日期,汇总所有的年份
|
|
|
+ startYear := result.List[0].Year
|
|
|
+ /*if jumpYear == 1 {
|
|
|
+ if startYear != calendarPreYear {
|
|
|
+ startYear = startYear - 1
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ itemLength := len(result.List[length-1].Items)
|
|
|
+ //获取数据的最新日期
|
|
|
+ lastDate := result.List[length-1].Items[itemLength-1].DataTime
|
|
|
+ lastDateT, tmpErr := time.Parse(utils.FormatDate, lastDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ endYear := lastDateT.Year()
|
|
|
+ nowYear := time.Now().Year()
|
|
|
+ dataMap := make(map[string]data_manage.QuarterXDateItem, 0)
|
|
|
+
|
|
|
+ quarterDataList := make([]*data_manage.QuarterData, 0)
|
|
|
+ resultData := make([]*data_manage.QuarterData, 0)
|
|
|
+ quarterMap := make(map[string][]*data_manage.EdbDataList, 0)
|
|
|
+
|
|
|
+ //整理出日期
|
|
|
+ idx := 1
|
|
|
+ chartLegendMap := make(map[string]int, 0)
|
|
|
+ for currentStartYear := startYear; currentStartYear <= endYear; currentStartYear++ {
|
|
|
+ startStr := fmt.Sprintf("%d-%s", currentStartYear, xStartDate)
|
|
|
+ currentEndYear := currentStartYear
|
|
|
+ if jumpYear == 1 {
|
|
|
+ currentEndYear = currentStartYear + 1
|
|
|
+ }
|
|
|
+ endStr := fmt.Sprintf("%d-%s", currentEndYear, xEndDate)
|
|
|
+ showName := fmt.Sprintf("%d_%d", currentStartYear, currentEndYear)
|
|
|
+
|
|
|
+ startT, tEr := time.Parse(utils.FormatDate, startStr)
|
|
|
+ if tEr != nil {
|
|
|
+ err = tEr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ endT, tEr := time.Parse(utils.FormatDate, endStr)
|
|
|
+ if tEr != nil {
|
|
|
+ err = tEr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if lastDateT.Before(startT) {
|
|
|
+ //如果最新的日期在起始日之前,则跳出循环
|
|
|
+ break
|
|
|
+ }
|
|
|
+ if endT.Year() > nowYear {
|
|
|
+ //如果最新的日期比真实年份要大,则数据全部按照最大的年份补齐
|
|
|
+ nowYear = endT.Year()
|
|
|
+ }
|
|
|
+ item := data_manage.QuarterXDateItem{
|
|
|
+ StartDate: startT,
|
|
|
+ EndDate: endT,
|
|
|
+ ShowName: showName,
|
|
|
+ }
|
|
|
+ dataMap[showName] = item
|
|
|
+ chartLegendMap[showName] = idx
|
|
|
+ idx++
|
|
|
+ if lastDateT.Before(endT) {
|
|
|
+ //如果最新的日期在起始日之前,则跳出循环
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lenYear := len(dataMap)
|
|
|
+ for k, v := range dataMap {
|
|
|
+ if i, ok := chartLegendMap[k]; ok {
|
|
|
+ v.ChartLegend = strconv.Itoa(endYear - lenYear + i)
|
|
|
+ }
|
|
|
+ dataMap[k] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ yearDataListMap := make(map[int]*data_manage.EdbDataItems, 0)
|
|
|
+
|
|
|
+ for _, lv := range result.List {
|
|
|
+ yearDataListMap[lv.Year] = lv
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断哪些点应该落在同一条时间线上
|
|
|
+ maxY := lastDateT.Year()
|
|
|
+ endTmp := fmt.Sprintf("%d-%s", maxY, xEndDate)
|
|
|
+ endTmpT, _ := time.Parse(utils.FormatDate, endTmp)
|
|
|
+ minY := maxY
|
|
|
+ if jumpYear == 1 {
|
|
|
+ minY = maxY - 1
|
|
|
+ }
|
|
|
+ startTmp := fmt.Sprintf("%d-%s", minY, xStartDate)
|
|
|
+ startTmpT, _ := time.Parse(utils.FormatDate, startTmp)
|
|
|
+
|
|
|
+ for name, dateItem := range dataMap {
|
|
|
+ lv, ok1 := yearDataListMap[dateItem.EndDate.Year()]
|
|
|
+ if dateItem.EndDate.Year() > lastDateT.Year() {
|
|
|
+ lv, ok1 = yearDataListMap[dateItem.StartDate.Year()]
|
|
|
+ }
|
|
|
+ if !ok1 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ for _, item := range lv.Items {
|
|
|
+ tmpVal := data_manage.EdbDataList{
|
|
|
+ EdbDataId: item.EdbDataId,
|
|
|
+ EdbInfoId: item.EdbInfoId,
|
|
|
+ DataTime: item.DataTime,
|
|
|
+ DataTimestamp: item.DataTimestamp,
|
|
|
+ Value: item.Value,
|
|
|
+ }
|
|
|
+ dataTimeT, _ := time.Parse(utils.FormatDate, item.DataTime)
|
|
|
+ year := dataTimeT.Year()
|
|
|
+ newItemDate := dataTimeT.AddDate(nowYear-year, 0, 0)
|
|
|
+ if dateItem.EndDate.Year() > maxY {
|
|
|
+ if (dateItem.StartDate.Before(dataTimeT) && dateItem.EndDate.After(dataTimeT)) || dateItem.StartDate == dataTimeT || dateItem.EndDate == dataTimeT {
|
|
|
+ if jumpYear == 1 {
|
|
|
+ //计算前一年最大的日期, 只补齐数据到去年
|
|
|
+ beforeYearMaxDate := fmt.Sprintf("%d-12-31", dateItem.StartDate.Year())
|
|
|
+ beforeYearMaxDateT, _ := time.Parse(utils.FormatDate, beforeYearMaxDate)
|
|
|
+ if dataTimeT.Before(beforeYearMaxDateT) || dataTimeT == beforeYearMaxDateT {
|
|
|
+ newItemDate = dataTimeT.AddDate(nowYear-year-1, 0, 0)
|
|
|
+ } else {
|
|
|
+ newItemDate = dataTimeT.AddDate(nowYear-year, 0, 0)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ newItemDate = dataTimeT.AddDate(nowYear-year, 0, 0)
|
|
|
}
|
|
|
- year := itemDate.Year()
|
|
|
- newItemDate := itemDate.AddDate(currentYear-year, 0, 0)
|
|
|
timestamp := newItemDate.UnixNano() / 1e6
|
|
|
- v.DataTimestamp = timestamp
|
|
|
- if findVal, ok := quarterMap[year]; !ok {
|
|
|
- quarterArr = append(quarterArr, year)
|
|
|
- findVal = append(findVal, v)
|
|
|
- quarterMap[year] = findVal
|
|
|
+ tmpVal.DataTimestamp = timestamp
|
|
|
+ tmpV := &tmpVal
|
|
|
+ if findVal, ok := quarterMap[name]; !ok {
|
|
|
+ findVal = append(findVal, tmpV)
|
|
|
+ quarterMap[name] = findVal
|
|
|
} else {
|
|
|
- findVal = append(findVal, v)
|
|
|
- quarterMap[year] = findVal
|
|
|
+ findVal = append(findVal, tmpV)
|
|
|
+ quarterMap[name] = findVal
|
|
|
+ }
|
|
|
+ if lv.Year >= latestDateYear {
|
|
|
+ // 切割的日期时间字符串
|
|
|
+ cuttingDataTimeStr := latestDate.AddDate(0, 0, lv.BetweenDay).Format(utils.FormatDate)
|
|
|
+ if item.DataTime == cuttingDataTimeStr {
|
|
|
+ dateItem.CuttingDataTimestamp = timestamp
|
|
|
+ dataMap[name] = dateItem
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- for _, v := range quarterArr {
|
|
|
- itemList := quarterMap[v]
|
|
|
- quarterItem := new(data_manage.QuarterData)
|
|
|
- quarterItem.Year = v
|
|
|
- quarterItem.DataList = itemList
|
|
|
-
|
|
|
- //如果等于最后的实际日期,那么将切割时间戳记录
|
|
|
- if v == latestDateYear {
|
|
|
- var cuttingDataTimestamp int64
|
|
|
- for _, tmpData := range itemList {
|
|
|
- if tmpData.DataTime == latestDateStr {
|
|
|
- cuttingDataTimestamp = tmpData.DataTimestamp
|
|
|
- break
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ if (startTmpT.Before(dataTimeT) && endTmpT.After(dataTimeT)) || startTmpT == dataTimeT || endTmpT == dataTimeT {
|
|
|
+ if jumpYear == 1 {
|
|
|
+ //计算前一年最大的日期, 只补齐数据到去年
|
|
|
+ beforeYearMaxDate := fmt.Sprintf("%d-12-31", startTmpT.Year())
|
|
|
+ beforeYearMaxDateT, _ := time.Parse(utils.FormatDate, beforeYearMaxDate)
|
|
|
+ if dataTimeT.Before(beforeYearMaxDateT) || dataTimeT == beforeYearMaxDateT {
|
|
|
+ newItemDate = dataTimeT.AddDate(nowYear-year-1, 0, 0)
|
|
|
+ } else {
|
|
|
+ newItemDate = dataTimeT.AddDate(nowYear-year, 0, 0)
|
|
|
}
|
|
|
- quarterItem.CuttingDataTimestamp = cuttingDataTimestamp
|
|
|
- } else if v > latestDateYear {
|
|
|
- //如果大于最后的实际日期,那么第一个点就是切割的时间戳
|
|
|
- if len(itemList) > 0 {
|
|
|
- quarterItem.CuttingDataTimestamp = itemList[0].DataTimestamp - 100
|
|
|
+ } else {
|
|
|
+ newItemDate = dataTimeT.AddDate(nowYear-year, 0, 0)
|
|
|
+ }
|
|
|
+ timestamp := newItemDate.UnixNano() / 1e6
|
|
|
+ tmpVal.DataTimestamp = timestamp
|
|
|
+ tmpV := &tmpVal
|
|
|
+ if findVal, ok := quarterMap[name]; !ok {
|
|
|
+ findVal = append(findVal, tmpV)
|
|
|
+ quarterMap[name] = findVal
|
|
|
+ } else {
|
|
|
+ findVal = append(findVal, tmpV)
|
|
|
+ quarterMap[name] = findVal
|
|
|
+ }
|
|
|
+ if lv.Year >= latestDateYear {
|
|
|
+ // 切割的日期时间字符串
|
|
|
+ cuttingDataTimeStr := latestDate.AddDate(0, 0, lv.BetweenDay).Format(utils.FormatDate)
|
|
|
+ if item.DataTime == cuttingDataTimeStr {
|
|
|
+ dateItem.CuttingDataTimestamp = timestamp
|
|
|
+ dataMap[name] = dateItem
|
|
|
}
|
|
|
}
|
|
|
- quarterDataList = append(quarterDataList, quarterItem)
|
|
|
}
|
|
|
- item.DataList = quarterDataList
|
|
|
}
|
|
|
- } else if chartType == 7 { //柱方图
|
|
|
- //item.DataList = dataList
|
|
|
- } else {
|
|
|
- item.DataList = dataList
|
|
|
}
|
|
|
- edbList = append(edbList, item)
|
|
|
+
|
|
|
+ }
|
|
|
+ for k, v := range dataMap {
|
|
|
+ itemList := quarterMap[k]
|
|
|
+ quarterItem := new(data_manage.QuarterData)
|
|
|
+ quarterItem.Years = v.ShowName
|
|
|
+ quarterItem.ChartLegend = v.ChartLegend
|
|
|
+ if le, ok := legendMap[v.ShowName]; ok {
|
|
|
+ if le != strconv.Itoa(v.StartDate.Year()) && le != strconv.Itoa(v.EndDate.Year()) {
|
|
|
+ quarterItem.ChartLegend = le
|
|
|
+ }
|
|
|
+ }
|
|
|
+ quarterItem.DataList = itemList
|
|
|
+ quarterItem.CuttingDataTimestamp = v.CuttingDataTimestamp
|
|
|
+
|
|
|
+ quarterDataList = append(quarterDataList, quarterItem)
|
|
|
+ }
|
|
|
+
|
|
|
+ if result.List[0].Year != calendarPreYear {
|
|
|
+ itemList := make([]*data_manage.EdbDataList, 0)
|
|
|
+ items := new(data_manage.QuarterData)
|
|
|
+ //items.Year = calendarPreYear
|
|
|
+ items.DataList = itemList
|
|
|
+
|
|
|
+ newResult := make([]*data_manage.QuarterData, 0)
|
|
|
+ newResult = append(newResult, items)
|
|
|
+ newResult = append(newResult, quarterDataList...)
|
|
|
+ resultData = newResult
|
|
|
+ } else {
|
|
|
+ resultData = quarterDataList
|
|
|
}
|
|
|
|
|
|
+ if len(quarterDataList) > 0 {
|
|
|
+ quarterDataListSort = resultData
|
|
|
+ sort.Sort(quarterDataListSort)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1241,7 +1623,7 @@ func CheckChartExtraConfig(chartType int, extraConfigStr string) (edbIdList []in
|
|
|
}
|
|
|
|
|
|
// GetSectionScatterChartData 截面散点图的数据处理
|
|
|
-func GetSectionScatterChartData(mappingList []*data_manage.ChartEdbInfoMapping, edbDataListMap map[int][]*data_manage.EdbDataList, extraConfig data_manage.SectionScatterReq) (edbIdList []int, chartDataResp data_manage.SectionScatterInfoResp, err error) {
|
|
|
+func GetSectionScatterChartData(chartInfoId int, mappingList []*data_manage.ChartEdbInfoMapping, edbDataListMap map[int][]*data_manage.EdbDataList, extraConfig data_manage.SectionScatterReq) (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 {
|
|
@@ -1502,6 +1884,7 @@ func GetSectionScatterChartData(mappingList []*data_manage.ChartEdbInfoMapping,
|
|
|
dataListResp = append(dataListResp, data_manage.SectionScatterSeriesItemResp{
|
|
|
Name: seriesItem.Name,
|
|
|
NameEn: seriesItem.NameEn,
|
|
|
+ IsNameDefault: seriesItem.IsNameDefault,
|
|
|
Color: seriesItem.Color,
|
|
|
EdbInfoList: tmpSeriesEdbInfoList,
|
|
|
ShowTrendLine: seriesItem.ShowTrendLine,
|
|
@@ -1513,6 +1896,39 @@ func GetSectionScatterChartData(mappingList []*data_manage.ChartEdbInfoMapping,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ // 截面散点图点击详情时自动更新系列名
|
|
|
+ if len(extraConfig.SeriesList) > 0 {
|
|
|
+ // 默认名字的时候才自动更新
|
|
|
+ if extraConfig.SeriesList[0].IsNameDefault {
|
|
|
+ firstXEdbInfoId := extraConfig.SeriesList[0].EdbInfoList[0].XEdbInfoId
|
|
|
+ needUpdate := false
|
|
|
+ if v, ok := edbMappingMap[firstXEdbInfoId]; ok {
|
|
|
+ extraConfig.SeriesList[0].Name = v.LatestDate
|
|
|
+ extraConfig.SeriesList[0].NameEn = v.LatestDate
|
|
|
+ dataListResp[0].Name = v.LatestDate
|
|
|
+ dataListResp[0].NameEn = v.LatestDate
|
|
|
+ needUpdate = true
|
|
|
+ }
|
|
|
+
|
|
|
+ extraConfigByte, e := json.Marshal(extraConfig)
|
|
|
+ if e != nil {
|
|
|
+ errMsg := "截面散点系列更新异常"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ extraConfigStr := string(extraConfigByte)
|
|
|
+
|
|
|
+ if needUpdate {
|
|
|
+ err = data_manage.EditChartInfoExtraConfig(chartInfoId, extraConfigStr)
|
|
|
+ if err != nil {
|
|
|
+ errMsg := "截面散点系列更新异常"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
chartDataResp = data_manage.SectionScatterInfoResp{
|
|
|
XName: extraConfig.XName,
|
|
|
XNameEn: extraConfig.XNameEn,
|
|
@@ -1568,6 +1984,8 @@ func AddChartInfo(req data_manage.AddChartInfoReq, sysUserId int, sysUserRealNam
|
|
|
chartType := req.ChartType
|
|
|
extraConfig := req.ExtraConfig
|
|
|
|
|
|
+ // 季节性图表额外配置信息
|
|
|
+ var seasonExtraConfig string
|
|
|
// 关联指标
|
|
|
var edbInfoIdArr []int
|
|
|
chartEdbInfoList := req.ChartEdbInfoList
|
|
@@ -1614,6 +2032,25 @@ func AddChartInfo(req data_manage.AddChartInfoReq, sysUserId int, sysUserRealNam
|
|
|
if existCount <= 0 {
|
|
|
go data_manage.AddCalculateQuarter(edbInfoId, edbInfo.Source, edbInfo.EdbCode)
|
|
|
}
|
|
|
+
|
|
|
+ // 处理季节性图表横轴配置
|
|
|
+ {
|
|
|
+ if req.SeasonExtraConfig.XEndDate != "" {
|
|
|
+ if req.SeasonExtraConfig.XStartDate > req.SeasonExtraConfig.XEndDate && req.SeasonExtraConfig.JumpYear != 1 {
|
|
|
+ errMsg = "季节性图表配置信息异常:横坐标日期配置错误"
|
|
|
+ err = errors.New("季节性图表配置信息异常: 横坐标日期配置错误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
|
|
|
+ if tErr != nil {
|
|
|
+ errMsg = "季节性图表配置信息异常"
|
|
|
+ err = errors.New("季节性图表配置信息异常,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ seasonExtraConfig = string(seasonExtra)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -1758,6 +2195,7 @@ func AddChartInfo(req data_manage.AddChartInfoReq, sysUserId int, sysUserRealNam
|
|
|
timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
|
chartInfo.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
|
|
|
|
|
|
+ // todo 判断是否需要重新计算用户的start_date
|
|
|
if req.DateType > 0 {
|
|
|
chartInfo.DateType = req.DateType
|
|
|
} else {
|
|
@@ -1772,11 +2210,12 @@ func AddChartInfo(req data_manage.AddChartInfoReq, sysUserId int, sysUserRealNam
|
|
|
if calendar == "" {
|
|
|
calendar = "公历"
|
|
|
}
|
|
|
+
|
|
|
chartInfo.Calendar = calendar
|
|
|
chartInfo.StartDate = req.StartDate
|
|
|
chartInfo.EndDate = req.EndDate
|
|
|
- chartInfo.SeasonStartDate = req.SeasonStartDate
|
|
|
- chartInfo.SeasonEndDate = req.SeasonEndDate
|
|
|
+ chartInfo.SeasonStartDate = req.StartDate
|
|
|
+ chartInfo.SeasonEndDate = req.EndDate
|
|
|
chartInfo.LeftMin = req.LeftMin
|
|
|
chartInfo.LeftMax = req.LeftMax
|
|
|
chartInfo.RightMin = req.RightMin
|
|
@@ -1784,6 +2223,8 @@ func AddChartInfo(req data_manage.AddChartInfoReq, sysUserId int, sysUserRealNam
|
|
|
chartInfo.Disabled = disableVal
|
|
|
chartInfo.BarConfig = barChartConf
|
|
|
chartInfo.ExtraConfig = extraConfig
|
|
|
+ chartInfo.SeasonExtraConfig = seasonExtraConfig
|
|
|
+ chartInfo.StartYear = req.StartYear
|
|
|
chartInfo.Source = utils.CHART_SOURCE_DEFAULT
|
|
|
newId, err := data_manage.AddChartInfo(chartInfo)
|
|
|
if err != nil {
|
|
@@ -1876,6 +2317,8 @@ func EditChartInfo(req data_manage.EditChartInfoReq, sysUser *system.Admin) (cha
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // 季节性图表额外配置信息
|
|
|
+ var seasonExtraConfig string
|
|
|
// 图表关联指标id
|
|
|
chartEdbInfoList := make([]*data_manage.ChartSaveItem, 0)
|
|
|
// 关联指标
|
|
@@ -1925,6 +2368,25 @@ func EditChartInfo(req data_manage.EditChartInfoReq, sysUser *system.Admin) (cha
|
|
|
if existCount <= 0 {
|
|
|
go data_manage.AddCalculateQuarter(edbInfoId, edbInfo.Source, edbInfo.EdbCode)
|
|
|
}
|
|
|
+
|
|
|
+ // 处理季节性图表横轴配置
|
|
|
+ {
|
|
|
+ if req.SeasonExtraConfig.XEndDate != "" {
|
|
|
+ if req.SeasonExtraConfig.XStartDate > req.SeasonExtraConfig.XEndDate && req.SeasonExtraConfig.JumpYear != 1 {
|
|
|
+ errMsg = "季节性图表配置信息异常:横坐标日期配置错误"
|
|
|
+ err = errors.New("季节性图表配置信息异常: 横坐标日期配置错误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
|
|
|
+ if tErr != nil {
|
|
|
+ errMsg = "季节性图表配置信息异常"
|
|
|
+ err = errors.New("季节性图表配置信息异常,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ seasonExtraConfig = string(seasonExtra)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
chartEdbInfoList = req.ChartEdbInfoList
|
|
@@ -2015,7 +2477,6 @@ func EditChartInfo(req data_manage.EditChartInfoReq, sysUser *system.Admin) (cha
|
|
|
dateType = 3
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
sort.Ints(edbInfoIdArr)
|
|
|
var edbInfoIdArrStr []string
|
|
|
for _, v := range edbInfoIdArr {
|
|
@@ -2087,7 +2548,7 @@ func EditChartInfo(req data_manage.EditChartInfoReq, sysUser *system.Admin) (cha
|
|
|
// 图表启用与否
|
|
|
disableVal := CheckIsDisableChart(edbInfoIdArr)
|
|
|
|
|
|
- err = data_manage.EditChartInfoAndMapping(&req, edbInfoIdStr, calendar, dateType, disableVal, barChartConf, chartEdbInfoList)
|
|
|
+ err = data_manage.EditChartInfoAndMapping(&req, edbInfoIdStr, calendar, dateType, disableVal, barChartConf, chartEdbInfoList, seasonExtraConfig)
|
|
|
if err != nil {
|
|
|
errMsg = "保存失败"
|
|
|
err = errors.New("保存失败,Err:" + err.Error())
|