瀏覽代碼

Merge branch 'master' of http://git.fast-fun.cn:92/ruili/zk-station-server

TitanWong 2 年之前
父節點
當前提交
13644e11b2

+ 11 - 9
.drone.yml

@@ -27,18 +27,20 @@ steps:
       - name: cache
         path: /cache
 
-  - name: docker-build
-    image: plugins/docker:linux-amd64
+  - name: docker-zk-station-server
+    image: plugins/docker:20.14.0-linux-amd64
+    pull: false
     settings:
-      mirror: https://dwfcyrfg.mirror.aliyuncs.com
+      purge: false
+      add_host:
+        - nas.fast-fun.cn:192.168.0.40
       tags:
-        - latest
-        - 1.0.${DRONE_BUILD_NUMBER}
-#      registry: nas.fast-fun.cn:5000
-      registry: 192.168.10.122:5000
+        - v1.0.0.${DRONE_BUILD_NUMBER}
+      registry: nas.fast-fun.cn:5000
       insecure: true
-      repo: 192.168.10.122:5000/zk/station-server
-#      repo: nas.fast-fun.cn:5000/zk/station-server
+      dockerfile: Dockerfile
+      mirror: https://1u6db9h5.mirror.aliyuncs.com
+      repo: nas.fast-fun.cn:5000/zk/zk-station-server
 
 volumes:
   - name: cache

+ 7 - 3
src/main/java/com/zhili/zkstationserver/dto/ExchangeEvent.java

