Browse Source

优化eta_bridge服务中的指标同步逻辑

- 调整了指标列表响应结构,将"Paging"字段改为"Page"
- 在指标信息中添加了"SourceCode"字段,用于存储来源编码
- 修改了获取来源的逻辑,支持通过来源编码确定数据来源
- 调整了任务调度中的初始化逻辑,从SyncGnUser改为SyncGnIndex
Roc 5 months ago
parent
commit
bacdcc094b
2 changed files with 24 additions and 19 deletions
  1. 23 18
      services/eta_bridge/gn.go
  2. 1 1
      services/task_gn.go

+ 23 - 18
services/eta_bridge/gn.go

@@ -159,8 +159,8 @@ type EtaBridgeGnIndexListResp struct {
 // IndexListResp
 // @Description: 指标列表数据
 type IndexListResp struct {
-	Paging paging.PagingItem `description:"分页数据"`
-	List   []IndexInfo
+	Page paging.PagingItem `description:"分页数据"`
+	List []IndexInfo
 }
 
 // IndexInfo
@@ -175,6 +175,7 @@ type IndexInfo struct {
 	Frequency         string `description:"频度"`
 	Unit              string `description:"单位"`
 	SourceName        string `description:"来源"`
+	SourceCode        string `description:"来源编码"`
 }
 
 // BridgeGnIndexParams
@@ -232,9 +233,9 @@ func syncGnIndex(currIndex, pageSize int, baseLastUpdateTimeStr string) (err err
 		}
 	}
 
-	fmt.Println(currIndex, "是否已结束:", result.Data.Paging.IsEnd)
+	fmt.Println(currIndex, "是否已结束:", result.Data.Page.IsEnd)
 	// 如果还有下一页,那么就继续请求下一页
-	if !result.Data.Paging.IsEnd {
+	if !result.Data.Page.IsEnd {
 		_, tmpErrMsgList := syncGnIndex(currIndex+1, utils.SyncCrmIndexNum, baseLastUpdateTimeStr)
 		errMsgList = append(errMsgList, tmpErrMsgList...)
 	}
@@ -499,13 +500,13 @@ func handleEdbInfo(index IndexInfo, thirdClassifyId int64) (err error) {
 	edbInfo, ok := CurrEdbInfoMap[index.DataIndexCode]
 	frequency := Frequency(strings.TrimSpace(index.Frequency))
 	unit := strings.TrimSpace(index.Unit)
-	sourceName, sourceId, err := GetSource(strings.TrimSpace(index.SourceName))
+	sourceName, sourceId, err := GetSource(strings.TrimSpace(index.SourceName), strings.TrimSpace(index.SourceCode))
 	if err != nil {
 		return
 	}
 
 	if !ok {
-		endDate := time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local)
+		endDate := time.Date(1899, 1, 1, 0, 0, 0, 0, time.Local)
 
 		timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
 
@@ -628,9 +629,10 @@ func Frequency(unit string) string {
 // @Description: 获取来源
 // @param sourceName
 // @return gnSourceName
+// @return sourceCode
 // @return source
 // @return err
-func GetSource(sourceName string) (gnSourceName string, source int, err error) {
+func GetSource(sourceName, sourceCode string) (gnSourceName string, source int, err error) {
 	gnSourceName = sourceName
 	var tableNameSuffix, indexNamePrefix string
 	tableNamePrefix := "edb_data_gn_"
@@ -647,16 +649,19 @@ func GetSource(sourceName string) (gnSourceName string, source int, err error) {
 		tableNameSuffix = "cci"
 		//return
 	default:
-		if strings.Contains(sourceName, "国能购销辅助决策系统") {
-			gnSourceName = `国能购销辅助决策系统`
-			tableNameSuffix = "purchase_sales"
-		} else if strings.Contains(sourceName, "国能市场分析平台") {
-			gnSourceName = `国能市场分析平台`
-			tableNameSuffix = "market_analysis"
-		} else {
-			// TODO 自动生成表名(暂时以时间作为表名后缀,如果客户提前告知了,那么可以直接先建data表,以及edb_source表写入新的source)
-			tableNameSuffix = fmt.Sprint(time.Now().Format(utils.FormatDateTimeUnSpace))
-		}
+		// 来源编码前缀把还是
+		tableNameSuffix = strings.ToLower(sourceCode)
+
+		//if strings.Contains(sourceName, "国能购销辅助决策系统") {
+		//	gnSourceName = `国能购销辅助决策系统`
+		//	tableNameSuffix = "purchase_sales"
+		//} else if strings.Contains(sourceName, "国能市场分析平台") {
+		//	gnSourceName = `国能市场分析平台`
+		//	tableNameSuffix = "market_analysis"
+		//} else {
+		//	// TODO 自动生成表名(暂时以时间作为表名后缀,如果客户提前告知了,那么可以直接先建data表,以及edb_source表写入新的source)
+		//	tableNameSuffix = fmt.Sprint(time.Now().Format(utils.FormatDateTimeUnSpace))
+		//}
 	}
 
 	sourceItem := data_manage.GetEdbSourceBySourceName(gnSourceName)
@@ -727,7 +732,7 @@ func syncGnIndexV2(currIndex, pageSize int, baseLastUpdateTimeStr string, indexI
 		}
 	}
 
-	fmt.Println(currIndex, "是否已结束:", result.Data.Paging.IsEnd)
+	fmt.Println(currIndex, "是否已结束:", result.Data.Page.IsEnd)
 	// 如果还有下一页,那么就继续请求下一页
 	//if !result.Data.Paging.IsEnd {
 	//	_, tmpErrMsgList := syncGnIndex(currIndex+1, utils.SyncCrmIndexNum, baseLastUpdateTimeStr)

+ 1 - 1
services/task_gn.go

@@ -9,7 +9,7 @@ import (
 
 func GnTask() {
 	// 初始化一次
-	fmt.Println(eta_bridge.SyncGnUser(nil))
+	fmt.Println(eta_bridge.SyncGnIndex(nil))
 
 	// 指标相关