|
@@ -0,0 +1,684 @@
|
|
|
+package data
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "errors"
|
|
|
+ "eta/eta_api/models/data_manage"
|
|
|
+ excelModel "eta/eta_api/models/data_manage/excel"
|
|
|
+ "eta/eta_api/models/data_manage/excel/request"
|
|
|
+ "eta/eta_api/models/system"
|
|
|
+ "eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
+ "math"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// AddBalanceExcelChart 添加平衡表图表
|
|
|
+func AddBalanceExcelChart(req request.AddBalanceTableChartReq, sysUser *system.Admin) (chartInfo *data_manage.ChartInfo, err error, errMsg string, isSendEmail bool) {
|
|
|
+ // 获取表格信息
|
|
|
+ excelInfo, err := excelModel.GetExcelInfoById(req.ExcelInfoId)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "找不到该EXCEL"
|
|
|
+ err = fmt.Errorf("找不到该EXCEL!%s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if excelInfo.Source != utils.BALANCE_TABLE {
|
|
|
+ errMsg = "EXCEL类型错误!"
|
|
|
+ err = fmt.Errorf("EXCEL类型错误!")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(req.ChartEdbInfoList) == 0 {
|
|
|
+ errMsg = "图表数据不能为空!"
|
|
|
+ err = fmt.Errorf("图表数据不能为空!%s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartEdbList := make([]*excelModel.AddChartEdbAndDataItem, 0)
|
|
|
+ for _, chartEdb := range req.ChartEdbInfoList {
|
|
|
+ excelEdb := new(excelModel.ExcelChartEdb)
|
|
|
+ excelEdb.EdbName = chartEdb.EdbName
|
|
|
+ randStr := utils.GetRandDigit(4)
|
|
|
+ excelEdb.EdbCode = `T` + time.Now().Format("060102150405") + "_" + randStr
|
|
|
+ excelEdb.ExcelInfoId = excelInfo.ExcelInfoId
|
|
|
+ excelEdb.DateSequence = chartEdb.DateSequenceStr
|
|
|
+ excelEdb.DataSequence = chartEdb.DataSequenceStr
|
|
|
+ excelEdb.SysUserId = sysUser.AdminId
|
|
|
+ excelEdb.SysUserRealName = sysUser.RealName
|
|
|
+ excelEdb.MaxData = chartEdb.MaxData
|
|
|
+ excelEdb.MinData = chartEdb.MinData
|
|
|
+ excelEdb.IsOrder = chartEdb.IsOrder
|
|
|
+ excelEdb.IsAxis = chartEdb.IsAxis
|
|
|
+ excelEdb.FromTag = chartEdb.FromTag
|
|
|
+ excelEdb.EdbInfoType = chartEdb.EdbInfoType
|
|
|
+ excelEdb.LeadValue = chartEdb.LeadValue
|
|
|
+ excelEdb.LeadUnit = chartEdb.LeadUnit
|
|
|
+ excelEdb.CreateTime = time.Now()
|
|
|
+ excelEdb.ModifyTime = time.Now()
|
|
|
+ var dateList []string
|
|
|
+ var dataList []float64
|
|
|
+ if excelInfo.BalanceType == 1 {
|
|
|
+ // 如果是静态表,则直接使用前端传输的数据落到数据库里
|
|
|
+ /*dateList, dataList, err, errMsg = utils.HandleEdbSequenceVal(chartEdb.DateSequenceVal, chartEdb.DataSequenceVal)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "时间序列或数据序列异常!"
|
|
|
+ err = fmt.Errorf("时间序列或数据序列异常!%s", err.Error())
|
|
|
+ return
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理日期列表和值列表
|
|
|
+ addItem := &excelModel.AddChartEdbAndDataItem{
|
|
|
+ ChartEdb: excelEdb,
|
|
|
+ DateList: dateList,
|
|
|
+ ValList: dataList,
|
|
|
+ }
|
|
|
+ chartEdbList = append(chartEdbList, addItem)
|
|
|
+ }
|
|
|
+ chartInfo, err, errMsg, isSendEmail = addBalanceExcelChart(req, sysUser.AdminId, sysUser.RealName)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "新增图表失败!"
|
|
|
+ err = fmt.Errorf("新增图表失败!%s, %s", errMsg, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ obj := new(excelModel.ExcelChartEdb)
|
|
|
+ err = obj.AddChartEdbAndData(chartEdbList, chartInfo)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "新增图表失败!"
|
|
|
+ err = fmt.Errorf("新增图表数据失败!%s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func addBalanceExcelChart(req request.AddBalanceTableChartReq, sysUserId int, sysUserRealName string) (chartInfo *data_manage.ChartInfo, err error, errMsg string, isSendEmail bool) {
|
|
|
+ isSendEmail = true // 默认错误的时候要发送邮件
|
|
|
+
|
|
|
+ req.ChartName = strings.Trim(req.ChartName, " ")
|
|
|
+ if req.ChartName == "" {
|
|
|
+ errMsg = "请填写图表名称!"
|
|
|
+ err = fmt.Errorf(errMsg)
|
|
|
+ isSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartType := req.ChartType
|
|
|
+ extraConfig := req.ExtraConfig
|
|
|
+ // todo 查找默认主题设置
|
|
|
+ // 季节性图表额外配置信息
|
|
|
+ var seasonExtraConfig string
|
|
|
+
|
|
|
+ if len(req.ChartEdbInfoList) <= 0 {
|
|
|
+ errMsg = "请选择指标!"
|
|
|
+ err = fmt.Errorf(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if chartType == 2 {
|
|
|
+ // 处理季节性图表横轴配置
|
|
|
+ {
|
|
|
+ if req.SeasonExtraConfig.XEndDate != "" {
|
|
|
+ if req.SeasonExtraConfig.XStartDate > req.SeasonExtraConfig.XEndDate && req.SeasonExtraConfig.JumpYear != 1 {
|
|
|
+ errMsg = "季节性图表配置信息异常:横坐标日期配置错误"
|
|
|
+ err = fmt.Errorf("季节性图表配置信息异常: 横坐标日期配置错误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
|
|
|
+ if tErr != nil {
|
|
|
+ errMsg = "季节性图表配置信息异常"
|
|
|
+ err = fmt.Errorf("季节性图表配置信息异常,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ seasonExtraConfig = string(seasonExtra)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 图表额外配置
|
|
|
+ extraConfig, err, errMsg = HandleExtraConfig(chartType, extraConfig)
|
|
|
+ if err != nil {
|
|
|
+ if errMsg == `` {
|
|
|
+ errMsg = "指标异常!"
|
|
|
+ }
|
|
|
+ err = fmt.Errorf("指标异常!Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断图表是否存在
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+
|
|
|
+ // 图表名称在不同图分类下不允许重复 需求调整时间:2022年11月07日09:47:07
|
|
|
+ condition += " AND chart_classify_id=0 "
|
|
|
+
|
|
|
+ condition += " AND chart_name=? AND source = ? "
|
|
|
+ pars = append(pars, req.ChartName, utils.CHART_SOURCE_BALANCE_EXCEL)
|
|
|
+
|
|
|
+ count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "判断图表名称是否存在失败"
|
|
|
+ err = fmt.Errorf("判断图表名称是否存在失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if count > 0 {
|
|
|
+ errMsg = "图表已存在,请重新填写"
|
|
|
+ err = fmt.Errorf("判断图表名称是否存在失败")
|
|
|
+ isSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // todo 判断是否是禁用的图表
|
|
|
+ // disableVal := data.CheckIsDisableChart(edbInfoIdArr)
|
|
|
+
|
|
|
+ chartInfo = new(data_manage.ChartInfo)
|
|
|
+ chartInfo.ChartName = req.ChartName
|
|
|
+ //chartInfo.EdbInfoIds = edbInfoIdStr
|
|
|
+ //chartInfo.ChartClassifyId = req.ChartClassifyId
|
|
|
+ chartInfo.SysUserId = sysUserId
|
|
|
+ chartInfo.SysUserRealName = sysUserRealName
|
|
|
+ chartInfo.CreateTime = time.Now()
|
|
|
+ chartInfo.ModifyTime = time.Now()
|
|
|
+ chartInfo.IsSetName = 0
|
|
|
+ timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
|
+ chartInfo.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
|
|
|
+
|
|
|
+ // todo 判断是否需要重新计算用户的start_date
|
|
|
+ chartInfo.DateType = 3
|
|
|
+
|
|
|
+ if chartType == 0 {
|
|
|
+ chartType = 1
|
|
|
+ }
|
|
|
+ chartInfo.ChartType = chartType
|
|
|
+
|
|
|
+ calendar := req.Calendar
|
|
|
+ if calendar == "" {
|
|
|
+ calendar = "公历"
|
|
|
+ }
|
|
|
+
|
|
|
+ chartInfo.Calendar = calendar
|
|
|
+ /* chartInfo.StartDate = req.StartDate
|
|
|
+ chartInfo.EndDate = req.EndDate
|
|
|
+ chartInfo.SeasonStartDate = req.StartDate
|
|
|
+ chartInfo.SeasonEndDate = req.EndDate*/
|
|
|
+ chartInfo.LeftMin = req.LeftMin
|
|
|
+ chartInfo.LeftMax = req.LeftMax
|
|
|
+ chartInfo.RightMin = req.RightMin
|
|
|
+ chartInfo.RightMax = req.RightMax
|
|
|
+ chartInfo.Right2Min = req.Right2Min
|
|
|
+ chartInfo.Right2Max = req.Right2Max
|
|
|
+ chartInfo.MinMaxSave = req.MinMaxSave
|
|
|
+ //chartInfo.Disabled = disableVal
|
|
|
+ //chartInfo.BarConfig = barChartConf
|
|
|
+ chartInfo.ExtraConfig = extraConfig
|
|
|
+ chartInfo.SeasonExtraConfig = seasonExtraConfig
|
|
|
+ //chartInfo.StartYear = req.StartYear
|
|
|
+ chartInfo.Source = utils.CHART_SOURCE_BALANCE_EXCEL
|
|
|
+ // chartInfo.ChartThemeId = req.ChartThemeId
|
|
|
+ chartInfo.SourcesFrom = req.SourcesFrom
|
|
|
+ /* chartInfo.Instructions = req.Instructions
|
|
|
+ chartInfo.MarkersLines = req.MarkersLines
|
|
|
+ chartInfo.MarkersAreas = req.MarkersAreas
|
|
|
+ chartInfo.Unit = req.Unit
|
|
|
+ chartInfo.UnitEn = req.UnitEn*/
|
|
|
+ /*newId, err := data_manage.AddChartInfo(chartInfo)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = `保存失败`
|
|
|
+ err = fmt.Errorf("保存失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartInfo.ChartInfoId = int(newId)*/
|
|
|
+
|
|
|
+ //添加es数据
|
|
|
+ //go EsAddOrEditChartInfo(chartInfo.ChartInfoId)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetBalanceExcelChartDetail(chartInfo *data_manage.ChartInfoView, mappingListTmp []*excelModel.ExcelChartEdb, sysUser *system.Admin, dataListMap map[int][]*data_manage.EdbDataList) (resp *data_manage.ChartInfoDetailResp, err error, errMsg string) {
|
|
|
+ // todo 图表权限处理
|
|
|
+ chartInfoId := chartInfo.ChartInfoId
|
|
|
+ resp = new(data_manage.ChartInfoDetailResp)
|
|
|
+
|
|
|
+ // 获取主题样式
|
|
|
+ chartTheme, err := GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "获取失败"
|
|
|
+ err = fmt.Errorf(" 获取主题信息失败 Err:%s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartInfo.ChartThemeStyle = chartTheme.Config
|
|
|
+ chartInfo.ChartThemeId = chartTheme.ChartThemeId
|
|
|
+
|
|
|
+ dateType := chartInfo.DateType
|
|
|
+ fmt.Println("dateType:", dateType)
|
|
|
+
|
|
|
+ chartType := chartInfo.ChartType
|
|
|
+ startDate := chartInfo.StartDate
|
|
|
+ endDate := chartInfo.EndDate
|
|
|
+ seasonStartDate := chartInfo.SeasonStartDate
|
|
|
+ seasonEndDate := chartInfo.SeasonEndDate
|
|
|
+ //startYear := chartInfo.StartYear
|
|
|
+
|
|
|
+ calendar := chartInfo.Calendar
|
|
|
+
|
|
|
+ if calendar == "" {
|
|
|
+ calendar = "公历"
|
|
|
+ }
|
|
|
+
|
|
|
+ mappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
|
|
|
+ //循环组装映射关系
|
|
|
+ for _, v := range mappingListTmp {
|
|
|
+ mapping := &data_manage.ChartEdbInfoMapping{
|
|
|
+ EdbInfoId: v.ExcelChartEdbId,
|
|
|
+ SourceName: "",
|
|
|
+ Source: 0,
|
|
|
+ SubSource: 0,
|
|
|
+ EdbCode: v.EdbCode,
|
|
|
+ EdbName: v.EdbName,
|
|
|
+ EdbAliasName: v.EdbName,
|
|
|
+ EdbNameEn: "",
|
|
|
+ EdbAliasNameEn: "",
|
|
|
+ EdbType: 0,
|
|
|
+ Frequency: "",
|
|
|
+ FrequencyEn: "",
|
|
|
+ Unit: "",
|
|
|
+ UnitEn: "",
|
|
|
+ StartDate: "",
|
|
|
+ EndDate: "",
|
|
|
+ ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
|
|
|
+ ChartEdbMappingId: v.ExcelChartEdbId,
|
|
|
+ ChartInfoId: chartInfoId,
|
|
|
+ MaxData: v.MaxData,
|
|
|
+ MinData: v.MinData,
|
|
|
+ IsOrder: v.IsOrder,
|
|
|
+ IsAxis: v.IsAxis,
|
|
|
+ //EdbInfoType: 0,
|
|
|
+ //EdbInfoCategoryType: 0,
|
|
|
+ LeadValue: v.LeadValue,
|
|
|
+ LeadUnit: v.LeadUnit,
|
|
|
+ LeadUnitEn: "",
|
|
|
+ ChartStyle: "",
|
|
|
+ ChartColor: "",
|
|
|
+ PredictChartColor: "",
|
|
|
+ ChartWidth: 0,
|
|
|
+ ChartType: 0,
|
|
|
+ LatestDate: "",
|
|
|
+ LatestValue: 0,
|
|
|
+ MoveLatestDate: "",
|
|
|
+ UniqueCode: "",
|
|
|
+ MinValue: 0,
|
|
|
+ MaxValue: 0,
|
|
|
+ DataList: nil,
|
|
|
+ IsNullData: false,
|
|
|
+ MappingSource: 0,
|
|
|
+ RegionType: "",
|
|
|
+ ClassifyId: 0,
|
|
|
+ IsConvert: 0,
|
|
|
+ ConvertType: 0,
|
|
|
+ ConvertValue: 0,
|
|
|
+ ConvertUnit: "",
|
|
|
+ ConvertEnUnit: "",
|
|
|
+ IsJoinPermission: 0,
|
|
|
+ HaveOperaAuth: true,
|
|
|
+ }
|
|
|
+ mappingList = append(mappingList, mapping)
|
|
|
+ }
|
|
|
+ if chartType == 2 {
|
|
|
+ startDate = seasonStartDate
|
|
|
+ endDate = seasonEndDate
|
|
|
+ if dateType <= 0 {
|
|
|
+ if startDate != "" {
|
|
|
+ dateType = 5
|
|
|
+ } else {
|
|
|
+ dateType = utils.DateTypeNYears
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if dateType <= 0 {
|
|
|
+ dateType = 3
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*yearMax := 0
|
|
|
+ if dateType == utils.DateTypeNYears {
|
|
|
+ for _, v := range mappingList {
|
|
|
+ if v.LatestDate != "" {
|
|
|
+ lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
|
|
|
+ if tErr != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if lastDateT.Year() > yearMax {
|
|
|
+ yearMax = lastDateT.Year()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)*/
|
|
|
+
|
|
|
+ if chartInfo.ChartType == 2 {
|
|
|
+ chartInfo.StartDate = startDate
|
|
|
+ chartInfo.EndDate = endDate
|
|
|
+ }
|
|
|
+ // 图表额外数据参数
|
|
|
+ extraConfigStr := chartInfo.ExtraConfig
|
|
|
+ // 柱方图的一些配置
|
|
|
+ var barConfig data_manage.BarChartInfoReq
|
|
|
+ if chartInfo != nil && chartInfo.ChartType == 7 {
|
|
|
+ if chartInfo.BarConfig == `` {
|
|
|
+ err = fmt.Errorf("柱方图未配置")
|
|
|
+ errMsg = "柱方图未配置"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("柱方图配置异常 json.Unmarshal Err:%s", err.Error())
|
|
|
+ errMsg = "柱方图配置异常"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ extraConfigStr = chartInfo.BarConfig
|
|
|
+ }
|
|
|
+ // 获取表格数据
|
|
|
+
|
|
|
+ excelChartInfoDataShow := new(ExcelChartInfoDataShow)
|
|
|
+ excelChartInfoDataShow.DataListMap = dataListMap
|
|
|
+
|
|
|
+ if chartInfo.HaveOperaAuth || true {
|
|
|
+ // 获取图表中的指标数据
|
|
|
+ edbList, xEdbIdValue, yDataList, dataResp, e, msg := GetChartEdbDataV2(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig, excelChartInfoDataShow)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取图表,指标数据失败,Err:%s", e.Error())
|
|
|
+ errMsg = msg
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 单位
|
|
|
+ if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
|
|
|
+ chartInfo.Unit = yDataList[0].Unit
|
|
|
+ chartInfo.UnitEn = yDataList[0].UnitEn
|
|
|
+ }
|
|
|
+ warnEdbList := make([]string, 0)
|
|
|
+ for _, v := range edbList {
|
|
|
+ if v.IsNullData {
|
|
|
+ warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(warnEdbList) > 0 {
|
|
|
+ chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
|
|
|
+ }
|
|
|
+ if chartInfoId > 0 && chartInfo != nil {
|
|
|
+ //判断是否加入我的图库
|
|
|
+ {
|
|
|
+ var myChartCondition string
|
|
|
+ var myChartPars []interface{}
|
|
|
+ myChartCondition += ` AND a.admin_id=? `
|
|
|
+ myChartPars = append(myChartPars, sysUser.AdminId)
|
|
|
+ myChartCondition += ` AND a.chart_info_id=? `
|
|
|
+ myChartPars = append(myChartPars, chartInfo.ChartInfoId)
|
|
|
+
|
|
|
+ myChartList, e := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ errMsg = "获取失败"
|
|
|
+ err = fmt.Errorf("获取我的图表信息失败,GetMyChartByCondition,Err:" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if myChartList != nil && len(myChartList) > 0 {
|
|
|
+ chartInfo.IsAdd = true
|
|
|
+ chartInfo.MyChartId = myChartList[0].MyChartId
|
|
|
+ chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断是否需要展示英文标识
|
|
|
+ chartInfo.IsEnChart = CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
|
|
|
+
|
|
|
+ // 图表的指标来源
|
|
|
+ sourceNameList, sourceNameEnList := GetEdbSourceByEdbInfoIdList(edbList)
|
|
|
+
|
|
|
+ chartInfo.ChartSource = strings.Join(sourceNameList, ",")
|
|
|
+ chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
|
|
|
+
|
|
|
+ // todo 指标权限
|
|
|
+ {
|
|
|
+ for _, item := range edbList {
|
|
|
+ // 数据权限
|
|
|
+ item.HaveOperaAuth = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resp.EdbInfoList = edbList
|
|
|
+ resp.XEdbIdValue = xEdbIdValue
|
|
|
+ resp.YDataList = yDataList
|
|
|
+ resp.DataResp = dataResp
|
|
|
+ } else {
|
|
|
+ resp.EdbInfoList = mappingList
|
|
|
+ }
|
|
|
+
|
|
|
+ //图表操作权限
|
|
|
+ chartInfo.IsEdit = CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
|
|
|
+ chartInfo.Button = data_manage.ChartViewButton{
|
|
|
+ IsEdit: chartInfo.IsEdit,
|
|
|
+ IsEnChart: chartInfo.IsEnChart,
|
|
|
+ IsAdd: chartInfo.IsAdd,
|
|
|
+ IsCopy: true,
|
|
|
+ IsSetName: chartInfo.IsSetName,
|
|
|
+ }
|
|
|
+
|
|
|
+ resp.ChartInfo = chartInfo
|
|
|
+ resp.BarChartInfo = barConfig
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetBalanceExcelEdbDataMapList 获取指标最后的基础数据
|
|
|
+func GetBalanceExcelEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping, seasonExtraConfig string, dataListMap map[int][]*data_manage.EdbDataList) (edbDataListMap map[int][]*data_manage.EdbDataList, edbList []*data_manage.ChartEdbInfoMapping, err error) {
|
|
|
+ // 指标对应的所有数据
|
|
|
+ edbDataListMap = make(map[int][]*data_manage.EdbDataList)
|
|
|
+
|
|
|
+ for _, v := range mappingList {
|
|
|
+ //fmt.Println("v:", v.EdbInfoId)
|
|
|
+ item := new(data_manage.ChartEdbInfoMapping)
|
|
|
+ item.EdbInfoId = v.EdbInfoId
|
|
|
+ item.SourceName = v.SourceName
|
|
|
+ item.Source = v.Source
|
|
|
+ item.EdbCode = v.EdbCode
|
|
|
+ item.EdbName = v.EdbName
|
|
|
+ item.EdbNameEn = v.EdbNameEn
|
|
|
+ item.Frequency = v.Frequency
|
|
|
+ item.EdbType = v.EdbType
|
|
|
+ item.FrequencyEn = GetFrequencyEn(v.Frequency)
|
|
|
+ if v.Unit != `无` {
|
|
|
+ item.Unit = v.Unit
|
|
|
+ }
|
|
|
+ item.UnitEn = v.UnitEn
|
|
|
+ item.StartDate = v.StartDate
|
|
|
+ item.EndDate = v.EndDate
|
|
|
+ item.ModifyTime = v.ModifyTime
|
|
|
+ item.EdbInfoCategoryType = v.EdbInfoCategoryType
|
|
|
+ item.PredictChartColor = v.PredictChartColor
|
|
|
+ item.ClassifyId = v.ClassifyId
|
|
|
+ if chartInfoId <= 0 {
|
|
|
+ item.IsAxis = 1
|
|
|
+ item.LeadValue = 0
|
|
|
+ item.LeadUnit = ""
|
|
|
+ item.ChartEdbMappingId = 0
|
|
|
+ item.ChartInfoId = 0
|
|
|
+ item.IsOrder = false
|
|
|
+ item.EdbInfoType = 1
|
|
|
+ item.ChartStyle = ""
|
|
|
+ item.ChartColor = ""
|
|
|
+ item.ChartWidth = 0
|
|
|
+ item.MaxData = v.MaxValue
|
|
|
+ item.MinData = v.MinValue
|
|
|
+ } else {
|
|
|
+ item.IsAxis = v.IsAxis
|
|
|
+ item.EdbInfoType = v.EdbInfoType
|
|
|
+ item.LeadValue = v.LeadValue
|
|
|
+ item.LeadUnit = v.LeadUnit
|
|
|
+ item.LeadUnitEn = GetLeadUnitEn(v.LeadUnit)
|
|
|
+ item.ChartEdbMappingId = v.ChartEdbMappingId
|
|
|
+ item.ChartInfoId = v.ChartInfoId
|
|
|
+ item.ChartStyle = v.ChartStyle
|
|
|
+ item.ChartColor = v.ChartColor
|
|
|
+ item.ChartWidth = v.ChartWidth
|
|
|
+ item.IsOrder = v.IsOrder
|
|
|
+ item.MaxData = v.MaxData
|
|
|
+ item.MinData = v.MinData
|
|
|
+ }
|
|
|
+ item.LatestValue = v.LatestValue
|
|
|
+ item.LatestDate = v.LatestDate
|
|
|
+ item.UniqueCode = v.UniqueCode
|
|
|
+ item.MoveLatestDate = v.LatestDate
|
|
|
+ item.EdbAliasName = v.EdbAliasName
|
|
|
+ item.IsConvert = v.IsConvert
|
|
|
+ item.ConvertType = v.ConvertType
|
|
|
+ item.ConvertValue = v.ConvertValue
|
|
|
+ item.ConvertUnit = v.ConvertUnit
|
|
|
+ item.ConvertEnUnit = v.ConvertEnUnit
|
|
|
+ item.IsJoinPermission = v.IsJoinPermission
|
|
|
+
|
|
|
+ var startDateReal string
|
|
|
+ var diffSeconds int64
|
|
|
+ if chartType == 2 { //季节性图
|
|
|
+ startDateReal = startDate
|
|
|
+ } else {
|
|
|
+ if v.EdbInfoType == 0 && v.LeadUnit != "" && v.LeadValue > 0 { //领先指标
|
|
|
+ var startTimeRealTemp time.Time
|
|
|
+ startDateParse, _ := time.Parse(utils.FormatDate, startDate)
|
|
|
+ switch v.LeadUnit {
|
|
|
+ case "天":
|
|
|
+ startTimeRealTemp = startDateParse.AddDate(0, 0, -v.LeadValue)
|
|
|
+ case "月":
|
|
|
+ startTimeRealTemp = startDateParse.AddDate(0, -v.LeadValue, 0)
|
|
|
+ case "季":
|
|
|
+ startTimeRealTemp = startDateParse.AddDate(0, -3*v.LeadValue, 0)
|
|
|
+ case "周":
|
|
|
+ startTimeRealTemp = startDateParse.AddDate(0, 0, -7*v.LeadValue)
|
|
|
+ case "年":
|
|
|
+ startTimeRealTemp = startDateParse.AddDate(-v.LeadValue, 0, 0)
|
|
|
+ }
|
|
|
+ if startTimeRealTemp.Before(startDateParse) {
|
|
|
+ startDateReal = startTimeRealTemp.Format(utils.FormatDate)
|
|
|
+ diffSeconds = (int64(startTimeRealTemp.UnixNano()) - int64(startDateParse.UnixNano())) / 1e6
|
|
|
+ } else {
|
|
|
+ startDateReal = startDate
|
|
|
+ diffSeconds = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ // 预测指标的开始日期也要偏移
|
|
|
+ {
|
|
|
+ day, tmpErr := utils.GetDaysBetween2Date(utils.FormatDate, startDate, startDateReal)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ moveLatestDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, item.MoveLatestDate, time.Local)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item.MoveLatestDate = moveLatestDateTime.AddDate(0, 0, day).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ startDateReal = startDate
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //fmt.Println("line 1011 chart:", v.Source, v.EdbInfoId, startDateReal, endDate)
|
|
|
+ calendarPreYear := 0
|
|
|
+ if calendar == "农历" {
|
|
|
+ newStartDateReal, err := time.Parse(utils.FormatDate, startDateReal)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("time.Parse:" + err.Error())
|
|
|
+ }
|
|
|
+ calendarPreYear = newStartDateReal.Year() - 1
|
|
|
+ newStartDateReal = newStartDateReal.AddDate(-1, 0, 0)
|
|
|
+ startDateReal = newStartDateReal.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ dataList := make([]*data_manage.EdbDataList, 0)
|
|
|
+ dataListTmp, ok := dataListMap[v.EdbInfoId]
|
|
|
+ if ok {
|
|
|
+ dataList = dataListTmp
|
|
|
+ } else {
|
|
|
+ err = errors.New(fmt.Sprint("获取失败,指标类型异常", v.EdbInfoId))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if v.IsConvert == 1 {
|
|
|
+ switch v.ConvertType {
|
|
|
+ case 1:
|
|
|
+ for i, data := range dataList {
|
|
|
+ dataList[i].Value = data.Value * v.ConvertValue
|
|
|
+ }
|
|
|
+ //item.MaxData = item.MaxData * v.ConvertValue
|
|
|
+ //item.MinData = item.MinData * v.ConvertValue
|
|
|
+ case 2:
|
|
|
+ for i, data := range dataList {
|
|
|
+ dataList[i].Value = data.Value / v.ConvertValue
|
|
|
+ }
|
|
|
+ //item.MaxData = item.MaxData / v.ConvertValue
|
|
|
+ //item.MinData = item.MinData / v.ConvertValue
|
|
|
+ case 3:
|
|
|
+ for i, data := range dataList {
|
|
|
+ if data.Value <= 0 {
|
|
|
+ err = errors.New("数据中含有负数或0,无法对数运算")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ dataList[i].Value = math.Log(data.Value) / math.Log(v.ConvertValue)
|
|
|
+ }
|
|
|
+ //item.MaxData = math.Log(item.MaxData) / math.Log(v.ConvertValue)
|
|
|
+ //item.MinData = math.Log(item.MinData) / math.Log(v.ConvertValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ edbDataListMap[v.EdbInfoId] = dataList
|
|
|
+
|
|
|
+ if diffSeconds != 0 && v.EdbInfoType == 0 {
|
|
|
+ dataListLen := len(dataList)
|
|
|
+ for i := 0; i < dataListLen; i++ {
|
|
|
+ dataList[i].DataTimestamp = dataList[i].DataTimestamp - diffSeconds
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if chartType == 2 {
|
|
|
+ latestDate, tmpErr := time.Parse(utils.FormatDate, v.LatestDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ //item.DataList = dataList
|
|
|
+ item.IsNullData = true
|
|
|
+ edbList = append(edbList, item)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if calendar == "农历" {
|
|
|
+ if len(dataList) <= 0 {
|
|
|
+ result := new(data_manage.EdbDataResult)
|
|
|
+ item.DataList = result
|
|
|
+ } else {
|
|
|
+ result, tmpErr := data_manage.AddCalculateQuarterV6(dataList)
|
|
|
+ if tmpErr != nil {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ quarterDataList, tErr := GetSeasonEdbInfoDataListByXDate(dataList, latestDate, seasonExtraConfig)
|
|
|
+ if tErr != nil {
|
|
|
+ err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item.DataList = quarterDataList
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if chartType == 7 || chartType == utils.CHART_TYPE_RADAR { //柱方图
|
|
|
+ //item.DataList = dataList
|
|
|
+ } else {
|
|
|
+ item.DataList = dataList
|
|
|
+ }
|
|
|
+ edbList = append(edbList, item)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|