rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java
@@ -207,7 +207,6 @@
    @Override
    @Transactional(timeout = 60, rollbackFor = Exception.class)
    public void syncMatnrs(List<BaseMatParms> matnrs) {
        List<Matnr> syncMatnrs = new ArrayList<>();
        if (!matnrs.isEmpty()) {
            matnrs.forEach(matnr -> {
                Matnr mat = new Matnr();
@@ -218,16 +217,27 @@
                mat.setCode(matnr.getMatnr()).setName(matnr.getMaktx());
                if (!Objects.isNull(matnr.getGroupName())) {
                    MatnrGroup matnrGroup = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>().eq(MatnrGroup::getName, matnr.getGroupName()).last("limit 1"), false);
                    if (Objects.isNull(matnrGroup)) {
                    if (!Objects.isNull(matnrGroup)) {
                        mat.setGroupCode(matnrGroup.getCode()).setGroupId(matnrGroup.getId());
                    }
                }
                syncMatnrs.add(mat);
            });
                Matnr exist = matnrService.getOne(new LambdaQueryWrapper<Matnr>()
                        .eq(Matnr::getCode, matnr.getMatnr())
                        .last("limit 1"));
            if (!matnrService.saveOrUpdateBatch(syncMatnrs)) {
                throw new CoolException("物料信息保存成功!!");
            }
                mat.setStatus(Objects.isNull(matnr.getOperateType()) ? 1 : (matnr.getOperateType() == 1 ? 0 : 1));
                if (!Objects.isNull(exist)) {
                    mat.setId(exist.getId());
                    if (!matnrService.saveOrUpdate(mat)) {
                        throw new CoolException("物料信息更新失败!!");
                    }
                } else {
                    mat.setId(null);
                    if (!matnrService.save(mat)) {
                        throw new CoolException("物料信息保存失败!!");
                    }
                }
            });
        }
    }
