Commit c5f54a1c authored by lcl's avatar lcl

数据解析批量插入优化

parent be0554b4
...@@ -54,8 +54,6 @@ public class DataAnalysisComponent { ...@@ -54,8 +54,6 @@ public class DataAnalysisComponent {
if (ObjectUtils.isEmpty(fileList)) return; if (ObjectUtils.isEmpty(fileList)) return;
//文件处理 //文件处理
for (CbProjectFile file : fileList) { for (CbProjectFile file : fileList) {
// if (file.getDelFlag() == 0) {
//文件下载 //文件下载
InputStream inputStream = ossService.downFileIO(file.getFileOssId()); InputStream inputStream = ossService.downFileIO(file.getFileOssId());
if (ObjectUtil.isNull(inputStream)) { if (ObjectUtil.isNull(inputStream)) {
...@@ -84,24 +82,28 @@ public class DataAnalysisComponent { ...@@ -84,24 +82,28 @@ public class DataAnalysisComponent {
} }
transactionTemplate.execute(status -> { transactionTemplate.execute(status -> {
try { try {
//分批次插入 // //分批次插入
if (quantitySummaryList.size() > 1000) { // if (quantitySummaryList.size() > 1000) {
int index = 0; // int index = 0;
int sum = quantitySummaryList.size(); // int sum = quantitySummaryList.size();
while (index < sum) { // while (index < sum) {
List<CbQuantitySummary> divideList = quantitySummaryList.subList(index, Math.min(index + 1000, sum)); // List<CbQuantitySummary> divideList = quantitySummaryList.subList(index, Math.min(index + 1000, sum));
boolean b = quantitySummaryService.saveBatch(divideList); // boolean b = quantitySummaryService.saveBatch(divideList);
if (!b) { // if (!b) {
throw new ServiceException("数据插入失败!"); // throw new ServiceException("数据插入失败!");
} // }
index += 1000; // index += 1000;
} // }
} else { // } else {
boolean b = quantitySummaryService.saveBatch(quantitySummaryList); // boolean b = quantitySummaryService.saveBatch(quantitySummaryList);
if (!b) { // if (!b) {
// throw new ServiceException("数据插入失败!");
// }
// }
boolean a = quantitySummaryService.batchInsert(quantitySummaryList);
if (!a) {
throw new ServiceException("数据插入失败!"); throw new ServiceException("数据插入失败!");
} }
}
file.setFileParseStatus(2); file.setFileParseStatus(2);
boolean b = projectFileService.updateById(file); boolean b = projectFileService.updateById(file);
if (!b) { if (!b) {
...@@ -115,10 +117,6 @@ public class DataAnalysisComponent { ...@@ -115,10 +117,6 @@ public class DataAnalysisComponent {
} }
return Boolean.TRUE; return Boolean.TRUE;
}); });
// } else {
// quantitySummaryService.remove(Wrappers.<CbQuantitySummary>lambdaQuery().eq(CbQuantitySummary::getCbProjectFileId, file.getId()));
// projectFileService.removeById(file);
// }
} }
} }
} }
...@@ -11,6 +11,7 @@ import java.io.Serializable; ...@@ -11,6 +11,7 @@ import java.io.Serializable;
import com.dsk.common.annotation.Excel; import com.dsk.common.annotation.Excel;
import lombok.Data; import lombok.Data;
import org.springframework.util.ObjectUtils;
/** /**
* 成本-工料汇总基本表(CbQuantitySummary)表实体类 * 成本-工料汇总基本表(CbQuantitySummary)表实体类
...@@ -146,7 +147,7 @@ public class CbQuantitySummary implements Serializable { ...@@ -146,7 +147,7 @@ public class CbQuantitySummary implements Serializable {
private String num; private String num;
public void setNum(String num) { public void setNum(String num) {
this.number = Integer.valueOf(num); this.number = ObjectUtils.isEmpty(num) ? null : Integer.valueOf(num);
} }
} }
...@@ -20,6 +20,7 @@ import java.util.Map; ...@@ -20,6 +20,7 @@ import java.util.Map;
*/ */
public interface CbQuantitySummaryMapper extends BaseMapperPlus<CbQuantitySummaryMapper,CbQuantitySummary,CbQuantitySummary> { public interface CbQuantitySummaryMapper extends BaseMapperPlus<CbQuantitySummaryMapper,CbQuantitySummary,CbQuantitySummary> {
int batchInsert(@Param("list") List<CbQuantitySummary> list);
List<Map<String, Object>> selectSubject(CbProjectBaseBo bo); List<Map<String, Object>> selectSubject(CbProjectBaseBo bo);
...@@ -29,5 +30,7 @@ public interface CbQuantitySummaryMapper extends BaseMapperPlus<CbQuantitySummar ...@@ -29,5 +30,7 @@ public interface CbQuantitySummaryMapper extends BaseMapperPlus<CbQuantitySummar
List<CbQuantitySummaryListVo> selectListBySubject(CbQuantitySummaryListBo bo); List<CbQuantitySummaryListVo> selectListBySubject(CbQuantitySummaryListBo bo);
} }
...@@ -28,5 +28,7 @@ public interface ICbQuantitySummaryService extends IService<CbQuantitySummary> { ...@@ -28,5 +28,7 @@ public interface ICbQuantitySummaryService extends IService<CbQuantitySummary> {
void pushData(CbQuantitySummaryActual bo); void pushData(CbQuantitySummaryActual bo);
boolean batchInsert(List<CbQuantitySummary> list);
} }
...@@ -139,5 +139,11 @@ public class CbQuantitySummaryServiceImpl extends ServiceImpl<CbQuantitySummaryM ...@@ -139,5 +139,11 @@ public class CbQuantitySummaryServiceImpl extends ServiceImpl<CbQuantitySummaryM
//TODO 推送数据 //TODO 推送数据
} }
@Override
public boolean batchInsert(List<CbQuantitySummary> list) {
int i = baseMapper.batchInsert(list);
return i == list.size();
}
} }
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dsk.cscec.mapper.CbQuantitySummaryMapper"> <mapper namespace="com.dsk.cscec.mapper.CbQuantitySummaryMapper">
<insert id="batchInsert" parameterType="com.dsk.cscec.domain.CbQuantitySummary">
INSERT INTO cscec_bms.cb_quantity_summary
(project_id, `number`, cb_stage, cb_subject_name, company_no, org_no, cb_name, job_content,
calculation_rule, unit, material_description, guide_price, bid_unit_price, unit_price_difference, quantity,
combined_price, combined_price_tax, brand_name, bid_source, remark, cb_project_file_id)
VALUES
<foreach collection="list" item="item" separator="," >
(#{item.projectId}, #{item.number}, #{item.cbStage}, #{item.cbSubjectName}, #{item.companyNo}, #{item.orgNo}, #{item.cbName},
#{item.jobContent},#{item.calculationRule},#{item.unit},#{item.materialDescription},#{item.guidePrice},
#{item.bidUnitPrice},#{item.unitPriceDifference},#{item.quantity},#{item.combinedPrice},#{item.combinedPriceTax},
#{item.brandName},#{item.bidSource},#{item.remark},#{item.cbProjectFileId})
</foreach>
</insert>
<select id="selectSubject" resultType="java.util.Map"> <select id="selectSubject" resultType="java.util.Map">
select select
......
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