羽信主板修改预约时间

This commit is contained in:
Guoqs
2026-06-18 14:22:06 +08:00
parent a8a5f45815
commit 3726037886

View File

@@ -9,11 +9,14 @@ import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.page.PageResponse;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.DelFlagEnum;
import com.jsowell.common.enums.ykc.PileMainboardManufacturerEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.PileProgramVersionUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.PileMemberRelation;
import com.jsowell.pile.domain.PileReservationInfo;
import com.jsowell.pile.domain.ykcCommond.ReservationChargingCommand;
@@ -164,12 +167,20 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic
}
private void sendReservationCommandAndAssertSuccess(PileReservationInfo pileReservationInfo, String memberId, String operation) {
if (!sendReservationCommand(pileReservationInfo, memberId, operation)) {
throwReservationCommandFailed();
}
}
private boolean sendReservationCommand(PileReservationInfo pileReservationInfo, String memberId, String operation) {
ReservationChargingCommand command = buildReservationChargingCommand(pileReservationInfo, memberId, operation);
String result = pileRemoteService.reservationCharging(command);
if (!StringUtils.equals(result, Constants.ONE)) {
throw new BusinessException(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_ERROR.getValue(),
ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_ERROR.getLabel() + ": 充电桩返回修改失败");
}
return StringUtils.equals(result, Constants.ONE);
}
private void throwReservationCommandFailed() {
throw new BusinessException(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_ERROR.getValue(),
ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_ERROR.getLabel() + ": 充电桩返回修改失败");
}
private ReservationChargingCommand buildReservationChargingCommand(PileReservationInfo pileReservationInfo, String memberId, String operation) {
@@ -294,7 +305,8 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic
@Override
public int createReservation(CreateReservedDTO dto) {
PileReservationInfo reservedInfo = selectByPileConnectorCode(dto.getPileConnectorCode());
boolean activeBeforeUpdate = reservedInfo != null && StringUtils.equals(reservedInfo.getStatus(), Constants.ONE);
PileReservationInfo oldReservationInfo = reservedInfo == null ? null : copyReservationInfo(reservedInfo);
boolean activeBeforeUpdate = oldReservationInfo != null && StringUtils.equals(oldReservationInfo.getStatus(), Constants.ONE);
if (reservedInfo == null) {
reservedInfo = new PileReservationInfo();
reservedInfo.setCreateBy(dto.getMemberId());
@@ -329,7 +341,13 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic
reservedInfo.getStartTime(), reservedInfo.getEndTime(), reservedInfo.getId())) {
throw new BusinessException(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_REFUSED);
}
sendReservationCommandAndAssertSuccess(reservedInfo, dto.getMemberId(), activeBeforeUpdate ? "03" : "01");
if (activeBeforeUpdate && isYuxinMainboard(reservedInfo.getPileSn())) {
if (!replaceYuxinReservation(dto.getMemberId(), oldReservationInfo, reservedInfo)) {
throwReservationCommandFailed();
}
} else {
sendReservationCommandAndAssertSuccess(reservedInfo, dto.getMemberId(), activeBeforeUpdate ? "03" : "01");
}
this.insertOrUpdateSelective(reservedInfo);
return reservedInfo.getId();
}
@@ -390,6 +408,7 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic
if (pileReservationInfo == null) {
return 0;
}
PileReservationInfo oldReservationInfo = copyReservationInfo(pileReservationInfo);
String redisKey = CacheConstants.UPDATE_RESERVATION_INFO + pileReservationInfo.getPileConnectorCode();
@@ -407,17 +426,21 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic
// 操作 0x01:启动 0x02:取消 0x03:修改
String operation = "03";
boolean modifyReservationSetting = false;
if (StringUtils.isNotBlank(dto.getStartTime())) {
pileReservationInfo.setStartTime(Time.valueOf(dto.getStartTime()));
operation = "03";
modifyReservationSetting = true;
}
if (StringUtils.isNotBlank(dto.getEndTime())) {
pileReservationInfo.setEndTime(Time.valueOf(dto.getEndTime()));
operation = "03";
modifyReservationSetting = true;
}
if (StringUtils.isNotBlank(dto.getVerifyIdentity())) {
pileReservationInfo.setVerifyIdentity(dto.getVerifyIdentity());
operation = "03";
modifyReservationSetting = true;
}
if (StringUtils.isNotBlank(dto.getStatus())) {
pileReservationInfo.setStatus(dto.getStatus());
@@ -437,37 +460,11 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic
发送指令
*/
if (sendFlag) {
// 查询会员的绑定vin列表 2024年7月30日11点04分 以当前请求会员的VIN为准
List<MemberPlateNumberVO> plateNumberVOList = memberPlateNumberRelationService.selectMemberPlateNumberRelation(dto.getMemberId());
List<String> vinCodes = Lists.newArrayList();
int count = 0;
for (MemberPlateNumberVO vo : plateNumberVOList) {
if (count < 3 && StringUtils.isNotBlank(vo.getVinCode())) {
vinCodes.add(vo.getVinCode());
count++;
}
if (shouldReplaceYuxinReservation(operation, modifyReservationSetting, oldReservationInfo, pileReservationInfo.getPileSn())) {
sendResult = replaceYuxinReservation(dto.getMemberId(), oldReservationInfo, pileReservationInfo);
} else {
sendResult = sendReservationCommand(pileReservationInfo, dto.getMemberId(), operation);
}
// 如果 vinCodes 的数量少于 3用 "0" 补足
while (vinCodes.size() < 3) {
vinCodes.add("");
}
String type = StringUtils.equals(pileReservationInfo.getReservationType(), "single") ? "00" : "01";
ReservationChargingCommand command = ReservationChargingCommand.builder()
.transactionCode(Constants.ILLEGAL_TRANSACTION_CODE)
.pileSn(pileReservationInfo.getPileSn())
.connectorCode(pileReservationInfo.getPileConnectorCode().replace(pileReservationInfo.getPileSn(), ""))
.operation(operation)
.reservationType(type)
.verifyIdentity(pileReservationInfo.getVerifyIdentity())
.vin1(vinCodes.get(0))
.vin2(vinCodes.get(1))
.vin3(vinCodes.get(2))
.reservedStartTime(pileReservationInfo.getStartTime().toLocalTime())
.reservedEndTime(pileReservationInfo.getEndTime().toLocalTime())
.amount(Constants.WHITELIST_DEFAULT_AMOUNT)
.build();
String result = pileRemoteService.reservationCharging(command);
sendResult = StringUtils.equals(result, Constants.ONE);
// 设置缓存1分钟, 如果更新数据库就删掉, 如果没有更新数据量缓存70秒
redisCache.setCacheObject(redisKey, JSON.toJSONString(pileReservationInfo), CacheConstants.cache_expire_time_70s);
@@ -483,6 +480,69 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic
return 0;
}
private boolean shouldReplaceYuxinReservation(String operation, boolean modifyReservationSetting,
PileReservationInfo oldReservationInfo, String pileSn) {
if (!modifyReservationSetting || !isYuxinMainboard(pileSn)) {
return false;
}
if (StringUtils.equals(operation, "03")) {
return true;
}
return StringUtils.equals(operation, "01")
&& oldReservationInfo != null
&& StringUtils.equals(oldReservationInfo.getStatus(), Constants.ONE);
}
private boolean replaceYuxinReservation(String memberId, PileReservationInfo oldReservationInfo, PileReservationInfo newReservationInfo) {
if (!sendReservationCommand(oldReservationInfo, memberId, "02")) {
return false;
}
if (sendReservationCommand(newReservationInfo, memberId, "01")) {
return true;
}
try {
if (!sendReservationCommand(oldReservationInfo, memberId, "01")) {
log.error("羽信主板修改预约失败后恢复旧预约失败, reservedId:{}, pileConnectorCode:{}",
oldReservationInfo.getId(), oldReservationInfo.getPileConnectorCode());
}
} catch (Exception e) {
log.error("羽信主板修改预约失败后恢复旧预约异常, reservedId:{}, pileConnectorCode:{}",
oldReservationInfo.getId(), oldReservationInfo.getPileConnectorCode(), e);
}
return false;
}
private boolean isYuxinMainboard(String pileSn) {
try {
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
String programVersion = pileBasicInfo == null ? null : pileBasicInfo.getProgramVersion();
return PileProgramVersionUtils.getMainboardManufacturer(programVersion) == PileMainboardManufacturerEnum.YUXIN;
} catch (Exception e) {
log.warn("判断羽信主板失败, pileSn:{}", pileSn, e);
return false;
}
}
private PileReservationInfo copyReservationInfo(PileReservationInfo source) {
PileReservationInfo target = new PileReservationInfo();
target.setId(source.getId());
target.setMemberId(source.getMemberId());
target.setPileSn(source.getPileSn());
target.setPileConnectorCode(source.getPileConnectorCode());
target.setStatus(source.getStatus());
target.setReservationType(source.getReservationType());
target.setVerifyIdentity(source.getVerifyIdentity());
target.setStartTime(source.getStartTime());
target.setEndTime(source.getEndTime());
target.setFreq(source.getFreq());
target.setCreateBy(source.getCreateBy());
target.setCreateTime(source.getCreateTime());
target.setUpdateBy(source.getUpdateBy());
target.setUpdateTime(source.getUpdateTime());
target.setDelFlag(source.getDelFlag());
return target;
}
/**
* 个人桩停止充电
* @param dto