line_chart_info.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. package line_equation
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_ETA_mobile_api/controllers"
  7. "hongze/hongze_ETA_mobile_api/models"
  8. "hongze/hongze_ETA_mobile_api/models/data_manage"
  9. "hongze/hongze_ETA_mobile_api/models/data_manage/line_equation/request"
  10. "hongze/hongze_ETA_mobile_api/models/system"
  11. "hongze/hongze_ETA_mobile_api/services/data"
  12. "hongze/hongze_ETA_mobile_api/services/data/line_equation"
  13. "hongze/hongze_ETA_mobile_api/utils"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // LineEquationChartInfoController 拟合方程图表管理
  19. type LineEquationChartInfoController struct {
  20. controllers.BaseAuthController
  21. }
  22. // List
  23. // @Title 拟合方程图表列表接口
  24. // @Description 拟合方程图表列表接口
  25. // @Param PageSize query int true "每页数据条数"
  26. // @Param CurrentIndex query int true "当前页页码,从1开始"
  27. // @Param ChartClassifyId query int true "分类id"
  28. // @Param Keyword query string true "搜索关键词"
  29. // @Param IsShowMe query bool true "是否只看我的,true、false"
  30. // @Param Source query int true "图表类型,3:拟合方程,4:滚动拟合方程"
  31. // @Success 200 {object} data_manage.ChartListResp
  32. // @router /chart_info/list [get]
  33. func (this *LineEquationChartInfoController) List() {
  34. br := new(models.BaseResponse).Init()
  35. defer func() {
  36. this.Data["json"] = br
  37. this.ServeJSON()
  38. }()
  39. sysUser := this.SysUser
  40. if sysUser == nil {
  41. br.Msg = "请登录"
  42. br.ErrMsg = "请登录,SysUser Is Empty"
  43. br.Ret = 408
  44. return
  45. }
  46. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  47. pageSize, _ := this.GetInt("PageSize")
  48. currentIndex, _ := this.GetInt("CurrentIndex")
  49. keyword := this.GetString("KeyWord")
  50. var total int
  51. page := paging.GetPaging(currentIndex, pageSize, total)
  52. var startSize int
  53. if pageSize <= 0 {
  54. pageSize = utils.PageSize20
  55. }
  56. if currentIndex <= 0 {
  57. currentIndex = 1
  58. }
  59. startSize = paging.StartIndex(currentIndex, pageSize)
  60. source, _ := this.GetInt("Source")
  61. if source <= 0 {
  62. source = utils.CHART_SOURCE_LINE_EQUATION
  63. }
  64. var condition string
  65. var pars []interface{}
  66. // 普通图表
  67. condition += ` AND source = ? `
  68. pars = append(pars, source)
  69. if chartClassifyId > 0 {
  70. chartClassifyId, err := data_manage.GetChartClassify(chartClassifyId)
  71. if err != nil && err.Error() != utils.ErrNoRow() {
  72. br.Msg = "获取图表信息失败"
  73. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  74. return
  75. }
  76. condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  77. }
  78. if keyword != "" {
  79. condition += ` AND ( chart_name LIKE '%` + keyword + `%' )`
  80. }
  81. //只看我的
  82. isShowMe, _ := this.GetBool("IsShowMe")
  83. if isShowMe {
  84. condition += ` AND sys_user_id = ? `
  85. pars = append(pars, sysUser.AdminId)
  86. }
  87. // 获取当前账号的不可见指标
  88. noPermissionChartIdList := make([]int, 0)
  89. {
  90. obj := data_manage.EdbInfoNoPermissionAdmin{}
  91. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  92. if err != nil && err.Error() != utils.ErrNoRow() {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  95. return
  96. }
  97. for _, v := range confList {
  98. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  99. }
  100. }
  101. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  102. if lenNoPermissionChartIdList > 0 {
  103. condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  104. pars = append(pars, noPermissionChartIdList)
  105. }
  106. //获取图表信息
  107. list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
  108. if err != nil && err.Error() != utils.ErrNoRow() {
  109. br.Success = true
  110. br.Msg = "获取图表信息失败"
  111. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  112. return
  113. }
  114. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  115. if err != nil && err.Error() != utils.ErrNoRow() {
  116. br.Msg = "获取图表信息失败"
  117. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  118. return
  119. }
  120. myChartMap := make(map[int]*data_manage.MyChartView)
  121. for _, v := range myChartList {
  122. myChartMap[v.ChartInfoId] = v
  123. }
  124. listLen := len(list)
  125. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  126. if listLen > 0 {
  127. chartInfoIds := ""
  128. for _, v := range list {
  129. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  130. }
  131. if chartInfoIds != "" {
  132. chartInfoIds = strings.Trim(chartInfoIds, ",")
  133. //判断是否需要展示英文标识
  134. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  135. if e != nil {
  136. br.Msg = "获取失败"
  137. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  138. return
  139. }
  140. for _, v := range edbList {
  141. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  142. }
  143. }
  144. }
  145. for i := 0; i < listLen; i++ {
  146. //判断是否需要展示英文标识
  147. if _, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  148. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, list[i].Source, list[i].ChartType)
  149. }
  150. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  151. list[i].IsAdd = true
  152. list[i].MyChartId = existItem.MyChartId
  153. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  154. }
  155. }
  156. resp := new(data_manage.ChartListResp)
  157. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  158. items := make([]*data_manage.ChartInfoView, 0)
  159. resp.Paging = page
  160. resp.List = items
  161. br.Ret = 200
  162. br.Success = true
  163. br.Msg = "获取成功"
  164. return
  165. }
  166. dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
  167. if err != nil && err.Error() != utils.ErrNoRow() {
  168. br.Msg = "获取指标信息失败"
  169. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  170. return
  171. }
  172. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  173. resp.Paging = page
  174. resp.List = list
  175. br.Ret = 200
  176. br.Success = true
  177. br.Msg = "获取成功"
  178. br.Data = resp
  179. }
  180. // Refresh
  181. // @Title 图表刷新接口
  182. // @Description 图表刷新接口
  183. // @Param ChartInfoId query int true "图表id"
  184. // @Param UniqueCode query string true "唯一code"
  185. // @Success Ret=200 刷新成功
  186. // @router /chart_info/refresh [get]
  187. func (this *LineEquationChartInfoController) Refresh() {
  188. br := new(models.BaseResponse).Init()
  189. defer func() {
  190. this.Data["json"] = br
  191. this.ServeJSON()
  192. }()
  193. sysUser := this.SysUser
  194. if sysUser == nil {
  195. br.Msg = "请登录"
  196. br.ErrMsg = "请登录,SysUser Is Empty"
  197. br.Ret = 408
  198. return
  199. }
  200. chartInfoId, _ := this.GetInt("ChartInfoId")
  201. uniqueCode := this.GetString("UniqueCode")
  202. if chartInfoId <= 0 && uniqueCode == `` {
  203. br.Msg = "参数错误"
  204. br.ErrMsg = "参数错误:chartInfoId:" + strconv.Itoa(chartInfoId) + ",UniqueCode:" + uniqueCode
  205. return
  206. }
  207. var chartInfo *data_manage.ChartInfo
  208. var err error
  209. if chartInfoId > 0 {
  210. chartInfo, err = data_manage.GetChartInfoById(chartInfoId)
  211. } else {
  212. chartInfo, err = data_manage.GetChartInfoByUniqueCode(uniqueCode)
  213. }
  214. if err != nil {
  215. if err.Error() == utils.ErrNoRow() {
  216. br.Msg = "图表已被删除,无需刷新"
  217. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  218. return
  219. }
  220. br.Msg = "刷新失败"
  221. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  222. return
  223. }
  224. // 刷新图表的指标信息
  225. err = data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
  226. //清除图表缓存
  227. {
  228. key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
  229. _ = utils.Rc.Delete(key)
  230. }
  231. br.Ret = 200
  232. br.Success = true
  233. br.Msg = "刷新成功"
  234. }
  235. // Copy
  236. // @Title 复制并新增图表接口
  237. // @Description 新增图表接口
  238. // @Param request body data_manage.CopyAddChartInfoReq true "type json string"
  239. // @Success 200 {object} data_manage.AddChartInfoResp
  240. // @router /chart_info/copy [post]
  241. func (this *LineEquationChartInfoController) Copy() {
  242. br := new(models.BaseResponse).Init()
  243. defer func() {
  244. this.Data["json"] = br
  245. this.ServeJSON()
  246. }()
  247. sysUser := this.SysUser
  248. if sysUser == nil {
  249. br.Msg = "请登录"
  250. br.ErrMsg = "请登录,SysUser Is Empty"
  251. br.Ret = 408
  252. return
  253. }
  254. deleteCache := true
  255. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  256. defer func() {
  257. if deleteCache {
  258. utils.Rc.Delete(cacheKey)
  259. }
  260. }()
  261. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  262. deleteCache = false
  263. br.Msg = "系统处理中,请稍后重试!"
  264. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  265. return
  266. }
  267. var req data_manage.CopyAddChartInfoReq
  268. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  269. if err != nil {
  270. br.Msg = "参数解析异常!"
  271. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  272. return
  273. }
  274. // 获取原图表信息
  275. oldChartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  276. if err != nil {
  277. br.Msg = "获取原图表信息失败"
  278. br.ErrMsg = "获取原图表信息失败,Err:" + err.Error()
  279. return
  280. }
  281. if oldChartInfo.Source != utils.CHART_SOURCE_LINE_EQUATION {
  282. br.Msg = `错误的图表类型`
  283. br.IsSendEmail = false
  284. return
  285. }
  286. var lineChartInfoConf request.LineChartInfoReq
  287. err = json.Unmarshal([]byte(oldChartInfo.ExtraConfig), &lineChartInfoConf)
  288. addChartList := make([]request.AddChart, 0)
  289. addChartList = append(addChartList, request.AddChart{
  290. Source: lineChartInfoConf.Source,
  291. ChartClassifyId: req.ChartClassifyId,
  292. ChartName: req.ChartName,
  293. LeftMin: oldChartInfo.LeftMin,
  294. LeftMax: oldChartInfo.LeftMax,
  295. ChartImage: oldChartInfo.ChartImage,
  296. })
  297. resp := new(data_manage.AddChartInfoResp)
  298. batchAddChartList, err, errMsg, isSendEmail := line_equation.BatchAddChartInfo(addChartList, lineChartInfoConf, sysUser)
  299. if err != nil {
  300. br.Msg = "保存失败"
  301. if errMsg != `` {
  302. br.Msg = errMsg
  303. }
  304. br.ErrMsg = err.Error()
  305. br.IsSendEmail = isSendEmail
  306. return
  307. }
  308. resp.ChartInfoId = batchAddChartList[0].ChartInfo.ChartInfoId
  309. resp.UniqueCode = batchAddChartList[0].ChartInfo.UniqueCode
  310. resp.ChartType = batchAddChartList[0].ChartInfo.ChartType
  311. //新增操作日志
  312. {
  313. for _, v := range batchAddChartList {
  314. chartInfo := v.ChartInfo
  315. chartLog := new(data_manage.ChartInfoLog)
  316. chartLog.ChartInfoId = chartInfo.ChartInfoId
  317. chartLog.ChartName = chartInfo.ChartName
  318. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  319. chartLog.SysUserId = sysUser.AdminId
  320. chartLog.SysUserRealName = sysUser.RealName
  321. chartLog.UniqueCode = chartInfo.UniqueCode
  322. chartLog.CreateTime = time.Now()
  323. chartLog.Content = string(this.Ctx.Input.RequestBody)
  324. chartLog.Status = "新增拟合方程图表"
  325. chartLog.Method = this.Ctx.Input.URI()
  326. go data_manage.AddChartInfoLog(chartLog)
  327. }
  328. }
  329. br.Ret = 200
  330. br.Data = resp
  331. br.Success = true
  332. br.Msg = "保存成功"
  333. br.IsAddLog = true
  334. }
  335. // GetChartInfoDetailFromUniqueCode 根据编码获取图表详情
  336. func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  337. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  338. adminId := sysUser.AdminId
  339. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  340. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  341. if utils.Re == nil && isCache {
  342. if utils.Re == nil && utils.Rc.IsExist(key) {
  343. if chartData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  344. err := json.Unmarshal(chartData, &resp)
  345. if err == nil && resp != nil {
  346. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  347. var myCond string
  348. var myPars []interface{}
  349. myCond += ` AND a.admin_id=? `
  350. myPars = append(myPars, adminId)
  351. myCond += ` AND a.chart_info_id=? `
  352. myPars = append(myPars, chartInfo.ChartInfoId)
  353. myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
  354. if err != nil && err.Error() != utils.ErrNoRow() {
  355. msg = "获取失败"
  356. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  357. return
  358. }
  359. resp.ChartInfo.IsAdd = false
  360. resp.ChartInfo.MyChartId = 0
  361. resp.ChartInfo.MyChartClassifyId = ""
  362. if myList != nil && len(myList) > 0 {
  363. resp.ChartInfo.IsAdd = true
  364. resp.ChartInfo.MyChartId = myList[0].MyChartId
  365. resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
  366. }
  367. isOk = true
  368. fmt.Println("source redis")
  369. return
  370. }
  371. }
  372. }
  373. }
  374. if chartInfo.ExtraConfig == `` {
  375. msg = "获取失败"
  376. errMsg = "获取配置信息失败"
  377. return
  378. }
  379. var lineChartInfoConfig request.LineChartInfoReq
  380. err := json.Unmarshal([]byte(chartInfo.ExtraConfig), &lineChartInfoConfig)
  381. if err != nil {
  382. msg = "获取失败"
  383. errMsg = "获取图表配置信息失败, Err:" + err.Error()
  384. return
  385. }
  386. var getAData, getBData, getR2Data bool
  387. switch lineChartInfoConfig.Source {
  388. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
  389. getAData = true
  390. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
  391. getBData = true
  392. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
  393. getR2Data = true
  394. }
  395. edbList, dataResp, err, errMsg := line_equation.GetChartEdbData(chartInfo.ChartInfoId, lineChartInfoConfig, getAData, getBData, getR2Data)
  396. if err != nil {
  397. if errMsg == `` {
  398. errMsg = "获取失败"
  399. }
  400. return
  401. }
  402. var resultResp interface{}
  403. switch lineChartInfoConfig.Source {
  404. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
  405. resultResp = dataResp.AData
  406. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
  407. resultResp = dataResp.BData
  408. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
  409. resultResp = dataResp.R2Data
  410. }
  411. if chartInfo.ChartInfoId > 0 && chartInfo != nil {
  412. //判断是否加入我的图库
  413. {
  414. var myChartCondition string
  415. var myChartPars []interface{}
  416. myChartCondition += ` AND a.admin_id=? `
  417. myChartPars = append(myChartPars, sysUser.AdminId)
  418. myChartCondition += ` AND a.chart_info_id=? `
  419. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  420. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  421. if err != nil && err.Error() != utils.ErrNoRow() {
  422. msg = "获取失败"
  423. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  424. return
  425. }
  426. if myChartList != nil && len(myChartList) > 0 {
  427. chartInfo.IsAdd = true
  428. chartInfo.MyChartId = myChartList[0].MyChartId
  429. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  430. }
  431. }
  432. }
  433. //图表操作权限
  434. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId)
  435. //判断是否需要展示英文标识
  436. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, chartInfo.Source, chartInfo.ChartType)
  437. //chartInfo.UnitEn = edbInfoMappingA.UnitEn
  438. isSaveAs := true
  439. // 另存为
  440. chartInfo.Button = data_manage.ChartViewButton{
  441. IsEdit: chartInfo.IsEdit,
  442. IsEnChart: chartInfo.IsEnChart,
  443. IsAdd: chartInfo.IsAdd,
  444. IsCopy: isSaveAs,
  445. IsSetName: chartInfo.IsSetName,
  446. }
  447. resp.ChartInfo = chartInfo
  448. resp.EdbInfoList = edbList
  449. resp.DataResp = resultResp
  450. resp.Status = true
  451. // 将数据加入缓存
  452. if utils.Re == nil {
  453. d, _ := json.Marshal(resp)
  454. _ = utils.Rc.Put(key, d, 2*time.Hour)
  455. }
  456. isOk = true
  457. return
  458. }
  459. // EnInfoEdit
  460. // @Title 编辑图表英文信息接口
  461. // @Description 编辑图表英文信息接口
  462. // @Param request body data_manage.EditChartEnInfoReq true "type json string"
  463. // @Success Ret=200 编辑成功
  464. // @router /chart_info/en/edit [post]
  465. func (this *LineEquationChartInfoController) EnInfoEdit() {
  466. br := new(models.BaseResponse).Init()
  467. defer func() {
  468. this.Data["json"] = br
  469. this.ServeJSON()
  470. }()
  471. sysUser := this.SysUser
  472. if sysUser == nil {
  473. br.Msg = "请登录"
  474. br.ErrMsg = "请登录,SysUser Is Empty"
  475. br.Ret = 408
  476. return
  477. }
  478. var req request.EditChartEnInfoReq
  479. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  480. if err != nil {
  481. br.Msg = "参数解析异常!"
  482. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  483. return
  484. }
  485. req.ChartNameEn = strings.Trim(req.ChartNameEn, " ")
  486. if req.ChartInfoId <= 0 {
  487. br.Msg = "请选择图表"
  488. return
  489. }
  490. if req.ChartNameEn == "" {
  491. br.Msg = "请输入英文图表名称"
  492. return
  493. }
  494. //判断指标名称是否存在
  495. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  496. if err != nil {
  497. if err.Error() == utils.ErrNoRow() {
  498. br.Msg = "图表已被删除,请刷新页面"
  499. br.ErrMsg = "图表已被删除,请刷新页面"
  500. return
  501. }
  502. br.Msg = "获取图表信息失败"
  503. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  504. return
  505. }
  506. // 校验名称是否有重复
  507. {
  508. var condition string
  509. var pars []interface{}
  510. condition += " AND chart_info_id <> ? AND chart_name_en = ? AND source = ?"
  511. pars = append(pars, req.ChartInfoId, req.ChartNameEn, utils.CHART_SOURCE_LINE_EQUATION)
  512. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  513. if err != nil {
  514. if err.Error() != utils.ErrNoRow() {
  515. br.Msg = "判断英文图表名称是否存在失败"
  516. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  517. return
  518. }
  519. }
  520. if err == nil && existItem.ChartInfoId > 0 {
  521. br.Msg = existItem.ChartName + ":" + req.ChartNameEn + "图表名称已存在"
  522. return
  523. }
  524. }
  525. chartItem.ChartNameEn = req.ChartNameEn
  526. chartItem.ModifyTime = time.Now().Local()
  527. if e := chartItem.Update([]string{"ChartNameEn", "ModifyTime"}); e != nil {
  528. br.Msg = "操作失败"
  529. br.ErrMsg = "更新图表信息失败, Err: " + e.Error()
  530. return
  531. }
  532. //添加es数据
  533. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  534. //修改my eta es数据
  535. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  536. //指标 修改es信息
  537. //go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  538. //新增操作日志
  539. {
  540. chartLog := new(data_manage.ChartInfoLog)
  541. chartLog.ChartName = chartItem.ChartName
  542. chartLog.ChartInfoId = req.ChartInfoId
  543. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  544. chartLog.SysUserId = sysUser.AdminId
  545. chartLog.SysUserRealName = sysUser.RealName
  546. chartLog.UniqueCode = chartItem.UniqueCode
  547. chartLog.CreateTime = time.Now()
  548. chartLog.Content = string(this.Ctx.Input.RequestBody)
  549. chartLog.Status = "编辑拟合方程图表英文信息"
  550. chartLog.Method = this.Ctx.Input.URL()
  551. go data_manage.AddChartInfoLog(chartLog)
  552. }
  553. // 清除缓存
  554. if utils.Re == nil && utils.Rc != nil {
  555. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  556. _ = utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  557. }
  558. br.Ret = 200
  559. br.Success = true
  560. br.Msg = "编辑成功"
  561. br.IsAddLog = true
  562. }
  563. // SearchByEs
  564. // @Title 图表模糊搜索(从es获取)
  565. // @Description 图表模糊搜索(从es获取)
  566. // @Param Keyword query string true "图表名称"
  567. // @Param IsShowMe query bool true "是否只看我的,true、false"
  568. // @Param Source query int true "来源,3:拟合方程,4:滚动拟合方程,默认0:全部"
  569. // @Success 200 {object} data_manage.ChartInfo
  570. // @router /chart_info/search_by_es [get]
  571. func (this *LineEquationChartInfoController) SearchByEs() {
  572. br := new(models.BaseResponse).Init()
  573. defer func() {
  574. this.Data["json"] = br
  575. this.ServeJSON()
  576. }()
  577. sysUser := this.SysUser
  578. if sysUser == nil {
  579. br.Msg = "请登录"
  580. br.ErrMsg = "请登录,SysUser Is Empty"
  581. br.Ret = 408
  582. return
  583. }
  584. pageSize, _ := this.GetInt("PageSize")
  585. currentIndex, _ := this.GetInt("CurrentIndex")
  586. var startSize int
  587. if pageSize <= 0 {
  588. pageSize = utils.PageSize20
  589. }
  590. if currentIndex <= 0 {
  591. currentIndex = 1
  592. }
  593. startSize = paging.StartIndex(currentIndex, pageSize)
  594. keyword := this.GetString("Keyword")
  595. //只看我的
  596. isShowMe, _ := this.GetBool("IsShowMe")
  597. showSysId := 0
  598. if isShowMe {
  599. showSysId = sysUser.AdminId
  600. }
  601. sourceList := []int{utils.CHART_SOURCE_LINE_EQUATION}
  602. var searchList []*data_manage.ChartInfo
  603. var total int64
  604. var err error
  605. // 获取当前账号的不可见指标
  606. noPermissionChartIdList := make([]int, 0)
  607. {
  608. obj := data_manage.EdbInfoNoPermissionAdmin{}
  609. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  610. if err != nil && err.Error() != utils.ErrNoRow() {
  611. br.Msg = "获取失败"
  612. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  613. return
  614. }
  615. for _, v := range confList {
  616. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  617. }
  618. }
  619. if keyword != "" {
  620. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  621. } else {
  622. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList)
  623. if err != nil && err.Error() != utils.ErrNoRow() {
  624. br.Msg = "获取失败"
  625. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  626. return
  627. }
  628. }
  629. finalList := make([]*data_manage.ChartInfoMore, 0)
  630. if len(searchList) > 0 {
  631. chartInfoIds := ""
  632. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  633. for _, v := range searchList {
  634. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  635. }
  636. if chartInfoIds != "" {
  637. chartInfoIds = strings.Trim(chartInfoIds, ",")
  638. //判断是否需要展示英文标识
  639. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  640. if e != nil {
  641. br.Msg = "获取失败"
  642. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  643. return
  644. }
  645. for _, v := range edbList {
  646. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  647. }
  648. }
  649. for _, v := range searchList {
  650. tmp := new(data_manage.ChartInfoMore)
  651. tmp.ChartInfo = *v
  652. //判断是否需要展示英文标识
  653. if _, ok := chartEdbMap[v.ChartInfoId]; ok {
  654. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, v.Source, v.ChartType)
  655. }
  656. finalList = append(finalList, tmp)
  657. }
  658. }
  659. //新增搜索词记录
  660. {
  661. searchKeyword := new(data_manage.SearchKeyword)
  662. searchKeyword.KeyWord = keyword
  663. searchKeyword.CreateTime = time.Now()
  664. go data_manage.AddSearchKeyword(searchKeyword)
  665. }
  666. page := paging.GetPaging(currentIndex, pageSize, int(total))
  667. resp := data_manage.ChartInfoListByEsResp{
  668. Paging: page,
  669. List: finalList,
  670. }
  671. br.Ret = 200
  672. br.Success = true
  673. br.Msg = "获取成功"
  674. br.Data = resp
  675. }