chart_info.go 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599
  1. package line_feature
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "hongze/hz_eta_api/controllers"
  8. "hongze/hz_eta_api/models"
  9. "hongze/hz_eta_api/models/data_manage"
  10. "hongze/hz_eta_api/models/data_manage/line_feature/request"
  11. "hongze/hz_eta_api/models/data_manage/line_feature/response"
  12. "hongze/hz_eta_api/models/system"
  13. "hongze/hz_eta_api/services/data"
  14. lineFeatureServ "hongze/hz_eta_api/services/data/line_feature"
  15. "hongze/hz_eta_api/utils"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // LineFeaturesChartInfoController 统计特征图表管理
  21. type LineFeaturesChartInfoController struct {
  22. controllers.BaseAuthController
  23. }
  24. // MultipleGraphConfigSave
  25. // @Title 保存配置接口
  26. // @Description 保存配置接口
  27. // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
  28. // @Success Ret=200 返回图表id
  29. // @router /config/save [post]
  30. func (this *LineFeaturesChartInfoController) MultipleGraphConfigSave() {
  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.SaveMultipleGraphConfigReq
  44. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  45. if err != nil {
  46. br.Msg = "参数解析异常!"
  47. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  48. return
  49. }
  50. if req.EdbInfoId <= 0 {
  51. br.Msg = "指标未选择"
  52. br.IsSendEmail = false
  53. return
  54. }
  55. _, err = data_manage.GetEdbInfoById(req.EdbInfoId)
  56. if err != nil {
  57. br.Msg = "指标A异常"
  58. br.ErrMsg = "指标A异常,err:" + err.Error()
  59. if err.Error() == utils.ErrNoRow() {
  60. br.Msg = `指标A不存在`
  61. br.IsSendEmail = false
  62. }
  63. return
  64. }
  65. configSave := request.ConfigSave{
  66. Curve: req.Curve,
  67. StandardDeviation: req.StandardDeviation,
  68. Percentile: req.Percentile,
  69. FrequencyDistribution: req.FrequencyDistribution,
  70. }
  71. configSaveStrByte, err := json.Marshal(configSave)
  72. if err != nil {
  73. br.Msg = `相关性配置异常`
  74. br.ErrMsg = `相关性配置异常,ERR:` + err.Error()
  75. return
  76. }
  77. var multipleGraphConfig *data_manage.MultipleGraphConfig
  78. if req.MultipleGraphConfigId > 0 {
  79. multipleGraphConfig, err = data_manage.GetMultipleGraphConfigById(req.MultipleGraphConfigId)
  80. if err != nil {
  81. br.Msg = `不存在该配置`
  82. br.ErrMsg = `不存在该配置`
  83. return
  84. }
  85. multipleGraphConfig.EdbInfoIdA = req.EdbInfoId
  86. multipleGraphConfig.Curve = string(configSaveStrByte)
  87. multipleGraphConfig.ModifyTime = time.Now()
  88. err = multipleGraphConfig.Update([]string{"EdbInfoIdA", "Curve", "ModifyTime"})
  89. } else {
  90. multipleGraphConfig = &data_manage.MultipleGraphConfig{
  91. //MultipleGraphConfigId: 0,
  92. EdbInfoIdA: req.EdbInfoId,
  93. Curve: string(configSaveStrByte),
  94. SysUserId: this.SysUser.AdminId,
  95. SysUserRealName: this.SysUser.RealName,
  96. ModifyTime: time.Now(),
  97. CreateTime: time.Now(),
  98. }
  99. err = data_manage.AddMultipleGraphConfig(multipleGraphConfig)
  100. }
  101. if err != nil {
  102. br.Msg = `保存失败`
  103. br.ErrMsg = `保存失败,Err:` + err.Error()
  104. return
  105. }
  106. br.Ret = 200
  107. br.Success = true
  108. br.Msg = "保存成功"
  109. br.Data = multipleGraphConfig
  110. br.IsAddLog = true
  111. }
  112. // MultipleGraphPreview
  113. // @Title 批量添加图表的预览接口
  114. // @Description 批量添加图表的预览接口
  115. // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
  116. // @Success Ret=200 返回图表id
  117. // @router /preview [post]
  118. func (this *LineFeaturesChartInfoController) MultipleGraphPreview() {
  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. var req request.SaveMultipleGraphConfigReq
  132. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  133. if err != nil {
  134. br.Msg = "参数解析异常!"
  135. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  136. return
  137. }
  138. edbInfoMapping, err := data_manage.GetChartEdbMappingByEdbInfoId(req.EdbInfoId)
  139. if err != nil {
  140. br.Msg = "获取失败"
  141. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  142. return
  143. }
  144. if edbInfoMapping == nil {
  145. br.Msg = "指标不存在"
  146. br.IsSendEmail = false
  147. return
  148. }
  149. resp := response.PreviewMultipleGraphConfigResp{}
  150. chartInfo := new(data_manage.ChartInfoView)
  151. chartInfo.Calendar = `公历`
  152. chartInfo.ChartName = edbInfoMapping.EdbName
  153. // 曲线图表信息
  154. {
  155. tmpChartInfo := *chartInfo
  156. curveConf := req.Curve
  157. startDate, endDate := utils.GetDateByDateType(curveConf.DateType, curveConf.StartDate, curveConf.EndDate)
  158. // 获取图表中的指标数据
  159. edbList, _, _, _, err, errMsg := data.GetChartEdbData(tmpChartInfo.ChartInfoId, tmpChartInfo.ChartType, tmpChartInfo.Calendar, startDate, endDate, []*data_manage.ChartEdbInfoMapping{edbInfoMapping}, tmpChartInfo.ExtraConfig)
  160. if err != nil {
  161. br.Msg = "获取失败"
  162. if errMsg != `` {
  163. br.Msg = errMsg
  164. }
  165. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  166. return
  167. }
  168. warnEdbList := make([]string, 0)
  169. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  170. for _, v := range edbList {
  171. if v.IsNullData {
  172. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  173. }
  174. chartEdbInfoMapping := *v
  175. chartEdbInfoMapping.IsOrder = false
  176. chartEdbInfoMapping.IsAxis = 1
  177. chartEdbInfoMapping.MinData = curveConf.LeftMin
  178. chartEdbInfoMapping.MaxData = curveConf.LeftMax
  179. chartEdbInfoMapping.ChartColor = `#00F`
  180. chartEdbInfoMapping.ChartWidth = 3
  181. chartEdbInfoMapping.EdbInfoType = 1
  182. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  183. }
  184. if len(warnEdbList) > 0 {
  185. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  186. }
  187. tmpChartInfo.Source = utils.CHART_SOURCE_DEFAULT
  188. tmpChartInfo.DateType = curveConf.DateType
  189. tmpChartInfo.StartDate = startDate
  190. tmpChartInfo.EndDate = endDate
  191. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  192. resp.CurveData = response.CurveResp{
  193. ChartInfo: tmpChartInfo,
  194. EdbInfoList: tmpEdbList,
  195. }
  196. }
  197. // 标准差图表信息
  198. {
  199. // 配置了数据才有返回
  200. if req.StandardDeviation.CalculateValue > 0 {
  201. tmpChartInfo := *chartInfo
  202. tmpChartInfo.ChartName = fmt.Sprintf("%s%d期滚动标准差", edbInfoMapping.EdbName, req.StandardDeviation.CalculateValue)
  203. // 获取图表中的指标数据
  204. edbList, dataResp, err, errMsg := lineFeatureServ.GetStandardDeviationData(0, edbInfoMapping, req.StandardDeviation.CalculateValue)
  205. if err != nil {
  206. br.Msg = "获取失败"
  207. if errMsg != `` {
  208. br.Msg = errMsg
  209. }
  210. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  211. return
  212. }
  213. warnEdbList := make([]string, 0)
  214. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  215. for _, v := range edbList {
  216. if v.IsNullData {
  217. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  218. }
  219. chartEdbInfoMapping := *v
  220. chartEdbInfoMapping.IsOrder = false
  221. chartEdbInfoMapping.IsAxis = 1
  222. //chartEdbInfoMapping.MinData = curveConf.LeftMin
  223. //chartEdbInfoMapping.MaxData = curveConf.LeftMax
  224. chartEdbInfoMapping.ChartColor = `#00F`
  225. chartEdbInfoMapping.ChartWidth = 3
  226. chartEdbInfoMapping.EdbInfoType = 1
  227. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  228. }
  229. if len(warnEdbList) > 0 {
  230. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  231. }
  232. tmpChartInfo.Source = utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION
  233. //tmpChartInfo.DateType = curveConf.DateType
  234. //tmpChartInfo.StartDate = startDate
  235. //tmpChartInfo.EndDate = endDate
  236. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  237. resp.StandardDeviationData = response.CurveResp{
  238. ChartInfo: tmpChartInfo,
  239. EdbInfoList: tmpEdbList,
  240. DataResp: dataResp,
  241. }
  242. }
  243. }
  244. // 百分位图表信息
  245. {
  246. // 配置了数据才有返回
  247. if req.Percentile.CalculateValue > 0 && req.Percentile.CalculateUnit != `` {
  248. tmpChartInfo := *chartInfo
  249. tmpChartInfo.ChartName = fmt.Sprintf("%s%d%s百分位", edbInfoMapping.EdbName, req.Percentile.CalculateValue, req.Percentile.CalculateUnit)
  250. // 获取图表中的指标数据
  251. edbList, dataResp, err, errMsg := lineFeatureServ.GetPercentileData(0, edbInfoMapping, req.Percentile.CalculateValue, req.Percentile.CalculateUnit)
  252. if err != nil && errMsg != `` {
  253. br.Msg = errMsg
  254. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  255. return
  256. }
  257. if err == nil {
  258. warnEdbList := make([]string, 0)
  259. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  260. for _, v := range edbList {
  261. if v.IsNullData {
  262. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  263. }
  264. chartEdbInfoMapping := *v
  265. chartEdbInfoMapping.IsOrder = false
  266. chartEdbInfoMapping.IsAxis = 1
  267. //chartEdbInfoMapping.MinData = curveConf.LeftMin
  268. //chartEdbInfoMapping.MaxData = curveConf.LeftMax
  269. chartEdbInfoMapping.ChartColor = `#00F`
  270. chartEdbInfoMapping.ChartWidth = 3
  271. chartEdbInfoMapping.EdbInfoType = 1
  272. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  273. }
  274. if len(warnEdbList) > 0 {
  275. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  276. }
  277. tmpChartInfo.Source = utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE
  278. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  279. resp.PercentileData = response.CurveResp{
  280. ChartInfo: tmpChartInfo,
  281. EdbInfoList: tmpEdbList,
  282. DataResp: dataResp,
  283. }
  284. }
  285. }
  286. }
  287. // 频率分布图表信息
  288. {
  289. // 配置了数据才有返回
  290. if req.FrequencyDistribution.DateType > 0 && req.FrequencyDistribution.FrequencyValue > 0 {
  291. tmpChartInfo := *chartInfo
  292. tmpChartInfo.ChartName = fmt.Sprintf("%s频率和累计频率", edbInfoMapping.EdbName)
  293. // 获取图表中的指标数据
  294. edbList, dataResp, err, errMsg := lineFeatureServ.GetFrequencyDistributionData(0, edbInfoMapping, req.FrequencyDistribution.DateType, req.FrequencyDistribution.FrequencyValue, req.FrequencyDistribution.StartDate, req.FrequencyDistribution.EndDate)
  295. if err != nil && errMsg != `` {
  296. br.Msg = errMsg
  297. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  298. return
  299. }
  300. if err == nil {
  301. warnEdbList := make([]string, 0)
  302. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  303. for _, v := range edbList {
  304. if v.IsNullData {
  305. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  306. }
  307. chartEdbInfoMapping := *v
  308. chartEdbInfoMapping.IsOrder = false
  309. chartEdbInfoMapping.IsAxis = 1
  310. //chartEdbInfoMapping.MinData = curveConf.LeftMin
  311. //chartEdbInfoMapping.MaxData = curveConf.LeftMax
  312. chartEdbInfoMapping.ChartColor = `#00F`
  313. chartEdbInfoMapping.ChartWidth = 3
  314. chartEdbInfoMapping.EdbInfoType = 1
  315. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  316. }
  317. if len(warnEdbList) > 0 {
  318. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  319. }
  320. tmpChartInfo.Source = utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY
  321. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  322. resp.FrequencyDistributionData = response.CurveResp{
  323. ChartInfo: tmpChartInfo,
  324. EdbInfoList: tmpEdbList,
  325. DataResp: dataResp,
  326. }
  327. }
  328. }
  329. }
  330. br.Ret = 200
  331. br.Success = true
  332. br.Msg = "获取成功"
  333. br.Data = resp
  334. }
  335. // MultipleGraphPreviewCurve
  336. // @Title 批量添加图表的预览曲线图接口(只返回曲线图的数据)
  337. // @Description 批量添加图表的预览曲线图接口
  338. // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
  339. // @Success Ret=200 返回图表id
  340. // @router /preview_cure [post]
  341. func (this *LineFeaturesChartInfoController) MultipleGraphPreviewCurve() {
  342. br := new(models.BaseResponse).Init()
  343. defer func() {
  344. this.Data["json"] = br
  345. this.ServeJSON()
  346. }()
  347. sysUser := this.SysUser
  348. if sysUser == nil {
  349. br.Msg = "请登录"
  350. br.ErrMsg = "请登录,SysUser Is Empty"
  351. br.Ret = 408
  352. return
  353. }
  354. var req request.SaveMultipleGraphConfigReq
  355. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  356. if err != nil {
  357. br.Msg = "参数解析异常!"
  358. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  359. return
  360. }
  361. edbInfoMapping, err := data_manage.GetChartEdbMappingByEdbInfoId(req.EdbInfoId)
  362. if err != nil {
  363. br.Msg = "获取失败"
  364. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  365. return
  366. }
  367. if edbInfoMapping == nil {
  368. br.Msg = "指标不存在"
  369. br.IsSendEmail = false
  370. return
  371. }
  372. resp := response.PreviewMultipleGraphConfigResp{}
  373. chartInfo := new(data_manage.ChartInfoView)
  374. chartInfo.Calendar = `公历`
  375. chartInfo.ChartName = edbInfoMapping.EdbName
  376. // 曲线图表信息
  377. {
  378. tmpChartInfo := *chartInfo
  379. curveConf := req.Curve
  380. startDate, endDate := utils.GetDateByDateType(curveConf.DateType, curveConf.StartDate, curveConf.EndDate)
  381. // 获取图表中的指标数据
  382. edbList, _, _, _, err, errMsg := data.GetChartEdbData(tmpChartInfo.ChartInfoId, tmpChartInfo.ChartType, tmpChartInfo.Calendar, startDate, endDate, []*data_manage.ChartEdbInfoMapping{edbInfoMapping}, tmpChartInfo.ExtraConfig)
  383. if err != nil {
  384. br.Msg = "获取失败"
  385. if errMsg != `` {
  386. br.Msg = errMsg
  387. }
  388. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  389. return
  390. }
  391. warnEdbList := make([]string, 0)
  392. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  393. for _, v := range edbList {
  394. if v.IsNullData {
  395. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  396. }
  397. chartEdbInfoMapping := *v
  398. chartEdbInfoMapping.IsOrder = false
  399. chartEdbInfoMapping.IsAxis = 1
  400. chartEdbInfoMapping.MinData = curveConf.LeftMin
  401. chartEdbInfoMapping.MaxData = curveConf.LeftMax
  402. chartEdbInfoMapping.ChartColor = `#00F`
  403. chartEdbInfoMapping.ChartWidth = 3
  404. chartEdbInfoMapping.EdbInfoType = 1
  405. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  406. }
  407. if len(warnEdbList) > 0 {
  408. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  409. }
  410. tmpChartInfo.Source = utils.CHART_SOURCE_DEFAULT
  411. tmpChartInfo.DateType = curveConf.DateType
  412. tmpChartInfo.StartDate = startDate
  413. tmpChartInfo.EndDate = endDate
  414. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  415. resp.CurveData = response.CurveResp{
  416. ChartInfo: tmpChartInfo,
  417. EdbInfoList: tmpEdbList,
  418. }
  419. }
  420. br.Ret = 200
  421. br.Success = true
  422. br.Msg = "获取成功"
  423. br.Data = resp
  424. }
  425. // MultipleGraphConfigSaveChart
  426. // @Title 保存图表接口
  427. // @Description 保存图表接口
  428. // @Param request body request.SaveMultipleGraphChartReq true "type json string"
  429. // @Success Ret=200 返回图表id
  430. // @router /chart/save [post]
  431. func (this *LineFeaturesChartInfoController) MultipleGraphConfigSaveChart() {
  432. br := new(models.BaseResponse).Init()
  433. defer func() {
  434. this.Data["json"] = br
  435. this.ServeJSON()
  436. }()
  437. sysUser := this.SysUser
  438. if sysUser == nil {
  439. br.Msg = "请登录"
  440. br.ErrMsg = "请登录,SysUser Is Empty"
  441. br.Ret = 408
  442. return
  443. }
  444. var req request.SaveMultipleGraphChartReq
  445. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  446. if err != nil {
  447. br.Msg = "参数解析异常!"
  448. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  449. return
  450. }
  451. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  452. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  453. br.Msg = "系统处理中,请稍后重试!"
  454. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  455. return
  456. }
  457. defer func() {
  458. _ = utils.Rc.Delete(cacheKey)
  459. }()
  460. if req.MultipleGraphConfigId <= 0 {
  461. br.Msg = "配置未保存"
  462. br.IsSendEmail = false
  463. return
  464. }
  465. if req.IsSaveAs {
  466. CopyMultipleGraphConfigSaveChart(req, this, br, sysUser)
  467. return
  468. }
  469. edbInfoMapping, err := data_manage.GetChartEdbMappingByEdbInfoId(req.EdbInfoId)
  470. if err != nil {
  471. br.Msg = "获取失败"
  472. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  473. return
  474. }
  475. if edbInfoMapping == nil {
  476. br.Msg = "指标不存在"
  477. br.IsSendEmail = false
  478. return
  479. }
  480. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
  481. if err != nil && err.Error() != utils.ErrNoRow() {
  482. br.Msg = `保存失败`
  483. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  484. return
  485. }
  486. err = nil
  487. var isAdd bool
  488. var chartInfoId int
  489. if multipleGraphConfigChartMapping == nil {
  490. isAdd = true
  491. } else {
  492. chartInfo, err := data_manage.GetChartInfoById(multipleGraphConfigChartMapping.ChartInfoId)
  493. if err != nil && err.Error() != utils.ErrNoRow() {
  494. br.Msg = `保存失败`
  495. br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
  496. return
  497. }
  498. // 说明图还在,没有被删除
  499. if chartInfo != nil {
  500. chartInfoId = multipleGraphConfigChartMapping.ChartInfoId
  501. req.ChartName = chartInfo.ChartName
  502. req.ClassifyId = chartInfo.ChartClassifyId
  503. }
  504. }
  505. var chartInfo *data_manage.ChartInfo
  506. var errMsg string
  507. isSendEmail := true
  508. switch req.Source {
  509. case utils.CHART_MULTIPLE_GRAPH_CURVE: // 曲线图
  510. curveConf := req.Curve
  511. chartSaveItemList := []*data_manage.ChartSaveItem{
  512. {
  513. EdbInfoId: edbInfoMapping.EdbInfoId,
  514. MaxData: curveConf.LeftMax,
  515. MinData: curveConf.LeftMin,
  516. IsOrder: false,
  517. IsAxis: 1,
  518. EdbInfoType: 1,
  519. //LeadValue: curveConf.LeadValue,
  520. //LeadUnit: curveConf.LeadUnit,
  521. ChartStyle: "spline",
  522. ChartColor: `#00F`,
  523. PredictChartColor: "",
  524. ChartWidth: 3,
  525. Source: utils.CHART_SOURCE_DEFAULT,
  526. },
  527. }
  528. if chartInfoId <= 0 {
  529. addChartReq := data_manage.AddChartInfoReq{
  530. ChartEdbInfoList: chartSaveItemList,
  531. ChartClassifyId: req.ClassifyId,
  532. ChartName: req.ChartName,
  533. ChartType: utils.CHART_TYPE_CURVE,
  534. DateType: curveConf.DateType,
  535. StartDate: curveConf.StartDate,
  536. EndDate: curveConf.EndDate,
  537. Calendar: "公历",
  538. SeasonStartDate: curveConf.StartDate,
  539. SeasonEndDate: curveConf.EndDate,
  540. LeftMin: fmt.Sprint(curveConf.LeftMin),
  541. LeftMax: fmt.Sprint(curveConf.LeftMax),
  542. }
  543. chartInfo, err, errMsg, isSendEmail = data.AddChartInfo(addChartReq, sysUser.AdminId, sysUser.RealName)
  544. } else {
  545. editChartReq := data_manage.EditChartInfoReq{
  546. ChartInfoId: multipleGraphConfigChartMapping.ChartInfoId,
  547. ChartName: req.ChartName,
  548. ChartClassifyId: req.ClassifyId,
  549. ChartEdbInfoList: chartSaveItemList,
  550. ChartType: utils.CHART_TYPE_CURVE,
  551. DateType: curveConf.DateType,
  552. StartDate: curveConf.StartDate,
  553. EndDate: curveConf.EndDate,
  554. Calendar: "公历",
  555. SeasonStartDate: curveConf.StartDate,
  556. SeasonEndDate: curveConf.EndDate,
  557. LeftMin: fmt.Sprint(curveConf.LeftMin),
  558. LeftMax: fmt.Sprint(curveConf.LeftMax),
  559. }
  560. chartInfo, err, errMsg, isSendEmail = data.EditChartInfo(editChartReq, sysUser)
  561. if err != nil {
  562. br.Msg = "保存失败"
  563. if errMsg != `` {
  564. br.Msg = errMsg
  565. }
  566. br.ErrMsg = err.Error()
  567. br.IsSendEmail = isSendEmail
  568. return
  569. }
  570. }
  571. default:
  572. var extraConfig string
  573. var chartSource int
  574. var leftMinVal, leftMaxVal, rightMinVal, rightMaxVal float64
  575. // 统计特征-标准差图表
  576. if req.Source == utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_STANDARD_DEVIATION {
  577. chartSource = utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION // 统计特征-标准差图表
  578. standardDeviationConf := req.StandardDeviation
  579. if standardDeviationConf.CalculateValue <= 0 {
  580. br.Msg = "滚动周期需要大于0"
  581. br.IsSendEmail = false
  582. return
  583. }
  584. extraConfig = fmt.Sprint(standardDeviationConf.CalculateValue)
  585. _, dataResp, err, errMsg := lineFeatureServ.GetStandardDeviationData(0, edbInfoMapping, req.StandardDeviation.CalculateValue)
  586. if err != nil {
  587. br.Msg = "保存失败"
  588. if errMsg != `` {
  589. br.Msg = errMsg
  590. }
  591. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  592. return
  593. }
  594. leftMinVal = dataResp.MinData
  595. leftMaxVal = dataResp.MaxData
  596. } else if req.Source == utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_PERCENTILE {
  597. chartSource = utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE // 统计特征-百分位图表
  598. percentileConf := req.Percentile
  599. if percentileConf.CalculateUnit == `` {
  600. br.Msg = "时间长度频度必选"
  601. br.IsSendEmail = false
  602. return
  603. }
  604. if percentileConf.CalculateValue <= 0 {
  605. br.Msg = "时间长度期数需要大于0"
  606. br.IsSendEmail = false
  607. return
  608. }
  609. extraConfigByte, _ := json.Marshal(percentileConf)
  610. extraConfig = string(extraConfigByte)
  611. // 获取图表中的指标数据
  612. _, dataResp, err, errMsg := lineFeatureServ.GetPercentileData(0, edbInfoMapping, req.Percentile.CalculateValue, req.Percentile.CalculateUnit)
  613. if err != nil && errMsg != `` {
  614. br.Msg = errMsg
  615. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  616. return
  617. }
  618. leftMinVal = dataResp.MinData
  619. leftMaxVal = dataResp.MaxData
  620. } else if req.Source == utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_FREQUENCY {
  621. chartSource = utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY // 统计特征-频率分布图表
  622. frequencyDistributionConf := req.FrequencyDistribution
  623. if frequencyDistributionConf.DateType <= 0 {
  624. br.Msg = "日期类型必选"
  625. br.IsSendEmail = false
  626. return
  627. }
  628. if frequencyDistributionConf.FrequencyValue <= 0 {
  629. br.Msg = "频段数必填"
  630. br.IsSendEmail = false
  631. return
  632. }
  633. extraConfigByte, _ := json.Marshal(frequencyDistributionConf)
  634. extraConfig = string(extraConfigByte)
  635. // 获取图表中的指标数据
  636. _, dataResp, err, errMsg := lineFeatureServ.GetFrequencyDistributionData(0, edbInfoMapping, req.FrequencyDistribution.DateType, req.FrequencyDistribution.FrequencyValue, req.FrequencyDistribution.StartDate, req.FrequencyDistribution.EndDate)
  637. if err != nil && errMsg != `` {
  638. br.Msg = errMsg
  639. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  640. return
  641. }
  642. leftMinVal = dataResp.LeftMinValue
  643. leftMaxVal = dataResp.LeftMaxValue
  644. rightMinVal = dataResp.RightMinValue
  645. rightMaxVal = dataResp.RightMaxValue
  646. }
  647. if chartSource <= 0 {
  648. br.Msg = "错误的来源"
  649. br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
  650. br.IsSendEmail = false
  651. return
  652. }
  653. if chartInfoId <= 0 {
  654. addChartReq := data_manage.AddChartInfoReq{
  655. ChartClassifyId: req.ClassifyId,
  656. ChartName: req.ChartName,
  657. ChartType: utils.CHART_TYPE_CURVE,
  658. Calendar: "公历",
  659. LeftMin: fmt.Sprint(leftMinVal),
  660. LeftMax: fmt.Sprint(leftMaxVal),
  661. RightMin: fmt.Sprint(rightMinVal),
  662. RightMax: fmt.Sprint(rightMaxVal),
  663. ExtraConfig: extraConfig,
  664. }
  665. chartInfo, err, errMsg, isSendEmail = lineFeatureServ.AddChartInfo(addChartReq, edbInfoMapping, chartSource, sysUser)
  666. } else {
  667. editChartReq := data_manage.EditChartInfoReq{
  668. ChartInfoId: multipleGraphConfigChartMapping.ChartInfoId,
  669. ChartName: req.ChartName,
  670. ChartClassifyId: req.ClassifyId,
  671. ChartType: utils.CHART_TYPE_CURVE,
  672. Calendar: "公历",
  673. LeftMin: fmt.Sprint(leftMinVal),
  674. LeftMax: fmt.Sprint(leftMaxVal),
  675. RightMin: fmt.Sprint(rightMinVal),
  676. RightMax: fmt.Sprint(rightMaxVal),
  677. ExtraConfig: extraConfig,
  678. }
  679. chartInfo, err, errMsg, isSendEmail = lineFeatureServ.EditChartInfo(editChartReq, edbInfoMapping, sysUser)
  680. if err != nil {
  681. br.Msg = "保存失败"
  682. if errMsg != `` {
  683. br.Msg = errMsg
  684. }
  685. br.ErrMsg = err.Error()
  686. br.IsSendEmail = isSendEmail
  687. return
  688. }
  689. }
  690. }
  691. if err != nil {
  692. br.Msg = "保存失败"
  693. if errMsg != `` {
  694. br.Msg = errMsg
  695. }
  696. br.ErrMsg = err.Error()
  697. br.IsSendEmail = isSendEmail
  698. return
  699. }
  700. // 如果图没有建立关联关系,那么就需要添加关系
  701. if isAdd {
  702. multipleGraphConfigChartMapping = &data_manage.MultipleGraphConfigChartMapping{
  703. //Id: 0,
  704. MultipleGraphConfigId: req.MultipleGraphConfigId,
  705. ChartInfoId: chartInfo.ChartInfoId,
  706. Source: req.Source,
  707. ModifyTime: time.Now(),
  708. CreateTime: time.Now(),
  709. }
  710. err = data_manage.AddMultipleGraphConfigChartMapping(multipleGraphConfigChartMapping)
  711. if err != nil {
  712. br.Msg = "保存失败"
  713. br.ErrMsg = "保存配置与图表的关联关系失败,ERR:" + err.Error()
  714. return
  715. }
  716. } else if multipleGraphConfigChartMapping != nil {
  717. multipleGraphConfigChartMapping.ChartInfoId = chartInfo.ChartInfoId
  718. multipleGraphConfigChartMapping.ModifyTime = time.Now()
  719. err = multipleGraphConfigChartMapping.Update([]string{"ChartInfoId", "ModifyTime"})
  720. if err != nil {
  721. br.Msg = "保存失败"
  722. br.ErrMsg = "保存配置与图表的关联关系失败,ERR:" + err.Error()
  723. return
  724. }
  725. }
  726. //新增操作日志
  727. {
  728. chartLog := new(data_manage.ChartInfoLog)
  729. chartLog.ChartInfoId = chartInfo.ChartInfoId
  730. chartLog.ChartName = req.ChartName
  731. chartLog.ChartClassifyId = req.ClassifyId
  732. chartLog.SysUserId = sysUser.AdminId
  733. chartLog.SysUserRealName = sysUser.RealName
  734. chartLog.UniqueCode = chartInfo.UniqueCode
  735. chartLog.CreateTime = time.Now()
  736. chartLog.Content = string(this.Ctx.Input.RequestBody)
  737. chartLog.Status = "统计特征保存图表"
  738. chartLog.Method = this.Ctx.Input.URI()
  739. go data_manage.AddChartInfoLog(chartLog)
  740. }
  741. resp := new(data_manage.AddChartInfoResp)
  742. resp.ChartInfoId = chartInfo.ChartInfoId
  743. resp.UniqueCode = chartInfo.UniqueCode
  744. resp.ChartType = chartInfo.ChartType
  745. br.Ret = 200
  746. br.Success = true
  747. br.Msg = "保存成功"
  748. br.Data = resp
  749. br.IsAddLog = true
  750. }
  751. // CopyMultipleGraphConfigSaveChart 图表另存为
  752. func CopyMultipleGraphConfigSaveChart(req request.SaveMultipleGraphChartReq, this *LineFeaturesChartInfoController, br *models.BaseResponse, sysUser *system.Admin) {
  753. edbInfoMapping, err := data_manage.GetChartEdbMappingByEdbInfoId(req.EdbInfoId)
  754. if err != nil {
  755. br.Msg = "获取失败"
  756. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  757. return
  758. }
  759. if edbInfoMapping == nil {
  760. br.Msg = "指标不存在"
  761. br.IsSendEmail = false
  762. return
  763. }
  764. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
  765. if err != nil && err.Error() != utils.ErrNoRow() {
  766. br.Msg = `保存失败`
  767. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  768. return
  769. }
  770. // 原图
  771. oldChartInfo, err := data_manage.GetChartInfoById(multipleGraphConfigChartMapping.ChartInfoId)
  772. if err != nil && err.Error() != utils.ErrNoRow() {
  773. br.Msg = `保存失败`
  774. br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
  775. return
  776. }
  777. // 说明图还在,没有被删除
  778. if oldChartInfo == nil {
  779. br.Msg = "原图不存在"
  780. br.IsSendEmail = false
  781. }
  782. var chartInfo *data_manage.ChartInfo
  783. var errMsg string
  784. isSendEmail := true
  785. switch req.Source {
  786. case utils.CHART_MULTIPLE_GRAPH_CURVE: // 曲线图
  787. curveConf := req.Curve
  788. chartSaveItemList := []*data_manage.ChartSaveItem{
  789. {
  790. EdbInfoId: edbInfoMapping.EdbInfoId,
  791. MaxData: curveConf.LeftMax,
  792. MinData: curveConf.LeftMin,
  793. IsOrder: false,
  794. IsAxis: 1,
  795. EdbInfoType: 1,
  796. //LeadValue: curveConf.LeadValue,
  797. //LeadUnit: curveConf.LeadUnit,
  798. ChartStyle: "spline",
  799. ChartColor: `#00F`,
  800. PredictChartColor: "",
  801. ChartWidth: 3,
  802. Source: utils.CHART_SOURCE_DEFAULT,
  803. },
  804. }
  805. addChartReq := data_manage.AddChartInfoReq{
  806. ChartEdbInfoList: chartSaveItemList,
  807. ChartClassifyId: req.ClassifyId,
  808. ChartName: req.ChartName,
  809. ChartType: utils.CHART_TYPE_CURVE,
  810. DateType: curveConf.DateType,
  811. StartDate: curveConf.StartDate,
  812. EndDate: curveConf.EndDate,
  813. Calendar: "公历",
  814. SeasonStartDate: curveConf.StartDate,
  815. SeasonEndDate: curveConf.EndDate,
  816. LeftMin: fmt.Sprint(curveConf.LeftMin),
  817. LeftMax: fmt.Sprint(curveConf.LeftMax),
  818. }
  819. chartInfo, err, errMsg, isSendEmail = data.AddChartInfo(addChartReq, sysUser.AdminId, sysUser.RealName)
  820. default:
  821. if !utils.InArrayByInt([]int{utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_PERCENTILE, utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_FREQUENCY}, req.Source) {
  822. br.Msg = "错误的来源"
  823. br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
  824. br.IsSendEmail = false
  825. return
  826. }
  827. chartInfo, err, errMsg, isSendEmail = lineFeatureServ.CopyChartInfo(multipleGraphConfigChartMapping.MultipleGraphConfigId, req.Source, req.ClassifyId, req.ChartName, edbInfoMapping, oldChartInfo, sysUser)
  828. }
  829. if err != nil {
  830. br.Msg = "保存失败"
  831. if errMsg != `` {
  832. br.Msg = errMsg
  833. }
  834. br.ErrMsg = err.Error()
  835. br.IsSendEmail = isSendEmail
  836. return
  837. }
  838. //新增操作日志
  839. {
  840. chartLog := new(data_manage.ChartInfoLog)
  841. chartLog.ChartInfoId = chartInfo.ChartInfoId
  842. chartLog.ChartName = req.ChartName
  843. chartLog.ChartClassifyId = req.ClassifyId
  844. chartLog.SysUserId = sysUser.AdminId
  845. chartLog.SysUserRealName = sysUser.RealName
  846. chartLog.UniqueCode = chartInfo.UniqueCode
  847. chartLog.CreateTime = time.Now()
  848. chartLog.Content = string(this.Ctx.Input.RequestBody)
  849. chartLog.Status = "统计特征另存为图表"
  850. chartLog.Method = this.Ctx.Input.URI()
  851. go data_manage.AddChartInfoLog(chartLog)
  852. }
  853. resp := new(data_manage.AddChartInfoResp)
  854. resp.ChartInfoId = chartInfo.ChartInfoId
  855. resp.UniqueCode = chartInfo.UniqueCode
  856. resp.ChartType = chartInfo.ChartType
  857. br.Ret = 200
  858. br.Success = true
  859. br.Msg = "保存成功"
  860. br.Data = resp
  861. br.IsAddLog = true
  862. }
  863. // MultipleGraphConfigSaveEdb
  864. // @Title 保存指标接口
  865. // @Description 保存指标接口
  866. // @Param request body request.SaveMultipleGraphEdbReq true "type json string"
  867. // @Success Ret=200 返回指标id
  868. // @router /edb/save [post]
  869. func (this *LineFeaturesChartInfoController) MultipleGraphConfigSaveEdb() {
  870. br := new(models.BaseResponse).Init()
  871. defer func() {
  872. this.Data["json"] = br
  873. this.ServeJSON()
  874. }()
  875. sysUser := this.SysUser
  876. if sysUser == nil {
  877. br.Msg = "请登录"
  878. br.ErrMsg = "请登录,SysUser Is Empty"
  879. br.Ret = 408
  880. return
  881. }
  882. var req request.SaveMultipleGraphEdbReq
  883. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  884. if err != nil {
  885. br.Msg = "参数解析异常!"
  886. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  887. return
  888. }
  889. cacheKey := "CACHE_CHART_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  890. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  891. br.Msg = "系统处理中,请稍后重试!"
  892. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  893. return
  894. }
  895. defer func() {
  896. _ = utils.Rc.Delete(cacheKey)
  897. }()
  898. edbInfoMapping, err := data_manage.GetChartEdbMappingByEdbInfoId(req.EdbInfoId)
  899. if err != nil {
  900. br.Msg = "获取失败"
  901. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  902. return
  903. }
  904. if edbInfoMapping == nil {
  905. br.Msg = "指标不存在"
  906. br.IsSendEmail = false
  907. return
  908. }
  909. // 计算公式
  910. var formula string
  911. var edbSource int
  912. switch req.Source {
  913. case utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_STANDARD_DEVIATION:
  914. edbSource = utils.DATA_SOURCE_CALCULATE_STANDARD_DEVIATION // 统计特征-标准差
  915. if edbInfoMapping.EdbInfoCategoryType == 1 {
  916. edbSource = utils.DATA_SOURCE_PREDICT_CALCULATE_STANDARD_DEVIATION // 统计特征-预测标准差
  917. }
  918. standardDeviationConf := req.StandardDeviation
  919. if standardDeviationConf.CalculateValue <= 0 {
  920. br.Msg = "滚动周期需要大于0"
  921. br.IsSendEmail = false
  922. return
  923. }
  924. formula = fmt.Sprint(standardDeviationConf.CalculateValue)
  925. case utils.CHART_MULTIPLE_GRAPH_LINE_FEATURE_PERCENTILE:
  926. edbSource = utils.DATA_SOURCE_CALCULATE_PERCENTILE // 统计特征-百分位图表
  927. if edbInfoMapping.EdbInfoCategoryType == 1 {
  928. edbSource = utils.DATA_SOURCE_PREDICT_CALCULATE_PERCENTILE // 统计特征-预测标准差
  929. }
  930. percentileConf := req.Percentile
  931. if percentileConf.CalculateUnit == `` {
  932. br.Msg = "时间长度频度必选"
  933. br.IsSendEmail = false
  934. return
  935. }
  936. if percentileConf.CalculateValue <= 0 {
  937. br.Msg = "时间长度期数需要大于0"
  938. br.IsSendEmail = false
  939. return
  940. }
  941. extraConfigByte, _ := json.Marshal(percentileConf)
  942. formula = string(extraConfigByte)
  943. default:
  944. br.Msg = "错误的来源"
  945. br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
  946. br.IsSendEmail = false
  947. return
  948. }
  949. multipleGraphConfigEdbMapping, err := data_manage.GetMultipleGraphConfigEdbMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
  950. if err != nil && err.Error() != utils.ErrNoRow() {
  951. br.Msg = `保存失败`
  952. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  953. return
  954. }
  955. err = nil
  956. var isAdd bool
  957. var edbInfoId int
  958. if multipleGraphConfigEdbMapping == nil {
  959. isAdd = true
  960. } else {
  961. edbInfo, err := data_manage.GetEdbInfoById(multipleGraphConfigEdbMapping.EdbInfoId)
  962. if err != nil && err.Error() != utils.ErrNoRow() {
  963. br.Msg = `保存失败`
  964. br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
  965. return
  966. }
  967. // 说明指标还在,没有被删除
  968. if edbInfo != nil && !req.IsSaveAs {
  969. edbInfoId = multipleGraphConfigEdbMapping.EdbInfoId
  970. req.EdbName = edbInfo.EdbName
  971. req.ClassifyId = edbInfo.ClassifyId
  972. req.Frequency = edbInfo.Frequency
  973. req.Unit = edbInfo.Unit
  974. }
  975. }
  976. var respItem *data.AddPredictEdbDataResponse
  977. // 0:普通,1:预测
  978. if edbInfoMapping.EdbInfoCategoryType == 0 {
  979. if edbInfoId <= 0 || req.IsSaveAs {
  980. req2 := &data_manage.EdbInfoCalculateBatchSaveReqByEdbLib{
  981. AdminId: sysUser.AdminId,
  982. AdminName: sysUser.RealName,
  983. EdbName: req.EdbName,
  984. Frequency: req.Frequency,
  985. Unit: req.Unit,
  986. ClassifyId: req.ClassifyId,
  987. Formula: formula,
  988. Source: edbSource,
  989. FromEdbInfoId: edbInfoMapping.EdbInfoId,
  990. Calendar: `公历`,
  991. }
  992. // 调用指标库去添加
  993. reqJson, err := json.Marshal(req2)
  994. if err != nil {
  995. br.Msg = "参数解析异常!"
  996. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  997. return
  998. }
  999. respItem, err = data.BatchSaveEdbCalculateData(string(reqJson))
  1000. if err != nil {
  1001. br.Msg = "新增失败"
  1002. br.ErrMsg = "新增失败,Err:" + err.Error()
  1003. return
  1004. }
  1005. } else {
  1006. req2 := &data_manage.EdbInfoCalculateBatchEditReqByEdbLib{
  1007. EdbInfoId: edbInfoId,
  1008. EdbName: req.EdbName,
  1009. Frequency: req.Frequency,
  1010. Unit: req.Unit,
  1011. ClassifyId: req.ClassifyId,
  1012. Formula: formula,
  1013. Source: edbSource,
  1014. FromEdbInfoId: edbInfoMapping.EdbInfoId,
  1015. Calendar: `公历`,
  1016. }
  1017. // 调用指标库去更新
  1018. reqJson, err := json.Marshal(req2)
  1019. if err != nil {
  1020. br.Msg = "参数解析异常!"
  1021. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1022. return
  1023. }
  1024. respItem, err = data.BatchEditEdbCalculateData(string(reqJson))
  1025. if err != nil {
  1026. br.Msg = "编辑失败"
  1027. br.ErrMsg = "编辑失败,Err:" + err.Error()
  1028. return
  1029. }
  1030. }
  1031. } else {
  1032. req2 := &data_manage.PredictEdbInfoCalculateBatchSaveReq{
  1033. AdminId: sysUser.AdminId,
  1034. AdminName: sysUser.RealName,
  1035. EdbName: req.EdbName,
  1036. Frequency: req.Frequency,
  1037. Unit: req.Unit,
  1038. ClassifyId: req.ClassifyId,
  1039. Formula: formula,
  1040. Source: edbSource,
  1041. FromEdbInfoId: edbInfoMapping.EdbInfoId,
  1042. Calendar: `公历`,
  1043. }
  1044. if edbInfoId > 0 && !req.IsSaveAs {
  1045. req2.EdbInfoId = edbInfoId
  1046. }
  1047. // 调用指标库去添加
  1048. reqJson, err := json.Marshal(req2)
  1049. if err != nil {
  1050. br.Msg = "参数解析异常!"
  1051. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1052. return
  1053. }
  1054. respItem, err = data.BatchSavePredictEdbData(string(reqJson))
  1055. if err != nil {
  1056. br.Msg = "新增失败"
  1057. br.ErrMsg = "新增失败,Err:" + err.Error()
  1058. return
  1059. }
  1060. }
  1061. if respItem == nil {
  1062. br.Msg = "保存失败"
  1063. br.ErrMsg = "保存失败"
  1064. return
  1065. }
  1066. if respItem.Ret != 200 {
  1067. br.Msg = respItem.Msg
  1068. br.ErrMsg = respItem.ErrMsg
  1069. return
  1070. }
  1071. resp := respItem.Data
  1072. //添加es
  1073. data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
  1074. // 如果不是另存为的话,那么需要建立配置与指标的关系
  1075. if !req.IsSaveAs {
  1076. // 如果指标没有建立关联关系,那么就需要添加关系
  1077. if isAdd {
  1078. multipleGraphConfigEdbMapping = &data_manage.MultipleGraphConfigEdbMapping{
  1079. //Id: 0,
  1080. MultipleGraphConfigId: req.MultipleGraphConfigId,
  1081. EdbInfoId: resp.EdbInfoId,
  1082. Source: req.Source,
  1083. ModifyTime: time.Now(),
  1084. CreateTime: time.Now(),
  1085. }
  1086. err = data_manage.AddMultipleGraphConfigEdbMapping(multipleGraphConfigEdbMapping)
  1087. if err != nil {
  1088. br.Msg = "保存失败"
  1089. br.ErrMsg = "保存配置与指标的关联关系失败,ERR:" + err.Error()
  1090. return
  1091. }
  1092. } else if multipleGraphConfigEdbMapping != nil {
  1093. multipleGraphConfigEdbMapping.EdbInfoId = resp.EdbInfoId
  1094. multipleGraphConfigEdbMapping.ModifyTime = time.Now()
  1095. err = multipleGraphConfigEdbMapping.Update([]string{"EdbInfoId", "ModifyTime"})
  1096. if err != nil {
  1097. br.Msg = "保存失败"
  1098. br.ErrMsg = "保存配置与指标的关联关系失败,ERR:" + err.Error()
  1099. return
  1100. }
  1101. }
  1102. }
  1103. //新增操作日志
  1104. //{
  1105. // edbLog := new(data_manage.EdbInfoLog)
  1106. // edbLog.EdbInfoId = resp.EdbInfoId
  1107. // edbLog.SourceName = edbInfo.SourceName
  1108. // edbLog.Source = edbInfo.Source
  1109. // edbLog.EdbCode = edbInfo.EdbCode
  1110. // edbLog.EdbName = req2.EdbName
  1111. // edbLog.ClassifyId = req2.ClassifyId
  1112. // edbLog.SysUserId = sysUser.AdminId
  1113. // edbLog.SysUserRealName = sysUser.RealName
  1114. // edbLog.CreateTime = time.Now()
  1115. // edbLog.Content = string(this.Ctx.Input.RequestBody)
  1116. // edbLog.Status = "多图配置保存指标"
  1117. // edbLog.Method = this.Ctx.Input.URI()
  1118. // go data_manage.AddEdbInfoLog(edbLog)
  1119. //}
  1120. br.Ret = 200
  1121. br.Success = true
  1122. br.Msg = "保存成功"
  1123. br.Data = resp
  1124. br.IsAddLog = true
  1125. }
  1126. // GetMultipleGraphConfig
  1127. // @Title 保存配置接口
  1128. // @Description 保存配置接口
  1129. // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  1130. // @Success Ret=200 返回图表id
  1131. // @router /config/detail [get]
  1132. func (this *LineFeaturesChartInfoController) GetMultipleGraphConfig() {
  1133. br := new(models.BaseResponse).Init()
  1134. defer func() {
  1135. this.Data["json"] = br
  1136. this.ServeJSON()
  1137. }()
  1138. sysUser := this.SysUser
  1139. if sysUser == nil {
  1140. br.Msg = "请登录"
  1141. br.ErrMsg = "请登录,SysUser Is Empty"
  1142. br.Ret = 408
  1143. return
  1144. }
  1145. uniqueCode := this.GetString("UniqueCode")
  1146. if uniqueCode == "" {
  1147. br.Msg = "参数错误"
  1148. br.ErrMsg = "参数错误,uniqueCode is empty"
  1149. return
  1150. }
  1151. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  1152. if err != nil {
  1153. br.Msg = "获取失败"
  1154. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1155. return
  1156. }
  1157. if chartInfo == nil {
  1158. br.Msg = "获取失败"
  1159. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1160. return
  1161. }
  1162. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByChartId(chartInfo.ChartInfoId)
  1163. if err != nil {
  1164. br.Msg = "获取失败"
  1165. br.ErrMsg = "获取滚动相关性图表的配置信息失败,Err:" + err.Error()
  1166. return
  1167. }
  1168. multipleGraphConfig, err := data_manage.GetMultipleGraphConfigById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
  1169. if err != nil {
  1170. br.Msg = `获取失败`
  1171. br.ErrMsg = `获取配置失败,ERR:` + err.Error()
  1172. return
  1173. }
  1174. // 生成的图表
  1175. multipleGraphConfigChartMappingList := make([]response.MultipleGraphConfigChartMapping, 0)
  1176. {
  1177. chartMappingList, err := data_manage.GetMultipleGraphConfigChartMappingListById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
  1178. if err != nil {
  1179. br.Msg = `获取失败`
  1180. br.ErrMsg = `获取关联图表配置失败,ERR:` + err.Error()
  1181. return
  1182. }
  1183. chartInfoIdList := make([]int, 0)
  1184. chartMappingMap := make(map[int]*data_manage.MultipleGraphConfigChartMapping)
  1185. for _, v := range chartMappingList {
  1186. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  1187. chartMappingMap[v.ChartInfoId] = v
  1188. }
  1189. chartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  1190. if err != nil {
  1191. br.Msg = `获取失败`
  1192. br.ErrMsg = `获取关联图表列表失败,ERR:` + err.Error()
  1193. return
  1194. }
  1195. for _, v := range chartList {
  1196. if tmpInfo, ok := chartMappingMap[v.ChartInfoId]; ok {
  1197. multipleGraphConfigChartMappingList = append(multipleGraphConfigChartMappingList, response.MultipleGraphConfigChartMapping{
  1198. ChartInfoId: tmpInfo.ChartInfoId,
  1199. Source: tmpInfo.Source,
  1200. MultipleLocationSource: tmpInfo.Source,
  1201. })
  1202. }
  1203. }
  1204. }
  1205. // 生成的指标
  1206. multipleGraphConfigEdbMappingList := make([]response.MultipleGraphConfigEdbMapping, 0)
  1207. {
  1208. edbMappingList, err := data_manage.GetMultipleGraphConfigEdbMappingListById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
  1209. if err != nil {
  1210. br.Msg = `获取失败`
  1211. br.ErrMsg = `获取关联指标配置失败,ERR:` + err.Error()
  1212. return
  1213. }
  1214. edbInfoIdList := make([]int, 0)
  1215. edbMappingMap := make(map[int]*data_manage.MultipleGraphConfigEdbMapping)
  1216. for _, v := range edbMappingList {
  1217. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  1218. edbMappingMap[v.EdbInfoId] = v
  1219. }
  1220. edbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1221. if err != nil {
  1222. br.Msg = `获取失败`
  1223. br.ErrMsg = `获取关联图表列表失败,ERR:` + err.Error()
  1224. return
  1225. }
  1226. for _, v := range edbList {
  1227. if tmpInfo, ok := edbMappingMap[v.EdbInfoId]; ok {
  1228. multipleGraphConfigEdbMappingList = append(multipleGraphConfigEdbMappingList, response.MultipleGraphConfigEdbMapping{
  1229. EdbInfoId: tmpInfo.EdbInfoId,
  1230. Source: tmpInfo.Source,
  1231. MultipleLocationSource: tmpInfo.Source,
  1232. })
  1233. }
  1234. }
  1235. }
  1236. // 关联指标
  1237. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{multipleGraphConfig.EdbInfoIdA, multipleGraphConfig.EdbInfoIdB})
  1238. if err != nil {
  1239. br.Msg = "获取失败"
  1240. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1241. return
  1242. }
  1243. var config request.ConfigSave
  1244. err = json.Unmarshal([]byte(multipleGraphConfig.Curve), &config)
  1245. if err != nil {
  1246. br.Msg = `相关性配置异常`
  1247. br.ErrMsg = `相关性配置异常,ERR:` + err.Error()
  1248. return
  1249. }
  1250. resp := response.MultipleGraphConfigDetailResp{
  1251. MultipleGraphConfigId: multipleGraphConfigChartMapping.MultipleGraphConfigId,
  1252. Curve: config.Curve,
  1253. StandardDeviation: config.StandardDeviation,
  1254. Percentile: config.Percentile,
  1255. FrequencyDistribution: config.FrequencyDistribution,
  1256. EdbInfoList: mappingList,
  1257. ChartMappingList: multipleGraphConfigChartMappingList,
  1258. EdbMappingList: multipleGraphConfigEdbMappingList,
  1259. }
  1260. br.Ret = 200
  1261. br.Success = true
  1262. br.Msg = "保存成功"
  1263. br.Data = resp
  1264. br.IsAddLog = true
  1265. }
  1266. // Move
  1267. // @Title 移动图表接口
  1268. // @Description 移动图表接口
  1269. // @Success 200 {object} data_manage.MoveChartInfoReq
  1270. // @router /chart_info/move [post]
  1271. func (this *LineFeaturesChartInfoController) Move() {
  1272. br := new(models.BaseResponse).Init()
  1273. defer func() {
  1274. this.Data["json"] = br
  1275. this.ServeJSON()
  1276. }()
  1277. sysUser := this.SysUser
  1278. if sysUser == nil {
  1279. br.Msg = "请登录"
  1280. br.ErrMsg = "请登录,SysUser Is Empty"
  1281. br.Ret = 408
  1282. return
  1283. }
  1284. var req data_manage.MoveChartInfoReq
  1285. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1286. if err != nil {
  1287. br.Msg = "参数解析异常!"
  1288. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1289. return
  1290. }
  1291. if req.ChartInfoId <= 0 {
  1292. br.Msg = "参数错误"
  1293. br.ErrMsg = "图表id小于等于0"
  1294. return
  1295. }
  1296. if req.ChartClassifyId <= 0 {
  1297. br.Msg = "请选择分类"
  1298. return
  1299. }
  1300. //判断分类是否存在
  1301. count, _ := data_manage.GetChartClassifyCountById(req.ChartClassifyId)
  1302. if count <= 0 {
  1303. br.Msg = "分类已被删除,不可移动,请刷新页面"
  1304. return
  1305. }
  1306. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1307. if err != nil {
  1308. br.Msg = "移动失败"
  1309. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1310. return
  1311. }
  1312. if !utils.InArrayByInt([]int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, chartInfo.Source) {
  1313. br.Msg = "图表异常"
  1314. br.ErrMsg = "分类异常,不是统计特征的图表"
  1315. return
  1316. }
  1317. //如果改变了分类,那么移动该图表数据
  1318. if chartInfo.ChartClassifyId != req.ChartClassifyId {
  1319. //查询需要修改的分类下是否存在同一个图表名称
  1320. tmpChartInfo, tmpErr := data_manage.GetChartInfoByClassifyIdAndName(req.ChartClassifyId, chartInfo.ChartName)
  1321. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1322. br.Msg = "移动失败"
  1323. br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  1324. return
  1325. }
  1326. if tmpChartInfo != nil {
  1327. br.Msg = "移动失败,同一个分类下图表名称不允许重复"
  1328. br.ErrMsg = "移动失败,同一个分类下图表名称不允许重复"
  1329. return
  1330. }
  1331. err = data_manage.MoveChartInfo(req.ChartInfoId, req.ChartClassifyId)
  1332. if err != nil {
  1333. br.Msg = "移动失败"
  1334. br.ErrMsg = "移动失败,Err:" + err.Error()
  1335. return
  1336. }
  1337. }
  1338. //移动排序
  1339. updateCol := make([]string, 0)
  1340. //如果有传入 上一个兄弟节点分类id
  1341. if req.PrevChartInfoId > 0 {
  1342. prevChartInfo, err := data_manage.GetChartInfoById(req.PrevChartInfoId)
  1343. if err != nil {
  1344. br.Msg = "移动失败"
  1345. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  1346. return
  1347. }
  1348. //如果是移动在两个兄弟节点之间
  1349. if req.NextChartInfoId > 0 {
  1350. //下一个兄弟节点
  1351. nextChartInfo, err := data_manage.GetChartInfoById(req.NextChartInfoId)
  1352. if err != nil {
  1353. br.Msg = "移动失败"
  1354. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  1355. return
  1356. }
  1357. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  1358. if prevChartInfo.Sort == nextChartInfo.Sort || prevChartInfo.Sort == chartInfo.Sort {
  1359. //变更兄弟节点的排序
  1360. updateSortStr := `sort + 2`
  1361. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, updateSortStr)
  1362. } else {
  1363. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  1364. if nextChartInfo.Sort-prevChartInfo.Sort == 1 {
  1365. //变更兄弟节点的排序
  1366. updateSortStr := `sort + 1`
  1367. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, updateSortStr)
  1368. }
  1369. }
  1370. }
  1371. chartInfo.Sort = prevChartInfo.Sort + 1
  1372. chartInfo.ModifyTime = time.Now()
  1373. updateCol = append(updateCol, "Sort", "ModifyTime")
  1374. } else {
  1375. firstClassify, err := data_manage.GetFirstChartInfoByClassifyId(req.ChartClassifyId)
  1376. if err != nil && err.Error() != utils.ErrNoRow() {
  1377. br.Msg = "移动失败"
  1378. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  1379. return
  1380. }
  1381. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  1382. if firstClassify != nil && firstClassify.Sort == 0 {
  1383. updateSortStr := ` sort + 1 `
  1384. _ = data_manage.UpdateChartInfoSortByClassifyId(firstClassify.ChartClassifyId, 0, firstClassify.ChartInfoId-1, []int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, updateSortStr)
  1385. }
  1386. chartInfo.Sort = 0 //那就是排在第一位
  1387. chartInfo.ModifyTime = time.Now()
  1388. updateCol = append(updateCol, "Sort", "ModifyTime")
  1389. }
  1390. //更新
  1391. if len(updateCol) > 0 {
  1392. err = chartInfo.Update(updateCol)
  1393. if err != nil {
  1394. br.Msg = "移动失败"
  1395. br.ErrMsg = "修改失败,Err:" + err.Error()
  1396. return
  1397. }
  1398. }
  1399. if err != nil {
  1400. br.Msg = "移动失败"
  1401. br.ErrMsg = "修改失败,Err:" + err.Error()
  1402. return
  1403. }
  1404. //添加es数据
  1405. go data.EsAddOrEditChartInfo(req.ChartInfoId)
  1406. //修改my eta es数据
  1407. go data.EsAddOrEditMyChartInfoByChartInfoId(req.ChartInfoId)
  1408. //新增操作日志
  1409. {
  1410. chartLog := new(data_manage.ChartInfoLog)
  1411. chartLog.ChartName = chartInfo.ChartName
  1412. chartLog.ChartInfoId = req.ChartInfoId
  1413. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  1414. chartLog.SysUserId = sysUser.AdminId
  1415. chartLog.SysUserRealName = sysUser.RealName
  1416. chartLog.UniqueCode = chartInfo.UniqueCode
  1417. chartLog.CreateTime = time.Now()
  1418. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1419. chartLog.Status = "移动统计特征图表"
  1420. chartLog.Method = this.Ctx.Input.URL()
  1421. go data_manage.AddChartInfoLog(chartLog)
  1422. }
  1423. br.Ret = 200
  1424. br.Success = true
  1425. br.Msg = "移动成功"
  1426. }
  1427. // List
  1428. // @Title 统计特征图表列表接口
  1429. // @Description 统计特征图表列表接口
  1430. // @Param PageSize query int true "每页数据条数"
  1431. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1432. // @Param ChartClassifyId query int true "分类id"
  1433. // @Param Keyword query string true "搜索关键词"
  1434. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1435. // @Param Source query int true "图表类型,3:统计特征,4:滚动统计特征"
  1436. // @Success 200 {object} data_manage.ChartListResp
  1437. // @router /chart_info/list [get]
  1438. func (this *LineFeaturesChartInfoController) List() {
  1439. br := new(models.BaseResponse).Init()
  1440. defer func() {
  1441. this.Data["json"] = br
  1442. this.ServeJSON()
  1443. }()
  1444. sysUser := this.SysUser
  1445. if sysUser == nil {
  1446. br.Msg = "请登录"
  1447. br.ErrMsg = "请登录,SysUser Is Empty"
  1448. br.Ret = 408
  1449. return
  1450. }
  1451. chartClassifyId, _ := this.GetInt("ChartClassifyId")
  1452. pageSize, _ := this.GetInt("PageSize")
  1453. currentIndex, _ := this.GetInt("CurrentIndex")
  1454. keyword := this.GetString("KeyWord")
  1455. var total int
  1456. page := paging.GetPaging(currentIndex, pageSize, total)
  1457. var startSize int
  1458. if pageSize <= 0 {
  1459. pageSize = utils.PageSize20
  1460. }
  1461. if currentIndex <= 0 {
  1462. currentIndex = 1
  1463. }
  1464. startSize = paging.StartIndex(currentIndex, pageSize)
  1465. var condition string
  1466. var pars []interface{}
  1467. // 普通图表
  1468. condition += ` AND source in(?,?,?) `
  1469. pars = append(pars, utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY)
  1470. if chartClassifyId > 0 {
  1471. chartClassifyId, err := data_manage.GetChartClassify(chartClassifyId)
  1472. if err != nil && err.Error() != utils.ErrNoRow() {
  1473. br.Msg = "获取图表信息失败"
  1474. br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
  1475. return
  1476. }
  1477. condition += " AND chart_classify_id IN(" + chartClassifyId + ") "
  1478. }
  1479. if keyword != "" {
  1480. condition += ` AND ( chart_name LIKE '%` + keyword + `%' )`
  1481. }
  1482. //只看我的
  1483. isShowMe, _ := this.GetBool("IsShowMe")
  1484. if isShowMe {
  1485. condition += ` AND sys_user_id = ? `
  1486. pars = append(pars, sysUser.AdminId)
  1487. }
  1488. // 获取当前账号的不可见指标
  1489. noPermissionChartIdList := make([]int, 0)
  1490. {
  1491. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1492. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  1493. if err != nil && err.Error() != utils.ErrNoRow() {
  1494. br.Msg = "获取失败"
  1495. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  1496. return
  1497. }
  1498. for _, v := range confList {
  1499. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  1500. }
  1501. }
  1502. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  1503. if lenNoPermissionChartIdList > 0 {
  1504. condition += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  1505. pars = append(pars, noPermissionChartIdList)
  1506. }
  1507. //获取图表信息
  1508. list, err := data_manage.GetChartListByCondition(condition, pars, startSize, pageSize)
  1509. if err != nil && err.Error() != utils.ErrNoRow() {
  1510. br.Success = true
  1511. br.Msg = "获取图表信息失败"
  1512. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1513. return
  1514. }
  1515. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  1516. if err != nil && err.Error() != utils.ErrNoRow() {
  1517. br.Msg = "获取图表信息失败"
  1518. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  1519. return
  1520. }
  1521. myChartMap := make(map[int]*data_manage.MyChartView)
  1522. for _, v := range myChartList {
  1523. myChartMap[v.ChartInfoId] = v
  1524. }
  1525. listLen := len(list)
  1526. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  1527. if listLen > 0 {
  1528. chartInfoIds := ""
  1529. for _, v := range list {
  1530. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  1531. }
  1532. if chartInfoIds != "" {
  1533. chartInfoIds = strings.Trim(chartInfoIds, ",")
  1534. //判断是否需要展示英文标识
  1535. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  1536. if e != nil {
  1537. br.Msg = "获取失败"
  1538. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  1539. return
  1540. }
  1541. for _, v := range edbList {
  1542. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  1543. }
  1544. }
  1545. }
  1546. for i := 0; i < listLen; i++ {
  1547. //判断是否需要展示英文标识
  1548. if _, ok := chartEdbMap[list[i].ChartInfoId]; ok {
  1549. list[i].IsEnChart = data.CheckIsEnChart(list[i].ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, list[i].Source, list[i].ChartType)
  1550. }
  1551. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  1552. list[i].IsAdd = true
  1553. list[i].MyChartId = existItem.MyChartId
  1554. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  1555. }
  1556. }
  1557. resp := new(data_manage.ChartListResp)
  1558. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  1559. items := make([]*data_manage.ChartInfoView, 0)
  1560. resp.Paging = page
  1561. resp.List = items
  1562. br.Ret = 200
  1563. br.Success = true
  1564. br.Msg = "获取成功"
  1565. return
  1566. }
  1567. dataCount, err := data_manage.GetChartListCountByCondition(condition, pars)
  1568. if err != nil && err.Error() != utils.ErrNoRow() {
  1569. br.Msg = "获取指标信息失败"
  1570. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  1571. return
  1572. }
  1573. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  1574. resp.Paging = page
  1575. resp.List = list
  1576. br.Ret = 200
  1577. br.Success = true
  1578. br.Msg = "获取成功"
  1579. br.Data = resp
  1580. }
  1581. // Detail
  1582. // @Title 获取图表详情
  1583. // @Description 获取图表详情接口
  1584. // @Param ChartInfoId query int true "图表id"
  1585. // @Success 200 {object} data_manage.ChartInfoDetailResp
  1586. // @router /chart_info/detail [get]
  1587. func (this *LineFeaturesChartInfoController) Detail() {
  1588. br := new(models.BaseResponse).Init()
  1589. defer func() {
  1590. this.Data["json"] = br
  1591. this.ServeJSON()
  1592. }()
  1593. sysUser := this.SysUser
  1594. if sysUser == nil {
  1595. br.Msg = "请登录"
  1596. br.ErrMsg = "请登录,SysUser Is Empty"
  1597. br.Ret = 408
  1598. return
  1599. }
  1600. chartInfoId, _ := this.GetInt("ChartInfoId")
  1601. if chartInfoId <= 0 {
  1602. br.Msg = "参数有误"
  1603. return
  1604. }
  1605. var err error
  1606. chartInfo := new(data_manage.ChartInfoView)
  1607. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  1608. if err != nil {
  1609. if err.Error() == utils.ErrNoRow() {
  1610. br.Msg = "图被删除,请刷新页面"
  1611. br.ErrMsg = "图被删除,请刷新页面,Err:" + err.Error()
  1612. return
  1613. }
  1614. br.Msg = "获取失败"
  1615. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1616. return
  1617. }
  1618. if chartInfo.ExtraConfig == `` {
  1619. br.Msg = "获取失败"
  1620. br.ErrMsg = "获取配置信息失败,图表的额外配置信息为空"
  1621. return
  1622. }
  1623. // 获取图表关联指标
  1624. edbMappingList, err := data_manage.GetChartEdbMappingList(chartInfoId)
  1625. if err != nil {
  1626. br.Msg = "获取失败"
  1627. br.ErrMsg = "获取图表关联指标信息失败,Err:" + err.Error()
  1628. return
  1629. }
  1630. if len(edbMappingList) != 1 {
  1631. br.Msg = "获取失败"
  1632. br.ErrMsg = fmt.Sprint("获取图表关联指标信息异常,数量:", len(edbMappingList))
  1633. return
  1634. }
  1635. edbMapping := edbMappingList[0]
  1636. var edbList []*data_manage.ChartEdbInfoMapping
  1637. var errMsg string
  1638. var resultResp interface{}
  1639. switch chartInfo.Source {
  1640. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION:
  1641. calculateValue, err := strconv.Atoi(chartInfo.ExtraConfig)
  1642. if err != nil {
  1643. br.Msg = "获取失败"
  1644. br.ErrMsg = "格式化配置项失败,Err:" + err.Error()
  1645. return
  1646. }
  1647. edbList, resultResp, err, errMsg = lineFeatureServ.GetStandardDeviationData(0, edbMapping, calculateValue)
  1648. case utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE:
  1649. var percentileConfig request.Percentile
  1650. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &percentileConfig)
  1651. if err != nil {
  1652. br.Msg = "获取失败"
  1653. br.ErrMsg = "格式化配置项失败,Err:" + err.Error()
  1654. return
  1655. }
  1656. edbList, resultResp, err, errMsg = lineFeatureServ.GetPercentileData(0, edbMapping, percentileConfig.CalculateValue, percentileConfig.CalculateUnit)
  1657. case utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  1658. var frequencyDistributionConfig request.FrequencyDistribution
  1659. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &frequencyDistributionConfig)
  1660. if err != nil {
  1661. br.Msg = "获取失败"
  1662. br.ErrMsg = "格式化配置项失败,Err:" + err.Error()
  1663. return
  1664. }
  1665. // 获取图表中的指标数据
  1666. edbList, resultResp, err, errMsg = lineFeatureServ.GetFrequencyDistributionData(0, edbMapping, frequencyDistributionConfig.DateType, frequencyDistributionConfig.FrequencyValue, frequencyDistributionConfig.StartDate, frequencyDistributionConfig.EndDate)
  1667. default:
  1668. errMsg = `错误的图表`
  1669. err = errors.New(fmt.Sprint("错误的图表来源,source", chartInfo.Source))
  1670. }
  1671. if err != nil {
  1672. br.Msg = "获取失败"
  1673. if errMsg != `` {
  1674. br.Msg = errMsg
  1675. }
  1676. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1677. return
  1678. }
  1679. warnEdbList := make([]string, 0)
  1680. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  1681. for _, v := range edbList {
  1682. if v.IsNullData {
  1683. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  1684. }
  1685. chartEdbInfoMapping := *v
  1686. chartEdbInfoMapping.IsOrder = false
  1687. chartEdbInfoMapping.IsAxis = 1
  1688. //chartEdbInfoMapping.MinData = curveConf.LeftMin
  1689. //chartEdbInfoMapping.MaxData = curveConf.LeftMax
  1690. chartEdbInfoMapping.ChartColor = `#00F`
  1691. chartEdbInfoMapping.ChartWidth = 3
  1692. chartEdbInfoMapping.EdbInfoType = 1
  1693. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  1694. }
  1695. if len(warnEdbList) > 0 {
  1696. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  1697. }
  1698. // 判断是否加入我的图库
  1699. if chartInfoId > 0 && chartInfo != nil {
  1700. {
  1701. var myChartCondition string
  1702. var myChartPars []interface{}
  1703. myChartCondition += ` AND a.admin_id=? `
  1704. myChartPars = append(myChartPars, sysUser.AdminId)
  1705. myChartCondition += ` AND a.chart_info_id=? `
  1706. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1707. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1708. if err != nil && err.Error() != utils.ErrNoRow() {
  1709. br.Msg = "获取失败"
  1710. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1711. return
  1712. }
  1713. if myChartList != nil && len(myChartList) > 0 {
  1714. chartInfo.IsAdd = true
  1715. chartInfo.MyChartId = myChartList[0].MyChartId
  1716. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1717. }
  1718. }
  1719. }
  1720. //图表操作权限
  1721. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId)
  1722. //判断是否需要展示英文标识
  1723. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, chartInfo.Source, chartInfo.ChartType)
  1724. //chartInfo.UnitEn = edbInfoMappingA.UnitEn
  1725. // 另存为
  1726. isSaveAs := true
  1727. chartInfo.Button = data_manage.ChartViewButton{
  1728. IsEdit: chartInfo.IsEdit,
  1729. IsEnChart: chartInfo.IsEnChart,
  1730. IsAdd: chartInfo.IsAdd,
  1731. IsCopy: isSaveAs,
  1732. IsSetName: chartInfo.IsSetName,
  1733. }
  1734. resp := new(data_manage.ChartInfoDetailResp)
  1735. resp.ChartInfo = chartInfo
  1736. resp.EdbInfoList = edbList
  1737. resp.DataResp = resultResp
  1738. br.Ret = 200
  1739. br.Success = true
  1740. br.Msg = "获取成功"
  1741. br.Data = resp
  1742. }
  1743. // DetailFromUniqueCode
  1744. // @Title 根据编码获取图表详情
  1745. // @Description 根据编码获取图表详情接口
  1746. // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  1747. // @Param IsCache query bool true "是否走缓存,默认false"
  1748. // @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
  1749. // @router /chart_info/detail/from_unique_code [get]
  1750. func (this *LineFeaturesChartInfoController) DetailFromUniqueCode() {
  1751. br := new(models.BaseResponse).Init()
  1752. defer func() {
  1753. this.Data["json"] = br
  1754. this.ServeJSON()
  1755. }()
  1756. sysUser := this.SysUser
  1757. if sysUser == nil {
  1758. br.Msg = "请登录"
  1759. br.ErrMsg = "请登录,SysUser Is Empty"
  1760. br.Ret = 408
  1761. return
  1762. }
  1763. adminId := sysUser.AdminId
  1764. uniqueCode := this.GetString("UniqueCode")
  1765. if uniqueCode == "" {
  1766. br.Msg = "参数错误"
  1767. br.ErrMsg = "参数错误,uniqueCode is empty"
  1768. return
  1769. }
  1770. //是否走缓存
  1771. isCache, _ := this.GetBool("IsCache")
  1772. resp := new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  1773. status := true
  1774. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  1775. if err != nil {
  1776. if err.Error() == utils.ErrNoRow() {
  1777. status = false
  1778. } else {
  1779. br.Msg = "获取失败"
  1780. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1781. return
  1782. }
  1783. }
  1784. if chartInfo == nil {
  1785. status = false
  1786. }
  1787. if !status {
  1788. endInfoList := make([]*data_manage.ChartEdbInfoMapping, 0)
  1789. resp.EdbInfoList = endInfoList
  1790. resp.ChartInfo = chartInfo
  1791. resp.Status = false
  1792. br.Ret = 200
  1793. br.Success = true
  1794. br.Msg = "获取成功"
  1795. br.Data = resp
  1796. return
  1797. }
  1798. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  1799. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  1800. if utils.Re == nil && isCache {
  1801. if utils.Re == nil && utils.Rc.IsExist(key) {
  1802. if d, e := utils.Rc.RedisBytes(key); e == nil {
  1803. err := json.Unmarshal(d, &resp)
  1804. if err == nil && resp != nil {
  1805. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  1806. var myCond string
  1807. var myPars []interface{}
  1808. myCond += ` AND a.admin_id=? `
  1809. myPars = append(myPars, adminId)
  1810. myCond += ` AND a.chart_info_id=? `
  1811. myPars = append(myPars, chartInfo.ChartInfoId)
  1812. myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
  1813. if err != nil && err.Error() != utils.ErrNoRow() {
  1814. br.Msg = "获取失败"
  1815. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1816. return
  1817. }
  1818. resp.ChartInfo.IsAdd = false
  1819. resp.ChartInfo.MyChartId = 0
  1820. resp.ChartInfo.MyChartClassifyId = ""
  1821. if myList != nil && len(myList) > 0 {
  1822. resp.ChartInfo.IsAdd = true
  1823. resp.ChartInfo.MyChartId = myList[0].MyChartId
  1824. resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
  1825. }
  1826. br.Ret = 200
  1827. br.Success = true
  1828. br.Msg = "获取成功"
  1829. br.Data = resp
  1830. return
  1831. }
  1832. }
  1833. }
  1834. }
  1835. resp, isOk, msg, errMsg := GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  1836. if !isOk {
  1837. br.Msg = msg
  1838. br.ErrMsg = errMsg
  1839. return
  1840. }
  1841. if !isOk {
  1842. br.Msg = msg
  1843. br.ErrMsg = errMsg
  1844. return
  1845. }
  1846. br.Ret = 200
  1847. br.Success = true
  1848. br.Msg = "获取成功"
  1849. br.Data = resp
  1850. }
  1851. // Refresh
  1852. // @Title 图表刷新接口
  1853. // @Description 图表刷新接口
  1854. // @Param ChartInfoId query int true "图表id"
  1855. // @Param UniqueCode query string true "唯一code"
  1856. // @Success Ret=200 刷新成功
  1857. // @router /chart_info/refresh [get]
  1858. func (this *LineFeaturesChartInfoController) Refresh() {
  1859. br := new(models.BaseResponse).Init()
  1860. defer func() {
  1861. this.Data["json"] = br
  1862. this.ServeJSON()
  1863. }()
  1864. sysUser := this.SysUser
  1865. if sysUser == nil {
  1866. br.Msg = "请登录"
  1867. br.ErrMsg = "请登录,SysUser Is Empty"
  1868. br.Ret = 408
  1869. return
  1870. }
  1871. chartInfoId, _ := this.GetInt("ChartInfoId")
  1872. uniqueCode := this.GetString("UniqueCode")
  1873. if chartInfoId <= 0 && uniqueCode == `` {
  1874. br.Msg = "参数错误"
  1875. br.ErrMsg = "参数错误:chartInfoId:" + strconv.Itoa(chartInfoId) + ",UniqueCode:" + uniqueCode
  1876. return
  1877. }
  1878. var chartInfo *data_manage.ChartInfo
  1879. var err error
  1880. if chartInfoId > 0 {
  1881. chartInfo, err = data_manage.GetChartInfoById(chartInfoId)
  1882. } else {
  1883. chartInfo, err = data_manage.GetChartInfoByUniqueCode(uniqueCode)
  1884. }
  1885. if err != nil {
  1886. if err.Error() == utils.ErrNoRow() {
  1887. br.Msg = "图表已被删除,无需刷新"
  1888. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  1889. return
  1890. }
  1891. br.Msg = "刷新失败"
  1892. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1893. return
  1894. }
  1895. // 刷新图表的指标信息
  1896. err = data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
  1897. //清除图表缓存
  1898. {
  1899. key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
  1900. _ = utils.Rc.Delete(key)
  1901. }
  1902. br.Ret = 200
  1903. br.Success = true
  1904. br.Msg = "刷新成功"
  1905. }
  1906. // Copy
  1907. // @Title 复制并新增图表接口
  1908. // @Description 复制并新增图表接口
  1909. // @Param request body data_manage.CopyAddChartInfoReq true "type json string"
  1910. // @Success 200 {object} data_manage.AddChartInfoResp
  1911. // @router /chart_info/copy [post]
  1912. func (this *LineFeaturesChartInfoController) Copy() {
  1913. br := new(models.BaseResponse).Init()
  1914. defer func() {
  1915. this.Data["json"] = br
  1916. this.ServeJSON()
  1917. }()
  1918. sysUser := this.SysUser
  1919. if sysUser == nil {
  1920. br.Msg = "请登录"
  1921. br.ErrMsg = "请登录,SysUser Is Empty"
  1922. br.Ret = 408
  1923. return
  1924. }
  1925. deleteCache := true
  1926. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  1927. defer func() {
  1928. if deleteCache {
  1929. utils.Rc.Delete(cacheKey)
  1930. }
  1931. }()
  1932. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1933. deleteCache = false
  1934. br.Msg = "系统处理中,请稍后重试!"
  1935. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1936. return
  1937. }
  1938. var req data_manage.CopyAddChartInfoReq
  1939. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1940. if err != nil {
  1941. br.Msg = "参数解析异常!"
  1942. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1943. return
  1944. }
  1945. // 获取原图表信息
  1946. oldChartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  1947. if err != nil {
  1948. br.Msg = "获取原图表信息失败"
  1949. br.ErrMsg = "获取原图表信息失败,Err:" + err.Error()
  1950. return
  1951. }
  1952. if !utils.InArrayByInt([]int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}, oldChartInfo.Source) {
  1953. br.Msg = `错误的图表类型`
  1954. br.IsSendEmail = false
  1955. return
  1956. }
  1957. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByChartId(oldChartInfo.ChartInfoId)
  1958. if err != nil && err.Error() != utils.ErrNoRow() {
  1959. br.Msg = `保存失败`
  1960. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  1961. return
  1962. }
  1963. // 获取图表关联指标
  1964. edbMappingList, err := data_manage.GetChartEdbMappingList(oldChartInfo.ChartInfoId)
  1965. if err != nil {
  1966. br.Msg = "获取失败"
  1967. br.ErrMsg = "获取图表关联指标信息失败,Err:" + err.Error()
  1968. return
  1969. }
  1970. if len(edbMappingList) != 1 {
  1971. br.Msg = "获取失败"
  1972. br.ErrMsg = fmt.Sprint("获取图表关联指标信息异常,数量:", len(edbMappingList))
  1973. return
  1974. }
  1975. edbInfoMapping := edbMappingList[0]
  1976. // 批量设置图
  1977. chartInfo, err, errMsg, isSendEmail := lineFeatureServ.CopyChartInfo(multipleGraphConfigChartMapping.MultipleGraphConfigId, multipleGraphConfigChartMapping.Source, req.ChartClassifyId, req.ChartName, edbInfoMapping, oldChartInfo, sysUser)
  1978. if err != nil {
  1979. br.Msg = "复制失败"
  1980. if errMsg != `` {
  1981. br.Msg = errMsg
  1982. }
  1983. br.ErrMsg = "复制失败,ERR:" + err.Error()
  1984. br.IsSendEmail = isSendEmail
  1985. return
  1986. }
  1987. resp := data_manage.AddChartInfoResp{
  1988. ChartInfoId: chartInfo.ChartInfoId,
  1989. UniqueCode: chartInfo.UniqueCode,
  1990. ChartType: chartInfo.ChartType,
  1991. }
  1992. //新增操作日志
  1993. {
  1994. chartLog := new(data_manage.ChartInfoLog)
  1995. chartLog.ChartInfoId = chartInfo.ChartInfoId
  1996. chartLog.ChartName = chartInfo.ChartName
  1997. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  1998. chartLog.SysUserId = sysUser.AdminId
  1999. chartLog.SysUserRealName = sysUser.RealName
  2000. chartLog.UniqueCode = chartInfo.UniqueCode
  2001. chartLog.CreateTime = time.Now()
  2002. chartLog.Content = string(this.Ctx.Input.RequestBody)
  2003. chartLog.Status = "新增统计特征图表"
  2004. chartLog.Method = this.Ctx.Input.URI()
  2005. go data_manage.AddChartInfoLog(chartLog)
  2006. }
  2007. br.Ret = 200
  2008. br.Data = resp
  2009. br.Success = true
  2010. br.Msg = "保存成功"
  2011. br.IsAddLog = true
  2012. }
  2013. // GetChartInfoDetailFromUniqueCode 根据编码获取图表详情
  2014. func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  2015. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  2016. adminId := sysUser.AdminId
  2017. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  2018. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  2019. if utils.Re == nil && isCache {
  2020. if utils.Re == nil && utils.Rc.IsExist(key) {
  2021. if chartData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  2022. err := json.Unmarshal(chartData, &resp)
  2023. if err == nil && resp != nil {
  2024. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  2025. var myCond string
  2026. var myPars []interface{}
  2027. myCond += ` AND a.admin_id=? `
  2028. myPars = append(myPars, adminId)
  2029. myCond += ` AND a.chart_info_id=? `
  2030. myPars = append(myPars, chartInfo.ChartInfoId)
  2031. myList, err := data_manage.GetMyChartByCondition(myCond, myPars)
  2032. if err != nil && err.Error() != utils.ErrNoRow() {
  2033. msg = "获取失败"
  2034. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  2035. return
  2036. }
  2037. resp.ChartInfo.IsAdd = false
  2038. resp.ChartInfo.MyChartId = 0
  2039. resp.ChartInfo.MyChartClassifyId = ""
  2040. if myList != nil && len(myList) > 0 {
  2041. resp.ChartInfo.IsAdd = true
  2042. resp.ChartInfo.MyChartId = myList[0].MyChartId
  2043. resp.ChartInfo.MyChartClassifyId = myList[0].MyChartClassifyId
  2044. }
  2045. isOk = true
  2046. fmt.Println("source redis")
  2047. return
  2048. }
  2049. }
  2050. }
  2051. }
  2052. if chartInfo.ExtraConfig == `` {
  2053. msg = "获取失败"
  2054. errMsg = "获取配置信息失败,图表的额外配置信息为空"
  2055. return
  2056. }
  2057. // 获取图表关联指标
  2058. edbMappingList, err := data_manage.GetChartEdbMappingList(chartInfo.ChartInfoId)
  2059. if err != nil {
  2060. msg = "获取失败"
  2061. errMsg = "获取图表关联指标信息失败,Err:" + err.Error()
  2062. return
  2063. }
  2064. if len(edbMappingList) != 1 {
  2065. msg = "获取失败"
  2066. errMsg = fmt.Sprint("获取图表关联指标信息异常,数量:", len(edbMappingList))
  2067. return
  2068. }
  2069. edbMapping := edbMappingList[0]
  2070. var edbList []*data_manage.ChartEdbInfoMapping
  2071. var resultResp interface{}
  2072. switch chartInfo.Source {
  2073. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION:
  2074. calculateValue, tmpErr := strconv.Atoi(chartInfo.ExtraConfig)
  2075. if tmpErr != nil {
  2076. msg = "获取失败"
  2077. errMsg = "格式化配置项失败,Err:" + tmpErr.Error()
  2078. return
  2079. }
  2080. edbList, resultResp, err, msg = lineFeatureServ.GetStandardDeviationData(0, edbMapping, calculateValue)
  2081. case utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE:
  2082. var percentileConfig request.Percentile
  2083. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &percentileConfig)
  2084. if err != nil {
  2085. msg = "获取失败"
  2086. errMsg = "格式化配置项失败,Err:" + err.Error()
  2087. return
  2088. }
  2089. edbList, resultResp, err, msg = lineFeatureServ.GetPercentileData(0, edbMapping, percentileConfig.CalculateValue, percentileConfig.CalculateUnit)
  2090. case utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  2091. var frequencyDistributionConfig request.FrequencyDistribution
  2092. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &frequencyDistributionConfig)
  2093. if err != nil {
  2094. msg = "获取失败"
  2095. errMsg = "格式化配置项失败,Err:" + err.Error()
  2096. return
  2097. }
  2098. // 获取图表中的指标数据
  2099. edbList, resultResp, err, errMsg = lineFeatureServ.GetFrequencyDistributionData(0, edbMapping, frequencyDistributionConfig.DateType, frequencyDistributionConfig.FrequencyValue, frequencyDistributionConfig.StartDate, frequencyDistributionConfig.EndDate)
  2100. default:
  2101. msg = `错误的图表`
  2102. errMsg = fmt.Sprint("错误的图表来源,source", chartInfo.Source)
  2103. return
  2104. }
  2105. if err != nil {
  2106. if msg == `` {
  2107. msg = "获取失败"
  2108. }
  2109. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2110. return
  2111. }
  2112. if chartInfo.ChartInfoId > 0 && chartInfo != nil {
  2113. //判断是否加入我的图库
  2114. {
  2115. var myChartCondition string
  2116. var myChartPars []interface{}
  2117. myChartCondition += ` AND a.admin_id=? `
  2118. myChartPars = append(myChartPars, sysUser.AdminId)
  2119. myChartCondition += ` AND a.chart_info_id=? `
  2120. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  2121. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  2122. if err != nil && err.Error() != utils.ErrNoRow() {
  2123. msg = "获取失败"
  2124. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  2125. return
  2126. }
  2127. if myChartList != nil && len(myChartList) > 0 {
  2128. chartInfo.IsAdd = true
  2129. chartInfo.MyChartId = myChartList[0].MyChartId
  2130. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  2131. }
  2132. }
  2133. }
  2134. //图表操作权限
  2135. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId)
  2136. //判断是否需要展示英文标识
  2137. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, chartInfo.Source, chartInfo.ChartType)
  2138. //chartInfo.UnitEn = edbInfoMappingA.UnitEn
  2139. isSaveAs := true
  2140. // 另存为
  2141. chartInfo.Button = data_manage.ChartViewButton{
  2142. IsEdit: chartInfo.IsEdit,
  2143. IsEnChart: chartInfo.IsEnChart,
  2144. IsAdd: chartInfo.IsAdd,
  2145. IsCopy: isSaveAs,
  2146. IsSetName: chartInfo.IsSetName,
  2147. }
  2148. resp.ChartInfo = chartInfo
  2149. resp.EdbInfoList = edbList
  2150. resp.DataResp = resultResp
  2151. resp.Status = true
  2152. // 将数据加入缓存
  2153. if utils.Re == nil {
  2154. d, _ := json.Marshal(resp)
  2155. _ = utils.Rc.Put(key, d, 2*time.Hour)
  2156. }
  2157. isOk = true
  2158. return
  2159. }
  2160. // EnInfoEdit
  2161. // @Title 编辑图表英文信息接口
  2162. // @Description 编辑图表英文信息接口
  2163. // @Param request body data_manage.EditChartEnInfoReq true "type json string"
  2164. // @Success Ret=200 编辑成功
  2165. // @router /chart_info/en/edit [post]
  2166. func (this *LineFeaturesChartInfoController) EnInfoEdit() {
  2167. br := new(models.BaseResponse).Init()
  2168. defer func() {
  2169. this.Data["json"] = br
  2170. this.ServeJSON()
  2171. }()
  2172. sysUser := this.SysUser
  2173. if sysUser == nil {
  2174. br.Msg = "请登录"
  2175. br.ErrMsg = "请登录,SysUser Is Empty"
  2176. br.Ret = 408
  2177. return
  2178. }
  2179. var req request.EditChartEnInfoReq
  2180. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2181. if err != nil {
  2182. br.Msg = "参数解析异常!"
  2183. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2184. return
  2185. }
  2186. req.ChartNameEn = strings.Trim(req.ChartNameEn, " ")
  2187. if req.ChartInfoId <= 0 {
  2188. br.Msg = "请选择图表"
  2189. return
  2190. }
  2191. if req.ChartNameEn == "" {
  2192. br.Msg = "请输入英文图表名称"
  2193. return
  2194. }
  2195. //判断指标名称是否存在
  2196. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  2197. if err != nil {
  2198. if err.Error() == utils.ErrNoRow() {
  2199. br.Msg = "图表已被删除,请刷新页面"
  2200. br.ErrMsg = "图表已被删除,请刷新页面"
  2201. return
  2202. }
  2203. br.Msg = "获取图表信息失败"
  2204. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2205. return
  2206. }
  2207. // 校验名称是否有重复
  2208. {
  2209. var condition string
  2210. var pars []interface{}
  2211. condition += " AND chart_info_id <> ? AND chart_name_en = ? AND source in (?,?,?)"
  2212. pars = append(pars, req.ChartInfoId, req.ChartNameEn, utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY)
  2213. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  2214. if err != nil {
  2215. if err.Error() != utils.ErrNoRow() {
  2216. br.Msg = "判断英文图表名称是否存在失败"
  2217. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  2218. return
  2219. }
  2220. }
  2221. if err == nil && existItem.ChartInfoId > 0 {
  2222. br.Msg = existItem.ChartName + ":" + req.ChartNameEn + "图表名称已存在"
  2223. return
  2224. }
  2225. }
  2226. chartItem.ChartNameEn = req.ChartNameEn
  2227. chartItem.ModifyTime = time.Now().Local()
  2228. if e := chartItem.Update([]string{"ChartNameEn", "ModifyTime"}); e != nil {
  2229. br.Msg = "操作失败"
  2230. br.ErrMsg = "更新图表信息失败, Err: " + e.Error()
  2231. return
  2232. }
  2233. //添加es数据
  2234. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  2235. //修改my eta es数据
  2236. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  2237. //指标 修改es信息
  2238. //go data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  2239. //新增操作日志
  2240. {
  2241. chartLog := new(data_manage.ChartInfoLog)
  2242. chartLog.ChartName = chartItem.ChartName
  2243. chartLog.ChartInfoId = req.ChartInfoId
  2244. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  2245. chartLog.SysUserId = sysUser.AdminId
  2246. chartLog.SysUserRealName = sysUser.RealName
  2247. chartLog.UniqueCode = chartItem.UniqueCode
  2248. chartLog.CreateTime = time.Now()
  2249. chartLog.Content = string(this.Ctx.Input.RequestBody)
  2250. chartLog.Status = "编辑统计特征图表英文信息"
  2251. chartLog.Method = this.Ctx.Input.URL()
  2252. go data_manage.AddChartInfoLog(chartLog)
  2253. }
  2254. // 清除缓存
  2255. if utils.Re == nil && utils.Rc != nil {
  2256. _ = utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  2257. _ = utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  2258. }
  2259. br.Ret = 200
  2260. br.Success = true
  2261. br.Msg = "编辑成功"
  2262. br.IsAddLog = true
  2263. }
  2264. // SearchByEs
  2265. // @Title 图表模糊搜索(从es获取)
  2266. // @Description 图表模糊搜索(从es获取)
  2267. // @Param Keyword query string true "图表名称"
  2268. // @Param IsShowMe query bool true "是否只看我的,true、false"
  2269. // @Param Source query int true "来源,3:统计特征,4:滚动统计特征,默认0:全部"
  2270. // @Success 200 {object} data_manage.ChartInfo
  2271. // @router /chart_info/search_by_es [get]
  2272. func (this *LineFeaturesChartInfoController) SearchByEs() {
  2273. br := new(models.BaseResponse).Init()
  2274. defer func() {
  2275. this.Data["json"] = br
  2276. this.ServeJSON()
  2277. }()
  2278. sysUser := this.SysUser
  2279. if sysUser == nil {
  2280. br.Msg = "请登录"
  2281. br.ErrMsg = "请登录,SysUser Is Empty"
  2282. br.Ret = 408
  2283. return
  2284. }
  2285. pageSize, _ := this.GetInt("PageSize")
  2286. currentIndex, _ := this.GetInt("CurrentIndex")
  2287. var startSize int
  2288. if pageSize <= 0 {
  2289. pageSize = utils.PageSize20
  2290. }
  2291. if currentIndex <= 0 {
  2292. currentIndex = 1
  2293. }
  2294. startSize = paging.StartIndex(currentIndex, pageSize)
  2295. keyword := this.GetString("Keyword")
  2296. //只看我的
  2297. isShowMe, _ := this.GetBool("IsShowMe")
  2298. showSysId := 0
  2299. if isShowMe {
  2300. showSysId = sysUser.AdminId
  2301. }
  2302. sourceList := []int{utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY}
  2303. var searchList []*data_manage.ChartInfo
  2304. var total int64
  2305. var err error
  2306. // 获取当前账号的不可见指标
  2307. noPermissionChartIdList := make([]int, 0)
  2308. {
  2309. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2310. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  2311. if err != nil && err.Error() != utils.ErrNoRow() {
  2312. br.Msg = "获取失败"
  2313. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  2314. return
  2315. }
  2316. for _, v := range confList {
  2317. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  2318. }
  2319. }
  2320. if keyword != "" {
  2321. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
  2322. } else {
  2323. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList)
  2324. if err != nil && err.Error() != utils.ErrNoRow() {
  2325. br.Msg = "获取失败"
  2326. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2327. return
  2328. }
  2329. }
  2330. finalList := make([]*data_manage.ChartInfoMore, 0)
  2331. if len(searchList) > 0 {
  2332. chartInfoIds := ""
  2333. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  2334. for _, v := range searchList {
  2335. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  2336. }
  2337. if chartInfoIds != "" {
  2338. chartInfoIds = strings.Trim(chartInfoIds, ",")
  2339. //判断是否需要展示英文标识
  2340. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  2341. if e != nil {
  2342. br.Msg = "获取失败"
  2343. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  2344. return
  2345. }
  2346. for _, v := range edbList {
  2347. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  2348. }
  2349. }
  2350. for _, v := range searchList {
  2351. tmp := new(data_manage.ChartInfoMore)
  2352. tmp.ChartInfo = *v
  2353. //判断是否需要展示英文标识
  2354. if _, ok := chartEdbMap[v.ChartInfoId]; ok {
  2355. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, []*data_manage.ChartEdbInfoMapping{}, v.Source, v.ChartType)
  2356. }
  2357. finalList = append(finalList, tmp)
  2358. }
  2359. }
  2360. //新增搜索词记录
  2361. {
  2362. searchKeyword := new(data_manage.SearchKeyword)
  2363. searchKeyword.KeyWord = keyword
  2364. searchKeyword.CreateTime = time.Now()
  2365. go data_manage.AddSearchKeyword(searchKeyword)
  2366. }
  2367. page := paging.GetPaging(currentIndex, pageSize, int(total))
  2368. resp := data_manage.ChartInfoListByEsResp{
  2369. Paging: page,
  2370. List: finalList,
  2371. }
  2372. br.Ret = 200
  2373. br.Success = true
  2374. br.Msg = "获取成功"
  2375. br.Data = resp
  2376. }