|
@@ -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;
|
|
|
+ }
|
|
|
+}
|