系统管理相关feign封装

This commit is contained in:
efren
2025-07-11 08:55:07 +08:00
parent 6bf5a84ac4
commit bb606396e0
2 changed files with 50 additions and 14 deletions

View File

@ -13,9 +13,15 @@ import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.annotation.Value;
import feign.RequestInterceptor;
import org.springframework.context.annotation.Configuration;
@FeignClient(name = ServiceNameConstants.SYSTEM_SERVICE
,fallback = SystemClientFallback.class
@FeignClient(
name = ServiceNameConstants.SYSTEM_SERVICE,
fallback = SystemClientFallback.class,
configuration = SystemClient.FeignConfig.class
)
public interface SystemClient {
@ -23,15 +29,14 @@ public interface SystemClient {
@ApiOperation("分页查询用户信息")
@PostMapping("/v1/sysuser/getPage")
BaseResponse<Page<SysUser>> getUserPage(
@ApiParam(value = "对象数据", required = true) @RequestBody SysUserVO sysUserDTO,
@RequestHeader("isFegin") String privateKey
@ApiParam(value = "对象数据", required = true) @RequestBody SysUserVO sysUserDTO
);
@ApiOperation("查询用户列表")
@GetMapping("/v1/sysuser/list")
BaseResponse<List<SysUser>> getUserlist(
@RequestHeader("isFegin") String privateKey,
@ApiParam(value = "查询对象数据", required = false) @SpringQueryMap SysUser param);
@ApiParam(value = "查询对象数据", required = false) @SpringQueryMap SysUser param
);
// -----------------------组织接口-----------------------
@ApiOperation("查询组织信息(当前组织及下级组织列表)")
@ -50,4 +55,36 @@ public interface SystemClient {
@GetMapping("/v1/sysorg/queryAll")
BaseResponse<List<SysOrgVO>> queryAll(@SpringQueryMap SysOrg sysOrg);
@Configuration
class FeignConfig {
@Value("${check.tokentime.checkpublicKey}")
private String publicKeyStr;
@Bean
public RequestInterceptor feignRequestInterceptor() {
return template -> {
try {
String str = "isfegin";
// 1. Base64 decode public key
byte[] keyBytes = java.util.Base64.getDecoder().decode(publicKeyStr);
java.security.spec.X509EncodedKeySpec keySpec = new java.security.spec.X509EncodedKeySpec(keyBytes);
java.security.KeyFactory keyFactory = java.security.KeyFactory.getInstance("RSA");
java.security.PublicKey publicKey = keyFactory.generatePublic(keySpec);
// 2. Encrypt str with public key
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance("RSA");
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, publicKey);
byte[] encrypted = cipher.doFinal(str.getBytes());
// 3. Base64 encode encrypted result
String encoded = java.util.Base64.getEncoder().encodeToString(encrypted);
template.header("isFegin", encoded);
} catch (Exception e) {
throw new RuntimeException("Failed to encrypt isFegin header", e);
}
};
}
}
}

View File

@ -14,14 +14,18 @@ import java.util.List;
@Component
public class SystemClientFallback implements SystemClient {
@Override
public BaseResponse<Page<SysUser>> getUserPage(SysUserVO sysUserDTO, String privateKey) {
public BaseResponse<Page<SysUser>> getUserPage(SysUserVO sysUserDTO) {
return null;
}
@Override
public BaseResponse<List<SysUser>> getUserlist(String privateKey, SysUser param) {
public BaseResponse<List<SysUser>> getUserlist(SysUser param) {
return null;
}
@Override
public BaseResponse<List<SysOrg>> getOrgWithChildren(SysOrg sysOrg) {
return null;
}
@ -39,9 +43,4 @@ public class SystemClientFallback implements SystemClient {
public BaseResponse<List<SysOrgVO>> queryAll(SysOrg sysOrg) {
return null;
}
@Override
public BaseResponse<List<SysOrg>> getOrgWithChildren(SysOrg sysOrg) {
return null;
}
}