Jelajahi Sumber

style:优化错误信息记录

Roc 1 tahun lalu
induk
melakukan
73dc7ccb42
1 mengubah file dengan 66 tambahan dan 56 penghapusan
  1. 66 56
      services/init_base_index.go

+ 66 - 56
services/init_base_index.go

@@ -1034,6 +1034,9 @@ func InitDataToEdbInfo(filePath string) {
 		}
 	}
 
+	//successIndexList := make([]string, 0)
+	errorIndexList := make([]string, 0)
+
 	for rk, row := range rows {
 		if rk > 0 {
 			var classifyFirst, classifySecond, classifyThree, classifyFourth, classifyFifth, classifySixth, indexCode, indexName, frequency, unit, source, mobile, terminalCode string
@@ -1071,32 +1074,32 @@ func InitDataToEdbInfo(filePath string) {
 
 			// 校验excel文件内容
 			{
-				errMsgList := make([]string, 0)
+				tmpErrMsgList := make([]string, 0)
 				if classifyFirst == "" {
-					errMsgList = append(errMsgList, `一级目录不允许为空`)
+					tmpErrMsgList = append(tmpErrMsgList, `一级目录不允许为空`)
 				}
 				if indexCode == "" {
-					errMsgList = append(errMsgList, `指标编码不允许为空`)
+					tmpErrMsgList = append(tmpErrMsgList, `指标编码不允许为空`)
 				}
 				if indexName == "" {
-					errMsgList = append(errMsgList, `指标名称不允许为空`)
+					tmpErrMsgList = append(tmpErrMsgList, `指标名称不允许为空`)
 				}
 				if frequency == "" {
-					errMsgList = append(errMsgList, `频度不允许为空`)
+					tmpErrMsgList = append(tmpErrMsgList, `频度不允许为空`)
 				}
 				if unit == "" {
-					errMsgList = append(errMsgList, `单位不允许为空`)
+					tmpErrMsgList = append(tmpErrMsgList, `单位不允许为空`)
 				}
 				if source == "" {
-					errMsgList = append(errMsgList, `指标来源不允许为空`)
+					tmpErrMsgList = append(tmpErrMsgList, `指标来源不允许为空`)
 				}
 				if terminalCode == "" {
-					errMsgList = append(errMsgList, `终端号不允许为空`)
+					tmpErrMsgList = append(tmpErrMsgList, `终端号不允许为空`)
 				}
 
 				// 如果有错误信息,那么就不继续执行
-				if len(errMsgList) > 0 {
-					fmt.Println(strings.Join(errMsgList, ";"))
+				if len(tmpErrMsgList) > 0 {
+					fmt.Println(strings.Join(tmpErrMsgList, ";"))
 					fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source, terminalCode)
 					continue
 				}
@@ -1128,6 +1131,7 @@ func InitDataToEdbInfo(filePath string) {
 					}
 				}
 
+				// 开始添加分类
 				var firstId, secondId, thirdId, fourthId, fifthId, lastId int
 				method := "classify/get_or_add"
 				classifyFirstMap := make(map[string]interface{})
@@ -1137,17 +1141,17 @@ func InitDataToEdbInfo(filePath string) {
 				classifyFirstMap["ClassifyType"] = 0
 				result, e := PostEdbLib(classifyFirstMap, method)
 				if e != nil {
-					err = fmt.Errorf("ClassifyFirst PostEdbLib err: %s", e.Error())
-					return
+					errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFirst PostEdbLib err: %s", indexCode, e.Error()))
+					continue
 				}
 				resp := new(models.ClassifyResp)
 				if e = json.Unmarshal(result, &resp); e != nil {
-					err = fmt.Errorf("ClassifyFirst json unmarshal err: %s", e.Error())
-					return
+					errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFirst json unmarshal err: %s", indexCode, e.Error()))
+					continue
 				}
 				if resp.Ret != 200 {
-					err = fmt.Errorf("ClassifyFirst resp msg: %s; errMsg: %s", resp.Msg, resp.ErrMsg)
-					return
+					errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFirst resp msg: %s; errMsg: %s", indexCode, resp.Msg, resp.ErrMsg))
+					continue
 				}
 				firstId = resp.Data.ClassifyId
 				lastId = firstId
@@ -1161,17 +1165,17 @@ func InitDataToEdbInfo(filePath string) {
 					classifySecondMap["ClassifyType"] = 0
 					res2, e := PostEdbLib(classifySecondMap, method)
 					if e != nil {
-						err = fmt.Errorf("ClassifySecond PostEdbLib err: %s", e.Error())
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySecond PostEdbLib err: %s", indexCode, e.Error()))
+						continue
 					}
 					resp2 := new(models.ClassifyResp)
 					if e = json.Unmarshal(res2, &resp2); e != nil {
-						err = fmt.Errorf("ClassifySecond json unmarshal err: %s", e.Error())
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySecond json unmarshal err: %s", indexCode, e.Error()))
+						continue
 					}
 					if resp2.Ret != 200 {
-						err = fmt.Errorf("ClassifySecond resp msg: %s; errMsg: %s", resp2.Msg, resp2.ErrMsg)
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySecond resp msg: %s; errMsg: %s", indexCode, resp2.Msg, resp2.ErrMsg))
+						continue
 					}
 					secondId = resp2.Data.ClassifyId
 					lastId = secondId
@@ -1186,17 +1190,17 @@ func InitDataToEdbInfo(filePath string) {
 					classifyThreeMap["ClassifyType"] = 0
 					res3, e := PostEdbLib(classifyThreeMap, method)
 					if e != nil {
-						err = fmt.Errorf("ClassifyThird PostEdbLib err: %s", e.Error())
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySecond ClassifyThird err: %s", indexCode, e.Error()))
+						continue
 					}
 					resp3 := new(models.ClassifyResp)
 					if e = json.Unmarshal(res3, &resp3); e != nil {
-						err = fmt.Errorf("ClassifyThird json unmarshal err: %s", e.Error())
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyThird json unmarshal err: %s", indexCode, e.Error()))
+						continue
 					}
 					if resp3.Ret != 200 {
-						err = fmt.Errorf("ClassifyThird resp msg: %s; errMsg: %s", resp3.Msg, resp3.ErrMsg)
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyThird resp msg: %s; errMsg: %s", indexCode, resp3.Msg, resp3.ErrMsg))
+						continue
 					}
 					thirdId = resp3.Data.ClassifyId
 					lastId = thirdId
@@ -1211,17 +1215,17 @@ func InitDataToEdbInfo(filePath string) {
 					classifyFourthMap["ClassifyType"] = 0
 					res4, e := PostEdbLib(classifyFourthMap, method)
 					if e != nil {
-						err = fmt.Errorf("ClassifyFourth PostEdbLib err: %s", e.Error())
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFourth ClassifyThird err: %s", indexCode, e.Error()))
+						continue
 					}
 					resp4 := new(models.ClassifyResp)
 					if e = json.Unmarshal(res4, &resp4); e != nil {
-						err = fmt.Errorf("ClassifyFourth json unmarshal err: %s", e.Error())
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFourth json unmarshal err: %s", indexCode, e.Error()))
+						continue
 					}
 					if resp4.Ret != 200 {
-						err = fmt.Errorf("ClassifyFourth resp msg: %s; errMsg: %s", resp4.Msg, resp4.ErrMsg)
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFourth resp msg: %s; errMsg: %s", indexCode, resp4.Msg, resp4.ErrMsg))
+						continue
 					}
 					fourthId = resp4.Data.ClassifyId
 					lastId = fourthId
@@ -1236,17 +1240,17 @@ func InitDataToEdbInfo(filePath string) {
 					classifyFifthMap["ClassifyType"] = 0
 					res5, e := PostEdbLib(classifyFifthMap, method)
 					if e != nil {
-						err = fmt.Errorf("ClassifyFifth PostEdbLib err: %s", e.Error())
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFifth ClassifyThird err: %s", indexCode, e.Error()))
+						continue
 					}
 					resp5 := new(models.ClassifyResp)
 					if e = json.Unmarshal(res5, &resp5); e != nil {
-						err = fmt.Errorf("ClassifyFifth json unmarshal err: %s", e.Error())
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFifth json unmarshal err: %s", indexCode, e.Error()))
+						continue
 					}
 					if resp5.Ret != 200 {
-						err = fmt.Errorf("ClassifyFifth resp msg: %s; errMsg: %s", resp5.Msg, resp5.ErrMsg)
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifyFifth resp msg: %s; errMsg: %s", indexCode, resp5.Msg, resp5.ErrMsg))
+						continue
 					}
 					fifthId = resp5.Data.ClassifyId
 					lastId = fifthId
@@ -1261,17 +1265,17 @@ func InitDataToEdbInfo(filePath string) {
 					classifySixthMap["ClassifyType"] = 0
 					res6, e := PostEdbLib(classifySixthMap, method)
 					if e != nil {
-						err = fmt.Errorf("ClassifySixth PostEdbLib err: %s", e.Error())
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySixth ClassifyThird err: %s", indexCode, e.Error()))
+						continue
 					}
 					resp6 := new(models.ClassifyResp)
 					if e = json.Unmarshal(res6, &resp6); e != nil {
-						err = fmt.Errorf("ClassifySixth json unmarshal err: %s", e.Error())
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySixth json unmarshal err: %s", indexCode, e.Error()))
+						continue
 					}
 					if resp6.Ret != 200 {
-						err = fmt.Errorf("ClassifySixth resp msg: %s; errMsg: %s", resp6.Msg, resp6.ErrMsg)
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,ClassifySixth resp msg: %s; errMsg: %s", indexCode, resp6.Msg, resp6.ErrMsg))
+						continue
 					}
 					lastId = resp6.Data.ClassifyId
 				}
@@ -1280,8 +1284,7 @@ func InitDataToEdbInfo(filePath string) {
 				method = "edb_info/add"
 				sourceId, ok := IndexSourceMap[source]
 				if !ok {
-					fmt.Println("source is not defined")
-					fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source)
+					errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,来源未定义:%s", indexCode, source))
 					continue
 				}
 				indexMap := make(map[string]interface{})
@@ -1299,24 +1302,26 @@ func InitDataToEdbInfo(filePath string) {
 				}
 				result, err = PostEdbLib(indexMap, method)
 				if err != nil {
+					errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,初始化指标失败:%s ;result:%s", indexCode, err.Error(), string(result)))
 					utils.FileLog.Info("初始化指标失败:" + err.Error() + " result:" + string(result))
-					return
+					continue
 				}
 
 				indexResp := new(models.EdbInfoResp)
 				err = json.Unmarshal(result, &indexResp)
 				if err != nil {
-					utils.FileLog.Info("初始化分类2失败:" + err.Error())
-					return
+					errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,初始化指标2失败:%s", indexCode, err.Error()))
+					utils.FileLog.Info("初始化指标2失败:" + err.Error())
+					continue
 				}
 
 				if indexResp.Ret != 200 {
 					if strings.Contains(indexResp.Msg, "新增指标失败") {
 						continue
 					} else {
-						fmt.Println("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
-						utils.FileLog.Info("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
-						return
+						errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,初始化指标3失败:%s;%s", indexCode, indexResp.Msg, indexResp.ErrMsg))
+						utils.FileLog.Info("初始化指标3失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
+						continue
 					}
 				}
 				fmt.Println("add index success:" + indexCode)
@@ -1324,8 +1329,8 @@ func InitDataToEdbInfo(filePath string) {
 				//刷新指标
 				method, ok = IndexSourceRefreshMap[sourceId]
 				if !ok {
-					fmt.Println("source refresh path is not defined")
-					fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source)
+					errorIndexList = append(errorIndexList, fmt.Sprintf("指标编码:%s,刷新地址未定义:%s;", indexCode, source))
+					//fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source)
 					continue
 				}
 				refreshMap := make(map[string]interface{})
@@ -1336,6 +1341,11 @@ func InitDataToEdbInfo(filePath string) {
 			}
 		}
 	}
+
+	if len(errorIndexList) > 0 {
+		fmt.Println("初始化指标失败列表:\n" + strings.Join(errorIndexList, "\n"))
+		utils.FileLog.Info("初始化指标失败列表:\n" + strings.Join(errorIndexList, "\n"))
+	}
 }
 
 // VerifyMysteelIndex