chart_info.go 55 KB

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