上饶警务-警车数据读取服务(udp)
zhongrj
2023-08-03 f6e4aa704f7661add2b64d47a350da2f85336ad9
新增警车设备信息插入(通过upd服务接收信息),并移除flowable工作流
4 files modified
33 files deleted
13 files added
4822 ■■■■■ changed files
pom.xml 8 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/business/controller/WorkController.java 146 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/business/service/FlowBusinessService.java 72 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/business/service/IFlowService.java 77 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/business/service/impl/FlowBusinessServiceImpl.java 333 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/business/service/impl/FlowServiceImpl.java 97 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/core/constant/ProcessConstant.java 61 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/core/entity/BladeFlow.java 179 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/core/entity/FlowEntity.java 43 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/core/enums/FlowModeEnum.java 45 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/core/utils/FlowUtil.java 66 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/core/utils/TaskUtil.java 71 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/demo/leave/controller/LeaveController.java 65 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/demo/leave/entity/ProcessLeave.java 67 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/demo/leave/mapper/LeaveMapper.java 29 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/demo/leave/mapper/LeaveMapper.xml 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/demo/leave/service/ILeaveService.java 37 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/demo/leave/service/impl/LeaveServiceImpl.java 79 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/demo/package-info.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/config/FlowableConfiguration.java 44 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/constant/FlowEngineConstant.java 52 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/controller/FlowFollowController.java 73 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/controller/FlowManagerController.java 125 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/controller/FlowModelController.java 121 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/controller/FlowProcessController.java 98 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/entity/FlowExecution.java 50 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/entity/FlowModel.java 58 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/entity/FlowProcess.java 65 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/mapper/FlowMapper.java 46 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/mapper/FlowMapper.xml 53 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/service/FlowEngineService.java 165 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java 559 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/flow/engine/utils/FlowCache.java 80 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/business/entity/PoliceCarEquipment.java 104 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/business/entity/PoliceCarEquipmentRecord.java 87 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/business/mapper/PoliceCarEquipmentMapper.java 42 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/business/mapper/PoliceCarEquipmentMapper.xml 73 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/business/service/PoliceCarEquipmentService.java 19 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/business/service/impl/PoliceCarEquipmentServiceImpl.java 60 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/config/MyDecoder.java 132 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/config/SysConfig.java 26 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/event/StartupEvent.java 38 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/handle/UdpServerHandler.java 160 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/server/UdpServer.java 86 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/util/Hex.java 552 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/netty/util/HexStringTool.java 303 ●●●●● patch | view | raw | blame | history
src/main/resources/application-dev.yml 6 ●●●● patch | view | raw | blame | history
src/main/resources/application-prod.yml 4 ●●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 8 ●●●● patch | view | raw | blame | history
src/test/java/org/springblade/test/BladeTest.java 46 ●●●●● patch | view | raw | blame | history
pom.xml
@@ -120,10 +120,10 @@
            <artifactId>blade-starter-report</artifactId>
        </dependency>
        <!-- 工作流 -->
        <dependency>
            <groupId>org.springblade</groupId>
            <artifactId>blade-starter-flowable</artifactId>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.springblade</groupId>-->
<!--            <artifactId>blade-starter-flowable</artifactId>-->
<!--        </dependency>-->
        <!-- 验证码 -->
        <dependency>
            <groupId>com.github.whvcse</groupId>
src/main/java/org/springblade/flow/business/controller/WorkController.java
File was deleted
src/main/java/org/springblade/flow/business/service/FlowBusinessService.java
File was deleted
src/main/java/org/springblade/flow/business/service/IFlowService.java
File was deleted
src/main/java/org/springblade/flow/business/service/impl/FlowBusinessServiceImpl.java
File was deleted
src/main/java/org/springblade/flow/business/service/impl/FlowServiceImpl.java
File was deleted
src/main/java/org/springblade/flow/core/constant/ProcessConstant.java
File was deleted
src/main/java/org/springblade/flow/core/entity/BladeFlow.java
File was deleted
src/main/java/org/springblade/flow/core/entity/FlowEntity.java
File was deleted
src/main/java/org/springblade/flow/core/enums/FlowModeEnum.java
File was deleted
src/main/java/org/springblade/flow/core/utils/FlowUtil.java
File was deleted
src/main/java/org/springblade/flow/core/utils/TaskUtil.java
File was deleted
src/main/java/org/springblade/flow/demo/leave/controller/LeaveController.java
File was deleted
src/main/java/org/springblade/flow/demo/leave/entity/ProcessLeave.java
File was deleted
src/main/java/org/springblade/flow/demo/leave/mapper/LeaveMapper.java
File was deleted
src/main/java/org/springblade/flow/demo/leave/mapper/LeaveMapper.xml
File was deleted
src/main/java/org/springblade/flow/demo/leave/service/ILeaveService.java
File was deleted
src/main/java/org/springblade/flow/demo/leave/service/impl/LeaveServiceImpl.java
File was deleted
src/main/java/org/springblade/flow/demo/package-info.java
File was deleted
src/main/java/org/springblade/flow/engine/config/FlowableConfiguration.java
File was deleted
src/main/java/org/springblade/flow/engine/constant/FlowEngineConstant.java
File was deleted
src/main/java/org/springblade/flow/engine/controller/FlowFollowController.java
File was deleted
src/main/java/org/springblade/flow/engine/controller/FlowManagerController.java
File was deleted
src/main/java/org/springblade/flow/engine/controller/FlowModelController.java
File was deleted
src/main/java/org/springblade/flow/engine/controller/FlowProcessController.java
File was deleted
src/main/java/org/springblade/flow/engine/entity/FlowExecution.java
File was deleted
src/main/java/org/springblade/flow/engine/entity/FlowModel.java
File was deleted
src/main/java/org/springblade/flow/engine/entity/FlowProcess.java
File was deleted
src/main/java/org/springblade/flow/engine/mapper/FlowMapper.java
File was deleted
src/main/java/org/springblade/flow/engine/mapper/FlowMapper.xml
File was deleted
src/main/java/org/springblade/flow/engine/service/FlowEngineService.java
File was deleted
src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java
File was deleted
src/main/java/org/springblade/flow/engine/utils/FlowCache.java
File was deleted
src/main/java/org/springblade/modules/netty/business/entity/PoliceCarEquipment.java
New file
@@ -0,0 +1,104 @@
package org.springblade.modules.netty.business.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
 * 对接设备信息表 实体类
 *
 * @author zhongrj
 * @since 2023-02-23
 */
