From c60d79fee9802de085d12f9cfb8a0243d9ad28ca Mon Sep 17 00:00:00 2001 From: yuyang <2265829957@qq.com> Date: Fri, 30 Jul 2021 16:29:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E7=AB=99=E8=B4=B9=E7=8E=87=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/XhpcChargingStationMapper.java | 7 + .../XhpcChargingStationServiceImpl.java | 135 +++++++++++++++++- .../mapper/XhpcChargingStationMapper.xml | 15 +- .../resources/mapper/XhpcTerminalMapper.xml | 1 + .../com/xhpc/common/api/PowerPileService.java | 3 +- 5 files changed, 158 insertions(+), 3 deletions(-) diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java index 6ef1f27c..7d7451b3 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/mapper/XhpcChargingStationMapper.java @@ -218,4 +218,11 @@ public interface XhpcChargingStationMapper { */ Set getXchargingPileList(@Param("chargingStationId")Long chargingStationId); + /** + * 按照没30分钟为一段进行分组 + * @param chargingStationId + * @return + */ + List> getXhpcRateTimeNumber(@Param("chargingStationId")Long chargingStationId); + } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java index a2bd42c2..68fd7948 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcChargingStationServiceImpl.java @@ -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 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 + + diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml index e4299120..f5481fb6 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcTerminalMapper.xml @@ -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, diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java index e52dd580..83e05df7 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/common/api/PowerPileService.java @@ -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 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); }