From fe541b0c3ed0a4e4845a985dd13622afafc7cb03 Mon Sep 17 00:00:00 2001 From: yuyang <2265829957@qq.com> Date: Mon, 1 Nov 2021 10:52:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=9C=AA=E5=90=AF=E5=8A=A8=EF=BC=8C=E5=9C=BA=E7=AB=99?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=BB=9F=E8=AE=A1=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?redis=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../station/mapper/XhpcTerminalMapper.java | 7 + .../station/service/IXhpcTerminalService.java | 9 +- .../XhpcChargingStationServiceImpl.java | 53 +- .../service/XhpcTerminalServiceImpl.java | 6 + .../mapper/XhpcChargingStationMapper.xml | 20 +- .../resources/mapper/XhpcTerminalMapper.xml | 5 + .../common/domain/XhpcChargingStation.java | 6 +- .../XhpcHistoryOrderController.java | 5 + .../impl/XhpcChargeOrderServiceImpl.java | 3 + .../impl/XhpcHistoryOrderServiceImpl.java | 565 +++++++++--------- .../impl/XhpcStatisticsServiceImpl.java | 10 + .../resources/mapper/XhpcStatisticsMapper.xml | 33 + .../XhpcRechargeOrderController.java | 2 + .../controller/XhpcRefundAuditController.java | 7 +- 14 files changed, 426 insertions(+), 305 deletions(-) diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java index 00134f09..81ec08df 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcTerminalMapper.java @@ -108,4 +108,11 @@ public interface XhpcTerminalMapper { */ List> getXhpcPileNameAndStationNameAndTerminalNumList(@Param("terminalSerialNumber") String terminalSerialNumber, @Param("pileName") String pileName, @Param("stationName") String stationName); + + /** + * 根据电站获取终端的编号 + * @param chargingStationId + * @return + */ + List getTerminal(@Param("chargingStationId") Long chargingStationId); } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcTerminalService.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcTerminalService.java index 2ff8da8a..4ef98274 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcTerminalService.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcTerminalService.java @@ -15,7 +15,7 @@ public interface IXhpcTerminalService { /** - * PC端页面统计 + * PC端页面统计(已作废) * @param chargingStationId 电站id * @return */ @@ -65,4 +65,11 @@ public interface IXhpcTerminalService { */ List> getXhpcPileNameAndStationNameAndTerminalNumList(String terminalSerialNumber, String pileName, String stationName); + /** + * 根据电站获取终端的编号 + * @param chargingStationId + * @return + */ + List getTerminal(Long chargingStationId); + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java index 1f0048dd..10d1b415 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java @@ -83,11 +83,36 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi if (xhpcRateTime != null) { map.putAll(xhpcRateTime); } - //获取桩的统计 - Map chargingId = xhpcTerminalService.countXhpcTerminalWorkStatus(chargingStationId); - if (chargingId != null) { - map.putAll(chargingId); + //获取桩的统计.redis 数据 + List terminal = xhpcTerminalService.getTerminal(chargingStationId); + int offLine =0;//离线 + int fault =0;//故障 + int freeTime =0;//空闲 + int charge =0;//充电 + int unknown =0;//未知 + if(terminal !=null && terminal.size()>0){ + for (String st:terminal) { + Map cacheMap = redisService.getCacheMap("gun:" + st); + if(!cacheMap.isEmpty()){ + if ("离线".equals(cacheMap.get("status").toString())){ + offLine++; + }else if("故障".equals(cacheMap.get("status").toString())){ + fault++; + }else if("空闲".equals(cacheMap.get("status").toString())){ + freeTime++; + }else{ + charge++; + } + }else{ + unknown++; + } + } } + map.put("offLine",offLine); + map.put("fault",fault); + map.put("freeTime",freeTime); + map.put("charge",charge); + map.put("unknown",unknown); } return list; } @@ -248,6 +273,12 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi if (xhpcChargingStationDto.getImgId() == null) { return AjaxResult.error(1001, "图片不能为空"); } + if (xhpcChargingStationDto.getServiceTel() == null) { + return AjaxResult.error(1001, "站点电话不能为空"); + } + if (xhpcChargingStationDto.getParkNums() == null) { + return AjaxResult.error(1001, "侧位数量不能为空"); + } //判断费率和费率时间段 是否有值 if (xhpcChargingStationDto.getXhpcRateList() == null && xhpcChargingStationDto.getXhpcRateList().size() == 0) { @@ -1029,15 +1060,11 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi // System.out.println(num); - for (int i = 0; i <10 ; i++) { - - if(i==5){ - continue; - } - System.out.println("i:"+i); - } - - + int i =0; + i++; + System.out.println("111????????????????"+i); + i=i++; + System.out.println("222????????????????"+i); } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcTerminalServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcTerminalServiceImpl.java index 75b15c52..5bcdfc88 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcTerminalServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcTerminalServiceImpl.java @@ -123,4 +123,10 @@ public class XhpcTerminalServiceImpl implements IXhpcTerminalService { return xhpcTerminalMapper.getXhpcPileNameAndStationNameAndTerminalNumList(terminalSerialNumber, pileName, stationName); } + + @Override + public List getTerminal(Long chargingStationId) { + return xhpcTerminalMapper.getTerminal(chargingStationId); + } + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml index 459f9e1d..4a8cabce 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcChargingStationMapper.xml @@ -173,7 +173,9 @@ reminder_instructions = #{reminderInstructions}, img_id = #{imgId}, station_type = #{stationType}, - operator_id_evcs = #{operatorIdEvcs} + operator_id_evcs = #{operatorIdEvcs}, + service_tel = #{serviceTel}, + park_nums = #{parkNums} where charging_station_id = #{chargingStationId} @@ -516,7 +518,13 @@ station_type, - operator_id_evcs + operator_id_evcs, + + + service_tel, + + + park_nums @@ -599,7 +607,13 @@ #{stationType}, - #{operatorIdEvcs} + #{operatorIdEvcs}, + + + #{serviceTel}, + + + #{parkNums} diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml index 8a217cfa..ad5e7012 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml @@ -372,4 +372,9 @@ And terminal.serial_number like CONCAT('%',#{stationName},'%') + + + diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/domain/XhpcChargingStation.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/domain/XhpcChargingStation.java index a5ef6e5c..395e697e 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/domain/XhpcChargingStation.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/domain/XhpcChargingStation.java @@ -114,7 +114,7 @@ public class XhpcChargingStation extends BaseEntity { /** *侧位数量 */ - private String parkNums; + private Integer parkNums; public String getOperatorIdEvcs() { @@ -342,12 +342,12 @@ public class XhpcChargingStation extends BaseEntity { this.serviceTel = serviceTel; } - public String getParkNums() { + public Integer getParkNums() { return parkNums; } - public void setParkNums(String parkNums) { + public void setParkNums(Integer parkNums) { this.parkNums = parkNums; } 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 d2ccb552..3dd85fbb 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 @@ -16,6 +16,7 @@ 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.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -31,6 +32,7 @@ import java.util.*; * @author yuyang * @date 2021/8/3 21:19 */ +@EnableScheduling @RestController @RequestMapping("/histotyOrder") @Api(value = "历史订单接口", tags = "历史订单接口") @@ -196,6 +198,9 @@ public class XhpcHistoryOrderController extends BaseController { } //每分钟多少度电 BigDecimal v = new BigDecimal((endTime.getTime() - startTime.getTime())).divide(new BigDecimal(60000),2,RoundingMode.HALF_UP); + if(v.compareTo(new BigDecimal(0)) !=1){ + break; + } BigDecimal multiply = xhpc.getChargingDegree().divide(v,2,RoundingMode.HALF_UP); //1时间没有跨天 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 6f3dc331..204f5538 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 @@ -170,11 +170,13 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { int number =0; if(!"".equals(userMessage.get("soc")) && userMessage.get("soc") !=null && !"".equals(userMessage.get("soc"))){ number =Integer.parseInt(userMessage.get("soc").toString()); + logger.info("<<<<<<<<<<<<<<<<<<<<<<<<用户>>>>>>>>>>>>>>>>>:"+number); } //平台 String soc = redisService.getCacheObject("global:SOC"); if(!"".equals(soc) && soc!=null){ if(number!=0){ + logger.info("<<<<<<<<<<<<<<<<<<<<<<<<平台>>>>>>>>>>>>>>>>>:"+soc); if(Integer.parseInt(soc)-number<0){ number=Integer.parseInt(soc); } @@ -185,6 +187,7 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { Map operatorMessage = xhpcChargeOrderMapper.getOperatorMessage(xhpcTerminal.getChargingStationId()); if(operatorMessage !=null && operatorMessage.get("soc") !=null && !"".equals(operatorMessage.get("soc"))){ if(number!=0){ + logger.info("<<<<<<<<<<<<<<<<<<<<<<<<营运商>>>>>>>>>>>>>>>>>:"+operatorMessage.get("soc").toString()); if(Integer.parseInt(operatorMessage.get("soc").toString())-number<0){ number=Integer.parseInt(operatorMessage.get("soc").toString()); } 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 897fc8df..7d06f605 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 @@ -115,301 +115,304 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService { logger.info("订单异常回调接口>>>>>orderNo:" + orderNo); //获取实时订单 CacheRealtimeData cacheRealtimeData = redisService.getCacheObject("order:" + orderNo + ".lord"); - XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo); - Long userId = xhpcChargeOrder.getUserId(); - try { - //开始时间 - Date startTime2 = xhpcChargeOrder.getStartTime(); - //当checking为true时,自动结算 - Integer chargingTime = cacheRealtimeData.getChargingTime(); - boolean checking = false; - if(type==1){ - if(chargingTime<3){ + if(cacheRealtimeData !=null){ + XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo); + Long userId = xhpcChargeOrder.getUserId(); + try { + //开始时间 + Date startTime2 = xhpcChargeOrder.getStartTime(); + //当checking为true时,自动结算 + Integer chargingTime = cacheRealtimeData.getChargingTime(); + boolean checking = false; + if(type==1){ + if(chargingTime<3){ + checking=true; + } + }else{ checking=true; } - }else{ - checking=true; - } - //毫秒 - DateTime date = DateUtil.offsetMinute(xhpcChargeOrder.getStartTime(), chargingTime); - xhpcChargeOrder.setEndTime(date); - xhpcChargeOrder.setUpdateTime(date); - if(checking){ - xhpcChargeOrder.setStatus(3); - }else{ - xhpcChargeOrder.setStatus(2); - } - xhpcChargeOrder.setEndSoc(cacheRealtimeData.getSoc()+""); - //充电时长 - Long tiem = Long.valueOf(cacheRealtimeData.getChargingTime() / 1000); - if (tiem > 3600) { - long hours = tiem / 3600; - double mins = (double) ((tiem - (hours * 3600)) / 60); - xhpcChargeOrder.setChargingTime(hours + "时" + new BigDecimal(mins).setScale(0) + "分"); - } else { - double mins = (double) (tiem / 60); - xhpcChargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "分"); - } - BigDecimal decimal = new BigDecimal(10000); - xhpcChargeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal)); - xhpcChargeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal)); - xhpcChargeOrder.setChargingTimeNumber(Long.valueOf(cacheRealtimeData.getChargingTime())); - - - if(checking){ - BigDecimal money =xhpcChargeOrder.getAmountCharged(); - //结算 - //总电费 - BigDecimal powerPrice =new BigDecimal(0); - //算时间是否跨天 - Long rateModelId = xhpcChargeOrder.getRateModelId(); - - Date updateTime2 = xhpcChargeOrder.getEndTime(); - long betweenDay = DateUtil.between(startTime2, updateTime2, DateUnit.DAY); - - if(betweenDay==0){ - powerPrice=getBigDecimal(rateModelId,startTime2,updateTime2,xhpcChargeOrder.getChargingDegree()); + //毫秒 + DateTime date = DateUtil.offsetMinute(xhpcChargeOrder.getStartTime(), chargingTime); + xhpcChargeOrder.setEndTime(date); + xhpcChargeOrder.setUpdateTime(date); + if(checking){ + xhpcChargeOrder.setStatus(3); }else{ - //跨天 - String startTime = DateUtil.format(startTime2, "yyyy-MM-dd"); - Date updateTime = DateUtil.parse(startTime+" 23:59:59"); - powerPrice=getBigDecimal(rateModelId,startTime2,updateTime,xhpcChargeOrder.getChargingDegree()); - //明天 - DateTime tomorrow = DateUtil.offsetDay(startTime2,1); - Date startTime3 =DateUtil.beginOfDay(tomorrow); - powerPrice=powerPrice.add(getBigDecimal(rateModelId,startTime3,updateTime2,xhpcChargeOrder.getChargingDegree())); - } - - //总服务费 - BigDecimal servicePrice = money.subtract(powerPrice); - //剩余的电费 - BigDecimal surplusPowerPrice = powerPrice; - //剩余的服务费 - BigDecimal surplusServicePrice = servicePrice; - - Map userMessage = xhpcChargeOrderService.getUserMessage(userId); - - XhpcHistoryOrder xhpcHistoryOrder = new XhpcHistoryOrder(); - xhpcHistoryOrder.setStopReasonEvcs(5); - xhpcHistoryOrder.setPowerPriceTotal(powerPrice); - xhpcHistoryOrder.setServicePriceTotal(servicePrice); - xhpcHistoryOrder.setTotalPower(cacheRealtimeData.getAmountCharged().doubleValue()/10000); - //电表总起值 - //xhpcHistoryOrder.setMeterValueStartEvcs(cacheOrderData.getElectricMeterStart().doubleValue()); - //电表总止值 - //xhpcHistoryOrder.setMeterValueEndEvcs(cacheOrderData.getElectricMeterEnd().doubleValue()); - //vin - //xhpcHistoryOrder.setVinNormal(vinNormal); - BigDecimal balance = new BigDecimal(userMessage.get("balance").toString()).divide(new BigDecimal(100)); - //电站活动抵扣--抵扣的总金额 - BigDecimal promotionDiscount = new BigDecimal(0); - - //实际价格-用户支付的钱 - BigDecimal actPrice =money; - //流量方总金额抽成 - BigDecimal internetCommission =new BigDecimal(0); - //流量方服务费抽成 - BigDecimal internetSvcCommission =new BigDecimal(0); - //平台总金额抽成 - BigDecimal platformCommission =new BigDecimal(0); - //平台服务费抽成 - BigDecimal platformSvcCommission =new BigDecimal(0); - //运维总抽成 - BigDecimal operationCommission =new BigDecimal(0); - //运维服务费抽成 - BigDecimal operationSvcCommission =new BigDecimal(0); - //判断是C端用户还是流量端用户 - if (xhpcChargeOrder.getSource() == 0) { - String state = ""; - BigDecimal discount = new BigDecimal(0); - //用户第几次充电 - int count = xhpcChargeOrderService.getCount(userId,xhpcChargeOrder.getChargeOrderId()); - if (count == 0) { - //活动折扣 - Map promotion = xhpcChargeOrderService.getPromotion(); - if (promotion != null && promotion.get("state") != null && promotion.get("discount") != null) { - //state 1.总金额 2.电费 3.服务费 discount 折扣率 - state = promotion.get("state").toString(); - discount =new BigDecimal(promotion.get("discount").toString()); - } - } - if(!"".equals(state)){ - - //查看是否优惠为0 - boolean fan = true; - if(discount.compareTo(new BigDecimal(0))==0){ - fan=false; - } - if("1".equals(state)){ - //总金额 - if(fan){ - promotionDiscount=money.multiply(discount); - actPrice = money.subtract(promotionDiscount); - surplusPowerPrice = surplusPowerPrice.subtract(promotionDiscount.divide(new BigDecimal(2))); - surplusServicePrice= surplusServicePrice.subtract(promotionDiscount.divide(new BigDecimal(2))); - } - }else if("2".equals(state)){ - if(fan){ - //电费 - promotionDiscount =powerPrice.multiply(balance); - actPrice = money.subtract(promotionDiscount); - surplusPowerPrice=surplusPowerPrice.subtract(promotionDiscount); - } - }else if("3".equals(state)){ - if(fan){ - //服务费 - promotionDiscount = servicePrice.multiply(balance); - actPrice = money.subtract(promotionDiscount); - surplusServicePrice =surplusServicePrice.subtract(promotionDiscount); - } - } - } - xhpcHistoryOrder.setInternetCommission(internetCommission); - xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission); - }else{ - //流量方,未实现,新增接口 - } - //获取运营商 - Map operatorMessage = xhpcChargeOrderService.getOperatorMessage(xhpcChargeOrder.getChargingStationId()); - if(operatorMessage !=null){ - if(operatorMessage.get("operatorIdEvcs")!=null){ - - if(operatorMessage.get("operatorIdEvcs") !=null && !"".equals(operatorMessage.get("operatorIdEvcs").toString())){ - String stw = operatorMessage.get("operatorIdEvcs").toString(); - if(stw.length()>9){ - xhpcHistoryOrder.setOperatorIdEvcs(stw.substring(8, stw.length() - 1)); - } - } - } - if(operatorMessage.get("maintenanceCommissionRate") !=null && operatorMessage.get("commissionType") !=null && operatorMessage.get("platformCommissionRate") !=null){ - Integer commissionType = (Integer) operatorMessage.get("commissionType"); - //运维提成 - BigDecimal maintenanceCommissionRate = new BigDecimal(operatorMessage.get("maintenanceCommissionRate").toString()).divide(new BigDecimal(100)); - //平台提成 - BigDecimal platformCommissionRate = new BigDecimal(operatorMessage.get("platformCommissionRate").toString()).divide(new BigDecimal(100)); - //提成类型(0总金额提成 1服务费提成) - if(commissionType==0){ - BigDecimal multiply1 = surplusPowerPrice.multiply(platformCommissionRate); - BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate); - platformCommission = multiply1.add(multiply2); - //剩下的钱 - surplusPowerPrice = surplusPowerPrice.subtract(multiply1); - surplusServicePrice = surplusServicePrice.subtract(multiply2); - BigDecimal multiply3 = surplusPowerPrice.multiply(maintenanceCommissionRate); - BigDecimal multiply4 = surplusServicePrice.multiply(maintenanceCommissionRate); - operationCommission = multiply1.add(multiply2); - //剩下的钱 - surplusPowerPrice = surplusPowerPrice.subtract(multiply3); - surplusServicePrice = surplusServicePrice.subtract(multiply4); - - }else if(commissionType==1){ - BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate); - platformSvcCommission=multiply2; - //剩下的钱 - surplusServicePrice = surplusServicePrice.subtract(multiply2); - - BigDecimal multiply4 = surplusServicePrice.multiply(maintenanceCommissionRate); - operationCommission = multiply4; - //剩下的钱 - surplusServicePrice = surplusServicePrice.subtract(multiply4); - } - }else{ - //订单异常 - xhpcChargeOrder.setStatus(2); - //异常原因 - xhpcChargeOrder.setErroRemark("运营商数据为空"); - } - } - - Long chargeOrderId = xhpcChargeOrder.getChargeOrderId(); - xhpcHistoryOrder.setChargeOrderId(chargeOrderId); - xhpcHistoryOrder.setChargingStationId(xhpcChargeOrder.getChargingStationId()); - xhpcHistoryOrder.setUserId(userId); - xhpcHistoryOrder.setTerminalId(xhpcChargeOrder.getTerminalId()); - xhpcHistoryOrder.setStartTime(xhpcChargeOrder.getStartTime()); - xhpcHistoryOrder.setStopReasonEvcs(xhpcChargeOrder.getStopReasonEvcs());//todo 从头开始设置所有evcs字段 - xhpcHistoryOrder.setChargeModelEvcs(xhpcChargeOrder.getChargeModelEvcs()); - xhpcHistoryOrder.setSerialNumber(xhpcChargeOrder.getSerialNumber()); - xhpcHistoryOrder.setStartSoc(xhpcChargeOrder.getStartSoc()); - xhpcHistoryOrder.setReconciliationStatus(0); - xhpcHistoryOrder.setSortingStatus(0); - xhpcHistoryOrder.setType(1); - //订单总价---运维服务费抽成 - xhpcHistoryOrder.setTotalPrice(money.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setPromotionDiscount(promotionDiscount.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setActPrice(actPrice.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setActPowerPrice(surplusPowerPrice.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setActServicePrice(surplusServicePrice.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setInternetCommission(internetCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setPlatformCommission(platformCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setPlatformSvcCommisssion(platformSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setOperationCommission(operationCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setOperationSvcCommission(operationSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); - xhpcHistoryOrder.setStartSoc(xhpcChargeOrder.getStartSoc()); - xhpcHistoryOrder.setEndSoc(xhpcChargeOrder.getEndSoc()); - xhpcHistoryOrder.setReconciliationStatus(0); - xhpcHistoryOrder.setCreateTime(new Date()); - xhpcHistoryOrder.setChargeModelEvcs(3); - xhpcHistoryOrder.setUserNameEvcs(userMessage.get("phone").toString()); - xhpcHistoryOrder.setPhone(userMessage.get("phone").toString()); - xhpcHistoryOrder.setConnectorPowerEvcs(Double.parseDouble(xhpcChargeOrder.getPower())); - - - //扣除用户实际消费金额,添加消费记录 - Map user = xhpcChargeOrderService.getUserMessage(userId); - //剩余的钱 - BigDecimal balance1 =(BigDecimal) user.get("balance"); - BigDecimal subtract = balance1.subtract(actPrice); - int i = xhpcChargeOrderService.updateUserBalance(userId, subtract); - if(i==0){ - //扣钱失败 xhpcChargeOrder.setStatus(2); - xhpcChargeOrder.setErroRemark("扣钱失败"); - }else{ - insert(xhpcHistoryOrder); - //添加流水 - xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date); - try{ - Map xhpcChargingPile = xhpcChargeOrderService.getXhpcChargingPile(xhpcChargeOrder.getTerminalId()); - if(xhpcChargingPile !=null){ - //发送短信 - if(user.get("phone") !=null){ - if("1".equals(xhpcChargingPile.get("type").toString())){ - HashMap paramMap = new HashMap<>(); - paramMap.put("elec", xhpcChargeOrder.getEndSoc()); - paramMap.put("sumMoney", actPrice.toString()); - paramMap.put("phone", user.get("phone").toString()); - paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。"); - smsService.sendNotice(paramMap); - }else { - HashMap paramMap = new HashMap<>(); - paramMap.put("sumMoney", actPrice.toString()); - paramMap.put("phone", user.get("phone").toString()); - paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。"); - smsService.sendNotice(paramMap); + } + xhpcChargeOrder.setEndSoc(cacheRealtimeData.getSoc()+""); + //充电时长 + Long tiem = Long.valueOf(cacheRealtimeData.getChargingTime() / 1000); + if (tiem > 3600) { + long hours = tiem / 3600; + double mins = (double) ((tiem - (hours * 3600)) / 60); + xhpcChargeOrder.setChargingTime(hours + "时" + new BigDecimal(mins).setScale(0) + "分"); + } else { + double mins = (double) (tiem / 60); + xhpcChargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "分"); + } + BigDecimal decimal = new BigDecimal(10000); + xhpcChargeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal)); + xhpcChargeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal)); + xhpcChargeOrder.setChargingTimeNumber(Long.valueOf(cacheRealtimeData.getChargingTime())); + + + if(checking){ + BigDecimal money =xhpcChargeOrder.getAmountCharged(); + //结算 + //总电费 + BigDecimal powerPrice =new BigDecimal(0); + //算时间是否跨天 + Long rateModelId = xhpcChargeOrder.getRateModelId(); + + Date updateTime2 = xhpcChargeOrder.getEndTime(); + long betweenDay = DateUtil.between(startTime2, updateTime2, DateUnit.DAY); + + if(betweenDay==0){ + powerPrice=getBigDecimal(rateModelId,startTime2,updateTime2,xhpcChargeOrder.getChargingDegree()); + }else{ + //跨天 + String startTime = DateUtil.format(startTime2, "yyyy-MM-dd"); + Date updateTime = DateUtil.parse(startTime+" 23:59:59"); + powerPrice=getBigDecimal(rateModelId,startTime2,updateTime,xhpcChargeOrder.getChargingDegree()); + //明天 + DateTime tomorrow = DateUtil.offsetDay(startTime2,1); + Date startTime3 =DateUtil.beginOfDay(tomorrow); + powerPrice=powerPrice.add(getBigDecimal(rateModelId,startTime3,updateTime2,xhpcChargeOrder.getChargingDegree())); + } + + //总服务费 + BigDecimal servicePrice = money.subtract(powerPrice); + //剩余的电费 + BigDecimal surplusPowerPrice = powerPrice; + //剩余的服务费 + BigDecimal surplusServicePrice = servicePrice; + + Map userMessage = xhpcChargeOrderService.getUserMessage(userId); + + XhpcHistoryOrder xhpcHistoryOrder = new XhpcHistoryOrder(); + xhpcHistoryOrder.setStopReasonEvcs(5); + xhpcHistoryOrder.setPowerPriceTotal(powerPrice); + xhpcHistoryOrder.setServicePriceTotal(servicePrice); + xhpcHistoryOrder.setTotalPower(cacheRealtimeData.getAmountCharged().doubleValue()/10000); + //电表总起值 + //xhpcHistoryOrder.setMeterValueStartEvcs(cacheOrderData.getElectricMeterStart().doubleValue()); + //电表总止值 + //xhpcHistoryOrder.setMeterValueEndEvcs(cacheOrderData.getElectricMeterEnd().doubleValue()); + //vin + //xhpcHistoryOrder.setVinNormal(vinNormal); + BigDecimal balance = new BigDecimal(userMessage.get("balance").toString()).divide(new BigDecimal(100)); + //电站活动抵扣--抵扣的总金额 + BigDecimal promotionDiscount = new BigDecimal(0); + + //实际价格-用户支付的钱 + BigDecimal actPrice =money; + //流量方总金额抽成 + BigDecimal internetCommission =new BigDecimal(0); + //流量方服务费抽成 + BigDecimal internetSvcCommission =new BigDecimal(0); + //平台总金额抽成 + BigDecimal platformCommission =new BigDecimal(0); + //平台服务费抽成 + BigDecimal platformSvcCommission =new BigDecimal(0); + //运维总抽成 + BigDecimal operationCommission =new BigDecimal(0); + //运维服务费抽成 + BigDecimal operationSvcCommission =new BigDecimal(0); + //判断是C端用户还是流量端用户 + if (xhpcChargeOrder.getSource() == 0) { + String state = ""; + BigDecimal discount = new BigDecimal(0); + //用户第几次充电 + int count = xhpcChargeOrderService.getCount(userId,xhpcChargeOrder.getChargeOrderId()); + if (count == 0) { + //活动折扣 + Map promotion = xhpcChargeOrderService.getPromotion(); + if (promotion != null && promotion.get("state") != null && promotion.get("discount") != null) { + //state 1.总金额 2.电费 3.服务费 discount 折扣率 + state = promotion.get("state").toString(); + discount =new BigDecimal(promotion.get("discount").toString()); + } + } + if(!"".equals(state)){ + + //查看是否优惠为0 + boolean fan = true; + if(discount.compareTo(new BigDecimal(0))==0){ + fan=false; + } + if("1".equals(state)){ + //总金额 + if(fan){ + promotionDiscount=money.multiply(discount); + actPrice = money.subtract(promotionDiscount); + surplusPowerPrice = surplusPowerPrice.subtract(promotionDiscount.divide(new BigDecimal(2))); + surplusServicePrice= surplusServicePrice.subtract(promotionDiscount.divide(new BigDecimal(2))); + } + }else if("2".equals(state)){ + if(fan){ + //电费 + promotionDiscount =powerPrice.multiply(balance); + actPrice = money.subtract(promotionDiscount); + surplusPowerPrice=surplusPowerPrice.subtract(promotionDiscount); + } + }else if("3".equals(state)){ + if(fan){ + //服务费 + promotionDiscount = servicePrice.multiply(balance); + actPrice = money.subtract(promotionDiscount); + surplusServicePrice =surplusServicePrice.subtract(promotionDiscount); } } } - }catch (Exception e){ - logger.info("<<<<<<<<<<<<<<<<发送短信失败>>>>>>>>>>>>>>>>>"); + xhpcHistoryOrder.setInternetCommission(internetCommission); + xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission); + }else{ + //流量方,未实现,新增接口 } - // 另起线程处理业务上传redis数据 - executorService.execute(new Runnable() { - @Override - public void run() { - xhpcRealTimeOrderService.addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(),1); + //获取运营商 + Map operatorMessage = xhpcChargeOrderService.getOperatorMessage(xhpcChargeOrder.getChargingStationId()); + if(operatorMessage !=null){ + if(operatorMessage.get("operatorIdEvcs")!=null){ + + if(operatorMessage.get("operatorIdEvcs") !=null && !"".equals(operatorMessage.get("operatorIdEvcs").toString())){ + String stw = operatorMessage.get("operatorIdEvcs").toString(); + if(stw.length()>9){ + xhpcHistoryOrder.setOperatorIdEvcs(stw.substring(8, stw.length() - 1)); + } + } } - }); + if(operatorMessage.get("maintenanceCommissionRate") !=null && operatorMessage.get("commissionType") !=null && operatorMessage.get("platformCommissionRate") !=null){ + Integer commissionType = (Integer) operatorMessage.get("commissionType"); + //运维提成 + BigDecimal maintenanceCommissionRate = new BigDecimal(operatorMessage.get("maintenanceCommissionRate").toString()).divide(new BigDecimal(100)); + //平台提成 + BigDecimal platformCommissionRate = new BigDecimal(operatorMessage.get("platformCommissionRate").toString()).divide(new BigDecimal(100)); + //提成类型(0总金额提成 1服务费提成) + if(commissionType==0){ + BigDecimal multiply1 = surplusPowerPrice.multiply(platformCommissionRate); + BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate); + platformCommission = multiply1.add(multiply2); + //剩下的钱 + surplusPowerPrice = surplusPowerPrice.subtract(multiply1); + surplusServicePrice = surplusServicePrice.subtract(multiply2); + BigDecimal multiply3 = surplusPowerPrice.multiply(maintenanceCommissionRate); + BigDecimal multiply4 = surplusServicePrice.multiply(maintenanceCommissionRate); + operationCommission = multiply1.add(multiply2); + //剩下的钱 + surplusPowerPrice = surplusPowerPrice.subtract(multiply3); + surplusServicePrice = surplusServicePrice.subtract(multiply4); + + }else if(commissionType==1){ + BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate); + platformSvcCommission=multiply2; + //剩下的钱 + surplusServicePrice = surplusServicePrice.subtract(multiply2); + + BigDecimal multiply4 = surplusServicePrice.multiply(maintenanceCommissionRate); + operationCommission = multiply4; + //剩下的钱 + surplusServicePrice = surplusServicePrice.subtract(multiply4); + } + }else{ + //订单异常 + xhpcChargeOrder.setStatus(2); + //异常原因 + xhpcChargeOrder.setErroRemark("运营商数据为空"); + } + } + + Long chargeOrderId = xhpcChargeOrder.getChargeOrderId(); + xhpcHistoryOrder.setChargeOrderId(chargeOrderId); + xhpcHistoryOrder.setChargingStationId(xhpcChargeOrder.getChargingStationId()); + xhpcHistoryOrder.setUserId(userId); + xhpcHistoryOrder.setTerminalId(xhpcChargeOrder.getTerminalId()); + xhpcHistoryOrder.setStartTime(xhpcChargeOrder.getStartTime()); + xhpcHistoryOrder.setStopReasonEvcs(xhpcChargeOrder.getStopReasonEvcs());//todo 从头开始设置所有evcs字段 + xhpcHistoryOrder.setChargeModelEvcs(xhpcChargeOrder.getChargeModelEvcs()); + xhpcHistoryOrder.setSerialNumber(xhpcChargeOrder.getSerialNumber()); + xhpcHistoryOrder.setStartSoc(xhpcChargeOrder.getStartSoc()); + xhpcHistoryOrder.setReconciliationStatus(0); + xhpcHistoryOrder.setSortingStatus(0); + xhpcHistoryOrder.setType(1); + //订单总价---运维服务费抽成 + xhpcHistoryOrder.setTotalPrice(money.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setPromotionDiscount(promotionDiscount.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setActPrice(actPrice.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setActPowerPrice(surplusPowerPrice.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setActServicePrice(surplusServicePrice.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setInternetCommission(internetCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setPlatformCommission(platformCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setPlatformSvcCommisssion(platformSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setOperationCommission(operationCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setOperationSvcCommission(operationSvcCommission.setScale(2, BigDecimal.ROUND_DOWN)); + xhpcHistoryOrder.setStartSoc(xhpcChargeOrder.getStartSoc()); + xhpcHistoryOrder.setEndSoc(xhpcChargeOrder.getEndSoc()); + xhpcHistoryOrder.setReconciliationStatus(0); + xhpcHistoryOrder.setCreateTime(new Date()); + xhpcHistoryOrder.setChargeModelEvcs(3); + xhpcHistoryOrder.setUserNameEvcs(userMessage.get("phone").toString()); + xhpcHistoryOrder.setPhone(userMessage.get("phone").toString()); + xhpcHistoryOrder.setConnectorPowerEvcs(Double.parseDouble(xhpcChargeOrder.getPower())); + + + //扣除用户实际消费金额,添加消费记录 + Map user = xhpcChargeOrderService.getUserMessage(userId); + //剩余的钱 + BigDecimal balance1 =(BigDecimal) user.get("balance"); + BigDecimal subtract = balance1.subtract(actPrice); + int i = xhpcChargeOrderService.updateUserBalance(userId, subtract); + if(i==0){ + //扣钱失败 + xhpcChargeOrder.setStatus(2); + xhpcChargeOrder.setErroRemark("扣钱失败"); + }else{ + insert(xhpcHistoryOrder); + //添加流水 + xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date); + try{ + Map xhpcChargingPile = xhpcChargeOrderService.getXhpcChargingPile(xhpcChargeOrder.getTerminalId()); + if(xhpcChargingPile !=null){ + //发送短信 + if(user.get("phone") !=null){ + if("1".equals(xhpcChargingPile.get("type").toString())){ + HashMap paramMap = new HashMap<>(); + paramMap.put("elec", xhpcChargeOrder.getEndSoc()); + paramMap.put("sumMoney", actPrice.toString()); + paramMap.put("phone", user.get("phone").toString()); + paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。"); + smsService.sendNotice(paramMap); + }else { + HashMap paramMap = new HashMap<>(); + paramMap.put("sumMoney", actPrice.toString()); + paramMap.put("phone", user.get("phone").toString()); + paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。"); + smsService.sendNotice(paramMap); + } + } + } + }catch (Exception e){ + logger.info("<<<<<<<<<<<<<<<<发送短信失败>>>>>>>>>>>>>>>>>"); + } + // 另起线程处理业务上传redis数据 + executorService.execute(new Runnable() { + @Override + public void run() { + xhpcRealTimeOrderService.addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(),1); + } + }); + } } + xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder); + } catch (Exception e) { + logger.info("异常订单回调失败"); + e.printStackTrace(); } - xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder); - } catch (Exception e) { - logger.info("异常订单回调失败"); - e.printStackTrace(); } + } /** 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 5677c833..702b14d7 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 @@ -256,6 +256,16 @@ public class XhpcStatisticsServiceImpl implements IXhpcStatisticsService { return map; } + /** + * 平台管理员权限问题 + */ + + private void jurisdiction(String userId){ + + + + + } } 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 1fc5cf6a..c08e8786 100644 --- a/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcStatisticsMapper.xml +++ b/xhpc-modules/xhpc-order/src/main/resources/mapper/XhpcStatisticsMapper.xml @@ -95,6 +95,11 @@ and internet_user_id=#{internetUserId} + + and operator_id in ( + SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId}) + ) + group by status order by status @@ -133,6 +138,11 @@ and internet_user_id=#{internetUserId} + + and operator_id in ( + SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId}) + ) + group by DATE_FORMAT(create_time,'%Y-%m-%d') order by DATE_FORMAT(create_time,'%Y-%m-%d') desc @@ -181,6 +191,11 @@ #{operatorId} + + and operator_id in ( + SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId}) + ) + group by ss.charging_station_id @@ -222,6 +237,11 @@ and ss.internet_user_id=#{internetUserId} + + and operator_id in ( + SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId}) + ) + group by ss.operator_id @@ -296,6 +316,11 @@ and te.terminal_id=#{terminalId} + + and operator_id in ( + SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId}) + ) + group by ss.terminal_id @@ -308,6 +333,9 @@ and operator_id =#{operatorId} + + and charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId}) + @@ -320,6 +348,11 @@ and operator_id =#{operatorId} + + and operator_id in ( + SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId}) + ) +