Skip to content

Commit

Permalink
refactor(open): 重构及优化应用管理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Nov 17, 2024
1 parent 3116836 commit d1b3824
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import top.continew.starter.security.crypto.autoconfigure.CryptoProperties;
import top.continew.starter.security.crypto.encryptor.AesEncryptor;
import top.continew.starter.security.crypto.encryptor.IEncryptor;

import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -40,6 +41,18 @@ public class SecureUtils {
private SecureUtils() {
}

/**
* 公钥加密
*
* @param data 要加密的内容
* @return 加密后的内容
*/
public static String encryptByRsaPublicKey(String data) {
String publicKey = RsaProperties.PUBLIC_KEY;
ValidationUtils.throwIfBlank(publicKey, "请配置 RSA 公钥");
return encryptByRsaPublicKey(data, publicKey);
}

/**
* 私钥解密
*
Expand All @@ -52,6 +65,17 @@ public static String decryptByRsaPrivateKey(String data) {
return decryptByRsaPrivateKey(data, privateKey);
}

/**
* 公钥加密
*
* @param data 要加密的内容
* @param publicKey 公钥
* @return 加密后的内容
*/
public static String encryptByRsaPublicKey(String data, String publicKey) {
return new String(SecureUtil.rsa(null, publicKey).encrypt(data, KeyType.PublicKey));
}

/**
* 私钥解密
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@

package top.continew.admin.open.model.entity;

import java.io.Serial;
import java.time.*;

import lombok.Data;

import com.baomidou.mybatisplus.annotation.TableName;

import lombok.Data;
import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.starter.extension.crud.model.entity.BaseDO;
import top.continew.starter.security.crypto.annotation.FieldEncrypt;

import java.io.Serial;
import java.time.LocalDateTime;

/**
* 应用实体
*
* @author chengzi
* @author Charles7c
* @since 2024/10/17 16:03
*/
@Data
Expand All @@ -39,42 +40,34 @@ public class AppDO extends BaseDO {
private static final long serialVersionUID = 1L;

/**
* ID
*/
private Long id;

/**
* 应用名称
* 名称
*/
private String name;

/**
* APPKEY
*/
private String appKey;

/**
* APPSECRET
* Access Key(访问密钥)
*/
private String appSecret;
@FieldEncrypt
private String accessKey;

/**
* 应用状态
* Secret Key(私有密钥)
*/
private String status;
@FieldEncrypt
private String secretKey;

/**
* 失效时间
*/
private LocalDateTime expirationTime;
private LocalDateTime expireTime;

/**
* 应用描述
* 描述
*/
private String appDesc;
private String description;

/**
* secret查看状态
* 状态
*/
private String secretStatus;
private DisEnableStatusEnum status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@

package top.continew.admin.open.model.query;

import java.io.Serial;
import java.io.Serializable;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;
import top.continew.starter.data.core.annotation.Query;
import top.continew.starter.data.core.enums.QueryType;

import java.io.Serial;
import java.io.Serializable;

/**
* 应用查询条件
*
* @author chengzi
* @author Charles7c
* @since 2024/10/17 16:03
*/
@Data
Expand All @@ -40,16 +39,9 @@ public class AppQuery implements Serializable {
private static final long serialVersionUID = 1L;

/**
* 应用名称
*/
@Schema(description = "应用名称")
@Query(type = QueryType.LIKE)
private String name;

/**
* APPKEY
* 关键词
*/
@Schema(description = "APPKEY")
@Query(type = QueryType.LIKE)
private String appKey;
@Schema(description = "关键词", example = "应用1")
@Query(columns = {"name", "description"}, type = QueryType.LIKE)
private String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,68 @@

package top.continew.admin.open.model.req;

import java.io.Serial;
import java.time.*;

import jakarta.validation.constraints.*;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.starter.extension.crud.model.req.BaseReq;

import java.io.Serial;
import java.time.LocalDateTime;

/**
* 创建或修改应用信息
* 创建或修改应用参数
*
* @author chengzi
* @author Charles7c
* @since 2024/10/17 16:03
*/
@Data
@Schema(description = "创建或修改应用信息")
@Schema(description = "创建或修改应用参数")
public class AppReq extends BaseReq {

@Serial
private static final long serialVersionUID = 1L;

/**
* 应用名称
* 名称
*/
@Schema(description = "应用名称")
@NotBlank(message = "应用名称不能为空")
@Length(max = 255, message = "应用名称长度不能超过 {max} 个字符")
@Schema(description = "名称", example = "应用1")
@NotBlank(message = "名称不能为空")
@Length(max = 100, message = "名称长度不能超过 {max} 个字符")
private String name;

/**
* APPKEY
* 失效时间
*/
@Schema(description = "应用密钥")
@NotBlank(message = "应用密钥不能为空")
@Length(max = 255, message = "应用密钥长度不能超过 {max} 个字符")
private String appKey;
@Schema(description = "失效时间", example = "2023-08-08 23:59:59", type = "string")
@Future(message = "失效时间必须是未来时间")
private LocalDateTime expireTime;

/**
* 应用状态
* 描述
*/
@Schema(description = "应用状态")
@NotBlank(message = "应用状态不能为空")
@Length(max = 255, message = "应用状态长度不能超过 {max} 个字符")
private String status;
@Schema(description = "描述", example = "应用1描述信息")
@Length(max = 200, message = "描述长度不能超过 {max} 个字符")
private String description;

/**
* 失效时间
* 状态
*/
@Schema(description = "状态", example = "1")
private DisEnableStatusEnum status;

/**
* Access Key(访问密钥)
*/
@Schema(description = "失效时间")
@NotNull(message = "失效时间不能为空")
private LocalDateTime expirationTime;
@Schema(hidden = true)
private String accessKey;

/**
* 应用描述
* Secret Key(密钥)
*/
@Schema(description = "应用描述")
@Length(max = 255, message = "应用描述长度不能超过 {max} 个字符")
private String appDesc;
@Schema(hidden = true)
private String secretKey;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

package top.continew.admin.open.model.resp;

import java.io.Serial;
import java.time.*;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
import top.continew.starter.file.excel.converter.ExcelBaseEnumConverter;

import java.io.Serial;
import java.time.LocalDateTime;

/**
* 应用详情信息
*
* @author chengzi
* @author Charles7c
* @since 2024/10/17 16:03
*/
@Data
Expand All @@ -43,37 +43,37 @@ public class AppDetailResp extends BaseDetailResp {
private static final long serialVersionUID = 1L;

/**
* 应用名称
* 名称
*/
@Schema(description = "应用名称")
@ExcelProperty(value = "应用名称")
@Schema(description = "名称", example = "应用1")
@ExcelProperty(value = "名称", order = 2)
private String name;

/**
* 应用密钥
* Access Key(访问密钥)
*/
@Schema(description = "应用密钥")
@ExcelProperty(value = "应用密钥")
private String appKey;
@Schema(description = "Access Key(访问密钥)", example = "YjUyMGJjYjIxNTE0NDAxMWE1NmRiY2")
@ExcelProperty(value = "Access Key", order = 3)
private String accessKey;

/**
* 应用状态
* 失效时间
*/
@Schema(description = "应用状态")
@ExcelProperty(value = "应用状态")
private String status;
@Schema(description = "失效时间", example = "2023-08-08 08:08:08", type = "string")
@ExcelProperty(value = "失效时间", order = 4)
private LocalDateTime expireTime;

/**
* 失效时间
* 状态
*/
@Schema(description = "失效时间")
@ExcelProperty(value = "失效时间")
private LocalDateTime expirationTime;
@Schema(description = "状态", example = "1")
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class, order = 5)
private DisEnableStatusEnum status;

/**
* 应用描述
* 描述
*/
@Schema(description = "应用描述")
@ExcelProperty(value = "应用描述")
private String appDesc;
@Schema(description = "描述", example = "应用1描述信息")
@ExcelProperty(value = "描述", order = 6)
private String description;
}
Loading

0 comments on commit d1b3824

Please sign in to comment.