|
@@ -21,52 +21,52 @@ import (
|
|
|
// @datetime 2024-01-10 13:55:05
|
|
|
// @param cont context.Context
|
|
|
// @return err error
|
|
|
-func ConfigRefreshData(cont context.Context) (err error) {
|
|
|
- errMsgList := make([]string, 0)
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- }
|
|
|
- }()
|
|
|
- // 一期是只做wind、同花顺、钢联、有色
|
|
|
-
|
|
|
- now := time.Now()
|
|
|
- //now = time.Date(2023, 12, 31, 19, 10, 59, 0, time.Local)
|
|
|
- //now = time.Date(2023, 12, 31, 16, 50, 59, 0, time.Local)
|
|
|
- defaultSourceEdbInfoListMap, err := getDefaultRefreshData(now)
|
|
|
- if err != nil {
|
|
|
- errMsgList = append(errMsgList, "获取默认刷新数据失败,Err:"+err.Error())
|
|
|
- }
|
|
|
- sourceEdbInfoListMap, err := getConfigRefreshData(now)
|
|
|
- if err != nil {
|
|
|
- errMsgList = append(errMsgList, "获取指标配置刷新数据失败,Err:"+err.Error())
|
|
|
- }
|
|
|
-
|
|
|
- // 将两个合并
|
|
|
- allSourceEdbInfoListMap := mergeMaps(defaultSourceEdbInfoListMap, sourceEdbInfoListMap)
|
|
|
- wgNum := len(allSourceEdbInfoListMap)
|
|
|
- if wgNum <= 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- wg := sync.WaitGroup{}
|
|
|
- wg.Add(wgNum)
|
|
|
-
|
|
|
- for _, edbList := range allSourceEdbInfoListMap {
|
|
|
- if edbList == nil {
|
|
|
- wg.Done()
|
|
|
- continue
|
|
|
- }
|
|
|
- if len(edbList) != 0 {
|
|
|
- go BaseRefreshData(&wg, edbList[0].Source, edbList[0].SubSource, edbList)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- wg.Wait()
|
|
|
-
|
|
|
- fmt.Println("Refresh End")
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
+//func ConfigRefreshData(cont context.Context) (err error) {
|
|
|
+// errMsgList := make([]string, 0)
|
|
|
+// defer func() {
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println(err)
|
|
|
+// }
|
|
|
+// }()
|
|
|
+// // 一期是只做wind、同花顺、钢联、有色
|
|
|
+//
|
|
|
+// now := time.Now()
|
|
|
+// //now = time.Date(2023, 12, 31, 19, 10, 59, 0, time.Local)
|
|
|
+// //now = time.Date(2023, 12, 31, 16, 50, 59, 0, time.Local)
|
|
|
+// defaultSourceEdbInfoListMap, err := getDefaultRefreshData(now)
|
|
|
+// if err != nil {
|
|
|
+// errMsgList = append(errMsgList, "获取默认刷新数据失败,Err:"+err.Error())
|
|
|
+// }
|
|
|
+// sourceEdbInfoListMap, err := getConfigRefreshData(now)
|
|
|
+// if err != nil {
|
|
|
+// errMsgList = append(errMsgList, "获取指标配置刷新数据失败,Err:"+err.Error())
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 将两个合并
|
|
|
+// allSourceEdbInfoListMap := mergeMaps(defaultSourceEdbInfoListMap, sourceEdbInfoListMap)
|
|
|
+// wgNum := len(allSourceEdbInfoListMap)
|
|
|
+// if wgNum <= 0 {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// wg := sync.WaitGroup{}
|
|
|
+// wg.Add(wgNum)
|
|
|
+//
|
|
|
+// for _, edbList := range allSourceEdbInfoListMap {
|
|
|
+// if edbList == nil {
|
|
|
+// wg.Done()
|
|
|
+// continue
|
|
|
+// }
|
|
|
+// if len(edbList) != 0 {
|
|
|
+// go BaseRefreshData(&wg, edbList[0].Source, edbList[0].SubSource, edbList)
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// wg.Wait()
|
|
|
+//
|
|
|
+// fmt.Println("Refresh End")
|
|
|
+//
|
|
|
+// return
|
|
|
+//}
|
|
|
|
|
|
// Function to merge two maps
|
|
|
func mergeMaps(dst map[string][]*edb_refresh.EdbInfoListAndRefreshConfig, src map[string][]*edb_refresh.EdbInfoListAndRefreshConfig) (newMap map[string][]*edb_refresh.EdbInfoListAndRefreshConfig) {
|
|
@@ -103,7 +103,6 @@ func getDefaultRefreshData(now time.Time) (sourceEdbInfoListMap map[string][]*ed
|
|
|
fmt.Println(err)
|
|
|
}
|
|
|
}()
|
|
|
- // 一期是只做wind、同花顺、钢联、有色
|
|
|
|
|
|
sourceEdbInfoListMap = make(map[string][]*edb_refresh.EdbInfoListAndRefreshConfig)
|
|
|
|
|
@@ -116,21 +115,21 @@ func getDefaultRefreshData(now time.Time) (sourceEdbInfoListMap map[string][]*ed
|
|
|
//刷新频率,枚举值:每自然日、每交易日、每周、每旬、每月、每季、每半年、每年
|
|
|
refreshFrequencyList := []string{"每自然日", "每交易日", "每周", "每旬", "每月", "每季", "每半年", "每年"}
|
|
|
|
|
|
- conf, err := models.GetBusinessConf()
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- utils.FileLog.Info("获取业务配置失败,Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
+ //conf, err := models.GetBusinessConf()
|
|
|
+ //if err != nil {
|
|
|
+ // fmt.Println(err)
|
|
|
+ // utils.FileLog.Info("获取业务配置失败,Err:" + err.Error())
|
|
|
+ // return
|
|
|
+ //}
|
|
|
|
|
|
// 获取钢联化工的数据获取方式
|
|
|
- mySteelChemicalDataMethod := "excel"
|
|
|
- if v, ok := conf["MySteelDataMethod"]; ok {
|
|
|
- if v == "api" {
|
|
|
- mySteelChemicalDataMethod = v
|
|
|
- }
|
|
|
- }
|
|
|
- utils.FileLog.Info("获取业务配置,MySteelDataMethod:" + mySteelChemicalDataMethod)
|
|
|
+ //mySteelChemicalDataMethod := "excel"
|
|
|
+ //if v, ok := conf["MySteelDataMethod"]; ok {
|
|
|
+ // if v == "api" {
|
|
|
+ // mySteelChemicalDataMethod = v
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //utils.FileLog.Info("获取业务配置,MySteelDataMethod:" + mySteelChemicalDataMethod)
|
|
|
// 获取各个刷新频率的配置
|
|
|
for _, refreshFrequency := range refreshFrequencyList {
|
|
|
// 获取刷新频率条件
|
|
@@ -144,14 +143,14 @@ func getDefaultRefreshData(now time.Time) (sourceEdbInfoListMap map[string][]*ed
|
|
|
pars = append(pars, refreshFrequency, currTimeStr)
|
|
|
|
|
|
// 这两个是excel的数据源,他是从公共机更新的,需要过滤掉
|
|
|
- if mySteelChemicalDataMethod == "api" {
|
|
|
- // 钢联化工使用api的方式获取数据的,不需要过滤
|
|
|
- condition += ` AND source not in (?)`
|
|
|
- pars = append(pars, utils.DATA_SOURCE_YS)
|
|
|
- } else {
|
|
|
- condition += ` AND source not in (?,?)`
|
|
|
- pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_YS)
|
|
|
- }
|
|
|
+ //if mySteelChemicalDataMethod == "api" {
|
|
|
+ // // 钢联化工使用api的方式获取数据的,不需要过滤
|
|
|
+ // condition += ` AND source not in (?)`
|
|
|
+ // pars = append(pars, utils.DATA_SOURCE_YS)
|
|
|
+ //} else {
|
|
|
+ // condition += ` AND source not in (?,?)`
|
|
|
+ // pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_YS)
|
|
|
+ //}
|
|
|
tmpList, tmpErr := edb_refresh.GetListByCondition(condition, pars)
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
@@ -187,71 +186,28 @@ func getDefaultRefreshData(now time.Time) (sourceEdbInfoListMap map[string][]*ed
|
|
|
}
|
|
|
|
|
|
for source, subSourceFrequencyListMap := range refreshDataFrequencyListMap {
|
|
|
- switch source {
|
|
|
- case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_YS:
|
|
|
- // 只处理钢联化工使用api方式获取数据的情况
|
|
|
- if mySteelChemicalDataMethod == "api" {
|
|
|
- for subSource, frequencyList := range subSourceFrequencyListMap {
|
|
|
- items, tmpErr := data_manage.GetBaseFromMysteelChemicalIndexItems(frequencyList)
|
|
|
- if tmpErr != nil {
|
|
|
- errMsgList = append(errMsgList, fmt.Sprint("source:", source, "subSource:", subSource, "frequencyList:", strings.Join(frequencyList, ","), "err:", tmpErr.Error()))
|
|
|
- }
|
|
|
- indexList := make([]*edb_refresh.EdbInfoListAndRefreshConfig, 0)
|
|
|
-
|
|
|
- for _, v := range items {
|
|
|
- tmpConf := new(edb_refresh.EdbInfoListAndRefreshConfig)
|
|
|
- // 数据刷新的期数
|
|
|
- dataRefreshNum := utils.DATA_REFRESH
|
|
|
- key := fmt.Sprintf("%d_%d_%s", utils.DATA_SOURCE_MYSTEEL_CHEMICAL, 0, v.Frequency)
|
|
|
- if edbRefreshDefaultConfig, ok := refreshDataNumMap[key]; ok {
|
|
|
- if edbRefreshDefaultConfig.RefreshAllData == 1 { // 刷新所有数据期数
|
|
|
- dataRefreshNum = 0
|
|
|
- } else if edbRefreshDefaultConfig.RefreshDataNum > 0 { //
|
|
|
- dataRefreshNum = edbRefreshDefaultConfig.RefreshDataNum
|
|
|
- }
|
|
|
- }
|
|
|
- tmpConf.EdbCode = v.IndexCode
|
|
|
- tmpConf.EdbName = v.IndexName
|
|
|
- tmpConf.Source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
|
|
|
- tmpConf.Frequency = v.Frequency
|
|
|
- tmpConf.Unit = v.Unit
|
|
|
- tmpConf.StartDate, err = time.Parse(utils.FormatDate, v.StartDate)
|
|
|
- tmpConf.EndDate, err = time.Parse(utils.FormatDate, v.EndDate)
|
|
|
- tmpConf.ClassifyId = int(v.BaseFromMysteelChemicalClassifyId)
|
|
|
- tmpConf.DataRefreshNum = dataRefreshNum
|
|
|
- tmpConf.EdbInfoId = v.EdbInfoId
|
|
|
- indexList = append(indexList, tmpConf)
|
|
|
- }
|
|
|
-
|
|
|
- key := fmt.Sprint(source, "_", subSource)
|
|
|
- sourceEdbInfoListMap[key] = indexList
|
|
|
- }
|
|
|
+ for subSource, frequencyList := range subSourceFrequencyListMap {
|
|
|
+ edbList, tmpErr := edb_refresh.GetDefaultRefreshEdbInfoListBySourceAndSubSource(source, subSource, frequencyList)
|
|
|
+ if tmpErr != nil {
|
|
|
+ errMsgList = append(errMsgList, fmt.Sprint("source:", source, "subSource:", subSource, "frequencyList:", strings.Join(frequencyList, ","), "err:", tmpErr.Error()))
|
|
|
}
|
|
|
- // 其他情况不处理
|
|
|
- default:
|
|
|
- for subSource, frequencyList := range subSourceFrequencyListMap {
|
|
|
- edbList, tmpErr := edb_refresh.GetDefaultRefreshEdbInfoListBySourceAndSubSource(source, subSource, frequencyList)
|
|
|
- if tmpErr != nil {
|
|
|
- errMsgList = append(errMsgList, fmt.Sprint("source:", source, "subSource:", subSource, "frequencyList:", strings.Join(frequencyList, ","), "err:", tmpErr.Error()))
|
|
|
- }
|
|
|
|
|
|
- for _, v := range edbList {
|
|
|
- // 数据刷新的期数
|
|
|
- dataRefreshNum := utils.DATA_REFRESH
|
|
|
- key := fmt.Sprintf("%d_%d_%s", v.Source, v.SubSource, v.Frequency)
|
|
|
- if edbRefreshDefaultConfig, ok := refreshDataNumMap[key]; ok {
|
|
|
- if edbRefreshDefaultConfig.RefreshAllData == 1 { // 刷新所有数据期数
|
|
|
- dataRefreshNum = 0
|
|
|
- } else if edbRefreshDefaultConfig.RefreshDataNum > 0 { //
|
|
|
- dataRefreshNum = edbRefreshDefaultConfig.RefreshDataNum
|
|
|
- }
|
|
|
+ for _, v := range edbList {
|
|
|
+ // 数据刷新的期数
|
|
|
+ dataRefreshNum := utils.DATA_REFRESH
|
|
|
+ key := fmt.Sprintf("%d_%d_%s", v.Source, v.SubSource, v.Frequency)
|
|
|
+ if edbRefreshDefaultConfig, ok := refreshDataNumMap[key]; ok {
|
|
|
+ if edbRefreshDefaultConfig.RefreshAllData == 1 { // 刷新所有数据期数
|
|
|
+ dataRefreshNum = 0
|
|
|
+ } else if edbRefreshDefaultConfig.RefreshDataNum > 0 { //
|
|
|
+ dataRefreshNum = edbRefreshDefaultConfig.RefreshDataNum
|
|
|
}
|
|
|
- v.DataRefreshNum = dataRefreshNum
|
|
|
}
|
|
|
-
|
|
|
- key := fmt.Sprint(source, "_", subSource)
|
|
|
- sourceEdbInfoListMap[key] = edbList
|
|
|
+ v.DataRefreshNum = dataRefreshNum
|
|
|
}
|
|
|
+
|
|
|
+ key := fmt.Sprint(source, "_", subSource)
|
|
|
+ sourceEdbInfoListMap[key] = edbList
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -272,7 +228,6 @@ func getConfigRefreshData(now time.Time) (sourceEdbInfoListMap map[string][]*edb
|
|
|
fmt.Println(err)
|
|
|
}
|
|
|
}()
|
|
|
- // 一期是只做wind、同花顺、钢联、有色
|
|
|
|
|
|
sourceEdbInfoListMap = make(map[string][]*edb_refresh.EdbInfoListAndRefreshConfig)
|
|
|
|
|
@@ -311,26 +266,26 @@ func getConfigRefreshData(now time.Time) (sourceEdbInfoListMap map[string][]*edb
|
|
|
configIdList = append(configIdList, v.EdbRefreshConfigId)
|
|
|
configIdEdbRefreshConfigMap[v.EdbRefreshConfigId] = v
|
|
|
}
|
|
|
- conf, err := models.GetBusinessConf()
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- return
|
|
|
- }
|
|
|
+ //conf, err := models.GetBusinessConf()
|
|
|
+ //if err != nil {
|
|
|
+ // fmt.Println(err)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
|
|
|
// 获取钢联化工的数据获取方式
|
|
|
- mySteelChemicalDataMethod := "excel"
|
|
|
- if v, ok := conf["MySteelDataMethod"]; ok {
|
|
|
- if v == "api" {
|
|
|
- mySteelChemicalDataMethod = v
|
|
|
- }
|
|
|
- }
|
|
|
+ //mySteelChemicalDataMethod := "excel"
|
|
|
+ //if v, ok := conf["MySteelDataMethod"]; ok {
|
|
|
+ // if v == "api" {
|
|
|
+ // mySteelChemicalDataMethod = v
|
|
|
+ // }
|
|
|
+ //}
|
|
|
// 当钢联的数据获取方式是api时,不用过滤
|
|
|
var sourceList []int
|
|
|
- if mySteelChemicalDataMethod == "api" {
|
|
|
- sourceList = []int{utils.DATA_SOURCE_YS}
|
|
|
- } else {
|
|
|
- sourceList = []int{utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_YS}
|
|
|
- }
|
|
|
+ //if mySteelChemicalDataMethod == "api" {
|
|
|
+ // sourceList = []int{utils.DATA_SOURCE_YS}
|
|
|
+ //} else {
|
|
|
+ // sourceList = []int{utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_YS}
|
|
|
+ //}
|
|
|
edbInfoList, err := edb_refresh.GetConfigRefreshEdbInfoListBySourceAndSubSource(sourceList, configIdList)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -383,110 +338,54 @@ func BaseRefreshData(wg *sync.WaitGroup, source, subSource int, items []*edb_ref
|
|
|
// 数据刷新的期数
|
|
|
dataRefreshNum := utils.DATA_REFRESH
|
|
|
// 是否从最开始的日期更新
|
|
|
- var isRefreshByStartDate bool
|
|
|
-
|
|
|
- if source != utils.DATA_SOURCE_THS {
|
|
|
- for _, v := range items {
|
|
|
- // 如果暂停更新,那就过滤
|
|
|
- if v.NoUpdate == 1 {
|
|
|
- continue
|
|
|
- }
|
|
|
- if v.DataRefreshNum > 0 {
|
|
|
- dataRefreshNum = v.DataRefreshNum
|
|
|
- }
|
|
|
-
|
|
|
- startDate := ""
|
|
|
- if isRefreshByStartDate {
|
|
|
- startDate = v.StartDate.Format(utils.FormatDate)
|
|
|
- } else {
|
|
|
- if v.Frequency == "日度" {
|
|
|
- startDate = v.EndDate.AddDate(0, 0, -dataRefreshNum).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "周度" {
|
|
|
- startDate = v.EndDate.AddDate(0, 0, -(dataRefreshNum * 7)).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "旬度" {
|
|
|
- startDate = v.EndDate.AddDate(0, 0, -(dataRefreshNum * 10)).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "月度" {
|
|
|
- startDate = v.EndDate.AddDate(0, -dataRefreshNum, 0).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "季度" {
|
|
|
- startDate = v.EndDate.AddDate(0, -dataRefreshNum*3, 0).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "半年度" {
|
|
|
- startDate = v.EndDate.AddDate(0, -dataRefreshNum*6, 0).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "年度" {
|
|
|
- startDate = v.EndDate.AddDate(-dataRefreshNum, 0, 0).Format(utils.FormatDate)
|
|
|
- } else {
|
|
|
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
|
|
|
- }
|
|
|
- }
|
|
|
- fmt.Println(startDate)
|
|
|
+ //var isRefreshByStartDate bool
|
|
|
|
|
|
- // 数据更新
|
|
|
- resp, tmpErr := data.RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
|
|
|
- if tmpErr != nil {
|
|
|
- errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+tmpErr.Error())
|
|
|
- continue
|
|
|
- }
|
|
|
- if resp.Ret != 200 {
|
|
|
- errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
|
|
|
- continue
|
|
|
- }
|
|
|
+ for _, v := range items {
|
|
|
+ // 如果暂停更新,那就过滤
|
|
|
+ if v.NoUpdate == 1 {
|
|
|
+ continue
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // 同花顺控制速率, 每秒最多4次请求(同花顺EDB函数限制为5, 考虑到可能存在用户同时在使用, 这里批量刷新设置为4, 话说5确实是有点少了吧=_=!)
|
|
|
- if source == utils.DATA_SOURCE_THS {
|
|
|
- ticker := time.NewTicker(250 * time.Millisecond)
|
|
|
- defer ticker.Stop()
|
|
|
-
|
|
|
- for _, v := range items {
|
|
|
- <-ticker.C
|
|
|
-
|
|
|
- // 如果暂停更新,那就过滤
|
|
|
- if v.NoUpdate == 1 {
|
|
|
- continue
|
|
|
- }
|
|
|
- if v.DataRefreshNum > 0 {
|
|
|
- dataRefreshNum = v.DataRefreshNum
|
|
|
- }
|
|
|
-
|
|
|
- startDate := ""
|
|
|
- if isRefreshByStartDate {
|
|
|
- startDate = v.StartDate.Format(utils.FormatDate)
|
|
|
- } else {
|
|
|
- if v.Frequency == "日度" {
|
|
|
- startDate = v.EndDate.AddDate(0, 0, -dataRefreshNum).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "周度" {
|
|
|
- startDate = v.EndDate.AddDate(0, 0, -(dataRefreshNum * 7)).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "旬度" {
|
|
|
- startDate = v.EndDate.AddDate(0, 0, -(dataRefreshNum * 10)).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "月度" {
|
|
|
- startDate = v.EndDate.AddDate(0, -dataRefreshNum, 0).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "季度" {
|
|
|
- startDate = v.EndDate.AddDate(0, -dataRefreshNum*3, 0).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "半年度" {
|
|
|
- startDate = v.EndDate.AddDate(0, -dataRefreshNum*6, 0).Format(utils.FormatDate)
|
|
|
- } else if v.Frequency == "年度" {
|
|
|
- startDate = v.EndDate.AddDate(-dataRefreshNum, 0, 0).Format(utils.FormatDate)
|
|
|
- } else {
|
|
|
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
|
|
|
- }
|
|
|
- }
|
|
|
- fmt.Println(startDate)
|
|
|
+ if v.DataRefreshNum > 0 {
|
|
|
+ dataRefreshNum = v.DataRefreshNum
|
|
|
+ }
|
|
|
+
|
|
|
+ startDate := ""
|
|
|
+ //if isRefreshByStartDate {
|
|
|
+ // startDate = v.StartDate.Format(utils.FormatDate)
|
|
|
+ //} else {
|
|
|
+ if v.Frequency == "日度" {
|
|
|
+ startDate = v.EndDate.AddDate(0, 0, -dataRefreshNum).Format(utils.FormatDate)
|
|
|
+ } else if v.Frequency == "周度" {
|
|
|
+ startDate = v.EndDate.AddDate(0, 0, -(dataRefreshNum * 7)).Format(utils.FormatDate)
|
|
|
+ } else if v.Frequency == "旬度" {
|
|
|
+ startDate = v.EndDate.AddDate(0, 0, -(dataRefreshNum * 10)).Format(utils.FormatDate)
|
|
|
+ } else if v.Frequency == "月度" {
|
|
|
+ startDate = v.EndDate.AddDate(0, -dataRefreshNum, 0).Format(utils.FormatDate)
|
|
|
+ } else if v.Frequency == "季度" {
|
|
|
+ startDate = v.EndDate.AddDate(0, -dataRefreshNum*3, 0).Format(utils.FormatDate)
|
|
|
+ } else if v.Frequency == "半年度" {
|
|
|
+ startDate = v.EndDate.AddDate(0, -dataRefreshNum*6, 0).Format(utils.FormatDate)
|
|
|
+ } else if v.Frequency == "年度" {
|
|
|
+ startDate = v.EndDate.AddDate(-dataRefreshNum, 0, 0).Format(utils.FormatDate)
|
|
|
+ } else {
|
|
|
+ startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ //}
|
|
|
+ fmt.Println(startDate)
|
|
|
|
|
|
- // 数据更新
|
|
|
- resp, tmpErr := data.RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
|
|
|
- if tmpErr != nil {
|
|
|
- errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+tmpErr.Error())
|
|
|
- continue
|
|
|
- }
|
|
|
- if resp.Ret != 200 {
|
|
|
- errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
|
|
|
- continue
|
|
|
- }
|
|
|
+ // 数据更新
|
|
|
+ resp, tmpErr := data.RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ errMsgList = append(errMsgList, v.EdbCode+"RefreshEdbData Err:"+tmpErr.Error())
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if resp.Ret != 200 {
|
|
|
+ errMsgList = append(errMsgList, v.EdbCode+";RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
|
|
|
+ continue
|
|
|
}
|
|
|
}
|
|
|
|
|
|
fmt.Println("来源:", source, ";子来源:", subSource, "刷新结束")
|
|
|
-
|
|
|
return err
|
|
|
}
|
|
|
|
|
@@ -873,3 +772,48 @@ func DisableEdbRefresh(cont context.Context) (err error) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// ConfigRefreshDataGn 根据配置刷新指标数据
|
|
|
+func ConfigRefreshDataGn(cont context.Context) (err error) {
|
|
|
+ errMsgList := make([]string, 0)
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ now := time.Now()
|
|
|
+ //now = time.Date(2023, 12, 31, 16, 50, 59, 0, time.Local)
|
|
|
+ defaultSourceEdbInfoListMap, err := getDefaultRefreshData(now)
|
|
|
+ if err != nil {
|
|
|
+ errMsgList = append(errMsgList, "获取默认刷新数据失败,Err:"+err.Error())
|
|
|
+ }
|
|
|
+ sourceEdbInfoListMap, err := getConfigRefreshData(now)
|
|
|
+ if err != nil {
|
|
|
+ errMsgList = append(errMsgList, "获取指标配置刷新数据失败,Err:"+err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将两个合并
|
|
|
+ allSourceEdbInfoListMap := mergeMaps(defaultSourceEdbInfoListMap, sourceEdbInfoListMap)
|
|
|
+ wgNum := len(allSourceEdbInfoListMap)
|
|
|
+ if wgNum <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ wg := sync.WaitGroup{}
|
|
|
+ wg.Add(wgNum)
|
|
|
+
|
|
|
+ for _, edbList := range allSourceEdbInfoListMap {
|
|
|
+ if edbList == nil {
|
|
|
+ wg.Done()
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if len(edbList) != 0 {
|
|
|
+ go BaseRefreshData(&wg, edbList[0].Source, edbList[0].SubSource, edbList)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ wg.Wait()
|
|
|
+
|
|
|
+ fmt.Println("Refresh End")
|
|
|
+ return
|
|
|
+}
|