chart_info.go 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933
  1. package cross_variety
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/data_manage"
  7. cross_varietyModels "eta/eta_api/models/data_manage/cross_variety"
  8. "eta/eta_api/models/data_manage/cross_variety/request"
  9. "eta/eta_api/models/data_manage/cross_variety/response"
  10. "eta/eta_api/models/system"
  11. "eta/eta_api/services/alarm_msg"
  12. "eta/eta_api/services/data"
  13. "eta/eta_api/services/data/cross_variety"
  14. "eta/eta_api/services/data/data_manage_permission"
  15. "eta/eta_api/utils"
  16. "fmt"
  17. "strconv"
  18. "strings"
  19. "time"
  20. "github.com/rdlucklib/rdluck_tools/paging"
  21. )
  22. // ChartInfoController
  23. // @Description: 跨品种分析图表
  24. type ChartInfoController struct {
  25. controllers.BaseAuthController
  26. }
  27. // List
  28. // @Title 跨品种分析图表列表接口
  29. // @Description 跨品种分析图表列表接口
  30. // @Param PageSize query int true "每页数据条数"
  31. // @Param CurrentIndex query int true "当前页页码,从1开始"
  32. // @Param ChartClassifyId query int true "分类id"
  33. // @Param Keyword query string true "搜索关键词"
  34. // @Param IsShowMe query bool true "是否只看我的,true、false"
  35. // @Param Source query int true "图表类型,10:跨品种分析
  36. // @Success 200 {object} data_manage.ChartListResp
  37. // @router /chart_info/list [get]
  38. func (c *ChartInfoController) List() {
  39. br := new(models.BaseResponse).Init()
  40. defer func() {
  41. c.Data["json"] = br
  42. c.ServeJSON()
  43. }()
  44. sysUser := c.SysUser
  45. if sysUser == nil {
  46. br.Msg = "请登录"
  47. br.ErrMsg = "请登录,SysUser Is Empty"
  48. br.Ret = 408
  49. return
  50. }
  51. chartClassifyId, _ := c.GetInt("ChartClassifyId")
  52. pageSize, _ := c.GetInt("PageSize")
  53. currentIndex, _ := c.GetInt("CurrentIndex")
  54. keyword := c.GetString("KeyWord")
  55. var total int
  56. page := paging.GetPaging(currentIndex, pageSize, total)
  57. var startSize int
  58. if pageSize <= 0 {
  59. pageSize = utils.PageSize20
  60. }
  61. if currentIndex <= 0 {
  62. currentIndex = 1
  63. }
  64. startSize = paging.StartIndex(currentIndex, pageSize)
  65. source, _ := c.GetInt("Source")
  66. if source <= 0 {
  67. source = utils.CHART_SOURCE_CROSS_HEDGING
  68. }
  69. var condition string
  70. var pars []interface{}
  71. // 普通图表
  72. condition += ` AND source = ? `
  73. pars = append(pars, source)
  74. if chartClassifyId > 0 {
  75. chartClassifyId, err := data_manage.GetChartClassify(chartClassifyId)
  76. if err != nil && err.Error() != utils.ErrNoRow() {
  77. br.Msg = "获取图表信息失败"
  78. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  79. return
  80. }
  81. condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  82. }
  83. var keyWordArr []string
  84. if keyword != "" {
  85. newKeyWord := strings.Split(keyword, " ")
  86. keywordStr := strings.Replace(keyword, " ", "", -1)
  87. condition += " AND ( "
  88. condition += ` chart_name LIKE '%` + keywordStr + `%' OR chart_name_en LIKE '%` + keywordStr + `%' OR`
  89. keyWordArr = append(keyWordArr, newKeyWord...)
  90. if len(keyWordArr) > 0 {
  91. for _, v := range keyWordArr {
  92. if v != "" {
  93. condition += ` chart_name LIKE '%` + v + `%' OR chart_name_en LIKE '%` + v + `%' OR`
  94. } }
  95. }
  96. condition = strings.TrimRight(condition, "OR")
  97. condition += " ) "
  98. }
  99. //只看我的
  100. isShowMe, _ := c.GetBool("IsShowMe")
  101. if isShowMe {
  102. condition += ` AND sys_user_id = ? `
  103. pars = append(pars, sysUser.AdminId)
  104. }
  105. // 获取当前账号的不可见指标
  106. noPermissionChartIdList := make([]int, 0)
  107. {
  108. obj := data_manage.EdbInfoNoPermissionAdmin{}
  109. confList, err := obj.GetAllChartListByAdminId(c.SysUser.AdminId)
  110. if err != nil && err.Error() != utils.ErrNoRow() {
  111. br.Msg = "获取失败"
  112. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  113. return
  114. }
  115. for _, v := range confList {
  116. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  117. }
  118. }
  119. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  120. if lenNoPermissionChartIdList > 0 {
  121. condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  122. pars = append(pars, noPermissionChartIdList)
  123. }
  124. //获取图表信息
  125. list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
  126. if err != nil && err.Error() != utils.ErrNoRow() {
  127. br.Success = true
  128. br.Msg = "获取图表信息失败"
  129. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  130. return
  131. }
  132. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  133. if err != nil && err.Error() != utils.ErrNoRow() {
  134. br.Msg = "获取图表信息失败"
  135. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  136. return
  137. }
  138. myChartMap := make(map[int]*data_manage.MyChartView)
  139. for _, v := range myChartList {
  140. myChartMap[v.ChartInfoId] = v
  141. }
  142. listLen := len(list)
  143. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  144. if listLen > 0 {
  145. chartInfoIds := ""
  146. for _, v := range list {
  147. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  148. }
  149. if chartInfoIds != "" {
  150. chartInfoIds = strings.Trim(chartInfoIds, ",")
  151. //判断是否需要展示英文标识
  152. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  153. if e != nil {
  154. br.Msg = "获取失败"
  155. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  156. return
  157. }
  158. for _, v := range edbList {
  159. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  160. }
  161. }
  162. }
  163. for i := 0; i < listLen; i++ {
  164. //判断是否需要展示英文标识
  165. if edbTmpList, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  166. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, edbTmpList, list[i].Source, list[i].ChartType)
  167. }
  168. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  169. list[i].IsAdd = true
  170. list[i].MyChartId = existItem.MyChartId
  171. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  172. }
  173. }
  174. resp := new(data_manage.ChartListResp)
  175. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  176. items := make([]*data_manage.ChartInfoView, 0)
  177. resp.Paging = page
  178. resp.List = items
  179. br.Ret = 200
  180. br.Success = true
  181. br.Msg = "获取成功"
  182. return
  183. }
  184. dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
  185. if err != nil && err.Error() != utils.ErrNoRow() {
  186. br.Msg = "获取指标信息失败"
  187. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  188. return
  189. }
  190. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  191. resp.Paging = page
  192. resp.List = list
  193. br.Ret = 200
  194. br.Success = true
  195. br.Msg = "获取成功"
  196. br.Data = resp
  197. }
  198. // Preview
  199. // @Title 跨品种分析图表-预览数据
  200. // @Description 跨品种分析图表-获取预览数据
  201. // // @Param request body request.ChartConfigReq true "type json string"
  202. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  203. // @router /chart_info/preview [post]
  204. func (c *ChartInfoController) Preview() {
  205. br := new(models.BaseResponse).Init()
  206. defer func() {
  207. c.Data["json"] = br
  208. c.ServeJSON()
  209. }()
  210. sysUser := c.SysUser
  211. if sysUser == nil {
  212. br.Msg = "请登录"
  213. br.ErrMsg = "请登录,SysUser Is Empty"
  214. br.Ret = 408
  215. return
  216. }
  217. var req request.ChartConfigReq
  218. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  219. br.Msg = "参数解析异常!"
  220. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  221. return
  222. }
  223. if req.TagX <= 0 {
  224. br.Msg = "请选择X轴坐标的标签"
  225. br.IsSendEmail = false
  226. return
  227. }
  228. if req.TagY <= 0 {
  229. br.Msg = "请选择Y轴坐标的标签"
  230. br.IsSendEmail = false
  231. return
  232. }
  233. if req.CalculateValue <= 0 {
  234. br.Msg = "请设置时间长度"
  235. br.IsSendEmail = false
  236. return
  237. }
  238. if req.CalculateUnit == `` {
  239. br.Msg = "请设置时间频度"
  240. br.IsSendEmail = false
  241. return
  242. }
  243. // 品种配置
  244. varietyListList := len(req.VarietyList)
  245. if varietyListList < 0 {
  246. br.Msg = "请选择品种"
  247. br.IsSendEmail = false
  248. return
  249. }
  250. // 日期配置
  251. dateConfigList := len(req.DateConfigList)
  252. if dateConfigList < 0 {
  253. br.Msg = "请选择日期"
  254. br.IsSendEmail = false
  255. return
  256. }
  257. if dateConfigList > 5 {
  258. br.Msg = "日期数量已达上限!"
  259. br.IsSendEmail = false
  260. return
  261. }
  262. chartInfo := new(data_manage.ChartInfoView)
  263. chartInfo.ChartType = utils.CHART_SOURCE_CROSS_HEDGING
  264. // 获取图表x轴y轴
  265. edbInfoList, dataResp, err, errMsg, isSendEmail := cross_variety.GetChartData(0, req)
  266. if err != nil {
  267. br.IsSendEmail = isSendEmail
  268. br.Msg = "获取失败"
  269. if errMsg != `` {
  270. br.Msg = errMsg
  271. }
  272. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  273. return
  274. }
  275. resp := response.ChartPreviewResp{
  276. EdbInfoList: edbInfoList,
  277. DataResp: dataResp,
  278. }
  279. //resp.EdbInfoList = edbList
  280. br.Data = resp
  281. br.Ret = 200
  282. br.Success = true
  283. br.Msg = "获取成功"
  284. }
  285. // Add
  286. // @Title 新增图表接口
  287. // @Description 新增图表接口
  288. // @Param request body request.AddChartInfoReq true "type json string"
  289. // @Success 200 {object} data_manage.AddChartInfoResp
  290. // @router /chart_info/add [post]
  291. func (c *ChartInfoController) Add() {
  292. br := new(models.BaseResponse).Init()
  293. defer func() {
  294. c.Data["json"] = br
  295. c.ServeJSON()
  296. }()
  297. sysUser := c.SysUser
  298. if sysUser == nil {
  299. br.Msg = "请登录"
  300. br.ErrMsg = "请登录,SysUser Is Empty"
  301. br.Ret = 408
  302. return
  303. }
  304. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  305. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  306. br.Msg = "系统处理中,请稍后重试!"
  307. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  308. return
  309. }
  310. defer func() {
  311. _ = utils.Rc.Delete(cacheKey)
  312. }()
  313. var req request.AddChartReq
  314. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  315. if err != nil {
  316. br.Msg = "参数解析异常!"
  317. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  318. return
  319. }
  320. // 添加图表
  321. req.ChartNameEn = req.ChartName
  322. chartInfo, err, errMsg, isSendEmail := cross_variety.AddChartInfo(req, sysUser, c.Lang)
  323. if err != nil {
  324. br.Msg = "保存失败"
  325. if errMsg != `` {
  326. br.Msg = errMsg
  327. }
  328. br.ErrMsg = err.Error()
  329. br.IsSendEmail = isSendEmail
  330. return
  331. }
  332. //新增操作日志
  333. {
  334. chartLog := new(data_manage.ChartInfoLog)
  335. chartLog.ChartInfoId = chartInfo.ChartInfoId
  336. chartLog.ChartName = req.ChartName
  337. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  338. chartLog.SysUserId = sysUser.AdminId
  339. chartLog.SysUserRealName = sysUser.RealName
  340. chartLog.UniqueCode = chartInfo.UniqueCode
  341. chartLog.CreateTime = time.Now()
  342. chartLog.Content = string(c.Ctx.Input.RequestBody)
  343. chartLog.Status = "新增跨品种分析图表"
  344. chartLog.Method = c.Ctx.Input.URI()
  345. go data_manage.AddChartInfoLog(chartLog)
  346. }
  347. resp := new(data_manage.AddChartInfoResp)
  348. resp.ChartInfoId = chartInfo.ChartInfoId
  349. resp.UniqueCode = chartInfo.UniqueCode
  350. resp.ChartType = chartInfo.ChartType
  351. br.Ret = 200
  352. br.Success = true
  353. br.Msg = "保存成功"
  354. br.Data = resp
  355. br.IsAddLog = true
  356. }
  357. // Edit
  358. // @Title 编辑图表接口
  359. // @Description 编辑图表接口
  360. // @Param request body request.EditChartInfoReq true "type json string"
  361. // @Success Ret=200 保存成功
  362. // @router /chart_info/edit [post]
  363. func (c *ChartInfoController) Edit() {
  364. br := new(models.BaseResponse).Init()
  365. defer func() {
  366. c.Data["json"] = br
  367. c.ServeJSON()
  368. }()
  369. sysUser := c.SysUser
  370. if sysUser == nil {
  371. br.Msg = "请登录"
  372. br.ErrMsg = "请登录,SysUser Is Empty"
  373. br.Ret = 408
  374. return
  375. }
  376. var req request.EditChartReq
  377. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  378. if err != nil {
  379. br.Msg = "参数解析异常!"
  380. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  381. return
  382. }
  383. chartItem, err, errMsg, isSendEmail := cross_variety.EditChartInfo(req, sysUser, c.Lang)
  384. if err != nil {
  385. br.Msg = "保存失败"
  386. if errMsg != `` {
  387. br.Msg = errMsg
  388. }
  389. br.ErrMsg = err.Error()
  390. br.IsSendEmail = isSendEmail
  391. return
  392. }
  393. resp := new(data_manage.AddChartInfoResp)
  394. resp.ChartInfoId = chartItem.ChartInfoId
  395. resp.UniqueCode = chartItem.UniqueCode
  396. //resp.ChartType = req.ChartType
  397. //新增操作日志
  398. {
  399. chartLog := new(data_manage.ChartInfoLog)
  400. chartLog.ChartName = chartItem.ChartName
  401. chartLog.ChartInfoId = req.ChartInfoId
  402. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  403. chartLog.SysUserId = sysUser.AdminId
  404. chartLog.SysUserRealName = sysUser.RealName
  405. chartLog.UniqueCode = chartItem.UniqueCode
  406. chartLog.CreateTime = time.Now()
  407. chartLog.Content = string(c.Ctx.Input.RequestBody)
  408. chartLog.Status = "编辑跨品种分析图表"
  409. chartLog.Method = c.Ctx.Input.URL()
  410. go data_manage.AddChartInfoLog(chartLog)
  411. }
  412. br.Ret = 200
  413. br.Success = true
  414. br.Msg = "保存成功"
  415. br.Data = resp
  416. br.IsAddLog = true
  417. }
  418. // Detail
  419. // @Title 获取图表详情
  420. // @Description 获取图表详情接口
  421. // @Param ChartInfoId query int true "图表id"
  422. // @Success 200 {object} data_manage.ChartInfoDetailResp
  423. // @router /chart_info/detail [get]
  424. func (c *ChartInfoController) Detail() {
  425. br := new(models.BaseResponse).Init()
  426. defer func() {
  427. c.Data["json"] = br
  428. c.ServeJSON()
  429. }()
  430. sysUser := c.SysUser
  431. if sysUser == nil {
  432. br.Msg = "请登录"
  433. br.ErrMsg = "请登录,SysUser Is Empty"
  434. br.Ret = 408
  435. return
  436. }
  437. chartInfoId, _ := c.GetInt("ChartInfoId")
  438. if chartInfoId <= 0 {
  439. br.Msg = "参数有误"
  440. return
  441. }
  442. var err error
  443. chartInfo := new(data_manage.ChartInfoView)
  444. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  445. if err != nil {
  446. if err.Error() == utils.ErrNoRow() {
  447. br.Msg = "图被删除,请刷新页面"
  448. br.ErrMsg = "图被删除,请刷新页面,Err:" + err.Error()
  449. return
  450. }
  451. br.Msg = "获取失败"
  452. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  453. return
  454. }
  455. // 获取主题样式
  456. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 5)
  457. if err != nil {
  458. br.Msg = "获取失败"
  459. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  460. return
  461. }
  462. chartInfo.ChartThemeStyle = chartTheme.Config
  463. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  464. if chartInfo.ExtraConfig == `` {
  465. br.Msg = "图表配置信息异常"
  466. br.ErrMsg = "图表配置信息异常"
  467. br.IsSendEmail = false
  468. return
  469. }
  470. var config request.ChartConfigReq
  471. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &config)
  472. if err != nil {
  473. br.Msg = "解析跨品种分析配置失败"
  474. br.ErrMsg = "解析跨品种分析配置失败,Err:" + err.Error()
  475. return
  476. }
  477. //mappingList, err := cross_varietyModel.GetChartVarietyMappingList(chartInfo.ChartInfoId)
  478. //if err != nil {
  479. // br.Msg = "获取品种失败"
  480. // br.ErrMsg = "获取品种失败,Err:" + err.Error()
  481. // return
  482. //}
  483. // 获取跨品种分析配置
  484. //chartInfoCrossVariety, err := cross_varietyModel.GetChartInfoCrossVarietyByChartInfoId(chartInfo.ChartInfoId)
  485. //if err != nil {
  486. // br.Msg = "获取跨品种分析配置失败"
  487. // br.ErrMsg = "获取跨品种分析配置失败,Err:" + err.Error()
  488. // return
  489. //}
  490. //
  491. //varietyIdList := make([]int,0)
  492. //for _,v:=range mappingList{
  493. // varietyIdList = append(varietyIdList,v.ChartVarietyId)
  494. //}
  495. //config := request.ChartConfigReq{
  496. // TagX: chartInfoCrossVariety.ChartXTagId,
  497. // TagY: chartInfoCrossVariety.ChartYTagId,
  498. // CalculateValue: chartInfoCrossVariety.CalculateValue,
  499. // CalculateUnit: chartInfoCrossVariety.CalculateUnit,
  500. // DateConfigList: config.DateConfigList,
  501. // VarietyList: varietyIdList,
  502. //}
  503. //config.TagX =
  504. // 获取图表x轴y轴
  505. edbList, dataResp, err, errMsg, isSendEmail := cross_variety.GetChartData(0, config)
  506. if err != nil {
  507. br.IsSendEmail = isSendEmail
  508. br.Msg = "获取失败"
  509. if errMsg != `` {
  510. br.Msg = errMsg
  511. }
  512. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  513. return
  514. }
  515. // 完善指标信息
  516. //edbList, e := correlationServ.GetChartEdbInfoFormat(chartInfo.ChartInfoId, edbInfoMappingA, edbInfoMappingB)
  517. //if e != nil {
  518. // br.Msg = "获取失败"
  519. // br.ErrMsg = "获取跨品种分析图表, 完善指标信息失败, Err:" + e.Error()
  520. // return
  521. //}
  522. // 判断是否加入我的图库
  523. if chartInfoId > 0 && chartInfo != nil {
  524. {
  525. var myChartCondition string
  526. var myChartPars []interface{}
  527. myChartCondition += ` AND a.admin_id=? `
  528. myChartPars = append(myChartPars, sysUser.AdminId)
  529. myChartCondition += ` AND a.chart_info_id=? `
  530. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  531. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  532. if err != nil && err.Error() != utils.ErrNoRow() {
  533. br.Msg = "获取失败"
  534. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  535. return
  536. }
  537. if myChartList != nil && len(myChartList) > 0 {
  538. chartInfo.IsAdd = true
  539. chartInfo.MyChartId = myChartList[0].MyChartId
  540. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  541. }
  542. }
  543. }
  544. //图表操作权限
  545. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  546. ////判断是否需要展示英文标识
  547. //chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList[0:1], chartInfo.Source, chartInfo.ChartType)
  548. //chartInfo.UnitEn = edbInfoMappingA.UnitEn
  549. // 另存为
  550. chartInfo.Button = data_manage.ChartViewButton{
  551. IsEdit: chartInfo.IsEdit,
  552. IsEnChart: chartInfo.IsEnChart,
  553. IsAdd: chartInfo.IsAdd,
  554. IsCopy: true,
  555. IsSetName: chartInfo.IsSetName,
  556. }
  557. chartInfo.HaveOperaAuth = true
  558. // 指标权限
  559. {
  560. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  561. classifyMap := make(map[int]*data_manage.EdbClassify)
  562. // 分类
  563. {
  564. classifyIdList := make([]int, 0)
  565. for _, v := range edbList {
  566. classifyIdList = append(classifyIdList, v.ClassifyId)
  567. }
  568. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  569. if tmpErr != nil {
  570. br.Msg = "获取失败"
  571. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  572. return
  573. }
  574. for _, v := range classifyList {
  575. classifyMap[v.ClassifyId] = v
  576. }
  577. }
  578. // 遍历到校验map
  579. for _, v := range edbList {
  580. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  581. ClassifyId: v.ClassifyId,
  582. IsJoinPermission: v.IsJoinPermission,
  583. EdbInfoId: v.EdbInfoId,
  584. }
  585. }
  586. // 获取所有有权限的指标和分类
  587. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  588. if err != nil {
  589. br.Msg = "获取失败"
  590. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  591. return
  592. }
  593. for _, v := range edbList {
  594. // 数据权限
  595. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  596. if !ok {
  597. continue
  598. }
  599. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  600. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  601. }
  602. }
  603. }
  604. resp := new(data_manage.ChartInfoDetailResp)
  605. resp.ChartInfo = chartInfo
  606. resp.DataResp = dataResp
  607. resp.EdbInfoList = edbList
  608. br.Ret = 200
  609. br.Success = true
  610. br.Msg = "获取成功"
  611. br.Data = resp
  612. }
  613. // Relation
  614. // @Title 获取图表的关联信息
  615. // @Description 获取图表的关联信息
  616. // @Param ChartInfoId query int true "图表id"
  617. // @Success 200 {object} data_manage.ChartInfoDetailResp
  618. // @router /chart_info/relation [get]
  619. func (c *ChartInfoController) Relation() {
  620. br := new(models.BaseResponse).Init()
  621. defer func() {
  622. c.Data["json"] = br
  623. c.ServeJSON()
  624. }()
  625. sysUser := c.SysUser
  626. if sysUser == nil {
  627. br.Msg = "请登录"
  628. br.ErrMsg = "请登录,SysUser Is Empty"
  629. br.Ret = 408
  630. return
  631. }
  632. chartInfoId, _ := c.GetInt("ChartInfoId")
  633. if chartInfoId <= 0 {
  634. br.Msg = "参数有误"
  635. return
  636. }
  637. var err error
  638. chartInfo := new(data_manage.ChartInfoView)
  639. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  640. if err != nil {
  641. if err.Error() == utils.ErrNoRow() {
  642. br.Msg = "图被删除,请刷新页面"
  643. br.ErrMsg = "图被删除,请刷新页面,Err:" + err.Error()
  644. return
  645. }
  646. br.Msg = "获取失败"
  647. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  648. return
  649. }
  650. if chartInfo.ExtraConfig == `` {
  651. br.Msg = "图表配置信息异常"
  652. br.ErrMsg = "图表配置信息异常"
  653. br.IsSendEmail = false
  654. return
  655. }
  656. var config request.ChartConfigReq
  657. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &config)
  658. if err != nil {
  659. br.Msg = "解析跨品种分析配置失败"
  660. br.ErrMsg = "解析跨品种分析配置失败,Err:" + err.Error()
  661. return
  662. }
  663. tmpTagList, err := cross_varietyModels.GetTagListByIdList([]int{config.TagX, config.TagY})
  664. if err != nil {
  665. br.Msg = "获取标签信息失败"
  666. br.ErrMsg = "获取标签信息失败,Err:" + err.Error()
  667. return
  668. }
  669. var xTag, yTag *cross_varietyModels.ChartTag
  670. for _, v := range tmpTagList {
  671. if v.ChartTagId == config.TagX {
  672. xTag = v
  673. } else {
  674. yTag = v
  675. }
  676. }
  677. tagList := []*cross_varietyModels.ChartTag{
  678. xTag, yTag,
  679. }
  680. // 获取品种列表
  681. varietyList, err := cross_varietyModels.GetVarietyListByIdList(config.VarietyList)
  682. if err != nil {
  683. br.Msg = "获取品种信息失败"
  684. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  685. return
  686. }
  687. resp := response.ChartRelationResp{
  688. ChartInfo: chartInfo,
  689. TagList: tagList,
  690. VarietyList: varietyList,
  691. }
  692. br.Ret = 200
  693. br.Success = true
  694. br.Msg = "获取成功"
  695. br.Data = resp
  696. }
  697. // Copy
  698. // @Title 复制并新增图表接口
  699. // @Description 新增图表接口
  700. // @Param request body data_manage.CopyAddChartInfoReq true "type json string"
  701. // @Success 200 {object} data_manage.AddChartInfoResp
  702. // @router /chart_info/copy [post]
  703. func (c *ChartInfoController) Copy() {
  704. br := new(models.BaseResponse).Init()
  705. defer func() {
  706. c.Data["json"] = br
  707. c.ServeJSON()
  708. }()
  709. sysUser := c.SysUser
  710. if sysUser == nil {
  711. br.Msg = "请登录"
  712. br.ErrMsg = "请登录,SysUser Is Empty"
  713. br.Ret = 408
  714. return
  715. }
  716. deleteCache := true
  717. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  718. defer func() {
  719. if deleteCache {
  720. utils.Rc.Delete(cacheKey)
  721. }
  722. }()
  723. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  724. deleteCache = false
  725. br.Msg = "系统处理中,请稍后重试!"
  726. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
  727. return
  728. }
  729. var req request.CopyAddChartInfoReq
  730. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  731. if err != nil {
  732. br.Msg = "参数解析异常!"
  733. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  734. return
  735. }
  736. // 获取原图表信息
  737. oldChartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  738. if err != nil {
  739. br.Msg = "获取原图表信息失败"
  740. br.ErrMsg = "获取原图表信息失败,Err:" + err.Error()
  741. return
  742. }
  743. var config request.AddChartReq
  744. err = json.Unmarshal([]byte(oldChartInfo.ExtraConfig), &config)
  745. if err != nil {
  746. br.Msg = "原图表信息配置解析异常!"
  747. br.ErrMsg = "原图表信息配置解析失败,Err:" + err.Error()
  748. return
  749. }
  750. config.ChartName = req.ChartName
  751. config.ChartImage = oldChartInfo.ChartImage
  752. config.ChartThemeId = oldChartInfo.ChartThemeId
  753. config.SourcesFrom = oldChartInfo.SourcesFrom
  754. config.Instructions = oldChartInfo.Instructions
  755. config.MarkersLines = oldChartInfo.MarkersLines
  756. config.MarkersAreas = oldChartInfo.MarkersAreas
  757. config.ChartNameEn = oldChartInfo.ChartNameEn
  758. // 添加图表
  759. chartInfo, err, errMsg, isSendEmail := cross_variety.AddChartInfo(config, sysUser, c.Lang)
  760. if err != nil {
  761. br.Msg = "保存失败"
  762. if errMsg != `` {
  763. br.Msg = errMsg
  764. }
  765. br.ErrMsg = err.Error()
  766. br.IsSendEmail = isSendEmail
  767. return
  768. }
  769. if err != nil {
  770. br.Msg = "保存失败"
  771. if errMsg != `` {
  772. br.Msg = errMsg
  773. }
  774. br.ErrMsg = err.Error()
  775. br.IsSendEmail = isSendEmail
  776. return
  777. }
  778. //新增操作日志
  779. {
  780. chartLog := new(data_manage.ChartInfoLog)
  781. chartLog.ChartInfoId = chartInfo.ChartInfoId
  782. chartLog.ChartName = req.ChartName
  783. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  784. chartLog.SysUserId = sysUser.AdminId
  785. chartLog.SysUserRealName = sysUser.RealName
  786. chartLog.UniqueCode = chartInfo.UniqueCode
  787. chartLog.CreateTime = time.Now()
  788. chartLog.Content = string(c.Ctx.Input.RequestBody)
  789. chartLog.Status = "复制跨品种分析图表"
  790. chartLog.Method = c.Ctx.Input.URI()
  791. go data_manage.AddChartInfoLog(chartLog)
  792. }
  793. br.Ret = 200
  794. br.Success = true
  795. br.Msg = "保存成功"
  796. br.Data = data_manage.AddChartInfoResp{
  797. ChartInfoId: chartInfo.ChartInfoId,
  798. UniqueCode: chartInfo.UniqueCode,
  799. ChartType: chartInfo.ChartType,
  800. }
  801. br.IsAddLog = true
  802. }
  803. // Move
  804. // @Title 移动图表接口
  805. // @Description 移动图表接口
  806. // @Success 200 {object} data_manage.MoveChartInfoReq
  807. // @router /chart_info/move [post]
  808. func (c *ChartInfoController) Move() {
  809. br := new(models.BaseResponse).Init()
  810. defer func() {
  811. c.Data["json"] = br
  812. c.ServeJSON()
  813. }()
  814. sysUser := c.SysUser
  815. if sysUser == nil {
  816. br.Msg = "请登录"
  817. br.ErrMsg = "请登录,SysUser Is Empty"
  818. br.Ret = 408
  819. return
  820. }
  821. var req data_manage.MoveChartInfoReq
  822. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  823. if err != nil {
  824. br.Msg = "参数解析异常!"
  825. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  826. return
  827. }
  828. if req.ChartInfoId <= 0 {
  829. br.Msg = "参数错误"
  830. br.ErrMsg = "图表id小于等于0"
  831. br.IsSendEmail = false
  832. return
  833. }
  834. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  835. if err != nil {
  836. br.Msg = "移动失败"
  837. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  838. return
  839. }
  840. if chartInfo.Source != utils.CHART_SOURCE_CROSS_HEDGING {
  841. br.Msg = "图表异常"
  842. br.ErrMsg = "分类异常,不是跨品种分析的图表"
  843. return
  844. }
  845. //移动排序
  846. updateCol := make([]string, 0)
  847. //如果有传入 上一个兄弟节点分类id
  848. if req.PrevChartInfoId > 0 {
  849. prevChartInfo, err := data_manage.GetChartInfoById(req.PrevChartInfoId)
  850. if err != nil {
  851. br.Msg = "移动失败"
  852. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  853. return
  854. }
  855. if prevChartInfo.ChartClassifyId != chartInfo.ChartClassifyId {
  856. br.Msg = "不允许跨分类移动"
  857. br.ErrMsg = "不允许跨分类移动"
  858. br.IsSendEmail = false
  859. return
  860. }
  861. //如果是移动在两个兄弟节点之间
  862. if req.NextChartInfoId > 0 {
  863. //下一个兄弟节点
  864. nextChartInfo, err := data_manage.GetChartInfoById(req.NextChartInfoId)
  865. if err != nil {
  866. br.Msg = "移动失败"
  867. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  868. return
  869. }
  870. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  871. if prevChartInfo.Sort == nextChartInfo.Sort || prevChartInfo.Sort == chartInfo.Sort {
  872. //变更兄弟节点的排序
  873. updateSortStr := `sort + 2`
  874. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{chartInfo.Source}, updateSortStr)
  875. } else {
  876. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  877. if nextChartInfo.Sort-prevChartInfo.Sort == 1 {
  878. //变更兄弟节点的排序
  879. updateSortStr := `sort + 1`
  880. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{chartInfo.Source}, updateSortStr)
  881. }
  882. }
  883. }
  884. chartInfo.Sort = prevChartInfo.Sort + 1
  885. chartInfo.ModifyTime = time.Now()
  886. updateCol = append(updateCol, "Sort", "ModifyTime")
  887. } else {
  888. firstClassify, err := data_manage.GetFirstChartInfoByClassifyId(chartInfo.ChartClassifyId)
  889. if err != nil && err.Error() != utils.ErrNoRow() {
  890. br.Msg = "移动失败"
  891. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  892. return
  893. }
  894. if firstClassify != nil && firstClassify.ChartClassifyId != chartInfo.ChartClassifyId {
  895. br.Msg = "不允许跨分类移动"
  896. br.ErrMsg = "不允许跨分类移动"
  897. br.IsSendEmail = false
  898. return
  899. }
  900. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  901. if firstClassify != nil && firstClassify.Sort == 0 {
  902. updateSortStr := ` sort + 1 `
  903. _ = data_manage.UpdateChartInfoSortByClassifyId(firstClassify.ChartClassifyId, 0, firstClassify.ChartInfoId-1, []int{chartInfo.Source}, updateSortStr)
  904. }
  905. chartInfo.Sort = 0 //那就是排在第一位
  906. chartInfo.ModifyTime = time.Now()
  907. updateCol = append(updateCol, "Sort", "ModifyTime")
  908. }
  909. //更新
  910. if len(updateCol) > 0 {
  911. err = chartInfo.Update(updateCol)
  912. if err != nil {
  913. br.Msg = "移动失败"
  914. br.ErrMsg = "修改失败,Err:" + err.Error()
  915. return
  916. }
  917. }
  918. if err != nil {
  919. br.Msg = "移动失败"
  920. br.ErrMsg = "修改失败,Err:" + err.Error()
  921. return
  922. }
  923. //添加es数据
  924. go data.EsAddOrEditChartInfo(req.ChartInfoId)
  925. //修改my eta es数据
  926. go data.EsAddOrEditMyChartInfoByChartInfoId(req.ChartInfoId)
  927. //新增操作日志
  928. {
  929. chartLog := new(data_manage.ChartInfoLog)
  930. chartLog.ChartName = chartInfo.ChartName
  931. chartLog.ChartInfoId = req.ChartInfoId
  932. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  933. chartLog.SysUserId = sysUser.AdminId
  934. chartLog.SysUserRealName = sysUser.RealName
  935. chartLog.UniqueCode = chartInfo.UniqueCode
  936. chartLog.CreateTime = time.Now()
  937. chartLog.Content = string(c.Ctx.Input.RequestBody)
  938. chartLog.Status = "移动跨品种分析图表"
  939. chartLog.Method = c.Ctx.Input.URL()
  940. go data_manage.AddChartInfoLog(chartLog)
  941. }
  942. br.Ret = 200
  943. br.Success = true
  944. br.Msg = "移动成功"
  945. }
  946. // Refresh
  947. // @Title 图表刷新接口
  948. // @Description 图表刷新接口
  949. // @Param ChartInfoId query int true "图表id"
  950. // @Param UniqueCode query string true "唯一code"
  951. // @Success Ret=200 刷新成功
  952. // @router /chart_info/refresh [get]
  953. func (c *ChartInfoController) Refresh() {
  954. br := new(models.BaseResponse).Init()
  955. defer func() {
  956. c.Data["json"] = br
  957. c.ServeJSON()
  958. }()
  959. sysUser := c.SysUser
  960. if sysUser == nil {
  961. br.Msg = "请登录"
  962. br.ErrMsg = "请登录,SysUser Is Empty"
  963. br.Ret = 408
  964. return
  965. }
  966. chartInfoId, _ := c.GetInt("ChartInfoId")
  967. uniqueCode := c.GetString("UniqueCode")
  968. if chartInfoId <= 0 && uniqueCode == `` {
  969. br.Msg = "参数错误"
  970. br.ErrMsg = "参数错误:chartInfoId:" + strconv.Itoa(chartInfoId) + ",UniqueCode:" + uniqueCode
  971. return
  972. }
  973. var chartInfo *data_manage.ChartInfo
  974. var err error
  975. if chartInfoId > 0 {
  976. chartInfo, err = data_manage.GetChartInfoById(chartInfoId)
  977. } else {
  978. chartInfo, err = data_manage.GetChartInfoByUniqueCode(uniqueCode)
  979. }
  980. if err != nil {
  981. if err.Error() == utils.ErrNoRow() {
  982. br.Msg = "图表已被删除,无需刷新"
  983. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  984. return
  985. }
  986. br.Msg = "刷新失败"
  987. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  988. return
  989. }
  990. var config request.ChartConfigReq
  991. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &config)
  992. if err != nil {
  993. br.Msg = "解析跨品种分析配置失败"
  994. br.ErrMsg = "解析跨品种分析配置失败,Err:" + err.Error()
  995. return
  996. }
  997. // 获取关联的指标信息
  998. _, _, edbInfoIdList, err := cross_variety.GetXYEdbIdList(config.TagX, config.TagY, config.VarietyList)
  999. if err != nil {
  1000. br.Msg = "刷新失败,获取指标信息失败"
  1001. br.ErrMsg = "刷新失败,获取指标信息失败,Err:" + err.Error()
  1002. return
  1003. }
  1004. // 批量刷新
  1005. err, isAsync := data.EdbInfoRefreshAllFromBaseV3(edbInfoIdList, false, false, false)
  1006. if err != nil {
  1007. return
  1008. }
  1009. //清除图表缓存
  1010. {
  1011. key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
  1012. _ = utils.Rc.Delete(key)
  1013. }
  1014. br.Ret = 200
  1015. br.Success = true
  1016. br.Msg = "刷新成功"
  1017. if isAsync {
  1018. br.Msg = "图表关联指标较多,请10分钟后刷新页面查看最新数据"
  1019. }
  1020. }
  1021. // EnInfoEdit
  1022. // @Title 编辑图表英文信息接口
  1023. // @Description 编辑图表英文信息接口
  1024. // @Param request body data_manage.EditChartEnInfoReq true "type json string"
  1025. // @Success Ret=200 编辑成功
  1026. // @router /chart_info/en/edit [post]
  1027. func (c *ChartInfoController) EnInfoEdit() {
  1028. br := new(models.BaseResponse).Init()
  1029. defer func() {
  1030. c.Data["json"] = br
  1031. c.ServeJSON()
  1032. }()
  1033. sysUser := c.SysUser
  1034. if sysUser == nil {
  1035. br.Msg = "请登录"
  1036. br.ErrMsg = "请登录,SysUser Is Empty"
  1037. br.Ret = 408
  1038. return
  1039. }
  1040. var req request.EditChartEnInfoReq
  1041. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1042. if err != nil {
  1043. br.Msg = "参数解析异常!"
  1044. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1045. return
  1046. }
  1047. req.ChartNameEn = strings.Trim(req.ChartNameEn, " ")
  1048. if req.ChartInfoId <= 0 {
  1049. br.Msg = "请选择图表"
  1050. return
  1051. }
  1052. if req.ChartNameEn == "" {
  1053. br.Msg = "请输入英文图表名称"
  1054. return
  1055. }
  1056. //判断指标名称是否存在
  1057. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1058. if err != nil {
  1059. if err.Error() == utils.ErrNoRow() {
  1060. br.Msg = "图表已被删除,请刷新页面"
  1061. br.ErrMsg = "图表已被删除,请刷新页面"
  1062. return
  1063. }
  1064. br.Msg = "获取图表信息失败"
  1065. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1066. return
  1067. }
  1068. // 校验名称是否有重复
  1069. //{
  1070. // var condition string
  1071. // var pars []interface{}
  1072. // condition += " AND chart_info_id <> ? AND chart_name_en = ? AND source = ?"
  1073. // pars = append(pars, req.ChartInfoId, req.ChartNameEn, utils.CHART_SOURCE_CROSS_HEDGING)
  1074. // existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  1075. // if err != nil {
  1076. // if err.Error() != utils.ErrNoRow() {
  1077. // br.Msg = "判断英文图表名称是否存在失败"
  1078. // br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  1079. // return
  1080. // }
  1081. // }
  1082. // if err == nil && existItem.ChartInfoId > 0 {
  1083. // br.Msg = existItem.ChartName + ":" + req.ChartNameEn + "图表名称已存在"
  1084. // return
  1085. // }
  1086. //}
  1087. chartItem.ChartNameEn = req.ChartNameEn
  1088. chartItem.ModifyTime = time.Now().Local()
  1089. if e := chartItem.Update([]string{"ChartNameEn", "ModifyTime"}); e != nil {
  1090. br.Msg = "操作失败"
  1091. br.ErrMsg = "更新图表信息失败, Err: " + e.Error()
  1092. return
  1093. }
  1094. err = cross_varietyModels.EditChartEn(chartItem, req)
  1095. if err != nil {
  1096. br.Msg = "修改失败"
  1097. br.ErrMsg = "更新图表英文信息失败, Err: " + err.Error()
  1098. return
  1099. }
  1100. //添加es数据
  1101. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  1102. //修改my eta es数据
  1103. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  1104. //指标 修改es信息
  1105. //go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  1106. //新增操作日志
  1107. {
  1108. chartLog := new(data_manage.ChartInfoLog)
  1109. chartLog.ChartName = chartItem.ChartName
  1110. chartLog.ChartInfoId = req.ChartInfoId
  1111. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  1112. chartLog.SysUserId = sysUser.AdminId
  1113. chartLog.SysUserRealName = sysUser.RealName
  1114. chartLog.UniqueCode = chartItem.UniqueCode
  1115. chartLog.CreateTime = time.Now()
  1116. chartLog.Content = string(c.Ctx.Input.RequestBody)
  1117. chartLog.Status = "编辑跨品种分析图表英文信息"
  1118. chartLog.Method = c.Ctx.Input.URL()
  1119. go data_manage.AddChartInfoLog(chartLog)
  1120. }
  1121. // 清除缓存
  1122. if utils.Re == nil && utils.Rc != nil {
  1123. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  1124. _ = utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  1125. }
  1126. br.Ret = 200
  1127. br.Success = true
  1128. br.Msg = "编辑成功"
  1129. br.IsAddLog = true
  1130. }
  1131. // DeleteChart
  1132. // @Title 删除跨品种分析分类/图表
  1133. // @Description 删除跨品种分析分类/图表接口
  1134. // @Param request body data_manage.DeleteChartClassifyReq true "type json string"
  1135. // @Success 200 Ret=200 删除成功
  1136. // @router /chart_info/delete [post]
  1137. func (c *ChartInfoController) DeleteChart() {
  1138. br := new(models.BaseResponse).Init()
  1139. defer func() {
  1140. c.Data["json"] = br
  1141. c.ServeJSON()
  1142. }()
  1143. sysUser := c.SysUser
  1144. if sysUser == nil {
  1145. br.Msg = "请登录"
  1146. br.ErrMsg = "请登录,SysUser Is Empty"
  1147. br.Ret = 408
  1148. return
  1149. }
  1150. var req data_manage.DeleteChartClassifyReq
  1151. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1152. if err != nil {
  1153. br.Msg = "参数解析异常!"
  1154. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1155. return
  1156. }
  1157. if req.ChartInfoId <= 0 {
  1158. br.Msg = "请选择图表"
  1159. br.IsSendEmail = false
  1160. return
  1161. }
  1162. resp := new(data_manage.AddChartInfoResp)
  1163. //删除图表
  1164. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1165. if err != nil {
  1166. if err.Error() == utils.ErrNoRow() {
  1167. br.Msg = "图表已删除,请刷新页面"
  1168. br.ErrMsg = "指标不存在,Err:" + err.Error()
  1169. return
  1170. } else {
  1171. br.Msg = "删除失败"
  1172. br.ErrMsg = "删除失败,获取指标信息失败,Err:" + err.Error()
  1173. return
  1174. }
  1175. }
  1176. if chartInfo == nil {
  1177. br.Msg = "图表已删除,请刷新页面"
  1178. return
  1179. }
  1180. //图表操作权限
  1181. ok := data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  1182. if !ok {
  1183. br.Msg = "没有该图表的操作权限"
  1184. br.ErrMsg = "没有该图表的操作权限"
  1185. return
  1186. }
  1187. myIds := make([]int, 0)
  1188. {
  1189. // 获取引用该图表的MyCharts, 用于ES删除
  1190. var myCond string
  1191. var myPars []interface{}
  1192. myCond += ` AND a.chart_info_id = ? `
  1193. myPars = append(myPars, req.ChartInfoId)
  1194. myCharts, e := data_manage.GetMyChartListGroupByCharyInfoIdAndAdminIdByCondition(myCond, myPars)
  1195. if e != nil {
  1196. br.Msg = "删除失败"
  1197. br.ErrMsg = "获取引用图表的MyChats失败, Err: " + e.Error()
  1198. return
  1199. }
  1200. for _, m := range myCharts {
  1201. myIds = append(myIds, m.MyChartId)
  1202. }
  1203. }
  1204. //删除图表及关联指标
  1205. err = data_manage.DeleteChartInfoAndData(chartInfo.ChartInfoId)
  1206. if err != nil {
  1207. br.Msg = "删除失败"
  1208. br.ErrMsg = "删除失败,Err:" + err.Error()
  1209. return
  1210. }
  1211. //删除ES
  1212. {
  1213. go data.EsDeleteChartInfo(chartInfo.ChartInfoId)
  1214. // 删除MY ETA 图表 es数据
  1215. go data.EsDeleteMyChartInfoByMyChartIds(myIds)
  1216. }
  1217. source := chartInfo.Source // 跨品种分析
  1218. var condition string
  1219. var pars []interface{}
  1220. condition += " AND chart_classify_id=? AND source = ? "
  1221. pars = append(pars, chartInfo.ChartClassifyId, source)
  1222. condition += " AND chart_info_id>? ORDER BY create_time ASC LIMIT 1 "
  1223. pars = append(pars, req.ChartInfoId)
  1224. nextItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  1225. if err != nil && err.Error() != utils.ErrNoRow() {
  1226. br.Msg = "删除失败"
  1227. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  1228. return
  1229. }
  1230. if nextItem != nil {
  1231. resp.UniqueCode = nextItem.UniqueCode
  1232. resp.ChartInfoId = nextItem.ChartInfoId
  1233. } else {
  1234. var tmpCondition string
  1235. var tmpPars []interface{}
  1236. tmpCondition += " AND level=1 "
  1237. //pars = append(pars, chartInfo.ChartClassifyId)
  1238. tmpCondition += " AND chart_classify_id>? ORDER BY chart_classify_id ASC LIMIT 1 "
  1239. tmpPars = append(tmpPars, chartInfo.ChartClassifyId)
  1240. classifyItem, err := data_manage.GetChartClassifyByCondition(tmpCondition, tmpPars)
  1241. if err != nil && err.Error() != utils.ErrNoRow() {
  1242. br.Msg = "删除失败"
  1243. br.ErrMsg = "获取下一级图库分类信息失败,Err:" + err.Error()
  1244. return
  1245. }
  1246. if classifyItem != nil {
  1247. nextItem, err = data_manage.GetNextChartInfo(chartInfo.ChartClassifyId)
  1248. if err != nil && err.Error() != utils.ErrNoRow() {
  1249. br.Msg = "删除失败"
  1250. br.ErrMsg = "获取下一级图库信息失败,Err:" + err.Error()
  1251. return
  1252. }
  1253. if nextItem != nil {
  1254. resp.UniqueCode = nextItem.UniqueCode
  1255. resp.ChartInfoId = nextItem.ChartInfoId
  1256. }
  1257. }
  1258. }
  1259. //新增操作日志
  1260. {
  1261. chartLog := new(data_manage.ChartInfoLog)
  1262. chartLog.ChartName = chartInfo.ChartName
  1263. chartLog.ChartInfoId = req.ChartInfoId
  1264. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  1265. chartLog.SysUserId = sysUser.AdminId
  1266. chartLog.SysUserRealName = sysUser.RealName
  1267. chartLog.UniqueCode = chartInfo.UniqueCode
  1268. chartLog.CreateTime = time.Now()
  1269. chartLog.Content = string(c.Ctx.Input.RequestBody)
  1270. chartLog.Status = "删除图表"
  1271. chartLog.Method = c.Ctx.Input.URI()
  1272. go data_manage.AddChartInfoLog(chartLog)
  1273. }
  1274. br.Ret = 200
  1275. br.Msg = "删除成功"
  1276. br.Success = true
  1277. br.Data = resp
  1278. br.IsAddLog = true
  1279. }
  1280. // SearchByEs
  1281. // @Title 图表模糊搜索(从es获取)
  1282. // @Description 图表模糊搜索(从es获取)
  1283. // @Param Keyword query string true "图表名称"
  1284. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1285. // @Param Source query int true "来源,3:拟合方程,4:滚动拟合方程,默认0:全部"
  1286. // @Success 200 {object} data_manage.ChartInfo
  1287. // @router /chart_info/search_by_es [get]
  1288. func (c *ChartInfoController) SearchByEs() {
  1289. br := new(models.BaseResponse).Init()
  1290. defer func() {
  1291. c.Data["json"] = br
  1292. c.ServeJSON()
  1293. }()
  1294. sysUser := c.SysUser
  1295. if sysUser == nil {
  1296. br.Msg = "请登录"
  1297. br.ErrMsg = "请登录,SysUser Is Empty"
  1298. br.Ret = 408
  1299. return
  1300. }
  1301. pageSize, _ := c.GetInt("PageSize")
  1302. currentIndex, _ := c.GetInt("CurrentIndex")
  1303. var startSize int
  1304. if pageSize <= 0 {
  1305. pageSize = utils.PageSize20
  1306. }
  1307. if currentIndex <= 0 {
  1308. currentIndex = 1
  1309. }
  1310. startSize = paging.StartIndex(currentIndex, pageSize)
  1311. keyword := c.GetString("Keyword")
  1312. if keyword == `` { // 兼容jp前端
  1313. keyword = c.GetString("KeyWord")
  1314. }
  1315. //只看我的
  1316. isShowMe, _ := c.GetBool("IsShowMe")
  1317. showSysId := 0
  1318. if isShowMe {
  1319. showSysId = sysUser.AdminId
  1320. }
  1321. sourceList := []int{utils.CHART_SOURCE_CROSS_HEDGING}
  1322. var searchList []*data_manage.ChartInfo
  1323. var total int64
  1324. var err error
  1325. // 获取当前账号的不可见指标
  1326. noPermissionChartIdList := make([]int, 0)
  1327. {
  1328. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1329. confList, err := obj.GetAllChartListByAdminId(c.SysUser.AdminId)
  1330. if err != nil && err.Error() != utils.ErrNoRow() {
  1331. br.Msg = "获取失败"
  1332. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1333. return
  1334. }
  1335. for _, v := range confList {
  1336. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1337. }
  1338. }
  1339. if keyword != "" {
  1340. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  1341. } else {
  1342. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  1343. if err != nil && err.Error() != utils.ErrNoRow() {
  1344. br.Msg = "获取失败"
  1345. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1346. return
  1347. }
  1348. }
  1349. finalList := make([]*data_manage.ChartInfoMore, 0)
  1350. if len(searchList) > 0 {
  1351. chartInfoIds := ""
  1352. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1353. for _, v := range searchList {
  1354. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1355. }
  1356. if chartInfoIds != "" {
  1357. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1358. //判断是否需要展示英文标识
  1359. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1360. if e != nil {
  1361. br.Msg = "获取失败"
  1362. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1363. return
  1364. }
  1365. for _, v := range edbList {
  1366. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1367. }
  1368. }
  1369. for _, v := range searchList {
  1370. tmp := new(data_manage.ChartInfoMore)
  1371. tmp.ChartInfo = *v
  1372. // 图表数据权限
  1373. tmp.HaveOperaAuth = true
  1374. //判断是否需要展示英文标识
  1375. if _, ok := chartEdbMap[v.ChartInfoId]; ok {
  1376. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, v.Source, v.ChartType)
  1377. }
  1378. finalList = append(finalList, tmp)
  1379. }
  1380. }
  1381. //新增搜索词记录
  1382. {
  1383. searchKeyword := new(data_manage.SearchKeyword)
  1384. searchKeyword.KeyWord = keyword
  1385. searchKeyword.CreateTime = time.Now()
  1386. go data_manage.AddSearchKeyword(searchKeyword)
  1387. }
  1388. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1389. resp := data_manage.ChartInfoListByEsResp{
  1390. Paging: page,
  1391. List: finalList,
  1392. }
  1393. br.Ret = 200
  1394. br.Success = true
  1395. br.Msg = "获取成功"
  1396. br.Data = resp
  1397. }
  1398. // GetChartInfoDetailFromUniqueCode 根据编码获取图表详情
  1399. func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  1400. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  1401. adminId := sysUser.AdminId
  1402. // 指标数据map
  1403. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  1404. defer func() {
  1405. if isOk {
  1406. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  1407. {
  1408. //判断是否加入我的图库
  1409. var myChartCondition string
  1410. var myChartPars []interface{}
  1411. myChartCondition += ` AND a.admin_id=? `
  1412. myChartPars = append(myChartPars, adminId)
  1413. myChartCondition += ` AND a.chart_info_id=? `
  1414. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1415. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1416. if err != nil && err.Error() != utils.ErrNoRow() {
  1417. msg = "获取失败"
  1418. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1419. return
  1420. }
  1421. if myChartList != nil && len(myChartList) > 0 {
  1422. chartInfo.IsAdd = true
  1423. chartInfo.MyChartId = myChartList[0].MyChartId
  1424. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1425. }
  1426. }
  1427. resp.ChartInfo.HaveOperaAuth = true
  1428. // 指标权限
  1429. {
  1430. classifyMap := make(map[int]*data_manage.EdbClassify)
  1431. // 分类
  1432. {
  1433. classifyIdList := make([]int, 0)
  1434. for _, v := range resp.EdbInfoList {
  1435. classifyIdList = append(classifyIdList, v.ClassifyId)
  1436. }
  1437. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  1438. if tmpErr != nil {
  1439. errMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  1440. return
  1441. }
  1442. for _, v := range classifyList {
  1443. classifyMap[v.ClassifyId] = v
  1444. }
  1445. }
  1446. // 指标
  1447. if len(edbClassifyPermissionMap) < 0 {
  1448. edbInfoIdList := make([]int, 0)
  1449. for _, v := range resp.EdbInfoList {
  1450. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  1451. }
  1452. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1453. if tmpErr != nil {
  1454. errMsg = "获取指标列表失败,Err:" + tmpErr.Error()
  1455. return
  1456. }
  1457. for _, v := range edbInfoList {
  1458. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  1459. ClassifyId: v.ClassifyId,
  1460. IsJoinPermission: v.IsJoinPermission,
  1461. EdbInfoId: v.EdbInfoId,
  1462. }
  1463. }
  1464. }
  1465. // 获取所有有权限的指标和分类
  1466. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1467. if err != nil {
  1468. errMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  1469. return
  1470. }
  1471. for _, v := range resp.EdbInfoList {
  1472. // 数据权限
  1473. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  1474. if !ok {
  1475. continue
  1476. }
  1477. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  1478. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1479. }
  1480. }
  1481. }
  1482. }
  1483. if !isOk {
  1484. if errMsg != "" {
  1485. uniqueCode := ""
  1486. if chartInfo != nil {
  1487. uniqueCode = chartInfo.UniqueCode
  1488. }
  1489. tmpTip := fmt.Sprintf("查询图表详情失败,cross_variety.GetChartInfoDetailFromUniqueCode UniqueCode:%s,err:%s", uniqueCode, errMsg)
  1490. utils.FileLog.Info(tmpTip)
  1491. go alarm_msg.SendAlarmMsg(tmpTip, 3)
  1492. }
  1493. }
  1494. }()
  1495. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  1496. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  1497. if utils.Re == nil && isCache {
  1498. if utils.Re == nil && utils.Rc.IsExist(key) {
  1499. if chartData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  1500. err := json.Unmarshal(chartData, &resp)
  1501. if err != nil || resp == nil {
  1502. return
  1503. }
  1504. isOk = true
  1505. fmt.Println("source redis")
  1506. return
  1507. }
  1508. }
  1509. }
  1510. // 获取主题样式
  1511. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 5)
  1512. if err != nil {
  1513. msg = "获取失败"
  1514. errMsg = "获取主题信息失败,Err:" + err.Error()
  1515. return
  1516. }
  1517. chartInfo.ChartThemeStyle = chartTheme.Config
  1518. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  1519. chartInfoId := chartInfo.ChartInfoId
  1520. if chartInfo.ExtraConfig == `` {
  1521. msg = "图表配置信息异常"
  1522. errMsg = "图表配置信息异常"
  1523. return
  1524. }
  1525. var config request.ChartConfigReq
  1526. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &config)
  1527. if err != nil {
  1528. msg = "解析跨品种分析配置失败"
  1529. errMsg = "解析跨品种分析配置失败,Err:" + err.Error()
  1530. return
  1531. }
  1532. // 获取图表x轴y轴
  1533. edbList, dataResp, err, msg, _ := cross_variety.GetChartData(0, config)
  1534. if err != nil {
  1535. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1536. return
  1537. }
  1538. if chartInfoId > 0 && chartInfo != nil {
  1539. //判断是否加入我的图库
  1540. {
  1541. var myChartCondition string
  1542. var myChartPars []interface{}
  1543. myChartCondition += ` AND a.admin_id=? `
  1544. myChartPars = append(myChartPars, sysUser.AdminId)
  1545. myChartCondition += ` AND a.chart_info_id=? `
  1546. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1547. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1548. if err != nil && err.Error() != utils.ErrNoRow() {
  1549. msg = "获取失败"
  1550. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1551. return
  1552. }
  1553. if myChartList != nil && len(myChartList) > 0 {
  1554. chartInfo.IsAdd = true
  1555. chartInfo.MyChartId = myChartList[0].MyChartId
  1556. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1557. }
  1558. }
  1559. }
  1560. //图表操作权限
  1561. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  1562. //判断是否需要展示英文标识
  1563. //chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList[0:1], chartInfo.Source, chartInfo.ChartType)
  1564. //chartInfo.UnitEn = edbInfoMappingA.UnitEn
  1565. //isSaveAs := true
  1566. // 另存为
  1567. chartInfo.Button = data_manage.ChartViewButton{
  1568. IsEdit: chartInfo.IsEdit,
  1569. IsEnChart: chartInfo.IsEnChart,
  1570. IsAdd: chartInfo.IsAdd,
  1571. IsCopy: true,
  1572. IsSetName: chartInfo.IsSetName,
  1573. }
  1574. // 图表的指标来源
  1575. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1576. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1577. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1578. resp.ChartInfo = chartInfo
  1579. resp.DataResp = dataResp
  1580. resp.EdbInfoList = edbList
  1581. resp.Status = true
  1582. // 遍历到校验map
  1583. for _, v := range edbList {
  1584. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  1585. ClassifyId: v.ClassifyId,
  1586. IsJoinPermission: v.IsJoinPermission,
  1587. EdbInfoId: v.EdbInfoId,
  1588. }
  1589. }
  1590. // 将数据加入缓存
  1591. if utils.Re == nil {
  1592. d, _ := json.Marshal(resp)
  1593. _ = utils.Rc.Put(key, d, 2*time.Hour)
  1594. }
  1595. isOk = true
  1596. return
  1597. }
  1598. // Save
  1599. // @Title 保存图表
  1600. // @Description 保存图表
  1601. // @Param request body request.SaveChartReq true "type json string"
  1602. // @Success Ret=200 保存成功
  1603. // @router /chart_info/save [post]
  1604. func (c *ChartInfoController) Save() {
  1605. br := new(models.BaseResponse).Init()
  1606. defer func() {
  1607. if br.ErrMsg == "" {
  1608. br.IsSendEmail = true
  1609. }
  1610. c.Data["json"] = br
  1611. c.ServeJSON()
  1612. }()
  1613. sysUser := c.SysUser
  1614. if sysUser == nil {
  1615. br.Msg = "请登录"
  1616. br.ErrMsg = "请登录,SysUser Is Empty"
  1617. br.Ret = 408
  1618. return
  1619. }
  1620. var req request.SaveChartReq
  1621. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1622. if err != nil {
  1623. br.Msg = "参数解析异常!"
  1624. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1625. return
  1626. }
  1627. if req.ChartInfoId <= 0 {
  1628. br.Msg = "参数有误"
  1629. br.ErrMsg = fmt.Sprintf("参数有误, ChartInfoId: %d", req.ChartInfoId)
  1630. return
  1631. }
  1632. chartItem, e := data_manage.GetChartInfoById(req.ChartInfoId)
  1633. if e != nil {
  1634. if e.Error() == utils.ErrNoRow() {
  1635. br.Msg = "图表已被删除, 请刷新页面"
  1636. return
  1637. }
  1638. br.Msg = "保存失败"
  1639. br.ErrMsg = "获取图表信息失败, Err: " + e.Error()
  1640. return
  1641. }
  1642. // 更新图表上下限
  1643. chartItem.LeftMin = req.LeftMin
  1644. chartItem.LeftMax = req.LeftMax
  1645. chartItem.XMin = req.XMin
  1646. chartItem.XMax = req.XMax
  1647. chartUpdateCols := []string{"ChartName", "ExtraConfig", "ModifyTime", "LeftMin", "LeftMax", "XMin", "XMax"}
  1648. if e = chartItem.Update(chartUpdateCols); e != nil {
  1649. br.Msg = "保存失败"
  1650. br.ErrMsg = "更新图表上下限失败, Err: " + e.Error()
  1651. return
  1652. }
  1653. resp := new(data_manage.AddChartInfoResp)
  1654. resp.ChartInfoId = chartItem.ChartInfoId
  1655. resp.UniqueCode = chartItem.UniqueCode
  1656. // 新增操作日志
  1657. {
  1658. chartLog := new(data_manage.ChartInfoLog)
  1659. chartLog.ChartName = chartItem.ChartName
  1660. chartLog.ChartInfoId = req.ChartInfoId
  1661. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  1662. chartLog.SysUserId = sysUser.AdminId
  1663. chartLog.SysUserRealName = sysUser.RealName
  1664. chartLog.UniqueCode = chartItem.UniqueCode
  1665. chartLog.CreateTime = time.Now()
  1666. chartLog.Content = string(c.Ctx.Input.RequestBody)
  1667. chartLog.Status = "保存跨品种分析图表"
  1668. chartLog.Method = c.Ctx.Input.URL()
  1669. go data_manage.AddChartInfoLog(chartLog)
  1670. }
  1671. br.Ret = 200
  1672. br.Success = true
  1673. br.Msg = "保存成功"
  1674. br.Data = resp
  1675. br.IsAddLog = true
  1676. }
  1677. // BaseInfoEdit
  1678. // @Title 编辑图表基础信息接口
  1679. // @Description 编辑图表基础信息接口
  1680. // @Param request body data_manage.EditChartBaseInfoReq true "type json string"
  1681. // @Success Ret=200 编辑成功
  1682. // @router /chart_info/base/edit [post]
  1683. func (c *ChartInfoController) BaseInfoEdit() {
  1684. br := new(models.BaseResponse).Init()
  1685. defer func() {
  1686. c.Data["json"] = br
  1687. c.ServeJSON()
  1688. }()
  1689. sysUser := c.SysUser
  1690. if sysUser == nil {
  1691. br.Msg = "请登录"
  1692. br.ErrMsg = "请登录,SysUser Is Empty"
  1693. br.Ret = 408
  1694. return
  1695. }
  1696. var req request.EditChartBaseInfoReq
  1697. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  1698. if err != nil {
  1699. br.Msg = "参数解析异常!"
  1700. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1701. return
  1702. }
  1703. req.ChartName = strings.Trim(req.ChartName, " ")
  1704. if req.ChartInfoId <= 0 {
  1705. br.Msg = "请选择图表"
  1706. return
  1707. }
  1708. if req.ChartName == "" {
  1709. br.Msg = "请输入图表名称"
  1710. return
  1711. }
  1712. //判断指标名称是否存在
  1713. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1714. if err != nil {
  1715. if err.Error() == utils.ErrNoRow() {
  1716. br.Msg = "图表已被删除,请刷新页面"
  1717. br.ErrMsg = "图表已被删除,请刷新页面"
  1718. return
  1719. }
  1720. br.Msg = "获取图表信息失败"
  1721. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1722. return
  1723. }
  1724. err = cross_varietyModels.EditChartBase(chartItem, req, c.Lang)
  1725. if err != nil {
  1726. br.Msg = "修改失败"
  1727. br.ErrMsg = "更新图表英文信息失败, Err: " + err.Error()
  1728. return
  1729. }
  1730. //添加es数据
  1731. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  1732. //修改my eta es数据
  1733. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  1734. //指标 修改es信息
  1735. //go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  1736. //新增操作日志
  1737. {
  1738. chartLog := new(data_manage.ChartInfoLog)
  1739. chartLog.ChartName = chartItem.ChartName
  1740. chartLog.ChartInfoId = req.ChartInfoId
  1741. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  1742. chartLog.SysUserId = sysUser.AdminId
  1743. chartLog.SysUserRealName = sysUser.RealName
  1744. chartLog.UniqueCode = chartItem.UniqueCode
  1745. chartLog.CreateTime = time.Now()
  1746. chartLog.Content = string(c.Ctx.Input.RequestBody)
  1747. chartLog.Status = "编辑跨品种分析图表基础信息"
  1748. chartLog.Method = c.Ctx.Input.URL()
  1749. go data_manage.AddChartInfoLog(chartLog)
  1750. }
  1751. // 清除缓存
  1752. if utils.Re == nil && utils.Rc != nil {
  1753. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  1754. _ = utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  1755. }
  1756. br.Ret = 200
  1757. br.Success = true
  1758. br.Msg = "编辑成功"
  1759. br.IsAddLog = true
  1760. }