chart_info_excel_balance.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. package data
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/chart_theme"
  7. excelModel "eta/eta_api/models/data_manage/excel"
  8. "eta/eta_api/models/data_manage/excel/request"
  9. "eta/eta_api/models/system"
  10. "eta/eta_api/utils"
  11. "fmt"
  12. "math"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // AddBalanceExcelChart 添加平衡表图表
  18. func AddBalanceExcelChart(req request.AddBalanceTableChartReq, sysUser *system.Admin) (chartInfo *data_manage.ChartInfo, err error, errMsg string, isSendEmail bool) {
  19. // 获取表格信息
  20. excelInfo, err := excelModel.GetExcelInfoById(req.ExcelInfoId)
  21. if err != nil {
  22. errMsg = "找不到该EXCEL"
  23. err = fmt.Errorf("找不到该EXCEL!%s", err.Error())
  24. return
  25. }
  26. if excelInfo.Source != utils.BALANCE_TABLE {
  27. errMsg = "EXCEL类型错误!"
  28. err = fmt.Errorf("EXCEL类型错误!")
  29. return
  30. }
  31. if len(req.ChartEdbInfoList) == 0 {
  32. errMsg = "图表数据不能为空!"
  33. err = fmt.Errorf("图表数据不能为空!%s", err.Error())
  34. return
  35. }
  36. chartEdbList := make([]*excelModel.AddChartEdbAndDataItem, 0)
  37. for _, chartEdb := range req.ChartEdbInfoList {
  38. excelEdb := new(excelModel.ExcelChartEdb)
  39. excelEdb.EdbName = chartEdb.EdbName
  40. randStr := utils.GetRandDigit(4)
  41. excelEdb.EdbCode = `T` + time.Now().Format("060102150405") + "_" + randStr
  42. excelEdb.ExcelInfoId = excelInfo.ExcelInfoId
  43. excelEdb.DateSequence = chartEdb.DateSequenceStr
  44. excelEdb.DataSequence = chartEdb.DataSequenceStr
  45. excelEdb.SysUserId = sysUser.AdminId
  46. excelEdb.SysUserRealName = sysUser.RealName
  47. excelEdb.MaxData = chartEdb.MaxData
  48. excelEdb.MinData = chartEdb.MinData
  49. excelEdb.IsOrder = chartEdb.IsOrder
  50. excelEdb.IsAxis = chartEdb.IsAxis
  51. excelEdb.FromTag = chartEdb.FromTag
  52. excelEdb.EdbInfoType = chartEdb.EdbInfoType
  53. excelEdb.LeadValue = chartEdb.LeadValue
  54. excelEdb.LeadUnit = chartEdb.LeadUnit
  55. excelEdb.CreateTime = time.Now()
  56. excelEdb.ModifyTime = time.Now()
  57. var dateList []string
  58. var dataList []float64
  59. if excelInfo.BalanceType == 1 {
  60. // 如果是静态表,则直接使用前端传输的数据落到数据库里
  61. /*dateList, dataList, err, errMsg = utils.HandleEdbSequenceVal(chartEdb.DateSequenceVal, chartEdb.DataSequenceVal)
  62. if err != nil {
  63. errMsg = "时间序列或数据序列异常!"
  64. err = fmt.Errorf("时间序列或数据序列异常!%s", err.Error())
  65. return
  66. }*/
  67. }
  68. // 处理日期列表和值列表
  69. addItem := &excelModel.AddChartEdbAndDataItem{
  70. ChartEdb: excelEdb,
  71. DateList: dateList,
  72. ValList: dataList,
  73. }
  74. chartEdbList = append(chartEdbList, addItem)
  75. }
  76. chartInfo, err, errMsg, isSendEmail = addBalanceExcelChart(req, sysUser.AdminId, sysUser.RealName)
  77. if err != nil {
  78. errMsg = "新增图表失败!"
  79. err = fmt.Errorf("新增图表失败!%s, %s", errMsg, err.Error())
  80. return
  81. }
  82. obj := new(excelModel.ExcelChartEdb)
  83. err = obj.AddChartEdbAndData(chartEdbList, chartInfo, []int{})
  84. if err != nil {
  85. errMsg = "新增图表失败!"
  86. err = fmt.Errorf("新增图表数据失败!%s", err.Error())
  87. return
  88. }
  89. return
  90. }
  91. func addBalanceExcelChart(req request.AddBalanceTableChartReq, sysUserId int, sysUserRealName string) (chartInfo *data_manage.ChartInfo, err error, errMsg string, isSendEmail bool) {
  92. isSendEmail = true // 默认错误的时候要发送邮件
  93. req.ChartName = strings.Trim(req.ChartName, " ")
  94. if req.ChartName == "" {
  95. errMsg = "请填写图表名称!"
  96. err = fmt.Errorf(errMsg)
  97. isSendEmail = false
  98. return
  99. }
  100. chartType := req.ChartType
  101. extraConfig := req.ExtraConfig
  102. // todo 查找默认主题设置
  103. // 查找主题类型id
  104. chartThemeType, err := chart_theme.GetChartThemeTypeByChartType(chartType)
  105. if err != nil {
  106. errMsg = "查找主题类型失败!"
  107. err = fmt.Errorf("%s, %s", errMsg, err.Error())
  108. return
  109. }
  110. chartThemeId := chartThemeType.DefaultChartThemeId
  111. // 季节性图表额外配置信息
  112. var seasonExtraConfig string
  113. if len(req.ChartEdbInfoList) <= 0 {
  114. errMsg = "请选择指标!"
  115. err = fmt.Errorf(errMsg)
  116. return
  117. }
  118. if chartType == 2 {
  119. // 处理季节性图表横轴配置
  120. {
  121. if req.SeasonExtraConfig.XEndDate != "" {
  122. if req.SeasonExtraConfig.XStartDate > req.SeasonExtraConfig.XEndDate && req.SeasonExtraConfig.JumpYear != 1 {
  123. errMsg = "季节性图表配置信息异常:横坐标日期配置错误"
  124. err = fmt.Errorf("季节性图表配置信息异常: 横坐标日期配置错误")
  125. return
  126. }
  127. seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
  128. if tErr != nil {
  129. errMsg = "季节性图表配置信息异常"
  130. err = fmt.Errorf("季节性图表配置信息异常,Err:" + tErr.Error())
  131. return
  132. }
  133. seasonExtraConfig = string(seasonExtra)
  134. }
  135. }
  136. }
  137. // 图表额外配置
  138. extraConfig, err, errMsg = HandleExtraConfig(chartType, extraConfig)
  139. if err != nil {
  140. if errMsg == `` {
  141. errMsg = "指标异常!"
  142. }
  143. err = fmt.Errorf("指标异常!Err:" + err.Error())
  144. return
  145. }
  146. //判断图表是否存在
  147. var condition string
  148. var pars []interface{}
  149. // 图表名称在不同图分类下不允许重复 需求调整时间:2022年11月07日09:47:07
  150. condition += " AND chart_classify_id=0 "
  151. condition += " AND chart_name=? AND source = ? "
  152. pars = append(pars, req.ChartName, utils.CHART_SOURCE_BALANCE_EXCEL)
  153. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  154. if err != nil {
  155. errMsg = "判断图表名称是否存在失败"
  156. err = fmt.Errorf("判断图表名称是否存在失败,Err:" + err.Error())
  157. return
  158. }
  159. if count > 0 {
  160. errMsg = "图表已存在,请重新填写"
  161. err = fmt.Errorf("判断图表名称是否存在失败")
  162. isSendEmail = false
  163. return
  164. }
  165. chartInfo = new(data_manage.ChartInfo)
  166. chartInfo.ChartName = req.ChartName
  167. //chartInfo.EdbInfoIds = edbInfoIdStr
  168. //chartInfo.ChartClassifyId = req.ChartClassifyId
  169. chartInfo.SysUserId = sysUserId
  170. chartInfo.SysUserRealName = sysUserRealName
  171. chartInfo.CreateTime = time.Now()
  172. chartInfo.ModifyTime = time.Now()
  173. chartInfo.IsSetName = 0
  174. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  175. chartInfo.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
  176. // todo 判断是否需要重新计算用户的start_date
  177. chartInfo.DateType = 3
  178. if chartType == 0 {
  179. chartType = 1
  180. }
  181. chartInfo.ChartType = chartType
  182. calendar := req.Calendar
  183. if calendar == "" {
  184. calendar = "公历"
  185. }
  186. chartInfo.Calendar = calendar
  187. /* chartInfo.StartDate = req.StartDate
  188. chartInfo.EndDate = req.EndDate
  189. chartInfo.SeasonStartDate = req.StartDate
  190. chartInfo.SeasonEndDate = req.EndDate*/
  191. chartInfo.LeftMin = req.LeftMin
  192. chartInfo.LeftMax = req.LeftMax
  193. chartInfo.RightMin = req.RightMin
  194. chartInfo.RightMax = req.RightMax
  195. chartInfo.Right2Min = req.Right2Min
  196. chartInfo.Right2Max = req.Right2Max
  197. chartInfo.MinMaxSave = req.MinMaxSave
  198. //chartInfo.Disabled = disableVal
  199. //chartInfo.BarConfig = barChartConf
  200. chartInfo.ExtraConfig = extraConfig
  201. chartInfo.SeasonExtraConfig = seasonExtraConfig
  202. //chartInfo.StartYear = req.StartYear
  203. chartInfo.Source = utils.CHART_SOURCE_BALANCE_EXCEL
  204. chartInfo.ChartThemeId = chartThemeId
  205. chartInfo.SourcesFrom = req.SourcesFrom
  206. /* chartInfo.Instructions = req.Instructions
  207. chartInfo.MarkersLines = req.MarkersLines
  208. chartInfo.MarkersAreas = req.MarkersAreas
  209. chartInfo.Unit = req.Unit
  210. chartInfo.UnitEn = req.UnitEn*/
  211. /*newId, err := data_manage.AddChartInfo(chartInfo)
  212. if err != nil {
  213. errMsg = `保存失败`
  214. err = fmt.Errorf("保存失败,Err:" + err.Error())
  215. return
  216. }
  217. chartInfo.ChartInfoId = int(newId)*/
  218. //添加es数据
  219. //go EsAddOrEditChartInfo(chartInfo.ChartInfoId)
  220. return
  221. }
  222. // EditBalanceExcelChart 添加平衡表图表
  223. func EditBalanceExcelChart(req request.AddBalanceTableChartReq, sysUser *system.Admin) (chartInfo *data_manage.ChartInfo, err error, errMsg string, isSendEmail bool) {
  224. // 获取表格信息
  225. excelInfo, err := excelModel.GetExcelInfoById(req.ExcelInfoId)
  226. if err != nil {
  227. errMsg = "找不到该EXCEL"
  228. err = fmt.Errorf("找不到该EXCEL!%s", err.Error())
  229. return
  230. }
  231. if excelInfo.Source != utils.BALANCE_TABLE {
  232. errMsg = "EXCEL类型错误!"
  233. err = fmt.Errorf("EXCEL类型错误!")
  234. return
  235. }
  236. if len(req.ChartEdbInfoList) == 0 {
  237. errMsg = "图表数据不能为空!"
  238. err = fmt.Errorf("图表数据不能为空!%s", err.Error())
  239. return
  240. }
  241. //查询已有的mapping
  242. mapping, err := excelModel.GetExcelChartEdbMappingByChartInfoId(req.ChartInfoId)
  243. if err != nil {
  244. errMsg = "查询图表mapping失败!"
  245. err = fmt.Errorf("查询图表mapping失败!%s", err.Error())
  246. return
  247. }
  248. deleteMap := make(map[int]int)
  249. for _, v := range mapping {
  250. deleteMap[v.ExcelChartEdbId] = v.ExcelChartEdbId
  251. }
  252. // 查询edbIds
  253. chartEdbList := make([]*excelModel.AddChartEdbAndDataItem, 0)
  254. for _, chartEdb := range req.ChartEdbInfoList {
  255. if _, ok := deleteMap[chartEdb.ExcelChartEdbId]; ok {
  256. delete(deleteMap, chartEdb.ExcelChartEdbId)
  257. }
  258. excelChartEdbId := chartEdb.ExcelChartEdbId
  259. excelEdb, tmpErr := excelModel.GetExcelChartEdbById(excelChartEdbId)
  260. if tmpErr != nil {
  261. if tmpErr.Error() == utils.ErrNoRow() {
  262. errMsg = "指标不存在!"
  263. err = errors.New("指标不存在,edbInfoId:" + strconv.Itoa(excelChartEdbId))
  264. return
  265. } else {
  266. errMsg = "获取指标信息失败!"
  267. err = errors.New("获取图表的指标信息失败,Err:" + tmpErr.Error())
  268. return
  269. }
  270. }
  271. if excelEdb == nil {
  272. errMsg = "指标已被删除,请重新选择!"
  273. err = errors.New("指标不存在,ChartInfoId:" + strconv.Itoa(req.ChartInfoId))
  274. return
  275. } else {
  276. if excelEdb.ExcelChartEdbId <= 0 {
  277. errMsg = "指标已被删除,请重新选择!"
  278. err = errors.New("指标不存在,ChartInfoId:" + strconv.Itoa(req.ChartInfoId))
  279. return
  280. }
  281. }
  282. excelEdb.EdbName = chartEdb.EdbName
  283. excelEdb.DateSequence = chartEdb.DateSequenceStr
  284. excelEdb.DataSequence = chartEdb.DataSequenceStr
  285. excelEdb.MaxData = chartEdb.MaxData
  286. excelEdb.MinData = chartEdb.MinData
  287. excelEdb.IsOrder = chartEdb.IsOrder
  288. excelEdb.IsAxis = chartEdb.IsAxis
  289. excelEdb.FromTag = chartEdb.FromTag
  290. excelEdb.EdbInfoType = chartEdb.EdbInfoType
  291. excelEdb.LeadValue = chartEdb.LeadValue
  292. excelEdb.LeadUnit = chartEdb.LeadUnit
  293. excelEdb.ModifyTime = time.Now()
  294. var dateList []string
  295. var dataList []float64
  296. if excelInfo.BalanceType == 1 {
  297. // 如果是静态表,则直接使用前端传输的数据落到数据库里
  298. /*dateList, dataList, err, errMsg = utils.HandleEdbSequenceVal(chartEdb.DateSequenceVal, chartEdb.DataSequenceVal)
  299. if err != nil {
  300. errMsg = "时间序列或数据序列异常!"
  301. err = fmt.Errorf("时间序列或数据序列异常!%s", err.Error())
  302. return
  303. }*/
  304. }
  305. // 处理日期列表和值列表
  306. addItem := &excelModel.AddChartEdbAndDataItem{
  307. ChartEdb: excelEdb,
  308. DateList: dateList,
  309. ValList: dataList,
  310. }
  311. chartEdbList = append(chartEdbList, addItem)
  312. }
  313. chartInfo, err, errMsg, isSendEmail = editBalanceExcelChart(req)
  314. if err != nil {
  315. errMsg = "新增图表失败!"
  316. err = fmt.Errorf("新增图表失败!%s, %s", errMsg, err.Error())
  317. return
  318. }
  319. obj := new(excelModel.ExcelChartEdb)
  320. //删除原先多余的指标
  321. deleteEdbIds := make([]int, 0)
  322. for k, _ := range deleteMap {
  323. deleteEdbIds = append(deleteEdbIds, k)
  324. }
  325. err = obj.AddChartEdbAndData(chartEdbList, chartInfo, deleteEdbIds)
  326. if err != nil {
  327. errMsg = "新增图表失败!"
  328. err = fmt.Errorf("新增图表数据失败!%s", err.Error())
  329. return
  330. }
  331. return
  332. }
  333. func editBalanceExcelChart(req request.AddBalanceTableChartReq) (chartInfo *data_manage.ChartInfo, err error, errMsg string, isSendEmail bool) {
  334. isSendEmail = true // 默认错误的时候要发送邮件
  335. chartType := req.ChartType
  336. extraConfig := req.ExtraConfig
  337. chartInfo, err = data_manage.GetChartInfoById(req.ChartInfoId)
  338. if err != nil {
  339. if err.Error() == utils.ErrNoRow() {
  340. errMsg = "图表已被删除,请刷新页面"
  341. err = errors.New(errMsg)
  342. isSendEmail = false
  343. return
  344. }
  345. errMsg = "获取图表信息失败"
  346. err = errors.New("获取图表信息失败,Err:" + err.Error())
  347. return
  348. }
  349. // todo 查找默认主题设置
  350. // todo 查找默认主题设置
  351. // 查找主题类型id
  352. chartThemeType, err := chart_theme.GetChartThemeTypeByChartType(chartType)
  353. if err != nil {
  354. errMsg = "查找主题类型失败!"
  355. err = fmt.Errorf("%s, %s", errMsg, err.Error())
  356. return
  357. }
  358. chartThemeId := chartThemeType.DefaultChartThemeId
  359. // 季节性图表额外配置信息
  360. var seasonExtraConfig string
  361. if chartType == 2 {
  362. // 处理季节性图表横轴配置
  363. {
  364. if req.SeasonExtraConfig.XEndDate != "" {
  365. if req.SeasonExtraConfig.XStartDate > req.SeasonExtraConfig.XEndDate && req.SeasonExtraConfig.JumpYear != 1 {
  366. errMsg = "季节性图表配置信息异常:横坐标日期配置错误"
  367. err = fmt.Errorf("季节性图表配置信息异常: 横坐标日期配置错误")
  368. return
  369. }
  370. seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
  371. if tErr != nil {
  372. errMsg = "季节性图表配置信息异常"
  373. err = fmt.Errorf("季节性图表配置信息异常,Err:" + tErr.Error())
  374. return
  375. }
  376. seasonExtraConfig = string(seasonExtra)
  377. }
  378. }
  379. }
  380. /*var extraConfigEdbInfoIdArr []int
  381. extraConfigEdbInfoIdArr, err, errMsg = CheckChartExtraConfig(req.ChartType, req.ExtraConfig)
  382. if err != nil {
  383. err = errors.New("添加失败:" + err.Error())
  384. return
  385. }*/
  386. // 图表额外配置
  387. extraConfig, err, errMsg = HandleExtraConfig(chartType, extraConfig)
  388. if err != nil {
  389. if errMsg == `` {
  390. errMsg = "指标异常!"
  391. }
  392. err = fmt.Errorf("指标异常!Err:" + err.Error())
  393. return
  394. }
  395. //判断图表是否存在
  396. var condition string
  397. var pars []interface{}
  398. condition += " AND chart_info_id<>? "
  399. pars = append(pars, req.ChartInfoId)
  400. // 图表名称在不同图分类下不允许重复 需求调整时间:2022年11月07日09:47:07
  401. condition += " AND chart_classify_id=0 "
  402. condition += " AND chart_name=? AND source = ? "
  403. pars = append(pars, req.ChartName, utils.CHART_SOURCE_BALANCE_EXCEL)
  404. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  405. if err != nil {
  406. errMsg = "判断图表名称是否存在失败"
  407. err = fmt.Errorf("判断图表名称是否存在失败,Err:" + err.Error())
  408. return
  409. }
  410. if count > 0 {
  411. errMsg = "图表已存在,请重新填写"
  412. err = fmt.Errorf("判断图表名称是否存在失败")
  413. isSendEmail = false
  414. return
  415. }
  416. // todo 判断是否是禁用的图表
  417. // disableVal := data.CheckIsDisableChart(edbInfoIdArr)
  418. chartInfo.ChartName = req.ChartName
  419. //chartInfo.EdbInfoIds = edbInfoIdStr
  420. //chartInfo.ChartClassifyId = req.ChartClassifyId
  421. chartInfo.ModifyTime = time.Now()
  422. chartInfo.IsSetName = 0
  423. // todo 判断是否需要重新计算用户的start_date
  424. chartInfo.DateType = 3
  425. if chartType == 0 {
  426. chartType = 1
  427. }
  428. chartInfo.ChartType = chartType
  429. calendar := req.Calendar
  430. if calendar == "" {
  431. calendar = "公历"
  432. }
  433. chartInfo.Calendar = calendar
  434. /* chartInfo.StartDate = req.StartDate
  435. chartInfo.EndDate = req.EndDate
  436. chartInfo.SeasonStartDate = req.StartDate
  437. chartInfo.SeasonEndDate = req.EndDate*/
  438. chartInfo.LeftMin = req.LeftMin
  439. chartInfo.LeftMax = req.LeftMax
  440. chartInfo.RightMin = req.RightMin
  441. chartInfo.RightMax = req.RightMax
  442. chartInfo.Right2Min = req.Right2Min
  443. chartInfo.Right2Max = req.Right2Max
  444. chartInfo.MinMaxSave = req.MinMaxSave
  445. //chartInfo.Disabled = disableVal
  446. //chartInfo.BarConfig = barChartConf
  447. chartInfo.ExtraConfig = extraConfig
  448. chartInfo.SeasonExtraConfig = seasonExtraConfig
  449. //chartInfo.StartYear = req.StartYear
  450. chartInfo.Source = utils.CHART_SOURCE_BALANCE_EXCEL
  451. chartInfo.ChartThemeId = chartThemeId
  452. chartInfo.SourcesFrom = req.SourcesFrom
  453. /* chartInfo.Instructions = req.Instructions
  454. chartInfo.MarkersLines = req.MarkersLines
  455. chartInfo.MarkersAreas = req.MarkersAreas
  456. chartInfo.Unit = req.Unit
  457. chartInfo.UnitEn = req.UnitEn*/
  458. /*newId, err := data_manage.AddChartInfo(chartInfo)
  459. if err != nil {
  460. errMsg = `保存失败`
  461. err = fmt.Errorf("保存失败,Err:" + err.Error())
  462. return
  463. }
  464. chartInfo.ChartInfoId = int(newId)*/
  465. //添加es数据
  466. //go EsAddOrEditChartInfo(chartInfo.ChartInfoId)
  467. return
  468. }
  469. func GetBalanceExcelChartDetail(chartInfo *data_manage.ChartInfoView, mappingListTmp []*excelModel.ExcelChartEdb, sysUser *system.Admin, dataListMap map[int][]*data_manage.EdbDataList) (resp *data_manage.ChartInfoDetailResp, err error, errMsg string) {
  470. // todo 图表权限处理
  471. chartInfoId := chartInfo.ChartInfoId
  472. resp = new(data_manage.ChartInfoDetailResp)
  473. // 获取主题样式
  474. chartTheme, err := GetChartThemeConfig(chartInfo.ChartThemeId, 1, chartInfo.ChartType)
  475. if err != nil {
  476. errMsg = "获取失败"
  477. err = fmt.Errorf(" 获取主题信息失败 Err:%s", err.Error())
  478. return
  479. }
  480. chartInfo.ChartThemeStyle = chartTheme.Config
  481. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  482. dateType := chartInfo.DateType
  483. fmt.Println("dateType:", dateType)
  484. chartType := chartInfo.ChartType
  485. startDate := chartInfo.StartDate
  486. endDate := chartInfo.EndDate
  487. seasonStartDate := chartInfo.SeasonStartDate
  488. seasonEndDate := chartInfo.SeasonEndDate
  489. //startYear := chartInfo.StartYear
  490. calendar := chartInfo.Calendar
  491. if calendar == "" {
  492. calendar = "公历"
  493. }
  494. mappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
  495. //循环组装映射关系
  496. for _, v := range mappingListTmp {
  497. mapping := &data_manage.ChartEdbInfoMapping{
  498. EdbInfoId: v.ExcelChartEdbId,
  499. SourceName: "",
  500. Source: 0,
  501. SubSource: 0,
  502. EdbCode: v.EdbCode,
  503. EdbName: v.EdbName,
  504. EdbAliasName: v.EdbName,
  505. EdbNameEn: "",
  506. EdbAliasNameEn: "",
  507. EdbType: 0,
  508. Frequency: "",
  509. FrequencyEn: "",
  510. Unit: "",
  511. UnitEn: "",
  512. StartDate: "",
  513. EndDate: "",
  514. ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  515. ChartEdbMappingId: v.ExcelChartEdbId,
  516. ChartInfoId: chartInfoId,
  517. MaxData: v.MaxData,
  518. MinData: v.MinData,
  519. IsOrder: v.IsOrder,
  520. IsAxis: v.IsAxis,
  521. //EdbInfoType: 0,
  522. //EdbInfoCategoryType: 0,
  523. LeadValue: v.LeadValue,
  524. LeadUnit: v.LeadUnit,
  525. LeadUnitEn: "",
  526. ChartStyle: "",
  527. ChartColor: "",
  528. PredictChartColor: "",
  529. ChartWidth: 0,
  530. ChartType: 0,
  531. LatestDate: "",
  532. LatestValue: 0,
  533. MoveLatestDate: "",
  534. UniqueCode: "",
  535. MinValue: 0,
  536. MaxValue: 0,
  537. DataList: nil,
  538. IsNullData: false,
  539. MappingSource: 0,
  540. RegionType: "",
  541. ClassifyId: 0,
  542. IsConvert: 0,
  543. ConvertType: 0,
  544. ConvertValue: 0,
  545. ConvertUnit: "",
  546. ConvertEnUnit: "",
  547. IsJoinPermission: 0,
  548. HaveOperaAuth: true,
  549. }
  550. mappingList = append(mappingList, mapping)
  551. }
  552. if chartType == 2 {
  553. startDate = seasonStartDate
  554. endDate = seasonEndDate
  555. if dateType <= 0 {
  556. if startDate != "" {
  557. dateType = 5
  558. } else {
  559. dateType = utils.DateTypeNYears
  560. }
  561. }
  562. } else {
  563. if dateType <= 0 {
  564. dateType = 3
  565. }
  566. }
  567. /*yearMax := 0
  568. if dateType == utils.DateTypeNYears {
  569. for _, v := range mappingList {
  570. if v.LatestDate != "" {
  571. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  572. if tErr != nil {
  573. br.Msg = "获取失败"
  574. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  575. return
  576. }
  577. if lastDateT.Year() > yearMax {
  578. yearMax = lastDateT.Year()
  579. }
  580. }
  581. }
  582. }
  583. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)*/
  584. if chartInfo.ChartType == 2 {
  585. chartInfo.StartDate = startDate
  586. chartInfo.EndDate = endDate
  587. }
  588. // 图表额外数据参数
  589. extraConfigStr := chartInfo.ExtraConfig
  590. // 柱方图的一些配置
  591. var barConfig data_manage.BarChartInfoReq
  592. if chartInfo != nil && chartInfo.ChartType == 7 {
  593. if chartInfo.BarConfig == `` {
  594. err = fmt.Errorf("柱方图未配置")
  595. errMsg = "柱方图未配置"
  596. return
  597. }
  598. err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  599. if err != nil {
  600. err = fmt.Errorf("柱方图配置异常 json.Unmarshal Err:%s", err.Error())
  601. errMsg = "柱方图配置异常"
  602. return
  603. }
  604. extraConfigStr = chartInfo.BarConfig
  605. }
  606. // 获取表格数据
  607. excelChartInfoDataShow := new(ExcelChartInfoDataShow)
  608. excelChartInfoDataShow.DataListMap = dataListMap
  609. if chartInfo.HaveOperaAuth || true {
  610. // 获取图表中的指标数据
  611. edbList, xEdbIdValue, yDataList, dataResp, e, msg := GetChartEdbDataV2(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig, excelChartInfoDataShow)
  612. if e != nil {
  613. err = fmt.Errorf("获取图表,指标数据失败,Err:%s", e.Error())
  614. errMsg = msg
  615. return
  616. }
  617. // 单位
  618. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  619. chartInfo.Unit = yDataList[0].Unit
  620. chartInfo.UnitEn = yDataList[0].UnitEn
  621. }
  622. warnEdbList := make([]string, 0)
  623. for _, v := range edbList {
  624. if v.IsNullData {
  625. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  626. }
  627. }
  628. if len(warnEdbList) > 0 {
  629. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  630. }
  631. if chartInfoId > 0 && chartInfo != nil {
  632. //判断是否加入我的图库
  633. {
  634. var myChartCondition string
  635. var myChartPars []interface{}
  636. myChartCondition += ` AND a.admin_id=? `
  637. myChartPars = append(myChartPars, sysUser.AdminId)
  638. myChartCondition += ` AND a.chart_info_id=? `
  639. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  640. myChartList, e := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  641. if e != nil && e.Error() != utils.ErrNoRow() {
  642. errMsg = "获取失败"
  643. err = fmt.Errorf("获取我的图表信息失败,GetMyChartByCondition,Err:" + e.Error())
  644. return
  645. }
  646. if myChartList != nil && len(myChartList) > 0 {
  647. chartInfo.IsAdd = true
  648. chartInfo.MyChartId = myChartList[0].MyChartId
  649. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  650. }
  651. }
  652. }
  653. //判断是否需要展示英文标识
  654. chartInfo.IsEnChart = CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  655. // 图表的指标来源
  656. sourceNameList, sourceNameEnList := GetEdbSourceByEdbInfoIdList(edbList)
  657. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  658. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  659. // todo 指标权限
  660. {
  661. for _, item := range edbList {
  662. // 数据权限
  663. item.HaveOperaAuth = true
  664. }
  665. }
  666. resp.EdbInfoList = edbList
  667. resp.XEdbIdValue = xEdbIdValue
  668. resp.YDataList = yDataList
  669. resp.DataResp = dataResp
  670. } else {
  671. resp.EdbInfoList = mappingList
  672. }
  673. //图表操作权限
  674. chartInfo.IsEdit = CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  675. chartInfo.Button = data_manage.ChartViewButton{
  676. IsEdit: chartInfo.IsEdit,
  677. IsEnChart: chartInfo.IsEnChart,
  678. IsAdd: chartInfo.IsAdd,
  679. IsCopy: true,
  680. IsSetName: chartInfo.IsSetName,
  681. }
  682. resp.ChartInfo = chartInfo
  683. resp.BarChartInfo = barConfig
  684. return
  685. }
  686. // GetBalanceExcelEdbDataMapList 获取指标最后的基础数据
  687. func GetBalanceExcelEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate string, mappingList []*data_manage.ChartEdbInfoMapping, seasonExtraConfig string, dataListMap map[int][]*data_manage.EdbDataList) (edbDataListMap map[int][]*data_manage.EdbDataList, edbList []*data_manage.ChartEdbInfoMapping, err error) {
  688. // 指标对应的所有数据
  689. edbDataListMap = make(map[int][]*data_manage.EdbDataList)
  690. for _, v := range mappingList {
  691. //fmt.Println("v:", v.EdbInfoId)
  692. item := new(data_manage.ChartEdbInfoMapping)
  693. item.EdbInfoId = v.EdbInfoId
  694. item.SourceName = v.SourceName
  695. item.Source = v.Source
  696. item.EdbCode = v.EdbCode
  697. item.EdbName = v.EdbName
  698. item.EdbNameEn = v.EdbNameEn
  699. item.Frequency = v.Frequency
  700. item.EdbType = v.EdbType
  701. item.FrequencyEn = GetFrequencyEn(v.Frequency)
  702. if v.Unit != `无` {
  703. item.Unit = v.Unit
  704. }
  705. item.UnitEn = v.UnitEn
  706. item.StartDate = v.StartDate
  707. item.EndDate = v.EndDate
  708. item.ModifyTime = v.ModifyTime
  709. item.EdbInfoCategoryType = v.EdbInfoCategoryType
  710. item.PredictChartColor = v.PredictChartColor
  711. item.ClassifyId = v.ClassifyId
  712. if chartInfoId <= 0 {
  713. item.IsAxis = 1
  714. item.LeadValue = 0
  715. item.LeadUnit = ""
  716. item.ChartEdbMappingId = 0
  717. item.ChartInfoId = 0
  718. item.IsOrder = false
  719. item.EdbInfoType = 1
  720. item.ChartStyle = ""
  721. item.ChartColor = ""
  722. item.ChartWidth = 0
  723. item.MaxData = v.MaxValue
  724. item.MinData = v.MinValue
  725. } else {
  726. item.IsAxis = v.IsAxis
  727. item.EdbInfoType = v.EdbInfoType
  728. item.LeadValue = v.LeadValue
  729. item.LeadUnit = v.LeadUnit
  730. item.LeadUnitEn = GetLeadUnitEn(v.LeadUnit)
  731. item.ChartEdbMappingId = v.ChartEdbMappingId
  732. item.ChartInfoId = v.ChartInfoId
  733. item.ChartStyle = v.ChartStyle
  734. item.ChartColor = v.ChartColor
  735. item.ChartWidth = v.ChartWidth
  736. item.IsOrder = v.IsOrder
  737. item.MaxData = v.MaxData
  738. item.MinData = v.MinData
  739. }
  740. item.LatestValue = v.LatestValue
  741. item.LatestDate = v.LatestDate
  742. item.UniqueCode = v.UniqueCode
  743. item.MoveLatestDate = v.LatestDate
  744. item.EdbAliasName = v.EdbAliasName
  745. item.IsConvert = v.IsConvert
  746. item.ConvertType = v.ConvertType
  747. item.ConvertValue = v.ConvertValue
  748. item.ConvertUnit = v.ConvertUnit
  749. item.ConvertEnUnit = v.ConvertEnUnit
  750. item.IsJoinPermission = v.IsJoinPermission
  751. var startDateReal string
  752. var diffSeconds int64
  753. if chartType == 2 { //季节性图
  754. startDateReal = startDate
  755. } else {
  756. if v.EdbInfoType == 0 && v.LeadUnit != "" && v.LeadValue > 0 { //领先指标
  757. var startTimeRealTemp time.Time
  758. startDateParse, _ := time.Parse(utils.FormatDate, startDate)
  759. switch v.LeadUnit {
  760. case "天":
  761. startTimeRealTemp = startDateParse.AddDate(0, 0, -v.LeadValue)
  762. case "月":
  763. startTimeRealTemp = startDateParse.AddDate(0, -v.LeadValue, 0)
  764. case "季":
  765. startTimeRealTemp = startDateParse.AddDate(0, -3*v.LeadValue, 0)
  766. case "周":
  767. startTimeRealTemp = startDateParse.AddDate(0, 0, -7*v.LeadValue)
  768. case "年":
  769. startTimeRealTemp = startDateParse.AddDate(-v.LeadValue, 0, 0)
  770. }
  771. if startTimeRealTemp.Before(startDateParse) {
  772. startDateReal = startTimeRealTemp.Format(utils.FormatDate)
  773. diffSeconds = (int64(startTimeRealTemp.UnixNano()) - int64(startDateParse.UnixNano())) / 1e6
  774. } else {
  775. startDateReal = startDate
  776. diffSeconds = 0
  777. }
  778. // 预测指标的开始日期也要偏移
  779. {
  780. day, tmpErr := utils.GetDaysBetween2Date(utils.FormatDate, startDate, startDateReal)
  781. if tmpErr != nil {
  782. err = tmpErr
  783. return
  784. }
  785. moveLatestDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, item.MoveLatestDate, time.Local)
  786. if tmpErr != nil {
  787. err = tmpErr
  788. return
  789. }
  790. item.MoveLatestDate = moveLatestDateTime.AddDate(0, 0, day).Format(utils.FormatDate)
  791. }
  792. } else {
  793. startDateReal = startDate
  794. }
  795. }
  796. //fmt.Println("line 1011 chart:", v.Source, v.EdbInfoId, startDateReal, endDate)
  797. calendarPreYear := 0
  798. if calendar == "农历" {
  799. newStartDateReal, err := time.Parse(utils.FormatDate, startDateReal)
  800. if err != nil {
  801. fmt.Println("time.Parse:" + err.Error())
  802. }
  803. calendarPreYear = newStartDateReal.Year() - 1
  804. newStartDateReal = newStartDateReal.AddDate(-1, 0, 0)
  805. startDateReal = newStartDateReal.Format(utils.FormatDate)
  806. }
  807. dataList := make([]*data_manage.EdbDataList, 0)
  808. dataListTmp, ok := dataListMap[v.EdbInfoId]
  809. if ok {
  810. dataList = dataListTmp
  811. } else {
  812. err = errors.New(fmt.Sprint("获取失败,指标类型异常", v.EdbInfoId))
  813. return
  814. }
  815. if v.IsConvert == 1 {
  816. switch v.ConvertType {
  817. case 1:
  818. for i, data := range dataList {
  819. dataList[i].Value = data.Value * v.ConvertValue
  820. }
  821. //item.MaxData = item.MaxData * v.ConvertValue
  822. //item.MinData = item.MinData * v.ConvertValue
  823. case 2:
  824. for i, data := range dataList {
  825. dataList[i].Value = data.Value / v.ConvertValue
  826. }
  827. //item.MaxData = item.MaxData / v.ConvertValue
  828. //item.MinData = item.MinData / v.ConvertValue
  829. case 3:
  830. for i, data := range dataList {
  831. if data.Value <= 0 {
  832. err = errors.New("数据中含有负数或0,无法对数运算")
  833. return
  834. }
  835. dataList[i].Value = math.Log(data.Value) / math.Log(v.ConvertValue)
  836. }
  837. //item.MaxData = math.Log(item.MaxData) / math.Log(v.ConvertValue)
  838. //item.MinData = math.Log(item.MinData) / math.Log(v.ConvertValue)
  839. }
  840. }
  841. edbDataListMap[v.EdbInfoId] = dataList
  842. if diffSeconds != 0 && v.EdbInfoType == 0 {
  843. dataListLen := len(dataList)
  844. for i := 0; i < dataListLen; i++ {
  845. dataList[i].DataTimestamp = dataList[i].DataTimestamp - diffSeconds
  846. }
  847. }
  848. if chartType == 2 {
  849. latestDate, tmpErr := time.Parse(utils.FormatDate, v.LatestDate)
  850. if tmpErr != nil {
  851. //item.DataList = dataList
  852. item.IsNullData = true
  853. edbList = append(edbList, item)
  854. continue
  855. }
  856. if calendar == "农历" {
  857. if len(dataList) <= 0 {
  858. result := new(data_manage.EdbDataResult)
  859. item.DataList = result
  860. } else {
  861. result, tmpErr := data_manage.AddCalculateQuarterV6(dataList)
  862. if tmpErr != nil {
  863. err = errors.New("获取农历数据失败,Err:" + tmpErr.Error())
  864. return
  865. }
  866. quarterDataList, tErr := GetSeasonEdbInfoDataListByXDateNong(result, latestDate, seasonExtraConfig, calendarPreYear)
  867. if tErr != nil {
  868. err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
  869. return
  870. }
  871. item.DataList = quarterDataList
  872. }
  873. } else {
  874. quarterDataList, tErr := GetSeasonEdbInfoDataListByXDate(dataList, latestDate, seasonExtraConfig)
  875. if tErr != nil {
  876. err = errors.New("获取季节性图表数据失败,Err:" + tErr.Error())
  877. return
  878. }
  879. item.DataList = quarterDataList
  880. }
  881. } else if chartType == 7 || chartType == utils.CHART_TYPE_RADAR { //柱方图
  882. //item.DataList = dataList
  883. } else {
  884. item.DataList = dataList
  885. }
  886. edbList = append(edbList, item)
  887. }
  888. return
  889. }
  890. func CheckBalanceChartCacheAndPermission(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  891. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  892. adminId := sysUser.AdminId
  893. // todo 图表数据权限
  894. // 已授权分类id
  895. /*permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(adminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  896. if err != nil {
  897. errMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  898. return
  899. }
  900. // 指标数据map
  901. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  902. defer func() {
  903. if isOk {
  904. // 图表权限校验
  905. {
  906. resp.ChartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  907. //图表操作权限
  908. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, resp.ChartInfo.HaveOperaAuth)
  909. chartInfo.Button = data_manage.ChartViewButton{
  910. IsEdit: chartInfo.IsEdit,
  911. IsEnChart: chartInfo.IsEnChart,
  912. IsAdd: chartInfo.IsAdd,
  913. IsCopy: true,
  914. IsSetName: chartInfo.IsSetName,
  915. }
  916. //if !resp.ChartInfo.HaveOperaAuth {
  917. // for _, v := range resp.EdbInfoList {
  918. // v.DataList = nil
  919. // }
  920. // resp.DataResp = nil
  921. // resp.XEdbIdValue = []int{}
  922. // resp.YDataList = []data_manage.YData{}
  923. //}
  924. }
  925. // 指标权限
  926. {
  927. classifyMap := make(map[int]*data_manage.EdbClassify)
  928. // 分类
  929. {
  930. classifyIdList := make([]int, 0)
  931. for _, v := range resp.EdbInfoList {
  932. classifyIdList = append(classifyIdList, v.ClassifyId)
  933. }
  934. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  935. if tmpErr != nil {
  936. errMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  937. return
  938. }
  939. for _, v := range classifyList {
  940. classifyMap[v.ClassifyId] = v
  941. }
  942. }
  943. // 指标
  944. if len(edbClassifyPermissionMap) < 0 {
  945. edbInfoIdList := make([]int, 0)
  946. for _, v := range resp.EdbInfoList {
  947. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  948. }
  949. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  950. if tmpErr != nil {
  951. errMsg = "获取指标列表失败,Err:" + tmpErr.Error()
  952. return
  953. }
  954. for _, v := range edbInfoList {
  955. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  956. ClassifyId: v.ClassifyId,
  957. IsJoinPermission: v.IsJoinPermission,
  958. EdbInfoId: v.EdbInfoId,
  959. }
  960. }
  961. }
  962. // 获取所有有权限的指标和分类
  963. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  964. if err != nil {
  965. errMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  966. return
  967. }
  968. for _, v := range resp.EdbInfoList {
  969. // 数据权限
  970. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  971. if !ok {
  972. continue
  973. }
  974. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  975. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  976. }
  977. }
  978. }
  979. }
  980. }()*/
  981. key := GetChartInfoDataKey(chartInfo.ChartInfoId)
  982. if utils.Re == nil && isCache {
  983. if utils.Re == nil && utils.Rc.IsExist(key) {
  984. if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  985. err := json.Unmarshal(redisData, &resp)
  986. if err != nil || resp == nil {
  987. return
  988. }
  989. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  990. var myCond string
  991. var myPars []interface{}
  992. myCond += ` AND a.admin_id=? `
  993. myPars = append(myPars, adminId)
  994. myCond += ` AND a.chart_info_id=? `
  995. myPars = append(myPars, chartInfo.ChartInfoId)
  996. myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
  997. if err != nil && err.Error() != utils.ErrNoRow() {
  998. msg = "获取失败"
  999. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1000. return
  1001. }
  1002. resp.ChartInfo.IsAdd = false
  1003. resp.ChartInfo.MyChartId = 0
  1004. resp.ChartInfo.MyChartClassifyId = ""
  1005. if myList != nil && len(myList) > 0 {
  1006. resp.ChartInfo.IsAdd = true
  1007. resp.ChartInfo.MyChartId = myList[0].MyChartId
  1008. resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
  1009. }
  1010. //判断是否加入我的图库
  1011. {
  1012. var myChartCondition string
  1013. var myChartPars []interface{}
  1014. myChartCondition += ` AND a.admin_id=? `
  1015. myChartPars = append(myChartPars, adminId)
  1016. myChartCondition += ` AND a.chart_info_id=? `
  1017. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1018. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1019. if err != nil && err.Error() != utils.ErrNoRow() {
  1020. msg = "获取失败"
  1021. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1022. return
  1023. }
  1024. if myChartList != nil && len(myChartList) > 0 {
  1025. chartInfo.IsAdd = true
  1026. chartInfo.MyChartId = myChartList[0].MyChartId
  1027. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1028. }
  1029. }
  1030. isOk = true
  1031. fmt.Println("source redis")
  1032. return
  1033. }
  1034. }
  1035. }
  1036. return
  1037. }