|
@@ -14,7 +14,6 @@ import com.jeesite.modules.basedata.entity.TemplateInfo;
|
|
|
import com.jeesite.modules.report.dao.ReportHtmlDao;
|
|
|
import com.jeesite.modules.report.dao.ResearchReportDao;
|
|
|
import com.jeesite.modules.report.dao.SiteInfoDao;
|
|
|
-import com.jeesite.modules.report.dto.ImportMarketScaleMessage;
|
|
|
import com.jeesite.modules.report.dto.ResearchReportDto;
|
|
|
import com.jeesite.modules.report.dto.ResearchReportMarketDrivenDto;
|
|
|
import com.jeesite.modules.report.dto.ResearchReportMarketScaleDto;
|
|
@@ -24,12 +23,11 @@ import com.jeesite.modules.report.entity.SiteInfo;
|
|
|
import com.jeesite.modules.report.util.TransContentUtils;
|
|
|
import com.jeesite.modules.report.util.XmlUtils;
|
|
|
import com.jeesite.modules.sys.dao.DictCusDataDao;
|
|
|
-import com.jeesite.modules.sys.dao.DictDataDao;
|
|
|
import com.jeesite.modules.sys.entity.DictData;
|
|
|
import com.jeesite.modules.sys.utils.RedisUtil;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.dom4j.DocumentException;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
-import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -37,8 +35,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
-import java.util.concurrent.ExecutionException;
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
|
/**
|
|
@@ -58,9 +54,6 @@ public class ResearchReportService extends CrudService<ResearchReportDao, Resear
|
|
|
private ReportHtmlDao reportHtmlDao;
|
|
|
@Resource
|
|
|
private RedisUtil redisUtil;
|
|
|
- @Resource
|
|
|
- private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 获取单条数据
|
|
@@ -947,117 +940,62 @@ public class ResearchReportService extends CrudService<ResearchReportDao, Resear
|
|
|
if(file.isEmpty()){
|
|
|
throw new ServiceException("请选择要导入的文件");
|
|
|
}
|
|
|
+ int saveCount = 0;
|
|
|
StringBuffer msg = new StringBuffer();
|
|
|
ExcelImport ei = new ExcelImport(file,2,0);
|
|
|
-
|
|
|
- List<ImportMarketScaleMessage> importMarketScaleMessages = new ArrayList<>();
|
|
|
List<ResearchReportMarketScaleDto> list = ei.getDataList(ResearchReportMarketScaleDto.class, new String[0]);
|
|
|
-
|
|
|
- List<CompletableFuture<Boolean>> futures = new ArrayList<>();
|
|
|
- for (List<ResearchReportMarketScaleDto> reportMarketScaleData : splitList(list, 500)) {
|
|
|
- CompletableFuture<Boolean> future = CompletableFuture.supplyAsync(() -> {
|
|
|
- ImportMarketScaleMessage importMarketScaleMessage = importMarketScale(reportMarketScaleData);
|
|
|
- importMarketScaleMessages.add(importMarketScaleMessage);
|
|
|
- return true;
|
|
|
- }, threadPoolTaskExecutor);
|
|
|
- futures.add(future);
|
|
|
- }
|
|
|
- try {
|
|
|
- CompletableFuture[] futureArr = {};
|
|
|
- CompletableFuture.allOf(futures.toArray(futureArr)).get();
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (ExecutionException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- int successNum = 0;
|
|
|
-
|
|
|
- StringBuilder failureMsg = new StringBuilder();
|
|
|
- for (ImportMarketScaleMessage i:importMarketScaleMessages)
|
|
|
- {
|
|
|
- successNum += i.getSuccessNum();
|
|
|
- failureMsg.append(i.getFailureMsg());
|
|
|
- }
|
|
|
-
|
|
|
- // 全部保存
|
|
|
- int total = list.size();
|
|
|
- if(total == successNum){
|
|
|
- failureMsg.insert(0,"数据导入成功,共"+successNum+"条");
|
|
|
- }else if(successNum > 0){
|
|
|
- failureMsg.insert(0,"数据部分导入成功,成功"+successNum+"条,失败"+(total - successNum)+"条!<br/>");
|
|
|
- }
|
|
|
- return failureMsg.toString();
|
|
|
- }
|
|
|
-
|
|
|
- public ImportMarketScaleMessage importMarketScale(List<ResearchReportMarketScaleDto> list){
|
|
|
-
|
|
|
- int successNum = 0;
|
|
|
- int failureNum = 0;
|
|
|
- StringBuilder msg = new StringBuilder();
|
|
|
-
|
|
|
+ List<ResearchReport> updateList = new ArrayList<>();
|
|
|
if(list != null && list.size() > 0){
|
|
|
for(int i = 0; i < list.size(); i++){
|
|
|
boolean isSave = true;
|
|
|
ResearchReportMarketScaleDto dto = list.get(i);
|
|
|
if(StringUtils.isBlank(dto.getReportCode())){
|
|
|
- //msg.append("第"+(i+1)+"行,报告代码不能为空!");
|
|
|
- msg.append("<br/>").append("报告代码 ").append(dto.getReportCode()).append(" 不能为空");
|
|
|
+ msg.append("第"+(i+1)+"行,报告代码不能为空!");
|
|
|
isSave = false;
|
|
|
}
|
|
|
if(StringUtils.isBlank(dto.getReportRegion())){
|
|
|
- //msg.append("第"+(i+1)+"行,版本不能为空!");
|
|
|
- msg.append("<br/>").append("版本 ").append(dto.getReportRegion()).append(" 不能为空");
|
|
|
+ msg.append("第"+(i+1)+"行,版本不能为空!");
|
|
|
isSave = false;
|
|
|
}
|
|
|
if(StringUtils.isBlank(dto.getMarketScale())){
|
|
|
- //msg.append("第"+(i+1)+"行,市场规模不能为空!");
|
|
|
- msg.append("<br/>").append("市场规模 ").append(dto.getMarketScale()).append(" 不能为空");
|
|
|
+ msg.append("第"+(i+1)+"行,市场规模不能为空!");
|
|
|
isSave = false;
|
|
|
}
|
|
|
if(isSave){
|
|
|
- try {
|
|
|
- ResearchReport where = new ResearchReport();
|
|
|
- where.setReportCode(dto.getReportCode());
|
|
|
- where.setReportRegion(dto.getReportRegion());
|
|
|
- ResearchReport researchReport = dao.getByEntity(where);
|
|
|
- if (researchReport != null) {
|
|
|
- researchReport.setMarketScale(String.format(Constants.textFormat, dto.getMarketScale()).replaceAll("\\n", "<br/>"));
|
|
|
- successNum += dao.update(researchReport);
|
|
|
- } else {
|
|
|
- //msg.append("第"+(i+1)+"行,研究报告对应为空!");
|
|
|
- msg.append("<br/>").append(dto.getReportCode()).append(" 不能为空");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- msg.append("<br/>").append("研究报告报告代码与版本存在重复!");
|
|
|
- }
|
|
|
+ ResearchReport update = new ResearchReport();
|
|
|
+ update.setReportCode(dto.getReportCode());
|
|
|
+ update.setReportRegion(dto.getReportRegion());
|
|
|
+ update.setMarketScale(String.format(Constants.textFormat, dto.getMarketScale()).replaceAll("\\n", "<br/>"));
|
|
|
+ updateList.add(update);
|
|
|
}
|
|
|
}
|
|
|
+ if (CollectionUtils.isEmpty(updateList)) {
|
|
|
+ msg.append("数据为空,导入失败!");
|
|
|
+ } else {
|
|
|
+ // 在循环中分批处理
|
|
|
+ int batchSize = 1000; // 测试调整这个值
|
|
|
+ for (int i = 0; i < updateList.size(); i += batchSize) {
|
|
|
+ int end = Math.min(i + batchSize, updateList.size());
|
|
|
+ List<ResearchReport> subList = updateList.subList(i, end);
|
|
|
+ saveCount += subList.stream().mapToInt(sb -> dao.updateMarketScale(sb)).sum();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ msg.append("数据为空,导入失败!");
|
|
|
}
|
|
|
|
|
|
- ImportMarketScaleMessage importMarketScaleMessage = new ImportMarketScaleMessage();
|
|
|
- importMarketScaleMessage.setFailureMsg(msg);
|
|
|
- importMarketScaleMessage.setSuccessNum(successNum);
|
|
|
- importMarketScaleMessage.setFailureNum(failureNum);
|
|
|
- return importMarketScaleMessage;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 按照数量切分导入列表
|
|
|
- * @param list
|
|
|
- * @param chunkSize
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<List<ResearchReportMarketScaleDto>> splitList(List<ResearchReportMarketScaleDto> list, int chunkSize) {
|
|
|
- List<List<ResearchReportMarketScaleDto>> result = new ArrayList<>();
|
|
|
- for (int i = 0; i < list.size(); i += chunkSize) {
|
|
|
- int end = Math.min(i + chunkSize, list.size());
|
|
|
- result.add(list.subList(i, end));
|
|
|
+ // 全部保存
|
|
|
+ int total = list.size();
|
|
|
+ if(total == saveCount){
|
|
|
+ msg.insert(0,"数据导入成功,共"+saveCount+"条");
|
|
|
+ }else if(saveCount > 0){
|
|
|
+ msg.insert(0,"数据部分导入成功,成功"+saveCount+"条,失败"+(total - saveCount)+"条!<br/>");
|
|
|
+ } else {
|
|
|
+ msg.insert(0,"数据导入失败,共"+total+"条!");
|
|
|
}
|
|
|
- return result;
|
|
|
+ return msg.toString();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Transactional
|
|
|
public String marketDrivenImportData(MultipartFile file) throws Exception {
|
|
|
if(file.isEmpty()){
|
|
@@ -1067,6 +1005,7 @@ public class ResearchReportService extends CrudService<ResearchReportDao, Resear
|
|
|
StringBuffer msg = new StringBuffer();
|
|
|
ExcelImport ei = new ExcelImport(file,2,0);
|
|
|
List<ResearchReportMarketDrivenDto> list = ei.getDataList(ResearchReportMarketDrivenDto.class, new String[0]);
|
|
|
+ List<ResearchReport> updateList = new ArrayList<>();
|
|
|
if(list != null && list.size() > 0){
|
|
|
for(int i = 0; i < list.size(); i++){
|
|
|
boolean isSave = true;
|
|
@@ -1084,20 +1023,22 @@ public class ResearchReportService extends CrudService<ResearchReportDao, Resear
|
|
|
isSave = false;
|
|
|
}
|
|
|
if(isSave){
|
|
|
- try {
|
|
|
- ResearchReport where = new ResearchReport();
|
|
|
- where.setReportCode(dto.getReportCode());
|
|
|
- where.setReportRegion(dto.getReportRegion());
|
|
|
- ResearchReport researchReport = dao.getByEntity(where);
|
|
|
- if (researchReport != null) {
|
|
|
- researchReport.setMarketDriven(String.format(Constants.textFormat, dto.getMarketDriven()).replaceAll("\\n", "<br/>"));
|
|
|
- saveCount += dao.update(researchReport);
|
|
|
- } else {
|
|
|
- msg.append("第"+(i+1)+"行,研究报告对应为空!");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- msg.append("第"+(i+1)+"行,研究报告报告代码与版本存在重复!");
|
|
|
- }
|
|
|
+ ResearchReport update = new ResearchReport();
|
|
|
+ update.setReportCode(dto.getReportCode());
|
|
|
+ update.setReportRegion(dto.getReportRegion());
|
|
|
+ update.setMarketDriven(String.format(Constants.textFormat, dto.getMarketDriven()).replaceAll("\\n", "<br/>"));
|
|
|
+ updateList.add(update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(updateList)) {
|
|
|
+ msg.append("数据为空,导入失败!");
|
|
|
+ } else {
|
|
|
+ // 在循环中分批处理
|
|
|
+ int batchSize = 1000; // 测试调整这个值
|
|
|
+ for (int i = 0; i < updateList.size(); i += batchSize) {
|
|
|
+ int end = Math.min(i + batchSize, updateList.size());
|
|
|
+ List<ResearchReport> subList = updateList.subList(i, end);
|
|
|
+ saveCount += subList.stream().mapToInt(sb -> dao.updateMarketDriven(sb)).sum();
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
@@ -1110,6 +1051,8 @@ public class ResearchReportService extends CrudService<ResearchReportDao, Resear
|
|
|
msg.insert(0,"数据导入成功,共"+saveCount+"条");
|
|
|
}else if(saveCount > 0){
|
|
|
msg.insert(0,"数据部分导入成功,成功"+saveCount+"条,失败"+(total - saveCount)+"条!<br/>");
|
|
|
+ } else {
|
|
|
+ msg.insert(0,"数据导入失败,共"+total+"条!");
|
|
|
}
|
|
|
return msg.toString();
|
|
|
}
|