实时异常订单审核接口

This commit is contained in:
yuyang 2021-08-30 15:49:42 +08:00
parent 4a5fd921af
commit a4efc46b12
11 changed files with 520 additions and 62 deletions

View File

@ -108,10 +108,13 @@ public class XhpcPileOrderController extends BaseController {
//解析订单编号
//String s1 = orderNo.substring(6);
Integer code = 500;
Long userId = update(0, remark, orderNo, 1);
Long userId=0L;
Map<String, Object> map = new HashMap<>();
if(status == 1|| status == 2){
userId = update(0, remark, orderNo, 1);
map.put("userId", userId);
}
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo);
map.put("userId", userId);
if (status == 1) {
xhpcChargeOrder.setStatus(0);
map.put("message", "停止充电成功");
@ -135,8 +138,22 @@ public class XhpcPileOrderController extends BaseController {
BigDecimal decimal = new BigDecimal(10000);
CacheRealtimeData cacheRealtimeData = list.get(number);
xhpcChargeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal));
//充电时长
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) + "");
}
xhpcChargeOrder.setChargingTimeNumber(Long.valueOf(cacheRealtimeData.getChargingTime()));
xhpcChargeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal));
xhpcChargeOrder.setEndSoc(""+cacheRealtimeData.getSoc());
CacheRealtimeData cacheRealtimeData1 = list.get(0);
xhpcChargeOrder.setStartSoc(""+cacheRealtimeData1.getSoc());
}
}else{
if (xhpcChargeOrder.getStatus() == 1 || xhpcChargeOrder.getStatus() == 3) {
@ -147,6 +164,8 @@ public class XhpcPileOrderController extends BaseController {
}
xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder);
code = 300;
userId =xhpcChargeOrder.getUserId();
map.put("userId",userId);
map.put("message", remark);
}else{
//修改订单判断订单
@ -174,6 +193,10 @@ public class XhpcPileOrderController extends BaseController {
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo);
Long userId = xhpcChargeOrder.getUserId();
try {
Date date = new Date();
xhpcChargeOrder.setEndTime(date);
xhpcChargeOrder.setUpdateTime(date);
xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder);
Map<String, Object> map = addOrderTime(cacheRealtimeData, xhpcChargeOrder, orderNo, 1);
JSONObject json = new JSONObject(map);
//消息对了内容
@ -303,7 +326,7 @@ public class XhpcPileOrderController extends BaseController {
//电站活动抵扣--抵扣的总金额
BigDecimal promotionDiscount = new BigDecimal(0);
//实际价格-用户支付的钱
BigDecimal actPrice =new BigDecimal(0);
BigDecimal actPrice =money;
//流量方总金额抽成
BigDecimal internetCommission =new BigDecimal(0);
//流量方服务费抽成
@ -322,7 +345,7 @@ public class XhpcPileOrderController extends BaseController {
String state = "";
BigDecimal discount = new BigDecimal(0);
//用户第几次充电
int count = xhpcChargeOrderService.getCount(userId);
int count = xhpcChargeOrderService.getCount(userId,xhpcChargeOrder.getChargeOrderId());
if (count == 0) {
//活动折扣
Map<String, Object> promotion = xhpcChargeOrderService.getPromotion();
@ -333,11 +356,9 @@ public class XhpcPileOrderController extends BaseController {
}
}
if(!"".equals(state)){
//查看是否优惠为0
boolean fan = true;
if(discount.compareTo(new BigDecimal(0))==0){
actPrice= money;
fan=false;
}
if("1".equals(state)){
@ -687,7 +708,6 @@ public class XhpcPileOrderController extends BaseController {
Long userId = xhpcChargeOrder.getUserId();
if (type == 1) {
//充电订单 --结束soc充电时长充电度数
xhpcChargeOrder.setEndTime(date);
}

View File

@ -8,6 +8,7 @@ import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -84,12 +85,22 @@ public class XhpcRealTimeOrderController extends BaseController {
}
/**
*异常订单审核
*异常订单审核详情
*/
@GetMapping("/getExamine")
public AjaxResult getExamine(@RequestParam Long chargingOrderId){
return xhpcRealTimeOrderService.getExamine(chargingOrderId);
@GetMapping("/getExamineMessage")
public AjaxResult getExamineMessage(@RequestParam Long realTimeOrderId){
return xhpcRealTimeOrderService.getExamineMessage(realTimeOrderId);
}
/**
* 异常订单审核
* @param chargingOrderId 订单id
* @param powerPrice 电费
* @param servicePrice 服务费
* @return
*/
@GetMapping("/getExamine")
public AjaxResult getExamine(@RequestParam Long chargingOrderId,@RequestParam BigDecimal powerPrice,@RequestParam BigDecimal servicePrice){
return xhpcRealTimeOrderService.getExamine(chargingOrderId,powerPrice,servicePrice);
}
}

View File

@ -93,7 +93,7 @@ public interface XhpcChargeOrderMapper {
* @param userId
* @return
*/
int getCount(@Param("userId") Long userId);
int getCount(@Param("userId") Long userId,@Param("chargeOrderId")Long chargeOrderId);
/**
* 活动

View File

@ -113,5 +113,5 @@ public interface XhpcRealTimeOrderMapper {
*/
XhpcRealTimeOrder getChargingOrderId(@Param("chargingOrderId")Long chargingOrderId);
Map<String,Object> getChargeOrderById(@Param("chargingOrderId")Long chargingOrderId);
}

View File

@ -62,7 +62,7 @@ public interface IXhpcChargeOrderService {
* @param userId
* @return
*/
int getCount(Long userId);
int getCount(Long userId,Long chargeOrderId);
/**
* 活动

View File

@ -6,6 +6,7 @@ import com.xhpc.order.domain.XhpcChargeOrderSoc;
import com.xhpc.order.domain.XhpcChargeOrderVoltage;
import com.xhpc.order.domain.XhpcRealTimeOrder;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -89,12 +90,17 @@ public interface IXhpcRealTimeOrderService {
*/
int addVoltage(XhpcChargeOrderVoltage xhpcChargeOrderVoltage);
/**
* 审核详情
* @param realTimeOrderId
* @return
*/
AjaxResult getExamineMessage(Long realTimeOrderId);
/**
* 审核
* @param chargingOrderId
* @return
*/
AjaxResult getExamine(Long chargingOrderId);
AjaxResult getExamine(Long chargingOrderId, BigDecimal powerPrice,BigDecimal servicePrice);
}

View File

@ -237,9 +237,9 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService {
}
@Override
public int getCount(Long userId) {
public int getCount(Long userId,Long chargeOrderId) {
return xhpcChargeOrderMapper.getCount(userId);
return xhpcChargeOrderMapper.getCount(userId,chargeOrderId);
}
@Override

View File

@ -1,8 +1,12 @@
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.*;
import com.xhpc.order.mapper.XhpcRealTimeOrderMapper;
import com.xhpc.order.service.IXhpcChargeOrderService;
@ -10,6 +14,7 @@ import com.xhpc.order.service.IXhpcHistoryOrderService;
import com.xhpc.order.service.IXhpcRealTimeOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
@ -31,6 +36,12 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService {
@Autowired
private IXhpcHistoryOrderService xhpcHistoryOrderService;
@Autowired
private SmsService smsService;
@Autowired
private RedisService redisService;
@Override
public List<Map<String, Object>> list(String phone, String transactionNumber, Integer source, String chargingStationName, String terminalName, Long operatorId, String startTime, String endTime,Integer status,Long userId,Integer type) {
@ -87,10 +98,17 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService {
return xhpcRealTimeOrderMapper.addVoltage(xhpcChargeOrderVoltage);
}
@Transactional
@Override
public AjaxResult getExamine(Long chargingOrderId) {
public AjaxResult getExamineMessage(Long realTimeOrderId) {
//基本信息
Map<String, Object> message = xhpcRealTimeOrderMapper.getMessage(realTimeOrderId);
if(message ==null || message.get("chargeOrderId") ==null){
return AjaxResult.success(new HashMap<>());
}
//获取开始充电时间结束时间计费模型充电度数已充金额
XhpcChargeOrder chargeOrder = xhpcChargeOrderService.getChargingOrderId(chargingOrderId);
XhpcChargeOrder chargeOrder = xhpcChargeOrderService.getChargingOrderId(Long.parseLong(message.get("chargeOrderId").toString()));
Long rateModelId = chargeOrder.getRateModelId();
Date startTime2 = chargeOrder.getStartTime();
Date updateTime2 = chargeOrder.getUpdateTime();
@ -101,53 +119,256 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService {
//1时间没有跨天
long betweenDay = DateUtil.between(startTime2, updateTime2, DateUnit.DAY);
if(betweenDay==0){
//算出相差时间,
double time = (updateTime2.getTime()-startTime2.getTime())/60000;
BigDecimal decimal = new BigDecimal(time).setScale(2);
//每分钟多少度
BigDecimal degree =chargingDegree.divide(decimal,2,BigDecimal.ROUND_HALF_UP);
//获取费率时间段
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 = powerFee.multiply(chargingDegree).setScale(2);
}else{
for (int i = 0; i <reatTimeList.size() ; i++) {
Map<String, Object> objectMap = reatTimeList.get(i);
BigDecimal powerFee =new BigDecimal(objectMap.get("powerFee").toString());
String startTime1 = objectMap.get("startTime").toString();
String endTime1 = objectMap.get("endTime").toString();
if(i==0){
powerPriceTotal = getBigDecimal(rateModelId, startTime2, updateTime2, chargingDegree, powerPriceTotal);
}else{
//跨天
String startTime = DateUtil.format(startTime2, "yyyy-MM-dd");
Date updateTime = DateUtil.parse(startTime+" 23:59:59");
powerPriceTotal = getBigDecimal(rateModelId, startTime2, updateTime, chargingDegree, powerPriceTotal);
//明天
DateTime tomorrow = DateUtil.offsetDay(startTime2,1);
String startTime1 = DateUtil.format(tomorrow, "yyyy-MM-dd");
Date startTime3 = DateUtil.parse(startTime1+" 00:00:00");
powerPriceTotal = getBigDecimal(rateModelId, startTime3, updateTime2, chargingDegree, powerPriceTotal);
}
//算服务费和电费
BigDecimal servicePriceTotal =amountCharged.subtract(powerPriceTotal);
message.put("powerPriceTotal",powerPriceTotal);
message.put("servicePriceTotal",servicePriceTotal);
return AjaxResult.success(message);
}
@Override
public AjaxResult getExamine(Long chargingOrderId, BigDecimal powerPrice, BigDecimal servicePrice) {
//电费不能为0
if(new BigDecimal(0).compareTo(powerPrice)==1){
return AjaxResult.error("电费为0");
}
//总金额
BigDecimal money = powerPrice.add(servicePrice);
//总服务费 servicePrice
//总电费 powerPrice
//剩余的电费
BigDecimal surplusPowerPrice = powerPrice;
//剩余的服务费
BigDecimal surplusServicePrice = servicePrice;
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getChargingOrderId(chargingOrderId);
xhpcChargeOrder.setStatus(3);
xhpcChargeOrder.setAmountCharged(money);
//生成一条历史订单
XhpcHistoryOrder xhpcHistoryOrder = new XhpcHistoryOrder();
xhpcHistoryOrder.setPowerPriceTotal(powerPrice);
xhpcHistoryOrder.setServicePriceTotal(servicePrice);
Long userId = xhpcChargeOrder.getUserId();
Map<String, Object> userMessage = xhpcChargeOrderService.getUserMessage(userId);
if (userMessage == null || userMessage.get("balance") == null) {
//订单异常
xhpcChargeOrder.setStatus(2);
//异常原因
xhpcChargeOrder.setErroRemark("用户id:" + userId + "为空");
}
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("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.setSerialNumber(xhpcChargeOrder.getSerialNumber());
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.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);
Date date = new Date();
xhpcHistoryOrder.setCreateTime(date);
//扣除用户实际消费金额添加消费记录
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){
//扣钱失败
xhpcHistoryOrder.setStatus(2);
xhpcHistoryOrder.setRemark("扣钱失败");
}else{
xhpcHistoryOrderService.insert(xhpcHistoryOrder);
// addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber());
//添加流水
xhpcChargeOrderService.addUserAccountStatement(userId, actPrice.negate(), subtract, xhpcChargeOrder.getChargeOrderId(), 3, date);
}
xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder);
return AjaxResult.success();
}
private BigDecimal getBigDecimal(Long rateModelId, Date startTime2, Date updateTime2, BigDecimal chargingDegree, BigDecimal powerPriceTotal) {
//算出相差时间,
double time = (updateTime2.getTime()-startTime2.getTime())/60000;
BigDecimal decimal = new BigDecimal(time).setScale(2);
//每分钟多少度
BigDecimal degree =chargingDegree.divide(decimal,2,BigDecimal.ROUND_HALF_UP);
//获取费率时间段
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 = powerFee.multiply(chargingDegree).setScale(2, RoundingMode.HALF_UP);
}else{
for (int i = 0; i <reatTimeList.size() ; i++) {
Map<String, Object> objectMap = reatTimeList.get(i);
BigDecimal powerFee =new BigDecimal(objectMap.get("powerFee").toString());
String startTime1 = objectMap.get("startTime").toString();
String endTime1 = objectMap.get("endTime").toString();
if(i==0){
powerPriceTotal=getRateTimeList(startTime1,endTime,degree,powerFee,powerPriceTotal);
}else{
if(size==2){
powerPriceTotal=getRateTimeList(startTime1,endTime,degree,powerFee,powerPriceTotal);
}else{
if(size==2){
powerPriceTotal=getRateTimeList(startTime1,endTime,degree,powerFee,powerPriceTotal);
//三个时段以上
if(i<size-1){
powerPriceTotal=getRateTimeList(startTime1,endTime1,degree,powerFee,powerPriceTotal);
}else{
//三个时段以上
if(i<size-1){
powerPriceTotal=getRateTimeList(startTime1,endTime1,degree,powerFee,powerPriceTotal);
}else{
powerPriceTotal=getRateTimeList(startTime1,endTime,degree,powerFee,powerPriceTotal);
}
powerPriceTotal=getRateTimeList(startTime1,endTime,degree,powerFee,powerPriceTotal);
}
}
}
}
}
}else{
//跨天
}
//算服务费和电费
BigDecimal servicePriceTotal =amountCharged.subtract(powerPriceTotal);
Map<String, Object> message = new HashMap<>();
message.put("powerPriceTotal",powerPriceTotal);
message.put("servicePriceTotal",servicePriceTotal);
return AjaxResult.success(message);
return powerPriceTotal;
}
private BigDecimal getRateTimeList(String startTime,String endTime,BigDecimal s,BigDecimal powerFee,BigDecimal powerPriceTotal){
@ -164,4 +385,167 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService {
xhpcRealTimeOrderMapper.deleteChargeVoltage(chargingOrderId);
}
private void addPileEndOrder(XhpcHistoryOrder xhpcHistoryOrder, XhpcChargeOrder xhpcChargeOrder,String orderNo) {
Map<String, Object> cacheMap = redisService.getCacheMap("order:" + orderNo);
Date date = new Date();
Long chargeOrderId = xhpcChargeOrder.getChargeOrderId();
//删除实时数据获取最新的实时数据
deleteRealTimeOrder(xhpcChargeOrder.getChargeOrderId());
//添加新的实时数据
List<CacheRealtimeData> list = (List<CacheRealtimeData>) cacheMap.get("realtimeDataList");
if (list != null && list.size() > 0) {
for (CacheRealtimeData cacheRealtimeData : list) {
addOrderTime(cacheRealtimeData, xhpcChargeOrder, orderNo, 2);
}
}
//添加redis到数据库
XhpcOrderRedisRecord xhpcOrderRedisRecord =new XhpcOrderRedisRecord();
xhpcOrderRedisRecord.setChargeOrderId(chargeOrderId);
xhpcOrderRedisRecord.setHistoryOrderOd(xhpcHistoryOrder.getHistoryOrderId());
if(cacheMap.get("endSoc") !=null){
xhpcOrderRedisRecord.setEndSoc(cacheMap.get("endSoc").toString());
}
if(cacheMap.get("status") !=null){
xhpcOrderRedisRecord.setStatus(cacheMap.get("status").toString());
}
if(cacheMap.get("balance") !=null){
xhpcOrderRedisRecord.setBalance(cacheMap.get("balance").toString());
}
if(cacheMap.get("tel") !=null){
xhpcOrderRedisRecord.setTel(cacheMap.get("tel").toString());
}
if(cacheMap.get("startSoc") !=null){
xhpcOrderRedisRecord.setStartSoc(cacheMap.get("startSoc").toString());
}
if(cacheMap.get("startResult") !=null){
xhpcOrderRedisRecord.setStartResult(cacheMap.get("startResult").toString());
}
if(cacheMap.get("realtimeDataList") !=null){
xhpcOrderRedisRecord.setRealtimeDataList(cacheMap.get("realtimeDataList").toString());
}
if(cacheMap.get("remainingTime") !=null){
xhpcOrderRedisRecord.setRemainingTime(cacheMap.get("remainingTime").toString());
}
if(cacheMap.get("rateModelId") !=null){
xhpcOrderRedisRecord.setRateModelId(cacheMap.get("rateModelId").toString());
}
if(cacheMap.get("lt5alerted") !=null){
xhpcOrderRedisRecord.setLt5alerted(cacheMap.get("lt5alerted").toString());
}
if(cacheMap.get("orderData") !=null){
xhpcOrderRedisRecord.setOrderData(cacheMap.get("orderData").toString());
}
xhpcOrderRedisRecord.setCreateTime(date);
xhpcChargeOrderService.addXhpcOrderRedisRecord(xhpcOrderRedisRecord);
//删除redis
//redisService.deleteObject("order:"+orderNo);
}
/**
* 添加实时数据
*
* @param cacheRealtimeData
* @param xhpcChargeOrder
* @param orderNo 订单号
* @param type 1.实时数据回调 2.结算回调
* @return
*/
private void addOrderTime(CacheRealtimeData cacheRealtimeData, XhpcChargeOrder xhpcChargeOrder,
String orderNo, Integer type) {
Map<String, Object> map = new HashMap<>();
Date date = new Date();
Long chargeOrderId = xhpcChargeOrder.getChargeOrderId();
XhpcRealTimeOrder xhpcRealTimeOrder = new XhpcRealTimeOrder();
xhpcRealTimeOrder.setChargingOrderId(xhpcChargeOrder.getChargeOrderId());
xhpcRealTimeOrder.setTransactionNumber(orderNo);
xhpcRealTimeOrder.setPileNumber(cacheRealtimeData.getPileNo());
String gunId = cacheRealtimeData.getGunId();
xhpcRealTimeOrder.setGunNumber(gunId);
if("00".equals(cacheRealtimeData.getPileGunStatus())){
xhpcRealTimeOrder.setPileGunStatus(0);
}else if("01".equals(cacheRealtimeData.getPileGunStatus())){
xhpcRealTimeOrder.setPileGunStatus(1);
}else{
xhpcRealTimeOrder.setPileGunStatus(2);
}
if("00".equals(cacheRealtimeData.getVehicleGunStatus())){
xhpcRealTimeOrder.setVehicleGunStatus(0);
}else{
xhpcRealTimeOrder.setVehicleGunStatus(1);
}
BigDecimal v = new BigDecimal(cacheRealtimeData.getWorkingVoltage()).divide(new BigDecimal(10));
BigDecimal c = new BigDecimal(cacheRealtimeData.getWorkingCurrent()).divide(new BigDecimal(10));
xhpcRealTimeOrder.setVoltage(v);
xhpcRealTimeOrder.setElectricCurrent(c);
xhpcRealTimeOrder.setGunLineTemperature(cacheRealtimeData.getGunLineTemperature());
xhpcRealTimeOrder.setGunLineNumber(cacheRealtimeData.getGunLineNumber());
Integer soc = cacheRealtimeData.getSoc();
xhpcRealTimeOrder.setSoc(soc.toString());
xhpcRealTimeOrder.setMaxTemperature(cacheRealtimeData.getMaxTemperature());
Integer chargingTime = cacheRealtimeData.getChargingTime();
if(chargingTime>60){
int hours = chargingTime / 60;
int mins = (chargingTime-(hours*60)) % 60;
xhpcRealTimeOrder.setChargingTime(hours+""+mins+"");
}else{
xhpcRealTimeOrder.setChargingTime(chargingTime+"");
}
Integer remainingTime = cacheRealtimeData.getRemainingTime();
if(remainingTime>60){
int hours = remainingTime / 60;
double mins = (remainingTime-(hours*60))/60;
xhpcRealTimeOrder.setRemainingTime(hours+""+new BigDecimal(mins).setScale(0)+"");
}else{
double mins = (double)(remainingTime/60);
xhpcRealTimeOrder.setRemainingTime(new BigDecimal(mins).setScale(0)+"");
}
BigDecimal decimal = new BigDecimal(10000);
BigDecimal divide = new BigDecimal(cacheRealtimeData.getLossChargingDegree()).divide(decimal);
BigDecimal chargingDegree = new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal);
xhpcRealTimeOrder.setChargingDegree(chargingDegree);
xhpcRealTimeOrder.setLossChargingDegree(divide);
BigDecimal amountCharged = new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal);
xhpcRealTimeOrder.setAmountCharged(amountCharged);
xhpcRealTimeOrder.setHardwareFault(cacheRealtimeData.getHardwareFault());
if ("00".equals(cacheRealtimeData.getStatus())) {
xhpcRealTimeOrder.setStatus(0);
} else if ("01".equals(cacheRealtimeData.getStatus())) {
xhpcRealTimeOrder.setStatus(1);
} else if ("02".equals(cacheRealtimeData.getStatus())) {
xhpcRealTimeOrder.setStatus(2);
} else {
xhpcRealTimeOrder.setStatus(3);
}
xhpcRealTimeOrder.setCreateTime(date);
xhpcRealTimeOrder.setUserId(xhpcChargeOrder.getUserId());
Long chargingStationId = xhpcChargeOrder.getChargingStationId();
xhpcRealTimeOrder.setChargingStationId(chargingStationId);
addXhpcRealTimeOrder(xhpcRealTimeOrder);
//实时数据存入MYsqlsoc电流电压
XhpcChargeOrderSoc xhpcChargeOrderSoc = new XhpcChargeOrderSoc();
xhpcChargeOrderSoc.setChargeOrderId(chargeOrderId);
xhpcChargeOrderSoc.setSoc(soc.toString());
xhpcChargeOrderSoc.setCreateTime(date);
addSOC(xhpcChargeOrderSoc);
XhpcChargeOrderCurrent xhpcChargeOrderCurrent =new XhpcChargeOrderCurrent();
xhpcChargeOrderCurrent.setChargeOrderId(chargeOrderId);
xhpcChargeOrderCurrent.setCurrent(c.toString());
xhpcChargeOrderCurrent.setCreateTime(date);
addCurrent(xhpcChargeOrderCurrent);
XhpcChargeOrderVoltage xhpcChargeOrderVoltage =new XhpcChargeOrderVoltage();
xhpcChargeOrderVoltage.setChargeOrderId(chargeOrderId);
xhpcChargeOrderVoltage.setVoltage(v.toString());
xhpcChargeOrderVoltage.setCreateTime(date);
addVoltage(xhpcChargeOrderVoltage);
}
}

View File

@ -302,7 +302,10 @@
</select>
<select id="getCount" resultType="int">
select count(charge_order_id) from xhpc_charge_order where user_id=#{userId} and del_flag =1
select count(charge_order_id) from xhpc_charge_order where user_id=#{userId} and del_flag =0 and (status !=1 or status !=3)
<if test="chargeOrderId !=null">
and charge_order_id=#{chargeOrderId}
</if>
</select>
<select id="getPromotion" resultType="map">

View File

@ -455,7 +455,7 @@
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.end_time &gt;= #{startTime}
and replace(rt.end_time, '00:00:00', '23:59:59') &gt;= #{startTime}
and rt.start_time &lt;= #{endTime}
</select>

View File

@ -458,6 +458,7 @@
<select id="getMessage" resultType="map">
select
ro.real_time_order_id as realTimeOrderId,
co.charge_order_id as chargeOrderId,
co.serial_number as serialNumber,
ct.name as chargingStationName,
ter.pile_serial_number as pileSerialNumber,
@ -549,4 +550,37 @@
select * from xhpc_real_time_order where charging_order_id=#{chargingOrderId} order by create_time desc limit 1
</select>
<select id="getChargeOrderById" resultType="map">
select
co.serial_number as serialNumber,
ct.name as chargingStationName,
ter.pile_serial_number as pileSerialNumber,
ter.name as terminalName,
op.operator_id as operatorId,
op.name as operatorName,
cp.serial_number as pileSerialNumber,
cp.power as power,
cp.type as type,
ro.soc as soc,
co.status as status,
co.create_time as createTime,
ro.charging_degree as chargingDegree,
ro.charging_time as chargingTime,
co.source as source,
co.internet_serial_number as internetSerialNumber,
co.erro_remark as erroRemark,
ro.amount_charged as amountCharged,
(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
from xhpc_charge_order as co
Left join xhpc_real_time_order ro on co.serial_number = ro.transaction_number
Left join xhpc_charging_station as ct on ct.charging_station_id = ro.charging_station_id
left join xhpc_operator as op on op.operator_id = ct.operator_id
left join xhpc_terminal as ter on ter.terminal_id = co.terminal_id
left join xhpc_charging_pile as cp on cp.charging_pile_id = ter.charging_pile_id
where ro.real_time_order_id=#{realTimeOrderId}
</select>
</mapper>