2024年6月11日 新增出行配置

This commit is contained in:
bai 2024-06-11 09:06:31 +08:00
parent 4e0dcc087f
commit 53a236ab8f
12 changed files with 978 additions and 3 deletions

View File

@ -3,12 +3,16 @@ package com.sqx.modules.common.controller;
import com.sqx.common.utils.Result;
import com.sqx.modules.common.entity.ArtificerPartitioningDetails;
import com.sqx.modules.common.entity.CommonInfo;
import com.sqx.modules.common.enums.CommonEnum;
import com.sqx.modules.common.service.CommonInfoService;
import com.sqx.modules.common.utils.CommonConfigUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@Api(value = "通用配置管理", tags = {"通用配置管理"})
@ -25,10 +29,9 @@ public class CommonController {
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
@ApiOperation("管理平台添加通用配置")
@ApiOperation("管理平台修改通用配置")
@ResponseBody
public Result addCommon(@RequestBody CommonInfo app) {
return commonService.update(app);
}
@ -86,5 +89,37 @@ public class CommonController {
return commonService.rulesUpd(artificerPartitioningDetails);
}
//默认空数据根据这个生成
@GetMapping("/getCommonEnum")
@ApiOperation("获取枚举")
public Result getCommonEnum() {
return Result.success().put("data", CommonConfigUtil.commonEnumToJson());
}
@GetMapping("/getCommonEnumByType")
@ApiOperation("获取枚举")
public Result getCommonEnumByType(@RequestParam(value = "type") Integer type) {
return Result.success().put("data", CommonConfigUtil.getCommonEnumByKeyToJson(type));
}
@GetMapping("/getV3OrderForm")
@ApiOperation("获取订单相关")
public Result getV3OrderForm() {
Result r = Result.success();
r.put("data", commonService.getV3OrderForm());
r.put("enumList", CommonConfigUtil.commonEnumToJson());
return r;
}
@RequestMapping(value = "/updateGroup", method = RequestMethod.POST)
@ApiOperation("管理平台修改通用配置(一组)")
@ResponseBody
public Result updateGroup(@RequestBody List<CommonInfo> infos) {
if(commonService.updateGroup(infos)){
return Result.success();
}
return Result.error();
}
}

View File

