应用集成平台服务端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
7.5 KiB

4 months ago
package customChartes
import (
"appPlatform/api/version1/customerform"
"appPlatform/overall/publicmethod"
"fmt"
"strconv"
)
/*
*
@ 作者: 秦东
@ 时间: 2025-07-22 16:16:33
@ 功能: 排行榜
*/
func (c *ChartInfo) barRaceChart(val interface{}, untis []customerform.MasterStruct, chartType string) (snedMap interface{}) {
for _, v := range c.XAxis {
fmt.Printf("\n\nc.X ===1==> %v =====> %v\n\n", v.Type, v)
switch v.Type {
case 3:
snedMap = c.TimeDataAnaly(v, c.YAxis, val, chartType)
default:
snedMap = c.BarRaceDataAnaly(v, c.YAxis, val, chartType, untis)
}
}
return
}
// 单一维度计算
func (c *ChartInfo) BarRaceDataAnaly(x XAxisInfo, y []YAxisInfo, val interface{}, chartType string, untis []customerform.MasterStruct) (charData BarRace) {
fmt.Printf("人员--->%v\n\n", val)
var timeList []string //根据维度分组
if yVal, isOk := val.([]map[string]interface{}); isOk {
fmt.Printf("人员--1->%v\n\n", yVal)
for _, mv := range yVal {
if xVal, isOk := mv[x.Field]; isOk {
fmt.Printf("人员--->%v\n\n", xVal)
pageTime := publicmethod.TypeToInterface(xVal)
if !publicmethod.IsInTrue[string](pageTime, timeList) {
timeList = append(timeList, pageTime)
}
}
}
}
var weiDu []PicChartInfo
for _, v := range timeList {
pickName := DimensionToChinaName(x.Field, v, untis)
charData.YAxisData = append(charData.YAxisData, pickName)
var weiduInfo PicChartInfo
weiduInfo.Name = v
weiduInfo.Value = pickName
weiDu = append(weiDu, weiduInfo)
}
charData.Max = len(weiDu)
charData.BarRaceAnalyRadarData(x.Field, weiDu, y, val)
return
}
/*
*
@ 作者: 秦东
@ 时间: 2025-07-22 11:22:34
@ 功能: 解析雷达数据
#xField x轴设定
w
# y Y轴设定
# val 查询到的值
#chartType 图标类型
1:求和2:平均值3:计数4:去重计数5:最大值6:最小值
当字段为时间类型时. 1:自动原始值2:整数3:保留1位小数4:保留2位小数5:百分比6:百分比1位小数7:百分比2位小数
*/
func (b *BarRace) BarRaceAnalyRadarData(xField string, x []PicChartInfo, y []YAxisInfo, val interface{}) {
for _, v := range y {
switch v.Method {
case 2:
b.AverageValuees(v, xField, x, val, v.Format)
case 3:
b.StatisticalQuantityes(v, xField, x, val, v.Format)
case 4:
b.RemoveDuplicateCountss(v, xField, x, val, v.Format)
case 5:
b.maxDataes(v, xField, x, val, v.Format)
case 6:
b.minDataes(v, xField, x, val, v.Format)
default:
b.sumDataes(v, xField, x, val, v.Format)
}
}
}
// 平均值
func (b *BarRace) AverageValuees(y YAxisInfo, xField string, x []PicChartInfo, val interface{}, format int) {
var serData DataInfo
serData.Name = y.OldTitle
for _, v := range x {
if yVal, isOk := val.([]map[string]interface{}); isOk {
var sumVal float64
jibuqi := 1
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
xValStr := publicmethod.TypeToInterface(xVal)
if xValStr == v.Name {
if yval, isOk := mv[y.Field]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(yval), 64)
if err == nil {
sumVal = sumVal + minVal
jibuqi++
}
}
}
}
}
if jibuqi > 0 {
sumValAvg := sumVal / float64(jibuqi)
jieguo := publicmethod.DataChuli(sumValAvg, format)
serData.Value = append(serData.Value, jieguo)
} else {
serData.Value = append(serData.Value, 0)
}
}
}
b.SeriesData = append(b.SeriesData, serData)
}
// 计数
func (b *BarRace) StatisticalQuantityes(y YAxisInfo, xField string, x []PicChartInfo, val interface{}, format int) {
var serData DataInfo
serData.Name = y.OldTitle
for _, v := range x {
if yVal, isOk := val.([]map[string]interface{}); isOk {
var sumVal []float64
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
xValStr := publicmethod.TypeToInterface(xVal)
if xValStr == v.Name {
if yval, isOk := mv[y.Field]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(yval), 64)
if err == nil {
sumVal = append(sumVal, minVal)
}
}
}
}
}
// jieguo := publicmethod.DataChuli(sumVal, format)
serData.Value = append(serData.Value, len(sumVal))
}
}
b.SeriesData = append(b.SeriesData, serData)
}
// 去重计数
func (b *BarRace) RemoveDuplicateCountss(y YAxisInfo, xField string, x []PicChartInfo, val interface{}, format int) {
var serData DataInfo
serData.Name = y.OldTitle
for _, v := range x {
if yVal, isOk := val.([]map[string]interface{}); isOk {
var sumVal []float64
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
xValStr := publicmethod.TypeToInterface(xVal)
if xValStr == v.Name {
if yval, isOk := mv[y.Field]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(yval), 64)
if err == nil {
if !publicmethod.IsInTrue[float64](minVal, sumVal) {
sumVal = append(sumVal, minVal)
}
}
}
}
}
}
// jieguo := publicmethod.DataChuli(sumVal, format)
serData.Value = append(serData.Value, len(sumVal))
}
}
b.SeriesData = append(b.SeriesData, serData)
}
// 最大值
func (b *BarRace) maxDataes(y YAxisInfo, xField string, x []PicChartInfo, val interface{}, format int) {
var serData DataInfo
serData.Name = y.OldTitle
for _, v := range x {
if yVal, isOk := val.([]map[string]interface{}); isOk {
var sumVal float64 = 0
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
xValStr := publicmethod.TypeToInterface(xVal)
if xValStr == v.Name {
if yval, isOk := mv[y.Field]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(yval), 64)
if err == nil {
if sumVal <= minVal {
sumVal = minVal
}
}
}
}
}
}
jieguo := publicmethod.DataChuli(sumVal, format)
serData.Value = append(serData.Value, jieguo)
}
}
b.SeriesData = append(b.SeriesData, serData)
}
// 最小值
func (b *BarRace) minDataes(y YAxisInfo, xField string, x []PicChartInfo, val interface{}, format int) {
var serData DataInfo
serData.Name = y.OldTitle
for _, v := range x {
if yVal, isOk := val.([]map[string]interface{}); isOk {
var sumVal float64 = 0
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
xValStr := publicmethod.TypeToInterface(xVal)
if xValStr == v.Name {
if yval, isOk := mv[y.Field]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(yval), 64)
if err == nil {
if sumVal >= minVal {
sumVal = minVal
}
}
}
}
}
}
jieguo := publicmethod.DataChuli(sumVal, format)
serData.Value = append(serData.Value, jieguo)
}
}
b.SeriesData = append(b.SeriesData, serData)
}
// 求和
func (b *BarRace) sumDataes(y YAxisInfo, xField string, x []PicChartInfo, val interface{}, format int) {
var serData DataInfo
serData.Name = y.OldTitle
for _, v := range x {
if yVal, isOk := val.([]map[string]interface{}); isOk {
var sumVal float64
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
xValStr := publicmethod.TypeToInterface(xVal)
if xValStr == v.Name {
if yval, isOk := mv[y.Field]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(yval), 64)
if err == nil {
sumVal = sumVal + minVal
}
}
}
}
}
jieguo := publicmethod.DataChuli(sumVal, format)
serData.Value = append(serData.Value, jieguo)
}
}
b.SeriesData = append(b.SeriesData, serData)
}