Ver Fonte

将门禁设备数据接收改在web中

zhengqiang há 5 anos atrás
pai
commit
0a37f8f0c1
19 ficheiros alterados com 509 adições e 122 exclusões
  1. 16 5
      common/src/main/java/com/jpsoft/smart/modules/common/utils/LApiUtil.java
  2. 7 0
      common/src/main/java/com/jpsoft/smart/modules/lapi/channel/LapiAttrKeys.java
  3. 25 0
      common/src/main/java/com/jpsoft/smart/modules/lapi/channel/LapiChannel.java
  4. 90 0
      common/src/main/java/com/jpsoft/smart/modules/lapi/request/LapiRequest.java
  5. 65 22
      common/src/main/java/com/jpsoft/smart/modules/lapi/service/impl/LapiServiceImpl.java
  6. 2 7
      lapi/src/main/java/com/jpsoft/smart/LapiApplication.java
  7. 19 0
      lapi/src/main/java/com/jpsoft/smart/lapi/HttpClientDealing.java
  8. 46 0
      lapi/src/main/java/com/jpsoft/smart/lapi/LapiClient.java
  9. 16 8
      lapi/src/main/java/com/jpsoft/smart/lapi/LapiTcpServer.java
  10. 0 4
      lapi/src/main/java/com/jpsoft/smart/lapi/channel/LapiChannel.java
  11. 1 2
      lapi/src/main/java/com/jpsoft/smart/lapi/config/LapiConfig.java
  12. 9 0
      lapi/src/main/java/com/jpsoft/smart/lapi/dto/LapiResponse.java
  13. 39 9
      lapi/src/main/java/com/jpsoft/smart/lapi/handler/HeartReportHandler.java
  14. 47 0
      lapi/src/main/java/com/jpsoft/smart/lapi/handler/HttpDecoder.java
  15. 80 0
      lapi/src/main/java/com/jpsoft/smart/lapi/handler/ParseHttpHandler.java
  16. 0 58
      lapi/src/main/java/com/jpsoft/smart/lapi/handler/ParseRequestHandler.java
  17. 34 0
      lapi/src/main/java/com/jpsoft/smart/lapi/handler/ResponseDataHandler.java
  18. 6 6
      web/src/main/java/com/jpsoft/smart/listener/WebStateListener.java
  19. 7 1
      web/src/main/resources/application.yml

+ 16 - 5
common/src/main/java/com/jpsoft/smart/modules/common/utils/LApiUtil.java

@@ -2,11 +2,18 @@ package com.jpsoft.smart.modules.common.utils;
 
 import cn.hutool.http.HttpRequest;
 import com.alibaba.fastjson.JSONObject;
+import com.jpsoft.smart.modules.lapi.channel.LapiChannel;
+import io.netty.handler.codec.http.DefaultHttpRequest;
+import io.netty.handler.codec.http.HttpMethod;
+import io.netty.handler.codec.http.HttpVersion;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import java.math.BigDecimal;
 import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author 墨鱼_mo
@@ -195,13 +202,17 @@ public class LApiUtil {
       // long time = date.getTime();
      //   System.out.println(date);
       //  192.168.11.13:80/V1.0/PeopleLibraries/1584409665/People/1111?LastChange=1584428390872
-        cn.hutool.json.JSONObject jsonObject = new cn.hutool.json.JSONObject();
-        Integer integer = getPersonCode(jsonObject,jsonObject);
-        System.out.println(integer);
-
-    }
+//        cn.hutool.json.JSONObject jsonObject = new cn.hutool.json.JSONObject();
+//        Integer integer = getPersonCode(jsonObject,jsonObject);
+//        System.out.println(integer);
+        Map<String,Object> map = new HashMap<>();
 
+//        String requestStr = HttpRequest.post("http://www.baidu.com")
+//                .timeout(TIMEOUT)
+//                .body(new JSONObject(map).toJSONString());
 
 
+//        System.out.println(requestStr);
+    }
 }
 

+ 7 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/channel/LapiAttrKeys.java

@@ -0,0 +1,7 @@
+package com.jpsoft.smart.modules.lapi.channel;
+
+import io.netty.util.AttributeKey;
+
+public class LapiAttrKeys {
+    public static final AttributeKey<String> DEVICE_NO = AttributeKey.newInstance("deviceNo");
+}

+ 25 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/channel/LapiChannel.java

@@ -0,0 +1,25 @@
+package com.jpsoft.smart.modules.lapi.channel;
+
+import io.netty.channel.Channel;
+import lombok.Data;
+
+import java.util.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+
+@Data
+public class LapiChannel {
+    private Channel channel;
+
+    //不同的uri对应一个接受队列
+    private Map<String,BlockingQueue<String>> receivePacketQueueMap;
+
+    public BlockingQueue<String> getReceivePacketQueue(String uri) {
+        if(!this.receivePacketQueueMap.containsKey(uri)){
+            BlockingQueue<String> queue =  new ArrayBlockingQueue<>(100);
+            receivePacketQueueMap.put(uri,queue);
+        }
+
+        return this.receivePacketQueueMap.get(uri);
+    }
+}