@ -0,0 +1,156 @@
package com.sqx.modules.common.enums;
import com.sqx.modules.common.utils.CommonConfigUtil;
import lombok.Getter;
@Getter
public enum CommonEnum {
NONE(null,null,null,null),
/**距离服务开始n个小时以上免费取消*/
V3_ORDER_FORM_CANCEL_NOT_START_01(436, "v3_order_form", "距离服务开始n个小时以上免费取消", "4"),
/**距离服务开始前取消n-n个小时内收取n元*/
V3_ORDER_FORM_CANCEL_NOT_START_02(437, "v3_order_form", "距离服务开始前取消n-n个小时内收取n元", "1.5,4,10"),
/**距离服务开始前取消少于n个小时内收取n元*/
V3_ORDER_FORM_CANCEL_NOT_START_03(438, "v3_order_form", "距离服务开始前取消少于n个小时内收取n元", "1.5,30"),
/**服务开始n分钟内取消订单扣项目费用n%车费全扣n%*/
V3_ORDER_FORM_CANCEL_START_01(439, "v3_order_form", "服务开始n分钟内取消订单扣项目费用n%车费全扣n%", "15,50,100"),
/**服务开始n分钟后不可以取消订单*/
V3_ORDER_FORM_CANCEL_START_02(440, "v3_order_form", "服务开始n分钟后不可以取消订单", "15"),
/**距离服务开始前n个小时可修改*/
V3_ORDER_FORM_EDIT_NOT_START_01(441, "v3_order_form", "距离服务开始前n个小时可修改", "2"),
/**距离服务开始n个小时内不可修改*/
V3_ORDER_FORM_EDIT_NOT_START_02(442, "v3_order_form", "距离服务开始n个小时内不可修改", "2"),
/**夏令时开始时间~结束时间*/
V3_TRAVEL_CONF_DAYLIGHT_SAVING_TIME(443, "v3_travel_conf", "夏令时开始时间~结束时间", "0521,0823"),
/**冬令时开始时间~结束时间(留空自动计算)*/
V3_TRAVEL_CONF_WINTER_TIME(444, "v3_travel_conf", "冬令时开始时间~结束时间(留空自动计算)", ","),
/**白天时段从n开始~n结束*/
V3_TRAVEL_CONF_DAY(445, "v3_travel_conf", "白天时段从n开始~n结束", "2"),
/**夜间时段从n开始~n结束(留空自动计算)*/
V3_TRAVEL_CONF_NIGHT(446, "v3_travel_conf", "夜间时段从n开始~n结束(留空自动计算)", ",");
private final Integer key;
private final String defCondition;
private final String defName;
private final String defValue;
CommonEnum(Integer key, String defCondition, String defName, String defValue) {
this.key = key;
this.defCondition = defCondition;
this.defName = defName;
this.defValue = defValue;
}
private boolean defValueIsEmpty() {
return CommonConfigUtil.defValueIsEmpty(this.defValue);
}
public Integer getIntValue() {
return CommonConfigUtil.getIntValue(this.defValue);
}
public Long getLongValue() {
return CommonConfigUtil.getLongValue(this.defValue);
}
public Double getDoubleValue() {
return CommonConfigUtil.getDoubleValue(this.defValue);
}
/**
* 获取数组默认按,分隔
* @return 数组
*/
public String[] getArrayValue() {
return CommonConfigUtil.getArrayValue(this.defValue);
}
/**
* 获取数组默认按,分隔
* @param splitStr 自定义分隔符
* @return 数组
*/
public String[] getArrayValue(String splitStr) {
return CommonConfigUtil.getArrayValue(this.defValue, splitStr);
}
@Getter
public enum GroupKeyEnum {
/**
* v3服务订单相关
*/
V3_ORDER_FORM(new Integer[]{
V3_ORDER_FORM_CANCEL_NOT_START_01.getKey(),
V3_ORDER_FORM_CANCEL_NOT_START_02.getKey(),
V3_ORDER_FORM_CANCEL_NOT_START_03.getKey(),
V3_ORDER_FORM_CANCEL_START_01.getKey(),
V3_ORDER_FORM_CANCEL_START_02.getKey(),
V3_ORDER_FORM_EDIT_NOT_START_01.getKey(),
V3_ORDER_FORM_EDIT_NOT_START_02.getKey()
}),
/**
* v3服务订单开始前取消
*/
V3_ORDER_FORM_CANCEL_NOT_START(new Integer[]{
V3_ORDER_FORM_CANCEL_NOT_START_01.getKey(),
V3_ORDER_FORM_CANCEL_NOT_START_02.getKey(),
V3_ORDER_FORM_CANCEL_NOT_START_03.getKey(),
}),
/**
* v3服务订单开始后取消
*/
V3_ORDER_FORM_CANCEL_START(new Integer[]{
V3_ORDER_FORM_CANCEL_START_01.getKey(),
V3_ORDER_FORM_CANCEL_START_02.getKey(),
}),
/**
* 服务开始前修改
*/
V3_ORDER_FORM_EDIT_NOT_START(new Integer[]{
V3_ORDER_FORM_EDIT_NOT_START_01.getKey(),
V3_ORDER_FORM_EDIT_NOT_START_02.getKey()
}),
/**
* 时令和白天黑夜配置
*/
V3_TRAVEL_CONF(new Integer[]{
V3_TRAVEL_CONF_DAYLIGHT_SAVING_TIME.getKey(),
V3_TRAVEL_CONF_WINTER_TIME.getKey(),
V3_TRAVEL_CONF_DAY.getKey(),
V3_TRAVEL_CONF_NIGHT.getKey()
});
private final Integer[] values;
GroupKeyEnum(Integer[] values) {
this.values = values;
}
}
@Getter
public enum GroupConditionEnum {
V3_ORDER_FORM("v3_order_form"),
V3_TRAVEL_CONF("v3_travel_conf");
private String value;
GroupConditionEnum(String value){
this.value = value;
}
}
}

View File

