2023-03-04 16:29:55 +08:00
|
|
|
|
package com.jsowell.netty.handler;
|
|
|
|
|
|
|
|
|
|
|
|
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
|
|
|
|
|
|
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
|
|
|
|
|
import com.jsowell.common.util.BytesUtil;
|
2024-02-21 16:52:56 +08:00
|
|
|
|
import com.jsowell.common.util.DateUtils;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import com.jsowell.common.util.YKCUtils;
|
|
|
|
|
|
import com.jsowell.netty.factory.YKCOperateFactory;
|
|
|
|
|
|
import com.jsowell.pile.domain.OrderBasicInfo;
|
2024-01-06 15:13:50 +08:00
|
|
|
|
import com.jsowell.pile.service.OrderBasicInfoService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 充电结束Handler
|
2023-07-18 13:54:49 +08:00
|
|
|
|
* 0x19
|
2023-03-04 16:29:55 +08:00
|
|
|
|
* GBT-27930 充电桩与 BMS 充电结束阶段报文
|
|
|
|
|
|
* @author JS-ZZA
|
|
|
|
|
|
* @date 2022/9/19 13:27
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
|
@Component
|
|
|
|
|
|
public class ChargeEndHandler extends AbstractHandler{
|
|
|
|
|
|
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGE_END_CODE.getBytes());
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2024-01-06 15:13:50 +08:00
|
|
|
|
private OrderBasicInfoService orderBasicInfoService;
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void afterPropertiesSet() throws Exception {
|
|
|
|
|
|
YKCOperateFactory.register(type, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) {
|
2023-11-14 11:29:55 +08:00
|
|
|
|
// log.info("[===执行充电结束逻辑===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString());
|
2023-03-04 16:29:55 +08:00
|
|
|
|
// 消息体
|
|
|
|
|
|
byte[] msgBody = ykcDataProtocol.getMsgBody();
|
|
|
|
|
|
|
|
|
|
|
|
int startIndex = 0;
|
|
|
|
|
|
int length = 16;
|
|
|
|
|
|
|
|
|
|
|
|
// 交易流水号
|
|
|
|
|
|
byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
2023-03-13 16:22:54 +08:00
|
|
|
|
String transactionCode = BytesUtil.bcd2Str(serialNumByteArr);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
// 桩编码
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
length = 7;
|
|
|
|
|
|
byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
|
|
|
|
|
|
|
|
|
|
|
|
// 保存时间
|
2023-12-07 16:19:47 +08:00
|
|
|
|
saveLastTimeAndCheckChannel(pileSn, channel);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
|
|
|
|
|
|
// 枪号
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
length = 1;
|
|
|
|
|
|
byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr);
|
|
|
|
|
|
|
|
|
|
|
|
// BMS中止荷电状态 SOC 1%/位, 0%偏移量; 数据范围: 0~100%
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
byte[] BMSStopChargingSOC = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
String stopSoc = BytesUtil.binary(BMSStopChargingSOC, 10);
|
|
|
|
|
|
|
|
|
|
|
|
// BMS 动力蓄电池单体最低电压 0.01 V/位, 0 V 偏移量;数据范围: 0 ~24 V
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
length = 2;
|
|
|
|
|
|
byte[] BMSBatteryMinVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
|
|
// BMS 动力蓄电池单体最高电压 0.01 V/位, 0 V 偏移量;数据范围: 0 ~24 V
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
byte[] BMSBatteryMaxVoltageByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
|
|
// BMS 动力蓄电池最低温度 1ºC/位, -50 ºC 偏移量;数据范围: -50 ºC ~+200 ºC
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
length = 1;
|
|
|
|
|
|
byte[] BMSBatteryMinTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
|
|
// BMS 动力蓄电池最高温度 1ºC/位, -50 ºC 偏移量;数据范围: -50 ºC ~+200 ºC
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
byte[] BMSBatteryMaxTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
|
|
// 电桩累计充电时间 1 min/位, 0 min 偏移量; 数据范围: 0~600 min
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
length = 2;
|
|
|
|
|
|
byte[] pileSumChargingTimeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
|
|
// 电桩输出能量 0.1 kWh/位, 0 kWh 偏移量; 数据范围: 0~1000 kWh
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
byte[] pileOutputEnergyByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
|
|
// 电桩充电机编号 充电机编号, 1/位, 1偏移量 ,数据范围 : 0 ~ 0xFFFFFFFF
|
|
|
|
|
|
startIndex += length;
|
|
|
|
|
|
length = 4;
|
|
|
|
|
|
byte[] pileChargedCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
|
|
|
|
|
|
|
|
|
|
|
// 查询订单,改为待结算 将结束soc传入
|
2023-03-13 16:22:54 +08:00
|
|
|
|
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
if (Objects.nonNull(orderInfo)) {
|
2024-02-21 16:52:56 +08:00
|
|
|
|
Date nowDate = DateUtils.getNowDate(); // 当前时间
|
2024-02-21 16:56:14 +08:00
|
|
|
|
// if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) {
|
|
|
|
|
|
// orderInfo.setOrderStatus(OrderStatusEnum.STAY_SETTLEMENT.getValue());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// orderInfo.setEndSoc(stopSoc);
|
|
|
|
|
|
// if (orderInfo.getChargeEndTime() == null) {
|
|
|
|
|
|
// orderInfo.setChargeEndTime(nowDate); // 结束充电时间
|
|
|
|
|
|
// }
|
2024-02-21 16:52:56 +08:00
|
|
|
|
// orderBasicInfoService.updateOrderBasicInfo(orderInfo);
|
|
|
|
|
|
|
|
|
|
|
|
// 只更新个别字段
|
|
|
|
|
|
OrderBasicInfo updateOrder = new OrderBasicInfo();
|
|
|
|
|
|
updateOrder.setId(orderInfo.getId());
|
|
|
|
|
|
updateOrder.setEndSoc(stopSoc);
|
|
|
|
|
|
if (orderInfo.getChargeEndTime() == null) {
|
|
|
|
|
|
updateOrder.setChargeEndTime(nowDate); // 结束充电时间
|
|
|
|
|
|
}
|
|
|
|
|
|
updateOrder.setUpdateTime(nowDate);
|
|
|
|
|
|
orderBasicInfoService.updateOrderBasicInfo(updateOrder);
|
2023-03-04 16:29:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|