cl
6 天以前 50393719d85fc30438456b0d0f065573a404fba5
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/CusBarcodeSyncViewQueryService.java
@@ -1,5 +1,6 @@
package com.vincent.rsf.server.manager.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -13,6 +14,8 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
import java.util.Collection;
@@ -25,6 +28,7 @@
/**
 * cus_barcode_sync_view:barcode 即为物料号(含 # 等字符亦原样),对应 man_matnr.code。与 {@link CusItemSyncViewQueryService} 独立。
 * 查询不启事务;{@code NOT_SUPPORTED} 挂起外层事务,避免主库连接占用导致副库路由失效。
 */
@UseDataSource(DataSourceNames.DJ_CLOUD_WMS)
@Service
@@ -65,6 +69,8 @@
        return viewItems.stream().anyMatch(r -> rowMatchesOrderMatnr(oc, Objects.toString(r.get("barcode"), null)));
    }
    /** 挂起外层事务,查询本身不包事务 */
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<Map<String, Object>> probeSample(int limit) {
        if (cusItemSyncDataSourceProvider.getIfAvailable() == null) {
            return Collections.emptyList();
@@ -81,6 +87,7 @@
        return toViewMaps(page.getRecords());
    }
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<Map<String, Object>> listByItemNos(Collection<String> itemNos) {
        if (itemNos == null || itemNos.isEmpty()) {
            return Collections.emptyList();
@@ -98,8 +105,7 @@
            return Collections.emptyList();
        }
        List<CusBarcodeSyncView> rows = cusBarcodeSyncViewMapper.selectList(
                Wrappers.<CusBarcodeSyncView>lambdaQuery()
                        .in(CusBarcodeSyncView::getBarcode, codes)
                buildBarcodeOrQuery(codes)
                        .select(
                                CusBarcodeSyncView::getBarcode,
                                CusBarcodeSyncView::getItemName,
@@ -108,6 +114,21 @@
        return toViewMaps(rows);
    }
    private LambdaQueryWrapper<CusBarcodeSyncView> buildBarcodeOrQuery(List<String> codes) {
        LambdaQueryWrapper<CusBarcodeSyncView> wrapper = Wrappers.lambdaQuery();
        wrapper.and(q -> {
            for (int i = 0; i < codes.size(); i++) {
                String code = codes.get(i);
                if (i == 0) {
                    q.eq(CusBarcodeSyncView::getBarcode, code);
                } else {
                    q.or().eq(CusBarcodeSyncView::getBarcode, code);
                }
            }
        });
        return wrapper;
    }
    private List<Map<String, Object>> toViewMaps(List<CusBarcodeSyncView> rows) {
        if (rows == null || rows.isEmpty()) {
            return Collections.emptyList();