Commit 3f6ab6e8 authored by lcl's avatar lcl

u

parent b8417920
......@@ -49,39 +49,42 @@ public class DataAnalysisComponent {
*/
@Async
public void quantitySummaryDataAnalysis(CbProjectBaseBo bo) throws Exception {
//查询工料汇总导入文件
List<CbProjectFile> fileList = projectFileService.selectAnalysisList(bo.getProjectId(), CbProjectConstants.CB_TYPE_QUANTITY_SUMMARY, bo.getCbStage());
if (ObjectUtils.isEmpty(fileList)) return;
//文件处理
for (CbProjectFile file : fileList) {
//文件下载
InputStream inputStream = ossService.downFileIO(file.getFileOssId());
if (ObjectUtil.isNull(inputStream)) {
file.setFileParseStatus(3);
file.setFailRemark("文件数据不存在");
projectFileService.updateById(file);
break;
}
//解析数据
List<CbQuantitySummary> importList = new ExcelUtils<>(CbQuantitySummary.class).importExcelAllSheet(inputStream, 1);
if (importList.isEmpty()) {
file.setFileParseStatus(3);
file.setFailRemark("表格中不存在待导入数据!");
projectFileService.updateById(file);
break;
}
List<CbQuantitySummary> quantitySummaryList = importList.stream().parallel()
.filter(item -> !ObjectUtils.isEmpty(item.getCbName()))
.peek(item -> {
item.setProjectId(bo.getProjectId());
item.setCbStage(bo.getCbStage());
item.setCbProjectFileId(file.getId());
}).collect(Collectors.toList());
if (quantitySummaryList.isEmpty()) {
throw new ServiceException("表格中不存在有效数据!");
}
transactionTemplate.execute(status -> {
try {
try {
//文件下载
InputStream inputStream = ossService.downFileIO(file.getFileOssId());
if (ObjectUtil.isNull(inputStream)) {
file.setFileParseStatus(3);
file.setFailRemark("文件数据不存在");
projectFileService.updateById(file);
break;
}
//解析数据
List<CbQuantitySummary> importList = new ExcelUtils<>(CbQuantitySummary.class).importExcelAllSheet(inputStream, 1);
if (importList.isEmpty()) {
file.setFileParseStatus(3);
file.setFailRemark("表格中不存在待导入数据!");
projectFileService.updateById(file);
break;
}
List<CbQuantitySummary> quantitySummaryList = importList.stream().parallel()
.filter(item -> !ObjectUtils.isEmpty(item.getCbName()))
.peek(item -> {
item.setProjectId(bo.getProjectId());
item.setCbStage(bo.getCbStage());
item.setCbProjectFileId(file.getId());
}).collect(Collectors.toList());
if (quantitySummaryList.isEmpty()) {
throw new ServiceException("表格中不存在有效数据!");
}
transactionTemplate.execute(status -> {
try {
// //分批次插入
// if (quantitySummaryList.size() > 1000) {
// int index = 0;
......@@ -100,23 +103,29 @@ public class DataAnalysisComponent {
// throw new ServiceException("数据插入失败!");
// }
// }
boolean a = quantitySummaryService.batchInsert(quantitySummaryList);
if (!a) {
throw new ServiceException("数据插入失败!");
}
file.setFileParseStatus(2);
boolean b = projectFileService.updateById(file);
if (!b) {
throw new ServiceException("文件状态更新失败!");
boolean a = quantitySummaryService.batchInsert(quantitySummaryList);
if (!a) {
throw new ServiceException("数据插入失败!");
}
file.setFileParseStatus(2);
boolean b = projectFileService.updateById(file);
if (!b) {
throw new ServiceException("文件状态更新失败!");
}
} catch (Exception e) {
status.setRollbackOnly();
file.setFileParseStatus(3);
file.setFailRemark(e.getMessage());
projectFileService.updateById(file);
}
} catch (Exception e) {
status.setRollbackOnly();
file.setFileParseStatus(3);
file.setFailRemark(e.getMessage());
projectFileService.updateById(file);
}
return Boolean.TRUE;
});
return Boolean.TRUE;
});
} catch (Exception e) {
file.setFileParseStatus(3);
file.setFailRemark(e.getMessage());
projectFileService.updateById(file);
}
}
}
}
......@@ -17,12 +17,11 @@
id, project_id, cb_stage, cb_type, file_name, file_oss_id, file_oss_url, file_parse_status, fail_remark,
del_flag, create_by, create_time, update_by, update_time
FROM cb_project_file
WHERE (del_flag = 0 and file_parse_status = 1
and project_id=#{projectId}
WHERE del_flag = 0 and file_parse_status in (1,3) and project_id=#{projectId}
<if test="cbStage != null">
and cb_stage =#{cbStage}
</if>
and cb_type = #{cbType})
and cb_type = #{cbType}
</select>
<update id="removeById">
......
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