package com.fzzy.igds.quantity.util;
|
|
import com.alibaba.fastjson.JSON;
|
import com.fzzy.igds.constant.RedisConst;
|
import com.fzzy.igds.quantity.dto.IoMessage;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.RandomUtils;
|
|
/**
|
* @Description
|
* @Author CZT
|
* @Date 2026/01/08 16:36
|
*/
|
@Slf4j
|
public class ServerUtils {
|
|
|
public static final String VERSION_1 = "v1.0";
|
|
|
public static final String SIGN_DEFAULT = "0000";
|
|
public static final String CHARSET = "UTF-8";
|
public static final String MSG_BEGIN = "<BHZN>";
|
public static final String MSG_END = "<END>";
|
|
//功能码
|
public static final String FUNCTION_1001 = "1001";// 基础参数配置
|
public static final String FUNCTION_2001 = "2001";// 开始检测
|
public static final String FUNCTION_2002 = "2002";// 停止检测
|
public static final String FUNCTION_2003 = "2003";// 进度查询
|
public static final String FUNCTION_2004 = "2004";// 结果上报
|
public static final String FUNCTION_2005 = "2005";// 坐标提取
|
public static final String FUNCTION_2006 = "2006";// 远程抓拍
|
public static final String FUNCTION_2007 = "2007";// 心跳维持
|
public static final String FUNCTION_1002 = "1002";// 时间同步
|
public static final String FUNCTION_1003 = "1003";// 设备登陆
|
|
|
//响应码
|
public static String RESP_0 = "0";// 成功
|
public static String RESP_1 = "1";// 命令格式错误
|
public static String RESP_2 = "2";// 命令数据检验异常
|
public static String RESP_3 = "3";// 发送超时错误
|
public static String RESP_4 = "4";// 终端设备不在线
|
public static String RESP_5 = "5";// 终端设备执行中
|
public static String RESP_6 = "6";// 终端设备抓拍失败
|
public static String RESP_9 = "9";// 其它错误
|
|
/**
|
* 生成TCP连接的KEY
|
*
|
* @param ip
|
* @param port
|
* @return
|
*/
|
public static String getServerKey(String ip, Integer port) {
|
return ip + ":" + port;
|
}
|
|
/**
|
* @param message
|
* @return
|
*/
|
public static IoMessage buildMessage(String message) throws Exception {
|
IoMessage ioMessage = JSON.parseObject(message, IoMessage.class);
|
return ioMessage;
|
}
|
|
public static String buildRequestKey(String companyId, String sn) {
|
return RedisConst.buildKey(companyId, sn);
|
}
|
|
public static String createOrderId() {
|
return RandomUtils.nextInt(1000, 9999) + "";
|
}
|
}
|