line_chart_info.go 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575
  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/data"
  11. "eta/eta_api/services/data/data_manage_permission"
  12. "eta/eta_api/services/data/line_equation"
  13. "eta/eta_api/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)
  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. resp := new(data_manage.ChartInfoDetailResp)
  778. resp.ChartInfo = chartInfo
  779. resp.EdbInfoList = edbList
  780. resp.DataResp = resultResp
  781. br.Ret = 200
  782. br.Success = true
  783. br.Msg = "获取成功"
  784. br.Data = resp
  785. }
  786. // DetailFromUniqueCode
  787. // @Title 根据编码获取图表详情
  788. // @Description 根据编码获取图表详情接口
  789. // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  790. // @Param IsCache query bool true "是否走缓存,默认false"
  791. // @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
  792. // @router /chart_info/detail/from_unique_code [get]
  793. func (this *LineEquationChartInfoController) DetailFromUniqueCode() {
  794. br := new(models.BaseResponse).Init()
  795. defer func() {
  796. this.Data["json"] = br
  797. this.ServeJSON()
  798. }()
  799. sysUser := this.SysUser
  800. if sysUser == nil {
  801. br.Msg = "请登录"
  802. br.ErrMsg = "请登录,SysUser Is Empty"
  803. br.Ret = 408
  804. return
  805. }
  806. adminId := sysUser.AdminId
  807. uniqueCode := this.GetString("UniqueCode")
  808. if uniqueCode == "" {
  809. br.Msg = "参数错误"
  810. br.ErrMsg = "参数错误,uniqueCode is empty"
  811. return
  812. }
  813. //是否走缓存
  814. isCache, _ := this.GetBool("IsCache")
  815. resp := new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  816. status := true
  817. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  818. if err != nil {
  819. if err.Error() == utils.ErrNoRow() {
  820. status = false
  821. } else {
  822. br.Msg = "获取失败"
  823. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  824. return
  825. }
  826. }
  827. if chartInfo == nil {
  828. status = false
  829. }
  830. if !status {
  831. endInfoList := make([]*data_manage.ChartEdbInfoMapping, 0)
  832. resp.EdbInfoList = endInfoList
  833. resp.ChartInfo = chartInfo
  834. resp.Status = false
  835. br.Ret = 200
  836. br.Success = true
  837. br.Msg = "获取成功"
  838. br.Data = resp
  839. return
  840. }
  841. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  842. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  843. if utils.Re == nil && isCache {
  844. if utils.Re == nil && utils.Rc.IsExist(key) {
  845. if d, e := utils.Rc.RedisBytes(key); e == nil {
  846. err := json.Unmarshal(d, &resp)
  847. if err == nil && resp != nil {
  848. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  849. var myCond string
  850. var myPars []interface{}
  851. myCond += ` AND a.admin_id=? `
  852. myPars = append(myPars, adminId)
  853. myCond += ` AND a.chart_info_id=? `
  854. myPars = append(myPars, chartInfo.ChartInfoId)
  855. myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
  856. if err != nil && err.Error() != utils.ErrNoRow() {
  857. br.Msg = "获取失败"
  858. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  859. return
  860. }
  861. resp.ChartInfo.IsAdd = false
  862. resp.ChartInfo.MyChartId = 0
  863. resp.ChartInfo.MyChartClassifyId = ""
  864. if myList != nil && len(myList) > 0 {
  865. resp.ChartInfo.IsAdd = true
  866. resp.ChartInfo.MyChartId = myList[0].MyChartId
  867. resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
  868. }
  869. br.Ret = 200
  870. br.Success = true
  871. br.Msg = "获取成功"
  872. br.Data = resp
  873. return
  874. }
  875. }
  876. }
  877. }
  878. resp, isOk, msg, errMsg := GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  879. if !isOk {
  880. br.Msg = msg
  881. br.ErrMsg = errMsg
  882. return
  883. }
  884. if !isOk {
  885. br.Msg = msg
  886. br.ErrMsg = errMsg
  887. return
  888. }
  889. br.Ret = 200
  890. br.Success = true
  891. br.Msg = "获取成功"
  892. br.Data = resp
  893. }
  894. // Refresh
  895. // @Title 图表刷新接口
  896. // @Description 图表刷新接口
  897. // @Param ChartInfoId query int true "图表id"
  898. // @Param UniqueCode query string true "唯一code"
  899. // @Success Ret=200 刷新成功
  900. // @router /chart_info/refresh [get]
  901. func (this *LineEquationChartInfoController) Refresh() {
  902. br := new(models.BaseResponse).Init()
  903. defer func() {
  904. this.Data["json"] = br
  905. this.ServeJSON()
  906. }()
  907. sysUser := this.SysUser
  908. if sysUser == nil {
  909. br.Msg = "请登录"
  910. br.ErrMsg = "请登录,SysUser Is Empty"
  911. br.Ret = 408
  912. return
  913. }
  914. chartInfoId, _ := this.GetInt("ChartInfoId")
  915. uniqueCode := this.GetString("UniqueCode")
  916. if chartInfoId <= 0 && uniqueCode == `` {
  917. br.Msg = "参数错误"
  918. br.ErrMsg = "参数错误:chartInfoId:" + strconv.Itoa(chartInfoId) + ",UniqueCode:" + uniqueCode
  919. return
  920. }
  921. var chartInfo *data_manage.ChartInfo
  922. var err error
  923. if chartInfoId > 0 {
  924. chartInfo, err = data_manage.GetChartInfoById(chartInfoId)
  925. } else {
  926. chartInfo, err = data_manage.GetChartInfoByUniqueCode(uniqueCode)
  927. }
  928. if err != nil {
  929. if err.Error() == utils.ErrNoRow() {
  930. br.Msg = "图表已被删除,无需刷新"
  931. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  932. return
  933. }
  934. br.Msg = "刷新失败"
  935. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  936. return
  937. }
  938. // 刷新图表的指标信息
  939. err, isAsync := data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
  940. //清除图表缓存
  941. {
  942. key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
  943. _ = utils.Rc.Delete(key)
  944. }
  945. br.Ret = 200
  946. br.Success = true
  947. br.Msg = "刷新成功"
  948. if isAsync {
  949. br.Msg = "图表关联指标较多,请10分钟后刷新页面查看最新数据"
  950. }
  951. }
  952. // Copy
  953. // @Title 复制并新增图表接口
  954. // @Description 新增图表接口
  955. // @Param request body data_manage.CopyAddChartInfoReq true "type json string"
  956. // @Success 200 {object} data_manage.AddChartInfoResp
  957. // @router /chart_info/copy [post]
  958. func (this *LineEquationChartInfoController) Copy() {
  959. br := new(models.BaseResponse).Init()
  960. defer func() {
  961. this.Data["json"] = br
  962. this.ServeJSON()
  963. }()
  964. sysUser := this.SysUser
  965. if sysUser == nil {
  966. br.Msg = "请登录"
  967. br.ErrMsg = "请登录,SysUser Is Empty"
  968. br.Ret = 408
  969. return
  970. }
  971. deleteCache := true
  972. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  973. defer func() {
  974. if deleteCache {
  975. utils.Rc.Delete(cacheKey)
  976. }
  977. }()
  978. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  979. deleteCache = false
  980. br.Msg = "系统处理中,请稍后重试!"
  981. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  982. return
  983. }
  984. var req data_manage.CopyAddChartInfoReq
  985. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  986. if err != nil {
  987. br.Msg = "参数解析异常!"
  988. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  989. return
  990. }
  991. // 获取原图表信息
  992. oldChartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  993. if err != nil {
  994. br.Msg = "获取原图表信息失败"
  995. br.ErrMsg = "获取原图表信息失败,Err:" + err.Error()
  996. return
  997. }
  998. if oldChartInfo.Source != utils.CHART_SOURCE_LINE_EQUATION {
  999. br.Msg = `错误的图表类型`
  1000. br.IsSendEmail = false
  1001. return
  1002. }
  1003. var lineChartInfoConf request.LineChartInfoReq
  1004. err = json.Unmarshal([]byte(oldChartInfo.ExtraConfig), &lineChartInfoConf)
  1005. addChartList := make([]request.AddChart, 0)
  1006. addChartList = append(addChartList, request.AddChart{
  1007. Source: lineChartInfoConf.Source,
  1008. ChartClassifyId: req.ChartClassifyId,
  1009. ChartName: req.ChartName,
  1010. LeftMin: oldChartInfo.LeftMin,
  1011. LeftMax: oldChartInfo.LeftMax,
  1012. ChartImage: oldChartInfo.ChartImage,
  1013. ChartThemeId: oldChartInfo.ChartThemeId,
  1014. SourcesFrom: oldChartInfo.SourcesFrom,
  1015. Instructions: oldChartInfo.Instructions,
  1016. MarkersLines: oldChartInfo.MarkersLines,
  1017. MarkersAreas: oldChartInfo.MarkersAreas,
  1018. })
  1019. resp := new(data_manage.AddChartInfoResp)
  1020. batchAddChartList, err, errMsg, isSendEmail := line_equation.BatchAddChartInfo(addChartList, lineChartInfoConf, sysUser)
  1021. if err != nil {
  1022. br.Msg = "保存失败"
  1023. if errMsg != `` {
  1024. br.Msg = errMsg
  1025. }
  1026. br.ErrMsg = err.Error()
  1027. br.IsSendEmail = isSendEmail
  1028. return
  1029. }
  1030. resp.ChartInfoId = batchAddChartList[0].ChartInfo.ChartInfoId
  1031. resp.UniqueCode = batchAddChartList[0].ChartInfo.UniqueCode
  1032. resp.ChartType = batchAddChartList[0].ChartInfo.ChartType
  1033. //新增操作日志
  1034. {
  1035. for _, v := range batchAddChartList {
  1036. chartInfo := v.ChartInfo
  1037. chartLog := new(data_manage.ChartInfoLog)
  1038. chartLog.ChartInfoId = chartInfo.ChartInfoId
  1039. chartLog.ChartName = chartInfo.ChartName
  1040. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  1041. chartLog.SysUserId = sysUser.AdminId
  1042. chartLog.SysUserRealName = sysUser.RealName
  1043. chartLog.UniqueCode = chartInfo.UniqueCode
  1044. chartLog.CreateTime = time.Now()
  1045. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1046. chartLog.Status = "新增拟合方程图表"
  1047. chartLog.Method = this.Ctx.Input.URI()
  1048. go data_manage.AddChartInfoLog(chartLog)
  1049. }
  1050. }
  1051. br.Ret = 200
  1052. br.Data = resp
  1053. br.Success = true
  1054. br.Msg = "保存成功"
  1055. br.IsAddLog = true
  1056. }
  1057. // GetChartInfoDetailFromUniqueCode 根据编码获取图表详情
  1058. func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  1059. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  1060. adminId := sysUser.AdminId
  1061. defer func() {
  1062. if isOk {
  1063. resp.ChartInfo.HaveOperaAuth = true
  1064. // 指标权限
  1065. {
  1066. classifyMap := make(map[int]*data_manage.EdbClassify)
  1067. // 分类
  1068. {
  1069. classifyIdList := make([]int, 0)
  1070. for _, v := range resp.EdbInfoList {
  1071. classifyIdList = append(classifyIdList, v.ClassifyId)
  1072. }
  1073. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  1074. if tmpErr != nil {
  1075. errMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  1076. return
  1077. }
  1078. for _, v := range classifyList {
  1079. classifyMap[v.ClassifyId] = v
  1080. }
  1081. }
  1082. // 获取所有有权限的指标和分类
  1083. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1084. if err != nil {
  1085. errMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  1086. return
  1087. }
  1088. for _, item := range resp.EdbInfoList {
  1089. // 数据权限
  1090. if currClassify, ok := classifyMap[item.ClassifyId]; ok {
  1091. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(item.IsJoinPermission, currClassify.IsJoinPermission, item.EdbInfoId, item.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1092. }
  1093. }
  1094. }
  1095. }
  1096. }()
  1097. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  1098. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  1099. if utils.Re == nil && isCache {
  1100. if utils.Re == nil && utils.Rc.IsExist(key) {
  1101. if chartData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  1102. err := json.Unmarshal(chartData, &resp)
  1103. if err == nil && resp != nil {
  1104. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  1105. var myCond string
  1106. var myPars []interface{}
  1107. myCond += ` AND a.admin_id=? `
  1108. myPars = append(myPars, adminId)
  1109. myCond += ` AND a.chart_info_id=? `
  1110. myPars = append(myPars, chartInfo.ChartInfoId)
  1111. myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
  1112. if err != nil && err.Error() != utils.ErrNoRow() {
  1113. msg = "获取失败"
  1114. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1115. return
  1116. }
  1117. resp.ChartInfo.IsAdd = false
  1118. resp.ChartInfo.MyChartId = 0
  1119. resp.ChartInfo.MyChartClassifyId = ""
  1120. if myList != nil && len(myList) > 0 {
  1121. resp.ChartInfo.IsAdd = true
  1122. resp.ChartInfo.MyChartId = myList[0].MyChartId
  1123. resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
  1124. }
  1125. isOk = true
  1126. fmt.Println("source redis")
  1127. return
  1128. }
  1129. }
  1130. }
  1131. }
  1132. // 获取主题样式
  1133. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  1134. if err != nil {
  1135. msg = "获取失败"
  1136. errMsg = "获取主题信息失败,Err:" + err.Error()
  1137. return
  1138. }
  1139. chartInfo.ChartThemeStyle = chartTheme.Config
  1140. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  1141. if chartInfo.ExtraConfig == `` {
  1142. msg = "获取失败"
  1143. errMsg = "获取配置信息失败"
  1144. return
  1145. }
  1146. var lineChartInfoConfig request.LineChartInfoReq
  1147. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &lineChartInfoConfig)
  1148. if err != nil {
  1149. msg = "获取失败"
  1150. errMsg = "获取图表配置信息失败, Err:" + err.Error()
  1151. return
  1152. }
  1153. var getAData, getBData, getR2Data bool
  1154. switch lineChartInfoConfig.Source {
  1155. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
  1156. getAData = true
  1157. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
  1158. getBData = true
  1159. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
  1160. getR2Data = true
  1161. }
  1162. edbList, dataResp, err, errMsg := line_equation.GetChartEdbData(chartInfo.ChartInfoId, lineChartInfoConfig, getAData, getBData, getR2Data)
  1163. if err != nil {
  1164. if errMsg == `` {
  1165. errMsg = "获取失败"
  1166. }
  1167. return
  1168. }
  1169. var resultResp interface{}
  1170. switch lineChartInfoConfig.Source {
  1171. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
  1172. resultResp = dataResp.AData
  1173. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
  1174. resultResp = dataResp.BData
  1175. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
  1176. resultResp = dataResp.R2Data
  1177. }
  1178. if chartInfo.ChartInfoId > 0 && chartInfo != nil {
  1179. //判断是否加入我的图库
  1180. {
  1181. var myChartCondition string
  1182. var myChartPars []interface{}
  1183. myChartCondition += ` AND a.admin_id=? `
  1184. myChartPars = append(myChartPars, sysUser.AdminId)
  1185. myChartCondition += ` AND a.chart_info_id=? `
  1186. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1187. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1188. if err != nil && err.Error() != utils.ErrNoRow() {
  1189. msg = "获取失败"
  1190. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1191. return
  1192. }
  1193. if myChartList != nil && len(myChartList) > 0 {
  1194. chartInfo.IsAdd = true
  1195. chartInfo.MyChartId = myChartList[0].MyChartId
  1196. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1197. }
  1198. }
  1199. }
  1200. //图表操作权限
  1201. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  1202. //判断是否需要展示英文标识
  1203. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, chartInfo.Source, chartInfo.ChartType)
  1204. //chartInfo.UnitEn = edbInfoMappingA.UnitEn
  1205. isSaveAs := true
  1206. // 另存为
  1207. chartInfo.Button = data_manage.ChartViewButton{
  1208. IsEdit: chartInfo.IsEdit,
  1209. IsEnChart: chartInfo.IsEnChart,
  1210. IsAdd: chartInfo.IsAdd,
  1211. IsCopy: isSaveAs,
  1212. IsSetName: chartInfo.IsSetName,
  1213. }
  1214. // 图表的指标来源
  1215. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1216. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1217. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1218. resp.ChartInfo = chartInfo
  1219. resp.EdbInfoList = edbList
  1220. resp.DataResp = resultResp
  1221. resp.Status = true
  1222. // 将数据加入缓存
  1223. if utils.Re == nil {
  1224. d, _ := json.Marshal(resp)
  1225. _ = utils.Rc.Put(key, d, 2*time.Hour)
  1226. }
  1227. isOk = true
  1228. return
  1229. }
  1230. // EnInfoEdit
  1231. // @Title 编辑图表英文信息接口
  1232. // @Description 编辑图表英文信息接口
  1233. // @Param request body data_manage.EditChartEnInfoReq true "type json string"
  1234. // @Success Ret=200 编辑成功
  1235. // @router /chart_info/en/edit [post]
  1236. func (this *LineEquationChartInfoController) EnInfoEdit() {
  1237. br := new(models.BaseResponse).Init()
  1238. defer func() {
  1239. this.Data["json"] = br
  1240. this.ServeJSON()
  1241. }()
  1242. sysUser := this.SysUser
  1243. if sysUser == nil {
  1244. br.Msg = "请登录"
  1245. br.ErrMsg = "请登录,SysUser Is Empty"
  1246. br.Ret = 408
  1247. return
  1248. }
  1249. var req request.EditChartEnInfoReq
  1250. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1251. if err != nil {
  1252. br.Msg = "参数解析异常!"
  1253. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1254. return
  1255. }
  1256. req.ChartNameEn = strings.Trim(req.ChartNameEn, " ")
  1257. if req.ChartInfoId <= 0 {
  1258. br.Msg = "请选择图表"
  1259. return
  1260. }
  1261. if req.ChartNameEn == "" {
  1262. br.Msg = "请输入英文图表名称"
  1263. return
  1264. }
  1265. //判断指标名称是否存在
  1266. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1267. if err != nil {
  1268. if err.Error() == utils.ErrNoRow() {
  1269. br.Msg = "图表已被删除,请刷新页面"
  1270. br.ErrMsg = "图表已被删除,请刷新页面"
  1271. return
  1272. }
  1273. br.Msg = "获取图表信息失败"
  1274. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1275. return
  1276. }
  1277. // 校验名称是否有重复
  1278. {
  1279. var condition string
  1280. var pars []interface{}
  1281. condition += " AND chart_info_id <> ? AND chart_name_en = ? AND source = ?"
  1282. pars = append(pars, req.ChartInfoId, req.ChartNameEn, utils.CHART_SOURCE_LINE_EQUATION)
  1283. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  1284. if err != nil {
  1285. if err.Error() != utils.ErrNoRow() {
  1286. br.Msg = "判断英文图表名称是否存在失败"
  1287. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  1288. return
  1289. }
  1290. }
  1291. if err == nil && existItem.ChartInfoId > 0 {
  1292. br.Msg = existItem.ChartName + ":" + req.ChartNameEn + "图表名称已存在"
  1293. return
  1294. }
  1295. }
  1296. chartItem.ChartNameEn = req.ChartNameEn
  1297. chartItem.ModifyTime = time.Now().Local()
  1298. if e := chartItem.Update([]string{"ChartNameEn", "ModifyTime"}); e != nil {
  1299. br.Msg = "操作失败"
  1300. br.ErrMsg = "更新图表信息失败, Err: " + e.Error()
  1301. return
  1302. }
  1303. //添加es数据
  1304. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  1305. //修改my eta es数据
  1306. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  1307. //指标 修改es信息
  1308. //go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  1309. //新增操作日志
  1310. {
  1311. chartLog := new(data_manage.ChartInfoLog)
  1312. chartLog.ChartName = chartItem.ChartName
  1313. chartLog.ChartInfoId = req.ChartInfoId
  1314. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  1315. chartLog.SysUserId = sysUser.AdminId
  1316. chartLog.SysUserRealName = sysUser.RealName
  1317. chartLog.UniqueCode = chartItem.UniqueCode
  1318. chartLog.CreateTime = time.Now()
  1319. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1320. chartLog.Status = "编辑拟合方程图表英文信息"
  1321. chartLog.Method = this.Ctx.Input.URL()
  1322. go data_manage.AddChartInfoLog(chartLog)
  1323. }
  1324. // 清除缓存
  1325. if utils.Re == nil && utils.Rc != nil {
  1326. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  1327. _ = utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  1328. }
  1329. br.Ret = 200
  1330. br.Success = true
  1331. br.Msg = "编辑成功"
  1332. br.IsAddLog = true
  1333. }
  1334. // SearchByEs
  1335. // @Title 图表模糊搜索(从es获取)
  1336. // @Description 图表模糊搜索(从es获取)
  1337. // @Param Keyword query string true "图表名称"
  1338. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1339. // @Param Source query int true "来源,3:拟合方程,4:滚动拟合方程,默认0:全部"
  1340. // @Success 200 {object} data_manage.ChartInfo
  1341. // @router /chart_info/search_by_es [get]
  1342. func (this *LineEquationChartInfoController) SearchByEs() {
  1343. br := new(models.BaseResponse).Init()
  1344. defer func() {
  1345. this.Data["json"] = br
  1346. this.ServeJSON()
  1347. }()
  1348. sysUser := this.SysUser
  1349. if sysUser == nil {
  1350. br.Msg = "请登录"
  1351. br.ErrMsg = "请登录,SysUser Is Empty"
  1352. br.Ret = 408
  1353. return
  1354. }
  1355. pageSize, _ := this.GetInt("PageSize")
  1356. currentIndex, _ := this.GetInt("CurrentIndex")
  1357. var startSize int
  1358. if pageSize <= 0 {
  1359. pageSize = utils.PageSize20
  1360. }
  1361. if currentIndex <= 0 {
  1362. currentIndex = 1
  1363. }
  1364. startSize = paging.StartIndex(currentIndex, pageSize)
  1365. keyword := this.GetString("Keyword")
  1366. //只看我的
  1367. isShowMe, _ := this.GetBool("IsShowMe")
  1368. showSysId := 0
  1369. if isShowMe {
  1370. showSysId = sysUser.AdminId
  1371. }
  1372. sourceList := []int{utils.CHART_SOURCE_LINE_EQUATION}
  1373. var searchList []*data_manage.ChartInfo
  1374. var total int64
  1375. var err error
  1376. // 获取当前账号的不可见指标
  1377. noPermissionChartIdList := make([]int, 0)
  1378. {
  1379. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1380. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1381. if err != nil && err.Error() != utils.ErrNoRow() {
  1382. br.Msg = "获取失败"
  1383. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1384. return
  1385. }
  1386. for _, v := range confList {
  1387. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1388. }
  1389. }
  1390. if keyword != "" {
  1391. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  1392. } else {
  1393. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  1394. if err != nil && err.Error() != utils.ErrNoRow() {
  1395. br.Msg = "获取失败"
  1396. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1397. return
  1398. }
  1399. }
  1400. finalList := make([]*data_manage.ChartInfoMore, 0)
  1401. if len(searchList) > 0 {
  1402. chartInfoIds := ""
  1403. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1404. for _, v := range searchList {
  1405. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1406. }
  1407. if chartInfoIds != "" {
  1408. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1409. //判断是否需要展示英文标识
  1410. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1411. if e != nil {
  1412. br.Msg = "获取失败"
  1413. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1414. return
  1415. }
  1416. for _, v := range edbList {
  1417. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1418. }
  1419. }
  1420. for _, v := range searchList {
  1421. tmp := new(data_manage.ChartInfoMore)
  1422. tmp.ChartInfo = *v
  1423. //判断是否需要展示英文标识
  1424. if _, ok := chartEdbMap[v.ChartInfoId]; ok {
  1425. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, v.Source, v.ChartType)
  1426. }
  1427. finalList = append(finalList, tmp)
  1428. }
  1429. }
  1430. //新增搜索词记录
  1431. {
  1432. searchKeyword := new(data_manage.SearchKeyword)
  1433. searchKeyword.KeyWord = keyword
  1434. searchKeyword.CreateTime = time.Now()
  1435. go data_manage.AddSearchKeyword(searchKeyword)
  1436. }
  1437. page := paging.GetPaging(currentIndex, pageSize, int(total))
  1438. resp := data_manage.ChartInfoListByEsResp{
  1439. Paging: page,
  1440. List: finalList,
  1441. }
  1442. br.Ret = 200
  1443. br.Success = true
  1444. br.Msg = "获取成功"
  1445. br.Data = resp
  1446. }