+ 90 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/request/LapiRequest.java

@@ -0,0 +1,90 @@
+package com.jpsoft.smart.modules.lapi.request;
+
+import cn.hutool.http.HttpRequest;
+import com.alibaba.fastjson.JSONObject;
+import com.jpsoft.smart.modules.lapi.channel.LapiChannel;
+import com.jpsoft.smart.modules.sys.entity.SysLog;
+import com.jpsoft.smart.modules.sys.service.SysLogService;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.handler.codec.http.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.UnsupportedEncodingException;
+import java.net.SocketAddress;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+@Component
+public class LapiRequest {
+    @Autowired
+    private Map<String, LapiChannel> activeLapiChannelMap;
+
+    @Autowired
+    private SysLogService sysLogService;
+
+    public JSONObject send(String deviceNo, String uri,HttpMethod httpMethod,HashMap map) throws Exception{
+        LapiChannel lapiChannel = activeLapiChannelMap.get(deviceNo);
+
+        if (lapiChannel==null){
+            log.error(deviceNo + "不在线!");
+            return null;
+        }
+
+        String msg = "";
+
+        if (map!=null) {
+            msg = new JSONObject(map).toJSONString();
+        }
+
+        ByteBuf byteBuf = Unpooled.wrappedBuffer(msg.getBytes("UTF-8"));
+
+        FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, httpMethod,uri,byteBuf);
+
+        //必须设置content_length,否则返回报错
+        request.headers().set(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes());
+
+        lapiChannel.getChannel().writeAndFlush(request).sync();
+
+        String body = lapiChannel.getReceivePacketQueue(uri).poll(10, TimeUnit.SECONDS);
+
+        SysLog sysLog = new SysLog();
+        sysLog.setUrl(uri);
+
+        if (StringUtils.isNotEmpty(msg) && msg.length()>255) {
+            sysLog.setData(msg.substring(0,255));
+        }
+        else{
+            sysLog.setData(msg);
+        }
+
+        if (body!=null){
+            if (body.length()>255){
+                sysLog.setRemark(body.substring(0,255));
+            }
+            else{
+                sysLog.setRemark(body);
+            }
+        }
+
+        SocketAddress remoteAddress = lapiChannel.getChannel().remoteAddress();
+        sysLog.setRemoteIp(remoteAddress.toString());
+        sysLog.setCreateTime(new Date());
+        sysLogService.insert(sysLog);
+
+        if (StringUtils.isNotEmpty(body)){
+            JSONObject jsonObject = JSONObject.parseObject(body);
+
+            return jsonObject;
+        }
+        else{
+            return null;
+        }
+    }
+}

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

@@ -2,6 +2,7 @@ package com.jpsoft.smart.modules.lapi.service.impl;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
 import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import com.jpsoft.smart.modules.base.entity.DeviceInfo;
 import com.jpsoft.smart.modules.base.entity.PersonDeviceRelation;
@@ -13,8 +14,10 @@ import com.jpsoft.smart.modules.base.service.PersonInfoService;
 import com.jpsoft.smart.modules.common.utils.LApiUtil;
 import com.jpsoft.smart.modules.common.utils.OSSUtil;
 import com.jpsoft.smart.modules.constant.LApiConstant;
+import com.jpsoft.smart.modules.lapi.request.LapiRequest;
 import com.jpsoft.smart.modules.lapi.service.ILapiService;
 import com.jpsoft.smart.modules.lapi.vo.*;
