Browse Source

lapi接受数据修改

M墨鱼—_mo 5 years ago
parent
commit
abee89c85b

+ 13 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonDeviceLogDAO.java

@@ -0,0 +1,13 @@
+package com.jpsoft.smart.modules.base.dao;
+
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-15 14:22
+ */
+@Repository
+public interface PersonDeviceLogDAO {
+
+
+}

+ 108 - 0
common/src/main/java/com/jpsoft/smart/modules/base/entity/PersonDeviceLog.java

@@ -0,0 +1,108 @@
+package com.jpsoft.smart.modules.base.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-15 13:30
+ */
+@Data
+@ApiModel(value = "base_person_device_log的实体类")
+public class PersonDeviceLog {
+
+    /**
+     * 主体id
+     */
+    @ApiModelProperty(value = "ID")
+    private String id;
+
+    /**
+     * 设备序列号
+     */
+    @ApiModelProperty(value = "设备序列号")
+    private String deviceNo;
+
+
+    /**
+     * 人员id
+     */
+    @ApiModelProperty(value = "人员id")
+    private String personId;
+
+    /**
+     * 记录温度
+     */
+    @ApiModelProperty(value = "记录温度")
+    private BigDecimal temperature;
+
+
+    /**
+     * 匹配状态
+     */
+    @ApiModelProperty(value = "匹配状态")
+    private Integer matchStatus;
+
+    /**
+     * 匹配信息
+     */
+    @ApiModelProperty(value = "匹配信息")
+    private String  matchMsg;
+
+
+    /**
+     * 匹配人脸 ID
+     */
+    @ApiModelProperty(value = "匹配人脸 ID")
+    private Integer  matchFaceId;
+
+    /**
+     * 图片地址
+     */
+    @ApiModelProperty(value = "图片地址")
+    private String faceImage;
+
+    /**
+     * 记录时间
+     */
+    @ApiModelProperty(value = "记录时间")
+    private Date recordTime;
+
+    /**
+     * 是否删除
+     */
+    @ApiModelProperty(value = "是否删除")
+    private Boolean delFlag;
+
+    /**
+     * 创建人
+     */
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+
+    /**
+     * 更新人
+     */
+    @ApiModelProperty(value = "更新人")
+    private String  updateBy;
+
+    /**
+     * 更新时间
+     */
+    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
+
+
+
+
+}

+ 22 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/PersonDeviceLogService.java

@@ -0,0 +1,22 @@
+package com.jpsoft.smart.modules.base.service;
+
+import cn.hutool.json.JSONObject;
+
+import java.math.BigDecimal;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-15 14:12
+ */
+public interface PersonDeviceLogService {
+
+    /**
+     * 设备自动上传的过人记录
+     * @param deviceNo
+     * @param temperature
+     * @param faceImageJson
+     * @param libMatInfoListJson
+     * @param matchPersonInfo
+     */
+    void deviceInsertLog(String deviceNo, BigDecimal temperature, JSONObject faceImageJson, JSONObject libMatInfoListJson, JSONObject matchPersonInfo);
+}

+ 43 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/PersonDeviceLogServiceImpl.java

@@ -0,0 +1,43 @@
+package com.jpsoft.smart.modules.base.service.impl;
+
+import cn.hutool.json.JSONObject;
+import com.jpsoft.smart.modules.base.dao.AlarmInfoDAO;
+import com.jpsoft.smart.modules.base.dao.PersonDeviceLogDAO;
+import com.jpsoft.smart.modules.base.entity.PersonDeviceLog;
+import com.jpsoft.smart.modules.base.service.PersonDeviceLogService;
+import com.jpsoft.smart.modules.common.utils.IApiUtil;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.UUID;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-15 14:12
+ */
+@Service
+@Transactional
+public class PersonDeviceLogServiceImpl implements PersonDeviceLogService {
+
+    @Resource(name="personDeviceLogDAO")
+    private PersonDeviceLogDAO personDeviceLogDAO;
+
+    @Override
+    public void deviceInsertLog(String deviceNo, BigDecimal temperature, JSONObject faceImageJson, JSONObject libMatInfoListJson, JSONObject matchPersonInfo) {
+        PersonDeviceLog personDeviceLog = new PersonDeviceLog();
+        personDeviceLog.setId(UUID.randomUUID().toString());
+        personDeviceLog.setDeviceNo(deviceNo);
+        personDeviceLog.setPersonId(matchPersonInfo.getStr("PersonCode"));
+        personDeviceLog.setTemperature(temperature);
+        personDeviceLog.setMatchStatus(libMatInfoListJson.getInt("MatchStatus"));
+        personDeviceLog.setMatchMsg(IApiUtil.getMatchMsg(libMatInfoListJson.getInt("MatchStatus")));
+        personDeviceLog.setMatchFaceId(libMatInfoListJson.getInt("MatchFaceID"));
+
+      //  long timestamp = jsonObject.getLong("Timestamp");
+      //  personDeviceLog.setRecordTime();
+
+
+    }
+}

