From dc40143800edd914d0f721b06f90c8b4d307b979 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期四, 17 八月 2023 15:46:19 +0800 Subject: [PATCH] 调整bom --- report/send.go | 115 ++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 69 insertions(+), 46 deletions(-) diff --git a/report/send.go b/report/send.go index f495445..35a6311 100644 --- a/report/send.go +++ b/report/send.go @@ -2,6 +2,7 @@ import ( "encoding/json" + "io/ioutil" "time" "kingdee-dbapi/cache" @@ -143,27 +144,48 @@ // bom鏁版嵁鍒哹om鍜宐omChild涓や釜琛� func SendBom(fData bool) { + var bomList []kingdee.ICBom + var bomChildList []kingdee.ICBomChild + // 涓婃姤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 { + // 灏哹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 _, bom := range bomList { + bom.Component = bomChildMap[bom.FInterID] + } + // 姣忔鍙� 1000 鏉� successCnt := 0 for i := 0; i < len(bomList); i += 1000 { @@ -173,6 +195,8 @@ } b, _ := json.Marshal(bomList[i:end]) + + ioutil.WriteFile("bomList.tmp", b, 0644) ok := nsqclient.Produce(config.Options.BomTopic, b) if !ok { @@ -190,49 +214,48 @@ 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) + // + //// 涓婃姤bom瀛愰」 + // + //// 濡傛灉璇锋眰鍏ㄩ噺鏁版嵁, 鐩存帴鏌ヨ鎵�鏈夌殑鏁版嵁骞跺彂閫�. 澧為噺涓婃姤, 鍏堝垽鏂璪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