| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- package com.template.controller;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
- import com.template.annotation.DESRespondSecret;
- import com.template.api.HikvisionAPI;
- import com.template.api.SmartNotificationControllerAPI;
- import com.template.common.utils.GetCameraPreviewURL;
- import com.template.common.utils.Message2;
- import com.template.model.pojo.SmartFaceDiscern;
- import com.template.model.pojo.SmartNotification;
- import com.template.model.pojo.SmartUser;
- import com.template.model.pojo.SmartWarning;
- import com.template.services.SmartFaceDiscernService;
- import com.template.services.SmartNotificationService;
- import com.template.services.SmartUserService;
- import com.template.services.SmartWarningService;
- import org.aspectj.weaver.ast.Var;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.http.HttpServletRequest;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.List;
- @RestController
- //返回参数加密注解
- @DESRespondSecret
- public class HikvisionController implements HikvisionAPI {
- @Autowired
- SmartWarningService smartWarningService;
- @Autowired
- SmartFaceDiscernService smartFaceDiscernService;
- @Autowired
- SmartUserService smartUserService;
- @Autowired
- SmartNotificationService smartNotificationService;
- /**
- * 事件订阅
- *
- * @param request
- */
- @Override
- public void subscription(HttpServletRequest request) {
- try {
- BufferedReader streamReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
- StringBuilder responseStrBuilder = new StringBuilder();
- String inputStr;
- while ((inputStr = streamReader.readLine()) != null) {
- responseStrBuilder.append(inputStr);
- }
- JSONObject jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
- // System.out.println("jsonObject = " + jsonObject);
- JSONObject params = jsonObject.getJSONObject("params");
- JSONArray events = params.getJSONArray("events");
- JSONObject jsonObject1 = events.getJSONObject(0);
- // 类型
- String eventType = jsonObject1.getString("eventType");
- // 时间
- String happenTime = jsonObject1.getString("happenTime");
- SmartWarning smartWarning = new SmartWarning();
- smartWarning.setDateTime(happenTime);
- smartWarning.setStatu(0);
- JSONObject data = jsonObject1.getJSONObject("data");
- // 地点
- String srcName = jsonObject1.getString("srcName");
- smartWarning.setLocation(srcName);
- // 推送的事件
- String pushType = "";
- if ("131588".equals(eventType)) {
- pushType = "区域入侵";
- smartWarning.setType("区域入侵");
- JSONArray fielddetection = data.getJSONArray("fielddetection");
- JSONObject jsonObject2 = fielddetection.getJSONObject(0);
- // 图片
- String imageUrl = jsonObject2.getString("imageUrl");
- smartWarning.setImage(imageUrl);
- } else if ("131586".equals(eventType)) {
- pushType = "进入危险区域";
- smartWarning.setType("进入区域");
- JSONArray regionEntrance = data.getJSONArray("regionEntrance");
- JSONObject jsonObject2 = regionEntrance.getJSONObject(0);
- // 图片
- String imageUrl = jsonObject2.getString("imageUrl");
- smartWarning.setImage(imageUrl);
- } else if ("131587".equals(eventType)) {
- pushType = "离开安全区域";
- smartWarning.setType("离开区域");
- JSONArray regionExiting = data.getJSONArray("regionExiting");
- JSONObject jsonObject2 = regionExiting.getJSONObject(0);
- // 图片
- String imageUrl = jsonObject2.getString("imageUrl");
- smartWarning.setImage(imageUrl);
- } else if ("131605".equals(eventType)) {
- pushType = "人员倒地";
- smartWarning.setType("倒地");
- JSONArray fallDown = data.getJSONArray("fallDown");
- JSONObject jsonObject2 = fallDown.getJSONObject(0);
- // 图片
- String imageUrl = jsonObject2.getString("imageUrl");
- smartWarning.setImage(imageUrl);
- }
- smartWarningService.save(smartWarning);
- // 获取推送人
- List<SmartUser> smartUserList = smartUserService.getListPush();
- if (ObjectUtils.isNotEmpty(smartUserList) && smartUserList.size() > 0) {
- for (SmartUser smartUser : smartUserList) {
- SmartNotification smartNotification = new SmartNotification();
- smartNotification.setUserId(smartUser.getId());
- smartNotification.setTypeName(pushType);
- smartNotification.setLocation(smartWarning.getLocation());
- smartNotification.setImage(smartWarning.getImage());
- smartNotification.setDateTime(smartWarning.getDateTime());
- smartNotification.setType(1);
- String gzhOpenId = smartUser.getGzhOpenId();
- if (ObjectUtils.isNotEmpty(gzhOpenId)) {
- // 时间格式是 yyyy-MM-dd HH:mm:ss,当前时间格式有问题
- DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- LocalDateTime now = LocalDateTime.now();
- String format = now.format(dateTimeFormatter1);
- // 公众号信息推送
- Message2.send(gzhOpenId, pushType, smartWarning.getLocation(), format);
- smartNotificationService.save(smartNotification);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 人脸比对
- *
- * @param request
- */
- @Override
- public void faceComparison(HttpServletRequest request) {
- try {
- BufferedReader streamReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
- StringBuilder responseStrBuilder = new StringBuilder();
- String inputStr;
- while ((inputStr = streamReader.readLine()) != null) {
- responseStrBuilder.append(inputStr);
- }
- JSONObject jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
- // System.out.println("jsonObject = " + jsonObject);
- JSONObject params = jsonObject.getJSONObject("params");
- JSONArray events = params.getJSONArray("events");
- JSONObject jsonObject1 = events.getJSONObject(0);
- // 类型
- String eventType = jsonObject1.getString("eventType");
- // 时间
- String happenTime = jsonObject1.getString("happenTime");
- SmartFaceDiscern smartFaceDiscern = new SmartFaceDiscern();
- smartFaceDiscern.setDateTime(happenTime);
- JSONObject data = jsonObject1.getJSONObject("data");
- // 地点
- String channelName = data.getString("channelName");
- smartFaceDiscern.setLocation(channelName);
- if ("131659".equals(eventType)) {
- smartFaceDiscern.setType("人脸比对");
- JSONArray alarmResult = data.getJSONArray("alarmResult");
- JSONObject jsonObject2 = alarmResult.getJSONObject(0);
- JSONObject targetAttrs = jsonObject2.getJSONObject("targetAttrs");
- String bkgUrl = targetAttrs.getString("bkgUrl");
- smartFaceDiscern.setImage(bkgUrl);
- // 获取人脸信息
- JSONArray faces = jsonObject2.getJSONArray("faces");
- JSONObject jsonObject3 = faces.getJSONObject(0);
- // 对比成功的图片
- JSONArray identify = jsonObject3.getJSONArray("identify");
- if (ObjectUtils.isNotEmpty(identify) && identify.size() > 0) {
- // 取对比成功的第一张
- JSONObject jsonObject4 = identify.getJSONObject(0);
- JSONArray candidate = jsonObject4.getJSONArray("candidate");
- JSONObject jsonObject5 = candidate.getJSONObject(0);
- JSONObject reserve_field = jsonObject5.getJSONObject("reserve_field");
- // 证件号
- String certificateNumber = reserve_field.getString("certificateNumber");
- // 名字
- String name = reserve_field.getString("name");
- smartFaceDiscern.setName(name);
- // todo 通过身份证查询是谁
- smartFaceDiscernService.save(smartFaceDiscern);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 重点人员
- *
- * @param request
- */
- @Override
- public void emphasisFace(HttpServletRequest request) {
- try {
- BufferedReader streamReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
- StringBuilder responseStrBuilder = new StringBuilder();
- String inputStr;
- while ((inputStr = streamReader.readLine()) != null) {
- responseStrBuilder.append(inputStr);
- }
- JSONObject jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
- // System.out.println("jsonObject = " + jsonObject);
- JSONObject params = jsonObject.getJSONObject("params");
- JSONArray events = params.getJSONArray("events");
- JSONObject jsonObject1 = events.getJSONObject(0);
- // 类型
- String eventType = jsonObject1.getString("eventType");
- // 时间
- String happenTime = jsonObject1.getString("happenTime");
- SmartWarning smartWarning = new SmartWarning();
- smartWarning.setDateTime(happenTime);
- smartWarning.setStatu(0);
- JSONObject data = jsonObject1.getJSONObject("data");
- // 获取地点
- JSONArray resInfo = data.getJSONArray("resInfo");
- JSONObject jsonObject3 = resInfo.getJSONObject(0);
- String cn = jsonObject3.getString("cn");
- smartWarning.setLocation(cn);
- if ("1644175361".equals(eventType)) {
- smartWarning.setType("重点人员识别");
- JSONObject faceRecognitionResult = data.getJSONObject("faceRecognitionResult");
- // 获取图片
- JSONObject snap = faceRecognitionResult.getJSONObject("snap");
- String bkgUrl = snap.getString("bkgUrl");
- smartWarning.setImage(bkgUrl);
- // 获取重点人员身份
- JSONArray faceMatch = faceRecognitionResult.getJSONArray("faceMatch");
- JSONObject jsonObject2 = faceMatch.getJSONObject(0);
- // 名字
- String faceInfoName = jsonObject2.getString("faceInfoName");
- smartWarning.setWarningName(faceInfoName);
- // 证件号码
- String certificate = jsonObject2.getString("certificate");
- smartWarningService.save(smartWarning);
- // 获取推送人
- List<SmartUser> smartUserList = smartUserService.getListPush();
- String pushType = "危险人员";
- for (SmartUser smartUser : smartUserList) {
- String gzhOpenId = smartUser.getGzhOpenId();
- if (ObjectUtils.isNotEmpty(gzhOpenId)) {
- SmartNotification smartNotification = new SmartNotification();
- smartNotification.setUserId(smartUser.getId());
- smartNotification.setUserName(faceInfoName);
- smartNotification.setTypeName(pushType);
- smartNotification.setLocation(smartWarning.getLocation());
- smartNotification.setImage(smartWarning.getImage());
- smartNotification.setDateTime(smartWarning.getDateTime());
- smartNotification.setType(1);
- // 时间格式是 yyyy-MM-dd HH:mm:ss,当前时间格式有问题
- DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- LocalDateTime now = LocalDateTime.now();
- String format = now.format(dateTimeFormatter1);
- // 公众号信息推送
- Message2.send(gzhOpenId, pushType, smartWarning.getLocation(), format);
- smartNotificationService.save(smartNotification);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public JSONObject playback() {
- String url = "/api/video/v2/cameras/playbackURLs";
- JSONObject jsonBoxdy = new JSONObject();
- jsonBoxdy.put("cameraIndexCode", "ff2a2978a71c4ba0ac43a1a6be97a1a1");
- jsonBoxdy.put("streamType", 0);
- jsonBoxdy.put("protocol", "rtsp");
- jsonBoxdy.put("transmode", 1);
- String s = GetCameraPreviewURL.CameraPreviewURL(url, jsonBoxdy);
- JSONObject jsonObject1 = JSONObject.parseObject(s);
- return jsonObject1;
- }
- @Override
- public JSONObject general(JSONObject jsonObject) {
- String url = jsonObject.getString("url");
- JSONObject jsonBoxdy = jsonObject.getJSONObject("jsonBoxdy");
- String s = GetCameraPreviewURL.CameraPreviewURL(url, jsonBoxdy);
- JSONObject jsonObject1 = JSONObject.parseObject(s);
- return jsonObject1;
- }
- }
|