7 天以前 b39154d1e708d7f8dd1f2832d881d853d583fe47
src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
@@ -16,13 +16,20 @@
import com.ruoyi.basic.pojo.CustomerUser;
import com.ruoyi.basic.service.*;
import com.ruoyi.basic.vo.CustomerVo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.procurementrecord.mapper.ReturnManagementMapper;
import com.ruoyi.procurementrecord.pojo.ReturnManagement;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.mapper.SalesQuotationMapper;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesQuotation;
import com.ruoyi.sales.vo.CustomerTransactionsDetailsVo;
import com.ruoyi.sales.vo.CustomerTransactionsVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
@@ -48,7 +55,11 @@
@Slf4j
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {
    @Autowired
    private  SalesLedgerMapper salesLedgerMapper;
    private SalesLedgerMapper salesLedgerMapper;
    @Autowired
    private SalesQuotationMapper salesQuotationMapper;
    @Autowired
    private ReturnManagementMapper returnManagementMapper;
    @Autowired
    private CustomerMapper customerMapper;
@@ -189,6 +200,8 @@
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long tenantId = loginUser.getTenantId();
        customer.setTenantId(tenantId);
        // 校验客户名称唯一性
        checkCustomerNameUnique(customer.getCustomerName(), tenantId, null);
        return customerMapper.insert(customer);
    }
@@ -203,7 +216,31 @@
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long tenantId = loginUser.getTenantId();
        customer.setTenantId(tenantId);
        // 校验客户名称唯一性(排除自身)
        checkCustomerNameUnique(customer.getCustomerName(), tenantId, customer.getId());
        return customerMapper.updateById(customer);
    }
    /**
     * 校验客户名称唯一性
     *
     * @param customerName 客户名称
     * @param tenantId 租户ID
     * @param excludeId 排除的客户ID(修改时排除自身)
     */
    private void checkCustomerNameUnique(String customerName, Long tenantId, Long excludeId) {
        if (StringUtils.isNotEmpty(customerName)) {
            LambdaQueryWrapper<Customer> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Customer::getTenantId, tenantId)
                    .eq(Customer::getCustomerName, customerName);
            if (excludeId != null) {
                queryWrapper.ne(Customer::getId, excludeId);
            }
            Long count = customerMapper.selectCount(queryWrapper);
            if (count > 0) {
                throw new ServiceException("客户名称'" + customerName + "'已存在,请修改");
            }
        }
    }
    /**
@@ -216,10 +253,24 @@
    @Transactional(rollbackFor = Exception.class)
    public int deleteCustomerByIds(Long[] ids) {
        List<Long> idList = Arrays.asList(ids);
        // 检查是否有销售台账关联
        List<SalesLedger> salesLedgers = salesLedgerMapper.selectList(new QueryWrapper<SalesLedger>().lambda().in(SalesLedger::getCustomerId, idList));
        if (!salesLedgers.isEmpty()) {
            throw new RuntimeException("客户档案下有销售合同,请先删除销售合同");
            throw new RuntimeException("客户档案下有销售台账,请先删除销售台账");
        }
        // 检查是否有销售退货关联
        List<ReturnManagement> returnManagements = returnManagementMapper.selectList(new QueryWrapper<ReturnManagement>().lambda().in(ReturnManagement::getCustomerId, idList));
        if (!returnManagements.isEmpty()) {
            throw new RuntimeException("客户档案下有销售退货,请先删除销售退货");
        }
        // 检查是否有销售报价关联
        List<SalesQuotation> salesQuotations = salesQuotationMapper.selectList(new QueryWrapper<SalesQuotation>().lambda().in(SalesQuotation::getCustomerId, idList));
        if (!salesQuotations.isEmpty()) {
            throw new RuntimeException("客户档案下有销售报价,请先删除销售报价");
        }
        // 查询是否有已分配的公海客户
        List<Customer> assignedPools = customerMapper.selectList(
                new QueryWrapper<Customer>().lambda()
@@ -379,6 +430,16 @@
        return this.updateById(customer);
    }
    @Override
    public IPage<CustomerTransactionsVo> customewTransactions(Page page, String customerName) {
        return customerMapper.customewTransactions(page, customerName);
    }
    @Override
    public IPage<CustomerTransactionsDetailsVo> customewTransactionsDetails(Page page, Long customerId) {
        return customerMapper.customewTransactionsDetails(page, customerId);
    }
    /**
     * 下划线命名转驼峰命名
     */