line_chart_info.go 47 KB

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