费用标准时间查重验证
费用结算 如果当前时间段不存在, 默认往前找, 前面没有,往后找
This commit is contained in:
parent
8f9e5cf565
commit
5f43f7510c
@ -80,6 +80,11 @@
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-crypto</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -17,4 +17,15 @@ public interface BatteryStationHdFeeStandardDao extends BaseMapper<BatteryStatio
|
||||
|
||||
List<BatteryStationHdFeeStandard> listFeeStandard(@Param("stationCode") String stationCode, @Param("day") String day);
|
||||
|
||||
/***
|
||||
* 订单结算时, 没有找到合适的时间范围, 默认找最新的一个
|
||||
* @param stationCode
|
||||
* @return
|
||||
*/
|
||||
List<BatteryStationHdFeeStandard> orderCreateBeforeFeeEndStandard(@Param("stationCode") String stationCode, @Param("day") String day);
|
||||
List<BatteryStationHdFeeStandard> orderCreateAfterFeeBeginStandard(@Param("stationCode") String stationCode, @Param("day") String day);
|
||||
|
||||
|
||||
Boolean existsData(@Param("stationCode") String stationCode, @Param("begin") String begin, @Param("end") String end, @Param("pkId")Integer pkId);
|
||||
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
package com.evotech.hd.cloud.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStationHdFeeStandardDetail;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zrb
|
||||
@ -13,4 +15,5 @@ public interface BatteryStationHdFeeStandardDetailDao extends BaseMapper<Battery
|
||||
|
||||
List<BatteryStationHdFeeStandardDetail> getDetailById(Integer id);
|
||||
|
||||
Boolean existsData(@Param("standardId") Integer standardId, @Param("begin") LocalTime begin, @Param("end") LocalTime end, @Param("pkId")Integer pkId);
|
||||
}
|
||||
|
||||
@ -1,17 +1,16 @@
|
||||
package com.evotech.hd.cloud.service.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.evotech.hd.cloud.dao.BatteryStationHdFeeStandardDetailDao;
|
||||
import com.evotech.hd.cloud.service.BatteryStationHdFeeStandardDetailService;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStationHdFeeStandardDetail;
|
||||
import com.evotech.hd.common.core.enums.CodeMsg;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
@ -22,11 +21,12 @@ public class BatteryStationHdFeeStandardDetailServiceImpl implements BatteryStat
|
||||
|
||||
@Override
|
||||
public Result<Integer> add(BatteryStationHdFeeStandardDetail bsfsd) {
|
||||
boolean b = batteryStationHdFeeStandardDetailDao.exists(new QueryWrapper<BatteryStationHdFeeStandardDetail>()
|
||||
.or(i -> i.and(j -> j.le("time_begin", bsfsd.getTimeBegin()).ge("time_end", bsfsd.getTimeBegin()))
|
||||
.or(j -> j.le("time_begin", bsfsd.getTimeEnd()).ge("time_end", bsfsd.getTimeEnd()))
|
||||
.or(j -> j.ge("time_begin", bsfsd.getTimeBegin()).le("time_end", bsfsd.getTimeEnd())))
|
||||
.eq("standard_id", bsfsd.getStandardId()));
|
||||
// boolean b = batteryStationHdFeeStandardDetailDao.exists(new QueryWrapper<BatteryStationHdFeeStandardDetail>()
|
||||
// .or(i -> i.and(j -> j.le("time_begin", bsfsd.getTimeBegin()).ge("time_end", bsfsd.getTimeBegin()))
|
||||
// .or(j -> j.le("time_begin", bsfsd.getTimeEnd()).ge("time_end", bsfsd.getTimeEnd()))
|
||||
// .or(j -> j.ge("time_begin", bsfsd.getTimeBegin()).le("time_end", bsfsd.getTimeEnd())))
|
||||
// .eq("standard_id", bsfsd.getStandardId()));
|
||||
boolean b = batteryStationHdFeeStandardDetailDao.existsData(bsfsd.getStandardId(), bsfsd.getTimeBegin(), bsfsd.getTimeEnd(), null);
|
||||
if (b) {
|
||||
return new Result<Integer>().error("换电站费用标准明细时间冲突!");
|
||||
}
|
||||
@ -49,6 +49,11 @@ public class BatteryStationHdFeeStandardDetailServiceImpl implements BatteryStat
|
||||
|
||||
@Override
|
||||
public Result<Integer> update(BatteryStationHdFeeStandardDetail bsfsd) {
|
||||
|
||||
boolean b = batteryStationHdFeeStandardDetailDao.existsData(bsfsd.getStandardId(), bsfsd.getTimeBegin(), bsfsd.getTimeEnd(), bsfsd.getPkId());
|
||||
if (b) {
|
||||
return new Result<Integer>().error("换电站费用标准明细时间冲突!");
|
||||
}
|
||||
int n = batteryStationHdFeeStandardDetailDao.updateById(bsfsd);
|
||||
if (n == 1) {
|
||||
return new Result<Integer>().success(n);
|
||||
|
||||
@ -1,11 +1,5 @@
|
||||
package com.evotech.hd.cloud.service.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.evotech.hd.cloud.dao.BatteryStationHdFeeStandardDao;
|
||||
import com.evotech.hd.cloud.dao.BatteryStationHdFeeStandardDetailDao;
|
||||
@ -14,8 +8,12 @@ import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStationHdFeeStandard;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStationHdFeeStandardDetail;
|
||||
import com.evotech.hd.common.core.enums.CodeMsg;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class BatteryStationHdFeeStandardServiceImpl implements BatteryStationHdFeeStandardService {
|
||||
@ -27,11 +25,14 @@ public class BatteryStationHdFeeStandardServiceImpl implements BatteryStationHdF
|
||||
|
||||
@Override
|
||||
public Result<Integer> add(BatteryStationHdFeeStandard bsfs) {
|
||||
boolean b = batteryStationHdFeeStandardDao.exists(new QueryWrapper<BatteryStationHdFeeStandard>()
|
||||
.or(i -> i.and(j -> j.le("day_begin", bsfs.getDayBegin()).ge("day_end", bsfs.getDayBegin()))
|
||||
.or(j -> j.le("day_begin", bsfs.getDayEnd()).ge("day_end", bsfs.getDayEnd()))
|
||||
.or(j -> j.ge("day_begin", bsfs.getDayBegin()).le("day_end", bsfs.getDayEnd())))
|
||||
.eq("station_code", bsfs.getStationCode()));
|
||||
// boolean b = batteryStationHdFeeStandardDao.exists(new QueryWrapper<BatteryStationHdFeeStandard>()
|
||||
// .or(i -> i.and(j -> j.le("day_begin", bsfs.getDayBegin()).ge("day_end", bsfs.getDayBegin()))
|
||||
// .or(j -> j.le("day_begin", bsfs.getDayEnd()).ge("day_end", bsfs.getDayEnd()))
|
||||
// .or(j -> j.ge("day_begin", bsfs.getDayBegin()).le("day_end", bsfs.getDayEnd())))
|
||||
// .eq("station_code", bsfs.getStationCode()));
|
||||
boolean b = batteryStationHdFeeStandardDao.existsData(bsfs.getStationCode(), bsfs.getDayBegin(), bsfs.getDayEnd(), null);
|
||||
|
||||
|
||||
if (b) {
|
||||
return new Result<Integer>().error("换电站费用标准日期冲突!");
|
||||
}
|
||||
@ -57,6 +58,10 @@ public class BatteryStationHdFeeStandardServiceImpl implements BatteryStationHdF
|
||||
|
||||
@Override
|
||||
public Result<Integer> update(BatteryStationHdFeeStandard bsfs) {
|
||||
boolean b = batteryStationHdFeeStandardDao.existsData(bsfs.getStationCode(), bsfs.getDayBegin(), bsfs.getDayEnd(), bsfs.getPkId());
|
||||
if (b) {
|
||||
return new Result<Integer>().error("换电站费用标准日期冲突!");
|
||||
}
|
||||
int n = batteryStationHdFeeStandardDao.updateById(bsfs);
|
||||
if (n == 1) {
|
||||
return new Result<Integer>().success(n);
|
||||
|
||||
@ -1,21 +1,20 @@
|
||||
package com.evotech.hd.cloud.utils.components;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.evotech.hd.cloud.dao.BatteryStationHdFeeStandardDao;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStationHdFeeStandard;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStationHdFeeStandardDetail;
|
||||
import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@ -34,7 +33,15 @@ public class SwapOrderBasicFeeComponent {
|
||||
public OrderSwapBattery orderBasicFee(OrderSwapBattery osb) {
|
||||
// 根据换电站编码和订单时间查询费用标准列表
|
||||
List<BatteryStationHdFeeStandard> list = batteryStationHdFeeStandardDao.listFeeStandard(osb.getStationCode(), DateUtil.format(osb.getOrderTime(), DatePattern.PURE_DATE_FORMATTER));
|
||||
log.info("换电站编码{}时间{}单费用计算参数========>:{}", DateUtil.format(osb.getOrderTime(), DatePattern.PURE_DATE_FORMATTER),osb.getStationCode(),JSONUtil.toJsonStr(osb));
|
||||
if(CollectionUtils.isEmpty(list)){
|
||||
list = batteryStationHdFeeStandardDao.orderCreateBeforeFeeEndStandard(osb.getStationCode(), DateUtil.format(osb.getOrderTime(), DatePattern.PURE_DATE_FORMATTER));
|
||||
}
|
||||
if(CollectionUtils.isEmpty(list)){
|
||||
list = batteryStationHdFeeStandardDao.orderCreateAfterFeeBeginStandard(osb.getStationCode(), DateUtil.format(osb.getOrderTime(), DatePattern.PURE_DATE_FORMATTER));
|
||||
}
|
||||
|
||||
|
||||
log.info("换电站编码{}时间{}订单费用计算参数========>:{}, 费用标准信息:{}", DateUtil.format(osb.getOrderTime(), DatePattern.PURE_DATE_FORMATTER),osb.getStationCode(),JSONUtil.toJsonStr(osb),JSONUtil.toJsonStr(list));
|
||||
// 如果费用标准列表不为空,说明找到了相关的费用标准
|
||||
if (!list.isEmpty()) {
|
||||
// 获取第一个费用标准
|
||||
|
||||
@ -32,4 +32,21 @@
|
||||
standard_id = #{id}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="existsData" parameterType="map" resultType="boolean">
|
||||
SELECT COUNT(a.pk_id) > 0 FROM yt_t_battery_station_hd_fee_standard_detail a
|
||||
WHERE a.standard_id = #{standardId}
|
||||
and (
|
||||
(DATE_FORMAT(a.time_begin,'%H:%i:%s') <=DATE_FORMAT(STR_TO_DATE(#{begin},'%H:%i:%s'),'%H:%i:%s') and DATE_FORMAT(a.time_end,'%H:%i:%s') >= DATE_FORMAT(STR_TO_DATE(#{begin},'%H:%i:%s'),'%H:%i:%s'))
|
||||
or
|
||||
(DATE_FORMAT(a.time_begin,'%H:%i:%s') <=DATE_FORMAT(STR_TO_DATE(#{end},'%H:%i:%s'),'%H:%i:%s') and DATE_FORMAT(a.time_end,'%H:%i:%s') >= DATE_FORMAT(STR_TO_DATE(#{end},'%H:%i:%s'),'%H:%i:%s'))
|
||||
or
|
||||
(DATE_FORMAT(a.time_begin,'%H:%i:%s') >=DATE_FORMAT(STR_TO_DATE(#{begin},'%H:%i:%s'),'%H:%i:%s') and DATE_FORMAT(a.time_end,'%H:%i:%s') <= DATE_FORMAT(STR_TO_DATE(#{end},'%H:%i:%s'),'%H:%i:%s'))
|
||||
)
|
||||
<if test="pkId!= null">
|
||||
and a.pk_id !=#{pkId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@ -40,12 +40,51 @@
|
||||
where
|
||||
a.station_code = #{stationCode}
|
||||
<if test="day!= null and day != '' ">
|
||||
and DATE_FORMAT(a.day_begin,'%Y-%m-%d') <=DATE_FORMAT(#{day},'%Y-%m-%d')
|
||||
</if>
|
||||
<if test="day!= null and day != '' ">
|
||||
and DATE_FORMAT(a.day_end,'%Y-%m-%d') >= DATE_FORMAT(#{day},'%Y-%m-%d')
|
||||
and DATE_FORMAT(a.day_begin,'%m-%d') <=DATE_FORMAT(#{day},'%m-%d')
|
||||
and DATE_FORMAT(a.day_end,'%m-%d') >= DATE_FORMAT(#{day},'%m-%d')
|
||||
</if>
|
||||
order by a.pk_id desc
|
||||
</select>
|
||||
</select>
|
||||
|
||||
<select id="orderCreateBeforeFeeEndStandard" resultMap="BaseResultMap">
|
||||
select
|
||||
a.*
|
||||
From
|
||||
yt_t_battery_station_hd_fee_standard a
|
||||
where
|
||||
a.station_code = #{stationCode}
|
||||
and DATE_FORMAT(a.day_end,'%m-%d') <= DATE_FORMAT(#{day},'%m-%d')
|
||||
order by a.day_end desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="orderCreateAfterFeeBeginStandard" resultMap="BaseResultMap">
|
||||
select
|
||||
a.*
|
||||
From
|
||||
yt_t_battery_station_hd_fee_standard a
|
||||
where
|
||||
a.station_code = #{stationCode}
|
||||
and DATE_FORMAT(a.day_begin,'%m-%d') >=DATE_FORMAT(#{day},'%m-%d')
|
||||
order by a.day_begin asc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<select id="existsData" parameterType="map" resultType="boolean">
|
||||
SELECT COUNT(a.pk_id) > 0 FROM yt_t_battery_station_hd_fee_standard a
|
||||
WHERE a.station_code = #{stationCode}
|
||||
and (
|
||||
(DATE_FORMAT(a.day_begin,'%m-%d') <=DATE_FORMAT(#{begin},'%m-%d') and DATE_FORMAT(a.day_end,'%m-%d') >= DATE_FORMAT(#{begin},'%m-%d'))
|
||||
or
|
||||
(DATE_FORMAT(a.day_begin,'%m-%d') <=DATE_FORMAT(#{end},'%m-%d') and DATE_FORMAT(a.day_end,'%m-%d') >= DATE_FORMAT(#{end},'%m-%d'))
|
||||
or
|
||||
(DATE_FORMAT(a.day_begin,'%m-%d') >=DATE_FORMAT(#{begin},'%m-%d') and DATE_FORMAT(a.day_end,'%m-%d') <= DATE_FORMAT(#{end},'%m-%d'))
|
||||
)
|
||||
<if test="pkId!= null">
|
||||
and a.pk_id !=#{pkId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user