+import io.netty.handler.codec.http.HttpMethod;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -30,8 +33,6 @@ import java.util.*;
 @Slf4j
 @Service
 public class LapiServiceImpl implements ILapiService {
-
-
     @Autowired
     private DeviceInfoService deviceInfoService;
 
@@ -44,9 +45,13 @@ public class LapiServiceImpl implements ILapiService {
     @Autowired
     private CompanyInfoService companyInfoService;
 
+    @Autowired
+    private LapiRequest lapiRequest;
+
     @Override
     public DeviceInfo findByIpAddressAndPort(String ipAddress, String port) throws Exception {
         JSONObject jsonObject = LApiUtil.getRequest(ipAddress + ":" + port + LApiConstant.DEVICEBASICINFO);
+
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         DeviceInfo deviceInfo = new DeviceInfo();
@@ -65,7 +70,9 @@ public class LapiServiceImpl implements ILapiService {
         if (deviceInfo == null) {
             throw new Exception("设备未绑定");
         }
-        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.KEEPALIVE);
+//        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.KEEPALIVE);
+        JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.KEEPALIVE, HttpMethod.GET,null);
+
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         return true;
     }
@@ -155,7 +162,9 @@ public class LapiServiceImpl implements ILapiService {
                 //获取人员人脸库id
                 String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
 
-                JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People", map);
+//                JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People", map);
+                JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.ADDPERSON + faceDbId + "/People",HttpMethod.POST,map);
+
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
@@ -268,7 +277,9 @@ public class LapiServiceImpl implements ILapiService {
                 //获取人员人脸库id
                 String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
 
-                JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People", map);
+                //JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People", map);
+                JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.ADDPERSON + faceDbId + "/People",HttpMethod.POST,map);
+
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
@@ -320,7 +331,10 @@ public class LapiServiceImpl implements ILapiService {
             throw new Exception("公司名称为空");
         }
         String faceDbId = "";
-        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.GETFACEDB);
+
+        //JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.GETFACEDB);
+        JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.GETFACEDB,HttpMethod.GET,null);
+
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         List listData = response.getJSONArray("LibList");
@@ -362,7 +376,9 @@ public class LapiServiceImpl implements ILapiService {
             throw new Exception("公司名称为空");
         }
         String faceDbId = "";
-        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.GETFACEDB);
+//        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.GETFACEDB);
+        JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.GETFACEDB,HttpMethod.GET,null);
+
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         List listData = response.getJSONArray("LibList");
@@ -411,7 +427,11 @@ public class LapiServiceImpl implements ILapiService {
             try {
                 //获取人员人脸库id
                 String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
-                JSONObject jsonObject = LApiUtil.deleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETEPERSON + faceDbId + "/People/" + personInfo.getId() + "?LastChange=" + new Date().getTime());
+//                JSONObject jsonObject = LApiUtil.deleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETEPERSON + faceDbId + "/People/" + personInfo.getId() + "?LastChange=" + new Date().getTime());
+
+                JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),
+                        LApiConstant.DELETEPERSON + faceDbId + "/People/" + personInfo.getId(),HttpMethod.DELETE,null);
+
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
@@ -459,7 +479,11 @@ public class LapiServiceImpl implements ILapiService {
             DeviceInfo deviceInfo = deviceInfoService.get(deviceId);
             try {
                 String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
-                JSONObject jsonObject = LApiUtil.deleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETEPERSON + faceDbId + "/People/" + personInfo.getId() + "?LastChange=" + new Date().getTime());
+//                JSONObject jsonObject = LApiUtil.deleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETEPERSON + faceDbId + "/People/" + personInfo.getId() + "?LastChange=" + new Date().getTime());
+
+                JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),
+                        LApiConstant.DELETEPERSON + faceDbId + "/People/" + personInfo.getId(),HttpMethod.DELETE,null);
+
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
@@ -496,7 +520,8 @@ public class LapiServiceImpl implements ILapiService {
             throw new Exception("设备已删除");
         }
 
-        JSONObject jsonObject = LApiUtil.putRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.REMOTEOPENED);
+//      JSONObject jsonObject = LApiUtil.putRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.REMOTEOPENED);
+        JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.REMOTEOPENED,HttpMethod.PUT,null);
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         return true;
@@ -511,7 +536,8 @@ public class LapiServiceImpl implements ILapiService {
         if (deviceInfo.getDelFlag()) {
             throw new Exception("设备已删除");
         }
-        JSONObject jsonObject = LApiUtil.putRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.REBOOT);
+//        JSONObject jsonObject = LApiUtil.putRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.REBOOT);
+        JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.REBOOT,HttpMethod.PUT,null);
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         return true;
@@ -545,7 +571,9 @@ public class LapiServiceImpl implements ILapiService {
                 map.put("MemberNum", 0);
                 map.put("Name", companyInfo.getName());
                 map.put("Type", 3);
-                JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDLIBRARY, map);
+                //JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDLIBRARY, map);
+                JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.ADDLIBRARY,HttpMethod.POST, map);
+
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 lapiResult.setMsg("添加成功");
@@ -591,7 +619,8 @@ public class LapiServiceImpl implements ILapiService {
             map.put("MemberNum", 0);
             map.put("Name", "默认员工库");
             map.put("Type", 3);
-            JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDLIBRARY, map);
+//            JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDLIBRARY, map);
+            JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.ADDLIBRARY,HttpMethod.POST, map);
             JSONObject dataJson = jsonObject.getJSONObject("Response");
             JSONObject response = LApiUtil.getResponse(dataJson);
             return response.getString("ID");
