From 74283d5ab08d7040f92e4345f2d759b16a2f3d82 Mon Sep 17 00:00:00 2001 From: Guoqs <123@jsowell.com> Date: Mon, 1 Jul 2024 09:56:47 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BF=AE=E6=94=B9=E5=85=85=E7=94=B5?= =?UTF-8?q?=E6=A1=A9=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jsowell/common/util/DateUtils.java | 7 +++ .../ReservationChargingCommand.java | 40 +++++++++--- .../pile/service/PileBasicInfoService.java | 4 +- .../service/SettleOrderReportService.java | 2 +- .../impl/OrderBasicInfoServiceImpl.java | 28 ++++----- .../impl/PileBasicInfoServiceImpl.java | 22 ------- .../impl/PileReservationInfoServiceImpl.java | 14 +++-- .../impl/SettleOrderReportServiceImpl.java | 61 ++++++++++--------- .../impl/YKCPushCommandServiceImpl.java | 37 +++++++++-- 9 files changed, 133 insertions(+), 82 deletions(-) diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/DateUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/DateUtils.java index 258b7ece8..6677e0752 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/util/DateUtils.java +++ b/jsowell-common/src/main/java/com/jsowell/common/util/DateUtils.java @@ -578,6 +578,13 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils { return formatDateTime(date); } + public static String formatDateTime(LocalTime localTime) { + if (localTime == null) { + return ""; + } + return localTime.toString(); + } + @Data @AllArgsConstructor @NoArgsConstructor diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/ykcCommond/ReservationChargingCommand.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/ykcCommond/ReservationChargingCommand.java index b5dfb58a0..95bef6804 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/domain/ykcCommond/ReservationChargingCommand.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/ykcCommond/ReservationChargingCommand.java @@ -8,6 +8,7 @@ import lombok.NoArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; import java.math.BigDecimal; +import java.time.LocalTime; import java.util.Date; /** @@ -40,18 +41,43 @@ public class ReservationChargingCommand { private String operation; /** - * 开始时间 + * 预约类型 + * 0x00:单次0x01:周期 */ - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date reservedStartTime; + private String reservationType; + + /** + * vin1 + */ + private String vin1; + + /** + * vin2 + */ + private String vin2; + + /** + * vin3 + */ + private String vin3; + + /** + * 开始时间 + * 2024年6月28日15点21分 改为时分秒 + */ + // @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + // private Date reservedStartTime; + private LocalTime reservedStartTime; /** * 结束时间 + * 2024年6月28日15点21分 改为时分秒 */ - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date reservedEndTime; + // @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + // private Date reservedEndTime; + private LocalTime reservedEndTime; /** * 启动金额 diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java index 9ba220989..a0e1f733f 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java @@ -120,12 +120,12 @@ public interface PileBasicInfoService { /** * 首次插枪 */ - public void firstPlugInCharger(String pileConnectorCode); + void firstPlugInCharger(String pileConnectorCode); /** * 首次拔枪 */ - public void firstUnplugCharger(String pileConnectorCode); + void firstUnplugCharger(String pileConnectorCode); /** * 通过桩编号查询站点id diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/SettleOrderReportService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/SettleOrderReportService.java index 09729e179..fc3f374b2 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/SettleOrderReportService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/SettleOrderReportService.java @@ -83,7 +83,7 @@ public interface SettleOrderReportService { int deleteByPrimaryKey(Integer id); - int insert(SettleOrderReport record); + // int insert(SettleOrderReport record); int insertOrUpdate(SettleOrderReport record); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java index 54e203752..b6a4c22d4 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java @@ -3119,20 +3119,20 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService { /** * 异步发送预约充电指令 */ - if (StringUtils.equals(orderInfo.getStartType(), StartTypeEnum.RESERVED.getValue())) { - ReservationChargingCommand command = ReservationChargingCommand.builder() - .transactionCode(orderInfo.getTransactionCode()) - .pileSn(orderInfo.getPileSn()) - .connectorCode(orderInfo.getConnectorCode()) - .operation(BytesUtil.bcd2Str(new byte[]{0x01})) - .reservedStartTime(orderInfo.getReservedStartTime()) - .reservedEndTime(orderInfo.getReservedEndTime()) - .amount(new BigDecimal(Constants.FIVE_HUNDRED)) - .build(); - // 发送预约充电指令 - logger.info("订单:{}支付成功, 发送预约充电指令, command:{}", dto.getOrderCode(), JSON.toJSONString(command)); - pileRemoteService.reservationCharging(command); - } + // if (StringUtils.equals(orderInfo.getStartType(), StartTypeEnum.RESERVED.getValue())) { + // ReservationChargingCommand command = ReservationChargingCommand.builder() + // .transactionCode(orderInfo.getTransactionCode()) + // .pileSn(orderInfo.getPileSn()) + // .connectorCode(orderInfo.getConnectorCode()) + // .operation(BytesUtil.bcd2Str(new byte[]{0x01})) + // .reservedStartTime(orderInfo.getReservedStartTime()) + // .reservedEndTime(orderInfo.getReservedEndTime()) + // .amount(new BigDecimal(Constants.FIVE_HUNDRED)) + // .build(); + // // 发送预约充电指令 + // logger.info("订单:{}支付成功, 发送预约充电指令, command:{}", dto.getOrderCode(), JSON.toJSONString(command)); + // pileRemoteService.reservationCharging(command); + // } if (OrderStatusEnum.STAY_RETROACTIVE_AMOUNT.getValue().equals(orderInfo.getOrderStatus())) { // 如果订单状态是待补缴,表示已经停止充电了,需要补缴费用,补缴完成订单状态改为订单完成,设置结算时间 diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java index 73c235af6..c3411598d 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java @@ -582,28 +582,6 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { // 保存到redis String redisKey = CacheConstants.PILE_REAL_TIME_MONITOR_DATA + realTimeMonitorData.getPileConnectorCode() + "_" + realTimeMonitorData.getTransactionCode(); - // 拿到所有数据取出最后一条数据,对比数据变化 - // Map map = redisCache.hmget(redisKey); - // if (map != null && !map.isEmpty()) { - // List keyList = map.keySet().stream() - // .map(x -> (String) x) - // .sorted(Comparator.reverseOrder()) // 对keyList排序 时间倒序 - // .collect(Collectors.toList()); - // if (CollectionUtils.isNotEmpty(keyList)) { - // // index为0是最新的时间 - // String lastTime = keyList.get(0); - // // 取出最新的数据 - // Object lastData = map.get(lastTime); - // RealTimeMonitorData data = JSONObject.parseObject((String) lastData, RealTimeMonitorData.class); - // if (Objects.nonNull(data)) { - // // 如果已充金额相同,则return - // if (StringUtils.equals(data.getChargingAmount(), realTimeMonitorData.getChargingAmount())) { - // return; - // } - // } - // } - // } - // 设置接收到实时数据的时间 Date now = new Date(); realTimeMonitorData.setDateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now)); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileReservationInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileReservationInfoServiceImpl.java index 0279ddf63..16478f601 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileReservationInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileReservationInfoServiceImpl.java @@ -109,7 +109,10 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic } pileReservationInfo.setStatus(Constants.ONE); // 保存之前,校验时间是否重叠 - saveReservation(pileReservationInfo); + int i = saveReservation(pileReservationInfo); + if (i > 0) { + // TODO 发送指令 + } } /** @@ -126,7 +129,10 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic } // 校验通过可以修改预约 pileReservationInfo.setStatus(Constants.ZERO); - pileReservationInfoMapper.updateByPrimaryKeySelective(pileReservationInfo); + int i = pileReservationInfoMapper.updateByPrimaryKeySelective(pileReservationInfo); + if (i > 0) { + // TODO 发送指令 + } } /** @@ -157,9 +163,9 @@ public class PileReservationInfoServiceImpl implements PileReservationInfoServic return true; } - public void saveReservation(PileReservationInfo reservation) { + public int saveReservation(PileReservationInfo reservation) { if (isTimeSlotAvailable(reservation.getMemberId(), reservation.getPileSn(), reservation.getStartTime(), reservation.getEndTime(), reservation.getId())) { - this.updateByPrimaryKeySelective(reservation); + return this.updateByPrimaryKeySelective(reservation); } else { throw new BusinessException(ReturnCodeEnum.CODE_UPDATE_RESERVED_STATUS_REFUSED); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/SettleOrderReportServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/SettleOrderReportServiceImpl.java index 69d180a0f..1c93918e6 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/SettleOrderReportServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/SettleOrderReportServiceImpl.java @@ -453,10 +453,10 @@ public class SettleOrderReportServiceImpl implements SettleOrderReportService { return settleOrderReportMapper.deleteByPrimaryKey(id); } - @Override - public int insert(SettleOrderReport record) { - return settleOrderReportMapper.insert(record); - } + // @Override + // public int insert(SettleOrderReport record) { + // return settleOrderReportMapper.insert(record); + // } @Override public int insertOrUpdate(SettleOrderReport record) { @@ -471,6 +471,12 @@ public class SettleOrderReportServiceImpl implements SettleOrderReportService { @Override public int insertOrUpdateSelective(SettleOrderReport record) { + Date nowDate = DateUtils.getNowDate(); + if (record.getId() == null) { + record.setCreateTime(nowDate); + } else { + record.setUpdateTime(nowDate); + } return settleOrderReportMapper.insertOrUpdateSelective(record); } @@ -724,19 +730,18 @@ public class SettleOrderReportServiceImpl implements SettleOrderReportService { public static void main(String[] args) { List list = Lists.newArrayList( - "17.56", - "26.13", - "11.79", - "34.80", - "12.72", - "18.03", - "19.80", - "66.76", - "15.27", - "37.50", - "28.45", - "24.81", - "16.75"); + "0.06", + "0.06", + "0.09", + "0.06", + "0.05", + "0.09", + "0.02", + "0.18", + "0.10", + "0.03", + "0.06", + "0.11"); // 总手续费 BigDecimal totalFeeAmount = BigDecimal.ZERO; @@ -744,11 +749,11 @@ public class SettleOrderReportServiceImpl implements SettleOrderReportService { for (String s : list) { BigDecimal settleAmount = new BigDecimal(s); - BigDecimal feeAmount = settleAmount.multiply(new BigDecimal(Constants.FEE_RATES)).setScale(2, RoundingMode.UP); + BigDecimal fee = settleAmount.multiply(new BigDecimal(Constants.FEE_RATES)).setScale(2, RoundingMode.UP); // 交易金额 = 结算金额 - 手续费 - BigDecimal tradeAmount = settleAmount.subtract(feeAmount); + BigDecimal tradeAmount = settleAmount.subtract(fee); - totalFeeAmount = totalFeeAmount.add(feeAmount); + totalFeeAmount = totalFeeAmount.add(fee); totalTradeAmount = totalTradeAmount.add(tradeAmount); } @@ -756,14 +761,14 @@ public class SettleOrderReportServiceImpl implements SettleOrderReportService { System.out.println("总交易金额" + totalTradeAmount); - BigDecimal settleAmount = new BigDecimal("330.37"); - // 计算手续费 = 结算金额 * 0.55% - BigDecimal fee = settleAmount.multiply(new BigDecimal(Constants.FEE_RATES)); - SplitSettleAmountVO resultVO = new SplitSettleAmountVO(); - resultVO.setSettleAmount(settleAmount); - resultVO.setFeeAmount(fee); - resultVO.setTradeAmount(settleAmount.subtract(fee)); - System.out.println(JSON.toJSONString(resultVO)); + // BigDecimal settleAmount = new BigDecimal("330.37"); + // // 计算手续费 = 结算金额 * 0.55% + // BigDecimal fee = settleAmount.multiply(new BigDecimal(Constants.FEE_RATES)); + // SplitSettleAmountVO resultVO = new SplitSettleAmountVO(); + // resultVO.setSettleAmount(settleAmount); + // resultVO.setFeeAmount(fee); + // resultVO.setTradeAmount(settleAmount.subtract(fee)); + // System.out.println(JSON.toJSONString(resultVO)); } } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java index 49b1e02b2..fc50a0706 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java @@ -20,10 +20,12 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.aspectj.weaver.ast.Var; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; +import java.time.LocalTime; import java.util.Date; import java.util.List; import java.util.Objects; @@ -499,13 +501,39 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService { String operation = command.getOperation(); byte[] operateByteArr = BytesUtil.str2Bcd(operation); + // 预约方式 + String reservationType = command.getReservationType(); + byte[] reservationTypeByteArr = BytesUtil.str2Bcd(reservationType); + + // VIN1 + String vin1 = command.getVin1(); + if (StringUtils.isBlank(vin1)) { + vin1 = Constants.ZERO; + } + byte[] vin1ByteArr = BytesUtil.str2Bcd(vin1); + vin1ByteArr = BytesUtil.checkLengthAndBehindAppendZero(vin1ByteArr, 17); + + String vin2 = command.getVin2(); + if (StringUtils.isBlank(vin2)) { + vin2 = Constants.ZERO; + } + byte[] vin2ByteArr = BytesUtil.str2Bcd(vin2); + vin2ByteArr = BytesUtil.checkLengthAndBehindAppendZero(vin2ByteArr, 17); + + String vin3 = command.getVin3(); + if (StringUtils.isBlank(vin3)) { + vin3 = Constants.ZERO; + } + byte[] vin3ByteArr = BytesUtil.str2Bcd(vin3); + vin3ByteArr = BytesUtil.checkLengthAndBehindAppendZero(vin3ByteArr, 17); + // 开始时间 - Date reservedStartTime = command.getReservedStartTime(); - byte[] reservedStartTimeByteArr = Cp56Time2aUtil.date2Hbyte(reservedStartTime); + LocalTime reservedStartTime = command.getReservedStartTime(); + byte[] reservedStartTimeByteArr = BytesUtil.createByteArray((byte) reservedStartTime.getHour(), (byte) reservedStartTime.getMinute()); // 结束时间 - Date reservedEndTime = command.getReservedEndTime(); - byte[] reservedEndTimeByteArr = Cp56Time2aUtil.date2Hbyte(reservedEndTime); + LocalTime reservedEndTime = command.getReservedEndTime(); + byte[] reservedEndTimeByteArr = BytesUtil.createByteArray((byte) reservedEndTime.getHour(), (byte) reservedEndTime.getMinute()); // 启动金额 BigDecimal amount = command.getAmount(); @@ -513,6 +541,7 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService { // 拼装msg信息 byte[] msg = Bytes.concat(transactionCodeArr, pileSnByteArr, connectorCodeByteArr, operateByteArr, + reservationTypeByteArr, vin1ByteArr, vin2ByteArr, vin3ByteArr, reservedStartTimeByteArr, reservedEndTimeByteArr, amountByteArr); this.push(msg, pileSn, YKCFrameTypeCode.RESERVE_CHARGING_CODE);