开放24小时自动审核异常订单

This commit is contained in:
yuyang 2022-04-25 13:30:45 +08:00
parent 1662362567
commit e2453aa785
12 changed files with 62 additions and 440 deletions

View File

@ -702,8 +702,7 @@ public class XhpcChargingStationServiceImpl extends BaseService implements IXhpc
if (map !=null &&map.get("imgId") != null && map.get("imgId").toString() != "") { if (map !=null &&map.get("imgId") != null && map.get("imgId").toString() != "") {
String[] split = map.get("imgId").toString().split(","); String[] split = map.get("imgId").toString().split(",");
imgList = Arrays.asList(split); imgList = Arrays.asList(split);
List<Map<String, Object>> imgLists = xhpcChargingStationMapper.getImageList(imgList); map.put("imgIdList", imgList);
map.put("imgIdList", imgLists);
} else { } else {
map.put("imgIdList", new ArrayList<>()); map.put("imgIdList", new ArrayList<>());
} }

View File

@ -378,22 +378,22 @@ public class XhpcPileOrderController extends BaseController {
BigDecimal powerPrice =new BigDecimal(0); BigDecimal powerPrice =new BigDecimal(0);
Integer totalPower =0; Integer totalPower =0;
if(!"0".equals(cacheOrderData.getT1PowerQuantity().toString())){ if(!"0".equals(cacheOrderData.getT1PowerQuantity().toString())){
BigDecimal multiply = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(t1powerFee); BigDecimal multiply = new BigDecimal(cacheOrderData.getT1PowerQuantity()).divide(bigDecimal).multiply(t1powerFee).setScale(2, BigDecimal.ROUND_HALF_UP);
totalPower =totalPower+cacheOrderData.getT1PowerQuantity(); totalPower =totalPower+cacheOrderData.getT1PowerQuantity();
powerPrice=powerPrice.add(multiply); powerPrice=powerPrice.add(multiply);
} }
if(!"0".equals(cacheOrderData.getT2PowerQuantity().toString())){ if(!"0".equals(cacheOrderData.getT2PowerQuantity().toString())){
BigDecimal multiply = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(t2powerFee); BigDecimal multiply = new BigDecimal(cacheOrderData.getT2PowerQuantity()).divide(bigDecimal).multiply(t2powerFee).setScale(2, BigDecimal.ROUND_HALF_UP);
totalPower =totalPower+cacheOrderData.getT2PowerQuantity(); totalPower =totalPower+cacheOrderData.getT2PowerQuantity();
powerPrice=powerPrice.add(multiply); powerPrice=powerPrice.add(multiply);
} }
if(!"0".equals(cacheOrderData.getT3PowerQuantity().toString())){ if(!"0".equals(cacheOrderData.getT3PowerQuantity().toString())){
BigDecimal multiply = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(t3powerFee); BigDecimal multiply = new BigDecimal(cacheOrderData.getT3PowerQuantity()).divide(bigDecimal).multiply(t3powerFee).setScale(2, BigDecimal.ROUND_HALF_UP);
totalPower =totalPower+cacheOrderData.getT3PowerQuantity(); totalPower =totalPower+cacheOrderData.getT3PowerQuantity();
powerPrice=powerPrice.add(multiply); powerPrice=powerPrice.add(multiply);
} }
if(!"0".equals(cacheOrderData.getT4PowerQuantity().toString())){ if(!"0".equals(cacheOrderData.getT4PowerQuantity().toString())){
BigDecimal multiply = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(t4powerFee); BigDecimal multiply = new BigDecimal(cacheOrderData.getT4PowerQuantity()).divide(bigDecimal).multiply(t4powerFee).setScale(2, BigDecimal.ROUND_HALF_UP);
totalPower =totalPower+cacheOrderData.getT4PowerQuantity(); totalPower =totalPower+cacheOrderData.getT4PowerQuantity();
powerPrice=powerPrice.add(multiply); powerPrice=powerPrice.add(multiply);
} }
@ -433,7 +433,7 @@ public class XhpcPileOrderController extends BaseController {
xhpcChargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + ""); xhpcChargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "");
} }
xhpcChargeOrder.setChargingTimeNumber(tiem); xhpcChargeOrder.setChargingTimeNumber(tiem);
BigDecimal divide = new BigDecimal(cacheOrderData.getTotalPowerQuantity()).divide(bigDecimal); BigDecimal divide = new BigDecimal(cacheOrderData.getTotalPowerQuantity()).divide(bigDecimal,2, BigDecimal.ROUND_HALF_UP);
xhpcChargeOrder.setChargingDegree(divide); xhpcChargeOrder.setChargingDegree(divide);
xhpcChargeOrder.setAmountCharged(money); xhpcChargeOrder.setAmountCharged(money);
String stopReason = cacheOrderData.getStopReason(); String stopReason = cacheOrderData.getStopReason();
@ -474,7 +474,6 @@ public class XhpcPileOrderController extends BaseController {
return R.fail(500,"添加订单回调失败"); return R.fail(500,"添加订单回调失败");
} }
}else{ }else{
if(pushOrder !=null){ if(pushOrder !=null){
if(pushOrder.get("internetSerialNumber") !=null){ if(pushOrder.get("internetSerialNumber") !=null){
xhpcHistoryOrder.setInternetSerialNumber(pushOrder.get("internetSerialNumber").toString()); xhpcHistoryOrder.setInternetSerialNumber(pushOrder.get("internetSerialNumber").toString());

View File

@ -878,51 +878,43 @@ public class XhpcHistoryOrderController extends BaseController {
//@Scheduled(cron = "0 0/5 * * * ?") //@Scheduled(cron = "0 0/5 * * * ?")
public void test4(){ public void test4(){
//获取异常的订单 24小时之外的异常订单 //获取异常的订单 24小时之外的异常订单
List<XhpcChargeOrder> xhpcChargeOrderList= chargeOrderService.getXhpcChargeOrderStatus(2, 0); List<Map<String,Object>> xhpcChargeOrderList= chargeOrderService.getXhpcChargeOrderStatus(2);
if(xhpcChargeOrderList !=null && xhpcChargeOrderList.size()>0){ if(xhpcChargeOrderList !=null && xhpcChargeOrderList.size()>0){
for (int i = 0; i <xhpcChargeOrderList.size() ; i++) { for (int i = 0; i <xhpcChargeOrderList.size() ; i++) {
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderList.get(i); Map<String,Object> map = xhpcChargeOrderList.get(i);
Integer source = xhpcChargeOrder.getSource(); if(map !=null){
String tenantId = xhpcChargeOrder.getTenantId(); Long chargeOrderId = Long.valueOf(map.get("chargeOrderId").toString());
if(!UserTypeUtil.INTERNET_TYPE.equals(source)){ if(map.get("realTimeOrderId")!=null){
R user = userTypeService.getUser(null, xhpcChargeOrder.getUserId(), source, null, tenantId); Long realTimeOrderId = Long.valueOf(map.get("realTimeOrderId").toString());
if(user !=null && user.getData() !=null){ xhpcHistoryOrderService.addXhpcChargeOrder(realTimeOrderId,chargeOrderId);
Map<String, Object> userMessage = (Map<String, Object>)user.getData();
if (userMessage != null && userMessage.get("balance") != null) {
xhpcHistoryOrderService.addXhpcChargeOrder(userMessage,xhpcChargeOrder.getSerialNumber(),2);
}
}
}else{ }else{
xhpcHistoryOrderService.addXhpcChargeOrder(null,xhpcChargeOrder.getSerialNumber(),2); xhpcHistoryOrderService.addXhpcChargeOrder(null,chargeOrderId);
} }
} }
} }
} }
}
@GetMapping("/getManualAudit") @GetMapping("/test44")
public void getManualAudit(Long chargeOrderId){ public void test44(){
//获取异常的订单 24小时之外的异常订单 //获取异常的订单 24小时之外的异常订单
XhpcChargeOrder xhpcChargeOrder = chargeOrderService.getChargingOrderId(chargeOrderId); List<Map<String,Object>> xhpcChargeOrderList= chargeOrderService.getXhpcChargeOrderStatus(2);
if(xhpcChargeOrder !=null){
Integer source = xhpcChargeOrder.getSource(); if(xhpcChargeOrderList !=null && xhpcChargeOrderList.size()>0){
String tenantId = xhpcChargeOrder.getTenantId(); for (int i = 0; i <xhpcChargeOrderList.size() ; i++) {
xhpcChargeOrder.getChargeOrderId(); Map<String,Object> map = xhpcChargeOrderList.get(i);
if(!UserTypeUtil.INTERNET_TYPE.equals(source)){ if(map !=null){
R user = userTypeService.getUser(null, xhpcChargeOrder.getUserId(), source, null, tenantId); Long chargeOrderId = Long.valueOf(map.get("chargeOrderId").toString());
if(user !=null && user.getData() !=null){ if(map.get("realTimeOrderId")!=null){
Map<String, Object> userMessage = (Map<String, Object>)user.getData(); Long realTimeOrderId = Long.valueOf(map.get("realTimeOrderId").toString());
if (userMessage != null && userMessage.get("balance") != null) { xhpcHistoryOrderService.addXhpcChargeOrder(realTimeOrderId,chargeOrderId);
xhpcHistoryOrderService.addXhpcChargeOrder(userMessage,xhpcChargeOrder.getSerialNumber(),2);
}
}
}else{ }else{
xhpcHistoryOrderService.addXhpcChargeOrder(null,xhpcChargeOrder.getSerialNumber(),2); xhpcHistoryOrderService.addXhpcChargeOrder(null,chargeOrderId);
}
}
} }
} }
} }
/** /**
* 标记异常大于创建4小时标记为异常 * 标记异常大于创建4小时标记为异常

View File

@ -93,7 +93,7 @@ public class XhpcRealTimeOrderController extends BaseController {
*/ */
@GetMapping("/getExamineMessage") @GetMapping("/getExamineMessage")
public AjaxResult getExamineMessage(Long realTimeOrderId,Long chargeOrderId){ public AjaxResult getExamineMessage(Long realTimeOrderId,Long chargeOrderId){
return xhpcRealTimeOrderService.getExamineMessage(realTimeOrderId,chargeOrderId); return AjaxResult.success(xhpcRealTimeOrderService.getExamineMessage(realTimeOrderId,chargeOrderId));
} }
/** /**

View File

@ -175,7 +175,7 @@ public interface XhpcChargeOrderMapper {
* @param source 0C端用户 1流量用户 * @param source 0C端用户 1流量用户
* @return * @return
*/ */
List<XhpcChargeOrder> getXhpcChargeOrderStatus(@Param("status") Integer status, @Param("source") Integer source); List<Map<String,Object>> getXhpcChargeOrderStatus(@Param("status") Integer status);
/** /**
* insert a row by 3rd. * insert a row by 3rd.

View File

@ -146,13 +146,11 @@ public interface IXhpcChargeOrderService {
*/ */
Map<String,Object> getXhpcChargingPile(Long terminalId); Map<String,Object> getXhpcChargingPile(Long terminalId);
/** /**
* 获取一次订单 * 24小时异常结算
* @param status -1准备充电 0开始充电 1自动结算2异常3平台结算
* @param source 0C端用户 1流量用户
* @return
*/ */
List<XhpcChargeOrder> getXhpcChargeOrderStatus(Integer status,Integer source); List<Map<String,Object>> getXhpcChargeOrderStatus(Integer status);
R startUpBy3rd(String internetSerialNumber, String driverId, Integer chargingAmt, String plateNum, Integer status, String connectorId); R startUpBy3rd(String internetSerialNumber, String driverId, Integer chargingAmt, String plateNum, Integer status, String connectorId);

View File

@ -101,11 +101,9 @@ public interface IXhpcHistoryOrderService {
/** /**
* 结算订单 * 异常订单24小时自动结算
* @param orderNo 订单号
* @param type 状态 1.异常 2.解决异常订单
*/ */
void addXhpcChargeOrder(Map<String, Object> userMessage,String orderNo,Integer type); void addXhpcChargeOrder(Long realTimeOrderId,Long chargeOrderId);
/** /**

View File

@ -93,7 +93,7 @@ public interface IXhpcRealTimeOrderService {
* @param realTimeOrderId * @param realTimeOrderId
* @return * @return
*/ */
AjaxResult getExamineMessage(Long realTimeOrderId,Long chargeOrderId); Map<String, Object> getExamineMessage(Long realTimeOrderId,Long chargeOrderId);
/** /**
* 审核 * 审核

View File

@ -448,8 +448,8 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar
} }
@Override @Override
public List<XhpcChargeOrder> getXhpcChargeOrderStatus(Integer status, Integer source) { public List<Map<String,Object>> getXhpcChargeOrderStatus(Integer status) {
return xhpcChargeOrderMapper.getXhpcChargeOrderStatus(status, source); return xhpcChargeOrderMapper.getXhpcChargeOrderStatus(status);
} }
@Override @Override

View File

@ -404,379 +404,15 @@ public class XhpcHistoryOrderServiceImpl extends BaseService implements IXhpcHis
} }
@Override @Override
public void addXhpcChargeOrder(Map<String, Object> userMessage,String orderNo, Integer type) { public void addXhpcChargeOrder(Long realTimeOrderId,Long chargeOrderId) {
//(调用时间-启动时间3分钟 自动结算) //(调用时间-启动时间3分钟 自动结算)
logger.info("订单异常回调接口>>>>>orderNo" + orderNo + " type:" + type); logger.info("订单异常回调接口>>>>>realTimeOrderId" + realTimeOrderId + " chargeOrderId:" + chargeOrderId);
//获取实时订单 Map<String, Object> map = xhpcRealTimeOrderService.getExamineMessage(realTimeOrderId,chargeOrderId);
CacheRealtimeData cacheRealtimeData = redisService.getCacheObject("order:" + orderNo + ".lord"); if(map !=null){
if (cacheRealtimeData != null) { BigDecimal powerPriceTotal = new BigDecimal(map.get("powerPriceTotal").toString());
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo); BigDecimal servicePriceTotal = new BigDecimal(map.get("servicePriceTotal").toString());
Long userId = xhpcChargeOrder.getUserId(); xhpcRealTimeOrderService.getExamine(chargeOrderId,powerPriceTotal,servicePriceTotal);
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;
}
//毫秒
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 time = (long) (cacheRealtimeData.getChargingTime() / 1000);
if (time > 3600) {
long hours = time / 3600;
double mins = (double) ((time - (hours * 3600)) / 60);
xhpcChargeOrder.setChargingTime(hours + "" + new BigDecimal(mins).setScale(0) + "");
} else {
double mins = (double) (time / 60);
xhpcChargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "");
}
BigDecimal decimal = new BigDecimal(10000);
xhpcChargeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal, 2, BigDecimal.ROUND_HALF_UP));
xhpcChargeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal, 2, BigDecimal.ROUND_HALF_UP));
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 {
//跨天
Date updateTime = DateUtil.endOfDay(startTime2);
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;
Integer source = xhpcChargeOrder.getSource();
String tenantId = xhpcChargeOrder.getTenantId();
XhpcHistoryOrder xhpcHistoryOrder = new XhpcHistoryOrder();
xhpcChargeOrder.setType("平台停止");
xhpcHistoryOrder.setStopReasonEvcs("平台停止");
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 internetDegreeCommission =new BigDecimal(0);
//平台总金额抽成
BigDecimal platformCommission = new BigDecimal(0);
//平台服务费抽成
BigDecimal platformSvcCommission = new BigDecimal(0);
//运维总抽成
BigDecimal operationCommission = new BigDecimal(0);
//运维服务费抽成
BigDecimal operationSvcCommission = new BigDecimal(0);
//判断是C端用户还是流量端用户
//先计算第三方优惠力度
String internetSerialNumber = xhpcChargeOrder.getInternetSerialNumber();
if(source==1 && internetSerialNumber!=null){
String substring = internetSerialNumber.substring(0, 9);
xhpcHistoryOrder.setInternetSerialNumber(xhpcChargeOrder.getInternetSerialNumber());
Map<String, Object> operatorIdEvcs = xhpcRealTimeOrderMapper.getOperatorIdEvcs(substring);
if(operatorIdEvcs !=null){
if(operatorIdEvcs.get("operatorIdEvcs")!=null && operatorIdEvcs.get("commissionType")!=null && operatorIdEvcs.get("commissionRate")!=null){
BigDecimal commissionRate = new BigDecimal(operatorIdEvcs.get("commissionRate").toString()).divide(new BigDecimal(100));
String commissionType = operatorIdEvcs.get("commissionType").toString();
if(operatorIdEvcs.get("internetUserId") !=null){
xhpcHistoryOrder.setChargingMode(operatorIdEvcs.get("internetUserId").toString());
}
//0总金额提成 1服务费提成
if(new BigDecimal(0).compareTo(commissionRate)==-1){
if("0".equals(commissionType) || "1".equals(commissionType)|| "2".equals(commissionType)){
//流量方的钱
if("0".equals(commissionType)){
BigDecimal decimal1 = surplusPowerPrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal decimal2 = surplusServicePrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_HALF_UP);
internetCommission = decimal1.add(decimal2);
surplusPowerPrice =surplusPowerPrice.subtract(decimal1);
surplusServicePrice =surplusServicePrice.subtract(decimal2);
}else if("1".equals(commissionType)){
BigDecimal decimal2 = surplusServicePrice.multiply(commissionRate).setScale(2, BigDecimal.ROUND_HALF_UP);
internetSvcCommission = decimal2;
surplusServicePrice = surplusServicePrice.subtract(decimal2);
}else{
//电量抽成
BigDecimal chargingDegree = xhpcChargeOrder.getChargingDegree();
internetDegreeCommission = chargingDegree.multiply(new BigDecimal(operatorIdEvcs.get("commissionRate").toString())).setScale(2, BigDecimal.ROUND_HALF_UP);
//减服务费
surplusServicePrice = surplusServicePrice.subtract(internetDegreeCommission);
}
}
}
}
}
}
if ( !UserTypeUtil.INTERNET_TYPE.equals(source)) {
//用户第几次充电
int count = xhpcChargeOrderService.getCount(userId,null,source,xhpcChargeOrder.getTenantId());
if (count == 0) {
//活动折扣
Map<String, Object> promotion = xhpcChargeOrderService.getPromotion();
if (promotion != null && promotion.get("state") != null && promotion.get("discount") != null) {
//state 1.总金额 2.电费 3.服务费 discount 折扣率
String state = promotion.get("state").toString();
BigDecimal discount =new BigDecimal(promotion.get("discount").toString()).divide(new BigDecimal(100));
if(discount.compareTo(new BigDecimal(0))==1){
if("1".equals(state) || "2".equals(state) || "3".equals(state)){
//折扣的钱
promotionDiscount=money.multiply(discount).setScale(2,BigDecimal.ROUND_HALF_UP);
//剩余的总金额
actPrice = money.subtract(promotionDiscount);
BigDecimal decimal1 = surplusPowerPrice.multiply(discount).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal decimal2 = surplusServicePrice.multiply(discount).setScale(2, BigDecimal.ROUND_HALF_UP);
if("1".equals(state)){
//总金额
actPrice =actPrice.subtract(decimal1.add(decimal2));
//折扣的钱
promotionDiscount = decimal1.add(decimal2);
surplusPowerPrice = surplusPowerPrice.subtract(decimal1);
surplusServicePrice= surplusServicePrice.subtract(decimal2);
}else if("2".equals(state)){
//电费
surplusPowerPrice=surplusPowerPrice.subtract(decimal1);
}else{
//服务费
surplusServicePrice =surplusServicePrice.subtract(decimal2);
}
}
}
}
}
}
//获取运营商
Map<String, Object> 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),2,BigDecimal.ROUND_HALF_UP);
//平台提成
BigDecimal platformCommissionRate = new BigDecimal(operatorMessage.get("platformCommissionRate").toString()).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP);
//提成类型0总金额提成 1服务费提成
if(commissionType==0){
//平台总抽成
BigDecimal multiply1 = surplusPowerPrice.multiply(platformCommissionRate).setScale(2,BigDecimal.ROUND_HALF_UP);
BigDecimal multiply2 = surplusServicePrice.multiply(platformCommissionRate).setScale(2,BigDecimal.ROUND_HALF_UP);
//运维总抽成
BigDecimal multiply3 = surplusPowerPrice.multiply(maintenanceCommissionRate).setScale(2,BigDecimal.ROUND_HALF_UP);
BigDecimal multiply4 = surplusServicePrice.multiply(maintenanceCommissionRate).setScale(2,BigDecimal.ROUND_HALF_UP);
//平台总金额抽成
platformCommission = multiply1.add(multiply2);
//剩下的钱电费和服务
surplusPowerPrice = surplusPowerPrice.subtract(multiply1);
surplusServicePrice = surplusServicePrice.subtract(multiply2);
//运维总金额抽成
operationCommission = multiply3.add(multiply4);
//剩下的钱电费和服务
surplusPowerPrice = surplusPowerPrice.subtract(multiply3);
surplusServicePrice = surplusServicePrice.subtract(multiply4);
}else if(commissionType==1){
BigDecimal multiply1 = surplusServicePrice.multiply(platformCommissionRate).setScale(2,BigDecimal.ROUND_HALF_UP);
BigDecimal multiply2 = surplusServicePrice.multiply(maintenanceCommissionRate).setScale(2,BigDecimal.ROUND_HALF_UP);
//平台服务费抽成金额
platformSvcCommission=multiply1;
//剩下的服务费钱
surplusServicePrice = surplusServicePrice.subtract(multiply1);
//运维服务费抽成金额
operationCommission = multiply2;
//剩下的钱
surplusServicePrice = surplusServicePrice.subtract(multiply2);
}
if("微信".equals(xhpcChargeOrder.getChargingMode())){
xhpcHistoryOrder.setChargingMode("微信");
}
if("支付宝".equals(xhpcChargeOrder.getChargingMode())){
xhpcHistoryOrder.setChargingMode("支付宝");
}
}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.setChargeModelEvcs(xhpcChargeOrder.getChargeModelEvcs());
xhpcHistoryOrder.setSerialNumber(xhpcChargeOrder.getSerialNumber());
xhpcHistoryOrder.setRateModelId(xhpcChargeOrder.getRateModelId());
xhpcHistoryOrder.setStartSoc(xhpcChargeOrder.getStartSoc());
xhpcHistoryOrder.setReconciliationStatus(0);
xhpcHistoryOrder.setSortingStatus(0);
xhpcHistoryOrder.setType(1);
//订单总价---运维服务费抽成
xhpcHistoryOrder.setTotalPrice(money.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setPromotionDiscount(promotionDiscount.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setActPrice(actPrice.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setActPowerPrice(surplusPowerPrice.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setActServicePrice(surplusServicePrice.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setInternetCommission(internetCommission.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setInternetDegreeCommission(internetDegreeCommission.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setPlatformCommission(platformCommission.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setPlatformSvcCommisssion(platformSvcCommission.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setOperationCommission(operationCommission.setScale(2, BigDecimal.ROUND_HALF_UP));
xhpcHistoryOrder.setOperationSvcCommission(operationSvcCommission.setScale(2, BigDecimal.ROUND_HALF_UP));
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());
if(xhpcChargeOrder.getPower()!=null){
xhpcHistoryOrder.setConnectorPowerEvcs(Double.parseDouble(xhpcChargeOrder.getPower()));
}
Map<String, Object> map =new HashMap<>();
if(!UserTypeUtil.INTERNET_TYPE.equals(source)){
xhpcHistoryOrder.setUserNameEvcs(userMessage.get("phone").toString());
xhpcHistoryOrder.setPhone(userMessage.get("phone").toString());
//增加流水订单号
if(operatorMessage!=null && operatorMessage.get("operatorId")!=null){
String evcs = EvcsUtil.transferInternetOrderNo(xhpcChargeOrder.getSerialNumber(), operatorMessage.get("operatorId").toString());
xhpcHistoryOrder.setEvcsOrderNo(evcs);
}
//扣除用户实际消费金额添加消费记录-余的钱
BigDecimal balance1 =new BigDecimal(userMessage.get("balance").toString());
BigDecimal subtract = balance1.subtract(actPrice);
int i = xhpcChargeOrderService.updateUserBalance(userId, subtract,source,xhpcChargeOrder.getTenantId());
if(i==0){
//扣钱失败
xhpcChargeOrder.setStatus(2);
xhpcChargeOrder.setErroRemark("扣钱失败");
}else{
//添加流水
xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date,source);
map.put("userId",userId);
map.put("amount",subtract);
map.put("source",xhpcChargeOrder.getSource());
map.put("tenantId",xhpcChargeOrder.getTenantId());
if(userMessage.get("weixinOpenId") !=null && !"".equals(userMessage.get("weixinOpenId").toString())){
map.put("openid",userMessage.get("weixinOpenId").toString());
map.put("type",1);
}else{
map.put("openid",userMessage.get("alipayOpenId").toString());
map.put("type",2);
}
map.put("remark","充电结算自动申请退款");
}
try{
Map<String, Object> xhpcChargingPile = xhpcChargeOrderService.getXhpcChargingPile(xhpcChargeOrder.getTerminalId());
if(xhpcChargingPile !=null){
//发送短信
if(userMessage.get("phone") !=null){
if("1".equals(xhpcChargingPile.get("type").toString())){
HashMap<String, String> paramMap = new HashMap<>();
paramMap.put("elec", xhpcChargeOrder.getEndSoc());
paramMap.put("sumMoney", actPrice.toString());
paramMap.put("phone", userMessage.get("phone").toString());
paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。");
smsService.sendNotice(paramMap);
}else {
HashMap<String, String> paramMap = new HashMap<>();
paramMap.put("sumMoney", actPrice.toString());
paramMap.put("phone", userMessage.get("phone").toString());
paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。");
smsService.sendNotice(paramMap);
}
}
}
}catch (Exception e){
logger.info("<<<<<<<<<<<<<<<<发送短信失败>>>>>>>>>>>>>>>>>");
}
}
insert(xhpcHistoryOrder);
// 另起线程处理业务上传redis数据
executorService.execute(new Runnable() {
@Override
public void run() {
//充电结算后自动申请退款
if(userMessage !=null && "1".equals(userMessage.get("isRefund").toString()) && map !=null){
refundOrderService.sendNotice(map.get("subtract").toString(),map.get("openid").toString(),source,map.get("type").toString(),map.get("userId").toString(),xhpcChargeOrder.getTenantId(),map.get("remark").toString());
}
xhpcRealTimeOrderService.addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(), 1);
}
});
}
xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder);
} catch (Exception e) {
logger.info("异常订单回调失败");
e.printStackTrace();
}
}
} }
@Override @Override

View File

@ -170,16 +170,14 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
@Transactional @Transactional
@Override @Override
public AjaxResult getExamineMessage(Long realTimeOrderId,Long chargeOrderId) { public Map<String, Object> getExamineMessage(Long realTimeOrderId,Long chargeOrderId) {
if(realTimeOrderId==null){ if(realTimeOrderId==null){
Map<String, Object> message = xhpcRealTimeOrderMapper.getMessageChargeOrderId(chargeOrderId); Map<String, Object> message = xhpcRealTimeOrderMapper.getMessageChargeOrderId(chargeOrderId);
message.put("powerPriceTotal",0); message.put("powerPriceTotal",0);
message.put("servicePriceTotal",0); message.put("servicePriceTotal",0);
return AjaxResult.success(message); return message;
} }
//基本信息 //基本信息
Map<String, Object> message = xhpcRealTimeOrderMapper.getMessage(realTimeOrderId); Map<String, Object> message = xhpcRealTimeOrderMapper.getMessage(realTimeOrderId);
try{ try{
@ -200,7 +198,7 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
endData =list.get(list.size()-1); endData =list.get(list.size()-1);
for (int i = 0; i <list.size() ; i++) { for (int i = 0; i <list.size() ; i++) {
startData =list.get(i); startData =list.get(i);
if(startData.getSoc()>0 && startData.getChargingTime()>0){ if(startData.getAmountCharged()>0 && startData.getChargingTime()>0){
break; break;
} }
} }
@ -261,7 +259,7 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
if(startRealTimeOrder.getRealTimeOrderId().equals(startRealTimeOrder.getRealTimeOrderId())){ if(startRealTimeOrder.getRealTimeOrderId().equals(startRealTimeOrder.getRealTimeOrderId())){
message.put("powerPriceTotal",0); message.put("powerPriceTotal",0);
message.put("servicePriceTotal",0); message.put("servicePriceTotal",0);
return AjaxResult.success(message); return message;
} }
chargeOrder.setStartTime(startTime); chargeOrder.setStartTime(startTime);
@ -275,7 +273,7 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
chargeOrder.setChargingTimeNumber(0L); chargeOrder.setChargingTimeNumber(0L);
} }
chargeOrder.setChargingDegree(chargingDegree); chargeOrder.setChargingDegree(chargingDegree);
chargeOrder.setType("平台停止"); chargeOrder.setType("平台停止充电");
chargeOrder.setAmountCharged(endRealTimeOrder.getAmountCharged()); chargeOrder.setAmountCharged(endRealTimeOrder.getAmountCharged());
} }
@ -323,7 +321,7 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
message.put("powerPriceTotal",0); message.put("powerPriceTotal",0);
message.put("servicePriceTotal",0); message.put("servicePriceTotal",0);
} }
return AjaxResult.success(message); return message;
} }
@ -349,7 +347,7 @@ public class XhpcRealTimeOrderServiceImpl extends BaseService implements IXhpcRe
xhpcChargeOrder.setStatus(3); xhpcChargeOrder.setStatus(3);
xhpcChargeOrder.setAmountCharged(money); xhpcChargeOrder.setAmountCharged(money);
xhpcChargeOrder.setStopReasonEvcs(45); xhpcChargeOrder.setStopReasonEvcs(45);
xhpcChargeOrder.setType("平台停止充电");
Long userId = xhpcChargeOrder.getUserId(); Long userId = xhpcChargeOrder.getUserId();
Integer source = xhpcChargeOrder.getSource(); Integer source = xhpcChargeOrder.getSource();
String tenantId = xhpcChargeOrder.getTenantId(); String tenantId = xhpcChargeOrder.getTenantId();

View File

@ -577,13 +577,15 @@
where charging_pile_id = (select charging_pile_id from xhpc_terminal where terminal_id = #{terminalId} and del_flag =0) and del_flag =0 where charging_pile_id = (select charging_pile_id from xhpc_terminal where terminal_id = #{terminalId} and del_flag =0) and del_flag =0
</select> </select>
<select id="getXhpcChargeOrderStatus" resultMap="XhpcChargeOrderResult"> <select id="getXhpcChargeOrderStatus" resultType="map">
select * select
from xhpc_charge_order xco.charge_order_id as chargeOrderId,
where del_flag = 0 max(xrt.real_time_order_id) as realTimeOrderId
and status = #{status} from xhpc_charge_order as xco
and source = #{source} left join xhpc_real_time_order as xrt on xrt.charging_order_id = xco.charge_order_id
and datediff(now(), create_time) > 1 where xco.del_flag = 0
and xco.status = #{status}
and datediff(now(), xco.create_time) > 1
</select> </select>