mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
update 重构
This commit is contained in:
@@ -58,8 +58,8 @@ public class YKCBusinessServiceImpl implements YKCBusinessService {
|
||||
// 获取帧类型
|
||||
String frameType = YKCUtils.frameType2Str(ykcDataProtocol.getFrameType());
|
||||
// 获取业务处理handler
|
||||
AbstractYkcHandler invokeStrategy = YKCOperateFactory.getInvokeStrategy(frameType);
|
||||
// AbstractYkcHandlerV2 invokeStrategy = ykcOperateFactoryV2.getInvokeStrategy(frameType);
|
||||
// AbstractYkcHandler invokeStrategy = YKCOperateFactory.getInvokeStrategy(frameType);
|
||||
AbstractYkcStrategy invokeStrategy = ykcOperateFactoryV2.getInvokeStrategy(frameType);
|
||||
return invokeStrategy.supplyProcess(ykcDataProtocol, ctx);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.primitives.Bytes;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
|
||||
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
||||
import com.jsowell.common.core.domain.ykc.device2platform.Data0x03;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.netty.factory.YKCOperateFactoryV2;
|
||||
@@ -33,42 +34,19 @@ public class HeartbeatRequestStrategy implements AbstractYkcStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext channel) {
|
||||
// log.info("[===充电桩心跳包===] param:{}, channel:{}", JSON.toJSONString(ykcDataProtocol), channel.toString());
|
||||
// 获取消息体
|
||||
byte[] msgBody = ykcDataProtocol.getMsgBody();
|
||||
|
||||
int startIndex = 0;
|
||||
int length = 7;
|
||||
|
||||
// 桩号
|
||||
byte[] pileSnByte = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String pileSn = BytesUtil.binary(pileSnByte, 16);
|
||||
|
||||
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext ctx) {
|
||||
Data0x03 data0x03 = new Data0x03(ykcDataProtocol.getBytes());
|
||||
data0x03.setChannelId(ctx.channel().id());
|
||||
log.info("Data0x03:{}, ", data0x03);
|
||||
String pileSn = data0x03.getPileSn();
|
||||
String connectorCode = data0x03.getConnectorCode();
|
||||
String connectorStatus = data0x03.getConnectorStatus();
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(pileSn, channel);
|
||||
|
||||
// 校验channel
|
||||
// PileChannelEntity.checkChannel(pileSn, channel);
|
||||
|
||||
// 枪号
|
||||
startIndex += length;
|
||||
length = 1;
|
||||
byte[] pileConnectorNumByte = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String pileConnectorNum = String.format("%02d", Integer.parseInt(BytesUtil.binary(pileConnectorNumByte, 16)));
|
||||
|
||||
//枪状态(不回复)
|
||||
startIndex += length;
|
||||
length = 1;
|
||||
byte[] connectorStatusByte = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String connectorStatus = BytesUtil.binary(connectorStatusByte, 16);
|
||||
// log.info("桩号:{}, 枪号:{}, 枪状态:{}", pileSn, pileConnectorNum, connectorStatus);
|
||||
|
||||
// updateStatus(pileSn, pileConnectorNum, connectorStatus);
|
||||
saveLastTimeAndCheckChannel(pileSn, ctx);
|
||||
|
||||
// 公共方法修改状态
|
||||
try {
|
||||
pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, pileConnectorNum, connectorStatus, null);
|
||||
pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, connectorCode, connectorStatus, null);
|
||||
} catch (Exception e) {
|
||||
log.error("公共方法修改状态error", e);
|
||||
}
|
||||
@@ -77,7 +55,7 @@ public class HeartbeatRequestStrategy implements AbstractYkcStrategy {
|
||||
byte[] flag = Constants.zeroByteArray;
|
||||
|
||||
// 消息体
|
||||
byte[] messageBody = Bytes.concat(pileSnByte, pileConnectorNumByte, flag);
|
||||
byte[] messageBody = Bytes.concat(YKCUtils.getPileSnBytes(pileSn), YKCUtils.getPileSnBytes(connectorCode), flag);
|
||||
return YKCUtils.getResult(ykcDataProtocol, messageBody);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.jsowell.common.annotation.CostTime;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.domain.ykc.LoginRequestData;
|
||||
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
|
||||
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
||||
import com.jsowell.common.core.domain.ykc.device2platform.Data0x01;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
@@ -29,7 +29,6 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@@ -127,74 +126,18 @@ public class LoginStrategy implements AbstractYkcStrategy {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取消息体
|
||||
byte[] msgBody = ykcDataProtocol.getMsgBody();
|
||||
Data0x01 data0x01 = new Data0x01(ykcDataProtocol.getBytes());
|
||||
data0x01.setChannelId(ctx.channel().id());
|
||||
log.info("data0x01:{}", data0x01);
|
||||
|
||||
int startIndex = 0;
|
||||
int length = 7;
|
||||
|
||||
// 桩编码
|
||||
byte[] pileSnByte = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String pileSn = BytesUtil.binary(pileSnByte, 16);
|
||||
// *********************** 字段解析完成,下面进行逻辑处理 *********************** //
|
||||
String pileSn = data0x01.getPileSn();
|
||||
String iccid = data0x01.getIccid();
|
||||
String internetConnection = data0x01.getInternetConnection();
|
||||
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(pileSn, ctx);
|
||||
|
||||
// 桩类型 0 表示直流桩, 1 表示交流桩
|
||||
startIndex += length;
|
||||
length = 1;
|
||||
byte[] pileTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String pileType = BytesUtil.bcd2Str(pileTypeByteArr);
|
||||
|
||||
// 充电枪数量
|
||||
startIndex += length;
|
||||
byte[] connectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String connectorNum = BytesUtil.bcd2Str(connectorNumByteArr);
|
||||
|
||||
// 通信协议版本 版本号乘 10,v1.0 表示 0x0A
|
||||
startIndex += length;
|
||||
byte[] communicationVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
BigDecimal bigDecimal = new BigDecimal(BytesUtil.bcd2Str(communicationVersionByteArr));
|
||||
BigDecimal communicationVersionTemp = bigDecimal.divide(new BigDecimal(10));
|
||||
String communicationVersion = "v" + communicationVersionTemp;
|
||||
|
||||
// 程序版本
|
||||
startIndex += length;
|
||||
length = 8;
|
||||
byte[] programVersionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String programVersion = BytesUtil.ascii2Str(programVersionByteArr);
|
||||
// log.info("程序版本:{} length:{}", programVersion, programVersion.length());
|
||||
|
||||
// 网络连接类型 0x00 SIM 卡 0x01 LAN 0x02 WAN 0x03 其他
|
||||
startIndex += length;
|
||||
length = 1;
|
||||
byte[] internetConnectionTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String internetConnection = BytesUtil.bcd2Str(internetConnectionTypeByteArr);
|
||||
|
||||
// sim卡
|
||||
startIndex += length;
|
||||
length = 10;
|
||||
byte[] simCardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String iccid = BytesUtil.bin2HexStr(simCardNumByteArr);
|
||||
|
||||
// 运营商 0x00 移动 0x02 电信 0x03 联通 0x04 其他
|
||||
startIndex += length;
|
||||
length = 1;
|
||||
byte[] businessTypeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String business = BytesUtil.bcd2Str(businessTypeByteArr);
|
||||
|
||||
// *********************** 字段解析完成,下面进行逻辑处理 *********************** //
|
||||
LoginRequestData loginRequestData = LoginRequestData.builder()
|
||||
.pileSn(pileSn)
|
||||
.pileType(pileType)
|
||||
.connectorNum(connectorNum)
|
||||
.communicationVersion(communicationVersion)
|
||||
.programVersion(programVersion)
|
||||
.internetConnection(internetConnection)
|
||||
.iccid(iccid)
|
||||
.business(business)
|
||||
.build();
|
||||
|
||||
// 结果(默认 0x01:登录失败)
|
||||
byte[] flag = Constants.oneByteArray;
|
||||
|
||||
@@ -274,7 +217,7 @@ public class LoginStrategy implements AbstractYkcStrategy {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
// 保存报文 没有登录认证通过还要不要保存报文?
|
||||
try {
|
||||
String jsonMsg = JSON.toJSONString(loginRequestData);
|
||||
String jsonMsg = JSON.toJSONString(data0x01);
|
||||
pileMsgRecordService.save(pileSn, pileSn, type, jsonMsg, ykcDataProtocol.getHEXString());
|
||||
} catch (Exception e) {
|
||||
log.error("保存报文失败pileSn:{}", pileSn, e);
|
||||
@@ -282,7 +225,7 @@ public class LoginStrategy implements AbstractYkcStrategy {
|
||||
}, executor);
|
||||
|
||||
// 消息体
|
||||
byte[] messageBody = Bytes.concat(pileSnByte, flag);
|
||||
byte[] messageBody = Bytes.concat(YKCUtils.getPileSnBytes(pileSn), flag);
|
||||
return YKCUtils.getResult(ykcDataProtocol, messageBody);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user