@@ -618,7 +647,10 @@ public class LapiServiceImpl implements ILapiService {
 
         LapiResult lapiResult = new LapiResult();
         try {
-            JSONObject jsonObject = LApiUtil.deleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETELIBRARY + libraryId);
+//          JSONObject jsonObject = LApiUtil.deleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETELIBRARY + libraryId);
+            JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),
+                    LApiConstant.DELETELIBRARY + libraryId,HttpMethod.DELETE,null);
+
             JSONObject dataJson = jsonObject.getJSONObject("Response");
             JSONObject response = LApiUtil.getResponse(dataJson);
             lapiResult.setSuccess(true);
@@ -664,7 +696,8 @@ public class LapiServiceImpl implements ILapiService {
         map1.put("BelongIndex", "");
         list.add(map1);
         map.put("LibList", list);
-        JSONObject jsonObject = LApiUtil.putRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.UPDATALIBRARY, map);
+//        JSONObject jsonObject = LApiUtil.putRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.UPDATALIBRARY, map);
+        JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(), LApiConstant.UPDATALIBRARY,HttpMethod.PUT, map);
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
 
@@ -687,7 +720,10 @@ public class LapiServiceImpl implements ILapiService {
         if (deviceInfo == null) {
             throw new Exception("设备不存在");
         }
-        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.UPDATALIBRARY);
+
+        //JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.UPDATALIBRARY);
+        JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.UPDATALIBRARY,HttpMethod.GET,null);
+
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         List<LibraryVo> list = JSONObject.parseArray(response.getString("LibList"), LibraryVo.class);
@@ -698,7 +734,10 @@ public class LapiServiceImpl implements ILapiService {
         for (LibraryVo libraryVo : list) {
             LapiResult lapiResult = new LapiResult();
             try {
-                JSONObject jsonObject1 = LApiUtil.deleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETELIBRARY + libraryVo.getID());
+//                JSONObject jsonObject1 = LApiUtil.deleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETELIBRARY + libraryVo.getID());
+                JSONObject jsonObject1 = lapiRequest.send(deviceInfo.getDeviceNo(),
+                        LApiConstant.DELETELIBRARY + libraryVo.getID(),HttpMethod.DELETE,null);
+
                 JSONObject dataJson1 = jsonObject1.getJSONObject("Response");
                 JSONObject response1 = LApiUtil.getResponse(dataJson1);
                 lapiResult.setSuccess(true);
@@ -730,7 +769,9 @@ public class LapiServiceImpl implements ILapiService {
         list.add(map1);
         map.put("QueryInfos", list);
         try {
-            JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People/Info", map);
+            //JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People/Info", map);
+            JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.ADDPERSON + faceDbId + "/People/Info",HttpMethod.POST, map);
+
             JSONObject dataJson = jsonObject.getJSONObject("Response");
             JSONObject response = LApiUtil.getResponse(dataJson);
             Integer num = response.getInteger("Total");
@@ -756,7 +797,9 @@ public class LapiServiceImpl implements ILapiService {
         if (!deviceInfo.getIsOnline()) {
             throw new Exception("设备离校,请联系管理员");
         }
-        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.RULE);
+        //JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.RULE);
+        JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(),LApiConstant.RULE,HttpMethod.GET,null);
+
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         return response;
@@ -802,13 +845,13 @@ public class LapiServiceImpl implements ILapiService {
             map.put("TemperatureRule", temperatureMap);
         }
 
+//      JSONObject jsonObject = LApiUtil.putRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.RULE, map);
+        JSONObject jsonObject = lapiRequest.send(deviceInfo.getDeviceNo(), LApiConstant.RULE,HttpMethod.PUT, map);
 
-        JSONObject jsonObject = LApiUtil.putRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.RULE, map);
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
-        return true;
-
 
+        return true;
     }
 
 

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

@@ -1,9 +1,8 @@
 package com.jpsoft.smart;
 
 import com.jpsoft.smart.lapi.handler.HeartReportHandler;
-import com.jpsoft.smart.lapi.handler.ParseRequestHandler;
+import com.jpsoft.smart.lapi.handler.ParseHttpHandler;
 import com.jpsoft.smart.lapi.handler.PersonVerificationHandler;
-import com.jpsoft.smart.lapi.handler.TextDecodeHandler;
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
@@ -13,14 +12,10 @@ 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.junit.Test;
-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.transaction.annotation.EnableTransactionManagement;
 
 import javax.annotation.PreDestroy;
 
@@ -60,7 +55,7 @@ public class LapiApplication implements CommandLineRunner {
 //				channel.pipeline().addLast(new HttpRequestDecoder());
                         channel.pipeline().addLast(new HttpServerCodec());
                         channel.pipeline().addLast(new HttpObjectAggregator(2048*10000));
-                        channel.pipeline().addLast(new ParseRequestHandler());
+                        channel.pipeline().addLast(new ParseHttpHandler());
                         channel.pipeline().addLast(heartReportHandler);
                         channel.pipeline().addLast(personVerificationHandler);
                     }

