chart_theme.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. "eta/eta_api/models/data_manage/chart_theme"
  8. "eta/eta_api/models/data_manage/chart_theme/request"
  9. "eta/eta_api/services/data"
  10. "eta/eta_api/services/eta_forum"
  11. "eta/eta_api/utils"
  12. "time"
  13. )
  14. // ChartThemeController
  15. // @Description: 图表主题配置模块
  16. type ChartThemeController struct {
  17. controllers.BaseAuthController
  18. }
  19. // List
  20. // @Title 获取主题列表
  21. // @Description 获取主题列表接口
  22. // @Param ChartThemeTypeId query int true "图表主题类型id"
  23. // @Success 200 {object} []*chart_theme.ChartTheme
  24. // @router /chart/theme/list [get]
  25. func (c *ChartThemeController) List() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. c.Data["json"] = br
  29. c.ServeJSON()
  30. }()
  31. sysUser := c.SysUser
  32. if sysUser == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,SysUser Is Empty"
  35. br.Ret = 408
  36. return
  37. }
  38. chartThemeTypeId, _ := c.GetInt("ChartThemeTypeId")
  39. if chartThemeTypeId <= 0 {
  40. br.Msg = "请选择图表样式类型"
  41. br.ErrMsg = "请选择图表样式类型"
  42. br.IsSendEmail = false
  43. return
  44. }
  45. list, err := chart_theme.GetChartThemeItemList(chartThemeTypeId)
  46. if err != nil {
  47. br.Msg = "获取失败"
  48. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  49. return
  50. }
  51. // 兼容历史数据,加入新字段LineOptionList
  52. for i, v := range list {
  53. newConfig, e := data.ConvertOldChartOptions(v.Config)
  54. if e != nil {
  55. continue
  56. }
  57. list[i].Config = newConfig
  58. }
  59. br.Ret = 200
  60. br.Success = true
  61. br.Msg = "获取成功"
  62. br.Data = list
  63. }
  64. // TypeList
  65. // @Title 获取主题类型列表
  66. // @Description 获取主题类型列表接口
  67. // @Success 200 {object} []*chart_theme.ChartThemeType
  68. // @router /chart/theme/type/list [get]
  69. func (c *ChartThemeController) TypeList() {
  70. br := new(models.BaseResponse).Init()
  71. defer func() {
  72. c.Data["json"] = br
  73. c.ServeJSON()
  74. }()
  75. sysUser := c.SysUser
  76. if sysUser == nil {
  77. br.Msg = "请登录"
  78. br.ErrMsg = "请登录,SysUser Is Empty"
  79. br.Ret = 408
  80. return
  81. }
  82. list, err := chart_theme.GetAllChartThemeTypeList()
  83. if err != nil {
  84. br.Msg = "获取失败"
  85. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  86. return
  87. }
  88. br.Ret = 200
  89. br.Success = true
  90. br.Msg = "获取成功"
  91. br.Data = list
  92. }
  93. // GetThemePreviewData
  94. // @Title 获取默认的预览图表数据
  95. // @Description 获取默认的预览图表数据接口
  96. // @Param ChartThemeTypeId query int true "图表主题类型id"
  97. // @Success 200 {object} data_manage.ChartInfoDetailResp
  98. // @router /chart/theme/preview_data [get]
  99. func (c *ChartThemeController) GetThemePreviewData() {
  100. br := new(models.BaseResponse).Init()
  101. defer func() {
  102. c.Data["json"] = br
  103. c.ServeJSON()
  104. }()
  105. sysUser := c.SysUser
  106. if sysUser == nil {
  107. br.Msg = "请登录"
  108. br.ErrMsg = "请登录,SysUser Is Empty"
  109. br.Ret = 408
  110. return
  111. }
  112. chartThemeTypeId, _ := c.GetInt("ChartThemeTypeId")
  113. if chartThemeTypeId <= 0 {
  114. br.Msg = "请选择图表样式类型"
  115. br.ErrMsg = "请选择图表样式类型"
  116. br.IsSendEmail = false
  117. return
  118. }
  119. chartThemeType, err := chart_theme.GetChartThemeTypeById(chartThemeTypeId)
  120. if err != nil {
  121. br.Msg = "获取失败"
  122. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  123. return
  124. }
  125. dateType := 3 // 曲线图
  126. startYear := 5
  127. chartType := chartThemeType.ChartType
  128. chartInfo := new(data_manage.ChartInfoView)
  129. // 图表额外数据参数
  130. extraConfigStr := ``
  131. var barConfig data_manage.BarChartInfoReq
  132. // 开始时间,结束时间
  133. var tmpStartDate, tmpEndDate string
  134. edbInfoIdList := make([]int, 0) // 指标列表
  135. switch chartType {
  136. case 1: // 曲线图
  137. edbInfoIdList = []int{1, 2, 3, 4, 5}
  138. chartInfo.ChartName = "曲线图"
  139. case 4: // 堆积柱状图
  140. edbInfoIdList = []int{1, 2, 3, 4, 5}
  141. chartInfo.ChartName = "堆积柱状图"
  142. dateType = 5
  143. tmpStartDate = `2021-03-05`
  144. case 6: // 组合图
  145. edbInfoIdList = []int{1, 2, 3, 4, 5}
  146. chartInfo.ChartName = "组合图"
  147. dateType = 5
  148. tmpStartDate = `2021-03-05`
  149. case 2: // 季节性
  150. dateType = 20 // 季节性图
  151. edbInfoIdList = []int{6}
  152. chartInfo.ChartName = "季节性图"
  153. case 5: // 散点图
  154. edbInfoIdList = []int{7, 8}
  155. chartInfo.ChartName = "散点图"
  156. case 7: // 柱形图
  157. edbInfoIdList = []int{1, 2, 3, 4, 5}
  158. chartInfo.LeftMin = "260"
  159. chartInfo.LeftMax = "430"
  160. extraConfigStr = `{"EdbInfoIdList":[{"EdbInfoId":1,"Name":"指标1","NameEn":"","Source":0},{"EdbInfoId":2,"Name":"指标2","NameEn":"","Source":0},{"EdbInfoId":3,"Name":"指标3","NameEn":"","Source":0},{"EdbInfoId":4,"Name":"指标4","NameEn":"","Source":0},{"EdbInfoId":5,"Name":"指标5","NameEn":"","Source":0}],"DateList":[{"Type":2,"Date":"","Value":100,"Color":"","Name":""},{"Type":1,"Date":"","Value":0,"Color":"","Name":""}],"Sort":{"Sort":0,"DateIndex":0},"XEdbList":null,"YEdbList":null,"Unit":"千桶","UnitEn":""}`
  161. chartInfo.ChartName = "柱形图"
  162. case 10: // 截面散点图
  163. edbInfoIdList = []int{9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
  164. extraConfigStr = `{"XName":"123","XNameEn":"123","XUnitName":"无","XUnitNameEn":"none","YName":"321","YNameEn":"321","YUnitName":"无","YUnitNameEn":"none","XMinValue":"230","XMaxValue":"395","YMinValue":"380","YMaxValue":"850","SeriesList":[{"Name":"2021-11-21","NameEn":"2021-11-21","IsNameDefault":true,"Color":"","EdbInfoList":[{"XEdbInfoId":9,"YEdbInfoId":14,"Name":"指标1","NameEn":"","XDateType":1,"XDate":"","XDateValue":0,"YDateType":1,"YDate":"","YDateValue":0,"IsShow":false},{"XEdbInfoId":10,"YEdbInfoId":15,"Name":"指标2","NameEn":"指标2","XDateType":1,"XDate":"","XDateValue":0,"YDateType":1,"YDate":"","YDateValue":0,"IsShow":false},{"XEdbInfoId":11,"YEdbInfoId":16,"Name":"指标3","NameEn":"","XDateType":1,"XDate":"","XDateValue":0,"YDateType":1,"YDate":"","YDateValue":0,"IsShow":false},{"XEdbInfoId":12,"YEdbInfoId":17,"Name":"指标4","NameEn":"指标4","XDateType":1,"XDate":"","XDateValue":0,"YDateType":1,"YDate":"","YDateValue":0,"IsShow":false},{"XEdbInfoId":13,"YEdbInfoId":18,"Name":"指标5","NameEn":"","XDateType":1,"XDate":"","XDateValue":0,"YDateType":1,"YDate":"","YDateValue":0,"IsShow":false}],"ShowTrendLine":false,"ShowFitEquation":false,"ShowRSquare":false}]}`
  165. chartInfo.ChartName = "截面散点图"
  166. case utils.CHART_TYPE_RADAR:
  167. edbInfoIdList = []int{19, 20, 21, 22, 23, 24}
  168. chartInfo.LeftMin = "10000"
  169. chartInfo.LeftMax = "60000"
  170. extraConfigStr = `{"DateList":[{"Type":3,"Date":"2023-11-01","Value":0,"Color":"","Name":""},{"Type":1,"Date":"","Value":0,"Color":"","Name":""}]}`
  171. chartInfo.ChartName = "雷达图"
  172. default:
  173. br.Msg = "暂不支持该类型"
  174. br.IsSendEmail = false
  175. return
  176. }
  177. calendar := "公历"
  178. mappingList, err := chart_theme.GetChartEdbMappingListByEdbInfoId(edbInfoIdList)
  179. if err != nil {
  180. br.Msg = "获取失败"
  181. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  182. return
  183. }
  184. switch chartType {
  185. case 6: // 组合图
  186. mappingList[0].ChartStyle = "spline"
  187. mappingList[1].ChartStyle = "spline"
  188. mappingList[2].ChartStyle = "spline"
  189. mappingList[3].ChartStyle = "column"
  190. mappingList[4].ChartStyle = "column"
  191. }
  192. chartInfo.Source = chartThemeType.ChartSource
  193. chartInfo.ChartType = chartThemeType.ChartType
  194. yearMax := 0
  195. if dateType == utils.DateTypeNYears {
  196. for _, v := range mappingList {
  197. if v.LatestDate != "" {
  198. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  199. if tErr != nil {
  200. br.Msg = "获取失败"
  201. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  202. return
  203. }
  204. if lastDateT.Year() > yearMax {
  205. yearMax = lastDateT.Year()
  206. }
  207. }
  208. }
  209. }
  210. // 开始/结束日期
  211. startDate, endDate := utils.GetDateByDateTypeV2(dateType, tmpStartDate, tmpEndDate, startYear, yearMax)
  212. // 获取图表中的指标数据
  213. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetThemePreviewChartEdbData(chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  214. if err != nil {
  215. br.Msg = "获取失败"
  216. if errMsg != `` {
  217. br.Msg = errMsg
  218. }
  219. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  220. return
  221. }
  222. switch chartType {
  223. case 6: // 组合图
  224. edbList[0].MaxData = 1000
  225. case 4: // 堆积柱状图
  226. edbList[0].MaxData = 2500
  227. }
  228. // 单位
  229. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  230. chartInfo.Unit = yDataList[0].Unit
  231. chartInfo.UnitEn = yDataList[0].UnitEn
  232. }
  233. resp := new(data_manage.ChartInfoDetailResp)
  234. resp.ChartInfo = chartInfo
  235. resp.EdbInfoList = edbList
  236. resp.XEdbIdValue = xEdbIdValue
  237. resp.YDataList = yDataList
  238. resp.DataResp = dataResp
  239. resp.BarChartInfo = barConfig
  240. br.Ret = 200
  241. br.Success = true
  242. br.Msg = "获取成功"
  243. br.Data = resp
  244. }
  245. // Add
  246. // @Title 新增主题
  247. // @Description
  248. // @Param request body request.DeleteThemeConfReq true "type json string"
  249. // @Success 200 Ret=200 添加成功
  250. // @router /chart/theme/add [post]
  251. func (c *ChartThemeController) Add() {
  252. br := new(models.BaseResponse).Init()
  253. defer func() {
  254. c.Data["json"] = br
  255. c.ServeJSON()
  256. }()
  257. sysUser := c.SysUser
  258. if sysUser == nil {
  259. br.Msg = "请登录"
  260. br.ErrMsg = "请登录,SysUser Is Empty"
  261. br.Ret = 408
  262. return
  263. }
  264. var req request.AddThemeReq
  265. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  266. if err != nil {
  267. br.Msg = "参数解析异常!"
  268. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  269. return
  270. }
  271. if req.ChartThemeTypeId <= 0 {
  272. br.Msg = "请选择图表类型"
  273. br.IsSendEmail = false
  274. return
  275. }
  276. req.ChartThemeName = utils.TrimLRStr(req.ChartThemeName)
  277. if req.ChartThemeName == `` {
  278. br.Msg = "请输入主题名称"
  279. br.IsSendEmail = false
  280. return
  281. }
  282. // 获取系统默认配置
  283. systemChartTheme, err := chart_theme.GetSystemChartTheme(req.ChartThemeTypeId)
  284. if err != nil {
  285. br.Msg = "添加失败"
  286. br.ErrMsg = "添加失败,查询系统默认配置异常,Err:" + err.Error()
  287. return
  288. }
  289. chartTheme := &chart_theme.ChartTheme{
  290. ChartThemeId: 0,
  291. ChartThemeName: req.ChartThemeName,
  292. ChartThemeTypeId: req.ChartThemeTypeId,
  293. Config: systemChartTheme.Config,
  294. ChartImage: systemChartTheme.ChartImage,
  295. IsDelete: 0,
  296. SysUserId: sysUser.AdminId,
  297. SysUserRealName: sysUser.RealName,
  298. ModifyTime: time.Now(),
  299. CreateTime: time.Now(),
  300. }
  301. // 添加入库
  302. err = chartTheme.Add()
  303. if err != nil {
  304. br.Msg = "添加失败"
  305. br.ErrMsg = "添加失败,Err:" + err.Error()
  306. return
  307. }
  308. go eta_forum.ChartThemeSave(chartTheme)
  309. br.Ret = 200
  310. br.Success = true
  311. br.Msg = "添加成功"
  312. }
  313. // Edit
  314. // @Title 编辑主题
  315. // @Description
  316. // @Param request body request.DeleteThemeConfReq true "type json string"
  317. // @Success 200 Ret=200 修改成功
  318. // @router /chart/theme/edit [post]
  319. func (c *ChartThemeController) Edit() {
  320. br := new(models.BaseResponse).Init()
  321. defer func() {
  322. c.Data["json"] = br
  323. c.ServeJSON()
  324. }()
  325. sysUser := c.SysUser
  326. if sysUser == nil {
  327. br.Msg = "请登录"
  328. br.ErrMsg = "请登录,SysUser Is Empty"
  329. br.Ret = 408
  330. return
  331. }
  332. var req request.EditThemeReq
  333. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  334. if err != nil {
  335. br.Msg = "参数解析异常!"
  336. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  337. return
  338. }
  339. if req.ChartThemeId < 0 {
  340. br.Msg = "请选择配置"
  341. br.IsSendEmail = false
  342. return
  343. }
  344. // 获取配置
  345. chartTheme, err := chart_theme.GetChartThemeId(req.ChartThemeId)
  346. if err != nil {
  347. if err.Error() == utils.ErrNoRow() {
  348. br.Msg = "主题不存在或已删除"
  349. br.ErrMsg = "主题不存在或已删除"
  350. br.IsSendEmail = false
  351. } else {
  352. br.Msg = "获取失败"
  353. br.ErrMsg = "获取图表配置信息失败,Err:" + err.Error()
  354. }
  355. return
  356. }
  357. // 更新
  358. if req.ChartThemeName != `` {
  359. chartTheme.ChartThemeName = req.ChartThemeName
  360. }
  361. if req.Config != `` {
  362. chartTheme.Config = req.Config
  363. }
  364. if req.ChartImage != `` {
  365. chartTheme.ChartImage = req.ChartImage
  366. }
  367. chartTheme.ModifyTime = time.Now()
  368. err = chartTheme.Update([]string{"ChartThemeName", "Config", "ChartImage", "ModifyTime"})
  369. if err != nil {
  370. br.Msg = "修改失败"
  371. br.ErrMsg = "修改失败,Err:" + err.Error()
  372. return
  373. }
  374. go eta_forum.ChartThemeSave(chartTheme)
  375. br.Ret = 200
  376. br.Success = true
  377. br.Msg = "修改成功"
  378. }
  379. // Delete
  380. // @Title 删除主题
  381. // @Description
  382. // @Param request body request.DeleteThemeConfReq true "type json string"
  383. // @Success 200 Ret=200 删除成功
  384. // @router /chart/theme/delete [post]
  385. func (c *ChartThemeController) Delete() {
  386. br := new(models.BaseResponse).Init()
  387. defer func() {
  388. c.Data["json"] = br
  389. c.ServeJSON()
  390. }()
  391. sysUser := c.SysUser
  392. if sysUser == nil {
  393. br.Msg = "请登录"
  394. br.ErrMsg = "请登录,SysUser Is Empty"
  395. br.Ret = 408
  396. return
  397. }
  398. var req request.DeleteThemeReq
  399. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  400. if err != nil {
  401. br.Msg = "参数解析异常!"
  402. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  403. return
  404. }
  405. if req.ChartThemeId < 0 {
  406. br.Msg = "请选择配置"
  407. br.IsSendEmail = false
  408. return
  409. }
  410. // 获取配置
  411. chartTheme, err := chart_theme.GetChartThemeId(req.ChartThemeId)
  412. if err != nil {
  413. if err.Error() == utils.ErrNoRow() {
  414. br.Msg = "主题不存在或已删除"
  415. br.ErrMsg = "主题不存在或已删除"
  416. br.IsSendEmail = false
  417. } else {
  418. br.Msg = "获取失败"
  419. br.ErrMsg = "获取图表配置信息失败,Err:" + err.Error()
  420. }
  421. return
  422. }
  423. if chartTheme.IsSystemTheme == 1 {
  424. br.Msg = "系统默认配置,无法删除"
  425. br.ErrMsg = "系统默认配置,无法删除"
  426. br.IsSendEmail = false
  427. return
  428. }
  429. // 根据给定的图表主题类型ID获取图表主题类型
  430. chartThemeType, err := chart_theme.GetChartThemeTypeById(chartTheme.ChartThemeTypeId)
  431. if err != nil {
  432. br.Msg = "获取失败"
  433. br.ErrMsg = "获取图表主题类型信息失败,Err:" + err.Error()
  434. return
  435. }
  436. // 判断是否是配置为默认设置,如果已经设置了,那么不能删除
  437. if chartThemeType.DefaultChartThemeId == chartTheme.ChartThemeId {
  438. br.Msg = "该主题已经配置为默认设置,不允许删除"
  439. br.ErrMsg = "该主题已经配置为默认设置,不允许删除"
  440. br.IsSendEmail = false
  441. return
  442. }
  443. // 更新
  444. chartTheme.IsDelete = 1
  445. err = chartTheme.Update([]string{"IsDelete"})
  446. if err != nil {
  447. br.Msg = "删除失败"
  448. br.ErrMsg = "删除失败,Err:" + err.Error()
  449. return
  450. }
  451. go eta_forum.ChartThemeSave(chartTheme)
  452. br.Ret = 200
  453. br.Success = true
  454. br.Msg = "删除成功"
  455. }
  456. // SetDefaultTheme
  457. // @Title 配置默认主题
  458. // @Description 配置默认主题
  459. // @Param request body request.DeleteThemeConfReq true "type json string"
  460. // @Success 200 Ret=200 配置成功
  461. // @router /chart/theme/set_default [post]
  462. func (c *ChartThemeController) SetDefaultTheme() {
  463. br := new(models.BaseResponse).Init()
  464. defer func() {
  465. c.Data["json"] = br
  466. c.ServeJSON()
  467. }()
  468. sysUser := c.SysUser
  469. if sysUser == nil {
  470. br.Msg = "请登录"
  471. br.ErrMsg = "请登录,SysUser Is Empty"
  472. br.Ret = 408
  473. return
  474. }
  475. var req request.SetDefaultThemeReq
  476. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  477. if err != nil {
  478. br.Msg = "参数解析异常!"
  479. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  480. return
  481. }
  482. if req.ChartThemeId < 0 {
  483. br.Msg = "请选择配置"
  484. br.IsSendEmail = false
  485. return
  486. }
  487. if req.ChartThemeTypeId < 0 {
  488. br.Msg = "请选择图表类型"
  489. br.IsSendEmail = false
  490. return
  491. }
  492. // 获取图表配置
  493. chartTheme, err := chart_theme.GetChartThemeId(req.ChartThemeId)
  494. if err != nil {
  495. if err.Error() == utils.ErrNoRow() {
  496. br.Msg = "主题不存在或已删除"
  497. br.ErrMsg = "主题不存在或已删除"
  498. br.IsSendEmail = false
  499. } else {
  500. br.Msg = "获取失败"
  501. br.ErrMsg = "获取图表配置信息失败,Err:" + err.Error()
  502. }
  503. return
  504. }
  505. // 获取图表类型
  506. chartThemeType, err := chart_theme.GetChartThemeTypeById(req.ChartThemeTypeId)
  507. if err != nil {
  508. if err.Error() == utils.ErrNoRow() {
  509. br.Msg = "获取图表类型不存在或已删除"
  510. br.ErrMsg = "获取图表类型不存在或已删除"
  511. br.IsSendEmail = false
  512. } else {
  513. br.Msg = "获取失败"
  514. br.ErrMsg = "获取图表配置信息失败,Err:" + err.Error()
  515. }
  516. return
  517. }
  518. // 判断主题与图表类型是否相符
  519. if chartTheme.ChartThemeTypeId != chartThemeType.ChartThemeTypeId {
  520. br.Msg = "主题与图表类型不符"
  521. br.ErrMsg = "主题与图表类型不符"
  522. br.IsSendEmail = false
  523. return
  524. }
  525. // 更新
  526. chartThemeType.DefaultChartThemeId = chartTheme.ChartThemeId
  527. chartThemeType.ModifyTime = time.Now()
  528. err = chartThemeType.Update([]string{"DefaultChartThemeId", "ModifyTime"})
  529. if err != nil {
  530. br.Msg = "配置失败"
  531. br.ErrMsg = "配置失败,Err:" + err.Error()
  532. return
  533. }
  534. go eta_forum.ChartThemeTypeSave(chartThemeType)
  535. br.Ret = 200
  536. br.Success = true
  537. br.Msg = "配置成功"
  538. }
  539. // TypeListBySource
  540. // @Title 根据来源获取主题类型列表
  541. // @Description 获取主题类型列表接口
  542. // @Param Source query int true "图表主题类型id"
  543. // @Success 200 {object} []*chart_theme.ChartThemeType
  544. // @router /chart/theme/type/list_by_source [get]
  545. func (c *ChartThemeController) TypeListBySource() {
  546. br := new(models.BaseResponse).Init()
  547. defer func() {
  548. c.Data["json"] = br
  549. c.ServeJSON()
  550. }()
  551. sysUser := c.SysUser
  552. if sysUser == nil {
  553. br.Msg = "请登录"
  554. br.ErrMsg = "请登录,SysUser Is Empty"
  555. br.Ret = 408
  556. return
  557. }
  558. source, _ := c.GetInt("Source")
  559. if source <= 0 {
  560. br.Msg = "请选择来源"
  561. br.ErrMsg = "请选择来源"
  562. br.IsSendEmail = false
  563. return
  564. }
  565. list, err := chart_theme.GetChartThemeTypeListBySource(source)
  566. if err != nil {
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  569. return
  570. }
  571. br.Ret = 200
  572. br.Success = true
  573. br.Msg = "获取成功"
  574. br.Data = list
  575. }
  576. // ListBySource
  577. // @Title 根据来源获取主题列表
  578. // @Description 获取主题列表接口
  579. // @Param ChartType query int true "图表类型"
  580. // @Param Source query int true "来源"
  581. // @Success 200 {object} []*chart_theme.ChartTheme
  582. // @router /chart/theme/list_by_source [get]
  583. func (c *ChartThemeController) ListBySource() {
  584. br := new(models.BaseResponse).Init()
  585. defer func() {
  586. c.Data["json"] = br
  587. c.ServeJSON()
  588. }()
  589. sysUser := c.SysUser
  590. if sysUser == nil {
  591. br.Msg = "请登录"
  592. br.ErrMsg = "请登录,SysUser Is Empty"
  593. br.Ret = 408
  594. return
  595. }
  596. chartType, _ := c.GetInt("ChartType")
  597. if chartType < 0 {
  598. br.Msg = "请选择图表类型"
  599. br.ErrMsg = "请选择图表类型"
  600. br.IsSendEmail = false
  601. return
  602. }
  603. source, _ := c.GetInt("Source")
  604. if chartType < 0 {
  605. br.Msg = "请选择图表来源"
  606. br.ErrMsg = "请选择图表来源"
  607. br.IsSendEmail = false
  608. return
  609. }
  610. chartThemeType, err := chart_theme.GetChartThemeTypeByChartTypeAndSource(chartType, source)
  611. if err != nil {
  612. br.Msg = "获取失败"
  613. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  614. return
  615. }
  616. list, err := chart_theme.GetChartThemeItemList(chartThemeType.ChartThemeTypeId)
  617. if err != nil {
  618. br.Msg = "获取失败"
  619. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  620. return
  621. }
  622. // 兼容历史数据,加入新字段LineOptionList
  623. for i, v := range list {
  624. newConfig, e := data.ConvertOldChartOptions(v.Config)
  625. if e != nil {
  626. continue
  627. }
  628. list[i].Config = newConfig
  629. }
  630. br.Ret = 200
  631. br.Success = true
  632. br.Msg = "获取成功"
  633. br.Data = list
  634. }