residual_analysis_service.go 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. package residual_analysis_service
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models/data_manage"
  5. "eta/eta_api/models/residual_analysis_model"
  6. "eta/eta_api/models/system"
  7. "eta/eta_api/services/data"
  8. "eta/eta_api/utils"
  9. "fmt"
  10. "math"
  11. "sort"
  12. "strconv"
  13. "time"
  14. )
  15. func ResidualAnalysisPreview(req residual_analysis_model.ResidualAnalysisReq) (residual_analysis_model.ResidualAnalysisResp, error) {
  16. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
  17. if err != nil {
  18. return residual_analysis_model.ResidualAnalysisResp{}, fmt.Errorf("获取图表,指标信息失败,Err:%s", err.Error())
  19. }
  20. var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
  21. for _, v := range mappingList {
  22. if v.Unit == "无" {
  23. v.Unit = ""
  24. }
  25. if v.EdbInfoId == req.EdbInfoIdA {
  26. edbInfoMappingA = v
  27. }
  28. if v.EdbInfoId == req.EdbInfoIdB {
  29. edbInfoMappingB = v
  30. }
  31. }
  32. if edbInfoMappingA == nil {
  33. return residual_analysis_model.ResidualAnalysisResp{}, fmt.Errorf("指标A不存在")
  34. }
  35. if edbInfoMappingB == nil {
  36. return residual_analysis_model.ResidualAnalysisResp{}, fmt.Errorf("指标B不存在")
  37. }
  38. // 时间处理
  39. var startDate, endDate string
  40. switch req.DateType {
  41. case 0:
  42. startDate = req.StartDate
  43. endDate = req.EndDate
  44. case 1:
  45. startDate = req.StartDate
  46. endDate = ""
  47. default:
  48. startDate = utils.GetPreYearTime(req.DateType)
  49. endDate = ""
  50. }
  51. resp := residual_analysis_model.ResidualAnalysisResp{}
  52. // 原始图表信息
  53. originalEdbList := make([]residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, 0)
  54. originalEdbList, fullADataList, fullBDataList, err := fillOriginalChart(req, mappingList, startDate, endDate, edbInfoMappingA, edbInfoMappingB, originalEdbList)
  55. if err != nil {
  56. return residual_analysis_model.ResidualAnalysisResp{}, err
  57. }
  58. originalChartInfo := createChartInfoResp(req, startDate, endDate, edbInfoMappingA.EdbName+"与"+edbInfoMappingB.EdbName)
  59. resp.OriginalChartData = residual_analysis_model.ChartResp{
  60. ChartInfo: originalChartInfo,
  61. EdbInfoList: originalEdbList,
  62. }
  63. // 如果只需要第一张图表的数据 直接返回,避免继续处理
  64. if req.QueryType == 1 {
  65. return resp, nil
  66. }
  67. dataAList, ok := edbInfoMappingA.DataList.([]*data_manage.EdbDataList)
  68. if !ok {
  69. return residual_analysis_model.ResidualAnalysisResp{}, fmt.Errorf("数据类型转换失败")
  70. }
  71. indexADataMap := map[string]*data_manage.EdbDataList{}
  72. for _, indexData := range dataAList {
  73. indexADataMap[indexData.DataTime] = indexData
  74. }
  75. // 映射图表信息
  76. mappingEdbList, a, b, r, err := fillMappingChartInfo(req, edbInfoMappingA, edbInfoMappingB, originalEdbList, indexADataMap, startDate, endDate, fullADataList, fullBDataList)
  77. if err != nil {
  78. return residual_analysis_model.ResidualAnalysisResp{}, err
  79. }
  80. mappingChartInfo := createChartInfoResp(req, startDate, endDate, edbInfoMappingA.EdbName+"与"+edbInfoMappingB.EdbName+"映射"+edbInfoMappingA.EdbName)
  81. resp.MappingChartData = residual_analysis_model.ChartResp{
  82. ChartInfo: mappingChartInfo,
  83. EdbInfoList: mappingEdbList,
  84. }
  85. // 残差图表信息
  86. residualEdbList, R2, err := fillResidualChartInfo(req, edbInfoMappingA, edbInfoMappingB, mappingEdbList)
  87. if err != nil {
  88. return residual_analysis_model.ResidualAnalysisResp{}, err
  89. }
  90. residualChartInfo := createChartInfoResp(req, startDate, endDate, edbInfoMappingA.EdbName+"与"+edbInfoMappingA.EdbName+"映射残差/"+edbInfoMappingB.EdbName)
  91. resp.ResidualChartData = residual_analysis_model.ChartResp{
  92. ChartInfo: residualChartInfo,
  93. EdbInfoList: residualEdbList,
  94. }
  95. if req.ResidualType == 2 {
  96. resp.A = math.Round(a*10000) / 10000
  97. resp.B = math.Round(b*10000) / 10000
  98. resp.R = math.Round(r*10000) / 10000
  99. resp.R2 = math.Round(R2*10000) / 10000
  100. }
  101. return resp, nil
  102. }
  103. func createChartInfoResp(req residual_analysis_model.ResidualAnalysisReq, startDate, endDate, chartName string) residual_analysis_model.ResidualAnalysisChartInfo {
  104. return residual_analysis_model.ResidualAnalysisChartInfo{
  105. Calendar: `公历`,
  106. Source: utils.CHART_SOURCE_DEFAULT,
  107. DateType: req.DateType,
  108. StartDate: startDate,
  109. EndDate: endDate,
  110. ChartType: utils.CHART_TYPE_CURVE,
  111. ChartName: chartName,
  112. }
  113. }
  114. func fillResidualChartInfo(req residual_analysis_model.ResidualAnalysisReq, edbInfoMappingA *data_manage.ChartEdbInfoMapping, edbInfoMappingB *data_manage.ChartEdbInfoMapping, mappingEdbList []residual_analysis_model.ResidualAnalysisChartEdbInfoMapping) ([]residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, float64, error) {
  115. // 计算公式 映射残差 = 因变量指标 - 映射指标
  116. var edbInfoA, edbInfoB residual_analysis_model.ResidualAnalysisChartEdbInfoMapping
  117. if mappingEdbList[0].EdbInfoId == edbInfoMappingA.EdbInfoId {
  118. edbInfoA = mappingEdbList[0]
  119. edbInfoB = mappingEdbList[1]
  120. } else {
  121. edbInfoA = mappingEdbList[1]
  122. edbInfoB = mappingEdbList[0]
  123. }
  124. dataAList, ok := edbInfoA.DataList.([]*data_manage.EdbDataList)
  125. if !ok {
  126. return nil, 0, fmt.Errorf("数据类型转换失败")
  127. }
  128. edbData := make([]*data_manage.EdbDataList, len(dataAList))
  129. for i, data := range dataAList {
  130. edbData[i] = &data_manage.EdbDataList{
  131. Value: data.Value, // 确保为每个元素创建一个新的对象
  132. DataTimestamp: data.DataTimestamp,
  133. DataTime: data.DataTime,
  134. EdbInfoId: data.EdbInfoId,
  135. EdbDataId: data.EdbDataId,
  136. }
  137. }
  138. dataBList, ok := edbInfoB.DataList.([]*data_manage.EdbDataList)
  139. if !ok {
  140. return nil, 0, fmt.Errorf("数据类型转换失败")
  141. }
  142. // 映射指标开始时间
  143. var startTime string
  144. if len(dataBList) > 0 {
  145. startTime = dataBList[0].DataTime
  146. }
  147. var indexDataBMap = make(map[string]*data_manage.EdbDataList)
  148. for _, data := range dataBList {
  149. indexDataBMap[data.DataTime] = data
  150. }
  151. // 求R2
  152. var valueB, sumValueA, averageValueA, residualQuadraticSum, totalQuadraticSum, R2 float64
  153. for _, indexData := range edbData {
  154. // 因变量的值总和
  155. sumValueA += indexData.Value
  156. }
  157. // 因变量平均值
  158. averageValueA = sumValueA / float64(len(edbData))
  159. var indexMax, indexMin float64
  160. var edbDataResp []*data_manage.EdbDataList
  161. if len(edbData) > 0 {
  162. indexMax = edbData[0].Value
  163. indexMin = edbData[0].Value
  164. for _, indexData := range edbData {
  165. if dataB, ok := indexDataBMap[indexData.DataTime]; ok {
  166. valueB = dataB.Value
  167. } else {
  168. continue
  169. }
  170. // 总因变量平方和
  171. totalQuadraticSum += math.Pow(indexData.Value-averageValueA, 2)
  172. // 补全残差值
  173. indexData.Value = math.Round((indexData.Value-valueB)*10000) / 10000
  174. // 残差平方和
  175. residualQuadraticSum += math.Pow(indexData.Value, 2)
  176. if indexData.Value > indexMax {
  177. indexMax = indexData.Value
  178. }
  179. if indexData.Value < indexMin {
  180. indexMin = indexData.Value
  181. }
  182. // 获取映射指标之后的数据
  183. if startTime != "" && utils.CompareDate(startTime, indexData.DataTime) {
  184. edbDataResp = append(edbDataResp, indexData)
  185. }
  186. }
  187. }
  188. // 计算R2 公式:R2=1-SSE/SST R2越大,越符合线性 R2 = 1 - 残差平方和/总平方和
  189. R2 = 1 - residualQuadraticSum/totalQuadraticSum
  190. mappingEdb := make([]residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, len(mappingEdbList))
  191. copy(mappingEdb, mappingEdbList)
  192. for i, mapping := range mappingEdb {
  193. if mapping.EdbInfoId != edbInfoMappingA.EdbInfoId {
  194. mappingEdb[i].DataList = edbDataResp
  195. mappingEdb[i].EdbName = edbInfoMappingA.EdbName + "映射残差/" + edbInfoMappingB.EdbName
  196. if req.IndexType == 2 {
  197. if req.LeadValue > 0 {
  198. mappingEdb[i].EdbName = edbInfoMappingA.EdbName + "映射残差/" + edbInfoMappingB.EdbName + "(领先" + strconv.Itoa(req.LeadValue) + req.LeadFrequency + ")"
  199. }
  200. }
  201. mappingEdb[i].IsAxis = 1
  202. mappingEdb[i].ChartColor = `#00F`
  203. mappingEdb[i].IsOrder = false
  204. mappingEdb[i].MinValue = indexMin
  205. mappingEdb[i].MaxValue = indexMax
  206. } else {
  207. mappingEdb[i].IsAxis = 0
  208. mappingEdb[i].ChartColor = `#F00`
  209. }
  210. }
  211. return mappingEdb, R2, nil
  212. }
  213. func fillMappingChartInfo(req residual_analysis_model.ResidualAnalysisReq, edbInfoMappingA *data_manage.ChartEdbInfoMapping, edbInfoMappingB *data_manage.ChartEdbInfoMapping, originalEdbList []residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, indexADataMap map[string]*data_manage.EdbDataList, startDate string, endDate string, fullADataList []*data_manage.EdbDataList, fullBDataList []*data_manage.EdbDataList) ([]residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, float64, float64, float64, error) {
  214. // 计算公式:Y=aX+b,Y为映射后的指标,X为自变量指标
  215. // 正序:a=(L2-L1)/(R2-R1) b=L2-R2*a
  216. // 逆序:a=(L2-L1)/(R1-R2) b=L2-R1*a
  217. // L2:左轴下限 R2:右轴上限 L1:左轴上限 R1:右轴下限
  218. var a, b, r float64
  219. // 映射残差 计算a,b
  220. if req.ResidualType == 1 {
  221. if req.IsOrder {
  222. a = (req.LeftIndexMax - req.LeftIndexMin) / (req.RightIndexMin - req.RightIndexMax)
  223. b = req.LeftIndexMax - req.RightIndexMin*a
  224. } else {
  225. a = (req.LeftIndexMax - req.LeftIndexMin) / (req.RightIndexMax - req.RightIndexMin)
  226. b = req.LeftIndexMax - req.RightIndexMax*a
  227. }
  228. }
  229. //dataAList := edbInfoMappingA.DataList.([]*data_manage.EdbDataList)
  230. dataList, ok := edbInfoMappingB.DataList.([]*data_manage.EdbDataList)
  231. if !ok {
  232. return nil, a, b, r, fmt.Errorf("数据类型转换失败")
  233. }
  234. // 指标B数据补充
  235. // 新建一个切片来保存补充的数据
  236. var replenishDataList []*data_manage.EdbDataList
  237. for index := 0; index < len(dataList)-1; index++ {
  238. // 获取当前数据和下一个数据
  239. beforeIndexData := dataList[index]
  240. afterIndexData := dataList[index+1]
  241. // 从最早时间开始,补充时间为自然日
  242. for utils.IsMoreThanOneDay(beforeIndexData.DataTime, afterIndexData.DataTime) {
  243. // 创建补充数据
  244. nextDay := utils.GetNextDay(beforeIndexData.DataTime)
  245. toTime := utils.StringToTime(nextDay)
  246. replenishIndexData := data_manage.EdbDataList{
  247. DataTime: nextDay, // 计算下一个自然日
  248. DataTimestamp: toTime.UnixMilli(),
  249. Value: beforeIndexData.Value, // 可以选择使用前一天的值,或者其他逻辑来计算值
  250. }
  251. // 将补充数据加入补充数据列表
  252. replenishDataList = append(replenishDataList, &replenishIndexData)
  253. // 更新 beforeIndexData 为新创建的补充数据
  254. beforeIndexData = &replenishIndexData
  255. }
  256. }
  257. // 将补充数据插入原始数据列表
  258. dataList = append(dataList, replenishDataList...)
  259. // 排序
  260. sort.Sort(ByDataTime(dataList))
  261. // 拟合残差 计算a,b
  262. var coordinateList []utils.Coordinate
  263. var replenishADataList []*data_manage.EdbDataList
  264. var replenishBDataList []*data_manage.EdbDataList
  265. if req.ResidualType == 2 {
  266. //
  267. // 因变量指标也转换为日度
  268. for index := 0; index < len(fullADataList)-1; index++ {
  269. // 获取当前数据和下一个数据
  270. beforeIndexData := fullADataList[index]
  271. afterIndexData := fullADataList[index+1]
  272. replenishADataList = append(replenishADataList, beforeIndexData)
  273. // 从最早时间开始,补充时间为自然日
  274. if utils.IsMoreThanOneDay(beforeIndexData.DataTime, afterIndexData.DataTime) {
  275. for {
  276. // 创建补充数据
  277. nextDay := utils.GetNextDay(beforeIndexData.DataTime)
  278. toTime := utils.StringToTime(nextDay)
  279. replenishIndexData := data_manage.EdbDataList{
  280. DataTime: nextDay, // 计算下一个自然日
  281. DataTimestamp: toTime.UnixMilli(),
  282. Value: beforeIndexData.Value, // 可以选择使用前一天的值,或者其他逻辑来计算值
  283. }
  284. // 将补充数据加入补充数据列表
  285. replenishADataList = append(replenishADataList, &replenishIndexData)
  286. // 更新 beforeIndexData 为新创建的补充数据
  287. beforeIndexData = &replenishIndexData
  288. // 检查是否还需要继续补充数据
  289. if !utils.IsMoreThanOneDay(beforeIndexData.DataTime, afterIndexData.DataTime) {
  290. break
  291. }
  292. }
  293. }
  294. }
  295. replenishADataList = append(replenishADataList, fullADataList[len(fullADataList)-1])
  296. // 自变量指标也转换为日度
  297. for index := 0; index < len(fullBDataList)-1; index++ {
  298. // 获取当前数据和下一个数据
  299. beforeIndexData := fullBDataList[index]
  300. afterIndexData := fullBDataList[index+1]
  301. replenishBDataList = append(replenishBDataList, beforeIndexData)
  302. // 从最早时间开始,补充时间为自然日
  303. if utils.IsMoreThanOneDay(beforeIndexData.DataTime, afterIndexData.DataTime) {
  304. for {
  305. // 创建补充数据
  306. nextDay := utils.GetNextDay(beforeIndexData.DataTime)
  307. toTime := utils.StringToTime(nextDay)
  308. replenishIndexData := data_manage.EdbDataList{
  309. DataTime: nextDay, // 计算下一个自然日
  310. DataTimestamp: toTime.UnixMilli(),
  311. Value: beforeIndexData.Value, // 可以选择使用前一天的值,或者其他逻辑来计算值
  312. }
  313. // 将补充数据加入补充数据列表
  314. replenishBDataList = append(replenishBDataList, &replenishIndexData)
  315. // 更新 beforeIndexData 为新创建的补充数据
  316. beforeIndexData = &replenishIndexData
  317. // 检查是否还需要继续补充数据
  318. if !utils.IsMoreThanOneDay(beforeIndexData.DataTime, afterIndexData.DataTime) {
  319. break
  320. }
  321. }
  322. }
  323. }
  324. replenishBDataList = append(replenishBDataList, fullBDataList[len(fullBDataList)-1])
  325. // replenishADataList --> map
  326. replenishADataMap := make(map[string]*data_manage.EdbDataList)
  327. for _, indexData := range replenishADataList {
  328. if (utils.StringToTime(indexData.DataTime).After(utils.StringToTime(startDate)) || utils.StringToTime(indexData.DataTime).Equal(utils.StringToTime(startDate))) && (endDate == "" || utils.StringToTime(indexData.DataTime).Before(utils.StringToTime(endDate))) {
  329. replenishADataMap[indexData.DataTime] = indexData
  330. }
  331. }
  332. for _, indexData := range replenishBDataList {
  333. if _, ok = replenishADataMap[indexData.DataTime]; ok {
  334. coordinate := utils.Coordinate{
  335. X: indexData.Value,
  336. Y: replenishADataMap[indexData.DataTime].Value,
  337. }
  338. coordinateList = append(coordinateList, coordinate)
  339. }
  340. }
  341. a, b = utils.GetLinearResult(coordinateList)
  342. r = utils.ComputeCorrelation(coordinateList)
  343. }
  344. // 填充映射指标值 使得时间长度一致
  345. dataList = FillDataBList(dataList, edbInfoMappingA)
  346. // 根据指标A的时间key,在B的映射指标中筛选出对应的值
  347. var dataBList []*data_manage.EdbDataList
  348. var indexMax, indexMin float64
  349. if len(dataList) > 0 {
  350. indexMax = dataList[0].Value
  351. indexMin = dataList[0].Value
  352. for _, indexData := range dataList {
  353. if _, ok := indexADataMap[indexData.DataTime]; ok {
  354. indexDataCopy := *indexData
  355. // 计算指标B映射值
  356. indexDataCopy.Value = math.Round((a*indexData.Value+b)*10000) / 10000
  357. // 比较最大值
  358. if indexData.Value > indexMax {
  359. indexMax = indexData.Value
  360. }
  361. // 比较最小值
  362. if indexData.Value < indexMin {
  363. indexMin = indexData.Value
  364. }
  365. // 将副本添加到 dataBList
  366. dataBList = append(dataBList, &indexDataCopy)
  367. }
  368. }
  369. }
  370. mappingEdbList := make([]residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, len(originalEdbList))
  371. copy(mappingEdbList, originalEdbList)
  372. for i, mapping := range mappingEdbList {
  373. if mapping.EdbInfoId != req.EdbInfoIdA {
  374. mappingEdbList[i].EdbInfoId = 0
  375. mappingEdbList[i].EdbCode = ""
  376. mappingEdbList[i].IsAxis = 1
  377. mappingEdbList[i].EdbName = edbInfoMappingB.EdbName + "映射" + edbInfoMappingA.EdbName
  378. if req.IndexType == 2 {
  379. if req.LeadValue > 0 {
  380. mappingEdbList[i].EdbName = edbInfoMappingB.EdbName + "映射" + edbInfoMappingA.EdbName + "(领先" + strconv.Itoa(req.LeadValue) + req.LeadFrequency + ")"
  381. }
  382. }
  383. mappingEdbList[i].DataList = dataBList
  384. mappingEdbList[i].MinValue = indexMin
  385. mappingEdbList[i].MaxValue = indexMax
  386. }
  387. }
  388. return mappingEdbList, a, b, r, nil
  389. }
  390. // FillDataBList 填充B的数据 使得与A的时间保持一致
  391. func FillDataBList(dataList []*data_manage.EdbDataList, edbInfoMappingA *data_manage.ChartEdbInfoMapping) []*data_manage.EdbDataList {
  392. dataAList, ok := edbInfoMappingA.DataList.([]*data_manage.EdbDataList)
  393. if !ok {
  394. return nil
  395. }
  396. for utils.StringToTime(dataList[len(dataList)-1].DataTime).Before(utils.StringToTime(dataAList[len(dataAList)-1].DataTime)) {
  397. // 使用A的时间填充时间差
  398. timeDiff := utils.GetNextDayN(dataList[len(dataList)-1].DataTime, 1)
  399. // 创建新的数据点并填充 前值填充
  400. newDataPoint := &data_manage.EdbDataList{
  401. DataTime: timeDiff,
  402. Value: dataList[len(dataList)-1].Value,
  403. DataTimestamp: utils.StringToTime(timeDiff).UnixMilli(),
  404. }
  405. // 将新数据点添加到dataList末尾
  406. dataList = append(dataList, newDataPoint)
  407. }
  408. return dataList
  409. }
  410. type ByDataTime []*data_manage.EdbDataList
  411. func (a ByDataTime) Len() int {
  412. return len(a)
  413. }
  414. func (a ByDataTime) Swap(i, j int) {
  415. a[i], a[j] = a[j], a[i]
  416. }
  417. func (a ByDataTime) Less(i, j int) bool {
  418. t1 := utils.StringToTime(a[i].DataTime)
  419. t2 := utils.StringToTime(a[j].DataTime)
  420. return t1.Before(t2)
  421. }
  422. func fillOriginalChart(req residual_analysis_model.ResidualAnalysisReq, mappingList []*data_manage.ChartEdbInfoMapping, startDate string, endDate string, edbInfoMappingA *data_manage.ChartEdbInfoMapping, edbInfoMappingB *data_manage.ChartEdbInfoMapping, originalEdbList []residual_analysis_model.ResidualAnalysisChartEdbInfoMapping) ([]residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, []*data_manage.EdbDataList, []*data_manage.EdbDataList, error) {
  423. var fullADataList, fullBDataList []*data_manage.EdbDataList
  424. for _, v := range mappingList {
  425. var edbInfoMapping residual_analysis_model.ResidualAnalysisChartEdbInfoMapping
  426. edbInfoMapping.EdbInfoType = 1
  427. edbInfoMapping.IsOrder = false
  428. edbInfoMapping.IsAxis = 1
  429. edbInfoMapping.ChartColor = `#00F`
  430. edbInfoMapping.ChartWidth = 3
  431. edbInfoMapping.EdbName = v.EdbName
  432. // 获取图表中的指标数据
  433. dataList, err := data_manage.GetEdbDataList(v.Source, v.SubSource, v.EdbInfoId, startDate, endDate)
  434. if err != nil {
  435. return nil, nil, nil, fmt.Errorf("获取指标数据失败,Err:%s", err.Error())
  436. }
  437. // 重新获取指标数据 产品要求需要和计算指标-拟合残差逻辑保持一致
  438. fullDataList, err := data_manage.GetEdbDataList(v.Source, v.SubSource, v.EdbInfoId, "", "")
  439. if err != nil {
  440. return nil, nil, nil, fmt.Errorf("获取指标数据失败,Err:%s", err.Error())
  441. }
  442. if v.EdbInfoId == req.EdbInfoIdB {
  443. edbInfoMapping.LeadValue = req.LeadValue
  444. edbInfoMapping.LeadUnit = req.LeadFrequency
  445. edbInfoMapping.EdbInfoType = req.IndexType
  446. edbInfoMapping.IsOrder = req.IsOrder
  447. edbInfoMapping.IsAxis = 0
  448. edbInfoMapping.ChartColor = `#F00`
  449. edbInfoMapping.ChartWidth = 1
  450. // 领先指标 dataList进行数据处理
  451. if req.IndexType == 2 {
  452. if req.LeadValue < 0 {
  453. return nil, nil, nil, fmt.Errorf("领先值不能小于0")
  454. } else if req.LeadValue > 0 {
  455. edbInfoMapping.EdbName = v.EdbName + "(领先" + strconv.Itoa(req.LeadValue) + req.LeadFrequency + ")"
  456. for _, indexData := range dataList {
  457. switch req.LeadFrequency {
  458. case "天":
  459. indexData.DataTime = utils.GetNextDayN(indexData.DataTime, req.LeadValue)
  460. case "周":
  461. indexData.DataTime = utils.GetNextDayN(indexData.DataTime, req.LeadValue*7)
  462. case "月":
  463. indexData.DataTime = utils.TimeToString(utils.AddDate(utils.StringToTime(indexData.DataTime), 0, req.LeadValue), utils.YearMonthDay)
  464. case "季":
  465. indexData.DataTime = utils.TimeToString(utils.AddDate(utils.StringToTime(indexData.DataTime), 0, req.LeadValue*3), utils.YearMonthDay)
  466. case "年":
  467. indexData.DataTime = utils.TimeToString(utils.AddDate(utils.StringToTime(indexData.DataTime), req.LeadValue, 0), utils.YearMonthDay)
  468. }
  469. indexData.DataTimestamp = utils.StringToTime(indexData.DataTime).UnixMilli()
  470. }
  471. }
  472. }
  473. edbInfoMappingB.DataList = dataList
  474. fullBDataList = fullDataList
  475. } else {
  476. edbInfoMappingA.DataList = dataList
  477. fullADataList = fullDataList
  478. }
  479. edbInfoMapping.EdbInfoId = v.EdbInfoId
  480. edbInfoMapping.EdbCode = v.EdbCode
  481. edbInfoMapping.Unit = v.Unit
  482. edbInfoMapping.Frequency = v.Frequency
  483. edbInfoMapping.Source = v.Source
  484. edbInfoMapping.SourceName = v.SourceName
  485. edbInfoMapping.MinValue = v.MinValue
  486. edbInfoMapping.MaxValue = v.MaxValue
  487. edbInfoMapping.LatestDate = v.LatestDate
  488. edbInfoMapping.LatestValue = v.LatestValue
  489. edbInfoMapping.DataList = dataList
  490. originalEdbList = append(originalEdbList, edbInfoMapping)
  491. }
  492. return originalEdbList, fullADataList, fullBDataList, nil
  493. }
  494. func ContrastPreview(indexCode string) (residual_analysis_model.ResidualAnalysisChartEdbInfoMapping, error) {
  495. var condition string
  496. var pars []interface{}
  497. if indexCode != "" {
  498. condition += " and edb_code=?"
  499. pars = append(pars, indexCode)
  500. }
  501. edbInfo, err := data_manage.GetEdbInfoByCondition(condition, pars)
  502. if err != nil {
  503. return residual_analysis_model.ResidualAnalysisChartEdbInfoMapping{}, err
  504. }
  505. if edbInfo == nil {
  506. return residual_analysis_model.ResidualAnalysisChartEdbInfoMapping{}, fmt.Errorf("指标不存在")
  507. }
  508. dataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, "", "")
  509. var resp residual_analysis_model.ResidualAnalysisChartEdbInfoMapping
  510. resp.EdbInfoId = edbInfo.EdbInfoId
  511. resp.EdbCode = edbInfo.EdbCode
  512. resp.ChartColor = "#F00"
  513. resp.SourceName = edbInfo.SourceName
  514. resp.EdbName = edbInfo.EdbName
  515. resp.Unit = edbInfo.Unit
  516. resp.Frequency = edbInfo.Frequency
  517. resp.MinValue = edbInfo.MinValue
  518. resp.MaxValue = edbInfo.MaxValue
  519. resp.DataList = dataList
  520. return resp, nil
  521. }
  522. func SaveResidualAnalysis(req residual_analysis_model.ResidualAnalysisIndexSaveReq, sysUser *system.Admin) error {
  523. // 验证分类是否存在
  524. classifyCount, err := data_manage.GetEdbClassifyCountById(req.ClassifyId)
  525. if err != nil {
  526. return err
  527. }
  528. if classifyCount <= 0 {
  529. return fmt.Errorf("分类不存在")
  530. }
  531. // 校验名称是否重复
  532. var condition string
  533. var pars []interface{}
  534. condition += " and source = ? AND edb_name=?"
  535. pars = append(pars, req.Source, req.EdbName)
  536. edbInfoByCondition, err := data_manage.GetEdbInfoByCondition(condition, pars)
  537. if err != nil && err.Error() != utils.ErrNoRow() {
  538. return err
  539. }
  540. // 获取指标数据最大值 最小值 最后更新时间 最后更新时间对应的值
  541. var indexMax, indexMin, indexLatestValue float64
  542. var indexLatestDate string
  543. if len(req.DataList) > 0 {
  544. latestTime, _ := time.Parse(utils.YearMonthDay, req.DataList[0].DataTime)
  545. for _, data := range req.DataList {
  546. // 比较最大值
  547. if data.Value > indexMax {
  548. indexMax = data.Value
  549. }
  550. // 比较最小值
  551. if data.Value < indexMin {
  552. indexMin = data.Value
  553. }
  554. // 比较最新时间和对应值
  555. currentTime, err := time.Parse(utils.YearMonthDay, data.DataTime)
  556. if err != nil {
  557. // 时间解析失败,跳过此项
  558. continue
  559. }
  560. // 如果当前时间更晚
  561. if currentTime.After(latestTime) {
  562. latestTime = currentTime
  563. indexLatestDate = data.DataTime
  564. indexLatestValue = data.Value
  565. }
  566. }
  567. }
  568. // 更新保存指标和配置的映射关系
  569. mappingList, err := residual_analysis_model.GetConfigMappingListByConfigId(req.ConfigId)
  570. if err != nil {
  571. return err
  572. }
  573. // 判断是更新还是修改 看指标配置映射中,是否存在对应指标 存在 则更新 不存在 则新增
  574. var edbInfoMapping residual_analysis_model.CalculateResidualAnalysisConfigMapping
  575. for _, mapping := range mappingList {
  576. if req.IndexType == mapping.IndexType && req.IndexType != 0 {
  577. edbInfoMapping = mapping
  578. }
  579. }
  580. var edbInfoId int64
  581. var edbCode string
  582. // 更新or新增
  583. if edbInfoMapping.EdbInfoId > 0 {
  584. // 查询指标库指标
  585. edbInfo, err := data_manage.GetEdbInfoById(int(edbInfoMapping.EdbInfoId))
  586. if err != nil {
  587. return err
  588. }
  589. if edbInfo == nil {
  590. return fmt.Errorf("指标不存在")
  591. }
  592. edbInfoId = int64(edbInfo.EdbInfoId)
  593. edbCode = edbInfo.EdbCode
  594. if edbInfoByCondition != nil && edbInfoByCondition.EdbInfoId != edbInfo.EdbInfoId {
  595. return fmt.Errorf("指标名称重复")
  596. }
  597. // 须补充更新指标最大值,最小值,数据最新时间,数据最新值
  598. edbInfo.MaxValue = indexMax
  599. edbInfo.MinValue = indexMin
  600. edbInfo.LatestDate = indexLatestDate
  601. edbInfo.LatestValue = indexLatestValue
  602. edbInfo.Unit = req.Unit
  603. edbInfo.Frequency = req.Frequency
  604. edbInfo.ClassifyId = req.ClassifyId
  605. edbInfo.EdbName = req.EdbName
  606. err = edbInfo.Update([]string{"min_value", "max_value", "latest_date", "latest_value", "unit", "frequency", "classify_id", "edb_name"})
  607. if err != nil {
  608. return err
  609. }
  610. // 删除对应得指标数据
  611. err = residual_analysis_model.DeleteResidualAnalysisDataByEdbCode(edbInfo.EdbCode)
  612. if err != nil {
  613. return fmt.Errorf("删除指标数据失败")
  614. }
  615. } else {
  616. if edbInfoByCondition != nil {
  617. return fmt.Errorf("指标名称重复")
  618. }
  619. // 新增指标
  620. edbCode, err = utils.GenerateEdbCode(1, "")
  621. if err != nil {
  622. return err
  623. }
  624. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  625. edbInfoId, err = data_manage.AddEdbInfo(&data_manage.EdbInfo{
  626. EdbCode: edbCode,
  627. UniqueCode: utils.MD5(utils.CHART_PREFIX + "_" + timestamp),
  628. EdbName: req.EdbName,
  629. EdbNameEn: req.EdbNameEn,
  630. ClassifyId: req.ClassifyId,
  631. EdbType: req.EdbType,
  632. Unit: req.Unit,
  633. UnitEn: req.UnitEn,
  634. Frequency: req.Frequency,
  635. Source: req.Source,
  636. SourceName: "残差分析",
  637. Calendar: req.Calendar,
  638. SysUserRealName: sysUser.RealName,
  639. SysUserId: sysUser.AdminId,
  640. LatestDate: indexLatestDate,
  641. LatestValue: indexLatestValue,
  642. MinValue: indexMin,
  643. MaxValue: indexMax,
  644. CreateTime: time.Now(),
  645. ModifyTime: time.Now(),
  646. })
  647. if err != nil {
  648. return err
  649. }
  650. // 新增指标配置关系
  651. _, err = residual_analysis_model.SaveConfigMapping(residual_analysis_model.CalculateResidualAnalysisConfigMapping{
  652. CalculateResidualAnalysisConfigId: req.ConfigId,
  653. EdbInfoId: edbInfoId,
  654. ResidualType: req.ResidualType,
  655. IndexType: req.IndexType,
  656. CreateTime: time.Now(),
  657. ModifyTime: time.Now(),
  658. })
  659. if err != nil {
  660. return err
  661. }
  662. }
  663. // 新增数据
  664. for i := range req.DataList {
  665. req.DataList[i].EdbDataId = 0
  666. req.DataList[i].EdbInfoId = int(edbInfoId)
  667. req.DataList[i].EdbCode = edbCode
  668. }
  669. _, err = residual_analysis_model.AddResidualAnalysisData(req.DataList)
  670. if err != nil {
  671. return err
  672. }
  673. // 新增自变量 因变量与配置得关系 配置中不存在该指标,则新增
  674. var indexMap = make(map[int64]residual_analysis_model.CalculateResidualAnalysisConfigMapping)
  675. for _, mapping := range mappingList {
  676. indexMap[mapping.EdbInfoId] = mapping
  677. }
  678. if _, ok := indexMap[int64(req.EdbInfoIdA)]; !ok {
  679. _, err = residual_analysis_model.SaveConfigMapping(residual_analysis_model.CalculateResidualAnalysisConfigMapping{
  680. CalculateResidualAnalysisConfigId: req.ConfigId,
  681. EdbInfoId: int64(req.EdbInfoIdA),
  682. ResidualType: req.ResidualType,
  683. IndexType: 3,
  684. CreateTime: time.Now(),
  685. ModifyTime: time.Now(),
  686. })
  687. if err != nil {
  688. return err
  689. }
  690. }
  691. if _, ok := indexMap[int64(req.EdbInfoIdB)]; !ok {
  692. _, err = residual_analysis_model.SaveConfigMapping(residual_analysis_model.CalculateResidualAnalysisConfigMapping{
  693. CalculateResidualAnalysisConfigId: req.ConfigId,
  694. EdbInfoId: int64(req.EdbInfoIdB),
  695. ResidualType: req.ResidualType,
  696. IndexType: 4,
  697. CreateTime: time.Now(),
  698. ModifyTime: time.Now(),
  699. })
  700. if err != nil {
  701. return err
  702. }
  703. }
  704. // 保存溯源信息
  705. {
  706. fromEdbInfo, err := data_manage.GetEdbInfoById(int(edbInfoId))
  707. if err != nil {
  708. if err.Error() == utils.ErrNoRow() {
  709. return fmt.Errorf("指标不存在,err:" + err.Error())
  710. }
  711. return fmt.Errorf("获取失败")
  712. }
  713. edbCalculateMappingInfo := new(data_manage.EdbInfoCalculateMapping)
  714. edbCalculateMappingInfo.EdbInfoId = int(edbInfoId)
  715. edbCalculateMappingInfo.Source = req.Source
  716. edbCalculateMappingInfo.SourceName = "残差分析"
  717. edbCalculateMappingInfo.EdbCode = edbCode
  718. edbCalculateMappingInfo.FromEdbInfoId = fromEdbInfo.EdbInfoId
  719. edbCalculateMappingInfo.FromEdbCode = fromEdbInfo.EdbCode
  720. edbCalculateMappingInfo.FromEdbName = fromEdbInfo.EdbName
  721. edbCalculateMappingInfo.FromSource = fromEdbInfo.Source
  722. edbCalculateMappingInfo.FromSourceName = fromEdbInfo.SourceName
  723. edbCalculateMappingInfo.CreateTime = time.Now()
  724. edbCalculateMappingInfo.ModifyTime = time.Now()
  725. err = edbCalculateMappingInfo.Insert()
  726. if err != nil {
  727. return fmt.Errorf("保存溯源信息失败,Err:" + err.Error())
  728. }
  729. }
  730. //添加es
  731. data.AddOrEditEdbInfoToEs(int(edbInfoId))
  732. return nil
  733. }
  734. func ResidualAnalysisDetail(edbInfoId int) (residual_analysis_model.ResidualAnalysisDetailResp, error) {
  735. // 通过指标配置映射表 拿到配置id,再获取关联的所有指标信息
  736. var condition string
  737. var pars []interface{}
  738. condition += " and edb_info_id=?"
  739. pars = append(pars, edbInfoId)
  740. mappingList, err := residual_analysis_model.GetConfigMappingListByCondition(condition, pars)
  741. if err != nil {
  742. return residual_analysis_model.ResidualAnalysisDetailResp{}, err
  743. }
  744. if len(mappingList) <= 0 {
  745. return residual_analysis_model.ResidualAnalysisDetailResp{}, fmt.Errorf("指标不存在")
  746. }
  747. mapping := mappingList[0]
  748. configMappingList, err := residual_analysis_model.GetConfigMappingListByConfigId(mapping.CalculateResidualAnalysisConfigId)
  749. if err != nil {
  750. return residual_analysis_model.ResidualAnalysisDetailResp{}, err
  751. }
  752. var edbInfoIdList []int64
  753. var edbInfoMap = make(map[int64]residual_analysis_model.CalculateResidualAnalysisConfigMapping)
  754. var mappgingFlag = false
  755. var residualFlag = false
  756. for _, v := range configMappingList {
  757. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  758. edbInfoMap[v.EdbInfoId] = v
  759. if v.IndexType == 1 {
  760. mappgingFlag = true
  761. } else if v.IndexType == 2 {
  762. residualFlag = true
  763. }
  764. }
  765. condition = ""
  766. pars = []interface{}{}
  767. condition += ` and edb_info_id in(` + utils.GetOrmInReplace(len(edbInfoIdList)) + `)`
  768. for _, id := range edbInfoIdList {
  769. pars = append(pars, id)
  770. }
  771. edbInfoList, err := data_manage.GetEdbInfoListByCond(condition, pars)
  772. if err != nil {
  773. return residual_analysis_model.ResidualAnalysisDetailResp{}, err
  774. }
  775. // 获取配置
  776. configInfo, err := residual_analysis_model.GetResidualAnalysisConfigById(mapping.CalculateResidualAnalysisConfigId)
  777. if err != nil {
  778. return residual_analysis_model.ResidualAnalysisDetailResp{}, err
  779. }
  780. var edbInfoListResp []*residual_analysis_model.DetailEdbInfoList
  781. var dependentEdbInfo residual_analysis_model.DetailEdbInfoList
  782. var independentEdbInfo residual_analysis_model.DetailEdbInfoList
  783. for _, edbInfo := range edbInfoList {
  784. var indexType int
  785. if _, ok := edbInfoMap[int64(edbInfo.EdbInfoId)]; ok {
  786. indexType = edbInfoMap[int64(edbInfo.EdbInfoId)].IndexType
  787. }
  788. info := residual_analysis_model.DetailEdbInfoList{
  789. EdbInfoId: edbInfo.EdbInfoId,
  790. EdbInfoType: edbInfo.EdbInfoType,
  791. IndexType: indexType,
  792. SourceName: edbInfo.SourceName,
  793. Source: edbInfo.Source,
  794. EdbCode: edbInfo.EdbCode,
  795. EdbName: edbInfo.EdbName,
  796. EdbNameEn: edbInfo.EdbNameEn,
  797. Unit: edbInfo.Unit,
  798. UnitEn: edbInfo.UnitEn,
  799. Frequency: edbInfo.Frequency,
  800. FrequencyEn: edbInfo.FrequencyEn,
  801. ClassifyId: edbInfo.ClassifyId,
  802. }
  803. edbInfoListResp = append(edbInfoListResp, &info)
  804. if indexType == 3 {
  805. dependentEdbInfo = info
  806. } else if indexType == 4 {
  807. independentEdbInfo = info
  808. }
  809. }
  810. // 补充表格中 映射指标或者残差指标
  811. if mappgingFlag && !residualFlag {
  812. info := residual_analysis_model.DetailEdbInfoList{
  813. IndexType: 2,
  814. EdbName: independentEdbInfo.EdbName + "映射残差/" + dependentEdbInfo.EdbName,
  815. EdbNameEn: dependentEdbInfo.EdbNameEn,
  816. Unit: dependentEdbInfo.Unit,
  817. UnitEn: dependentEdbInfo.UnitEn,
  818. Frequency: dependentEdbInfo.Frequency,
  819. FrequencyEn: dependentEdbInfo.FrequencyEn,
  820. ClassifyId: dependentEdbInfo.ClassifyId,
  821. }
  822. edbInfoListResp = append(edbInfoListResp, &info)
  823. } else if !mappgingFlag && residualFlag {
  824. info := residual_analysis_model.DetailEdbInfoList{
  825. IndexType: 1,
  826. EdbName: dependentEdbInfo.EdbName + "映射" + independentEdbInfo.EdbName,
  827. EdbNameEn: dependentEdbInfo.EdbNameEn,
  828. Unit: dependentEdbInfo.Unit,
  829. UnitEn: dependentEdbInfo.UnitEn,
  830. Frequency: dependentEdbInfo.Frequency,
  831. FrequencyEn: dependentEdbInfo.FrequencyEn,
  832. ClassifyId: dependentEdbInfo.ClassifyId,
  833. }
  834. edbInfoListResp = append(edbInfoListResp, &info)
  835. }
  836. resp := residual_analysis_model.ResidualAnalysisDetailResp{
  837. ConfigInfo: &configInfo,
  838. EdbInfoList: edbInfoListResp,
  839. ResidualType: mapping.ResidualType,
  840. }
  841. return resp, nil
  842. }
  843. func SaveResidualAnalysisConfig(req residual_analysis_model.ResidualAnalysisReq, sysUser *system.Admin) (int64, error) {
  844. config := residual_analysis_model.ResidualAnalysisConfigVo{
  845. DateType: req.DateType,
  846. StartDate: req.StartDate,
  847. EndDate: req.EndDate,
  848. IsOrder: req.IsOrder,
  849. IndexType: req.IndexType,
  850. LeadValue: req.LeadValue,
  851. LeadFrequency: req.LeadFrequency,
  852. LeftIndexMin: req.LeftIndexMin,
  853. LeftIndexMax: req.LeftIndexMax,
  854. RightIndexMin: req.RightIndexMin,
  855. RightIndexMax: req.RightIndexMax,
  856. ResidualIndexMin: req.ResidualIndexMin,
  857. ResidualIndexMax: req.ResidualIndexMax,
  858. ContrastIndexMin: req.ContrastIndexMin,
  859. ContrastIndexMax: req.ContrastIndexMax,
  860. }
  861. // 转换为json格式
  862. configJson, err := json.Marshal(config)
  863. if err != nil {
  864. return 0, err
  865. }
  866. // 新增or更新
  867. /*
  868. var condition string
  869. var pars []interface{}
  870. if req.EdbInfoId > 0 {
  871. condition += " and edb_info_id=?"
  872. pars = append(pars, req.EdbInfoId)
  873. configMappings, err := residual_analysis_model.GetConfigMappingListByCondition(condition, pars)
  874. if err != nil {
  875. return 0, err
  876. }
  877. if len(configMappings) > 0 {
  878. mapping := configMappings[0]
  879. configInfo, err := residual_analysis_model.GetResidualAnalysisConfigById(mapping.CalculateResidualAnalysisConfigId)
  880. if err != nil {
  881. return 0, err
  882. }
  883. configInfo.Config = string(configJson)
  884. err = residual_analysis_model.UpdateResidualAnalysisConfig(configInfo)
  885. if err != nil {
  886. return 0, err
  887. }
  888. }
  889. }*/
  890. var configId int64
  891. if req.ConfigId > 0 {
  892. configInfo, err := residual_analysis_model.GetResidualAnalysisConfigById(req.ConfigId)
  893. if err != nil {
  894. return 0, err
  895. }
  896. if configInfo.CalculateResidualAnalysisConfigId == 0 {
  897. return 0, fmt.Errorf("未找到配置信息")
  898. }
  899. configId = int64(configInfo.CalculateResidualAnalysisConfigId)
  900. configInfo.Config = string(configJson)
  901. err = residual_analysis_model.UpdateResidualAnalysisConfig(configInfo)
  902. if err != nil {
  903. return 0, err
  904. }
  905. } else {
  906. analysisConfig := residual_analysis_model.CalculateResidualAnalysisConfig{
  907. Config: string(configJson),
  908. SysUserId: sysUser.AdminId,
  909. CreateTime: time.Now(),
  910. ModifyTime: time.Now(),
  911. }
  912. configId, err = residual_analysis_model.SaveResidualAnalysisConfig(analysisConfig)
  913. if err != nil {
  914. return 0, err
  915. }
  916. }
  917. return configId, nil
  918. }
  919. func CheckResidualAnalysisExist(configId int) (int64, error) {
  920. configMappingList, err := residual_analysis_model.GetConfigMappingListByConfigId(configId)
  921. if err != nil {
  922. return 0, err
  923. }
  924. var configMapping residual_analysis_model.CalculateResidualAnalysisConfigMapping
  925. for _, mapping := range configMappingList {
  926. if mapping.IndexType == 2 {
  927. configMapping = mapping
  928. }
  929. }
  930. return configMapping.EdbInfoId, nil
  931. }