@@ -307,7 +317,8 @@
    @Override
    @Transactional(timeout = 60, rollbackFor = Exception.class)
    public R syncMatGroups(List<SyncMatGroupsParams> matGroupsParams) {
        List<MatnrGroup> syncMatGroups = new ArrayList<>();
        final int[] insertCount = {0};
        final int[] updateCount = {0};
        matGroupsParams.forEach(matGroupsParam -> {
            MatnrGroup matnrGroup = new MatnrGroup();
            BeanUtils.copyProperties(matGroupsParam, matnrGroup);
@@ -320,12 +331,36 @@
            if (Objects.isNull(matGroupsParam.getParCode())) {
                throw new CoolException("上级物料分组编码不能为空!!");
            }
            syncMatGroups.add(matnrGroup);
            // 幂等同步:优先按编码匹配,找不到再按名称匹配
            MatnrGroup one = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>()
                    .eq(MatnrGroup::getCode, matGroupsParam.getCode())
                    .last("limit 1"));
            if (Objects.isNull(one)) {
                one = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>()
                        .eq(MatnrGroup::getName, matGroupsParam.getName())
                        .last("limit 1"));
            }
            if (!Objects.isNull(one)) {
                matnrGroup.setId(one.getId());
                if (!matnrGroupService.saveOrUpdate(matnrGroup)) {
                    throw new CoolException("物料分组更新失败!!");
                }
                updateCount[0]++;
            } else {
                matnrGroup.setId(null);
                if (!matnrGroupService.save(matnrGroup)) {
                    throw new CoolException("物料分组保存失败!!");
                }
                insertCount[0]++;
            }
        });
        if (!matnrGroupService.saveBatch(syncMatGroups)) {
            throw new CoolException("物料分组保存失败!!");
        }
        return R.ok();
        Map<String, Object> result = new HashMap<>();
        result.put("total", matGroupsParams.size());
        result.put("insertCount", insertCount[0]);
        result.put("updateCount", updateCount[0]);
        return R.ok(result);
    }
    /**
@@ -337,23 +372,45 @@
    @Override
    @Transactional(timeout = 60, rollbackFor = Exception.class)
    public R syncWarehouseAreas(List<LocAreasParams> areasParams) {
        final int[] insertCount = {0};
        final int[] updateCount = {0};
        areasParams.forEach(param -> {
            WarehouseAreas locArea = new WarehouseAreas();
            BeanUtils.copyProperties(param, locArea);
            WarehouseAreas warehouseAreas = warehouseAreasService
                    .getOne(new LambdaQueryWrapper<WarehouseAreas>()
                            .eq(WarehouseAreas::getName, param.getName()));
            // 幂等同步:优先按编码匹配,找不到再按名称匹配
            WarehouseAreas warehouseAreas = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>()
                    .eq(WarehouseAreas::getCode, param.getCode())
                    .last("limit 1"));
            if (Objects.isNull(warehouseAreas)) {
                warehouseAreas = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>()
                        .eq(WarehouseAreas::getName, param.getName())
                        .last("limit 1"));
            }
            if (!Objects.isNull(warehouseAreas)) {
                locArea.setWarehouseId(warehouseAreas.getId());
            }
            locArea.setName(param.getName())
                    .setCode(param.getCode())
                    .setId(null);
            if (!warehouseAreasService.save(locArea)) {
                throw new CoolException("库区保存失败!!");
                    .setCode(param.getCode());
            if (!Objects.isNull(warehouseAreas)) {
                locArea.setId(warehouseAreas.getId());
                if (!warehouseAreasService.saveOrUpdate(locArea)) {
                    throw new CoolException("库区更新失败!!");
                }
                updateCount[0]++;
            } else {
                locArea.setId(null);
                if (!warehouseAreasService.save(locArea)) {
                    throw new CoolException("库区保存失败!!");
                }
                insertCount[0]++;
            }
        });
        return R.ok();
        Map<String, Object> result = new HashMap<>();
        result.put("total", areasParams.size());
        result.put("insertCount", insertCount[0]);
        result.put("updateCount", updateCount[0]);
        return R.ok(result);
    }
    /**
@@ -365,15 +422,35 @@
    @Override
    @Transactional(timeout = 60, rollbackFor = Exception.class)
    public R syncWarehouse(List<WarehouseParams> warehouses) {
        final int[] insertCount = {0};
        final int[] updateCount = {0};
        warehouses.forEach(warehouse -> {
            Warehouse ware = new Warehouse();
            BeanUtils.copyProperties(warehouse, ware);
            ware.setId(null);
            if (!warehouseService.save(ware)) {
                throw new CoolException("仓库同步保存失败!!");
            // 幂等同步:按仓库名称匹配
            Warehouse one = warehouseService.getOne(new LambdaQueryWrapper<Warehouse>()
                    .eq(Warehouse::getName, warehouse.getName())
                    .last("limit 1"));
            ware.setStatus(Objects.isNull(warehouse.getOperateType()) ? 1 : (warehouse.getOperateType() == 1 ? 0 : 1));
            if (!Objects.isNull(one)) {
                ware.setId(one.getId());
                if (!warehouseService.saveOrUpdate(ware)) {
                    throw new CoolException("仓库同步更新失败!!");
                }
                updateCount[0]++;
            } else {
                ware.setId(null);
                if (!warehouseService.save(ware)) {
                    throw new CoolException("仓库同步保存失败!!");
                }
                insertCount[0]++;
            }
        });
        return R.ok();
        Map<String, Object> result = new HashMap<>();
        result.put("total", warehouses.size());
        result.put("insertCount", insertCount[0]);
        result.put("updateCount", updateCount[0]);
        return R.ok(result);
    }
    /**
@@ -388,20 +465,37 @@
        companyParams.forEach(param -> {
            Companys companys = new Companys();
            BeanUtils.copyProperties(param, companys);
            if (Objects.isNull(companys.getCode())) {
            if (Objects.isNull(companys.getCode()) || StringUtils.isBlank(companys.getCode())) {
                throw new CoolException("企业编码不能为空!!");
            }
            Companys one = companysService.getOne(new LambdaQueryWrapper<Companys>().eq(Companys::getName, param.getName()).last("limit 1"));
            if (Objects.isNull(one)) {
                String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_COMPANYS_CODE, null);
                companys.setCode(ruleCode);
            } else {
                throw new CoolException(one.getName() + ",企业名重复!!");
            if (Objects.isNull(companys.getName()) || StringUtils.isBlank(companys.getName())) {
                throw new CoolException("企业名称不能为空!!");
            }
            companys.setType(CompanysType.getCustomVal(param.getType()))
                    .setId(null);
            if (!companysService.save(companys)) {
                throw new CoolException("企业保存失败!!");
            // 幂等同步:优先按编码匹配,找不到再按名称匹配
            Companys one = companysService.getOne(new LambdaQueryWrapper<Companys>()
                    .eq(Companys::getCode, param.getCode())
                    .last("limit 1"));
            if (Objects.isNull(one)) {
                one = companysService.getOne(new LambdaQueryWrapper<Companys>()
                        .eq(Companys::getName, param.getName())
                        .last("limit 1"));
            }
            companys.setType(CompanysType.getCustomVal(param.getType()));
            companys.setStatus(Objects.isNull(param.getOperateType()) ? 1 : (param.getOperateType() == 1 ? 0 : 1));
            if (!Objects.isNull(one)) {
                companys.setId(one.getId());
                // 已存在则更新,不重复报错
                if (!companysService.saveOrUpdate(companys)) {
                    throw new CoolException("企业更新失败!!");
                }
            } else {
                companys.setId(null);
                // 新增时保留ERP传入编码,不再覆盖生成
                if (!companysService.save(companys)) {
                    throw new CoolException("企业保存失败!!");
                }
            }
        });
        return R.ok();