Browse Source

新增接口,事件中心修改远端图片

Wang-Xiao-Ran 1 year ago
parent
commit
76467ba72f

+ 6 - 0
pom.xml

@@ -102,6 +102,12 @@
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.dahuatech.icc</groupId>
+            <artifactId>java-sdk-oauth</artifactId>
+            <version>1.0.9</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 

+ 20 - 4
src/main/java/com/sooka/sponest/event/centereventteventcatalogue/controller/AlarmEventController.java

@@ -2,8 +2,11 @@ package com.sooka.sponest.event.centereventteventcatalogue.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.dahuatech.icc.exception.ClientException;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.utils.StringUtils;
+import com.ruoyi.common.core.web.domain.AjaxResult;
+import com.sooka.sponest.event.centereventteventcatalogue.domain.DaHuaEventBO;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.dahua.DaHuaFireEventVO;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.dahua.DaHuaOtherEventVO;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.haikang.HaiKangEventVo;
@@ -16,11 +19,9 @@ import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import java.io.IOException;
 import java.util.List;
 
 @Api(tags = "海康")
@@ -223,4 +224,19 @@ public class AlarmEventController {
         }
         return R.ok(i);// 3951
     }
+
+    /**
+     * 更新火险事件图片
+     */
+    @PostMapping("/updateFireEventImage")
+    public AjaxResult updateFireEventImage(@RequestBody DaHuaEventBO eventBO) throws ClientException {
+        int i = alarmEventService.updateFireEventImage(eventBO);
+        if(i<0){
+            return AjaxResult.error("Sooka -> daHua -> Invoking the remote interface fails.");
+        }else if(i==0){
+            return AjaxResult.error("Sooka -> event -> The requested event type or event status is incorrect.");
+        }else{
+            return AjaxResult.success();
+        }
+    }
 }

+ 12 - 0
src/main/java/com/sooka/sponest/event/centereventteventcatalogue/domain/DaHuaEventBO.java

@@ -0,0 +1,12 @@
+package com.sooka.sponest.event.centereventteventcatalogue.domain;
+
+import lombok.Data;
+
+@Data
+public class DaHuaEventBO {
+    private String eventCode;
+    private String logId;
+    private String alarmCode;
+    private String alarmDate;
+    private String dbType;
+}

+ 6 - 0
src/main/java/com/sooka/sponest/event/centereventteventcatalogue/service/AlarmEventService.java

@@ -1,11 +1,15 @@
 package com.sooka.sponest.event.centereventteventcatalogue.service;
 
+import com.dahuatech.icc.exception.ClientException;
+import com.sooka.sponest.event.centereventteventcatalogue.domain.DaHuaEventBO;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.dahua.DaHuaFireEventVO;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.dahua.DaHuaOtherEventVO;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.haikang.EventsVo;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.haikang.HaiKangEventVo;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.sensor.SensorEventVo;
 
