| | |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*; |
| | |
| | | public void deleteSupplier(Long id) { |
| | | // 校验存在 |
| | | validateSupplierExists(id); |
| | | // 校验供应商是否被业务引用 |
| | | validateSupplierNoReference(id); |
| | | // 删除 |
| | | supplierMapper.deleteById(id); |
| | | } |
| | | |
| | | /** |
| | | * 校验供应商未被业务引用(采购、质检、生产、库存等) |
| | | * |
| | | * @param id 供应商编号 |
| | | */ |
| | | private void validateSupplierNoReference(Long id) { |
| | | List<Map<String, Object>> references = supplierMapper.selectSupplierReferenceCount(id); |
| | | if (CollUtil.isNotEmpty(references)) { |
| | | String refDesc = references.stream() |
| | | .map(r -> r.get("source") + "(" + r.get("cnt") + ")") |
| | | .collect(Collectors.joining("、")); |
| | | throw exception(SUPPLIER_EXISTS_REFERENCE, refDesc); |
| | | } |
| | | } |
| | | |
| | | private void validateSupplierExists(Long id) { |
| | | if (supplierMapper.selectById(id) == null) { |
| | | throw exception(SUPPLIER_NOT_EXISTS); |