修改定时任务未启动,场站列表统计修改为redis数据

This commit is contained in:
yuyang 2021-11-01 10:52:56 +08:00
parent ac744d40c6
commit fe541b0c3e
14 changed files with 426 additions and 305 deletions

View File

@ -108,4 +108,11 @@ public interface XhpcTerminalMapper {
*/
List<Map<String, Object>> getXhpcPileNameAndStationNameAndTerminalNumList(@Param("terminalSerialNumber") String terminalSerialNumber, @Param("pileName") String pileName, @Param("stationName") String stationName);
/**
* 根据电站获取终端的编号
* @param chargingStationId
* @return
*/
List<String> getTerminal(@Param("chargingStationId") Long chargingStationId);
}

View File

@ -15,7 +15,7 @@ public interface IXhpcTerminalService {
/**
* PC端页面统计
* PC端页面统计(已作废)
* @param chargingStationId 电站id
* @return
*/
@ -65,4 +65,11 @@ public interface IXhpcTerminalService {
*/
List<Map<String, Object>> getXhpcPileNameAndStationNameAndTerminalNumList(String terminalSerialNumber, String pileName, String stationName);
/**
* 根据电站获取终端的编号
* @param chargingStationId
* @return
*/
List<String> getTerminal(Long chargingStationId);
}

View File

@ -83,11 +83,36 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi
if (xhpcRateTime != null) {
map.putAll(xhpcRateTime);
}
//获取桩的统计
Map<String, Object> chargingId = xhpcTerminalService.countXhpcTerminalWorkStatus(chargingStationId);
if (chargingId != null) {
map.putAll(chargingId);
//获取桩的统计.redis 数据
List<String> terminal = xhpcTerminalService.getTerminal(chargingStationId);
int offLine =0;//离线
int fault =0;//故障
int freeTime =0;//空闲
int charge =0;//充电
int unknown =0;//未知
if(terminal !=null && terminal.size()>0){
for (String st:terminal) {
Map<String, Object> cacheMap = redisService.getCacheMap("gun:" + st);
if(!cacheMap.isEmpty()){
if ("离线".equals(cacheMap.get("status").toString())){
offLine++;
}else if("故障".equals(cacheMap.get("status").toString())){
fault++;
}else if("空闲".equals(cacheMap.get("status").toString())){
freeTime++;
}else{
charge++;
}
}else{
unknown++;
}
}
}
map.put("offLine",offLine);
map.put("fault",fault);
map.put("freeTime",freeTime);
map.put("charge",charge);
map.put("unknown",unknown);
}
return list;
}
@ -248,6 +273,12 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi
if (xhpcChargingStationDto.getImgId() == null) {
return AjaxResult.error(1001, "图片不能为空");
}
if (xhpcChargingStationDto.getServiceTel() == null) {
return AjaxResult.error(1001, "站点电话不能为空");
}
if (xhpcChargingStationDto.getParkNums() == null) {
return AjaxResult.error(1001, "侧位数量不能为空");
}
//判断费率和费率时间段 是否有值
if (xhpcChargingStationDto.getXhpcRateList() == null && xhpcChargingStationDto.getXhpcRateList().size() == 0) {
@ -1029,15 +1060,11 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi
// System.out.println(num);
for (int i = 0; i <10 ; i++) {
if(i==5){
continue;
}
System.out.println("i:"+i);
}
int i =0;
i++;
System.out.println("111????????????????"+i);
i=i++;
System.out.println("222????????????????"+i);
}

View File

@ -123,4 +123,10 @@ public class XhpcTerminalServiceImpl implements IXhpcTerminalService {
return xhpcTerminalMapper.getXhpcPileNameAndStationNameAndTerminalNumList(terminalSerialNumber, pileName, stationName);
}
@Override
public List<String> getTerminal(Long chargingStationId) {
return xhpcTerminalMapper.getTerminal(chargingStationId);
}
}

View File