+ 19 - 0
lapi/src/main/java/com/jpsoft/smart/lapi/HttpClientDealing.java

@@ -0,0 +1,19 @@
+package com.jpsoft.smart.lapi;
+
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.handler.codec.http.HttpContent;
+import io.netty.handler.codec.http.HttpResponse;
+
+public class HttpClientDealing extends ChannelInboundHandlerAdapter {
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+        if(msg instanceof HttpResponse){
+            System.out.println(msg.toString());//打印服务器返回的httpResponse
+        }
+
+        if(msg instanceof HttpContent) {
+            System.out.println(msg.toString());
+        }
+    }
+}

+ 46 - 0
lapi/src/main/java/com/jpsoft/smart/lapi/LapiClient.java

@@ -0,0 +1,46 @@
+package com.jpsoft.smart.lapi;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.*;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.handler.codec.http.*;
+import java.net.URI;
+
+public class LapiClient {
+    public static void main(String[] args) {
+        NioEventLoopGroup workerGroup = new NioEventLoopGroup();
+
+        try {
+            Bootstrap bootstrap = new Bootstrap();
+            bootstrap.group(workerGroup)
+                    .channel(NioSocketChannel.class)
+                    .option(ChannelOption.SO_KEEPALIVE, true)
+                    .handler(new ChannelInitializer<SocketChannel>() {
+                        @Override
+                        protected void initChannel(SocketChannel socketChannel) throws Exception {
+                            socketChannel.pipeline().addLast(new HttpRequestEncoder());//客户端对发送的httpRequest进行编码
+                            socketChannel.pipeline().addLast(new HttpResponseDecoder());//客户端需要对服务端返回的httpresopnse解码
+                            // socketChannel.pipeline().addLast(new HttpClientCodec());//HttpClientCodec()包含了上面两种
+                            socketChannel.pipeline().addLast(new HttpClientDealing());
+                        }
+                    });
+            try {
+                Channel channel = bootstrap.connect("127.0.0.1", 8080).sync().channel();
+
+                URI uri = new URI("http://127.0.0.1:8080");
+                DefaultFullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.toASCIIString());//生成一个默认的httpRequest。
+
+                channel.writeAndFlush(httpRequest).sync();//发送
+
+                channel.closeFuture().sync();
+            }
+            catch (Exception ex){
+                ex.printStackTrace();
+            }
+        } finally {
+            workerGroup.shutdownGracefully();
+        }
+    }
+}

+ 16 - 8
lapi/src/main/java/com/jpsoft/smart/lapi/LapiTcpServer.java

@@ -1,16 +1,13 @@
 package com.jpsoft.smart.lapi;
 
