From 1873461012c99801f364bd07fae2c218d245048e Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期一, 11 九月 2023 19:42:39 +0800
Subject: [PATCH] 修复bom第一启动时的全量上报

---
 report/send.go |   79 +++++++++++++++------------------------
 1 files changed, 30 insertions(+), 49 deletions(-)

diff --git a/report/send.go b/report/send.go
index f495445..13e7af0 100644
--- a/report/send.go
+++ b/report/send.go
@@ -143,31 +143,57 @@
 
 // bom鏁版嵁鍒哹om鍜宐omChild涓や釜琛�
 func SendBom(fData bool) {
+	var bomList []kingdee.ICBom
+	var bomChildList []kingdee.ICBomChild
+
+	// 绗竴娆″惎鍔�, 涓婃姤鍏ㄩ噺
+	if len(bomReportedCache) == 0 {
+		fData = true
+	}
+
 	// 涓婃姤bom
-	bomList := kingdee.BomList(fData)
+	bomList = kingdee.BomList(fData)
 	logger.Debug("鏌ヨ鍒�%d鏉OM鏁版嵁", len(bomList))
 
 	// 杩囨护鏁版嵁, 鍒ゆ柇鏄惁宸茬粡涓婃姤杩�, 璇锋眰鍏ㄩ噺鏁版嵁涓嶈繃婊�, 鐩存帴涓婃姤
 	if !fData {
+		var bomNumbers []string
 		for i := 0; i < len(bomList); {
 			cacheKey := bomList[i].FBOMNumber + bomList[i].FAudDate
 			if _, ok := bomReportedCache[cacheKey]; ok {
 				bomList = append(bomList[:i], bomList[i+1:]...)
 			} else {
 				bomReportedCache[cacheKey] = struct{}{}
+				bomNumbers = append(bomNumbers, bomList[i].FBOMNumber)
 				i++
 			}
 		}
+		if len(bomNumbers) > 0 {
+			bomChildList = kingdee.BomChild(bomNumbers)
+		}
+	} else {
+		bomChildList = kingdee.BomChild(nil)
 	}
 
 	// 鍒嗙粍涓婁紶bom鏁版嵁
 	if len(bomList) == 0 {
 		logger.Debug("娌℃湁瑕佹洿鏂扮殑BOM鏁版嵁.")
 	} else {
-		// 姣忔鍙� 1000 鏉�
+		// 灏哹om缁勪欢鎸塨omId鏁寸悊
+		var bomChildMap = make(map[int][]kingdee.ICBomChild, 0)
+		for idx, bomChild := range bomChildList {
+			bomChildMap[bomChild.FInterID] = append(bomChildMap[bomChild.FInterID], bomChildList[idx])
+		}
+
+		// 缁檅om娣诲姞缁勪欢
+		for idx, bom := range bomList {
+			bomList[idx].Component = bomChildMap[bom.FInterID]
+		}
+
+		// 姣忔鍙� 200 鏉�
 		successCnt := 0
-		for i := 0; i < len(bomList); i += 1000 {
-			end := i + 1000
+		for i := 0; i < len(bomList); i += 200 {
+			end := i + 200
 			if end > len(bomList) {
 				end = len(bomList)
 			}
@@ -190,49 +216,4 @@
 
 		logger.Debug("宸蹭笂鎶�%d鏉OM鏁版嵁", successCnt)
 	}
-
-	// 涓婃姤bom瀛愰」
-	var bomChildList []kingdee.ICBomChild
-
-	// 濡傛灉璇锋眰鍏ㄩ噺鏁版嵁, 鐩存帴鏌ヨ鎵�鏈夌殑鏁版嵁骞跺彂閫�. 澧為噺涓婃姤, 鍏堝垽鏂璪om鏄惁鏈夋洿鏂�,鐒跺悗鎸塨om缂栫爜鏌ヨ瀛愰」
-	if fData {
-		bomChildList = kingdee.BomChild(nil)
-	} else {
-		if len(bomList) <= 0 {
-			return
-		}
-
-		var bomIds []string
-		for _, v := range bomList {
-			bomIds = append(bomIds, v.FBOMNumber)
-		}
-
-		bomChildList = kingdee.BomChild(bomIds)
-	}
-
-	logger.Debug("鏌ヨ鍒�%d鏉OM瀛愰」鏁版嵁", len(bomList))
-
-	if len(bomChildList) == 0 {
-		logger.Debug("娌℃湁瑕佹洿鏂扮殑BOM瀛愰」鏁版嵁.")
-		return
-	}
-
-	// 姣忔鍙� 1000 鏉�
-	successCnt := 0
-	for i := 0; i < len(bomChildList); i += 1000 {
-		end := i + 1000
-		if end > len(bomChildList) {
-			end = len(bomChildList)
-		}
-
-		b, _ := json.Marshal(bomChildList[i:end])
-
-		ok := nsqclient.Produce(config.Options.BomChildTopic, b)
-		if !ok {
-			logger.Warn("BOM鏁版嵁涓婃姤澶辫触")
-		} else {
-			successCnt = end
-		}
-	}
-	logger.Debug("宸蹭笂鎶�%d鏉OM瀛愰」鏁版嵁", successCnt)
 }

--
Gitblit v1.8.0