+ 103 - 0
common/src/main/java/com/jpsoft/smart/modules/common/utils/IApiUtil.java

@@ -0,0 +1,103 @@
+package com.jpsoft.smart.modules.common.utils;
+
+import cn.hutool.http.HttpRequest;
+import com.alibaba.fastjson.JSONObject;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-14 16:43
+ */
+@Component
+public class IApiUtil {
+
+
+   /* public JSONObject PostRequest(String url){
+
+        String body = HttpRequest.post(url).header("referer",referer).form(map).execute().body();
+        JSONObject jsonbody = JSONObject.parseObject(body);
+        return jsonbody;
+
+
+    }*/
+
+    public static JSONObject GetRequest(String url) throws Exception{
+
+        String body = HttpRequest.get(url).execute().body();
+        JSONObject jsonbody = JSONObject.parseObject(body);
+        return jsonbody;
+
+
+    }
+
+    public static JSONObject getResponse(JSONObject dataJson) throws Exception{
+
+        if (dataJson.getInteger("ResponseCode") == 1){
+            throw new Exception("通用错误");
+        }
+        if (dataJson.getInteger("ResponseCode") == 2){
+            throw new Exception("参数非法");
+        }
+        if (dataJson.getInteger("ResponseCode") == 3){
+            throw new Exception("用户无权限");
+        }
+        if (dataJson.getInteger("ResponseCode") == 4){
+            throw new Exception("设备不支持");
+        }
+        if (dataJson.getInteger("ResponseCode") == 5){
+            throw new Exception("用户状态异常");
+        }
+        if (dataJson.getInteger("StatusCode") == 1){
+            throw new Exception("执行失败");
+        }
+        if (dataJson.getInteger("StatusCode") == 2){
+            throw new Exception("输入参数非法");
+        }
+        if (dataJson.getInteger("StatusCode") == 3){
+            throw new Exception("系统内存不足");
+        }
+        if (dataJson.getInteger("StatusCode") == 8){
+            throw new Exception("功能不支持");
+        }
+        if (dataJson.getInteger("StatusCode") == 10){
+            throw new Exception("序列化执行失败");
+        }
+        if (dataJson.getInteger("StatusCode") == 11){
+            throw new Exception("Basic 鉴权失败");
+        }
+        if (dataJson.getInteger("StatusCode") == 12){
+            throw new Exception("Digest 鉴权失败");
+        }
+        if (dataJson.getInteger("StatusCode") == 13){
+            throw new Exception("订阅已满");
+        }
+        if (dataJson.getInteger("StatusCode") == 14){
+            throw new Exception("重复订阅");
+        }
+        return dataJson.getJSONObject("Data");
+    }
+
+    public static String getMatchMsg(Integer matchStatus){
+        String matchMsg = "";
+        if (matchStatus ==1){
+            matchMsg = "核验成功";
+        }
+        else if (matchStatus == 2){
+            matchMsg = "对比失败";
+        }
+        else if (matchStatus == 3){
+            matchMsg = "对比成功,不在布控时间";
+        }
+        else if (matchStatus == 10){
+            matchMsg = "对比成功,人脸属性异常";
+        }
+        else {
+            matchMsg = "未知匹配消息";
+        }
+
+        return matchMsg;
+    }
+}
+

+ 19 - 0
common/src/main/java/com/jpsoft/smart/modules/constant/LApiConstant.java

@@ -0,0 +1,19 @@
+package com.jpsoft.smart.modules.constant;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-15 9:50
+ */
+public class LApiConstant {
+
+    /**
+     * 获取设备的基本信息。
+     */
+    public static final String DEVICEBASICINFO = "/LAPI/V1.0/System/DeviceBasicInfo";
+
+    /**
+     * 获取设备的在线状态,可每隔 3s 获取一次
+     */
+    public static final String KEEPALIVE = "/LAPI/V1.0/System/KeepAlive";
+
+}

+ 26 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/service/ILapiService.java

