diff --git a/api/version1/customChartesing/getSearchTime.go b/api/version1/customChartesing/getSearchTime.go index 0fd44b5..f9c6259 100644 --- a/api/version1/customChartesing/getSearchTime.go +++ b/api/version1/customChartesing/getSearchTime.go @@ -41,6 +41,7 @@ func (c *ChartInfo) JieXiSearchTime() (xAlist []string) { starYearInt, _ := strconv.ParseInt(starYear, 10, 64) endYearInt, _ := strconv.ParseInt(endYear, 10, 64) buJinzhi := endYearInt - starYearInt + fmt.Printf("年度计算:%v-------->%v-------->%v\n\n", endYearInt, starYearInt, buJinzhi) if buJinzhi == 0 { xAlist = append(xAlist, fmt.Sprintf("%v", buJinzhi)) } else { @@ -54,27 +55,30 @@ func (c *ChartInfo) JieXiSearchTime() (xAlist []string) { beginMonth := publicmethod.UnixTimeToDay(startTime, 17) endYear := publicmethod.UnixTimeToDay(endTime, 16) endMonth := publicmethod.UnixTimeToDay(endTime, 17) + // fmt.Printf("年度计算:%v-------->%v-------->%v-------->%v\n\n", starYear, beginMonth, endYear, endMonth) if starYear == endYear && beginMonth == endMonth { xAlist = append(xAlist, fmt.Sprintf("%v-%v", starYear, beginMonth)) } else if starYear == endYear && beginMonth != endMonth { beginMonthInt, _ := strconv.ParseInt(beginMonth, 10, 64) endMonthInt, _ := strconv.ParseInt(endMonth, 10, 64) for i := beginMonthInt; i <= endMonthInt; i++ { - xAlist = append(xAlist, fmt.Sprintf("%v-%v", starYear, beginMonthInt+i)) + xAlist = append(xAlist, fmt.Sprintf("%v-%v", starYear, i)) } + // fmt.Printf("年度计算:%v-----1--->%v-------->%v-------->%v\n\n", starYear, beginMonthInt, endYear, xAlist) } else { beginMonthInt, _ := strconv.ParseInt(beginMonth, 10, 64) endMonthInt, _ := strconv.ParseInt(endMonth, 10, 64) - + // fmt.Printf("年度计算:%v-----2--->%v-------->%v-------->%v\n\n", starYear, beginMonthInt, endYear, endMonthInt) for i := beginMonthInt; i <= 12; i++ { xAlist = append(xAlist, fmt.Sprintf("%v-%v", starYear, beginMonthInt+i)) } var j int64 - for j = 0; j <= endMonthInt; j++ { + for j = 0; j < endMonthInt; j++ { xAlist = append(xAlist, fmt.Sprintf("%v-%v", endYear, j)) } } + // fmt.Printf("年度计算:%v-----3--->%v-------->%v-------->%v\n\n", starYear, xAlist, endYear, xAlist) case "day": starday := publicmethod.UnixTimeToDay(startTime, 14) endday := publicmethod.UnixTimeToDay(endTime, 14) diff --git a/api/version1/customChartesing/pieChart.go b/api/version1/customChartesing/pieChart.go index 26d93f9..69ffcf1 100644 --- a/api/version1/customChartesing/pieChart.go +++ b/api/version1/customChartesing/pieChart.go @@ -373,14 +373,14 @@ func (c *ChartInfo) PieDataAnaly(x XAxisInfo, y []YAxisInfo, val interface{}, ch // 处理主数据 func (s *SendPicInfo) picMasterDataAnaly(xField, keyName string, fathreName, val interface{}) { - fmt.Printf("处理主数据----->%v-----------%v\n\n\n", keyName, fathreName) + // fmt.Printf("处理主数据----->%v-----------%v\n\n\n", keyName, fathreName) if yVal, isOk := val.([]map[string]interface{}); isOk { jsq := 0 var masterInfo PicChartInfo masterInfo.Name = publicmethod.TypeToInterface(fathreName) for _, mv := range yVal { if xVal, isOk := mv[xField]; isOk { - fmt.Printf("处理主数据--2323--->%v-----------%v\n\n\n", xVal, fathreName) + // fmt.Printf("处理主数据--2323--->%v-----------%v\n\n\n", xVal, fathreName) xValStr := publicmethod.TypeToInterface(xVal) if xValStr == keyName { jsq++ diff --git a/api/version1/customChartesing/radar.go b/api/version1/customChartesing/radar.go index c567c90..6cd04f1 100644 --- a/api/version1/customChartesing/radar.go +++ b/api/version1/customChartesing/radar.go @@ -5,6 +5,7 @@ import ( "appPlatform/overall/publicmethod" "fmt" "strconv" + "strings" "time" ) @@ -29,13 +30,151 @@ func (c *ChartInfo) radarChart(val interface{}, untis []customerform.MasterStruc } func (c *ChartInfo) RadarTimeDataAnaly(x XAxisInfo, y []YAxisInfo, val interface{}, chartType string) (charData RadarInfo) { tayTime := time.Now().Unix() + searchTime := c.JieXiSearchTime() + fmt.Printf("时间集---1-->%v\n\n", searchTime) switch x.TimeType { case "year": + tayTimeing := int(time.Now().Year()) + var timeList []string + // for i := 0; i <= tayTimeing; i++ { + timeList = append(timeList, fmt.Sprintf("%v", tayTimeing)) + // } + if len(searchTime) > 0 { + timeList = searchTime + } + var jiSuanVal []RadarTimeInfo + + fmt.Printf("时间集----->%v\n\n", timeList) + // for _, v := range y { + // charData.Legend = append(charData.Legend, v.OldTitle) + var newVal []map[string]interface{} + for _, tv := range timeList { + + startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01-01 00:00:00", tv)) + endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-12-31 23:59:59", tv)) + if yVal, isOk := val.([]map[string]interface{}); isOk { + for _, mv := range yVal { + if xVal, isOk := mv[x.Field]; isOk { + var begTime int64 + var eldTime int64 + pageTime, _ := publicmethod.StringToInt64(xVal) + if publicmethod.GetIntLength(pageTime) >= 13 { + begTime = startTime * 1000 + eldTime = endTime * 1000 + } + if begTime <= pageTime && pageTime <= eldTime { + // fmt.Printf("维度--3---》%v---》%v---》%v\n\n", tv, begTime <= pageTime, pageTime <= eldTime) + newVal = append(newVal, mv) + } + } + } + } + var timeData RadarTimeInfo + timeData.XName = tv + timeData.DataVal = newVal + jiSuanVal = append(jiSuanVal, timeData) + // fmt.Printf("维度--1---》%v---》%v\n\n", tv, len(newVal)) + } + // jsonVal, _ := json.Marshal(jiSuanVal) + // fmt.Printf("维度-----》%v\n\n", string(jsonVal)) + charData.ParsingData(jiSuanVal, y) + case "month": + var timeList []string + yearVal := publicmethod.UnixTimeToDay(tayTime, 16) + tayTimeing := int(time.Now().Month()) + for i := 1; i <= tayTimeing; i++ { + timeList = append(timeList, fmt.Sprintf("%v-%v", yearVal, i)) + } + if len(searchTime) > 0 { + timeList = searchTime + } + var jiSuanVal []RadarTimeInfo + // for _, v := range y { + // charData.Legend = append(charData.Legend, v.OldTitle) + var newVal []map[string]interface{} + for _, tv := range timeList { + startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01 00:00:00", tv)) + nyAry := strings.Split(tv, "-") + year, _ := strconv.Atoi(nyAry[0]) + mon, _ := strconv.Atoi(nyAry[len(nyAry)-1]) + endTime := publicmethod.GetDaysInMonth(year, mon) + fmt.Printf("维度--1---》%v---》%v---》%v\n\n", startTime, mon, endTime) + // endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v- 23:59:59", tv)) + if yVal, isOk := val.([]map[string]interface{}); isOk { + for _, mv := range yVal { + if xVal, isOk := mv[x.Field]; isOk { + var begTime int64 + var eldTime int64 + pageTime, _ := publicmethod.StringToInt64(xVal) + if publicmethod.GetIntLength(pageTime) >= 13 { + begTime = startTime * 1000 + eldTime = endTime.AllTime * 1000 + } + if begTime <= pageTime && pageTime <= eldTime { + // fmt.Printf("维度--3---》%v---》%v---》%v\n\n", tv, begTime <= pageTime, pageTime <= eldTime) + newVal = append(newVal, mv) + } + } + } + } + var timeData RadarTimeInfo + timeData.XName = tv + timeData.DataVal = newVal + jiSuanVal = append(jiSuanVal, timeData) + // fmt.Printf("维度--1---》%v---》%v\n\n", tv, len(newVal)) + } + // jsonVal, _ := json.Marshal(jiSuanVal) + // fmt.Printf("维度-----》%v\n\n", string(jsonVal)) + charData.ParsingData(jiSuanVal, y) + // }y case "day": - case "hour": - case "minute": - case "second": - case "ymdhms": + tayTimeing := int(time.Now().Day()) + yearVal := publicmethod.UnixTimeToDay(tayTime, 15) + var timeList []string + for i := 1; i <= tayTimeing; i++ { + timeList = append(timeList, fmt.Sprintf("%v-%v", yearVal, i)) + } + if len(searchTime) > 0 { + timeList = searchTime + } + var jiSuanVal []RadarTimeInfo + // for _, v := range y { + // charData.Legend = append(charData.Legend, v.OldTitle) + var newVal []map[string]interface{} + for _, tv := range timeList { + startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 00:00:00", tv)) + endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 23:59:59", tv)) + if yVal, isOk := val.([]map[string]interface{}); isOk { + for _, mv := range yVal { + if xVal, isOk := mv[x.Field]; isOk { + var begTime int64 + var eldTime int64 + pageTime, _ := publicmethod.StringToInt64(xVal) + if publicmethod.GetIntLength(pageTime) >= 13 { + begTime = startTime * 1000 + eldTime = endTime * 1000 + } + if begTime <= pageTime && pageTime <= eldTime { + fmt.Printf("维度--3---》%v---》%v---》%v\n\n", tv, begTime <= pageTime, pageTime <= eldTime) + newVal = append(newVal, mv) + } + } + } + } + var timeData RadarTimeInfo + timeData.XName = tv + timeData.DataVal = newVal + jiSuanVal = append(jiSuanVal, timeData) + fmt.Printf("维度--1---》%v---》%v\n\n", tv, len(newVal)) + } + // jsonVal, _ := json.Marshal(jiSuanVal) + // fmt.Printf("维度-----》%v\n\n", string(jsonVal)) + charData.ParsingData(jiSuanVal, y) + // }y + // case "hour": + // case "minute": + // case "second": + // case "ymdhms": default: yearVal := publicmethod.UnixTimeToDay(tayTime, 16) yearValInt, _ := strconv.Atoi(yearVal) @@ -73,6 +212,23 @@ func (c *ChartInfo) RadarTimeDataAnaly(x XAxisInfo, y []YAxisInfo, val interface return } +func (r *RadarInfo) ParsingNewData(timeVal []RadarTimeInfo, y YAxisInfo) { + switch y.Method { + case 2: + r.AverageValueesTime(y, timeVal, y.Format) + case 3: + r.StatisticalQuantityesTime(y, timeVal, y.Format) + case 4: + r.RemoveDuplicateCountssTime(y, timeVal, y.Format) + case 5: + r.maxDataesTime(y, timeVal, y.Format) + case 6: + r.minDataesTime(y, timeVal, y.Format) + default: + r.sumDataesTime(y, timeVal, y.Format) + } +} + /* * @ 作者: 秦东 @@ -334,7 +490,8 @@ func (r *RadarInfo) sumDataesTime(y YAxisInfo, timeVal []RadarTimeInfo, format i if err == nil { isWrite = false if minVal <= sumVal { - r.Indicator[ri].Max = sumVal + + r.Indicator[ri].Max = sumVal + TianJiaCanshu(sumVal) } } } @@ -349,6 +506,21 @@ func (r *RadarInfo) sumDataesTime(y YAxisInfo, timeVal []RadarTimeInfo, format i r.DataList = append(r.DataList, serData) } +func TianJiaCanshu(val float64) float64 { + if val > 100000 { + return 100000 + } else if val > 10000 { + return 10000 + } else if val > 1000 { + return 1000 + } else if val > 100 { + return 100 + } else { + return 10 + } + return 0 +} + // 普通字段 func (c *ChartInfo) RadarDataAnaly(x XAxisInfo, y []YAxisInfo, val interface{}, chartType string, untis []customerform.MasterStruct) (charData RadarInfo) { var timeList []string //根据维度分组 diff --git a/overall/publicmethod/technique.go b/overall/publicmethod/technique.go index f3a273b..ac8ff67 100644 --- a/overall/publicmethod/technique.go +++ b/overall/publicmethod/technique.go @@ -2997,9 +2997,14 @@ func RemoveDuplicate[T GenericityVariable](ary []T) []T { // 获得月份最后一天,最后一秒 func GetDaysInMonth(nextYear int, nextMonth int) DateTimeTotimes { - firstDayOfNextMonth := time.Date(nextYear, time.Month(nextMonth), 1, 0, 0, 0, 0, time.UTC) + crueMonth := nextMonth + 1 + if crueMonth > 12 { + crueMonth = crueMonth - 12 + nextYear = nextYear + 1 + } + firstDayOfNextMonth := time.Date(nextYear, time.Month(crueMonth), 1, 0, 0, 0, 0, time.UTC) lastDayOfThisMonth := firstDayOfNextMonth.Add(-1 * time.Second) - //fmt.Println("本月最后一天时间:", lastDayOfThisMonth) + // fmt.Println("本月最后一天时间:", lastDayOfThisMonth) dates := lastDayOfThisMonth.Format("2006-01-02 15:04:05") var creTimeAll DateTimeTotimes creTimeAll.BaisStrToTime(dates)