Просмотр исходного кода

2024-12-06 矿大南湖小程序准入申请列表查询效率低优化代码。

chaiyunlong 1 год назад
Родитель
Сommit
f018cb7bc8

+ 22 - 5
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/LabSecurityApplyController.java

@@ -42,6 +42,8 @@ import java.net.HttpURLConnection;
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * 安全准入申请Controller
@@ -513,7 +515,7 @@ public class LabSecurityApplyController extends BaseController {
     @GetMapping("/listOrderByYmd")
     @ApiOperation(value = "查询安全准入审核列表")
     public TableDataInfo<Map<String, Object>> selectLabCheckRecordListOrderBydate(LabSecurityApplyVO labSecurityApplyVO) {
-        startPage();
+
         ///获取当前登录用户信息
         LoginModel sysUser = tokenService.getLoginUser();
 
@@ -538,13 +540,28 @@ public class LabSecurityApplyController extends BaseController {
             //学生登录
             labSecurityApplyVO.setUserId(sysUser.getUserId());
         }
+        startPage();
         //查询日期
         List<LabSecurityApplyVO> list = labSecurityApplyService.selectLabSecurityApplyListOrderBydate(labSecurityApplyVO);
+        List<LabSecurityApplyVO> list2 = labSecurityApplyService.selectLabSecurityApplyListYmd(labSecurityApplyVO);
+        //日期格式转换
+        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
+
+        //日期匹配函数
+        Function <LabSecurityApplyVO,List<LabSecurityApplyVO>> function = a->Optional.ofNullable(list2).orElseGet(Collections::emptyList)
+                .stream()
+                .filter(p->{
+                    String createTime1 = format.format(a.getCreatTime());
+                    String createTime2 = format.format(p.getCreatTime());
+                    if(createTime1.equals(createTime2)){
+                        return true;
+                    }
+                    return false;
+                })
+                .collect(Collectors.toList());
 
-        for (int i = 0; i < list.size(); i++) {
-            labSecurityApplyVO.setCreatTime(list.get(i).getCreatTime());
-            List<LabSecurityApplyVO> list2 = labSecurityApplyService.selectLabSecurityApplyListYmd(labSecurityApplyVO);
-            list.get(i).setApplyList(list2);
+        for(LabSecurityApplyVO secApplyVO : list){
+            secApplyVO.setApplyList(function.apply(secApplyVO));
         }
         return getDataTable(list);
     }