chart_theme.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. package data
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/chart_theme"
  7. "eta/eta_api/utils"
  8. "fmt"
  9. "github.com/shopspring/decimal"
  10. "math"
  11. "time"
  12. )
  13. // GetThemePreviewChartEdbData 获取图表的指标数据
  14. func GetThemePreviewChartEdbData(chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping, extraConfigStr string, seasonExtraConfig string) (edbList []*data_manage.ChartEdbInfoMapping, xEdbIdValue []int, yDataList []data_manage.YData, dataResp interface{}, err error, errMsg string) {
  15. edbList = make([]*data_manage.ChartEdbInfoMapping, 0)
  16. xEdbIdValue = make([]int, 0)
  17. yDataList = make([]data_manage.YData, 0)
  18. var extraConfig interface{}
  19. switch chartType {
  20. case 7: // 柱形图
  21. var barConfig data_manage.BarChartInfoReq
  22. if extraConfigStr == `` {
  23. errMsg = "柱方图未配置"
  24. err = errors.New(errMsg)
  25. return
  26. }
  27. err = json.Unmarshal([]byte(extraConfigStr), &barConfig)
  28. if err != nil {
  29. errMsg = "柱方图配置异常"
  30. err = errors.New(errMsg)
  31. return
  32. }
  33. extraConfig = barConfig
  34. case 10: // 截面散点图
  35. var tmpExtraConfig data_manage.SectionScatterReq
  36. if extraConfigStr == `` {
  37. errMsg = "截面散点图未配置"
  38. err = errors.New(errMsg)
  39. return
  40. }
  41. err = json.Unmarshal([]byte(extraConfigStr), &tmpExtraConfig)
  42. if err != nil {
  43. errMsg = "截面散点配置异常"
  44. err = errors.New(errMsg)
  45. return
  46. }
  47. extraConfig = tmpExtraConfig
  48. case utils.CHART_TYPE_RADAR:
  49. var barConfig data_manage.RadarChartInfoReq
  50. if extraConfigStr == `` {
  51. errMsg = "雷达图未配置"
  52. err = errors.New(errMsg)
  53. return
  54. }
  55. err = json.Unmarshal([]byte(extraConfigStr), &barConfig)
  56. if err != nil {
  57. errMsg = "雷达图配置异常"
  58. err = errors.New(errMsg)
  59. return
  60. }
  61. extraConfig = barConfig
  62. default:
  63. xEdbIdValue = make([]int, 0)
  64. yDataList = make([]data_manage.YData, 0)
  65. }
  66. // 指标对应的所有数据
  67. edbDataListMap, edbList, err := getThemePreviewEdbDataMapList(chartType, calendar, startDate, endDate, mappingList, seasonExtraConfig)
  68. if err != nil {
  69. return
  70. }
  71. // 特殊图形数据处理
  72. switch chartType {
  73. case 7: // 柱形图
  74. barChartConf := extraConfig.(data_manage.BarChartInfoReq)
  75. xEdbIdValue, yDataList, err = BarChartData(mappingList, edbDataListMap, barChartConf.DateList, barChartConf.Sort)
  76. for k := range yDataList {
  77. yDataList[k].Unit = barChartConf.Unit
  78. yDataList[k].UnitEn = barChartConf.UnitEn
  79. }
  80. for _, v := range edbList {
  81. // 指标别名
  82. if barChartConf.EdbInfoIdList != nil && len(barChartConf.EdbInfoIdList) > 0 {
  83. for _, reqEdb := range barChartConf.EdbInfoIdList {
  84. if v.EdbInfoId == reqEdb.EdbInfoId {
  85. v.EdbAliasName = reqEdb.Name
  86. }
  87. }
  88. }
  89. }
  90. case 10: // 截面散点图
  91. sectionScatterConf := extraConfig.(data_manage.SectionScatterReq)
  92. xEdbIdValue, dataResp, err = getThemePreviewSectionScatterChartData(mappingList, edbDataListMap, sectionScatterConf)
  93. var tmpExtraConfig data_manage.SectionScatterReq
  94. if extraConfigStr == `` {
  95. errMsg = "截面散点图未配置"
  96. err = errors.New(errMsg)
  97. return
  98. }
  99. err = json.Unmarshal([]byte(extraConfigStr), &tmpExtraConfig)
  100. if err != nil {
  101. errMsg = "截面散点配置异常"
  102. err = errors.New(errMsg)
  103. return
  104. }
  105. // 这个数据没有必要返回给前端
  106. for _, v := range edbList {
  107. v.DataList = nil
  108. }
  109. case utils.CHART_TYPE_RADAR: //雷达图
  110. radarConf := extraConfig.(data_manage.RadarChartInfoReq)
  111. xEdbIdValue, dataResp, err = RadarChartData(mappingList, edbDataListMap, radarConf)
  112. }
  113. return
  114. }
  115. func getThemePreviewEdbDataMapList(chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping, seasonExtraConfig string) (edbDataListMap map[int][]*data_manage.EdbDataList, edbList []*data_manage.ChartEdbInfoMapping, err error) {
  116. // 指标对应的所有数据
  117. edbDataListMap = make(map[int][]*data_manage.EdbDataList)
  118. for _, v := range mappingList {
  119. //fmt.Println("v:", v.EdbInfoId)
  120. item := new(data_manage.ChartEdbInfoMapping)
  121. item.EdbInfoId = v.EdbInfoId
  122. item.SourceName = v.SourceName
  123. item.Source = v.Source
  124. item.EdbCode = v.EdbCode
  125. item.EdbName = v.EdbName
  126. item.EdbNameEn = v.EdbNameEn
  127. item.Frequency = v.Frequency
  128. item.EdbType = v.EdbType
  129. item.FrequencyEn = GetFrequencyEn(v.Frequency)
  130. if v.Unit != `无` {
  131. item.Unit = v.Unit
  132. }
  133. item.UnitEn = v.UnitEn
  134. item.StartDate = v.StartDate
  135. item.EndDate = v.EndDate
  136. item.ModifyTime = v.ModifyTime
  137. item.EdbInfoCategoryType = v.EdbInfoCategoryType
  138. item.PredictChartColor = v.PredictChartColor
  139. item.ClassifyId = v.ClassifyId
  140. item.IsAxis = 1
  141. item.EdbInfoType = 1
  142. item.LeadValue = v.LeadValue
  143. item.LeadUnit = v.LeadUnit
  144. item.LeadUnitEn = GetLeadUnitEn(v.LeadUnit)
  145. item.ChartEdbMappingId = v.ChartEdbMappingId
  146. item.ChartInfoId = v.ChartInfoId
  147. item.ChartStyle = v.ChartStyle
  148. item.ChartColor = v.ChartColor
  149. item.ChartWidth = 0
  150. item.IsOrder = false
  151. item.MaxData = v.MaxValue
  152. item.MinData = v.MinValue
  153. item.LatestValue = v.LatestValue
  154. item.LatestDate = v.LatestDate
  155. item.UniqueCode = v.UniqueCode
  156. item.MoveLatestDate = v.LatestDate
  157. var startDateReal string
  158. var diffSeconds int64
  159. if chartType == 2 { //季节性图
  160. startDateReal = startDate
  161. } else {
  162. if v.EdbInfoType == 0 && v.LeadUnit != "" && v.LeadValue > 0 { //领先指标
  163. var startTimeRealTemp time.Time
  164. startDateParse, _ := time.Parse(utils.FormatDate, startDate)
  165. switch v.LeadUnit {
  166. case "天":
  167. startTimeRealTemp = startDateParse.AddDate(0, 0, -v.LeadValue)
  168. case "月":
  169. startTimeRealTemp = startDateParse.AddDate(0, -v.LeadValue, 0)
  170. case "季":
  171. startTimeRealTemp = startDateParse.AddDate(0, -3*v.LeadValue, 0)
  172. case "周":
  173. startTimeRealTemp = startDateParse.AddDate(0, 0, -7*v.LeadValue)
  174. case "年":
  175. startTimeRealTemp = startDateParse.AddDate(-v.LeadValue, 0, 0)
  176. }
  177. if startTimeRealTemp.Before(startDateParse) {
  178. startDateReal = startTimeRealTemp.Format(utils.FormatDate)
  179. diffSeconds = (int64(startTimeRealTemp.UnixNano()) - int64(startDateParse.UnixNano())) / 1e6
  180. } else {
  181. startDateReal = startDate
  182. diffSeconds = 0
  183. }
  184. // 预测指标的开始日期也要偏移
  185. {
  186. day, tmpErr := utils.GetDaysBetween2Date(utils.FormatDate, startDate, startDateReal)
  187. if tmpErr != nil {
  188. err = tmpErr
  189. return
  190. }
  191. moveLatestDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, item.MoveLatestDate, time.Local)
  192. if tmpErr != nil {
  193. err = tmpErr
  194. return
  195. }
  196. item.MoveLatestDate = moveLatestDateTime.AddDate(0, 0, day).Format(utils.FormatDate)
  197. }
  198. } else {
  199. startDateReal = startDate
  200. }
  201. }
  202. dataList := make([]*data_manage.EdbDataList, 0)
  203. dataList, err = chart_theme.GetChartThemeDefaultDataItemList(v.EdbInfoId, startDateReal)
  204. if err != nil {
  205. return
  206. }
  207. edbDataListMap[v.EdbInfoId] = dataList
  208. if diffSeconds != 0 && v.EdbInfoType == 0 {
  209. dataListLen := len(dataList)
  210. for i := 0; i < dataListLen; i++ {
  211. dataList[i].DataTimestamp = dataList[i].DataTimestamp - diffSeconds
  212. }
  213. }
  214. if chartType == 2 {
  215. latestDate, tmpErr := time.Parse(utils.FormatDate, v.LatestDate)
  216. if tmpErr != nil {
  217. //item.DataList = dataList
  218. item.IsNullData = true
  219. edbList = append(edbList, item)
  220. continue
  221. }
  222. quarterDataList, tErr := GetSeasonEdbInfoDataListByXDate(dataList, latestDate, seasonExtraConfig)
  223. if tErr != nil {
  224. err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
  225. return
  226. }
  227. item.DataList = quarterDataList
  228. } else if chartType == 7 || chartType == utils.CHART_TYPE_RADAR { //柱方图
  229. //item.DataList = dataList
  230. } else {
  231. item.DataList = dataList
  232. }
  233. edbList = append(edbList, item)
  234. }
  235. return
  236. }
  237. func getThemePreviewSectionScatterChartData(mappingList []*data_manage.ChartEdbInfoMapping, edbDataListMap map[int][]*data_manage.EdbDataList, extraConfig data_manage.SectionScatterReq) (edbIdList []int, chartDataResp data_manage.SectionScatterInfoResp, err error) {
  238. // 指标数据数组(10086:{"2022-12-02":100.01,"2022-12-01":102.3})
  239. edbDataMap := make(map[int]map[string]float64)
  240. for edbInfoId, edbDataList := range edbDataListMap {
  241. edbDateData := make(map[string]float64)
  242. for _, edbData := range edbDataList {
  243. edbDateData[edbData.DataTime] = edbData.Value
  244. }
  245. edbDataMap[edbInfoId] = edbDateData
  246. }
  247. // edbIdList 指标展示顺序;x轴的指标顺序
  248. edbIdList = make([]int, 0)
  249. edbMappingMap := make(map[int]*data_manage.ChartEdbInfoMapping)
  250. for _, v := range mappingList {
  251. edbIdList = append(edbIdList, v.EdbInfoId)
  252. edbMappingMap[v.EdbInfoId] = v
  253. }
  254. //SectionScatterSeriesInfoResp
  255. dataListResp := make([]data_manage.SectionScatterSeriesItemResp, 0) //y轴的数据列表
  256. for _, seriesItem := range extraConfig.SeriesList {
  257. var maxDate time.Time
  258. // 系列中的指标数据
  259. tmpSeriesEdbInfoList := make([]data_manage.SectionScatterEdbItemResp, 0)
  260. var minXVal, maxXVal, minYVal, maxYVal float64
  261. for _, edbConf := range seriesItem.EdbInfoList {
  262. tmpItem := data_manage.SectionScatterEdbItemResp{
  263. IsShow: edbConf.IsShow,
  264. Name: edbConf.Name,
  265. NameEn: edbConf.NameEn,
  266. } //单个坐标点的数据
  267. //X轴的数据
  268. {
  269. edbInfoId := edbConf.XEdbInfoId //X轴的指标
  270. edbMappingInfo, ok := edbMappingMap[edbInfoId]
  271. if !ok {
  272. continue
  273. }
  274. findDate := edbConf.XDate //需要的日期值
  275. dataList := edbDataListMap[edbInfoId] //指标的所有数据值
  276. if len(dataList) <= 0 {
  277. // 没有数据的指标id
  278. //findDataList = append(findDataList, 0)
  279. continue
  280. }
  281. tmpItem.XEdbInfoId = edbInfoId
  282. tmpItem.XName = edbMappingInfo.EdbName
  283. tmpItem.XNameEn = edbMappingInfo.EdbNameEn
  284. switch edbConf.XDateType {
  285. case 1: //最新值
  286. findDate = dataList[len(dataList)-1].DataTime
  287. case 2: //近期几天
  288. findDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[len(dataList)-1].DataTime, time.Local)
  289. if tmpErr != nil {
  290. err = tmpErr
  291. return
  292. }
  293. findDateTime = findDateTime.AddDate(0, 0, -edbConf.XDateValue)
  294. lenData := len(dataList) - 1
  295. for i := lenData; i >= 0; i-- {
  296. currDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[i].DataTime, time.Local)
  297. if tmpErr != nil {
  298. err = tmpErr
  299. return
  300. }
  301. if currDateTime.Equal(findDateTime) || currDateTime.Before(findDateTime) {
  302. findDate = dataList[i].DataTime
  303. break
  304. }
  305. }
  306. case 3: // 固定日期
  307. //最早的日期
  308. minDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[0].DataTime, time.Local)
  309. if tmpErr != nil {
  310. err = tmpErr
  311. return
  312. }
  313. //寻找固定日期的数据
  314. findDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, edbConf.XDate, time.Local)
  315. if tmpErr != nil {
  316. err = tmpErr
  317. return
  318. }
  319. for tmpDateTime := findDateTime; tmpDateTime.After(minDateTime) || tmpDateTime.Equal(minDateTime); tmpDateTime = tmpDateTime.AddDate(0, 0, -1) {
  320. tmpDate := tmpDateTime.Format(utils.FormatDate)
  321. if _, ok := edbDataMap[edbInfoId][tmpDate]; ok { //如果能找到数据,那么就返回
  322. findDate = tmpDate
  323. break
  324. }
  325. }
  326. default:
  327. err = errors.New(fmt.Sprint("日期类型异常,Type:", edbConf.XDate))
  328. return
  329. }
  330. findDateTime, _ := time.ParseInLocation(utils.FormatDate, findDate, time.Local)
  331. if maxDate.IsZero() {
  332. maxDate = findDateTime
  333. } else {
  334. if findDateTime.After(maxDate) {
  335. maxDate = findDateTime
  336. }
  337. }
  338. if tmpValue, ok := edbDataMap[edbInfoId][findDate]; ok {
  339. tmpItem.XDate = findDate
  340. tmpItem.XValue = tmpValue
  341. } else {
  342. continue
  343. }
  344. }
  345. //Y轴的数据
  346. {
  347. edbInfoId := edbConf.YEdbInfoId //Y轴的指标
  348. edbMappingInfo, ok := edbMappingMap[edbInfoId]
  349. if !ok {
  350. continue
  351. }
  352. findDate := edbConf.YDate //需要的日期值
  353. dataList := edbDataListMap[edbInfoId] //指标的所有数据值
  354. if len(dataList) <= 0 {
  355. // 没有数据的指标id
  356. //findDataList = append(findDataList, 0)
  357. continue
  358. }
  359. tmpItem.YEdbInfoId = edbInfoId
  360. tmpItem.YName = edbMappingInfo.EdbName
  361. tmpItem.YNameEn = edbMappingInfo.EdbNameEn
  362. switch edbConf.YDateType {
  363. case 1: //最新值
  364. findDate = dataList[len(dataList)-1].DataTime
  365. case 2: //近期几天
  366. findDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[len(dataList)-1].DataTime, time.Local)
  367. if tmpErr != nil {
  368. err = tmpErr
  369. return
  370. }
  371. findDateTime = findDateTime.AddDate(0, 0, -edbConf.YDateValue)
  372. lenData := len(dataList) - 1
  373. for i := lenData; i >= 0; i-- {
  374. currDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[i].DataTime, time.Local)
  375. if tmpErr != nil {
  376. err = tmpErr
  377. return
  378. }
  379. if currDateTime.Equal(findDateTime) || currDateTime.Before(findDateTime) {
  380. findDate = dataList[i].DataTime
  381. break
  382. }
  383. }
  384. case 3: // 固定日期
  385. //最早的日期
  386. minDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, dataList[0].DataTime, time.Local)
  387. if tmpErr != nil {
  388. err = tmpErr
  389. return
  390. }
  391. //寻找固定日期的数据
  392. findDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, edbConf.YDate, time.Local)
  393. if tmpErr != nil {
  394. err = tmpErr
  395. return
  396. }
  397. for tmpDateTime := findDateTime; tmpDateTime.After(minDateTime) || tmpDateTime.Equal(minDateTime); tmpDateTime = tmpDateTime.AddDate(0, 0, -1) {
  398. tmpDate := tmpDateTime.Format(utils.FormatDate)
  399. if _, ok := edbDataMap[edbInfoId][tmpDate]; ok { //如果能找到数据,那么就返回
  400. findDate = tmpDate
  401. break
  402. }
  403. }
  404. default:
  405. err = errors.New(fmt.Sprint("日期类型异常,Type:", edbConf.YDate))
  406. return
  407. }
  408. findDateTime, _ := time.ParseInLocation(utils.FormatDate, findDate, time.Local)
  409. if maxDate.IsZero() {
  410. maxDate = findDateTime
  411. } else {
  412. if findDateTime.After(maxDate) {
  413. maxDate = findDateTime
  414. }
  415. }
  416. if tmpValue, ok := edbDataMap[edbInfoId][findDate]; ok {
  417. tmpItem.YDate = findDate
  418. tmpItem.YValue = tmpValue
  419. } else {
  420. continue
  421. }
  422. }
  423. // 获取当前系列的X轴的最大最小值
  424. {
  425. if tmpItem.XValue < minXVal {
  426. minXVal = tmpItem.XValue
  427. }
  428. if tmpItem.XValue > maxXVal {
  429. maxXVal = tmpItem.XValue
  430. }
  431. if tmpItem.YValue < minYVal {
  432. minYVal = tmpItem.YValue
  433. }
  434. if tmpItem.YValue > maxYVal {
  435. maxYVal = tmpItem.YValue
  436. }
  437. }
  438. tmpSeriesEdbInfoList = append(tmpSeriesEdbInfoList, tmpItem)
  439. }
  440. trendLimitData := make([]data_manage.CoordinatePoint, 0) //趋势线的前后坐标点
  441. var trendLine, rSquare string
  442. // 生成线性方程式
  443. var a, b float64
  444. {
  445. coordinateData := make([]utils.Coordinate, 0)
  446. for _, tmpSeriesEdbInfo := range tmpSeriesEdbInfoList {
  447. tmpCoordinate1 := utils.Coordinate{
  448. X: tmpSeriesEdbInfo.XValue,
  449. Y: tmpSeriesEdbInfo.YValue,
  450. }
  451. coordinateData = append(coordinateData, tmpCoordinate1)
  452. }
  453. // 只有存在两个坐标点的时候,才能去计算线性方程和R平方
  454. if len(coordinateData) >= 2 {
  455. a, b = utils.GetLinearResult(coordinateData)
  456. if !math.IsNaN(a) && !math.IsNaN(b) {
  457. if b > 0 {
  458. trendLine = fmt.Sprintf("y=%sx+%s", utils.SubFloatToString(a, 4), utils.SubFloatToString(b, 4))
  459. } else {
  460. trendLine = fmt.Sprintf("y=%sx%s", utils.SubFloatToString(a, 4), utils.SubFloatToString(b, 4))
  461. }
  462. minYVal, _ = decimal.NewFromFloat(a).Mul(decimal.NewFromFloat(minXVal)).Add(decimal.NewFromFloat(b)).Round(4).Float64()
  463. maxYVal, _ = decimal.NewFromFloat(a).Mul(decimal.NewFromFloat(maxXVal)).Add(decimal.NewFromFloat(b)).Round(4).Float64()
  464. }
  465. // 计算R平方
  466. rSquare = fmt.Sprint(utils.CalculationDecisive(coordinateData))
  467. }
  468. trendLimitData = append(trendLimitData, data_manage.CoordinatePoint{
  469. X: minXVal,
  470. Y: minYVal,
  471. }, data_manage.CoordinatePoint{
  472. X: maxXVal,
  473. Y: maxYVal,
  474. })
  475. }
  476. dataListResp = append(dataListResp, data_manage.SectionScatterSeriesItemResp{
  477. Name: seriesItem.Name,
  478. NameEn: seriesItem.NameEn,
  479. IsNameDefault: seriesItem.IsNameDefault,
  480. Color: seriesItem.Color,
  481. EdbInfoList: tmpSeriesEdbInfoList,
  482. ShowTrendLine: seriesItem.ShowTrendLine,
  483. ShowFitEquation: seriesItem.ShowFitEquation,
  484. ShowRSquare: seriesItem.ShowRSquare,
  485. TrendLine: trendLine,
  486. RSquare: rSquare,
  487. TrendLimitData: trendLimitData,
  488. })
  489. }
  490. // 截面散点图点击详情时自动更新系列名
  491. if len(extraConfig.SeriesList) > 0 {
  492. // 默认名字的时候才自动更新
  493. if extraConfig.SeriesList[0].IsNameDefault {
  494. firstXEdbInfoId := extraConfig.SeriesList[0].EdbInfoList[0].XEdbInfoId
  495. if v, ok := edbMappingMap[firstXEdbInfoId]; ok {
  496. extraConfig.SeriesList[0].Name = v.LatestDate
  497. extraConfig.SeriesList[0].NameEn = v.LatestDate
  498. dataListResp[0].Name = v.LatestDate
  499. dataListResp[0].NameEn = v.LatestDate
  500. }
  501. }
  502. }
  503. chartDataResp = data_manage.SectionScatterInfoResp{
  504. XName: extraConfig.XName,
  505. XNameEn: extraConfig.XNameEn,
  506. XUnitName: extraConfig.XUnitName,
  507. XUnitNameEn: extraConfig.XUnitNameEn,
  508. YName: extraConfig.YName,
  509. YNameEn: extraConfig.YNameEn,
  510. YUnitName: extraConfig.YUnitName,
  511. YUnitNameEn: extraConfig.YUnitNameEn,
  512. XMinValue: extraConfig.XMinValue,
  513. XMaxValue: extraConfig.XMaxValue,
  514. YMinValue: extraConfig.YMinValue,
  515. YMaxValue: extraConfig.YMaxValue,
  516. DataList: dataListResp,
  517. }
  518. return
  519. }
  520. // GetChartThemeConfig
  521. // @Description: 根据主题id获取主题信息,如果获取不到的话,那么就获取默认的主题
  522. // @author: Roc
  523. // @datetime 2023-12-19 14:31:17
  524. // @param chartThemeId int
  525. // @param chartType int
  526. // @param source int
  527. // @return chartTheme *chart_theme.ChartTheme
  528. // @return err error
  529. func GetChartThemeConfig(chartThemeId, source, chartType int) (chartTheme *chart_theme.ChartTheme, err error) {
  530. chartTheme, err = chart_theme.GetChartThemeId(chartThemeId)
  531. if err != nil && err.Error() != utils.ErrNoRow() {
  532. return
  533. }
  534. err = nil
  535. // 如果找到了,那么就返回
  536. if chartTheme != nil {
  537. return
  538. }
  539. // 没有找到的话,那么就找默认的主题
  540. // 查找主题类型id
  541. chartThemeType, err := chart_theme.GetChartThemeTypeByChartTypeAndSource(chartType, source)
  542. if err != nil {
  543. return
  544. }
  545. // 寻找默认的主题id
  546. chartTheme, err = chart_theme.GetChartThemeId(chartThemeType.DefaultChartThemeId)
  547. if err != nil && err.Error() != utils.ErrNoRow() {
  548. return
  549. }
  550. err = nil
  551. // 如果找到了,那么就返回
  552. if chartTheme != nil {
  553. return
  554. }
  555. // 如果还是没找到,那就系统的主题id
  556. chartTheme, err = chart_theme.GetSystemChartTheme(chartThemeType.ChartThemeTypeId)
  557. return
  558. }