jiangping
2025-02-17 5ca11ae7f64bea7463b8a14c27a79036efc62f04
jtt808初始化
已添加2个文件
已修改2个文件
318 ■■■■■ 文件已修改
server/services/src/main/java/com/doumee/core/utils/StringTools.java 269 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/service/business/impl/BikesServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/web/src/main/java/com/doumee/api/web/HomeApi.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/web/src/main/java/com/doumee/jtt808/web/service/Jtt808Service.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/core/utils/StringTools.java
对比新文件
@@ -0,0 +1,269 @@
package com.doumee.core.utils;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.*;
/**
 * @author yezhihao
 * https://gitee.com/yezhihao/jt808-server
 */
public class StringTools {
    public static final int[] EMPTY = new int[0];
    public static final Integer[] EMPTY_ = new Integer[0];
    public static int[] toInts(String str, String delimiter) {
        String[] split = str.split(delimiter);
        int[] result = new int[split.length];
        for (int i = 0; i < split.length; i++)
            result[i] = Integer.parseInt(split[i]);
        return result;
    }
    public static double[] toDoubles(String str, String delimiter) {
        String[] split = str.split(delimiter);
        double[] result = new double[split.length];
        for (int i = 0; i < split.length; i++)
            result[i] = Double.parseDouble(split[i]);
        return result;
    }
    public static byte[] toBytes(String str, String delimiter) {
        String[] split = str.split(delimiter);
        byte[] result = new byte[split.length];
        for (int i = 0; i < split.length; i++)
            result[i] = (byte) Integer.parseInt(split[i]);
        return result;
    }
    public static String merge(String delimiter, Collection value) {
        if (value == null || value.size() == 0)
            return null;
        StringBuilder result = new StringBuilder(value.size() * 5);
        for (Object id : value)
            result.append(id).append(delimiter);
        return result.substring(0, result.length() - 1);
    }
    public static String merge(String delimiter, Object... value) {
        if (value == null || value.length == 0)
            return null;
        StringBuilder result = new StringBuilder(value.length * 5);
        for (Object id : value)
            result.append(id).append(delimiter);
        return result.substring(0, result.length() - 1);
    }
    public static String merge(String delimiter, int... value) {
        if (value == null || value.length == 0)
            return null;
        StringBuilder result = new StringBuilder(value.length * 5);
        for (int id : value)
            result.append(id).append(delimiter);
        return result.substring(0, result.length() - 1);
    }
    public static int[] toInts(Integer[] src) {
        if (src == null || src.length == 0)
            return EMPTY;
        int[] dest = new int[src.length];
        for (int i = 0; i < src.length; i++)
            dest[i] = src[i];
        return dest;
    }
    public static Integer[] toInts(int[] src) {
        if (src == null || src.length == 0)
            return EMPTY_;
        Integer[] dest = new Integer[src.length];
        for (int i = 0; i < src.length; i++)
            dest[i] = src[i];
        return dest;
    }
    public static Integer parseInt(String num) {
        return parseInt(num, null);
    }
    public static Integer parseInt(String num, Integer defVal) {
        if (isBlank(num))
            return defVal;
        try {
            return Integer.parseInt(num);
        } catch (NumberFormatException e) {
            return defVal;
        }
    }
    public static String toUnderline(String str) {
        StringBuilder result = new StringBuilder(str.length() + 4);
        char[] chars = str.toCharArray();
        result.append(Character.toLowerCase(chars[0]));
        for (int i = 1; i < chars.length; i++) {
            char c = chars[i];
            if (Character.isUpperCase(c))
                result.append('_').append(Character.toLowerCase(c));
            else
                result.append(c);
        }
        return result.toString();
    }
    public static String subPrefix(String str, String prefix) {
        if (str != null && str.startsWith(prefix))
            str = str.substring(prefix.length());
        return str;
    }
    public static Map newMap(Object... entrys) {
        Map result = new HashMap((int) (entrys.length / 1.5) + 1);
        for (int i = 0; i < entrys.length; )
            result.put(entrys[i++], entrys[i++]);
        return result;
    }
    public static boolean isNotBlank(String str) {
        return !isBlank(str);
    }
    public static boolean isBlank(String str) {
        return str == null || str.length() == 0 || str.trim().length() == 0;
    }
    public static <T> T getDefault(T value, T defaultValue) {
        return value != null ? value : defaultValue;
    }
    public static String leftPad(String str, int size, char ch) {
        if(str ==null){
            str = "";
        }
        int length = str.length();
        int pads = size - length;
        if (pads > 0) {
            char[] result = new char[size];
            str.getChars(0, length, result, pads);
            while (pads > 0)
                result[--pads] = ch;
            return new String(result);
        }
        return str;
    }
    public static String leftTrip(String str,  char ch) {
        if(str==null ){
            return null;
        }
        int index = 0;
        while (index < str.length() && str.charAt(index) == ch) {
            index++;
        }
        String result = str.substring(index);
        return str;
    }
    public static int[] toArray(Collection<Integer> list) {
        if (list == null || list.isEmpty())
            return null;
        int[] result = new int[list.size()];
        int i = 0;
        for (Integer e : list) {
            if (e != null)
                result[i++] = e;
        }
        return result;
    }
    public static Set<Integer> toSet(int... num) {
        if (num == null || num.length == 0) {
            return Collections.EMPTY_SET;
        }
        Set<Integer> result;
        if (num.length <= 3) {
            result = new TreeSet<>();
        } else {
            result = new HashSet<>(num.length << 1);
        }
        for (int i : num) {
            result.add(i);
        }
        return result;
    }
    public static boolean isNum(String val) {
        if (isBlank(val)) {
            return false;
        }
        int sz = val.length();
        for (int i = 0; i < sz; i++) {
            if (!Character.isDigit(val.charAt(i))) {
                return false;
            }
        }
        return true;
    }
    public static String getStackTrace(final Throwable throwable) {
        final StringWriter sw = new StringWriter(7680);
        final PrintWriter pw = new PrintWriter(sw, true);
        throwable.printStackTrace(pw);
        return sw.getBuffer().toString();
    }
    private static final char[] hexCode = "0123456789abcdef".toCharArray();
    public static String bytes2Hex(byte[] bytes) {
        char[] hex = new char[bytes.length << 1];
        for (int j = 0, i = 0; i < bytes.length; i++) {
            byte b = bytes[i];
            hex[j++] = hexCode[(b >> 4) & 0xF];
            hex[j++] = hexCode[(b & 0xF)];
        }
        return new String(hex);
    }
    public static byte[] hex2Bytes(String hex) {
        final int len = hex.length();
        if (len % 2 != 0) {
            throw new IllegalArgumentException("hexBinary needs to be even-length: " + hex);
        }
        byte[] out = new byte[len >> 1];
        for (int i = 0; i < len; i += 2) {
            int h = hexToBin(hex.charAt(i));
            int l = hexToBin(hex.charAt(i + 1));
            if (h == -1 || l == -1) {
                throw new IllegalArgumentException("contains illegal character for hexBinary: " + hex);
            }
            out[i >> 1] = (byte) (h * 16 + l);
        }
        return out;
    }
    public static int hexToBin(char ch) {
        if ('0' <= ch && ch <= '9') {
            return ch - '0';
        }
        if ('A' <= ch && ch <= 'F') {
            return ch - ('A' - 10);
        }
        if ('a' <= ch && ch <= 'f') {
            return ch - ('a' - 10);
        }
        return -1;
    }
}
server/services/src/main/java/com/doumee/service/business/impl/BikesServiceImpl.java
@@ -4,6 +4,7 @@
import com.doumee.core.constants.Constants;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.StringTools;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.BikesMapper;
import com.doumee.dao.business.join.BikesJoinMapper;
@@ -19,6 +20,7 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.service.system.SystemDictDataService;
import com.github.xiaoymin.knife4j.core.util.StrUtil;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -96,12 +98,7 @@
        if(StringUtils.isBlank(m.getDeviceSn() )){
            return;
        }
        String tSn = m.getDeviceSn();
        if(tSn.length() <12){
            for (int i = 0; i < 12-tSn.length(); i++) {
                tSn = "0"+tSn;
            }
        }
        String tSn = StringTools.leftPad(m.getDeviceSn(),12,'0') ;
        Bikes bikes = bikesJoinMapper.selectOne(new QueryWrapper<Bikes>().lambda()
                        .eq(Bikes::getDeviceSn,tSn)
                        .eq(Bikes::getIsdeleted,Constants.ZERO)
server/web/src/main/java/com/doumee/api/web/HomeApi.java
@@ -6,6 +6,7 @@
import com.doumee.core.model.ApiResponse;
import com.doumee.dao.business.web.response.HomeResponse;
import com.doumee.dao.business.web.response.RidesDetailResponse;
import com.doumee.jtt808.web.service.Jtt808Service;
import com.doumee.service.business.GoodsorderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -13,10 +14,11 @@
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.yzh.commons.model.APIResult;
import org.yzh.protocol.t808.T0201_0500;
import org.yzh.protocol.t808.T0805;
import org.yzh.protocol.t808.T8500;
/**
 * Created by IntelliJ IDEA.
@@ -34,6 +36,8 @@
    @Autowired
    private GoodsorderService goodsorderService;
    @Autowired
    private Jtt808Service jtt808Service;
    @LoginRequired
    @ApiOperation(value = "棣栭〉淇℃伅", notes = "棣栭〉淇℃伅")
@@ -45,5 +49,10 @@
        HomeResponse homeResponse = goodsorderService.getHome(getMemberId());
        return  ApiResponse.success("鏌ヨ鎴愬姛",homeResponse);
    }
    @ApiOperation(value = "娴嬭瘯鐢垫睜鎺у埗", notes = "娴嬭瘯鐢垫睜鎺у埗")
    @PostMapping("/testControl")
    public ApiResponse<APIResult<T0201_0500>> testControl(@RequestBody  T8500 param) {
        return  ApiResponse.success( jtt808Service.bikeControl(param));
    }
}
server/web/src/main/java/com/doumee/jtt808/web/service/Jtt808Service.java
对比新文件
@@ -0,0 +1,23 @@
package com.doumee.jtt808.web.service;
import com.doumee.jtt808.web.endpoint.MessageManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.yzh.commons.model.APIResult;
import org.yzh.protocol.t808.T0201_0500;
import org.yzh.protocol.t808.T8500;
import reactor.core.publisher.Mono;
@Service
public class Jtt808Service {
    @Autowired
    private MessageManager messageManager;
    public  APIResult<T0201_0500>  bikeControl(@RequestBody T8500 request) {
        Mono<APIResult<T0201_0500>>  result = messageManager.requestR(request, T0201_0500.class);
        APIResult<T0201_0500> data = result.block();
        return  data;
    }
}