飞滴出行网约车2022-service-price从数据库中读取计价规则

master
yh 3 years ago
parent c0e453b6a5
commit 22b6d9682f

@ -26,6 +26,10 @@ public enum CommonStatusEnum {
*/ */
,USER_NOT_EXISTS(1200,"当前用户不存在") ,USER_NOT_EXISTS(1200,"当前用户不存在")
/**
*1300-1399
*/
,PRICE_RULE_EMPTY(1300,"计价规则不存在")
; ;

@ -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;
}

@ -36,6 +36,16 @@
<artifactId>feign-httpclient</artifactId> <artifactId>feign-httpclient</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies> </dependencies>

@ -1,5 +1,6 @@
package com.mashibing.serviceprice; package com.mashibing.serviceprice;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@ -8,6 +9,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients @EnableFeignClients
@MapperScan("com.mashibing.serviceprice.mapper")
public class ServicePriceApplication { public class ServicePriceApplication {
public static void main(String[] args) { public static void main(String[] args) {

@ -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<PriceRule> {
}

@ -1,14 +1,21 @@
package com.mashibing.serviceprice.service; 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.dto.ResponseResult;
import com.mashibing.internalcommon.request.ForecastPriceDTO; import com.mashibing.internalcommon.request.ForecastPriceDTO;
import com.mashibing.internalcommon.response.DirectionResponse; import com.mashibing.internalcommon.response.DirectionResponse;
import com.mashibing.internalcommon.response.ForecastPriceResponse; import com.mashibing.internalcommon.response.ForecastPriceResponse;
import com.mashibing.serviceprice.mapper.PriceRuleMapper;
import com.mashibing.serviceprice.remote.ServiceMapClient; import com.mashibing.serviceprice.remote.ServiceMapClient;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j @Slf4j
@Service @Service
public class ForecastPriceService { public class ForecastPriceService {
@ -16,6 +23,9 @@ public class ForecastPriceService {
@Autowired @Autowired
private ServiceMapClient serviceMapClient; private ServiceMapClient serviceMapClient;
@Autowired
private PriceRuleMapper priceRuleMapper;
/** /**
* *
* @param depLongitude * @param depLongitude
@ -45,6 +55,14 @@ public class ForecastPriceService {
System.out.println("duration = " + duration); System.out.println("duration = " + duration);
// 读取计价规则 // 读取计价规则
Map<String,Object> queryMap = new HashMap<>();
queryMap.put("city_code","110000");
queryMap.put("vehicle_type","1");
List<PriceRule> 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);
// 根据 距离时长 进行价格预估 // 根据 距离时长 进行价格预估

@ -7,3 +7,8 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: localhost:8848 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
Loading…
Cancel
Save