| | |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.*; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.vincent.rsf.server.manager.service.impl.MatnrServiceImpl; |
| | | import com.vincent.rsf.server.system.constant.DictTypeCode; |
| | | import com.vincent.rsf.server.system.constant.GlobalConfigCode; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | |
| | | @Autowired |
| | | private MatnrGroupService matnrGroupService; |
| | | @Autowired |
| | | private MatnrServiceImpl matnrService; |
| | | private MatnrService matnrService; |
| | | @Autowired |
| | | private AsnOrderService asnOrderService; |
| | | @Autowired |
| | |
| | | public void syncMatnrs(List<BaseMatParms> matnrs) { |
| | | List<Matnr> syncMatnrs = new ArrayList<>(); |
| | | if (!matnrs.isEmpty()) { |
| | | assertUniqueMatnrInSyncList(matnrs); |
| | | matnrs.forEach(matnr -> { |
| | | Matnr mat = new Matnr(); |
| | | if (Objects.isNull(matnr.getMatnr())) { |
| | | throw new RuntimeException("物料编码不能为空!!"); |
| | | } |
| | | BeanUtils.copyProperties(matnr, mat); |
| | | mat.setCode(matnr.getMatnr()).setName(matnr.getMaktx()); |
| | | mat.setCode(matnr.getMatnr()).setName(matnr.getMaktx()) |
| | | .setBatch(matnrService.normalizeMatnrBatchValue(matnr.getBatch())); |
| | | if (!Objects.isNull(matnr.getGroupName())) { |
| | | MatnrGroup matnrGroup = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>().eq(MatnrGroup::getName, matnr.getGroupName()), false); |
| | | if (Objects.isNull(matnrGroup)) { |
| | | if (!Objects.isNull(matnrGroup)) { |
| | | mat.setGroupCode(matnrGroup.getCode()).setGroupId(matnrGroup.getId()); |
| | | } |
| | | } |
| | |
| | | |
| | | if (!matnrService.saveOrUpdateBatch(syncMatnrs)) { |
| | | throw new CoolException("物料信息保存成功!!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void assertUniqueMatnrInSyncList(List<BaseMatParms> matnrs) { |
| | | Set<String> keys = new HashSet<>(); |
| | | for (BaseMatParms p : matnrs) { |
| | | if (StringUtils.isBlank(p.getMatnr())) { |
| | | continue; |
| | | } |
| | | String key = p.getMatnr().trim() + "\u0000" + matnrService.normalizeMatnrBatchValue(p.getBatch()); |
| | | if (!keys.add(key)) { |
| | | throw new CoolException("同步列表中物料编码与批次重复:" + p.getMatnr().trim() |
| | | + (StringUtils.isNotBlank(matnrService.normalizeMatnrBatchValue(p.getBatch())) |
| | | ? " / " + matnrService.normalizeMatnrBatchValue(p.getBatch()) : "")); |
| | | } |
| | | } |
| | | } |
| | |
| | | Integer operateType = baseMatParms.getOperateType(); |
| | | // 3 禁用 / 4 启用:仅更新状态(status 1 正常 0 冻结) |
| | | if (Integer.valueOf(3).equals(operateType) || Integer.valueOf(4).equals(operateType)) { |
| | | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, baseMatParms.getMatnr())); |
| | | Matnr matnr = matnrService.getOneByCodeAndBatch(baseMatParms.getMatnr(), baseMatParms.getBatch()); |
| | | if (matnr == null) { |
| | | throw new CoolException("物料不存在,无法执行禁用/启用!!"); |
| | | } |
| | |
| | | return R.ok(); |
| | | } |
| | | // 1 新增 / 2 修改 / 不传:有则更新、无则新增 |
| | | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, baseMatParms.getMatnr())); |
| | | Matnr matnr = matnrService.getOneByCodeAndBatch(baseMatParms.getMatnr(), baseMatParms.getBatch()); |
| | | if (Objects.isNull(matnr)) { |
| | | Matnr matnr1 = new Matnr(); |
| | | BeanUtils.copyProperties(baseMatParms, matnr1); |
| | | matnr1.setCode(baseMatParms.getMatnr()); |
| | | matnr1.setName(baseMatParms.getMaktx()); |
| | | matnr1.setBatch(matnrService.normalizeMatnrBatchValue(baseMatParms.getBatch())); |
| | | if (!Objects.isNull(baseMatParms.getGroupName())) { |
| | | MatnrGroup matnrGroup = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>() |
| | | .eq(MatnrGroup::getName, baseMatParms.getGroupName())); |
| | |
| | | matnr.setName(baseMatParms.getMaktx()) |
| | | .setColor(baseMatParms.getColor()) |
| | | .setModel(baseMatParms.getModel()) |
| | | .setSpec(baseMatParms.getSpec()); |
| | | .setSpec(baseMatParms.getSpec()) |
| | | .setBatch(matnrService.normalizeMatnrBatchValue(baseMatParms.getBatch())); |
| | | |
| | | if (!matnrService.updateById(matnr)) { |
| | | throw new CoolException("物料更新失败!!"); |