@ -3,6 +3,10 @@ package com.sqx.modules.common.service;
import com.sqx.common.utils.Result;
import com.sqx.modules.common.entity.ArtificerPartitioningDetails;
import com.sqx.modules.common.entity.CommonInfo;
import com.sqx.modules.common.enums.CommonEnum;
import java.util.List;
import java.util.Map;
/**
* @author fang
@ -47,4 +51,45 @@ public interface CommonInfoService {
Result rules(String type);
Result rulesUpd(ArtificerPartitioningDetails artificerPartitioningDetails);
/**
* 按枚举查询
* @param commonEnum
* @return
*/
CommonInfo findOneByEnum(CommonEnum commonEnum);
/**
* 根据类型查询一组配置
* @param condition
* @return
*/
List<CommonInfo> getListByCondition(String condition);
/**
* 根据类型查询一组配置
* @param condition
* @return
*/
List<CommonInfo> getListByConditionLike(String condition);
List<CommonInfo> getListByTypes(Integer[] values);
boolean updateGroup(List<CommonInfo> infos);
/**
* 是否可以修改订单
* @return
*/
boolean isCheckChangeOrder();
/**
* 是否可以编辑订单
* @return
*/
boolean isCheckEditOrder();
List<CommonInfo> getV3OrderForm();
Map<Integer, CommonInfo> getMaoByCondition(String condition);
}

View File

@ -1,19 +1,25 @@
package com.sqx.modules.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.sqx.common.utils.Result;
import com.sqx.modules.artificer.dao.UserRechargeDao;
import com.sqx.modules.common.dao.ArtificerPartitioningDetailsMapper;
import com.sqx.modules.common.dao.CommonInfoDao;
import com.sqx.modules.common.entity.ArtificerPartitioningDetails;
import com.sqx.modules.common.entity.CommonInfo;
import com.sqx.modules.common.enums.CommonEnum;
import com.sqx.modules.common.service.CommonInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author fang
@ -69,7 +75,7 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
@Override
public Result findByTypeAndCondition(String condition) {
return Result.success().put("data",commonInfoDao.findByCondition(condition));
return Result.success().put("data", getListByCondition(condition));
}
@Override
@ -84,4 +90,63 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
return Result.success();
}
@Override
public CommonInfo findOneByEnum(CommonEnum commonEnum) {
return findOne(commonEnum.getKey());
}
@Override
public List<CommonInfo> getListByCondition(String condition) {
return commonInfoDao.findByCondition(condition);
}
@Override
public List<CommonInfo> getListByConditionLike(String condition) {
QueryWrapper<CommonInfo> qw = new QueryWrapper<>();
qw.lambda().like(CommonInfo::getConditionFrom,condition);
return list(qw);
}
@Override
public List<CommonInfo> getListByTypes(Integer[] values) {
QueryWrapper<CommonInfo> qw = new QueryWrapper<>();
qw.lambda().in(CommonInfo::getType,values);
return list(qw);
}
@Override
@Transactional(rollbackFor = {java.lang.Exception.class})
public boolean updateGroup(List<CommonInfo> infos) {
if(infos != null && !infos.isEmpty()){
//保证有初始数据这里不做新增
return updateBatchById(infos);
}
return false;
}
@Override
public List<CommonInfo> getV3OrderForm() {
return getListByTypes(CommonEnum.GroupKeyEnum.V3_ORDER_FORM.getValues());
}
@Override
public Map<Integer, CommonInfo> getMaoByCondition(String condition) {
List<CommonInfo> commonInfoList = commonInfoDao.findByCondition(condition);
Map<Integer, CommonInfo> commonInfoMap = Maps.newHashMap();
commonInfoList.forEach(x -> commonInfoMap.put(x.getType(), x));
return commonInfoMap;
}
@Override
public boolean isCheckChangeOrder() {
return false;
}
@Override
public boolean isCheckEditOrder() {
return false;
}
}

View File