@ -173,7 +173,9 @@
<if test="reminderInstructions != null">reminder_instructions = #{reminderInstructions},</if>
<if test="imgId != null">img_id = #{imgId},</if>
<if test="stationType != null">station_type = #{stationType},</if>
<if test="operatorIdEvcs != null">operator_id_evcs = #{operatorIdEvcs}</if>
<if test="operatorIdEvcs != null">operator_id_evcs = #{operatorIdEvcs},</if>
<if test="serviceTel != null">service_tel = #{serviceTel},</if>
<if test="parkNums != null">park_nums = #{parkNums}</if>
</trim>
where charging_station_id = #{chargingStationId}
</update>
@ -516,7 +518,13 @@
station_type,
</if>
<if test="null != operatorIdEvcs and '' != operatorIdEvcs">
operator_id_evcs
operator_id_evcs,
</if>
<if test="null != serviceTel and '' != serviceTel">
service_tel,
</if>
<if test="null != parkNums and '' != parkNums">
park_nums
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
@ -599,7 +607,13 @@
#{stationType},
</if>
<if test="null != operatorIdEvcs and '' != operatorIdEvcs">
#{operatorIdEvcs}
#{operatorIdEvcs},
</if>
<if test="null != serviceTel and '' != serviceTel">
#{serviceTel},
</if>
<if test="null != parkNums and '' != parkNums">
#{parkNums}
</if>
</trim>
</insert>

View File

