slowslo пре 4 година
родитељ
комит
8b46ee2ffa

+ 164 - 0
smart-city-grid-yinchuan-server/src/main/java/org/springblade/openinterface/facedevice/qinlin/util/ZHHttpUtil.java

@@ -0,0 +1,164 @@
+package org.springblade.openinterface.facedevice.qinlin.util;
+
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.springblade.community.accessrecord.service.IAccessRecordService;
+import org.springblade.core.tool.api.R;
+import lombok.extern.slf4j.Slf4j;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.smartapplication.smartmonitor.constant.ZHConstant;
+import org.springblade.third.doordevice.dto.DeviceDTO;
+import org.springblade.third.doordevice.dto.UserDeviceDTO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.HashOperations;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+import org.springframework.util.Base64Utils;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * @author zwx
+ * @create 2020/12/16 1:52
+ */
+@Slf4j
+@Component
+public class ZHHttpUtil {
+
+	@Autowired
+	private RedisTemplate<String,String> redisTemplate;
+	private final static String ZH_DEVICE_INSTRUCT_COMMAND_SEQ = "zh:device:instruct:commonSeq";
+	@Autowired
+	private IAccessRecordService accessRecordService;
+
+    /**
+     *  新增用户
+     *   新增用户
+     * @return
+     */
+    public R addUser(UserDeviceDTO userDeviceDTO){
+		List<DeviceDTO> deviceList = userDeviceDTO.getDeviceList();
+		log.info("===============下发的设备序列号=========================");
+		log.info(JSONUtil.toJsonStr(deviceList));
+		for (DeviceDTO deviceDTO : deviceList){
+			log.info("===============正在下发的设备序列号=========================");
+			log.info(deviceDTO.getSerialNum());
+			String serialNum = deviceDTO.getSerialNum();
+			HashOperations<String, String, String> hashOperations = this.redisTemplate.opsForHash();
+			String num = hashOperations.get(ZH_DEVICE_INSTRUCT_COMMAND_SEQ, serialNum);
+			Integer commonSeq = 10;
+			if(StringUtil.hasText(num)){
+				commonSeq = Integer.parseInt(num) + 1;
+				num = commonSeq + "";
+			}else{
+				num = "10"; //设备指令的commonSeq从10开始
+			}
+			JSONObject request = new JSONObject();
+			JSONObject data = new JSONObject();
+			JSONArray list = new JSONArray();
+			JSONObject listData = new JSONObject();
+			listData.put("Name", userDeviceDTO.getUserName());
+			listData.put("FaceId", userDeviceDTO.getUserId());
+			listData.put("Enable", 1);
+			listData.put("StartTime", userDeviceDTO.getStartTime());
+			listData.put("EndTime", userDeviceDTO.getEndTime());
+			listData.put("ScheduleType", 0);
+			listData.put("WiegandAssignType", 0);
+			try {
+				URL url = null;
+				url = new URL(userDeviceDTO.getUserFaceUrl());
+				URLConnection connection = url.openConnection();
+				InputStream inputStream = connection.getInputStream();
+				byte[] imageBytes = IoUtil.readBytes(inputStream);
+				String base64 = Base64Utils.encodeToString(imageBytes);
+				listData.put("FaceData", base64);
+			} catch (Exception e) {
+				e.printStackTrace();
+				return R.fail(e.getMessage());
+			}
+			list.add(listData);
+			data.put("List", list);
+			data.put("TargetName", "defaultwhitelist");
+			request.put("Data", data);
+			request.put("Type", ZHConstant.I8H.add_user_face.getType());
+			request.put("Command", ZHConstant.I8H.add_user_face.getCommand());
+			request.put("CommandSeq", commonSeq);
+			//设备指令commonSeq计数更新
+			this.redisTemplate.opsForHash().put(ZH_DEVICE_INSTRUCT_COMMAND_SEQ, serialNum, num);
+			//设备指令Data更新
+			String listName = serialNum + "_list";
+			this.redisTemplate.opsForList().leftPush(listName, request.toJSONString());
+		}
+		return R.status(true);
+    }
+
+	/**
+	 * 远程开门
+	 * @param serialNum
+	 * @param isOpen
+	 * @return
+	 */
+	public R remoteOpenDoor(Long userId, Integer userType, String serialNum, boolean isOpen){
+		HashOperations<String, String, String> hashOperations = this.redisTemplate.opsForHash();
+		String num = hashOperations.get(ZH_DEVICE_INSTRUCT_COMMAND_SEQ, serialNum);
+		Integer commonSeq = 10;
+		if(StringUtil.hasText(num)){
+			commonSeq = Integer.parseInt(num) + 1;
+			num = commonSeq + "";
+		}else{
+			num = "10"; //设备指令的commonSeq从10开始
+		}
+		JSONObject request = new JSONObject();
+		JSONObject data = new JSONObject();
+		if(isOpen){
+			data.put("WorkState", 0);
+		}else{
+			data.put("WorkState", 1);
+		}
+		request.put("Command", ZHConstant.I8H.open_door.getCommand());
+		request.put("CommandSeq", commonSeq);
+		request.put("Type", ZHConstant.I8H.open_door.getType());
+		request.put("Data", data);
+		accessRecordService.generateAccessRecord(serialNum, userId, null, userType, 2, 1, null, String.valueOf(commonSeq), null, new Date());
+		//设备指令commonSeq计数更新
+		this.redisTemplate.opsForHash().put(ZH_DEVICE_INSTRUCT_COMMAND_SEQ, serialNum, num);
+		//设备指令Data更新
+		String listName = serialNum + "_openDoor";
+		this.redisTemplate.opsForList().leftPush(listName, request.toJSONString());
+		this.redisTemplate.expire(listName, 1L, TimeUnit.MINUTES);
+		return R.status(true);
+	}
+
+	public R deleteUser(UserDeviceDTO userDeviceDTO, String serialNum) {
+		HashOperations<String, String, String> hashOperations = this.redisTemplate.opsForHash();
+		String num = hashOperations.get(ZH_DEVICE_INSTRUCT_COMMAND_SEQ, serialNum);
+		Integer commonSeq = 10;
+		if(StringUtil.hasText(num)){
+			commonSeq = Integer.parseInt(num) + 1;
+			num = commonSeq + "";
+		}else{
+			num = "10"; //设备指令的commonSeq从10开始
+		}
+		JSONObject request = new JSONObject();
+		JSONObject data = new JSONObject();
+		data.put("FaceId", userDeviceDTO.getUserId());
+		request.put("Data", data);
+		request.put("Type", ZHConstant.I8H.delete_user_face.getType());
+		request.put("Command", ZHConstant.I8H.delete_user_face.getCommand());
+		request.put("CommandSeq", commonSeq);
+		//设备指令commonSeq计数更新
+		this.redisTemplate.opsForHash().put(ZH_DEVICE_INSTRUCT_COMMAND_SEQ, serialNum, num);
+		//设备指令Data更新
+		String listName = serialNum + "_list";
+		this.redisTemplate.opsForList().leftPush(listName, request.toJSONString());
+		return R.status(true);
+	}
+
+}

