Преглед изворни кода

pms 修复bug(运行记录 瑞都日报 中航北斗)

zhangcl пре 1 месец
родитељ
комит
fe596feb9e

+ 3 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotopeationfill/IotOpeationFillController.java

@@ -935,6 +935,9 @@ public class IotOpeationFillController {
         IotOpeationFillDO fillDO = new IotOpeationFillDO();
         fillDO.setId(id);
         IotOpeationFillDO iotOpeationFill = iotOpeationFillService.getFillById(fillDO);
+        if (ObjUtil.isEmpty(iotOpeationFill)) {
+            return success(BeanUtils.toBean(fillDO, IotOpeationFillDO.class));
+        }
         Map<Long, String> wellNamePair = new HashMap<>();
         iotOpeationFill.setWellNamePair(wellNamePair);
         TenantUtils.executeIgnore(() -> {

+ 5 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrddailyreport/IotRdDailyReportServiceImpl.java

@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pms.service.iotrddailyreport;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.date.LocalDateTimeUtil;
+import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
@@ -761,7 +762,10 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
                     taskStatusPair.put(task.getId(), task.getStatus());
                     taskCreateTimePair.put(task.getId(), task.getCreateTime());
                     // 获取所有任务的工作量数据
-                    taskWorkloadPair.put(task.getId(), new BigDecimal(task.getWorkloadDesign()));
+                    String workloadDesign = task.getWorkloadDesign();
+                    if (NumberUtil.isNumber(workloadDesign)) {
+                        taskWorkloadPair.put(task.getId(), new BigDecimal(task.getWorkloadDesign()));
+                    }
                     if (techniqueDictPair.containsKey(task.getTechnique())) {
                         String techniqueName = techniqueDictPair.get(task.getTechnique());
                         taskTechniquePair.put(task.getId(), techniqueName);

+ 80 - 70
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/util/ZHBDUtil.java

@@ -57,35 +57,38 @@ public class ZHBDUtil {
      * @return
      * @throws Exception
      */
-    public Map<Integer, IotDeviceCarFuelVO> carFuels(String carIds, String startDate, String endDate) throws Exception {
-        String zhbdtoken = redisTemplate.opsForValue().get("zhbdtoken");
-        String clientId = redisTemplate.opsForValue().get("zhdbClientId");
-        if (StrUtil.isBlank(zhbdtoken) || StrUtil.isBlank(clientId)) {
-            Map<String, String> map = new HashMap<>();
-            map.put("id", ID);
-            map.put("secret", SECRET);
-            JSONObject entries = restTemplate.postForObject(TOKEN_URL, map, JSONObject.class);
-            if (Objects.nonNull(entries)&&entries.get("code") != null&&Integer.parseInt(String.valueOf(entries.get("code")))==200) {
-                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(entries.get("data")));
-                zhbdtoken = jsonObject.get("token").toString();
-                // 缓存 client_id
-                clientId = jsonObject.get("client_id").toString();
-                redisTemplate.opsForValue().set("zhbdtoken", zhbdtoken, 80000, TimeUnit.SECONDS);
-                redisTemplate.opsForValue().set("zhdbClientId", clientId, 80000, TimeUnit.SECONDS);
-            }
-        }
-        // 构建请求JSON
-        Map<String, Object> requestMap = new HashMap<>();
-        requestMap.put("client_ids", clientId);
-        requestMap.put("vehicle_ids", carIds);
-        requestMap.put("begin_time", startDate);
-        requestMap.put("end_time", endDate);
-        requestMap.put("page_num", 1);
-        requestMap.put("page_size", 10);
+    public Map<Integer, IotDeviceCarFuelVO> carFuels(String carIds, String startDate, String endDate) {
         // key车辆carId   value油耗值
         Map<Integer, IotDeviceCarFuelVO> carOilFuelPair = new HashMap<>();
-        if (StrUtil.isNotBlank(zhbdtoken)) {
-            try {
+
+        try {
+            String zhbdtoken = redisTemplate.opsForValue().get("zhbdtoken");
+            String clientId = redisTemplate.opsForValue().get("zhdbClientId");
+            if (StrUtil.isBlank(zhbdtoken) || StrUtil.isBlank(clientId)) {
+                Map<String, String> map = new HashMap<>();
+                map.put("id", ID);
+                map.put("secret", SECRET);
+                JSONObject entries = restTemplate.postForObject(TOKEN_URL, map, JSONObject.class);
+                if (Objects.nonNull(entries)&&entries.get("code") != null&&Integer.parseInt(String.valueOf(entries.get("code")))==200) {
+                    JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(entries.get("data")));
+                    zhbdtoken = jsonObject.get("token").toString();
+                    // 缓存 client_id
+                    clientId = jsonObject.get("client_id").toString();
+                    redisTemplate.opsForValue().set("zhbdtoken", zhbdtoken, 80000, TimeUnit.SECONDS);
+                    redisTemplate.opsForValue().set("zhdbClientId", clientId, 80000, TimeUnit.SECONDS);
+                }
+            }
+
+            if (StrUtil.isNotBlank(zhbdtoken)) {
+                // 构建请求JSON
+                Map<String, Object> requestMap = new HashMap<>();
+                requestMap.put("client_ids", clientId);
+                requestMap.put("vehicle_ids", carIds);
+                requestMap.put("begin_time", startDate);
+                requestMap.put("end_time", endDate);
+                requestMap.put("page_num", 1);
+                requestMap.put("page_size", 10);
+
                 String jsonResponse = sendPostRequest(requestMap, zhbdtoken, DAILY_FUEL_STATISTICS_URL);
                 ApiOilResponse response = parseResponse(jsonResponse);
                 if (response != null && response.code == 200) {
@@ -104,10 +107,12 @@ public class ZHBDUtil {
                         carOilFuelPair.put(carId, carFuel);
                     }
                 }
-            } catch (Exception e) {
-                log.info("获取油耗数据失败!");
+
             }
+        } catch (Exception e) {
+            log.info("获取油耗数据失败!");
         }
+
         return carOilFuelPair;
     }
 
@@ -118,28 +123,28 @@ public class ZHBDUtil {
      * @throws Exception
      */
     public Map<String, Integer> carLocations(String plates) throws Exception {
-        String zhbdtoken = redisTemplate.opsForValue().get("zhbdtoken");
-        if (StrUtil.isBlank(zhbdtoken)) {
-            Map<String, String> map = new HashMap<>();
-            map.put("id", ID);
-            map.put("secret", SECRET);
-            JSONObject entries = restTemplate.postForObject(TOKEN_URL, map, JSONObject.class);
-            if (Objects.nonNull(entries)&&entries.get("code") != null&&Integer.parseInt(String.valueOf(entries.get("code")))==200) {
-                JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(entries.get("data")));
-                zhbdtoken = jsonObject.get("token").toString();
-                redisTemplate.opsForValue().set("zhbdtoken", zhbdtoken, 80000, TimeUnit.SECONDS);
-            }
-        }
-        // 构建请求JSON
-        Map<String, Object> requestMap = new HashMap<>();
-        // 车牌号码 用逗号分隔,例如(示例车牌1,示例车牌2)
-        requestMap.put("plates", plates);
-        requestMap.put("time", null);
-
         // key车牌号   value车辆carId
         Map<String, Integer> plateCarIdPair = new HashMap<>();
-        if (StrUtil.isNotBlank(zhbdtoken)) {
-            try {
+        try {
+            String zhbdtoken = redisTemplate.opsForValue().get("zhbdtoken");
+            if (StrUtil.isBlank(zhbdtoken)) {
+                Map<String, String> map = new HashMap<>();
+                map.put("id", ID);
+                map.put("secret", SECRET);
+                JSONObject entries = restTemplate.postForObject(TOKEN_URL, map, JSONObject.class);
+                if (Objects.nonNull(entries)&&entries.get("code") != null&&Integer.parseInt(String.valueOf(entries.get("code")))==200) {
+                    JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(entries.get("data")));
+                    zhbdtoken = jsonObject.get("token").toString();
+                    redisTemplate.opsForValue().set("zhbdtoken", zhbdtoken, 80000, TimeUnit.SECONDS);
+                }
+            }
+            // 构建请求JSON
+            Map<String, Object> requestMap = new HashMap<>();
+            // 车牌号码 用逗号分隔,例如(示例车牌1,示例车牌2)
+            requestMap.put("plates", plates);
+            requestMap.put("time", null);
+
+            if (StrUtil.isNotBlank(zhbdtoken)) {
                 String jsonResponse = sendPostRequest(requestMap, zhbdtoken, GET_LOCATION_USE_PLATES_URL);
                 ApiOilResponse response = parseResponse(jsonResponse);
                 if (response != null && response.code == 200) {
@@ -154,36 +159,41 @@ public class ZHBDUtil {
                         }
                     }
                 }
-            } catch (Exception e) {
-                log.info("获取油耗数据失败!");
             }
+        } catch (Exception e) {
+            log.info("获取车辆位置数据失败!");
         }
         return plateCarIdPair;
     }
 
-    private String sendPostRequest(Map<String, Object> requestData, String token, String requestUrl) throws IOException {
+    private String sendPostRequest(Map<String, Object> requestData, String token, String requestUrl) {
 
         OkHttpClient client = new OkHttpClient();
         ObjectMapper objectMapper = new ObjectMapper();
-        String json = objectMapper.writeValueAsString(requestData);
-        okhttp3.RequestBody body = okhttp3.RequestBody.create(json, okhttp3.MediaType.parse("application/json"));
-
-        Request request = new Request.Builder()
-                .url(requestUrl)
-                .post(body)
-                .addHeader("Content-Type", "application/json")
-                .addHeader("Authorization", "Bearer " + token)// 关键头信息
-                .build();
-        String responseData = "";
-        try (Response response = client.newCall(request).execute()) {
-            if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
-            responseData = response.body().string();
-            System.out.println(responseData);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
+        try {
+            String json = objectMapper.writeValueAsString(requestData);
+            okhttp3.RequestBody body = okhttp3.RequestBody.create(json, okhttp3.MediaType.parse("application/json"));
+            Request request = new Request.Builder()
+                    .url(requestUrl)
+                    .post(body)
+                    .addHeader("Content-Type", "application/json")
+                    .addHeader("Authorization", "Bearer " + token)
+                    .build();
 
-        return responseData;
+            try (Response response = client.newCall(request).execute()) {
+                if (!response.isSuccessful()) {
+                    logger.warn("第三方接口返回非200状态码: {}", response.code());
+                    return null;
+                }
+                String responseData = response.body().string();
+                logger.debug("第三方接口返回数据: {}", responseData);
+                return responseData;
+            }
+        } catch (Exception e) {
+            // 任何网络/SSL/解析异常都被这里吞掉,返回 null
+            logger.error("调用第三方接口失败,URL: {}", requestUrl, e);
+            return null;
+        }
     }
 
     private ApiOilResponse parseResponse(String json) throws IOException {