| | |
| | | public void deleteItem(Long id) { |
| | | // 校验存在 |
| | | MdmItemDO item = validateItemExists(id); |
| | | // 解决软删除唯一键冲突:如果已存在相同 code 且已软删除的记录,先物理删除它 |
| | | // MdmItemDO existingDeleted = itemMapper.selectByCodeAndDeleted(item.getCode(), true); |
| | | // if (existingDeleted != null && !existingDeleted.getId().equals(id)) { |
| | | // itemMapper.physicalDeleteById(existingDeleted.getId()); |
| | | // } |
| | | // 校验物料是否被业务引用 |
| | | validateItemNoReference(id); |
| | | // 软删除当前记录 |
| | | itemMapper.deleteById(id); |
| | | } |
| | | |
| | | /** |
| | | * 校验物料未被业务引用(销售、采购、生产、质检、库存等) |
| | | * |
| | | * @param id 物料编号 |
| | | */ |
| | | private void validateItemNoReference(Long id) { |
| | | List<Map<String, Object>> references = itemMapper.selectItemReferenceCount(id); |
| | | if (CollUtil.isNotEmpty(references)) { |
| | | String refDesc = references.stream() |
| | | .map(r -> r.get("source") + "(" + r.get("cnt") + ")") |
| | | .collect(Collectors.joining("、")); |
| | | throw exception(MDM_ITEM_EXISTS_REFERENCE, refDesc); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteItemList(Collection<Long> ids) { |
| | | if (CollUtil.isEmpty(ids)) { |
| | | return; |
| | | } |
| | | // 逐个删除(复用单条删除逻辑,保持校验) |
| | | ids.forEach(this::deleteItem); |
| | | } |
| | | |
| | | @Override |
| | | public MdmItemDO validateItemExists(Long id) { |
| | | MdmItemDO item = itemMapper.selectById(id); |