-import com.jpsoft.smart.lapi.handler.HeartReportHandler;
-import com.jpsoft.smart.lapi.handler.ParseRequestHandler;
-import com.jpsoft.smart.lapi.handler.PersonVerificationHandler;
+import com.jpsoft.smart.lapi.handler.*;
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
-import io.netty.handler.codec.http.HttpObjectAggregator;
-import io.netty.handler.codec.http.HttpServerCodec;
+import io.netty.handler.codec.http.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -26,6 +23,9 @@ public class LapiTcpServer {
     @Autowired
     private HeartReportHandler heartReportHandler;
 
+    @Autowired
+    private ResponseDataHandler responseDataHandler;
+
     @Value("${server.port}")
     private Integer port;
 
@@ -42,11 +42,19 @@ public class LapiTcpServer {
                 .childHandler(new ChannelInitializer(){
                     @Override
                     protected void initChannel(Channel channel) throws Exception {
-                        channel.pipeline().addLast(new HttpServerCodec());
-                        channel.pipeline().addLast(new HttpObjectAggregator(2048*10000));
-                        channel.pipeline().addLast(new ParseRequestHandler());
+//                        channel.pipeline().addLast(new HttpRequestDecoder());
+//                        channel.pipeline().addLast(new HttpResponseDecoder());
+//                        channel.pipeline().addLast(new ParseResponseHandler());
+//                        channel.pipeline().addLast(new HttpClientCodec());
+//                        channel.pipeline().addLast(new HttpServerCodec());
+                        channel.pipeline().addLast(new HttpDecoder());
+                        channel.pipeline().addLast("aggregator", new HttpObjectAggregator(10 * 1024 * 1024));
+                        channel.pipeline().addLast(new ParseHttpHandler());
                         channel.pipeline().addLast(heartReportHandler);
                         channel.pipeline().addLast(personVerificationHandler);
+                        channel.pipeline().addLast(responseDataHandler);
+                        channel.pipeline().addLast(new HttpRequestEncoder());
+                        channel.pipeline().addLast(new HttpResponseEncoder());
                     }
                 });
 

+ 0 - 4
lapi/src/main/java/com/jpsoft/smart/lapi/channel/LapiChannel.java

@@ -1,4 +0,0 @@
-package com.jpsoft.smart.lapi.channel;
-
-public class LapiChannel {
-}

+ 1 - 2
lapi/src/main/java/com/jpsoft/smart/lapi/config/LapiConfig.java

@@ -1,6 +1,6 @@
 package com.jpsoft.smart.lapi.config;
 
-import com.jpsoft.smart.lapi.channel.LapiChannel;
+import com.jpsoft.smart.modules.lapi.channel.LapiChannel;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.stereotype.Component;
@@ -14,7 +14,6 @@ public class LapiConfig {
     @Bean(name="activeLapiChannelMap")
     public Map<String, LapiChannel> activeLapiChannelMap(){
         Map<String, LapiChannel> channelMap = new ConcurrentHashMap<>();
-
         return channelMap;
     }
 }

+ 9 - 0
lapi/src/main/java/com/jpsoft/smart/lapi/dto/LapiResponse.java

@@ -0,0 +1,9 @@
+package com.jpsoft.smart.lapi.dto;
+
+import cn.hutool.json.JSONObject;
+import lombok.Data;
+
+@Data
+public class LapiResponse {
+    private JSONObject data;
+}

+ 39 - 9
lapi/src/main/java/com/jpsoft/smart/lapi/handler/HeartReportHandler.java

@@ -1,19 +1,22 @@
 package com.jpsoft.smart.lapi.handler;
 
-import cn.hutool.json.JSONObject;
+import com.jpsoft.smart.modules.lapi.channel.LapiAttrKeys;
+import com.jpsoft.smart.modules.lapi.channel.LapiChannel;
 import com.jpsoft.smart.lapi.dto.HeartReportInfo;
 import com.jpsoft.smart.modules.base.service.DeviceInfoService;
-import com.jpsoft.smart.modules.base.service.PersonDeviceLogService;
+import com.jpsoft.smart.modules.sys.entity.SysLog;
+import com.jpsoft.smart.modules.sys.service.SysLogService;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
-import io.netty.handler.codec.http.FullHttpRequest;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.text.SimpleDateFormat;
+import java.net.SocketAddress;
 import java.util.Date;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 @Slf4j
 @Component
@@ -22,19 +25,46 @@ public class HeartReportHandler extends SimpleChannelInboundHandler<HeartReportI
     @Autowired
     private DeviceInfoService deviceInfoService;
 
-    @Override
-    protected void channelRead0(ChannelHandlerContext channelHandlerContext, HeartReportInfo heartReportInfo) throws Exception {
+    @Autowired
+    private Map<String, LapiChannel> activeLapiChannelMap;
 
-      //  log.warn(String.valueOf(channelHandlerContext.channel().remoteAddress()));
+    @Autowired
+    private SysLogService sysLogService;
+
+    @Override
+    protected void channelRead0(ChannelHandlerContext ctx, HeartReportInfo heartReportInfo) throws Exception {
         log.warn(heartReportInfo.toString());
-        String ipAndPort = String.valueOf(channelHandlerContext.channel().remoteAddress());
+        String ipAndPort = String.valueOf(ctx.channel().remoteAddress());
         String deviceNo = heartReportInfo.getDeviceCode();
         String ip = ipAndPort.substring(ipAndPort.indexOf("/")+1,ipAndPort.indexOf(":"));
-        log.warn(deviceNo);
+
+        log.warn("收到设备心跳,deviceNo=" + deviceNo);
         log.warn("ip =="+ip);
 
+        SysLog sysLog = new SysLog();
+        sysLog.setUrl("/LAPI/V1.0/PACS/Controller/HeartReportInfo");
+        sysLog.setData(heartReportInfo.toString());
+        sysLog.setRemark("收到设备心跳");
+        SocketAddress remoteAddress = ctx.channel().remoteAddress();
+        sysLog.setRemoteIp(remoteAddress.toString());
+        sysLog.setCreateTime(new Date());
+
+        sysLogService.insert(sysLog);
+
         deviceInfoService.updateByDeviceNo(deviceNo,ip);
 
+        //设置连接对应设备号
+        if(ctx.channel().attr(LapiAttrKeys.DEVICE_NO).get()==null){
+            ctx.channel().attr(LapiAttrKeys.DEVICE_NO).set(deviceNo);
+        }
+
+        //将连接保存到map中,以便发数据
+        if(!activeLapiChannelMap.containsKey(deviceNo)){
+            LapiChannel lapiChannel = new LapiChannel();
+            lapiChannel.setChannel(ctx.channel());
+            lapiChannel.setReceivePacketQueueMap(new ConcurrentHashMap<>());
 
+            activeLapiChannelMap.put(deviceNo,lapiChannel);
+        }
     }
 }

+ 47 - 0
lapi/src/main/java/com/jpsoft/smart/lapi/handler/HttpDecoder.java

@@ -0,0 +1,47 @@
+package com.jpsoft.smart.lapi.handler;
+
+
+import io.netty.handler.codec.http.*;
+
+public class HttpDecoder extends HttpObjectDecoder {
+
+    /**
+     * 相应未知状态
+     */
+   private static final HttpResponseStatus UNKOWN_STATUS = new HttpResponseStatus(999, "Unkown");
+
+    /**
+     * 是否是request解码
+     */
+   private boolean isDecodingRequest = true;
+
+    @Override
+    protected boolean isDecodingRequest() {
+        return isDecodingRequest;
+    }
+
+    @Override
+    protected HttpMessage createMessage(String[] initialLine) throws Exception {
+       if (initialLine[0].contains("HTTP")) {
+           isDecodingRequest = false;
+       } else if (initialLine[2].contains("HTTP")){
+           isDecodingRequest = true;
+       }
+       if (isDecodingRequest) {
+           return new DefaultHttpRequest(HttpVersion.valueOf(initialLine[2]),
+                   HttpMethod.valueOf(initialLine[0]), initialLine[1], validateHeaders);
+       } else  {
+           return new DefaultHttpResponse(HttpVersion.valueOf(initialLine[0]),
+                   new HttpResponseStatus(Integer.parseInt(initialLine[1]), initialLine[2]), validateHeaders);
+       }
+    }
+
+    @Override
+    protected HttpMessage createInvalidMessage() {
+        if (isDecodingRequest) {
+            return new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/bad-request", validateHeaders);
+        } else  {
+            return new DefaultFullHttpResponse(HttpVersion.HTTP_1_0, UNKOWN_STATUS, validateHeaders);
+        }
+    }
+}

+ 80 - 0
lapi/src/main/java/com/jpsoft/smart/lapi/handler/ParseHttpHandler.java

@@ -0,0 +1,80 @@
+package com.jpsoft.smart.lapi.handler;
+
+import cn.hutool.json.JSONObject;
+import com.jpsoft.smart.lapi.dto.HeartReportInfo;
+import com.jpsoft.smart.lapi.dto.LapiResponse;
+import com.jpsoft.smart.lapi.dto.PersonVerification;
+import com.jpsoft.smart.modules.lapi.request.LapiRequest;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.FullHttpResponse;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class ParseHttpHandler extends SimpleChannelInboundHandler {
+    @Override
+    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
+        if (msg instanceof FullHttpRequest){
+            FullHttpRequest request = (FullHttpRequest)msg;
+
+            ByteBuf byteBuf = request.content();
+
+            byteBuf.markReaderIndex();
+
+            byte[] buffer = new byte[byteBuf.readableBytes()];
+
+            for(int i=0;i<buffer.length;i++) {
+                buffer[i] = byteBuf.readByte();
+            }
+
+            byteBuf.resetReaderIndex();
+
+            log.warn(request.uri());
+
+            String json = new String(buffer,"UTF-8");
+
+            if(request.uri().contains("HeartReportInfo")) {
+                JSONObject jsonObject = new JSONObject(json);
+                HeartReportInfo heartReportInfo = jsonObject.toBean(HeartReportInfo.class);
+
+                ctx.fireChannelRead(heartReportInfo);
+            }
+            else if(request.uri().contains("Notifications")) {
+                log.warn("PersonVerification"+request.uri());
+                PersonVerification personVerification = new PersonVerification();
+                personVerification.setUri(request.uri());
+
+                JSONObject jsonObject = new JSONObject(json);
+                personVerification.setJsonObject(jsonObject);
+
+                ctx.fireChannelRead(personVerification);
+            }
+        }
+        else if(msg instanceof FullHttpResponse){
+            FullHttpResponse response = (FullHttpResponse)msg;
+
+            ByteBuf byteBuf = response.content();
+
+            byteBuf.markReaderIndex();
+
+            byte[] buffer = new byte[byteBuf.readableBytes()];
+
+            for(int i=0;i<buffer.length;i++) {
+                buffer[i] = byteBuf.readByte();
+            }
+
+            byteBuf.resetReaderIndex();
+
+            String json = new String(buffer,"UTF-8");
+
+            JSONObject jsonObject = new JSONObject(json);
+
+            LapiResponse lapiResponse = new LapiResponse();
+            lapiResponse.setData(jsonObject);
+
+            ctx.fireChannelRead(lapiResponse);
+        }
+    }
+}

+ 0 - 58
lapi/src/main/java/com/jpsoft/smart/lapi/handler/ParseRequestHandler.java

@@ -1,58 +0,0 @@
-package com.jpsoft.smart.lapi.handler;
-
-import cn.hutool.json.JSONObject;
-import com.jpsoft.smart.lapi.dto.HeartReportInfo;
-import com.jpsoft.smart.lapi.dto.PersonVerification;
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.SimpleChannelInboundHandler;
-import io.netty.handler.codec.http.FullHttpRequest;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-import java.net.SocketAddress;
-
-@Slf4j
-@Component
-public class ParseRequestHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
-    @Override
-    protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
-        ByteBuf byteBuf = request.content();
-
-        byteBuf.markReaderIndex();
-
-        byte[] buffer = new byte[byteBuf.readableBytes()];
-
-        for(int i=0;i<buffer.length;i++) {
-            buffer[i] = byteBuf.readByte();
-        }
-
-        byteBuf.resetReaderIndex();
-
-     //   log.warn(request.uri());
-     //   log.warn(String.valueOf(ctx.channel().remoteAddress()));
-
-        String json = new String(buffer,"UTF-8");
-
-        SocketAddress remoteAddress = ctx.channel().remoteAddress();
-
-        //log.warn(String.format("收到来自%s数据:%s",remoteAddress.toString(), json));
-
-        if(request.uri().contains("HeartReportInfo")) {
-            JSONObject jsonObject = new JSONObject(json);
-            HeartReportInfo heartReportInfo = jsonObject.toBean(HeartReportInfo.class);
-
-            ctx.fireChannelRead(heartReportInfo);
-        }
-        else if(request.uri().contains("Notifications")) {
-            log.warn("PersonVerification"+request.uri());
-            PersonVerification personVerification = new PersonVerification();
-            personVerification.setUri(request.uri());
-
-            JSONObject jsonObject = new JSONObject(json);
-            personVerification.setJsonObject(jsonObject);
-
-            ctx.fireChannelRead(personVerification);
-        }
-    }
-}

