#
cl
19 小时以前 6a40531396583fac35bd06e5e1b92433e5a56acf
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/CusBarcodeSyncMatnrService.java
@@ -159,8 +159,9 @@
                continue;
            }
            boolean viewHit = viewItems != null && CusBarcodeSyncViewQueryService.orderMatnrHitsBarcodeView(code, viewItems);
            log.info("[cus_barcode_sync] 本地无记录 code={} viewHit={} viewRowCount={}", code, viewHit,
                    viewItems == null ? 0 : viewItems.size());
            int viewRowCount = viewItems == null ? 0 : viewItems.size();
            log.info("[cus_barcode_sync] 本地无记录 code={} viewHit={} viewRowCount={}", code, viewHit, viewRowCount);
            Exception applyEx = null;
            if (viewHit && viewItems != null) {
                List<Map<String, Object>> rowsForCode = viewItems.stream()
                        .filter(r -> CusBarcodeSyncViewQueryService.rowMatchesOrderMatnr(code, Objects.toString(r.get("barcode"), null)))
@@ -170,19 +171,51 @@
                        log.info("[cus_barcode_sync] 按条码补档 apply rows={} code={}", rowsForCode.size(), code);
                        cusBarcodeSyncMatnrApplyService.applyFromViewRows(rowsForCode, orderItemByCode, loginUserId);
                    } catch (Exception ex) {
                        applyEx = ex;
                        log.warn("[cus_barcode_sync] 按视图补全物料失败 code={}", code, ex);
                    }
                    m = findLocalMatnrForOrderCode(code);
                }
            }
            if (m == null) {
                log.warn("[cus_barcode_sync] 仍无法落地 man_matnr code={} viewHit={} viewSample=[{}]",
                        code, viewHit, summarizeViewBarcodes(viewItems));
                throw new CoolException("物料不存在:" + code);
                ManMatnrFailReason fr = resolveManMatnrFailReason(viewItems, viewHit, applyEx);
                log.warn("[cus_barcode_sync] 无法落地 man_matnr code={} reason={} viewRowCount={} viewBarcodes=[{}]",
                        code, fr.name(), viewRowCount, summarizeViewBarcodes(viewItems));
                throw new CoolException("物料不存在:" + code + "," + fr.userMessage);
            }
        }
    }
    private enum ManMatnrFailReason {
        VIEW_QUERY_ERROR("副库视图查询异常,未拿到结果集"),
        VIEW_ZERO_ROWS("副库视图本次查询 0 行,请核对 dj-cloud-wms 与视图数据"),
        VIEW_CODE_NOT_IN_RESULT("副库视图有返回行但无与本单 matnr 相等的 barcode"),
        APPLY_ERROR("视图已命中但写入 man_matnr 失败"),
        APPLY_STILL_EMPTY("视图已命中且已 apply 仍无主库物料记录");
        final String userMessage;
        ManMatnrFailReason(String userMessage) {
            this.userMessage = userMessage;
        }
    }
    private static ManMatnrFailReason resolveManMatnrFailReason(List<Map<String, Object>> viewItems, boolean viewHit, Exception applyEx) {
        if (viewItems == null) {
            return ManMatnrFailReason.VIEW_QUERY_ERROR;
        }
        if (viewItems.isEmpty()) {
            return ManMatnrFailReason.VIEW_ZERO_ROWS;
        }
        if (!viewHit) {
            return ManMatnrFailReason.VIEW_CODE_NOT_IN_RESULT;
        }
        if (applyEx != null) {
            return ManMatnrFailReason.APPLY_ERROR;
        }
        return ManMatnrFailReason.APPLY_STILL_EMPTY;
    }
    private static String joinCodesForLog(List<String> matnrCodes) {
        if (matnrCodes == null || matnrCodes.isEmpty()) {
            return "";