line_chart_info.go 55 KB

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