@@ -0,0 +1,26 @@
+package com.jpsoft.smart.modules.lapi.service;
+
+import com.jpsoft.smart.modules.base.entity.DeviceInfo;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-15 9:36
+ */
+public interface ILapiService {
+
+    /**
+     * 通过ip和port查看门禁设备,有设备信息返回为正常
+     * @param ipAddress
+     * @param port
+     * @return
+     * @throws Exception
+     */
+     DeviceInfo findByIpAddressAndPort(String ipAddress, String port) throws Exception;
+
+    /**
+     * 根据设备id查看设备在线状态
+     * @param id 设备id
+     * @return
+     */
+     Boolean keepAlive(String id) throws Exception;
+}

+ 50 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/service/impl/LapiServiceImpl.java

@@ -0,0 +1,50 @@
+package com.jpsoft.smart.modules.lapi.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.jpsoft.smart.modules.base.entity.DeviceInfo;
+import com.jpsoft.smart.modules.base.service.DeviceInfoService;
+import com.jpsoft.smart.modules.common.utils.IApiUtil;
+import com.jpsoft.smart.modules.constant.LApiConstant;
+import com.jpsoft.smart.modules.lapi.service.ILapiService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.UUID;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-15 9:37
+ */
+@Service
+public class LapiServiceImpl implements ILapiService {
+
+
+    @Autowired
+    private DeviceInfoService deviceInfoService;
+
+    @Override
+    public DeviceInfo findByIpAddressAndPort(String ipAddress, String port) throws Exception {
+        JSONObject jsonObject = IApiUtil.GetRequest(ipAddress + ":" + port + LApiConstant.DEVICEBASICINFO);
+        JSONObject dataJson = jsonObject.getJSONObject("Response");
+        JSONObject response = IApiUtil.getResponse(dataJson);
+        DeviceInfo deviceInfo = new DeviceInfo();
+        deviceInfo.setId(UUID.randomUUID().toString());
+        deviceInfo.setIpAddress(ipAddress);
+        deviceInfo.setPort(port);
+        deviceInfo.setIsOnline(true);
+        deviceInfo.setDeviceNo(response.getString("SerialNumber"));
+
+        return deviceInfo;
+    }
+
+    @Override
+    public Boolean keepAlive(String id) throws Exception{
+        DeviceInfo deviceInfo = deviceInfoService.get(id);
+        if (deviceInfo == null){
+            throw new Exception("设备未绑定");
+        }
+        JSONObject jsonObject = IApiUtil.GetRequest(deviceInfo.getIpAddress()+":" + deviceInfo.getPort()+LApiConstant.KEEPALIVE);
+        JSONObject dataJson = jsonObject.getJSONObject("Response");
+        return true;
+    }
+}

+ 58 - 0
lapi/pom.xml

@@ -27,7 +27,18 @@
             <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.jpsoft.smart</groupId>
+            <artifactId>common</artifactId>
+            <version>1.0.0</version>
+        </dependency>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <scope>runtime</scope>
+        </dependency>
     </dependencies>
+
     <build>
         <plugins>
             <plugin>
@@ -40,4 +51,51 @@
             </plugin>
         </plugins>
     </build>
+
+    <profiles>
+        <profile>
+            <id>dev</id>
+            <dependencies>
+                <dependency>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-tomcat</artifactId>
+                </dependency>
+            </dependencies>
+            <properties>
+                <active.profile>dev</active.profile>
+            </properties>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+        </profile>
+        <profile>
+            <id>test</id>
+            <dependencies>
+                <dependency>
+                    <groupId>javax.servlet</groupId>
+                    <artifactId>javax.servlet-api</artifactId>
+                    <version>3.1.0</version>
+                    <scope>provided</scope>
+                </dependency>
+            </dependencies>
+            <properties>
+                <active.profile>test</active.profile>
+            </properties>
+        </profile>
+        <profile>
+            <id>production</id>
+            <properties>
+                <active.profile>production</active.profile>
+            </properties>
+            <dependencies>
+                <dependency>
+                    <groupId>javax.servlet</groupId>
+                    <artifactId>javax.servlet-api</artifactId>
+                    <version>3.1.0</version>
+                    <scope>provided</scope>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+
 </project>

+ 8 - 2
lapi/src/main/java/com/jpsoft/smart/lapi/LapiApplication.java

@@ -13,16 +13,22 @@ import io.netty.channel.socket.nio.NioServerSocketChannel;
 import io.netty.handler.codec.http.HttpObjectAggregator;
 import io.netty.handler.codec.http.HttpServerCodec;
 import lombok.extern.slf4j.Slf4j;
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 import javax.annotation.PreDestroy;
 
 @Slf4j
 @SpringBootApplication
