应用集成平台服务端
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.
 
 
 

810 lines
30 KiB

package customChartesing
import (
"appPlatform/api/version1/customerform"
"appPlatform/models/modelshr"
"appPlatform/models/modelssystempermission"
"appPlatform/overall"
"appPlatform/overall/publicmethod"
"fmt"
"strconv"
)
// 普通字段
func (c *ChartInfo) DataAnaly(x XAxisInfo, y []YAxisInfo, val interface{}, chartType string, untis []customerform.MasterStruct) (charData BarDataInfo) {
charData.XAxis.Types = "category"
charData.YAxis.Types = "value"
var timeList []string
var SunWdList []SunWd
var allMasterKey []string
if yVal, isOk := val.([]map[string]interface{}); isOk {
for _, mv := range yVal {
if yVal, isOk := mv[x.Field]; isOk {
pageTime := publicmethod.TypeToInterface(yVal)
if !publicmethod.IsInTrue[string](pageTime, timeList) {
timeList = append(timeList, pageTime)
if mastKey, isok := mv["masters_key"]; isok {
mastKeyStr := publicmethod.TypeToInterface(mastKey)
var SunWdInfo SunWd
SunWdInfo.TitleVal = pageTime
SunWdInfo.MasterKey = mastKeyStr
allMasterKey = append(allMasterKey, mastKeyStr)
SunWdList = append(SunWdList, SunWdInfo)
}
}
}
}
}
charData.XAxisData(x.Field, timeList, untis)
// charData.XAxis.Data = timeList
for _, v := range y {
var seriesInfo SeriesList
seriesInfo.Name = v.OldTitle
seriesInfo.Types = chartType
if !publicmethod.IsInTrue[string](v.OldTitle, charData.Legend.Data) {
charData.Legend.Data = append(charData.Legend.Data, v.OldTitle)
}
}
charData.AggregateCalculating(x.Field, y, val, timeList, chartType)
if len(SunWdList) > 0 {
charData.SunWuTimeAnaly(SunWdList, c.XSunAxis, c.YSunAxis, chartType, allMasterKey)
}
return
}
/*
*
@ 作者: 秦东
@ 时间: 2025-08-30 15:00:46
@ 功能: 计算子表图表数据
*/
func (b *BarDataInfo) SunWuTimeAnaly(sunWdList []SunWd, x, y []SunTableSetup, chartType string, allMasterKey []string) {
dlValMap := AllSunTableGroup(x, y, allMasterKey)
var timeList []string
for _, v := range sunWdList { //x轴分布
if !publicmethod.IsInTrue[string](v.TitleVal, timeList) {
timeList = append(timeList, v.TitleVal)
}
}
// for _, v := range sunWdList { //x轴分布
for _, dv := range dlValMap {
for _, yv := range y {
var seriesInfo SeriesList
titleStr := fmt.Sprintf("%v:%v-%v", dv.Title, dv.Label, yv.Title)
seriesInfo.Name = titleStr
seriesInfo.Types = chartType
if !publicmethod.IsInTrue[string](titleStr, b.Legend.Data) {
b.Legend.Data = append(b.Legend.Data, titleStr)
}
switch yv.Method {
case 2:
seriesInfo.AverageValuees(dv.Field, yv.Field, timeList, dv.List, yv.Format)
case 3:
seriesInfo.StatisticalQuantityes(dv.Field, yv.Field, timeList, dv.List, yv.Format)
case 4:
seriesInfo.RemoveDuplicateCountss(dv.Field, yv.Field, timeList, dv.List, yv.Format)
case 5:
seriesInfo.maxDataes(dv.Field, yv.Field, timeList, dv.List, yv.Format)
case 6:
seriesInfo.minDataes(dv.Field, yv.Field, timeList, dv.List, yv.Format)
default:
seriesInfo.sumDataes(dv.Field, yv.Field, timeList, dv.List, yv.Format)
}
b.Series = append(b.Series, seriesInfo)
}
}
// }
}
// 获取所有子表的度量
func AllSunTableGroup(x, y []SunTableSetup, allMasterKey []string) (duLianCanshu []WeiDuInfos) {
for _, v := range x {
var listData []map[string]interface{}
overall.CONSTANT_DB_CustomerForm.Table(v.TableKey).Where("`states` = 1 AND `masters_key` IN ?", allMasterKey).Find(&listData)
if len(listData) > 0 {
if mapAry, isOk := v.Options.([]interface{}); isOk {
for _, mv := range mapAry {
if mvMap, isOk := mv.(map[string]interface{}); isOk {
if mvVal, isOk := mvMap["value"]; isOk {
mvValStr := publicmethod.TypeToInterface(mvVal)
var WeiDuConter WeiDuInfos
WeiDuConter.Field = v.Field
WeiDuConter.DataVal = mvValStr
WeiDuConter.Title = v.OldTitle
if labelVal, isOk := mvMap["label"]; isOk {
WeiDuConter.Label = publicmethod.TypeToInterface(labelVal)
}
for _, lv := range listData {
if lvVal, isOk := lv[v.Field]; isOk {
lvValStr := publicmethod.TypeToInterface(lvVal)
if lvValStr == mvValStr {
WeiDuConter.List = append(WeiDuConter.List, lv)
}
}
}
duLianCanshu = append(duLianCanshu, WeiDuConter)
}
}
}
} else {
var fenlei []string
for _, lv := range listData {
if lvVal, isOk := lv[v.Field]; isOk {
lvValStr := publicmethod.TypeToInterface(lvVal)
if !publicmethod.IsInTrue[string](lvValStr, fenlei) {
fenlei = append(fenlei, lvValStr)
}
}
}
for _, fv := range fenlei {
var WeiDuConter WeiDuInfos
WeiDuConter.Field = v.Field
WeiDuConter.DataVal = fv
WeiDuConter.Title = v.OldTitle
WeiDuConter.Label = fv
for _, lv := range listData {
if lvVal, isOk := lv[v.Field]; isOk {
lvValStr := publicmethod.TypeToInterface(lvVal)
if lvValStr == fv {
WeiDuConter.List = append(WeiDuConter.List, lv)
}
}
}
duLianCanshu = append(duLianCanshu, WeiDuConter)
}
}
}
}
return
}
// x轴是否要转换中文
func (b *BarDataInfo) XAxisData(xField string, timeList []string, untis []customerform.MasterStruct) {
for _, v := range untis {
if v.Name == xField {
switch v.Type {
case "pickrole":
var roleName []string
if len(timeList) > 0 {
overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.SystemRole{}).Select("`name`").Where("`id` IN ?", timeList).Find(&roleName)
}
b.XAxis.Data = roleName
case "pickpost":
var roleName []string
if len(timeList) > 0 {
overall.CONSTANT_DB_HR.Model(&modelshr.Position{}).Select("`name`").Where("`id` IN ?", timeList).Find(&roleName)
}
b.XAxis.Data = roleName
case "deptOrg":
var roleName []string
if len(timeList) > 0 {
overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`name`").Where("`id` IN ?", timeList).Find(&roleName)
}
b.XAxis.Data = roleName
case "orgCentent":
var roleName []string
if len(timeList) > 0 {
overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`name`").Where("`id` IN ?", timeList).Find(&roleName)
}
b.XAxis.Data = roleName
case "owner":
var roleName []string
if len(timeList) > 0 {
overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`name`").Where("`key` IN ?", timeList).Find(&roleName)
}
b.XAxis.Data = roleName
case "founder":
var roleName []string
if len(timeList) > 0 {
overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`name`").Where("`key` IN ?", timeList).Find(&roleName)
}
b.XAxis.Data = roleName
case "expand-user":
var roleName []string
if len(timeList) > 0 {
overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`name`").Where("`key` IN ?", timeList).Find(&roleName)
}
b.XAxis.Data = roleName
case "checkbox":
if len(v.Options) > 0 {
var cbox []string
for _, tv := range timeList {
for _, ov := range v.Options {
if tv == ov.Value {
cbox = append(cbox, ov.Label)
}
}
}
b.XAxis.Data = cbox
} else {
b.XAxis.Data = timeList
}
case "radio":
if len(v.Options) > 0 {
var cbox []string
for _, tv := range timeList {
for _, ov := range v.Options {
if tv == ov.Value {
cbox = append(cbox, ov.Label)
}
}
}
b.XAxis.Data = cbox
} else {
b.XAxis.Data = timeList
}
default:
b.XAxis.Data = timeList
}
}
}
}
/*
*
@ 作者: 秦东
@ 时间: 2025-07-18 08:45:24
@ 功能: 聚合计算
# y Y轴设定
# val 查询到的值
#xField X轴字段
#chartType 图标类型
1:求和;2:平均值;3:计数;4:去重计数;5:最大值;6:最小值
当字段为时间类型时. 1:自动(原始值);2:整数;3:保留1位小数;4:保留2位小数;5:百分比;6:百分比1位小数;7:百分比2位小数;
*/
func (b *BarDataInfo) AggregateCalculating(x string, y []YAxisInfo, val interface{}, timeList []string, chartType string) {
for _, v := range y {
var seriesInfo SeriesList
seriesInfo.Name = v.OldTitle
seriesInfo.Types = chartType
switch v.Method {
case 2:
seriesInfo.AverageValuees(x, v.Field, timeList, val, v.Format)
case 3:
seriesInfo.StatisticalQuantityes(x, v.Field, timeList, val, v.Format)
case 4:
seriesInfo.RemoveDuplicateCountss(x, v.Field, timeList, val, v.Format)
case 5:
seriesInfo.maxDataes(x, v.Field, timeList, val, v.Format)
case 6:
seriesInfo.minDataes(x, v.Field, timeList, val, v.Format)
default:
seriesInfo.sumDataes(x, v.Field, timeList, val, v.Format)
}
if !publicmethod.IsInTrue[string](v.OldTitle, b.Legend.Data) {
b.Legend.Data = append(b.Legend.Data, v.OldTitle)
}
b.Series = append(b.Series, seriesInfo)
}
}
// 求平均值
func (s *SeriesList) AverageValuees(xField, yField string, xAry []string, val interface{}, format int) {
for _, v := range xAry {
var sumVal float64
if yVal, isOk := val.([]map[string]interface{}); isOk {
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
if v == publicmethod.TypeToInterface(xVal) {
if vVal, isOk := mv[yField]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(vVal), 64)
if err == nil {
sumVal = sumVal + minVal
}
}
}
}
}
sumValAvg := sumVal / float64(len(yVal))
jieguo := publicmethod.DataChuli(sumValAvg, format)
s.Data = append(s.Data, jieguo)
}
}
}
// 计数
func (s *SeriesList) StatisticalQuantityes(xField, yField string, xAry []string, val interface{}, format int) {
for _, v := range xAry {
var sumVal []float64
if yVal, isOk := val.([]map[string]interface{}); isOk {
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
if v == publicmethod.TypeToInterface(xVal) {
if vVal, isOk := mv[yField]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(vVal), 64)
if err == nil {
sumVal = append(sumVal, minVal)
}
}
}
}
}
}
// jieguo := publicmethod.DataChuli(sumVal, format)
s.Data = append(s.Data, len(sumVal))
}
}
// 去重计数
func (s *SeriesList) RemoveDuplicateCountss(xField, yField string, xAry []string, val interface{}, format int) {
for _, v := range xAry {
var sumVal []float64
if yVal, isOk := val.([]map[string]interface{}); isOk {
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
if v == publicmethod.TypeToInterface(xVal) {
if vVal, isOk := mv[yField]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(vVal), 64)
if err == nil {
if !publicmethod.IsInTrue[float64](minVal, sumVal) {
sumVal = append(sumVal, minVal)
}
}
}
}
}
}
}
// jieguo := publicmethod.DataChuli(sumVal, format)
s.Data = append(s.Data, len(sumVal))
}
}
// 求最大值
func (s *SeriesList) maxDataes(xField, yField string, xAry []string, val interface{}, format int) {
for _, v := range xAry {
var sumVal float64 = 0
if yVal, isOk := val.([]map[string]interface{}); isOk {
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
if v == publicmethod.TypeToInterface(xVal) {
if vVal, isOk := mv[yField]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(vVal), 64)
if err == nil {
if sumVal <= minVal {
sumVal = minVal
}
}
}
}
}
}
}
jieguo := publicmethod.DataChuli(sumVal, format)
s.Data = append(s.Data, jieguo)
}
}
// 求最小值
func (s *SeriesList) minDataes(xField, yField string, xAry []string, val interface{}, format int) {
for _, v := range xAry {
var sumVal float64 = 1
if yVal, isOk := val.([]map[string]interface{}); isOk {
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
if v == publicmethod.TypeToInterface(xVal) {
if vVal, isOk := mv[yField]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(vVal), 64)
if err == nil {
if sumVal >= minVal {
sumVal = minVal
}
}
}
}
}
}
}
jieguo := publicmethod.DataChuli(sumVal, format)
s.Data = append(s.Data, jieguo)
}
}
// 求和
/*
xField x轴字段
yField y轴字段
xAry x轴值
val 查询出来的所有值
format 取值方式
*/
func (s *SeriesList) sumDataes(xField, yField string, xAry []string, val interface{}, format int) {
for _, v := range xAry {
var sumVal float64
if yVal, isOk := val.([]map[string]interface{}); isOk {
for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk {
if v == publicmethod.TypeToInterface(xVal) {
if vVal, isOk := mv[yField]; isOk {
minVal, err := strconv.ParseFloat(publicmethod.TypeToInterface(vVal), 64)
if err == nil {
sumVal = sumVal + minVal
}
}
}
}
}
}
jieguo := publicmethod.DataChuli(sumVal, format)
s.Data = append(s.Data, jieguo)
}
}
// 计算柱形子表数据
// 计算数值
// 1:求和;2:平均值;3:计数;4:去重计数;5:最大值;6:最小值
// 当字段为时间类型时. 1:自动(原始值);2:整数;3:保留1位小数;4:保留2位小数;5:百分比;6:百分比1位小数;7:百分比2位小数;
/*
val 获取到的数值
x 纬度
y 量化
chartType 图表类型
types 时间类型
types 时间类型
*/
func (b *BarDataInfo) SunDayCalculateValues(val interface{}, x, y []SunTableSetup, chartType string, types string, timeAry []string) {
// fmt.Printf("子表数据---->%v\n\n\n", val)
var dataMastKey []string
if valMapAry, isOk := val.([]map[string]interface{}); isOk {
for _, v := range valMapAry {
if mastKey, isok := v["masters_key"]; isok {
key := publicmethod.TypeToInterface(mastKey)
if !publicmethod.IsInTrue[string](key, dataMastKey) {
dataMastKey = append(dataMastKey, key)
}
}
}
}
// fmt.Printf("子表数据--dataMastKey-->%v\n\n\n", dataMastKey)
if len(dataMastKey) > 0 {
var SunTabelName []string
var weiduDataMap []EveryOneSunTableData
for _, v := range x {
if !publicmethod.IsInTrue[string](v.TableKey, SunTabelName) {
SunTabelName = append(SunTabelName, v.TableKey)
weiduDataMap = append(weiduDataMap, SunTableDataList(v, dataMastKey))
}
}
// jsonm, _ := json.Marshal(weiduDataMap)
// fmt.Printf("子表数据--dataMastKey-->%v\n-->%v\n\n", SunTabelName, string(jsonm))
if len(weiduDataMap) > 0 {
for _, v := range weiduDataMap {
for _, lv := range v.List {
for _, yv := range y {
var seriesInfo SeriesList
titleStr := fmt.Sprintf("%v:%v-%v", lv.Title, lv.Label, yv.Title)
seriesInfo.Name = titleStr
seriesInfo.Types = chartType
if !publicmethod.IsInTrue[string](titleStr, b.Legend.Data) {
b.Legend.Data = append(b.Legend.Data, titleStr)
}
fmt.Printf("子表数据--yv.Method-->%v\n\n\n", yv.Method)
switch yv.Method {
case 2:
seriesInfo.SunSumDataAverage(lv.Field, yv.Field, types, lv.List, yv.Format, timeAry)
case 3:
seriesInfo.SunSumDataStatisticalQuantity(lv.Field, yv.Field, types, lv.List, yv.Format, timeAry)
case 4:
seriesInfo.SunSumDataRemoveDuplicate(lv.Field, yv.Field, types, lv.List, yv.Format, timeAry)
case 5:
seriesInfo.SunSumDataMax(lv.Field, yv.Field, types, lv.List, yv.Format, timeAry)
case 6:
seriesInfo.SunSumDataMin(lv.Field, yv.Field, types, lv.List, yv.Format, timeAry)
default:
seriesInfo.SunSumData(lv.Field, yv.Field, types, lv.List, yv.Format, timeAry)
}
b.Series = append(b.Series, seriesInfo)
// seriesInfo.DuLiangAnalySun(lv, yv, types, timeAry)
// fmt.Printf("seriesInfo----->%v\n\n\n", seriesInfo)
}
}
}
}
}
}
func (s *SeriesList) SunSumDataMin(xField, yField, types string, val interface{}, format int, timeAry []string) {
var monthAry []interface{}
for _, v := range timeAry {
switch types {
case "year":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01-01 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-12-31 23:59:59", v))
monthAry = append(monthAry, s.QuMinData(startTime, endTime, val, xField, yField, format))
case "month":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01 00:00:00", v))
yearValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 16))
monthValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 17))
endTime := publicmethod.GetDaysInMonth(yearValInt, monthValInt)
monthAry = append(monthAry, s.QuMinData(startTime, endTime.AllTime, val, xField, yField, format))
case "day":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 23:59:59", v))
monthAry = append(monthAry, s.QuMinData(startTime, endTime, val, xField, yField, format))
case "hour":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuMinData(startTime, endTime, val, xField, yField, format))
case "minute":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59", v))
monthAry = append(monthAry, s.QuMinData(startTime, endTime, val, xField, yField, format))
case "second":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuMinData(startTime, endTime, val, xField, yField, format))
default:
}
}
s.Data = monthAry
}
func (s *SeriesList) SunSumDataMax(xField, yField, types string, val interface{}, format int, timeAry []string) {
var monthAry []interface{}
for _, v := range timeAry {
switch types {
case "year":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01-01 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-12-31 23:59:59", v))
monthAry = append(monthAry, s.QuMaxData(startTime, endTime, val, xField, yField, format))
case "month":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01 00:00:00", v))
yearValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 16))
monthValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 17))
endTime := publicmethod.GetDaysInMonth(yearValInt, monthValInt)
monthAry = append(monthAry, s.QuMaxData(startTime, endTime.AllTime, val, xField, yField, format))
case "day":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 23:59:59", v))
monthAry = append(monthAry, s.QuMaxData(startTime, endTime, val, xField, yField, format))
case "hour":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuMaxData(startTime, endTime, val, xField, yField, format))
case "minute":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59", v))
monthAry = append(monthAry, s.QuMaxData(startTime, endTime, val, xField, yField, format))
case "second":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuMaxData(startTime, endTime, val, xField, yField, format))
default:
}
}
s.Data = monthAry
}
func (s *SeriesList) SunSumDataRemoveDuplicate(xField, yField, types string, val interface{}, format int, timeAry []string) {
var monthAry []interface{}
for _, v := range timeAry {
switch types {
case "year":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01-01 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-12-31 23:59:59", v))
monthAry = append(monthAry, s.QuChongData(startTime, endTime, val, xField, yField, format))
case "month":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01 00:00:00", v))
yearValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 16))
monthValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 17))
endTime := publicmethod.GetDaysInMonth(yearValInt, monthValInt)
monthAry = append(monthAry, s.QuChongData(startTime, endTime.AllTime, val, xField, yField, format))
case "day":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 23:59:59", v))
monthAry = append(monthAry, s.QuChongData(startTime, endTime, val, xField, yField, format))
case "hour":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuChongData(startTime, endTime, val, xField, yField, format))
case "minute":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59", v))
monthAry = append(monthAry, s.QuChongData(startTime, endTime, val, xField, yField, format))
case "second":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuChongData(startTime, endTime, val, xField, yField, format))
default:
}
}
s.Data = monthAry
}
func (s *SeriesList) SunSumDataStatisticalQuantity(xField, yField, types string, val interface{}, format int, timeAry []string) {
var monthAry []interface{}
for _, v := range timeAry {
switch types {
case "year":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01-01 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-12-31 23:59:59", v))
monthAry = append(monthAry, s.QuJishuData(startTime, endTime, val, xField, yField, format))
case "month":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01 00:00:00", v))
yearValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 16))
monthValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 17))
endTime := publicmethod.GetDaysInMonth(yearValInt, monthValInt)
monthAry = append(monthAry, s.QuJishuData(startTime, endTime.AllTime, val, xField, yField, format))
case "day":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 23:59:59", v))
monthAry = append(monthAry, s.QuJishuData(startTime, endTime, val, xField, yField, format))
case "hour":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuJishuData(startTime, endTime, val, xField, yField, format))
case "minute":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59", v))
monthAry = append(monthAry, s.QuJishuData(startTime, endTime, val, xField, yField, format))
case "second":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuJishuData(startTime, endTime, val, xField, yField, format))
default:
}
}
s.Data = monthAry
}
func (s *SeriesList) SunSumDataAverage(xField, yField, types string, val interface{}, format int, timeAry []string) {
var monthAry []interface{}
for _, v := range timeAry {
switch types {
case "year":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01-01 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-12-31 23:59:59", v))
monthAry = append(monthAry, s.QuPingjunSumData(startTime, endTime, val, xField, yField, format))
case "month":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01 00:00:00", v))
yearValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 16))
monthValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 17))
endTime := publicmethod.GetDaysInMonth(yearValInt, monthValInt)
monthAry = append(monthAry, s.QuPingjunSumData(startTime, endTime.AllTime, val, xField, yField, format))
case "day":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 23:59:59", v))
monthAry = append(monthAry, s.QuPingjunSumData(startTime, endTime, val, xField, yField, format))
case "hour":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuPingjunSumData(startTime, endTime, val, xField, yField, format))
case "minute":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59", v))
monthAry = append(monthAry, s.QuPingjunSumData(startTime, endTime, val, xField, yField, format))
case "second":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuPingjunSumData(startTime, endTime, val, xField, yField, format))
default:
}
}
s.Data = monthAry
}
// func (s *SeriesList) SunSumData(mastreVal interface{}, xField, yField, types string, val interface{}, format int, timeAry []string) {
func (s *SeriesList) SunSumData(xField, yField, types string, val interface{}, format int, timeAry []string) {
// jsonVal, _ := json.Marshal(val)
// fmt.Printf("jisuan----->%v\n\n\n----->%v\n\n\n----->%v\n\n\n----->%v\n\n\n", xField, yField, types, string(jsonVal))
var monthAry []interface{}
for _, v := range timeAry {
switch types {
case "year":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01-01 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-12-31 23:59:59", v))
monthAry = append(monthAry, s.QuSumData(startTime, endTime, val, xField, yField, format))
case "month":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01 00:00:00", v))
yearValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 16))
monthValInt, _ := strconv.Atoi(publicmethod.UnixTimeToDay(startTime, 17))
endTime := publicmethod.GetDaysInMonth(yearValInt, monthValInt)
monthAry = append(monthAry, s.QuSumData(startTime, endTime.AllTime, val, xField, yField, format))
case "day":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 00:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 23:59:59", v))
monthAry = append(monthAry, s.QuSumData(startTime, endTime, val, xField, yField, format))
// fmt.Printf("计算一天的数据:\n\n%v 到 %v 结果:%v\n\n", startTime, endTime, monthAry)
case "hour":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuSumData(startTime, endTime, val, xField, yField, format))
case "minute":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59", v))
monthAry = append(monthAry, s.QuSumData(startTime, endTime, val, xField, yField, format))
case "second":
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:00:00", v))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v:59:59", v))
monthAry = append(monthAry, s.QuSumData(startTime, endTime, val, xField, yField, format))
default:
}
}
s.Data = monthAry
}
/*
*
@ 作者: 秦东
@ 时间: 2025-08-29 16:51:03
@ 功能: 获取不同子表得数据
*/
func SunTableDataList(table SunTableSetup, mastKey []string) (list EveryOneSunTableData) {
list.TableName = table.TableKey
if len(mastKey) > 0 {
var listData []map[string]interface{}
overall.CONSTANT_DB_CustomerForm.Table(table.TableKey).Where("`states` = 1 AND `masters_key` IN ?", mastKey).Find(&listData)
if len(listData) > 0 {
if mapAry, isOk := table.Options.([]interface{}); isOk {
for _, mv := range mapAry {
if mvMap, isOk := mv.(map[string]interface{}); isOk {
if mvVal, isOk := mvMap["value"]; isOk {
mvValStr := publicmethod.TypeToInterface(mvVal)
var WeiDuConter WeiDuInfos
WeiDuConter.Field = table.Field
WeiDuConter.DataVal = mvValStr
WeiDuConter.Title = table.OldTitle
if labelVal, isOk := mvMap["label"]; isOk {
WeiDuConter.Label = publicmethod.TypeToInterface(labelVal)
}
for _, lv := range listData {
if lvVal, isOk := lv[table.Field]; isOk {
lvValStr := publicmethod.TypeToInterface(lvVal)
if lvValStr == mvValStr {
WeiDuConter.List = append(WeiDuConter.List, lv)
}
}
}
list.List = append(list.List, WeiDuConter)
}
}
}
} else {
var fenlei []string
for _, v := range listData {
if lvVal, isOk := v[table.Field]; isOk {
lvValStr := publicmethod.TypeToInterface(lvVal)
if !publicmethod.IsInTrue[string](lvValStr, fenlei) {
fenlei = append(fenlei, lvValStr)
}
}
}
for _, v := range fenlei {
var WeiDuConter WeiDuInfos
WeiDuConter.Field = table.Field
WeiDuConter.DataVal = v
WeiDuConter.Title = table.OldTitle
WeiDuConter.Label = v
for _, lv := range listData {
if lvVal, isOk := lv[table.Field]; isOk {
lvValStr := publicmethod.TypeToInterface(lvVal)
if lvValStr == v {
WeiDuConter.List = append(WeiDuConter.List, lv)
}
}
}
list.List = append(list.List, WeiDuConter)
}
}
}
}
return
}