| | |
| | | @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(); |
| | |
| | | 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("物料信息保存失败!!"); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | |
| | | @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); |
| | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | @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); |
| | | } |
| | | |
| | | /** |
| | |
| | | @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); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | 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()); |
| | | // 已存在则更新,不重复报错 |