line_chart_info.go 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818
  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. var keyWordArr []string
  548. if keyword != "" {
  549. newKeyWord := strings.Split(keyword, " ")
  550. keywordStr := strings.Replace(keyword, " ", "", -1)
  551. condition += " AND ( "
  552. condition += ` chart_name LIKE '%` + keywordStr + `%' OR chart_name_en LIKE '%` + keywordStr + `%' OR`
  553. keyWordArr = append(keyWordArr, newKeyWord...)
  554. if len(keyWordArr) > 0 {
  555. for _, v := range keyWordArr {
  556. if v != "" {
  557. condition += ` chart_name LIKE '%` + v + `%' OR chart_name_en LIKE '%` + v + `%' OR`
  558. }
  559. }
  560. }
  561. condition = strings.TrimRight(condition, "OR")
  562. condition += " ) "
  563. }
  564. //只看我的
  565. isShowMe, _ := this.GetBool("IsShowMe")
  566. if isShowMe {
  567. condition += ` AND sys_user_id = ? `
  568. pars = append(pars, sysUser.AdminId)
  569. }
  570. // 获取当前账号的不可见指标
  571. noPermissionChartIdList := make([]int, 0)
  572. {
  573. obj := data_manage.EdbInfoNoPermissionAdmin{}
  574. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  575. if err != nil && err.Error() != utils.ErrNoRow() {
  576. br.Msg = "获取失败"
  577. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  578. return
  579. }
  580. for _, v := range confList {
  581. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  582. }
  583. }
  584. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  585. if lenNoPermissionChartIdList > 0 {
  586. condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  587. pars = append(pars, noPermissionChartIdList)
  588. }
  589. //获取图表信息
  590. list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
  591. if err != nil && err.Error() != utils.ErrNoRow() {
  592. br.Success = true
  593. br.Msg = "获取图表信息失败"
  594. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  595. return
  596. }
  597. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  598. if err != nil && err.Error() != utils.ErrNoRow() {
  599. br.Msg = "获取图表信息失败"
  600. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  601. return
  602. }
  603. myChartMap := make(map[int]*data_manage.MyChartView)
  604. for _, v := range myChartList {
  605. myChartMap[v.ChartInfoId] = v
  606. }
  607. listLen := len(list)
  608. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  609. if listLen > 0 {
  610. chartInfoIds := ""
  611. for _, v := range list {
  612. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  613. }
  614. if chartInfoIds != "" {
  615. chartInfoIds = strings.Trim(chartInfoIds, ",")
  616. //判断是否需要展示英文标识
  617. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  618. if e != nil {
  619. br.Msg = "获取失败"
  620. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  621. return
  622. }
  623. for _, v := range edbList {
  624. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  625. }
  626. }
  627. }
  628. for i := 0; i < listLen; i++ {
  629. //判断是否需要展示英文标识
  630. if _, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  631. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, list[i].Source, list[i].ChartType)
  632. }
  633. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  634. list[i].IsAdd = true
  635. list[i].MyChartId = existItem.MyChartId
  636. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  637. }
  638. }
  639. resp := new(data_manage.ChartListResp)
  640. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  641. items := make([]*data_manage.ChartInfoView, 0)
  642. resp.Paging = page
  643. resp.List = items
  644. br.Ret = 200
  645. br.Success = true
  646. br.Msg = "获取成功"
  647. return
  648. }
  649. dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
  650. if err != nil && err.Error() != utils.ErrNoRow() {
  651. br.Msg = "获取指标信息失败"
  652. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  653. return
  654. }
  655. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  656. resp.Paging = page
  657. resp.List = list
  658. br.Ret = 200
  659. br.Success = true
  660. br.Msg = "获取成功"
  661. br.Data = resp
  662. }
  663. // Detail
  664. // @Title 获取图表详情
  665. // @Description 获取图表详情接口
  666. // @Param ChartInfoId query int true "图表id"
  667. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"
  668. // @Param StartDate query string true "自定义开始日期"
  669. // @Param EndDate query string true "自定义结束日期"
  670. // @Param Calendar query string true "公历/农历"
  671. // @Param SeasonStartDate query string true "季节性图开始日期"
  672. // @Param SeasonEndDate query string true "季节性图结束日期"
  673. // @Param EdbInfoId query string true "指标ID,多个用英文逗号隔开"
  674. // @Param ChartType query int true "生成样式:1:曲线图,2:季节性图"
  675. // @Success 200 {object} data_manage.ChartInfoDetailResp
  676. // @router /chart_info/detail [get]
  677. func (this *LineEquationChartInfoController) Detail() {
  678. br := new(models.BaseResponse).Init()
  679. defer func() {
  680. this.Data["json"] = br
  681. this.ServeJSON()
  682. }()
  683. sysUser := this.SysUser
  684. if sysUser == nil {
  685. br.Msg = "请登录"
  686. br.ErrMsg = "请登录,SysUser Is Empty"
  687. br.Ret = 408
  688. return
  689. }
  690. chartInfoId, _ := this.GetInt("ChartInfoId")
  691. if chartInfoId <= 0 {
  692. br.Msg = "参数有误"
  693. return
  694. }
  695. var err error
  696. chartInfo := new(data_manage.ChartInfoView)
  697. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  698. if err != nil {
  699. if err.Error() == utils.ErrNoRow() {
  700. br.Msg = "图被删除,请刷新页面"
  701. br.ErrMsg = "图被删除,请刷新页面,Err:" + err.Error()
  702. return
  703. }
  704. br.Msg = "获取失败"
  705. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  706. return
  707. }
  708. // 获取主题样式
  709. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  710. if err != nil {
  711. br.Msg = "获取失败"
  712. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  713. return
  714. }
  715. chartInfo.ChartThemeStyle = chartTheme.Config
  716. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  717. if chartInfo.ExtraConfig == `` {
  718. br.Msg = "获取失败"
  719. br.ErrMsg = "获取配置信息失败,图表的额外配置信息为空"
  720. return
  721. }
  722. var lineChartInfoConfig request.LineChartInfoReq
  723. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &lineChartInfoConfig)
  724. if err != nil {
  725. br.Msg = "获取失败"
  726. br.ErrMsg = "获取图表配置信息失败,Err:" + err.Error()
  727. return
  728. }
  729. var getAData, getBData, getR2Data bool
  730. switch lineChartInfoConfig.Source {
  731. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
  732. getAData = true
  733. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
  734. getBData = true
  735. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
  736. getR2Data = true
  737. }
  738. edbList, dataResp, err, errMsg := line_equation.GetChartEdbData(chartInfoId, lineChartInfoConfig, getAData, getBData, getR2Data)
  739. if err != nil {
  740. br.Msg = "获取失败"
  741. if errMsg != `` {
  742. br.Msg = errMsg
  743. }
  744. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  745. return
  746. }
  747. var resultResp interface{}
  748. switch lineChartInfoConfig.Source {
  749. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
  750. resultResp = dataResp.AData
  751. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
  752. resultResp = dataResp.BData
  753. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
  754. resultResp = dataResp.R2Data
  755. }
  756. // 判断是否加入我的图库
  757. if chartInfoId > 0 && chartInfo != nil {
  758. {
  759. var myChartCondition string
  760. var myChartPars []interface{}
  761. myChartCondition += ` AND a.admin_id=? `
  762. myChartPars = append(myChartPars, sysUser.AdminId)
  763. myChartCondition += ` AND a.chart_info_id=? `
  764. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  765. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  766. if err != nil && err.Error() != utils.ErrNoRow() {
  767. br.Msg = "获取失败"
  768. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  769. return
  770. }
  771. if myChartList != nil && len(myChartList) > 0 {
  772. chartInfo.IsAdd = true
  773. chartInfo.MyChartId = myChartList[0].MyChartId
  774. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  775. }
  776. }
  777. }
  778. //图表操作权限
  779. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  780. //判断是否需要展示英文标识
  781. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, chartInfo.Source, chartInfo.ChartType)
  782. //chartInfo.UnitEn = edbInfoMappingA.UnitEn
  783. // 另存为
  784. isSaveAs := true
  785. chartInfo.Button = data_manage.ChartViewButton{
  786. IsEdit: chartInfo.IsEdit,
  787. IsEnChart: chartInfo.IsEnChart,
  788. IsAdd: chartInfo.IsAdd,
  789. IsCopy: isSaveAs,
  790. IsSetName: chartInfo.IsSetName,
  791. }
  792. chartInfo.HaveOperaAuth = true
  793. // 指标权限
  794. {
  795. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  796. classifyMap := make(map[int]*data_manage.EdbClassify)
  797. // 分类
  798. {
  799. classifyIdList := make([]int, 0)
  800. for _, v := range edbList {
  801. classifyIdList = append(classifyIdList, v.ClassifyId)
  802. }
  803. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  804. if tmpErr != nil {
  805. br.Msg = "获取失败"
  806. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  807. return
  808. }
  809. for _, v := range classifyList {
  810. classifyMap[v.ClassifyId] = v
  811. }
  812. }
  813. // 遍历到校验map
  814. for _, v := range edbList {
  815. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  816. ClassifyId: v.ClassifyId,
  817. IsJoinPermission: v.IsJoinPermission,
  818. EdbInfoId: v.EdbInfoId,
  819. }
  820. }
  821. // 获取所有有权限的指标和分类
  822. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  823. if err != nil {
  824. br.Msg = "获取失败"
  825. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  826. return
  827. }
  828. for _, v := range edbList {
  829. // 数据权限
  830. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  831. if !ok {
  832. continue
  833. }
  834. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  835. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  836. }
  837. }
  838. }
  839. resp := new(data_manage.ChartInfoDetailResp)
  840. resp.ChartInfo = chartInfo
  841. resp.EdbInfoList = edbList
  842. resp.DataResp = resultResp
  843. br.Ret = 200
  844. br.Success = true
  845. br.Msg = "获取成功"
  846. br.Data = resp
  847. }
  848. // DetailFromUniqueCode
  849. // @Title 根据编码获取图表详情
  850. // @Description 根据编码获取图表详情接口
  851. // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  852. // @Param IsCache query bool true "是否走缓存,默认false"
  853. // @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
  854. // @router /chart_info/detail/from_unique_code [get]
  855. func (this *LineEquationChartInfoController) DetailFromUniqueCode() {
  856. br := new(models.BaseResponse).Init()
  857. defer func() {
  858. this.Data["json"] = br
  859. this.ServeJSON()
  860. }()
  861. sysUser := this.SysUser
  862. if sysUser == nil {
  863. br.Msg = "请登录"
  864. br.ErrMsg = "请登录,SysUser Is Empty"
  865. br.Ret = 408
  866. return
  867. }
  868. adminId := sysUser.AdminId
  869. uniqueCode := this.GetString("UniqueCode")
  870. if uniqueCode == "" {
  871. br.Msg = "参数错误"
  872. br.ErrMsg = "参数错误,uniqueCode is empty"
  873. return
  874. }
  875. //是否走缓存
  876. isCache, _ := this.GetBool("IsCache")
  877. resp := new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  878. status := true
  879. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  880. if err != nil {
  881. if err.Error() == utils.ErrNoRow() {
  882. status = false
  883. } else {
  884. br.Msg = "获取失败"
  885. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  886. return
  887. }
  888. }
  889. if chartInfo == nil {
  890. status = false
  891. }
  892. if !status {
  893. endInfoList := make([]*data_manage.ChartEdbInfoMapping, 0)
  894. resp.EdbInfoList = endInfoList
  895. resp.ChartInfo = chartInfo
  896. resp.Status = false
  897. br.Ret = 200
  898. br.Success = true
  899. br.Msg = "获取成功"
  900. br.Data = resp
  901. return
  902. }
  903. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  904. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  905. if utils.Re == nil && isCache {
  906. if utils.Re == nil && utils.Rc.IsExist(key) {
  907. if d, e := utils.Rc.RedisBytes(key); e == nil {
  908. err := json.Unmarshal(d, &resp)
  909. if err == nil && resp != nil {
  910. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  911. var myCond string
  912. var myPars []interface{}
  913. myCond += ` AND a.admin_id=? `
  914. myPars = append(myPars, adminId)
  915. myCond += ` AND a.chart_info_id=? `
  916. myPars = append(myPars, chartInfo.ChartInfoId)
  917. myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
  918. if err != nil && err.Error() != utils.ErrNoRow() {
  919. br.Msg = "获取失败"
  920. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  921. return
  922. }
  923. resp.ChartInfo.IsAdd = false
  924. resp.ChartInfo.MyChartId = 0
  925. resp.ChartInfo.MyChartClassifyId = ""
  926. if myList != nil && len(myList) > 0 {
  927. resp.ChartInfo.IsAdd = true
  928. resp.ChartInfo.MyChartId = myList[0].MyChartId
  929. resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
  930. }
  931. br.Ret = 200
  932. br.Success = true
  933. br.Msg = "获取成功"
  934. br.Data = resp
  935. return
  936. }
  937. }
  938. }
  939. }
  940. resp, isOk, msg, errMsg := GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  941. if !isOk {
  942. br.Msg = msg
  943. br.ErrMsg = errMsg
  944. return
  945. }
  946. if !isOk {
  947. br.Msg = msg
  948. br.ErrMsg = errMsg
  949. return
  950. }
  951. br.Ret = 200
  952. br.Success = true
  953. br.Msg = "获取成功"
  954. br.Data = resp
  955. }
  956. // Refresh
  957. // @Title 图表刷新接口
  958. // @Description 图表刷新接口
  959. // @Param ChartInfoId query int true "图表id"
  960. // @Param UniqueCode query string true "唯一code"
  961. // @Success Ret=200 刷新成功
  962. // @router /chart_info/refresh [get]
  963. func (this *LineEquationChartInfoController) Refresh() {
  964. br := new(models.BaseResponse).Init()
  965. defer func() {
  966. this.Data["json"] = br
  967. this.ServeJSON()
  968. }()
  969. sysUser := this.SysUser
  970. if sysUser == nil {
  971. br.Msg = "请登录"
  972. br.ErrMsg = "请登录,SysUser Is Empty"
  973. br.Ret = 408
  974. return
  975. }
  976. chartInfoId, _ := this.GetInt("ChartInfoId")
  977. uniqueCode := this.GetString("UniqueCode")
  978. if chartInfoId <= 0 && uniqueCode == `` {
  979. br.Msg = "参数错误"
  980. br.ErrMsg = "参数错误:chartInfoId:" + strconv.Itoa(chartInfoId) + ",UniqueCode:" + uniqueCode
  981. return
  982. }
  983. var chartInfo *data_manage.ChartInfo
  984. var err error
  985. if chartInfoId > 0 {
  986. chartInfo, err = data_manage.GetChartInfoById(chartInfoId)
  987. } else {
  988. chartInfo, err = data_manage.GetChartInfoByUniqueCode(uniqueCode)
  989. }
  990. if err != nil {
  991. if err.Error() == utils.ErrNoRow() {
  992. br.Msg = "图表已被删除,无需刷新"
  993. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  994. return
  995. }
  996. br.Msg = "刷新失败"
  997. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  998. return
  999. }
  1000. // 刷新图表的指标信息
  1001. err, isAsync := data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
  1002. //清除图表缓存
  1003. {
  1004. key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
  1005. _ = utils.Rc.Delete(key)
  1006. }
  1007. br.Ret = 200
  1008. br.Success = true
  1009. br.Msg = "刷新成功"
  1010. if isAsync {
  1011. br.Msg = "图表关联指标较多,请10分钟后刷新页面查看最新数据"
  1012. }
  1013. }
  1014. // Copy
  1015. // @Title 复制并新增图表接口
  1016. // @Description 新增图表接口
  1017. // @Param request body data_manage.CopyAddChartInfoReq true "type json string"
  1018. // @Success 200 {object} data_manage.AddChartInfoResp
  1019. // @router /chart_info/copy [post]
  1020. func (this *LineEquationChartInfoController) Copy() {
  1021. br := new(models.BaseResponse).Init()
  1022. defer func() {
  1023. this.Data["json"] = br
  1024. this.ServeJSON()
  1025. }()
  1026. sysUser := this.SysUser
  1027. if sysUser == nil {
  1028. br.Msg = "请登录"
  1029. br.ErrMsg = "请登录,SysUser Is Empty"
  1030. br.Ret = 408
  1031. return
  1032. }
  1033. deleteCache := true
  1034. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  1035. defer func() {
  1036. if deleteCache {
  1037. utils.Rc.Delete(cacheKey)
  1038. }
  1039. }()
  1040. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1041. deleteCache = false
  1042. br.Msg = "系统处理中,请稍后重试!"
  1043. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1044. return
  1045. }
  1046. var req data_manage.CopyAddChartInfoReq
  1047. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1048. if err != nil {
  1049. br.Msg = "参数解析异常!"
  1050. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1051. return
  1052. }
  1053. // 获取原图表信息
  1054. oldChartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1055. if err != nil {
  1056. br.Msg = "获取原图表信息失败"
  1057. br.ErrMsg = "获取原图表信息失败,Err:" + err.Error()
  1058. return
  1059. }
  1060. if oldChartInfo.Source != utils.CHART_SOURCE_LINE_EQUATION {
  1061. br.Msg = `错误的图表类型`
  1062. br.IsSendEmail = false
  1063. return
  1064. }
  1065. var lineChartInfoConf request.LineChartInfoReq
  1066. err = json.Unmarshal([]byte(oldChartInfo.ExtraConfig), &lineChartInfoConf)
  1067. addChartList := make([]request.AddChart, 0)
  1068. addChartList = append(addChartList, request.AddChart{
  1069. Source: lineChartInfoConf.Source,
  1070. ChartClassifyId: req.ChartClassifyId,
  1071. ChartName: req.ChartName,
  1072. LeftMin: oldChartInfo.LeftMin,
  1073. LeftMax: oldChartInfo.LeftMax,
  1074. ChartImage: oldChartInfo.ChartImage,
  1075. ChartThemeId: oldChartInfo.ChartThemeId,
  1076. SourcesFrom: oldChartInfo.SourcesFrom,
  1077. Instructions: oldChartInfo.Instructions,
  1078. MarkersLines: oldChartInfo.MarkersLines,
  1079. MarkersAreas: oldChartInfo.MarkersAreas,
  1080. })
  1081. resp := new(data_manage.AddChartInfoResp)
  1082. batchAddChartList, err, errMsg, isSendEmail := line_equation.BatchAddChartInfo(addChartList, lineChartInfoConf, sysUser, this.Lang)
  1083. if err != nil {
  1084. br.Msg = "保存失败"
  1085. if errMsg != `` {
  1086. br.Msg = errMsg
  1087. }
  1088. br.ErrMsg = err.Error()
  1089. br.IsSendEmail = isSendEmail
  1090. return
  1091. }
  1092. resp.ChartInfoId = batchAddChartList[0].ChartInfo.ChartInfoId
  1093. resp.UniqueCode = batchAddChartList[0].ChartInfo.UniqueCode
  1094. resp.ChartType = batchAddChartList[0].ChartInfo.ChartType
  1095. //新增操作日志
  1096. {
  1097. for _, v := range batchAddChartList {
  1098. chartInfo := v.ChartInfo
  1099. chartLog := new(data_manage.ChartInfoLog)
  1100. chartLog.ChartInfoId = chartInfo.ChartInfoId
  1101. chartLog.ChartName = chartInfo.ChartName
  1102. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  1103. chartLog.SysUserId = sysUser.AdminId
  1104. chartLog.SysUserRealName = sysUser.RealName
  1105. chartLog.UniqueCode = chartInfo.UniqueCode
  1106. chartLog.CreateTime = time.Now()
  1107. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1108. chartLog.Status = "新增拟合方程图表"
  1109. chartLog.Method = this.Ctx.Input.URI()
  1110. go data_manage.AddChartInfoLog(chartLog)
  1111. }
  1112. }
  1113. br.Ret = 200
  1114. br.Data = resp
  1115. br.Success = true
  1116. br.Msg = "保存成功"
  1117. br.IsAddLog = true
  1118. }
  1119. // GetChartInfoDetailFromUniqueCode 根据编码获取图表详情
  1120. func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  1121. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  1122. adminId := sysUser.AdminId
  1123. // 指标数据map
  1124. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  1125. defer func() {
  1126. if isOk {
  1127. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  1128. {
  1129. //判断是否加入我的图库
  1130. var myChartCondition string
  1131. var myChartPars []interface{}
  1132. myChartCondition += ` AND a.admin_id=? `
  1133. myChartPars = append(myChartPars, adminId)
  1134. myChartCondition += ` AND a.chart_info_id=? `
  1135. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1136. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1137. if err != nil && err.Error() != utils.ErrNoRow() {
  1138. msg = "获取失败"
  1139. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1140. return
  1141. }
  1142. if myChartList != nil && len(myChartList) > 0 {
  1143. chartInfo.IsAdd = true
  1144. chartInfo.MyChartId = myChartList[0].MyChartId
  1145. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1146. }
  1147. }
  1148. resp.ChartInfo.HaveOperaAuth = true
  1149. // 指标权限
  1150. {
  1151. classifyMap := make(map[int]*data_manage.EdbClassify)
  1152. // 分类
  1153. {
  1154. classifyIdList := make([]int, 0)
  1155. for _, v := range resp.EdbInfoList {
  1156. classifyIdList = append(classifyIdList, v.ClassifyId)
  1157. }
  1158. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  1159. if tmpErr != nil {
  1160. errMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  1161. return
  1162. }
  1163. for _, v := range classifyList {
  1164. classifyMap[v.ClassifyId] = v
  1165. }
  1166. }
  1167. // 指标
  1168. if len(edbClassifyPermissionMap) < 0 {
  1169. edbInfoIdList := make([]int, 0)
  1170. for _, v := range resp.EdbInfoList {
  1171. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  1172. }
  1173. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1174. if tmpErr != nil {
  1175. errMsg = "获取指标列表失败,Err:" + tmpErr.Error()
  1176. return
  1177. }
  1178. for _, v := range edbInfoList {
  1179. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  1180. ClassifyId: v.ClassifyId,
  1181. IsJoinPermission: v.IsJoinPermission,
  1182. EdbInfoId: v.EdbInfoId,
  1183. }
  1184. }
  1185. }
  1186. // 获取所有有权限的指标和分类
  1187. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1188. if err != nil {
  1189. errMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  1190. return
  1191. }
  1192. for _, v := range resp.EdbInfoList {
  1193. // 数据权限
  1194. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  1195. if !ok {
  1196. continue
  1197. }
  1198. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  1199. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1200. }
  1201. }
  1202. }
  1203. }
  1204. if !isOk {
  1205. if errMsg != "" {
  1206. uniqueCode := ""
  1207. if chartInfo != nil {
  1208. uniqueCode = chartInfo.UniqueCode
  1209. }
  1210. tmpTip := fmt.Sprintf("查询图表详情失败,line_equation.GetChartInfoDetailFromUniqueCode UniqueCode:%s,err:%s", uniqueCode, errMsg)
  1211. utils.FileLog.Info(tmpTip)
  1212. go alarm_msg.SendAlarmMsg(tmpTip, 3)
  1213. }
  1214. }
  1215. }()
  1216. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  1217. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  1218. if utils.Re == nil && isCache {
  1219. if utils.Re == nil && utils.Rc.IsExist(key) {
  1220. if chartData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  1221. err := json.Unmarshal(chartData, &resp)
  1222. if err != nil || resp == nil {
  1223. return
  1224. }
  1225. isOk = true
  1226. fmt.Println("source redis")
  1227. return
  1228. }
  1229. }
  1230. }
  1231. // 获取主题样式
  1232. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  1233. if err != nil {
  1234. msg = "获取失败"
  1235. errMsg = "获取主题信息失败,Err:" + err.Error()
  1236. return
  1237. }
  1238. chartInfo.ChartThemeStyle = chartTheme.Config
  1239. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  1240. if chartInfo.ExtraConfig == `` {
  1241. msg = "获取失败"
  1242. errMsg = "获取配置信息失败"
  1243. return
  1244. }
  1245. var lineChartInfoConfig request.LineChartInfoReq
  1246. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &lineChartInfoConfig)
  1247. if err != nil {
  1248. msg = "获取失败"
  1249. errMsg = "获取图表配置信息失败, Err:" + err.Error()
  1250. return
  1251. }
  1252. var getAData, getBData, getR2Data bool
  1253. switch lineChartInfoConfig.Source {
  1254. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
  1255. getAData = true
  1256. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
  1257. getBData = true
  1258. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
  1259. getR2Data = true
  1260. }
  1261. edbList, dataResp, err, errMsg := line_equation.GetChartEdbData(chartInfo.ChartInfoId, lineChartInfoConfig, getAData, getBData, getR2Data)
  1262. if err != nil {
  1263. if errMsg == `` {
  1264. errMsg = "获取失败"
  1265. }
  1266. return
  1267. }
  1268. var resultResp interface{}
  1269. switch lineChartInfoConfig.Source {
  1270. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
  1271. resultResp = dataResp.AData
  1272. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
  1273. resultResp = dataResp.BData
  1274. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
  1275. resultResp = dataResp.R2Data
  1276. }
  1277. if chartInfo.ChartInfoId > 0 && chartInfo != nil {
  1278. //判断是否加入我的图库
  1279. {
  1280. var myChartCondition string
  1281. var myChartPars []interface{}
  1282. myChartCondition += ` AND a.admin_id=? `
  1283. myChartPars = append(myChartPars, sysUser.AdminId)
  1284. myChartCondition += ` AND a.chart_info_id=? `
  1285. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1286. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1287. if err != nil && err.Error() != utils.ErrNoRow() {
  1288. msg = "获取失败"
  1289. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1290. return
  1291. }
  1292. if myChartList != nil && len(myChartList) > 0 {
  1293. chartInfo.IsAdd = true
  1294. chartInfo.MyChartId = myChartList[0].MyChartId
  1295. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1296. }
  1297. }
  1298. }
  1299. //图表操作权限
  1300. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  1301. //判断是否需要展示英文标识
  1302. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, chartInfo.Source, chartInfo.ChartType)
  1303. //chartInfo.UnitEn = edbInfoMappingA.UnitEn
  1304. isSaveAs := true
  1305. // 另存为
  1306. chartInfo.Button = data_manage.ChartViewButton{
  1307. IsEdit: chartInfo.IsEdit,
  1308. IsEnChart: chartInfo.IsEnChart,
  1309. IsAdd: chartInfo.IsAdd,
  1310. IsCopy: isSaveAs,
  1311. IsSetName: chartInfo.IsSetName,
  1312. }
  1313. // 图表的指标来源
  1314. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1315. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1316. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1317. resp.ChartInfo = chartInfo
  1318. resp.EdbInfoList = edbList
  1319. resp.DataResp = resultResp
  1320. resp.Status = true
  1321. // 遍历到校验map
  1322. for _, v := range edbList {
  1323. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  1324. ClassifyId: v.ClassifyId,
  1325. IsJoinPermission: v.IsJoinPermission,
  1326. EdbInfoId: v.EdbInfoId,
  1327. }
  1328. }
  1329. // 将数据加入缓存
  1330. if utils.Re == nil {
  1331. d, _ := json.Marshal(resp)
  1332. _ = utils.Rc.Put(key, d, 2*time.Hour)
  1333. }
  1334. isOk = true
  1335. return
  1336. }
  1337. // EnInfoEdit
  1338. // @Title 编辑图表英文信息接口
  1339. // @Description 编辑图表英文信息接口
  1340. // @Param request body data_manage.EditChartEnInfoReq true "type json string"
  1341. // @Success Ret=200 编辑成功
  1342. // @router /chart_info/en/edit [post]
  1343. func (this *LineEquationChartInfoController) EnInfoEdit() {
  1344. br := new(models.BaseResponse).Init()
  1345. defer func() {
  1346. this.Data["json"] = br
  1347. this.ServeJSON()
  1348. }()
  1349. sysUser := this.SysUser
  1350. if sysUser == nil {
  1351. br.Msg = "请登录"
  1352. br.ErrMsg = "请登录,SysUser Is Empty"
  1353. br.Ret = 408
  1354. return
  1355. }
  1356. var req request.EditChartEnInfoReq
  1357. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1358. if err != nil {
  1359. br.Msg = "参数解析异常!"
  1360. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1361. return
  1362. }
  1363. req.ChartNameEn = strings.Trim(req.ChartNameEn, " ")
  1364. if req.ChartInfoId <= 0 {
  1365. br.Msg = "请选择图表"
  1366. return
  1367. }
  1368. if req.ChartNameEn == "" {
  1369. br.Msg = "请输入英文图表名称"
  1370. return
  1371. }
  1372. //判断指标名称是否存在
  1373. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1374. if err != nil {
  1375. if err.Error() == utils.ErrNoRow() {
  1376. br.Msg = "图表已被删除,请刷新页面"
  1377. br.ErrMsg = "图表已被删除,请刷新页面"
  1378. return
  1379. }
  1380. br.Msg = "获取图表信息失败"
  1381. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1382. return
  1383. }
  1384. // 校验名称是否有重复
  1385. {
  1386. var condition string
  1387. var pars []interface{}
  1388. condition += " AND chart_info_id <> ? AND chart_name_en = ? AND source = ?"
  1389. pars = append(pars, req.ChartInfoId, req.ChartNameEn, utils.CHART_SOURCE_LINE_EQUATION)
  1390. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  1391. if err != nil {
  1392. if err.Error() != utils.ErrNoRow() {
  1393. br.Msg = "判断英文图表名称是否存在失败"
  1394. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  1395. return
  1396. }
  1397. }
  1398. if err == nil && existItem.ChartInfoId > 0 {
  1399. br.Msg = existItem.ChartName + ":" + req.ChartNameEn + "图表名称已存在"
  1400. return
  1401. }
  1402. }
  1403. chartItem.ChartNameEn = req.ChartNameEn
  1404. chartItem.ModifyTime = time.Now().Local()
  1405. if e := chartItem.Update([]string{"ChartNameEn", "ModifyTime"}); e != nil {
  1406. br.Msg = "操作失败"
  1407. br.ErrMsg = "更新图表信息失败, Err: " + e.Error()
  1408. return
  1409. }
  1410. //添加es数据
  1411. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  1412. //修改my eta es数据
  1413. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  1414. //指标 修改es信息
  1415. //go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  1416. //新增操作日志
  1417. {
  1418. chartLog := new(data_manage.ChartInfoLog)
  1419. chartLog.ChartName = chartItem.ChartName
  1420. chartLog.ChartInfoId = req.ChartInfoId
  1421. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  1422. chartLog.SysUserId = sysUser.AdminId
  1423. chartLog.SysUserRealName = sysUser.RealName
  1424. chartLog.UniqueCode = chartItem.UniqueCode
  1425. chartLog.CreateTime = time.Now()
  1426. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1427. chartLog.Status = "编辑拟合方程图表英文信息"
  1428. chartLog.Method = this.Ctx.Input.URL()
  1429. go data_manage.AddChartInfoLog(chartLog)
  1430. }
  1431. // 清除缓存
  1432. if utils.Re == nil && utils.Rc != nil {
  1433. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  1434. _ = utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  1435. }
  1436. br.Ret = 200
  1437. br.Success = true
  1438. br.Msg = "编辑成功"
  1439. br.IsAddLog = true
  1440. }
  1441. // SearchByEs
  1442. // @Title 图表模糊搜索(从es获取)
  1443. // @Description 图表模糊搜索(从es获取)
  1444. // @Param Keyword query string true "图表名称"
  1445. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1446. // @Param Source query int true "来源,3:拟合方程,4:滚动拟合方程,默认0:全部"
  1447. // @Success 200 {object} data_manage.ChartInfo
  1448. // @router /chart_info/search_by_es [get]
  1449. func (this *LineEquationChartInfoController) SearchByEs() {
  1450. br := new(models.BaseResponse).Init()
  1451. defer func() {
  1452. this.Data["json"] = br
  1453. this.ServeJSON()
  1454. }()
  1455. sysUser := this.SysUser
  1456. if sysUser == nil {
  1457. br.Msg = "请登录"
  1458. br.ErrMsg = "请登录,SysUser Is Empty"
  1459. br.Ret = 408
  1460. return
  1461. }
  1462. pageSize, _ := this.GetInt("PageSize")
  1463. currentIndex, _ := this.GetInt("CurrentIndex")
  1464. var startSize int
  1465. if pageSize <= 0 {
  1466. pageSize = utils.PageSize20
  1467. }
  1468. if currentIndex <= 0 {
  1469. currentIndex = 1
  1470. }
  1471. startSize = paging.StartIndex(currentIndex, pageSize)
  1472. keyword := this.GetString("Keyword")
  1473. //只看我的
  1474. isShowMe, _ := this.GetBool("IsShowMe")
  1475. showSysId := 0
  1476. if isShowMe {
  1477. showSysId = sysUser.AdminId
  1478. }
  1479. sourceList := []int{utils.CHART_SOURCE_LINE_EQUATION}
  1480. var searchList []*data_manage.ChartInfo
  1481. var total int64
  1482. var err error
  1483. // 获取当前账号的不可见指标
  1484. noPermissionChartIdList := make([]int, 0)
  1485. {
  1486. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1487. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1488. if err != nil && err.Error() != utils.ErrNoRow() {
  1489. br.Msg = "获取失败"
  1490. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1491. return
  1492. }
  1493. for _, v := range confList {
  1494. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1495. }
  1496. }
  1497. if keyword != "" {
  1498. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  1499. } else {
  1500. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  1501. if err != nil && err.Error() != utils.ErrNoRow() {
  1502. br.Msg = "获取失败"
  1503. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1504. return
  1505. }
  1506. }
  1507. finalList := make([]*data_manage.ChartInfoMore, 0)
  1508. if len(searchList) > 0 {
  1509. chartInfoIds := ""
  1510. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1511. for _, v := range searchList {
  1512. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1513. }
  1514. if chartInfoIds != "" {
  1515. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1516. //判断是否需要展示英文标识
  1517. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1518. if e != nil {
  1519. br.Msg = "获取失败"
  1520. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1521. return
  1522. }
  1523. for _, v := range edbList {
  1524. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1525. }
  1526. }
  1527. for _, v := range searchList {
  1528. tmp := new(data_manage.ChartInfoMore)
  1529. tmp.ChartInfo = *v
  1530. // 图表数据权限
  1531. tmp.HaveOperaAuth = true
  1532. //判断是否需要展示英文标识
  1533. if _, ok := chartEdbMap[v.ChartInfoId]; ok {
  1534. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, v.Source, v.ChartType)
  1535. }
  1536. finalList = append(finalList, tmp)
  1537. }
  1538. }
  1539. //新增搜索词记录
  1540. {
  1541. searchKeyword := new(data_manage.SearchKeyword)
  1542. searchKeyword.KeyWord = keyword
  1543. searchKeyword.CreateTime = time.Now()
  1544. go data_manage.AddSearchKeyword(searchKeyword)
  1545. }
  1546. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1547. resp := data_manage.ChartInfoListByEsResp{
  1548. Paging: page,
  1549. List: finalList,
  1550. }
  1551. br.Ret = 200
  1552. br.Success = true
  1553. br.Msg = "获取成功"
  1554. br.Data = resp
  1555. }
  1556. // BaseInfoEdit
  1557. // @Title 编辑图表基础信息接口
  1558. // @Description 编辑图表基础信息接口
  1559. // @Param request body data_manage.EditChartBaseInfoReq true "type json string"
  1560. // @Success Ret=200 编辑成功
  1561. // @router /chart_info/base/edit [post]
  1562. func (this *LineEquationChartInfoController) BaseInfoEdit() {
  1563. br := new(models.BaseResponse).Init()
  1564. defer func() {
  1565. this.Data["json"] = br
  1566. this.ServeJSON()
  1567. }()
  1568. sysUser := this.SysUser
  1569. if sysUser == nil {
  1570. br.Msg = "请登录"
  1571. br.ErrMsg = "请登录,SysUser Is Empty"
  1572. br.Ret = 408
  1573. return
  1574. }
  1575. var req request.EditChartBaseInfoReq
  1576. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1577. if err != nil {
  1578. br.Msg = "参数解析异常!"
  1579. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1580. return
  1581. }
  1582. req.ChartName = strings.Trim(req.ChartName, " ")
  1583. if req.ChartInfoId <= 0 {
  1584. br.Msg = "请选择图表"
  1585. return
  1586. }
  1587. if req.ChartName == "" {
  1588. br.Msg = "请输入英文图表名称"
  1589. return
  1590. }
  1591. //判断指标名称是否存在
  1592. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1593. if err != nil {
  1594. if err.Error() == utils.ErrNoRow() {
  1595. br.Msg = "图表已被删除,请刷新页面"
  1596. br.ErrMsg = "图表已被删除,请刷新页面"
  1597. return
  1598. }
  1599. br.Msg = "获取图表信息失败"
  1600. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1601. return
  1602. }
  1603. // 校验名称是否有重复
  1604. {
  1605. var condition string
  1606. var pars []interface{}
  1607. condition += " AND chart_info_id <> ? AND source = ? "
  1608. pars = append(pars, req.ChartInfoId, utils.CHART_SOURCE_LINE_EQUATION)
  1609. switch this.Lang {
  1610. case utils.EnLangVersion:
  1611. condition += " AND chart_name_en = ? "
  1612. default:
  1613. condition += " AND chart_name = ? "
  1614. }
  1615. pars = append(pars, req.ChartName)
  1616. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  1617. if err != nil {
  1618. if err.Error() != utils.ErrNoRow() {
  1619. br.Msg = "判断英文图表名称是否存在失败"
  1620. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  1621. return
  1622. }
  1623. }
  1624. if err == nil && existItem.ChartInfoId > 0 {
  1625. br.Msg = existItem.ChartName + ":" + req.ChartName + "图表名称已存在"
  1626. return
  1627. }
  1628. }
  1629. switch this.Lang {
  1630. case utils.EnLangVersion:
  1631. chartItem.ChartNameEn = req.ChartName
  1632. default:
  1633. chartItem.ChartName = req.ChartName
  1634. }
  1635. chartItem.ModifyTime = time.Now().Local()
  1636. if e := chartItem.Update([]string{"ChartName", "ChartNameEn", "ModifyTime"}); e != nil {
  1637. br.Msg = "操作失败"
  1638. br.ErrMsg = "更新图表信息失败, Err: " + e.Error()
  1639. return
  1640. }
  1641. //添加es数据
  1642. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  1643. //修改my eta es数据
  1644. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  1645. //新增操作日志
  1646. {
  1647. chartLog := new(data_manage.ChartInfoLog)
  1648. chartLog.ChartName = chartItem.ChartName
  1649. chartLog.ChartInfoId = req.ChartInfoId
  1650. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  1651. chartLog.SysUserId = sysUser.AdminId
  1652. chartLog.SysUserRealName = sysUser.RealName
  1653. chartLog.UniqueCode = chartItem.UniqueCode
  1654. chartLog.CreateTime = time.Now()
  1655. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1656. chartLog.Status = "编辑拟合方程图表基础信息"
  1657. chartLog.Method = this.Ctx.Input.URL()
  1658. go data_manage.AddChartInfoLog(chartLog)
  1659. }
  1660. // 清除缓存
  1661. if utils.Re == nil && utils.Rc != nil {
  1662. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  1663. _ = utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  1664. }
  1665. br.Ret = 200
  1666. br.Success = true
  1667. br.Msg = "编辑成功"
  1668. br.IsAddLog = true
  1669. }