line_chart_info.go 54 KB

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