diff --git a/internal-common/src/main/java/com/mashibing/internalcommon/constant/CommonStatusEnum.java b/internal-common/src/main/java/com/mashibing/internalcommon/constant/CommonStatusEnum.java index e04c754..d852167 100644 --- a/internal-common/src/main/java/com/mashibing/internalcommon/constant/CommonStatusEnum.java +++ b/internal-common/src/main/java/com/mashibing/internalcommon/constant/CommonStatusEnum.java @@ -26,6 +26,10 @@ public enum CommonStatusEnum { */ ,USER_NOT_EXISTS(1200,"当前用户不存在") + /** + *计价规则:1300-1399 + */ + ,PRICE_RULE_EMPTY(1300,"计价规则不存在") ; diff --git a/internal-common/src/main/java/com/mashibing/internalcommon/dto/PriceRule.java b/internal-common/src/main/java/com/mashibing/internalcommon/dto/PriceRule.java new file mode 100644 index 0000000..08d1798 --- /dev/null +++ b/internal-common/src/main/java/com/mashibing/internalcommon/dto/PriceRule.java @@ -0,0 +1,15 @@ +package com.mashibing.internalcommon.dto; + +import lombok.Data; + +@Data +public class PriceRule { + + private String cityCode; + private String vehicleType; + private Double startFare ; + private Integer startMile; + private Double unitPricePerMile; + private Double unitPricePerMinute; + +} diff --git a/service-price/pom.xml b/service-price/pom.xml index 771c80f..b84aef3 100644 --- a/service-price/pom.xml +++ b/service-price/pom.xml @@ -36,6 +36,16 @@ feign-httpclient + + com.baomidou + mybatis-plus-boot-starter + 3.4.1 + + + mysql + mysql-connector-java + + diff --git a/service-price/src/main/java/com/mashibing/serviceprice/ServicePriceApplication.java b/service-price/src/main/java/com/mashibing/serviceprice/ServicePriceApplication.java index cd5a119..0a3cf34 100644 --- a/service-price/src/main/java/com/mashibing/serviceprice/ServicePriceApplication.java +++ b/service-price/src/main/java/com/mashibing/serviceprice/ServicePriceApplication.java @@ -1,5 +1,6 @@ package com.mashibing.serviceprice; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @@ -8,6 +9,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication @EnableDiscoveryClient @EnableFeignClients +@MapperScan("com.mashibing.serviceprice.mapper") public class ServicePriceApplication { public static void main(String[] args) { diff --git a/service-price/src/main/java/com/mashibing/serviceprice/mapper/PriceRuleMapper.java b/service-price/src/main/java/com/mashibing/serviceprice/mapper/PriceRuleMapper.java new file mode 100644 index 0000000..8f93515 --- /dev/null +++ b/service-price/src/main/java/com/mashibing/serviceprice/mapper/PriceRuleMapper.java @@ -0,0 +1,10 @@ +package com.mashibing.serviceprice.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mashibing.internalcommon.dto.PriceRule; +import org.springframework.stereotype.Repository; + +@Repository +public interface PriceRuleMapper extends BaseMapper { + +} diff --git a/service-price/src/main/java/com/mashibing/serviceprice/service/ForecastPriceService.java b/service-price/src/main/java/com/mashibing/serviceprice/service/ForecastPriceService.java index d65f33d..e43168f 100644 --- a/service-price/src/main/java/com/mashibing/serviceprice/service/ForecastPriceService.java +++ b/service-price/src/main/java/com/mashibing/serviceprice/service/ForecastPriceService.java @@ -1,14 +1,21 @@ package com.mashibing.serviceprice.service; +import com.mashibing.internalcommon.constant.CommonStatusEnum; +import com.mashibing.internalcommon.dto.PriceRule; import com.mashibing.internalcommon.dto.ResponseResult; import com.mashibing.internalcommon.request.ForecastPriceDTO; import com.mashibing.internalcommon.response.DirectionResponse; import com.mashibing.internalcommon.response.ForecastPriceResponse; +import com.mashibing.serviceprice.mapper.PriceRuleMapper; import com.mashibing.serviceprice.remote.ServiceMapClient; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + @Slf4j @Service public class ForecastPriceService { @@ -16,6 +23,9 @@ public class ForecastPriceService { @Autowired private ServiceMapClient serviceMapClient; + @Autowired + private PriceRuleMapper priceRuleMapper; + /** * 根据 出发地和目地的 地经纬度 计算预估价格 * @param depLongitude @@ -45,6 +55,14 @@ public class ForecastPriceService { System.out.println("duration = " + duration); // 读取计价规则 + Map queryMap = new HashMap<>(); + queryMap.put("city_code","110000"); + queryMap.put("vehicle_type","1"); + List priceRules = priceRuleMapper.selectByMap(queryMap); + if (priceRules == null || priceRules.size() == 0) { + return ResponseResult.fail(CommonStatusEnum.PRICE_RULE_EMPTY.getCode(),CommonStatusEnum.PRICE_RULE_EMPTY.getValue()); + } + PriceRule priceRule = priceRules.get(0); // 根据 距离时长 进行价格预估 diff --git a/service-price/src/main/resources/application.yml b/service-price/src/main/resources/application.yml index 9c9bad6..bdfa946 100644 --- a/service-price/src/main/resources/application.yml +++ b/service-price/src/main/resources/application.yml @@ -6,4 +6,9 @@ spring: cloud: nacos: discovery: - server-addr: localhost:8848 \ No newline at end of file + server-addr: localhost:8848 + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/service-price?characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: root + password: 123456 \ No newline at end of file