perf(文档对比): 国内、海外、企业添加逻辑删除标识,优化重构文档对比查询速度,更改填充属性逻辑

This commit is contained in:
yjz
2023-10-11 11:57:58 +08:00
parent a856ec849f
commit 745f7d4a1f
4 changed files with 99 additions and 19 deletions
@@ -3,6 +3,7 @@ package com.jero.modules.compare.controller;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.api.vo.Result;
@@ -39,8 +40,11 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
@@ -99,16 +103,90 @@ public class SarFileCompareInfoController extends JeroController<SarFileCompareI
queryWrapper.orderByDesc(SarFileCompareInfo::getCreateTime);
Page<SarFileCompareInfo> page = new Page<>(pageNo, pageSize);
IPage<SarFileCompareInfo> pageList = sarFileCompareInfoService.page(page, queryWrapper);
// 提取 编号1、编号2
List<String> serialNumberList = new ArrayList<>();
List<String> serialNumberLeftList = pageList.getRecords().stream().map(SarFileCompareInfo::getSerialNumberLeft).collect(Collectors.toList());
List<String> serialNumberRightList = pageList.getRecords().stream().map(SarFileCompareInfo::getSerialNumberRight).collect(Collectors.toList());
serialNumberList.addAll(serialNumberLeftList);
serialNumberList.addAll(serialNumberRightList);
// 国内
List<LawsDomesticStandard> lawsDomesticStandards = new ArrayList<>();
// 海外
List<LawsOverseasStandard> lawsOverseasStandards = new ArrayList<>();
// 企业
List<LawsEnterpriseStandard> lawsEnterpriseStandards = new ArrayList<>();
// 获取编号对应的国内、海外、企业信息
if (!serialNumberList.isEmpty()){
lawsDomesticStandards = lawsDomesticStandardService.list(new QueryWrapper<LawsDomesticStandard>().lambda().in(LawsDomesticStandard::getStandardNumber, serialNumberList));
lawsOverseasStandards = lawsOverseasStandardService.list(new QueryWrapper<LawsOverseasStandard>().lambda().in(LawsOverseasStandard::getStandardNumber, serialNumberList));
lawsEnterpriseStandards = ILawsEnterpriseStandardService.list(new QueryWrapper<LawsEnterpriseStandard>().lambda().in(LawsEnterpriseStandard::getStandardNumber, serialNumberList));
}
for (SarFileCompareInfo info : pageList.getRecords()) {
info.setReleaseStateTitle(ReleaseConditionEnum.getTextByValue(info.getReleaseState(), cut));
info.setFileTypeLeft(getFileTypeText(info.getFileTypeLeft(), cut));
info.setFileTypeRight(getFileTypeText(info.getFileTypeRight(), cut));
//根据左右标准编号赋值标准ID、标准来源4个字段值,补充创建人
this.assignment(info);
// 根据编号赋值标准ID、标准来源补充创建人
setProperty(info, lawsDomesticStandards, lawsOverseasStandards, lawsEnterpriseStandards);
}
return Result.OK(pageList);
}
private void setProperty(SarFileCompareInfo info, List<LawsDomesticStandard> lawsDomesticStandards, List<LawsOverseasStandard> lawsOverseasStandards, List<LawsEnterpriseStandard> lawsEnterpriseStandards) {
// 编号1
String serialNumberLeft = info.getSerialNumberLeft();
// 编号2
String serialNumberRight = info.getSerialNumberRight();
if (StringUtils.isNotBlank(serialNumberLeft)){
judgeLeftOrRight(info, lawsDomesticStandards, lawsOverseasStandards, lawsEnterpriseStandards, serialNumberLeft, "left");
}
if (StringUtils.isNotBlank(serialNumberRight)){
judgeLeftOrRight(info, lawsDomesticStandards, lawsOverseasStandards, lawsEnterpriseStandards, serialNumberLeft, "right");
}
// 创建人
info.setCreateNameNo(sysUserService.getNameNoByUsername(info.getCreateBy()));
}
private static void judgeLeftOrRight(SarFileCompareInfo info, List<LawsDomesticStandard> lawsDomesticStandards, List<LawsOverseasStandard> lawsOverseasStandards, List<LawsEnterpriseStandard> lawsEnterpriseStandards, String serialNumberLeft, String leftOrRight) {
// 国内
Optional<LawsDomesticStandard> lawsDomesticStandardOptional = lawsDomesticStandards.stream().filter(v -> serialNumberLeft.equals(v.getStandardNumber())).findFirst();
if (lawsDomesticStandardOptional.isPresent()){
if ("left".equals(leftOrRight)){
info.setStandardSourceLeft(CommonConstant.STANDARD_SOURCE_1);
info.setStandardIdLeft(lawsDomesticStandardOptional.get().getId());
}else {
info.setStandardSourceRight(CommonConstant.STANDARD_SOURCE_1);
info.setStandardIdRight(lawsDomesticStandardOptional.get().getId());
}
return;
}
// 海外
Optional<LawsOverseasStandard> lawsOverseasStandardOptional = lawsOverseasStandards.stream().filter(v -> serialNumberLeft.equals(v.getStandardNumber())).findFirst();
if (lawsOverseasStandardOptional.isPresent()){
if ("left".equals(leftOrRight)){
info.setStandardSourceLeft(CommonConstant.STANDARD_SOURCE_2);
info.setStandardIdLeft(lawsOverseasStandardOptional.get().getId());
}else {
info.setStandardSourceRight(CommonConstant.STANDARD_SOURCE_2);
info.setStandardIdRight(lawsOverseasStandardOptional.get().getId());
}
return;
}
// 企业
Optional<LawsEnterpriseStandard> lawsEnterpriseStandardOptional = lawsEnterpriseStandards.stream().filter(v -> serialNumberLeft.equals(v.getStandardNumber())).findFirst();
if (lawsEnterpriseStandardOptional.isPresent()){
if ("left".equals(leftOrRight)){
info.setStandardSourceLeft(CommonConstant.STANDARD_SOURCE_3);
info.setStandardIdLeft(lawsEnterpriseStandardOptional.get().getId());
}else {
info.setStandardSourceRight(CommonConstant.STANDARD_SOURCE_3);
info.setStandardIdRight(lawsEnterpriseStandardOptional.get().getId());
}
}
}
private void assignment(SarFileCompareInfo info) {
String serialNumberLeft = info.getSerialNumberLeft();
String serialNumberRight = info.getSerialNumberRight();