@ -372,4 +372,9 @@
And terminal.serial_number like CONCAT('%',#{stationName},'%')
</if>
</select>
<select id="getTerminal" resultType="String">
select serial_number as serialNumber from xhpc_terminal where charging_station_id=#{chargingStationId}
</select>
</mapper>

View File

@ -114,7 +114,7 @@ public class XhpcChargingStation extends BaseEntity {
/**
*侧位数量
*/
private String parkNums;
private Integer parkNums;
public String getOperatorIdEvcs() {
@ -342,12 +342,12 @@ public class XhpcChargingStation extends BaseEntity {
this.serviceTel = serviceTel;
}
public String getParkNums() {
public Integer getParkNums() {
return parkNums;
}
public void setParkNums(String parkNums) {
public void setParkNums(Integer parkNums) {
this.parkNums = parkNums;
}

View File

@ -16,6 +16,7 @@ import com.xhpc.order.service.IXhpcHistoryOrderService;
import com.xhpc.order.service.IXhpcStatisticsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -31,6 +32,7 @@ import java.util.*;
* @author yuyang
* @date 2021/8/3 21:19
*/
@EnableScheduling
@RestController
@RequestMapping("/histotyOrder")
@Api(value = "历史订单接口", tags = "历史订单接口")
@ -196,6 +198,9 @@ public class XhpcHistoryOrderController extends BaseController {
}
//每分钟多少度电
BigDecimal v = new BigDecimal((endTime.getTime() - startTime.getTime())).divide(new BigDecimal(60000),2,RoundingMode.HALF_UP);
if(v.compareTo(new BigDecimal(0)) !=1){
break;
}
BigDecimal multiply = xhpc.getChargingDegree().divide(v,2,RoundingMode.HALF_UP);
//1时间没有跨天

View File

@ -170,11 +170,13 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService {
int number =0;
if(!"".equals(userMessage.get("soc")) && userMessage.get("soc") !=null && !"".equals(userMessage.get("soc"))){
number =Integer.parseInt(userMessage.get("soc").toString());
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<用户>>>>>>>>>>>>>>>>>:"+number);
}
//平台
String soc = redisService.getCacheObject("global:SOC");
if(!"".equals(soc) && soc!=null){
if(number!=0){
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<平台>>>>>>>>>>>>>>>>>:"+soc);
if(Integer.parseInt(soc)-number<0){
number=Integer.parseInt(soc);
}
@ -185,6 +187,7 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService {
Map<String, Object> operatorMessage = xhpcChargeOrderMapper.getOperatorMessage(xhpcTerminal.getChargingStationId());
if(operatorMessage !=null && operatorMessage.get("soc") !=null && !"".equals(operatorMessage.get("soc"))){
if(number!=0){
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<营运商>>>>>>>>>>>>>>>>>:"+operatorMessage.get("soc").toString());
if(Integer.parseInt(operatorMessage.get("soc").toString())-number<0){
number=Integer.parseInt(operatorMessage.get("soc").toString());
}

View File

@ -115,301 +115,304 @@ public class XhpcHistoryOrderServiceImpl implements IXhpcHistoryOrderService {
logger.info("订单异常回调接口>>>>>orderNo" + orderNo);
//获取实时订单
CacheRealtimeData cacheRealtimeData = redisService.getCacheObject("order:" + orderNo + ".lord");
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo);
Long userId = xhpcChargeOrder.getUserId();
try {
//开始时间
Date startTime2 = xhpcChargeOrder.getStartTime();
//当checking为true时自动结算
Integer chargingTime = cacheRealtimeData.getChargingTime();
boolean checking = false;
if(type==1){
if(chargingTime<3){
if(cacheRealtimeData !=null){
XhpcChargeOrder xhpcChargeOrder = xhpcChargeOrderService.getSerialNumberMessage(orderNo);
Long userId = xhpcChargeOrder.getUserId();
try {
//开始时间
Date startTime2 = xhpcChargeOrder.getStartTime();
//当checking为true时自动结算
Integer chargingTime = cacheRealtimeData.getChargingTime();
boolean checking = false;
if(type==1){
if(chargingTime<3){
checking=true;
}
}else{
checking=true;
}
}else{
checking=true;
}
//毫秒
DateTime date = DateUtil.offsetMinute(xhpcChargeOrder.getStartTime(), chargingTime);
xhpcChargeOrder.setEndTime(date);
xhpcChargeOrder.setUpdateTime(date);
if(checking){
xhpcChargeOrder.setStatus(3);
}else{
xhpcChargeOrder.setStatus(2);
}
xhpcChargeOrder.setEndSoc(cacheRealtimeData.getSoc()+"");
//充电时长
Long tiem = Long.valueOf(cacheRealtimeData.getChargingTime() / 1000);
if (tiem > 3600) {
long hours = tiem / 3600;
double mins = (double) ((tiem - (hours * 3600)) / 60);
xhpcChargeOrder.setChargingTime(hours + "" + new BigDecimal(mins).setScale(0) + "");
} else {
double mins = (double) (tiem / 60);
xhpcChargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "");
}
BigDecimal decimal = new BigDecimal(10000);
xhpcChargeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal));
xhpcChargeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal));
xhpcChargeOrder.setChargingTimeNumber(Long.valueOf(cacheRealtimeData.getChargingTime()));
if(checking){
BigDecimal money =xhpcChargeOrder.getAmountCharged();
//结算
//总电费
BigDecimal powerPrice =new BigDecimal(0);
//算时间是否跨天
Long rateModelId = xhpcChargeOrder.getRateModelId();
Date updateTime2 = xhpcChargeOrder.getEndTime();
long betweenDay = DateUtil.between(startTime2, updateTime2, DateUnit.DAY);
if(betweenDay==0){
powerPrice=getBigDecimal(rateModelId,startTime2,updateTime2,xhpcChargeOrder.getChargingDegree());
//毫秒
DateTime date = DateUtil.offsetMinute(xhpcChargeOrder.getStartTime(), chargingTime);
xhpcChargeOrder.setEndTime(date);
xhpcChargeOrder.setUpdateTime(date);
if(checking){
xhpcChargeOrder.setStatus(3);
}else{
//跨天
String startTime = DateUtil.format(startTime2, "yyyy-MM-dd");
Date updateTime = DateUtil.parse(startTime+" 23:59:59");
powerPrice=getBigDecimal(rateModelId,startTime2,updateTime,xhpcChargeOrder.getChargingDegree());
//明天
DateTime tomorrow = DateUtil.offsetDay(startTime2,1);
Date startTime3 =DateUtil.beginOfDay(tomorrow);
powerPrice=powerPrice.add(getBigDecimal(rateModelId,startTime3,updateTime2,xhpcChargeOrder.getChargingDegree()));
}
//总服务费
BigDecimal servicePrice = money.subtract(powerPrice);
//剩余的电费
BigDecimal surplusPowerPrice = powerPrice;
//剩余的服务费
BigDecimal surplusServicePrice = servicePrice;
Map<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())){
HashMap<String, String> paramMap = new HashMap<>();
paramMap.put("elec", xhpcChargeOrder.getEndSoc());
paramMap.put("sumMoney", actPrice.toString());
paramMap.put("phone", user.get("phone").toString());
paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。");
smsService.sendNotice(paramMap);
}else {
HashMap<String, String> paramMap = new HashMap<>();
paramMap.put("sumMoney", actPrice.toString());
paramMap.put("phone", user.get("phone").toString());
paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。");
smsService.sendNotice(paramMap);
}
xhpcChargeOrder.setEndSoc(cacheRealtimeData.getSoc()+"");
//充电时长
Long tiem = Long.valueOf(cacheRealtimeData.getChargingTime() / 1000);
if (tiem > 3600) {
long hours = tiem / 3600;
double mins = (double) ((tiem - (hours * 3600)) / 60);
xhpcChargeOrder.setChargingTime(hours + "" + new BigDecimal(mins).setScale(0) + "");
} else {
double mins = (double) (tiem / 60);
xhpcChargeOrder.setChargingTime(new BigDecimal(mins).setScale(0) + "");
}
BigDecimal decimal = new BigDecimal(10000);
xhpcChargeOrder.setChargingDegree(new BigDecimal(cacheRealtimeData.getChargingDegree()).divide(decimal));
xhpcChargeOrder.setAmountCharged(new BigDecimal(cacheRealtimeData.getAmountCharged()).divide(decimal));
xhpcChargeOrder.setChargingTimeNumber(Long.valueOf(cacheRealtimeData.getChargingTime()));
if(checking){
BigDecimal money =xhpcChargeOrder.getAmountCharged();
//结算
//总电费
BigDecimal powerPrice =new BigDecimal(0);
//算时间是否跨天
Long rateModelId = xhpcChargeOrder.getRateModelId();
Date updateTime2 = xhpcChargeOrder.getEndTime();
long betweenDay = DateUtil.between(startTime2, updateTime2, DateUnit.DAY);
if(betweenDay==0){
powerPrice=getBigDecimal(rateModelId,startTime2,updateTime2,xhpcChargeOrder.getChargingDegree());
}else{
//跨天
String startTime = DateUtil.format(startTime2, "yyyy-MM-dd");
Date updateTime = DateUtil.parse(startTime+" 23:59:59");
powerPrice=getBigDecimal(rateModelId,startTime2,updateTime,xhpcChargeOrder.getChargingDegree());
//明天
DateTime tomorrow = DateUtil.offsetDay(startTime2,1);
Date startTime3 =DateUtil.beginOfDay(tomorrow);
powerPrice=powerPrice.add(getBigDecimal(rateModelId,startTime3,updateTime2,xhpcChargeOrder.getChargingDegree()));
}
//总服务费
BigDecimal servicePrice = money.subtract(powerPrice);
//剩余的电费
BigDecimal surplusPowerPrice = powerPrice;
//剩余的服务费
BigDecimal surplusServicePrice = servicePrice;
Map<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);
}
}
}
}catch (Exception e){
logger.info("<<<<<<<<<<<<<<<<发送短信失败>>>>>>>>>>>>>>>>>");
xhpcHistoryOrder.setInternetCommission(internetCommission);
xhpcHistoryOrder.setInternetSvcCommission(internetSvcCommission);
}else{
//流量方未实现新增接口
}
// 另起线程处理业务上传redis数据
executorService.execute(new Runnable() {
@Override
public void run() {
xhpcRealTimeOrderService.addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(),1);
//获取运营商
Map<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())){
HashMap<String, String> paramMap = new HashMap<>();
paramMap.put("elec", xhpcChargeOrder.getEndSoc());
paramMap.put("sumMoney", actPrice.toString());
paramMap.put("phone", user.get("phone").toString());
paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,电量为:" + xhpcChargeOrder.getEndSoc() + "%,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。");
smsService.sendNotice(paramMap);
}else {
HashMap<String, String> paramMap = new HashMap<>();
paramMap.put("sumMoney", actPrice.toString());
paramMap.put("phone", user.get("phone").toString());
paramMap.put("content", "【小华停止充电】尊敬的用户,你的爱车已停止充电,总费用为:" + actPrice + "元,充电费用明细,请查询小华充电小程序,谢谢。");
smsService.sendNotice(paramMap);
}
}
}
}catch (Exception e){
logger.info("<<<<<<<<<<<<<<<<发送短信失败>>>>>>>>>>>>>>>>>");
}
// 另起线程处理业务上传redis数据
executorService.execute(new Runnable() {
@Override
public void run() {
xhpcRealTimeOrderService.addPileEndOrder(xhpcHistoryOrder, xhpcChargeOrder, xhpcChargeOrder.getSerialNumber(),1);
}
});
}
}
xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder);
} catch (Exception e) {
logger.info("异常订单回调失败");
e.printStackTrace();
}
xhpcChargeOrderService.updateXhpcChargeOrder(xhpcChargeOrder);
} catch (Exception e) {
logger.info("异常订单回调失败");
e.printStackTrace();
}
}
/**

View File

@ -256,6 +256,16 @@ public class XhpcStatisticsServiceImpl implements IXhpcStatisticsService {
return map;
}
/**
* 平台管理员权限问题
*/
private void jurisdiction(String userId){
}
}

