Browse Source

连船记录增量分页查询优化(分页漏数据)

sbj 3 weeks ago
parent
commit
cd46fc851e

+ 16 - 3
src/main/java/com/shcd/controller/ShorePowerController.java

@@ -229,7 +229,14 @@ public class ShorePowerController {
         });
         log.info("==============> 业务转换为港航数据:{}",
             JSONObject.toJSONString(deviceInfoList));
-        deviceInfoList.forEach(x -> deviceInfoNewService.saveOrUpdate(x));
+        deviceInfoList.forEach(x -> {
+              if(x.getDeviceCertifiCateId()!=null) {
+                deviceInfoNewService.saveOrUpdate(x);
+              }else{
+                log.info("设备DeviceCertifiCateId为空:"+x);
+              }
+            }
+        );
         log.info("操作完成,共有{}条数据", deviceInfoList.size());
       }
     } catch (Exception e) {
@@ -467,10 +474,16 @@ public class ShorePowerController {
       Integer total = shorePowerScheduler.getTotal(result);
       // total > limit 继续分页调用,else 保存数据
       if(total > Integer.parseInt(limit) * Integer.parseInt(page)){
-        while (total > Integer.parseInt(limit) * Integer.parseInt(page)){
-          page = String.valueOf(Integer.parseInt(page) + 1);
+        Integer maxPageSize = 0;
+        if(total%Integer.parseInt(limit) == 0){
+          maxPageSize = total/Integer.parseInt(limit);
+        }else{
+          maxPageSize = total/Integer.parseInt(limit) + 1;
+        }
+        while (maxPageSize >= Integer.parseInt(page)){
           String res = shorePowerScheduler.executeConnRecordInfoUrl(portId, deviceId, berthId, page, limit, startTime, endTime);
           shorePowerScheduler.saveConnRecordInfos(res);
+          page = String.valueOf(Integer.parseInt(page) + 1);
         }
       }else{
         shorePowerScheduler.saveConnRecordInfos(result);

+ 8 - 2
src/main/java/com/shcd/scheduling/ShorePowerScheduler.java

@@ -610,10 +610,16 @@ public class ShorePowerScheduler {
       Integer total = getTotal(result);
       // total > limit 继续分页调用,else 保存数据
       if(total > Integer.parseInt(limit) * Integer.parseInt(page)){
-        while (total > Integer.parseInt(limit) * Integer.parseInt(page)){
-          page = String.valueOf(Integer.parseInt(page) + 1);
+        Integer maxPageSize = 0;
+        if(total%Integer.parseInt(limit) == 0){
+          maxPageSize = total/Integer.parseInt(limit);
+        }else{
+          maxPageSize = total/Integer.parseInt(limit) + 1;
+        }
+        while (maxPageSize >= Integer.parseInt(page)){
           String res = executeConnRecordInfoUrl(portId, deviceId, berthId, page, limit, startTime, endTime);
           saveConnRecordInfos(res);
+          page = String.valueOf(Integer.parseInt(page) + 1);
         }
       }else{
         saveConnRecordInfos(result);