From feccc684b55bd3b4f35f2684f9b8ba2d43a7d226 Mon Sep 17 00:00:00 2001 From: yuyang <2265829957@qq.com> Date: Fri, 10 Sep 2021 15:35:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=9E=E6=97=B6=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=85=B1=E6=9C=89=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=B0=8F?= =?UTF-8?q?=E6=97=B6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/constant/ServiceNameConstants.java | 4 + .../com/xhpc/common/api/WebSocketService.java | 26 ++ .../api/factory/WebSocketFallbackFactory.java | 28 ++ .../xhpc/order/domain/XhpcHistoryOrder.java | 5 + .../order/api/XhpcChargeOrderController.java | 14 +- .../order/api/XhpcPileOrderController.java | 2 +- .../XhpcHistoryOrderController.java | 342 ++++++++++-------- .../domain/XhpcStatisticsTimeInterval.java | 15 + .../service/IXhpcRealTimeOrderService.java | 3 +- .../impl/XhpcChargeOrderServiceImpl.java | 3 +- .../impl/XhpcHistoryOrderServiceImpl.java | 3 +- .../impl/XhpcRealTimeOrderServiceImpl.java | 5 +- .../impl/XhpcStatisticsServiceImpl.java | 2 +- .../mapper/XhpcHistoryOrderMapper.xml | 10 +- .../resources/mapper/XhpcStatisticsMapper.xml | 10 +- .../OrderNotificationWebSocketController.java | 6 + .../xhpc/wxma/rabbitm/RabbitmConsumer.java | 9 + 17 files changed, 314 insertions(+), 173 deletions(-) create mode 100644 xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/WebSocketService.java create mode 100644 xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/WebSocketFallbackFactory.java diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/ServiceNameConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/ServiceNameConstants.java index 91dd9b68..9a9ff54e 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/ServiceNameConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/xhpc/common/core/constant/ServiceNameConstants.java @@ -33,6 +33,10 @@ public class ServiceNameConstants */ public static final String XHPC_ORDER ="xhpc-order"; + /** + * 订单服务 + */ + public static final String XHPC_WXMA ="xhpc-wxma"; /** * 通用服务 */ diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/WebSocketService.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/WebSocketService.java new file mode 100644 index 00000000..8dc77894 --- /dev/null +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/WebSocketService.java @@ -0,0 +1,26 @@ +package com.xhpc.common.api; + +import com.xhpc.common.api.factory.WebSocketFallbackFactory; +import com.xhpc.common.core.constant.ServiceNameConstants; +import com.xhpc.common.core.domain.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author yuyang + * @date 2021/9/10 15:13 + * @Version 1.0 + */ +@FeignClient(contextId ="webSocketService",value = ServiceNameConstants.XHPC_WXMA, fallbackFactory = WebSocketFallbackFactory.class) +public interface WebSocketService { + + /** + * 发送实时数据接口 + * @param userId 接收用户 + * @param message 接收信息 + * @return + */ + @GetMapping("/orderWebSocket/getMessage") + R getMessage(@RequestParam(value = "userId") String userId, @RequestParam(value = "message") String message); +} diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/WebSocketFallbackFactory.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/WebSocketFallbackFactory.java new file mode 100644 index 00000000..637b3efb --- /dev/null +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/factory/WebSocketFallbackFactory.java @@ -0,0 +1,28 @@ +package com.xhpc.common.api.factory; + +import com.xhpc.common.api.WebSocketService; +import com.xhpc.common.core.domain.R; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; + +/** + * @author yuyang + * @date 2021/9/10 15:14 + * @Version 1.0 + */ +public class WebSocketFallbackFactory implements FallbackFactory { + + private static final Logger logger = LoggerFactory.getLogger(WebSocketFallbackFactory.class); + + @Override + public WebSocketService create(Throwable cause){ + logger.error("消息发送调用失败:{}//fallback",cause.getMessage()); + return new WebSocketService() { + @Override + public R getMessage(String userId, String message) { + return R.fail("消息发送调用失败:" + cause.getMessage()); + } + }; + } +} diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/order/domain/XhpcHistoryOrder.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/order/domain/XhpcHistoryOrder.java index c923bd5e..9e686ec5 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/order/domain/XhpcHistoryOrder.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/order/domain/XhpcHistoryOrder.java @@ -158,4 +158,9 @@ public class XhpcHistoryOrder extends BaseEntity { * 0未统计 1已统计 */ private Integer state; + + /** + * VIN 码 + */ + private String vinNormal; } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcChargeOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcChargeOrderController.java index 9b580b3e..47039883 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcChargeOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/api/XhpcChargeOrderController.java @@ -1,8 +1,10 @@ package com.xhpc.order.api; +import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONObject; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; +import com.xhpc.common.api.WebSocketService; import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.page.TableDataInfo; @@ -10,6 +12,7 @@ import com.xhpc.common.util.ConnectionRabbitMQUtil; import com.xhpc.order.service.IXhpcChargeOrderService; import com.xhpc.order.service.IXhpcHistoryOrderService; import io.swagger.annotations.Api; +import org.checkerframework.checker.units.qual.A; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -19,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; +import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,6 +40,8 @@ public class XhpcChargeOrderController extends BaseController { private IXhpcChargeOrderService iXhpcChargeOrderService; @Autowired private IXhpcHistoryOrderService xhpcHistoryOrderService; + @Autowired + private WebSocketService webSocketService; private static final Logger logger = LoggerFactory.getLogger(XhpcChargeOrderController.class); /** @@ -130,6 +136,8 @@ public class XhpcChargeOrderController extends BaseController { logger.info("<<<<<<<<<<再次<<<<<<<<<<<<<实时数据接口>>>>>>>>>>>>>>>>>>"+userId); logger.info("<<<<<<<<<<再次<<<<<<<<<<<<<<实时数据接口>>>>>>>>>>>>>>>>>"+userId); logger.info("<<<<<<<<<<再次<<<<<<<<<<<<<<实时数据接口>>>>>>>>>>>>>>>>>"); + logger.info("<<<<<<<<<<接收时间<<<<<<<<<<<<<<"+ DateUtil.format(Calendar.getInstance().getTime(), "yyyy-MM-dd HH:mm:ss")+">>>>>>>>>>>>>>>>>"); + Map orderMessage = iXhpcChargeOrderService.getOrderMessage(userId); Map map =new HashMap<>(); map.put("code", 200); @@ -155,11 +163,9 @@ public class XhpcChargeOrderController extends BaseController { }else{ map.put("data",orderMessage); } - JSONObject json = new JSONObject(map); - - logger.info("<<<<<<<<<<再次<<<<<<<<<<<<<>>>>>>>>>>>>>>>>"+json.toString()); - rabbimt(userId + "##" + json); + webSocketService.getMessage(""+userId,json.toString()); + logger.info("<<<<<<<<<<发送时间<<<<<<<<<<<<<<"+ DateUtil.format(Calendar.getInstance().getTime(), "yyyy-MM-dd HH:mm:ss")+">>>>>>>>>>>>>>>>>"); } private void rabbimt(String message) { 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 cc699745..efd524e8 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 @@ -331,7 +331,7 @@ public class XhpcPileOrderController extends BaseController { R.ok(); } //结算 - xhpcRealTimeOrderService.addSettlement(powerPrice,servicePrice,money,surplusPowerPrice,surplusServicePrice,xhpcChargeOrder,userId,userMessage,1); + xhpcRealTimeOrderService.addSettlement(powerPrice,servicePrice,money,surplusPowerPrice,surplusServicePrice,xhpcChargeOrder,userId,userMessage,1,cacheOrderData.getVinNormal()); Map map = new HashMap<>(); map.put("code", 500); map.put("userId", userId); diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java index 8365c805..59218eae 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcHistoryOrderController.java @@ -1,5 +1,6 @@ package com.xhpc.order.controller; +import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import com.xhpc.common.core.web.controller.BaseController; @@ -76,180 +77,207 @@ public class XhpcHistoryOrderController extends BaseController { public void test(){ //获取500条待统计历史订单 //跨时段,跨费率,计费模型 - //小时统计、日期统计、电站统计、终端统计、运营商统计、流量方统计 + //小时统计 List list = xhpcHistoryOrderService.getStatistisList(500); if(list !=null && list.size()>0){ - //开始时间和结束时间之差,是否超过 30分钟 - for (XhpcChargeHistoryOrder xhpcChargeHistoryOrder:list) { - Date startTime = xhpcChargeHistoryOrder.getStartTime(); - Date endTime = xhpcChargeHistoryOrder.getEndTime(); - Long rateModelId = xhpcChargeHistoryOrder.getRateModelId(); - int source = xhpcChargeHistoryOrder.getSource(); - Long userId =xhpcChargeHistoryOrder.getUserId(); - Long operatorId =xhpcChargeHistoryOrder.getOperatorId(); - Long chargeOrderId =xhpcChargeHistoryOrder.getChargeOrderId(); - Long chargingStationId = xhpcChargeHistoryOrder.getChargingStationId(); - Long terminalId = xhpcChargeHistoryOrder.getTerminalId(); + for (XhpcChargeHistoryOrder xhpc:list) { + //开始时间、结束时间、模型id、状态、用户id、运营商、订单id、场站id、终端id、历史订单id、时间 + Date startTime = xhpc.getStartTime(); + Date endTime = xhpc.getEndTime(); + Long rateModelId = xhpc.getRateModelId(); + Long operatorId =xhpc.getOperatorId(); + Long chargingStationId = xhpc.getChargingStationId(); + Long terminalId = xhpc.getTerminalId(); + Long historyOrderId = xhpc.getHistoryOrderId(); Date data = Calendar.getInstance().getTime(); - //充电时长 - Long chargingTimeNumber =xhpcChargeHistoryOrder.getChargingTimeNumber(); - - long betweenDay = DateUtil.between(DateUtil.parse(xhpcChargeHistoryOrder.getStartTime().toString(), "yyyy-MM-dd"), DateUtil.parse(xhpcChargeHistoryOrder.getEndTime().toString(), "yyyy-MM-dd"), DateUnit.DAY); + //1时间没有跨天 + DateTime parse = DateUtil.parse(DateUtil.format(startTime, "yyyy-MM-dd"), "yyyy-MM-dd"); + DateTime parse1 = DateUtil.parse(DateUtil.format(endTime, "yyyy-MM-dd"), "yyyy-MM-dd"); + long betweenDay = DateUtil.between(parse,parse1, DateUnit.DAY); if(betweenDay==0){ //没有跨天 - //获取费率 - //电费 - BigDecimal powerPrice =xhpcChargeHistoryOrder.getActPowerPrice(); - //服务费 - BigDecimal servicePrice =xhpcChargeHistoryOrder.getActServicePrice(); - //订单总价 - BigDecimal totalPrice =xhpcChargeHistoryOrder.getTotalPrice(); - //电站活动抵扣--抵扣的总金额 - BigDecimal promotionDiscount =xhpcChargeHistoryOrder.getPromotionDiscount(); - //实际价格-用户支付的钱 - BigDecimal actPrice =xhpcChargeHistoryOrder.getActPrice(); - //实收电费-运营商电费 - BigDecimal actPowerPrice =xhpcChargeHistoryOrder.getActPowerPrice(); - //实收服务费-运营商服务费 - BigDecimal actServicePrice =xhpcChargeHistoryOrder.getActServicePrice(); - //流量方总金额抽成 - BigDecimal internetCommission =xhpcChargeHistoryOrder.getInternetCommission(); - //流量方服务费抽成 - BigDecimal internetSvcCommission =xhpcChargeHistoryOrder.getInternetSvcCommission(); - //平台总金额抽成 - BigDecimal platformCommission =xhpcChargeHistoryOrder.getPlatformCommission(); - //平台服务费抽成 - BigDecimal platformSvcCommission =xhpcChargeHistoryOrder.getPlatformSvcCommisssion(); - //运维总抽成 - BigDecimal operationCommission =xhpcChargeHistoryOrder.getOperationCommission(); - //运维服务费抽成 - BigDecimal operationSvcCommission =xhpcChargeHistoryOrder.getOperationSvcCommission(); - //每分钟都少钱 - BigDecimal pp1 = powerPrice.divide(new BigDecimal(chargingTimeNumber / 60), 2, RoundingMode.HALF_UP); - BigDecimal sp1 = servicePrice.divide(new BigDecimal(chargingTimeNumber / 60), 2, RoundingMode.HALF_UP); - - String startTime1 = DateUtil.formatTime(startTime); - String endTime1 = DateUtil.formatTime(endTime); + //是否跨时段 int startHour = DateUtil.hour(startTime, true); int endHour = DateUtil.hour(endTime, true); if(endHour==startHour){ //没有跨时段 - XhpcStatisticsTimeInterval xhpc = new XhpcStatisticsTimeInterval(); - xhpc.setStatus(endHour+1); - xhpc.setChargingDegree(xhpcChargeHistoryOrder.getChargingDegree()); - xhpc.setChargingTime(new BigDecimal(chargingTimeNumber/3600).setScale(2, RoundingMode.HALF_UP)); - xhpc.setChargingNumber(1); - xhpc.setPowerPrice(powerPrice); - xhpc.setServicePrice(servicePrice); - xhpc.setTotalPrice(totalPrice); - xhpc.setPromotionDiscount(promotionDiscount); - xhpc.setActPrice(actPrice); - xhpc.setActPowerPrice(actPowerPrice); - xhpc.setActServicePrice(actServicePrice); - xhpc.setInternetCommission(internetCommission); - xhpc.setInternetSvcCommission(internetSvcCommission); - xhpc.setPlatformCommission(platformCommission); - xhpc.setPlatformSvcCommisssion(platformSvcCommission); - xhpc.setOperationCommission(operationCommission); - xhpc.setOperationSvcCommission(operationSvcCommission); - xhpc.setOperatorId(chargeOrderId); - xhpc.setChargingStationId(chargingStationId); - xhpc.setCreateTime(data); - xhpc.setTerminalId(terminalId); - xhpcStatisticsService.addStatisticsTime(xhpc); - //修改历史订单表状态 - XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder(); - xhpcHistoryOrder.setHistoryOrderId(xhpcChargeHistoryOrder.getHistoryOrderId()); - xhpcHistoryOrder.setState(1); - xhpcHistoryOrderService.update(xhpcHistoryOrder); - }else{ - - //跨时段,跨多少时段,每个时段单独算 - //每个时段折扣 - BigDecimal pd = new BigDecimal(0); - if(promotionDiscount.compareTo(pd)==1){ - pd = promotionDiscount.divide(new BigDecimal(endHour + 1)); - } - for (int i = startHour; i <=endHour+1 ; i++) { - //获取费率 - if(i==startHour){ - String end=i+1+":59:59"; - long time1 = DateUtil.parse(end).getTime(); - long time2 = DateUtil.parse(startTime1).getTime(); - BigDecimal time = new BigDecimal((time1-time2)/6000); - - List> reatTimeList = xhpcHistoryOrderService.getReatTimeList(startTime1, end, rateModelId); - if(reatTimeList!=null && reatTimeList.size()>0){ - if(reatTimeList.size()==1){ - XhpcStatisticsTimeInterval xhpc = new XhpcStatisticsTimeInterval(); - xhpc.setStatus(endHour+1); - xhpc.setChargingDegree(xhpcChargeHistoryOrder.getChargingDegree()); - xhpc.setChargingTime(new BigDecimal(chargingTimeNumber/3600).setScale(2, RoundingMode.HALF_UP)); - xhpc.setChargingNumber(1); - BigDecimal decimal1 = time.multiply(pp1).setScale(2, RoundingMode.HALF_UP); - BigDecimal decimal2 = time.multiply(sp1).setScale(2, RoundingMode.HALF_UP); - xhpc.setPowerPrice(decimal1); - xhpc.setServicePrice(decimal2); - xhpc.setTotalPrice(decimal1.add(decimal2)); - xhpc.setPromotionDiscount(pd); - xhpc.setActPrice(decimal1.add(decimal2).subtract(pd)); - - - powerPrice.subtract(decimal1); - servicePrice.subtract(decimal2); - - - - - - - - - - - - xhpc.setActPowerPrice(xhpcChargeHistoryOrder.getActPowerPrice()); - xhpc.setActServicePrice(xhpcChargeHistoryOrder.getActServicePrice()); - xhpc.setInternetCommission(xhpcChargeHistoryOrder.getInternetCommission()); - xhpc.setInternetSvcCommission(xhpcChargeHistoryOrder.getInternetSvcCommission()); - xhpc.setPlatformCommission(xhpcChargeHistoryOrder.getPlatformCommission()); - xhpc.setPlatformSvcCommisssion(xhpcChargeHistoryOrder.getPlatformSvcCommisssion()); - xhpc.setOperationCommission(xhpcChargeHistoryOrder.getOperationCommission()); - xhpc.setOperationSvcCommission(xhpcChargeHistoryOrder.getOperationSvcCommission()); - xhpc.setOperatorId(xhpcChargeHistoryOrder.getOperatorId()); - xhpc.setChargingStationId(xhpcChargeHistoryOrder.getChargingStationId()); - xhpc.setCreateTime(data); - xhpc.setTerminalId(xhpcChargeHistoryOrder.getTerminalId()); - xhpcStatisticsService.addStatisticsTime(xhpc); - //修改历史订单表状态 - XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder(); - xhpcHistoryOrder.setHistoryOrderId(xhpcChargeHistoryOrder.getHistoryOrderId()); - xhpcHistoryOrder.setState(1); - xhpcHistoryOrderService.update(xhpcHistoryOrder); - } - } - }else{ - String sta=i+":00:00"; - String end=i+1+":59:59"; - } - - - - - - - - + XhpcStatisticsTimeInterval xhpcSt = new XhpcStatisticsTimeInterval(); + xhpcSt.setStatus(endHour+1); + xhpcSt.setChargingDegree(xhpc.getChargingDegree()); + xhpcSt.setChargingTime(new BigDecimal(xhpc.getChargingTimeNumber()/3600).setScale(2, RoundingMode.HALF_UP)); + xhpcSt.setChargingNumber(1); + xhpcSt.setPowerPrice(xhpc.getActPowerPrice()); + xhpcSt.setServicePrice(xhpc.getActServicePrice()); + xhpcSt.setTotalPrice(xhpc.getTotalPrice()); + xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount()); + xhpcSt.setActPrice(xhpc.getActPrice()); + xhpcSt.setActPowerPrice(xhpc.getActPowerPrice()); + xhpcSt.setActServicePrice(xhpc.getActServicePrice()); + xhpcSt.setInternetCommission(xhpc.getInternetCommission()); + xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission()); + xhpcSt.setPlatformCommission(xhpc.getPlatformCommission()); + xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion()); + xhpcSt.setOperationCommission(xhpc.getOperationCommission()); + xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission()); + xhpcSt.setOperatorId(operatorId); + xhpcSt.setChargingStationId(chargingStationId); + xhpcSt.setCreateTime(data); + xhpcSt.setTerminalId(terminalId); + xhpcSt.setHistoryOrderId(historyOrderId); + if(xhpc.getSource()==1){ + xhpcSt.setInternetUserId(xhpc.getUserId()); } + xhpcStatisticsService.addStatisticsTime(xhpcSt); + }else { + //跨时段 + //总共时段 endHour+1-startHour + addStatisTime(xhpc, startTime, endTime, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, startHour, endHour); } + }else{ + //跨天 + Date updateTime2= DateUtil.parse(parse+" 23:59:59"); + int startHour = DateUtil.hour(startTime, true); + int endHour = DateUtil.hour(updateTime2, true); + addInterval(xhpc, startTime, updateTime2, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, startHour, endHour); + //明天 + DateTime tomorrow = DateUtil.offsetDay(startTime,1); + Date startTime3 =DateUtil.beginOfDay(tomorrow); + int startHour1 = DateUtil.hour(startTime3, true); + int endHour1 = DateUtil.hour(endTime, true); + addInterval(xhpc, startTime3, endTime, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, startHour1, endHour1); + } + //修改状态 + //修改历史订单表状态 + XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder(); + xhpcHistoryOrder.setHistoryOrderId(xhpc.getHistoryOrderId()); + xhpcHistoryOrder.setState(1); + xhpcHistoryOrderService.update(xhpcHistoryOrder); + } + } + } + private void addStatisTime(XhpcChargeHistoryOrder xhpc, Date startTime, Date endTime, Long rateModelId, Long operatorId, Long chargingStationId, Long terminalId, Long historyOrderId, int startHour, int endHour) { + + BigDecimal number = new BigDecimal(endHour + 1 - startHour); + for (int i = startHour; i <= endHour + 1; i++) { + //获取费率 + if (i == startHour) { + //开始时间、结束时间 + addStatis(xhpc, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, endHour, number, DateUtil.formatTime(startTime), i + ":59:59"); + } else if (i != endHour + 1) { + addStatis(xhpc, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, endHour, number, i + ":00:00", i + ":59:59"); + } else { + addStatis(xhpc, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, endHour, number, i + ":00:00", DateUtil.formatTime(endTime)); + } + } + } + + private void addInterval(XhpcChargeHistoryOrder xhpc, Date startTime, Date endTime, Long rateModelId, Long operatorId, Long chargingStationId, Long terminalId, Long historyOrderId, int startHour, int endHour) { + Date data = Calendar.getInstance().getTime(); + if(endHour==startHour){ + //没有跨时段 + XhpcStatisticsTimeInterval xhpcSt = new XhpcStatisticsTimeInterval(); + xhpcSt.setStatus(endHour+1); + xhpcSt.setChargingDegree(xhpc.getChargingDegree()); + xhpcSt.setChargingTime(new BigDecimal(xhpc.getChargingTimeNumber()/3600).setScale(2, RoundingMode.HALF_UP)); + xhpcSt.setChargingNumber(1); + BigDecimal number = new BigDecimal(2); + xhpcSt.setPowerPrice(xhpc.getActPowerPrice().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setServicePrice(xhpc.getActServicePrice().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setTotalPrice(xhpc.getTotalPrice().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setActPrice(xhpc.getActPrice().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setActPowerPrice(xhpc.getActPowerPrice().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setActServicePrice(xhpc.getActServicePrice().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setInternetCommission(xhpc.getInternetCommission().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setPlatformCommission(xhpc.getPlatformCommission().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setOperationCommission(xhpc.getOperationCommission().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission().divide(number,2,RoundingMode.HALF_UP)); + xhpcSt.setOperatorId(operatorId); + xhpcSt.setChargingStationId(chargingStationId); + xhpcSt.setCreateTime(data); + xhpcSt.setTerminalId(terminalId); + xhpcSt.setHistoryOrderId(historyOrderId); + if(xhpc.getSource()==1){ + xhpcSt.setInternetUserId(xhpc.getUserId()); + } + xhpcStatisticsService.addStatisticsTime(xhpcSt); + }else{ + //跨时段 + //总共时段 endHour+1-startHour + addStatisTime(xhpc, startTime, endTime, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, startHour, endHour); + } + } + + private void addStatis(XhpcChargeHistoryOrder xhpc, Long rateModelId, Long operatorId, Long chargingStationId, Long terminalId, Long historyOrderId, int endHour, BigDecimal number, String start, String end) { + List> reatTimeList = xhpcHistoryOrderService.getReatTimeList(start, end, rateModelId); + if (reatTimeList != null && reatTimeList.size() > 0) { + if (reatTimeList.size() == 1) { + addSte(xhpc, operatorId, chargingStationId, terminalId, historyOrderId, endHour, number, reatTimeList, 0, 1); + } else { + for (int j = 0; j < reatTimeList.size(); j++) { + addSte(xhpc, operatorId, chargingStationId, terminalId, historyOrderId, endHour, number, reatTimeList, j, 2); } } } } + private void addSte(XhpcChargeHistoryOrder xhpc, Long operatorId, Long chargingStationId, Long terminalId, Long historyOrderId, int endHour, BigDecimal number, List> reatTimeList, int j, int type) { + Date data = Calendar.getInstance().getTime(); + Map map = reatTimeList.get(j); + BigDecimal size = new BigDecimal(reatTimeList.size()); + long time3 = DateUtil.parse(map.get("endTime").toString()).getTime(); + long time4 = DateUtil.parse(map.get("startTime").toString()).getTime(); + BigDecimal time5 = new BigDecimal((time3-time4)/6000); + BigDecimal powerFee =new BigDecimal(map.get("powerFee").toString()); + BigDecimal serviceFee =new BigDecimal(map.get("serviceFee").toString()); + XhpcStatisticsTimeInterval xhpcSt = new XhpcStatisticsTimeInterval(); + xhpcSt.setStatus(endHour+1); + xhpcSt.setChargingDegree(xhpc.getChargingDegree()); + xhpcSt.setChargingTime(time5); + xhpcSt.setChargingNumber(1); + BigDecimal powerFee1 = powerFee.multiply(time5).setScale(2, RoundingMode.HALF_UP); + BigDecimal serviceFee1 = serviceFee.multiply(time5).setScale(2, RoundingMode.HALF_UP); + xhpcSt.setPowerPrice(powerFee1); + xhpcSt.setServicePrice(serviceFee1); + xhpcSt.setTotalPrice(powerFee1.add(serviceFee1)); + if(type==1){ + xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount().divide(number,2, RoundingMode.HALF_UP)); + xhpcSt.setActPrice(powerFee1.add(serviceFee1).subtract(xhpcSt.getPromotionDiscount())); + xhpcSt.setActPowerPrice(xhpc.getActPowerPrice().divide(number,2, RoundingMode.HALF_UP)); + xhpcSt.setActServicePrice(xhpc.getActServicePrice().divide(number,2, RoundingMode.HALF_UP)); + xhpcSt.setInternetCommission(xhpc.getInternetCommission().divide(number,2, RoundingMode.HALF_UP)); + xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission().divide(number,2, RoundingMode.HALF_UP)); + xhpcSt.setPlatformCommission(xhpc.getPlatformCommission().divide(number,2, RoundingMode.HALF_UP)); + xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion().divide(number,2, RoundingMode.HALF_UP)); + xhpcSt.setOperationCommission(xhpc.getOperationCommission().divide(number,2, RoundingMode.HALF_UP)); + xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission().divide(number,2, RoundingMode.HALF_UP)); + }else{ + xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP)); + xhpcSt.setActPrice(powerFee1.add(serviceFee1).subtract(xhpcSt.getPromotionDiscount())); + xhpcSt.setActPowerPrice(xhpc.getActPowerPrice().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP)); + xhpcSt.setActServicePrice(xhpc.getActServicePrice().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP)); + xhpcSt.setInternetCommission(xhpc.getInternetCommission().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP)); + xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP)); + xhpcSt.setPlatformCommission(xhpc.getPlatformCommission().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP)); + xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP)); + xhpcSt.setOperationCommission(xhpc.getOperationCommission().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP)); + xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP)); + } + xhpcSt.setOperatorId(operatorId); + xhpcSt.setChargingStationId(chargingStationId); + xhpcSt.setCreateTime(data); + xhpcSt.setTerminalId(terminalId); + xhpcSt.setHistoryOrderId(historyOrderId); + if(xhpc.getSource()==1){ + xhpcSt.setInternetUserId(xhpc.getUserId()); + } + xhpcStatisticsService.addStatisticsTime(xhpcSt); + } + public static void main(String[] args) { - - + System.out.println(">>>>>"+DateUtil.format(Calendar.getInstance().getTime(), "yyyy-MM-dd HH:mm:ss")); } } diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcStatisticsTimeInterval.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcStatisticsTimeInterval.java index 532bc76b..d0a06b48 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcStatisticsTimeInterval.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/domain/XhpcStatisticsTimeInterval.java @@ -109,6 +109,11 @@ public class XhpcStatisticsTimeInterval extends BaseEntity { */ private Long terminalId; + /** + * 历史订单id + */ + private Long historyOrderId; + public Long getStatisticsTimeIntervalId() { return statisticsTimeIntervalId; @@ -339,4 +344,14 @@ public class XhpcStatisticsTimeInterval extends BaseEntity { this.terminalId = terminalId; } + public Long getHistoryOrderId() { + + return historyOrderId; + } + + public void setHistoryOrderId(Long historyOrderId) { + + this.historyOrderId = historyOrderId; + } + } 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 5653d7cc..685fca44 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 @@ -114,8 +114,9 @@ public interface IXhpcRealTimeOrderService { * @param userId * @param userMessage * @param type 0 不发短信 1发短信 + * @param vinNormal VUN 码 */ - void addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, Map userMessage,Integer type); + void addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, Map userMessage,Integer type,String vinNormal); /** * 添加redis到数据库 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 0127ba42..626f9e55 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 @@ -247,7 +247,8 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { if(xhpcChargingPileById.get("communicationProtocolVersion")!=null && !"".equals(xhpcChargingPileById.get("communicationProtocolVersion").toString())){ version=xhpcChargingPileById.get("communicationProtocolVersion").toString(); } - R oa = powerPileService.stopCharging(xhpcTerminal.getPileSerialNumber(), xhpcTerminal.getSerialNumber(), version); + + R oa = powerPileService.stopCharging(xhpcTerminal.getPileSerialNumber(), xhpcTerminal.getSerialNumber().substring(14), version); logger.info("<<<<<<<<<<<<<<<<<<<<<<<<停止充电返回>>>>>>>>>>>>>>>>>"); logger.info("<<<<<<<<<<<<<<<<<<<<<<<<"+oa.getCode()+">>>>>>>>>>>>>>>>>"); logger.info("<<<<<<<<<<<<<<<<<<<<<<<<"+oa.getMsg()+">>>>>>>>>>>>>>>>>"); 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 29a7c675..4e59dae0 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 @@ -111,8 +111,7 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { BigDecimal servicePriceTotal1 =(BigDecimal)map1.get("servicePriceTotal"); //明天 DateTime tomorrow = DateUtil.offsetDay(startTime2,1); - String startTime1 = DateUtil.format(tomorrow, "yyyy-MM-dd"); - Date startTime3 = DateUtil.parse(startTime1+" 00:00:00"); + Date startTime3 =DateUtil.beginOfDay(tomorrow); Map map2 = getBigDecimal(actPrice, powerPriceTotal1, servicePriceTotal1, chargeOrder, rateModelId, startTime3, updateTime2, chargingDegree, list); return map2; } 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 6c73af48..553e908b 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 @@ -179,7 +179,7 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService { return AjaxResult.error("用户id:" + userId + "为空"); } //生成一条历史订单 - addSettlement(powerPrice, servicePrice, money, surplusPowerPrice, surplusServicePrice, xhpcChargeOrder, userId, userMessage,0); + addSettlement(powerPrice, servicePrice, money, surplusPowerPrice, surplusServicePrice, xhpcChargeOrder, userId, userMessage,0,null); return AjaxResult.success(); } @@ -197,10 +197,11 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService { * @param type 0 不发短信 1发短信 */ @Override - public void addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, Map userMessage,Integer type) { + public void addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, Map userMessage,Integer type,String vinNormal) { XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder(); xhpcHistoryOrder.setPowerPriceTotal(powerPrice); xhpcHistoryOrder.setServicePriceTotal(servicePrice); + xhpcHistoryOrder.setVinNormal(vinNormal); BigDecimal balance = new BigDecimal(userMessage.get("balance").toString()).divide(new BigDecimal(100)); //电站活动抵扣--抵扣的总金额 BigDecimal promotionDiscount = new BigDecimal(0); 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 f8a8d76e..cd71f32c 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 @@ -207,7 +207,7 @@ public class XhpcStatisticsServiceImpl implements IXhpcStatisticsService { @Override public void addStatisticsTime(XhpcStatisticsTimeInterval xhpcStatisticsTimeInterval) { - + xhpcStatisticsServiceMapper.addStatisticsTime(xhpcStatisticsTimeInterval); } private boolean getJudge(Long internetUserId, Long operatorId, Integer type) { 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 5a169737..9b27eecf 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcHistoryOrderMapper.xml @@ -134,7 +134,10 @@ power_price_total, - service_price_total + service_price_total, + + + vin_normal @@ -229,7 +232,10 @@ #{powerPriceTotal}, - #{servicePriceTotal} + #{servicePriceTotal}, + + + #{vinNormal} diff --git a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcStatisticsMapper.xml b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcStatisticsMapper.xml index a2666b5f..5bd92d97 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcStatisticsMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcStatisticsMapper.xml @@ -416,7 +416,10 @@ remark, - terminal_id + terminal_id, + + + history_order_id @@ -496,7 +499,10 @@ #{terminalId}, - #{chargingTimeNumber} + #{chargingTimeNumber}, + + + #{historyOrderId} diff --git a/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/controller/OrderNotificationWebSocketController.java b/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/controller/OrderNotificationWebSocketController.java index 68ddca92..bf09cc5c 100644 --- a/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/controller/OrderNotificationWebSocketController.java +++ b/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/controller/OrderNotificationWebSocketController.java @@ -19,4 +19,10 @@ public class OrderNotificationWebSocketController { OrderNotificationWebSocket.sendMessage(userId,"有新订单啦"); } + @GetMapping("/getMessage") + public void getMessage(@RequestParam String userId,@RequestParam String message){ + OrderNotificationWebSocket.sendMessage(userId,message); + } + + } diff --git a/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/rabbitm/RabbitmConsumer.java b/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/rabbitm/RabbitmConsumer.java index 8c6087e4..a57dc9fd 100644 --- a/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/rabbitm/RabbitmConsumer.java +++ b/xhpc-modules/xhpc-wxma/src/main/java/com/xhpc/wxma/rabbitm/RabbitmConsumer.java @@ -1,13 +1,17 @@ package com.xhpc.wxma.rabbitm; +import cn.hutool.core.date.DateUtil; import com.rabbitmq.client.*; import com.xhpc.common.util.ConnectionRabbitMQUtil; import com.xhpc.wxma.socket.OrderNotificationWebSocket; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; import java.io.IOException; +import java.util.Calendar; /** * @author yuyang @@ -17,6 +21,9 @@ import java.io.IOException; public class RabbitmConsumer implements ApplicationRunner { //队列名称 private final static String NAME="webSocket"; + + private static final Logger logger = LoggerFactory.getLogger(RabbitmConsumer.class); + @Override public void run(ApplicationArguments args) throws Exception { try { @@ -35,9 +42,11 @@ public class RabbitmConsumer implements ApplicationRunner { //消息id,mq在channel中用来标识消息的id,可用于确认消息已接收 //long deliveryTag = envelope.getDeliveryTag(); // body 即消息体 + logger.info("<<<<<<<<<<收到消息队列时间<<<<<<<<<<<<<<"+ DateUtil.format(Calendar.getInstance().getTime(), "yyyy-MM-dd HH:mm:ss")+">>>>>>>>>>>>>>>>>"); String msg = new String(body,"utf-8"); String[] split = msg.split("##"); OrderNotificationWebSocket.sendMessage(split[0],split[1]); + logger.info("<<<<<<<<<<消息队列发送时间<<<<<<<<<<<<<<"+ DateUtil.format(Calendar.getInstance().getTime(), "yyyy-MM-dd HH:mm:ss")+">>>>>>>>>>>>>>>>>"); } }; channel.basicConsume(NAME, true, consumer);