chart_info.go 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932
  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. "github.com/rdlucklib/rdluck_tools/paging"
  18. "strconv"
  19. "strings"
  20. "time"
  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. }