|
@@ -40,9 +40,8 @@ func ModifyChartInfoAndMapping(edbInfoIdStr string, req *chartInfoModel.SaveChar
|
|
|
}()
|
|
|
|
|
|
// 更新图表信息
|
|
|
- if chartType == 1 {
|
|
|
- sql := ` UPDATE chart_info
|
|
|
- SET
|
|
|
+ if chartType != 2 {
|
|
|
+ updateStr := `
|
|
|
edb_info_ids = ?,
|
|
|
modify_time = NOW(),
|
|
|
date_type = ?,
|
|
@@ -51,13 +50,18 @@ func ModifyChartInfoAndMapping(edbInfoIdStr string, req *chartInfoModel.SaveChar
|
|
|
left_min = ?,
|
|
|
left_max = ?,
|
|
|
right_min = ?,
|
|
|
- right_max = ?,extra_config = ?
|
|
|
- WHERE chart_info_id = ?`
|
|
|
- err = tx.Exec(sql, edbInfoIdStr, req.DateType, req.StartDate, req.EndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax, req.ExtraConfig, req.ChartInfoId).Error
|
|
|
+ right_max = ?`
|
|
|
+ pars := []interface{}{edbInfoIdStr, req.DateType, req.StartDate, req.EndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax}
|
|
|
+
|
|
|
+ if req.ExtraConfig != `` {
|
|
|
+ updateStr += `,extra_config=? `
|
|
|
+ pars = append(pars, req.ExtraConfig)
|
|
|
+ }
|
|
|
+ pars = append(pars, req.ChartInfoId)
|
|
|
+ sql := ` UPDATE chart_info SET ` + updateStr + ` WHERE chart_info_id = ?`
|
|
|
+ err = tx.Exec(sql, pars...).Error
|
|
|
} else {
|
|
|
- sql := ` UPDATE chart_info
|
|
|
- SET
|
|
|
- edb_info_ids = ?,
|
|
|
+ updateStr := `edb_info_ids = ?,
|
|
|
modify_time = NOW(),
|
|
|
date_type = ?,
|
|
|
calendar = ?,
|
|
@@ -68,9 +72,15 @@ func ModifyChartInfoAndMapping(edbInfoIdStr string, req *chartInfoModel.SaveChar
|
|
|
left_min = ?,
|
|
|
left_max = ?,
|
|
|
right_min = ?,
|
|
|
- right_max = ?,extra_config = ?
|
|
|
- WHERE chart_info_id = ?`
|
|
|
- err = tx.Exec(sql, edbInfoIdStr, req.DateType, req.Calendar, req.StartDate, req.EndDate, req.StartDate, req.EndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax, req.ExtraConfig, req.ChartInfoId).Error
|
|
|
+ right_max = ?`
|
|
|
+ pars := []interface{}{edbInfoIdStr, req.DateType, req.Calendar, req.StartDate, req.EndDate, req.StartDate, req.EndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax}
|
|
|
+ if req.ExtraConfig != `` {
|
|
|
+ updateStr += `,extra_config=? `
|
|
|
+ pars = append(pars, req.ExtraConfig)
|
|
|
+ }
|
|
|
+ pars = append(pars, req.ChartInfoId)
|
|
|
+ sql := ` UPDATE chart_info SET ` + updateStr + ` WHERE chart_info_id = ?`
|
|
|
+ err = tx.Exec(sql, pars...).Error
|
|
|
}
|
|
|
if err != nil {
|
|
|
fmt.Println("UPDATE chart_info Err:", err.Error())
|
|
@@ -439,6 +449,23 @@ func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate st
|
|
|
return
|
|
|
}
|
|
|
extraConfig = tmpExtraConfig
|
|
|
+ case utils.CHART_TYPE_RADAR:
|
|
|
+ var barConfig request.RadarChartInfoReq
|
|
|
+ if extraConfigStr == `` {
|
|
|
+ errMsg = "雷达图未配置"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = json.Unmarshal([]byte(extraConfigStr), &barConfig)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "雷达图配置异常"
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ extraConfig = barConfig
|
|
|
+ default:
|
|
|
+ xEdbIdValue = make([]int, 0)
|
|
|
+ yDataList = make([]chart_info.YData, 0)
|
|
|
}
|
|
|
|
|
|
// 指标对应的所有数据
|
|
@@ -471,6 +498,9 @@ func GetChartEdbData(chartInfoId, chartType int, calendar, startDate, endDate st
|
|
|
for _, v := range edbList {
|
|
|
v.DataList = nil
|
|
|
}
|
|
|
+ case utils.CHART_TYPE_RADAR: //雷达图
|
|
|
+ radarConf := extraConfig.(request.RadarChartInfoReq)
|
|
|
+ xEdbIdValue, dataResp, err = RadarChartData(mappingList, edbDataListMap, radarConf)
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -547,6 +577,7 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
|
|
|
item.LatestDate = v.LatestDate
|
|
|
item.UniqueCode = v.UniqueCode
|
|
|
item.MoveLatestDate = item.LatestDate
|
|
|
+ item.EdbAliasName = v.EdbAliasName
|
|
|
|
|
|
var startDateReal string
|
|
|
var diffSeconds int64
|
|
@@ -659,7 +690,7 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
|
|
|
}
|
|
|
item.DataList = quarterDataList
|
|
|
}
|
|
|
- } else if chartType == 7 { //柱方图
|
|
|
+ } else if chartType == 7 || chartType == utils.CHART_TYPE_RADAR { //柱方图
|
|
|
//item.DataList = dataList
|
|
|
} else {
|
|
|
item.DataList = dataList
|
|
@@ -1692,3 +1723,117 @@ func GetSectionScatterChartData(mappingList []*chartEdbMappingModel.ChartEdbInfo
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// RadarChartData 雷达图的数据处理
|
|
|
+func RadarChartData(mappingList []*chartEdbMappingModel.ChartEdbInfoMapping, edbDataListMap map[int][]*edbDataModel.EdbDataList, extraConfig request.RadarChartInfoReq) (edbIdList []int, chartDataResp chart_info.RadarChartInfoResp, 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)
|
|
|
+ for _, v := range mappingList {
|
|
|
+ edbIdList = append(edbIdList, v.EdbInfoId)
|
|
|
+ }
|
|
|
+ chartDateList := extraConfig.DateList
|
|
|
+
|
|
|
+ yDataList := make([]chart_info.RadarYData, 0) //y轴的数据列表
|
|
|
+
|
|
|
+ for _, chartDate := range chartDateList {
|
|
|
+ var maxDate time.Time
|
|
|
+
|
|
|
+ findDataList := make([]float64, 0) // 当前日期的数据值
|
|
|
+ for _, edbInfoId := range edbIdList {
|
|
|
+ findDate := chartDate.Date //需要的日期值
|
|
|
+ dataList := edbDataListMap[edbInfoId] //指标的所有数据值
|
|
|
+ if len(dataList) <= 0 {
|
|
|
+ // 没有数据的指标id
|
|
|
+ findDataList = append(findDataList, 0)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ switch chartDate.Type {
|
|
|
+ case 1: //最新值
|
|
|
+ findDate = dataList[len(dataList)-1].DataTime
|
|
|
+ case 2: //近期几天
|
|
|
+ findDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[len(dataList)-1].DataTime, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ findDateTime = findDateTime.AddDate(0, 0, -chartDate.Value)
|
|
|
+
|
|
|
+ lenData := len(dataList) - 1
|
|
|
+ for i := lenData; i >= 0; i-- {
|
|
|
+ currDateTime, e := time.ParseInLocation(utils.FormatDate, dataList[i].DataTime, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if currDateTime.Equal(findDateTime) || currDateTime.Before(findDateTime) {
|
|
|
+ findDate = dataList[i].DataTime
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case 3: // 固定日期
|
|
|
+ //最早的日期
|
|
|
+ minDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[0].DataTime, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //寻找固定日期的数据
|
|
|
+ findDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, chartDate.Date, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for tmpDateTime := findDateTime; tmpDateTime.After(minDateTime) || tmpDateTime.Equal(minDateTime); tmpDateTime = tmpDateTime.AddDate(0, 0, -1) {
|
|
|
+ tmpDate := tmpDateTime.Format(utils.FormatDate)
|
|
|
+ if _, ok := edbDataMap[edbInfoId][tmpDate]; ok { //如果能找到数据,那么就返回
|
|
|
+ findDate = tmpDate
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ err = errors.New(fmt.Sprint("日期类型异常,Type:", chartDate.Type))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ 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 {
|
|
|
+ tmpValue, _ = decimal.NewFromFloat(tmpValue).Round(4).Float64()
|
|
|
+ findDataList = append(findDataList, tmpValue)
|
|
|
+ } else {
|
|
|
+ findDataList = append(findDataList, 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ yDate := "0000-00-00"
|
|
|
+ if !maxDate.IsZero() {
|
|
|
+ yDate = maxDate.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ yDataList = append(yDataList, chart_info.RadarYData{
|
|
|
+ Date: yDate,
|
|
|
+ Value: findDataList,
|
|
|
+ Color: chartDate.Color,
|
|
|
+ Name: chartDate.Name,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ chartDataResp = chart_info.RadarChartInfoResp{
|
|
|
+ YDataList: yDataList,
|
|
|
+ XEdbIdValue: edbIdList,
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|