Merge branch 'master' of http://47.115.223.229:8888/yangjun/sadjv3_java
This commit is contained in:
commit
06ba5081fa
|
@ -0,0 +1,54 @@
|
|||
package com.sqx.common.utils;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.apache.http.HttpStatus;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 返回数据-泛型版
|
||||
*
|
||||
*/
|
||||
@ApiModel("统一返回值")
|
||||
@Data
|
||||
public class Result2<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "状态码,0为正常,500为异常", example = "0")
|
||||
private int code = 0;
|
||||
|
||||
@ApiModelProperty(value = "消息", example = "保存成功!")
|
||||
private String msg;
|
||||
|
||||
@ApiModelProperty(value = "返回对象")
|
||||
private T data;
|
||||
|
||||
public Result2<T> error() {
|
||||
return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常,请联系管理员");
|
||||
}
|
||||
|
||||
public Result2<T> error(String msg) {
|
||||
return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
|
||||
}
|
||||
|
||||
public Result2<T> error(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Result2<T> success(String msg) {
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Result2<T> success() {
|
||||
return new Result2<>();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package com.sqx.common.utils.baidu;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.setting.dialect.Props;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName BaiduCommon
|
||||
* @Description TODO
|
||||
* @Author bai
|
||||
* @Date 2024/6/17 下午8:22
|
||||
* @Version 1.0
|
||||
**/
|
||||
public class BaiduCommon {
|
||||
|
||||
//接口版本
|
||||
public static final String VERSION = "1";
|
||||
|
||||
//接口前缀
|
||||
public static final String BASE_PREFIX_PATH = "https://pns.baidubce.com/cloud/api/v";
|
||||
|
||||
//接口前缀
|
||||
|
||||
//拼接后的完整接口前缀
|
||||
public static final String BASE_PATH = BASE_PREFIX_PATH + VERSION;
|
||||
|
||||
//绑定
|
||||
public static final String API_AXB_BINDING = BASE_PATH + "/axb/binding";
|
||||
|
||||
//解绑
|
||||
public static final String API_AXB_UNBINDING = BASE_PATH + "/axb/unbinding";
|
||||
|
||||
//转绑
|
||||
public static final String API_AXB_CHANGE_BINDING = BASE_PATH + "/axb/changeBinding";
|
||||
|
||||
public static String genSigned(){
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getUTCDate(){
|
||||
DateTime now = DateTime.now();
|
||||
return DateUtil.format(now, DatePattern.UTC_PATTERN);
|
||||
}
|
||||
|
||||
//发出请求
|
||||
public static String baseSendHttp(String url, Map<String, String> headerMap, String json) {
|
||||
return HttpRequest
|
||||
.post(url)
|
||||
.headerMap(headerMap, true)
|
||||
//.form(paramMap)
|
||||
.body(json)
|
||||
.execute()
|
||||
.body();
|
||||
}
|
||||
|
||||
public static Map<String, String> getBaseHeaderMap(){
|
||||
Map<String, String> baseHeaderMap = Maps.newHashMap();
|
||||
baseHeaderMap.put("Authorization","bce-auth-v{1}/{accessKeyId}/{timestamp}/{expirationPeriodInSeconds}/{signedHeaders}/{signature}");
|
||||
|
||||
// version是正整数。
|
||||
// timestamp是生成签名时的UTC时间。
|
||||
// expirationPeriodInSeconds表示签名有效期限。
|
||||
// signedHeaders是签名算法中涉及到的头域列表。头域名之间用分号(;)分隔,如host;x-bce-date。列表按照字典序排列。(本API签名仅使用host和x-bce-date两个header)
|
||||
// signature是256位签名的十六进制表示,由64个小写字母组成。
|
||||
|
||||
baseHeaderMap.put("Content-Type","application/json; charset=utf-8");
|
||||
baseHeaderMap.put("x-bce-date", getUTCDate());//2019-10-30T10:55:26Z
|
||||
return baseHeaderMap;
|
||||
}
|
||||
|
||||
public static JSON sendHttpToJson(String url, Map<String, Object> paramMap){
|
||||
//
|
||||
Props props = new Props("test.properties");
|
||||
props.getStr("1111");
|
||||
return JSONUtil.parse(baseSendHttp(url, getBaseHeaderMap(), JSONUtil.toJsonStr(paramMap)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -84,6 +84,7 @@ public class CommonMapUtils {
|
|||
if ("0".equals(status)) {
|
||||
result = jsonObject.getJSONObject("result");
|
||||
} else {
|
||||
log.error("返回值:{}",jsonObject.toJSONString());
|
||||
log.error("转换失败!!!原因:" + jsonObject.getString("message"));
|
||||
}
|
||||
break;
|
||||
|
@ -100,6 +101,7 @@ public class CommonMapUtils {
|
|||
if ("1".equals(status)) {
|
||||
result = jsonObject.getJSONObject("regeocode");
|
||||
}else {
|
||||
log.error("返回值:{}",jsonObject.toJSONString());
|
||||
log.error("转换失败!!!原因:" + jsonObject.getString("info"));
|
||||
}
|
||||
break;
|
||||
|
@ -120,8 +122,10 @@ public class CommonMapUtils {
|
|||
String status = jsonObject.getString("status");
|
||||
if("0".equals(status)){
|
||||
result = jsonObject.getJSONObject("result");
|
||||
}else {
|
||||
log.error("返回值:{}",jsonObject.toJSONString());
|
||||
log.error("转换失败!!!原因:" + jsonObject.getString("msg"));
|
||||
}
|
||||
log.error("转换失败!!!原因:" + jsonObject.getString("msg"));
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
|
@ -131,8 +135,8 @@ public class CommonMapUtils {
|
|||
|
||||
/**
|
||||
* 根据经纬度获取实际地址
|
||||
* @param longitude 经度 116.307490
|
||||
* @param latitude 纬度 39.984154
|
||||
* @param longitude 经度 125.294234
|
||||
* @param latitude 纬度 43.887282
|
||||
* @return 经纬度所对应的文字地址 如【北京市东城区东华门街道天安门-城楼】以行政区划+道路+门牌号等信息组成的标准格式化地址
|
||||
*/
|
||||
public static String getLocationToAddress(String longitude, String latitude){
|
||||
|
@ -159,8 +163,8 @@ public class CommonMapUtils {
|
|||
|
||||
/**
|
||||
* 按坐标获取行政区划信息
|
||||
* @param longitude 经度 116.307490
|
||||
* @param latitude 纬度 39.984154
|
||||
* @param longitude 经度 125.294234
|
||||
* @param latitude 纬度 43.887282
|
||||
* @return province:省/直辖市,city:市/地级区 及同级行政区划,如果当前城市为省直辖县级区划,city与district字段均会返回此城市,district:区/县级市 及同级行政区划,address:经纬度所对应的文字地址 如【北京市东城区东华门街道天安门-城楼】以行政区划+道路+门牌号等信息组成的标准格式化地址
|
||||
*/
|
||||
|
||||
|
@ -215,11 +219,11 @@ public class CommonMapUtils {
|
|||
/**
|
||||
* 根据开始位置和结束位置根据出行方式获取米
|
||||
* @param mapType
|
||||
* @param tripWay
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param toLongitude
|
||||
* @param toLatitude
|
||||
* @param tripWay (2:驾车/出租,其他值:公交)
|
||||
* @param longitude 经度 125.294234
|
||||
* @param latitude 纬度 43.887282
|
||||
* @param toLongitude 经度 125.294234
|
||||
* @param toLatitude 纬度 43.887282
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject calcTaxiMoney(MapEnum mapType,Integer tripWay, String longitude, String latitude, String toLongitude, String toLatitude, String city, String cityCode){
|
||||
|
@ -246,6 +250,7 @@ public class CommonMapUtils {
|
|||
if ("0".equals(status)) {
|
||||
result = jsonObject.getJSONObject("result");
|
||||
} else {
|
||||
log.error("返回值:{}",jsonObject.toJSONString());
|
||||
log.error("{}路线计算失败: {}",tripWay == 1?"公交":"驾车" , jsonObject.getString("message"));
|
||||
}
|
||||
break;
|
||||
|
@ -273,6 +278,7 @@ public class CommonMapUtils {
|
|||
if ("1".equals(status)) {
|
||||
result = jsonObject.getJSONObject("route");
|
||||
}else {
|
||||
log.error("返回值:{}",jsonObject.toJSONString());
|
||||
log.error("{}路线计算失败: {}",tripWay == 1?"公交":"驾车" , jsonObject.getString("message"));
|
||||
}
|
||||
break;
|
||||
|
@ -287,11 +293,11 @@ public class CommonMapUtils {
|
|||
|
||||
/**
|
||||
* 根据开始位置和结束位置根据出行方式获取米
|
||||
* @param tripWay
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param toLongitude
|
||||
* @param toLatitude
|
||||
* @param tripWay (2:驾车/出租,其他值:公交)
|
||||
* @param longitude 经度 125.294234
|
||||
* @param latitude 纬度 43.887282
|
||||
* @param toLongitude 经度 125.294234
|
||||
* @param toLatitude 纬度 43.887282
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject calcTaxiMoneyInfo(Integer tripWay, String longitude, String latitude, String toLongitude, String toLatitude, String city, String cityCode){
|
||||
|
@ -348,5 +354,22 @@ public class CommonMapUtils {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询距离 (米)
|
||||
* @param tripWay (2:驾车/出租,其他值:公交)
|
||||
* @param longitude 经度 125.294234
|
||||
* @param latitude 纬度 43.887282
|
||||
* @param toLongitude 经度 43.887282
|
||||
* @param toLatitude 纬度 43.887282
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject calcTaxiMoneyInfo(Integer tripWay, String longitude, String latitude, String toLongitude, String toLatitude) {
|
||||
JSONObject mapAdRes = CommonMapUtils.getLocationToAdInfo(longitude, latitude);
|
||||
String cityName = mapAdRes.getString("city");
|
||||
String cityCode = mapAdRes.getString("adcode");
|
||||
return calcTaxiMoneyInfo(tripWay, longitude, latitude, toLongitude, toLatitude, cityName, cityCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -166,10 +166,7 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
|||
}
|
||||
|
||||
//获取城市名称
|
||||
JSONObject mapAdRes = CommonMapUtils.getLocationToAdInfo(longitude, latitude);
|
||||
String cityName = mapAdRes.getString("city");
|
||||
String cityCode = mapAdRes.getString("adcode");
|
||||
JSONObject mapRes = CommonMapUtils.calcTaxiMoneyInfo(artificer.getTripWay(), longitude, latitude, artificer.getLongitude(), artificer.getLatitude(), cityName, cityCode);//根据出行方式计算距离
|
||||
JSONObject mapRes = CommonMapUtils.calcTaxiMoneyInfo(artificer.getTripWay(), longitude, latitude, artificer.getLongitude(), artificer.getLatitude());//根据出行方式计算距离
|
||||
|
||||
//判断技师的出行方式
|
||||
if (artificer.getTripWay() == null || artificer.getTripWay() == 1) {
|
||||
|
|
|
@ -2,8 +2,10 @@ package com.sqx.modules.common.enums;
|
|||
|
||||
import com.sqx.modules.common.utils.CommonConfigUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum CommonEnum {
|
||||
|
||||
NONE(null,null,null,null),
|
||||
|
@ -32,7 +34,9 @@ public enum CommonEnum {
|
|||
/**白天时段从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结束(留空自动计算)", ",");
|
||||
V3_TRAVEL_CONF_NIGHT(446, "v3_travel_conf", "夜间时段从n开始~n结束(留空自动计算)", ","),
|
||||
|
||||
V3_TRAVEL_CONF_IS_FIXED(447, "v3_travel_conf", "出行配置使用动态价格", "true");
|
||||
|
||||
private final Integer key;
|
||||
|
||||
|
@ -42,13 +46,6 @@ public enum CommonEnum {
|
|||
|
||||
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);
|
||||
// }
|
||||
|
@ -84,6 +81,7 @@ public enum CommonEnum {
|
|||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum GroupKeyEnum {
|
||||
|
||||
/**
|
||||
|
@ -131,17 +129,15 @@ public enum CommonEnum {
|
|||
V3_TRAVEL_CONF_DAYLIGHT_SAVING_TIME.getKey(),
|
||||
V3_TRAVEL_CONF_WINTER_TIME.getKey(),
|
||||
V3_TRAVEL_CONF_DAY.getKey(),
|
||||
V3_TRAVEL_CONF_NIGHT.getKey()
|
||||
V3_TRAVEL_CONF_NIGHT.getKey(),
|
||||
V3_TRAVEL_CONF_IS_FIXED.getKey()
|
||||
});
|
||||
|
||||
private final Integer[] values;
|
||||
|
||||
GroupKeyEnum(Integer[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum GroupConditionEnum {
|
||||
|
||||
V3_ORDER_FORM("v3_order_form"),
|
||||
|
@ -149,8 +145,5 @@ public enum CommonEnum {
|
|||
V3_TRAVEL_CONF("v3_travel_conf");
|
||||
|
||||
private final String value;
|
||||
GroupConditionEnum(String value){
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class CommonConfigUtil {
|
|||
* @return 是否是空
|
||||
*/
|
||||
public static boolean defValueIsEmpty(String value) {
|
||||
return StringUtils.isNotBlank(value);
|
||||
return !StringUtils.isNotBlank(value);
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,6 +56,18 @@ public class CommonConfigUtil {
|
|||
return Double.valueOf(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为boolean类型
|
||||
* @param value 转换的值
|
||||
* @return 转换后的值
|
||||
*/
|
||||
public static boolean getBooleanValue(String value) {
|
||||
if(defValueIsEmpty(value)) return false;
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取数组,默认按,分隔
|
||||
* @param value 转换的值
|
||||
|
|
|
@ -86,5 +86,4 @@ public class TravelConfController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.sqx.modules.travelconf.controller.app;
|
||||
|
||||
import com.sqx.common.exception.SqxException;
|
||||
import com.sqx.common.utils.Result2;
|
||||
import com.sqx.modules.travelconf.service.TravelConfService;
|
||||
import com.sqx.modules.travelconf.vo.TravelPriceVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author bai
|
||||
* @date 2024/06/08
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(value = "出行", tags = { "APP" })
|
||||
@RequestMapping(value = "/app/travelConf")
|
||||
public class AppTravelConfController {
|
||||
|
||||
@Autowired
|
||||
private TravelConfService service;
|
||||
|
||||
@GetMapping("/calcTravelPrice")
|
||||
@ApiOperation("计算本次服务出行金额")
|
||||
public Result2<TravelPriceVo> calcTravelPrice(@ApiParam(value = "技师ID 示例:116", required = true, example = "116") Long artificerId,
|
||||
@ApiParam(value = "经度 示例:125.294234", required = true, example = "125.294234") String toLongitude,
|
||||
@ApiParam(value = "纬度 示例:43.887282", required = true, example = "43.887282") String toLatitude){
|
||||
Result2<TravelPriceVo> res = new Result2<>();
|
||||
try {
|
||||
res.setData(service.calcTravelPrice(artificerId, toLongitude, toLatitude));
|
||||
}catch (SqxException e) {
|
||||
//业务错误
|
||||
log.error(e.getMsg(),e);
|
||||
res.error(e.getMsg());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,8 @@ 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 io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -13,6 +15,7 @@ import java.time.LocalDateTime;
|
|||
* @author bai
|
||||
* @date 2024/06/08
|
||||
*/
|
||||
@ApiModel("出行配置")
|
||||
@Data
|
||||
@TableName("v3_travel_conf")
|
||||
public class TravelConf implements Serializable {
|
||||
|
@ -21,72 +24,86 @@ public class TravelConf implements Serializable {
|
|||
/**
|
||||
* ID
|
||||
*/
|
||||
@ApiModelProperty("主键")
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ApiModelProperty("创建时间")
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@ApiModelProperty("修改时间")
|
||||
private String updateTime;
|
||||
|
||||
/**
|
||||
* 价格类型(1:固定价格,2:动态价格)
|
||||
*/
|
||||
@ApiModelProperty("价格类型(1:固定价格,2:动态价格)")
|
||||
private Integer pricingType;
|
||||
|
||||
/**
|
||||
* 出行方式(1:公交,2:出租,3:免费)
|
||||
*/
|
||||
@ApiModelProperty("出行方式(1:公交,2:出租,3:免费)")
|
||||
private Integer travelType;
|
||||
|
||||
/**
|
||||
* 时令(1:夏令时,2:冬令时)
|
||||
*/
|
||||
@ApiModelProperty("时令(1:夏令时,2:冬令时)")
|
||||
private Integer seasonsType;
|
||||
|
||||
/**
|
||||
* 时段(1:白天,2:夜间)
|
||||
*/
|
||||
@ApiModelProperty("时段(1:白天,2:夜间)")
|
||||
private Integer timeIntervalType;
|
||||
|
||||
/**
|
||||
* 起步价(元)
|
||||
*/
|
||||
@ApiModelProperty("起步价(元)")
|
||||
private BigDecimal startingPrice;
|
||||
|
||||
/**
|
||||
* 免费公里数(元)
|
||||
*/
|
||||
@ApiModelProperty("免费公里数(元)")
|
||||
private BigDecimal freeKilometers;
|
||||
|
||||
/**
|
||||
* 夜间出行费(元)
|
||||
*/
|
||||
@ApiModelProperty("夜间出行费(元)")
|
||||
private BigDecimal nightTravelExpenses;
|
||||
|
||||
/**
|
||||
* 每公里价格(元)
|
||||
*/
|
||||
@ApiModelProperty("每公里价格(元)")
|
||||
private BigDecimal pricePerKilometer;
|
||||
|
||||
/**
|
||||
* 固定价格类型(1:往返,2:单程)
|
||||
*/
|
||||
@ApiModelProperty("固定价格类型(1:往返,2:单程)")
|
||||
private Integer fixedType;
|
||||
|
||||
/**
|
||||
* 固定价格(元)
|
||||
*/
|
||||
@ApiModelProperty("固定价格(元)")
|
||||
private BigDecimal fixedPrice;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.sqx.modules.travelconf.enums;
|
||||
|
||||
import com.sqx.modules.common.utils.CommonConfigUtil;
|
||||
import com.sqx.modules.travelconf.entity.TravelConf;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public class TravelEnum {
|
||||
|
||||
|
@ -11,6 +10,7 @@ public class TravelEnum {
|
|||
* 价格类型
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum PricingType {
|
||||
|
||||
/***
|
||||
|
@ -23,10 +23,25 @@ public class TravelEnum {
|
|||
TRENDS(2);
|
||||
|
||||
private final Integer value;
|
||||
}
|
||||
|
||||
PricingType(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
/**
|
||||
* 固定价格类型
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum FixedType {
|
||||
|
||||
/**
|
||||
* 往返
|
||||
*/
|
||||
RETURN(1),
|
||||
/**
|
||||
* 单程
|
||||
*/
|
||||
ONE_WAY(2);
|
||||
|
||||
private final Integer value;
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,6 +49,7 @@ public class TravelEnum {
|
|||
* 出行方式
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum TravelType {
|
||||
|
||||
/***
|
||||
|
@ -50,16 +66,13 @@ public class TravelEnum {
|
|||
FREE(3);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
TravelType(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 时令
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum SeasonsType {
|
||||
|
||||
/***
|
||||
|
@ -72,16 +85,13 @@ public class TravelEnum {
|
|||
WINTER_TIME(2);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
SeasonsType(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 时段
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum TimeIntervalType {
|
||||
|
||||
/***
|
||||
|
@ -94,10 +104,6 @@ public class TravelEnum {
|
|||
NIGHT(2);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
TimeIntervalType(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@ package com.sqx.modules.travelconf.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.modules.travelconf.entity.TravelConf;
|
||||
import com.sqx.modules.travelconf.vo.TravelPriceVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
public interface TravelConfService extends IService<TravelConf> {
|
||||
|
@ -11,11 +13,10 @@ public interface TravelConfService extends IService<TravelConf> {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param pricingType 价格类型(1:固定价格,2:动态价格)
|
||||
* @param travelType 出行方式(1:免费,2:出租,3:公共交通)
|
||||
* @return
|
||||
*/
|
||||
TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Date businessTime);
|
||||
TravelConf getConfByAccordingCondition(Integer travelType, Date businessTime);
|
||||
|
||||
/**
|
||||
* 根据类型获取出行配置
|
||||
|
@ -27,4 +28,24 @@ public interface TravelConfService extends IService<TravelConf> {
|
|||
*/
|
||||
TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Integer seasonsType, Integer timeIntervalType);
|
||||
|
||||
/**
|
||||
* 按ID获取出行价格
|
||||
* @param artificerId
|
||||
* @param toLongitude
|
||||
* @param toLatitude
|
||||
* @return
|
||||
*/
|
||||
TravelPriceVo calcTravelPrice(Long artificerId, String toLongitude, String toLatitude);
|
||||
|
||||
/**
|
||||
* 最终获取出行价格
|
||||
* @param _travelType
|
||||
* @param freeKilometers
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param toLongitude
|
||||
* @param toLatitude
|
||||
* @return
|
||||
*/
|
||||
TravelPriceVo calcTravelPrice(Integer _travelType, BigDecimal freeKilometers, String longitude, String latitude, String toLongitude, String toLatitude);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,14 @@ package com.sqx.modules.travelconf.service.impl;
|
|||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.map.CommonMapUtils;
|
||||
import com.sqx.modules.artificer.entity.Artificer;
|
||||
import com.sqx.modules.artificer.service.ArtificerService;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.enums.CommonEnum;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
|
@ -13,9 +18,11 @@ 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 com.sqx.modules.travelconf.vo.TravelPriceVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -28,20 +35,36 @@ public class TravelConfServiceImpl extends ServiceImpl<TravelConfDao, TravelConf
|
|||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
|
||||
@Autowired
|
||||
private ArtificerService artificerService;
|
||||
|
||||
@Override
|
||||
public TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Date businessTime) {
|
||||
public TravelConf getConfByAccordingCondition(Integer travelType, Date businessTime) {
|
||||
//为空则使用当前系统时间
|
||||
if(businessTime == null) businessTime = DateUtil.date();
|
||||
|
||||
//价格类型
|
||||
Integer pricingType;
|
||||
//时令
|
||||
Integer seasonsType = null;
|
||||
Integer seasonsType;
|
||||
//时段
|
||||
Integer timeIntervalType = null;
|
||||
Integer timeIntervalType;
|
||||
|
||||
//从配置文件中取出时间配置(包含很多个)
|
||||
Map<Integer,CommonInfo> commonInfoMap = commonInfoService.getMapByCondition(CommonEnum.GroupConditionEnum.V3_TRAVEL_CONF.getValue());
|
||||
|
||||
//价格类型
|
||||
CommonInfo pricingTypeConfig = commonInfoMap.get(CommonEnum.V3_TRAVEL_CONF_IS_FIXED.getKey());
|
||||
|
||||
if(pricingTypeConfig == null) {
|
||||
//throw new SqxException("无法找到出行配置,请联系管理员!");
|
||||
pricingType = TravelEnum.PricingType.TRENDS.getValue();
|
||||
}else if(CommonConfigUtil.getBooleanValue(pricingTypeConfig.getValue())){
|
||||
pricingType = TravelEnum.PricingType.TRENDS.getValue();
|
||||
} else {
|
||||
pricingType = TravelEnum.PricingType.FIXED.getValue();
|
||||
}
|
||||
|
||||
//夏令时段
|
||||
CommonInfo daylightSavingTime = commonInfoMap.get(CommonEnum.V3_TRAVEL_CONF_DAYLIGHT_SAVING_TIME.getKey());
|
||||
//冬令时段
|
||||
|
@ -112,7 +135,7 @@ public class TravelConfServiceImpl extends ServiceImpl<TravelConfDao, TravelConf
|
|||
}
|
||||
}else{
|
||||
//双方混合判断
|
||||
//TODO 前台无法创建 23:00:00-12:00:00的数据,直接甩出错误或者忽略
|
||||
//前台无法创建 23:00:00-12:00:00的数据,直接甩出错误或者忽略
|
||||
throw new SqxException("请清空夜间时间配置配置,请联系管理员!");
|
||||
}
|
||||
return getConfByAccordingCondition(pricingType, travelType, seasonsType, timeIntervalType);
|
||||
|
@ -143,6 +166,10 @@ public class TravelConfServiceImpl extends ServiceImpl<TravelConfDao, TravelConf
|
|||
|
||||
@Override
|
||||
public TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Integer seasonsType, Integer timeIntervalType) {
|
||||
if(TravelEnum.PricingType.FIXED.getValue().equals(pricingType)){
|
||||
seasonsType = null;
|
||||
timeIntervalType = null;
|
||||
}
|
||||
QueryWrapper<TravelConf> qw = new QueryWrapper<>();
|
||||
//价格类型
|
||||
qw.lambda().eq(pricingType != null, TravelConf::getPricingType, pricingType);
|
||||
|
@ -158,4 +185,82 @@ public class TravelConfServiceImpl extends ServiceImpl<TravelConfDao, TravelConf
|
|||
}
|
||||
return conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TravelPriceVo calcTravelPrice(Long artificerId, String toLongitude, String toLatitude) {
|
||||
Artificer artificerInfo = artificerService.getById(artificerId);
|
||||
|
||||
Integer travelType = TravelEnum.TravelType.TAXI.getValue();//先默认出租车 TODO 现在没有字段后补
|
||||
BigDecimal freeKilometers = new BigDecimal(0);//TODO 现在没有字段后补
|
||||
String longitude = artificerInfo.getLongitude();
|
||||
String latitude = artificerInfo.getLatitude();
|
||||
return calcTravelPrice(travelType, freeKilometers, longitude, latitude, toLongitude, toLatitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TravelPriceVo calcTravelPrice(Integer _travelType, BigDecimal freeKilometers, String longitude, String latitude, String toLongitude, String toLatitude){
|
||||
TravelPriceVo vo = new TravelPriceVo();
|
||||
|
||||
Date now = DateTime.now();
|
||||
//按条件取配置,
|
||||
TravelConf conf = getConfByAccordingCondition(_travelType, now);
|
||||
vo.setConf(conf);
|
||||
|
||||
Integer pricingType = conf.getPricingType();
|
||||
Integer fixedType = conf.getFixedType();
|
||||
Integer travelType = conf.getTravelType();
|
||||
//Integer seasonsType = conf.getSeasonsType();
|
||||
Integer timeIntervalType = conf.getTimeIntervalType();
|
||||
|
||||
//加载距离米数
|
||||
//类型转换
|
||||
int tripWay = 2;
|
||||
if(TravelEnum.TravelType.MASS_TRANSIT.getValue().equals(travelType)) {
|
||||
tripWay = 1;
|
||||
}
|
||||
JSONObject distanceJson = CommonMapUtils.calcTaxiMoneyInfo(tripWay, longitude, latitude, toLongitude, toLatitude);
|
||||
if (distanceJson == null) {
|
||||
throw new SqxException("驾车路线计算失败!");
|
||||
}
|
||||
//距离(米)
|
||||
Integer distances = distanceJson.getInteger("distance");
|
||||
vo.setDistances(distances);
|
||||
|
||||
//转换为公里数【距离(米) * 1000】
|
||||
BigDecimal kilometerNum = NumberUtil.div(distances, new BigDecimal("1000"));
|
||||
vo.setKilometerNum(NumberUtil.decimalFormat("0.00", kilometerNum));
|
||||
|
||||
if(TravelEnum.PricingType.FIXED.getValue().equals(pricingType)) {
|
||||
//固定的
|
||||
BigDecimal fixedPrice = conf.getFixedPrice();//单程
|
||||
if(TravelEnum.FixedType.RETURN.getValue().equals(fixedType)) {
|
||||
//往返
|
||||
fixedPrice = NumberUtil.mul(fixedPrice, 2);
|
||||
}
|
||||
//最终价格
|
||||
vo.setTravelPrice(NumberUtil.decimalFormat("0.00", fixedPrice));
|
||||
}else if(TravelEnum.PricingType.TRENDS.getValue().equals(pricingType)){
|
||||
//动态的
|
||||
BigDecimal nightTravelExpenses = new BigDecimal("0");//白天
|
||||
if(TravelEnum.TimeIntervalType.NIGHT.getValue().equals(timeIntervalType)) {
|
||||
//夜间
|
||||
nightTravelExpenses = conf.getNightTravelExpenses();
|
||||
}
|
||||
|
||||
//免费公里数
|
||||
//freeKilometers
|
||||
//起步价
|
||||
BigDecimal startingPrice = conf.getStartingPrice();
|
||||
//每公里价格
|
||||
BigDecimal pricePerKilometer = conf.getPricePerKilometer();
|
||||
|
||||
//最终价格
|
||||
//计算公式为【起步价 + 夜间出行费 + ((公里数 - 免费公里数) * 每公里价格)= 最终价格】
|
||||
BigDecimal travelPrice = NumberUtil.add(startingPrice, nightTravelExpenses, NumberUtil.mul(NumberUtil.sub(kilometerNum, freeKilometers), pricePerKilometer));
|
||||
vo.setTravelPrice(NumberUtil.decimalFormat("0.00", travelPrice));
|
||||
}
|
||||
return vo;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.sqx.modules.travelconf.vo;
|
||||
|
||||
import com.sqx.modules.travelconf.entity.TravelConf;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @ClassName TravelPriceVo
|
||||
* @Description TODO
|
||||
* @Author bai
|
||||
* @Date 2024/6/18 下午10:10
|
||||
* @Version 1.0
|
||||
**/
|
||||
@ApiModel("出行价格结果")
|
||||
@Data
|
||||
public class TravelPriceVo {
|
||||
|
||||
/**出行价格(元)*/
|
||||
@ApiModelProperty("出行价格(元)")
|
||||
String travelPrice;
|
||||
|
||||
/**出行距离(米)*/
|
||||
@ApiModelProperty("出行距离(米)")
|
||||
Integer distances;
|
||||
|
||||
/**出行距离(公里/千米)*/
|
||||
@ApiModelProperty("出行距离(公里)")
|
||||
String kilometerNum;
|
||||
|
||||
/**出行配置具体参数*/
|
||||
@ApiModelProperty("出行配置具体参数")
|
||||
TravelConf conf;
|
||||
}
|
Loading…
Reference in New Issue