diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationStatusController.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationStatusController.java index faef9a02..cba28ffb 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationStatusController.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/api/QueryStationStatusController.java @@ -1,14 +1,29 @@ package com.xhpc.evcs.api; import com.xhpc.common.api.dto.ChargingStationDto; -import com.xhpc.evcs.dto.*; +import com.xhpc.common.domain.XhpcTerminal; +import com.xhpc.evcs.dto.CommonRequest; +import com.xhpc.evcs.dto.CommonResponse; +import com.xhpc.evcs.dto.ConnectorStatusInfo; +import com.xhpc.evcs.dto.StationStatusInfo; +import com.xhpc.evcs.dto.StationStatusInfoWrapper; +import com.xhpc.evcs.dto.StationStatusRequest; import com.xhpc.evcs.encryption.EvcsConst; +import com.xhpc.evcs.jpa.XhpcTerminalRepository; import com.xhpc.evcs.utils.JSONUtil; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import java.util.*; +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import static cn.hutool.core.util.NumberUtil.isInteger; import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS; @@ -16,6 +31,8 @@ import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS; @RestController public class QueryStationStatusController { + @Resource + XhpcTerminalRepository terminalRepository; @PostMapping("/v1/query_station_status") public CommonResponse queryStationsInfo(@RequestBody CommonRequest commonRequest) throws Exception { @@ -46,6 +63,10 @@ public class QueryStationStatusController { for (int i = 0; i < keys.length; i++) { statusMap.put(keys[i], values[i]); } + + List terminalList = terminalRepository.selectStatusBySql(); + Map terminalDBMap = terminalList.stream().collect(Collectors.toMap(XhpcTerminal::getSerialNumber,XhpcTerminal::getStatus)); + for (String stationID : stationIDs) { ChargingStationDto chargingStationDto = REDIS.getCacheObject("station:" + stationID); Set pileIds = new HashSet<>(); @@ -59,11 +80,20 @@ public class QueryStationStatusController { if (pileId.equals(value.substring(0, 14))) { existsGun = true; ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo(); - Object status = REDIS.getCacheMapValue("gun:" + value, "status"); - if (isInteger(status.toString())) { - connectorStatusInfo.setStatus(3); + Integer gunStatus = terminalDBMap.get(value); + if (gunStatus == null){ + existsGun = false; } else { - connectorStatusInfo.setStatus(statusMap.get(status)); + if (gunStatus == 0){ + Object status = REDIS.getCacheMapValue("gun:" + value, "status"); + if (isInteger(status.toString())) { + connectorStatusInfo.setStatus(3); + } else { + connectorStatusInfo.setStatus(statusMap.get(status)); + } + } else { + connectorStatusInfo.setStatus(0); + } } connectorStatusInfo.setConnectorID(value); connectorStatusInfos.add(connectorStatusInfo); diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcTerminalRepository.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcTerminalRepository.java index 2918c6eb..88d22ba6 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcTerminalRepository.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/jpa/XhpcTerminalRepository.java @@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.QueryByExampleExecutor; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; /** @@ -31,4 +32,7 @@ public interface XhpcTerminalRepository extends JpaRepository selectStatusBySql(); } diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationChargeOrderInfo4BonusTask.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationChargeOrderInfo4BonusTask.java index 179ac956..66ec3bb1 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationChargeOrderInfo4BonusTask.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationChargeOrderInfo4BonusTask.java @@ -76,6 +76,11 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher { if (operatorIdEvcs == null) { Long chargingStationId = xhpcHistoryOrder.getChargingStationId(); XhpcChargingStation station = chargingStationRepo.findById(chargingStationId).orElse(null); + if(station == null){ + logger.error("station[{}] is not exits", chargingStationId); + return false; + } + String stationOperatorIdEvcs = station.getOperatorIdEvcs(); if (stationOperatorIdEvcs == null) { logger.error("station[{}] operator id evcs not set", chargingStationId); diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationChargeOrderInfoTask.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationChargeOrderInfoTask.java index 0ba116cc..470f7d7f 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationChargeOrderInfoTask.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationChargeOrderInfoTask.java @@ -45,7 +45,13 @@ public class NotificationChargeOrderInfoTask extends CoreDispatcher { Collection orderKeys = REDIS.keys("order:*"); Instant now = Instant.now(); for (String okey : orderKeys) { - Date otime = DateUtil.orderNo2Date(okey.substring(6)); + String orderNo = okey.substring(6); + if(orderNo.length() < 32){ + logger.error("orderNo[{}] is error", orderNo); + continue; + } + + Date otime = DateUtil.orderNo2Date(orderNo); if (Duration.between(otime.toInstant(), now).toHours() > 24 * 3) { REDIS.deleteObject(okey); REDIS.deleteObject(okey.replace("order", "pushOrder")); diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStationStatusTask.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStationStatusTask.java index 6ec28d03..4ed540e8 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStationStatusTask.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStationStatusTask.java @@ -1,6 +1,7 @@ package com.xhpc.evcs.notification; import com.xhpc.common.api.dto.ChargingStationDto; +import com.xhpc.common.domain.XhpcTerminal; import com.xhpc.evcs.domain.AuthSecretToken; import com.xhpc.evcs.domain.XhpcInternetUser; import com.xhpc.evcs.domain.XhpcStationInternetBlacklist; @@ -10,6 +11,7 @@ import com.xhpc.evcs.dto.ConnectorStatusInfoReq; import com.xhpc.evcs.jpa.AuthSecretTokenRepository; import com.xhpc.evcs.jpa.XhpcInternetUserRepository; import com.xhpc.evcs.jpa.XhpcStationInternetBlacklistRepository; +import com.xhpc.evcs.jpa.XhpcTerminalRepository; import com.xhpc.evcs.utils.ChangePoleStatus; import com.xhpc.evcs.utils.JSONUtil; import lombok.extern.slf4j.Slf4j; @@ -17,13 +19,22 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.io.IOException; import java.time.Instant; -import java.util.*; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS; import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_OUT; -import static com.xhpc.evcs.dto.ConnectorStatusInfo.*; +import static com.xhpc.evcs.dto.ConnectorStatusInfo.CHARGING; +import static com.xhpc.evcs.dto.ConnectorStatusInfo.ERROR; +import static com.xhpc.evcs.dto.ConnectorStatusInfo.FREE; +import static com.xhpc.evcs.dto.ConnectorStatusInfo.OFF_LINE; @Component @Slf4j @@ -35,12 +46,17 @@ public class NotificationStationStatusTask extends CoreDispatcher { private XhpcInternetUserRepository xhpcInternetUserRepository; @Autowired private XhpcStationInternetBlacklistRepository xhpcStationInternetBlacklistRepo; + @Resource + private XhpcTerminalRepository terminalRepository; @Scheduled(fixedRate = 1000 * 45) protected void run() throws IOException { Collection stationTerminalKeys = REDIS.keys("stationTerminalStatus:*"); + List terminalList = terminalRepository.selectStatusBySql(); + Map terminalDBMap = terminalList.stream().collect(Collectors.toMap(XhpcTerminal::getSerialNumber,XhpcTerminal::getStatus)); + Instant now = Instant.now(); List xhpcInternetUserList = xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(now, now); @@ -49,7 +65,7 @@ public class NotificationStationStatusTask extends CoreDispatcher { "station")); String operatorId = chargingStationDto.getOperatorId(); Map terminalStatusMap = REDIS.getCacheMap(stationTerminalKey); - Set connectorStatusInfos = translateStatus(operatorId, terminalStatusMap); + Set connectorStatusInfos = translateStatus(operatorId, terminalStatusMap, terminalDBMap); Set changeStatus = ChangePoleStatus.getChangeStatus(connectorStatusInfos); if (!changeStatus.isEmpty()) { for (XhpcInternetUser xhpcInternetUser : xhpcInternetUserList) { @@ -70,7 +86,7 @@ public class NotificationStationStatusTask extends CoreDispatcher { } } - private Set translateStatus(String operatorId, Map terminalStatusMap) { + private Set translateStatus(String operatorId, Map terminalStatusMap, Map terminalDBMap) { Set connectorStatusInfoList = new HashSet<>(); final Set connectorIds = terminalStatusMap.keySet(); @@ -78,7 +94,12 @@ public class NotificationStationStatusTask extends CoreDispatcher { ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo(); connectorStatusInfo.setConnectorID(gunId); connectorStatusInfo.setOperatorID(operatorId); - connectorStatusInfo.setStatus(translateStatus(terminalStatusMap.get(gunId))); + Integer dbStatus = terminalDBMap.get(gunId); + if(dbStatus == 0){ + connectorStatusInfo.setStatus(translateStatus(terminalStatusMap.get(gunId))); + } else { + connectorStatusInfo.setStatus(0); + } connectorStatusInfoList.add(connectorStatusInfo); } return connectorStatusInfoList; diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/Constants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/Constants.java index 3547b49b..d81d1140 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/Constants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/Constants.java @@ -90,7 +90,7 @@ public class Constants /** * 令牌有效期(分钟) */ - public final static long TOKEN_EXPIRE = 10; + public final static long TOKEN_EXPIRE = 60*24; /** * 参数管理 cache key diff --git a/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcChargingStationMapper.xml b/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcChargingStationMapper.xml index 1a192dd0..668e58b3 100644 --- a/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcChargingStationMapper.xml +++ b/xhpc-modules/xhpc-card/src/main/resources/mapper/XhpcChargingStationMapper.xml @@ -566,6 +566,7 @@ and find_in_set(tenant_id, #{tenantIdsStr}) order by create_time desc + LIMIT 50 \ No newline at end of file diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PileOrderService.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PileOrderService.java index d7dcce51..a9adba9e 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PileOrderService.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PileOrderService.java @@ -83,4 +83,12 @@ public interface PileOrderService { @GetMapping("/api/chargeOrder/pileVin") R pileVin(@RequestParam(value = "serialNumber") String serialNumber,@RequestParam(value = "vinNumber") String vinNumber); + + /** + * 桩订单实时订单BMS回调接口 + * @param orderNo 订单号 + * @return + */ + @GetMapping("/chargeOrder/pileRimeOrderBms") + R pileRimeOrderBms(@RequestParam(value = "orderNo") String orderNo); } diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PileOrderFallbackFactory.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PileOrderFallbackFactory.java index 2dc49ed9..12b58cf3 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PileOrderFallbackFactory.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/PileOrderFallbackFactory.java @@ -59,6 +59,17 @@ public class PileOrderFallbackFactory implements FallbackFactory getMap(){ + return Arrays.stream(StopReasonEnum.values()).collect(Collectors.toMap(StopReasonEnum::getCode, StopReasonEnum::getName)); + } + } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java index 04b3e65f..79414dfc 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcPileOrderController.java @@ -9,6 +9,7 @@ import com.xhpc.common.api.WebSocketService; import com.xhpc.common.api.WorkOrderYuService; import com.xhpc.common.core.domain.R; import com.xhpc.common.core.web.controller.BaseController; +import com.xhpc.common.data.redis.CacheBmsReqChargerOutputData; import com.xhpc.common.data.redis.CacheOrderData; import com.xhpc.common.data.redis.CacheRealtimeData; import com.xhpc.common.domain.XhpcRate; @@ -802,4 +803,23 @@ public R pileStartUpBy3rd(@RequestParam(value = "internetSerialNumber") String i workOrderYuService.addNewOrder("28","有异常订单订单且该桩进行校时效价处理","定时任务自动扫描异常订单","","","",""); } + /** + * 桩实时数据BMS回调接口 + * @param orderNo 订单号 + * @return + */ + @Transactional + @GetMapping("/chargeOrder/pileRimeOrderBms") + public R pileRimeOrderBms(@RequestParam(value = "orderNo")String orderNo) { + + logger.info("桩实时数据BMS回调接口>>>>>orderNo:" + orderNo); + //获取实时订单 + + xhpcRealTimeOrderService.addRealTimeOrderBms(orderNo); + + return R.ok(); + } + + + } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcRealTimeOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcRealTimeOrderController.java index 9894d06d..46f216cd 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcRealTimeOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcRealTimeOrderController.java @@ -77,17 +77,57 @@ public class XhpcRealTimeOrderController extends BaseController { return getDataTable(list); } + @GetMapping("/timeBmsList") + public TableDataInfo timeBmsList(@RequestParam Long chargingOrderId) + { + startPage(); + List> list = xhpcRealTimeOrderService.timeBmsList(chargingOrderId); + return getDataTable(list); + } /** * 实时/异常订单详情数据图表(PC) * @param chargingOrderId * @return */ - @GetMapping("/timeChartList") - public AjaxResult timeChartList(@RequestParam Long chargingOrderId) +// @GetMapping("/timeChartList") +// public AjaxResult timeChartList(@RequestParam Long chargingOrderId) +// { +// return xhpcRealTimeOrderService.timeChartList(chargingOrderId); +// } + + /** + * 实时/异常订单详情数据电压图表(PC) + * @param chargingOrderId + * @return + */ + @GetMapping("/timeChartListVoltage") + public AjaxResult timeChartListVoltage(@RequestParam Long chargingOrderId) { - return xhpcRealTimeOrderService.timeChartList(chargingOrderId); + return xhpcRealTimeOrderService.timeChartListVoltage(chargingOrderId); } + /** + * 实时/异常订单详情数据电流图表(PC) + * @param chargingOrderId + * @return + */ + @GetMapping("/timeChartListCurrent") + public AjaxResult timeChartListCurrent(@RequestParam Long chargingOrderId) + { + return xhpcRealTimeOrderService.timeChartListCurrent(chargingOrderId); + } + /** + * 实时/异常订单详情数据soc图表(PC) + * @param chargingOrderId + * @return + */ + @GetMapping("/timeChartListSoc") + public AjaxResult timeChartListSoc(@RequestParam Long chargingOrderId) + { + return xhpcRealTimeOrderService.timeChartListSoc(chargingOrderId); + } + + /** *异常订单审核详情 */ diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcRealTimeOrderBms.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcRealTimeOrderBms.java new file mode 100644 index 00000000..096c8c43 --- /dev/null +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcRealTimeOrderBms.java @@ -0,0 +1,33 @@ +package com.xhpc.order.domain; + +import com.xhpc.common.core.web.domain.BaseEntity; +import lombok.Data; + +/** + * @author yuyang + * @date 2022/8/31 17:32 + */ +@Data +public class XhpcRealTimeOrderBms extends BaseEntity { + + + private Long realTimeOrderBmsId; + + private String orderNo; //交易流水号 + private String pileNo; //桩号 + private String gunId; //枪号 + private Double bmsVoltageRequest; //BMS 电压需求 + private Double bmsCurrentRequest; //BMS 电流需求 + private Integer bmsChargingMod; //BMS 充电模式 + private Double bmsChargingVolt; //BMS 充电电压测量值 + private Double bmsChargingCurrent; //BMS 充电电流测量值 + private Double monoBatteryVolt; //BMS 最高单体动力蓄电池电压 + private Integer soc; //BMS 当前荷电状态 SOC( %) + private String bmsEstRemainingTime; //BMS 估算剩余充电时间 + private Double pileVoltageOutput; //电桩电压输出值 + private Double pileCurrentOutput; //电桩电流输出值 + private String chargingTimeSummary; //累计充电时间 + private Integer monoBatteryVoltGroupId; // BMS 最高单体动力蓄电池电压所在组号ID + private Long chargingOrderId; + +} diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java index 040d9300..46fa60cf 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcChargeOrderMapper.java @@ -142,7 +142,6 @@ public interface XhpcChargeOrderMapper { */ void addXhpcOrderRedisRecord(XhpcOrderRedisRecord xhpcOrderRedisRecord); - /** * 添加流水 * @param userId 用户id diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcHistoryOrderMapper.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcHistoryOrderMapper.java index 17b8c6df..fbdb98b7 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcHistoryOrderMapper.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcHistoryOrderMapper.java @@ -134,4 +134,7 @@ public interface XhpcHistoryOrderMapper { * 查询启动订单表 */ Map getchargingOrderById(@Param("chargingOrderId")Long chargingOrderId,@Param("userId")Long userId,@Param("source")Integer source,@Param("tenantId")String tenantId); + + //获取跨天最后一帧数据 + Map getXhpcRealTimeOrderTwentyFour(@Param("chargingOrderId")Long chargingOrderId,@Param("time")String time); } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcRealTimeOrderMapper.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcRealTimeOrderMapper.java index 409cd57e..086e5d21 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcRealTimeOrderMapper.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/mapper/XhpcRealTimeOrderMapper.java @@ -1,9 +1,6 @@ package com.xhpc.order.mapper; -import com.xhpc.order.domain.XhpcChargeOrderCurrent; -import com.xhpc.order.domain.XhpcChargeOrderSoc; -import com.xhpc.order.domain.XhpcChargeOrderVoltage; -import com.xhpc.order.domain.XhpcRealTimeOrder; +import com.xhpc.order.domain.*; import com.xhpc.order.dto.RateTime; import com.xhpc.order.dto.XhpcActivityDiscountDto; import com.xhpc.order.dto.XhpcActivityFormulaDomainDto; @@ -27,7 +24,12 @@ public interface XhpcRealTimeOrderMapper { */ int insertXhpcRealTimeOrder(XhpcRealTimeOrder xhpcRealTimeOrder); - + /** + * 添加实时充电订单 + * @param xhpcRealTimeOrderBms + * @return + */ + int insertRealTimeOrderBms(XhpcRealTimeOrderBms xhpcRealTimeOrderBms); /** * 添加订单实时SOC * @param xhpcChargeOrderSoc @@ -73,6 +75,10 @@ public interface XhpcRealTimeOrderMapper { */ Map getMessage(@Param("realTimeOrderId")Long realTimeOrderId); + /** + * 获取场站信息 + */ + Map getXhpcChargingStationById(Long chargingStationId); /** * 异常订单详情接口(PC端) * @param chargeOrderId @@ -88,6 +94,13 @@ public interface XhpcRealTimeOrderMapper { */ List> timeList(@Param("chargingOrderId")Long chargingOrderId); + /** + * 实时订单详情数据列表BMS(PC) + * @param chargingOrderId + * @return + */ + List> timeBmsList(@Param("chargingOrderId")Long chargingOrderId); + /** * 实时订单详情数据图表SOC(PC) * @param chargingOrderId diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java index 7a53ab86..ef2910b9 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/IXhpcRealTimeOrderService.java @@ -47,12 +47,30 @@ public interface IXhpcRealTimeOrderService { */ List> timeList(Long chargingOrderId); + /** + * 实时订单详情数据列表(PC) + * @param chargingOrderId 充电订单id + * @return + */ + List> timeBmsList(Long chargingOrderId); /** * 实时订单详情数据图表(PC) * @param chargingOrderId * @return */ - AjaxResult timeChartList(Long chargingOrderId); + AjaxResult timeChartListVoltage(Long chargingOrderId); + /** + * 实时订单详情数据图表(PC) + * @param chargingOrderId + * @return + */ + AjaxResult timeChartListCurrent(Long chargingOrderId); + /** + * 实时订单详情数据图表(PC) + * @param chargingOrderId + * @return + */ + AjaxResult timeChartListSoc(Long chargingOrderId); /** * 删除之前的实时订单数据 @@ -149,4 +167,11 @@ public interface IXhpcRealTimeOrderService { * 添加一条金额为0的数据 */ void addZeroHistoryOrder(XhpcChargeOrder xhpcChargeOrder); + + + /** + * 添加一条实时订单的BMS + */ + void addRealTimeOrderBms(String orderNo); + } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java index 65b84a55..32108beb 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java @@ -9,6 +9,7 @@ import com.xhpc.common.core.utils.StringUtils; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.service.BaseService; import com.xhpc.common.data.down.StartChargingData; +import com.xhpc.common.data.redis.CacheBmsReqChargerOutputData; import com.xhpc.common.data.redis.CacheRealtimeData; import com.xhpc.common.data.redis.StaticBeanUtil; import com.xhpc.common.domain.XhpcRate; @@ -440,6 +441,7 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar xhpcChargeOrderMapper.addXhpcOrderRedisRecord(xhpcOrderRedisRecord); } + @Override public int addUserAccountStatement(Long userId, BigDecimal amount, BigDecimal remainingSum, Long chargeOrderId, Integer type, Date date,Integer source) { @@ -507,13 +509,14 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar //终端信息 XhpcTerminal xhpcTerminal = xhpcChargeOrderMapper.getXhpcTerminalSerialNumber(connectorId,null); if (xhpcTerminal == null || xhpcTerminal.getTerminalId() == null || xhpcTerminal.getChargingPileId() == null || xhpcTerminal.getPileSerialNumber() == null) { - r.setCode(1); - String pilePrompt = redisService.getCacheObject("pilePrompt:000000"); - if(!"".equals(pilePrompt) && pilePrompt !=null){ - r.setMsg(pilePrompt); - }else{ - r.setMsg("因限电该桩已停用,请选择其他桩进行充电"); - } + r.setCode(500); +// String pilePrompt = redisService.getCacheObject("pilePrompt:000000"); +// if(!"".equals(pilePrompt) && pilePrompt !=null){ +// r.setMsg(pilePrompt); +// }else{ +// r.setMsg("因限电该桩已停用,请选择其他桩进行充电"); +// } + r.setMsg("因限电该桩已停用请选择其他桩进行充电"); return r; } //终端状态是否空闲 diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java index 487d2c99..6b615446 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcHistoryOrderServiceImpl.java @@ -12,6 +12,7 @@ import com.xhpc.common.core.utils.SecurityUtils; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.service.BaseService; import com.xhpc.common.data.redis.CacheRealtimeData; +import com.xhpc.common.enums.StopReasonEnum; import com.xhpc.common.redis.service.RedisService; import com.xhpc.common.security.service.TokenService; import com.xhpc.common.util.UserTypeUtil; @@ -363,6 +364,9 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis list = xhpcHistoryOrderMapper.getListPage(chargingStationId,chargingPileId,terminalId,phone, transactionNumber, 0, chargingStationName, operatorId, source, beginStartTime, beginEndTime, userId, type, number,affiliationOrganization,evcsOrderNo,plateNum,internetId,internetSerialNumber,terminalName,vinCode,overStartTime,overEndTime,personnelId,confirmResult,tenantId,1); } + Map reasonMap = StopReasonEnum.getMap(); + list.stream().forEach(map->map.put("stopReasonEvcsStr", reasonMap.get(map.get("stopReasonEvcs")))); + // 通过工具类创建writer,默认创建xls格式 BigExcelWriter writer = ExcelUtil.getBigWriter("HistoryOrder_" + System.currentTimeMillis() + ".xlsx"); writer.addHeaderAlias("historyOrderId", "历史订单ID"); @@ -406,7 +410,8 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis writer.addHeaderAlias("endTime", "结束充电时间"); writer.addHeaderAlias("updateTime", "结算时间"); writer.addHeaderAlias("chargingModeName", "订单来源"); - writer.addHeaderAlias("stopReasonEvcs", "停止原因"); + writer.addHeaderAlias("stopReasonEvcs", "停止原因代码"); + writer.addHeaderAlias("stopReasonEvcsStr", "停止原因说明"); writer.addHeaderAlias("sourceName", "用户类型"); // writer.addHeaderAlias("plateNum", "电站名称"); @@ -514,7 +519,12 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis if(map !=null){ BigDecimal powerPriceTotal = new BigDecimal(map.get("powerPriceTotal").toString()); BigDecimal servicePriceTotal = new BigDecimal(map.get("servicePriceTotal").toString()); - xhpcRealTimeOrderService.getExamine(chargeOrderId,powerPriceTotal,servicePriceTotal,null,null,null); + BigDecimal chargingDegree = new BigDecimal(map.get("chargingDegree").toString()); + if(map.get("startTime")!=null && map.get("endTime")!=null){ + xhpcRealTimeOrderService.getExamine(chargeOrderId,powerPriceTotal,servicePriceTotal,chargingDegree,map.get("startTime").toString(),map.get("endTime").toString()); + }else{ + xhpcRealTimeOrderService.getExamine(chargeOrderId,powerPriceTotal,servicePriceTotal,chargingDegree,null,null); + } } } @@ -531,6 +541,7 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis BigDecimal powerPriceTotal = new BigDecimal(0); BigDecimal servicePriceTotal = new BigDecimal(0); + BigDecimal divide = new BigDecimal(totalPower); //累计充电时间、计费模型、开始时间、结束时间、已充金额 XhpcChargeOrder chargeOrder = xhpcChargeOrderService.getSerialNumberMessage(serialNumber); Long rateModelId = chargeOrder.getRateModelId(); @@ -540,24 +551,64 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis BigDecimal chargingDegree = new BigDecimal(totalPower); List> list = new ArrayList<>(); //1时间没有跨天 - long betweenDay = DateUtil.between(startTime2, updateTime2, DateUnit.DAY); + DateTime parse = DateUtil.parse(DateUtil.format(startTime2, "yyyy-MM-dd"), "yyyy-MM-dd"); + DateTime parse1 = DateUtil.parse(DateUtil.format(updateTime2, "yyyy-MM-dd"), "yyyy-MM-dd"); + long betweenDay = DateUtil.between(parse, parse1, DateUnit.DAY); if (betweenDay == 0) { return getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime2, chargingDegree, list); } else { - //跨天 + //当天晚上时间 23:59:59 + Map map =new HashMap<>(); Date updateTime = DateUtil.endOfDay(startTime2); - Map map1 = getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime, chargingDegree, list); - //获取 - // BigDecimal powerPriceTotal1 = new BigDecimal(map1.get("powerPriceTotal").toString()); - // BigDecimal servicePriceTotal1 = new BigDecimal(map1.get("servicePriceTotal").toString()); - //明天 + String format = DateUtil.format(updateTime, "yyyy-MM-dd HH:mm:ss"); DateTime tomorrow = DateUtil.offsetDay(startTime2, 1); Date startTime3 = DateUtil.beginOfDay(tomorrow); - Map map2 = getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime3, updateTime2, chargingDegree, list); - return map2; + Map twentyFour = xhpcHistoryOrderMapper.getXhpcRealTimeOrderTwentyFour(chargeOrder.getChargeOrderId(), format); + if(twentyFour !=null && twentyFour.get("chargingDegree")!=null){ + BigDecimal chargingDegree1 = new BigDecimal(twentyFour.get("chargingDegree").toString()); + BigDecimal decimal = divide.subtract(chargingDegree1); + if(chargingDegree1.compareTo(new BigDecimal(0))==0){ + String start = DateUtil.formatTime(updateTime); + Map map1 = new HashMap<>(); + map1.put("time", start+"-23:59:59"); + map1.put("powerPrice", 0); + map1.put("servicePrice", 0); + map1.put("chargingDegree", 0); + map1.put("actPrice", 0); + list.add(map1); + map.put("list", list);//数据列表 + map.putAll(getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime3, updateTime2, chargingDegree, list)); + return map; + }else if(decimal.compareTo(new BigDecimal(0))==1){ + map =getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime, chargingDegree1, list); + map.putAll(getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime3, updateTime2, decimal, list));; + return map; + }else{ + String end = DateUtil.formatTime(updateTime2); + map.putAll(getBigDecimal(totalPrice, powerPriceTotal, servicePriceTotal, chargeOrder, rateModelId, startTime2, updateTime, chargingDegree, list)); + Map map1 = new HashMap<>(); + map1.put("time", "00:00:00-"+end); + map1.put("powerPrice", 0); + map1.put("servicePrice", 0); + map1.put("chargingDegree", 0); + map1.put("actPrice", 0); + list.add(map1); + map.put("list", list);// + return map; + } + } + return null; + } } + + + + + + + private Map getBigDecimal(String totalPrice, BigDecimal powerPriceTotal, BigDecimal servicePriceTotal, XhpcChargeOrder chargeOrder, Long rateModelId, Date startTime2, Date updateTime2, BigDecimal chargingDegree, List> list) { Map map = new HashMap<>(); @@ -777,4 +828,5 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis return sr; // } } + } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java index 87c83923..1e945236 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcRealTimeOrderServiceImpl.java @@ -11,8 +11,10 @@ import com.xhpc.common.core.domain.R; import com.xhpc.common.core.utils.SecurityUtils; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.service.BaseService; +import com.xhpc.common.data.redis.CacheBmsReqChargerOutputData; import com.xhpc.common.data.redis.CacheOrderData; import com.xhpc.common.data.redis.CacheRealtimeData; +import com.xhpc.common.domain.XhpcRate; import com.xhpc.common.enums.StopReasonEnum; import com.xhpc.common.redis.service.RedisService; import com.xhpc.common.security.service.TokenService; @@ -134,11 +136,28 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe } @Override - public AjaxResult timeChartList(Long chargingOrderId) { + public List> timeBmsList(Long chargingOrderId) { + return xhpcRealTimeOrderMapper.timeBmsList(chargingOrderId); + } + + @Override + public AjaxResult timeChartListVoltage(Long chargingOrderId) { + Map map =new HashMap(); + map.put("voltage",xhpcRealTimeOrderMapper.timeChartVoltageList(chargingOrderId)); + return AjaxResult.success(map); + } + + @Override + public AjaxResult timeChartListCurrent(Long chargingOrderId) { + Map map =new HashMap(); + map.put("current",xhpcRealTimeOrderMapper.timeChartCurrentList(chargingOrderId)); + return AjaxResult.success(map); + } + + @Override + public AjaxResult timeChartListSoc(Long chargingOrderId) { Map map =new HashMap(); map.put("soc",xhpcRealTimeOrderMapper.timeChartSOCList(chargingOrderId)); - map.put("voltage",xhpcRealTimeOrderMapper.timeChartVoltageList(chargingOrderId)); - map.put("current",xhpcRealTimeOrderMapper.timeChartCurrentList(chargingOrderId)); return AjaxResult.success(map); } @@ -147,6 +166,40 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe return xhpcRealTimeOrderMapper.insertXhpcRealTimeOrder(xhpcRealTimeOrder); } + /** + * 添加一条实时订单的BMS + * + * @param orderNo + */ + @Override + public void addRealTimeOrderBms(String orderNo) { + CacheBmsReqChargerOutputData cacheBmsReqChargerOutputData = redisService.getCacheObject("order:" + orderNo + ".bms"); + if(cacheBmsReqChargerOutputData !=null){ + XhpcRealTimeOrderBms xhpcRealTimeOrderBms = new XhpcRealTimeOrderBms(); + BeanUtils.copyProperties(cacheBmsReqChargerOutputData, xhpcRealTimeOrderBms); + Integer bmsEstRemainingTime = cacheBmsReqChargerOutputData.getBmsEstRemainingTime(); + Integer chargingTimeSummary = cacheBmsReqChargerOutputData.getChargingTimeSummary(); + if (bmsEstRemainingTime > 60) { + Integer hours = bmsEstRemainingTime / 60; + Integer mins = bmsEstRemainingTime - (hours * 60); + xhpcRealTimeOrderBms.setBmsEstRemainingTime(hours + "时" + mins + "分"); + } else { + xhpcRealTimeOrderBms.setBmsEstRemainingTime(bmsEstRemainingTime + "分"); + } + if (chargingTimeSummary > 60) { + Integer hours = chargingTimeSummary / 60; + Integer mins = chargingTimeSummary - (hours * 60); + xhpcRealTimeOrderBms.setChargingTimeSummary(hours + "时" + mins + "分"); + } else { + xhpcRealTimeOrderBms.setChargingTimeSummary(chargingTimeSummary + "分"); + } + XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo); + xhpcRealTimeOrderBms.setChargingOrderId(xhpcChargeOrder.getChargeOrderId()); + xhpcRealTimeOrderMapper.insertRealTimeOrderBms(xhpcRealTimeOrderBms); + } + + } + @Override public int addSOC(XhpcChargeOrderSoc xhpcChargeOrderSoc) { return xhpcRealTimeOrderMapper.insertSOC(xhpcChargeOrderSoc); @@ -165,7 +218,6 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe @Transactional @Override public Map getExamineMessage(Long realTimeOrderId,Long chargeOrderId) { - if(realTimeOrderId==null){ Map message = xhpcRealTimeOrderMapper.getMessageChargeOrderId(chargeOrderId); message.put("powerPriceTotal",0); @@ -175,145 +227,254 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe //基本信息 Map message = xhpcRealTimeOrderMapper.getMessage(realTimeOrderId); try{ - if(message ==null || message.get("chargeOrderId") ==null){ + XhpcChargeOrder chargeOrder = xhpcChargeOrderService.getChargingOrderId(Long.parseLong(message.get("chargeOrderId").toString())); + Map cacheMap = redisService.getCacheMap("order:" + chargeOrder.getSerialNumber()); + if (cacheMap !=null && cacheMap.get("startTime")!=null && cacheMap.get("lastOrderTime")!=null) { + String startTime = cacheMap.get("startTime").toString(); + String lastOrderTime = cacheMap.get("lastOrderTime").toString(); + chargeOrder.setStartTime(DateUtil.parse(startTime)); + chargeOrder.setEndTime(DateUtil.parse(lastOrderTime)); + message.put("startTime",startTime); + message.put("endTime",lastOrderTime); + if (cacheMap.get("totalPower")!=null && cacheMap.get("totalMoney")!=null) { + String totalPower = cacheMap.get("totalPower").toString(); + //String totalPowerSub = totalPower.substring(0, totalPower.length() - 1); + String totalMoney = cacheMap.get("totalMoney").toString(); + //String totalMoneySub = totalMoney.substring(0, totalMoney.length() - 1); + chargeOrder.setChargingDegree(new BigDecimal(totalPower)); + chargeOrder.setAmountCharged(new BigDecimal(totalMoney)); + message.put("chargingDegree",new BigDecimal(totalPower)); + } + } + if(message.get("chargeOrderId") == null){ message.put("powerPriceTotal",0); message.put("servicePriceTotal",0); return message; } //获取开始充电时间、结束时间、计费模型、充电度数、已充金额 - XhpcChargeOrder chargeOrder = xhpcChargeOrderService.getChargingOrderId(Long.parseLong(message.get("chargeOrderId").toString())); - //获取该订单最后一条实时数据 - Map cacheMap = redisService.getCacheMap("order:" + chargeOrder.getSerialNumber()); - List list = (List) cacheMap.get("realtimeDataList"); - - CacheRealtimeData startData =new CacheRealtimeData(); - CacheRealtimeData endData =new CacheRealtimeData(); - - if (list != null && list.size() > 0) { - endData =list.get(list.size()-1); - for (int i = 0; i 0 && startData.getChargingTime()>0){ - break; - } - } + if(chargeOrder.getRateModelId()==null || "".equals(chargeOrder.getRateModelId().toString())){ + Map xhpcChargingStationMap = xhpcRealTimeOrderMapper.getXhpcChargingStationById(chargeOrder.getChargingStationId()); + chargeOrder.setRateModelId(Long.valueOf(xhpcChargingStationMap.get("rateModelId").toString())); } + //获取该订单最后一条实时数据 Long rateModelId = chargeOrder.getRateModelId(); - - if(endData !=null && endData.getAmountCharged() !=null && startData.getChargingTime()>0){ - - message.put("soc",endData.getSoc()); - //最后一祯时间 - Date endTime = DateUtil.parse(endData.getCreateTime()); - Date startTime =DateUtil.parse(startData.getCreateTime()); - //充电时长 - Long tiem = (endTime.getTime() - startTime.getTime()) / 1000; - if (tiem > 3600) { - long hours = tiem / 3600; - double mins = (double) ((tiem - (hours * 3600)) / 60); - message.put("chargingTime",hours + "时" + new BigDecimal(mins).setScale(0) + "分"); - chargeOrder.setChargingTime(hours + "时" + new BigDecimal(mins).setScale(0) + "分"); - } else { - double mins = (double) (tiem / 60); - message.put("chargingTime",new BigDecimal(mins).setScale(0) + "分"); - chargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "分"); + if(cacheMap !=null && cacheMap.get("orderData") !=null){ + CacheOrderData cacheOrderData = (CacheOrderData)cacheMap.get("orderData"); + BigDecimal bigDecimal = new BigDecimal(10000); + BigDecimal money = new BigDecimal(cacheOrderData.getCost()).divide(bigDecimal,2,BigDecimal.ROUND_HALF_UP); + //00: 尖费率 01: 峰费率 02: 平费率 03: 谷费率 + BigDecimal t1powerFee =new BigDecimal(0); + BigDecimal t2powerFee =new BigDecimal(0); + BigDecimal t3powerFee =new BigDecimal(0); + BigDecimal t4powerFee =new BigDecimal(0); + BigDecimal t1serviceFee =new BigDecimal(0); + BigDecimal t2serviceFee =new BigDecimal(0); + BigDecimal t3serviceFee =new BigDecimal(0); + BigDecimal t4serviceFee =new BigDecimal(0); + //费率计费模型 + List rateModelList = xhpcChargeOrderService.getRateModelId(rateModelId); + for (XhpcRate xhpcRate:rateModelList) { + if("00".equals(xhpcRate.getRateValue())){ + t1powerFee = xhpcRate.getPowerFee(); + t1serviceFee =xhpcRate.getServiceFee(); + } + if("01".equals(xhpcRate.getRateValue())){ + t2powerFee = xhpcRate.getPowerFee(); + t2serviceFee =xhpcRate.getServiceFee(); + } + if("02".equals(xhpcRate.getRateValue())){ + t3powerFee = xhpcRate.getPowerFee(); + t3serviceFee = xhpcRate.getServiceFee(); + } + if("03".equals(xhpcRate.getRateValue())){ + t4powerFee = xhpcRate.getPowerFee(); + t4serviceFee =xhpcRate.getServiceFee(); + } } - BigDecimal chargingDegree = new BigDecimal(endData.getChargingDegree()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP); - message.put("chargingDegree",chargingDegree); - - chargeOrder.setStartTime(startTime); - chargeOrder.setEndTime(endTime); - chargeOrder.setStartSoc(startData.getSoc().toString()); - chargeOrder.setEndSoc(endData.getSoc().toString()); - chargeOrder.setChargingTimeNumber(tiem); - chargeOrder.setChargingDegree(chargingDegree); - chargeOrder.setType("平台停止"); - chargeOrder.setAmountCharged(new BigDecimal(endData.getAmountCharged()).divide(new BigDecimal(10000),2,BigDecimal.ROUND_HALF_UP)); + BigDecimal powerPrice =new BigDecimal(0); + BigDecimal servicePrice =new BigDecimal(0); + //因桩有误差,电费和服务费重新计算 + if(!"0".equals(cacheOrderData.getT1PowerQuantity().toString())){ + BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(t1powerFee).setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(t1serviceFee).setScale(2, BigDecimal.ROUND_HALF_UP); + powerPrice=powerPrice.add(multiply1); + servicePrice=servicePrice.add(multiply2); + } + if(!"0".equals(cacheOrderData.getT2PowerQuantity().toString())){ + BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(t2powerFee).setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(t2serviceFee).setScale(2, BigDecimal.ROUND_HALF_UP); + powerPrice=powerPrice.add(multiply1); + servicePrice=servicePrice.add(multiply2); + } + if(!"0".equals(cacheOrderData.getT3PowerQuantity().toString())){ + BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(t3powerFee).setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(t3serviceFee).setScale(2, BigDecimal.ROUND_HALF_UP); + powerPrice=powerPrice.add(multiply1); + servicePrice=servicePrice.add(multiply2); + } + if(!"0".equals(cacheOrderData.getT4PowerQuantity().toString())){ + BigDecimal multiply1 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(t4powerFee).setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal multiply2 = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(t4serviceFee).setScale(2, BigDecimal.ROUND_HALF_UP); + powerPrice=powerPrice.add(multiply1); + servicePrice=servicePrice.add(multiply2); + } + powerPrice =powerPrice.setScale(2,BigDecimal.ROUND_HALF_UP); + //总服务费 + servicePrice =servicePrice.setScale(2,BigDecimal.ROUND_HALF_UP); + message.put("powerPriceTotal",powerPrice); + message.put("servicePriceTotal",servicePrice); + chargeOrder.setStartTime(DateUtil.parse(cacheOrderData.getStartTime())); + chargeOrder.setEndTime(DateUtil.parse(cacheOrderData.getEndTime())); + if(cacheOrderData.getStartSoc() !=null){ + chargeOrder.setStartSoc(cacheOrderData.getStartSoc()+""); + } + if(cacheOrderData.getEndTime() !=null){ + chargeOrder.setEndSoc(cacheOrderData.getEndSoc()+""); + } + if(cacheOrderData.getTotalPowerQuantity() !=null){ + BigDecimal chargingDegree1 = new BigDecimal(cacheOrderData.getTotalPowerQuantity()).divide(bigDecimal,2,BigDecimal.ROUND_HALF_UP); + chargeOrder.setChargingDegree(chargingDegree1); + } + chargeOrder.setAmountCharged(money); }else{ - //当没有缓存数据时,查询数据库 - XhpcRealTimeOrder startRealTimeOrder = xhpcRealTimeOrderMapper.getChargingOrderId(chargeOrder.getChargeOrderId(), 1); - - if(startRealTimeOrder ==null){ - message.put("powerPriceTotal",0); - message.put("servicePriceTotal",0); - return message; - } - XhpcRealTimeOrder endRealTimeOrder = xhpcRealTimeOrderMapper.getChargingOrderId(chargeOrder.getChargeOrderId(), 2); - - message.put("soc",endRealTimeOrder.getSoc()); - //最后一祯时间 - Date endTime = endRealTimeOrder.getCreateTime(); - Date startTime = startRealTimeOrder.getCreateTime(); - - BigDecimal chargingDegree = endRealTimeOrder.getChargingDegree(); - message.put("chargingDegree",chargingDegree); - chargeOrder.setChargingTime(endRealTimeOrder.getChargingTime()); - message.put("chargingTime",endRealTimeOrder.getChargingTime()); - - if(startRealTimeOrder.getRealTimeOrderId().equals(startRealTimeOrder.getRealTimeOrderId())){ - message.put("powerPriceTotal",0); - message.put("servicePriceTotal",0); - return message; - } - - chargeOrder.setStartTime(startTime); - chargeOrder.setEndTime(endTime); - chargeOrder.setStartSoc(startRealTimeOrder.getSoc()); - chargeOrder.setEndSoc(endRealTimeOrder.getSoc()); - Integer chargingTimeNumber = endRealTimeOrder.getChargingTimeNumber(); - if(chargingTimeNumber>0){ - chargeOrder.setChargingTimeNumber(Long.valueOf(chargingTimeNumber*60)); + if (cacheMap.get("startTime")!=null && cacheMap.get("lastOrderTime")!=null) { + chargeOrder.setStartTime(DateUtil.parse(cacheMap.get("startTime").toString())); + chargeOrder.setEndTime(DateUtil.parse(cacheMap.get("lastOrderTime").toString())); + if (cacheMap.get("totalPower")!=null && cacheMap.get("totalMoney")!=null) { + String totalPower = cacheMap.get("totalPower").toString(); + //String totalPowerSub = totalPower.substring(0, totalPower.length() - 1); + String totalMoney = cacheMap.get("totalMoney").toString(); + chargeOrder.setChargingDegree(new BigDecimal(totalPower)); + chargeOrder.setAmountCharged(new BigDecimal(totalMoney)); + } }else{ - chargeOrder.setChargingTimeNumber(0L); + //没有获取到时间 1.获取缓存数据 2.缓存没有获取数据库数据 + List list = (List) cacheMap.get("realtimeDataList"); + + CacheRealtimeData startData =new CacheRealtimeData(); + CacheRealtimeData endData =new CacheRealtimeData(); + + if (list != null && list.size() > 0) { + endData =list.get(list.size()-1); + for (int i = 0; i 0){ + break; + } + } + } + if(endData !=null && endData.getAmountCharged() !=null && startData.getChargingTime()>0){ + //最后一祯时间 + Date endTime = DateUtil.parse(endData.getCreateTime()); + Date startTime =DateUtil.parse(startData.getCreateTime()); + //充电时长 + BigDecimal chargingDegree = new BigDecimal(endData.getChargingDegree()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP); + chargeOrder.setStartTime(startTime); + chargeOrder.setEndTime(endTime); + chargeOrder.setStartSoc(startData.getSoc().toString()); + chargeOrder.setEndSoc(endData.getSoc().toString()); + chargeOrder.setChargingDegree(chargingDegree); + chargeOrder.setAmountCharged(new BigDecimal(endData.getAmountCharged()).divide(new BigDecimal(10000),2,BigDecimal.ROUND_HALF_UP)); + }else{ + //当没有缓存数据时,查询数据库 + XhpcRealTimeOrder startRealTimeOrder = xhpcRealTimeOrderMapper.getChargingOrderId(chargeOrder.getChargeOrderId(), 1); + if(startRealTimeOrder ==null){ + message.put("powerPriceTotal",0); + message.put("servicePriceTotal",0); + return message; + } + XhpcRealTimeOrder endRealTimeOrder = xhpcRealTimeOrderMapper.getChargingOrderId(chargeOrder.getChargeOrderId(), 2); + //最后一祯时间 + Date endTime = endRealTimeOrder.getCreateTime(); + Date startTime = startRealTimeOrder.getCreateTime(); + BigDecimal chargingDegree = endRealTimeOrder.getChargingDegree(); + chargeOrder.setChargingTime(endRealTimeOrder.getChargingTime()); + if(startRealTimeOrder.getRealTimeOrderId().equals(startRealTimeOrder.getRealTimeOrderId())){ + message.put("powerPriceTotal",0); + message.put("servicePriceTotal",0); + return message; + } + chargeOrder.setStartTime(startTime); + chargeOrder.setEndTime(endTime); + chargeOrder.setStartSoc(startRealTimeOrder.getSoc()); + chargeOrder.setEndSoc(endRealTimeOrder.getSoc()); + Integer chargingTimeNumber = endRealTimeOrder.getChargingTimeNumber(); + if(chargingTimeNumber>0){ + chargeOrder.setChargingTimeNumber(Long.valueOf(chargingTimeNumber*60)); + }else{ + chargeOrder.setChargingTimeNumber(0L); + } + chargeOrder.setChargingDegree(chargingDegree); + + chargeOrder.setAmountCharged(endRealTimeOrder.getAmountCharged()); + } + } + Date startTime2 = chargeOrder.getStartTime(); + Date updateTime2 = chargeOrder.getEndTime(); + BigDecimal amountCharged = chargeOrder.getAmountCharged(); + //充电度数 + BigDecimal chargingDegree = chargeOrder.getChargingDegree(); + BigDecimal powerPriceTotal =new BigDecimal(0); + //1时间没有跨天 + DateTime parse = DateUtil.parse(DateUtil.format(startTime2, "yyyy-MM-dd"), "yyyy-MM-dd"); + DateTime parse1 = DateUtil.parse(DateUtil.format(updateTime2, "yyyy-MM-dd"), "yyyy-MM-dd"); + //每分钟多少度电 + BigDecimal decimal = new BigDecimal((updateTime2.getTime() - startTime2.getTime())).divide(new BigDecimal(60000),4,BigDecimal.ROUND_HALF_UP); + BigDecimal divide = chargingDegree.divide(decimal,4,BigDecimal.ROUND_HALF_UP); + long betweenDay = DateUtil.between(parse,parse1, DateUnit.DAY); + if(betweenDay==0){ + powerPriceTotal = getBigDecimal(rateModelId,DateUtil.formatTime(startTime2), DateUtil.formatTime(updateTime2), powerPriceTotal, divide); + }else{ + //跨天 + powerPriceTotal = getBigDecimal(rateModelId, DateUtil.formatTime(startTime2), "23:59:59", powerPriceTotal, divide); + System.out.println(">>>>>>跨天前>>>>>>>"+powerPriceTotal); + //明天 + DateTime tomorrow = DateUtil.offsetDay(startTime2,1); + Date startTime3 = DateUtil.beginOfDay(tomorrow); + powerPriceTotal = getBigDecimal(rateModelId, DateUtil.formatTime(startTime3), DateUtil.formatTime(updateTime2), powerPriceTotal, divide); + System.out.println(">>>>>>跨天后>>>>>>>"+powerPriceTotal); + } + //算服务费和电费 + if(amountCharged.compareTo(powerPriceTotal)>-1){ + BigDecimal servicePriceTotal =amountCharged.subtract(powerPriceTotal); + message.put("powerPriceTotal",powerPriceTotal); + message.put("servicePriceTotal",servicePriceTotal); + }else{ + message.put("powerPriceTotal",amountCharged); + message.put("servicePriceTotal",0); } - chargeOrder.setChargingDegree(chargingDegree); - chargeOrder.setType("平台停止充电"); - chargeOrder.setAmountCharged(endRealTimeOrder.getAmountCharged()); - } - Date startTime2 = chargeOrder.getStartTime(); - Date updateTime2 = chargeOrder.getEndTime(); - BigDecimal amountCharged = chargeOrder.getAmountCharged(); - //充电度数 - BigDecimal chargingDegree = chargeOrder.getChargingDegree(); - BigDecimal powerPriceTotal =new BigDecimal(0); - //1时间没有跨天 - DateTime parse = DateUtil.parse(DateUtil.format(startTime2, "yyyy-MM-dd"), "yyyy-MM-dd"); - DateTime parse1 = DateUtil.parse(DateUtil.format(updateTime2, "yyyy-MM-dd"), "yyyy-MM-dd"); - //每分钟多少度电 - BigDecimal decimal = new BigDecimal((updateTime2.getTime() - startTime2.getTime())).divide(new BigDecimal(60000),4,BigDecimal.ROUND_HALF_UP); - BigDecimal divide = chargingDegree.divide(decimal,4,BigDecimal.ROUND_HALF_UP); - long betweenDay = DateUtil.between(parse,parse1, DateUnit.DAY); - if(betweenDay==0){ - powerPriceTotal = getBigDecimal(rateModelId,DateUtil.formatTime(startTime2), DateUtil.formatTime(updateTime2), powerPriceTotal, divide); + message.put("chargingDegree",chargeOrder.getChargingDegree()); + Long tiem = (chargeOrder.getEndTime().getTime() - chargeOrder.getStartTime().getTime()) / 1000; + if (tiem > 3600) { + long hours = tiem / 3600; + double mins = (double) ((tiem - (hours * 3600)) / 60); + message.put("chargingTime",hours + "时" + new BigDecimal(mins).setScale(0) + "分"); + chargeOrder.setChargingTime(hours + "时" + new BigDecimal(mins).setScale(0) + "分"); + } else { + double mins = (double) (tiem / 60); + message.put("chargingTime",new BigDecimal(mins).setScale(0) + "分"); + chargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "分"); + } + message.put("startSoc",chargeOrder.getStartSoc()); + message.put("endSoc",chargeOrder.getEndSoc()); + + if(cacheMap.get("stopReasonHex") !=null && "".equals(cacheMap.get("stopReasonHex").toString())){ + chargeOrder.setType(cacheMap.get("stopReasonHex").toString()); }else{ - //跨天 - powerPriceTotal = getBigDecimal(rateModelId, DateUtil.formatTime(startTime2), "23:59:59", powerPriceTotal, divide); - System.out.println(">>>>>>跨天前>>>>>>>"+powerPriceTotal); - //明天 - DateTime tomorrow = DateUtil.offsetDay(startTime2,1); - Date startTime3 = DateUtil.beginOfDay(tomorrow); - powerPriceTotal = getBigDecimal(rateModelId, DateUtil.formatTime(startTime3), DateUtil.formatTime(updateTime2), powerPriceTotal, divide); - System.out.println(">>>>>>跨天后>>>>>>>"+powerPriceTotal); + chargeOrder.setType("90"); } - - //算服务费和电费 - if(amountCharged.compareTo(powerPriceTotal)>-1){ - BigDecimal servicePriceTotal =amountCharged.subtract(powerPriceTotal); - message.put("powerPriceTotal",powerPriceTotal); - message.put("servicePriceTotal",servicePriceTotal); - }else{ - message.put("powerPriceTotal",amountCharged); - message.put("servicePriceTotal",0); - } - + message.put("startTime",chargeOrder.getStartTime()); + message.put("endTime",chargeOrder.getEndTime()); //修改充电订单 xhpcChargeOrderService.updateXhpcChargeOrder(chargeOrder); }catch (Exception e){ + e.printStackTrace(); + logger.info("======================异常订单审核异常======================="); message.put("powerPriceTotal",0); message.put("servicePriceTotal",0); } @@ -334,6 +495,10 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder); return AjaxResult.success(); } + if(xhpcChargeOrder.getRateModelId()==null || "".equals(xhpcChargeOrder.getRateModelId())){ + Map xhpcChargingStationMap = xhpcRealTimeOrderMapper.getXhpcChargingStationById(xhpcChargeOrder.getChargingStationId()); + xhpcChargeOrder.setRateModelId(Long.valueOf(xhpcChargingStationMap.get("rateModelId").toString())); + } //总金额 BigDecimal money = powerPrice.add(servicePrice); //总服务费 servicePrice @@ -1535,6 +1700,8 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe xhpcHistoryOrderService.insert(xhpcHistoryOrder); } + + private BigDecimal getBigDecimal(Long rateModelId, String startTime, String updateTime, BigDecimal powerPriceTotal, BigDecimal divide) { if("00:00:00".equals(updateTime)){ updateTime="23:59:59"; diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcStatisticsServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcStatisticsServiceImpl.java index fec783a7..bad847da 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcStatisticsServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcStatisticsServiceImpl.java @@ -1530,6 +1530,7 @@ public class XhpcStatisticsServiceImpl extends BaseService implements IXhpcStati int freeTime =0;//空闲 int charge =0;//充电 int unknown =0;//未知 + int insertGun =0;//已插枪 if(terminal !=null && terminal.size()>0){ for (String st:terminal) { Map cacheMap = redisService.getCacheMap("gun:" + st); @@ -1542,7 +1543,11 @@ public class XhpcStatisticsServiceImpl extends BaseService implements IXhpcStati fault++; }else if(cacheMap.containsKey("status") && "空闲".equals(cacheMap.get("status").toString())){ - freeTime++; + if("是".equals(cacheMap.get("vehicleGunStatus").toString())){ + insertGun++; + }else{ + freeTime++; + } }else{ charge++; } @@ -1586,6 +1591,12 @@ public class XhpcStatisticsServiceImpl extends BaseService implements IXhpcStati mapList4.add(objectMap4); mapList.addAll(mapList4); + List> mapList5 =new ArrayList<>(); + Map objectMap5 =new HashMap<>(); + objectMap5.put("name","已插枪"); + objectMap5.put("value",insertGun); + mapList5.add(objectMap5); + mapList.addAll(mapList5); return mapList; } diff --git a/xhpc-modules/xhpc-order/src/main/resources/bootstrap.yml b/xhpc-modules/xhpc-order/src/main/resources/bootstrap.yml index fca35f2a..a45f7112 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/bootstrap.yml +++ b/xhpc-modules/xhpc-order/src/main/resources/bootstrap.yml @@ -14,10 +14,10 @@ spring: nacos: discovery: # 服务注册地址 - server-addr: 172.31.183.135:8848 + server-addr: mse-e2a05960-nacos-ans.mse.aliyuncs.com:8848 config: # 配置中心地址 - server-addr: 172.31.183.135:8848 + server-addr: mse-e2a05960-nacos-ans.mse.aliyuncs.com:8848 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml index b4e0504e..0ae07f9a 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml @@ -1162,7 +1162,7 @@ and ho.total_price >=0 - order by ho.create_time desc + order by ho.end_time desc + + + diff --git a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcRealTimeOrderMapper.xml b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcRealTimeOrderMapper.xml index bf4de915..35107998 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcRealTimeOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcRealTimeOrderMapper.xml @@ -212,6 +212,105 @@ + + insert into xhpc_real_time_order_bms + + + order_no, + + + pile_no, + + + gun_id, + + + bms_voltage_request, + + + bms_current_request, + + + bms_charging_mod, + + + bms_charging_volt, + + + bms_charging_current, + + + soc, + + + bms_est_remaining_time, + + + pile_voltage_output, + + + pile_current_output, + + + charging_time_summary, + + + mono_battery_volt_groupId, + + + charging_order_id, + + + + + #{orderNo}, + + + #{pileNo}, + + + #{gunId}, + + + #{bmsVoltageRequest}, + + + #{bmsCurrentRequest}, + + + #{bmsChargingMod}, + + + #{monoBatteryVolt}, + + + #{bmsChargingCurrent}, + + + #{soc}, + + + #{bmsEstRemainingTime}, + + + #{pileVoltageOutput}, + + + #{pileCurrentOutput}, + + + #{chargingTimeSummary}, + + + #{monoBatteryVoltGroupId}, + + + #{chargingOrderId}, + + + + + insert into xhpc_charge_order_soc @@ -547,6 +646,13 @@ where ro.real_time_order_id=#{realTimeOrderId} + + + + +