line_chart_info.go 55 KB

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