chart_info.go 54 KB

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