+import java.io.IOException;
+
 public interface AlarmEventService {
 
     // 海康火情事件
@@ -24,4 +28,6 @@ public interface AlarmEventService {
 
     // 传感器事件
     String insertSensorEvent(SensorEventVo sensorEventVo);
+
+    int updateFireEventImage(DaHuaEventBO eventBO)throws ClientException;
 }

+ 63 - 2
src/main/java/com/sooka/sponest/event/centereventteventcatalogue/service/impl/AlarmEventServiceImpl.java

@@ -1,13 +1,18 @@
 package com.sooka.sponest.event.centereventteventcatalogue.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.dahuatech.icc.exception.ClientException;
+import com.dahuatech.icc.oauth.http.IccHttpHttpRequest;
 import com.ruoyi.common.core.utils.DateUtils;
 import com.ruoyi.common.core.utils.SpringUtils;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.uuid.IdUtils;
+import com.ruoyi.common.core.web.domain.AjaxResult;
 import com.sooka.sponest.event.centereventtdeptevent.domain.CentereventDeptEvent;
 import com.sooka.sponest.event.centereventtdeptevent.service.ICentereventDeptEventService;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.CentereventTEventcatalogue;
+import com.sooka.sponest.event.centereventteventcatalogue.domain.DaHuaEventBO;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.dahua.DaHuaFireEventVO;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.dahua.DaHuaOtherEventVO;
 import com.sooka.sponest.event.centereventteventcatalogue.domain.dahua.PictureVO;
@@ -22,17 +27,18 @@ import com.sooka.sponest.event.centereventtfirelog.domain.CentereventTFireLog;
 import com.sooka.sponest.event.centereventtfirelog.service.ICentereventTFireLogService;
 import com.sooka.sponest.event.remoteapi.RemoteDataService;
 import com.sooka.sponest.event.remoteapi.domain.CenterdataTAttach;
+import com.sooka.sponest.event.utils.RemoteApiUtil;
 import com.sooka.sponest.monitor.api.RemoteMonitorService;
 import com.sooka.sponest.monitor.api.domain.CenterdataTAidevicedept;
 import com.sooka.sponest.monitor.api.domain.CenterdataTCamera;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 import static com.ruoyi.common.core.utils.DateUtils.YYYY_MM_DD_HH_MM_SS;
 import static com.sooka.sponest.event.utils.EventConstants.*;
@@ -57,6 +63,13 @@ public class AlarmEventServiceImpl implements AlarmEventService {
     @Autowired
     private ICentereventTEventtypeService centereventTEventtypeService;
 
+    @Value("${sooka.event.detail.url:}")
+    private String detailUrl;
+
+    private static final String HEADER_KEY = "Authorization";
+
+    private static final String HEADER_VALUE = "Bearer ";
+
     static final String ERROR_MSG_CHANNEL = "无法匹配相关设备!通道编号为:{}";
 
     static final String ERROR_MSG_DEPT = "无法匹配相关部门!摄像头编号为:{}";
@@ -253,6 +266,12 @@ public class AlarmEventServiceImpl implements AlarmEventService {
         String logId = this.insertEventLog(centereventTEventcatalogue);
         if (StringUtils.isNotBlank(daHuaFireEventVO.getInfo().getPicture())) {
             String[] pictures = daHuaFireEventVO.getInfo().getPicture().split(",");
+            //图片结合中应由热感和高清两张图片
+            if (pictures.length != 2) {
+                //延迟获取图片
+            }
+
+
             for (String picture : pictures) {
                 CenterdataTAttach tAttach = new CenterdataTAttach();
                 tAttach.setBusId(logId);
@@ -348,4 +367,46 @@ public class AlarmEventServiceImpl implements AlarmEventService {
         }
         return centereventTEventcatalogue.getEventCode() + "_" + eventtype.getEventTypeName();
     }
+
+
+    @Override
+    public int updateFireEventImage(DaHuaEventBO eventBO) throws ClientException {
+        //通过eventCode查询详情
+        CentereventTEventcatalogue centereventTEventcatalogue = centereventTEventcatalogueService.selectCentereventTEventcatalogueByEventCode(eventBO.getEventCode());
+        //确认为          火情事件                                 并且                           状态为上报
+        if("1".equals(centereventTEventcatalogue.getEventType()) && "forest_event_status_1".equals(centereventTEventcatalogue.getEventStatusValue())){
+            //按照指定格式拼接路径
+            String url = "alarmCode=" + RemoteApiUtil.encodeUrl(eventBO.getAlarmCode()) + "&dbType=" + RemoteApiUtil.encodeUrl(eventBO.getDbType()) + "&alarmDate=" + RemoteApiUtil.encodeUrl(eventBO.getAlarmDate());
+            //获取大华token
+            String token = RemoteApiUtil.getInstance().getToken();//3c001989-3ba8-48ff-96f4-c2963455aa6e
+            //创建请求实体 并 发送请求
+            String prBody = new IccHttpHttpRequest(detailUrl + url).header(HEADER_KEY, HEADER_VALUE + token).execute();
+            //打印响应结果
+            JSONObject responseData = JSON.parseObject(prBody);
+            if(responseData.getBoolean("success")){
+                ArrayList<String> pictures = responseData.getJSONObject("data").getObject("pictures", ArrayList.class);
+                //删除旧附件
+                remoteDataService.deleteAttchByBusId(eventBO.getLogId());
+                //添加新附件
+                List<CenterdataTAttach> attachList = new ArrayList<>();
+                for (String picture : pictures) {
+                    CenterdataTAttach tAttach = new CenterdataTAttach();
+                    tAttach.setBusId(eventBO.getLogId());
+                    tAttach.setAttachPath(picture);
+                    tAttach.setBusIndx(BUS_INDEX_1);
+                    tAttach.setBusSource("DH_1");
+                    tAttach.setFileType(FILE_TYPE_1);
+                    attachList.add(tAttach);
+                }
+                JSONObject requestObj = new JSONObject();
+                requestObj.put("attachList", attachList);
+                return remoteDataService.insertAttachToArray(requestObj.toJSONString());
+            }else{
+                logger.error("请求结果:{}", prBody);
+                return -1;
+            }
+        }else{
+            return 0;
+        }
+    }
 }

+ 7 - 4
src/main/java/com/sooka/sponest/event/remoteapi/RemoteDataService.java

@@ -5,10 +5,7 @@ import com.ruoyi.common.core.domain.R;
 import com.sooka.sponest.event.remoteapi.domain.*;
 import com.sooka.sponest.event.remoteapi.factory.RemoteDataServiceFallbackFactory;
 import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 import java.util.Map;
@@ -65,4 +62,10 @@ public interface RemoteDataService {
 
     @GetMapping("/emergency/inspectionitem/getItemInfo/{id}")
     R<CenterdataTEmergencyInspectionitem> getItemInfo(@PathVariable("id") String id);
+
+    @GetMapping("/attach/deleteAttchByBusId")
+    int deleteAttchByBusId(@RequestParam("busId") String busId);
+
+    @GetMapping("/attach/insertAttachToArray")
+    int insertAttachToArray(@RequestParam("jsonString") String jsonString);
 }

+ 10 - 0
src/main/java/com/sooka/sponest/event/remoteapi/factory/RemoteDataServiceFallbackFactory.java

@@ -76,6 +76,16 @@ public class RemoteDataServiceFallbackFactory implements FallbackFactory<RemoteD
             public R<CenterdataTEmergencyInspectionitem> getItemInfo(String id) {
                 return null;
             }
+
+            @Override
+            public int deleteAttchByBusId(String busId) {
+                return 0;
+            }
+
+            @Override
+            public int insertAttachToArray(String jsonString) {
+                return 0;
+            }
         };
     }
 }

+ 13 - 0
src/main/java/com/sooka/sponest/event/utils/RemoteApiUtil.java

@@ -19,6 +19,7 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.context.request.RequestAttributes;
 import org.springframework.web.context.request.RequestContextHolder;
 
+import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
@@ -235,4 +236,16 @@ public class RemoteApiUtil {
             }
         }
     }
+
+
+    public static String encodeUrl(String input) {
+        try {
+            // 使用 URLEncoder 类的 encode 方法对输入字符串进行编码
+            return URLEncoder.encode(input, "UTF-8");
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
 }