View File

@ -95,6 +95,11 @@
<if test="type==3">
and internet_user_id=#{internetUserId}
</if>
<if test="type==1 and userId !=1">
and operator_id in (
SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId})
)
</if>
group by status
order by status
</select>
@ -133,6 +138,11 @@
<if test="type==3">
and internet_user_id=#{internetUserId}
</if>
<if test="type==1 and userId !=1">
and operator_id in (
SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId})
)
</if>
group by DATE_FORMAT(create_time,'%Y-%m-%d')
order by DATE_FORMAT(create_time,'%Y-%m-%d') desc
</select>
@ -181,6 +191,11 @@
#{operatorId}
</foreach>
</if>
<if test="type==1 and userId !=1">
and operator_id in (
SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId})
)
</if>
group by ss.charging_station_id
</select>
@ -222,6 +237,11 @@
<if test="type==3">
and ss.internet_user_id=#{internetUserId}
</if>
<if test="type==1 and userId !=1">
and operator_id in (
SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId})
)
</if>
group by ss.operator_id
</select>
@ -296,6 +316,11 @@
<if test="terminalId !=null">
and te.terminal_id=#{terminalId}
</if>
<if test="type==1 and userId !=1">
and operator_id in (
SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId})
)
</if>
group by ss.terminal_id
</select>
@ -308,6 +333,9 @@
<if test="type==2">
and operator_id =#{operatorId}
</if>
<if test="type==1 and userId !=1">
and charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId})
</if>
</select>
@ -320,6 +348,11 @@
<if test="type==2">
and operator_id =#{operatorId}
</if>
<if test="type==1 and userId !=1">
and operator_id in (
SELECT operator_id from xhpc_charging_station where charging_station_id in (SELECT charging_station_id FROM xhpc_user_privilege where user_id=#{userId})
)
</if>
</select>
<select id="getInternetUserIList" resultType="map">

View File

@ -10,6 +10,7 @@ import com.xhpc.payment.service.IXhpcRechargeOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -23,6 +24,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
@EnableScheduling
@RestController
@RequestMapping("/recharge/order")
@Api(value = "充值订单接口", tags = "充值订单接口")

View File

@ -1,17 +1,14 @@
package com.xhpc.payment.controller;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.Participant;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.xhpc.common.core.constant.HttpStatus;
import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.listener.ConfigListener;
import com.xhpc.common.core.utils.DateUtils;
import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.utils.WXPayUtil;
@ -40,13 +37,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;
import javax.net.ssl.SSLContext;
import javax.xml.soap.SAAJResult;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -55,6 +52,7 @@ import java.security.KeyStore;
import java.util.List;
import java.util.Map;
@EnableScheduling
@RestController
@RequestMapping("/refund/audit")
@Api(value = "退款审核接口", tags = "退款审核接口")
@ -517,6 +515,7 @@ public class XhpcRefundAuditController extends BaseController {
@Scheduled(cron = "0 */5 * * * ?")
@GetMapping("/moneyPage")
public void moneyPage(){
logger.info("++++++++++++111自动审核异常111++++++++++++++++");
try {
List<Long> list = iXhpcRefundOrderService.moneyPage();
if(list !=null && list.size()>0){