diff --git a/src/main/java/com/sqx/common/utils/Result2.java b/src/main/java/com/sqx/common/utils/Result2.java new file mode 100644 index 0000000..e63aa0c --- /dev/null +++ b/src/main/java/com/sqx/common/utils/Result2.java @@ -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 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 error() { + return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常,请联系管理员"); + } + + public Result2 error(String msg) { + return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg); + } + + public Result2 error(int code, String msg) { + this.code = code; + this.msg = msg; + return this; + } + + public Result2 success(String msg) { + this.msg = msg; + return this; + } + + public Result2 success() { + return new Result2<>(); + } + +} diff --git a/src/main/java/com/sqx/map/CommonMapUtils.java b/src/main/java/com/sqx/map/CommonMapUtils.java index 8d3e2a3..614dfe0 100644 --- a/src/main/java/com/sqx/map/CommonMapUtils.java +++ b/src/main/java/com/sqx/map/CommonMapUtils.java @@ -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) { diff --git a/src/main/java/com/sqx/modules/common/utils/CommonConfigUtil.java b/src/main/java/com/sqx/modules/common/utils/CommonConfigUtil.java index 1fd535e..b979d1d 100644 --- a/src/main/java/com/sqx/modules/common/utils/CommonConfigUtil.java +++ b/src/main/java/com/sqx/modules/common/utils/CommonConfigUtil.java @@ -22,7 +22,7 @@ public class CommonConfigUtil { * @return 是否是空 */ public static boolean defValueIsEmpty(String value) { - return StringUtils.isNotBlank(value); + return !StringUtils.isNotBlank(value); } diff --git a/src/main/java/com/sqx/modules/travelconf/controller/TravelConfController.java b/src/main/java/com/sqx/modules/travelconf/controller/TravelConfController.java index 7f01d19..ded1a09 100644 --- a/src/main/java/com/sqx/modules/travelconf/controller/TravelConfController.java +++ b/src/main/java/com/sqx/modules/travelconf/controller/TravelConfController.java @@ -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)); - } - - - } \ No newline at end of file diff --git a/src/main/java/com/sqx/modules/travelconf/controller/app/AppTravelConfController.java b/src/main/java/com/sqx/modules/travelconf/controller/app/AppTravelConfController.java new file mode 100644 index 0000000..90b0b46 --- /dev/null +++ b/src/main/java/com/sqx/modules/travelconf/controller/app/AppTravelConfController.java @@ -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 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 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; + } + +} \ No newline at end of file diff --git a/src/main/java/com/sqx/modules/travelconf/entity/TravelConf.java b/src/main/java/com/sqx/modules/travelconf/entity/TravelConf.java index e607e3e..8eeef46 100644 --- a/src/main/java/com/sqx/modules/travelconf/entity/TravelConf.java +++ b/src/main/java/com/sqx/modules/travelconf/entity/TravelConf.java @@ -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; diff --git a/src/main/java/com/sqx/modules/travelconf/service/impl/TravelConfServiceImpl.java b/src/main/java/com/sqx/modules/travelconf/service/impl/TravelConfServiceImpl.java index 1ff07cc..0168cba 100644 --- a/src/main/java/com/sqx/modules/travelconf/service/impl/TravelConfServiceImpl.java +++ b/src/main/java/com/sqx/modules/travelconf/service/impl/TravelConfServiceImpl.java @@ -166,6 +166,10 @@ public class TravelConfServiceImpl extends ServiceImpl qw = new QueryWrapper<>(); //价格类型 qw.lambda().eq(pricingType != null, TravelConf::getPricingType, pricingType); @@ -186,7 +190,7 @@ public class TravelConfServiceImpl extends ServiceImpl