chart_info_excel_balance.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. package data
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_mobile/models/data_manage"
  6. excelModel "eta/eta_mobile/models/data_manage/excel"
  7. "eta/eta_mobile/models/system"
  8. "eta/eta_mobile/services/data/data_manage_permission"
  9. "eta/eta_mobile/utils"
  10. "fmt"
  11. "math"
  12. "strings"
  13. "time"
  14. )
  15. 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) {
  16. // 图表数据权限
  17. {
  18. // 已授权分类id
  19. permissionChartIdList, permissionClassifyIdList, e := data_manage_permission.GetUserChartAndClassifyPermissionList(sysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  20. if e != nil {
  21. errMsg = "获取失败"
  22. err = fmt.Errorf("获取已授权分类id数据失败,Err:" + err.Error())
  23. return
  24. }
  25. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, 0, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  26. }
  27. chartInfoId := chartInfo.ChartInfoId
  28. resp = new(data_manage.ChartInfoDetailResp)
  29. // 获取主题样式
  30. chartTheme, err := GetChartThemeConfig(chartInfo.ChartThemeId, 1, chartInfo.ChartType)
  31. if err != nil {
  32. errMsg = "获取失败"
  33. err = fmt.Errorf(" 获取主题信息失败 Err:%s", err.Error())
  34. return
  35. }
  36. chartInfo.ChartThemeStyle = chartTheme.Config
  37. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  38. dateType := chartInfo.DateType
  39. fmt.Println("dateType:", dateType)
  40. chartType := chartInfo.ChartType
  41. startDate := chartInfo.StartDate
  42. endDate := chartInfo.EndDate
  43. seasonStartDate := chartInfo.SeasonStartDate
  44. seasonEndDate := chartInfo.SeasonEndDate
  45. startYear := chartInfo.StartYear
  46. calendar := chartInfo.Calendar
  47. if calendar == "" {
  48. calendar = "公历"
  49. }
  50. mappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
  51. //循环组装映射关系
  52. for _, v := range mappingListTmp {
  53. dataList := make([]*data_manage.EdbDataList, 0)
  54. dataListTmp, ok := dataListMap[v.ExcelChartEdbId]
  55. if ok {
  56. dataList = dataListTmp
  57. } else {
  58. err = errors.New(fmt.Sprint("获取失败,指标类型异常", v.ExcelChartEdbId))
  59. return
  60. }
  61. startDateStr, endDateStr, _, endVal, maxValue, minValue := getBalanceDataListStartDateAndValue(dataList)
  62. mapping := &data_manage.ChartEdbInfoMapping{
  63. EdbInfoId: v.ExcelChartEdbId,
  64. SourceName: "",
  65. Source: 0,
  66. SubSource: 0,
  67. EdbCode: v.EdbCode,
  68. EdbName: v.EdbName,
  69. EdbAliasName: v.EdbName,
  70. EdbNameEn: "",
  71. EdbAliasNameEn: "",
  72. EdbType: 0,
  73. Frequency: "",
  74. FrequencyEn: "",
  75. Unit: "",
  76. UnitEn: "",
  77. StartDate: startDateStr,
  78. EndDate: endDateStr,
  79. ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  80. ChartEdbMappingId: v.ExcelChartEdbId,
  81. ChartInfoId: chartInfoId,
  82. MaxData: v.MaxData,
  83. MinData: v.MinData,
  84. IsOrder: v.IsOrder,
  85. IsAxis: v.IsAxis,
  86. //EdbInfoType: 0,
  87. //EdbInfoCategoryType: 0,
  88. LeadValue: v.LeadValue,
  89. LeadUnit: v.LeadUnit,
  90. LeadUnitEn: "",
  91. ChartStyle: "",
  92. ChartColor: "",
  93. PredictChartColor: "",
  94. ChartWidth: v.ChartWidth,
  95. ChartType: chartType,
  96. LatestDate: endDateStr,
  97. LatestValue: endVal,
  98. MoveLatestDate: "",
  99. UniqueCode: "",
  100. MinValue: minValue,
  101. MaxValue: maxValue,
  102. DataList: nil,
  103. IsNullData: false,
  104. MappingSource: 0,
  105. RegionType: "",
  106. ClassifyId: 0,
  107. IsConvert: 0,
  108. ConvertType: 0,
  109. ConvertValue: 0,
  110. ConvertUnit: "",
  111. ConvertEnUnit: "",
  112. IsJoinPermission: 0,
  113. HaveOperaAuth: true,
  114. }
  115. mappingList = append(mappingList, mapping)
  116. }
  117. if chartType == 2 {
  118. startDate = seasonStartDate
  119. endDate = seasonEndDate
  120. if dateType <= 0 {
  121. if startDate != "" {
  122. dateType = 5
  123. } else {
  124. dateType = utils.DateTypeNYears
  125. }
  126. }
  127. } else {
  128. if dateType <= 0 {
  129. dateType = 3
  130. }
  131. }
  132. yearMax := 0
  133. if dateType == utils.DateTypeNYears {
  134. for _, v := range mappingList {
  135. if v.LatestDate != "" {
  136. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  137. if tErr != nil {
  138. errMsg = "获取失败"
  139. err = fmt.Errorf("获取图表日期信息失败,Err:" + tErr.Error())
  140. return
  141. }
  142. if lastDateT.Year() > yearMax {
  143. yearMax = lastDateT.Year()
  144. }
  145. }
  146. }
  147. }
  148. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
  149. if chartInfo.ChartType == 2 {
  150. chartInfo.StartDate = startDate
  151. chartInfo.EndDate = endDate
  152. }
  153. // 图表额外数据参数
  154. extraConfigStr := chartInfo.ExtraConfig
  155. // 柱方图的一些配置
  156. var barConfig data_manage.BarChartInfoReq
  157. if chartInfo != nil && chartInfo.ChartType == 7 {
  158. if chartInfo.BarConfig == `` {
  159. err = fmt.Errorf("柱方图未配置")
  160. errMsg = "柱方图未配置"
  161. return
  162. }
  163. err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  164. if err != nil {
  165. err = fmt.Errorf("柱方图配置异常 json.Unmarshal Err:%s", err.Error())
  166. errMsg = "柱方图配置异常"
  167. return
  168. }
  169. extraConfigStr = chartInfo.BarConfig
  170. }
  171. // 获取表格数据
  172. excelChartInfoDataShow := new(ExcelChartInfoDataShow)
  173. excelChartInfoDataShow.DataListMap = dataListMap
  174. if chartInfo.HaveOperaAuth {
  175. // 获取图表中的指标数据
  176. edbList, xEdbIdValue, yDataList, dataResp, e, msg := GetChartEdbDataV2(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig, excelChartInfoDataShow)
  177. if e != nil {
  178. err = fmt.Errorf("获取图表,指标数据失败,Err:%s", e.Error())
  179. errMsg = msg
  180. return
  181. }
  182. // 单位
  183. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  184. chartInfo.Unit = yDataList[0].Unit
  185. chartInfo.UnitEn = yDataList[0].UnitEn
  186. }
  187. warnEdbList := make([]string, 0)
  188. for _, v := range edbList {
  189. if v.IsNullData {
  190. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  191. }
  192. }
  193. if len(warnEdbList) > 0 {
  194. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  195. }
  196. if chartInfoId > 0 && chartInfo != nil {
  197. //判断是否加入我的图库
  198. {
  199. var myChartCondition string
  200. var myChartPars []interface{}
  201. myChartCondition += ` AND a.admin_id=? `
  202. myChartPars = append(myChartPars, sysUser.AdminId)
  203. myChartCondition += ` AND a.chart_info_id=? `
  204. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  205. myChartList, e := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  206. if e != nil && e.Error() != utils.ErrNoRow() {
  207. errMsg = "获取失败"
  208. err = fmt.Errorf("获取我的图表信息失败,GetMyChartByCondition,Err:" + e.Error())
  209. return
  210. }
  211. if myChartList != nil && len(myChartList) > 0 {
  212. chartInfo.IsAdd = true
  213. chartInfo.MyChartId = myChartList[0].MyChartId
  214. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  215. }
  216. }
  217. }
  218. //判断是否需要展示英文标识
  219. chartInfo.IsEnChart = CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  220. // 图表的指标来源
  221. sourceNameList, sourceNameEnList := GetEdbSourceByEdbInfoIdList(edbList)
  222. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  223. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  224. // todo 指标权限
  225. {
  226. for _, item := range edbList {
  227. // 数据权限
  228. item.HaveOperaAuth = true
  229. }
  230. }
  231. resp.EdbInfoList = edbList
  232. resp.XEdbIdValue = xEdbIdValue
  233. resp.YDataList = yDataList
  234. resp.DataResp = dataResp
  235. } else {
  236. resp.EdbInfoList = mappingList
  237. }
  238. //图表操作权限
  239. chartInfo.IsEdit = CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  240. chartInfo.Button = data_manage.ChartViewButton{
  241. IsEdit: chartInfo.IsEdit,
  242. IsEnChart: chartInfo.IsEnChart,
  243. IsAdd: chartInfo.IsAdd,
  244. IsCopy: true,
  245. IsSetName: chartInfo.IsSetName,
  246. }
  247. resp.ChartInfo = chartInfo
  248. resp.BarChartInfo = barConfig
  249. return
  250. }
  251. // GetBalanceExcelEdbDataMapList 获取指标最后的基础数据
  252. 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) {
  253. // 指标对应的所有数据
  254. edbDataListMap = make(map[int][]*data_manage.EdbDataList)
  255. for _, v := range mappingList {
  256. //fmt.Println("v:", v.EdbInfoId)
  257. item := new(data_manage.ChartEdbInfoMapping)
  258. item.EdbInfoId = v.EdbInfoId
  259. item.SourceName = v.SourceName
  260. item.Source = v.Source
  261. item.EdbCode = v.EdbCode
  262. item.EdbName = v.EdbName
  263. item.EdbNameEn = v.EdbNameEn
  264. item.Frequency = v.Frequency
  265. item.EdbType = v.EdbType
  266. item.FrequencyEn = GetFrequencyEn(v.Frequency)
  267. if v.Unit != `无` {
  268. item.Unit = v.Unit
  269. }
  270. item.UnitEn = v.UnitEn
  271. item.StartDate = v.StartDate
  272. item.EndDate = v.EndDate
  273. item.ModifyTime = v.ModifyTime
  274. item.EdbInfoCategoryType = v.EdbInfoCategoryType
  275. item.PredictChartColor = v.PredictChartColor
  276. item.ClassifyId = v.ClassifyId
  277. if chartInfoId <= 0 {
  278. item.IsAxis = 1
  279. item.LeadValue = 0
  280. item.LeadUnit = ""
  281. item.ChartEdbMappingId = 0
  282. item.ChartInfoId = 0
  283. item.IsOrder = false
  284. item.EdbInfoType = 1
  285. item.ChartStyle = ""
  286. item.ChartColor = ""
  287. item.ChartWidth = 0
  288. item.MaxData = v.MaxValue
  289. item.MinData = v.MinValue
  290. } else {
  291. item.IsAxis = v.IsAxis
  292. item.EdbInfoType = v.EdbInfoType
  293. item.LeadValue = v.LeadValue
  294. item.LeadUnit = v.LeadUnit
  295. item.LeadUnitEn = GetLeadUnitEn(v.LeadUnit)
  296. item.ChartEdbMappingId = v.ChartEdbMappingId
  297. item.ChartInfoId = v.ChartInfoId
  298. item.ChartStyle = v.ChartStyle
  299. item.ChartColor = v.ChartColor
  300. item.ChartWidth = v.ChartWidth
  301. item.IsOrder = v.IsOrder
  302. item.MaxData = v.MaxData
  303. item.MinData = v.MinData
  304. }
  305. item.LatestValue = v.LatestValue
  306. item.LatestDate = v.LatestDate
  307. item.UniqueCode = v.UniqueCode
  308. item.MoveLatestDate = v.LatestDate
  309. item.EdbAliasName = v.EdbAliasName
  310. item.IsConvert = v.IsConvert
  311. item.ConvertType = v.ConvertType
  312. item.ConvertValue = v.ConvertValue
  313. item.ConvertUnit = v.ConvertUnit
  314. item.ConvertEnUnit = v.ConvertEnUnit
  315. item.IsJoinPermission = v.IsJoinPermission
  316. var startDateReal string
  317. var diffSeconds int64
  318. if chartType == 2 { //季节性图
  319. startDateReal = startDate
  320. } else {
  321. if v.EdbInfoType == 0 && v.LeadUnit != "" && v.LeadValue > 0 { //领先指标
  322. var startTimeRealTemp time.Time
  323. startDateParse, _ := time.Parse(utils.FormatDate, startDate)
  324. switch v.LeadUnit {
  325. case "天":
  326. startTimeRealTemp = startDateParse.AddDate(0, 0, -v.LeadValue)
  327. case "月":
  328. startTimeRealTemp = startDateParse.AddDate(0, -v.LeadValue, 0)
  329. case "季":
  330. startTimeRealTemp = startDateParse.AddDate(0, -3*v.LeadValue, 0)
  331. case "周":
  332. startTimeRealTemp = startDateParse.AddDate(0, 0, -7*v.LeadValue)
  333. case "年":
  334. startTimeRealTemp = startDateParse.AddDate(-v.LeadValue, 0, 0)
  335. }
  336. if startTimeRealTemp.Before(startDateParse) {
  337. startDateReal = startTimeRealTemp.Format(utils.FormatDate)
  338. diffSeconds = (int64(startTimeRealTemp.UnixNano()) - int64(startDateParse.UnixNano())) / 1e6
  339. } else {
  340. startDateReal = startDate
  341. diffSeconds = 0
  342. }
  343. // 预测指标的开始日期也要偏移
  344. {
  345. day, tmpErr := utils.GetDaysBetween2Date(utils.FormatDate, startDate, startDateReal)
  346. if tmpErr != nil {
  347. err = tmpErr
  348. return
  349. }
  350. moveLatestDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, item.MoveLatestDate, time.Local)
  351. if tmpErr != nil {
  352. err = tmpErr
  353. return
  354. }
  355. item.MoveLatestDate = moveLatestDateTime.AddDate(0, 0, day).Format(utils.FormatDate)
  356. }
  357. } else {
  358. startDateReal = startDate
  359. }
  360. }
  361. //fmt.Println("line 1011 chart:", v.Source, v.EdbInfoId, startDateReal, endDate)
  362. calendarPreYear := 0
  363. if calendar == "农历" {
  364. newStartDateReal, e := time.Parse(utils.FormatDate, startDateReal)
  365. if e != nil {
  366. err = fmt.Errorf("时间解析 time.Parse(%s, %s) error: %v", utils.FormatDate, startDateReal, e)
  367. return
  368. }
  369. calendarPreYear = newStartDateReal.Year() - 1
  370. newStartDateReal = newStartDateReal.AddDate(-1, 0, 0)
  371. startDateReal = newStartDateReal.Format(utils.FormatDate)
  372. }
  373. dataList := make([]*data_manage.EdbDataList, 0)
  374. dataListTmp, ok := dataListMap[v.EdbInfoId]
  375. if ok {
  376. dataList = dataListTmp
  377. } else {
  378. err = errors.New(fmt.Sprint("获取失败,指标类型异常", v.EdbInfoId))
  379. return
  380. }
  381. if v.IsConvert == 1 {
  382. switch v.ConvertType {
  383. case 1:
  384. for i, data := range dataList {
  385. dataList[i].Value = data.Value * v.ConvertValue
  386. }
  387. //item.MaxData = item.MaxData * v.ConvertValue
  388. //item.MinData = item.MinData * v.ConvertValue
  389. case 2:
  390. for i, data := range dataList {
  391. dataList[i].Value = data.Value / v.ConvertValue
  392. }
  393. //item.MaxData = item.MaxData / v.ConvertValue
  394. //item.MinData = item.MinData / v.ConvertValue
  395. case 3:
  396. for i, data := range dataList {
  397. if data.Value <= 0 {
  398. err = errors.New("数据中含有负数或0,无法对数运算")
  399. return
  400. }
  401. dataList[i].Value = math.Log(data.Value) / math.Log(v.ConvertValue)
  402. }
  403. //item.MaxData = math.Log(item.MaxData) / math.Log(v.ConvertValue)
  404. //item.MinData = math.Log(item.MinData) / math.Log(v.ConvertValue)
  405. }
  406. }
  407. edbDataListMap[v.EdbInfoId] = dataList
  408. if diffSeconds != 0 && v.EdbInfoType == 0 {
  409. dataListLen := len(dataList)
  410. for i := 0; i < dataListLen; i++ {
  411. dataList[i].DataTimestamp = dataList[i].DataTimestamp - diffSeconds
  412. }
  413. }
  414. if chartType == 2 {
  415. latestDate, tmpErr := time.Parse(utils.FormatDate, v.LatestDate)
  416. if tmpErr != nil {
  417. //item.DataList = dataList
  418. item.IsNullData = true
  419. edbList = append(edbList, item)
  420. continue
  421. }
  422. if calendar == "农历" {
  423. if len(dataList) <= 0 {
  424. result := new(data_manage.EdbDataResult)
  425. item.DataList = result
  426. } else {
  427. result, tmpErr := data_manage.AddCalculateQuarterV6(dataList)
  428. if tmpErr != nil {
  429. err = errors.New("获取农历数据失败,Err:" + tmpErr.Error())
  430. return
  431. }
  432. quarterDataList, tErr := GetSeasonEdbInfoDataListByXDateNong(result, latestDate, seasonExtraConfig, calendarPreYear)
  433. if tErr != nil {
  434. err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
  435. return
  436. }
  437. item.DataList = quarterDataList
  438. }
  439. } else {
  440. quarterDataList, tErr := GetSeasonEdbInfoDataListByXDate(dataList, latestDate, seasonExtraConfig)
  441. if tErr != nil {
  442. err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
  443. return
  444. }
  445. item.DataList = quarterDataList
  446. }
  447. } else if chartType == 7 || chartType == utils.CHART_TYPE_RADAR { //柱方图
  448. //item.DataList = dataList
  449. } else {
  450. item.DataList = dataList
  451. }
  452. edbList = append(edbList, item)
  453. }
  454. return
  455. }
  456. func CheckBalanceChartCacheAndPermission(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  457. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  458. adminId := sysUser.AdminId
  459. // todo 图表数据权限
  460. // 已授权分类id
  461. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(adminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  462. if err != nil {
  463. errMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  464. return
  465. }
  466. defer func() {
  467. if isOk {
  468. // 图表权限校验
  469. {
  470. resp.ChartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, 0, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  471. //图表操作权限
  472. chartInfo.IsEdit = CheckOpChartPermission(sysUser, chartInfo.SysUserId, resp.ChartInfo.HaveOperaAuth)
  473. chartInfo.Button = data_manage.ChartViewButton{
  474. IsEdit: chartInfo.IsEdit,
  475. IsEnChart: chartInfo.IsEnChart,
  476. IsAdd: chartInfo.IsAdd,
  477. IsCopy: true,
  478. IsSetName: chartInfo.IsSetName,
  479. }
  480. //if !resp.ChartInfo.HaveOperaAuth {
  481. // for _, v := range resp.EdbInfoList {
  482. // v.DataList = nil
  483. // }
  484. // resp.DataResp = nil
  485. // resp.XEdbIdValue = []int{}
  486. // resp.YDataList = []data_manage.YData{}
  487. //}
  488. }
  489. // todo 是否需要返回平衡表指标权限即判断平衡表的表格数据权限
  490. {
  491. // 查询图表关联的表格ID
  492. excelInfo, e := excelModel.GetExcelInfoByChartInfoId(chartInfo.ChartInfoId)
  493. if e != nil {
  494. errMsg = "获取图表关联的表格ID失败,Err:" + e.Error()
  495. err = e
  496. return
  497. }
  498. checkExcelInfo := excelInfo
  499. if excelInfo.Source == utils.BALANCE_TABLE {
  500. checkExcelInfoId := excelInfo.ExcelInfoId
  501. if excelInfo.BalanceType == 1 {
  502. checkExcelInfoId = excelInfo.RelExcelInfoId
  503. } else {
  504. if excelInfo.ParentId > 0 {
  505. checkExcelInfoId = excelInfo.ParentId
  506. }
  507. }
  508. if checkExcelInfoId != excelInfo.ExcelInfoId {
  509. checkExcelInfo, err = excelModel.GetExcelInfoById(checkExcelInfoId)
  510. if err != nil {
  511. errMsg = "获取平衡表格信息失败"
  512. err = errors.New("获取平衡表格信息失败,Err:" + err.Error())
  513. return
  514. }
  515. }
  516. }
  517. haveOperaAuth, e := data_manage_permission.CheckExcelPermissionByExcelInfoId(checkExcelInfo.ExcelInfoId, checkExcelInfo.ExcelClassifyId, checkExcelInfo.IsJoinPermission, adminId)
  518. if e != nil {
  519. errMsg = "获取平衡表格数据权限失败"
  520. err = errors.New("获取表格权限信息失败,Err" + e.Error())
  521. return
  522. }
  523. // 数据权限
  524. for _, v := range resp.EdbInfoList {
  525. v.HaveOperaAuth = haveOperaAuth
  526. }
  527. }
  528. }
  529. }()
  530. key := GetChartInfoDataKey(chartInfo.ChartInfoId)
  531. if utils.Re == nil && isCache {
  532. if utils.Re == nil && utils.Rc.IsExist(key) {
  533. if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  534. err := json.Unmarshal(redisData, &resp)
  535. if err != nil || resp == nil {
  536. return
  537. }
  538. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  539. var myCond string
  540. var myPars []interface{}
  541. myCond += ` AND a.admin_id=? `
  542. myPars = append(myPars, adminId)
  543. myCond += ` AND a.chart_info_id=? `
  544. myPars = append(myPars, chartInfo.ChartInfoId)
  545. myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
  546. if err != nil && err.Error() != utils.ErrNoRow() {
  547. msg = "获取失败"
  548. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  549. return
  550. }
  551. resp.ChartInfo.IsAdd = false
  552. resp.ChartInfo.MyChartId = 0
  553. resp.ChartInfo.MyChartClassifyId = ""
  554. if myList != nil && len(myList) > 0 {
  555. resp.ChartInfo.IsAdd = true
  556. resp.ChartInfo.MyChartId = myList[0].MyChartId
  557. resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
  558. }
  559. //判断是否加入我的图库
  560. {
  561. var myChartCondition string
  562. var myChartPars []interface{}
  563. myChartCondition += ` AND a.admin_id=? `
  564. myChartPars = append(myChartPars, adminId)
  565. myChartCondition += ` AND a.chart_info_id=? `
  566. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  567. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  568. if err != nil && err.Error() != utils.ErrNoRow() {
  569. msg = "获取失败"
  570. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  571. return
  572. }
  573. if myChartList != nil && len(myChartList) > 0 {
  574. chartInfo.IsAdd = true
  575. chartInfo.MyChartId = myChartList[0].MyChartId
  576. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  577. }
  578. }
  579. isOk = true
  580. fmt.Println("source redis")
  581. return
  582. }
  583. }
  584. }
  585. return
  586. }
  587. func getBalanceDataListStartDateAndValue(dataList []*data_manage.EdbDataList) (startDate, endDate string, startVal, endVal, maxVal, minVal float64) {
  588. if len(dataList) == 0 {
  589. return
  590. }
  591. startDate = dataList[0].DataTime
  592. startVal = dataList[0].Value
  593. maxVal = dataList[0].Value
  594. minVal = dataList[0].Value
  595. endDate = dataList[len(dataList)-1].DataTime
  596. endVal = dataList[len(dataList)-1].Value
  597. for _, v := range dataList {
  598. if v.DataTime < startDate {
  599. startDate = v.DataTime
  600. startVal = v.Value
  601. }
  602. if v.DataTime > endDate {
  603. endDate = v.DataTime
  604. endVal = v.Value
  605. }
  606. if v.Value > maxVal {
  607. maxVal = v.Value
  608. }
  609. if v.Value < minVal {
  610. minVal = v.Value
  611. }
  612. }
  613. return
  614. }