edb_info.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. package chart
  2. import (
  3. "errors"
  4. "fmt"
  5. chartEdbMappingModel "hongze/hongze_yb/models/tables/chart_edb_mapping"
  6. edbInfoModel "hongze/hongze_yb/models/tables/edb_info"
  7. predictEdbConfCalculateMappingModel "hongze/hongze_yb/models/tables/predict_edb_conf_calculate_mapping"
  8. "hongze/hongze_yb/services/alarm_msg"
  9. "hongze/hongze_yb/utils"
  10. "sort"
  11. "time"
  12. )
  13. // EdbInfoRefreshAllFromBase 全部刷新指标(切换到edb_lib服务)
  14. // @author Roc
  15. // @datetime 2022-09-16 11:04:44
  16. // @description 将原有的单个指标刷新,调整为批量多个指标刷新
  17. func EdbInfoRefreshAllFromBase(edbInfoIdList []int, refreshAll bool) (err error, errmsg string) {
  18. defer func() {
  19. if err != nil {
  20. fmt.Println("EdbInfoRefreshAllFromBaseV2 Err:" + err.Error() + ";errmsg:" + errmsg)
  21. go alarm_msg.SendAlarmMsg("EdbInfoRefreshFromBaseV2,Err"+err.Error()+";errMsg:"+errmsg, 3)
  22. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
  23. }
  24. }()
  25. // 获取关联的基础指标
  26. newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr, err, errmsg := getRefreshEdbInfoListByIds(edbInfoIdList)
  27. if err != nil {
  28. return
  29. }
  30. var startDate string
  31. for _, bv := range newBaseEdbInfoArr {
  32. //source := bv.Source
  33. //edbInfoId := bv.EdbInfoId
  34. //edbCode := bv.EdbCode
  35. if bv.StartDate.IsZero() {
  36. continue
  37. }
  38. //开始时间
  39. startDate = ``
  40. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  41. startDate = bv.StartDate.Format(utils.FormatDate)
  42. } else {
  43. sTime := bv.EndDate
  44. frequency := bv.Frequency
  45. var limitDay int
  46. switch frequency {
  47. case "日度":
  48. limitDay = utils.DATA_START_REFRESH_LIMIT
  49. case "周度":
  50. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  51. case "月度":
  52. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  53. case "季度":
  54. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  55. case "年度":
  56. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  57. default:
  58. limitDay = utils.DATA_START_REFRESH_LIMIT
  59. }
  60. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  61. }
  62. result, tmpErr := RefreshEdbData(bv.EdbInfoId, bv.Source, bv.SubSource, bv.EdbCode, startDate)
  63. if tmpErr != nil {
  64. err = tmpErr
  65. fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err", time.Now())
  66. errmsg = "RefreshBaseEdbData Err:" + err.Error()
  67. return
  68. }
  69. if result.Ret != 200 {
  70. fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  71. errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  72. err = fmt.Errorf("刷新失败, err:", errmsg)
  73. return
  74. }
  75. //maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  76. //if err != nil {
  77. // if err.Error() == utils.ErrNoRow() { //找不到数据,那么就进入到下一条数据做处理
  78. // continue
  79. // }
  80. // return err
  81. //}
  82. //if maxAndMinItem != nil {
  83. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
  84. // if err != nil {
  85. // return err
  86. // }
  87. //}
  88. fmt.Println("end newBaseEdbInfoArr:", bv, time.Now())
  89. }
  90. //刷新相关普通计算指标
  91. for _, v := range calculateArr {
  92. edbInfo := newCalculateMap[v]
  93. if edbInfo == nil {
  94. return
  95. }
  96. startDate = edbInfo.StartDate.Format(utils.FormatDate)
  97. source := edbInfo.Source
  98. if edbInfo.StartDate.IsZero() { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  99. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  100. } else {
  101. if source == utils.DATA_SOURCE_CALCULATE {
  102. startDate = ``
  103. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  104. startDate = edbInfo.StartDate.Format(utils.FormatDate)
  105. } else {
  106. sTime := edbInfo.EndDate
  107. frequency := edbInfo.Frequency
  108. var limitDay int
  109. switch frequency {
  110. case "日度":
  111. limitDay = utils.DATA_START_REFRESH_LIMIT
  112. case "周度":
  113. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  114. case "月度":
  115. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  116. case "季度":
  117. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  118. case "年度":
  119. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  120. default:
  121. limitDay = utils.DATA_START_REFRESH_LIMIT
  122. }
  123. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  124. }
  125. }
  126. }
  127. result, tmpErr := RefreshEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  128. if tmpErr != nil {
  129. err = tmpErr
  130. fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
  131. errmsg = "RefreshEdbCalculateData Err:" + err.Error()
  132. return
  133. }
  134. if result.Ret != 200 {
  135. fmt.Println(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  136. errmsg = fmt.Sprint(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  137. err = fmt.Errorf("刷新失败")
  138. return
  139. }
  140. }
  141. //刷新相关预测计算指标
  142. for _, v := range predictCalculateArr {
  143. edbInfo := newPredictCalculateMap[v]
  144. if edbInfo == nil {
  145. return
  146. }
  147. startDate = edbInfo.StartDate.Format(utils.FormatDate)
  148. source := edbInfo.Source
  149. if edbInfo.StartDate.IsZero() { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  150. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  151. } else {
  152. if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
  153. startDate = ``
  154. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  155. startDate = edbInfo.StartDate.Format(utils.FormatDate)
  156. } else {
  157. sTime := edbInfo.EndDate
  158. frequency := edbInfo.Frequency
  159. var limitDay int
  160. switch frequency {
  161. case "日度":
  162. limitDay = utils.DATA_START_REFRESH_LIMIT
  163. case "周度":
  164. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  165. case "月度":
  166. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  167. case "季度":
  168. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  169. case "年度":
  170. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  171. default:
  172. limitDay = utils.DATA_START_REFRESH_LIMIT
  173. }
  174. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  175. }
  176. }
  177. }
  178. result, tmpErr := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  179. if tmpErr != nil {
  180. err = tmpErr
  181. fmt.Println(v, "RefreshPredictEdbCalculateData err", time.Now())
  182. errmsg = "RefreshPredictEdbCalculateData Err:" + err.Error()
  183. return
  184. }
  185. if result.Ret != 200 {
  186. fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  187. errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  188. err = fmt.Errorf("刷新失败")
  189. return
  190. }
  191. }
  192. // 4、更新动态环差值
  193. {
  194. predictEdbInfoIdList := make([]int, 0)
  195. for _, v := range newBasePredictEdbInfoArr {
  196. predictEdbInfoIdList = append(predictEdbInfoIdList, v.EdbInfoId)
  197. }
  198. fmt.Println("predictEdbConfCalculateMappingDetailList:", predictEdbInfoIdList)
  199. predictEdbConfCalculateMappingDetailList, tmpErr := predictEdbConfCalculateMappingModel.GetPredictEdbRuleDataList(predictEdbInfoIdList)
  200. if tmpErr != nil {
  201. err = tmpErr
  202. errmsg = fmt.Sprint("更新动态环差值时,获取数据失败:" + err.Error())
  203. return
  204. }
  205. for _, bv := range predictEdbConfCalculateMappingDetailList {
  206. result, tmpErr := RefreshEdbData(bv.EdbInfoId, utils.DATA_SOURCE_PREDICT, utils.DATA_SUB_SOURCE_EDB, bv.EdbCode, "")
  207. if tmpErr != nil {
  208. err = tmpErr
  209. fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err", time.Now())
  210. errmsg = "RefreshBasePredictEdbData Err:" + err.Error()
  211. return
  212. }
  213. if result.Ret != 200 {
  214. fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  215. errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  216. err = errors.New("刷新失败:" + errmsg)
  217. return
  218. }
  219. fmt.Println("end predictEdbConfCalculateMappingDetailList:", bv, time.Now())
  220. }
  221. }
  222. //5、刷新相关预测计算指标
  223. for _, v := range predictCalculateArr {
  224. edbInfo := newPredictCalculateMap[v]
  225. if edbInfo == nil {
  226. return
  227. }
  228. startDate = edbInfo.StartDate.Format(utils.FormatDate)
  229. source := edbInfo.Source
  230. if edbInfo.StartDate.IsZero() { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  231. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  232. } else {
  233. if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
  234. startDate = ``
  235. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  236. startDate = edbInfo.StartDate.Format(utils.FormatDate)
  237. } else {
  238. sTime := edbInfo.EndDate
  239. frequency := edbInfo.Frequency
  240. var limitDay int
  241. switch frequency {
  242. case "日度":
  243. limitDay = utils.DATA_START_REFRESH_LIMIT
  244. case "周度":
  245. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  246. case "月度":
  247. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  248. case "季度":
  249. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  250. case "年度":
  251. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  252. default:
  253. limitDay = utils.DATA_START_REFRESH_LIMIT
  254. }
  255. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  256. }
  257. }
  258. }
  259. result, tmpErr := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  260. if tmpErr != nil {
  261. err = tmpErr
  262. fmt.Println(v, "RefreshPredictEdbCalculateData err", time.Now())
  263. errmsg = "RefreshPredictEdbCalculateData Err:" + err.Error()
  264. return
  265. }
  266. if result.Ret != 200 {
  267. fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  268. errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  269. err = fmt.Errorf("刷新失败")
  270. return
  271. }
  272. }
  273. return
  274. }
  275. // getRefreshEdbInfoList 获取待更新的指标(普通基础指标、普通运算指标,预测运算指标)
  276. func getRefreshEdbInfoListByIds(edbInfoIdList []int) (newBaseEdbInfoArr, newBasePredictEdbInfoArr []*edbInfoModel.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*edbInfoModel.EdbInfo, calculateArr, predictCalculateArr []int, err error, errMsg string) {
  277. calculateList, err := edbInfoModel.GetEdbInfoAllCalculateByEdbInfoIdList(edbInfoIdList)
  278. if err != nil && err != utils.ErrNoRow {
  279. err = errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
  280. return
  281. }
  282. // 获取指标信息
  283. edbInfoList, err := edbInfoModel.GetEdbInfoByIdList(edbInfoIdList)
  284. if err != nil {
  285. err = errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
  286. return
  287. }
  288. baseEdbInfoArr := make([]*edbInfoModel.EdbInfo, 0) // 基础普通指标
  289. calculateInfoArr := make([]*edbInfoModel.EdbInfo, 0) //基础运算指标
  290. basePredictEdbInfoArr := make([]*edbInfoModel.EdbInfo, 0) // 预测普通指标
  291. predictCalculateInfoArr := make([]*edbInfoModel.EdbInfo, 0) //预测运算指标
  292. for _, baseEdbInfo := range edbInfoList {
  293. if baseEdbInfo.EdbInfoType == 0 { //普通指标
  294. switch baseEdbInfo.EdbType {
  295. case 1: //基础指标
  296. baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
  297. case 2: //计算指标
  298. calculateList = append(calculateList, baseEdbInfo)
  299. }
  300. } else { //预测指标
  301. switch baseEdbInfo.EdbType {
  302. case 1: //基础指标
  303. basePredictEdbInfoArr = append(basePredictEdbInfoArr, baseEdbInfo)
  304. case 2: //计算指标
  305. predictCalculateInfoArr = append(predictCalculateInfoArr, baseEdbInfo)
  306. }
  307. }
  308. }
  309. // 计算指标
  310. for _, v := range calculateList {
  311. getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := edbInfoModel.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  312. if tmpErr != nil {
  313. err = tmpErr
  314. fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  315. errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  316. return
  317. }
  318. for _, tmpEdbInfo := range getBaseEdbInfoArr {
  319. switch tmpEdbInfo.EdbInfoType {
  320. case 0: //普通基础指标
  321. baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  322. case 1: //预测基础指标
  323. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  324. }
  325. }
  326. for _, tmpEdbInfo := range getCalculateInfoArr {
  327. switch tmpEdbInfo.EdbInfoType {
  328. case 0: //普通运算指标
  329. calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  330. case 1: //预测运算指标
  331. //predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  332. if tmpEdbInfo.EdbType == 1 { //预测普通指标
  333. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  334. } else {
  335. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  336. }
  337. }
  338. }
  339. switch v.EdbInfoType {
  340. case 0: //普通运算指标
  341. calculateInfoArr = append(calculateInfoArr, v)
  342. case 1: //预测运算指标
  343. //predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  344. if v.EdbType == 1 { //预测普通指标
  345. basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
  346. } else {
  347. predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  348. }
  349. }
  350. }
  351. // 预测计算指标
  352. for _, v := range predictCalculateInfoArr {
  353. getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := edbInfoModel.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  354. if tmpErr != nil {
  355. err = tmpErr
  356. fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  357. errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  358. return
  359. }
  360. for _, tmpEdbInfo := range getBaseEdbInfoArr {
  361. switch tmpEdbInfo.EdbInfoType {
  362. case 0: //普通基础指标
  363. baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  364. case 1: //预测基础指标
  365. //basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  366. if tmpEdbInfo.EdbType == 1 { //预测普通指标
  367. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  368. } else {
  369. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  370. }
  371. }
  372. }
  373. for _, tmpEdbInfo := range getCalculateInfoArr {
  374. switch tmpEdbInfo.EdbInfoType {
  375. case 0: //普通运算指标
  376. calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  377. case 1: //预测运算指标
  378. //predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  379. if tmpEdbInfo.EdbType == 1 { //预测普通指标
  380. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  381. } else {
  382. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  383. }
  384. }
  385. }
  386. switch v.EdbInfoType {
  387. case 0: //普通运算指标
  388. calculateInfoArr = append(calculateInfoArr, v)
  389. case 1: //预测运算指标
  390. //predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  391. if v.EdbType == 1 { //预测普通指标
  392. basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
  393. } else {
  394. predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  395. }
  396. }
  397. }
  398. // 第一次的计算指标map
  399. newCalculateMap = make(map[int]*edbInfoModel.EdbInfo)
  400. for _, v := range calculateInfoArr {
  401. if v.NoUpdate == 1 {
  402. continue
  403. }
  404. if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  405. calculateArr = append(calculateArr, v.EdbInfoId)
  406. }
  407. newCalculateMap[v.EdbInfoId] = v
  408. }
  409. // 基础预测指标
  410. if len(basePredictEdbInfoArr) > 0 {
  411. basePredictEdbInfoIdList := make([]int, 0)
  412. for _, v := range basePredictEdbInfoArr {
  413. basePredictEdbInfoIdList = append(basePredictEdbInfoIdList, v.EdbInfoId)
  414. }
  415. baseEdbInfoList, tmpErr := edbInfoModel.GetPredictEdbInfoAllCalculate(basePredictEdbInfoIdList)
  416. if tmpErr != nil {
  417. err = tmpErr
  418. return
  419. }
  420. tmpCalculateList := make([]*edbInfoModel.EdbInfo, 0)
  421. for _, v := range baseEdbInfoList {
  422. switch v.EdbType {
  423. case 1:
  424. baseEdbInfoArr = append(baseEdbInfoArr, v)
  425. case 2:
  426. // 如果不在第一次里面,那么在第二次 刷新预测指标的时候 需要加进去
  427. if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  428. tmpCalculateList = append(tmpCalculateList, v)
  429. }
  430. }
  431. }
  432. // 这里是查询预测指标用到的 普通计算指标
  433. for _, v := range tmpCalculateList {
  434. getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := edbInfoModel.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  435. if tmpErr != nil {
  436. err = tmpErr
  437. fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  438. errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  439. return
  440. }
  441. // 基础指标
  442. for _, tmpEdbInfo := range getBaseEdbInfoArr {
  443. switch tmpEdbInfo.EdbInfoType {
  444. case 0: //普通基础指标
  445. baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  446. case 1: //预测基础指标
  447. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  448. }
  449. }
  450. // 计算指标
  451. for _, tmpEdbInfo := range getCalculateInfoArr {
  452. switch tmpEdbInfo.EdbInfoType {
  453. case 0: //普通运算指标
  454. calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  455. case 1: //预测运算指标
  456. //predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  457. if v.EdbType == 1 { //预测普通指标
  458. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  459. } else {
  460. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  461. }
  462. }
  463. }
  464. switch v.EdbInfoType {
  465. case 0: //普通运算指标
  466. calculateInfoArr = append(calculateInfoArr, v)
  467. case 1: //预测运算指标
  468. //predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  469. if v.EdbType == 1 { //预测普通指标
  470. basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
  471. } else { //预测运算指标
  472. predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  473. }
  474. }
  475. }
  476. // 第二次计算指标的map
  477. for _, v := range calculateInfoArr {
  478. if v.NoUpdate == 1 {
  479. continue
  480. }
  481. if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  482. calculateArr = append(calculateArr, v.EdbInfoId)
  483. }
  484. newCalculateMap[v.EdbInfoId] = v
  485. }
  486. }
  487. // 普通基础指标去重
  488. newBaseEdbInfoArr = make([]*edbInfoModel.EdbInfo, 0)
  489. baseMap := make(map[int]int)
  490. for _, v := range baseEdbInfoArr {
  491. if v.NoUpdate == 1 {
  492. continue
  493. }
  494. if _, ok := baseMap[v.EdbInfoId]; !ok {
  495. newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
  496. }
  497. baseMap[v.EdbInfoId] = v.EdbInfoId
  498. }
  499. // 普通计算指标的id
  500. sort.Ints(calculateArr)
  501. // 普通预测指标去重
  502. newBasePredictEdbInfoArr = make([]*edbInfoModel.EdbInfo, 0)
  503. basePredictMap := make(map[int]int)
  504. for _, v := range basePredictEdbInfoArr {
  505. if _, ok := basePredictMap[v.EdbInfoId]; !ok {
  506. newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, v)
  507. }
  508. basePredictMap[v.EdbInfoId] = v.EdbInfoId
  509. }
  510. // 预测计算指标去重
  511. newPredictCalculateMap = make(map[int]*edbInfoModel.EdbInfo)
  512. for _, v := range predictCalculateInfoArr {
  513. if _, ok := newPredictCalculateMap[v.EdbInfoId]; !ok {
  514. predictCalculateArr = append(predictCalculateArr, v.EdbInfoId)
  515. }
  516. newPredictCalculateMap[v.EdbInfoId] = v
  517. }
  518. // 预测计算指标的id
  519. sort.Ints(predictCalculateArr)
  520. return
  521. }
  522. // GetEdbSourceByEdbInfoIdList 获取关联指标的来源
  523. func GetEdbSourceByEdbInfoIdList(chartEdbInfoMappingList []*chartEdbMappingModel.ChartEdbInfoMappingList) (sourceNameList, sourceNameEnList []string) {
  524. sourceNameList = []string{}
  525. sourceNameEnList = []string{}
  526. sourceMap := make(map[int]string)
  527. for _, v := range chartEdbInfoMappingList {
  528. // 指标类型:1:基础指标,2:计算指标
  529. if v.EdbType == 2 || v.EdbInfoCategoryType == 1 {
  530. //sourceMap[0] = "弘则研究"
  531. baseEdbInfoArr, _, _ := edbInfoModel.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  532. for _, baseEdbInfo := range baseEdbInfoArr {
  533. if baseEdbInfo.EdbInfoType == 0 { //普通指标才参与,预测指标不参与
  534. sourceMap[baseEdbInfo.Source] = baseEdbInfo.SourceName
  535. }
  536. }
  537. } else {
  538. sourceMap[v.Source] = v.SourceName
  539. }
  540. }
  541. for source, sourceName := range sourceMap {
  542. if utils.InArrayByInt([]int{utils.DATA_SOURCE_MANUAL, utils.DATA_SOURCE_MYSTEEL_CHEMICAL}, source) {
  543. continue
  544. }
  545. sourceNameList = append(sourceNameList, sourceName)
  546. sourceNameEn, ok := utils.DataSourceEnMap[source]
  547. if !ok {
  548. sourceNameEn = sourceName
  549. }
  550. sourceNameEnList = append(sourceNameEnList, sourceNameEn)
  551. }
  552. sourceNameList = append(sourceNameList, `弘则研究`)
  553. sourceNameEnList = append(sourceNameEnList, `Horizon Insights`)
  554. return
  555. }