chart_theme.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/data_manage/chart_theme"
  8. "eta_gn/eta_api/models/data_manage/chart_theme/request"
  9. "eta_gn/eta_api/services/data"
  10. "eta_gn/eta_api/services/eta_forum"
  11. "eta_gn/eta_api/utils"
  12. "time"
  13. )
  14. type ChartThemeController struct {
  15. controllers.BaseAuthController
  16. }
  17. // @router /chart/theme/list [get]
  18. func (c *ChartThemeController) List() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. c.Data["json"] = br
  22. c.ServeJSON()
  23. }()
  24. sysUser := c.SysUser
  25. if sysUser == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,SysUser Is Empty"
  28. br.Ret = 408
  29. return
  30. }
  31. chartThemeTypeId, _ := c.GetInt("ChartThemeTypeId")
  32. if chartThemeTypeId <= 0 {
  33. br.Msg = "请选择图表样式类型"
  34. br.ErrMsg = "请选择图表样式类型"
  35. br.IsSendEmail = false
  36. return
  37. }
  38. list, err := chart_theme.GetChartThemeItemList(chartThemeTypeId)
  39. if err != nil {
  40. br.Msg = "获取失败"
  41. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  42. return
  43. }
  44. for i, v := range list {
  45. newConfig, e := data.ConvertOldChartOptions(v.Config)
  46. if e != nil {
  47. continue
  48. }
  49. list[i].Config = newConfig
  50. }
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. br.Data = list
  55. }
  56. // @router /chart/theme/type/list [get]
  57. func (c *ChartThemeController) TypeList() {
  58. br := new(models.BaseResponse).Init()
  59. defer func() {
  60. c.Data["json"] = br
  61. c.ServeJSON()
  62. }()
  63. sysUser := c.SysUser
  64. if sysUser == nil {
  65. br.Msg = "请登录"
  66. br.ErrMsg = "请登录,SysUser Is Empty"
  67. br.Ret = 408
  68. return
  69. }
  70. listTmp, err := chart_theme.GetAllChartThemeTypeList()
  71. if err != nil {
  72. br.Msg = "获取失败"
  73. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  74. return
  75. }
  76. chartTypeMap := make(map[int][]*chart_theme.ChartThemeTypeList)
  77. for _, v := range listTmp {
  78. if v.ParentId > 0 {
  79. chartTypeMap[v.ParentId] = append(chartTypeMap[v.ParentId], v)
  80. }
  81. }
  82. list := make([]*chart_theme.ChartThemeTypeList, 0)
  83. for _, v := range listTmp {
  84. if v.ParentId == 0 {
  85. tmp := v
  86. child, ok := chartTypeMap[v.ChartType]
  87. if ok {
  88. tmp.Child = child
  89. }
  90. list = append(list, tmp)
  91. }
  92. }
  93. br.Ret = 200
  94. br.Success = true
  95. br.Msg = "获取成功"
  96. br.Data = list
  97. }
  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. extraConfigStr := ``
  130. var tmpStartDate, tmpEndDate string
  131. edbInfoIdList := make([]int, 0) // 指标列表
  132. switch chartType {
  133. case 1: // 曲线图
  134. edbInfoIdList = []int{1, 2, 3, 4, 5}
  135. chartInfo.ChartName = "曲线图"
  136. case 4: // 堆积柱状图
  137. edbInfoIdList = []int{1, 2, 3, 4, 5}
  138. chartInfo.ChartName = "堆积柱状图"
  139. dateType = 5
  140. tmpStartDate = `2021-03-05`
  141. case 6: // 组合图
  142. edbInfoIdList = []int{1, 2, 3, 4, 5}
  143. chartInfo.ChartName = "组合图"
  144. dateType = 5
  145. tmpStartDate = `2021-03-05`
  146. case 2: // 季节性
  147. dateType = 20 // 季节性图
  148. edbInfoIdList = []int{6}
  149. chartInfo.ChartName = "季节性图"
  150. case 5: // 散点图
  151. edbInfoIdList = []int{7, 8}
  152. chartInfo.ChartName = "散点图"
  153. case 7: // 柱形图
  154. edbInfoIdList = []int{1, 2, 3, 4, 5}
  155. 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":""}`
  156. chartInfo.ChartName = "柱形图"
  157. case 10: // 截面散点图
  158. edbInfoIdList = []int{9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
  159. 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}]}`
  160. chartInfo.ChartName = "截面散点图"
  161. case utils.CHART_TYPE_RADAR:
  162. edbInfoIdList = []int{19, 20, 21, 22, 23, 24}
  163. chartInfo.LeftMin = "10000"
  164. chartInfo.LeftMax = "60000"
  165. extraConfigStr = `{"DateList":[{"Type":3,"Date":"2023-11-01","Value":0,"Color":"","Name":""},{"Type":1,"Date":"","Value":0,"Color":"","Name":""}]}`
  166. chartInfo.ChartName = "雷达图"
  167. case utils.CHART_TYPE_SECTION_COMBINE:
  168. edbInfoIdList = []int{19, 20, 21, 22, 23, 24, 25, 28}
  169. chartInfo.LeftMin = "0"
  170. chartInfo.LeftMax = "4000"
  171. extraConfigStr = `{"DateConfList":[],"IsHeap":0,"XDataList":[{"Name":"内销"},{"Name":"出口"},{"Name":"销量"},{"Name":"产量"}],"UnitList":{"LeftName":"万台","RightName":"%","RightTwoName":""},"BaseChartSeriesName":"增量","SortType":0,"SeriesList":[{"ChartSeriesId":0,"SeriesName":"增量","ChartStyle":"column","ChartColor":"rgba(0, 0, 255, 1)","ChartWidth":1,"IsPoint":0,"IsNumber":0,"IsAxis":1,"EdbInfoList":[{"ChartSeriesEdbMappingId":0,"ChartSeriesId":0,"EdbInfoId":19,"DateConfName":"","DateConfType":0,"DateConf":{"MoveForward":0,"DateChange":[]}},{"ChartSeriesEdbMappingId":0,"ChartSeriesId":0,"EdbInfoId":20,"DateConfName":"","DateConfType":0,"DateConf":{"MoveForward":0,"DateChange":[]}},{"ChartSeriesEdbMappingId":0,"ChartSeriesId":0,"EdbInfoId":21,"DateConfName":"","DateConfType":0,"DateConf":{"MoveForward":0,"DateChange":[]}},{"ChartSeriesEdbMappingId":0,"ChartSeriesId":0,"EdbInfoId":22,"DateConfName":"","DateConfType":0,"DateConf":{"MoveForward":0,"DateChange":[]}}]},{"ChartSeriesId":0,"SeriesName":"增速","ChartStyle":"spline","ChartColor":"rgba(255, 0, 200, 1)","ChartWidth":1,"IsPoint":0,"IsNumber":0,"IsAxis":0,"EdbInfoList":[{"ChartSeriesEdbMappingId":0,"ChartSeriesId":0,"EdbInfoId":23,"DateConfName":"","DateConfType":0,"DateConf":{"MoveForward":0,"DateChange":[]}},{"ChartSeriesEdbMappingId":0,"ChartSeriesId":0,"EdbInfoId":24,"DateConfName":"","DateConfType":0,"DateConf":{"MoveForward":0,"DateChange":[]}},{"ChartSeriesEdbMappingId":0,"ChartSeriesId":0,"EdbInfoId":25,"DateConfName":"","DateConfType":0,"DateConf":{"MoveForward":0,"DateChange":[]}},{"ChartSeriesEdbMappingId":0,"ChartSeriesId":0,"EdbInfoId":26,"DateConfName":"","DateConfType":0,"DateConf":{"MoveForward":0,"DateChange":[]}}]}]}`
  172. chartInfo.ChartName = "图表标题"
  173. default:
  174. br.Msg = "暂不支持该类型"
  175. br.IsSendEmail = false
  176. return
  177. }
  178. calendar := "公历"
  179. mappingList, err := chart_theme.GetChartEdbMappingListByEdbInfoId(edbInfoIdList)
  180. if err != nil {
  181. br.Msg = "获取失败"
  182. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  183. return
  184. }
  185. switch chartType {
  186. case 6: // 组合图
  187. mappingList[0].ChartStyle = "spline"
  188. mappingList[1].ChartStyle = "spline"
  189. mappingList[2].ChartStyle = "spline"
  190. mappingList[3].ChartStyle = "column"
  191. mappingList[4].ChartStyle = "column"
  192. }
  193. chartInfo.Source = chartThemeType.ChartSource
  194. chartInfo.ChartType = chartThemeType.ChartType
  195. yearMax := 0
  196. if dateType == utils.DateTypeNYears {
  197. for _, v := range mappingList {
  198. v.ConvertToResp()
  199. if v.LatestDate != "" {
  200. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  201. if tErr != nil {
  202. br.Msg = "获取失败"
  203. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  204. return
  205. }
  206. if lastDateT.Year() > yearMax {
  207. yearMax = lastDateT.Year()
  208. }
  209. }
  210. }
  211. }
  212. startDate, endDate := utils.GetDateByDateTypeV2(dateType, tmpStartDate, tmpEndDate, startYear, yearMax)
  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. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  229. chartInfo.Unit = yDataList[0].Unit
  230. chartInfo.UnitEn = yDataList[0].UnitEn
  231. }
  232. resp := new(data_manage.ChartInfoDetailResp)
  233. resp.ChartInfo = chartInfo
  234. resp.EdbInfoList = edbList
  235. resp.XEdbIdValue = xEdbIdValue
  236. resp.YDataList = yDataList
  237. resp.DataResp = dataResp
  238. br.Ret = 200
  239. br.Success = true
  240. br.Msg = "获取成功"
  241. br.Data = resp
  242. }
  243. // @router /chart/theme/add [post]
  244. func (c *ChartThemeController) Add() {
  245. br := new(models.BaseResponse).Init()
  246. defer func() {
  247. c.Data["json"] = br
  248. c.ServeJSON()
  249. }()
  250. sysUser := c.SysUser
  251. if sysUser == nil {
  252. br.Msg = "请登录"
  253. br.ErrMsg = "请登录,SysUser Is Empty"
  254. br.Ret = 408
  255. return
  256. }
  257. var req request.AddThemeReq
  258. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  259. if err != nil {
  260. br.Msg = "参数解析异常!"
  261. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  262. return
  263. }
  264. if req.ChartThemeTypeId <= 0 {
  265. br.Msg = "请选择图表类型"
  266. br.IsSendEmail = false
  267. return
  268. }
  269. req.ChartThemeName = utils.TrimLRStr(req.ChartThemeName)
  270. if req.ChartThemeName == `` {
  271. br.Msg = "请输入主题名称"
  272. br.IsSendEmail = false
  273. return
  274. }
  275. systemChartTheme, err := chart_theme.GetSystemChartTheme(req.ChartThemeTypeId)
  276. if err != nil {
  277. br.Msg = "添加失败"
  278. br.ErrMsg = "添加失败,查询系统默认配置异常,Err:" + err.Error()
  279. return
  280. }
  281. chartTheme := &chart_theme.ChartTheme{
  282. ChartThemeId: 0,
  283. ChartThemeName: req.ChartThemeName,
  284. ChartThemeTypeId: req.ChartThemeTypeId,
  285. Config: systemChartTheme.Config,
  286. ChartImage: systemChartTheme.ChartImage,
  287. IsDelete: 0,
  288. SysUserId: sysUser.AdminId,
  289. SysUserRealName: sysUser.RealName,
  290. ModifyTime: time.Now(),
  291. CreateTime: time.Now(),
  292. }
  293. err = chartTheme.Add()
  294. if err != nil {
  295. br.Msg = "添加失败"
  296. br.ErrMsg = "添加失败,Err:" + err.Error()
  297. return
  298. }
  299. go eta_forum.ChartThemeSave(chartTheme)
  300. br.Ret = 200
  301. br.Success = true
  302. br.Msg = "添加成功"
  303. }
  304. // @router /chart/theme/edit [post]
  305. func (c *ChartThemeController) Edit() {
  306. br := new(models.BaseResponse).Init()
  307. defer func() {
  308. c.Data["json"] = br
  309. c.ServeJSON()
  310. }()
  311. sysUser := c.SysUser
  312. if sysUser == nil {
  313. br.Msg = "请登录"
  314. br.ErrMsg = "请登录,SysUser Is Empty"
  315. br.Ret = 408
  316. return
  317. }
  318. var req request.EditThemeReq
  319. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  320. if err != nil {
  321. br.Msg = "参数解析异常!"
  322. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  323. return
  324. }
  325. if req.ChartThemeId < 0 {
  326. br.Msg = "请选择配置"
  327. br.IsSendEmail = false
  328. return
  329. }
  330. chartTheme, err := chart_theme.GetChartThemeId(req.ChartThemeId)
  331. if err != nil {
  332. if utils.IsErrNoRow(err) {
  333. br.Msg = "主题不存在或已删除"
  334. br.ErrMsg = "主题不存在或已删除"
  335. br.IsSendEmail = false
  336. } else {
  337. br.Msg = "获取失败"
  338. br.ErrMsg = "获取图表配置信息失败,Err:" + err.Error()
  339. }
  340. return
  341. }
  342. if req.ChartThemeName != `` {
  343. chartTheme.ChartThemeName = req.ChartThemeName
  344. }
  345. if req.Config != `` {
  346. chartTheme.Config = req.Config
  347. }
  348. if req.ChartImage != `` {
  349. chartTheme.ChartImage = req.ChartImage
  350. }
  351. chartTheme.ModifyTime = time.Now()
  352. err = chartTheme.Update([]string{"ChartThemeName", "Config", "ChartImage", "ModifyTime"})
  353. if err != nil {
  354. br.Msg = "修改失败"
  355. br.ErrMsg = "修改失败,Err:" + err.Error()
  356. return
  357. }
  358. go eta_forum.ChartThemeSave(chartTheme)
  359. br.Ret = 200
  360. br.Success = true
  361. br.Msg = "修改成功"
  362. }
  363. // @router /chart/theme/delete [post]
  364. func (c *ChartThemeController) Delete() {
  365. br := new(models.BaseResponse).Init()
  366. defer func() {
  367. c.Data["json"] = br
  368. c.ServeJSON()
  369. }()
  370. sysUser := c.SysUser
  371. if sysUser == nil {
  372. br.Msg = "请登录"
  373. br.ErrMsg = "请登录,SysUser Is Empty"
  374. br.Ret = 408
  375. return
  376. }
  377. var req request.DeleteThemeReq
  378. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  379. if err != nil {
  380. br.Msg = "参数解析异常!"
  381. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  382. return
  383. }
  384. if req.ChartThemeId < 0 {
  385. br.Msg = "请选择配置"
  386. br.IsSendEmail = false
  387. return
  388. }
  389. chartTheme, err := chart_theme.GetChartThemeId(req.ChartThemeId)
  390. if err != nil {
  391. if utils.IsErrNoRow(err) {
  392. br.Msg = "主题不存在或已删除"
  393. br.ErrMsg = "主题不存在或已删除"
  394. br.IsSendEmail = false
  395. } else {
  396. br.Msg = "获取失败"
  397. br.ErrMsg = "获取图表配置信息失败,Err:" + err.Error()
  398. }
  399. return
  400. }
  401. if chartTheme.IsSystemTheme == 1 {
  402. br.Msg = "系统默认配置,无法删除"
  403. br.ErrMsg = "系统默认配置,无法删除"
  404. br.IsSendEmail = false
  405. return
  406. }
  407. chartThemeType, err := chart_theme.GetChartThemeTypeById(chartTheme.ChartThemeTypeId)
  408. if err != nil {
  409. br.Msg = "获取失败"
  410. br.ErrMsg = "获取图表主题类型信息失败,Err:" + err.Error()
  411. return
  412. }
  413. if chartThemeType.DefaultChartThemeId == chartTheme.ChartThemeId {
  414. br.Msg = "该主题已经配置为默认设置,不允许删除"
  415. br.ErrMsg = "该主题已经配置为默认设置,不允许删除"
  416. br.IsSendEmail = false
  417. return
  418. }
  419. chartTheme.IsDelete = 1
  420. err = chartTheme.Update([]string{"IsDelete"})
  421. if err != nil {
  422. br.Msg = "删除失败"
  423. br.ErrMsg = "删除失败,Err:" + err.Error()
  424. return
  425. }
  426. go eta_forum.ChartThemeSave(chartTheme)
  427. br.Ret = 200
  428. br.Success = true
  429. br.Msg = "删除成功"
  430. }
  431. // @router /chart/theme/set_default [post]
  432. func (c *ChartThemeController) SetDefaultTheme() {
  433. br := new(models.BaseResponse).Init()
  434. defer func() {
  435. c.Data["json"] = br
  436. c.ServeJSON()
  437. }()
  438. sysUser := c.SysUser
  439. if sysUser == nil {
  440. br.Msg = "请登录"
  441. br.ErrMsg = "请登录,SysUser Is Empty"
  442. br.Ret = 408
  443. return
  444. }
  445. var req request.SetDefaultThemeReq
  446. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  447. if err != nil {
  448. br.Msg = "参数解析异常!"
  449. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  450. return
  451. }
  452. if req.ChartThemeId < 0 {
  453. br.Msg = "请选择配置"
  454. br.IsSendEmail = false
  455. return
  456. }
  457. if req.ChartThemeTypeId < 0 {
  458. br.Msg = "请选择图表类型"
  459. br.IsSendEmail = false
  460. return
  461. }
  462. chartTheme, err := chart_theme.GetChartThemeId(req.ChartThemeId)
  463. if err != nil {
  464. if utils.IsErrNoRow(err) {
  465. br.Msg = "主题不存在或已删除"
  466. br.ErrMsg = "主题不存在或已删除"
  467. br.IsSendEmail = false
  468. } else {
  469. br.Msg = "获取失败"
  470. br.ErrMsg = "获取图表配置信息失败,Err:" + err.Error()
  471. }
  472. return
  473. }
  474. chartThemeType, err := chart_theme.GetChartThemeTypeById(req.ChartThemeTypeId)
  475. if err != nil {
  476. if utils.IsErrNoRow(err) {
  477. br.Msg = "获取图表类型不存在或已删除"
  478. br.ErrMsg = "获取图表类型不存在或已删除"
  479. br.IsSendEmail = false
  480. } else {
  481. br.Msg = "获取失败"
  482. br.ErrMsg = "获取图表配置信息失败,Err:" + err.Error()
  483. }
  484. return
  485. }
  486. if chartTheme.ChartThemeTypeId != chartThemeType.ChartThemeTypeId {
  487. br.Msg = "主题与图表类型不符"
  488. br.ErrMsg = "主题与图表类型不符"
  489. br.IsSendEmail = false
  490. return
  491. }
  492. chartThemeType.DefaultChartThemeId = chartTheme.ChartThemeId
  493. chartThemeType.ModifyTime = time.Now()
  494. err = chartThemeType.Update([]string{"DefaultChartThemeId", "ModifyTime"})
  495. if err != nil {
  496. br.Msg = "配置失败"
  497. br.ErrMsg = "配置失败,Err:" + err.Error()
  498. return
  499. }
  500. go eta_forum.ChartThemeTypeSave(chartThemeType)
  501. br.Ret = 200
  502. br.Success = true
  503. br.Msg = "配置成功"
  504. }
  505. // @router /chart/theme/type/list_by_source [get]
  506. func (c *ChartThemeController) TypeListBySource() {
  507. br := new(models.BaseResponse).Init()
  508. defer func() {
  509. c.Data["json"] = br
  510. c.ServeJSON()
  511. }()
  512. sysUser := c.SysUser
  513. if sysUser == nil {
  514. br.Msg = "请登录"
  515. br.ErrMsg = "请登录,SysUser Is Empty"
  516. br.Ret = 408
  517. return
  518. }
  519. source, _ := c.GetInt("Source")
  520. if source <= 0 {
  521. br.Msg = "请选择来源"
  522. br.ErrMsg = "请选择来源"
  523. br.IsSendEmail = false
  524. return
  525. }
  526. list, err := chart_theme.GetChartThemeTypeListBySource(source)
  527. if err != nil {
  528. br.Msg = "获取失败"
  529. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  530. return
  531. }
  532. br.Ret = 200
  533. br.Success = true
  534. br.Msg = "获取成功"
  535. br.Data = list
  536. }
  537. // @router /chart/theme/list_by_source [get]
  538. func (c *ChartThemeController) ListBySource() {
  539. br := new(models.BaseResponse).Init()
  540. defer func() {
  541. c.Data["json"] = br
  542. c.ServeJSON()
  543. }()
  544. sysUser := c.SysUser
  545. if sysUser == nil {
  546. br.Msg = "请登录"
  547. br.ErrMsg = "请登录,SysUser Is Empty"
  548. br.Ret = 408
  549. return
  550. }
  551. chartType, _ := c.GetInt("ChartType")
  552. if chartType < 0 {
  553. br.Msg = "请选择图表类型"
  554. br.ErrMsg = "请选择图表类型"
  555. br.IsSendEmail = false
  556. return
  557. }
  558. source, _ := c.GetInt("Source")
  559. if chartType < 0 {
  560. br.Msg = "请选择图表来源"
  561. br.ErrMsg = "请选择图表来源"
  562. br.IsSendEmail = false
  563. return
  564. }
  565. chartThemeType, err := chart_theme.GetChartThemeTypeByChartTypeAndSource(chartType, source)
  566. if err != nil {
  567. br.Msg = "获取失败"
  568. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  569. return
  570. }
  571. list, err := chart_theme.GetChartThemeItemList(chartThemeType.ChartThemeTypeId)
  572. if err != nil {
  573. br.Msg = "获取失败"
  574. br.ErrMsg = "获取图表样式类型信息失败,Err:" + err.Error()
  575. return
  576. }
  577. for i, v := range list {
  578. newConfig, e := data.ConvertOldChartOptions(v.Config)
  579. if e != nil {
  580. continue
  581. }
  582. list[i].Config = newConfig
  583. }
  584. br.Ret = 200
  585. br.Success = true
  586. br.Msg = "获取成功"
  587. br.Data = list
  588. }