From 783272d17be7fce92808bd9fb99f9d64f450bfc9 Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期四, 11 七月 2024 14:24:11 +0800
Subject: [PATCH] 添加三一车辆透传订阅提交

---
 ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplSerialPort.java |  261 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java  |    5 +
 2 files changed, 266 insertions(+), 0 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
index d7644e2..00c1e59 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
@@ -13,6 +13,7 @@
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.sy.gps31.PushClientImplSerialPort;
 import com.ruoyi.sy.param.ArdSyCarParam;
 import com.ruoyi.sy.service.IArdTankAbnormalParkAlarmService;
 import com.ruoyi.sy.vo.ArdSyCarVo;
@@ -131,6 +132,10 @@
         Thread pushClientImplAlarmThread = new Thread(pushClientImplAlarm);
         pushClientImplAlarmThread.start();
 
+        PushClientImplSerialPort pushClientImplSerialPort = new PushClientImplSerialPort(ip,userId,password);
+        Thread pushClientImplSerialPortThread = new Thread(pushClientImplSerialPort);
+        pushClientImplSerialPortThread.start();
+
         //鍒犻櫎缁撴潫鏃堕棿涓簄ull鐨勮褰�
         int result = ardTankAbnormalParkAlarmService.deleteArdTankAbnormalParkAlarmByEndTime();
     }