@ -0,0 +1,191 @@
package com.sqx.modules.common.utils;
import cn.hutool.core.date.*;
import com.google.gson.Gson;
import com.sqx.modules.common.enums.CommonEnum;
import org.apache.commons.lang3.StringUtils;
import java.util.Date;
/**
* @ClassName CommonConfigUtil
* @Description TODO
* @Author bai
* @Date 2024/6/6 22:32
* @Version 1.0
**/
public class CommonConfigUtil {
/**
* 判定空
* @param value 判断的值
* @return 是否是空
*/
public static boolean defValueIsEmpty(String value) {
return StringUtils.isNotBlank(value);
}
/**
* 转为Long类型
* @param value 转换的值
* @return 转换后的值
*/
public static Integer getIntValue(String value) {
if(defValueIsEmpty(value)) return null;
return Integer.valueOf(value);
}
/**
* 转为Long类型
* @param value 转换的值
* @return 转换后的值
*/
public static Long getLongValue(String value) {
if(defValueIsEmpty(value)) return null;
return Long.valueOf(value);
}
/**
* 转为Double类型
* @param value 转换的值
* @return 转换后的值
*/
public static Double getDoubleValue(String value) {
if(defValueIsEmpty(value)) return null;
return Double.valueOf(value);
}
/**
* 获取数组默认按,分隔
* @param value 转换的值
* @return 数组
*/
public static String[] getArrayValue(String value) {
return getArrayValue(value, ",");
}
/**
* 获取数组按指定分隔符分隔
* @param value 转换的值
* @param splitStr 自定义分隔符
* @return 数组
*/
public static String[] getArrayValue(String value, String splitStr) {
if(defValueIsEmpty(value)) return new String[0];
return StringUtils.split(value, splitStr);
}
public static CommonEnum getCommonEnumByKey(Integer key) {
if(key == null) return CommonEnum.NONE;
CommonEnum enumData = null;
for (CommonEnum enumd : CommonEnum.values()) {
if(enumd.getKey().equals(key)){
enumData = enumd;
}
}
if(enumData != null){
return enumData;
} else {
return CommonEnum.NONE;
}
}
public static String getCommonEnumByKeyToJson(Integer key) {
return objectToJson(getCommonEnumByKey(key));
}
public static String objectToJson(Object o) {
return new Gson().toJson(o);
}
public static String commonEnumToJson() {
return objectToJson(CommonEnum.values());
}
//将时间或日期按格式转成正常的时间对象
public static DateTime changeMiniDateTimeToDate(String miniTime, String format) {
return new DateTime(miniTime, format);
}
//校准日期(日期)
public static DateTime changeMiniDateCheck(Date businessTime, String miniDate) {
int year = DateUtil.year(businessTime);
return changeMiniDateTimeToDate(year + miniDate, "yyyyMMdd");
}
//校准日期时间
public static DateTime changeMiniTimeCheck(Date businessTime, String miniTime) {
String now = DateUtil.format(businessTime, DatePattern.NORM_DATE_PATTERN);
return changeMiniDateTimeToDate(now + miniTime, DatePattern.NORM_DATE_PATTERN + "HHmmss");
}
public static boolean calcIsDateSlotCentre(Date businessTime, String startDateStr, String endDateStr) {
return calcIsDateSlotCentre(businessTime, startDateStr, endDateStr, true, true);
}
/**
* 计算时间是否在时间段中间
* @param businessTime 需要计算的时间
* @param isCriticalValueStart
* @param isCriticalValueEnd
* @return
*/
public static boolean calcIsDateSlotCentre(Date businessTime, String startDateStr, String endDateStr, boolean isCriticalValueStart, boolean isCriticalValueEnd) {
DateTime startDate = changeMiniDateCheck(businessTime, startDateStr);
DateTime endDate = changeMiniDateCheck(businessTime, endDateStr);
boolean isStartTrue = false;
boolean isEndTrue = false;
long s_b = DateUtil.between(startDate, businessTime, DateUnit.DAY, false);
long b_e = DateUtil.between(businessTime, endDate, DateUnit.DAY, false);
if(isCriticalValueStart){
//是临界
if(s_b >= 0 ) isStartTrue = true;
} else {
if(s_b > 0 ) isStartTrue = true;
}
if(isCriticalValueEnd){
//是临界
if(b_e >= 0 ) isEndTrue = true;
} else {
if(b_e > 0 ) isEndTrue = true;
}
return isStartTrue && isEndTrue;
}
public static boolean calcIsTimeSlotCentre(Date businessTime, String startTimeStr, String endTimeStr) {
return calcIsTimeSlotCentre(businessTime, startTimeStr, endTimeStr, true, true);
}
public static boolean calcIsTimeSlotCentre(Date businessTime, String startTimeStr, String endTimeStr, boolean isCriticalValueStart, boolean isCriticalValueEnd) {
DateTime startTime = changeMiniTimeCheck(businessTime, startTimeStr);
DateTime endTime = changeMiniTimeCheck(businessTime, endTimeStr);
boolean isStartTrue = false;
boolean isEndTrue = false;
long s_b = DateUtil.between(startTime, businessTime, DateUnit.SECOND, false);
long b_e = DateUtil.between(businessTime, endTime, DateUnit.SECOND, false);
if(isCriticalValueStart){
//是临界
if(s_b >= 0 ) isStartTrue = true;
} else {
if(s_b > 0 ) isStartTrue = true;
}
if(isCriticalValueEnd){
//是临界
if(b_e >= 0 ) isEndTrue = true;
} else {
if(b_e > 0 ) isEndTrue = true;
}
return isStartTrue && isEndTrue;
}
}

