Explorar o código

疏浚数据对接更新

zoro hai 7 meses
pai
achega
c79b7aa3d6

+ 25 - 14
src/main/java/com/shcd/service/dredging/impl/DredgingServiceImpl.java

@@ -1,6 +1,7 @@
 package com.shcd.service.dredging.impl;
 
 import cn.hutool.core.lang.generator.SnowflakeGenerator;
+import cn.hutool.http.HttpException;
 import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.http.Method;
@@ -153,14 +154,20 @@ public class DredgingServiceImpl implements DredgingService {
                         ArrayList<DDredgingShip> dDredgingShips = new ArrayList<>();
                         for (Map.Entry<String, String> entry : map.entrySet()) {
                             DDredgingShip dDredgingShip = new DDredgingShip();
-                            Thread.sleep(1);
+                            try {
+                                Thread.sleep(1);
+                            } catch (InterruptedException e) {
+                                log.error("线程休眠问题{}",e.getMessage());
+                            }
                             dDredgingShip.setId(snowflakeGenerator.next().toString());
                             dDredgingShip.setShipCode(entry.getKey());
                             dDredgingShip.setShipName(entry.getValue());
                             dDredgingShip.setIsDelete(0);
                             dDredgingShips.add(dDredgingShip);
                         }
-                        dDredgingShipService.saveOrUpdateBatch(dDredgingShips);
+                        if (!CollectionUtils.isEmpty(dDredgingShips)){
+                            dDredgingShipService.saveOrUpdateBatch(dDredgingShips);
+                        }
                         //工单轨迹
                         for (DredgingWorkOrder dredgingWorkOrder : dredgingWorkOrders) {
                             HashMap<String, String> workOrderParams = new HashMap<>();
@@ -197,27 +204,31 @@ public class DredgingServiceImpl implements DredgingService {
                     }
 
                     //更新船舶绑定的videId
-                    JSONObject jsonObject = new JSONObject();
-                    jsonObject.put("projectId",dredgingImportRule.getProjectOverviewId());
-                    HttpResponse response = HttpUtil.createPost(dredgingWorkCameraUrl).body(jsonObject.toString()).setConnectionTimeout(30000).execute();
-                    List<HashMap> hashMaps = JSONArray.parseArray(response.body(), HashMap.class);
-                    List<DredgingProjectShips> projectShips = dredgingProjectShipService.list(Wrappers.<DredgingProjectShips>lambdaQuery().eq(DredgingProjectShips::getOverviewId, dredgingImportRule.getProjectOverviewId()));
-                    for (DredgingProjectShips projectShip : projectShips) {
-                        for (HashMap hashMap : hashMaps) {
-                            if (hashMap.get("ShipCode").equals(projectShip.getCode())){
-                                projectShip.setVideoId(hashMap.get("Code").toString());
-                                break;
+                    try {
+                        JSONObject jsonObject = new JSONObject();
+                        jsonObject.put("projectId",dredgingImportRule.getProjectOverviewId());
+                        HttpResponse response = HttpUtil.createPost(dredgingWorkCameraUrl).body(jsonObject.toString()).setConnectionTimeout(30000).execute();
+                        List<HashMap> hashMaps = JSONArray.parseArray(response.body(), HashMap.class);
+                        List<DredgingProjectShips> projectShips = dredgingProjectShipService.list(Wrappers.<DredgingProjectShips>lambdaQuery().eq(DredgingProjectShips::getOverviewId, dredgingImportRule.getProjectOverviewId()));
+                        for (DredgingProjectShips projectShip : projectShips) {
+                            for (HashMap hashMap : hashMaps) {
+                                if (hashMap.get("ShipCode").equals(projectShip.getCode())){
+                                    projectShip.setVideoId(hashMap.get("Code").toString());
+                                    break;
+                                }
                             }
                         }
+                        dredgingProjectShipService.updateBatchById(projectShips);
+                    } catch (HttpException e) {
+                        log.error("获取船舶id异常{}",e.getMessage());
                     }
-                    dredgingProjectShipService.updateBatchById(projectShips);
                 } else {
                     //这里代表主表的信息不存在,没必要继续进行
                     return null;
                 }
             }
         } catch (Exception e) {
-            log.error("数据导入异常{}",e.getCause());
+            log.error("数据导入异常{}",e.getMessage());
             return null;
         }
         return null;

+ 1 - 1
src/main/resources/profile/test/application.properties

@@ -38,7 +38,7 @@ spring.jmx.enabled=false
 xxl.job.admin.addresses=http://127.0.0.1:8091/xxl-job-admin
 xxl.job.executor.appname=DredgingImport
 xxl.job.executor.ip=127.0.0.1
-xxl.job.executor.port=9994
+xxl.job.executor.port=9992
 xxl.job.accessToken=
 xxl.job.executor.logpath=E:/xxl-job/applogs/xxl-job
 xxl.job.executor.logretentiondays=30