multiple_graph_config.go 57 KB

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