+ 34 - 0
lapi/src/main/java/com/jpsoft/smart/lapi/handler/ResponseDataHandler.java

@@ -0,0 +1,34 @@
+package com.jpsoft.smart.lapi.handler;
+
+import cn.hutool.json.JSONObject;
+import com.jpsoft.smart.lapi.dto.LapiResponse;
+import com.jpsoft.smart.modules.lapi.channel.LapiAttrKeys;
+import com.jpsoft.smart.modules.lapi.channel.LapiChannel;
+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.util.Map;
+import java.util.concurrent.BlockingQueue;
+
+@Slf4j
+@Component
+@ChannelHandler.Sharable
+public class ResponseDataHandler extends SimpleChannelInboundHandler<LapiResponse> {
+    @Autowired
+    private Map<String, LapiChannel> activeLapiChannelMap;
+
+    @Override
+    protected void channelRead0(ChannelHandlerContext ctx, LapiResponse msg) throws Exception {
+        JSONObject jsonObject = msg.getData();
+
+        String uri = jsonObject.getJSONObject("Response").get("ResponseURL").toString();
+        String deviceNo = ctx.channel().attr(LapiAttrKeys.DEVICE_NO).get();
+
+        BlockingQueue<String> queue = activeLapiChannelMap.get(deviceNo).getReceivePacketQueue(uri);
+
+        queue.put(jsonObject.toString());
+    }
+}

