浏览代码

http请求修改

gao.qiang 3 天之前
父节点
当前提交
c8da922fef

+ 15 - 9
hazard-admin/src/main/java/com/ozs/web/core/util/CameraUtil.java

@@ -46,6 +46,7 @@ import com.jcraft.jsch.Session;
 import com.ozs.common.utils.HttpClientUtil;
 import com.ozs.service.entity.*;
 import com.ozs.service.service.*;
+import okhttp3.Response;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -533,19 +534,24 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
      * @return
      */
     public static String getRecordUrl(String cameraCode, String channel, Date startTm, Date endTm) {
-        String result = null;
         log.info(bakUrl + "/gb28181/api/invite?id=" + cameraCode + "&channel=" + channel + "&startTime=" + startTm.getTime()/1000 + "&endTime=" + endTm.getTime()/1000);
         String url = bakUrl + "/gb28181/api/invite?id=" + cameraCode + "&channel=" + channel + "&startTime=" + startTm.getTime()/1000 + "&endTime=" + endTm.getTime()/1000;
         try {
-            result = HttpClientUtil.get(url);
-            log.info("-----getRecordUrl-----"+result);
-            if (result.equals("200")) {
-                String path = apiSummary(cameraCode + "/" + channel+"/"+startTm.getTime()/1000+"-"+endTm.getTime()/1000);
-                if (StringUtils.isNotEmpty(path)){
-                    return path;
-                }else {
-                    return "当前相机暂无回放视频";
+            Response response = HttpClientUtil.get(url);
+            if (response != null) {
+                log.info("-----getRecordUrl----code-" + response.code());
+                log.info("-----getRecordUrl----message--" + cameraCode + "---" + response.message());
+                log.info("-----getRecordUrl----body--" + cameraCode + "---" + response.body());
+                if (response.code() == 200) {
+                    String path = apiSummary(cameraCode + "/" + channel + "/" + startTm.getTime() / 1000 + "-" + endTm.getTime() / 1000);
+                    if (StringUtils.isNotEmpty(path)) {
+                        return path;
+                    } else {
+                        return "当前相机暂无回放视频";
+                    }
                 }
+            }else {
+                return "当前相机暂无回放视频";
             }
         } catch (Exception e) {
             log.info(e.getMessage());

+ 26 - 20
hazard-sdk/src/main/java/com/ozs/controller/upload/GeoHazardMonitorTokenController.java

@@ -22,6 +22,7 @@ import com.ozs.service.entity.vo.ReqMsgAlarmVo;
 import com.ozs.vo.RespGeoHazardMonitorVo;
 import com.ozs.vo.RespMsgAlarmVo;
 import lombok.extern.slf4j.Slf4j;
+import okhttp3.Response;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -398,7 +399,7 @@ public class GeoHazardMonitorTokenController {
             BaseUser admin = baseUserService.getUserName("admin");
             lw.eq(BaseDeviceDynamicManagement::getCameraCode, reqDeviceVo.getCameraCode());
             BaseDeviceDynamicManagement baseDynamicManagement = baseDeviceDynamicManagementService.getOne(lw);
-            if (ObjectUtils.isEmpty(baseDynamicManagement)){
+            if (ObjectUtils.isEmpty(baseDynamicManagement)) {
                 jsonObject.put("resultCode", 0);
                 jsonObject.put("message", "相机编码不存在");
                 return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), "4370780c9a8c43e5");
@@ -416,7 +417,7 @@ public class GeoHazardMonitorTokenController {
                 baseDynamicManagement.setUpdateBy(admin.getUserId());
                 log.info("reqDeviceVo:{}", baseDynamicManagement);
                 if (baseDeviceDynamicManagementService.updateById(baseDynamicManagement)) {
-                    BaseElectricityResume baseElectricityResume=new BaseElectricityResume();
+                    BaseElectricityResume baseElectricityResume = new BaseElectricityResume();
                     baseElectricityResume.setCameraCode(baseDynamicManagement.getCameraCode());
                     baseElectricityResume.setElectricity(reqDeviceVo.getElectricity());
                     baseElectricityResumeService.save(baseElectricityResume);
@@ -447,18 +448,18 @@ public class GeoHazardMonitorTokenController {
      * @return
      */
     @PostMapping("/cloud/state")
-    public String cloudState(@RequestParam("parameter") String parameter,HttpServletRequest request){
+    public String cloudState(@RequestParam("parameter") String parameter, HttpServletRequest request) {
         JSONObject jsonObject = new JSONObject();
         String token = apiTokenUtils.getGeoHazardMonitorToken(request);
         log.info("token:{}", token);
         if (StringUtils.isNotEmpty(token)) {
             CloudState cloudState = new CloudState();
             cloudState.setCreateTime(new Date());
-            if (cloudStateService.save(cloudState)){
+            if (cloudStateService.save(cloudState)) {
                 jsonObject.put("resultCode", 1);
                 jsonObject.put("message", "成功");
                 return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), "4370780c9a8c43e5");
-            }else {
+            } else {
                 jsonObject.put("resultCode", 0);
                 jsonObject.put("message", "新增数据失败");
                 return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), "4370780c9a8c43e5");
@@ -504,24 +505,29 @@ public class GeoHazardMonitorTokenController {
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
         }
-        String result;
         String url = bakUrl + "/gb28181/api/invite?id=" + cameraCode + "&channel=" + channel + "&startTime=" + seconds + "&endTime=" + second;
         try {
-            result = HttpClientUtil.get(url);
-            log.info("-----alarmHistoryPlay----code--"+cameraCode+"---" + result);
-            if ("200".equals(result)) {
-                String path = apiSummary(cameraCode + "/" + channel + "/" + seconds + "-" + second);
-                if (org.apache.commons.lang3.StringUtils.isNotEmpty(path)) {
-                    String codes = HttpUtils.sendGet(startRecording(cameraCode + "/" + channel + "/" + seconds + "-" + second));
-                    log.info("codes------>" + codes);
-                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-                    // 使用SimpleDateFormat将Date对象格式化为指定样式的字符串
-                    String formattedDate = sdf.format(alarmDate);
-                    log.info("-----formattedDate-----------" + formattedDate);
-                    String records = getQueryRecords(cameraCode + "/" + channel + "/" + seconds + "-" + second, formattedDate, "mp4");
-                    log.info("-----records-----------" + records);
-                    return records;
+            Response response = HttpClientUtil.get(url);
+            if (response != null) {
+                log.info("-----alarmHistoryPlay----code--" + cameraCode + "---" + response.code());
+                log.info("-----alarmHistoryPlay----message--" + cameraCode + "---" + response.message());
+                log.info("-----alarmHistoryPlay----body--" + cameraCode + "---" + response.body());
+                if (200 == response.code()) {
+                    String path = apiSummary(cameraCode + "/" + channel + "/" + seconds + "-" + second);
+                    if (org.apache.commons.lang3.StringUtils.isNotEmpty(path)) {
+                        String codes = HttpUtils.sendGet(startRecording(cameraCode + "/" + channel + "/" + seconds + "-" + second));
+                        log.info("codes------>" + codes);
+                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                        // 使用SimpleDateFormat将Date对象格式化为指定样式的字符串
+                        String formattedDate = sdf.format(alarmDate);
+                        log.info("-----formattedDate-----------" + formattedDate);
+                        String records = getQueryRecords(cameraCode + "/" + channel + "/" + seconds + "-" + second, formattedDate, "mp4");
+                        log.info("-----records-----------" + records);
+                        return records;
+                    }
                 }
+            }else {
+                return null;
             }
         } catch (Exception e) {
             log.info(e.getMessage());