diff --git a/car-base-remote/src/main/java/com/god/base/remote/RemoteCarService.java b/car-base-remote/src/main/java/com/god/base/remote/RemoteCarService.java new file mode 100644 index 0000000..9cd58b7 --- /dev/null +++ b/car-base-remote/src/main/java/com/god/base/remote/RemoteCarService.java @@ -0,0 +1,27 @@ +package com.god.base.remote; + +import com.god.base.remote.factory.RemoteCarFallbackFactory; +import com.god.base.server.common.domain.Car; +import com.god.common.core.constant.SecurityConstants; +import com.god.common.core.constant.ServiceNameConstants; +import com.god.common.core.domain.Result; +import com.god.common.security.annotation.RequiresPermissions; +import com.god.common.system.remote.factory.RemoteLogFallbackFactory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; + +/** + * 车辆服务 + * + * @author LouZhiSHuo + * @Date 2023/11/27 19:14 + **/ +@FeignClient(contextId = "remoteCarService", value = "god-car-base", fallbackFactory = RemoteCarFallbackFactory.class) +public interface RemoteCarService { + + + @GetMapping("/car/list/{vinId}") + public Result list(@PathVariable String vinId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); +} diff --git a/car-base-remote/src/main/java/com/god/base/remote/RemoteFenceService.java b/car-base-remote/src/main/java/com/god/base/remote/RemoteFenceService.java new file mode 100644 index 0000000..b449e6c --- /dev/null +++ b/car-base-remote/src/main/java/com/god/base/remote/RemoteFenceService.java @@ -0,0 +1,24 @@ +package com.god.base.remote; + +import com.god.base.common.domain.Fence; +import com.god.base.remote.factory.RemoteFenceFallbackFactory; +import com.god.common.core.constant.SecurityConstants; +import com.god.common.core.domain.Result; +import com.god.common.log.annotation.Log; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * 围栏服务 + * + * @author LouZhiSHuo + * @Date 2023/11/27 19:39 + **/ +@FeignClient(contextId = "remoteFenceService", value = "god-car-base", fallbackFactory = RemoteFenceFallbackFactory.class) +public interface RemoteFenceService { + + @PostMapping("/baseFence/fenceById") + public Result fenceById(@RequestParam("fenceId") Integer fenceId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); +} diff --git a/car-base-remote/src/main/java/com/god/base/remote/factory/RemoteCarFallbackFactory.java b/car-base-remote/src/main/java/com/god/base/remote/factory/RemoteCarFallbackFactory.java new file mode 100644 index 0000000..7e840fc --- /dev/null +++ b/car-base-remote/src/main/java/com/god/base/remote/factory/RemoteCarFallbackFactory.java @@ -0,0 +1,33 @@ +package com.god.base.remote.factory; + +import com.god.base.remote.RemoteCarService; +import com.god.base.server.common.domain.Car; +import com.god.common.core.domain.Result; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; + +/** + * 车辆服务 + * + * @author LouZhiSHuo + * @Date 2023/11/27 19:15 + **/ +@Component +public class RemoteCarFallbackFactory implements FallbackFactory { + + private static final Logger log = LoggerFactory.getLogger(RemoteCarFallbackFactory.class); + + @Override + public RemoteCarService create(Throwable cause) { + log.error("远程调用车辆信息错误:{}",cause.getMessage()); + + return new RemoteCarService() { + @Override + public Result list(String vinId, String source) { + return Result.error("保存操作日志失败:" + cause.getMessage()); + } + }; + } +} diff --git a/car-base-remote/src/main/java/com/god/base/remote/factory/RemoteFenceFallbackFactory.java b/car-base-remote/src/main/java/com/god/base/remote/factory/RemoteFenceFallbackFactory.java new file mode 100644 index 0000000..a8ee745 --- /dev/null +++ b/car-base-remote/src/main/java/com/god/base/remote/factory/RemoteFenceFallbackFactory.java @@ -0,0 +1,31 @@ +package com.god.base.remote.factory; + +import com.god.base.common.domain.Fence; +import com.god.base.remote.RemoteFenceService; +import com.god.common.core.domain.Result; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; + +/** + * 围栏服务 + * + * @author LouZhiSHuo + * @Date 2023/11/27 19:40 + **/ +public class RemoteFenceFallbackFactory implements FallbackFactory { + + private static final Logger log = LoggerFactory.getLogger(RemoteFenceFallbackFactory.class); + @Override + public RemoteFenceService create(Throwable cause) { + + log.error("远程调用围栏服务失败:{}",cause.getMessage()); + return new RemoteFenceService() { + + @Override + public Result fenceById(Integer fenceId, String source) { + return Result.error("保存操作日志失败:" + cause.getMessage()); + } + }; + } +} diff --git a/car-base-server/src/main/java/com/god/base/server/controller/FenceController.java b/car-base-server/src/main/java/com/god/base/server/controller/FenceController.java index e0b0d4e..e28ea1a 100644 --- a/car-base-server/src/main/java/com/god/base/server/controller/FenceController.java +++ b/car-base-server/src/main/java/com/god/base/server/controller/FenceController.java @@ -87,10 +87,24 @@ public class FenceController { * @return */ @PostMapping("/fenceListAndPage") - @Log(title = "查询围栏信息",businessType = BusinessType.FORCE) + @Log(title = "查询围栏信息") public Result> fenceListAndPage(@RequestBody FenceQueryRequest fenceQueryRequest){ //分页查询围栏列表 TableDataInfo dataInfo = fenceService.fenceListAndPage(fenceQueryRequest); return Result.success(dataInfo); } + + + /** + * 根据围栏Id查询围栏信息 + * @param fenceId + * @return + */ + @PostMapping("/fenceById") + @Log(title = "通过围栏Id查询围栏信息") + public Result fenceById(@RequestParam("fenceId") Integer fenceId){ + //通过围栏Id查询围栏信息 + Fence fence = fenceService.getById(fenceId); + return Result.success(fence); + } } diff --git a/car-base-server/src/main/java/com/god/base/server/service/impl/FenceServiceImpl.java b/car-base-server/src/main/java/com/god/base/server/service/impl/FenceServiceImpl.java index 801e450..d1f8362 100644 --- a/car-base-server/src/main/java/com/god/base/server/service/impl/FenceServiceImpl.java +++ b/car-base-server/src/main/java/com/god/base/server/service/impl/FenceServiceImpl.java @@ -95,6 +95,22 @@ public class FenceServiceImpl extends ServiceImpl implement return true; } + /** + * 根据围栏Id查询围栏信息 + * @param id + * @return + */ + @Override + public Fence getById(Serializable id) { + Fence fence = super.getById(id); + if (null == fence){ + log.warn("根据围栏编号查询围栏信息失败! 围栏编号:[/-{}-/]", + id); + throw new RuntimeException("查询围栏信息失败!"); + } + return fence; + } + /** * 分页查询电子围栏列表