View File

@ -0,0 +1,90 @@
package com.sqx.modules.travelconf.controller;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.common.utils.Result;
import com.sqx.modules.travelconf.entity.TravelConf;
import com.sqx.modules.travelconf.service.TravelConfService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
/**
* @author bai
* @date 2024/06/08
*/
@RestController
@Api(value = "出行管理", tags = { "出行管理" })
@RequestMapping(value = "/travelConf")
public class TravelConfController {
@Autowired
private TravelConfService service;
@GetMapping("/list")
@ApiOperation("获取数据列表")
public Result list(TravelConf entity, Integer page,Integer limit){
QueryWrapper<TravelConf> qw = new QueryWrapper<>();
if(entity != null) {
//价格类型
qw.lambda().eq(entity.getPricingType() != null, TravelConf::getPricingType, entity.getPricingType());
//出行方式
qw.lambda().eq(entity.getTravelType() != null, TravelConf::getTravelType, entity.getTravelType());
//时令
qw.lambda().eq(entity.getSeasonsType() != null, TravelConf::getSeasonsType, entity.getSeasonsType());
//时段
qw.lambda().eq(entity.getTimeIntervalType() != null, TravelConf::getTimeIntervalType, entity.getTimeIntervalType());
}
// qw.orderByAsc("sort");
IPage<TravelConf> pageList = service.page(new Page<>(page,limit),qw);
return Result.success().put("data",pageList);
}
@PostMapping(value = "/add")
@ApiOperation("新增")
public Result add(@RequestBody TravelConf entity){
entity.setCreateTime(DateUtil.now());
entity.setUpdateTime(DateUtil.now());
return Result.success().put("data",service.save(entity));
}
@PostMapping(value = "/update")
@ApiOperation("修改")
public Result update(@RequestBody TravelConf entity){
entity.setUpdateTime(DateUtil.now());
return Result.success().put("data",service.updateById(entity));
}
@RequestMapping("/info/{id}")
public Result info(@PathVariable("id") Long id){
TravelConf data = service.getById(id);
return Result.success().put("data", data);
}
@DeleteMapping(value = "/deleteById")
@ApiOperation("删除")
public Result deleteById(Long id){
service.removeById(id);
return Result.success();
}
@DeleteMapping(value = "/deleteByIds")
@ApiOperation("批量删除")
public Result deleteByIds(String id){
if(StringUtils.isNotBlank(id)){
String[] ids = StringUtils.split(id,",");
service.removeByIds(Arrays.asList(ids));
}
return Result.success();
}
}

View File

@ -0,0 +1,14 @@
package com.sqx.modules.travelconf.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sqx.modules.travelconf.entity.TravelConf;
import org.apache.ibatis.annotations.Mapper;
/**
* @author bai
* @date 2024/06/08
*/
@Mapper
public interface TravelConfDao extends BaseMapper<TravelConf> {
}

View File