+ 6 - 6
web/src/main/java/com/jpsoft/smart/listener/WebStateListener.java

@@ -31,9 +31,9 @@ public class WebStateListener implements ServletContextListener {
         // TODO Auto-generated method stub
         System.out.println("web应用销毁");
 
-        if(electricityTcpServer!=null) {
-            electricityTcpServer.stop();
-        }
+//        if(electricityTcpServer!=null) {
+//            electricityTcpServer.stop();
+//        }
 
         if (lapiTcpServer!=null){
             lapiTcpServer.stop();
@@ -45,9 +45,9 @@ public class WebStateListener implements ServletContextListener {
         // TODO Auto-generated method stub
         System.out.println("web应用初始化");
 
-        if(electricityTcpServer!=null) {
-            electricityTcpServer.start(electricityParamConfig.getPort());
-        }
+//        if(electricityTcpServer!=null) {
+//            electricityTcpServer.start(electricityParamConfig.getPort());
+//        }
 
         if (lapiTcpServer!=null){
             lapiTcpServer.start(lapiParamConfig.getPort());

+ 7 - 1
web/src/main/resources/application.yml

@@ -157,4 +157,10 @@ oss:
   objectPre: smart
 
 mobile:
-  unMeasureUrl: http://wisdomhousewechat.sudaonline.net/prevention/adundetect_wx_message.html
+  unMeasureUrl: http://wisdomhousewechat.sudaonline.net/prevention/adundetect_wx_message.html
+
+electricity:
+  port: 9966    #监听端口
+
+lapi:
+  port: 9988