6 天以前 f569e2257372a2f940aace9ad151fd758196eb9a
src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
@@ -16,6 +16,7 @@
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;
@@ -199,6 +200,8 @@
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long tenantId = loginUser.getTenantId();
        customer.setTenantId(tenantId);
        // 校验客户名称唯一性
        checkCustomerNameUnique(customer.getCustomerName(), tenantId, null);
        return customerMapper.insert(customer);
    }
@@ -213,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 + "'已存在,请修改");
            }
        }
    }
    /**
@@ -404,6 +431,24 @@
    }
    @Override
    public void handoverCustomer(CustomerDto customerDto) {
        Customer customer = customerMapper.selectById(customerDto.getId());
        if (customer == null) {
            throw new ServiceException("客户不存在");
        }
        if (customer.getType() != 0) {
            throw new ServiceException("仅私海客户支持交接");
        }
        if (customerDto.getMaintainer() == null || customerDto.getMaintainer().trim().isEmpty()) {
            throw new ServiceException("新维护人不能为空");
        }
        customer.setMaintainer(customerDto.getMaintainer());
        customer.setMaintenanceTime(new Date());
        customer.setCreateUser(customerDto.getMaintainerId());
        customerMapper.updateById(customer);
    }
    @Override
    public IPage<CustomerTransactionsVo> customewTransactions(Page page, String customerName) {
        return customerMapper.customewTransactions(page, customerName);
    }