chart_theme.go 18 KB

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