2024年6月19日 修改接口
This commit is contained in:
parent
7e9c4b59d3
commit
f56a9cb904
|
@ -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<>();
|
||||
}
|
||||
|
||||
}
|
|
@ -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:经纬度所对应的文字地址 如【北京市东城区东华门街道天安门-城楼】以行政区划+道路+门牌号等信息组成的标准格式化地址
|
||||
*/
|
||||
|
||||
|
@ -216,10 +220,10 @@ public class CommonMapUtils {
|
|||
* 根据开始位置和结束位置根据出行方式获取米
|
||||
* @param mapType
|
||||
* @param tripWay (2:驾车/出租,其他值:公交)
|
||||
* @param longitude 经度 116.307490
|
||||
* @param latitude 纬度 39.984154
|
||||
* @param toLongitude 经度 116.307490
|
||||
* @param toLatitude 纬度 39.984154
|
||||
* @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;
|
||||
|
@ -288,10 +294,10 @@ public class CommonMapUtils {
|
|||
/**
|
||||
* 根据开始位置和结束位置根据出行方式获取米
|
||||
* @param tripWay (2:驾车/出租,其他值:公交)
|
||||
* @param longitude 经度 116.307490
|
||||
* @param latitude 纬度 39.984154
|
||||
* @param toLongitude 经度 116.307490
|
||||
* @param toLatitude 纬度 39.984154
|
||||
* @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){
|
||||
|
@ -351,10 +357,10 @@ public class CommonMapUtils {
|
|||
/**
|
||||
* 查询距离 (米)
|
||||
* @param tripWay (2:驾车/出租,其他值:公交)
|
||||
* @param longitude 经度 116.307490
|
||||
* @param latitude 纬度 39.984154
|
||||
* @param toLongitude 经度 116.307490
|
||||
* @param toLatitude 纬度 39.984154
|
||||
* @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) {
|
||||
|
|
|
@ -22,7 +22,7 @@ public class CommonConfigUtil {
|
|||
* @return 是否是空
|
||||
*/
|
||||
public static boolean defValueIsEmpty(String value) {
|
||||
return StringUtils.isNotBlank(value);
|
||||
return !StringUtils.isNotBlank(value);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -86,12 +86,4 @@ public class TravelConfController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/calcTravelPrice")
|
||||
@ApiOperation("获取出行价格")
|
||||
public Result calcTravelPrice(Long artificerId, String toLongitude, String toLatitude){
|
||||
return Result.success().put("data", service.calcTravelPrice(artificerId, toLongitude, toLatitude));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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 = { "出行" })
|
||||
@RequestMapping(value = "/app/travelConf")
|
||||
public class AppTravelConfController {
|
||||
|
||||
@Autowired
|
||||
private TravelConfService service;
|
||||
|
||||
@GetMapping("/calcTravelPrice")
|
||||
@ApiOperation("根据技师ID和用户所选的经纬度获取出行价格")
|
||||
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;
|
||||
|
||||
|
||||
|
|
|
@ -166,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);
|
||||
|
@ -186,7 +190,7 @@ public class TravelConfServiceImpl extends ServiceImpl<TravelConfDao, TravelConf
|
|||
public TravelPriceVo calcTravelPrice(Long artificerId, String toLongitude, String toLatitude) {
|
||||
Artificer artificerInfo = artificerService.getById(artificerId);
|
||||
|
||||
Integer travelType = 1;//TODO 现在没有字段后补
|
||||
Integer travelType = TravelEnum.TravelType.TAXI.getValue();//先默认出租车 TODO 现在没有字段后补
|
||||
BigDecimal freeKilometers = new BigDecimal(0);//TODO 现在没有字段后补
|
||||
String longitude = artificerInfo.getLongitude();
|
||||
String latitude = artificerInfo.getLatitude();
|
||||
|
@ -215,6 +219,9 @@ public class TravelConfServiceImpl extends ServiceImpl<TravelConfDao, TravelConf
|
|||
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);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
|
@ -10,18 +12,23 @@ import lombok.Data;
|
|||
* @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