liuf 1 ano atrás
pai
commit
8738de6ec6

+ 11 - 0
readme.txt

@@ -0,0 +1,11 @@
+
+
+
+
+1. docker ps查看容器状态
+2. docker stop device-link-ykc停止云快充docker容器
+3. docker rm device-link-ykc删除容器
+4. docker rmi device-link-ykc删除镜像
+5. 更换路径\wgd\docker-compose\ykc-jar路径下的jar包
+6. \wgd\docker-compose路径下重新构建启动项目docker-compose up -d --build device-link-ykc
+7. 启动完成查看日志docker logs -f -n100 device-link-ykc或在\wgd\docker-compose\logs目录中查看日志tail -f -n100 YKC-info.log

+ 1 - 0
src/main/java/com/tmzn/devicelinkykc/constant/RedisConstant.java

@@ -10,6 +10,7 @@ public class RedisConstant {
     //根据枪号缓存的设备状态表信息,状态变位时更新
     public static final String ONLINE_DEVICE_ONE= "onlineDevicePortOneYKC";
     public static final String ONLINE_DEVICE_TWO= "onlineDevicePortTwoYKC";
+    public static final String POWER_ZERO_TIMES = "powerZeroTimes";
 
     //最新设备103消息
     public static final String DEVICE_PORT_STATUS= "devicePortStatusYKC";

+ 16 - 1
src/main/java/com/tmzn/devicelinkykc/controller/TestController.java

@@ -17,11 +17,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.connection.Message;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
-
+import org.springframework.web.bind.annotation.*;
 import java.util.HashMap;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
@@ -47,6 +49,19 @@ public class TestController {
     @Autowired
     private RedisCache redisCache;
 
+
+    @Autowired
+    private DeviceMsgHandle deviceMsgHandle;
+
+    @PostMapping("/msg")
+    public void testMsg(@RequestBody String message) {
+        try {
+            deviceMsgHandle.testMsg(message);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     @GetMapping("/test")
     public String test(@RequestParam("method") String method, @RequestParam("imei") String imei) {
 

+ 66 - 2
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/LoginFrame.java

@@ -41,7 +41,13 @@ public class LoginFrame {
     public void loginMsgSend(DeviceConnectionMsg deviceConnectionMsg,Device device){
         byte[] send = new byte[0];
         try {
-            send = loginMsg(device);
+            System.out.println(device.getCommProtocolVer());
+            if(!device.getCommProtocolVer().startsWith("1.8")){
+                send = loginMsgNot18(device);
+            }else{
+                send = loginMsg18(device);
+            }
+
         } catch (Exception e) {
             log.info("pileCode:"+device.getPileCode()+" login params Exception:");
             e.printStackTrace();
@@ -66,8 +72,66 @@ public class LoginFrame {
         log.info("pileCode:"+device.getPileCode()+" login over");
     }
 
+    private byte[] loginMsgNot18( Device device) throws Exception {
+
+        byte[] msg = new byte[30];//消息体
+
+        int index = 0;
+        //1.桩编码
+        byte[] pile_code = new byte[7];
+        byte[] bcd = DataConversion.bcdToBytes(device.getPileCode(), pile_code.length);
+        System.arraycopy(bcd, 0, pile_code, 0, bcd.length);
+        System.arraycopy(pile_code, 0, msg, index, pile_code.length);
+        index += pile_code.length;
+        //3. 充电桩类型,0:直流,1:交流
+        byte[] pile_type = new byte[]{device.getPileType()};
+        System.arraycopy(pile_type, 0, msg, index, pile_type.length);
+        index += pile_type.length;
+        // 4.充电枪连接数
+        byte[] charger_gun_num = new byte[]{device.getChargerGunNum()};
+        System.arraycopy(charger_gun_num, 0, msg, index, charger_gun_num.length);
+        index += charger_gun_num.length;
+        // 5.通讯协议版本
+        byte[] comm_protocol_ver = new byte[1]; // 通讯协议版本
+
+        // 提取前两位
+        String[] parts = device.getCommProtocolVer().split("\\.");
+        String firstTwoParts = parts[0] + "." + parts[1];
+        // 转换为数字并乘以 10
+        double number = Double.parseDouble(firstTwoParts);
+        double result = number * 10;
+        byte byteValue = (byte) result;
+        comm_protocol_ver[0] = byteValue;
+
+        System.arraycopy(comm_protocol_ver, 0, msg, index, comm_protocol_ver.length);
+        index += comm_protocol_ver.length;
+
+        //6.程序版本
+        byte[] program_version = new byte[8];
+        byte[] program_versions = device.getProgramVersion().getBytes();
+        System.arraycopy(program_versions, 0, program_version, 0, program_versions.length);
+
+        System.arraycopy(program_version, 0, msg, index, program_version.length);
+        index += program_version.length;
+        // 7.网络链接类型,0:sim 卡
+        byte[] net_link_type = new byte[]{device.getNetLinkType()};
+        System.arraycopy(net_link_type, 0, msg, index, net_link_type.length);
+        index += net_link_type.length;
+        //8.SIM卡
+        byte[] sim_card = new byte[10];
+        sim_card = DataConversion.bcdToBytes(device.getSimCard(), sim_card.length);
+        System.arraycopy(sim_card, 0, msg, index, sim_card.length);
+        index += sim_card.length;
+        // 9.运营商,0:移动
+        byte[] operators = new byte[]{device.getOperators()};
+        System.arraycopy(operators, 0, msg, index, operators.length);
+        index += operators.length;
+
+        return msg;
+
+    }
 
-    private byte[] loginMsg( Device device) throws Exception {
+    private byte[] loginMsg18( Device device) throws Exception {
         Random random = new Random();
         StringBuilder sb = new StringBuilder();
         for (int i = 0; i < 16; i++) {

+ 70 - 0
src/main/java/com/tmzn/devicelinkykc/message/DeviceMsgHandle.java

@@ -19,6 +19,7 @@ import com.tmzn.devicelinkykc.frameMsg.frameType.LoginFrame;
 import com.tmzn.devicelinkykc.frameMsg.frameType.RealTimeStatusPushFrame;
 import com.tmzn.devicelinkykc.frameMsg.frameType.TransactionFlowPushFrame;
 import com.tmzn.devicelinkykc.msgEnum.DeviceSendYkc;
+import com.tmzn.devicelinkykc.openfeign.transdata.RpcResult;
 import com.tmzn.devicelinkykc.redis.RedisCache;
 import com.tmzn.devicelinkykc.service.*;
 import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
@@ -142,6 +143,16 @@ public class DeviceMsgHandle {
         }
     }
 
+    public void testMsg(String msg) throws Exception {
+        logger.info("testmsg>>>" + msg);
+        JSONObject jsonObject = null;
+        jsonObject = JSONObject.parseObject(msg);
+        //设备状态更新,true:没有type不是设备上送类型不往云快充处理 false:需要根据设备消息类型往下处理是不是需要上报云快充
+        if (checkDeviceStatus(jsonObject)) {
+            return;
+        }
+    }
+
     private void checkActive(String s) {
 
         Long now = System.currentTimeMillis();
@@ -185,6 +196,52 @@ public class DeviceMsgHandle {
         }
     }
 
+    private boolean checkAutoStop(int power,String imei,int portId){
+
+        try{
+            String hkey = imei+"_"+portId;
+            Integer lastPower0Times = 0;
+            if(power>0){
+
+            }else{
+                lastPower0Times = redisCache.getCacheMapValue(RedisConstant.POWER_ZERO_TIMES,hkey);
+                if(lastPower0Times == null){
+                    lastPower0Times = 0;
+                }
+                lastPower0Times = lastPower0Times+1;
+            }
+
+            redisCache.setCacheMapValue(RedisConstant.POWER_ZERO_TIMES,hkey,lastPower0Times);
+
+            if(lastPower0Times<5){
+                return true;
+            }
+
+            //查找订单开始时间 如果开始时间过过2分钟 且连续power为0 就需要停止充电
+            QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
+            orderStatusQueryWrapper.eq("device_imei", imei).eq("guns_code", portId).orderByDesc("create_time").last("limit 1");
+            OrderStatus one = orderStatusService.getOne(orderStatusQueryWrapper);
+            if(one.getNowOrderStatus()!=StatusConstant.NOW_ORDER_STATUS_CHARGING){
+                return true;
+            }
+            if((System.currentTimeMillis()- one.getCreateTime())<120*1000){
+                return true;
+            }
+
+            //连续3次功率0 就要停止充电
+            RpcResult rpcResult = deviceControlerService.stopCharge(imei, imei, (int) portId);
+            logger.info("{}-{}触发无功率自停{}",imei,portId,lastPower0Times);
+            return true;
+        }catch (Exception e){
+            logger.error("无功率检测异常{}",e.getMessage());
+            e.printStackTrace();
+        }
+
+        return false;
+
+
+    }
+
     /**
      * 设备状态按照设备上报和设备心跳上送时间校验修改,这里就必须更新状态的修改时间;通过定时任务判断在线设备接收心跳包超10分钟改为离线
      *
@@ -225,6 +282,17 @@ public class DeviceMsgHandle {
 //                if (port_second_status != null&&power==0&&port_second_status==PortStatusConstant.CHARGING){
 //                    port_second_status=PortStatusConstant.FREE;
 //                }
+
+            //判断连续无功率就自动停止
+            if(port_first_status==PortStatusConstant.CHARGING){
+                 checkAutoStop(power,imei,1);
+
+            }
+            if(port_second_status==PortStatusConstant.CHARGING){
+                checkAutoStop(power,imei,2);
+            }
+
+
             redisCache.setCacheObject(RedisConstant.DEVICE_PORT_STATUS + imei, data, 15, TimeUnit.MINUTES);
             if (port_first_status != null) {
                 checkPort(port_first_status, 1, imei, type);
@@ -718,6 +786,8 @@ public class DeviceMsgHandle {
             if (one == null) {
                 logger.info("当前设备imei:" + imei + ",没有绑定ykc桩编码!!!!!!!!!!!!!!!!!!");
                 return;
+            }else{
+
             }
             statusServiceOne = new DeviceStatus();
             statusServiceOne.setDeviceImei(imei);

+ 1 - 1
src/main/java/com/tmzn/devicelinkykc/taskQueue/HeartTask.java

@@ -48,7 +48,7 @@ public class HeartTask {
                 msgHeartQueue.add(deviceConnectionMsgMap);
             }
         };
-        scheduler.scheduleAtFixedRate(task,0,10*1000, TimeUnit.MILLISECONDS);
+        scheduler.scheduleAtFixedRate(task,0,100*1000, TimeUnit.MILLISECONDS);
 
     }
 }

+ 2 - 1
src/main/java/com/tmzn/devicelinkykc/taskQueue/queue/TaskRunner.java

@@ -81,6 +81,7 @@ public class TaskRunner {
     @Async("heartTaskAsyncPool")
     public void heartMsg(Map<String, DeviceConnectionMsg> map) throws Exception {
         log.info("======Heart beat task starting=====");
+        //todo return
         //任务处理
         //map拿出来进行心跳包上报,1:直接检查心跳时间是否大于三十秒
         Set<String> devicePileCodes = map.keySet();
@@ -492,7 +493,7 @@ public class TaskRunner {
                     }
                 }
                 if (redisCache.hasKey(RedisConstant.ONLINE_DEVICE_TWO)) {
-                    DeviceStatus deviceStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_ONE, devicePileCode);
+                    DeviceStatus deviceStatus = redisCache.getCacheMapValue(RedisConstant.ONLINE_DEVICE_TWO, devicePileCode);
 
                     if (deviceStatus != null) {
 

+ 6 - 6
src/main/resources/application-dev.yml

@@ -1,17 +1,17 @@
 spring:
   redis:
     # 地址
-    host: 116.62.171.226
+    host: 127.0.0.1
     # 端口,默认为6379
-    port: 6789
+    port: 6379
     # 数据库索引
     database: 1
     # 密码
-    password: Qq8575791623+-
+    password:
   datasource:
-    url: jdbc:mysql://61.183.212.90:57911/ykctest?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
-    username: root
-    password: Qyy#2023.Wzh!
+    url: jdbc:mysql://47.96.68.249:3456/wdttest?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
+    username: wtdtest
+    password: dB5SzapmL5aL4L2H
     type: com.alibaba.druid.pool.DruidDataSource
     driver-class-name: com.mysql.cj.jdbc.Driver
 redisMsgChanel: redisMsgChanel