chart_info.go 54 KB

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