浏览代码

新增分类查看各类事件

zhuoning 3 年之前
父节点
当前提交
59a1cb0db9

+ 7 - 3
huimv-farm-video/pom.xml

@@ -19,9 +19,6 @@
         <version>1.0.8</version>
     </dependency>
 
-
-
-
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient</artifactId>
@@ -51,6 +48,13 @@
             <version>2.8.0</version>
         </dependency>
 
+        <dependency>
+            <groupId>net.sf.json-lib</groupId>
+            <artifactId>json-lib</artifactId>
+            <version>2.2.3</version>
+            <classifier>jdk15</classifier>
+            <!-- jdk版本 -->
+        </dependency>
     </dependencies>
 
 

+ 2 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/controller/ClientController/ClientAllEventController.java

@@ -132,5 +132,7 @@ public class ClientAllEventController {
         System.out.println(jsonObject1);
         return jsonObject1.get("value").toString();
     }
+
+
 }
 

文件差异内容过多而无法显示
+ 2 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/icc/CommonConstant.java


+ 11 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/service/IClientAllEventService.java

@@ -0,0 +1,11 @@
+package com.huimv.video.dhicc.service;
+
+import com.dahuatech.icc.exception.ClientException;
+import com.huimv.video.dhicc.result.R;
+
+import javax.servlet.http.HttpServletRequest;
+
+public interface IClientAllEventService {
+    //
+    R getEventBySort(Integer farmId, Integer sort, String startDateText, String endDateText, Integer pageNum, Integer pageSize, HttpServletRequest request) throws ClientException;
+}

+ 275 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/service/impl/ClientAllEventServiceImpl.java

