From 5a83189579066cae9d66bb5b58159580d2726a1f Mon Sep 17 00:00:00 2001 From: zhangli <123879394@qq.com> Date: Sun, 13 Jul 2025 14:21:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=9F=E8=BD=A6=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sczx/car/aspect/FacadeAspect.java | 58 +++++++++++++++++++ .../sczx/car/constant/SystemConstants.java | 2 +- .../car/controller/CarRentalController.java | 37 ++++++++++++ .../com/sczx/car/dto/CarRentalDetailDTO.java | 14 +++++ .../sczx/car/service/CarRentalService.java | 15 +++++ .../service/impl/CarRentalServiceImpl.java | 23 ++++++++ .../car/thirdpart/dto/CompanyStoreDTO.java | 58 +++++++++++++++++++ .../car/thirdpart/facade/StoreFacade.java | 14 +++++ .../car/thirdpart/integration/StoreInteg.java | 30 ++++++++++ src/main/resources/application.yml | 3 +- 10 files changed, 252 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/sczx/car/aspect/FacadeAspect.java create mode 100644 src/main/java/com/sczx/car/controller/CarRentalController.java create mode 100644 src/main/java/com/sczx/car/dto/CarRentalDetailDTO.java create mode 100644 src/main/java/com/sczx/car/service/CarRentalService.java create mode 100644 src/main/java/com/sczx/car/service/impl/CarRentalServiceImpl.java create mode 100644 src/main/java/com/sczx/car/thirdpart/dto/CompanyStoreDTO.java create mode 100644 src/main/java/com/sczx/car/thirdpart/facade/StoreFacade.java create mode 100644 src/main/java/com/sczx/car/thirdpart/integration/StoreInteg.java diff --git a/src/main/java/com/sczx/car/aspect/FacadeAspect.java b/src/main/java/com/sczx/car/aspect/FacadeAspect.java new file mode 100644 index 0000000..46130d4 --- /dev/null +++ b/src/main/java/com/sczx/car/aspect/FacadeAspect.java @@ -0,0 +1,58 @@ +package com.sczx.car.aspect; + +import com.alibaba.fastjson.JSON; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.stereotype.Component; + +/** + * @Author Huang Kai + * @Date 2023/1/18 17:01 + * @Version 1.0 + */ +@Aspect +@Component +@Slf4j +public class FacadeAspect { + + + + /** 以 controller 包下定义的所有请求为切入点 */ + @Pointcut("execution(public * com..facade.*.*(..))") + public void facadeLog() {} + + /** + * 在切点之前织入 + * @param joinPoint + */ + @Before("facadeLog()") + public void doBefore(JoinPoint joinPoint) { + // 打印请求相关参数 + log.info("=========================remote Start ========================="); + // 打印 Http method + //log.info("HTTP Method : {}", request.getMethod()); + // 打印调用 controller 的全路径以及执行方法 + log.info("Class Method:{}.{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName()); + // 打印请求的 IP + //log.info("IP : {}", request.getRemoteAddr()); + // 打印请求入参 + log.info("facadeAspect_Request:{}", JSON.toJSONString(joinPoint.getArgs())); + } + + @Around("facadeLog()") + public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { + long startTime = System.currentTimeMillis(); + Object result = proceedingJoinPoint.proceed(); + // 打印出参 + log.info("facadeAspect_Response:{}", JSON.toJSONString(result)); + // 执行耗时 + log.info("Time-Consuming : {} ms", System.currentTimeMillis() - startTime); + log.info("=========================remote End ========================="); + return result; + } +} \ No newline at end of file diff --git a/src/main/java/com/sczx/car/constant/SystemConstants.java b/src/main/java/com/sczx/car/constant/SystemConstants.java index 6f2587c..c0d64f0 100644 --- a/src/main/java/com/sczx/car/constant/SystemConstants.java +++ b/src/main/java/com/sczx/car/constant/SystemConstants.java @@ -18,6 +18,6 @@ public interface SystemConstants { /*** * feign客户端所在包路径 */ - String FEIGN_CLIENT_BASE_PACKAGE = "com.sczx.app.thirdpart.facade"; + String FEIGN_CLIENT_BASE_PACKAGE = "com.sczx.car.thirdpart.facade"; } diff --git a/src/main/java/com/sczx/car/controller/CarRentalController.java b/src/main/java/com/sczx/car/controller/CarRentalController.java new file mode 100644 index 0000000..9f47c31 --- /dev/null +++ b/src/main/java/com/sczx/car/controller/CarRentalController.java @@ -0,0 +1,37 @@ +package com.sczx.car.controller; + + +import com.sczx.car.common.Result; +import com.sczx.car.dto.CarRentalDetailDTO; +import com.sczx.car.service.CarRentalService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +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.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 车型表 前端控制器 + *

+ * + * @author zhangli + * @since 2025-07-12 19:55:31 + */ +@Api(value = "租车相关接口", tags = "租车相关") +@RestController +@RequestMapping("/carRental") +public class CarRentalController { + + @Autowired + private CarRentalService carRentalService; + + @ApiOperation(value = "分页查询门店车型列表") + @GetMapping("/queryCarRentalDetail") + public Result queryCarRentalDetail(@RequestParam(name = "storeId") Integer storeId, + @RequestParam(name = "carModelId") Integer carModelId){ + return Result.ok(carRentalService.queryCarRentalDetail(storeId, carModelId)); + } +} diff --git a/src/main/java/com/sczx/car/dto/CarRentalDetailDTO.java b/src/main/java/com/sczx/car/dto/CarRentalDetailDTO.java new file mode 100644 index 0000000..3b66d79 --- /dev/null +++ b/src/main/java/com/sczx/car/dto/CarRentalDetailDTO.java @@ -0,0 +1,14 @@ +package com.sczx.car.dto; + +import com.sczx.car.thirdpart.dto.CompanyStoreDTO; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(value = "租车详情对象") +public class CarRentalDetailDTO { + + @ApiModelProperty("门店信息") + private CompanyStoreDTO storeInfo; +} diff --git a/src/main/java/com/sczx/car/service/CarRentalService.java b/src/main/java/com/sczx/car/service/CarRentalService.java new file mode 100644 index 0000000..e5f82b3 --- /dev/null +++ b/src/main/java/com/sczx/car/service/CarRentalService.java @@ -0,0 +1,15 @@ +package com.sczx.car.service; + +import com.sczx.car.dto.CarRentalDetailDTO; + +public interface CarRentalService { + + /** + * 根据门店id和车型id查询租车详情信息 + * + * @param storeId + * @param carModelId + * @return + */ + CarRentalDetailDTO queryCarRentalDetail(Integer storeId, Integer carModelId); +} diff --git a/src/main/java/com/sczx/car/service/impl/CarRentalServiceImpl.java b/src/main/java/com/sczx/car/service/impl/CarRentalServiceImpl.java new file mode 100644 index 0000000..b172b34 --- /dev/null +++ b/src/main/java/com/sczx/car/service/impl/CarRentalServiceImpl.java @@ -0,0 +1,23 @@ +package com.sczx.car.service.impl; + +import com.sczx.car.dto.CarRentalDetailDTO; +import com.sczx.car.service.CarRentalService; +import com.sczx.car.thirdpart.integration.StoreInteg; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class CarRentalServiceImpl implements CarRentalService { + + @Autowired + private StoreInteg storeInteg; + @Override + public CarRentalDetailDTO queryCarRentalDetail(Integer storeId, Integer carModelId) { + CarRentalDetailDTO carRentalDetailDTO = new CarRentalDetailDTO(); + //查询门店信息 + carRentalDetailDTO.setStoreInfo(storeInteg.getStoreById(storeId)); + return carRentalDetailDTO; + } +} diff --git a/src/main/java/com/sczx/car/thirdpart/dto/CompanyStoreDTO.java b/src/main/java/com/sczx/car/thirdpart/dto/CompanyStoreDTO.java new file mode 100644 index 0000000..cf822a2 --- /dev/null +++ b/src/main/java/com/sczx/car/thirdpart/dto/CompanyStoreDTO.java @@ -0,0 +1,58 @@ +package com.sczx.car.thirdpart.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(value = "CompanyStoreDTO对象", description = "门店信息") +public class CompanyStoreDTO { + + @ApiModelProperty("主键id") + private Integer id; + + @ApiModelProperty("门店名称") + private String name; + + @ApiModelProperty("联系人") + private String contactPerson; + + @ApiModelProperty("手机号码") + private String phone; + + @ApiModelProperty("联系人2") + private String contactPerson2; + + @ApiModelProperty("手机号码2") + private String phone2; + + + @ApiModelProperty("详细地址") + private String detailedAddress; + + @ApiModelProperty("门店logo") + private String image; + + @ApiModelProperty("纬度") + private Double latitude; + + @ApiModelProperty("经度") + private Double longitude; + + @ApiModelProperty("标签 1.可租车 2.可换电 3.二手车,多个用,号隔开,例如1,2,3") + private String label; + + @ApiModelProperty("运营公司id") + private Integer operatingCompanyId; + + @ApiModelProperty("运营性质 1.直营 0.合作") + private Boolean operatingNature; + + @ApiModelProperty("简介") + private String introduction; + + + @ApiModelProperty("门店编号") + private String storeNumber; + +} diff --git a/src/main/java/com/sczx/car/thirdpart/facade/StoreFacade.java b/src/main/java/com/sczx/car/thirdpart/facade/StoreFacade.java new file mode 100644 index 0000000..238d2b7 --- /dev/null +++ b/src/main/java/com/sczx/car/thirdpart/facade/StoreFacade.java @@ -0,0 +1,14 @@ +package com.sczx.car.thirdpart.facade; + +import com.sczx.car.common.Result; +import com.sczx.car.thirdpart.dto.CompanyStoreDTO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@FeignClient(name = "sczx-store") +public interface StoreFacade { + + @GetMapping("/pub/getStoreById") + Result getStoreById(@RequestParam(name = "storeId") Integer storeId); +} diff --git a/src/main/java/com/sczx/car/thirdpart/integration/StoreInteg.java b/src/main/java/com/sczx/car/thirdpart/integration/StoreInteg.java new file mode 100644 index 0000000..e196026 --- /dev/null +++ b/src/main/java/com/sczx/car/thirdpart/integration/StoreInteg.java @@ -0,0 +1,30 @@ +package com.sczx.car.thirdpart.integration; + +import com.sczx.car.common.Result; +import com.sczx.car.exception.InnerException; +import com.sczx.car.thirdpart.dto.CompanyStoreDTO; +import com.sczx.car.thirdpart.facade.StoreFacade; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class StoreInteg { + + @Autowired + private StoreFacade storeFacade; + + public CompanyStoreDTO getStoreById(Integer storeId) { + try{ + Result result = storeFacade.getStoreById(storeId); + if(result.isSuccess()){ + return result.getData(); + } + } catch (Exception e){ + log.error("根据门店id获取门店信息失败",e); + throw new InnerException("根据门店id获取门店信息失败"); + } + return null; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0fe082f..7463842 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,7 +4,7 @@ server: spring: application: - name: sczx_car # 微服务名称 + name: sczx-car # 微服务名称 http: encoding: charset: UTF-8 @@ -31,6 +31,7 @@ spring: hikari: maximum-pool-size: 10 auto-commit: true + connection_init_sql: SELECT 1 redis: host: 115.190.8.52 port: 6379