修改历史订单接口
This commit is contained in:
parent
a44f86b7a3
commit
7bcca156ac
@ -173,6 +173,10 @@ public class XhpcHistoryOrder extends BaseEntity {
|
||||
private Double totalPower;
|
||||
|
||||
private Date startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private Date endTime;
|
||||
|
||||
/**
|
||||
* 0:用户手动停止充电
|
||||
@ -644,4 +648,14 @@ public class XhpcHistoryOrder extends BaseEntity {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public Date getEndTime() {
|
||||
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(Date endTime) {
|
||||
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ import com.xhpc.order.domain.XhpcHistoryOrder;
|
||||
import com.xhpc.order.service.IXhpcChargeOrderService;
|
||||
import com.xhpc.order.service.IXhpcHistoryOrderService;
|
||||
import com.xhpc.order.service.IXhpcRealTimeOrderService;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -50,10 +51,6 @@ public class XhpcPileOrderController extends BaseController {
|
||||
@Autowired
|
||||
private IXhpcHistoryOrderService xhpcHistoryOrderService;
|
||||
|
||||
@Autowired
|
||||
private SmsService smsService;
|
||||
|
||||
private ExecutorService executorService = Executors.newFixedThreadPool(20);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(XhpcPileOrderController.class);
|
||||
/**
|
||||
@ -344,7 +341,8 @@ public class XhpcPileOrderController extends BaseController {
|
||||
//历史订单
|
||||
Long userId = xhpcChargeOrder.getUserId();
|
||||
//生成一条历史订单
|
||||
|
||||
xhpcHistoryOrder.setStartTime(startTime);
|
||||
xhpcHistoryOrder.setEndTime(endTime);
|
||||
xhpcHistoryOrder.setPowerPriceTotal(powerPrice);
|
||||
xhpcHistoryOrder.setServicePriceTotal(servicePrice);
|
||||
xhpcHistoryOrder.setTotalPower(totalPower.doubleValue()/10000);
|
||||
@ -380,293 +378,10 @@ public class XhpcPileOrderController extends BaseController {
|
||||
@Transactional
|
||||
@PostMapping("/chargeOrder/abnormalOrder")
|
||||
public R abnormalOrder(@RequestParam(value = "orderNo") String orderNo) {
|
||||
//(调用时间-启动时间《3分钟 自动结算)
|
||||
logger.info("订单异常回调接口>>>>>orderNo:" + orderNo);
|
||||
xhpcHistoryOrderService.addXhpcChargeOrder(orderNo,1);
|
||||
//获取实时订单
|
||||
CacheRealtimeData cacheRealtimeData = redisService.getCacheObject("order:" + orderNo + ".lord");
|
||||
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo);
|
||||
Long userId = xhpcChargeOrder.getUserId();
|
||||
try {
|
||||
//开始时间
|
||||
Date startTime2 = xhpcChargeOrder.getStartTime();
|
||||
//当checking为true时,自动结算
|
||||
boolean checking = false;
|
||||
if((System.currentTimeMillis()-startTime2.getTime())<180000){
|
||||
checking=true;
|
||||
}
|
||||
|
||||
long l = xhpcChargeOrder.getStartTime().getTime() + Long.parseLong(String.valueOf(cacheRealtimeData.getChargingTime()));
|
||||
//毫秒
|
||||
Date date = new Date(l);
|
||||
xhpcChargeOrder.setEndTime(date);
|
||||
xhpcChargeOrder.setUpdateTime(date);
|
||||
if(checking){
|
||||
xhpcChargeOrder.setStatus(1);
|
||||
}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()));
|
||||
xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder);
|
||||
|
||||
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<String, Object> 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<String, Object> 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<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));
|
||||
//平台提成
|
||||
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<String, Object> 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{
|
||||
xhpcHistoryOrderService.insert(xhpcHistoryOrder);
|
||||
//添加流水
|
||||
xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date);
|
||||
try{
|
||||
Map<String, Object> xhpcChargingPile = xhpcChargeOrderService.getXhpcChargingPile(xhpcChargeOrder.getTerminalId());
|
||||
if(xhpcChargingPile !=null){
|
||||
//发送短信
|
||||
if(user.get("phone") !=null){
|
||||
if("1".equals(xhpcChargingPile.get("type").toString())){
|
||||
String content = "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。";
|
||||
smsService.sendNotice(user.get("phone").toString(),content);
|
||||
}else{
|
||||
String content = "【小华停止充电】尊敬的用户,你的爱车已停止充电,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。";
|
||||
smsService.sendNotice(user.get("phone").toString(),content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
logger.info("<<<<<<<<<<<<<<<<发送短信失败>>>>>>>>>>>>>>>>>");
|
||||
}
|
||||
// 另起线程处理业务上传redis数据
|
||||
executorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
xhpcRealTimeOrderService.addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(),1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("异常订单回调失败");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", 500);
|
||||
map.put("userId", xhpcChargeOrder.getUserId());
|
||||
@ -709,61 +424,7 @@ public class XhpcPileOrderController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param rateModelId 费率id
|
||||
* @param startTime2 开始时间
|
||||
* @param updateTime2 结算时间
|
||||
* @param chargingDegree 总度数
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal getBigDecimal(Long rateModelId, Date startTime2, Date updateTime2, BigDecimal chargingDegree) {
|
||||
//算出相差时间,分
|
||||
BigDecimal decimal = new BigDecimal((updateTime2.getTime()-startTime2.getTime())/60000).setScale(2);
|
||||
//每分钟多少度
|
||||
BigDecimal degree =chargingDegree.divide(decimal).setScale(2);
|
||||
BigDecimal powerPriceTotal =new BigDecimal(0);
|
||||
//获取费率时间段
|
||||
String startTime = DateUtil.formatTime(startTime2);
|
||||
String endTime = DateUtil.formatTime(updateTime2);
|
||||
List<Map<String, Object>> reatTimeList = xhpcHistoryOrderService.getReatTimeList(startTime, endTime, rateModelId);
|
||||
if(reatTimeList !=null && reatTimeList.size()>0){
|
||||
int size = reatTimeList.size();
|
||||
if(size==1){
|
||||
BigDecimal powerFee = new BigDecimal(reatTimeList.get(0).get("powerFee").toString());
|
||||
powerPriceTotal = powerPriceTotal.add(powerFee.multiply(degree).setScale(2, RoundingMode.HALF_UP));
|
||||
}else{
|
||||
for (int i = 0; i <reatTimeList.size() ; i++) {
|
||||
Map<String, Object> objectMap = reatTimeList.get(i);
|
||||
BigDecimal powerPrice =new BigDecimal(objectMap.get("powerFee").toString());
|
||||
String startTime1 = objectMap.get("startTime").toString();
|
||||
String endTime1 = objectMap.get("endTime").toString();
|
||||
if(i==0){
|
||||
powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime,endTime1,degree,powerPrice));
|
||||
}else{
|
||||
if(size==2){
|
||||
powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime,endTime,degree,powerPrice));
|
||||
}else{
|
||||
//三个时段以上
|
||||
if(i<size-1){
|
||||
powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime1,endTime1,degree,powerPrice));
|
||||
}else{
|
||||
powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime1,endTime,degree,powerPrice));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return powerPriceTotal;
|
||||
}
|
||||
|
||||
private BigDecimal getRateTimeList(String startTime,String endTime,BigDecimal degree,BigDecimal powerPrice){
|
||||
BigDecimal v = new BigDecimal((DateUtil.parse(endTime).getTime() - DateUtil.parse(startTime).getTime())/60000).multiply(degree);
|
||||
BigDecimal multiply = powerPrice.multiply(v).setScale(2, RoundingMode.HALF_UP);
|
||||
return multiply;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import com.xhpc.common.core.web.controller.BaseController;
|
||||
import com.xhpc.common.core.web.domain.AjaxResult;
|
||||
import com.xhpc.common.core.web.page.TableDataInfo;
|
||||
import com.xhpc.order.domain.XhpcChargeOrder;
|
||||
import com.xhpc.order.domain.XhpcHistoryOrder;
|
||||
import com.xhpc.order.domain.XhpcStatisticsStation;
|
||||
import com.xhpc.order.domain.XhpcStatisticsTimeInterval;
|
||||
@ -40,6 +41,9 @@ public class XhpcHistoryOrderController extends BaseController {
|
||||
@Autowired
|
||||
private IXhpcStatisticsService xhpcStatisticsService;
|
||||
|
||||
@Autowired
|
||||
private IXhpcChargeOrderService chargeOrderService;
|
||||
|
||||
/**
|
||||
* 历史订单
|
||||
* @param phone 用户账号
|
||||
@ -76,7 +80,7 @@ public class XhpcHistoryOrderController extends BaseController {
|
||||
* 终端统计
|
||||
*/
|
||||
@GetMapping("/test3")
|
||||
@Scheduled(cron = "0 0 12 * * ?")
|
||||
//@Scheduled(cron = "0 0 12 * * ?")
|
||||
public void test3(){
|
||||
add(100,3);
|
||||
}
|
||||
@ -84,7 +88,7 @@ public class XhpcHistoryOrderController extends BaseController {
|
||||
* 场站统计
|
||||
*/
|
||||
@GetMapping("/test2")
|
||||
@Scheduled(cron = "0 0 11 * * ?")
|
||||
//@Scheduled(cron = "0 0 11 * * ?")
|
||||
public void test2(){
|
||||
add(100,2);
|
||||
}
|
||||
@ -93,7 +97,7 @@ public class XhpcHistoryOrderController extends BaseController {
|
||||
* 日期统计
|
||||
*/
|
||||
@GetMapping("/test1")
|
||||
@Scheduled(cron = "0 0 00 * * ?")
|
||||
//@Scheduled(cron = "0 0 00 * * ?")
|
||||
public void test1(){
|
||||
//获取500条待统计历史订单
|
||||
//跨时段,跨费率,计费模型
|
||||
@ -187,7 +191,9 @@ public class XhpcHistoryOrderController extends BaseController {
|
||||
if(xhpc.getTotalPrice().compareTo(new BigDecimal(0)) !=1){
|
||||
break;
|
||||
}
|
||||
|
||||
if(xhpc.getChargingDegree().compareTo(new BigDecimal(0)) !=1){
|
||||
break;
|
||||
}
|
||||
//每分钟多少度电
|
||||
BigDecimal v = new BigDecimal((endTime.getTime() - startTime.getTime())).divide(new BigDecimal(60000),2,RoundingMode.HALF_UP);
|
||||
BigDecimal multiply = xhpc.getChargingDegree().divide(v,2,RoundingMode.HALF_UP);
|
||||
@ -264,6 +270,25 @@ public class XhpcHistoryOrderController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 24小时异常订单自动结算
|
||||
*/
|
||||
@GetMapping("/test4")
|
||||
//@Scheduled(cron = "0 0/5 * * * ?")
|
||||
public void test4(){
|
||||
//获取异常的订单 24小时之外的异常订单
|
||||
List<XhpcChargeOrder> xhpcChargeOrderList= chargeOrderService.getXhpcChargeOrderStatus(2, 0);
|
||||
|
||||
if(xhpcChargeOrderList !=null && xhpcChargeOrderList.size()>0){
|
||||
for (int i = 0; i <xhpcChargeOrderList.size() ; i++) {
|
||||
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderList.get(i);
|
||||
xhpcHistoryOrderService.addXhpcChargeOrder(xhpcChargeOrder.getSerialNumber(),2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void add(int number,int type){
|
||||
//获取500条待统计历史订单
|
||||
List<XhpcChargeHistoryOrder> list = xhpcHistoryOrderService.getStatistisList(number,type);
|
||||
|
||||
@ -148,4 +148,13 @@ public interface XhpcChargeOrderMapper {
|
||||
* @return
|
||||
*/
|
||||
Map<String,Object> getXhpcChargingPile(@Param("terminalId")Long terminalId);
|
||||
|
||||
|
||||
/**
|
||||
* 获取一次订单
|
||||
* @param status -1准备充电 0开始充电 1自动结算,2异常,3平台结算
|
||||
* @param source 0C端用户 1流量用户
|
||||
* @return
|
||||
*/
|
||||
List<XhpcChargeOrder> getXhpcChargeOrderStatus(@Param("status")Integer status,@Param("source")Integer source);
|
||||
}
|
||||
|
||||
@ -143,4 +143,13 @@ public interface IXhpcChargeOrderService {
|
||||
* @return
|
||||
*/
|
||||
Map<String,Object> getXhpcChargingPile(Long terminalId);
|
||||
|
||||
/**
|
||||
* 获取一次订单
|
||||
* @param status -1准备充电 0开始充电 1自动结算,2异常,3平台结算
|
||||
* @param source 0C端用户 1流量用户
|
||||
* @return
|
||||
*/
|
||||
List<XhpcChargeOrder> getXhpcChargeOrderStatus(Integer status,Integer source);
|
||||
|
||||
}
|
||||
|
||||
@ -82,4 +82,12 @@ public interface IXhpcHistoryOrderService {
|
||||
*/
|
||||
void updateXhpcHistoryOrder(Long historyOrderId,Integer state);
|
||||
|
||||
|
||||
/**
|
||||
* 结算订单
|
||||
* @param orderNo 订单号
|
||||
* @param type 状态 1.异常 2.解决异常订单
|
||||
*/
|
||||
void addXhpcChargeOrder(String orderNo,Integer type);
|
||||
|
||||
}
|
||||
|
||||
@ -334,5 +334,10 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService {
|
||||
return xhpcChargeOrderMapper.getXhpcChargingPile(terminalId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<XhpcChargeOrder> getXhpcChargeOrderStatus(Integer status, Integer source) {
|
||||
return xhpcChargeOrderMapper.getXhpcChargeOrderStatus(status, source);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -3,19 +3,27 @@ package com.xhpc.order.service.impl;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.xhpc.common.api.SmsService;
|
||||
import com.xhpc.common.core.web.domain.AjaxResult;
|
||||
import com.xhpc.common.data.redis.CacheRealtimeData;
|
||||
import com.xhpc.common.redis.service.RedisService;
|
||||
import com.xhpc.order.domain.XhpcChargeOrder;
|
||||
import com.xhpc.order.domain.XhpcHistoryOrder;
|
||||
import com.xhpc.order.dto.XhpcChargeHistoryOrder;
|
||||
import com.xhpc.order.mapper.XhpcHistoryOrderMapper;
|
||||
import com.xhpc.order.service.IXhpcChargeOrderService;
|
||||
import com.xhpc.order.service.IXhpcHistoryOrderService;
|
||||
import com.xhpc.order.service.IXhpcRealTimeOrderService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @author yuyang
|
||||
@ -30,6 +38,20 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService {
|
||||
@Autowired
|
||||
private IXhpcChargeOrderService xhpcChargeOrderService;
|
||||
|
||||
@Autowired
|
||||
private SmsService smsService;
|
||||
|
||||
private ExecutorService executorService = Executors.newFixedThreadPool(20);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(XhpcHistoryOrderServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private IXhpcRealTimeOrderService xhpcRealTimeOrderService;
|
||||
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> list(Long userId) {
|
||||
return xhpcHistoryOrderMapper.list(userId);
|
||||
@ -87,6 +109,302 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService {
|
||||
xhpcHistoryOrderMapper.updateXhpcHistoryOrder(historyOrderId,state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addXhpcChargeOrder(String orderNo,Integer type) {
|
||||
//(调用时间-启动时间《3分钟 自动结算)
|
||||
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){
|
||||
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());
|
||||
}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<String, Object> 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<String, Object> 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<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));
|
||||
//平台提成
|
||||
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<String, Object> 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<String, Object> xhpcChargingPile = xhpcChargeOrderService.getXhpcChargingPile(xhpcChargeOrder.getTerminalId());
|
||||
if(xhpcChargingPile !=null){
|
||||
//发送短信
|
||||
if(user.get("phone") !=null){
|
||||
if("1".equals(xhpcChargingPile.get("type").toString())){
|
||||
String content = "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。";
|
||||
smsService.sendNotice(user.get("phone").toString(),content);
|
||||
}else{
|
||||
String content = "【小华停止充电】尊敬的用户,你的爱车已停止充电,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。";
|
||||
smsService.sendNotice(user.get("phone").toString(),content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史信息费率时段
|
||||
*/
|
||||
@ -125,8 +443,9 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService {
|
||||
private Map<String, Object> getBigDecimal(String actPrice, BigDecimal powerPriceTotal, BigDecimal servicePriceTotal, XhpcChargeOrder chargeOrder, Long rateModelId, Date startTime2, Date updateTime2, BigDecimal chargingDegree, List<Map<String, Object>> list) {
|
||||
Map<String, Object> map =new HashMap<>();
|
||||
//算出相差时间,分
|
||||
double time = (updateTime2.getTime()-startTime2.getTime())/60000;
|
||||
BigDecimal decimal = new BigDecimal(time).setScale(2);
|
||||
BigDecimal decimal = new BigDecimal((updateTime2.getTime()-startTime2.getTime())/60000).setScale(2);
|
||||
//每分钟多少度
|
||||
BigDecimal degree =chargingDegree.divide(decimal,2,BigDecimal.ROUND_DOWN);
|
||||
//获取费率时间段
|
||||
String startTime = DateUtil.formatTime(startTime2);
|
||||
String endTime = DateUtil.formatTime(updateTime2);
|
||||
@ -135,10 +454,10 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService {
|
||||
Map<String, Object> map1 =new HashMap<>();
|
||||
int size = reatTimeList.size();
|
||||
if(size==1){
|
||||
BigDecimal powerFee = new BigDecimal(reatTimeList.get(0).get("powerFee").toString());
|
||||
powerPriceTotal = powerFee.multiply(chargingDegree).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal servicePrice = new BigDecimal(reatTimeList.get(0).get("serviceFee").toString());
|
||||
servicePriceTotal=servicePrice.multiply(chargingDegree).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal powerFee = new BigDecimal(reatTimeList.get(0).get("powerFee").toString()).setScale(2, BigDecimal.ROUND_DOWN);
|
||||
powerPriceTotal = powerFee.multiply(degree).setScale(2, BigDecimal.ROUND_DOWN);
|
||||
BigDecimal servicePrice = new BigDecimal(reatTimeList.get(0).get("serviceFee").toString()).setScale(2, BigDecimal.ROUND_DOWN);
|
||||
servicePriceTotal=servicePrice.multiply(chargingDegree).setScale(2, BigDecimal.ROUND_DOWN);
|
||||
map1.put("time",startTime+"-"+endTime);
|
||||
map1.put("powerPrice",powerFee);
|
||||
map1.put("servicePrice",servicePrice);
|
||||
@ -148,21 +467,21 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService {
|
||||
}else{
|
||||
for (int i = 0; i <reatTimeList.size() ; i++) {
|
||||
Map<String, Object> objectMap = reatTimeList.get(i);
|
||||
BigDecimal powerPrice =new BigDecimal(objectMap.get("powerFee").toString());
|
||||
BigDecimal servicePrice =new BigDecimal(objectMap.get("serviceFee").toString());
|
||||
BigDecimal powerPrice =new BigDecimal(objectMap.get("powerFee").toString()).setScale(2, BigDecimal.ROUND_DOWN);
|
||||
BigDecimal servicePrice =new BigDecimal(objectMap.get("serviceFee").toString()).setScale(2, BigDecimal.ROUND_DOWN);
|
||||
String startTime1 = objectMap.get("startTime").toString();
|
||||
String endTime1 = objectMap.get("endTime").toString();
|
||||
if(i==0){
|
||||
list.add(getRateTimeList(startTime,endTime1,decimal,powerPrice,servicePrice));
|
||||
list.add(getRateTimeList(startTime,endTime1,degree,powerPrice,servicePrice));
|
||||
}else{
|
||||
if(size==2){
|
||||
list.add(getRateTimeList(startTime,endTime,decimal,powerPrice,servicePrice));
|
||||
list.add(getRateTimeList(startTime1,endTime,degree,powerPrice,servicePrice));
|
||||
}else{
|
||||
//三个时段以上
|
||||
if(i<size-1){
|
||||
list.add(getRateTimeList(startTime1,endTime1,decimal,powerPrice,servicePrice));
|
||||
list.add(getRateTimeList(startTime1,endTime1,degree,powerPrice,servicePrice));
|
||||
}else{
|
||||
list.add(getRateTimeList(startTime1,endTime,decimal,powerPrice,servicePrice));
|
||||
list.add(getRateTimeList(startTime1,endTime,degree,powerPrice,servicePrice));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,17 +490,17 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService {
|
||||
}
|
||||
|
||||
map.put("list",list);//数据列表
|
||||
map.put("chargingTimeTotal",chargeOrder.getChargingTime());//总时长
|
||||
map.put("powerPriceTotal",powerPriceTotal);//总电费单价(元/度)
|
||||
map.put("servicePriceTotal",servicePriceTotal);//总服务费单价(元/度)
|
||||
map.put("chargingDegreeTotal",chargeOrder.getChargingDegree());//总度数
|
||||
map.put("actPriceTotal",actPrice);//总费用
|
||||
//map.put("chargingTimeTotal",chargeOrder.getChargingTime());//总时长
|
||||
//map.put("powerPriceTotal",powerPriceTotal);//总电费单价(元/度)
|
||||
//map.put("servicePriceTotal",servicePriceTotal);//总服务费单价(元/度)
|
||||
//map.put("chargingDegreeTotal",chargeOrder.getChargingDegree());//总度数
|
||||
//map.put("actPriceTotal",actPrice);//总费用
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, Object> getRateTimeList(String startTime,String endTime,BigDecimal s,BigDecimal powerPrice,BigDecimal servicePrice){
|
||||
private Map<String, Object> getRateTimeList(String startTime,String endTime,BigDecimal degree,BigDecimal powerPrice,BigDecimal servicePrice){
|
||||
Map<String, Object> map =new HashMap<>();
|
||||
BigDecimal v = new BigDecimal((DateUtil.parse(endTime).getTime() - DateUtil.parse(startTime).getTime())/60000).multiply(s);
|
||||
BigDecimal v = new BigDecimal((DateUtil.parse(endTime).getTime() - DateUtil.parse(startTime).getTime())/60000).multiply(degree);
|
||||
BigDecimal multiply = powerPrice.add(servicePrice).multiply(v).setScale(2, RoundingMode.HALF_UP);
|
||||
map.put("time",startTime+"-"+endTime);
|
||||
map.put("powerPrice",powerPrice);
|
||||
@ -191,4 +510,59 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param rateModelId 费率id
|
||||
* @param startTime2 开始时间
|
||||
* @param updateTime2 结算时间
|
||||
* @param chargingDegree 总度数
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal getBigDecimal(Long rateModelId, Date startTime2, Date updateTime2, BigDecimal chargingDegree) {
|
||||
//算出相差时间,分
|
||||
BigDecimal decimal = new BigDecimal((updateTime2.getTime()-startTime2.getTime())/60000).setScale(2);
|
||||
//每分钟多少度
|
||||
BigDecimal degree =chargingDegree.divide(decimal,2,BigDecimal.ROUND_DOWN);
|
||||
BigDecimal powerPriceTotal =new BigDecimal(0);
|
||||
//获取费率时间段
|
||||
String startTime = DateUtil.formatTime(startTime2);
|
||||
String endTime = DateUtil.formatTime(updateTime2);
|
||||
List<Map<String, Object>> reatTimeList = getReatTimeList(startTime, endTime, rateModelId);
|
||||
if(reatTimeList !=null && reatTimeList.size()>0){
|
||||
int size = reatTimeList.size();
|
||||
if(size==1){
|
||||
BigDecimal powerFee = new BigDecimal(reatTimeList.get(0).get("powerFee").toString());
|
||||
powerPriceTotal = powerPriceTotal.add(powerFee.multiply(degree).setScale(2, RoundingMode.HALF_UP));
|
||||
}else{
|
||||
for (int i = 0; i <reatTimeList.size() ; i++) {
|
||||
Map<String, Object> objectMap = reatTimeList.get(i);
|
||||
BigDecimal powerPrice =new BigDecimal(objectMap.get("powerFee").toString());
|
||||
String startTime1 = objectMap.get("startTime").toString();
|
||||
String endTime1 = objectMap.get("endTime").toString();
|
||||
if(i==0){
|
||||
powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime,endTime1,degree,powerPrice));
|
||||
}else{
|
||||
if(size==2){
|
||||
powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime,endTime,degree,powerPrice));
|
||||
}else{
|
||||
//三个时段以上
|
||||
if(i<size-1){
|
||||
powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime1,endTime1,degree,powerPrice));
|
||||
}else{
|
||||
powerPriceTotal = powerPriceTotal.add(getRateTimeList(startTime1,endTime,degree,powerPrice));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return powerPriceTotal;
|
||||
}
|
||||
|
||||
private BigDecimal getRateTimeList(String startTime,String endTime,BigDecimal degree,BigDecimal powerPrice){
|
||||
BigDecimal v = new BigDecimal((DateUtil.parse(endTime).getTime() - DateUtil.parse(startTime).getTime())/60000).multiply(degree);
|
||||
BigDecimal multiply = powerPrice.multiply(v).setScale(2, RoundingMode.HALF_UP);
|
||||
return multiply;
|
||||
}
|
||||
}
|
||||
|
||||
@ -479,4 +479,9 @@
|
||||
IFNULL(type,'1') as type
|
||||
from xhpc_charging_pile where charging_pile_id =(select charging_pile_id from xhpc_terminal where terminal_id=#{terminalId})
|
||||
</select>
|
||||
|
||||
<select id="getXhpcChargeOrderStatus" resultMap="XhpcChargeOrderResult">
|
||||
select * from xhpc_charge_order where del_flag=0 and status=#{status} and source=#{source} and datediff(now(),create_time)>1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@ -47,6 +47,7 @@
|
||||
<result column="meter_value_start_evcs" jdbcType="DOUBLE" property="meterValueStartEvcs"/>
|
||||
<result column="operator_id3rdpty_evcs" jdbcType="VARCHAR" property="operatorId3rdptyEvcs"/>
|
||||
<result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
|
||||
<result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
|
||||
<result column="stop_reason_evcs" jdbcType="INTEGER" property="stopReasonEvcs"/>
|
||||
<result column="total_power" jdbcType="DOUBLE" property="totalPower"/>
|
||||
<result column="user_name_evcs" jdbcType="VARCHAR" property="userNameEvcs"/>
|
||||
@ -190,6 +191,9 @@
|
||||
<if test="startTime != null">
|
||||
start_time,
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
end_time,
|
||||
</if>
|
||||
<if test="stopReasonEvcs != null">
|
||||
stop_reason_evcs,
|
||||
</if>
|
||||
@ -327,6 +331,9 @@
|
||||
<if test="startTime != null">
|
||||
#{startTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
#{endTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="stopReasonEvcs != null">
|
||||
#{stopReasonEvcs,jdbcType=INTEGER},
|
||||
</if>
|
||||
@ -661,8 +668,8 @@
|
||||
from xhpc_rate_time as rt
|
||||
left join xhpc_rate ra on rt.rate_id =ra.rate_id
|
||||
where rt.rate_model_id=#{rateModelId}
|
||||
and (rt.start_time <= #{startTime} and replace(rt.end_time, '00:00:00', '23:59:59') >= #{startTime})
|
||||
and (rt.start_time <= #{endTime} and replace(rt.end_time, '00:00:00', '23:59:59') >= #{endTime})
|
||||
and ((rt.start_time <= #{startTime} and replace(rt.end_time, '00:00:00', '23:59:59') >= #{startTime})
|
||||
or (rt.start_time <= #{endTime} and replace(rt.end_time, '00:00:00', '23:59:59') >= #{endTime}))
|
||||
</select>
|
||||
|
||||
<select id="getById" resultType="map">
|
||||
@ -684,6 +691,7 @@
|
||||
co.end_time as endTime,
|
||||
co.update_time as updateTime,
|
||||
ho.total_price as totalPrice,
|
||||
ho.remark as remark,
|
||||
ho.promotion_discount as promotionDiscount,
|
||||
ho.act_price as actPrice,
|
||||
co.erro_remark as erroRemark,
|
||||
|
||||
@ -392,10 +392,10 @@
|
||||
co.erro_remark as erroRemark,
|
||||
co.create_time as createTime,
|
||||
co.start_time as startTime,
|
||||
(select real_time_order_id from xhpc_real_time_order where transaction_number =co.serial_number order by create_time desc limit 1) realTimeOrderId,
|
||||
(select soc from xhpc_real_time_order where transaction_number =co.serial_number order by create_time desc limit 1) soc,
|
||||
(select charging_degree from xhpc_real_time_order where transaction_number =co.serial_number order by create_time desc limit 1) chargingDegree,
|
||||
(select charging_time from xhpc_real_time_order where transaction_number =co.serial_number order by create_time desc limit 1) chargingTime,
|
||||
(select real_time_order_id from xhpc_real_time_order where transaction_number =co.serial_number order by real_time_order_id desc limit 1) realTimeOrderId,
|
||||
(select soc from xhpc_real_time_order where transaction_number =co.serial_number order by real_time_order_id desc limit 1) soc,
|
||||
(select charging_degree from xhpc_real_time_order where transaction_number =co.serial_number order by real_time_order_id desc limit 1) chargingDegree,
|
||||
(select charging_time from xhpc_real_time_order where transaction_number =co.serial_number order by real_time_order_id desc limit 1) chargingTime,
|
||||
co.source as source,
|
||||
(SELECT phone FROM xhpc_app_user where app_user_id = co.user_id) as appUserPhone,
|
||||
(SELECT phone from xhpc_internet_user where internet_user_id = co.user_id) as internetUserPhone
|
||||
@ -409,13 +409,13 @@
|
||||
and co.start_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime !=null and endTime !=''">
|
||||
and co.start_time <= #{startTime}
|
||||
and co.start_time <= #{endTime}
|
||||
</if>
|
||||
<if test="transactionNumber !=null and transactionNumber !=''">
|
||||
and co.serial_number like concat('%', #{transactionNumber}, '%')
|
||||
</if>
|
||||
<if test="chargingStationName !=null and chargingStationName !=''">
|
||||
and co.serial_number like concat('%', #{transactionNumber}, '%')
|
||||
and co.serial_number like concat('%', #{chargingStationName}, '%')
|
||||
</if>
|
||||
<if test="terminalName !=null and terminalName !=''">
|
||||
and ter.name like concat('%', #{terminalName}, '%')
|
||||
@ -469,6 +469,8 @@
|
||||
cp.power as power,
|
||||
cp.type as type,
|
||||
ro.soc as soc,
|
||||
ro.voltage as voltage,
|
||||
ro.electric_current as electricCurrent,
|
||||
co.status as status,
|
||||
co.create_time as createTime,
|
||||
ro.charging_degree as chargingDegree,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user