电站费率模型设置

This commit is contained in:
yuyang 2021-07-30 16:29:52 +08:00
parent c6e81465dc
commit c60d79fee9
5 changed files with 158 additions and 3 deletions

View File

@ -218,4 +218,11 @@ public interface XhpcChargingStationMapper {
*/
Set<String> getXchargingPileList(@Param("chargingStationId")Long chargingStationId);
/**
* 按照没30分钟为一段进行分组
* @param chargingStationId
* @return
*/
List<Map<String,Object>> getXhpcRateTimeNumber(@Param("chargingStationId")Long chargingStationId);
}

View File

@ -1,10 +1,14 @@
package com.xhpc.charging.station.service;
import cn.hutool.core.date.BetweenFormatter;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.xhpc.common.api.PowerPileService;
import com.xhpc.common.api.dto.ChargingPileDto;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.utils.DateUtils;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.data.redis.CacheRateModel;
import com.xhpc.common.domain.XhpcChargingStation;
import com.xhpc.common.domain.XhpcRate;
import com.xhpc.common.domain.XhpcRateModel;
@ -20,6 +24,7 @@ import org.springframework.data.annotation.Version;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -244,6 +249,13 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi
}
if(xhpcChargingStationDto.getXhpcRateTimeList() ==null && xhpcChargingStationDto.getXhpcRateTimeList().size()==0){
return AjaxResult.error(1001,"费率时段不能为空");
}else{
for (int i = 0; i < xhpcChargingStationDto.getXhpcRateTimeList().size(); i++) {
String id = xhpcChargingStationDto.getXhpcRateTimeList().get(i).getId();
if("00".equals(id)||"01".equals(id)||"02".equals(id)||"03".equals(id)){}else{
return AjaxResult.error("1003","费率id格式不对");
}
}
}
List<XhpcRateTimeDto> xhpcRateTimeList = xhpcChargingStationDto.getXhpcRateTimeList();
@ -251,10 +263,15 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi
XhpcRateTimeDto xhpcRateTime = xhpcRateTimeList.get(i);
String start = xhpcRateTime.getStartTime();
String end = xhpcRateTime.getEndTime();
String id = xhpcRateTime.getId();
//检查格式,正则验证 [0-2][0-9][0-6][0][0]{2}
String pattern ="^([0-2][0-9]:([0]|[3])[0]:[0][0])";
Pattern compile = Pattern.compile(pattern);
Matcher m =compile.matcher(start);
if("00".equals(id)||"01".equals(id)||"02".equals(id)||"03".equals(id)){}else{
return AjaxResult.error("1003","费率id格式不对");
}
boolean isMatch = m.matches();
if(!isMatch){
return AjaxResult.error("1003","时间格式不对");
@ -339,6 +356,9 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi
}
//默认费率类型值
String rateValue =xhpcChargingStationDto.getDefaultPeriodId();
String[] tfPricesSeq = new String[48];
int number =0;
int sort =1;
for (int k = 0; k < list.size(); k++) {
XhpcRateTimeDto xhpcRateTimeDto = list.get(k);
@ -351,34 +371,137 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi
if(!"00:00:00".equals(xhpcRateTimeDto.getStartTime())){
//添加一条默认费率时段
sort = addXhpcRateTime(chargingStationId,rateModelId,defaultPeriodId,"00:00:00",startTime,sort,2,rateValue);
//时间差
long betweenDay = DateUtil.between(DateUtil.parse("00:00:00"), DateUtil.parse(startTime), DateUnit.SECOND);
int day1 = Math.toIntExact(betweenDay / 1800);
for (int l = 0; l < day1; l++) {
tfPricesSeq[number] =rateValue;
number=number+1;
}
}
//并把本条数据也添加上
sort = addXhpcRateTime(chargingStationId,rateModelId,defaultPeriodIdMap,startTime,endTime,sort,1,rateValues);
//时间差
long betweenDay = DateUtil.between(DateUtil.parse(startTime), DateUtil.parse(endTime), DateUnit.SECOND);
int day2 = Math.toIntExact(betweenDay / 1800);
for (int l = 0; l < day2; l++) {
tfPricesSeq[number] =rateValues;
number=number+1;
}
}else if(k<list.size()){
//判断上条数据的结束时间是否等于现在这条数据的开始时间不等于添加一条默认费率时段
String endTimeK = list.get(k - 1).getEndTime();
if(!endTimeK.equals(startTime)){
//添加一条默认费率时段
sort = addXhpcRateTime(chargingStationId,rateModelId,defaultPeriodId,endTimeK,startTime,sort,2,rateValue);
//时间差
long betweenDay = DateUtil.between(DateUtil.parse(endTimeK), DateUtil.parse(startTime), DateUnit.SECOND);
int day3 = Math.toIntExact(betweenDay / 1800);
for (int l = 0; l < day3; l++) {
tfPricesSeq[number] =rateValue;
number=number+1;
}
}
//并把本条数据也添加上
sort = addXhpcRateTime(chargingStationId,rateModelId,defaultPeriodIdMap,startTime,endTime,sort,1,rateValues);
//时间差
long betweenDay = DateUtil.between(DateUtil.parse(startTime), DateUtil.parse(endTime), DateUnit.SECOND);
int day4 = Math.toIntExact(betweenDay / 1800);
for (int l = 0; l < day4; l++) {
tfPricesSeq[number] =rateValues;
number=number+1;
}
}else{
String endTimeK = list.get(k - 1).getEndTime();
if(!endTimeK.equals(startTime)){
//添加一条默认费率时段
sort = addXhpcRateTime(chargingStationId,rateModelId,defaultPeriodId,endTimeK,startTime,sort,2,rateValue);
//时间差
long betweenDay = DateUtil.between(DateUtil.parse(endTimeK), DateUtil.parse(startTime), DateUnit.SECOND);
int day5 = Math.toIntExact(betweenDay / 1800);
for (int l = 0; l < day5; l++) {
tfPricesSeq[number] =rateValue;
number=number+1;
}
}
//并把本条数据也添加上
sort = addXhpcRateTime(chargingStationId,rateModelId,defaultPeriodIdMap,startTime,endTime,sort,1,rateValues);
//时间差
long betweenDay1 = DateUtil.between(DateUtil.parse(startTime), DateUtil.parse(endTime), DateUnit.SECOND);
int day6 = Math.toIntExact(betweenDay1 / 1800);
for (int l = 0; l < day6; l++) {
tfPricesSeq[number] =rateValues;
number=number+1;
}
if(!endTime.equals("24:00:00")){
//添加一条默认费率时段
sort = addXhpcRateTime(chargingStationId,rateModelId,defaultPeriodId,startTime,"24:00:00",sort,2,rateValue);
//时间差
long betweenDay3 = DateUtil.between(DateUtil.parse(startTime), DateUtil.parse("24:00:00"), DateUnit.SECOND);
int day7 = Math.toIntExact(betweenDay3 / 1800);
for (int l = 0; l < day7; l++) {
tfPricesSeq[number] =rateValue;
number=number+1;
}
}
}
}
//设置费率模型
CacheRateModel cacheRateModel = new CacheRateModel();
cacheRateModel.setLossRate(0);
BigDecimal valueSec =new BigDecimal(100000);
boolean t1 =true;
boolean t2 =true;
boolean t3 =true;
boolean t4 =true;
for (XhpcRateDto xhpcRateDto:xhpcRateList) {
BigDecimal powerFee=xhpcRateDto.getPowerFee();
BigDecimal serviceFee=xhpcRateDto.getServiceFee();
String id =xhpcRateDto.getId();
int i1 = powerFee.multiply(valueSec).intValue();
int i2 = serviceFee.multiply(valueSec).intValue();
if("00".equals(id)){
cacheRateModel.setT1Price(i1);
cacheRateModel.setT1SvcPrice(i2);
t1=false;
}else if("01".equals(id)){
cacheRateModel.setT2Price(i1);
cacheRateModel.setT2SvcPrice(i2);
t2=false;
}else if("02".equals(id)){
cacheRateModel.setT3Price(i1);
cacheRateModel.setT3SvcPrice(i2);
t3=false;
}else if("03".equals(id)){
cacheRateModel.setT4Price(i1);
cacheRateModel.setT4SvcPrice(i2);
t4=false;
}
}
if(t1){
cacheRateModel.setT1Price(0);
cacheRateModel.setT1SvcPrice(0);
}
if(t2){
cacheRateModel.setT2Price(0);
cacheRateModel.setT2SvcPrice(0);
}
if(t3){
cacheRateModel.setT3Price(0);
cacheRateModel.setT3SvcPrice(0);
}
if(t4){
cacheRateModel.setT4Price(0);
cacheRateModel.setT4SvcPrice(0);
}
cacheRateModel.setTfPricesSeq(tfPricesSeq);
R r = powerPileService.setStationRateModel(chargingStationId, rateModelId, cacheRateModel);
System.out.println(r.toString());
return AjaxResult.success();
}
/**
* 场站详情接口
* @param chargingStationId
@ -429,7 +552,7 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi
xhpcRateTime.setType(type);
xhpcRateTime.setRateValue(rateValue);
xhpcChargingStationMapper.addXhpcRateTime(xhpcRateTime);
sort++;
sort=sort+1;
return sort;
}
@ -747,4 +870,14 @@ public class XhpcChargingStationServiceImpl implements IXhpcChargingStationServi
}
}
public static void main(String[] args) {
//时间差
long betweenDay = DateUtil.between(DateUtil.parse("00:00:00"), DateUtil.parse("10:00:00"), DateUnit.SECOND);
System.out.println("betweenDay:"+betweenDay);
}
}

View File

@ -293,6 +293,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
te.name as name,
cp.power as power,
cp.auxiliary_power_supply as auxiliaryPowerSupply,
cp.serial_number as serialNumber,
cp.input_voltage as inputVoltage
from xhpc_terminal as te
left join xhpc_charging_pile as cp on cp.charging_pile_id = te.charging_pile_id
@ -679,9 +680,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select
power_fee as powerFee,
service_fee as serviceFee,
name as name
name as name,
rate_value as rateValue
from xhpc_rate
where charging_station_id=#{chargingStationId} and del_flag =0
GROUP BY rate_value
</select>
<select id="getXhpcRateTimeTypeList" resultType="java.util.Map">
@ -732,4 +735,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from xhpc_charging_pile
where charging_station_id=#{chargingStationId} and del_flag =0 and status =0
</select>
<select id="getXhpcRateTimeNumber" resultType="java.util.Map">
SELECT
CAST(((UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(start_time))/1800) AS SIGNED) as number,
rate_value as rateValue
FROM
xhpc_rate_time
where charging_station_id=#{chargingStationId}
order by sort
</select>
</mapper>

View File

@ -255,6 +255,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ter.name as terminalName,
ter.serial_number as serialNumber,
cp.power as power,
cp.type as type,
cp.max_voltage as maxVoltage,
cp.auxiliary_power_supply as auxiliaryPowerSupply,
ct.parking_instructions as parkingInstructions,

View File

@ -6,6 +6,7 @@ import com.xhpc.common.core.domain.R;
import com.xhpc.common.api.factory.PowerPileFallbackFactory;
import com.xhpc.common.data.down.StartChargingData;
import com.xhpc.common.data.redis.CacheRateModel;
import org.apache.ibatis.annotations.Param;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
@ -28,6 +29,6 @@ public interface PowerPileService {
R deletePileWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set<String> pileNoSet);
@PostMapping("/station/rateModel/{stationId}/{rateModelId}")
R setStationRateModel(@PathVariable("stationId") Long stationId, @PathVariable("rateModelId") Long rateModelId, @RequestBody CacheRateModel rateModel);
R setStationRateModel(@PathVariable("stationId") @Param("stationId") Long stationId, @PathVariable("rateModelId") @Param("rateModelId") Long rateModelId, @RequestBody @Param("rateModel") CacheRateModel rateModel);
}