新增实时数据共有接口,小时统计
This commit is contained in:
parent
c65f02064b
commit
feccc684b5
@ -33,6 +33,10 @@ public class ServiceNameConstants
|
||||
*/
|
||||
public static final String XHPC_ORDER ="xhpc-order";
|
||||
|
||||
/**
|
||||
* 订单服务
|
||||
*/
|
||||
public static final String XHPC_WXMA ="xhpc-wxma";
|
||||
/**
|
||||
* 通用服务
|
||||
*/
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package com.xhpc.common.api;
|
||||
|
||||
import com.xhpc.common.api.factory.WebSocketFallbackFactory;
|
||||
import com.xhpc.common.core.constant.ServiceNameConstants;
|
||||
import com.xhpc.common.core.domain.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author yuyang
|
||||
* @date 2021/9/10 15:13
|
||||
* @Version 1.0
|
||||
*/
|
||||
@FeignClient(contextId ="webSocketService",value = ServiceNameConstants.XHPC_WXMA, fallbackFactory = WebSocketFallbackFactory.class)
|
||||
public interface WebSocketService {
|
||||
|
||||
/**
|
||||
* 发送实时数据接口
|
||||
* @param userId 接收用户
|
||||
* @param message 接收信息
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/orderWebSocket/getMessage")
|
||||
R getMessage(@RequestParam(value = "userId") String userId, @RequestParam(value = "message") String message);
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.xhpc.common.api.factory;
|
||||
|
||||
import com.xhpc.common.api.WebSocketService;
|
||||
import com.xhpc.common.core.domain.R;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
|
||||
/**
|
||||
* @author yuyang
|
||||
* @date 2021/9/10 15:14
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class WebSocketFallbackFactory implements FallbackFactory<WebSocketService> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(WebSocketFallbackFactory.class);
|
||||
|
||||
@Override
|
||||
public WebSocketService create(Throwable cause){
|
||||
logger.error("消息发送调用失败:{}//fallback",cause.getMessage());
|
||||
return new WebSocketService() {
|
||||
@Override
|
||||
public R getMessage(String userId, String message) {
|
||||
return R.fail("消息发送调用失败:" + cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -158,4 +158,9 @@ public class XhpcHistoryOrder extends BaseEntity {
|
||||
* 0未统计 1已统计
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* VIN 码
|
||||
*/
|
||||
private String vinNormal;
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package com.xhpc.order.api;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.rabbitmq.client.Connection;
|
||||
import com.xhpc.common.api.WebSocketService;
|
||||
import com.xhpc.common.core.web.controller.BaseController;
|
||||
import com.xhpc.common.core.web.domain.AjaxResult;
|
||||
import com.xhpc.common.core.web.page.TableDataInfo;
|
||||
@ -10,6 +12,7 @@ import com.xhpc.common.util.ConnectionRabbitMQUtil;
|
||||
import com.xhpc.order.service.IXhpcChargeOrderService;
|
||||
import com.xhpc.order.service.IXhpcHistoryOrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -19,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -36,6 +40,8 @@ public class XhpcChargeOrderController extends BaseController {
|
||||
private IXhpcChargeOrderService iXhpcChargeOrderService;
|
||||
@Autowired
|
||||
private IXhpcHistoryOrderService xhpcHistoryOrderService;
|
||||
@Autowired
|
||||
private WebSocketService webSocketService;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(XhpcChargeOrderController.class);
|
||||
/**
|
||||
@ -130,6 +136,8 @@ public class XhpcChargeOrderController extends BaseController {
|
||||
logger.info("<<<<<<<<<<再次<<<<<<<<<<<<<实时数据接口>>>>>>>>>>>>>>>>>>"+userId);
|
||||
logger.info("<<<<<<<<<<再次<<<<<<<<<<<<<<实时数据接口>>>>>>>>>>>>>>>>>"+userId);
|
||||
logger.info("<<<<<<<<<<再次<<<<<<<<<<<<<<实时数据接口>>>>>>>>>>>>>>>>>");
|
||||
logger.info("<<<<<<<<<<接收时间<<<<<<<<<<<<<<"+ DateUtil.format(Calendar.getInstance().getTime(), "yyyy-MM-dd HH:mm:ss")+">>>>>>>>>>>>>>>>>");
|
||||
|
||||
Map<String, Object> orderMessage = iXhpcChargeOrderService.getOrderMessage(userId);
|
||||
Map<String,Object> map =new HashMap<>();
|
||||
map.put("code", 200);
|
||||
@ -155,11 +163,9 @@ public class XhpcChargeOrderController extends BaseController {
|
||||
}else{
|
||||
map.put("data",orderMessage);
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject(map);
|
||||
|
||||
logger.info("<<<<<<<<<<再次<<<<<<<<<<<<<<json实时数据接口>>>>>>>>>>>>>>>>>"+json.toString());
|
||||
rabbimt(userId + "##" + json);
|
||||
webSocketService.getMessage(""+userId,json.toString());
|
||||
logger.info("<<<<<<<<<<发送时间<<<<<<<<<<<<<<"+ DateUtil.format(Calendar.getInstance().getTime(), "yyyy-MM-dd HH:mm:ss")+">>>>>>>>>>>>>>>>>");
|
||||
}
|
||||
|
||||
private void rabbimt(String message) {
|
||||
|
||||
@ -331,7 +331,7 @@ public class XhpcPileOrderController extends BaseController {
|
||||
R.ok();
|
||||
}
|
||||
//结算
|
||||
xhpcRealTimeOrderService.addSettlement(powerPrice,servicePrice,money,surplusPowerPrice,surplusServicePrice,xhpcChargeOrder,userId,userMessage,1);
|
||||
xhpcRealTimeOrderService.addSettlement(powerPrice,servicePrice,money,surplusPowerPrice,surplusServicePrice,xhpcChargeOrder,userId,userMessage,1,cacheOrderData.getVinNormal());
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", 500);
|
||||
map.put("userId", userId);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.xhpc.order.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.xhpc.common.core.web.controller.BaseController;
|
||||
@ -76,180 +77,207 @@ public class XhpcHistoryOrderController extends BaseController {
|
||||
public void test(){
|
||||
//获取500条待统计历史订单
|
||||
//跨时段,跨费率,计费模型
|
||||
//小时统计、日期统计、电站统计、终端统计、运营商统计、流量方统计
|
||||
//小时统计
|
||||
List<XhpcChargeHistoryOrder> list = xhpcHistoryOrderService.getStatistisList(500);
|
||||
if(list !=null && list.size()>0){
|
||||
//开始时间和结束时间之差,是否超过 30分钟
|
||||
for (XhpcChargeHistoryOrder xhpcChargeHistoryOrder:list) {
|
||||
Date startTime = xhpcChargeHistoryOrder.getStartTime();
|
||||
Date endTime = xhpcChargeHistoryOrder.getEndTime();
|
||||
Long rateModelId = xhpcChargeHistoryOrder.getRateModelId();
|
||||
int source = xhpcChargeHistoryOrder.getSource();
|
||||
Long userId =xhpcChargeHistoryOrder.getUserId();
|
||||
Long operatorId =xhpcChargeHistoryOrder.getOperatorId();
|
||||
Long chargeOrderId =xhpcChargeHistoryOrder.getChargeOrderId();
|
||||
Long chargingStationId = xhpcChargeHistoryOrder.getChargingStationId();
|
||||
Long terminalId = xhpcChargeHistoryOrder.getTerminalId();
|
||||
for (XhpcChargeHistoryOrder xhpc:list) {
|
||||
//开始时间、结束时间、模型id、状态、用户id、运营商、订单id、场站id、终端id、历史订单id、时间
|
||||
Date startTime = xhpc.getStartTime();
|
||||
Date endTime = xhpc.getEndTime();
|
||||
Long rateModelId = xhpc.getRateModelId();
|
||||
Long operatorId =xhpc.getOperatorId();
|
||||
Long chargingStationId = xhpc.getChargingStationId();
|
||||
Long terminalId = xhpc.getTerminalId();
|
||||
Long historyOrderId = xhpc.getHistoryOrderId();
|
||||
Date data = Calendar.getInstance().getTime();
|
||||
//充电时长
|
||||
Long chargingTimeNumber =xhpcChargeHistoryOrder.getChargingTimeNumber();
|
||||
|
||||
long betweenDay = DateUtil.between(DateUtil.parse(xhpcChargeHistoryOrder.getStartTime().toString(), "yyyy-MM-dd"), DateUtil.parse(xhpcChargeHistoryOrder.getEndTime().toString(), "yyyy-MM-dd"), DateUnit.DAY);
|
||||
//1时间没有跨天
|
||||
DateTime parse = DateUtil.parse(DateUtil.format(startTime, "yyyy-MM-dd"), "yyyy-MM-dd");
|
||||
DateTime parse1 = DateUtil.parse(DateUtil.format(endTime, "yyyy-MM-dd"), "yyyy-MM-dd");
|
||||
long betweenDay = DateUtil.between(parse,parse1, DateUnit.DAY);
|
||||
if(betweenDay==0){
|
||||
//没有跨天
|
||||
//获取费率
|
||||
//电费
|
||||
BigDecimal powerPrice =xhpcChargeHistoryOrder.getActPowerPrice();
|
||||
//服务费
|
||||
BigDecimal servicePrice =xhpcChargeHistoryOrder.getActServicePrice();
|
||||
//订单总价
|
||||
BigDecimal totalPrice =xhpcChargeHistoryOrder.getTotalPrice();
|
||||
//电站活动抵扣--抵扣的总金额
|
||||
BigDecimal promotionDiscount =xhpcChargeHistoryOrder.getPromotionDiscount();
|
||||
//实际价格-用户支付的钱
|
||||
BigDecimal actPrice =xhpcChargeHistoryOrder.getActPrice();
|
||||
//实收电费-运营商电费
|
||||
BigDecimal actPowerPrice =xhpcChargeHistoryOrder.getActPowerPrice();
|
||||
//实收服务费-运营商服务费
|
||||
BigDecimal actServicePrice =xhpcChargeHistoryOrder.getActServicePrice();
|
||||
//流量方总金额抽成
|
||||
BigDecimal internetCommission =xhpcChargeHistoryOrder.getInternetCommission();
|
||||
//流量方服务费抽成
|
||||
BigDecimal internetSvcCommission =xhpcChargeHistoryOrder.getInternetSvcCommission();
|
||||
//平台总金额抽成
|
||||
BigDecimal platformCommission =xhpcChargeHistoryOrder.getPlatformCommission();
|
||||
//平台服务费抽成
|
||||
BigDecimal platformSvcCommission =xhpcChargeHistoryOrder.getPlatformSvcCommisssion();
|
||||
//运维总抽成
|
||||
BigDecimal operationCommission =xhpcChargeHistoryOrder.getOperationCommission();
|
||||
//运维服务费抽成
|
||||
BigDecimal operationSvcCommission =xhpcChargeHistoryOrder.getOperationSvcCommission();
|
||||
//每分钟都少钱
|
||||
BigDecimal pp1 = powerPrice.divide(new BigDecimal(chargingTimeNumber / 60), 2, RoundingMode.HALF_UP);
|
||||
BigDecimal sp1 = servicePrice.divide(new BigDecimal(chargingTimeNumber / 60), 2, RoundingMode.HALF_UP);
|
||||
|
||||
String startTime1 = DateUtil.formatTime(startTime);
|
||||
String endTime1 = DateUtil.formatTime(endTime);
|
||||
//是否跨时段
|
||||
int startHour = DateUtil.hour(startTime, true);
|
||||
int endHour = DateUtil.hour(endTime, true);
|
||||
if(endHour==startHour){
|
||||
//没有跨时段
|
||||
XhpcStatisticsTimeInterval xhpc = new XhpcStatisticsTimeInterval();
|
||||
xhpc.setStatus(endHour+1);
|
||||
xhpc.setChargingDegree(xhpcChargeHistoryOrder.getChargingDegree());
|
||||
xhpc.setChargingTime(new BigDecimal(chargingTimeNumber/3600).setScale(2, RoundingMode.HALF_UP));
|
||||
xhpc.setChargingNumber(1);
|
||||
xhpc.setPowerPrice(powerPrice);
|
||||
xhpc.setServicePrice(servicePrice);
|
||||
xhpc.setTotalPrice(totalPrice);
|
||||
xhpc.setPromotionDiscount(promotionDiscount);
|
||||
xhpc.setActPrice(actPrice);
|
||||
xhpc.setActPowerPrice(actPowerPrice);
|
||||
xhpc.setActServicePrice(actServicePrice);
|
||||
xhpc.setInternetCommission(internetCommission);
|
||||
xhpc.setInternetSvcCommission(internetSvcCommission);
|
||||
xhpc.setPlatformCommission(platformCommission);
|
||||
xhpc.setPlatformSvcCommisssion(platformSvcCommission);
|
||||
xhpc.setOperationCommission(operationCommission);
|
||||
xhpc.setOperationSvcCommission(operationSvcCommission);
|
||||
xhpc.setOperatorId(chargeOrderId);
|
||||
xhpc.setChargingStationId(chargingStationId);
|
||||
xhpc.setCreateTime(data);
|
||||
xhpc.setTerminalId(terminalId);
|
||||
xhpcStatisticsService.addStatisticsTime(xhpc);
|
||||
//修改历史订单表状态
|
||||
XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder();
|
||||
xhpcHistoryOrder.setHistoryOrderId(xhpcChargeHistoryOrder.getHistoryOrderId());
|
||||
xhpcHistoryOrder.setState(1);
|
||||
xhpcHistoryOrderService.update(xhpcHistoryOrder);
|
||||
}else{
|
||||
|
||||
//跨时段,跨多少时段,每个时段单独算
|
||||
//每个时段折扣
|
||||
BigDecimal pd = new BigDecimal(0);
|
||||
if(promotionDiscount.compareTo(pd)==1){
|
||||
pd = promotionDiscount.divide(new BigDecimal(endHour + 1));
|
||||
}
|
||||
for (int i = startHour; i <=endHour+1 ; i++) {
|
||||
//获取费率
|
||||
if(i==startHour){
|
||||
String end=i+1+":59:59";
|
||||
long time1 = DateUtil.parse(end).getTime();
|
||||
long time2 = DateUtil.parse(startTime1).getTime();
|
||||
BigDecimal time = new BigDecimal((time1-time2)/6000);
|
||||
|
||||
List<Map<String, Object>> reatTimeList = xhpcHistoryOrderService.getReatTimeList(startTime1, end, rateModelId);
|
||||
if(reatTimeList!=null && reatTimeList.size()>0){
|
||||
if(reatTimeList.size()==1){
|
||||
XhpcStatisticsTimeInterval xhpc = new XhpcStatisticsTimeInterval();
|
||||
xhpc.setStatus(endHour+1);
|
||||
xhpc.setChargingDegree(xhpcChargeHistoryOrder.getChargingDegree());
|
||||
xhpc.setChargingTime(new BigDecimal(chargingTimeNumber/3600).setScale(2, RoundingMode.HALF_UP));
|
||||
xhpc.setChargingNumber(1);
|
||||
BigDecimal decimal1 = time.multiply(pp1).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal decimal2 = time.multiply(sp1).setScale(2, RoundingMode.HALF_UP);
|
||||
xhpc.setPowerPrice(decimal1);
|
||||
xhpc.setServicePrice(decimal2);
|
||||
xhpc.setTotalPrice(decimal1.add(decimal2));
|
||||
xhpc.setPromotionDiscount(pd);
|
||||
xhpc.setActPrice(decimal1.add(decimal2).subtract(pd));
|
||||
|
||||
|
||||
powerPrice.subtract(decimal1);
|
||||
servicePrice.subtract(decimal2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
xhpc.setActPowerPrice(xhpcChargeHistoryOrder.getActPowerPrice());
|
||||
xhpc.setActServicePrice(xhpcChargeHistoryOrder.getActServicePrice());
|
||||
xhpc.setInternetCommission(xhpcChargeHistoryOrder.getInternetCommission());
|
||||
xhpc.setInternetSvcCommission(xhpcChargeHistoryOrder.getInternetSvcCommission());
|
||||
xhpc.setPlatformCommission(xhpcChargeHistoryOrder.getPlatformCommission());
|
||||
xhpc.setPlatformSvcCommisssion(xhpcChargeHistoryOrder.getPlatformSvcCommisssion());
|
||||
xhpc.setOperationCommission(xhpcChargeHistoryOrder.getOperationCommission());
|
||||
xhpc.setOperationSvcCommission(xhpcChargeHistoryOrder.getOperationSvcCommission());
|
||||
xhpc.setOperatorId(xhpcChargeHistoryOrder.getOperatorId());
|
||||
xhpc.setChargingStationId(xhpcChargeHistoryOrder.getChargingStationId());
|
||||
xhpc.setCreateTime(data);
|
||||
xhpc.setTerminalId(xhpcChargeHistoryOrder.getTerminalId());
|
||||
xhpcStatisticsService.addStatisticsTime(xhpc);
|
||||
//修改历史订单表状态
|
||||
XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder();
|
||||
xhpcHistoryOrder.setHistoryOrderId(xhpcChargeHistoryOrder.getHistoryOrderId());
|
||||
xhpcHistoryOrder.setState(1);
|
||||
xhpcHistoryOrderService.update(xhpcHistoryOrder);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
String sta=i+":00:00";
|
||||
String end=i+1+":59:59";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
XhpcStatisticsTimeInterval xhpcSt = new XhpcStatisticsTimeInterval();
|
||||
xhpcSt.setStatus(endHour+1);
|
||||
xhpcSt.setChargingDegree(xhpc.getChargingDegree());
|
||||
xhpcSt.setChargingTime(new BigDecimal(xhpc.getChargingTimeNumber()/3600).setScale(2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setChargingNumber(1);
|
||||
xhpcSt.setPowerPrice(xhpc.getActPowerPrice());
|
||||
xhpcSt.setServicePrice(xhpc.getActServicePrice());
|
||||
xhpcSt.setTotalPrice(xhpc.getTotalPrice());
|
||||
xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount());
|
||||
xhpcSt.setActPrice(xhpc.getActPrice());
|
||||
xhpcSt.setActPowerPrice(xhpc.getActPowerPrice());
|
||||
xhpcSt.setActServicePrice(xhpc.getActServicePrice());
|
||||
xhpcSt.setInternetCommission(xhpc.getInternetCommission());
|
||||
xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission());
|
||||
xhpcSt.setPlatformCommission(xhpc.getPlatformCommission());
|
||||
xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion());
|
||||
xhpcSt.setOperationCommission(xhpc.getOperationCommission());
|
||||
xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission());
|
||||
xhpcSt.setOperatorId(operatorId);
|
||||
xhpcSt.setChargingStationId(chargingStationId);
|
||||
xhpcSt.setCreateTime(data);
|
||||
xhpcSt.setTerminalId(terminalId);
|
||||
xhpcSt.setHistoryOrderId(historyOrderId);
|
||||
if(xhpc.getSource()==1){
|
||||
xhpcSt.setInternetUserId(xhpc.getUserId());
|
||||
}
|
||||
xhpcStatisticsService.addStatisticsTime(xhpcSt);
|
||||
}else {
|
||||
//跨时段
|
||||
//总共时段 endHour+1-startHour
|
||||
addStatisTime(xhpc, startTime, endTime, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, startHour, endHour);
|
||||
}
|
||||
}else{
|
||||
//跨天
|
||||
Date updateTime2= DateUtil.parse(parse+" 23:59:59");
|
||||
int startHour = DateUtil.hour(startTime, true);
|
||||
int endHour = DateUtil.hour(updateTime2, true);
|
||||
addInterval(xhpc, startTime, updateTime2, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, startHour, endHour);
|
||||
//明天
|
||||
DateTime tomorrow = DateUtil.offsetDay(startTime,1);
|
||||
Date startTime3 =DateUtil.beginOfDay(tomorrow);
|
||||
int startHour1 = DateUtil.hour(startTime3, true);
|
||||
int endHour1 = DateUtil.hour(endTime, true);
|
||||
addInterval(xhpc, startTime3, endTime, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, startHour1, endHour1);
|
||||
}
|
||||
//修改状态
|
||||
//修改历史订单表状态
|
||||
XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder();
|
||||
xhpcHistoryOrder.setHistoryOrderId(xhpc.getHistoryOrderId());
|
||||
xhpcHistoryOrder.setState(1);
|
||||
xhpcHistoryOrderService.update(xhpcHistoryOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addStatisTime(XhpcChargeHistoryOrder xhpc, Date startTime, Date endTime, Long rateModelId, Long operatorId, Long chargingStationId, Long terminalId, Long historyOrderId, int startHour, int endHour) {
|
||||
|
||||
BigDecimal number = new BigDecimal(endHour + 1 - startHour);
|
||||
for (int i = startHour; i <= endHour + 1; i++) {
|
||||
//获取费率
|
||||
if (i == startHour) {
|
||||
//开始时间、结束时间
|
||||
addStatis(xhpc, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, endHour, number, DateUtil.formatTime(startTime), i + ":59:59");
|
||||
} else if (i != endHour + 1) {
|
||||
addStatis(xhpc, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, endHour, number, i + ":00:00", i + ":59:59");
|
||||
} else {
|
||||
addStatis(xhpc, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, endHour, number, i + ":00:00", DateUtil.formatTime(endTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addInterval(XhpcChargeHistoryOrder xhpc, Date startTime, Date endTime, Long rateModelId, Long operatorId, Long chargingStationId, Long terminalId, Long historyOrderId, int startHour, int endHour) {
|
||||
Date data = Calendar.getInstance().getTime();
|
||||
if(endHour==startHour){
|
||||
//没有跨时段
|
||||
XhpcStatisticsTimeInterval xhpcSt = new XhpcStatisticsTimeInterval();
|
||||
xhpcSt.setStatus(endHour+1);
|
||||
xhpcSt.setChargingDegree(xhpc.getChargingDegree());
|
||||
xhpcSt.setChargingTime(new BigDecimal(xhpc.getChargingTimeNumber()/3600).setScale(2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setChargingNumber(1);
|
||||
BigDecimal number = new BigDecimal(2);
|
||||
xhpcSt.setPowerPrice(xhpc.getActPowerPrice().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setServicePrice(xhpc.getActServicePrice().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setTotalPrice(xhpc.getTotalPrice().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setActPrice(xhpc.getActPrice().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setActPowerPrice(xhpc.getActPowerPrice().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setActServicePrice(xhpc.getActServicePrice().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setInternetCommission(xhpc.getInternetCommission().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setPlatformCommission(xhpc.getPlatformCommission().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setOperationCommission(xhpc.getOperationCommission().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission().divide(number,2,RoundingMode.HALF_UP));
|
||||
xhpcSt.setOperatorId(operatorId);
|
||||
xhpcSt.setChargingStationId(chargingStationId);
|
||||
xhpcSt.setCreateTime(data);
|
||||
xhpcSt.setTerminalId(terminalId);
|
||||
xhpcSt.setHistoryOrderId(historyOrderId);
|
||||
if(xhpc.getSource()==1){
|
||||
xhpcSt.setInternetUserId(xhpc.getUserId());
|
||||
}
|
||||
xhpcStatisticsService.addStatisticsTime(xhpcSt);
|
||||
}else{
|
||||
//跨时段
|
||||
//总共时段 endHour+1-startHour
|
||||
addStatisTime(xhpc, startTime, endTime, rateModelId, operatorId, chargingStationId, terminalId, historyOrderId, startHour, endHour);
|
||||
}
|
||||
}
|
||||
|
||||
private void addStatis(XhpcChargeHistoryOrder xhpc, Long rateModelId, Long operatorId, Long chargingStationId, Long terminalId, Long historyOrderId, int endHour, BigDecimal number, String start, String end) {
|
||||
List<Map<String, Object>> reatTimeList = xhpcHistoryOrderService.getReatTimeList(start, end, rateModelId);
|
||||
if (reatTimeList != null && reatTimeList.size() > 0) {
|
||||
if (reatTimeList.size() == 1) {
|
||||
addSte(xhpc, operatorId, chargingStationId, terminalId, historyOrderId, endHour, number, reatTimeList, 0, 1);
|
||||
} else {
|
||||
for (int j = 0; j < reatTimeList.size(); j++) {
|
||||
addSte(xhpc, operatorId, chargingStationId, terminalId, historyOrderId, endHour, number, reatTimeList, j, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addSte(XhpcChargeHistoryOrder xhpc, Long operatorId, Long chargingStationId, Long terminalId, Long historyOrderId, int endHour, BigDecimal number, List<Map<String, Object>> reatTimeList, int j, int type) {
|
||||
Date data = Calendar.getInstance().getTime();
|
||||
Map<String, Object> map = reatTimeList.get(j);
|
||||
BigDecimal size = new BigDecimal(reatTimeList.size());
|
||||
long time3 = DateUtil.parse(map.get("endTime").toString()).getTime();
|
||||
long time4 = DateUtil.parse(map.get("startTime").toString()).getTime();
|
||||
BigDecimal time5 = new BigDecimal((time3-time4)/6000);
|
||||
BigDecimal powerFee =new BigDecimal(map.get("powerFee").toString());
|
||||
BigDecimal serviceFee =new BigDecimal(map.get("serviceFee").toString());
|
||||
XhpcStatisticsTimeInterval xhpcSt = new XhpcStatisticsTimeInterval();
|
||||
xhpcSt.setStatus(endHour+1);
|
||||
xhpcSt.setChargingDegree(xhpc.getChargingDegree());
|
||||
xhpcSt.setChargingTime(time5);
|
||||
xhpcSt.setChargingNumber(1);
|
||||
BigDecimal powerFee1 = powerFee.multiply(time5).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal serviceFee1 = serviceFee.multiply(time5).setScale(2, RoundingMode.HALF_UP);
|
||||
xhpcSt.setPowerPrice(powerFee1);
|
||||
xhpcSt.setServicePrice(serviceFee1);
|
||||
xhpcSt.setTotalPrice(powerFee1.add(serviceFee1));
|
||||
if(type==1){
|
||||
xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount().divide(number,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setActPrice(powerFee1.add(serviceFee1).subtract(xhpcSt.getPromotionDiscount()));
|
||||
xhpcSt.setActPowerPrice(xhpc.getActPowerPrice().divide(number,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setActServicePrice(xhpc.getActServicePrice().divide(number,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setInternetCommission(xhpc.getInternetCommission().divide(number,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission().divide(number,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setPlatformCommission(xhpc.getPlatformCommission().divide(number,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion().divide(number,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setOperationCommission(xhpc.getOperationCommission().divide(number,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission().divide(number,2, RoundingMode.HALF_UP));
|
||||
}else{
|
||||
xhpcSt.setPromotionDiscount(xhpc.getPromotionDiscount().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setActPrice(powerFee1.add(serviceFee1).subtract(xhpcSt.getPromotionDiscount()));
|
||||
xhpcSt.setActPowerPrice(xhpc.getActPowerPrice().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setActServicePrice(xhpc.getActServicePrice().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setInternetCommission(xhpc.getInternetCommission().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setInternetSvcCommission(xhpc.getInternetSvcCommission().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setPlatformCommission(xhpc.getPlatformCommission().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setPlatformSvcCommisssion(xhpc.getPlatformSvcCommisssion().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setOperationCommission(xhpc.getOperationCommission().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP));
|
||||
xhpcSt.setOperationSvcCommission(xhpc.getOperationSvcCommission().divide(number,2, RoundingMode.HALF_UP).divide(size,2, RoundingMode.HALF_UP));
|
||||
}
|
||||
xhpcSt.setOperatorId(operatorId);
|
||||
xhpcSt.setChargingStationId(chargingStationId);
|
||||
xhpcSt.setCreateTime(data);
|
||||
xhpcSt.setTerminalId(terminalId);
|
||||
xhpcSt.setHistoryOrderId(historyOrderId);
|
||||
if(xhpc.getSource()==1){
|
||||
xhpcSt.setInternetUserId(xhpc.getUserId());
|
||||
}
|
||||
xhpcStatisticsService.addStatisticsTime(xhpcSt);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
System.out.println(">>>>>"+DateUtil.format(Calendar.getInstance().getTime(), "yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,6 +109,11 @@ public class XhpcStatisticsTimeInterval extends BaseEntity {
|
||||
*/
|
||||
private Long terminalId;
|
||||
|
||||
/**
|
||||
* 历史订单id
|
||||
*/
|
||||
private Long historyOrderId;
|
||||
|
||||
public Long getStatisticsTimeIntervalId() {
|
||||
|
||||
return statisticsTimeIntervalId;
|
||||
@ -339,4 +344,14 @@ public class XhpcStatisticsTimeInterval extends BaseEntity {
|
||||
this.terminalId = terminalId;
|
||||
}
|
||||
|
||||
public Long getHistoryOrderId() {
|
||||
|
||||
return historyOrderId;
|
||||
}
|
||||
|
||||
public void setHistoryOrderId(Long historyOrderId) {
|
||||
|
||||
this.historyOrderId = historyOrderId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -114,8 +114,9 @@ public interface IXhpcRealTimeOrderService {
|
||||
* @param userId
|
||||
* @param userMessage
|
||||
* @param type 0 不发短信 1发短信
|
||||
* @param vinNormal VUN 码
|
||||
*/
|
||||
void addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, Map<String, Object> userMessage,Integer type);
|
||||
void addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, Map<String, Object> userMessage,Integer type,String vinNormal);
|
||||
|
||||
/**
|
||||
* 添加redis到数据库
|
||||
|
||||
@ -247,7 +247,8 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService {
|
||||
if(xhpcChargingPileById.get("communicationProtocolVersion")!=null && !"".equals(xhpcChargingPileById.get("communicationProtocolVersion").toString())){
|
||||
version=xhpcChargingPileById.get("communicationProtocolVersion").toString();
|
||||
}
|
||||
R oa = powerPileService.stopCharging(xhpcTerminal.getPileSerialNumber(), xhpcTerminal.getSerialNumber(), version);
|
||||
|
||||
R oa = powerPileService.stopCharging(xhpcTerminal.getPileSerialNumber(), xhpcTerminal.getSerialNumber().substring(14), version);
|
||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<停止充电返回>>>>>>>>>>>>>>>>>");
|
||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<"+oa.getCode()+">>>>>>>>>>>>>>>>>");
|
||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<"+oa.getMsg()+">>>>>>>>>>>>>>>>>");
|
||||
|
||||
@ -111,8 +111,7 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService {
|
||||
BigDecimal servicePriceTotal1 =(BigDecimal)map1.get("servicePriceTotal");
|
||||
//明天
|
||||
DateTime tomorrow = DateUtil.offsetDay(startTime2,1);
|
||||
String startTime1 = DateUtil.format(tomorrow, "yyyy-MM-dd");
|
||||
Date startTime3 = DateUtil.parse(startTime1+" 00:00:00");
|
||||
Date startTime3 =DateUtil.beginOfDay(tomorrow);
|
||||
Map<String, Object> map2 = getBigDecimal(actPrice, powerPriceTotal1, servicePriceTotal1, chargeOrder, rateModelId, startTime3, updateTime2, chargingDegree, list);
|
||||
return map2;
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService {
|
||||
return AjaxResult.error("用户id:" + userId + "为空");
|
||||
}
|
||||
//生成一条历史订单
|
||||
addSettlement(powerPrice, servicePrice, money, surplusPowerPrice, surplusServicePrice, xhpcChargeOrder, userId, userMessage,0);
|
||||
addSettlement(powerPrice, servicePrice, money, surplusPowerPrice, surplusServicePrice, xhpcChargeOrder, userId, userMessage,0,null);
|
||||
|
||||
return AjaxResult.success();
|
||||
}
|
||||
@ -197,10 +197,11 @@ public class XhpcRealTimeOrderServiceImpl implements IXhpcRealTimeOrderService {
|
||||
* @param type 0 不发短信 1发短信
|
||||
*/
|
||||
@Override
|
||||
public void addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, Map<String, Object> userMessage,Integer type) {
|
||||
public void addSettlement(BigDecimal powerPrice, BigDecimal servicePrice, BigDecimal money, BigDecimal surplusPowerPrice, BigDecimal surplusServicePrice, XhpcChargeOrder xhpcChargeOrder, Long userId, Map<String, Object> userMessage,Integer type,String vinNormal) {
|
||||
XhpcHistoryOrder xhpcHistoryOrder =new XhpcHistoryOrder();
|
||||
xhpcHistoryOrder.setPowerPriceTotal(powerPrice);
|
||||
xhpcHistoryOrder.setServicePriceTotal(servicePrice);
|
||||
xhpcHistoryOrder.setVinNormal(vinNormal);
|
||||
BigDecimal balance = new BigDecimal(userMessage.get("balance").toString()).divide(new BigDecimal(100));
|
||||
//电站活动抵扣--抵扣的总金额
|
||||
BigDecimal promotionDiscount = new BigDecimal(0);
|
||||
|
||||
@ -207,7 +207,7 @@ public class XhpcStatisticsServiceImpl implements IXhpcStatisticsService {
|
||||
|
||||
@Override
|
||||
public void addStatisticsTime(XhpcStatisticsTimeInterval xhpcStatisticsTimeInterval) {
|
||||
|
||||
xhpcStatisticsServiceMapper.addStatisticsTime(xhpcStatisticsTimeInterval);
|
||||
}
|
||||
|
||||
private boolean getJudge(Long internetUserId, Long operatorId, Integer type) {
|
||||
|
||||
@ -134,7 +134,10 @@
|
||||
power_price_total,
|
||||
</if>
|
||||
<if test="null != servicePriceTotal and '' != servicePriceTotal">
|
||||
service_price_total
|
||||
service_price_total,
|
||||
</if>
|
||||
<if test="null != vinNormal and '' != vinNormal">
|
||||
vin_normal
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
@ -229,7 +232,10 @@
|
||||
#{powerPriceTotal},
|
||||
</if>
|
||||
<if test="null != servicePriceTotal and '' != servicePriceTotal">
|
||||
#{servicePriceTotal}
|
||||
#{servicePriceTotal},
|
||||
</if>
|
||||
<if test="null != vinNormal and '' != vinNormal">
|
||||
#{vinNormal}
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@ -416,7 +416,10 @@
|
||||
remark,
|
||||
</if>
|
||||
<if test="null != terminalId ">
|
||||
terminal_id
|
||||
terminal_id,
|
||||
</if>
|
||||
<if test="null != historyOrderId ">
|
||||
history_order_id
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
@ -496,7 +499,10 @@
|
||||
#{terminalId},
|
||||
</if>
|
||||
<if test="null != chargingTimeNumber ">
|
||||
#{chargingTimeNumber}
|
||||
#{chargingTimeNumber},
|
||||
</if>
|
||||
<if test="null != historyOrderId ">
|
||||
#{historyOrderId}
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@ -19,4 +19,10 @@ public class OrderNotificationWebSocketController {
|
||||
OrderNotificationWebSocket.sendMessage(userId,"有新订单啦");
|
||||
}
|
||||
|
||||
@GetMapping("/getMessage")
|
||||
public void getMessage(@RequestParam String userId,@RequestParam String message){
|
||||
OrderNotificationWebSocket.sendMessage(userId,message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
package com.xhpc.wxma.rabbitm;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.rabbitmq.client.*;
|
||||
import com.xhpc.common.util.ConnectionRabbitMQUtil;
|
||||
import com.xhpc.wxma.socket.OrderNotificationWebSocket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* @author yuyang
|
||||
@ -17,6 +21,9 @@ import java.io.IOException;
|
||||
public class RabbitmConsumer implements ApplicationRunner {
|
||||
//队列名称
|
||||
private final static String NAME="webSocket";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RabbitmConsumer.class);
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
try {
|
||||
@ -35,9 +42,11 @@ public class RabbitmConsumer implements ApplicationRunner {
|
||||
//消息id,mq在channel中用来标识消息的id,可用于确认消息已接收
|
||||
//long deliveryTag = envelope.getDeliveryTag();
|
||||
// body 即消息体
|
||||
logger.info("<<<<<<<<<<收到消息队列时间<<<<<<<<<<<<<<"+ DateUtil.format(Calendar.getInstance().getTime(), "yyyy-MM-dd HH:mm:ss")+">>>>>>>>>>>>>>>>>");
|
||||
String msg = new String(body,"utf-8");
|
||||
String[] split = msg.split("##");
|
||||
OrderNotificationWebSocket.sendMessage(split[0],split[1]);
|
||||
logger.info("<<<<<<<<<<消息队列发送时间<<<<<<<<<<<<<<"+ DateUtil.format(Calendar.getInstance().getTime(), "yyyy-MM-dd HH:mm:ss")+">>>>>>>>>>>>>>>>>");
|
||||
}
|
||||
};
|
||||
channel.basicConsume(NAME, true, consumer);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user