@Data
@TableName("sys_police_car_equipment")
public class PoliceCarEquipment implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 主键id
     */
    private Long id;
    /**
     * 设备名称
     */
    private String name;
    /**
     * 设备编号
     */
    private String code;
    /**
     * 设备状态 0:离线  1:在线
     */
    private Integer status;
    /**
     * 终端编号
     */
    private String terminalNumber;
    /**
     * 经度
     */
    private String longitude;
    /**
     * 纬度
     */
    private String latitude;
    /**
     * 速度,单位 米/秒
     */
    private String speed;
    /**
     * 方向,以正北方向为 0 角度,顺时针方向偏转
     */
    private String direction;
    /**
     * 高程,单位:米
     */
    private String elevation;
    /**
     * 精度
     */
    private String precisions;
    /**
     * 日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date receiveTime;
    /**
     * 创建时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /**
     * 更新时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    /**
     * 说明
     */
//    @ApiModelProperty(value = "说明")
//    private String remark;
}
src/main/java/org/springblade/modules/netty/business/entity/PoliceCarEquipmentRecord.java
New file
@@ -0,0 +1,87 @@
package org.springblade.modules.netty.business.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
 * 对接设备信息记录表 实体类
 *
 * @author zhongrj
 * @since 2023-02-23
 */
@Data
@TableName("sys_police_car_equipment_record")
public class PoliceCarEquipmentRecord implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 主键id
     */
    private Long id;
    /**
     * 设备id
     */
    private Long policeCarEquipmentId;
    /**
     * 设备状态 0:离线  1:在线
     */
    private Integer status;
    /**
     * 终端编号
     */
    private String terminalNumber;
    /**
     * 经度
     */
    private String longitude;
    /**
     * 纬度
     */
    private String latitude;
    /**
     * 速度,单位 米/秒
     */
    private String speed;
    /**
     * 方向,以正北方向为 0 角度,顺时针方向偏转
     */
    private String direction;
    /**
     * 高程,单位:米
     */
    private String elevation;
    /**
     * 精度
     */
    private String precisions;
    /**
     * 日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date receiveTime;
    /**
     * 创建时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
}
src/main/java/org/springblade/modules/netty/business/mapper/PoliceCarEquipmentMapper.java
New file
@@ -0,0 +1,42 @@
package org.springblade.modules.netty.business.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springblade.modules.netty.business.entity.PoliceCarEquipment;
import org.springblade.modules.netty.business.entity.PoliceCarEquipmentRecord;
/**
 * 对讲设备mapper映射层
 * @author zhongrj
 * @date 2023-03-02
 */
@Mapper
public interface PoliceCarEquipmentMapper {
    /**
     * 新增对讲设备数据
     * @param policeCarEquipment
     */
    void saveTalkBackEquipment(PoliceCarEquipment policeCarEquipment);
    /**
     * 新增对讲设备历史数据
     * @param policeCarEquipmentRecord
     */
    void saveTalkBackEquipmentRecord(PoliceCarEquipmentRecord policeCarEquipmentRecord);
    /**
     * 查询设备信息
     * @param code
     * @return
     */
    PoliceCarEquipment getTalkBackEquipment(@Param("code") String code);
    /**
     * 修改对讲设备信息
     * @param policeCarEquipment
     */
    void updateTalkBackEquipment(PoliceCarEquipment policeCarEquipment);
}
src/main/java/org/springblade/modules/netty/business/mapper/PoliceCarEquipmentMapper.xml
New file
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.netty.business.mapper.PoliceCarEquipmentMapper">
    <!--新增对讲设备信息-->
    <insert id="saveTalkBackEquipment" useGeneratedKeys="true" keyProperty="id">
        insert into sys_police_car_equipment
        (
        name,code,status,terminal_number,longitude,latitude,
        speed,direction,elevation,precisions,receive_time,create_time,update_time
        )
        values
        (
        #{name},#{code},#{status},#{terminalNumber},#{longitude},#{latitude},
        #{speed},#{direction},#{elevation},#{precisions},#{receiveTime},#{createTime},#{updateTime}
        )
    </insert>
    <!--新增对接设备历史记录信息-->
    <insert id="saveTalkBackEquipmentRecord">
        insert into sys_police_car_equipment_record
        (
        police_car_equipment_id,status,terminal_number,
        longitude,latitude,speed,direction,elevation,precisions,receive_time,create_time
        )
        values
        (
        #{policeCarEquipmentId},#{status},#{terminalNumber},
        #{longitude},#{latitude},#{speed},#{direction},#{elevation},#{precisions},#{receiveTime},#{createTime}
        )
    </insert>
    <!--查询设备信息-->
    <select id="getTalkBackEquipment" resultType="org.springblade.modules.netty.business.entity.PoliceCarEquipment">
        select * from sys_police_car_equipment where terminal_number = #{code}
    </select>
    <!--修改对讲设备信息-->
    <update id="updateTalkBackEquipment">
        update sys_police_car_equipment
        set
        code = #{code},
        name = #{name},
        status = #{status},
        <if test="null!=terminalNumber and terminalNumber!=''">
            terminal_number = #{terminalNumber},
        </if>
        <if test="null!=longitude and longitude!=''">
            longitude = #{longitude},
        </if>
        <if test="null!=latitude and latitude!=''">
            latitude = #{latitude},
        </if>
        <if test="null!=speed and speed!=''">
            speed = #{speed},
        </if>
        <if test="null!=direction and direction!=''">
            direction = #{direction},
        </if>
        <if test="null!=elevation and elevation!=''">
            elevation = #{elevation},
        </if>
        <if test="null!=precisions and precisions!=''">
            precisions = #{precisions},
        </if>
        <if test="null!=receiveTime">
            receive_time = #{receiveTime},
        </if>
        update_time = #{updateTime}
        where id = #{id}
    </update>
</mapper>
src/main/java/org/springblade/modules/netty/business/service/PoliceCarEquipmentService.java
New file
@@ -0,0 +1,19 @@
package org.springblade.modules.netty.business.service;
import org.springblade.modules.netty.business.entity.PoliceCarEquipment;
/**
 * 对讲设备信息表 服务类
 *
 * @author zhongrj
 * @date 2023-03-02
 */
