Commit df23d0cd by 阮思源

Merge branch 'zyj-exceltozip' into 'master'

导出excel压缩包

See merge request rays/pcloud-book!283
parents 9d19f66b 244d7d6f
......@@ -24,6 +24,7 @@ import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import com.pcloud.book.group.dao.BookGroupDao;
import com.pcloud.book.group.dao.GroupQrcodeDao;
import com.pcloud.book.group.vo.ClassifyVO;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.core.biz.MessageBiz;
import com.pcloud.common.core.constant.SystemCode;
......@@ -56,8 +57,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
......@@ -71,7 +70,6 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component("groupTagBiz")
public class GroupTagBizImpl implements GroupTagBiz {
private static final ExecutorService EXECUTOR_SINGLE_SERVICE = Executors.newSingleThreadExecutor();
@Autowired
private GroupQrcodeDao groupQrcodeDao;
......@@ -282,7 +280,7 @@ public class GroupTagBizImpl implements GroupTagBiz {
}
advertisingGroupTagDao.insert(tagList);
//书下每个群添加记录
EXECUTOR_SINGLE_SERVICE.execute(() -> {
ThreadPoolUtils.EXPORT_THREAD_POOL.execute(() -> {
List<Long> beforeQrcodeIds = advertisingGroupTagDao.getGroupQrcodeIdsByBrandId(brandId);
for (Long bookId : bookIds) {
List<AdvertisingGroupTag> addList = new ArrayList<>();
......@@ -410,25 +408,71 @@ public class GroupTagBizImpl implements GroupTagBiz {
if (ListUtils.isEmpty(list)) {
return;
}
EXECUTOR_SINGLE_SERVICE.execute(() -> {
String fileName = "微信群导出_" + DateUtils.getShortDateStr();
ThreadPoolUtils.EXPORT_THREAD_POOL.execute(() -> {
String fileName = "微信群导出";
String zipTitle = "微信群导出_" + DateUtils.getShortDateStr();
Boolean isSuccess = true;
String fileUrl = "";
try {
setGroupInfo(list);
this.setGroupMessageInfo(list);
fileUrl = exportGroupBrandfile(list, fileName);
fileUrl = packExcelZip4GroupBrand(list, fileName, zipTitle);
} catch (Exception e) {
log.error("生成导出文件失败" + e.getMessage(), e);
isSuccess = false;
}
// 发送消息
if (isSuccess) {
sendNotify(partyId, fileUrl, fileName);
sendNotify(partyId, fileUrl, zipTitle);
}
});
}
/**
* excel打包
*/
private String packExcelZip4GroupBrand(List<GroupTagDTO> list, String fileName, String zipTitle) {
Integer totalCount = list.size();
// 分批Excel文件URL
List<String[]> fileUrls = new ArrayList<String[]>();
// 每个Excel大小
Integer perExcelSize = 10000;
// 单个excel文件存储
if (totalCount <= perExcelSize) {
setGroupInfo(list);
this.setGroupMessageInfo(list);
fileUrls.add(new String[]{fileName, exportGroupBrandfile(list, fileName)});
}
// 多个excel文件存储(//大于10000条记录)
else {
int excelNums = 0;
if (totalCount % perExcelSize == 0) {
excelNums = totalCount / perExcelSize;
} else {
excelNums = totalCount / perExcelSize + 1;
}
for (int i = 0; i < excelNums; i++) {
List<GroupTagDTO> exportList;
if (i == excelNums - 1) {
exportList = list.subList(i * perExcelSize, list.size());
} else {
exportList = list.subList(i * perExcelSize, (i + 1) * perExcelSize);
}
setGroupInfo(exportList);
this.setGroupMessageInfo(exportList);
fileUrls.add(new String[]{fileName, exportGroupBrandfile(exportList, fileName)});
}
}
// 压缩包url
String resultUrl = null;
// 压缩文件
if (!ListUtils.isEmpty(fileUrls)) {
log.info("压缩文件fileUrls:" + fileUrls + "为:" + zipTitle);
UploadResultInfo uploadResultInfo = CompressUtils.zip(fileUrls, zipTitle);
resultUrl = uploadResultInfo.getUrl();
}
return resultUrl;
}
/**
* 填充群消息数量
* @param groupTagDTOS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment