优化分析项库绑定流程模版和知识库
This commit is contained in:
@@ -4,6 +4,28 @@ import java.lang.reflect.Field;
|
||||
|
||||
public class BaseBean {
|
||||
|
||||
public void handleNull()
|
||||
{
|
||||
Class cls = this.getClass();
|
||||
Field[] fields = cls.getDeclaredFields();
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
Class typeClass = field.getType();
|
||||
if (typeClass.equals(String.class))
|
||||
{
|
||||
Object object = field.get(this);
|
||||
if (object == null)
|
||||
{
|
||||
field.set(this, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void init()
|
||||
{
|
||||
Class cls = this.getClass();
|
||||
|
||||
58
common/src/main/java/com/sdm/common/entity/bo/JwtToken.java
Normal file
58
common/src/main/java/com/sdm/common/entity/bo/JwtToken.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.sdm.common.entity.bo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JwtToken {
|
||||
private String keyId;
|
||||
private String issuer;
|
||||
private String subject;
|
||||
private String userName;
|
||||
private final long EXPIRE_TIME = 100*60*60*1000;
|
||||
public JwtToken(String keyId,String userId,String userName,String appName)
|
||||
{
|
||||
this.keyId = keyId;
|
||||
this.issuer = userId;
|
||||
this.subject = appName;
|
||||
this.userName = userName;
|
||||
}
|
||||
public String getKeyId()
|
||||
{
|
||||
return keyId;
|
||||
}
|
||||
|
||||
public String getIssuer()
|
||||
{
|
||||
return issuer;
|
||||
}
|
||||
|
||||
public String getUserName()
|
||||
{
|
||||
return userName;
|
||||
}
|
||||
|
||||
public String getSubject()
|
||||
{
|
||||
return subject;
|
||||
}
|
||||
|
||||
public String getJwtId()
|
||||
{
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public long getExpirationTime()
|
||||
{
|
||||
return EXPIRE_TIME;
|
||||
}
|
||||
|
||||
public Map<String,?> getClaimMap()
|
||||
{
|
||||
Map<String,String> claimMap = new HashMap<>();
|
||||
claimMap.put("userid",issuer);
|
||||
claimMap.put("username",userName);
|
||||
claimMap.put("account",userName);
|
||||
return claimMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.sdm.common.entity.pojo.task;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FlowBindTaskPoolItem {
|
||||
|
||||
public String poolName;
|
||||
|
||||
public String version;
|
||||
|
||||
public String flowCode;
|
||||
|
||||
public List<TaskBaseInfo> taskList = new ArrayList<>();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.sdm.common.entity.pojo.task;
|
||||
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
|
||||
public class TaskBaseInfo {
|
||||
|
||||
public String taskName;
|
||||
|
||||
public String taskCode;
|
||||
|
||||
public String uuid;
|
||||
|
||||
public String poolName;
|
||||
|
||||
public String version;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.sdm.common.entity.req.task;
|
||||
|
||||
import com.sdm.common.entity.pojo.task.FlowBindTaskPoolItem;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BindTaskAndFlowTemplateReq {
|
||||
|
||||
@Schema(description = "流程模版编号")
|
||||
@NotBlank(message = "流程模版编号不能为空")
|
||||
public String flowCode;
|
||||
|
||||
@Schema(description = "分析项库中绑定到执行流程的分析项信息")
|
||||
public List<FlowBindTaskPoolItem> bindTaskkPoolItem = new ArrayList<>();
|
||||
}
|
||||
@@ -1,11 +1,18 @@
|
||||
package com.sdm.common.feign.impl.task;
|
||||
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.entity.pojo.task.FlowBindTaskPoolItem;
|
||||
import com.sdm.common.entity.pojo.task.TaskBaseInfo;
|
||||
import com.sdm.common.entity.req.system.LaunchApproveReq;
|
||||
import com.sdm.common.entity.req.task.BindTaskAndFlowTemplateReq;
|
||||
import com.sdm.common.feign.inter.task.ISimuluationTaskPoolFeignClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -30,4 +37,54 @@ public class SimuluationTaskPoolFeignClientImpl implements ISimuluationTaskPoolF
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SdmResponse updateTaskAndFlowTemplate(BindTaskAndFlowTemplateReq req) {
|
||||
SdmResponse response;
|
||||
try {
|
||||
response = simuluationTaskPoolFeignClient.updateTaskAndFlowTemplate(req);
|
||||
if (!response.isSuccess()) {
|
||||
response = SdmResponse.failed("绑定分析项和流程模版失败");
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("绑定分析项和流程模版异常");
|
||||
response = SdmResponse.failed(("绑定分析项和流程模版异常"));
|
||||
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse<List<FlowBindTaskPoolItem>> getFlowTemplateBindTaskRelate(String flowCode) {
|
||||
SdmResponse response;
|
||||
try {
|
||||
response = simuluationTaskPoolFeignClient.getFlowTemplateBindTaskRelate(flowCode);
|
||||
if (!response.isSuccess()) {
|
||||
response = SdmResponse.failed("获取流程模版与分析项的绑定关系失败");
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("获取流程模版与分析项的绑定关系异常");
|
||||
response = SdmResponse.failed(("获取流程模版与分析项的绑定关系异常"));
|
||||
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse<Map<String, TaskBaseInfo>> getTaskPoolTaskMap( long poolId, String version)
|
||||
{
|
||||
SdmResponse response;
|
||||
try {
|
||||
response = simuluationTaskPoolFeignClient.getTaskPoolTaskMap(poolId, version);
|
||||
if (!response.isSuccess()) {
|
||||
response = SdmResponse.failed("获取分析项库");
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("获取分析项库异常");
|
||||
response = SdmResponse.failed(("获取分析项库异常"));
|
||||
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@ public interface IFileSimulationMappingFeignClient {
|
||||
@PostMapping("/getFileSimulationMappingBySimulationPoolIdAndVersionAndTaskId")
|
||||
SdmResponse<List<FileMetadataInfoResp>> getFileSimulationMappingBySimulationPoolIdAndVersionAndTaskId(@RequestBody GetFileSimulationMappingReq getFileSimulationMappingReq);
|
||||
|
||||
@PostMapping("/batchGetFileSimulationMappingBySimulationPoolIdAndVersion")
|
||||
@PostMapping("/fileSimulationMapping/batchGetFileSimulationMappingBySimulationPoolIdAndVersion")
|
||||
SdmResponse<Map<String, List<FileMetadataInfoResp>>> batchGetFileSimulationMappingBySimulationPoolIdAndVersion(@RequestBody GetFileSimulationMappingReq getFileSimulationMappingReq);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package com.sdm.common.feign.inter.task;
|
||||
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.entity.pojo.task.FlowBindTaskPoolItem;
|
||||
import com.sdm.common.entity.pojo.task.TaskBaseInfo;
|
||||
import com.sdm.common.entity.req.system.LaunchApproveReq;
|
||||
import com.sdm.common.entity.req.task.BindTaskAndFlowTemplateReq;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -14,4 +19,18 @@ public interface ISimuluationTaskPoolFeignClient {
|
||||
@PostMapping("/taskpool/approveHandleNotice")
|
||||
SdmResponse receiveApproveNotice(@RequestBody LaunchApproveReq req);
|
||||
|
||||
|
||||
@PostMapping(value = "/taskpool/updateTaskAndFlowTemplate")
|
||||
@ResponseBody
|
||||
SdmResponse updateTaskAndFlowTemplate(@RequestBody BindTaskAndFlowTemplateReq req);
|
||||
|
||||
|
||||
@GetMapping(value = "/taskpool/getFlowTaskRelate")
|
||||
SdmResponse<List<FlowBindTaskPoolItem>> getFlowTemplateBindTaskRelate(@RequestParam("flowCode")String flowCode);
|
||||
|
||||
@GetMapping(value = "/taskpool/getTaskPoolTaskMap")
|
||||
@ResponseBody
|
||||
SdmResponse<Map<String, TaskBaseInfo>> getTaskPoolTaskMap(@RequestParam("poolName") long poolId, @RequestParam("version")String version);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,32 @@
|
||||
package com.sdm.common.utils;
|
||||
|
||||
|
||||
import com.sdm.common.entity.bo.JwtToken;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.interfaces.RSAPrivateKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class SystemOperate {
|
||||
@@ -157,4 +173,90 @@ public class SystemOperate {
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
|
||||
public static PrivateKey getPrivateKey(String key) throws Exception
|
||||
{
|
||||
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(key.getBytes()));
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
return keyFactory.generatePrivate(spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成JWT
|
||||
* @param jwtToken
|
||||
* @param key
|
||||
* @param isUnique
|
||||
* @return
|
||||
*/
|
||||
public static String generateToken(JwtToken jwtToken, String key, boolean isUnique) {
|
||||
|
||||
String token = "";
|
||||
try
|
||||
{
|
||||
PrivateKey privateKey = getPrivateKey(key);
|
||||
Algorithm algorithm = Algorithm.RSA256(null, (RSAPrivateKey) privateKey);
|
||||
|
||||
Date issuedAt = new Date();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(issuedAt);
|
||||
issuedAt = calendar.getTime();
|
||||
// 未设置过期时间,则默认签发时间后10分钟内有效
|
||||
Date expiresAt = new Date(issuedAt.getTime() + (jwtToken.getExpirationTime() <= 0 ? 600000 : jwtToken.getExpirationTime()));
|
||||
token = JWT.create()
|
||||
.withKeyId(jwtToken.getKeyId()) //密钥ID
|
||||
.withIssuer(jwtToken.getUserName()+":"+jwtToken.getIssuer()+":1") //用户名:用户ID:租户
|
||||
.withSubject(jwtToken.getSubject()) //appName
|
||||
.withExpiresAt(expiresAt)
|
||||
.withIssuedAt(issuedAt)
|
||||
.withJWTId(jwtToken.getJwtId()) //随机UUID
|
||||
.withClaim("claimsMap", jwtToken.getClaimMap()) //保持默认值
|
||||
.sign(algorithm);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
private static PublicKey getPublicKey(String publicKeyStr) {
|
||||
byte[] keyBytes = Base64.getDecoder().decode(publicKeyStr);
|
||||
X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory;
|
||||
try {
|
||||
keyFactory = KeyFactory.getInstance("RSA");
|
||||
return keyFactory.generatePublic(x509EncodedKeySpec);
|
||||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean verify( String pubKey, String token) {
|
||||
// 从公钥缓存中获取对应的密钥编号的公钥
|
||||
PublicKey publicKey =getPublicKey(pubKey);
|
||||
try {
|
||||
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey) publicKey, null);
|
||||
DecodedJWT decodedJwt = JWT.require(algorithm).ignoreIssuedAt().build().verify(token);
|
||||
Date expiresAt = decodedJwt.getExpiresAt();
|
||||
// 验证token是否过期
|
||||
if (expiresAt.before(new Date())) {
|
||||
return false;
|
||||
}
|
||||
// 验证自己是否为接收方
|
||||
List<String> audience = decodedJwt.getAudience();
|
||||
if (audience != null && !audience.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user