From abeb57e19aff585bafb642463e1957c35e23a183 Mon Sep 17 00:00:00 2001 From: msb_89821 Date: Mon, 24 Oct 2022 16:58:17 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=AE=9E=E7=8E=B0=E8=AE=A1=E4=BB=B7?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sendserver/SendServerApplication.java | 3 + .../v1/onelinetextplublic/service-map/pom.xml | 18 +++ .../service/map/ServiceMapApplication.java | 9 ++ .../service/map/service/DistanceService.java | 76 +++++++++- .../src/main/resources/application.yml | 7 +- .../onelinetextplublic/service-price/pom.xml | 16 +++ .../price/ServicePriceApplication.java | 13 ++ .../service/price/feign/ServiceMapClient.java | 28 ++++ .../service/price/mapper/PriceRuleMapper.java | 20 +++ .../price/service/ForecastPriceService.java | 133 ++++++++++++++++++ .../constant/AmapConfigConstants.java | 62 ++++++++ .../mashibing/constant/CommonStatusEnum.java | 66 +++++++++ .../com/mashibing/dto/DistanceResult.java | 8 +- .../java/com/mashibing/dto/PriceRule.java | 60 ++++++++ .../response/ForecastPriceResponse.java | 17 +++ .../com/mashibing/util/BigDecimalUtils.java | 59 ++++++++ 16 files changed, 586 insertions(+), 9 deletions(-) create mode 100644 oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/feign/ServiceMapClient.java create mode 100644 oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/mapper/PriceRuleMapper.java create mode 100644 oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/service/ForecastPriceService.java create mode 100644 oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/AmapConfigConstants.java create mode 100644 oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/dto/PriceRule.java create mode 100644 oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/response/ForecastPriceResponse.java create mode 100644 oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/util/BigDecimalUtils.java diff --git a/oneLineTxt/v1/onelinetextplublic/send-server/src/main/java/com/mashibing/sendserver/SendServerApplication.java b/oneLineTxt/v1/onelinetextplublic/send-server/src/main/java/com/mashibing/sendserver/SendServerApplication.java index a48ee9e..29b6abe 100644 --- a/oneLineTxt/v1/onelinetextplublic/send-server/src/main/java/com/mashibing/sendserver/SendServerApplication.java +++ b/oneLineTxt/v1/onelinetextplublic/send-server/src/main/java/com/mashibing/sendserver/SendServerApplication.java @@ -3,6 +3,9 @@ package com.mashibing.sendserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; @SpringBootApplication @EnableDiscoveryClient diff --git a/oneLineTxt/v1/onelinetextplublic/service-map/pom.xml b/oneLineTxt/v1/onelinetextplublic/service-map/pom.xml index 74d58a7..c01079f 100644 --- a/oneLineTxt/v1/onelinetextplublic/service-map/pom.xml +++ b/oneLineTxt/v1/onelinetextplublic/service-map/pom.xml @@ -32,6 +32,24 @@ compile + + com.baomidou + mybatis-plus-boot-starter + + + + mysql + mysql-connector-java + + + + com.baomidou + mybatis-plus-boot-starter + + 3.3.2 + + + diff --git a/oneLineTxt/v1/onelinetextplublic/service-map/src/main/java/com/mashibing/service/map/ServiceMapApplication.java b/oneLineTxt/v1/onelinetextplublic/service-map/src/main/java/com/mashibing/service/map/ServiceMapApplication.java index 99448a4..eeef04d 100644 --- a/oneLineTxt/v1/onelinetextplublic/service-map/src/main/java/com/mashibing/service/map/ServiceMapApplication.java +++ b/oneLineTxt/v1/onelinetextplublic/service-map/src/main/java/com/mashibing/service/map/ServiceMapApplication.java @@ -2,6 +2,9 @@ package com.mashibing.service.map; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; /** * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved. @@ -17,8 +20,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; *
Date: 2022/10/22 16:32 */ @SpringBootApplication +@EnableDiscoveryClient public class ServiceMapApplication { public static void main(String[] args) { SpringApplication.run(ServiceMapApplication.class,args); } + + @Bean + public RestTemplate restTemplate(){ + return new RestTemplate(); + } } diff --git a/oneLineTxt/v1/onelinetextplublic/service-map/src/main/java/com/mashibing/service/map/service/DistanceService.java b/oneLineTxt/v1/onelinetextplublic/service-map/src/main/java/com/mashibing/service/map/service/DistanceService.java index 5492cde..cddb08a 100644 --- a/oneLineTxt/v1/onelinetextplublic/service-map/src/main/java/com/mashibing/service/map/service/DistanceService.java +++ b/oneLineTxt/v1/onelinetextplublic/service-map/src/main/java/com/mashibing/service/map/service/DistanceService.java @@ -1,10 +1,16 @@ package com.mashibing.service.map.service; -import com.alibaba.fastjson.JSON; +import com.mashibing.constant.AmapConfigConstants; import com.mashibing.dto.AddressLatiLong; import com.mashibing.dto.DistanceResult; import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; /** * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved. @@ -25,11 +31,73 @@ public class DistanceService { private static final String reqPath = "/v3/direction/driving"; + + + @Value("${amap.key}") + private String amapKey; + + @Value("${amap.url}") + private String url; + + @Autowired + private RestTemplate restTemplate; + public DistanceResult queryDistanceResult(AddressLatiLong addressLatiLong){ - log.info("调高德服务商获取距离 参数={}", JSON.toJSONString(addressLatiLong)); + // 组装请求调用url + StringBuilder urlBuild = new StringBuilder(); + urlBuild.append(url+reqPath); + urlBuild.append("?"); + urlBuild.append("origin="+addressLatiLong.getOriginLong()+","+addressLatiLong.getOriginLati()); + urlBuild.append("&"); + urlBuild.append("destination="+addressLatiLong.getDestinationLong()+","+addressLatiLong.getDestinationLati()); + urlBuild.append("&"); + urlBuild.append("extensions=base"); + urlBuild.append("&"); + urlBuild.append("output=json"); + urlBuild.append("&"); + urlBuild.append("key="+amapKey); + log.info(urlBuild.toString()); + // 调用高德接口 + log.info("高德地图:路径规划,请求信息:"+urlBuild.toString()); + ResponseEntity directionEntity = restTemplate.getForEntity(urlBuild.toString(), String.class); + String directionString = directionEntity.getBody(); + log.info("高德地图:路径规划,返回信息:"+directionString); + // 解析接口 + DistanceResult directionResponse = parseDirectionEntity(directionString); - DistanceResult distanceResult =new DistanceResult(); + return directionResponse; + } + + private DistanceResult parseDirectionEntity(String directionString){ + DistanceResult directionResponse = null; + try { + // 最外层 + JSONObject result = JSONObject.fromObject(directionString); + if(result.has(AmapConfigConstants.STATUS)) { + int status = result.getInt(AmapConfigConstants.STATUS); + if (status == 1){ + if (result.has(AmapConfigConstants.ROUTE)){ + JSONObject routeObject = result.getJSONObject(AmapConfigConstants.ROUTE); + JSONArray pathsArray = routeObject.getJSONArray(AmapConfigConstants.PATHS); + JSONObject pathObject = pathsArray.getJSONObject(0); + directionResponse = new DistanceResult(); + + if (pathObject.has(AmapConfigConstants.DISTANCE)){ + int distance = pathObject.getInt(AmapConfigConstants.DISTANCE); + directionResponse.setDistance(distance); + } + if (pathObject.has(AmapConfigConstants.DURATION)){ + int duration = pathObject.getInt(AmapConfigConstants.DURATION); + directionResponse.setDuration(duration); + } + } + } + } - return distanceResult; + }catch (Exception e){ + + } + return directionResponse; } + } diff --git a/oneLineTxt/v1/onelinetextplublic/service-map/src/main/resources/application.yml b/oneLineTxt/v1/onelinetextplublic/service-map/src/main/resources/application.yml index 11c5ecf..6dd4977 100644 --- a/oneLineTxt/v1/onelinetextplublic/service-map/src/main/resources/application.yml +++ b/oneLineTxt/v1/onelinetextplublic/service-map/src/main/resources/application.yml @@ -9,8 +9,13 @@ spring: server-addr: 127.0.0.1:8848 application: name: service-map + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://10.2.23.46:3306/service-map?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true + username: root + password: 1qaz@WSX -gaodeMap: +amap: key: 595148d3d09d60942adaaacf7dfb95aa url: https://restapi.amap.com diff --git a/oneLineTxt/v1/onelinetextplublic/service-price/pom.xml b/oneLineTxt/v1/onelinetextplublic/service-price/pom.xml index 20724e5..640b206 100644 --- a/oneLineTxt/v1/onelinetextplublic/service-price/pom.xml +++ b/oneLineTxt/v1/onelinetextplublic/service-price/pom.xml @@ -32,6 +32,22 @@ compile + + com.baomidou + mybatis-plus-boot-starter + + 3.3.2 + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + diff --git a/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/ServicePriceApplication.java b/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/ServicePriceApplication.java index 35a0e44..e095a86 100644 --- a/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/ServicePriceApplication.java +++ b/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/ServicePriceApplication.java @@ -2,6 +2,10 @@ package com.mashibing.service.price; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; /** * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved. @@ -17,9 +21,18 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; *
Date: 2022/10/22 11:30 */ @SpringBootApplication +@EnableDiscoveryClient public class ServicePriceApplication { public static void main(String[] args) { SpringApplication.run(ServicePriceApplication.class, args); } + + + @Bean + @LoadBalanced + public RestTemplate restTemplate(){ + return new RestTemplate(); + } + } diff --git a/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/feign/ServiceMapClient.java b/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/feign/ServiceMapClient.java new file mode 100644 index 0000000..acd3e3e --- /dev/null +++ b/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/feign/ServiceMapClient.java @@ -0,0 +1,28 @@ +package com.mashibing.service.price.feign; + +import com.mashibing.dto.AddressLatiLong; +import com.mashibing.dto.DistanceResult; +import com.mashibing.dto.ResponseResult; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved. + * 1.版权归博纳德集团公司所有; + * 2.未经原作者允许不得转载本代码内容,否则将视为侵权; + * 3.对于不遵守此声明或者其他违法使用本代码内容者,本公司依法保留追究权。. + * + * @packageName: com.mashibing.service.price.feign + * @description: + * @author: nod + * @create: 2022-10-24 + */ +@FeignClient("service-map") +public interface ServiceMapClient { + + @RequestMapping(value = "/queryDistanceResult" ,method = RequestMethod.POST) + public ResponseResult queryDistanceResult(@RequestBody AddressLatiLong addressLatiLong); + +} diff --git a/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/mapper/PriceRuleMapper.java b/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/mapper/PriceRuleMapper.java new file mode 100644 index 0000000..53a2255 --- /dev/null +++ b/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/mapper/PriceRuleMapper.java @@ -0,0 +1,20 @@ +package com.mashibing.service.price.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mashibing.dto.PriceRule; +import org.apache.ibatis.annotations.Mapper; + +/** + * Copyright© 2020.10.20 by 博纳德集团有限公司.All rights reserved. + * 1.版权归博纳德集团公司所有; + * 2.未经原作者允许不得转载本代码内容,否则将视为侵权; + * 3.对于不遵守此声明或者其他违法使用本代码内容者,本公司依法保留追究权。. + * + * @packageName: com.mashibing.service.price.mapper + * @description: + * @author: nod + * @create: 2022-10-24 + */ +@Mapper +public interface PriceRuleMapper extends BaseMapper { +} diff --git a/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/service/ForecastPriceService.java b/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/service/ForecastPriceService.java new file mode 100644 index 0000000..e055d42 --- /dev/null +++ b/oneLineTxt/v1/onelinetextplublic/service-price/src/main/java/com/mashibing/service/price/service/ForecastPriceService.java @@ -0,0 +1,133 @@ +package com.mashibing.service.price.service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.mashibing.constant.CommonStatusEnum; +import com.mashibing.dto.AddressLatiLong; +import com.mashibing.dto.DistanceResult; +import com.mashibing.dto.PriceRule; +import com.mashibing.dto.ResponseResult; + +import com.mashibing.response.ForecastPriceResponse; +import com.mashibing.service.price.feign.ServiceMapClient; +import com.mashibing.service.price.mapper.PriceRuleMapper; +import com.mashibing.util.BigDecimalUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.List; + +@Service +@Slf4j +public class ForecastPriceService { + + @Resource + private ServiceMapClient serviceMapClient; + + @Resource + private PriceRuleMapper priceRuleMapper; + + public ResponseResult forecastPrice(String depLongitude, String depLatitude, String destLongitude, String destLatitude, + String cityCode, String vehicleType){ + + log.info("出发地经度:"+depLongitude); + log.info("出发地纬度:"+depLatitude); + log.info("目的地经度:"+destLongitude); + log.info("目的地纬度:"+destLatitude); + + log.info("调用地图服务,查询距离和时长"); + AddressLatiLong forecastPriceDTO = new AddressLatiLong(); + forecastPriceDTO.setDestinationLong(depLongitude); + forecastPriceDTO.setDestinationLati(depLatitude); + forecastPriceDTO.setOriginLong(destLongitude); + forecastPriceDTO.setOriginLati(destLatitude); + ResponseResult direction = serviceMapClient.queryDistanceResult(forecastPriceDTO); + Integer distance = direction.getData().getDistance(); + Integer duration = direction.getData().getDuration(); + log.info(("距离:"+distance+",时长:"+duration)); + + log.info("读取计价规则"); + + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("city_code",cityCode); + queryWrapper.eq("vehicle_type",vehicleType); + queryWrapper.orderByDesc("fare_version"); + + List priceRules = priceRuleMapper.selectList(queryWrapper); + if (priceRules.size() == 0){ + return ResponseResult.fail(CommonStatusEnum.PRICE_RULE_EMPTY.getCode(),CommonStatusEnum.PRICE_RULE_EMPTY.getMessage()); + } + + PriceRule priceRule = priceRules.get(0); + + log.info("根据距离、时长和计价规则,计算价格"); + + double price = getPrice(distance, duration, priceRule); + + + ForecastPriceResponse forecastPriceResponse = new ForecastPriceResponse(); + forecastPriceResponse.setPrice(price); + forecastPriceResponse.setCityCode(cityCode); + forecastPriceResponse.setVehicleType(vehicleType); + forecastPriceResponse.setFareType(priceRule.getFareType()); + forecastPriceResponse.setFareVersion(priceRule.getFareVersion()); + + return ResponseResult.success(forecastPriceResponse); + } + + /** + * 根据距离、时长 和计价规则,计算最终价格 + * @param distance 距离 + * @param duration 时长 + * @param priceRule 计价规则 + * @return + */ + private double getPrice(Integer distance , Integer duration,PriceRule priceRule){ + double price = 0; + + // 起步价 + double startFare = priceRule.getStartFare(); + price = BigDecimalUtils.add(price,startFare); + + // 里程费 + // 总里程 m + double distanceMile = BigDecimalUtils.divide(distance,1000); + // 起步里程 + double startMile = (double)priceRule.getStartMile(); + double distanceSubtract = BigDecimalUtils.substract(distanceMile,startMile); + // 最终收费的里程数 km + double mile = distanceSubtract<0?0:distanceSubtract; + // 计程单价 元/km + double unitPricePerMile = priceRule.getUnitPricePerMile(); + // 里程价格 + double mileFare = BigDecimalUtils.multiply(mile,unitPricePerMile); + price = BigDecimalUtils.add(price,mileFare); + + // 时长费 + // 时长的分钟数 + double timeMinute = BigDecimalUtils.divide(duration,60); + // 计时单价 + double unitPricePerMinute = priceRule.getUnitPricePerMinute(); + + // 时长费用 + double timeFare = BigDecimalUtils.multiply(timeMinute,unitPricePerMinute); + price = BigDecimalUtils.add(price,timeFare); + + BigDecimal priceBigDecimal = new BigDecimal(price); + priceBigDecimal = priceBigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP); + + return priceBigDecimal.doubleValue(); + } + +// public static void main(String[] args) { +// PriceRule priceRule = new PriceRule(); +// priceRule.setUnitPricePerMile(1.8); +// priceRule.setUnitPricePerMinute(0.5); +// priceRule.setStartFare(10.0); +// priceRule.setStartMile(3); +// +// System.out.println(getPrice(6500,1800,priceRule)); +// } +} diff --git a/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/AmapConfigConstants.java b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/AmapConfigConstants.java new file mode 100644 index 0000000..c50b183 --- /dev/null +++ b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/AmapConfigConstants.java @@ -0,0 +1,62 @@ +package com.mashibing.constant; + +public class AmapConfigConstants { + /** + * 路径规划地址 + */ + public static final String DIRECTION_URL = "https://restapi.amap.com/v3/direction/driving"; + + /** + * 行政区域查询 + */ + public static final String DISTRICT_URL = "https://restapi.amap.com/v3/config/district"; + + /** + * 新增服务 + */ + public static final String SERVICE_ADD_URL = "https://tsapi.amap.com/v1/track/service/add"; + + /** + * 创建终端 + */ + public static final String TERMINAL_ADD = "https://tsapi.amap.com/v1/track/terminal/add"; + + /** + * 创建轨迹 + */ + public static final String TRACK_ADD = "https://tsapi.amap.com/v1/track/trace/add"; + + /** + * 轨迹点上传 + */ + public static final String POINT_UPLOAD = "https://tsapi.amap.com/v1/track/point/upload"; + + /** + * 终端搜索 + */ + public static final String TERMINAL_AROUNDSEARCH = "https://tsapi.amap.com/v1/track/terminal/aroundsearch"; + + + /** + * 路径规划 json key值 + */ + public static final String STATUS = "status"; + + public static final String ROUTE = "route"; + + public static final String PATHS = "paths"; + + public static final String DISTANCE = "distance"; + + public static final String DURATION = "duration"; + + public static final String DISTRICTS = "districts"; + + public static final String ADCODE = "adcode"; + + public static final String NAME = "name"; + + public static final String LEVEL = "level"; + + public static final String STREET = "street"; +} diff --git a/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/CommonStatusEnum.java b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/CommonStatusEnum.java index 6843fbd..3d4b365 100644 --- a/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/CommonStatusEnum.java +++ b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/constant/CommonStatusEnum.java @@ -5,9 +5,75 @@ import lombok.Getter; public enum CommonStatusEnum { + + /** + * 验证码错误提示:1000-1099 + */ + VERIFICATION_CODE_ERROR(1099,"验证码不正确"), + + /** + * Token类提示:1100-1199 + */ + TOKEN_ERROR(1199,"token错误"), + + /** + * 用户提示:1200-1299 + */ + USER_NOT_EXISTS(1200,"当前用户不存在"), + + /** + * 计价规则:1300-1399 + */ + PRICE_RULE_EMPTY(1300,"计价规则不存在"), + + PRICE_RULE_EXISTS(1301,"计价规则已存在,不允许添加"), + + PRICE_RULE_NOT_EDIT(1302,"计价规则没有变化"), + + PRICE_RULE_CHANGED(1303,"计价规则有变化"), + + + + /** + * 地图信息:1400-1499 + */ + MAP_DISTRICT_ERROR(1400,"请求地图错误"), + + /** + * 司机和车辆:1500-1599 + */ + DRIVER_CAR_BIND_NOT_EXISTS(1500,"司机和车辆绑定关系不存在"), + + DRIVER_NOT_EXITST(1501,"司机不存在"), + + DRIVER_CAR_BIND_EXISTS(1502,"司机和车辆绑定关系已存在,请勿重复绑定"), + + DRIVER_BIND_EXISTS(1503,"司机已经被绑定了,请勿重复绑定"), + + CAR_BIND_EXISTS(1504,"车辆已经被绑定了,请勿重复绑定"), + + CITY_DRIVER_EMPTY(1505,"当前城市没有可用的司机"), + + AVAILABLE_DRIVER_EMPTY(1506,"可用的司机为空"), + + /** + * 订单:1600-1699 + */ + ORDER_GOING_ON(1600,"有正在进行的订单"), + + /** + * 下单异常 + */ + DEVICE_IS_BLACK(1601,"该设备超过下单次数"), + + CITY_SERVICE_NOT_SERVICE(1602,"当前城市不提供叫车服务"), + SUCCESS(1,"SUCCESS"), FAIL(0,"FAIL"); + + + @Getter private int code; @Getter diff --git a/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/dto/DistanceResult.java b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/dto/DistanceResult.java index d2f3d3a..e3cfa12 100644 --- a/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/dto/DistanceResult.java +++ b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/dto/DistanceResult.java @@ -21,8 +21,8 @@ public class DistanceResult { private Integer distance; private Integer duration; - public DistanceResult(Integer distance, Integer duration) { - this.distance = distance; - this.duration = duration; - } +// public DistanceResult(Integer distance, Integer duration) { +// this.distance = distance; +// this.duration = duration; +// } } diff --git a/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/dto/PriceRule.java b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/dto/PriceRule.java new file mode 100644 index 0000000..5437e20 --- /dev/null +++ b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/dto/PriceRule.java @@ -0,0 +1,60 @@ +package com.mashibing.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author cpf + * @since 2022-10-11 + */ +@Data +public class PriceRule implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 城市代码 + */ + private String cityCode; + + /** + * 车辆类型 + */ + private String vehicleType; + + /** + * 起步价 + */ + private Double startFare; + + /** + * 起步里程 + */ + private Integer startMile; + + /** + * 单位距离价格(千米) + */ + private Double unitPricePerMile; + + /** + * 单位时长价格(分钟) + */ + private Double unitPricePerMinute; + + /** + * 版本,默认1,修改往上增。 + */ + private Integer fareVersion; + + /** + * 运价类型编码 + */ + private String fareType; + +} diff --git a/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/response/ForecastPriceResponse.java b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/response/ForecastPriceResponse.java new file mode 100644 index 0000000..c5a9c04 --- /dev/null +++ b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/response/ForecastPriceResponse.java @@ -0,0 +1,17 @@ +package com.mashibing.response; + +import lombok.Data; + +@Data +public class ForecastPriceResponse { + + private double price; + + private String cityCode; + + private String vehicleType; + + private String fareType; + + private Integer fareVersion; +} diff --git a/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/util/BigDecimalUtils.java b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/util/BigDecimalUtils.java new file mode 100644 index 0000000..96846ef --- /dev/null +++ b/oneLineTxt/v1/onelinetextplublic/untitled4/src/main/java/com/mashibing/util/BigDecimalUtils.java @@ -0,0 +1,59 @@ +package com.mashibing.util; + +import java.math.BigDecimal; + +public class BigDecimalUtils { + + /** + * 加法 + * @param v1 + * @param v2 + * @return + */ + public static double add(double v1 , double v2){ + BigDecimal b1 = BigDecimal.valueOf(v1); + BigDecimal b2 = BigDecimal.valueOf(v2); + + return b1.add(b2).doubleValue(); + } + + /** + * 减法 + * @param v1 + * @param v2 + * @return + */ + public static double substract(double v1,double v2){ + BigDecimal b1 = BigDecimal.valueOf(v1); + BigDecimal b2 = BigDecimal.valueOf(v2); + return b1.subtract(b2).doubleValue(); + } + + /** + * 乘法 + * @param v1 + * @param v2 + * @return + */ + public static double multiply(double v1,double v2){ + BigDecimal b1 = BigDecimal.valueOf(v1); + BigDecimal b2 = BigDecimal.valueOf(v2); + return b1.multiply(b2).doubleValue(); + + } + /** + * 除法 + * @param v1 + * @param v2 + * @return + */ + public static double divide(int v1, int v2){ + if (v2 <= 0){ + throw new IllegalArgumentException("除数非法"); + } + + BigDecimal b1 = BigDecimal.valueOf(v1); + BigDecimal b2 = BigDecimal.valueOf(v2); + return b1.divide(b2,2,BigDecimal.ROUND_HALF_UP).doubleValue(); + } +}