@@ -43,6 +43,8 @@ public class ExchangeEvent {
     Integer step;
     Integer startSource;
     Date time;
+    Integer powerState;
+    Integer lockState;
 
     public class ExchangeSeq {
         public static final int PLATE_RECOGNIZE = 0;
@@ -67,10 +69,10 @@ public class ExchangeEvent {
         serialNo = BytesUtil.parseString(ArrayUtils.subarray(data, 32, 64));
         seq = Byte.toUnsignedInt(data[64]);
         status = Byte.toUnsignedInt(data[65]);
-        plate = BytesUtil.parseStringFromGb2312Bytes(ArrayUtils.subarray(data, 66, 86));
+        plate = BytesUtil.deUnicode(ArrayUtils.subarray(data, 66, 86));
         vin = BytesUtil.parseString(ArrayUtils.subarray(data, 86, 103));
-        model = BytesUtil.parseString(ArrayUtils.subarray(data, 103, 119));
-        sourceSn = BytesUtil.parseString(ArrayUtils.subarray(data, 119, 146));
+        model = BytesUtil.deUnicode(ArrayUtils.subarray(data, 103, 119));
+        sourceSn = BytesUtil.parseStringZero(ArrayUtils.subarray(data, 119, 146));
         sourceRatedEnergy = BytesUtil.toIntWithLowerFirst(ArrayUtils.subarray(data, 146, 148)) * 0.1f;
         sourceSoc = Byte.toUnsignedInt(data[148]) * 0.4f;
         sourceSoh = Byte.toUnsignedInt(data[149]) * 0.4f;
@@ -87,6 +89,8 @@ public class ExchangeEvent {
         timeStr = BytesUtil.composeTimeString(ArrayUtils.subarray(data, 198, 206));
         step = Byte.toUnsignedInt(data[206]);
         startSource = Byte.toUnsignedInt(data[207]);
+        powerState = Byte.toUnsignedInt(data[208]);
+        lockState = Byte.toUnsignedInt(data[209]);
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         Date timeD = null;
         try {

+ 2 - 0
src/main/java/com/zhili/zkstationserver/entity/ExchangeRecord.java

@@ -44,4 +44,6 @@ public class ExchangeRecord {
     Boolean uploaded;
     Date updateTime;
     Date time;
+    Integer powerState;
+    Integer lockState;
 }

+ 69 - 0
src/main/java/com/zhili/zkstationserver/util/BytesUtil.java

@@ -3,9 +3,11 @@ package com.zhili.zkstationserver.util;
 import org.apache.commons.lang3.StringUtils;
 
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.List;
 
@@ -57,6 +59,7 @@ public class BytesUtil {
 
     public static String parseStringFromGb2312Bytes(byte[] bytes){
         try{
+            //System.out.println("------------------"+BytesUtil.bytesToHexString(bytes));
             String gb2312Str = new String(bytes, "gb2312");
             return gb2312Str.substring(0,gb2312Str.indexOf((char)0));
         }catch (Exception e){
@@ -64,6 +67,33 @@ public class BytesUtil {
         }
     }
 
+    //将16进制数转换为汉字
+    public static String deUnicode(byte[] bytes){
+        System.out.println("------------------"+BytesUtil.bytesToHexString(bytes));
+        String content = BytesUtil.bytesToHexStringNew(bytes);
+        String enUnicode=null;
+        String deUnicode=null;
+        for(int i=0;i<content.length();i++){
+            if(enUnicode==null){
+                enUnicode=String.valueOf(content.charAt(i));
+            }else{
+                enUnicode=enUnicode+content.charAt(i);
+            }
+            if(i%4==3){
+                if(enUnicode!=null){
+                    if(deUnicode==null){
+                        deUnicode=String.valueOf((char)Integer.valueOf(enUnicode, 16).intValue());
+                    }else{
+                        deUnicode=deUnicode+String.valueOf((char)Integer.valueOf(enUnicode, 16).intValue());
+                    }
+                }
+                enUnicode=null;
+            }
+
+        }
+        return deUnicode.substring(0,deUnicode.indexOf((char)0));
+    }
+
     public static String parseString(byte[] b) {
         StringBuilder sb = new StringBuilder();
         for (int i = 0; i < b.length; i++) {
@@ -74,6 +104,29 @@ public class BytesUtil {
         return k>=0?rawString.substring(0, k):rawString;
     }
 
+    /**
+     * 显示0的字符串
+     * @param b
+     * @return
+     */
+    public static String parseStringZero(byte[] b) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < b.length; i++) {
+            sb.append((char) b[i]);
+        }
+        String rawString = sb.toString();
+        int k = rawString.indexOf(0);
+        if(k==0){
+            String res = Arrays.toString(b);
+            res = StringUtils.strip(res,"[]") //去掉两边括号
+                    .replaceAll(",","")
+                    .replaceAll("\\s*","");//去掉空格
+            return res;
+        }
+        return k>=0?rawString.substring(0, k):rawString;
+
+    }
+
     public static byte[] fromString(String s, int len, byte fill) {
         byte[] res = new byte[len];
         for (int i = 0; i < s.length(); i++) {
@@ -210,6 +263,22 @@ public class BytesUtil {
         return sb.toString();
     }
 
+    public static String bytesToHexStringNew(byte[] src){
+        StringBuilder stringBuilder = new StringBuilder("");
+        if (src == null || src.length <= 0) {
+            return null;
+        }
+        for (int i = 0; i < src.length; i++) {
+            int v = src[i] & 0xFF;
+            String hv = Integer.toHexString(v);
+            if (hv.length() < 2) {
+                stringBuilder.append(0);
+            }
+            stringBuilder.append(hv);
+        }
+        return stringBuilder.toString();
+    }
+
     /**
      * description: 字符串转 Unicode --- 原生方法
      *

+ 51 - 0
src/main/resources/application-test.yml

@@ -0,0 +1,51 @@
+server:
+  port: 8888
+
+zookeeper:
+  server: 172.16.121.248:2181
+
+spring:
+  datasource:
+    url: jdbc:mysql://172.16.121.248:3306/station_control_cloud?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+    username: root
+#    password: 'jek123'
+    password: 'Qx123456'
+    driverClassName: com.mysql.cj.jdbc.Driver
+  redis:
+    host: 172.16.121.248
+    port: 6379
+    #password: jek123
+  kafka:
+    bootstrap-servers: 172.16.121.248:9092
+    producer:
+      key-serializer: org.apache.kafka.common.serialization.StringSerializer
+      value-serializer: org.apache.kafka.common.serialization.StringSerializer
+      acks: 1
+    consumer:
+      group-id: default-group
+      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
+      max-poll-records: 50
+    listener:
+      ack-mode: MANUAL_IMMEDIATE
+      missing-topics-fatal: false
+
+logging:
+  level:
+    com.zhili: info
+    root: error
+
+mybatis-plus:
+  mapper-locations: mapper/*.xml
+  typeAliasesPackage: com.zhili.stationcontrol.entrty
+  global-config:
+    banner: false
+  configuration:
+#        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
+
+
+station-server:
+  port: 9987
+#  advertised-network: 192.168.10.*
+#  advertised-network: 192.168.0.*