+@EnableTransactionManagement
+@MapperScan("com.jpsoft.smart.**.dao")
+@ComponentScan("com.jpsoft.smart.**")
 public class LapiApplication implements CommandLineRunner {
     public static void main(String[] args) {
         SpringApplication.run(LapiApplication.class, args);
@@ -51,10 +57,10 @@ public class LapiApplication implements CommandLineRunner {
                 .childHandler(new ChannelInitializer(){
                     @Override
                     protected void initChannel(Channel channel) throws Exception {
-//				channel.pipeline().addLast(new TextDecodeHandler());
+				channel.pipeline().addLast(new TextDecodeHandler());
 //				channel.pipeline().addLast(new HttpRequestDecoder());
                         channel.pipeline().addLast(new HttpServerCodec());
-                        channel.pipeline().addLast(new HttpObjectAggregator(2048*10000));
+                        channel.pipeline().addLast(new HttpObjectAggregator(2048*10000*10));
                         channel.pipeline().addLast(new ParseRequestHandler());
                         channel.pipeline().addLast(heartReportHandler);
                         channel.pipeline().addLast(personVerificationHandler);

+ 37 - 2
lapi/src/main/java/com/jpsoft/smart/lapi/handler/PersonVerificationHandler.java

@@ -2,12 +2,15 @@ package com.jpsoft.smart.lapi.handler;
 
 import cn.hutool.json.JSONObject;
 import com.jpsoft.smart.lapi.dto.PersonVerification;
+import com.jpsoft.smart.modules.base.service.PersonDeviceLogService;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
@@ -15,6 +18,10 @@ import java.util.Date;
 @Component
 @ChannelHandler.Sharable
 public class PersonVerificationHandler extends SimpleChannelInboundHandler<PersonVerification> {
+
+    @Autowired
+    private PersonDeviceLogService personDeviceLogService;
+
     @Override
     protected void channelRead0(ChannelHandlerContext channelHandlerContext, PersonVerification personVerification) throws Exception {
         log.warn(personVerification.toString());
@@ -24,14 +31,42 @@ public class PersonVerificationHandler extends SimpleChannelInboundHandler<Perso
         log.warn(jsonObject.toString());
       //  JSONObject faceJson = jsonObject.get("FaceInfoList");
         log.warn("FaceInfoList" +jsonObject.getStr("FaceInfoList"));
+
+
         JSONObject faceJson = new JSONObject(jsonObject.getStr("FaceInfoList").substring(1,jsonObject.getStr("FaceInfoList").length()-1));
-        log.warn("faceJson"+faceJson);
+        log.warn(faceJson.getStr("FaceImage"));
+
+        //设备序列号
+        String deviceNo = jsonObject.getStr("DeviceCode");
+
+        //人员温度信息
+        BigDecimal temperature = faceJson.getBigDecimal("Temperature");
+
+        //人员抓拍信息
+        JSONObject faceImageJson = faceJson.getJSONObject("FaceImage");
+
+        //匹配状态信息
+        JSONObject libMatInfoListJson = new JSONObject(jsonObject.getStr("LibMatInfoList").substring(1,jsonObject.getStr("LibMatInfoList").length()-1));
+
+        //匹配人员信息
+        JSONObject matchPersonInfo = libMatInfoListJson.getJSONObject("MatchPersonInfo");
+
+
+        personDeviceLogService.deviceInsertLog(deviceNo,temperature,faceImageJson,libMatInfoListJson,matchPersonInfo);
+
+
+
+
+        /*log.warn("faceJson"+faceJson);
+        log.warn("FaceImage"+faceImageJson);
+        log.warn("LibMatInfoList"+libMatInfoListJson);
+        log.warn("MatchPersonInfo"+matchPersonInfo);
         long timestamp = jsonObject.getLong("Timestamp");
 
         Date date = new Date(timestamp);
 
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
-        log.warn("考勤时间:" + sdf.format(date));
+        log.warn("考勤时间:" + sdf.format(date));*/
     }
 }

+ 33 - 0
web/src/test/java/com/jpsoft/smart/LApiTest.java

@@ -0,0 +1,33 @@
+package com.jpsoft.smart;
+
+import com.jpsoft.smart.modules.lapi.service.ILapiService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2020-3-15 9:58
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class LApiTest {
+
+    @Autowired
+    private ILapiService lapiService;
+
+    @Test
+    public void testKeepLive(){
+        try {
+            Boolean result = lapiService.keepAlive("1");
+            System.out.println(result);
+        } catch (Exception e) {
+            e.printStackTrace();
+            String message = e.getMessage();
+        }
+
+    }
+
+}