123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783 |
- package data
- import (
- "encoding/json"
- "errors"
- "eta/eta_mobile/models/data_manage"
- excelModel "eta/eta_mobile/models/data_manage/excel"
- "eta/eta_mobile/models/system"
- "eta/eta_mobile/services/data/data_manage_permission"
- "eta/eta_mobile/utils"
- "fmt"
- "math"
- "sort"
- "strings"
- "time"
- )
- 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) {
- // 图表数据权限
- {
- // 已授权分类id
- permissionChartIdList, permissionClassifyIdList, e := data_manage_permission.GetUserChartAndClassifyPermissionList(sysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
- if e != nil {
- errMsg = "获取失败"
- err = fmt.Errorf("获取已授权分类id数据失败,Err:" + err.Error())
- return
- }
- chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, 0, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- }
- chartInfoId := chartInfo.ChartInfoId
- resp = new(data_manage.ChartInfoDetailResp)
- // 获取主题样式
- chartTheme, err := GetChartThemeConfig(chartInfo.ChartThemeId, 1, 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, err := TransferChartEdbToEdbMappingFormat(chartInfoId, chartType, mappingListTmp, dataListMap)
- if err != nil {
- return
- }
- 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 {
- errMsg = "获取失败"
- err = fmt.Errorf("获取图表日期信息失败,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 {
- // 获取图表中的指标数据
- 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
- }
- // todo 平衡表图表操作权限平衡表表格的操作权限保持一致,前端未用到该按钮权限,故不处理
- chartInfo.IsEdit, _ = GetBalanceExcelInfoOpButtonByChartInfoId(sysUser.AdminId, chartInfo.ChartInfoId, 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 = 1
- 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
- if len(mappingList) > 1 {
- item.IsAxis = v.IsAxis
- }
- } 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, e := time.Parse(utils.FormatDate, startDateReal)
- if e != nil {
- err = fmt.Errorf("时间解析 time.Parse(%s, %s) error: %v", utils.FormatDate, startDateReal, e)
- return
- }
- 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
- // 对dataList 根据dataTimestamp 进行排序
- sort.Slice(dataList, func(i, j int) bool {
- return dataList[i].DataTimestamp < dataList[j].DataTimestamp
- })
- } else {
- //err = errors.New(fmt.Sprint("获取失败,指标类型异常", v.EdbInfoId))
- utils.FileLog.Info(fmt.Sprintf("获取失败,指标数据异常 %d", v.EdbInfoId))
- }
- 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 && item.IsAxis == 1 {
- 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 == 2 && item.IsAxis == 0 {
- // 右轴数据处理
- xStartDate := "01-01"
- jumpYear := 0
- var seasonExtra data_manage.SeasonExtraItem
- if seasonExtraConfig != "" {
- err = json.Unmarshal([]byte(seasonExtraConfig), &seasonExtra)
- if err != nil {
- return
- }
- }
- if seasonExtra.XStartDate != "" {
- xStartDate = seasonExtra.XStartDate
- jumpYear = seasonExtra.JumpYear
- }
- length := len(dataList)
- if length == 0 {
- return
- }
- latestDate, tmpErr := time.Parse(utils.FormatDate, v.LatestDate)
- if tmpErr != nil {
- //item.DataList = dataList
- item.IsNullData = true
- edbList = append(edbList, item)
- continue
- err = errors.New(fmt.Sprint("获取最后实际数据的日期失败,Err:" + tmpErr.Error() + ";LatestDate:" + v.LatestDate))
- return
- }
- var rightAxisDate time.Time
- if jumpYear == 1 {
- latestDate = latestDate.AddDate(-1, 0, 0)
- latestDateStr := fmt.Sprintf("%d-%s", latestDate.Year(),xStartDate)
- rightAxisDate, err = time.Parse(utils.FormatDate, latestDateStr)
- if err != nil {
- return
- }
- }
- newDataList := make([]*data_manage.EdbDataList, 0)
- for _, v := range dataList {
- dataTime, e := time.Parse(utils.FormatDate, v.DataTime)
- if e != nil {
- err = errors.New("季节性图处理右轴指标数据转换日期失败,Err:" + e.Error())
- return
- }
- if dataTime.Equal(rightAxisDate) || dataTime.After(rightAxisDate) {
- newDataList = append(newDataList, v)
- }
- }
- item.DataList = newDataList
- } else if chartType == 7 || chartType == utils.CHART_TYPE_RADAR { //柱方图
- //item.DataList = dataList
- } else {
- item.DataList = dataList
- }
- edbList = append(edbList, item)
- }
- return
- }
- func CheckBalanceChartCacheAndPermission(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
- //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
- adminId := sysUser.AdminId
- // todo 图表数据权限
- // 已授权分类id
- permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(adminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
- if err != nil {
- errMsg = "获取已授权分类id数据失败,Err:" + err.Error()
- return
- }
- defer func() {
- if isOk {
- // 图表权限校验
- {
- resp.ChartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, 0, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
- //图表操作权限
- chartInfo.IsEdit = CheckOpChartPermission(sysUser, chartInfo.SysUserId, resp.ChartInfo.HaveOperaAuth)
- chartInfo.Button = data_manage.ChartViewButton{
- IsEdit: chartInfo.IsEdit,
- IsEnChart: chartInfo.IsEnChart,
- IsAdd: chartInfo.IsAdd,
- IsCopy: true,
- IsSetName: chartInfo.IsSetName,
- }
- //if !resp.ChartInfo.HaveOperaAuth {
- // for _, v := range resp.EdbInfoList {
- // v.DataList = nil
- // }
- // resp.DataResp = nil
- // resp.XEdbIdValue = []int{}
- // resp.YDataList = []data_manage.YData{}
- //}
- }
- // todo 是否需要返回平衡表指标权限即判断平衡表的表格数据权限
- {
- // 查询图表关联的表格ID
- excelInfo, e := excelModel.GetExcelInfoByChartInfoId(chartInfo.ChartInfoId)
- if e != nil {
- errMsg = "获取图表关联的表格ID失败,Err:" + e.Error()
- err = e
- return
- }
- checkExcelInfo := excelInfo
- if excelInfo.Source == utils.BALANCE_TABLE {
- checkExcelInfoId := excelInfo.ExcelInfoId
- if excelInfo.BalanceType == 1 {
- checkExcelInfoId = excelInfo.RelExcelInfoId
- } else {
- if excelInfo.ParentId > 0 {
- checkExcelInfoId = excelInfo.ParentId
- }
- }
- if checkExcelInfoId != excelInfo.ExcelInfoId {
- checkExcelInfo, err = excelModel.GetExcelInfoById(checkExcelInfoId)
- if err != nil {
- errMsg = "获取平衡表格信息失败"
- err = errors.New("获取平衡表格信息失败,Err:" + err.Error())
- return
- }
- }
- }
- haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, adminId)
- if e != nil {
- errMsg = "获取平衡表格数据权限失败"
- err = errors.New("获取表格权限信息失败,Err" + e.Error())
- return
- }
- // 数据权限
- for _, v := range resp.EdbInfoList {
- v.HaveOperaAuth = haveOperaAuth
- }
- }
- }
- }()
- key := GetChartInfoDataKey(chartInfo.ChartInfoId)
- if utils.Re == nil && isCache {
- if utils.Re == nil && utils.Rc.IsExist(key) {
- if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
- err := json.Unmarshal(redisData, &resp)
- if err != nil || resp == nil {
- return
- }
- // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
- var myCond string
- var myPars []interface{}
- myCond += ` AND a.admin_id=? `
- myPars = append(myPars, adminId)
- myCond += ` AND a.chart_info_id=? `
- myPars = append(myPars, chartInfo.ChartInfoId)
- myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- msg = "获取失败"
- errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
- return
- }
- resp.ChartInfo.IsAdd = false
- resp.ChartInfo.MyChartId = 0
- resp.ChartInfo.MyChartClassifyId = ""
- if myList != nil && len(myList) > 0 {
- resp.ChartInfo.IsAdd = true
- resp.ChartInfo.MyChartId = myList[0].MyChartId
- resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
- }
- //判断是否加入我的图库
- {
- var myChartCondition string
- var myChartPars []interface{}
- myChartCondition += ` AND a.admin_id=? `
- myChartPars = append(myChartPars, adminId)
- myChartCondition += ` AND a.chart_info_id=? `
- myChartPars = append(myChartPars, chartInfo.ChartInfoId)
- myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- msg = "获取失败"
- errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
- return
- }
- if myChartList != nil && len(myChartList) > 0 {
- chartInfo.IsAdd = true
- chartInfo.MyChartId = myChartList[0].MyChartId
- chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
- }
- }
- isOk = true
- fmt.Println("source redis")
- return
- }
- }
- }
- return
- }
- func getBalanceDataListStartDateAndValue(dataList []*data_manage.EdbDataList) (startDate, endDate string, startVal, endVal, maxVal, minVal float64) {
- if len(dataList) == 0 {
- return
- }
- startDate = dataList[0].DataTime
- startVal = dataList[0].Value
- maxVal = dataList[0].Value
- minVal = dataList[0].Value
- endDate = dataList[len(dataList)-1].DataTime
- endVal = dataList[len(dataList)-1].Value
- for _, v := range dataList {
- if v.DataTime < startDate {
- startDate = v.DataTime
- startVal = v.Value
- }
- if v.DataTime > endDate {
- endDate = v.DataTime
- endVal = v.Value
- }
- if v.Value > maxVal {
- maxVal = v.Value
- }
- if v.Value < minVal {
- minVal = v.Value
- }
- }
- return
- }
- func TransferChartEdbToEdbMappingFormat(chartInfoId, chartType int, mappingListTmp []*excelModel.ExcelChartEdb, dataListMap map[int][]*data_manage.EdbDataList) (mappingList []*data_manage.ChartEdbInfoMapping, err error) {
- mappingList = make([]*data_manage.ChartEdbInfoMapping, 0)
- //循环组装映射关系
- for _, v := range mappingListTmp {
- dataList := make([]*data_manage.EdbDataList, 0)
- dataListTmp, ok := dataListMap[v.ExcelChartEdbId]
- if ok {
- dataList = dataListTmp
- } else {
- //err = errors.New(fmt.Sprint("获取失败,指标类型异常", v.ExcelChartEdbId))
- utils.FileLog.Info(fmt.Sprintf("获取失败,指标数据异常 %d", v.ExcelChartEdbId))
- }
- startDateStr, endDateStr, _, endVal, maxValue, minValue := getBalanceDataListStartDateAndValue(dataList)
- mapping := &data_manage.ChartEdbInfoMapping{
- EdbInfoId: v.ExcelChartEdbId,
- SourceName: "平衡表",
- Source: 0,
- SubSource: 0,
- EdbCode: v.EdbCode,
- EdbName: v.EdbName,
- EdbAliasName: v.EdbName,
- EdbNameEn: v.EdbNameEn,
- EdbAliasNameEn: "",
- EdbType: 0,
- Frequency: "",
- FrequencyEn: "",
- Unit: v.Unit,
- UnitEn: v.UnitEn,
- StartDate: startDateStr,
- EndDate: endDateStr,
- ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- ChartEdbMappingId: v.ExcelChartEdbId,
- ChartInfoId: chartInfoId,
- MaxData: v.MaxData,
- MinData: v.MinData,
- IsOrder: v.IsOrder,
- IsAxis: v.IsAxis,
- EdbInfoType: v.EdbInfoType,
- //EdbInfoCategoryType: 0,
- LeadValue: v.LeadValue,
- LeadUnit: v.LeadUnit,
- LeadUnitEn: "",
- ChartStyle: "",
- ChartColor: "",
- PredictChartColor: "",
- ChartWidth: v.ChartWidth,
- ChartType: chartType,
- LatestDate: endDateStr,
- LatestValue: endVal,
- MoveLatestDate: "",
- UniqueCode: "",
- MinValue: minValue,
- MaxValue: maxValue,
- 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)
- }
- return
- }
- // GetBalanceExcelInfoOpButtonByChartInfoId 获取图表权限
- func GetBalanceExcelInfoOpButtonByChartInfoId(sysUserId, chartInfoId int, chartHaveOperaAuth bool) (opButton bool, err error) {
- // 如果没有数据权限,那么直接返回
- if !chartHaveOperaAuth {
- return
- }
- // 获取表格信息
- excelInfo, e := excelModel.GetExcelInfoByChartInfoId(chartInfoId)
- if e != nil {
- err = fmt.Errorf("获取ETA表格失败 Err %s", e.Error())
- return
- }
- checkExcelInfo := excelInfo
- if excelInfo.Source == utils.BALANCE_TABLE {
- checkExcelInfoId := excelInfo.ExcelInfoId
- if excelInfo.BalanceType == 1 {
- checkExcelInfoId = excelInfo.RelExcelInfoId
- } else {
- if excelInfo.ParentId > 0 {
- checkExcelInfoId = excelInfo.ParentId
- }
- }
- if checkExcelInfoId != excelInfo.ExcelInfoId {
- checkExcelInfo, e = excelModel.GetExcelInfoById(checkExcelInfoId)
- if e != nil {
- err = fmt.Errorf("获取平衡表格信息失败,Err:" + e.Error())
- return
- }
- }
- } else {
- return
- }
- // 数据权限
- haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, sysUserId)
- if e != nil {
- err = fmt.Errorf("获取表格权限信息失败,Err" + e.Error())
- return
- }
- // 如果没有数据权限,那么直接返回
- if !haveOperaAuth {
- return
- }
- //button := GetBalanceExcelInfoOpButton(sysUserId, checkExcelInfo.SysUserId, haveOperaAuth, checkExcelInfo.ExcelInfoId)
- if sysUserId == checkExcelInfo.SysUserId {
- opButton = true
- } else {
- obj := new(excelModel.ExcelWorker)
- workerList, e := obj.GetByExcelInfoId(checkExcelInfo.ExcelInfoId)
- if e == nil {
- for _, v := range workerList {
- if v.SysUserId == sysUserId {
- opButton = true
- break
- }
- }
- }
- }
- return
- }
|