cl
2026-04-17 b8359b134e6618b154c79f4e24e700bc4affe424
视图兼容
1个文件已修改
73 ■■■■■ 已修改文件
rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/PdaCheckOrderServiceImpl.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/PdaCheckOrderServiceImpl.java
@@ -28,6 +28,7 @@
import com.vincent.rsf.server.system.service.impl.FieldsItemServiceImpl;
import com.vincent.rsf.server.system.service.impl.UserServiceImpl;
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
import com.vincent.rsf.server.system.utils.SystemAuthUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -71,6 +72,9 @@
    @Autowired
    private CheckOrderService checkOrderService;
    @Autowired
    private CusItemSyncViewQueryService cusItemSyncViewQueryService;
    @Override
@@ -263,7 +267,7 @@
        if (Cools.isEmpty(matnrCode)) {
            return R.error("物料码为空");
        }
        Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, matnrCode));
        Matnr matnr = getMatnrByCodePreferView(matnrCode);
        if (null == matnr) {
            return R.error("未找到编码对应的明细");
        }
@@ -275,6 +279,73 @@
        return R.ok(checkDiffItem);
    }
    /** 扫物料先查视图,命中后同步物料主数据 */
    private Matnr getMatnrByCodePreferView(String matnrCode) {
        String code = StringUtils.trimToNull(matnrCode);
        if (code == null) {
            return null;
        }
        List<Map<String, Object>> viewItems = null;
        try {
            viewItems = cusItemSyncViewQueryService.listByItemNos(Collections.singletonList(code));
        } catch (Exception ignore) {
        }
        Map<String, Object> row = null;
        if (viewItems != null) {
            row = viewItems.stream()
                    .filter(v -> StringUtils.equals(code, StringUtils.trimToNull(Objects.toString(v.get("item_no"), null))))
                    .findFirst()
                    .orElse(null);
        }
        if (row == null) {
            return matnrService.getOneByCodeAndBatch(code, "");
        }
        String viewSpec = StringUtils.trimToEmpty(Objects.toString(row.get("item_spec"), ""));
        String viewUnit = StringUtils.trimToNull(Objects.toString(row.get("unit_no"), null));
        Long loginUserId = SystemAuthUtils.getLoginUserId() == null ? 1L : SystemAuthUtils.getLoginUserId();
        Matnr local = matnrService.getOneByCodeAndBatch(code, "");
        if (local == null) {
            Matnr matnr = new Matnr();
            matnr.setCode(code)
                    .setBatch("")
                    .setName(code)
                    .setSpec(viewSpec)
                    .setUnit(viewUnit)
                    .setStockUnit(viewUnit)
                    .setStatus(1)
                    .setCreateBy(loginUserId)
                    .setUpdateBy(loginUserId)
                    .setCreateTime(new Date())
                    .setUpdateTime(new Date());
            if (!matnrService.save(matnr)) {
                throw new CoolException("物料信息保存失败");
            }
            return matnr;
        }
        boolean specDiff = !StringUtils.equals(StringUtils.trimToEmpty(local.getSpec()), viewSpec);
        boolean unitDiff = viewUnit != null
                && (!StringUtils.equals(StringUtils.trimToEmpty(local.getUnit()), viewUnit)
                || !StringUtils.equals(StringUtils.trimToEmpty(local.getStockUnit()), viewUnit));
        if (specDiff || unitDiff) {
            Matnr update = new Matnr();
            update.setId(local.getId());
            if (specDiff) {
                update.setSpec(viewSpec);
                local.setSpec(viewSpec);
            }
            if (unitDiff) {
                update.setUnit(viewUnit).setStockUnit(viewUnit);
                local.setUnit(viewUnit);
                local.setStockUnit(viewUnit);
            }
            update.setUpdateBy(loginUserId).setUpdateTime(new Date());
            if (!matnrService.updateById(update)) {
                throw new CoolException("物料信息更新失败");
            }
        }
        return local;
    }
    @Override
    public R getCheckTaskItemList2(String barcode) {
        LambdaQueryWrapper<Task> lambdaQueryWrapper = new LambdaQueryWrapper<>();