public interface PoliceCarEquipmentService {
    /**
     * 保存对讲设备数据
     * @param talkBackEquipment
     */
    void save(PoliceCarEquipment talkBackEquipment);
}
src/main/java/org/springblade/modules/netty/business/service/impl/PoliceCarEquipmentServiceImpl.java
New file
@@ -0,0 +1,60 @@
package org.springblade.modules.netty.business.service.impl;
import org.springblade.modules.netty.business.entity.PoliceCarEquipment;
import org.springblade.modules.netty.business.entity.PoliceCarEquipmentRecord;
import org.springblade.modules.netty.business.mapper.PoliceCarEquipmentMapper;
import org.springblade.modules.netty.business.service.PoliceCarEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
 * 对讲设备服务实现层
 * @author zhongrj
 * @date 2023-03-02
 */
@Service
public class PoliceCarEquipmentServiceImpl implements PoliceCarEquipmentService {
    @Autowired
    private PoliceCarEquipmentMapper policeCarEquipmentMapper;
    /**
     * 保存对讲设备数据
     * @param talkBackEquipment
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(PoliceCarEquipment talkBackEquipment) {
        //判断设备是否已存在,如果存在则更新,不存在则新增
        PoliceCarEquipment backEquipment = policeCarEquipmentMapper.getTalkBackEquipment(talkBackEquipment.getTerminalNumber());
        if (null==backEquipment) {
            talkBackEquipment.setCreateTime(new Date());
            //新增对接设备数据
            policeCarEquipmentMapper.saveTalkBackEquipment(talkBackEquipment);
        }else {
            talkBackEquipment.setId(backEquipment.getId());
            //修改
            policeCarEquipmentMapper.updateTalkBackEquipment(talkBackEquipment);
        }
        //判断是否存在设备id
        if (null != talkBackEquipment.getId()) {
            PoliceCarEquipmentRecord equipmentRecord = new PoliceCarEquipmentRecord();
            equipmentRecord.setPoliceCarEquipmentId(talkBackEquipment.getId());
            equipmentRecord.setStatus(talkBackEquipment.getStatus());
            equipmentRecord.setTerminalNumber(talkBackEquipment.getTerminalNumber());
            equipmentRecord.setLongitude(talkBackEquipment.getLongitude());
            equipmentRecord.setLatitude(talkBackEquipment.getLatitude());
            equipmentRecord.setSpeed(talkBackEquipment.getSpeed());
            equipmentRecord.setDirection(talkBackEquipment.getDirection());
            equipmentRecord.setElevation(talkBackEquipment.getElevation());
            equipmentRecord.setPrecisions(talkBackEquipment.getPrecisions());
            equipmentRecord.setReceiveTime(talkBackEquipment.getReceiveTime());
            equipmentRecord.setCreateTime(new Date());
            //新增记录信息
            policeCarEquipmentMapper.saveTalkBackEquipmentRecord(equipmentRecord);
        }
    }
}
src/main/java/org/springblade/modules/netty/config/MyDecoder.java
New file
@@ -0,0 +1,132 @@
package org.springblade.modules.netty.config;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import org.springframework.stereotype.Component;
import java.util.List;
/**
 * 自定义解析
 */
@Component
public class MyDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
        //创建字节数组,buffer.readableBytes可读字节长度
        byte[] b = new byte[buffer.readableBytes()];
        //复制内容到字节数组b
        buffer.readBytes(b);
        //字节数组转字符串
        String str = new String(b);
        System.out.println(str);
        out.add(bytesToHexString(b));
    }
    public String bytesToHexString(byte[] bArray) {
        StringBuffer sb = new StringBuffer(bArray.length);
        String sTemp;
        for (int i = 0; i < bArray.length; i++) {
            sTemp = Integer.toHexString(0xFF & bArray[i]);
            if (sTemp.length() < 2)
                sb.append(0);
            sb.append(sTemp.toUpperCase());
        }
        return sb.toString();
    }
    public static String toHexString1(byte[] b) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < b.length; ++i) {
            buffer.append(toHexString1(b[i]));
        }
        return buffer.toString();
    }
    public static String toHexString1(byte b) {
        String s = Integer.toHexString(b & 0xFF);
        if (s.length() == 1) {
            return "0" + s;
        } else {
            return s;
        }
    }
    /**
     * 16进制字符串转换为字符串
     *
     * @param s
     * @return
     */
    public static String hexStringToString(String s) {
        if (s == null || s.equals("")) {
            return null;
        }
        s = s.replace(" ", "");
        byte[] baKeyword = new byte[s.length() / 2];
        for (int i = 0; i < baKeyword.length; i++) {
            try {
                baKeyword[i] = (byte) (0xff & Integer.parseInt(
                        s.substring(i * 2, i * 2 + 2), 16));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        try {
            s = new String(baKeyword, "gbk");
            new String();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return s;
    }
    /**
     * Hex字符串转byte
     * @param inHex 待转换的Hex字符串
     * @return  转换后的byte
     */
    public static byte hexToByte(String inHex){
        return (byte) Integer.parseInt(inHex,16);
    }
    /**
     * Hex字符串转byte
     * @param inHex 待转换的Hex字符串
     * @return  转换后的byte
     */
    public static short hexTohort(String inHex){
        return (short) Integer.parseInt(inHex,16);
    }
    /**
     * hex字符串转byte数组
     * @param inHex 待转换的Hex字符串
     * @return  转换后的byte数组结果
     */
    public static byte[] hexToByteArray(String inHex){
        int hexlen = inHex.length();
        byte[] result;
        if (hexlen % 2 == 1){
            //奇数
            hexlen++;
            result = new byte[(hexlen/2)];
            inHex="0"+inHex;
        }else {
            //偶数
            result = new byte[(hexlen/2)];
        }
        int j=0;
        for (int i = 0; i < hexlen; i+=2){
            result[j]=hexToByte(inHex.substring(i,i+2));
            j++;
        }
        return result;
    }
}
src/main/java/org/springblade/modules/netty/config/SysConfig.java
New file
@@ -0,0 +1,26 @@
package org.springblade.modules.netty.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
 * netty 相关配置信息
 * @author zhongrj
 * @date 2023-02-21
 */
@Component
@ConfigurationProperties(prefix="syscfg")
public class SysConfig {
    /**
     * UDP消息接收端口
     */
    private int UdpReceivePort;
    public int getUdpReceivePort() {
        return UdpReceivePort;
    }
    public void setUdpReceivePort(int udpReceivePort) {
        UdpReceivePort = udpReceivePort;
    }
}
src/main/java/org/springblade/modules/netty/event/StartupEvent.java
New file
@@ -0,0 +1,38 @@
package org.springblade.modules.netty.event;
import org.springblade.modules.netty.config.SysConfig;
import org.springblade.modules.netty.server.UdpServer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
/**
 * netty udp 服务启动监听
 * @author zhongrj
 * @date 2023-02-21
 */
@Component
public class StartupEvent implements ApplicationListener<ContextRefreshedEvent> {
    private static ApplicationContext context;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        try {
            context = contextRefreshedEvent.getApplicationContext();
            SysConfig sysConfig = (SysConfig) context.getBean(SysConfig.class);
            //获取 udpServer
            UdpServer udpServer = (UdpServer) StartupEvent.getBean(UdpServer.class);
            //开启
            udpServer.run(sysConfig.getUdpReceivePort());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static Object getBean(Class beanName) {
        return context != null ? context.getBean(beanName) : null;
    }
}
src/main/java/org/springblade/modules/netty/handle/UdpServerHandler.java
New file
@@ -0,0 +1,160 @@
package org.springblade.modules.netty.handle;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;
import io.netty.util.CharsetUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.modules.netty.business.entity.PoliceCarEquipment;
import org.springblade.modules.netty.business.service.PoliceCarEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static org.springblade.modules.netty.config.MyDecoder.hexToByte;
import static org.springblade.modules.netty.config.MyDecoder.hexTohort;
import static org.springblade.modules.netty.util.Hex.getDouble;
import static org.springblade.modules.netty.util.Hex.hexStr2Str;
/**
 * updHandler udp 服务端数据接收处理
 * @author zhongrj
 * @date 2023-02-21
 */
@Component
public class UdpServerHandler extends SimpleChannelInboundHandler<DatagramPacket> {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    private static UdpServerHandler udpServerHandler;
    @Autowired
    private PoliceCarEquipmentService policeCarEquipmentService;
    @PostConstruct
    public void init() {
        udpServerHandler = this;
        udpServerHandler.policeCarEquipmentService = this.policeCarEquipmentService;
    }
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, DatagramPacket datagramPacket) throws Exception {
        // 读取收到的数据
        ByteBuf buf = (ByteBuf) datagramPacket.copy().content();
        byte[] req = new byte[buf.readableBytes()];
        buf.readBytes(req);
        String body = new String(req, CharsetUtil.UTF_8);
        // 字节转16进制字符串
        String s = bytesToHexString(req);
        //获取字符串的长度
        int length = s.length();
//        System.out.println("数据长度>>>>>> = " + length);
        //数据解析
        dataHandler(s);
    }
    /**
     * 数据解析
     * @param s 16位字符串
     */
    private void dataHandler(String s) {
        s = "AAAACCCC220000000033373933343732393100000000000000000000000052D50451F77D5D406C04E275FD723C400000015F0000000507E70306103B0A";
        //创建设备对象
        PoliceCarEquipment backEquipment = new PoliceCarEquipment();
        if (s.substring(4,8).equals("CCCC")) {
            backEquipment.setStatus(1);
        }
        //断开连接
        if (s.substring(4,8).equals("FFFF")) {
            backEquipment.setStatus(0);
        }
        //截取字符串
        backEquipment.setTerminalNumber(hexStr2Str(s.substring(20, 60)));
        backEquipment.setLongitude(Double.toString(getDouble(s.substring(60, 76))));
        backEquipment.setLatitude(Double.toString(getDouble(s.substring(76, 92))));
        backEquipment.setSpeed(Short.toString(hexTohort(s.substring(92, 96))));
        backEquipment.setDirection(Short.toString(hexTohort(s.substring(96, 100))));
        backEquipment.setElevation(Short.toString(hexTohort(s.substring(100, 104))));
        backEquipment.setPrecisions(Short.toString(hexTohort(s.substring(104, 108))));
        String year = Short.toString(hexTohort(s.substring(108, 112)));
        String month = Short.toString(hexToByte(s.substring(112, 114)));
        if (Integer.parseInt(month)<10){
            month = "0" + month;
        }
        String day = Short.toString(hexToByte(s.substring(114, 116)));
        if (Integer.parseInt(day)<10){
            day = "0" + day;
        }
        String hour = Short.toString(hexToByte(s.substring(116, 118)));
        if (Integer.parseInt(hour)<10){
            hour = "0" + hour;
        }
        String minute = Short.toString(hexToByte(s.substring(118, 120)));
        if (Integer.parseInt(minute)<10){
            minute = "0" + minute;
        }
        String second = Short.toString(hexToByte(s.substring(120, 122)));
        if (Integer.parseInt(second)<10){
            second = "0" + second;
        }
        String time = year + "-" + month + "-" + day +" " + hour + ":" + minute + ":" + second;
        //时间拼接
        try {
            backEquipment.setReceiveTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        backEquipment.setUpdateTime(new Date());
        // 新增
        udpServerHandler.policeCarEquipmentService.save(backEquipment);
    }
    /**
     * 转换
     * @param bArray
     * @return
     */
    public String bytesToHexString(byte[] bArray) {
        StringBuffer sb = new StringBuffer(bArray.length);
        String sTemp;
        for (int i = 0; i < bArray.length; i++) {
            sTemp = Integer.toHexString(0xFF & bArray[i]);
            if (sTemp.length() < 2)
                sb.append(0);
            sb.append(sTemp.toUpperCase());
        }
        return sb.toString();
    }
    /**
     * 捕获异常
     * @param ctx
     * @param cause
     * @throws Exception
     */
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)throws Exception {
        logger.error("UdpServerHandler exceptionCaught"+cause.getMessage());
        System.out.println("UdpServerHandler exceptionCaught"+cause.getMessage());
        cause.printStackTrace();
        ctx.close();
    }
    /**
     * 消息没有结束的时候触发
     * @param ctx
     * @throws Exception
     */
    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        ctx.flush();
    }
}
src/main/java/org/springblade/modules/netty/server/UdpServer.java
New file
@@ -0,0 +1,86 @@
package org.springblade.modules.netty.server;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.modules.netty.config.MyDecoder;
import org.springblade.modules.netty.handle.UdpServerHandler;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
/**
 * updServer udp服务端
 *
 * @author zhongrj
 * @date 2023-02-21
 */
@Component
public class UdpServer {
    private static Logger LOG = LoggerFactory.getLogger(UdpServer.class);
    //给管道抽象出接口,给Channel更多的能力和配置,例如Channel的状态,参数,IO操作
    //使用ChannelPipeline实现自定义IO
    //Channel channel;
    @Async("taskExecutor")
    public void run(int port) {
        //启动服务
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        //优化使用的线程
        final EventExecutorGroup group = new DefaultEventExecutorGroup(16);
        try {
            //udp不能使用ServerBootstrap
            Bootstrap b = new Bootstrap();
            //设置UDP通道
            b.group(workerGroup).channel(NioDatagramChannel.class)
                    //设置udp的管道工厂
                    .handler(new ChannelInitializer<NioDatagramChannel>() {
                        //NioDatagramChannel标志着是UDP格式的
                        @Override
                        protected void initChannel(NioDatagramChannel ch)
                                throws Exception {
                            // TODO Auto-generated method stub
                            //创建一个执行Handler的容器
                            ChannelPipeline pipeline = ch.pipeline();
//                            pipeline.addLast(new StringDecoder());
                            pipeline.addLast("decoder",new MyDecoder());
//                            pipeline.addLast(new StringEncoder());
                            pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 4, 4, -8, 0));
                            //执行具体的自定义处理器
                            pipeline.addLast(group, "handler", new UdpServerHandler());
                        }
                    })//初始化处理器
                    //true / false 多播模式(UDP适用),可以向多个主机发送消息
                    .option(ChannelOption.SO_BROADCAST, true)
                    // 设置UDP读缓冲区为2M
                    .option(ChannelOption.SO_RCVBUF, 2048 * 1024)
                    // 设置UDP写缓冲区为1M
                    .option(ChannelOption.SO_SNDBUF, 1024 * 1024);
            // 绑定端口,开始接收进来的连接
            ChannelFuture f = b.bind(port).sync();
            //获取channel通道
            System.out.println("UDP Server 启动,端口:" + port);
            // 等待服务器 socket 关闭 。
            // 这不会发生,可以优雅地关闭服务器。
            f.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            //优雅退出 释放线程池资源
            group.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
src/main/java/org/springblade/modules/netty/util/Hex.java
New file
@@ -0,0 +1,552 @@
package org.springblade.modules.netty.util;
import java.nio.ByteBuffer;
import static org.springblade.modules.netty.config.MyDecoder.hexToByte;
import static org.springblade.modules.netty.config.MyDecoder.hexTohort;
public class Hex {
    /**
     * 用于建立十六进制字符的输出的小写字符数组
     */
    private static final char[] DIGITS_LOWER = {'0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    /**
     * 用于建立十六进制字符的输出的大写字符数组
     */
    private static final char[] DIGITS_UPPER = {'0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
    private static ByteBuffer buffer = ByteBuffer.allocate(8);
    /**
     * 字符串转换成十六进制字符串
     *
     * @param str 待转换的ASCII字符串
     * @return String 每个Byte之间空格分隔,如: [61 6C 6B]
     */
    public static String str2HexStr(String str) {
        char[] chars = "0123456789ABCDEF".toCharArray();
        StringBuilder sb = new StringBuilder("");
        byte[] bs = str.getBytes();
        int bit;
        for (int i = 0; i < bs.length; i++) {
            bit = (bs[i] & 0x0f0) >> 4;
            sb.append(chars[bit]);
            bit = bs[i] & 0x0f;
            sb.append(chars[bit]);
            sb.append(' ');
        }
        return sb.toString().trim();
    }
    /**
     * 十六进制转换字符串
     *
     * @param hexStr Byte字符串(Byte之间无分隔符 如:[616C6B])
     * @return String 对应的字符串
     */
    public static String hexStr2Str(String hexStr) {
        String str = "0123456789ABCDEF";
        char[] hexs = hexStr.toCharArray();
        byte[] bytes = new byte[hexStr.length() / 2];
        int n;
        for (int i = 0; i < bytes.length; i++) {
            n = str.indexOf(hexs[2 * i]) * 16;
            n += str.indexOf(hexs[2 * i + 1]);
            bytes[i] = (byte) (n & 0xff);
        }
        return new String(bytes);
    }
    /**
     * bytes转换成十六进制字符串
     *
     * @param b byte数组
     * @return String 每个Byte值之间空格分隔
     */
    public static String byte2HexStr(byte[] b) {
        String stmp = "";
        StringBuilder sb = new StringBuilder("");
        for (int n = 0; n < b.length; n++) {
            stmp = Integer.toHexString(b[n] & 0xFF);
            sb.append((stmp.length() == 1) ? "0" + stmp : stmp);
//            sb.append(" ");
        }
        return sb.toString().toUpperCase().trim();
    }
    /**
     * bytes字符串转换为Byte值
     *
     * @param src Byte字符串,每个Byte之间没有分隔符
     * @return byte[]
     */
    public static byte[] hexStr2Bytes(String src) {
        int m = 0, n = 0;
        int l = src.length() / 2;
        System.out.println(l);
        byte[] ret = new byte[l];
        for (int i = 0; i < l; i++) {
            m = i * 2 + 1;
            n = m + 1;
            String tmp = "0x" + src.substring(i * 2, m) + src.substring(m, n);
            ret[i] = Byte.decode(tmp);
        }
        return ret;
    }
    /**
     * bytes字符串转换为Byte值
     *
     * @param hexString
     * @return
     */
    public static byte[] hexToBytes(String hexString) {
        if (hexString == null || hexString.equals("")) {
            return null;
        }
        int length = hexString.length() / 2;
        char[] hexChars = hexString.toCharArray();
        byte[] bytes = new byte[length];
//        String hexDigits = "0123456789abcdefABCDEF";
        String hexDigits = "0123456789abcdef";
        for (int i = 0; i < length; i++) {
            int pos = i * 2; // 两个字符对应一个byte
            int h = hexDigits.indexOf(hexChars[pos]) << 4; // 注1
            int l = hexDigits.indexOf(hexChars[pos + 1]); // 注2
            if (h == -1 || l == -1) { // 非16进制字符
                return null;
            }
            bytes[i] = (byte) (h | l);
        }
        return bytes;
    }
    /**
     * String的字符串转换成unicode的String
     *
     * @param strText 全角字符串
     * @return String 每个unicode之间无分隔符
     * @throws Exception
     */
    public static String strToUnicode(String strText) throws Exception {
        char c;
        StringBuilder str = new StringBuilder();
        int intAsc;
        String strHex;
        for (int i = 0; i < strText.length(); i++) {
            c = strText.charAt(i);
            intAsc = (int) c;
            strHex = Integer.toHexString(intAsc);
            if (intAsc > 128)
                str.append("\\u" + strHex);
            else
                // 低位在前面补00
                str.append("\\u00" + strHex);
        }
        return str.toString();
    }
    /**
     * unicode的String转换成String的字符串
     *
     * @param hex 16进制值字符串 (一个unicode为2byte)
     * @return String 全角字符串
     */
    public static String unicodeToString(String hex) {
        int t = hex.length() / 6;
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < t; i++) {
            String s = hex.substring(i * 6, (i + 1) * 6);
            // 高位需要补上00再转
            String s1 = s.substring(2, 4) + "00";
            // 低位直接转
            String s2 = s.substring(4);
            // 将16进制的string转为int
            int n = Integer.valueOf(s1, 16) + Integer.valueOf(s2, 16);
            // 将int转换为字符
            char[] chars = Character.toChars(n);
            str.append(new String(chars));
        }
        return str.toString();
    }
    /**
     * 将字节数组转换为十六进制字符数组
     *
     * @param data byte[]
     * @return 十六进制char[]
     */
    public static char[] encodeHex(byte[] data) {
        return encodeHex(data, true);
    }
    /**
     * 将字节数组转换为十六进制字符数组
     *
     * @param data        byte[]
     * @param toLowerCase <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
     * @return 十六进制char[]
     */
    public static char[] encodeHex(byte[] data, boolean toLowerCase) {
        return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
    }
    /**
     * 将字节数组转换为十六进制字符数组
     *
     * @param data     byte[]
     * @param toDigits 用于控制输出的char[]
     * @return 十六进制char[]
     */
    protected static char[] encodeHex(byte[] data, char[] toDigits) {
        int l = data.length;
        char[] out = new char[l << 1];
        // two characters form the hex value.
        for (int i = 0, j = 0; i < l; i++) {
            out[j++] = toDigits[(0xF0 & data[i]) >>> 4];
            out[j++] = toDigits[0x0F & data[i]];
        }
        return out;
    }
    /**
     * 将字节数组转换为十六进制字符串
     *
     * @param data byte[]
     * @return 十六进制String
     */
    public static String encodeHexStr(byte[] data) {
        return encodeHexStr(data, true);
    }
    /**
     * 将字节数组转换为十六进制字符串
     *
     * @param data        byte[]
     * @param toLowerCase <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
     * @return 十六进制String
     */
    public static String encodeHexStr(byte[] data, boolean toLowerCase) {
        return encodeHexStr(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
    }
    /**
     * 将字节数组转换为十六进制字符串
     *
     * @param data     byte[]
     * @param toDigits 用于控制输出的char[]
     * @return 十六进制String
     */
    protected static String encodeHexStr(byte[] data, char[] toDigits) {
        return new String(encodeHex(data, toDigits));
    }
    /**
     * 将十六进制字符数组转换为字节数组
     *
     * @param data 十六进制char[]
     * @return byte[]
     * @throws RuntimeException 如果源十六进制字符数组是一个奇怪的长度,将抛出运行时异常
     */
    public static byte[] decodeHex(char[] data) {
        int len = data.length;
        if ((len & 0x01) != 0) {
            throw new RuntimeException("Odd number of characters.");
        }
        byte[] out = new byte[len >> 1];
        // two characters form the hex value.
        for (int i = 0, j = 0; j < len; i++) {
            int f = toDigit(data[j], j) << 4;
            j++;
            f = f | toDigit(data[j], j);
            j++;
            out[i] = (byte) (f & 0xFF);
        }
        return out;
    }
    /**
     * 将十六进制字符转换成一个整数
     *
     * @param ch    十六进制char
     * @param index 十六进制字符在字符数组中的位置
     * @return 一个整数
     * @throws RuntimeException 当ch不是一个合法的十六进制字符时,抛出运行时异常
     */
    protected static int toDigit(char ch, int index) {
        int digit = Character.digit(ch, 16);
        if (digit == -1) {
            throw new RuntimeException("Illegal hexadecimal character " + ch
                    + " at index " + index);
        }
        return digit;
    }
    /**
     * float -> byte[]
     *
     * @param data
     * @return
     */
    public static byte[] getBytes(float data) {
        int intBits = Float.floatToIntBits(data);
        return intToByteArray(intBits);
    }
    /**
     * double -> byte[]
     *
     * @param data
     * @return
     */
    public static byte[] getBytes(double data) {
        long longBits = Double.doubleToLongBits(data);
        return longToBytes(longBits);
    }
    /**
     * byte[] -> float
     *
     * @param bytes
     * @return
     */
    public static float getFloat(byte[] bytes) {
        return Float.intBitsToFloat(getInt(bytes));
    }
    public static int getInt(byte[] bytes) {
        return (0xff & bytes[0]) | (0xff00 & (bytes[1] << 8)) | (0xff0000 & (bytes[2] << 16)) | (0xff000000 & (bytes[3] << 24));
    }
    /**
     * byte[] -> double
     *
     * @return
     */
    public static double getDouble(byte[] b) {
        long l;
        l = b[0];
        l &= 0xff;
        l |= ((long) b[1] << 8);
        l &= 0xffff;
        l |= ((long) b[2] << 16);
        l &= 0xffffff;
        l |= ((long) b[3] << 24);
        l &= 0xffffffffL;
        l |= ((long) b[4] << 32);
        l &= 0xffffffffffL;
        l |= ((long) b[5] << 40);
        l &= 0xffffffffffffL;
        l |= ((long) b[6] << 48);
        l &= 0xffffffffffffffL;
        l |= ((long) b[7] << 56);
        return Double.longBitsToDouble(l);
    }
    /**
     * 字节数组字符串 -> double
     *
     * @param bytesStr
     * @return
     */
    public static double getDouble(String bytesStr) {
        byte[] aa = hexToBytes(bytesStr.toLowerCase());
        return getDouble(aa);
    }
    /**
     * 字节数组字符串 -> float
     *
     * @param bytesStr
     * @return
     */
    public static float getFloat(String bytesStr) {
        byte[] aa = hexToBytes(bytesStr.toLowerCase());
        return getFloat(aa);
    }
    /**
     * 16进制字符串 -> byte数组
     */
    public static byte[] str16ToByte(String str16) {
        int len = str16.length();
        if (len % 2 > 0) {
            return null;
        }
        byte res[] = new byte[len / 2];
        for (int i = 0; i < len / 2; i++) {
            String tmp = str16.substring(i*2, (i + 1) * 2);
            byte t[] = hexToBytes(tmp);
            res[i] = t[0];
        }
        return res;
    }
    public static void main(String args[]) throws Exception {
        String aa = "AAAACCCC220000000033373933343732393100000000000000000000000052D50451F77D5D406C04E275FD723C400000015F0000000507E70306103B0A";
        String substring = aa.substring(20, 60);
        String substring1 = aa.substring(60, 76);
        String substring2 = aa.substring(76, 92);
        // 编号
        String a1 = "AAAACCCC2200000000333739333437323931000000000000000000000000";
        // 编号
        String a2 = "3739333437323931000000000000000000000000";
        System.out.println("a2 = " + hexStr2Str(a2));
        //经
        String lng = "52D50451F77D5D40";
        System.out.println("lng = " + getDouble(lng));
        String lat = "6C04E275FD723C40";
        System.out.println("lat = " + getDouble(lat));
        //日
        String str = "0000";
        System.out.println("a = " + hexTohort(str));
        String str1 = "015F";
        System.out.println("b = " + hexTohort(str1));
        //日
        String str2 = "0000";
        System.out.println("c = " + hexTohort(str2));
        String str3 = "0005";
        System.out.println("tr3 = " + hexTohort(str3));
        String nian = "07E7";
        System.out.println("nian = " + hexTohort(nian));
        String yue = "03";
        System.out.println("yue = " + hexToByte(yue));
        String ri = "06";
        System.out.println("ri = " + hexToByte(ri));
        String h = "10";
        System.out.println("h = " + hexToByte(h));
        String f = "3B";
        System.out.println("f = " + hexToByte(f));
        String m = "0A";
        System.out.println("m = " + hexToByte(m));
    }
    public static int toshort(String str) {
        char[] in = str.toCharArray();
        /*
         * for(int i=0;i<in.length;i+=2) { int value= tohx16(in[i]); int value2=
         * tohx16(in[i+1]); int value3=value<<4|value2;
         *
         * System.out.print(value3); }//这里可设计照规则进行转换
         */
        int j = 0;
        for(int i=0;i<in.length;i+=2) {
            int value= tohx16(in[i]);
            int value2=tohx16(in[i+1]);
            j=value<<4|value2;
        }
        return j;
    }
    public static int tohx16(char str) {
        switch (str) {
            case '0':
                return 0;
            case '1':
                return '1';
            case '2':
                return 2;
            case '3':
                return 3;
            case '4':
                return 4;
            case '5':
                return 5;
            case '6':
                return 6;
            case '7':
                return 7;
            case '8':
                return 8;
            case '9':
                return 9;
            case 'a':
            case 'A':
                return 10;
            case 'b':
            case 'B':
                return 11;
            case 'c':
            case 'C':
                return 12;
            case 'd':
            case 'D':
                return 13;
            case 'e':
            case 'E':
                return 14;
            case 'f':
            case 'F':
                return 15;
        }
        return 0;
    }
    public static byte[] intToByteArray(int a) {
        return new byte[]{
                (byte) ((a >> 24) & 0xFF),
                (byte) ((a >> 16) & 0xFF),
                (byte) ((a >> 8) & 0xFF),
                (byte) (a & 0xFF)
        };
    }
    public static byte intToByte(int a) {
        return (byte) (a & 0xFF);
    }
    public static byte[] longToBytes(long x) {
        buffer.putLong(0, x);
        return buffer.array();
    }
}
src/main/java/org/springblade/modules/netty/util/HexStringTool.java
New file
@@ -0,0 +1,303 @@
package org.springblade.modules.netty.util;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
public class HexStringTool {
    private static final char[] HEX_CHAR_ARR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    private static final String HEX_STR = "0123456789abcdef";
    //对字符串,进行分组,转化为List
    public static List<String> getStrList(String str16, int frontLen, int size, int length) {
        List<String> list = new ArrayList<String>();
        String content = str16.substring(frontLen);
        String tem = "";
        for (int index = 0; index < size; index++) {
            tem = content.substring(0, length);
            content = content.substring(length);
            list.add(tem);
        }
        return list;
    }
    //对字符串,进行分组,转化为List(字符串数据类型转化专用)
    public static List<String> getStrList(String str16, int frontLen, int size, int totalLen, int lenLen) {
        List<String> list = new ArrayList<>();
        String content = str16.substring(frontLen);
        String tem = "";
        for (int index = 0; index < size; index++) {
            String len16 = content.substring(totalLen * 2, (totalLen + lenLen) * 2);
            int len = Integer.parseInt(len16, 16);
            int length = (totalLen + lenLen + len) * 2;
            tem = content.substring(0, length);
            content = content.substring(length);
            list.add(tem);
        }
        return list;
    }
    //字符串转换unicode
    public static String string2Unicode(String string) {
        StringBuffer unicode = new StringBuffer();
        for (int i = 0; i < string.length(); i++) {
            // 取出每一个字符
            char c = string.charAt(i);
            // 转换为unicode
            unicode.append("\\u" + Integer.toHexString(c));
        }
        return unicode.toString();
    }
    //字符串转化成为16进制字符串
    public static String strTo16(String s) {
        String str = "";
        for (int i = 0; i < s.length(); i++) {
            int ch = (int) s.charAt(i);
            String s4 = Integer.toHexString(ch);
            str = str + s4;
        }
        return str;
    }
    //16进制转换成为string类型字符串
    public static String hexStringToString(String s) {
        if (s == null || s.equals("")) {
            return null;
        }
        s = s.replace(" ", "");
        byte[] baKeyword = new byte[s.length() / 2];
        for (int i = 0; i < baKeyword.length; i++) {
            try {
                baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        try {
            s = new String(baKeyword, "UTF-8");
            new String();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return s;
    }
    //unicode 转字符串
    public static String unicode2String(String unicode) {
        StringBuffer string = new StringBuffer();
        String[] hex = unicode.split("\\\\u");
        for (int i = 1; i < hex.length; i++) {
            // 转换出每一个代码点
            int data = Integer.parseInt(hex[i], 16);
            // 追加成string
            string.append((char) data);
        }
        return string.toString();
    }
    //字符串转换成为16进制(无需Unicode编码)
    public static String str2HexStr(String str) {
        char[] chars = "0123456789ABCDEF".toCharArray();
        StringBuilder sb = new StringBuilder("");
        byte[] bs = str.getBytes();
        int bit;
        for (int i = 0; i < bs.length; i++) {
            bit = (bs[i] & 0x0f0) >> 4;
            sb.append(chars[bit]);
            bit = bs[i] & 0x0f;
            sb.append(chars[bit]);
            // sb.append(' ');
        }
        return sb.toString().trim();
    }
    //16进制直接转换成为字符串(无需Unicode解码)
    public static String hexStr2Str(String hexStr) {
        String str = "0123456789ABCDEF";
        char[] hexs = hexStr.toCharArray();
        byte[] bytes = new byte[hexStr.length() / 2];
        int n;
        for (int i = 0; i < bytes.length; i++) {
            n = str.indexOf(hexs[2 * i]) * 16;
            n += str.indexOf(hexs[2 * i + 1]);
            bytes[i] = (byte) (n & 0xff);
        }
        return new String(bytes);
    }
    /**
     * int/long转16字节字符串(按所占字节数用0补齐)
     *
     * @param byteLen 所占字节长度
     * @param b       需要转换的数字
     * @return str16
     */
    public static String numToStr16(int byteLen, long b) {
        return String.format("%0" + byteLen * 2 + "x", b);
    }
    /**
     * float/double转16字节字符串(按所占字节数用0补齐)
     *
     * @param byteLen 所占字节长度
     * @param b       需要转换的数字
     * @return str16
     */
    public static String numToStr16(int byteLen, double b) {
        byte[] bytes = Hex.getBytes(b);
        int anInt = Hex.getInt(bytes);
        return String.format("%0" + byteLen * 2 + "x", anInt);
    }
    /**
     * 16进制字符串转字符串(ASCII)
     *
     * @param x16 十六进制字符串
     * @return string
     */
    public static String x16toString(String x16) {
        if (x16 == null || "".equals(x16.trim())) {
            return "";
        }
        String tempStr = "";
        byte[] b = new byte[x16.length() / 2];
        for (int i = 0; i < x16.length() / 2; i++) {
            tempStr = x16.substring(i * 2, i * 2 + 2);
            int temp = Integer.parseInt(tempStr, 16);
            b[i] = (byte) temp;
        }
        return new String(b, StandardCharsets.US_ASCII);
    }
    /**
     * 16进制字符串转字符串(GBK)
     *
     * @param x16 十六进制字符串
     * @return string
     */
    public static String x16toGbk(String x16) {
        byte[] bytes = new byte[x16.length() / 2];
        byte tempByte = 0;
        byte tempHigh = 0;
        byte tempLow = 0;
        for (int i = 0, j = 0; i < x16.length(); i += 2, j++) {
            tempByte = (byte) (((int) x16.charAt(i)) & 0xff);
            if (tempByte >= 48 && tempByte <= 57) {
                tempHigh = (byte) ((tempByte - 48) << 4);
            } else if (tempByte >= 97 && tempByte <= 101) {
                tempHigh = (byte) ((tempByte - 97 + 10) << 4);
            }
            tempByte = (byte) (((int) x16.charAt(i + 1)) & 0xff);
            if (tempByte >= 48 && tempByte <= 57) {
                tempLow = (byte) (tempByte - 48);
            } else if (tempByte >= 97 && tempByte <= 101) {
                tempLow = (byte) (tempByte - 97 + 10);
            }
            bytes[j] = (byte) (tempHigh | tempLow);
        }
        String result = null;
        try {
            result = new String(bytes, "GBK");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }
    public static boolean isChinese(String s) {
        boolean result = false;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
            if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
                    || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                    || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                    || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
                    || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
                    || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
                result = true;
            }
        }
        return result;
    }
    private static String byteArrToHex(byte[] btArr) {
        char[] strArr = new char[btArr.length * 2];
        int i = 0;
        for (byte bt : btArr) {
            strArr[i++] = HEX_CHAR_ARR[bt >>> 4 & 0xf];
            strArr[i++] = HEX_CHAR_ARR[bt & 0xf];
        }
        return new String(strArr);
    }
    private static byte[] hexToByteArr(String hexStr) {
        char[] charArr = hexStr.toCharArray();
        byte[] btArr = new byte[charArr.length / 2];
        int index = 0;
        for (int i = 0; i < charArr.length; i++) {
            int highBit = HEX_STR.indexOf(charArr[i]);
            int lowBit = HEX_STR.indexOf(charArr[++i]);
            btArr[index] = (byte) (highBit << 4 | lowBit);
            index++;
        }
        return btArr;
    }
    /**
     * 字符串转16进制字符串(无汉字utf-8,有汉字gbk)
     *
     * @param str
     * @return
     */
    public static String str2StrHex(String str) {
        boolean chinese = isChinese(str);
        if (chinese) {
            try {
                byte[] bytes1 = str.getBytes(StandardCharsets.UTF_8);
                byte[] bytes2 = new String(bytes1, StandardCharsets.UTF_8).getBytes("gbk");
                String gbk = new String(bytes2, "gbk");
                byte[] gbkArr = gbk.getBytes();
                return byteArrToHex(gbkArr);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return null;
            }
        } else {
            return strTo16(str);
        }
    }
    /**
     * 16进制字符串转字符串(无汉字utf-8,有汉字gbk)
     *
     * @param strHex
     * @return
     */
    public static String strHex2Str(String strHex) {
        byte[] bytes = hexToByteArr(strHex);
        String s1 = new String(bytes, StandardCharsets.UTF_8);
        boolean chinese = isChinese(s1);
        if (!chinese) {
            try {
                return new String(bytes, "gbk");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return null;
            }
        } else {
            return s1;
        }
    }
}
src/main/resources/application-dev.yml
@@ -13,7 +13,7 @@
    #  commandTimeout: 5000
  datasource:
    # MySql
    url: jdbc:mysql://10.141.11.7:3308/srjw?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
    url: jdbc:mysql://10.141.11.7:3308/wvp?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
    username: root
    password: srjw@2023
    # PostgreSQL
@@ -52,3 +52,7 @@
    upload-domain: http://localhost:8999
    remote-path: /usr/share/nginx/html
# 警车udp接收端口
syscfg:
  udpReceivePort: 9989
src/main/resources/application-prod.yml
@@ -38,3 +38,7 @@
    remote-mode: true
    upload-domain: http://localhost:8999
    remote-path: /usr/share/nginx/html
# 警车udp接收端口
syscfg:
  udpReceivePort: 9989
src/main/resources/application-test.yml
@@ -14,9 +14,9 @@
    #  nodes: 127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003
    #  commandTimeout: 5000
  datasource:
    url: jdbc:mysql://106.225.193.35:3306/srjw?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
    url: jdbc:mysql://127.0.0.1:3308/wvp?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
    username: root
    password: HCyj@2022
    password: 123456
#第三方登陆
social:
@@ -38,3 +38,7 @@
    remote-mode: true
    upload-domain: http://localhost:8999
    remote-path: /usr/share/nginx/html
# 警车udp接收端口
syscfg:
  udpReceivePort: 9989
src/test/java/org/springblade/test/BladeTest.java
File was deleted