gongchunyi
2026-04-29 56b73ce57147653cfbcfe87a7c28e9792dbb2f72
src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
@@ -9,6 +9,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.dto.CustomerDto;
import com.ruoyi.basic.dto.CustomerFollowUpDto;
import com.ruoyi.basic.excel.CustomerExcelDTO;
import com.ruoyi.basic.mapper.CustomerMapper;
import com.ruoyi.basic.pojo.Customer;
import com.ruoyi.basic.pojo.CustomerFollowUp;
@@ -23,6 +24,7 @@
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.pojo.SalesLedger;
import lombok.AllArgsConstructor;
@@ -33,10 +35,8 @@
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
@@ -58,6 +58,8 @@
    private CustomerFollowUpFileService customerFollowUpFileService;
    private CustomerReturnVisitService customerReturnVisitService;
    private SysUserMapper sysUserMapper;
    /**
     * 查询客户档案
@@ -141,6 +143,7 @@
            queryWrapper.like(Customer::getCustomerType, customerType);
        }
        // 3. 执行分页查询(保留分页元数据)
        IPage<Customer> customerPage = customerMapper.selectPage(page, queryWrapper);
@@ -163,7 +166,11 @@
                    if (followUp != null) {
                        c.setFollowUpLevel(followUp.getFollowUpLevel());
                        c.setFollowUpTime(followUp.getFollowUpTime());
                        c.setFollowUpTime(
                                Date.from(
                                        followUp.getFollowUpTime().atZone(ZoneId.systemDefault()).toInstant()
                                )
                        );
                    }
                })
                .collect(Collectors.toList());
@@ -183,9 +190,17 @@
     */
    @Override
    public int insertCustomer(Customer customer) {
        // 1. 校验客户名称是否已存在
        LambdaQueryWrapper<Customer> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Customer::getCustomerName, customer.getCustomerName());
        List<Customer> customerList = customerMapper.selectList(queryWrapper);
        if (!customerList.isEmpty()) {
            throw new RuntimeException("客户名称已存在");
        }
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long tenantId = loginUser.getTenantId();
        customer.setTenantId(tenantId);
        customer.setCreateUser(loginUser.getUserId().intValue());
        return customerMapper.insert(customer);
    }
@@ -197,6 +212,14 @@
     */
    @Override
    public int updateCustomer(Customer customer) {
        // 1. 校验客户名称是否已存在
        LambdaQueryWrapper<Customer> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Customer::getCustomerName, customer.getCustomerName());
        queryWrapper.ne(Customer::getId, customer.getId());
        List<Customer> customerList = customerMapper.selectList(queryWrapper);
        if (!customerList.isEmpty()) {
            throw new RuntimeException("客户名称已存在");
        }
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long tenantId = loginUser.getTenantId();
        customer.setTenantId(tenantId);
@@ -234,8 +257,18 @@
    }
    @Override
    public List<CustomerExcelDTO> selectCustomerDtoByIds(Long[] ids) {
        return customerMapper.selectCustomerDtoListByIds(Arrays.asList(ids));
    }
    @Override
    public List<Customer> selectCustomerLists(Customer customer) {
        return customerMapper.selectList(null);
    }
    @Override
    public List<CustomerExcelDTO> selectCustomerDtoLists() {
        return customerMapper.selectCustomerDtoLists();
    }
    @Override
@@ -292,4 +325,21 @@
        }
        return sb.toString();
    }
    @Override
    public int transferCustomer(CustomerDto customerDto) {
        // 校验维护人是否存在
        SysUser sysUser = sysUserMapper.selectUserById(customerDto.getCreateUser().longValue());
        if (sysUser == null) {
            throw new RuntimeException("维护人不存在");
        }
        // 校验客户是否存在
        Customer customer = customerMapper.selectById(customerDto.getId());
        if (customer == null) {
            throw new RuntimeException("客户不存在");
        }
        customer.setMaintainer(sysUser.getNickName());
        customer.setCreateUser(customerDto.getCreateUser());
        return customerMapper.updateById(customer);
    }
}