+ 168 - 0
smart-city-grid-yinchuan-server/src/main/java/org/springblade/smartapplication/vcdevice/beans/StreamInfo.java

@@ -0,0 +1,168 @@
+package org.springblade.smartapplication.vcdevice.beans;
+
+import com.alibaba.fastjson.JSONArray;
+
+public class StreamInfo {
+
+    private String app;
+    private String streamId;
+    private String deviceID;
+    private String channelId;
+    private String flv;
+    private String ws_flv;
+    private String fmp4;
+    private String ws_fmp4;
+    private String hls;
+    private String ws_hls;
+    private String ts;
+    private String ws_ts;
+    private String rtmp;
+    private String rtsp;
+    private String rtc;
+    private JSONArray tracks;
+
+    public static class TransactionInfo{
+        public String callId;
+        public String localTag;
+        public String remoteTag;
+        public String branch;
+    }
+
+    private TransactionInfo transactionInfo;
+
+    public String getApp() {
+        return app;
+    }
+
+    public void setApp(String app) {
+        this.app = app;
+    }
+
+    public String getDeviceID() {
+        return deviceID;
+    }
+
+    public void setDeviceID(String deviceID) {
+        this.deviceID = deviceID;
+    }
+
+    public String getChannelId() {
+        return channelId;
+    }
+
+    public void setChannelId(String channelId) {
+        this.channelId = channelId;
+    }
+
+    public String getFlv() {
+        return flv;
+    }
+
+    public void setFlv(String flv) {
+        this.flv = flv;
+    }
+
+    public String getWs_flv() {
+        return ws_flv;
+    }
+
+    public void setWs_flv(String ws_flv) {
+        this.ws_flv = ws_flv;
+    }
+
+    public String getRtmp() {
+        return rtmp;
+    }
+
+    public void setRtmp(String rtmp) {
+        this.rtmp = rtmp;
+    }
+
+    public String getHls() {
+        return hls;
+    }
+
+    public void setHls(String hls) {
+        this.hls = hls;
+    }
+
+    public String getRtsp() {
+        return rtsp;
+    }
+
+    public void setRtsp(String rtsp) {
+        this.rtsp = rtsp;
+    }
+
+    public JSONArray getTracks() {
+        return tracks;
+    }
+
+    public void setTracks(JSONArray tracks) {
+        this.tracks = tracks;
+    }
+
+    public String getFmp4() {
+        return fmp4;
+    }
+
+    public void setFmp4(String fmp4) {
+        this.fmp4 = fmp4;
+    }
+
+    public String getWs_fmp4() {
+        return ws_fmp4;
+    }
+
+    public void setWs_fmp4(String ws_fmp4) {
+        this.ws_fmp4 = ws_fmp4;
+    }
+
+    public String getWs_hls() {
+        return ws_hls;
+    }
+
+    public void setWs_hls(String ws_hls) {
+        this.ws_hls = ws_hls;
+    }
+
+    public String getTs() {
+        return ts;
+    }
+
+    public void setTs(String ts) {
+        this.ts = ts;
+    }
+
+    public String getWs_ts() {
+        return ws_ts;
+    }
+
+    public void setWs_ts(String ws_ts) {
+        this.ws_ts = ws_ts;
+    }
+
+    public String getStreamId() {
+        return streamId;
+    }
+
+    public void setStreamId(String streamId) {
+        this.streamId = streamId;
+    }
+
+    public String getRtc() {
+        return rtc;
+    }
+
+    public void setRtc(String rtc) {
+        this.rtc = rtc;
+    }
+
+    public TransactionInfo getTransactionInfo() {
+        return transactionInfo;
+    }
+
+    public void setTransactionInfo(TransactionInfo transactionInfo) {
+        this.transactionInfo = transactionInfo;
+    }
+}

+ 10 - 0
smart-city-grid-yinchuan-server/src/main/java/org/springblade/third/doordevice/dto/DeviceDTO.java

@@ -0,0 +1,10 @@
+package org.springblade.third.doordevice.dto;
+
+import lombok.Data;
+
+@Data
+public class DeviceDTO {
+
+	private String serialNum;
+	private String factory;
+}

+ 52 - 0
smart-city-grid-yinchuan-server/src/main/java/org/springblade/third/doordevice/dto/UserDeviceDTO.java

@@ -0,0 +1,52 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.third.doordevice.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import java.util.List;
+
+/**
+ * 数据传输对象实体类
+ *
+ * @author BladeX
+ * @since 2021-04-27
+ */
+@Data
+public class UserDeviceDTO {
+	private static final long serialVersionUID = 1L;
+
+	@NotBlank
+	private String userId;
+
+	@NotBlank
+	private String userName;
+
+	@NotBlank
+	private String userFaceUrl;
+
+	@NotBlank
+	private List<DeviceDTO> deviceList;
+
+	//格式:2019-06-10 00:00:00
+	private String startTime;
+
+	//格式:2019-06-10 00:00:00
+	private String endTime;
+
+}