2023-03-04 16:29:55 +08:00
|
|
|
|
package com.jsowell.netty.handler;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
|
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
|
|
|
|
|
|
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
2023-08-18 12:02:34 +08:00
|
|
|
|
import com.jsowell.common.enums.uniapp.OccupyOrderStatusEnum;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.common.util.BytesUtil;
|
2023-08-18 11:40:23 +08:00
|
|
|
|
import com.jsowell.common.util.DateUtils;
|
|
|
|
|
|
import com.jsowell.common.util.StringUtils;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.common.util.YKCUtils;
|
|
|
|
|
|
import com.jsowell.netty.factory.YKCOperateFactory;
|
2023-08-18 11:40:23 +08:00
|
|
|
|
import com.jsowell.pile.domain.OrderPileOccupy;
|
|
|
|
|
|
import com.jsowell.pile.service.OrderPileOccupyService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2023-08-18 11:40:23 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
2023-08-18 11:40:23 +08:00
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 充电桩返回遥控地锁升锁与降锁数据(上行)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author JS-ZZA
|
|
|
|
|
|
* @date 2022/9/27 13:21
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
|
@Component
|
|
|
|
|
|
public class RemoteControlGroundLockResponseHandler extends AbstractHandler{
|
2023-08-18 11:40:23 +08:00
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private OrderPileOccupyService orderPileOccupyService;
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_PILE_RESPOND_GROUND_LOCK_LIFTING_CODE.getBytes());
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void afterPropertiesSet() throws Exception {
|
|
|
|
|
|
YKCOperateFactory.register(type, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) {
|
|
|
|
|
|
log.info("[===充电桩返回遥控地锁升锁与降锁数据(上行)===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString());
|
|
|
|
|
|
// 消息体
|
|
|
|
|
|
byte[] msgBody = ykcDataProtocol.getMsgBody();
|
|
|
|
|
|
|
|
|
|
|
|
int startIndex = 0;
|
|
|
|
|
|
int length = 7;
|
|
|
|
|
|
// 桩编号
|
|
|
|
|
|
byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
2023-08-10 09:40:20 +08:00
|
|
|
|
String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
// 枪号
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
length = 1;
|
|
|
|
|
|
byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
2023-08-10 09:40:20 +08:00
|
|
|
|
String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
2023-08-18 14:21:12 +08:00
|
|
|
|
// 升/降地锁标识 升锁 0X55,降锁 0XFF
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
byte[] raiseLowMarkingByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
String raiseLowMarking = BytesUtil.bin2HexStr(raiseLowMarkingByteArr);
|
|
|
|
|
|
|
2023-03-04 16:29:55 +08:00
|
|
|
|
// 地锁控制返回标志 布尔型( 1, 鉴权成功; 0, 鉴权失败)
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
byte[] controlResultByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
2023-08-10 09:40:20 +08:00
|
|
|
|
String controlResult = BytesUtil.bcd2Str(controlResultByteArr);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
// 预留位
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
length = 4;
|
|
|
|
|
|
byte[] waitingUseByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
2023-08-18 14:21:12 +08:00
|
|
|
|
log.info("===充电桩返回遥控地锁升锁与降锁数据(上行)=== result: 桩编号:{}, 枪号:{}, 升/降地锁标识:{}, 地锁控制返回标志:( 1, 鉴权成功; 0, 鉴权失败){}",
|
|
|
|
|
|
pileSn, connectorCode,raiseLowMarking, controlResult);
|
2023-08-18 11:40:23 +08:00
|
|
|
|
|
|
|
|
|
|
if (StringUtils.equals(controlResult, "01")) {
|
|
|
|
|
|
// 鉴权成功
|
2023-08-18 14:23:04 +08:00
|
|
|
|
lowerTheGroundLock(pileSn, connectorCode);
|
2023-08-18 11:40:23 +08:00
|
|
|
|
}
|
2023-08-18 12:02:34 +08:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 降锁成功的时候调用
|
2023-08-18 14:23:04 +08:00
|
|
|
|
* lowerTheGroundLock
|
|
|
|
|
|
* raiseTheGroundLock
|
2023-08-18 12:02:34 +08:00
|
|
|
|
* @param pileSn
|
|
|
|
|
|
* @param connectorCode
|
|
|
|
|
|
*/
|
2023-08-18 14:23:04 +08:00
|
|
|
|
private void lowerTheGroundLock(String pileSn, String connectorCode) {
|
|
|
|
|
|
// 查出占桩订单 草稿单 ,将开始时间set进订单信息
|
2023-08-18 11:40:23 +08:00
|
|
|
|
OrderPileOccupy orderInfo = orderPileOccupyService.getOrderInfoByPile(pileSn, connectorCode);
|
2023-08-18 12:02:34 +08:00
|
|
|
|
|
2023-08-18 11:40:23 +08:00
|
|
|
|
if (orderInfo == null) {
|
2023-08-18 12:02:34 +08:00
|
|
|
|
return;
|
2023-08-18 11:40:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (Objects.isNull(orderInfo.getStartTime())) {
|
2023-08-18 12:02:34 +08:00
|
|
|
|
orderInfo.setStatus(OccupyOrderStatusEnum.OCCUPIED.getValue());
|
2023-08-18 11:40:23 +08:00
|
|
|
|
orderInfo.setStartTime(DateUtils.getNowDate());
|
|
|
|
|
|
// 修改数据库
|
|
|
|
|
|
orderPileOccupyService.updateByPrimaryKey(orderInfo);
|
|
|
|
|
|
}
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
2023-08-18 14:23:04 +08:00
|
|
|
|
|
|
|
|
|
|
private void raiseTheGroundLock(String pileSn, String connectorCode) {
|
|
|
|
|
|
orderPileOccupyService.stopOccupyPileOrder(pileSn, connectorCode);
|
|
|
|
|
|
}
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|