合并sso分支
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package org.nl.common;
|
||||
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表格分页数据对象
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class TableDataInfo<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
private long totalElements;
|
||||
|
||||
/**
|
||||
* 列表数据
|
||||
*/
|
||||
private List<T> content;
|
||||
|
||||
/**
|
||||
* 消息状态码
|
||||
*/
|
||||
private int code;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param list 列表数据
|
||||
* @param total 总记录数
|
||||
*/
|
||||
public TableDataInfo(List<T> list, long total) {
|
||||
this.content = list;
|
||||
this.totalElements = total;
|
||||
}
|
||||
|
||||
public static <T> TableDataInfo<T> build(IPage<T> page) {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(HttpStatus.HTTP_OK);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setContent(page.getRecords());
|
||||
rspData.setTotalElements(page.getTotal());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
public static <T> TableDataInfo<T> build(List<T> list) {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(HttpStatus.HTTP_OK);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setContent(list);
|
||||
rspData.setTotalElements(list.size());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
public static <T> TableDataInfo<T> build() {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(HttpStatus.HTTP_OK);
|
||||
rspData.setMsg("查询成功");
|
||||
return rspData;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.nl.common.domain.constant;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/26 9:29 上午
|
||||
*/
|
||||
public class DictConstantPool {
|
||||
|
||||
public static final String DICT_SYS_CODE = "system_type";
|
||||
public static final String DICT_SYS_NAME = "所属系统";
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.nl.common.domain.entity;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019年10月24日20:48:53
|
||||
*/
|
||||
@Data
|
||||
public class BaseDto implements Serializable {
|
||||
|
||||
private String create_name;
|
||||
|
||||
private String create_id;
|
||||
|
||||
private String update_optname;
|
||||
|
||||
private String update_optid;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date create_time;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date update_time;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package org.nl.common.domain.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: Redis Key 定义类
|
||||
* @Date: 2022-08-04
|
||||
*/
|
||||
@Data
|
||||
public class RedisKeyDefine {
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum KeyTypeEnum {
|
||||
|
||||
STRING("String"),
|
||||
LIST("List"),
|
||||
HASH("Hash"),
|
||||
SET("Set"),
|
||||
ZSET("Sorted Set"),
|
||||
STREAM("Stream"),
|
||||
PUBSUB("Pub/Sub");
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@JsonValue
|
||||
private final String type;
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum TimeoutTypeEnum {
|
||||
|
||||
FOREVER(1), // 永不超时
|
||||
DYNAMIC(2), // 动态超时
|
||||
FIXED(3); // 固定超时
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@JsonValue
|
||||
private final Integer type;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Key 模板
|
||||
*/
|
||||
private final String keyTemplate;
|
||||
/**
|
||||
* Key 类型的枚举
|
||||
*/
|
||||
private final KeyTypeEnum keyType;
|
||||
/**
|
||||
* Value 类型
|
||||
*
|
||||
* 如果是使用分布式锁,设置为 {@link java.util.concurrent.locks.Lock} 类型
|
||||
*/
|
||||
private final Class<?> valueType;
|
||||
/**
|
||||
* 超时类型
|
||||
*/
|
||||
private final TimeoutTypeEnum timeoutType;
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private final Duration timeout;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private final String memo;
|
||||
|
||||
private RedisKeyDefine(String memo, String keyTemplate, KeyTypeEnum keyType, Class<?> valueType,
|
||||
TimeoutTypeEnum timeoutType, Duration timeout) {
|
||||
this.memo = memo;
|
||||
this.keyTemplate = keyTemplate;
|
||||
this.keyType = keyType;
|
||||
this.valueType = valueType;
|
||||
this.timeout = timeout;
|
||||
this.timeoutType = timeoutType;
|
||||
// 添加注册表
|
||||
RedisKeyRegistry.add(this);
|
||||
}
|
||||
|
||||
public RedisKeyDefine(String memo, String keyTemplate, KeyTypeEnum keyType, Class<?> valueType, Duration timeout) {
|
||||
this(memo, keyTemplate, keyType, valueType, TimeoutTypeEnum.FIXED, timeout);
|
||||
}
|
||||
|
||||
public RedisKeyDefine(String memo, String keyTemplate, KeyTypeEnum keyType, Class<?> valueType, TimeoutTypeEnum timeoutType) {
|
||||
this(memo, keyTemplate, keyType, valueType, timeoutType, Duration.ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化 Key
|
||||
*
|
||||
* 注意,内部采用 {@link String#format(String, Object...)} 实现
|
||||
*
|
||||
* @param args 格式化的参数
|
||||
* @return Key
|
||||
*/
|
||||
public String formatKey(Object... args) {
|
||||
return String.format(keyTemplate, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.nl.common.domain.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: {@link RedisKeyDefine} 注册表
|
||||
* @Date: 2022-08-04
|
||||
*/
|
||||
public class RedisKeyRegistry {
|
||||
/**
|
||||
* Redis RedisKeyDefine 数组
|
||||
*/
|
||||
private static final List<RedisKeyDefine> defines = new ArrayList<>();
|
||||
|
||||
public static void add(RedisKeyDefine define) {
|
||||
defines.add(define);
|
||||
}
|
||||
|
||||
public static List<RedisKeyDefine> list() {
|
||||
return defines;
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return defines.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.nl.common.domain.query;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.ColumnCache;
|
||||
import lombok.Data;
|
||||
import org.nl.common.enums.QueryTEnum;
|
||||
import org.nl.common.utils.MapOf;
|
||||
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/14 6:33 下午
|
||||
* 泛型必须为数据tb对应do:由mybatis管理
|
||||
*/
|
||||
@Data
|
||||
public class BaseQuery<T> {
|
||||
/**
|
||||
* 模糊查询
|
||||
*/
|
||||
private String blurry;
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean isUsed;
|
||||
/**
|
||||
* 创建时间范围查询
|
||||
*/
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
|
||||
|
||||
/**
|
||||
* 字段映射Map:指定字段对应QueryWrapper的查询类型
|
||||
* 字段与数据库字段对应,不支持驼峰
|
||||
* @see QueryTEnum
|
||||
* 通过buid构建
|
||||
*/
|
||||
public Map<String, QParam> doP = MapOf.of("blurry", QParam.builder().k(new String[]{"name"}).type(QueryTEnum.LK).build()
|
||||
,"startTime", QParam.builder().k(new String[]{"create_time"}).type(QueryTEnum.LT).build()
|
||||
,"endTime", QParam.builder().k(new String[]{"create_time"}).type(QueryTEnum.LE).build()
|
||||
,"sort", QParam.builder().k(new String[]{"sort"}).type(QueryTEnum.BY).build()
|
||||
);
|
||||
|
||||
public QueryWrapper<T> build(){
|
||||
this.paramMapping();
|
||||
QueryWrapper<T> wrapper = new QueryWrapper<>();
|
||||
JSONObject json = (JSONObject)JSONObject.toJSON(this);
|
||||
Type[] types = ((ParameterizedTypeImpl) this.getClass().getGenericSuperclass()).getActualTypeArguments();
|
||||
Map<String, ColumnCache> columnMap = LambdaUtils.getColumnMap((Class<?>) types[0]);
|
||||
json.forEach((key, vel) -> {
|
||||
if (vel != null && !key.equals("doP")){
|
||||
QParam qParam = doP.get(key);
|
||||
if (qParam != null){
|
||||
QueryTEnum.build(qParam.type,wrapper,qParam.k,vel);
|
||||
}else {
|
||||
ColumnCache columnCache = columnMap.get(LambdaUtils.formatKey(key));
|
||||
if (columnCache!=null){
|
||||
wrapper.eq(columnCache.getColumn(),vel);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public void paramMapping(){};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.nl.common.domain.query;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/14 8:40 下午
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface LConsumer<X,Y,Z> {
|
||||
|
||||
void accept(X x,Y y,Z z);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package org.nl.common.domain.query;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
* 分页参数
|
||||
*/
|
||||
@Data
|
||||
public class PageQuery implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 分页大小
|
||||
*/
|
||||
private Integer size;
|
||||
|
||||
/**
|
||||
* 当前页数
|
||||
*/
|
||||
private Integer page;
|
||||
|
||||
/**
|
||||
* 排序列
|
||||
*/
|
||||
private String sort;
|
||||
|
||||
/**
|
||||
* 排序的方向desc或者asc
|
||||
*/
|
||||
private Boolean isAsc;
|
||||
|
||||
/**
|
||||
* 当前记录起始索引 默认值
|
||||
*/
|
||||
public static final int DEFAULT_PAGE_NUM = 1;
|
||||
|
||||
/**
|
||||
* 每页显示记录数 默认值 默认查全部
|
||||
*/
|
||||
public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
|
||||
|
||||
public <T> Page<T> build() {
|
||||
Integer pageNum = ObjectUtil.defaultIfNull(getPage(), DEFAULT_PAGE_NUM);
|
||||
Integer pageSize = ObjectUtil.defaultIfNull(getSize(), DEFAULT_PAGE_SIZE);
|
||||
if (pageNum <= 0) {
|
||||
pageNum = DEFAULT_PAGE_NUM;
|
||||
}
|
||||
Page<T> page = new Page<>(pageNum, pageSize);
|
||||
if (StringUtils.isNotEmpty(sort)){
|
||||
String[] split = sort.split(",");
|
||||
for (int i = 0; i < (split.length & ~1); i=i+2) {
|
||||
String col = split[i];
|
||||
OrderItem item = new OrderItem();
|
||||
item.setColumn(col);
|
||||
item.setAsc(split[i+1].toLowerCase(Locale.ROOT).equals("asc"));
|
||||
page.addOrder(item);
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
public <R,T> Page<T> build(Class<R> r) {
|
||||
Integer pageNum = ObjectUtil.defaultIfNull(getPage(), DEFAULT_PAGE_NUM);
|
||||
Integer pageSize = ObjectUtil.defaultIfNull(getSize(), DEFAULT_PAGE_SIZE);
|
||||
if (pageNum <= 0) {
|
||||
pageNum = DEFAULT_PAGE_NUM;
|
||||
}
|
||||
Page<T> page = new Page<>(pageNum, pageSize);
|
||||
if (StringUtils.isNotEmpty(sort)){
|
||||
String[] split = sort.split(",");
|
||||
for (int i = 0; i < (split.length & ~1); i=i+2) {
|
||||
String col = split[i];
|
||||
if ("id".equals(col)){
|
||||
String mId = mappingId(r);
|
||||
col = StringUtils.isNotEmpty(mId)?mId:col;
|
||||
}
|
||||
OrderItem item = new OrderItem();
|
||||
item.setColumn(col);
|
||||
item.setAsc(split[i+1].toLowerCase(Locale.ROOT).equals("asc"));
|
||||
page.addOrder(item);
|
||||
}
|
||||
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
private <R> String mappingId(R r){
|
||||
if (r instanceof Class){
|
||||
Field[] fields = ((Class) r).getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
TableId[] byType = field.getAnnotationsByType(TableId.class);
|
||||
if (byType !=null && byType.length>0){
|
||||
TableId tableId = byType[0];
|
||||
return tableId.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.nl.common.domain.query;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.nl.common.enums.QueryTEnum;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/15 1:41 下午
|
||||
*/
|
||||
@Builder
|
||||
public class QParam {
|
||||
public String[] k;
|
||||
public QueryTEnum type;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.nl.common.enums;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.domain.query.LConsumer;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/14 8:26 下午
|
||||
*/
|
||||
@Getter
|
||||
public enum QueryTEnum {
|
||||
//
|
||||
EQ((q, k, v) -> { q.eq(k[0],v); }),
|
||||
IN((q, key, o) -> { if (o instanceof Collection){ q.in(key[0],(Collection) o); } }),
|
||||
LK((q, keys, o) -> { for (String key : keys) { q.like(key,o); } }),
|
||||
LE((q, k, v) -> { q.le(k[0],v); }),
|
||||
BY((q, k, v) -> { q.orderByDesc(k[0],v); }),
|
||||
NO((q, k, v) -> { q.isNull(k[0]); }),
|
||||
LT((q, k, v) -> { q.lt(k[0],v); }),
|
||||
OREQ((q, k, v) -> { if (StringUtils.isBlank((String)v)){ q.isNull(k[0]); }else { q.eq(k[0],v); } });
|
||||
|
||||
private LConsumer<QueryWrapper,String[], Object> doP;
|
||||
|
||||
QueryTEnum(LConsumer<QueryWrapper,String[], Object> doP) {
|
||||
this.doP = doP;
|
||||
}
|
||||
|
||||
public static void build(QueryTEnum type, QueryWrapper q, String[] k , Object v){
|
||||
type.getDoP().accept(q,k,v);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.nl.common.utils;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/1 3:35 下午
|
||||
*/
|
||||
public class CopyUtil {
|
||||
public static <F, T> List<T> copyList(final Collection<F> sources, final Class<T> clazz) {
|
||||
if (sources == null) {
|
||||
return new ArrayList(0);
|
||||
} else {
|
||||
List<T> list = new ArrayList(sources.size());
|
||||
Iterator var3 = sources.iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
Object source = var3.next();
|
||||
|
||||
try {
|
||||
T dest = clazz.newInstance();
|
||||
BeanUtils.copyProperties(source, dest);
|
||||
list.add(dest);
|
||||
} catch (Throwable var6) {
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package org.nl.common.utils;
|
||||
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.DESKeySpec;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
/**
|
||||
* Des加密解密算法工具类
|
||||
*/
|
||||
public class DesUtil {
|
||||
//加密算法是des
|
||||
private static final String ALGORITHM = "DES";
|
||||
//转换格式
|
||||
private static final String TRANSFORMATION = "DES/CBC/PKCS5Padding";
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param src 数据源
|
||||
* @param key 密钥,长度必须是8的倍数
|
||||
* @return 返回加密后的数据
|
||||
* @throws Exception 出错
|
||||
*/
|
||||
public static byte[] encrypt(byte[] src, byte[] key) throws Exception {
|
||||
// DES算法要求有一个可信任的随机数源
|
||||
SecureRandom sr = new SecureRandom();
|
||||
// 从原始密匙数据建立 DESKeySpec对象
|
||||
DESKeySpec dks = new DESKeySpec(key);
|
||||
// 建立一个密匙工厂,然后用它把DESKeySpec转换成
|
||||
// 一个SecretKey对象
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
|
||||
SecretKey securekey = keyFactory.generateSecret(dks);
|
||||
// Cipher对象实际完成加密操作
|
||||
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
|
||||
// 用密匙原始化Cipher对象
|
||||
cipher.init(Cipher.ENCRYPT_MODE, securekey, new IvParameterSpec(key));
|
||||
// 现在,获取数据并加密
|
||||
// 正式执行加密操作
|
||||
return cipher.doFinal(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param src 数据源
|
||||
* @param key 密钥,长度必须是8的倍数
|
||||
* @return 返回解密后的原始数据
|
||||
* @throws Exception 出错
|
||||
*/
|
||||
public static byte[] decrypt(byte[] src, byte[] key) throws Exception {
|
||||
// DES算法要求有一个可信任的随机数源
|
||||
SecureRandom sr = new SecureRandom();
|
||||
// 从原始密匙数据建立一个DESKeySpec对象
|
||||
DESKeySpec dks = new DESKeySpec(key);
|
||||
// 建立一个密匙工厂,然后用它把DESKeySpec对象转换成
|
||||
// 一个SecretKey对象
|
||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
|
||||
SecretKey securekey = keyFactory.generateSecret(dks);
|
||||
// Cipher对象实际完成解密操作
|
||||
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
|
||||
// 用密匙原始化Cipher对象
|
||||
cipher.init(Cipher.DECRYPT_MODE, securekey, new IvParameterSpec(key));
|
||||
// 现在,获取数据并解密
|
||||
// 正式执行解密操作
|
||||
return cipher.doFinal(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description 根据键值进行加密
|
||||
*
|
||||
* @param data
|
||||
* @param key 加密键byte数组
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encrypt(String data, String key) throws Exception {
|
||||
byte[] bt = encrypt(data.getBytes("UTF-8"), key.getBytes("UTF-8"));
|
||||
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
return encoder.encode(bt);
|
||||
|
||||
//return new String(Base64.encodeBase64(bt), "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* Description 根据键值进行解密
|
||||
*
|
||||
* @param data
|
||||
* @param key 加密键byte数组
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decrypt(String data, String key) throws Exception {
|
||||
if (data == null)
|
||||
return null;
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
byte[] buf = decoder.decodeBuffer(data);
|
||||
|
||||
byte[] bt = decrypt(buf, key.getBytes("UTF-8"));
|
||||
return new String(bt, "UTF-8");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
//uL8fXioyU2M=
|
||||
String key = "11111111";
|
||||
String pp = encrypt("123456", key);
|
||||
System.out.println("加密:" + pp);
|
||||
|
||||
String mm2 = decrypt(pp, key);
|
||||
System.out.println("解密:" + mm2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.nl.common.utils;
|
||||
|
||||
public class IdUtil {
|
||||
public static Long getLongId() {
|
||||
return cn.hutool.core.util.IdUtil.getSnowflake(1, 1).nextId();
|
||||
}
|
||||
|
||||
public static String getStringId() {
|
||||
return String.valueOf(IdUtil.getLongId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.nl.common.utils;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/11/29 2:55 下午
|
||||
*/
|
||||
public class MapOf implements Serializable {
|
||||
|
||||
public static <K> HashMap of(K... key){
|
||||
HashMap map = new HashMap<>();
|
||||
for (int i = 0; i < (key.length & ~1); i=i+2) {
|
||||
map.put(key[i],key[i+1]);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.nl.common.utils;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.system.service.user.dto.CurrentUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: lyd
|
||||
* @description: 获取当前用户的信息 - 前提下在登录之后将数据存储到session
|
||||
* @Date:
|
||||
*/
|
||||
@Slf4j
|
||||
public class SecurityUtils {
|
||||
|
||||
/**
|
||||
* 获取系统用户 - CurrentUser
|
||||
*
|
||||
* @return 系统用户
|
||||
*/
|
||||
public static CurrentUser getCurrentUser() {
|
||||
try {
|
||||
JSONObject json = (JSONObject) StpUtil.getExtra("loginInfo");
|
||||
if (ObjectUtil.isNotEmpty(json)) {
|
||||
return json.toBean(CurrentUser.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new CurrentUser();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统用户名称
|
||||
*
|
||||
* @return 系统用户名称
|
||||
*/
|
||||
public static String getCurrentUsername() {
|
||||
return getCurrentUser().getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统用户名称
|
||||
*
|
||||
* @return 系统用户名称
|
||||
*/
|
||||
public static String getCurrentNickName() {
|
||||
return getCurrentUser().getPresonName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统用户Id
|
||||
*
|
||||
* @return 系统用户Id
|
||||
*/
|
||||
public static String getCurrentUserId() {
|
||||
return getCurrentUser().getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统用户Id
|
||||
*
|
||||
* @return 系统用户Id
|
||||
*/
|
||||
public static Long getDeptId() {
|
||||
// return getCurrentUser().getUser().getDept().getId();
|
||||
return 1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户权限
|
||||
*
|
||||
* @return 权限列表
|
||||
*/
|
||||
public static List<String> getCurrentUserPermissions() {
|
||||
JSONObject json = (JSONObject) StpUtil.getExtra("loginInfo");
|
||||
JSONArray permissions = json.getJSONArray("permissions");
|
||||
if (permissions.size() > 0) {
|
||||
return permissions.toList(String.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user