| | |
| | | package cn.iocoder.yudao.module.erp.service.purchase; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | |
| | | import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.supplier.ErpSupplierSaveReqVO; |
| | | import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpSupplierDO; |
| | | import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpSupplierMapper; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.SrmSupplierApi; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.dto.SrmSupplierRespDTO; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | 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.*; |
| | |
| | | |
| | | @Resource |
| | | private ErpSupplierMapper supplierMapper; |
| | | |
| | | @Resource |
| | | private SrmSupplierApi srmSupplierApi; |
| | | |
| | | @Override |
| | | public Long createSupplier(ErpSupplierSaveReqVO createReqVO) { |
| | |
| | | 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) { |
| | |
| | | |
| | | @Override |
| | | public ErpSupplierDO validateSupplier(Long id) { |
| | | ErpSupplierDO supplier = supplierMapper.selectById(id); |
| | | SrmSupplierRespDTO supplier = srmSupplierApi.getSupplier(id).getCheckedData(); |
| | | if (supplier == null) { |
| | | throw exception(SUPPLIER_NOT_EXISTS); |
| | | } |
| | | if (CommonStatusEnum.isDisable(supplier.getStatus())) { |
| | | throw exception(SUPPLIER_NOT_ENABLE, supplier.getName()); |
| | | } |
| | | return supplier; |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<ErpSupplierDO> getSupplierList(Collection<Long> ids) { |
| | | if (CollUtil.isEmpty(ids)) { |
| | | return CollUtil.newArrayList(); |
| | | } |
| | | return supplierMapper.selectByIds(ids); |
| | | } |
| | | |