@ -0,0 +1,94 @@
package com.sqx.modules.travelconf.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* @author bai
* @date 2024/06/08
*/
@Data
@TableName("v3_travel_conf")
public class TravelConf implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 创建时间
*/
private String createTime;
/**
* 修改时间
*/
private String updateTime;
/**
* 价格类型(1:固定价格,2:动态价格)
*/
private Integer pricingType;
/**
* 出行方式(1:免费,2:出租,3:公共交通)
*/
private Integer travelType;
/**
* 时令(1:夏令时,2:冬令时)
*/
private Integer seasonsType;
/**
* 时段(1:白天,2:夜间)
*/
private Integer timeIntervalType;
/**
* 起步价()
*/
private BigDecimal startingPrice;
/**
* 免费公里数()
*/
private BigDecimal freeKilometers;
/**
* 夜间出行费()
*/
private BigDecimal nightTravelExpenses;
/**
* 每公里价格()
*/
private BigDecimal pricePerKilometer;
/**
* 固定价格类型(1:往返,2:单程)
*/
private Integer fixedType;
/**
* 固定价格()
*/
private BigDecimal fixedPrice;
/**
* 备注
*/
private String remark;
}

View File

@ -0,0 +1,105 @@
package com.sqx.modules.travelconf.enums;
import com.sqx.modules.common.utils.CommonConfigUtil;
import com.sqx.modules.travelconf.entity.TravelConf;
import lombok.Getter;
public class TravelEnum {
/**
* 价格类型
*/
@Getter
public enum PricingType {
/***
* 固定价格
*/
FIXED(1),
/**
* 动态价格
*/
TRENDS(2);
private final Integer value;
PricingType(Integer value) {
this.value = value;
}
}
/**
* 出行方式
*/
@Getter
public enum TravelType {
/***
* 免费
*/
FREE(1),
/**
* 出租
*/
TAXI(2),
/**
* 公共交通
*/
MASS_TRANSIT(3);
private final Integer value;
TravelType(Integer value) {
this.value = value;
}
}
/**
* 时令
*/
@Getter
public enum SeasonsType {
/***
* 夏令时
*/
DAYLIGHT_SAVING_TIME(1),
/**
* 冬令时
*/
WINTER_TIME(2);
private final Integer value;
SeasonsType(Integer value) {
this.value = value;
}
}
/**
* 时段
*/
@Getter
public enum TimeIntervalType {
/***
* 白天
*/
DAY(1),
/**
* 夜间
*/
NIGHT(2);
private final Integer value;
TimeIntervalType(Integer value) {
this.value = value;
}
}
}

View File

@ -0,0 +1,30 @@
package com.sqx.modules.travelconf.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sqx.modules.travelconf.entity.TravelConf;
import java.util.Date;
public interface TravelConfService extends IService<TravelConf> {
/**
*
* @param pricingType 价格类型(1:固定价格,2:动态价格)
* @param travelType 出行方式(1:免费,2:出租,3:公共交通)
* @return
*/
TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Date businessTime);
/**
* 根据类型获取出行配置
* @param pricingType 价格类型(1:固定价格,2:动态价格)
* @param travelType 出行方式(1:免费,2:出租,3:公共交通)
* @param seasonsType 时令(1:夏令时,2:冬令时)
* @param timeIntervalType 时段(1:白天,2:夜间)
* @return 配置对象
*/
TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Integer seasonsType, Integer timeIntervalType);
}

View File

