multiple_graph_config.go 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/data_manage"
  6. "eta/eta_api/models/data_manage/request"
  7. "eta/eta_api/models/data_manage/response"
  8. "eta/eta_api/models/system"
  9. "eta/eta_api/services/data"
  10. correlationServ "eta/eta_api/services/data/correlation"
  11. "eta/eta_api/utils"
  12. "fmt"
  13. "math"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. //多图配置
  19. // MultipleGraphConfigSave
  20. // @Title 保存配置接口
  21. // @Description 保存配置接口
  22. // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
  23. // @Success Ret=200 返回图表id
  24. // @router /multiple_graph/config/save [post]
  25. func (this *ChartInfoController) MultipleGraphConfigSave() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. sysUser := this.SysUser
  32. if sysUser == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,SysUser Is Empty"
  35. br.Ret = 408
  36. return
  37. }
  38. var req request.SaveMultipleGraphConfigReq
  39. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  40. if err != nil {
  41. br.Msg = "参数解析异常!"
  42. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  43. return
  44. }
  45. if req.EdbInfoIdA <= 0 {
  46. br.Msg = "指标A未选择"
  47. br.IsSendEmail = false
  48. return
  49. }
  50. _, err = data_manage.GetEdbInfoById(req.EdbInfoIdA)
  51. if err != nil {
  52. br.Msg = "指标A异常"
  53. br.ErrMsg = "指标A异常,err:" + err.Error()
  54. if err.Error() == utils.ErrNoRow() {
  55. br.Msg = `指标A不存在`
  56. br.IsSendEmail = false
  57. }
  58. return
  59. }
  60. if req.EdbInfoIdB <= 0 {
  61. br.Msg = "指标B未选择"
  62. br.IsSendEmail = false
  63. return
  64. }
  65. _, err = data_manage.GetEdbInfoById(req.EdbInfoIdB)
  66. if err != nil {
  67. br.Msg = "指标B异常"
  68. br.ErrMsg = "指标B异常,err:" + err.Error()
  69. if err.Error() == utils.ErrNoRow() {
  70. br.Msg = `指标B不存在`
  71. br.IsSendEmail = false
  72. }
  73. return
  74. }
  75. curveStrByte, err := json.Marshal(req.Curve)
  76. if err != nil {
  77. br.Msg = `曲线图配置异常`
  78. br.ErrMsg = `曲线图配置异常,ERR:` + err.Error()
  79. return
  80. }
  81. if req.Correlation.LeadValue <= 0 {
  82. br.Msg = `分析周期不允许设置为负数或0`
  83. br.IsSendEmail = false
  84. return
  85. }
  86. correlationStrByte, err := json.Marshal(req.Correlation)
  87. if err != nil {
  88. br.Msg = `相关性配置异常`
  89. br.ErrMsg = `相关性配置异常,ERR:` + err.Error()
  90. return
  91. }
  92. rollingCorrelationStrByte, err := json.Marshal(req.RollingCorrelation)
  93. if err != nil {
  94. br.Msg = `滚动相关性配置异常`
  95. br.ErrMsg = `滚动相关性配置异常,ERR:` + err.Error()
  96. return
  97. }
  98. var multipleGraphConfig *data_manage.MultipleGraphConfig
  99. if req.MultipleGraphConfigId > 0 {
  100. multipleGraphConfig, err = data_manage.GetMultipleGraphConfigById(req.MultipleGraphConfigId)
  101. if err != nil {
  102. br.Msg = `不存在该配置`
  103. br.ErrMsg = `不存在该配置`
  104. return
  105. }
  106. multipleGraphConfig.EdbInfoIdA = req.EdbInfoIdA
  107. multipleGraphConfig.EdbInfoIdB = req.EdbInfoIdB
  108. multipleGraphConfig.Curve = string(curveStrByte)
  109. multipleGraphConfig.Correlation = string(correlationStrByte)
  110. multipleGraphConfig.RollingCorrelation = string(rollingCorrelationStrByte)
  111. multipleGraphConfig.ModifyTime = time.Now()
  112. err = multipleGraphConfig.Update([]string{"EdbInfoIdA", "EdbInfoIdB", "Curve", "Correlation", "RollingCorrelation", "ModifyTime"})
  113. } else {
  114. multipleGraphConfig = &data_manage.MultipleGraphConfig{
  115. //MultipleGraphConfigId: 0,
  116. EdbInfoIdA: req.EdbInfoIdA,
  117. EdbInfoIdB: req.EdbInfoIdB,
  118. Curve: string(curveStrByte),
  119. Correlation: string(correlationStrByte),
  120. RollingCorrelation: string(rollingCorrelationStrByte),
  121. SysUserId: this.SysUser.AdminId,
  122. SysUserRealName: this.SysUser.RealName,
  123. ModifyTime: time.Now(),
  124. CreateTime: time.Now(),
  125. }
  126. err = data_manage.AddMultipleGraphConfig(multipleGraphConfig)
  127. }
  128. if err != nil {
  129. br.Msg = `保存失败`
  130. br.ErrMsg = `保存失败,Err:` + err.Error()
  131. return
  132. }
  133. br.Ret = 200
  134. br.Success = true
  135. br.Msg = "保存成功"
  136. br.Data = multipleGraphConfig
  137. br.IsAddLog = true
  138. }
  139. // MultipleGraphPreview
  140. // @Title 批量添加图表的预览接口
  141. // @Description 批量添加图表的预览接口
  142. // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
  143. // @Success Ret=200 返回图表id
  144. // @router /multiple_graph/preview [post]
  145. func (this *ChartInfoController) MultipleGraphPreview() {
  146. br := new(models.BaseResponse).Init()
  147. defer func() {
  148. this.Data["json"] = br
  149. this.ServeJSON()
  150. }()
  151. sysUser := this.SysUser
  152. if sysUser == nil {
  153. br.Msg = "请登录"
  154. br.ErrMsg = "请登录,SysUser Is Empty"
  155. br.Ret = 408
  156. return
  157. }
  158. var req request.SaveMultipleGraphConfigReq
  159. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  160. if err != nil {
  161. br.Msg = "参数解析异常!"
  162. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  163. return
  164. }
  165. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
  166. if err != nil {
  167. br.Msg = "获取失败"
  168. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  169. return
  170. }
  171. maxYear := 0
  172. var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
  173. for _, v := range mappingList {
  174. if v.EdbInfoId == req.EdbInfoIdA {
  175. edbInfoMappingA = v
  176. }
  177. if v.EdbInfoId == req.EdbInfoIdB {
  178. edbInfoMappingB = v
  179. }
  180. if v.LatestDate != "" {
  181. latestDateT, _ := time.Parse(utils.FormatDate, v.LatestDate)
  182. maxYear = latestDateT.Year()
  183. }
  184. }
  185. if edbInfoMappingA == nil {
  186. br.Msg = "指标A不存在"
  187. br.IsSendEmail = false
  188. return
  189. }
  190. if edbInfoMappingB == nil {
  191. br.Msg = "指标B不存在"
  192. br.IsSendEmail = false
  193. return
  194. }
  195. resp := response.PreviewMultipleGraphConfigResp{}
  196. chartInfo := new(data_manage.ChartInfoView)
  197. chartInfo.Calendar = `公历`
  198. chartInfo.ChartName = edbInfoMappingA.EdbName + "与" + edbInfoMappingB.EdbName
  199. // 曲线图表信息
  200. {
  201. tmpChartInfo := *chartInfo
  202. curveConf := req.Curve
  203. edbInfoType := 0
  204. if curveConf.EdbInfoType {
  205. edbInfoType = 1
  206. }
  207. for _, v := range mappingList {
  208. v.EdbInfoType = 1
  209. v.IsOrder = false
  210. if v.EdbInfoId == req.EdbInfoIdB {
  211. v.LeadValue = curveConf.LeadValue
  212. v.LeadUnit = curveConf.LeadUnit
  213. v.EdbInfoType = edbInfoType
  214. v.IsOrder = curveConf.IsOrder
  215. }
  216. }
  217. startDate, endDate := utils.GetDateByDateTypeV2(curveConf.DateType, curveConf.StartDate, curveConf.EndDate, curveConf.StartYear, maxYear)
  218. // 获取图表中的指标数据
  219. edbList, _, _, _, err, errMsg := data.GetChartEdbData(tmpChartInfo.ChartInfoId, tmpChartInfo.ChartType, tmpChartInfo.Calendar, startDate, endDate, mappingList, tmpChartInfo.ExtraConfig, tmpChartInfo.SeasonExtraConfig)
  220. if err != nil {
  221. br.Msg = "获取失败"
  222. if errMsg != `` {
  223. br.Msg = errMsg
  224. }
  225. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  226. return
  227. }
  228. warnEdbList := make([]string, 0)
  229. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  230. for _, v := range edbList {
  231. if v.IsNullData {
  232. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  233. }
  234. chartEdbInfoMapping := *v
  235. chartEdbInfoMapping.IsOrder = false
  236. if v.EdbInfoId == req.EdbInfoIdA {
  237. chartEdbInfoMapping.IsAxis = 1
  238. chartEdbInfoMapping.MinData = curveConf.LeftMin
  239. chartEdbInfoMapping.MaxData = curveConf.LeftMax
  240. chartEdbInfoMapping.ChartColor = `#00F`
  241. chartEdbInfoMapping.LeadValue = curveConf.LeadValue
  242. chartEdbInfoMapping.LeadUnit = curveConf.LeadUnit
  243. chartEdbInfoMapping.ChartWidth = 3
  244. chartEdbInfoMapping.EdbInfoType = edbInfoType
  245. } else {
  246. chartEdbInfoMapping.IsAxis = 0
  247. chartEdbInfoMapping.MinData = curveConf.RightMin
  248. chartEdbInfoMapping.MaxData = curveConf.RightMax
  249. chartEdbInfoMapping.ChartColor = `#F00`
  250. chartEdbInfoMapping.LeadValue = curveConf.LeadValue
  251. chartEdbInfoMapping.LeadUnit = curveConf.LeadUnit
  252. chartEdbInfoMapping.ChartWidth = 1
  253. chartEdbInfoMapping.IsOrder = curveConf.IsOrder
  254. chartEdbInfoMapping.EdbInfoType = edbInfoType
  255. }
  256. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  257. }
  258. if len(warnEdbList) > 0 {
  259. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  260. }
  261. tmpChartInfo.Source = utils.CHART_SOURCE_DEFAULT
  262. tmpChartInfo.DateType = curveConf.DateType
  263. tmpChartInfo.StartDate = startDate
  264. tmpChartInfo.EndDate = endDate
  265. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  266. resp.CurveData = response.CurveResp{
  267. ChartInfo: tmpChartInfo,
  268. EdbInfoList: tmpEdbList,
  269. }
  270. }
  271. // 相关性图表信息
  272. {
  273. correlationConf := req.Correlation
  274. // 配置了数据才有返回
  275. if correlationConf.LeadValue > 0 {
  276. tmpChartInfo := *chartInfo
  277. moveUnitDays, ok := utils.FrequencyDaysMap[correlationConf.CalculateUnit]
  278. if !ok {
  279. br.Msg = "错误的分析周期"
  280. br.IsSendEmail = false
  281. return
  282. }
  283. startDate := time.Now().AddDate(0, 0, -correlationConf.CalculateValue*moveUnitDays).Format(utils.FormatDate)
  284. endDate := time.Now().Format(utils.FormatDate)
  285. xEdbIdValue, yDataList, e := correlationServ.GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB, correlationConf.LeadValue, correlationConf.LeadUnit, startDate, endDate)
  286. if e != nil {
  287. br.Msg = "获取失败"
  288. br.ErrMsg = "获取相关性图表, 图表计算值失败, Err:" + e.Error()
  289. return
  290. }
  291. tmpChartInfo.ChartName += fmt.Sprint(`(`, correlationConf.CalculateValue, correlationConf.CalculateUnit, `)`)
  292. tmpChartInfo.Source = utils.CHART_SOURCE_CORRELATION
  293. resp.CorrelationData = response.CorrelationResp{
  294. ChartInfo: tmpChartInfo,
  295. EdbInfoList: mappingList,
  296. XEdbIdValue: xEdbIdValue,
  297. YDataList: yDataList,
  298. CorrelationChartInfo: data_manage.CorrelationInfo{
  299. LeadValue: correlationConf.LeadValue,
  300. LeadUnit: correlationConf.LeadUnit,
  301. StartDate: startDate,
  302. EndDate: endDate,
  303. EdbInfoIdFirst: edbInfoMappingA.EdbInfoId,
  304. EdbInfoIdSecond: edbInfoMappingB.EdbInfoId,
  305. },
  306. }
  307. }
  308. }
  309. // 滚动相关性图表信息
  310. {
  311. correlationConf := req.Correlation
  312. rollingCorrelationConfList := req.RollingCorrelation
  313. // 配置了数据才有返回
  314. if correlationConf.LeadValue > 0 {
  315. //moveUnitDays, ok := utils.FrequencyDaysMap[correlationConf.CalculateUnit]
  316. //if !ok {
  317. // br.Msg = "错误的分析周期"
  318. // br.IsSendEmail = false
  319. // return
  320. //}
  321. //startDate := time.Now().AddDate(0, 0, -correlationConf.CalculateValue*moveUnitDays).Format(utils.FormatDate)
  322. //endDate := time.Now().Format(utils.FormatDate)
  323. // 数据的开始/结束日期
  324. curveConf := req.Curve
  325. startDate, endDate := utils.GetDateByDateTypeV2(curveConf.DateType, curveConf.StartDate, curveConf.EndDate, curveConf.StartYear, maxYear)
  326. rollingCorrelationData := make([]interface{}, 0)
  327. for _, rollingCorrelationConf := range rollingCorrelationConfList {
  328. if rollingCorrelationConf.CalculateValue > 0 && rollingCorrelationConf.CalculateUnit != `` {
  329. tmpChartInfo := *chartInfo
  330. tmpChartInfo.Source = utils.CHART_SOURCE_ROLLING_CORRELATION
  331. // ”指标A名称“+”指标B名称“+"滚动相关性"+”滚动相关性计算窗口值“+”滚动相关性计算窗口单位“
  332. // 若滚动相关性的计算周期为30天
  333. // 1、B即不领先也不滞后时:“指标A名称”与“指标B名称"30天滚动相关性;
  334. // 2、B有领先时:“指标A名称”与“指标B名称(领先15天)"30天滚动相关性;
  335. // 3、B滞后时:“指标A名称”与“指标B名称(滞后15天)"30天滚动相关性
  336. if rollingCorrelationConf.LeadValue == 0 {
  337. tmpChartInfo.ChartName = fmt.Sprintf(`%s与%s%d%s滚动相关性`, edbInfoMappingA.EdbName, edbInfoMappingB.EdbName, rollingCorrelationConf.CalculateValue, rollingCorrelationConf.CalculateUnit)
  338. } else if rollingCorrelationConf.LeadValue < 0 {
  339. tmpChartInfo.ChartName = fmt.Sprintf(`%s与%s(滞后%d%s)%d%s滚动相关性`, edbInfoMappingA.EdbName, edbInfoMappingB.EdbName, int(math.Abs(float64(rollingCorrelationConf.LeadValue))), rollingCorrelationConf.LeadUnit, rollingCorrelationConf.CalculateValue, rollingCorrelationConf.CalculateUnit)
  340. } else {
  341. tmpChartInfo.ChartName = fmt.Sprintf(`%s与%s(领先%d%s)%d%s滚动相关性`, edbInfoMappingA.EdbName, edbInfoMappingB.EdbName, int(math.Abs(float64(rollingCorrelationConf.LeadValue))), rollingCorrelationConf.LeadUnit, rollingCorrelationConf.CalculateValue, rollingCorrelationConf.CalculateUnit)
  342. }
  343. dataResp, e := correlationServ.GetRollingCorrelationChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB, rollingCorrelationConf.LeadValue, rollingCorrelationConf.LeadUnit, rollingCorrelationConf.CalculateValue, rollingCorrelationConf.CalculateUnit, startDate, endDate, tmpChartInfo.ChartName, tmpChartInfo.ChartNameEn)
  344. if e != nil {
  345. br.Msg = "获取失败"
  346. br.ErrMsg = "获取滚动相关性图表, 图表计算值失败, Err:" + e.Error()
  347. return
  348. }
  349. rollingCorrelationData = append(rollingCorrelationData, response.RollingCorrelationResp{
  350. ChartInfo: tmpChartInfo,
  351. EdbInfoList: mappingList,
  352. DataResp: dataResp,
  353. CorrelationChartInfo: data_manage.CorrelationInfo{
  354. LeadValue: rollingCorrelationConf.LeadValue,
  355. LeadUnit: rollingCorrelationConf.LeadUnit,
  356. CalculateValue: rollingCorrelationConf.CalculateValue,
  357. CalculateUnit: rollingCorrelationConf.CalculateUnit,
  358. StartDate: startDate,
  359. EndDate: endDate,
  360. EdbInfoIdFirst: edbInfoMappingA.EdbInfoId,
  361. EdbInfoIdSecond: edbInfoMappingB.EdbInfoId,
  362. },
  363. })
  364. } else {
  365. rollingCorrelationData = append(rollingCorrelationData, nil)
  366. }
  367. }
  368. resp.RollingCorrelationData = rollingCorrelationData
  369. } else {
  370. resp.RollingCorrelationData = []interface{}{nil, nil}
  371. }
  372. }
  373. br.Ret = 200
  374. br.Success = true
  375. br.Msg = "获取成功"
  376. br.Data = resp
  377. }
  378. // MultipleGraphPreviewCurve
  379. // @Title 批量添加图表的预览曲线图接口(只返回曲线图的数据)
  380. // @Description 批量添加图表的预览曲线图接口
  381. // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
  382. // @Success Ret=200 返回图表id
  383. // @router /multiple_graph/preview_cure [post]
  384. func (this *ChartInfoController) MultipleGraphPreviewCurve() {
  385. br := new(models.BaseResponse).Init()
  386. defer func() {
  387. this.Data["json"] = br
  388. this.ServeJSON()
  389. }()
  390. sysUser := this.SysUser
  391. if sysUser == nil {
  392. br.Msg = "请登录"
  393. br.ErrMsg = "请登录,SysUser Is Empty"
  394. br.Ret = 408
  395. return
  396. }
  397. var req request.SaveMultipleGraphConfigReq
  398. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  399. if err != nil {
  400. br.Msg = "参数解析异常!"
  401. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  402. return
  403. }
  404. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
  405. if err != nil {
  406. br.Msg = "获取失败"
  407. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  408. return
  409. }
  410. var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
  411. for _, v := range mappingList {
  412. if v.EdbInfoId == req.EdbInfoIdA {
  413. edbInfoMappingA = v
  414. }
  415. if v.EdbInfoId == req.EdbInfoIdB {
  416. edbInfoMappingB = v
  417. }
  418. }
  419. if edbInfoMappingA == nil {
  420. br.Msg = "指标A不存在"
  421. br.IsSendEmail = false
  422. return
  423. }
  424. if edbInfoMappingB == nil {
  425. br.Msg = "指标B不存在"
  426. br.IsSendEmail = false
  427. return
  428. }
  429. resp := response.PreviewMultipleGraphConfigResp{}
  430. chartInfo := new(data_manage.ChartInfoView)
  431. chartInfo.Calendar = `公历`
  432. chartInfo.ChartName = edbInfoMappingA.EdbName + "与" + edbInfoMappingB.EdbName
  433. // 曲线图表信息
  434. {
  435. tmpChartInfo := *chartInfo
  436. curveConf := req.Curve
  437. startDate := curveConf.StartDate
  438. endDate := curveConf.EndDate
  439. switch curveConf.DateType {
  440. case 1:
  441. startDate = "2000-01-01"
  442. case 2:
  443. startDate = "2010-01-01"
  444. case 3:
  445. startDate = "2015-01-01"
  446. case 4:
  447. //startDate = strconv.Itoa(time.Now().Year()) + "-01-01"
  448. startDate = "2021-01-01"
  449. case 5:
  450. startDate = startDate + "-01"
  451. endDate = endDate + "-01"
  452. case 6:
  453. startDate = startDate + "-01"
  454. case 7:
  455. startDate = "2018-01-01"
  456. case 8:
  457. startDate = "2019-01-01"
  458. case 9:
  459. startDate = "2020-01-01"
  460. case 11:
  461. startDate = "2022-01-01"
  462. }
  463. edbInfoType := 0
  464. if curveConf.EdbInfoType {
  465. edbInfoType = 1
  466. }
  467. for _, v := range mappingList {
  468. v.EdbInfoType = 1
  469. v.IsOrder = false
  470. if v.EdbInfoId == req.EdbInfoIdB {
  471. v.LeadValue = curveConf.LeadValue
  472. v.LeadUnit = curveConf.LeadUnit
  473. v.EdbInfoType = edbInfoType
  474. v.IsOrder = curveConf.IsOrder
  475. }
  476. }
  477. // 获取图表中的指标数据
  478. edbList, _, _, _, err, errMsg := data.GetChartEdbData(tmpChartInfo.ChartInfoId, tmpChartInfo.ChartType, tmpChartInfo.Calendar, startDate, endDate, mappingList, tmpChartInfo.ExtraConfig, tmpChartInfo.SeasonExtraConfig)
  479. if err != nil {
  480. br.Msg = "获取失败"
  481. if errMsg != `` {
  482. br.Msg = errMsg
  483. }
  484. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  485. return
  486. }
  487. warnEdbList := make([]string, 0)
  488. tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
  489. for _, v := range edbList {
  490. if v.IsNullData {
  491. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  492. }
  493. chartEdbInfoMapping := *v
  494. chartEdbInfoMapping.IsOrder = false
  495. chartEdbInfoMapping.EdbInfoType = 1
  496. if v.EdbInfoId == req.EdbInfoIdA {
  497. chartEdbInfoMapping.IsAxis = 1
  498. chartEdbInfoMapping.MinData = curveConf.LeftMin
  499. chartEdbInfoMapping.MaxData = curveConf.LeftMax
  500. chartEdbInfoMapping.ChartColor = `#00F`
  501. //chartEdbInfoMapping.LeadValue = curveConf.LeadValue
  502. //chartEdbInfoMapping.LeadUnit = curveConf.LeadUnit
  503. chartEdbInfoMapping.ChartWidth = 3
  504. } else {
  505. chartEdbInfoMapping.IsAxis = 0
  506. chartEdbInfoMapping.MinData = curveConf.RightMin
  507. chartEdbInfoMapping.MaxData = curveConf.RightMax
  508. chartEdbInfoMapping.ChartColor = `#F00`
  509. chartEdbInfoMapping.LeadValue = curveConf.LeadValue
  510. chartEdbInfoMapping.LeadUnit = curveConf.LeadUnit
  511. chartEdbInfoMapping.ChartWidth = 1
  512. chartEdbInfoMapping.IsOrder = curveConf.IsOrder
  513. chartEdbInfoMapping.EdbInfoType = edbInfoType
  514. }
  515. tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
  516. }
  517. if len(warnEdbList) > 0 {
  518. tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  519. }
  520. tmpChartInfo.Source = utils.CHART_SOURCE_DEFAULT
  521. tmpChartInfo.DateType = curveConf.DateType
  522. tmpChartInfo.StartDate = startDate
  523. tmpChartInfo.EndDate = endDate
  524. tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
  525. resp.CurveData = response.CurveResp{
  526. ChartInfo: tmpChartInfo,
  527. EdbInfoList: tmpEdbList,
  528. }
  529. }
  530. br.Ret = 200
  531. br.Success = true
  532. br.Msg = "获取成功"
  533. br.Data = resp
  534. }
  535. // MultipleGraphConfigSaveChart
  536. // @Title 保存图表接口
  537. // @Description 保存图表接口
  538. // @Param request body request.SaveMultipleGraphChartReq true "type json string"
  539. // @Success Ret=200 返回图表id
  540. // @router /multiple_graph/chart/save [post]
  541. func (this *ChartInfoController) MultipleGraphConfigSaveChart() {
  542. br := new(models.BaseResponse).Init()
  543. defer func() {
  544. this.Data["json"] = br
  545. this.ServeJSON()
  546. }()
  547. sysUser := this.SysUser
  548. if sysUser == nil {
  549. br.Msg = "请登录"
  550. br.ErrMsg = "请登录,SysUser Is Empty"
  551. br.Ret = 408
  552. return
  553. }
  554. var req request.SaveMultipleGraphChartReq
  555. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  556. if err != nil {
  557. br.Msg = "参数解析异常!"
  558. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  559. return
  560. }
  561. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  562. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  563. br.Msg = "系统处理中,请稍后重试!"
  564. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  565. return
  566. }
  567. defer func() {
  568. _ = utils.Rc.Delete(cacheKey)
  569. }()
  570. if req.IsSaveAs {
  571. CopyMultipleGraphConfigSaveChart(req, this, br, sysUser)
  572. return
  573. }
  574. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
  575. if err != nil {
  576. br.Msg = "获取失败"
  577. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  578. return
  579. }
  580. var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
  581. for _, v := range mappingList {
  582. if v.EdbInfoId == req.EdbInfoIdA {
  583. edbInfoMappingA = v
  584. }
  585. if v.EdbInfoId == req.EdbInfoIdB {
  586. edbInfoMappingB = v
  587. }
  588. }
  589. if edbInfoMappingA == nil {
  590. br.Msg = "指标A不存在"
  591. br.IsSendEmail = false
  592. return
  593. }
  594. if edbInfoMappingB == nil {
  595. br.Msg = "指标B不存在"
  596. br.IsSendEmail = false
  597. return
  598. }
  599. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
  600. if err != nil && err.Error() != utils.ErrNoRow() {
  601. br.Msg = `保存失败`
  602. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  603. return
  604. }
  605. err = nil
  606. var isAdd bool
  607. var chartInfoId int
  608. if multipleGraphConfigChartMapping == nil {
  609. isAdd = true
  610. } else {
  611. chartInfo, err := data_manage.GetChartInfoById(multipleGraphConfigChartMapping.ChartInfoId)
  612. if err != nil && err.Error() != utils.ErrNoRow() {
  613. br.Msg = `保存失败`
  614. br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
  615. return
  616. }
  617. // 说明图还在,没有被删除
  618. if chartInfo != nil {
  619. chartInfoId = multipleGraphConfigChartMapping.ChartInfoId
  620. req.ChartName = chartInfo.ChartName
  621. req.ClassifyId = chartInfo.ChartClassifyId
  622. }
  623. }
  624. var chartInfo *data_manage.ChartInfo
  625. var errMsg string
  626. isSendEmail := true
  627. switch req.Source {
  628. case 1: // 曲线图
  629. curveConf := req.Curve
  630. edbInfoType := 1 //1:标准指标,0:领先指标
  631. if !curveConf.EdbInfoType {
  632. edbInfoType = 0
  633. }
  634. chartSaveItemList := []*data_manage.ChartSaveItem{
  635. {
  636. EdbInfoId: edbInfoMappingA.EdbInfoId,
  637. MaxData: curveConf.LeftMax,
  638. MinData: curveConf.LeftMin,
  639. IsOrder: false,
  640. IsAxis: 1,
  641. EdbInfoType: 1,
  642. //LeadValue: curveConf.LeadValue,
  643. //LeadUnit: curveConf.LeadUnit,
  644. ChartStyle: "spline",
  645. ChartColor: `#00F`,
  646. PredictChartColor: "",
  647. ChartWidth: 3,
  648. Source: utils.CHART_SOURCE_DEFAULT,
  649. }, {
  650. EdbInfoId: edbInfoMappingB.EdbInfoId,
  651. MaxData: curveConf.RightMax,
  652. MinData: curveConf.RightMin,
  653. IsOrder: curveConf.IsOrder,
  654. IsAxis: 0,
  655. EdbInfoType: edbInfoType,
  656. LeadValue: curveConf.LeadValue,
  657. LeadUnit: curveConf.LeadUnit,
  658. ChartStyle: "spline",
  659. ChartColor: `#F00`,
  660. PredictChartColor: "",
  661. ChartWidth: 1,
  662. Source: utils.CHART_SOURCE_DEFAULT,
  663. },
  664. }
  665. if chartInfoId <= 0 {
  666. addChartReq := data_manage.AddChartInfoReq{
  667. ChartEdbInfoList: chartSaveItemList,
  668. ChartClassifyId: req.ClassifyId,
  669. ChartName: req.ChartName,
  670. ChartType: utils.CHART_TYPE_CURVE,
  671. DateType: curveConf.DateType,
  672. StartDate: curveConf.StartDate,
  673. EndDate: curveConf.EndDate,
  674. StartYear: curveConf.StartYear,
  675. Calendar: "公历",
  676. LeftMin: fmt.Sprint(curveConf.LeftMin),
  677. LeftMax: fmt.Sprint(curveConf.LeftMax),
  678. RightMin: fmt.Sprint(curveConf.RightMin),
  679. RightMax: fmt.Sprint(curveConf.RightMax),
  680. }
  681. chartInfo, err, errMsg, isSendEmail = data.AddChartInfo(addChartReq, sysUser.AdminId, sysUser.RealName)
  682. } else {
  683. editChartReq := data_manage.EditChartInfoReq{
  684. ChartInfoId: multipleGraphConfigChartMapping.ChartInfoId,
  685. ChartName: req.ChartName,
  686. ChartClassifyId: req.ClassifyId,
  687. ChartEdbInfoList: chartSaveItemList,
  688. ChartType: utils.CHART_TYPE_CURVE,
  689. DateType: curveConf.DateType,
  690. StartDate: curveConf.StartDate,
  691. EndDate: curveConf.EndDate,
  692. StartYear: curveConf.StartYear,
  693. Calendar: "公历",
  694. LeftMin: fmt.Sprint(curveConf.LeftMin),
  695. LeftMax: fmt.Sprint(curveConf.LeftMax),
  696. RightMin: fmt.Sprint(curveConf.RightMin),
  697. RightMax: fmt.Sprint(curveConf.RightMax),
  698. }
  699. chartInfo, err, errMsg, isSendEmail = data.EditChartInfo(editChartReq, sysUser)
  700. if err != nil {
  701. br.Msg = "保存失败"
  702. if errMsg != `` {
  703. br.Msg = errMsg
  704. }
  705. br.ErrMsg = err.Error()
  706. br.IsSendEmail = isSendEmail
  707. return
  708. }
  709. }
  710. case 2, 3, 4: // 相关性图(滚动相关性)
  711. correlationConf := req.Correlation
  712. // 配置了数据才有返回
  713. if correlationConf.LeadValue > 0 {
  714. leadValue := correlationConf.LeadValue
  715. leadUnit := correlationConf.LeadUnit
  716. baseCalculateValue := correlationConf.CalculateValue
  717. baseCalculateUnit := correlationConf.CalculateUnit
  718. calculateValue := baseCalculateValue
  719. calculateUnit := baseCalculateUnit
  720. chartSource := utils.CHART_SOURCE_CORRELATION // 默认是相关性图
  721. moveUnitDays, ok := utils.FrequencyDaysMap[calculateUnit]
  722. if !ok {
  723. br.Msg = "错误的分析周期"
  724. br.IsSendEmail = false
  725. return
  726. }
  727. startDate := time.Now().AddDate(0, 0, -correlationConf.CalculateValue*moveUnitDays).Format(utils.FormatDate)
  728. endDate := time.Now().Format(utils.FormatDate)
  729. // 日期类型
  730. var dateType int
  731. if req.Source != 2 {
  732. chartSource = utils.CHART_SOURCE_ROLLING_CORRELATION
  733. var rollingCorrelation data_manage.RollingCorrelationConfig
  734. if req.Source == 3 {
  735. rollingCorrelation = req.RollingCorrelation[0]
  736. } else {
  737. rollingCorrelation = req.RollingCorrelation[1]
  738. }
  739. leadValue = rollingCorrelation.LeadValue
  740. leadUnit = rollingCorrelation.LeadUnit
  741. calculateValue = rollingCorrelation.CalculateValue
  742. calculateUnit = rollingCorrelation.CalculateUnit
  743. // 开始日期,结束日期
  744. dateType = req.Curve.DateType
  745. startDate, endDate = utils.GetDateByDateType(req.Curve.DateType, req.Curve.StartDate, req.Curve.EndDate)
  746. }
  747. correlationChartInfoReq := data_manage.CorrelationChartInfoReq{
  748. LeadValue: leadValue,
  749. LeadUnit: leadUnit,
  750. CalculateValue: calculateValue,
  751. CalculateUnit: calculateUnit,
  752. BaseCalculateValue: baseCalculateValue,
  753. BaseCalculateUnit: baseCalculateUnit,
  754. DateType: dateType,
  755. StartDate: startDate,
  756. EndDate: endDate,
  757. EdbInfoIdList: []data_manage.CorrelationChartInfoEdbItemReq{
  758. {
  759. EdbInfoId: edbInfoMappingA.EdbInfoId,
  760. Name: "",
  761. NameEn: "",
  762. }, {
  763. EdbInfoId: edbInfoMappingB.EdbInfoId,
  764. Name: "",
  765. NameEn: "",
  766. },
  767. },
  768. }
  769. if chartInfoId <= 0 {
  770. addChartReq := data_manage.AddChartInfoReq{
  771. ChartClassifyId: req.ClassifyId,
  772. ChartName: req.ChartName,
  773. ChartType: utils.CHART_TYPE_CURVE,
  774. Calendar: "公历",
  775. CorrelationChartInfo: correlationChartInfoReq,
  776. }
  777. chartInfo, err, errMsg, isSendEmail = correlationServ.AddChartInfo(addChartReq, chartSource, sysUser)
  778. } else {
  779. editChartReq := data_manage.EditChartInfoReq{
  780. ChartInfoId: multipleGraphConfigChartMapping.ChartInfoId,
  781. ChartName: req.ChartName,
  782. ChartClassifyId: req.ClassifyId,
  783. ChartType: utils.CHART_TYPE_CURVE,
  784. Calendar: "公历",
  785. CorrelationChartInfo: correlationChartInfoReq,
  786. }
  787. chartInfo, err, errMsg, isSendEmail = correlationServ.EditChartInfo(editChartReq, sysUser)
  788. if err != nil {
  789. br.Msg = "保存失败"
  790. if errMsg != `` {
  791. br.Msg = errMsg
  792. }
  793. br.ErrMsg = err.Error()
  794. br.IsSendEmail = isSendEmail
  795. return
  796. }
  797. }
  798. }
  799. default:
  800. br.Msg = "错误的来源"
  801. br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
  802. br.IsSendEmail = false
  803. return
  804. }
  805. if err != nil {
  806. br.Msg = "保存失败"
  807. if errMsg != `` {
  808. br.Msg = errMsg
  809. }
  810. br.ErrMsg = err.Error()
  811. br.IsSendEmail = isSendEmail
  812. return
  813. }
  814. // 如果图没有建立关联关系,那么就需要添加关系
  815. if isAdd {
  816. multipleGraphConfigChartMapping = &data_manage.MultipleGraphConfigChartMapping{
  817. //Id: 0,
  818. MultipleGraphConfigId: req.MultipleGraphConfigId,
  819. ChartInfoId: chartInfo.ChartInfoId,
  820. Source: req.Source,
  821. ModifyTime: time.Now(),
  822. CreateTime: time.Now(),
  823. }
  824. err = data_manage.AddMultipleGraphConfigChartMapping(multipleGraphConfigChartMapping)
  825. if err != nil {
  826. br.Msg = "保存失败"
  827. br.ErrMsg = "保存配置与图表的关联关系失败,ERR:" + err.Error()
  828. return
  829. }
  830. } else if multipleGraphConfigChartMapping != nil {
  831. multipleGraphConfigChartMapping.ChartInfoId = chartInfo.ChartInfoId
  832. multipleGraphConfigChartMapping.ModifyTime = time.Now()
  833. err = multipleGraphConfigChartMapping.Update([]string{"ChartInfoId", "ModifyTime"})
  834. if err != nil {
  835. br.Msg = "保存失败"
  836. br.ErrMsg = "保存配置与图表的关联关系失败,ERR:" + err.Error()
  837. return
  838. }
  839. }
  840. //新增操作日志
  841. {
  842. chartLog := new(data_manage.ChartInfoLog)
  843. chartLog.ChartInfoId = chartInfo.ChartInfoId
  844. chartLog.ChartName = req.ChartName
  845. chartLog.ChartClassifyId = req.ClassifyId
  846. chartLog.SysUserId = sysUser.AdminId
  847. chartLog.SysUserRealName = sysUser.RealName
  848. chartLog.UniqueCode = chartInfo.UniqueCode
  849. chartLog.CreateTime = time.Now()
  850. chartLog.Content = string(this.Ctx.Input.RequestBody)
  851. chartLog.Status = "多图配置保存图表"
  852. chartLog.Method = this.Ctx.Input.URI()
  853. go data_manage.AddChartInfoLog(chartLog)
  854. }
  855. resp := new(data_manage.AddChartInfoResp)
  856. resp.ChartInfoId = chartInfo.ChartInfoId
  857. resp.UniqueCode = chartInfo.UniqueCode
  858. resp.ChartType = chartInfo.ChartType
  859. br.Ret = 200
  860. br.Success = true
  861. br.Msg = "保存成功"
  862. br.Data = resp
  863. br.IsAddLog = true
  864. }
  865. // CopyMultipleGraphConfigSaveChart 图表另存为
  866. func CopyMultipleGraphConfigSaveChart(req request.SaveMultipleGraphChartReq, this *ChartInfoController, br *models.BaseResponse, sysUser *system.Admin) {
  867. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
  868. if err != nil {
  869. br.Msg = "获取失败"
  870. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  871. return
  872. }
  873. var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
  874. for _, v := range mappingList {
  875. if v.EdbInfoId == req.EdbInfoIdA {
  876. edbInfoMappingA = v
  877. }
  878. if v.EdbInfoId == req.EdbInfoIdB {
  879. edbInfoMappingB = v
  880. }
  881. }
  882. if edbInfoMappingA == nil {
  883. br.Msg = "指标A不存在"
  884. br.IsSendEmail = false
  885. return
  886. }
  887. if edbInfoMappingB == nil {
  888. br.Msg = "指标B不存在"
  889. br.IsSendEmail = false
  890. return
  891. }
  892. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
  893. if err != nil && err.Error() != utils.ErrNoRow() {
  894. br.Msg = `保存失败`
  895. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  896. return
  897. }
  898. // 原图
  899. oldChartInfo, err := data_manage.GetChartInfoById(multipleGraphConfigChartMapping.ChartInfoId)
  900. if err != nil && err.Error() != utils.ErrNoRow() {
  901. br.Msg = `保存失败`
  902. br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
  903. return
  904. }
  905. // 说明图还在,没有被删除
  906. if oldChartInfo == nil {
  907. br.Msg = "原图不存在"
  908. br.IsSendEmail = false
  909. }
  910. var chartInfo *data_manage.ChartInfo
  911. var errMsg string
  912. isSendEmail := true
  913. switch req.Source {
  914. case 1: // 曲线图
  915. curveConf := req.Curve
  916. edbInfoType := 1 //1:标准指标,0:领先指标
  917. if !curveConf.EdbInfoType {
  918. edbInfoType = 0
  919. }
  920. chartSaveItemList := []*data_manage.ChartSaveItem{
  921. {
  922. EdbInfoId: edbInfoMappingA.EdbInfoId,
  923. MaxData: curveConf.LeftMax,
  924. MinData: curveConf.LeftMin,
  925. IsOrder: false,
  926. IsAxis: 1,
  927. EdbInfoType: 1,
  928. //LeadValue: curveConf.LeadValue,
  929. //LeadUnit: curveConf.LeadUnit,
  930. ChartStyle: "spline",
  931. ChartColor: `#00F`,
  932. PredictChartColor: "",
  933. ChartWidth: 3,
  934. Source: utils.CHART_SOURCE_DEFAULT,
  935. }, {
  936. EdbInfoId: edbInfoMappingB.EdbInfoId,
  937. MaxData: curveConf.RightMax,
  938. MinData: curveConf.RightMin,
  939. IsOrder: curveConf.IsOrder,
  940. IsAxis: 0,
  941. EdbInfoType: edbInfoType,
  942. LeadValue: curveConf.LeadValue,
  943. LeadUnit: curveConf.LeadUnit,
  944. ChartStyle: "spline",
  945. ChartColor: `#F00`,
  946. PredictChartColor: "",
  947. ChartWidth: 1,
  948. Source: utils.CHART_SOURCE_DEFAULT,
  949. },
  950. }
  951. addChartReq := data_manage.AddChartInfoReq{
  952. ChartEdbInfoList: chartSaveItemList,
  953. ChartClassifyId: req.ClassifyId,
  954. ChartName: req.ChartName,
  955. ChartType: utils.CHART_TYPE_CURVE,
  956. DateType: curveConf.DateType,
  957. StartDate: curveConf.StartDate,
  958. EndDate: curveConf.EndDate,
  959. StartYear: curveConf.StartYear,
  960. Calendar: "公历",
  961. LeftMin: fmt.Sprint(curveConf.LeftMin),
  962. LeftMax: fmt.Sprint(curveConf.LeftMax),
  963. RightMin: fmt.Sprint(curveConf.RightMin),
  964. RightMax: fmt.Sprint(curveConf.RightMax),
  965. }
  966. chartInfo, err, errMsg, isSendEmail = data.AddChartInfo(addChartReq, sysUser.AdminId, sysUser.RealName)
  967. case 2: // 相关性图
  968. correlationConf := req.Correlation
  969. // 配置了数据才有返回
  970. if correlationConf.LeadValue > 0 {
  971. leadValue := correlationConf.LeadValue
  972. leadUnit := correlationConf.LeadUnit
  973. calculateValue := correlationConf.CalculateValue
  974. calculateUnit := correlationConf.CalculateUnit
  975. moveUnitDays, ok := utils.FrequencyDaysMap[calculateUnit]
  976. if !ok {
  977. br.Msg = "错误的分析周期"
  978. br.IsSendEmail = false
  979. return
  980. }
  981. startDate := time.Now().AddDate(0, 0, -correlationConf.CalculateValue*moveUnitDays).Format(utils.FormatDate)
  982. endDate := time.Now().Format(utils.FormatDate)
  983. correlationChartInfoReq := data_manage.CorrelationChartInfoReq{
  984. LeadValue: leadValue,
  985. LeadUnit: leadUnit,
  986. CalculateValue: calculateValue,
  987. CalculateUnit: calculateUnit,
  988. StartDate: startDate,
  989. EndDate: endDate,
  990. EdbInfoIdList: []data_manage.CorrelationChartInfoEdbItemReq{
  991. {
  992. EdbInfoId: edbInfoMappingA.EdbInfoId,
  993. Name: "",
  994. NameEn: "",
  995. }, {
  996. EdbInfoId: edbInfoMappingB.EdbInfoId,
  997. Name: "",
  998. NameEn: "",
  999. },
  1000. },
  1001. }
  1002. chartInfo, err, errMsg, isSendEmail = correlationServ.CopyChartInfo(multipleGraphConfigChartMapping.MultipleGraphConfigId, req.ClassifyId, req.ChartName, correlationChartInfoReq, sysUser)
  1003. }
  1004. default:
  1005. br.Msg = "错误的来源"
  1006. br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
  1007. br.IsSendEmail = false
  1008. return
  1009. }
  1010. if err != nil {
  1011. br.Msg = "保存失败"
  1012. if errMsg != `` {
  1013. br.Msg = errMsg
  1014. }
  1015. br.ErrMsg = err.Error()
  1016. br.IsSendEmail = isSendEmail
  1017. return
  1018. }
  1019. //新增操作日志
  1020. {
  1021. chartLog := new(data_manage.ChartInfoLog)
  1022. chartLog.ChartInfoId = chartInfo.ChartInfoId
  1023. chartLog.ChartName = req.ChartName
  1024. chartLog.ChartClassifyId = req.ClassifyId
  1025. chartLog.SysUserId = sysUser.AdminId
  1026. chartLog.SysUserRealName = sysUser.RealName
  1027. chartLog.UniqueCode = chartInfo.UniqueCode
  1028. chartLog.CreateTime = time.Now()
  1029. chartLog.Content = string(this.Ctx.Input.RequestBody)
  1030. chartLog.Status = "多图配置另存为图表"
  1031. chartLog.Method = this.Ctx.Input.URI()
  1032. go data_manage.AddChartInfoLog(chartLog)
  1033. }
  1034. resp := new(data_manage.AddChartInfoResp)
  1035. resp.ChartInfoId = chartInfo.ChartInfoId
  1036. resp.UniqueCode = chartInfo.UniqueCode
  1037. resp.ChartType = chartInfo.ChartType
  1038. br.Ret = 200
  1039. br.Success = true
  1040. br.Msg = "保存成功"
  1041. br.Data = resp
  1042. br.IsAddLog = true
  1043. }
  1044. // MultipleGraphConfigSaveEdb
  1045. // @Title 保存指标接口
  1046. // @Description 保存指标接口
  1047. // @Param request body request.SaveMultipleGraphEdbReq true "type json string"
  1048. // @Success Ret=200 返回指标id
  1049. // @router /multiple_graph/edb/save [post]
  1050. func (this *ChartInfoController) MultipleGraphConfigSaveEdb() {
  1051. br := new(models.BaseResponse).Init()
  1052. defer func() {
  1053. this.Data["json"] = br
  1054. this.ServeJSON()
  1055. }()
  1056. sysUser := this.SysUser
  1057. if sysUser == nil {
  1058. br.Msg = "请登录"
  1059. br.ErrMsg = "请登录,SysUser Is Empty"
  1060. br.Ret = 408
  1061. return
  1062. }
  1063. var req request.SaveMultipleGraphEdbReq
  1064. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1065. if err != nil {
  1066. br.Msg = "参数解析异常!"
  1067. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1068. return
  1069. }
  1070. cacheKey := "CACHE_CHART_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  1071. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1072. br.Msg = "系统处理中,请稍后重试!"
  1073. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1074. return
  1075. }
  1076. defer func() {
  1077. _ = utils.Rc.Delete(cacheKey)
  1078. }()
  1079. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
  1080. if err != nil {
  1081. br.Msg = "获取失败"
  1082. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1083. return
  1084. }
  1085. var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
  1086. for _, v := range mappingList {
  1087. if v.EdbInfoId == req.EdbInfoIdA {
  1088. edbInfoMappingA = v
  1089. }
  1090. if v.EdbInfoId == req.EdbInfoIdB {
  1091. edbInfoMappingB = v
  1092. }
  1093. }
  1094. if edbInfoMappingA == nil {
  1095. br.Msg = "指标A不存在"
  1096. br.IsSendEmail = false
  1097. return
  1098. }
  1099. if edbInfoMappingB == nil {
  1100. br.Msg = "指标B不存在"
  1101. br.IsSendEmail = false
  1102. return
  1103. }
  1104. correlationConf := req.Correlation
  1105. // 配置了数据才有返回
  1106. if correlationConf.LeadValue <= 0 {
  1107. br.Msg = "相关性计算窗口必须大于0"
  1108. br.IsSendEmail = false
  1109. return
  1110. }
  1111. // 滚动相关性配置
  1112. var rollingCorrelation data_manage.RollingCorrelationConfig
  1113. switch req.Source {
  1114. case 3:
  1115. rollingCorrelation = req.RollingCorrelation[0]
  1116. case 4:
  1117. rollingCorrelation = req.RollingCorrelation[1]
  1118. default:
  1119. br.Msg = "错误的来源"
  1120. br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
  1121. br.IsSendEmail = false
  1122. return
  1123. }
  1124. // 配置了数据才有返回
  1125. if rollingCorrelation.CalculateValue <= 0 {
  1126. br.Msg = "滚动相关性计算窗口必须大于0"
  1127. br.IsSendEmail = false
  1128. return
  1129. }
  1130. multipleGraphConfigEdbMapping, err := data_manage.GetMultipleGraphConfigEdbMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
  1131. if err != nil && err.Error() != utils.ErrNoRow() {
  1132. br.Msg = `保存失败`
  1133. br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
  1134. return
  1135. }
  1136. err = nil
  1137. var isAdd bool
  1138. var edbInfoId int
  1139. if multipleGraphConfigEdbMapping == nil {
  1140. isAdd = true
  1141. } else {
  1142. edbInfo, err := data_manage.GetEdbInfoById(multipleGraphConfigEdbMapping.EdbInfoId)
  1143. if err != nil && err.Error() != utils.ErrNoRow() {
  1144. br.Msg = `保存失败`
  1145. br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
  1146. return
  1147. }
  1148. // 说明指标还在,没有被删除
  1149. if edbInfo != nil && !req.IsSaveAs {
  1150. edbInfoId = multipleGraphConfigEdbMapping.EdbInfoId
  1151. req.EdbName = edbInfo.EdbName
  1152. req.ClassifyId = edbInfo.ClassifyId
  1153. req.Frequency = edbInfo.Frequency
  1154. req.Unit = edbInfo.Unit
  1155. }
  1156. }
  1157. // 关联指标
  1158. edbInfoIdArr := []data_manage.EdbInfoFromTag{
  1159. {
  1160. EdbInfoId: edbInfoMappingA.EdbInfoId,
  1161. FromTag: "A",
  1162. MoveValue: 0,
  1163. }, {
  1164. EdbInfoId: edbInfoMappingB.EdbInfoId,
  1165. FromTag: "B",
  1166. MoveValue: 0,
  1167. },
  1168. }
  1169. calculateFormula := request.EdbCalculateFormula{
  1170. BaseCalculateValue: correlationConf.CalculateValue,
  1171. BaseCalculateUnit: correlationConf.CalculateUnit,
  1172. LeadValue: rollingCorrelation.LeadValue,
  1173. LeadUnit: rollingCorrelation.LeadUnit,
  1174. CalculateValue: rollingCorrelation.CalculateValue,
  1175. CalculateUnit: rollingCorrelation.CalculateUnit,
  1176. }
  1177. calculateFormulaByte, err := json.Marshal(calculateFormula)
  1178. if err != nil {
  1179. br.Msg = "参数解析异常!"
  1180. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1181. return
  1182. }
  1183. var respItem *data.AddPredictEdbDataResponse
  1184. if edbInfoId <= 0 || req.IsSaveAs {
  1185. req2 := &data_manage.EdbInfoCalculateBatchSaveReqByEdbLib{
  1186. AdminId: sysUser.AdminId,
  1187. AdminName: sysUser.RealName,
  1188. EdbName: req.EdbName,
  1189. Frequency: req.Frequency,
  1190. Unit: req.Unit,
  1191. ClassifyId: req.ClassifyId,
  1192. Formula: string(calculateFormulaByte),
  1193. Source: utils.DATA_SOURCE_CALCULATE_CORRELATION,
  1194. EdbInfoIdArr: edbInfoIdArr,
  1195. Calendar: `公历`,
  1196. }
  1197. // 调用指标库去添加
  1198. reqJson, err := json.Marshal(req2)
  1199. if err != nil {
  1200. br.Msg = "参数解析异常!"
  1201. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1202. return
  1203. }
  1204. respItem, err = data.BatchSaveEdbCalculateData(string(reqJson))
  1205. if err != nil {
  1206. br.Msg = "新增失败"
  1207. br.ErrMsg = "新增失败,Err:" + err.Error()
  1208. return
  1209. }
  1210. } else {
  1211. req2 := &data_manage.EdbInfoCalculateBatchEditReqByEdbLib{
  1212. EdbInfoId: edbInfoId,
  1213. EdbName: req.EdbName,
  1214. Frequency: req.Frequency,
  1215. Unit: req.Unit,
  1216. ClassifyId: req.ClassifyId,
  1217. Formula: string(calculateFormulaByte),
  1218. Source: utils.DATA_SOURCE_CALCULATE_CORRELATION,
  1219. EdbInfoIdArr: edbInfoIdArr,
  1220. Calendar: `公历`,
  1221. }
  1222. // 调用指标库去更新
  1223. reqJson, err := json.Marshal(req2)
  1224. if err != nil {
  1225. br.Msg = "参数解析异常!"
  1226. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1227. return
  1228. }
  1229. respItem, err = data.BatchEditEdbCalculateData(string(reqJson))
  1230. if err != nil {
  1231. br.Msg = "编辑失败"
  1232. br.ErrMsg = "编辑失败,Err:" + err.Error()
  1233. return
  1234. }
  1235. }
  1236. if respItem == nil {
  1237. br.Msg = "保存失败"
  1238. br.ErrMsg = "保存失败"
  1239. return
  1240. }
  1241. if respItem.Ret != 200 {
  1242. br.Msg = respItem.Msg
  1243. br.ErrMsg = respItem.ErrMsg
  1244. return
  1245. }
  1246. resp := respItem.Data
  1247. //添加es
  1248. data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
  1249. // 如果不是另存为的话,那么需要建立配置与指标的关系
  1250. if !req.IsSaveAs {
  1251. // 如果指标没有建立关联关系,那么就需要添加关系
  1252. if isAdd {
  1253. multipleGraphConfigEdbMapping = &data_manage.MultipleGraphConfigEdbMapping{
  1254. //Id: 0,
  1255. MultipleGraphConfigId: req.MultipleGraphConfigId,
  1256. EdbInfoId: resp.EdbInfoId,
  1257. Source: req.Source,
  1258. ModifyTime: time.Now(),
  1259. CreateTime: time.Now(),
  1260. }
  1261. err = data_manage.AddMultipleGraphConfigEdbMapping(multipleGraphConfigEdbMapping)
  1262. if err != nil {
  1263. br.Msg = "保存失败"
  1264. br.ErrMsg = "保存配置与指标的关联关系失败,ERR:" + err.Error()
  1265. return
  1266. }
  1267. } else if multipleGraphConfigEdbMapping != nil {
  1268. multipleGraphConfigEdbMapping.EdbInfoId = resp.EdbInfoId
  1269. multipleGraphConfigEdbMapping.ModifyTime = time.Now()
  1270. err = multipleGraphConfigEdbMapping.Update([]string{"EdbInfoId", "ModifyTime"})
  1271. if err != nil {
  1272. br.Msg = "保存失败"
  1273. br.ErrMsg = "保存配置与指标的关联关系失败,ERR:" + err.Error()
  1274. return
  1275. }
  1276. }
  1277. }
  1278. //新增操作日志
  1279. //{
  1280. // edbLog := new(data_manage.EdbInfoLog)
  1281. // edbLog.EdbInfoId = resp.EdbInfoId
  1282. // edbLog.SourceName = edbInfo.SourceName
  1283. // edbLog.Source = edbInfo.Source
  1284. // edbLog.EdbCode = edbInfo.EdbCode
  1285. // edbLog.EdbName = req2.EdbName
  1286. // edbLog.ClassifyId = req2.ClassifyId
  1287. // edbLog.SysUserId = sysUser.AdminId
  1288. // edbLog.SysUserRealName = sysUser.RealName
  1289. // edbLog.CreateTime = time.Now()
  1290. // edbLog.Content = string(this.Ctx.Input.RequestBody)
  1291. // edbLog.Status = "多图配置保存指标"
  1292. // edbLog.Method = this.Ctx.Input.URI()
  1293. // go data_manage.AddEdbInfoLog(edbLog)
  1294. //}
  1295. br.Ret = 200
  1296. br.Success = true
  1297. br.Msg = "保存成功"
  1298. br.Data = resp
  1299. br.IsAddLog = true
  1300. }
  1301. // GetMultipleGraphConfig
  1302. // @Title 保存配置接口
  1303. // @Description 保存配置接口
  1304. // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  1305. // @Success Ret=200 返回图表id
  1306. // @router /multiple_graph/config/detail [get]
  1307. func (this *ChartInfoController) GetMultipleGraphConfig() {
  1308. br := new(models.BaseResponse).Init()
  1309. defer func() {
  1310. this.Data["json"] = br
  1311. this.ServeJSON()
  1312. }()
  1313. sysUser := this.SysUser
  1314. if sysUser == nil {
  1315. br.Msg = "请登录"
  1316. br.ErrMsg = "请登录,SysUser Is Empty"
  1317. br.Ret = 408
  1318. return
  1319. }
  1320. uniqueCode := this.GetString("UniqueCode")
  1321. if uniqueCode == "" {
  1322. br.Msg = "参数错误"
  1323. br.ErrMsg = "参数错误,uniqueCode is empty"
  1324. return
  1325. }
  1326. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  1327. if err != nil {
  1328. br.Msg = "获取失败"
  1329. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1330. return
  1331. }
  1332. if chartInfo == nil {
  1333. br.Msg = "获取失败"
  1334. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1335. return
  1336. }
  1337. multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByChartId(chartInfo.ChartInfoId)
  1338. if err != nil {
  1339. br.Msg = "获取失败"
  1340. br.ErrMsg = "获取滚动相关性图表的配置信息失败,Err:" + err.Error()
  1341. return
  1342. }
  1343. multipleGraphConfig, err := data_manage.GetMultipleGraphConfigById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
  1344. if err != nil {
  1345. br.Msg = `获取失败`
  1346. br.ErrMsg = `获取配置失败,ERR:` + err.Error()
  1347. return
  1348. }
  1349. // 生成的图表
  1350. multipleGraphConfigChartMappingList := make([]response.MultipleGraphConfigChartMapping, 0)
  1351. {
  1352. chartMappingList, err := data_manage.GetMultipleGraphConfigChartMappingListById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
  1353. if err != nil {
  1354. br.Msg = `获取失败`
  1355. br.ErrMsg = `获取关联图表配置失败,ERR:` + err.Error()
  1356. return
  1357. }
  1358. chartInfoIdList := make([]int, 0)
  1359. chartMappingMap := make(map[int]*data_manage.MultipleGraphConfigChartMapping)
  1360. for _, v := range chartMappingList {
  1361. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  1362. chartMappingMap[v.ChartInfoId] = v
  1363. }
  1364. chartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  1365. if err != nil {
  1366. br.Msg = `获取失败`
  1367. br.ErrMsg = `获取关联图表列表失败,ERR:` + err.Error()
  1368. return
  1369. }
  1370. for _, v := range chartList {
  1371. if tmpInfo, ok := chartMappingMap[v.ChartInfoId]; ok {
  1372. multipleGraphConfigChartMappingList = append(multipleGraphConfigChartMappingList, response.MultipleGraphConfigChartMapping{
  1373. ChartInfoId: tmpInfo.ChartInfoId,
  1374. Source: tmpInfo.Source,
  1375. MultipleLocationSource: tmpInfo.Source,
  1376. })
  1377. }
  1378. }
  1379. }
  1380. // 生成的指标
  1381. multipleGraphConfigEdbMappingList := make([]response.MultipleGraphConfigEdbMapping, 0)
  1382. {
  1383. edbMappingList, err := data_manage.GetMultipleGraphConfigEdbMappingListById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
  1384. if err != nil {
  1385. br.Msg = `获取失败`
  1386. br.ErrMsg = `获取关联指标配置失败,ERR:` + err.Error()
  1387. return
  1388. }
  1389. edbInfoIdList := make([]int, 0)
  1390. edbMappingMap := make(map[int]*data_manage.MultipleGraphConfigEdbMapping)
  1391. for _, v := range edbMappingList {
  1392. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  1393. edbMappingMap[v.EdbInfoId] = v
  1394. }
  1395. edbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1396. if err != nil {
  1397. br.Msg = `获取失败`
  1398. br.ErrMsg = `获取关联图表列表失败,ERR:` + err.Error()
  1399. return
  1400. }
  1401. for _, v := range edbList {
  1402. if tmpInfo, ok := edbMappingMap[v.EdbInfoId]; ok {
  1403. multipleGraphConfigEdbMappingList = append(multipleGraphConfigEdbMappingList, response.MultipleGraphConfigEdbMapping{
  1404. EdbInfoId: tmpInfo.EdbInfoId,
  1405. Source: tmpInfo.Source,
  1406. MultipleLocationSource: tmpInfo.Source,
  1407. })
  1408. }
  1409. }
  1410. }
  1411. // 关联指标
  1412. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{multipleGraphConfig.EdbInfoIdA, multipleGraphConfig.EdbInfoIdB})
  1413. if err != nil {
  1414. br.Msg = "获取失败"
  1415. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1416. return
  1417. }
  1418. resp := response.MultipleGraphConfigDetailResp{
  1419. EdbInfoList: mappingList,
  1420. MultipleGraphConfig: *multipleGraphConfig,
  1421. ChartMappingList: multipleGraphConfigChartMappingList,
  1422. EdbMappingList: multipleGraphConfigEdbMappingList,
  1423. }
  1424. br.Ret = 200
  1425. br.Success = true
  1426. br.Msg = "保存成功"
  1427. br.Data = resp
  1428. br.IsAddLog = true
  1429. }
  1430. // func init() {
  1431. // //correlationChart := new(data_manage.ChartInfoCorrelation)
  1432. //
  1433. // condition := ` AND source = 3 `
  1434. // list, err := data_manage.GetChartListByCondition(condition, []interface{}{}, 0, 1000)
  1435. // if err != nil {
  1436. // fmt.Println("err:", err)
  1437. // return
  1438. // }
  1439. // timeNowFormat := time.Now().Format(utils.FormatDate)
  1440. // for _, v := range list {
  1441. // item, tmpErr := data_manage.GetMultipleGraphConfigChartMappingByChartIdAndSource(v.ChartInfoId)
  1442. // if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  1443. // fmt.Println("tmpErr:", tmpErr)
  1444. // continue
  1445. // }
  1446. // if item == nil {
  1447. // correlationChart := new(data_manage.ChartInfoCorrelation)
  1448. // e := correlationChart.GetItemById(v.ChartInfoId)
  1449. // if e != nil {
  1450. // fmt.Println("获取历史配置失败:", e)
  1451. // continue
  1452. // }
  1453. // day, _ := utils.GetDaysBetween2Date(utils.FormatDate, timeNowFormat, correlationChart.StartDate.Format(utils.FormatDate))
  1454. // req := request.SaveMultipleGraphConfigReq{
  1455. // MultipleGraphConfigId: 0,
  1456. // EdbInfoIdA: correlationChart.EdbInfoIdFirst,
  1457. // EdbInfoIdB: correlationChart.EdbInfoIdSecond,
  1458. // Curve: data_manage.CurveConfig{},
  1459. // Correlation: data_manage.CorrelationConfig{
  1460. // LeadValue: correlationChart.LeadValue,
  1461. // LeadUnit: correlationChart.LeadUnit,
  1462. // CalculateValue: day,
  1463. // CalculateUnit: "天",
  1464. // },
  1465. // RollingCorrelation: []data_manage.RollingCorrelationConfig{
  1466. // {}, {},
  1467. // },
  1468. // }
  1469. // curveStrByte, _ := json.Marshal(req.Curve)
  1470. // correlationStrByte, _ := json.Marshal(req.Correlation)
  1471. // rollingCorrelationStrByte, _ := json.Marshal(req.RollingCorrelation)
  1472. //
  1473. // multipleGraphConfig := &data_manage.MultipleGraphConfig{
  1474. // //MultipleGraphConfigId: 0,
  1475. // EdbInfoIdA: req.EdbInfoIdA,
  1476. // EdbInfoIdB: req.EdbInfoIdB,
  1477. // Curve: string(curveStrByte),
  1478. // Correlation: string(correlationStrByte),
  1479. // RollingCorrelation: string(rollingCorrelationStrByte),
  1480. // SysUserId: v.SysUserId,
  1481. // SysUserRealName: v.SysUserRealName,
  1482. // ModifyTime: v.ModifyTime,
  1483. // CreateTime: v.CreateTime,
  1484. // }
  1485. // err = data_manage.AddMultipleGraphConfig(multipleGraphConfig)
  1486. //
  1487. // if err != nil {
  1488. // fmt.Println(v.ChartInfoId, "创建配置失败:", err)
  1489. // continue
  1490. // }
  1491. //
  1492. // multipleGraphConfigChartMapping := &data_manage.MultipleGraphConfigChartMapping{
  1493. // //Id: 0,
  1494. // MultipleGraphConfigId: multipleGraphConfig.MultipleGraphConfigId,
  1495. // ChartInfoId: v.ChartInfoId,
  1496. // Source: 2,
  1497. // ModifyTime: time.Now(),
  1498. // CreateTime: time.Now(),
  1499. // }
  1500. // err = data_manage.AddMultipleGraphConfigChartMapping(multipleGraphConfigChartMapping)
  1501. // if err != nil {
  1502. // fmt.Println(v.ChartInfoId, "保存配置与图表的关联关系失败:", err)
  1503. // }
  1504. //
  1505. // correlationChart.CalculateUnit = "天"
  1506. // correlationChart.CalculateValue = day
  1507. // err = correlationChart.Update([]string{"CalculateUnit", "CalculateValue"})
  1508. // if err != nil {
  1509. // fmt.Println(v.ChartInfoId, "修复历史数据失败:", err)
  1510. // }
  1511. // }
  1512. // }
  1513. // }
  1514. // 修复相关性图表与滚动相关性图表的强关联关系
  1515. //func init() {
  1516. // condition := ` AND source = ? `
  1517. // pars := []interface{}{utils.CHART_SOURCE_ROLLING_CORRELATION}
  1518. // list, err := data_manage.GetChartListByCondition(condition, pars, 0, 1000)
  1519. // if err != nil {
  1520. // fmt.Println("err:", err)
  1521. // return
  1522. // }
  1523. // for _, chartInfo := range list {
  1524. // multipleGraphConfigChartMapping, e := data_manage.GetMultipleGraphConfigChartMappingByChartId(chartInfo.ChartInfoId)
  1525. // if e != nil {
  1526. // fmt.Println(chartInfo.ChartInfoId, ";获取滚动相关性图表的配置信息失败, Err:"+e.Error())
  1527. // continue
  1528. // }
  1529. // baseChartMultipleGraphConfigChartMapping, e := data_manage.GetMultipleGraphConfigChartMappingByIdAndSource(multipleGraphConfigChartMapping.MultipleGraphConfigId, 2)
  1530. // if e != nil {
  1531. // fmt.Println(chartInfo.ChartInfoId, ";获取相关性图表的配置信息失败, Err:"+e.Error())
  1532. // continue
  1533. // }
  1534. // baseChartCorrelationChart := new(data_manage.ChartInfoCorrelation)
  1535. // if e := baseChartCorrelationChart.GetItemById(baseChartMultipleGraphConfigChartMapping.ChartInfoId); e != nil {
  1536. // fmt.Println(chartInfo.ChartInfoId, ";获取基础相关性图表信息失败, Err:"+e.Error())
  1537. // continue
  1538. // }
  1539. //
  1540. // // 自己的配置
  1541. // selfChartCorrelationChart := new(data_manage.ChartInfoCorrelation)
  1542. // if e := selfChartCorrelationChart.GetItemById(chartInfo.ChartInfoId); e != nil {
  1543. // fmt.Println(chartInfo.ChartInfoId, ";获取自己的相关性图表信息失败, Err:"+e.Error())
  1544. // continue
  1545. // }
  1546. //
  1547. // selfChartCorrelationChart.BaseCalculateUnit = baseChartCorrelationChart.CalculateUnit
  1548. // selfChartCorrelationChart.BaseCalculateValue = baseChartCorrelationChart.CalculateValue
  1549. // err = selfChartCorrelationChart.Update([]string{"BaseCalculateUnit", "BaseCalculateValue"})
  1550. // if err != nil {
  1551. // fmt.Println(chartInfo.ChartInfoId, ";更新相关性图表信息失败, Err:"+err.Error())
  1552. // continue
  1553. // }
  1554. // }
  1555. //
  1556. //}
  1557. // 修复相关性图表与滚动相关性图表的强关联关系
  1558. //func init() {
  1559. // {
  1560. // condition := ` AND source = ? `
  1561. // pars := []interface{}{utils.CHART_SOURCE_ROLLING_CORRELATION}
  1562. // list, err := data_manage.GetChartListByCondition(condition, pars, 0, 1000)
  1563. // if err != nil {
  1564. // fmt.Println("err:", err)
  1565. // return
  1566. // }
  1567. // for _, chartInfo := range list {
  1568. // multipleGraphConfigChartMapping, e := data_manage.GetMultipleGraphConfigChartMappingByChartId(chartInfo.ChartInfoId)
  1569. // if e != nil {
  1570. // fmt.Println(chartInfo.ChartInfoId, ";获取滚动相关性图表的配置信息失败, Err:"+e.Error())
  1571. // continue
  1572. // }
  1573. // multipleGraphConfig, e := data_manage.GetMultipleGraphConfigById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
  1574. // if e != nil {
  1575. // fmt.Println(chartInfo.ChartInfoId, ";获取相关性图表的配置信息失败, Err:"+e.Error())
  1576. // continue
  1577. // }
  1578. // var curveConf data_manage.CurveConfig
  1579. // e = json.Unmarshal([]byte(multipleGraphConfig.Curve), &curveConf)
  1580. // if e != nil {
  1581. // fmt.Println(chartInfo.ChartInfoId, ";格式化曲线图数据失败, Err:"+e.Error())
  1582. // continue
  1583. // }
  1584. //
  1585. // // 自己的配置
  1586. // selfChartCorrelationChart := new(data_manage.ChartInfoCorrelation)
  1587. // if e := selfChartCorrelationChart.GetItemById(chartInfo.ChartInfoId); e != nil {
  1588. // fmt.Println(chartInfo.ChartInfoId, ";获取自己的相关性图表信息失败, Err:"+e.Error())
  1589. // continue
  1590. // }
  1591. //
  1592. // selfChartCorrelationChart.DateType = curveConf.DateType
  1593. //
  1594. // startDate, endDate := utils.GetDateByDateType(curveConf.DateType, curveConf.StartDate, curveConf.EndDate)
  1595. // if startDate != `` {
  1596. // startDateTime, e := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  1597. // if e != nil {
  1598. // fmt.Println(chartInfo.ChartInfoId, ";开始日期格式化失败,开始日期:", startDate, ", Err:"+e.Error())
  1599. // continue
  1600. // }
  1601. // selfChartCorrelationChart.StartDate = startDateTime
  1602. // }
  1603. // if endDate != `` {
  1604. // endDateTime, e := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  1605. // if e != nil {
  1606. // fmt.Println(chartInfo.ChartInfoId, ";开始日期格式化失败,开始日期:", startDate, ", Err:"+e.Error())
  1607. // continue
  1608. // }
  1609. // selfChartCorrelationChart.EndDate = endDateTime
  1610. // }
  1611. // err = selfChartCorrelationChart.Update([]string{"DateType", "StartDate", "EndDate"})
  1612. // if err != nil {
  1613. // fmt.Println(chartInfo.ChartInfoId, ";更新相关性图表信息失败, Err:"+err.Error())
  1614. // continue
  1615. // }
  1616. // }
  1617. //
  1618. // fmt.Println("图表更新完成")
  1619. // }
  1620. //
  1621. // {
  1622. // // 更新指标
  1623. // condition := ` AND source = ? `
  1624. // pars := []interface{}{utils.DATA_SOURCE_CALCULATE_CORRELATION}
  1625. // list, err := data_manage.GetEdbInfoListV2ByCondition(condition, pars, 0, 10000)
  1626. // if err != nil {
  1627. // fmt.Println("err:", err)
  1628. // return
  1629. // }
  1630. // for _, edbInfo := range list {
  1631. // multipleGraphConfigEdbMappingInfo, e := data_manage.GetMultipleGraphConfigEdbMappingByEdbInfoId(edbInfo.EdbInfoId)
  1632. // if e != nil {
  1633. // fmt.Println(edbInfo.EdbInfoId, ";获取滚动相关性指标的配置信息失败, Err:"+e.Error())
  1634. // continue
  1635. // }
  1636. // multipleGraphConfig, e := data_manage.GetMultipleGraphConfigById(multipleGraphConfigEdbMappingInfo.MultipleGraphConfigId)
  1637. // if e != nil {
  1638. // fmt.Println(edbInfo.EdbInfoId, ";获取相关性图表的配置信息失败, Err:"+e.Error())
  1639. // continue
  1640. // }
  1641. //
  1642. // // 曲线图配置
  1643. // var curveConf data_manage.CurveConfig
  1644. // e = json.Unmarshal([]byte(multipleGraphConfig.Curve), &curveConf)
  1645. // if e != nil {
  1646. // fmt.Println(edbInfo.EdbInfoId, ";格式化曲线图数据失败, Err:"+e.Error())
  1647. // continue
  1648. // }
  1649. //
  1650. // var formulaConf request.EdbCalculateFormula
  1651. // e = json.Unmarshal([]byte(edbInfo.CalculateFormula), &formulaConf)
  1652. // if e != nil {
  1653. // fmt.Println(edbInfo.EdbInfoId, ";格式化指标计算配置数据失败, Err:"+e.Error())
  1654. // continue
  1655. // }
  1656. // formulaConf.DateType = curveConf.DateType
  1657. // formulaConf.StartDate = curveConf.StartDate
  1658. // formulaConf.EndDate = curveConf.EndDate
  1659. // calculateFormulaByte, err := json.Marshal(formulaConf)
  1660. // edbInfo.CalculateFormula = string(calculateFormulaByte)
  1661. // err = edbInfo.Update([]string{"CalculateFormula"})
  1662. // if err != nil {
  1663. // fmt.Println(edbInfo.EdbInfoId, ";更新指标信息失败, Err:"+err.Error())
  1664. // continue
  1665. // }
  1666. // }
  1667. //
  1668. // fmt.Println("指标更新完成")
  1669. // }
  1670. //}