@@ -0,0 +1,275 @@
+package com.huimv.video.dhicc.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.dahuatech.hutool.http.Method;
+import com.dahuatech.icc.exception.ClientException;
+import com.dahuatech.icc.oauth.http.DefaultClient;
+import com.dahuatech.icc.oauth.http.IClient;
+import com.dahuatech.icc.oauth.model.v202010.GeneralRequest;
+import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
+import com.huimv.common.utils.StringUtilsWork;
+import com.huimv.video.dhicc.icc.CommonConstant;
+import com.huimv.video.dhicc.result.R;
+import com.huimv.video.dhicc.service.IClientAllEventService;
+import net.sf.json.JSONObject;
+import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import javax.servlet.http.HttpServletRequest;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Service
+public class ClientAllEventServiceImpl implements IClientAllEventService {
+
+    @Override
+    public R getEventBySort(Integer farmId, Integer sort,String startDateText, String endDateText, Integer pageNum, Integer pageSize,HttpServletRequest request) throws ClientException {
+        Map paramsMap = new HashMap();
+        paramsMap.put("farmId",farmId);
+        paramsMap.put("pageNum",pageNum);
+        paramsMap.put("pageSize",pageSize);
+        //
+        switch (sort) {
+            case 1:
+                //大门事件
+                paramsMap.put("alarmStartDateString",startDateText);
+                paramsMap.put("alarmEndDateString",endDateText);
+                System.out.println("大门事件输入参数>>"+paramsMap.toString());
+                return getGateEvent(paramsMap);
+            case 2:
+                //洗消事件
+                paramsMap.put("alarmStartDateString",startDateText);
+                paramsMap.put("alarmEndDateString",endDateText);
+                System.out.println("洗消事件输入参数>>"+paramsMap.toString());
+                return getWashEvent(paramsMap);
+            case 3:
+                //死猪通道事件
+                paramsMap.put("alarmStartDateString",startDateText);
+                paramsMap.put("alarmEndDateString",endDateText);
+                System.out.println("死猪通道事件输入参数>>"+paramsMap.toString());
+                return getDeadPigChannel(paramsMap);
+            case 4:
+                //人员门禁事件
+                paramsMap.put("startSwingTime",startDateText);
+                paramsMap.put("endSwingTime",endDateText);
+                paramsMap.put("openType",61);
+                System.out.println("人员门禁事件输入参数>>"+paramsMap.toString());
+                return getEntranceGuard(paramsMap);
+            default:
+                //车辆闸机事件
+                System.out.println("车辆闸机事件输入参数>>"+paramsMap.toString());
+                return getCarGateMachine(request,paramsMap);
+        }
+    }
+
+    //大门事件
+    private R getGateEvent(Map<String, Object> paramsMap) throws ClientException {
+        //绑定大门通道
+        String[] doorChannle = CommonConstant.DoorChannle;
+        return R.ok("请求成功").put("data", getEventList(paramsMap, doorChannle)).put("total", CountTimes(paramsMap, doorChannle));
+    }
+
+    //洗消事件
+    private R getWashEvent(Map<String, Object> paramsMap) throws ClientException {
+        //绑定大门通道
+        String[] washChannle = CommonConstant.XixiaoChannle;
+        return R.ok("请求成功").put("data", getEventList(paramsMap, washChannle)).put("total", CountTimes(paramsMap, washChannle));
+    }
+
+    //死猪事件
+    private R getDeadPigChannel(Map<String, Object> paramsMap) throws ClientException {
+        String[] deadPigChannle = CommonConstant.SIZhuChannle;
+        return R.ok("请求成功").put("data", getEventList(paramsMap, deadPigChannle)).put("total", CountTimes(paramsMap, deadPigChannle));
+    }
+
+    //人员门禁事件
+    private R getEntranceGuard(Map<String, Object> paramsMap) throws ClientException {
+        //
+        return R.ok("请求成功").put("data", getAccidentRecord1(paramsMap)).put("total", parseTotal(get_person_record_totalpage(paramsMap).toString()));
+    }
+
+    //解析总页码
+    private Integer parseTotal(String totalText) {
+        totalText = totalText.substring(totalText.indexOf("data"),totalText.length());
+        totalText = totalText.substring(totalText.indexOf(":")+1,totalText.indexOf("}"));
+        return Integer.parseInt(totalText);
+    }
+
+    //车辆闸机事件
+    private R getCarGateMachine(HttpServletRequest request, Map<String, Object> paramsMap) throws ClientException {
+        Integer  farmId= (int) paramsMap.get("farmId");
+        //
+        return R.ok("请求成功").put("data", getCarRecord(request,farmId));
+    }
+
+    //查询车辆通行记录 by Yangdi
+    public GeneralResponse getCarRecord(HttpServletRequest request  , @RequestParam(name = "farmId") Integer farmId  ) throws ClientException {
+        if(farmId!=1){
+            //返回为空数据
+            return  new GeneralResponse() ;
+        }
+        System.out.println(request.getRequestURL()   );
+        System.out.println(request.getQueryString());
+        String queryString = request.getQueryString();
+        String URL = "/evo-apigw/ipms/carcapture/find/conditions?";  //获取事件URL    post请求
+        IClient iClient = new DefaultClient();
+        System.out.println("开始执行");
+        String newUrl = URL + queryString;
+        System.out.println(newUrl);
+        //这种已经在配置文件里面安排了账号ip以及密码    现在变了
+        GeneralRequest generalRequest = new GeneralRequest(newUrl, Method.GET);
+        GeneralResponse generalResponse = iClient.doAction(generalRequest, generalRequest.getResponseClass());
+        System.out.println("执行结束");
+        return generalResponse;
+    }
+
+    //返回所有的事件 的集合  包括死猪和洗消和大门 --分页参数 by Yangdi
+    public GeneralResponse getEventList(Map<String, Object> params1, String[] nodeCodeListIn) throws ClientException {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar c = Calendar.getInstance();
+        Date date = new Date();
+        c.setTime(date);
+        c.set(Calendar.HOUR, 0);
+        c.set(Calendar.MINUTE, 0);
+        c.set(Calendar.SECOND, 0);
+        Date A = c.getTime();
+        String formatA = format.format(A);
+        c.set(Calendar.HOUR, +24);
+        Date d = c.getTime();
+        String formatD = format.format(d);
+        Map<String, Object> params = new HashMap<>();
+        params.put("alarmStartDateString", formatA);
+        params.put("alarmEndDateString", formatD);
+        if (StringUtilsWork.isNotEmpty((String) params1.get("alarmStartDateString"))) {
+            params.put("alarmStartDateString", (String) params1.get("alarmStartDateString"));
+            params.put("alarmEndDateString", (String) params1.get("alarmEndDateString"));
+        }
+        params.put("pageNum", (Integer) params1.get("pageNum"));
+        params.put("pageSize", (Integer) params1.get("pageSize"));
+        params.put("alarmType", 303);
+        params.put("dbType", 0);
+        params.put("deviceCategory", 1);
+//        String[] nodeCodeList = CommonConstant.AllChannle;
+        params.put("nodeCodeList", nodeCodeListIn);
+        // String URL = "/evo-apigw/evo-event/1.2.0/alarm-record/page"; //获取事件URL    post请求
+        String URL = "/evo-apigw/evo-event/1.2.0/alarm-record/page";  //获取事件URL    post请求
+        IClient iClient = new DefaultClient();
+        String NewUrl = URL;
+        //这种已经在配置文件里面安排了账号ip以及密码
+        GeneralRequest generalRequest = new GeneralRequest(NewUrl, Method.POST);
+        System.out.println(NewUrl);
+        generalRequest.header("Content-Type", " application/json");
+        generalRequest.body(JSON.toJSONString(params));
+        GeneralResponse generalResponse = iClient.doAction(generalRequest, generalRequest.getResponseClass());
+        return generalResponse;
+    }
+
+    //计算次数 by Yangdi
+    public String CountTimes(Map<String, Object> params1, String[] nodeCodeListIn) throws ClientException {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar c = Calendar.getInstance();
+        Date date = new Date();
+        c.setTime(date);
+        c.set(Calendar.HOUR, 0);
+        c.set(Calendar.MINUTE, 0);
+        c.set(Calendar.SECOND, 0);
+        Date A = c.getTime();
+        String formatA = format.format(A);
+        c.set(Calendar.HOUR, +24);
+        Date d = c.getTime();
+        String formatD = format.format(d);
+        Map<String, Object> params = new HashMap<>();
+        params.put("alarmStartDateString", formatA);
+        params.put("alarmEndDateString", formatD);
+        if (StringUtilsWork.isNotEmpty((String) params1.get("alarmStartDateString"))) {
+            params.put("alarmStartDateString", (String) params1.get("alarmStartDateString"));
+            params.put("alarmEndDateString", (String) params1.get("alarmEndDateString"));
+        }
+        params.put("alarmType", 303);
+        params.put("dbType", 0);
+        params.put("deviceCategory", 1);
+//        String[] nodeCodeList = CommonConstant.AllChannle;
+        params.put("nodeCodeList", nodeCodeListIn);
+        String URL = "/evo-apigw/evo-event/1.0.0/alarm-record/count-num";  //获取事件URL    post请求
+        IClient iClient = new DefaultClient();
+        String NewUrl = URL;
+        System.out.println("开始执行");
+        //这种已经在配置文件里面安排了账号ip以及密码
+        GeneralRequest generalRequest = new GeneralRequest(NewUrl, Method.POST);
+        System.out.println(NewUrl);
+        generalRequest.header("Content-Type", " application/json");
+        System.out.println(JSON.toJSONString(params));
+        //里面是
+        generalRequest.body(JSON.toJSONString(params));
+        //发起请求处理应答
+        GeneralResponse generalResponse = iClient.doAction(generalRequest, generalRequest.getResponseClass());
+        System.out.println("执行结束");
+        JSONObject jsonObject = JSONObject.fromObject(generalResponse.getResult());
+        Object data = jsonObject.get("data");
+        JSONObject jsonObject1 = JSONObject.fromObject(data);
+        System.out.println(jsonObject1);
+        return jsonObject1.get("value").toString();
+    }
+
+    //查询人员违规记录 by Yangdi
+    public GeneralResponse getAccidentRecord1( @RequestBody Map<String, Object> params ) throws ClientException {
+        Integer  farmId= (int) params.get("farmId");
+        if(farmId!=1){
+            //返回为空数据
+            return  new GeneralResponse() ;
+        }
+        String URL = "/evo-apigw/evo-accesscontrol/1.0.0/card/accessControl/swingCardRecord/bycondition/combined";  //获取事件URL    post请求
+        IClient iClient = new DefaultClient();
+        System.out.println("开始执行");
+        //这种已经在配置文件里面安排了账号ip以及密码
+        GeneralRequest generalRequest = new GeneralRequest(URL, Method.POST);
+        generalRequest.header("Content-Type", " application/json");
+        System.out.println(JSON.toJSONString(params));
+        //里面是
+        generalRequest.body(JSON.toJSONString(params));
+        //发起请求处理应答
+        GeneralResponse generalResponse = iClient.doAction(generalRequest, generalRequest.getResponseClass());
+        System.out.println("执行结束");
+        return generalResponse;
+    }
+
+    //人员通道查询总页数 by Yangdi
+    @RequestMapping("/get_person_record_totalpage")
+    public GeneralResponse get_person_record_totalpage( @RequestBody Map<String, Object> params ) throws ClientException {
+        Integer  farmId= (int) params.get("farmId");
+        if(farmId!=1){
+            //返回为空数据
+            return  new GeneralResponse() ;
+        }
+        String URL = "/evo-apigw/evo-accesscontrol/1.0.0/card/accessControl/swingCardRecord/bycondition/combinedCount?systime=";  //获取事件URL    post请求
+        IClient iClient = new DefaultClient();
+        String timestamp = String.valueOf((new Date()).getTime());
+        Long aLong = Long.valueOf(timestamp);
+        String NewUrl = URL + aLong;
+        System.out.println("开始执行");
+        //这种已经在配置文件里面安排了账号ip以及密码
+        GeneralRequest generalRequest = new GeneralRequest(NewUrl, Method.POST);
+        System.out.println(NewUrl);
+        generalRequest.header("Content-Type", " application/json");
+        System.out.println(JSON.toJSONString(params));
+        //里面是
+        generalRequest.body(JSON.toJSONString(params));
+        //发起请求处理应答
+        GeneralResponse generalResponse = iClient.doAction(generalRequest, generalRequest.getResponseClass());
+        System.out.println("执行结束");
+        return generalResponse;
+    }
+}

