From d9bc2c9e991b2fe925565dfd7d0ec667b64bb52f Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期四, 17 八月 2023 16:01:02 +0800 Subject: [PATCH] 完成bom上报 --- report/send.go | 73 +++++++++++++----------------------- 1 files changed, 27 insertions(+), 46 deletions(-) diff --git a/report/send.go b/report/send.go index c51e58d..aadd06b 100644 --- a/report/send.go +++ b/report/send.go @@ -2,7 +2,6 @@ import ( "encoding/json" - "io/ioutil" "time" "kingdee-dbapi/cache" @@ -144,34 +143,52 @@ // bom鏁版嵁鍒哹om鍜宐omChild涓や釜琛� func SendBom(fData bool) { - // 涓婃姤bom - bomList := kingdee.BomList(fData) - logger.Debug("鏌ヨ鍒�%d鏉om鏁版嵁", len(bomList)) + var bomList []kingdee.ICBom + var bomChildList []kingdee.ICBomChild - b, _ := json.Marshal(bomList) - ioutil.WriteFile("bomList.tmp", b, 0644) + // 涓婃姤bom + 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) } @@ -191,43 +208,7 @@ successCnt = end } } + logger.Debug("宸蹭笂鎶�%d鏉OM鏁版嵁", successCnt) - } - - // 涓婃姤bom瀛愰」 - var bomChildList []kingdee.ICBomChild - - // 濡傛灉璇锋眰鍏ㄩ噺鏁版嵁, 鐩存帴鏌ヨ鎵�鏈夌殑鏁版嵁骞跺彂閫�. 澧為噺涓婃姤, 鍏堝垽鏂璪om鏄惁鏈夋洿鏂�,鐒跺悗鎸塨om缂栫爜鏌ヨ瀛愰」 - if fData { - bomChildList = kingdee.BomChild(nil) - b, _ := json.Marshal(bomChildList) - ioutil.WriteFile("bomChdList.tmp", b, 0644) - } else { - if len(bomList) <= 0 { - return - } - } - - if len(bomChildList) == 0 { - logger.Debug("娌℃湁瑕佹洿鏂扮殑BOM瀛愰」鏁版嵁.") - } else { - // 姣忔鍙� 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