chenhj
2026-04-21 2f20856ea3ca6f2f238ba66252164687f47fcd7e
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());
        }
    }
}