liyong
2026-04-17 8b68e5a8d8d43bcb45c9032c3eb893a2b8995acf
fix(customer): 修复客户私海相关查询和导入功能

- 修复CustomerMapper.xml中的私海用户查询,添加删除标记过滤条件
- 修改CustomerPrivatePoolMapper.xml中的查询逻辑,同时搜索客户名称并调整绑定ID筛选为类型筛选
- 在CustomerPrivateServiceImpl中注入必要的依赖项
- 为新增私海记录设置默认类型值为0
- 优化导入功能,添加重复数据检测和统计返回结果
- 改进导入异常处理,返回具体的错误信息
已修改3个文件
32 ■■■■ 文件已修改
src/main/java/com/ruoyi/basic/service/impl/CustomerPrivateServiceImpl.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/basic/CustomerMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/basic/CustomerPrivatePoolMapper.xml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/basic/service/impl/CustomerPrivateServiceImpl.java
@@ -56,6 +56,11 @@
    @Autowired
    private SalesLedgerMapper salesLedgerMapper;
    @Autowired
    private  CustomerPrivateMapper customerPrivateMapper;
    @Autowired
    private CustomerPrivateService customerPrivateService;
    @Override
    public Boolean add(CustomerPrivateDto customerPrivateDto) {
@@ -64,6 +69,7 @@
        //新增私海记录
        CustomerPrivatePool customerPrivatePool = new CustomerPrivatePool();
        customerPrivatePool.setCustomerId(customerPrivateDto.getId());
        customerPrivatePool.setType(0L);
        customerPrivatePool.setBoundId(SecurityUtils.getLoginUser().getUserId());
        customerPrivatePoolMapper.insert(customerPrivatePool);
        return true;
@@ -93,20 +99,34 @@
    @Override
    public R importData(MultipartFile file) {
        try {
            List<CustomerPrivate> existingList = customerPrivateService.list();
            java.util.Set<String> existingCustomerNames = existingList.stream()
                    .map(CustomerPrivate::getCustomerName)
                    .collect(Collectors.toSet());
            ExcelUtil<CustomerPrivate> util = new ExcelUtil<CustomerPrivate>(CustomerPrivate.class);
            List<CustomerPrivate> userList = util.importExcel(file.getInputStream());
            if (CollectionUtils.isEmpty(userList)) {
                return R.fail("模板错误或导入数据为空");
            }
            int successCount = 0;
            int skipCount = 0;
            for (CustomerPrivate user : userList) {
                if (existingCustomerNames.contains(user.getCustomerName())) {
                    skipCount++;
                    continue;
                }
                CustomerPrivateDto customerPrivateDto = new CustomerPrivateDto();
                BeanUtils.copyProperties(user, customerPrivateDto);
                this.add(customerPrivateDto);
                existingCustomerNames.add(user.getCustomerName());
                successCount++;
            }
            return R.ok(true);
            return R.ok("导入完成,成功" + successCount + "条,跳过重复" + skipCount + "条");
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail("导入失败");
            return R.fail("导入失败:" + e.getMessage());
        }
    }
}
src/main/resources/mapper/basic/CustomerMapper.xml
@@ -14,7 +14,7 @@
        select group_concat(u2.user_name separator ', ')
        from customer_private_pool cpp2
        left join sys_user u2 on cpp2.bound_id = u2.user_id
        where cpp2.customer_id = c.id
        where cpp2.customer_id = c.id and cpp2.delete_flag = 0
        and cpp2.bound_id != c.usage_user
        ) as together_user_names
        from customer c
src/main/resources/mapper/basic/CustomerPrivatePoolMapper.xml
@@ -36,10 +36,10 @@
        <where>
            cpp.delete_flag = 0
            <if test="c.customerName != null and c.customerName != ''">
                and c.customer_name like concat('%', #{c.customerName}, '%')
                and (c.customer_name like concat('%', #{c.customerName}, '%') or cp.customer_name like concat('%', #{c.customerName}, '%'))
            </if>
            <if test="c.boundId != null">
                and cpp.bound_id = #{c.boundId}
            <if test="c.customerType != null">
                and c.customer_type = #{c.customerType}
            </if>
        </where>
        order by cpp.id desc