Browse Source

fix: 查询性能优化

master
buaixuexideshitongxue 4 weeks ago
parent
commit
f929ed7c58
  1. 49
      src/main/java/com/biutag/supervision/controller/report/ReportProjectController.java
  2. 10
      src/main/java/com/biutag/supervision/service/SupDepartService.java
  3. 2
      src/main/resources/mapper/ReportProjectMapper.xml

49
src/main/java/com/biutag/supervision/controller/report/ReportProjectController.java

@ -31,6 +31,7 @@ import com.biutag.supervision.pojo.param.Report.ReportProjectQueryParam;
import com.biutag.supervision.pojo.param.entryWindow.EntryWindowQueryParam; import com.biutag.supervision.pojo.param.entryWindow.EntryWindowQueryParam;
import com.biutag.supervision.pojo.param.statement.StatementQueryParam; import com.biutag.supervision.pojo.param.statement.StatementQueryParam;
import com.biutag.supervision.pojo.request.reportProject.ReportProjectDeleteRequest; import com.biutag.supervision.pojo.request.reportProject.ReportProjectDeleteRequest;
import com.biutag.supervision.pojo.vo.DepartTree;
import com.biutag.supervision.pojo.vo.entryWindow.EntryWindowExcelVo; import com.biutag.supervision.pojo.vo.entryWindow.EntryWindowExcelVo;
import com.biutag.supervision.pojo.vo.entryWindow.EntryWindowVo; import com.biutag.supervision.pojo.vo.entryWindow.EntryWindowVo;
import com.biutag.supervision.pojo.vo.excel.ExcelControlPriceVo; import com.biutag.supervision.pojo.vo.excel.ExcelControlPriceVo;
@ -258,6 +259,11 @@ public class ReportProjectController {
@PostMapping("/pageConditionVo") @PostMapping("/pageConditionVo")
public Result<Page<ConditionVo>> pageConditionVo(@RequestBody StatementQueryParam queryParam){ public Result<Page<ConditionVo>> pageConditionVo(@RequestBody StatementQueryParam queryParam){
QueryWrapper<ReportProject> wrapper=new QueryWrapper<>(); QueryWrapper<ReportProject> wrapper=new QueryWrapper<>();
List<SupDepart> departs = departService.list(new LambdaQueryWrapper<SupDepart>()
.orderByAsc(SupDepart::getOrderNo));
List<DepartTree> departTree = departService.buildTreeAll(departs);
Map<String, SupDepart> departMap = departs.stream()
.collect(Collectors.toMap(SupDepart::getId, depart -> depart));
wrapper.eq(StrUtil.isNotBlank(queryParam.getNode()),"p.node",queryParam.getNode()) wrapper.eq(StrUtil.isNotBlank(queryParam.getNode()),"p.node",queryParam.getNode())
.like(StrUtil.isNotBlank(queryParam.getReportName()),"p.report_name",queryParam.getReportName()) .like(StrUtil.isNotBlank(queryParam.getReportName()),"p.report_name",queryParam.getReportName())
@ -278,10 +284,10 @@ public class ReportProjectController {
} }
if (StrUtil.isNotBlank(queryParam.getAuditUnitId())) { if (StrUtil.isNotBlank(queryParam.getAuditUnitId())) {
// 获取选择的审计单位及其所有子部门的ID // 获取选择的审计单位及其所有子部门的ID
wrapper.in("p.audit_unit_id", departService.getAllNodeIds(queryParam.getAuditUnitId())); wrapper.in("p.audit_unit_id", departService.getAllNodeIds(queryParam.getAuditUnitId(), departTree));
} }
if (StrUtil.isNotBlank(queryParam.getProjectUnitId())){ if (StrUtil.isNotBlank(queryParam.getProjectUnitId())){
wrapper.in("p.project_unit_id", departService.getAllNodeIds(queryParam.getProjectUnitId())); wrapper.in("p.project_unit_id", departService.getAllNodeIds(queryParam.getProjectUnitId(), departTree));
} }
wrapper.groupBy("p.id"); wrapper.groupBy("p.id");
wrapper.eq("p.delete_flag", DeleteStatusEnum.NO.getCode()); wrapper.eq("p.delete_flag", DeleteStatusEnum.NO.getCode());
@ -291,12 +297,12 @@ public class ReportProjectController {
boolean superAuth = AppConstants.USER_TYPE_SUPER.equals(user.getUserType()); boolean superAuth = AppConstants.USER_TYPE_SUPER.equals(user.getUserType());
boolean firstAuth = superAuth || user.getRoleCodes().contains(RoleCodeEnum.FIRST_ADMIN.getCode()); boolean firstAuth = superAuth || user.getRoleCodes().contains(RoleCodeEnum.FIRST_ADMIN.getCode());
List<String> userAuthOrgIds = firstAuth List<String> userAuthOrgIds = firstAuth
? departService.getAllNodeIds(ROOTID) ? departService.getAllNodeIds(ROOTID, departTree)
: (user.getAuthDepartIds().isEmpty() ? departService.getAllNodeIds(user.getDepartId()) : departService.getAllNodeIds(user.getAuthDepartIds())); : (user.getAuthDepartIds().isEmpty() ? departService.getAllNodeIds(user.getDepartId(), departTree) : departService.getAllNodeIds(user.getAuthDepartIds(), departTree));
if (!superAuth) { if (!superAuth) {
wrapper.and(p -> p.in("p.audit_unit_id", userAuthOrgIds).or().in("p.project_unit_id", userAuthOrgIds)); wrapper.and(p -> p.in("p.audit_unit_id", userAuthOrgIds).or().in("p.project_unit_id", userAuthOrgIds));
} }
List<String> dszdOrgIds = departService.getAllNodeIds(AppConstants.DSZD); List<String> dszdOrgIds = departService.getAllNodeIds(AppConstants.DSZD, departTree);
// 页面鉴权 // 页面鉴权
Map<String, Consumer<QueryWrapper<ReportProject>>> authStrategy = Map.of( Map<String, Consumer<QueryWrapper<ReportProject>>> authStrategy = Map.of(
// “审计单位”为督审支队的项目 // “审计单位”为督审支队的项目
@ -319,25 +325,30 @@ public class ReportProjectController {
Page<ConditionVo> conditionPage = reportProjectService.getConditionPage(new Page<>(queryParam.getCurrent(), queryParam.getSize()), wrapper); Page<ConditionVo> conditionPage = reportProjectService.getConditionPage(new Page<>(queryParam.getCurrent(), queryParam.getSize()), wrapper);
conditionPage.getRecords().forEach(s->{ conditionPage.getRecords().forEach(s->{
SupDepart auditById = departService.getById(s.getAuditUnitId()); s.setAuditUnitStr(getConditionUnitStr(departMap, s.getAuditUnitId(),
SupDepart projectById = departService.getById(s.getProjectUnitId()); StrUtil.blankToDefault(s.getAuditUnitStr(), s.getAuditUnit())));
if (3==(auditById.getLevel())){ s.setProjectUnitStr(getConditionUnitStr(departMap, s.getProjectUnitId(),
SupDepart byPId = departService.getById(auditById.getPid()); StrUtil.blankToDefault(s.getProjectUnitStr(), s.getProjectUnit())));
s.setAuditUnitStr(byPId.getShortName() +"/" + auditById.getShortName());
}else {
s.setAuditUnitStr(auditById.getShortName() +"/");
}
if (3==projectById.getLevel()){
SupDepart byPId = departService.getById(projectById.getPid());
s.setProjectUnitStr(byPId.getShortName() +"/" + projectById.getShortName());
}else {
s.setProjectUnitStr(projectById.getShortName() +"/");
}
}); });
return Result.success(conditionPage); return Result.success(conditionPage);
} }
private String getConditionUnitStr(Map<String, SupDepart> departMap, String departId, String fallbackName) {
SupDepart depart = departMap.get(departId);
if (depart == null) {
return StrUtil.blankToDefault(fallbackName, "");
}
if (Integer.valueOf(3).equals(depart.getLevel())) {
SupDepart parent = departMap.get(depart.getPid());
if (parent == null) {
return StrUtil.blankToDefault(fallbackName, "");
}
return parent.getShortName() + "/" + depart.getShortName();
}
return depart.getShortName() + "/";
}
//审计情况表导出 //审计情况表导出
@PostMapping("/excelConditionVo") @PostMapping("/excelConditionVo")
public void excelConditionVo(@RequestBody StatementQueryParam queryParam, HttpServletResponse response) throws Exception { public void excelConditionVo(@RequestBody StatementQueryParam queryParam, HttpServletResponse response) throws Exception {

10
src/main/java/com/biutag/supervision/service/SupDepartService.java

@ -70,6 +70,16 @@ public class SupDepartService extends ServiceImpl<SupDepartMapper, SupDepart> {
return getAllNode(departIds).stream().map(DepartTree::getId).toList(); return getAllNode(departIds).stream().map(DepartTree::getId).toList();
} }
public List<String> getAllNodeIds(String departId, List<DepartTree> treeList) {
return getAllNodeIds(List.of(departId), treeList);
}
public List<String> getAllNodeIds(Collection<String> departIds, List<DepartTree> treeList) {
List<DepartTree> nodes = new ArrayList<>();
getAllNodeRecursive(departIds, treeList, nodes);
return nodes.stream().map(DepartTree::getId).toList();
}
public List<DepartTree> getAllNode(Collection<String> departIds) { public List<DepartTree> getAllNode(Collection<String> departIds) {
List<DepartTree> treeList = buildTreeAll(); List<DepartTree> treeList = buildTreeAll();
List<DepartTree> nodes = new ArrayList<>(); List<DepartTree> nodes = new ArrayList<>();

2
src/main/resources/mapper/ReportProjectMapper.xml

@ -145,7 +145,7 @@
LIMIT 1 LIMIT 1
) as approvalSupervisor, ) as approvalSupervisor,
rv.review_content as content rv.review_content as content
from report_project p LEFT JOIN report_flow flow on p.id = flow.report_id from report_project p
left join report_review rv on p.id = rv.report_id left join report_review rv on p.id = rv.report_id
${ew.getCustomSqlSegment} ${ew.getCustomSqlSegment}
</select> </select>

Loading…
Cancel
Save