|
@@ -1,15 +1,27 @@
|
|
|
package com.ylx.massage.service.impl;
|
|
package com.ylx.massage.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ylx.common.constant.MassageConstants;
|
|
import com.ylx.common.constant.MassageConstants;
|
|
|
|
|
+import com.ylx.common.core.domain.entity.SysDictData;
|
|
|
import com.ylx.common.exception.ServiceException;
|
|
import com.ylx.common.exception.ServiceException;
|
|
|
|
|
+import com.ylx.common.utils.StringUtils;
|
|
|
|
|
+import com.ylx.massage.domain.vo.TFareSettingVo;
|
|
|
import com.ylx.massage.mapper.TFareSettingMapper;
|
|
import com.ylx.massage.mapper.TFareSettingMapper;
|
|
|
import com.ylx.massage.domain.TFareSetting;
|
|
import com.ylx.massage.domain.TFareSetting;
|
|
|
|
|
+import com.ylx.system.service.ISysDictTypeService;
|
|
|
import io.jsonwebtoken.lang.Collections;
|
|
import io.jsonwebtoken.lang.Collections;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ylx.massage.service.TFareSettingService;
|
|
import com.ylx.massage.service.TFareSettingService;
|
|
|
|
|
|
|
|
|
|
+import java.time.LocalTime;
|
|
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
|
|
+import java.util.Calendar;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -19,9 +31,13 @@ import java.util.stream.Collectors;
|
|
|
* @author makejava
|
|
* @author makejava
|
|
|
* @since 2024-08-22 17:41:00
|
|
* @since 2024-08-22 17:41:00
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
@Service("tFareSettingService")
|
|
@Service("tFareSettingService")
|
|
|
public class TFareSettingServiceImpl extends ServiceImpl<TFareSettingMapper, TFareSetting> implements TFareSettingService {
|
|
public class TFareSettingServiceImpl extends ServiceImpl<TFareSettingMapper, TFareSetting> implements TFareSettingService {
|
|
|
|
|
+ private static final String DAY_TIME = "day_time";
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ISysDictTypeService dictTypeService;
|
|
|
@Override
|
|
@Override
|
|
|
public TFareSetting add(TFareSetting tFareSetting) {
|
|
public TFareSetting add(TFareSetting tFareSetting) {
|
|
|
//判断部门重复设置
|
|
//判断部门重复设置
|
|
@@ -57,21 +73,72 @@ public class TFareSettingServiceImpl extends ServiceImpl<TFareSettingMapper, TFa
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * C端根据城市编码获取车费起步价配置
|
|
|
|
|
|
|
+ * C端根据城市编码和用户预约时间获取车费起步价配置
|
|
|
* @param cityCode
|
|
* @param cityCode
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public TFareSetting getFareSetting(String cityCode) {
|
|
|
|
|
- if (cityCode == null || cityCode.trim().isEmpty()) {
|
|
|
|
|
|
|
+ public TFareSettingVo getFareSetting(String userbookingTime, String cityCode) {
|
|
|
|
|
+ // 参数校验
|
|
|
|
|
+ if (StringUtils.isBlank(userbookingTime) || StringUtils.isBlank(cityCode)) {
|
|
|
|
|
+ throw new IllegalArgumentException("预约时间和城市编码不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询最新的有效配置
|
|
|
|
|
+ TFareSetting setting = getLatestValidFareSetting(cityCode);
|
|
|
|
|
+ if (setting == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 解析预约时间
|
|
|
|
|
+ Date bookingDate;
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 假设格式为 yyyy-MM-dd HH:mm:ss,可根据实际调整
|
|
|
|
|
+ bookingDate = DateUtil.parse(userbookingTime, "yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new IllegalArgumentException("预约时间格式错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+ cal.setTime(bookingDate);
|
|
|
|
|
+ LocalTime bookingTime = LocalTime.of(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
|
|
|
|
|
+ // 定义白天时间段(比如 6:00 - 22:00),读取字典表配置
|
|
|
|
|
+ List<SysDictData> dataDayTimes = dictTypeService.selectDictDataByType(DAY_TIME);
|
|
|
|
|
+ if (dataDayTimes == null || dataDayTimes.size() < 2) {
|
|
|
|
|
+ throw new IllegalStateException("白天时段字典配置缺失,请检查 dat_time 类型");
|
|
|
|
|
+ }
|
|
|
|
|
+ LocalTime dayStart, dayEnd;
|
|
|
|
|
+ try {
|
|
|
|
|
+ dayStart = LocalTime.parse(dataDayTimes.get(0).getDictValue());
|
|
|
|
|
+ dayEnd = LocalTime.parse(dataDayTimes.get(1).getDictValue());
|
|
|
|
|
+ } catch (DateTimeParseException e) {
|
|
|
|
|
+ throw new IllegalArgumentException("白天时段配置格式错误,应为 HH:mm");
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean isDaytime = !bookingTime.isBefore(dayStart) && !bookingTime.isAfter(dayEnd);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ TFareSettingVo vo = new TFareSettingVo();
|
|
|
|
|
+ if (isDaytime) {
|
|
|
|
|
+ vo.setBaseFare(setting.getDaytimeBaseFare());
|
|
|
|
|
+ vo.setBaseDistance(setting.getDaytimeBaseDistance());
|
|
|
|
|
+ vo.setAdditionalFarePer(setting.getDaytimeAdditionalFarePer());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ vo.setBaseFare(setting.getNightBaseFare());
|
|
|
|
|
+ vo.setBaseDistance(setting.getNightBaseDistance());
|
|
|
|
|
+ vo.setAdditionalFarePer(setting.getNightAdditionalFarePer());
|
|
|
|
|
+ }
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据城市编码获取最新的有效车费配置
|
|
|
|
|
+ */
|
|
|
|
|
+ private TFareSetting getLatestValidFareSetting(String cityCode) {
|
|
|
LambdaQueryWrapper<TFareSetting> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<TFareSetting> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(TFareSetting::getCityCode, cityCode)
|
|
wrapper.eq(TFareSetting::getCityCode, cityCode)
|
|
|
|
|
+ .eq(TFareSetting::getEnable, 1)
|
|
|
|
|
+ .eq(TFareSetting::getIsDelete, 0)
|
|
|
.orderByDesc(TFareSetting::getCreateTime)
|
|
.orderByDesc(TFareSetting::getCreateTime)
|
|
|
.last("LIMIT 1");
|
|
.last("LIMIT 1");
|
|
|
-
|
|
|
|
|
return this.getOne(wrapper);
|
|
return this.getOne(wrapper);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|