|
|
@@ -1,7 +1,6 @@
|
|
|
package com.fs.his.service.impl;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -12,10 +11,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.his.dto.MemberExcelDTO;
|
|
|
import com.fs.his.listenner.MemberImportListener;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import com.fs.qw.mapper.FsCompanyCustomerMapper;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.his.mapper.FsImportMemberMapper;
|
|
|
import com.fs.his.domain.FsImportMember;
|
|
|
+import com.fs.qw.domain.FsCompanyCustomer;
|
|
|
import com.fs.his.service.IFsImportMemberService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
@@ -29,6 +31,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
@Service
|
|
|
public class FsImportMemberServiceImpl extends ServiceImpl<FsImportMemberMapper, FsImportMember> implements IFsImportMemberService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsCompanyCustomerMapper fsCompanyCustomerMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询导入会员
|
|
|
*
|
|
|
@@ -130,4 +135,44 @@ public class FsImportMemberServiceImpl extends ServiceImpl<FsImportMemberMapper,
|
|
|
}
|
|
|
return listener.getResult();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int batchAddCompanyCustomer() {
|
|
|
+ // 1. 获取未加入到销售客户信息表的会员信息
|
|
|
+ FsImportMember queryImportMember = new FsImportMember();
|
|
|
+ queryImportMember.setStatus(0);
|
|
|
+ List<FsImportMember> fsImportMembers = baseMapper.selectFsImportMemberList(queryImportMember);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(fsImportMembers)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 将导入会员转换为销售客户对象
|
|
|
+ List<FsCompanyCustomer> companyCustomers = fsImportMembers.stream().map(member -> {
|
|
|
+ FsCompanyCustomer customer = new FsCompanyCustomer();
|
|
|
+ customer.setCustomerName(member.getMemberName());
|
|
|
+ customer.setPhone(member.getMemberPhone());
|
|
|
+ customer.setAddress(member.getAddress());
|
|
|
+ return customer;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 3. 分批插入,并统计实际成功插入的数量
|
|
|
+ int batchSize = 500;
|
|
|
+ int totalInsertedCount = 0; // 记录总共成功插入了多少条
|
|
|
+
|
|
|
+ for (int i = 0; i < companyCustomers.size(); i += batchSize) {
|
|
|
+ int end = Math.min(i + batchSize, companyCustomers.size());
|
|
|
+ List<FsCompanyCustomer> subList = companyCustomers.subList(i, end);
|
|
|
+ // insertBatchFsCompanyCustomer 返回该批次实际影响的行数
|
|
|
+ int insertedInBatch = fsCompanyCustomerMapper.insertBatchFsCompanyCustomer(subList);
|
|
|
+ totalInsertedCount += insertedInBatch;
|
|
|
+ }
|
|
|
+ // 4. 合并需要更新状态的ID
|
|
|
+ List<Long> allProcessedIds = fsImportMembers.stream()
|
|
|
+ .map(FsImportMember::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // 6. 批量修改导入会员状态
|
|
|
+ return baseMapper.completionStatus(allProcessedIds);
|
|
|
+ }
|
|
|
}
|