+ 34 - 0
huimv-farm-video/src/main/resources/application-prod2.yml

@@ -0,0 +1,34 @@
+server:
+  port: 8096
+spring:
+  application:
+    name: pigfarm-local-device
+  #------DataSource-----
+  datasource:
+    url: jdbc:mysql://47.96.4.54:10052/huimv-farm-center?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
+    username: root
+    password: hm123456789
+    driver-class-name: com.mysql.cj.jdbc.Driver
+  jpa:
+    hibernate:
+      ddl-auto: update
+    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
+  redis:
+    host: 122.112.224.199
+    port: 6379
+    password: hm123456
+# Socket配置
+#socket:
+  # 监听端口 9001
+#  listen:
+#    #ip: 192.168.16.3
+#    ip: 192.168.1.49
+#    port: 10020
+  # 线程池 - 保持线程数 20
+  #pool-keep: 20
+  # 线程池 - 核心线程数 10
+  #pool-core: 10
+  # 线程池 - 最大线程数 20
+  #pool-max: 30
+  # 线程队列容量 10
+  #pool-queue-init: 10

+ 34 - 0
huimv-farm-video/src/test/java/com/huimv/video/dhicc/service/ClientAllEventServiceImplTest.java

@@ -0,0 +1,34 @@
+package com.huimv.video.dhicc.service;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@SpringBootTest
+public class ClientAllEventServiceImplTest {
+
+    @Test
+    public void testPasrse(){
+        String text = "IccResponse{result='{\"success\":true,\"code\":\"0\",\"errMsg\":\"success\",\"data\":104}', requestId='null', code='0', success=true, errMsg='success'}";
+        System.out.println("text 1>>"+text);
+        text = text.substring(text.indexOf("data"),text.length());
+//        System.out.println("text 2>>"+text);
+        text = text.substring(text.indexOf(":")+1,text.indexOf("}"));
+        System.out.println("text 3>>"+text);
+//        text = text.substring(0,text.length()-1);
+//        System.out.println("text 3>>"+text);
+
+//        JSONObject dataJo = JSON.parseObject(text);
+//        System.out.println("dataJo>>"+dataJo);
+
+    }
+}