增加remote接口
parent
075dbffcfc
commit
818b002fc9
|
@ -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<Car> list(@PathVariable String vinId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
}
|
|
@ -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<Fence> fenceById(@RequestParam("fenceId") Integer fenceId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
}
|
|
@ -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<RemoteCarService> {
|
||||
|
||||
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<Car> list(String vinId, String source) {
|
||||
return Result.error("保存操作日志失败:" + cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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<RemoteFenceService> {
|
||||
|
||||
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<Fence> fenceById(Integer fenceId, String source) {
|
||||
return Result.error("保存操作日志失败:" + cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -87,10 +87,24 @@ public class FenceController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("/fenceListAndPage")
|
||||
@Log(title = "查询围栏信息",businessType = BusinessType.FORCE)
|
||||
@Log(title = "查询围栏信息")
|
||||
public Result<TableDataInfo<Fence>> fenceListAndPage(@RequestBody FenceQueryRequest fenceQueryRequest){
|
||||
//分页查询围栏列表
|
||||
TableDataInfo<Fence> dataInfo = fenceService.fenceListAndPage(fenceQueryRequest);
|
||||
return Result.success(dataInfo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据围栏Id查询围栏信息
|
||||
* @param fenceId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/fenceById")
|
||||
@Log(title = "通过围栏Id查询围栏信息")
|
||||
public Result<Fence> fenceById(@RequestParam("fenceId") Integer fenceId){
|
||||
//通过围栏Id查询围栏信息
|
||||
Fence fence = fenceService.getById(fenceId);
|
||||
return Result.success(fence);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,6 +95,22 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper , Fence> 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询电子围栏列表
|
||||
|
|
Loading…
Reference in New Issue