From 04ff0efb1054e9962b7ea29996b840255b18ce1c Mon Sep 17 00:00:00 2001 From: ZZ Date: Thu, 14 Oct 2021 19:31:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/xhpc/OrderApplication.java | 3 +- .../XhpcHistoryOrderController.java | 229 +++++++++--------- .../XhpcStopChargingOrderController.java | 1 - 3 files changed, 116 insertions(+), 117 deletions(-) diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/OrderApplication.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/OrderApplication.java index 183ededd..dc175762 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/OrderApplication.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/OrderApplication.java @@ -6,8 +6,9 @@ import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.scheduling.annotation.EnableScheduling; - +@EnableScheduling @EnableCustomConfig @EnableRyFeignClients @EnableFeignClients 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 272fbc4e..b8e3731e 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 @@ -10,10 +10,12 @@ import com.xhpc.order.domain.XhpcHistoryOrder; import com.xhpc.order.domain.XhpcStatisticsStation; import com.xhpc.order.domain.XhpcStatisticsTimeInterval; import com.xhpc.order.dto.XhpcChargeHistoryOrder; +import com.xhpc.order.service.IXhpcChargeOrderService; import com.xhpc.order.service.IXhpcHistoryOrderService; import com.xhpc.order.service.IXhpcStatisticsService; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -74,76 +76,31 @@ public class XhpcHistoryOrderController extends BaseController { * 终端统计 */ @GetMapping("/test3") + @Scheduled(cron = "0 0 12 * * ?") public void test3() { - - add(500, 3); + add(100,3); } /** * 场站统计 */ @GetMapping("/test2") + @Scheduled(cron = "0 0 11 * * ?") public void test2() { - - add(500, 2); - } - - - public void add(int number, int type) { - //获取500条待统计历史订单 - List list = xhpcHistoryOrderService.getStatistisList(number, type); - //场站、运营商、流量方 - if (list != null && list.size() > 0) { - for (XhpcChargeHistoryOrder xhpc : list) { - XhpcStatisticsStation xhpcSt = new XhpcStatisticsStation(); - xhpcSt.setChargingDegree(xhpc.getChargingDegree()); - BigDecimal decimal = new BigDecimal(xhpc.getChargingTimeNumber() / 3600).setScale(2, RoundingMode.HALF_UP); - xhpcSt.setChargingTime(decimal); - xhpcSt.setChargingNumber(1); - xhpcSt.setPowerPrice(xhpc.getPowerPriceTotal()); - xhpcSt.setServicePrice(xhpc.getServicePriceTotal()); - xhpcSt.setTotalPrice(xhpc.getTotalPrice()); - xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount()); - xhpcSt.setActPrice(xhpc.getActPrice()); - 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.setActPowerPrice(xhpc.getActPowerPrice()); - xhpcSt.setActServicePrice(xhpc.getActServicePrice()); - if (xhpc.getSource() == 1) { - xhpcSt.setInternetUserId(xhpc.getUserId()); + add(100,2); } - xhpcSt.setOperatorId(xhpc.getOperatorId()); - xhpcSt.setChargingStationId(xhpc.getChargingStationId()); - xhpcSt.setCreateTime(Calendar.getInstance().getTime()); - xhpcSt.setTerminalId(xhpc.getTerminalId()); - xhpcSt.setHistoryOrderId(xhpc.getHistoryOrderId()); - xhpcSt.setChargingPileId(xhpc.getChargingPileId()); - xhpcSt.setType(type); - xhpcStatisticsService.addStatisticsStation(xhpcSt); - - //修改历史订单表状态 - XhpcHistoryOrder xhpcHistoryOrder = new XhpcHistoryOrder(); - xhpcHistoryOrder.setHistoryOrderId(xhpc.getHistoryOrderId()); - xhpcHistoryOrder.setState(type + 1); - xhpcHistoryOrderService.update(xhpcHistoryOrder); - } - } - } /** * 日期统计 */ @GetMapping("/test1") + @Scheduled(cron = "0 0 00 * * ?") public void test1(){ //获取500条待统计历史订单 //跨时段,跨费率,计费模型 //日期统计 int type = 1; - List list = xhpcHistoryOrderService.getStatistisList(500, type); + List list = xhpcHistoryOrderService.getStatistisList(100,type); //是否跨天 if(list !=null && list.size()>0){ for (XhpcChargeHistoryOrder xhpc:list) { @@ -211,77 +168,16 @@ public class XhpcHistoryOrderController extends BaseController { } } - - private void addStation(XhpcChargeHistoryOrder xhpc, BigDecimal chargingTime, int type, String startTime, String endTime, - BigDecimal divide) { - - BigDecimal chargingDegree1 = new BigDecimal(0); - BigDecimal powerPrice1 = new BigDecimal(0); - BigDecimal servicePrice1 = new BigDecimal(0); - List> reatTimeList = xhpcHistoryOrderService.getReatTimeList(startTime, endTime, - xhpc.getRateModelId()); - if (reatTimeList != null && reatTimeList.size() > 0) { - for (int i = 0; i < reatTimeList.size(); i++) { - Map objectMap = reatTimeList.get(i); - BigDecimal powerPrice = new BigDecimal(objectMap.get("powerFee").toString()); - BigDecimal servicePrice = new BigDecimal(objectMap.get("serviceFee").toString()); - String startTime1 = objectMap.get("startTime").toString(); - String endTime1 = objectMap.get("endTime").toString(); - //总度数 - BigDecimal chargingDegree2 = - new BigDecimal((DateUtil.parse(endTime1).getTime() - DateUtil.parse(startTime1).getTime()) / 60000).multiply(divide).setScale(2, RoundingMode.HALF_UP); - chargingDegree1 = chargingDegree1.add(chargingDegree2); - powerPrice1 = powerPrice1.add(powerPrice.multiply(chargingDegree2).setScale(2, RoundingMode.HALF_UP)); - servicePrice1 = servicePrice1.add(servicePrice.multiply(chargingDegree2).setScale(2, RoundingMode.HALF_UP)); - } - } - - XhpcStatisticsStation xhpcSt = new XhpcStatisticsStation(); - xhpcSt.setChargingDegree(chargingDegree1); - xhpcSt.setChargingTime(chargingTime); - xhpcSt.setChargingNumber(1); - xhpcSt.setPowerPrice(powerPrice1); - xhpcSt.setServicePrice(servicePrice1); - xhpcSt.setTotalPrice(powerPrice1.add(servicePrice1)); - BigDecimal promotion = new BigDecimal(2); - xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount().divide(promotion, 2, RoundingMode.HALF_UP)); - xhpcSt.setActPrice(xhpcSt.getTotalPrice().subtract(xhpcSt.getPromotionDiscount())); - xhpcSt.setInternetCommission(xhpc.getInternetCommission().divide(promotion, 2, RoundingMode.HALF_UP)); - xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission().divide(promotion, 2, RoundingMode.HALF_UP)); - xhpcSt.setPlatformCommission(xhpc.getPlatformCommission().divide(promotion, 2, RoundingMode.HALF_UP)); - xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion().divide(promotion, 2, RoundingMode.HALF_UP)); - xhpcSt.setOperationCommission(xhpc.getOperationCommission().divide(promotion, 2, RoundingMode.HALF_UP)); - xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission().divide(promotion, 2, RoundingMode.HALF_UP)); - - //抽成费用 - BigDecimal money = xhpcSt.getPlatformCommission().add(xhpcSt.getPlatformSvcCommisssion()) - .add(xhpcSt.getInternetCommission()).add(xhpcSt.getInternetSvcCommission()) - .add(xhpcSt.getOperationCommission()).add(xhpcSt.getOperationSvcCommission()); - xhpcSt.setActPowerPrice(powerPrice1.subtract(money)); - xhpcSt.setActServicePrice(servicePrice1.subtract(money)); - if (xhpc.getSource() == 1) { - xhpcSt.setInternetUserId(xhpc.getUserId()); - } - xhpcSt.setOperatorId(xhpc.getOperatorId()); - xhpcSt.setChargingStationId(xhpc.getChargingStationId()); - xhpcSt.setCreateTime(Calendar.getInstance().getTime()); - xhpcSt.setTerminalId(xhpc.getTerminalId()); - xhpcSt.setHistoryOrderId(xhpc.getHistoryOrderId()); - xhpcSt.setChargingPileId(xhpc.getChargingPileId()); - xhpcSt.setType(type); - xhpcStatisticsService.addStatisticsStation(xhpcSt); - } - - /** - * 小时统计 + * 小时统计,每分钟执行 */ @GetMapping("/test") + @Scheduled(cron = "0 * * * * ?") public void test() { //获取500条待统计历史订单 //跨时段,跨费率,计费模型 //小时统计 - List list = xhpcHistoryOrderService.getStatistisList(500, 0); + List list = xhpcHistoryOrderService.getStatistisList(50,0); if(list !=null && list.size()>0){ for (XhpcChargeHistoryOrder xhpc:list) { //开始时间、结束时间、模型id、状态、用户id、运营商、订单id、场站id、终端id、历史订单id、时间 @@ -373,6 +269,109 @@ public class XhpcHistoryOrderController extends BaseController { } } + public void add(int number,int type){ + //获取500条待统计历史订单 + List list = xhpcHistoryOrderService.getStatistisList(number,type); + //场站、运营商、流量方 + if(list !=null && list.size()>0){ + for (XhpcChargeHistoryOrder xhpc:list) { + XhpcStatisticsStation xhpcSt =new XhpcStatisticsStation(); + xhpcSt.setChargingDegree(xhpc.getChargingDegree()); + BigDecimal decimal = new BigDecimal(xhpc.getChargingTimeNumber() / 3600).setScale(2, RoundingMode.HALF_UP); + xhpcSt.setChargingTime(decimal); + xhpcSt.setChargingNumber(1); + xhpcSt.setPowerPrice(xhpc.getPowerPriceTotal()); + xhpcSt.setServicePrice(xhpc.getServicePriceTotal()); + xhpcSt.setTotalPrice(xhpc.getTotalPrice()); + xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount()); + xhpcSt.setActPrice(xhpc.getActPrice()); + 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.setActPowerPrice(xhpc.getActPowerPrice()); + xhpcSt.setActServicePrice(xhpc.getActServicePrice()); + if(xhpc.getSource()==1){ + xhpcSt.setInternetUserId(xhpc.getUserId()); + } + xhpcSt.setOperatorId(xhpc.getOperatorId()); + xhpcSt.setChargingStationId(xhpc.getChargingStationId()); + xhpcSt.setCreateTime(Calendar.getInstance().getTime()); + xhpcSt.setTerminalId(xhpc.getTerminalId()); + xhpcSt.setHistoryOrderId(xhpc.getHistoryOrderId()); + xhpcSt.setChargingPileId(xhpc.getChargingPileId()); + xhpcSt.setType(type); + xhpcStatisticsService.addStatisticsStation(xhpcSt); + + + //修改历史订单表状态 + XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder(); + xhpcHistoryOrder.setHistoryOrderId(xhpc.getHistoryOrderId()); + xhpcHistoryOrder.setState(type+1); + xhpcHistoryOrderService.update(xhpcHistoryOrder); + } + } + } + + private void addStation(XhpcChargeHistoryOrder xhpc,BigDecimal chargingTime,int type,String startTime,String endTime,BigDecimal divide) { + + BigDecimal chargingDegree1 =new BigDecimal(0); + BigDecimal powerPrice1 =new BigDecimal(0); + BigDecimal servicePrice1 =new BigDecimal(0); + List> reatTimeList = xhpcHistoryOrderService.getReatTimeList(startTime, endTime, xhpc.getRateModelId()); + if(reatTimeList !=null && reatTimeList.size()>0){ + for (int i = 0; i objectMap = reatTimeList.get(i); + BigDecimal powerPrice =new BigDecimal(objectMap.get("powerFee").toString()); + BigDecimal servicePrice =new BigDecimal(objectMap.get("serviceFee").toString()); + String startTime1 = objectMap.get("startTime").toString(); + String endTime1 = objectMap.get("endTime").toString(); + //总度数 + BigDecimal chargingDegree2 = new BigDecimal((DateUtil.parse(endTime1).getTime() - DateUtil.parse(startTime1).getTime())/60000).multiply(divide).setScale(2, RoundingMode.HALF_UP); + chargingDegree1 =chargingDegree1.add(chargingDegree2); + powerPrice1 =powerPrice1.add(powerPrice.multiply(chargingDegree2).setScale(2, RoundingMode.HALF_UP)); + servicePrice1 =servicePrice1.add(servicePrice.multiply(chargingDegree2).setScale(2, RoundingMode.HALF_UP)); + } + } + + XhpcStatisticsStation xhpcSt =new XhpcStatisticsStation(); + xhpcSt.setChargingDegree(chargingDegree1); + xhpcSt.setChargingTime(chargingTime); + xhpcSt.setChargingNumber(1); + xhpcSt.setPowerPrice(powerPrice1); + xhpcSt.setServicePrice(servicePrice1); + xhpcSt.setTotalPrice(powerPrice1.add(servicePrice1)); + BigDecimal promotion =new BigDecimal(2); + xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount().divide(promotion,2, RoundingMode.HALF_UP)); + xhpcSt.setActPrice(xhpcSt.getTotalPrice().subtract(xhpcSt.getPromotionDiscount())); + xhpcSt.setInternetCommission(xhpc.getInternetCommission().divide(promotion,2, RoundingMode.HALF_UP)); + xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission().divide(promotion,2, RoundingMode.HALF_UP)); + xhpcSt.setPlatformCommission(xhpc.getPlatformCommission().divide(promotion,2, RoundingMode.HALF_UP)); + xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion().divide(promotion,2, RoundingMode.HALF_UP)); + xhpcSt.setOperationCommission(xhpc.getOperationCommission().divide(promotion,2, RoundingMode.HALF_UP)); + xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission().divide(promotion,2, RoundingMode.HALF_UP)); + + //抽成费用 + BigDecimal money = xhpcSt.getPlatformCommission().add(xhpcSt.getPlatformSvcCommisssion()) + .add(xhpcSt.getInternetCommission()).add(xhpcSt.getInternetSvcCommission()) + .add(xhpcSt.getOperationCommission()).add(xhpcSt.getOperationSvcCommission()); + xhpcSt.setActPowerPrice(powerPrice1.subtract(money)); + xhpcSt.setActServicePrice(servicePrice1.subtract(money)); + if(xhpc.getSource()==1){ + xhpcSt.setInternetUserId(xhpc.getUserId()); + } + xhpcSt.setOperatorId(xhpc.getOperatorId()); + xhpcSt.setChargingStationId(xhpc.getChargingStationId()); + xhpcSt.setCreateTime(Calendar.getInstance().getTime()); + xhpcSt.setTerminalId(xhpc.getTerminalId()); + xhpcSt.setHistoryOrderId(xhpc.getHistoryOrderId()); + xhpcSt.setChargingPileId(xhpc.getChargingPileId()); + xhpcSt.setType(type); + xhpcStatisticsService.addStatisticsStation(xhpcSt); + } + private void addStatisTime(XhpcChargeHistoryOrder xhpc, Date startTime, Date endTime, Long rateModelId, Long operatorId, Long chargingStationId, Long terminalId, Long historyOrderId, int startHour, int endHour,String yyyyMMdd,BigDecimal multiply) { BigDecimal number = new BigDecimal(endHour + 1 - startHour); diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcStopChargingOrderController.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcStopChargingOrderController.java index 7aca54b6..d4f67235 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcStopChargingOrderController.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/controller/XhpcStopChargingOrderController.java @@ -41,7 +41,6 @@ public class XhpcStopChargingOrderController extends BaseController { * @param chargingOrderId 充电id * @return */ - @Scheduled(cron = "0 59 23 * * ?") @GetMapping("/stopUp") public AjaxResult stopUp(@RequestParam Long userId, @RequestParam String terminalSerialNumber, @RequestParam Long chargingOrderId){