chart_theme.go 19 KB

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