diff --git a/ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplSerialPort.java b/ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplSerialPort.java
new file mode 100644
index 0000000..4cb0a4d
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplSerialPort.java
@@ -0,0 +1,261 @@
+/**
+ * <p>Description: </p>
+ * <p>Copyright: Copyright (c) 2020</p>
+ * <p>Company: www.31gps.net</p>
+ * @author chencq
+ * @version 1.0
+ */
+package com.ruoyi.sy.gps31;
+
+import com.alibaba.fastjson2.JSON;
+import com.gps31.push.netty.PushClient;
+import com.gps31.push.netty.PushMsg;
+import com.gps31.push.netty.client.TcpClient;
+import com.gps31.push.util.MapUtil;
+import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.sy.domain.ArdSyCarLock;
+import com.ruoyi.sy.domain.ArdSyCarRtu;
+import com.ruoyi.sy.service.ArdSyCarLockService;
+import com.ruoyi.sy.service.ArdSyCarRtuService;
+import com.ruoyi.sy.service.impl.ArdSyCarDayServiceImpl;
+import com.ruoyi.sy.service.impl.ArdSyCarServiceImpl;
+import com.ruoyi.sy.service.impl.ArdTankAbnormalParkAlarmServiceImpl;
+import com.ruoyi.utils.qymqtt.newM.EmqClient;
+import com.ruoyi.utils.qymqtt.newM.QosEnum;
+import lombok.extern.slf4j.Slf4j;
+import org.eclipse.paho.client.mqttv3.MqttException;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * <p>Description: </p>
+ * <p>Copyright: Copyright (c) 2020</p>
+ * <p>Company: www.31gps.net</p>
+ * @author chencq
+ * @version 1.0
+ */
+@Slf4j(topic = "mqttCar")
+public class PushClientImplSerialPort extends PushClient implements Runnable {
+
+//    private static final Log log = LogFactory.getLog(PushClientImplPosition.class);
+
+    private String ip;
+
+    private String userId;
+
+    private String password;
+
+    public PushClientImplSerialPort(String ip, String userId, String password) {
+        this.ip = ip;
+        this.userId = userId;
+        this.password = password;
+    }
+
+    public PushClientImplSerialPort() {
+
+    }
+
+    @Override
+    public void messageReceived(TcpClient tcpClient, PushMsg pushMsg)
+            throws Exception {
+        if("8001".equals(pushMsg.getCmd())) {//鐧诲綍搴旂瓟
+            String rspResult = MapUtil.getStrVal(pushMsg.getJsonMap(),"rspResult","1");
+            if("0".equals(rspResult)) {//鐧诲綍鎴愬姛锛屽畾闃呭姩鎬佹秷鎭�
+                Map<String,Object> map = new HashMap<String,Object>();
+                map.put("seq", "1");
+                map.put("action", "add");
+                map.put("msgIds", JSON.toJSONString(getSubCmdSet()));
+                PushMsg subMsg = getInstance("0003",map);
+                sendMsg(subMsg);
+            }
+        }else if("8002".equals(pushMsg.getCmd())){//蹇冭烦搴旂瓟
+
+        }else if("8003".equals(pushMsg.getCmd())){//璁㈤槄鍔ㄦ�佹秷鎭簲绛�
+            String rspResult = MapUtil.getStrVal(pushMsg.getJsonMap(),"rspResult","1");
+            //log.error(String.format("    璁㈤槄搴旂瓟:%s", "0".equals(rspResult)?"鎴愬姛":"澶辫触"));
+        }else if("0200".equals(pushMsg.getCmd())) {//瀹氫綅淇℃伅
+            Map<String,Object> gpsMap = pushMsg.getJsonMap();
+            log.debug(String.format("   ---->----鏀跺埌瀹氫綅鏁版嵁濡備笅:%s",JSON.toJSONString(gpsMap)));
+            /**
+             *
+             * 璇峰姞鍏ヤ笁鏂归泦鎴愭柟鐨勪笟鍔¢�昏緫
+             *
+             */
+        }else if("0300".equals(pushMsg.getCmd())) {//鎶ヨ娑堟伅
+            Map<String,Object> alarmMap = pushMsg.getJsonMap();
+            String carName = MapUtil.getStrVal(alarmMap, "carName","");//鑾峰彇杞︾墝鍙�
+            //log.error(String.format("   ---->鏀跺埌鎶ヨ鏁版嵁:%s",JSON.toJSONString(alarmMap)));
+            /**
+             *
+             * 璇峰姞鍏ヤ笁鏂归泦鎴愭柟鐨勪笟鍔¢�昏緫
+             *
+             */
+        }else if("0401".equals(pushMsg.getCmd())) {//閫忎紶娑堟伅
+            Map<String,Object> dataMap = pushMsg.getJsonMap();
+            String carName = MapUtil.getStrVal(dataMap, "carName","");//鑾峰彇杞︾墝鍙�
+            //log.error(String.format("   ---->鏀跺埌閫忎紶鏁版嵁:%s",JSON.toJSONString(dataMap)));
+            /**
+             *
+             * 璇峰姞鍏ヤ笁鏂归泦鎴愭柟鐨勪笟鍔¢�昏緫
+             *
+             */
+        }
+    }
+
+    public void sendMassage() {
+        try {
+            PushClientImplSerialPort client = new PushClientImplSerialPort();
+            client.setLog(false);//鏄惁鎵撳嵃鏄庢枃
+            client.setHost(this.ip);//鏈嶅姟鍣↖P
+            client.setPort(10100);//鏈嶅姟鍣ㄧ鍙�
+            client.setUserName(this.userId);//绯荤粺鐢ㄦ埛鍚�
+            client.setPwd(this.password);//绯荤粺鐢ㄦ埛瀵嗙爜
+            client.setSubMsgIds("0401");//璁㈤槄鐨勫姩鎬佹秷鎭紝澶氫釜鍔ㄦ�佹秷鎭娇鐢▅杈熷垎锛屽綋鍓嶇ず渚嬫槸璁㈤槄  瀹氫綅娑堟伅(0x0200)鍜屾姤璀︽秷鎭�(0x0300)
+            client.setDesc("娴嬭瘯瀹㈡埛绔�");//瀹㈡埛绔殑鎻忚堪锛�
+            client.start();
+            while(true) {
+                Thread.sleep(1000);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void run() {
+        sendMassage();
+    }
+
+    private void feng(String carId,String type,ArdSyCarRtuService carRtuService,ArdSyCarLockService lockService) throws MqttException {
+        //鏌ヨ瑁呮补鐐规棦瀹歊tu鐘舵��
+        ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId);
+        if(ardSyCarRtu!=null){
+            //鏌ヨ閿佷俊鎭�
+            List<ArdSyCarLock> ardSyCarLocks = lockService.carLock(ardSyCarRtu.getId());
+            if(ardSyCarLocks.size()>0){
+                Integer fengType = null;
+                if("瑁呮补鐐�".equals(type)){
+                    fengType = ardSyCarRtu.getInstallType();
+                }else if("鍗告补鐐�".equals(type)){
+                    fengType = ardSyCarRtu.getUnloadType();
+                }else if("鏂藉皝".equals(type)){
+                    fengType = 0;
+                }
+                //1瑙e皝
+                if(fengType==1){
+                    //濡傛灉涓嶆槸瑙e皝灏佺姸鎬侊紝鍒欏彂閫佹柦灏佸懡浠�
+                    if(ardSyCarLocks.get(0).getRelayInfo()==0 || ardSyCarLocks.get(0).getRelayInfo()==null){
+//                            Map<String,Object> map = new HashMap<>();
+//                            map.put("A01", 110000);//瀵奸�氱涓�璺户鐢靛櫒
+//                            map.put("A02", 110000);//瀵奸�氱浜岃矾缁х數鍣�
+//                            map.put("res", String.valueOf(System.currentTimeMillis()));
+//                            String mapString = com.alibaba.fastjson.JSON.toJSONString(map);
+                        String mapString = "{\"A01\":110000,\"A02\":110000,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}";
+                        log.debug("鑷姩瑙e皝锛�"+mapString);
+                        EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+                        emqClient.connect();
+                        emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
+                        log.debug("杞﹁締"+carId+"瑙e皝鍛戒护鍙戦�佹垚鍔燂紒");
+                        //                mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"瑙e皝");
+                    }
+                }
+
+                //0鏂藉皝
+                if(fengType==0){
+                    if(ardSyCarLocks.get(0).getRelayInfo()==1 || ardSyCarLocks.get(0).getRelayInfo()==null){
+                        //閿佸紑鍏崇姸鎬�
+                        int lockCloseNum = 0;
+                        String mapString1 = "{\"A01\":100000,\"A02\":100000,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}";
+                        System.out.println("鑷姩鏂藉皝锛�"+mapString1);
+                        EmqClient emqClient1 = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+                        emqClient1.connect();
+                        emqClient1.publish(ardSyCarRtu.getTopicPublish(),mapString1, QosEnum.QoS2,false);
+                        //濡傛灉涓嶆槸鏂藉皝鐘舵�侊紝鍒欏彂閫佹柦灏佸懡浠�
+                        if(ardSyCarLocks.get(0).getRelayInfo()!=null){
+                            if(ardSyCarLocks.get(0).getRelayInfo()==1){
+                                for (int j = 0; j < ardSyCarLocks.size(); j++) {
+                                    ArdSyCarLock ardSyCarLock = ardSyCarLocks.get(j);
+                                    String currents = ardSyCarLock.getCurrents();
+                                    Double currentInfo = ardSyCarLock.getCurrentInfo();
+                                    //鐢垫祦鍊间负4.0鏄叧閿佺姸鎬�
+                                    if(currentInfo.equals(4.00) || currentInfo.equals(4)){
+                                        lockCloseNum += 1;
+                                    }else {
+                                        String key = "";
+                                        if(currents.equals("C01")){
+                                            key = "D03";
+                                        }else if(currents.equals("C02")){
+                                            key = "D04";
+                                        }
+//                                    Map<String,Object> map = new HashMap();
+//                                    map.put(key, 0.01);
+//                                    map.put("res", String.valueOf(System.currentTimeMillis()));
+//                                    String mapString = com.alibaba.fastjson.JSON.toJSONString(map);
+                                        String mapString = "{\""+key+"\":0.01,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}";
+                                        log.debug("鑷姩鍏抽攣锛�"+mapString);
+                                        EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID());
+                                        emqClient.connect();
+                                        emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false);
+                                        //                        mqttOnce.publishCar("carId",ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"寮�閿侊細"+currents);
+                                        while(true){
+                                            ArdSyCarLock ardSyCarLock1 = lockService.getCurrentInfo(ardSyCarRtu.getId(),currents);
+                                            Double currentInfo1 = ardSyCarLock1.getCurrentInfo();
+                                            if(currentInfo1.equals(4.00) || currentInfo1.equals(4)){
+                                                lockCloseNum +=1;
+                                                break;
+                                            }
+                                        }
+                                    }
+                                }
+                                if(lockCloseNum == 2){
+//                                Map<String,Object> map = new HashMap<>();
+//                                map.put("A01", 100000);//鏂紑绗竴璺户鐢靛櫒
+//                                map.put("A02", 100000);//鏂紑绗簩璺户鐢靛櫒
+//                                map.put("res", String.valueOf(System.currentTimeMillis()));
+//                                String mapString = com.alibaba.fastjson.JSON.toJSONString(map);
+                                    log.debug("杞﹁締"+carId+"鏂藉皝鍛戒护鍙戦�佹垚鍔燂紒");
+                                    //                    mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"鏂藉皝");
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    public Double[] azimuth_offset(double origin_lon, double origin_lat, Integer direction,double distance){
+        Double[] lonlat = new Double[2];
+        if(direction != null && distance > 0){
+            lonlat[0] = origin_lon + distance * Math.sin(direction* Math.PI / 180) * 180 / ( Math.PI * 6371229 * Math.cos(origin_lat * Math.PI / 180));
+            lonlat[1] = origin_lat + distance * Math.cos(direction* Math.PI / 180) / ( Math.PI * 6371229 / 180);
+        }else{
+            lonlat[0] = origin_lon;
+            lonlat[1] = origin_lat;
+        }
+        return lonlat;
+    }
+
+    public Double getDistance(Double velocity ,Double acceleration ,String time){
+        Double distance = velocity*Double.parseDouble(time) + 0.5*acceleration*Double.parseDouble(time)*Double.parseDouble(time);
+        return distance;
+    }
+
+    /*public Double getVelocity(Double velocity ,Double acceleration ,String time){
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Long t = (long) 0;
+        try {
+            t = (new Date().getTime() - simpleDateFormat.parse(time).getTime())/1000;
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        Double velocityt = velocity + acceleration*t;
+        return velocityt;
+    }*/
+
+}

--
Gitblit v1.9.3