chart_info.go 55 KB

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