@ -0,0 +1,144 @@
package com.sqx.modules.travelconf.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.exception.SqxException;
import com.sqx.modules.common.entity.CommonInfo;
import com.sqx.modules.common.enums.CommonEnum;
import com.sqx.modules.common.service.CommonInfoService;
import com.sqx.modules.common.utils.CommonConfigUtil;
import com.sqx.modules.travelconf.dao.TravelConfDao;
import com.sqx.modules.travelconf.entity.TravelConf;
import com.sqx.modules.travelconf.enums.TravelEnum;
import com.sqx.modules.travelconf.service.TravelConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 消息
*/
@Service
public class TravelConfServiceImpl extends ServiceImpl<TravelConfDao, TravelConf> implements TravelConfService {
@Autowired
private CommonInfoService commonInfoService;
@Override
public TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Date businessTime) {
//为空则使用当前系统时间
if(businessTime == null) businessTime = DateUtil.date();
Integer seasonsType = null;
Integer timeIntervalType = null;
//从配置文件中取出时间配置(包含很多个)
Map<Integer,CommonInfo> commonInfoMap = commonInfoService.getMaoByCondition(CommonEnum.GroupConditionEnum.V3_TRAVEL_CONF.getValue());
//夏令时段
CommonInfo daylightSavingTime = commonInfoMap.get(CommonEnum.V3_TRAVEL_CONF_DAYLIGHT_SAVING_TIME.getKey());
//冬令时段
CommonInfo winterTime = commonInfoMap.get(CommonEnum.V3_TRAVEL_CONF_WINTER_TIME.getKey());
//白天时段
CommonInfo day = commonInfoMap.get(CommonEnum.V3_TRAVEL_CONF_DAY.getKey());
//夜间时段
CommonInfo night = commonInfoMap.get(CommonEnum.V3_TRAVEL_CONF_NIGHT.getKey());
if(daylightSavingTime == null || winterTime == null || day == null || night == null){
throw new SqxException("无法找到时令或白夜时段配置,请联系管理员!");
}
String daylightSavingTimeValue = daylightSavingTime.getValue();
String winterTimeValue = winterTime.getValue();
String dayValue = day.getValue();
String nightValue = night.getValue();
String[] daylightSavingTimeValues = CommonConfigUtil.getArrayValue(daylightSavingTimeValue);
//为空则自动
String[] winterTimeValues = CommonConfigUtil.getArrayValue(winterTimeValue);
String[] dayValues = CommonConfigUtil.getArrayValue(dayValue);
//为空则自动
String[] nightValues = CommonConfigUtil.getArrayValue(nightValue);
if(daylightSavingTimeValues.length != 2 || dayValues.length != 2){
throw new SqxException("无法找到时令或白夜时段配置,请联系管理员!");
}
if(winterTimeValues.length == 0){
//非夏令时就是冬令时
boolean isSeasonsType = CommonConfigUtil.calcIsDateSlotCentre(DateUtil.date(), daylightSavingTimeValues[0],daylightSavingTimeValues[1]);
if(isSeasonsType) {
//夏令时
seasonsType = TravelEnum.SeasonsType.DAYLIGHT_SAVING_TIME.getValue();
} else {
//冬令时
seasonsType = TravelEnum.SeasonsType.WINTER_TIME.getValue();
}
}else{
//双方混合判断
}
if(nightValues.length == 0){
//非白天就是夜间
boolean isTimeIntervalType = CommonConfigUtil.calcIsTimeSlotCentre(DateUtil.date(), dayValues[0],dayValues[1]);
if(isTimeIntervalType) {
//白天
timeIntervalType = TravelEnum.TimeIntervalType.DAY.getValue();
} else {
//夜间
timeIntervalType = TravelEnum.TimeIntervalType.NIGHT.getValue();
}
}else{
//双方混合判断
}
return getConfByAccordingCondition(pricingType, travelType, seasonsType, timeIntervalType);
}
public static void main(String[] args) {
DateTime dateTime = new DateTime("2017-01-05 12:34:23", "yyyy-MM-dd HH:mm:ss");
DateTime dateTime2 = new DateTime("0105", "MMdd");
DateTime dateTime3 = new DateTime("123423", "HHmmss");
String now = DateUtil.today();
System.out.println(now);
System.out.println(dateTime);
System.out.println(dateTime2);
System.out.println(dateTime3);
boolean oneRes = CommonConfigUtil.calcIsDateSlotCentre(DateUtil.date(), "0521","0823");
System.out.println(oneRes);
boolean oneRes2 = CommonConfigUtil.calcIsTimeSlotCentre(DateUtil.date(), "080000","172200");
System.out.println(oneRes2);
}
@Override
public TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Integer seasonsType, Integer timeIntervalType) {
QueryWrapper<TravelConf> qw = new QueryWrapper<>();
//价格类型
qw.lambda().eq(pricingType != null, TravelConf::getPricingType, pricingType);
//出行方式
qw.lambda().eq(travelType != null, TravelConf::getTravelType, travelType);
//时令
qw.lambda().eq(seasonsType != null, TravelConf::getSeasonsType, seasonsType);
//时段
qw.lambda().eq(timeIntervalType != null, TravelConf::getTimeIntervalType, timeIntervalType);
TravelConf conf = getOne(qw);
if(conf == null) {
throw new SqxException("无法找到出行配置,请联系管理员!");
}
return conf;
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sqx.modules.travelconf.dao.TravelConfDao">
</mapper>