chart_theme.go 21 KB

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