remove
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.cache;
|
||||
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
|
||||
/**
|
||||
* 缓存名
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface CacheNames {
|
||||
|
||||
/**
|
||||
* 返回拼接后的key
|
||||
*
|
||||
* @param cacheKey 缓存key
|
||||
* @param cacheKeyValue 缓存key值
|
||||
* @return tenantKey
|
||||
*/
|
||||
static String cacheKey(String cacheKey, String cacheKeyValue) {
|
||||
return cacheKey.concat(cacheKeyValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回租户格式的key
|
||||
*
|
||||
* @param tenantId 租户编号
|
||||
* @param cacheKey 缓存key
|
||||
* @param cacheKeyValue 缓存key值
|
||||
* @return tenantKey
|
||||
*/
|
||||
static String tenantKey(String tenantId, String cacheKey, String cacheKeyValue) {
|
||||
return tenantId.concat(StringPool.COLON).concat(cacheKey).concat(cacheKeyValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码key
|
||||
*/
|
||||
String CAPTCHA_KEY = "blade:auth::blade:captcha:";
|
||||
|
||||
/**
|
||||
* 账号失败key
|
||||
*/
|
||||
String ACCOUNT_FAIL_KEY = "blade:lock::account:fail:";
|
||||
|
||||
/**
|
||||
* IP失败key
|
||||
*/
|
||||
String IP_FAIL_KEY = "blade:lock::ip:fail:";
|
||||
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.cache;
|
||||
|
||||
import org.springblade.common.enums.DictBizEnum;
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.utils.SpringUtil;
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
import org.springblade.modules.system.pojo.entity.DictBiz;
|
||||
import org.springblade.modules.system.service.IDictBizService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.DICT_CACHE;
|
||||
|
||||
/**
|
||||
* 业务字典缓存工具类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class DictBizCache {
|
||||
|
||||
private static final String DICT_ID = "dictBiz:id";
|
||||
private static final String DICT_VALUE = "dictBiz:value";
|
||||
private static final String DICT_LIST = "dictBiz:list";
|
||||
|
||||
private static final IDictBizService dictService;
|
||||
|
||||
static {
|
||||
dictService = SpringUtil.getBean(IDictBizService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典实体
|
||||
*
|
||||
* @param id 主键
|
||||
* @return DictBiz
|
||||
*/
|
||||
public static DictBiz getById(Long id) {
|
||||
String keyPrefix = DICT_ID.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
|
||||
return CacheUtil.get(DICT_CACHE, keyPrefix, id, () -> dictService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
*
|
||||
* @param code 字典编号枚举
|
||||
* @param dictKey Integer型字典键
|
||||
* @return String
|
||||
*/
|
||||
public static String getValue(DictBizEnum code, Integer dictKey) {
|
||||
return getValue(code.getName(), dictKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
*
|
||||
* @param code 字典编号
|
||||
* @param dictKey Integer型字典键
|
||||
* @return String
|
||||
*/
|
||||
public static String getValue(String code, Integer dictKey) {
|
||||
String keyPrefix = DICT_VALUE.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
|
||||
return CacheUtil.get(DICT_CACHE, keyPrefix + code + StringPool.COLON, String.valueOf(dictKey), () -> dictService.getValue(code, String.valueOf(dictKey)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
*
|
||||
* @param code 字典编号枚举
|
||||
* @param dictKey String型字典键
|
||||
* @return String
|
||||
*/
|
||||
public static String getValue(DictBizEnum code, String dictKey) {
|
||||
return getValue(code.getName(), dictKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
*
|
||||
* @param code 字典编号
|
||||
* @param dictKey String型字典键
|
||||
* @return String
|
||||
*/
|
||||
public static String getValue(String code, String dictKey) {
|
||||
String keyPrefix = DICT_VALUE.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
|
||||
return CacheUtil.get(DICT_CACHE, keyPrefix + code + StringPool.COLON, dictKey, () -> dictService.getValue(code, dictKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典集合
|
||||
*
|
||||
* @param code 字典编号
|
||||
* @return List<DictBiz>
|
||||
*/
|
||||
public static List<DictBiz> getList(String code) {
|
||||
String keyPrefix = DICT_LIST.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
|
||||
return CacheUtil.get(DICT_CACHE, keyPrefix, code, () -> dictService.getList(code));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.cache;
|
||||
|
||||
import org.springblade.common.enums.DictEnum;
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.tool.utils.SpringUtil;
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
import org.springblade.modules.system.pojo.entity.Dict;
|
||||
import org.springblade.modules.system.service.IDictService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.DICT_CACHE;
|
||||
|
||||
/**
|
||||
* 字典缓存工具类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class DictCache {
|
||||
|
||||
private static final String DICT_ID = "dict:id:";
|
||||
private static final String DICT_KEY = "dict:key:";
|
||||
private static final String DICT_VALUE = "dict:value:";
|
||||
private static final String DICT_LIST = "dict:list:";
|
||||
|
||||
private static final Boolean TENANT_MODE = Boolean.FALSE;
|
||||
|
||||
private static final IDictService dictService;
|
||||
|
||||
static {
|
||||
dictService = SpringUtil.getBean(IDictService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典实体
|
||||
*
|
||||
* @param id 主键
|
||||
* @return Dict
|
||||
*/
|
||||
public static Dict getById(Long id) {
|
||||
return CacheUtil.get(DICT_CACHE, DICT_ID, id, () -> dictService.getById(id), TENANT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
*
|
||||
* @param code 字典编号枚举
|
||||
* @param dictValue 字典值
|
||||
* @return String
|
||||
*/
|
||||
public static String getKey(DictEnum code, String dictValue) {
|
||||
return getKey(code.getName(), dictValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典键
|
||||
*
|
||||
* @param code 字典编号
|
||||
* @param dictValue 字典值
|
||||
* @return String
|
||||
*/
|
||||
public static String getKey(String code, String dictValue) {
|
||||
return CacheUtil.get(DICT_CACHE, DICT_KEY + code + StringPool.COLON, dictValue, () -> {
|
||||
List<Dict> list = getList(code);
|
||||
Optional<String> key = list.stream().filter(
|
||||
dict -> dict.getDictValue().equalsIgnoreCase(dictValue)
|
||||
).map(Dict::getDictKey).findFirst();
|
||||
return key.orElse(StringPool.EMPTY);
|
||||
}, TENANT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
*
|
||||
* @param code 字典编号枚举
|
||||
* @param dictKey Integer型字典键
|
||||
* @return String
|
||||
*/
|
||||
public static String getValue(DictEnum code, Integer dictKey) {
|
||||
return getValue(code.getName(), dictKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
*
|
||||
* @param code 字典编号
|
||||
* @param dictKey Integer型字典键
|
||||
* @return String
|
||||
*/
|
||||
public static String getValue(String code, Integer dictKey) {
|
||||
return CacheUtil.get(DICT_CACHE, DICT_VALUE + code + StringPool.COLON, String.valueOf(dictKey), () -> dictService.getValue(code, String.valueOf(dictKey)), TENANT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
*
|
||||
* @param code 字典编号枚举
|
||||
* @param dictKey String型字典键
|
||||
* @return String
|
||||
*/
|
||||
public static String getValue(DictEnum code, String dictKey) {
|
||||
return getValue(code.getName(), dictKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典值
|
||||
*
|
||||
* @param code 字典编号
|
||||
* @param dictKey String型字典键
|
||||
* @return String
|
||||
*/
|
||||
public static String getValue(String code, String dictKey) {
|
||||
return CacheUtil.get(DICT_CACHE, DICT_VALUE + code + StringPool.COLON, dictKey, () -> dictService.getValue(code, dictKey), TENANT_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典集合
|
||||
*
|
||||
* @param code 字典编号
|
||||
* @return List<Dict>
|
||||
*/
|
||||
public static List<Dict> getList(String code) {
|
||||
return CacheUtil.get(DICT_CACHE, DICT_LIST, code, () -> dictService.getList(code), TENANT_MODE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.cache;
|
||||
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.tool.utils.SpringUtil;
|
||||
import org.springblade.modules.system.pojo.entity.Param;
|
||||
import org.springblade.modules.system.service.IParamService;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.PARAM_CACHE;
|
||||
|
||||
/**
|
||||
* 参数缓存工具类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class ParamCache {
|
||||
|
||||
private static final String PARAM_ID = "param:id:";
|
||||
private static final String PARAM_VALUE = "param:value:";
|
||||
|
||||
private static final IParamService paramService;
|
||||
|
||||
static {
|
||||
paramService = SpringUtil.getBean(IParamService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数实体
|
||||
*
|
||||
* @param id 主键
|
||||
* @return Param
|
||||
*/
|
||||
public static Param getById(Long id) {
|
||||
return CacheUtil.get(PARAM_CACHE, PARAM_ID, id, () -> paramService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数配置
|
||||
*
|
||||
* @param paramKey 参数值
|
||||
* @return String
|
||||
*/
|
||||
public static String getValue(String paramKey) {
|
||||
return CacheUtil.get(PARAM_CACHE, PARAM_VALUE, paramKey, () -> paramService.getValue(paramKey));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.cache;
|
||||
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.tool.utils.SpringUtil;
|
||||
import org.springblade.modules.system.pojo.entity.Region;
|
||||
import org.springblade.modules.system.service.IRegionService;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
|
||||
|
||||
/**
|
||||
* 行政区划缓存工具类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class RegionCache {
|
||||
public static final String MAIN_CODE = "00";
|
||||
public static final int PROVINCE_LEVEL = 1;
|
||||
public static final int CITY_LEVEL = 2;
|
||||
public static final int DISTRICT_LEVEL = 3;
|
||||
public static final int TOWN_LEVEL = 4;
|
||||
public static final int VILLAGE_LEVEL = 5;
|
||||
|
||||
private static final String REGION_CODE = "region:code:";
|
||||
|
||||
private static final IRegionService regionService;
|
||||
|
||||
static {
|
||||
regionService = SpringUtil.getBean(IRegionService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取行政区划实体
|
||||
*
|
||||
* @param code 区划编号
|
||||
* @return Param
|
||||
*/
|
||||
public static Region getByCode(String code) {
|
||||
return CacheUtil.get(SYS_CACHE, REGION_CODE, code, () -> regionService.getById(code));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,334 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.cache;
|
||||
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.mp.enums.StatusType;
|
||||
import org.springblade.core.tool.utils.SpringUtil;
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
import org.springblade.modules.system.pojo.entity.*;
|
||||
import org.springblade.modules.system.service.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
|
||||
|
||||
/**
|
||||
* 系统缓存
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class SysCache {
|
||||
private static final String MENU_ID = "menu:id:";
|
||||
private static final String DEPT_ID = "dept:id:";
|
||||
private static final String DEPT_NAME = "dept:name:";
|
||||
private static final String DEPT_NAME_FUZZY = "dept:nameFuzzy:";
|
||||
private static final String DEPT_NAME_ID = "deptName:id:";
|
||||
private static final String DEPT_NAMES_ID = "deptNames:id:";
|
||||
private static final String DEPT_CHILD_ID = "deptChild:id:";
|
||||
private static final String DEPT_CHILDIDS_ID = "deptChildIds:id:";
|
||||
private static final String POST_ID = "post:id:";
|
||||
private static final String POST_NAME = "post:name:";
|
||||
private static final String POST_NAME_FUZZY = "post:nameFuzzy:";
|
||||
private static final String POST_NAME_ID = "postName:id:";
|
||||
private static final String POST_NAMES_ID = "postNames:id:";
|
||||
private static final String ROLE_ID = "role:id:";
|
||||
private static final String ROLE_NAME = "role:name:";
|
||||
private static final String ROLE_NAME_ID = "roleName:id:";
|
||||
private static final String ROLE_NAMES_ID = "roleNames:id:";
|
||||
private static final String ROLE_ALIAS_ID = "roleAlias:id:";
|
||||
private static final String ROLE_ALIASES_ID = "roleAliases:id:";
|
||||
public static final String TENANT_ID = "tenant:id:";
|
||||
public static final String TENANT_TENANT_ID = "tenant:tenantId:";
|
||||
public static final String TENANT_PACKAGE_ID = "tenant:packageId:";
|
||||
|
||||
private static final IMenuService menuService;
|
||||
private static final IDeptService deptService;
|
||||
private static final IPostService postService;
|
||||
private static final IRoleService roleService;
|
||||
private static final ITenantService tenantService;
|
||||
private static final ITenantPackageService tenantPackageService;
|
||||
|
||||
static {
|
||||
menuService = SpringUtil.getBean(IMenuService.class);
|
||||
deptService = SpringUtil.getBean(IDeptService.class);
|
||||
postService = SpringUtil.getBean(IPostService.class);
|
||||
roleService = SpringUtil.getBean(IRoleService.class);
|
||||
tenantService = SpringUtil.getBean(ITenantService.class);
|
||||
tenantPackageService = SpringUtil.getBean(ITenantPackageService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 菜单
|
||||
*/
|
||||
public static Menu getMenu(Long id) {
|
||||
return CacheUtil.get(SYS_CACHE, MENU_ID, id, () -> menuService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 部门
|
||||
*/
|
||||
public static Dept getDept(Long id) {
|
||||
return CacheUtil.get(SYS_CACHE, DEPT_ID, id, () -> deptService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门id
|
||||
*
|
||||
* @param tenantId 租户id
|
||||
* @param deptNames 部门名
|
||||
* @return 部门id
|
||||
*/
|
||||
public static String getDeptIds(String tenantId, String deptNames) {
|
||||
return CacheUtil.get(SYS_CACHE, DEPT_NAME, tenantId + StringPool.DASH + deptNames, () -> deptService.getDeptIds(tenantId, deptNames));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门id
|
||||
*
|
||||
* @param tenantId 租户id
|
||||
* @param deptNames 部门名模糊查询
|
||||
* @return 部门id
|
||||
*/
|
||||
public static String getDeptIdsByFuzzy(String tenantId, String deptNames) {
|
||||
return CacheUtil.get(SYS_CACHE, DEPT_NAME_FUZZY, tenantId + StringPool.DASH + deptNames, () -> deptService.getDeptIdsByFuzzy(tenantId, deptNames));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门名
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 部门名
|
||||
*/
|
||||
public static String getDeptName(Long id) {
|
||||
return CacheUtil.get(SYS_CACHE, DEPT_NAME_ID, id, () -> deptService.getById(id).getDeptName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取部门名集合
|
||||
*
|
||||
* @param deptIds 主键集合
|
||||
* @return 部门名
|
||||
*/
|
||||
public static List<String> getDeptNames(String deptIds) {
|
||||
return CacheUtil.get(SYS_CACHE, DEPT_NAMES_ID, deptIds, () -> deptService.getDeptNames(deptIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子部门集合
|
||||
*
|
||||
* @param deptId 主键
|
||||
* @return 子部门
|
||||
*/
|
||||
public static List<Dept> getDeptChild(Long deptId) {
|
||||
return CacheUtil.get(SYS_CACHE, DEPT_CHILD_ID, deptId, () -> deptService.getDeptChild(deptId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子部门ID集合
|
||||
*
|
||||
* @param deptId 主键
|
||||
* @return 子部门ID
|
||||
*/
|
||||
public static List<Long> getDeptChildIds(Long deptId) {
|
||||
if (deptId == null) {
|
||||
return null;
|
||||
}
|
||||
List<Long> deptIdList = CacheUtil.get(SYS_CACHE, DEPT_CHILDIDS_ID, deptId, List.class);
|
||||
if (deptIdList == null) {
|
||||
deptIdList = new ArrayList<>();
|
||||
List<Dept> deptChild = getDeptChild(deptId);
|
||||
if (deptChild != null) {
|
||||
List<Long> collect = deptChild.stream().map(Dept::getId).collect(Collectors.toList());
|
||||
deptIdList.addAll(collect);
|
||||
}
|
||||
deptIdList.add(deptId);
|
||||
CacheUtil.put(SYS_CACHE, DEPT_CHILDIDS_ID, deptId, deptIdList);
|
||||
}
|
||||
return deptIdList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取岗位
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
public static Post getPost(Long id) {
|
||||
return CacheUtil.get(SYS_CACHE, POST_ID, id, () -> postService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取岗位id
|
||||
*
|
||||
* @param tenantId 租户id
|
||||
* @param postNames 岗位名
|
||||
* @return
|
||||
*/
|
||||
public static String getPostIds(String tenantId, String postNames) {
|
||||
return CacheUtil.get(SYS_CACHE, POST_NAME, tenantId + StringPool.DASH + postNames, () -> postService.getPostIds(tenantId, postNames));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取岗位id
|
||||
*
|
||||
* @param tenantId 租户id
|
||||
* @param postNames 岗位名模糊查询
|
||||
* @return
|
||||
*/
|
||||
public static String getPostIdsByFuzzy(String tenantId, String postNames) {
|
||||
return CacheUtil.get(SYS_CACHE, POST_NAME_FUZZY, tenantId + StringPool.DASH + postNames, () -> postService.getPostIdsByFuzzy(tenantId, postNames));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取岗位名
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 岗位名
|
||||
*/
|
||||
public static String getPostName(Long id) {
|
||||
return CacheUtil.get(SYS_CACHE, POST_NAME_ID, id, () -> postService.getById(id).getPostName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取岗位名集合
|
||||
*
|
||||
* @param postIds 主键集合
|
||||
* @return 岗位名
|
||||
*/
|
||||
public static List<String> getPostNames(String postIds) {
|
||||
return CacheUtil.get(SYS_CACHE, POST_NAMES_ID, postIds, () -> postService.getPostNames(postIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色
|
||||
*
|
||||
* @param id 主键
|
||||
* @return Role
|
||||
*/
|
||||
public static Role getRole(Long id) {
|
||||
return CacheUtil.get(SYS_CACHE, ROLE_ID, id, () -> roleService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色id
|
||||
*
|
||||
* @param tenantId 租户id
|
||||
* @param roleNames 角色名
|
||||
* @return
|
||||
*/
|
||||
public static String getRoleIds(String tenantId, String roleNames) {
|
||||
return CacheUtil.get(SYS_CACHE, ROLE_NAME, tenantId + StringPool.DASH + roleNames, () -> roleService.getRoleIds(tenantId, roleNames));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色名
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 角色名
|
||||
*/
|
||||
public static String getRoleName(Long id) {
|
||||
return CacheUtil.get(SYS_CACHE, ROLE_NAME_ID, id, () -> roleService.getById(id).getRoleName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色名集合
|
||||
*
|
||||
* @param roleIds 主键集合
|
||||
* @return 角色名
|
||||
*/
|
||||
public static List<String> getRoleNames(String roleIds) {
|
||||
return CacheUtil.get(SYS_CACHE, ROLE_NAMES_ID, roleIds, () -> roleService.getRoleNames(roleIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色别名
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 角色别名
|
||||
*/
|
||||
public static String getRoleAlias(Long id) {
|
||||
return CacheUtil.get(SYS_CACHE, ROLE_ALIAS_ID, id, () -> roleService.getById(id).getRoleAlias());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色别名集合
|
||||
*
|
||||
* @param roleIds 主键集合
|
||||
* @return 角色别名
|
||||
*/
|
||||
public static List<String> getRoleAliases(String roleIds) {
|
||||
return CacheUtil.get(SYS_CACHE, ROLE_ALIASES_ID, roleIds, () -> roleService.getRoleAliases(roleIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户
|
||||
*
|
||||
* @param id 主键
|
||||
* @return Tenant
|
||||
*/
|
||||
public static Tenant getTenant(Long id) {
|
||||
return CacheUtil.get(SYS_CACHE, TENANT_ID, id, () -> Optional.ofNullable(tenantService.getById(id))
|
||||
.filter(tenant -> tenant.getStatus() != null)
|
||||
.filter(tenant -> tenant.getStatus() == StatusType.ACTIVE.getType())
|
||||
.orElse(null), Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户
|
||||
*
|
||||
* @param tenantId 租户id
|
||||
* @return Tenant
|
||||
*/
|
||||
public static Tenant getTenant(String tenantId) {
|
||||
return CacheUtil.get(SYS_CACHE, TENANT_TENANT_ID, tenantId, () -> Optional.ofNullable(tenantService.getByTenantId(tenantId))
|
||||
.filter(tenant -> tenant.getStatus() != null)
|
||||
.filter(tenant -> tenant.getStatus() == StatusType.ACTIVE.getType())
|
||||
.orElse(null), Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户产品包
|
||||
*
|
||||
* @param tenantId 租户id
|
||||
* @return Tenant
|
||||
*/
|
||||
public static TenantPackage getTenantPackage(String tenantId) {
|
||||
Tenant tenant = getTenant(tenantId);
|
||||
return CacheUtil.get(SYS_CACHE, TENANT_PACKAGE_ID, tenantId, () -> tenantPackageService.getById(tenant.getPackageId()), Boolean.FALSE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.cache;
|
||||
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.SpringUtil;
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.modules.system.pojo.entity.User;
|
||||
import org.springblade.modules.system.service.IUserService;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE;
|
||||
import static org.springblade.core.launch.constant.FlowConstant.TASK_USR_PREFIX;
|
||||
|
||||
/**
|
||||
* 系统缓存
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class UserCache {
|
||||
private static final String USER_CACHE_ID = "user:id:";
|
||||
private static final String USER_CACHE_ACCOUNT = "user:account:";
|
||||
|
||||
private static final IUserService userService;
|
||||
|
||||
static {
|
||||
userService = SpringUtil.getBean(IUserService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据任务用户id获取用户信息
|
||||
*
|
||||
* @param taskUserId 任务用户id
|
||||
* @return
|
||||
*/
|
||||
public static User getUserByTaskUser(String taskUserId) {
|
||||
Long userId = Func.toLong(StringUtil.removePrefix(taskUserId, TASK_USR_PREFIX));
|
||||
return getUser(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return
|
||||
*/
|
||||
public static User getUser(Long userId) {
|
||||
return CacheUtil.get(USER_CACHE, USER_CACHE_ID, userId, () -> userService.getById(userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
*
|
||||
* @param tenantId 租户id
|
||||
* @param account 账号名
|
||||
* @return
|
||||
*/
|
||||
public static User getUser(String tenantId, String account) {
|
||||
return CacheUtil.get(USER_CACHE, USER_CACHE_ACCOUNT, tenantId + StringPool.DASH + account, () -> userService.userByAccount(tenantId, account));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.config;
|
||||
|
||||
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
import org.springblade.core.oauth2.endpoint.OAuth2SocialEndpoint;
|
||||
import org.springblade.core.oauth2.endpoint.OAuth2TokenEndPoint;
|
||||
import org.springblade.core.secure.provider.HttpMethod;
|
||||
import org.springblade.core.secure.registry.SecureRegistry;
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
import org.springblade.modules.auth.endpoint.Oauth2SmsEndpoint;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* Blade配置
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class BladeConfiguration implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
* 安全框架配置
|
||||
*/
|
||||
@Bean
|
||||
public SecureRegistry secureRegistry() {
|
||||
return new SecureRegistry()
|
||||
// 开启认证配置
|
||||
.enabled()
|
||||
// 令牌严格模式配置
|
||||
.strictTokenEnabled()
|
||||
// 请求头严格模式配置
|
||||
.strictHeaderEnabled()
|
||||
// 认证放行配置
|
||||
.skipUrls(
|
||||
"/blade-auth/**",
|
||||
"/blade-system/tenant/info",
|
||||
"/blade-flow/process/resource-view",
|
||||
"/blade-flow/process/diagram-view",
|
||||
"/blade-flow/manager/check-upload",
|
||||
"/blade-resource/sms/endpoint/send-validate",
|
||||
"/doc.html",
|
||||
"/swagger-ui.html",
|
||||
"/static/**",
|
||||
"/webjars/**",
|
||||
"/swagger-resources/**",
|
||||
"/druid/**"
|
||||
)
|
||||
// 认证鉴权配置
|
||||
.authEnabled()
|
||||
.addAuthPattern(HttpMethod.ALL, "/blade-chat/message/**", "hasAuth()")
|
||||
.addAuthPattern(HttpMethod.POST, "/blade-desk/dashboard/upload", "hasTimeAuth(9, 17)")
|
||||
.addAuthPattern(HttpMethod.POST, "/blade-desk/dashboard/submit", "hasAnyRole('administrator', 'admin', 'user')")
|
||||
// 基础认证配置
|
||||
.basicEnabled()
|
||||
.addBasicPattern(HttpMethod.POST, "/blade-desk/dashboard/info", "blade", "blade")
|
||||
// 签名认证配置
|
||||
.signDisabled()
|
||||
.addSignPattern(HttpMethod.POST, "/blade-desk/dashboard/sign", "sha1");
|
||||
}
|
||||
|
||||
/**
|
||||
* 跨域配置
|
||||
*/
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/cors/**")
|
||||
.allowedOriginPatterns("*")
|
||||
.allowedHeaders("*")
|
||||
.allowedMethods("*")
|
||||
.maxAge(3600)
|
||||
.allowCredentials(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给OAuth2服务端添加前缀
|
||||
*/
|
||||
@Override
|
||||
public void configurePathMatch(PathMatchConfigurer configurer) {
|
||||
configurer.addPathPrefix(StringPool.SLASH + AppConstant.APPLICATION_AUTH_NAME,
|
||||
c -> c.isAnnotationPresent(RestController.class) && (
|
||||
OAuth2TokenEndPoint.class.equals(c) || OAuth2SocialEndpoint.class.equals(c) || Oauth2SmsEndpoint.class.equals(c))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
|
||||
package org.springblade.common.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.common.handler.BladePermissionHandler;
|
||||
import org.springblade.common.handler.BladeRecordHandler;
|
||||
import org.springblade.common.handler.BladeScopeModelHandler;
|
||||
import org.springblade.core.datarecord.processor.DataRecordHandler;
|
||||
import org.springblade.core.datascope.handler.ScopeModelHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
* Blade处理器自动配置
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@AllArgsConstructor
|
||||
public class BladeHandlerConfiguration {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Bean
|
||||
public DataRecordHandler dataRecordHandler() {
|
||||
return new BladeRecordHandler(jdbcTemplate);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ScopeModelHandler scopeModelHandler() {
|
||||
return new BladeScopeModelHandler(jdbcTemplate);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BladePermissionHandler permissionHandler() {
|
||||
return new BladePermissionHandler(jdbcTemplate);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
|
||||
package org.springblade.common.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.common.event.ApiLogListener;
|
||||
import org.springblade.common.event.ErrorLogListener;
|
||||
import org.springblade.common.event.UsualLogListener;
|
||||
import org.springblade.core.launch.props.BladeProperties;
|
||||
import org.springblade.core.launch.server.ServerInfo;
|
||||
import org.springblade.modules.system.service.ILogService;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 日志工具自动配置
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@AllArgsConstructor
|
||||
public class BladeLogConfiguration {
|
||||
|
||||
private final ILogService logService;
|
||||
private final ServerInfo serverInfo;
|
||||
private final BladeProperties bladeProperties;
|
||||
|
||||
@Bean(name = "apiLogListener")
|
||||
public ApiLogListener apiLogListener() {
|
||||
return new ApiLogListener(logService, serverInfo, bladeProperties);
|
||||
}
|
||||
|
||||
@Bean(name = "errorEventListener")
|
||||
public ErrorLogListener errorEventListener() {
|
||||
return new ErrorLogListener(logService, serverInfo, bladeProperties);
|
||||
}
|
||||
|
||||
@Bean(name = "usualEventListener")
|
||||
public UsualLogListener usualEventListener() {
|
||||
return new UsualLogListener(logService, serverInfo, bladeProperties);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.config;
|
||||
|
||||
import org.springblade.core.report.datasource.ReportDataSource;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* 报表配置类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(value = "report.enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class BladeReportConfiguration {
|
||||
|
||||
/**
|
||||
* 自定义报表可选数据源
|
||||
*/
|
||||
@Bean
|
||||
public ReportDataSource reportDataSource(DataSource dataSource) {
|
||||
return new ReportDataSource(dataSource);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Swagger配置类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@AllArgsConstructor
|
||||
@ConditionalOnProperty(value = "swagger.enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class SwaggerConfiguration {
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi authApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("授权模块")
|
||||
.packagesToScan(AppConstant.BASE_PACKAGES + ".core.oauth2", AppConstant.BASE_PACKAGES + ".modules.auth")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi sysApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("系统模块")
|
||||
.packagesToScan(AppConstant.BASE_PACKAGES + ".modules.system", AppConstant.BASE_PACKAGES + ".modules.resource")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi flowApi() {
|
||||
// 创建并返回GroupedOpenApi对象
|
||||
return GroupedOpenApi.builder()
|
||||
.group("工作流模块")
|
||||
.packagesToScan(AppConstant.BASE_PACKAGES + ".flow")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.constant;
|
||||
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
|
||||
/**
|
||||
* 通用常量
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface CommonConstant {
|
||||
|
||||
/**
|
||||
* app name
|
||||
*/
|
||||
String APPLICATION_NAME = AppConstant.APPLICATION_NAME_PREFIX + "api";
|
||||
|
||||
/**
|
||||
* sword 系统名
|
||||
*/
|
||||
String SWORD_NAME = "sword";
|
||||
|
||||
/**
|
||||
* saber 系统名
|
||||
*/
|
||||
String SABER_NAME = "saber";
|
||||
|
||||
/**
|
||||
* 顶级父节点id
|
||||
*/
|
||||
Long TOP_PARENT_ID = 0L;
|
||||
|
||||
/**
|
||||
* 顶级父节点名称
|
||||
*/
|
||||
String TOP_PARENT_NAME = "顶级";
|
||||
|
||||
/**
|
||||
* 未封存状态值
|
||||
*/
|
||||
Integer NOT_SEALED_ID = 0;
|
||||
|
||||
/**
|
||||
* 默认密码
|
||||
*/
|
||||
String DEFAULT_PASSWORD = "123456";
|
||||
|
||||
/**
|
||||
* 默认密码参数值
|
||||
*/
|
||||
String DEFAULT_PARAM_PASSWORD = "account.initPassword";
|
||||
|
||||
/**
|
||||
* 默认排序字段
|
||||
*/
|
||||
String SORT_FIELD = "sort";
|
||||
|
||||
/**
|
||||
* 数据权限类型
|
||||
*/
|
||||
Integer DATA_SCOPE_CATEGORY = 1;
|
||||
|
||||
/**
|
||||
* 接口权限类型
|
||||
*/
|
||||
Integer API_SCOPE_CATEGORY = 2;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.constant;
|
||||
|
||||
/**
|
||||
* 字典常量.
|
||||
*
|
||||
* @author zhuangqian
|
||||
*/
|
||||
public interface DictConstant {
|
||||
|
||||
String SEX_CODE = "sex";
|
||||
|
||||
String NOTICE_CODE = "notice";
|
||||
|
||||
String MENU_CATEGORY_CODE = "menu_category";
|
||||
|
||||
String BUTTON_FUNC_CODE = "button_func";
|
||||
|
||||
String YES_NO_CODE = "yes_no";
|
||||
|
||||
String FLOW_CATEGORY_CODE = "flow_category";
|
||||
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.constant;
|
||||
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
|
||||
/**
|
||||
* 启动常量
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface LauncherConstant {
|
||||
|
||||
/**
|
||||
* sentinel dev 地址
|
||||
*/
|
||||
String SENTINEL_DEV_ADDR = "127.0.0.1:8858";
|
||||
|
||||
/**
|
||||
* sentinel prod 地址
|
||||
*/
|
||||
String SENTINEL_PROD_ADDR = "10.211.55.5:8858";
|
||||
|
||||
/**
|
||||
* sentinel test 地址
|
||||
*/
|
||||
String SENTINEL_TEST_ADDR = "172.30.0.58:8858";
|
||||
|
||||
/**
|
||||
* elk dev 地址
|
||||
*/
|
||||
String ELK_DEV_ADDR = "127.0.0.1:9000";
|
||||
|
||||
/**
|
||||
* elk prod 地址
|
||||
*/
|
||||
String ELK_PROD_ADDR = "172.30.0.58:9000";
|
||||
|
||||
/**
|
||||
* elk test 地址
|
||||
*/
|
||||
String ELK_TEST_ADDR = "172.30.0.58:9000";
|
||||
|
||||
/**
|
||||
* 动态获取sentinel地址
|
||||
*
|
||||
* @param profile 环境变量
|
||||
* @return addr
|
||||
*/
|
||||
static String sentinelAddr(String profile) {
|
||||
return switch (profile) {
|
||||
case (AppConstant.PROD_CODE) -> SENTINEL_PROD_ADDR;
|
||||
case (AppConstant.TEST_CODE) -> SENTINEL_TEST_ADDR;
|
||||
default -> SENTINEL_DEV_ADDR;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态获取elk地址
|
||||
*
|
||||
* @param profile 环境变量
|
||||
* @return addr
|
||||
*/
|
||||
static String elkAddr(String profile) {
|
||||
return switch (profile) {
|
||||
case (AppConstant.PROD_CODE) -> ELK_PROD_ADDR;
|
||||
case (AppConstant.TEST_CODE) -> ELK_TEST_ADDR;
|
||||
default -> ELK_DEV_ADDR;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.constant;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 租户常量
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public interface TenantConstant {
|
||||
|
||||
/**
|
||||
* 租户默认密码KEY
|
||||
*/
|
||||
String PASSWORD_KEY = "tenant.default.password";
|
||||
|
||||
/**
|
||||
* 租户默认账号额度KEY
|
||||
*/
|
||||
String ACCOUNT_NUMBER_KEY = "tenant.default.accountNumber";
|
||||
|
||||
/**
|
||||
* 租户默认菜单集合KEY
|
||||
*/
|
||||
String ACCOUNT_MENU_CODE_KEY = "tenant.default.menuCode";
|
||||
|
||||
/**
|
||||
* 租户默认密码
|
||||
*/
|
||||
String DEFAULT_PASSWORD = "123456";
|
||||
|
||||
/**
|
||||
* 租户授权码默认16位密钥
|
||||
*/
|
||||
String DES_KEY = "0000000000000000";
|
||||
|
||||
/**
|
||||
* 租户默认账号额度
|
||||
*/
|
||||
Integer DEFAULT_ACCOUNT_NUMBER = -1;
|
||||
|
||||
/**
|
||||
* 租户默认菜单集合
|
||||
*/
|
||||
List<String> MENU_CODES = Arrays.asList(
|
||||
"desk", "flow", "work", "monitor", "resource", "role", "user", "dept", "dictbiz", "topmenu"
|
||||
);
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 业务字典枚举类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DictBizEnum {
|
||||
|
||||
/**
|
||||
* 测试
|
||||
*/
|
||||
TEST("test"),
|
||||
;
|
||||
|
||||
final String name;
|
||||
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 系统字典枚举类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DictEnum {
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
SEX("sex"),
|
||||
/**
|
||||
* 通知类型
|
||||
*/
|
||||
NOTICE("notice"),
|
||||
/**
|
||||
* 菜单类型
|
||||
*/
|
||||
MENU_CATEGORY("menu_category"),
|
||||
/**
|
||||
* 按钮功能
|
||||
*/
|
||||
BUTTON_FUNC("button_func"),
|
||||
/**
|
||||
* 是否
|
||||
*/
|
||||
YES_NO("yes_no"),
|
||||
/**
|
||||
* 流程类型
|
||||
*/
|
||||
FLOW("flow"),
|
||||
/**
|
||||
* 机构类型
|
||||
*/
|
||||
ORG_CATEGORY("org_category"),
|
||||
/**
|
||||
* 数据权限
|
||||
*/
|
||||
DATA_SCOPE_TYPE("data_scope_type"),
|
||||
/**
|
||||
* 接口权限
|
||||
*/
|
||||
API_SCOPE_TYPE("api_scope_type"),
|
||||
/**
|
||||
* 权限类型
|
||||
*/
|
||||
SCOPE_CATEGORY("scope_category"),
|
||||
/**
|
||||
* 对象存储类型
|
||||
*/
|
||||
OSS("oss"),
|
||||
/**
|
||||
* 短信服务类型
|
||||
*/
|
||||
SMS("sms"),
|
||||
/**
|
||||
* 岗位类型
|
||||
*/
|
||||
POST_CATEGORY("post_category"),
|
||||
/**
|
||||
* 行政区划
|
||||
*/
|
||||
REGION("region"),
|
||||
/**
|
||||
* 用户平台
|
||||
*/
|
||||
USER_TYPE("user_type"),
|
||||
;
|
||||
|
||||
final String name;
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
|
||||
package org.springblade.common.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.launch.props.BladeProperties;
|
||||
import org.springblade.core.launch.server.ServerInfo;
|
||||
import org.springblade.core.log.constant.EventConstant;
|
||||
import org.springblade.core.log.event.ApiLogEvent;
|
||||
import org.springblade.core.log.model.LogApi;
|
||||
import org.springblade.core.log.utils.LogAbstractUtil;
|
||||
import org.springblade.modules.system.service.ILogService;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 异步监听日志事件
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ApiLogListener {
|
||||
|
||||
private final ILogService logService;
|
||||
private final ServerInfo serverInfo;
|
||||
private final BladeProperties bladeProperties;
|
||||
|
||||
|
||||
@Async
|
||||
@Order
|
||||
@EventListener(ApiLogEvent.class)
|
||||
public void saveApiLog(ApiLogEvent event) {
|
||||
Map<String, Object> source = (Map<String, Object>) event.getSource();
|
||||
LogApi logApi = (LogApi) source.get(EventConstant.EVENT_LOG);
|
||||
LogAbstractUtil.addOtherInfoToLog(logApi, bladeProperties, serverInfo);
|
||||
logService.saveApiLog(logApi);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.event;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.launch.props.BladeProperties;
|
||||
import org.springblade.core.launch.server.ServerInfo;
|
||||
import org.springblade.core.log.constant.EventConstant;
|
||||
import org.springblade.core.log.event.ErrorLogEvent;
|
||||
import org.springblade.core.log.model.LogError;
|
||||
import org.springblade.core.log.utils.LogAbstractUtil;
|
||||
import org.springblade.modules.system.service.ILogService;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 异步监听错误日志事件
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ErrorLogListener {
|
||||
|
||||
private final ILogService logService;
|
||||
private final ServerInfo serverInfo;
|
||||
private final BladeProperties bladeProperties;
|
||||
|
||||
@Async
|
||||
@Order
|
||||
@EventListener(ErrorLogEvent.class)
|
||||
public void saveErrorLog(ErrorLogEvent event) {
|
||||
try {
|
||||
Map<String, Object> source = (Map<String, Object>) event.getSource();
|
||||
LogError logError = (LogError) source.get(EventConstant.EVENT_LOG);
|
||||
LogAbstractUtil.addOtherInfoToLog(logError, bladeProperties, serverInfo);
|
||||
logService.saveErrorLog(logError);
|
||||
} catch (Exception e) {
|
||||
// 可以根据需要进行更多的异常处理,例如发送警报等
|
||||
log.error("保存错误日志时发生异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.event;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.launch.props.BladeProperties;
|
||||
import org.springblade.core.launch.server.ServerInfo;
|
||||
import org.springblade.core.log.constant.EventConstant;
|
||||
import org.springblade.core.log.event.UsualLogEvent;
|
||||
import org.springblade.core.log.model.LogUsual;
|
||||
import org.springblade.core.log.utils.LogAbstractUtil;
|
||||
import org.springblade.modules.system.service.ILogService;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 异步监听日志事件
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class UsualLogListener {
|
||||
|
||||
private final ILogService logService;
|
||||
private final ServerInfo serverInfo;
|
||||
private final BladeProperties bladeProperties;
|
||||
|
||||
@Async
|
||||
@Order
|
||||
@EventListener(UsualLogEvent.class)
|
||||
public void saveUsualLog(UsualLogEvent event) {
|
||||
Map<String, Object> source = (Map<String, Object>) event.getSource();
|
||||
LogUsual logUsual = (LogUsual) source.get(EventConstant.EVENT_LOG);
|
||||
LogAbstractUtil.addOtherInfoToLog(logUsual, bladeProperties, serverInfo);
|
||||
logService.saveUsualLog(logUsual);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
package org.springblade.common.handler;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.secure.BladeUser;
|
||||
import org.springblade.core.secure.handler.IPermissionHandler;
|
||||
import org.springblade.core.secure.provider.PermissionMenu;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
import org.springblade.core.tool.utils.WebUtil;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
|
||||
import static org.springblade.core.secure.constant.PermissionConstant.*;
|
||||
|
||||
/**
|
||||
* 默认授权校验类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
//若开启动态数据源功能,则加上@Master注解指定权限数据库为主库
|
||||
//@Master
|
||||
@AllArgsConstructor
|
||||
public class BladePermissionHandler implements IPermissionHandler {
|
||||
|
||||
private static final String SCOPE_CACHE_ROLE = "apiScope:role:";
|
||||
|
||||
private static final String SCOPE_CACHE_CODE = "apiScope:code:";
|
||||
|
||||
private static final String SCOPE_CACHE_MENU = "apiScope:menu:";
|
||||
|
||||
private static final String SCOPE_CACHE_ALL_MENU = "apiScope:allMenu:permission";
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Override
|
||||
public boolean permissionAll() {
|
||||
HttpServletRequest request = WebUtil.getRequest();
|
||||
BladeUser user = AuthUtil.getUser();
|
||||
if (request == null || user == null) {
|
||||
return false;
|
||||
}
|
||||
String uri = request.getRequestURI();
|
||||
List<String> paths = permissionPath(user.getRoleId());
|
||||
if (paths.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return paths.stream().anyMatch(uri::contains);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
HttpServletRequest request = WebUtil.getRequest();
|
||||
BladeUser user = AuthUtil.getUser();
|
||||
if (request == null || user == null) {
|
||||
return false;
|
||||
}
|
||||
List<String> codes = permissionCode(permission, user.getRoleId());
|
||||
return !codes.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMenu(String permission) {
|
||||
HttpServletRequest request = WebUtil.getRequest();
|
||||
BladeUser user = AuthUtil.getUser();
|
||||
if (request == null || user == null) {
|
||||
return false;
|
||||
}
|
||||
if (AuthUtil.isAdministrator()) {
|
||||
return true;
|
||||
}
|
||||
List<String> codes = permissionMenu(permission, user.getRoleId());
|
||||
return !codes.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口权限地址
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return permissions
|
||||
*/
|
||||
private List<String> permissionPath(String roleId) {
|
||||
List<String> permissions = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_ROLE, roleId, List.class, Boolean.FALSE);
|
||||
if (permissions == null) {
|
||||
List<Long> roleIds = Func.toLongList(roleId);
|
||||
permissions = jdbcTemplate.queryForList(permissionAllStatement(roleIds.size()), String.class, roleIds.toArray());
|
||||
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_ROLE, roleId, permissions, Boolean.FALSE);
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口权限信息
|
||||
*
|
||||
* @param permission 权限编号
|
||||
* @param roleId 角色id
|
||||
* @return permissions
|
||||
*/
|
||||
private List<String> permissionCode(String permission, String roleId) {
|
||||
List<String> permissions = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_CODE, permission + StringPool.COLON + roleId, List.class, Boolean.FALSE);
|
||||
if (permissions == null) {
|
||||
List<Object> args = new ArrayList<>(Collections.singletonList(permission));
|
||||
List<Long> roleIds = Func.toLongList(roleId);
|
||||
args.addAll(roleIds);
|
||||
permissions = jdbcTemplate.queryForList(permissionCodeStatement(roleIds.size()), String.class, args.toArray());
|
||||
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_CODE, permission + StringPool.COLON + roleId, permissions, Boolean.FALSE);
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单权限信息
|
||||
*
|
||||
* @param permission 菜单编号
|
||||
* @param roleId 角色id
|
||||
* @return permissions
|
||||
*/
|
||||
private List<String> permissionMenu(String permission, String roleId) {
|
||||
List<String> permissions = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_MENU, permission + StringPool.COLON + roleId, List.class, Boolean.FALSE);
|
||||
if (permissions == null) {
|
||||
// 获取所有菜单
|
||||
List<PermissionMenu> allMenus = permissionAllMenu();
|
||||
// 获取角色菜单
|
||||
List<Long> roleIds = Func.toLongList(roleId);
|
||||
List<PermissionMenu> roleIdMenus = jdbcTemplate.query(permissionMenuStatement(roleIds.size()), new BeanPropertyRowMapper<>(PermissionMenu.class), roleIds.toArray());
|
||||
// 反向递归角色菜单所有父级
|
||||
List<PermissionMenu> routes = new LinkedList<>(roleIdMenus);
|
||||
roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
|
||||
// 获取匹配的菜单权限值
|
||||
permissions = routes.stream().map(PermissionMenu::getCode).filter(code -> Func.equals(code, permission)).collect(Collectors.toList());
|
||||
// 写入缓存值
|
||||
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_MENU, permission + StringPool.COLON + roleId, permissions, Boolean.FALSE);
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有菜单权限信息
|
||||
*/
|
||||
private List<PermissionMenu> permissionAllMenu() {
|
||||
List<PermissionMenu> permissions = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_ALL_MENU, StringPool.EMPTY, List.class, Boolean.FALSE);
|
||||
if (permissions == null) {
|
||||
permissions = jdbcTemplate.query(permissionAllMenuStatement(), new BeanPropertyRowMapper<>(PermissionMenu.class));
|
||||
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_ALL_MENU, StringPool.EMPTY, permissions, Boolean.FALSE);
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取菜单父级
|
||||
*
|
||||
* @param allMenus 所有菜单合集
|
||||
* @param routes 角色分配的菜单合集
|
||||
* @param roleMenu 当前菜单
|
||||
*/
|
||||
private void recursion(List<PermissionMenu> allMenus, List<PermissionMenu> routes, PermissionMenu roleMenu) {
|
||||
Optional<PermissionMenu> menu = allMenus.stream().filter(x -> Func.equals(x.getId(), roleMenu.getParentId())).findFirst();
|
||||
if (menu.isPresent() && !routes.contains(menu.get())) {
|
||||
routes.add(menu.get());
|
||||
recursion(allMenus, routes, menu.get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.handler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.datarecord.annotation.DataRecord;
|
||||
import org.springblade.core.datarecord.annotation.DataRecordLevel;
|
||||
import org.springblade.core.datarecord.model.DataRecordInfo;
|
||||
import org.springblade.core.datarecord.processor.DataRecordHandler;
|
||||
import org.springblade.core.tool.constant.BladeConstant;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.springblade.core.datarecord.constant.DataRecordConstant.RECORD_INSERT_SQL;
|
||||
|
||||
/**
|
||||
* 日志数据审计处理器
|
||||
* <p>
|
||||
* 将数据审计输出到日志
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
//若开启动态数据源功能,则加上@Master注解指定权限数据库为主库
|
||||
//@Master
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class BladeRecordHandler implements DataRecordHandler {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Override
|
||||
public void handle(DataRecordInfo recordInfo, DataRecord dataRecord) {
|
||||
// 获取格式化的记录信息
|
||||
String recordMessage = formatRecordInfo(recordInfo);
|
||||
// 获取数据审计级别
|
||||
DataRecordLevel level = dataRecord.level();
|
||||
|
||||
// 数据审计入库处理
|
||||
int affectedRows = saveRecordData(recordInfo, level.name(), recordMessage);
|
||||
if (affectedRows > 0) {
|
||||
// 根据配置的日志级别输出
|
||||
switch (level) {
|
||||
case DEBUG:
|
||||
log.debug("数据审计[{}]: {}", recordInfo.getModule(), recordMessage);
|
||||
break;
|
||||
case INFO:
|
||||
log.info("数据审计[{}]: {}", recordInfo.getModule(), recordMessage);
|
||||
break;
|
||||
case WARN:
|
||||
log.warn("数据审计[{}]: {}", recordInfo.getModule(), recordMessage);
|
||||
break;
|
||||
case ERROR:
|
||||
log.error("数据审计[{}]: {}", recordInfo.getModule(), recordMessage);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// 如果入库失败,记录错误日志
|
||||
log.error("数据审计[{}] 保存入库失败", recordInfo.getTableName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化记录信息
|
||||
*
|
||||
* @param recordInfo 记录信息
|
||||
* @return 格式化后的字符串
|
||||
*/
|
||||
private String formatRecordInfo(DataRecordInfo recordInfo) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 添加模块信息
|
||||
sb.append("\n").append("[表名]: ").append(recordInfo.getTableName()).append("\n");
|
||||
sb.append("[操作]: ").append(recordInfo.getOperation()).append("\n");
|
||||
if (recordInfo.getPrimaryKeyValue() != null) {
|
||||
sb.append("[主键]: ").append(recordInfo.getPrimaryKeyValue()).append("\n");
|
||||
}
|
||||
// 添加用户信息
|
||||
if (recordInfo.getUserName() != null) {
|
||||
sb.append("[用户]: ").append(recordInfo.getUserName()).append("\n");
|
||||
}
|
||||
// 添加IP信息
|
||||
if (recordInfo.getRemoteIp() != null) {
|
||||
sb.append("[IP]: ").append(recordInfo.getRemoteIp()).append("\n");
|
||||
}
|
||||
// 添加请求URI
|
||||
if (recordInfo.getRequestUri() != null) {
|
||||
sb.append("[URI]: ").append(recordInfo.getRequestUri()).append("\n");
|
||||
}
|
||||
if (recordInfo.getChangedFields() != null && !recordInfo.getChangedFields().isEmpty()) {
|
||||
sb.append("[变更]: ").append(recordInfo.getChangedFields()).append("\n");
|
||||
}
|
||||
if (recordInfo.getCost() != null) {
|
||||
sb.append("[耗时]: ").append(recordInfo.getCost()).append("ms").append("\n");
|
||||
}
|
||||
// 如果需要详细信息,添加变更详情
|
||||
if (recordInfo.getChangeData() != null && !recordInfo.getChangeData().isEmpty()) {
|
||||
sb.append("[详情]: {");
|
||||
recordInfo.getChangeData().forEach((field, change) -> sb.append(change.getChangeDescription()).append(", "));
|
||||
if (sb.toString().endsWith(", ")) {
|
||||
sb.setLength(sb.length() - 2);
|
||||
}
|
||||
sb.append("}");
|
||||
}
|
||||
return sb.append("\n").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用 JdbcTemplate 保存数据审计记录
|
||||
*
|
||||
* @param recordInfo 记录信息
|
||||
* @param recordLevel 记录级别
|
||||
* @param recordMessage 记录消息
|
||||
* @return 影响的行数
|
||||
*/
|
||||
private int saveRecordData(DataRecordInfo recordInfo, String recordLevel, String recordMessage) {
|
||||
return jdbcTemplate.update(RECORD_INSERT_SQL,
|
||||
// 主键
|
||||
recordInfo.getRecordId(),
|
||||
// 基础服务信息
|
||||
recordInfo.getServiceId(),
|
||||
recordInfo.getServerHost(),
|
||||
recordInfo.getServerIp(),
|
||||
recordInfo.getEnv(),
|
||||
// 审计级别
|
||||
recordLevel,
|
||||
// 请求信息
|
||||
recordInfo.getMethod(),
|
||||
recordInfo.getRequestUri(),
|
||||
recordInfo.getUserAgent(),
|
||||
recordInfo.getRemoteIp(),
|
||||
// 操作信息
|
||||
recordInfo.getOperation(),
|
||||
recordInfo.getTableName(),
|
||||
// 数据转换:将 Map 转换为 JSON 字符串
|
||||
JsonUtil.toJson(recordInfo.getOldData()),
|
||||
JsonUtil.toJson(recordInfo.getNewData()),
|
||||
// 审计消息
|
||||
recordMessage,
|
||||
// 审计结果
|
||||
recordInfo.getRecordResult(),
|
||||
// 记录耗时
|
||||
Func.toStr(recordInfo.getCost()),
|
||||
// 记录时间
|
||||
recordInfo.getRecordTime(),
|
||||
// 记录人
|
||||
Func.toLong(recordInfo.getUserId()),
|
||||
// 业务状态:默认为正常状态
|
||||
BladeConstant.DB_STATUS_NORMAL,
|
||||
// 逻辑删除状态:默认为未删除状态
|
||||
BladeConstant.DB_NOT_DELETED
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.handler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springblade.core.cache.utils.CacheUtil;
|
||||
import org.springblade.core.datascope.constant.DataScopeConstant;
|
||||
import org.springblade.core.datascope.handler.ScopeModelHandler;
|
||||
import org.springblade.core.datascope.model.DataScopeModel;
|
||||
import org.springblade.core.tool.utils.CollectionUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
|
||||
|
||||
/**
|
||||
* BladeScopeModelHandler
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
//若开启动态数据源功能,则加上@Master注解指定权限数据库为主库
|
||||
//@Master
|
||||
@RequiredArgsConstructor
|
||||
public class BladeScopeModelHandler implements ScopeModelHandler {
|
||||
|
||||
private static final String SCOPE_CACHE_CODE = "dataScope:code:";
|
||||
private static final String SCOPE_CACHE_CLASS = "dataScope:class:";
|
||||
private static final String DEPT_CACHE_ANCESTORS = "dept:ancestors:";
|
||||
private static final DataScopeModel SEARCHED_DATA_SCOPE_MODEL = new DataScopeModel(Boolean.TRUE);
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
/**
|
||||
* 获取数据权限
|
||||
*
|
||||
* @param mapperId 数据权限mapperId
|
||||
* @param roleId 用户角色集合
|
||||
* @return DataScopeModel
|
||||
*/
|
||||
@Override
|
||||
public DataScopeModel getDataScopeByMapper(String mapperId, String roleId) {
|
||||
List<Object> args = new ArrayList<>(Collections.singletonList(mapperId));
|
||||
List<Long> roleIds = Func.toLongList(roleId);
|
||||
args.addAll(roleIds);
|
||||
// 增加searched字段防止未配置的参数重复读库导致缓存击穿
|
||||
// 后续若有新增配置则会清空缓存重新加载
|
||||
DataScopeModel dataScope = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_CLASS, mapperId + StringPool.COLON + roleId, DataScopeModel.class, Boolean.FALSE);
|
||||
if (dataScope == null || !dataScope.getSearched()) {
|
||||
List<DataScopeModel> list = jdbcTemplate.query(DataScopeConstant.dataByMapper(roleIds.size()), new BeanPropertyRowMapper<>(DataScopeModel.class), args.toArray());
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
dataScope = list.iterator().next();
|
||||
dataScope.setSearched(Boolean.TRUE);
|
||||
} else {
|
||||
dataScope = SEARCHED_DATA_SCOPE_MODEL;
|
||||
}
|
||||
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_CLASS, mapperId + StringPool.COLON + roleId, dataScope, Boolean.FALSE);
|
||||
}
|
||||
return StringUtil.isNotBlank(dataScope.getResourceCode()) ? dataScope : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据权限
|
||||
*
|
||||
* @param code 数据权限资源编号
|
||||
* @return DataScopeModel
|
||||
*/
|
||||
@Override
|
||||
public DataScopeModel getDataScopeByCode(String code) {
|
||||
DataScopeModel dataScope = CacheUtil.get(SYS_CACHE, SCOPE_CACHE_CODE, code, DataScopeModel.class, Boolean.FALSE);
|
||||
// 增加searched字段防止未配置的参数重复读库导致缓存击穿
|
||||
// 后续若有新增配置则会清空缓存重新加载
|
||||
if (dataScope == null || !dataScope.getSearched()) {
|
||||
List<DataScopeModel> list = jdbcTemplate.query(DataScopeConstant.DATA_BY_CODE, new BeanPropertyRowMapper<>(DataScopeModel.class), code);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
dataScope = list.iterator().next();
|
||||
dataScope.setSearched(Boolean.TRUE);
|
||||
} else {
|
||||
dataScope = SEARCHED_DATA_SCOPE_MODEL;
|
||||
}
|
||||
CacheUtil.put(SYS_CACHE, SCOPE_CACHE_CODE, code, dataScope, Boolean.FALSE);
|
||||
}
|
||||
return StringUtil.isNotBlank(dataScope.getResourceCode()) ? dataScope : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门子级
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return deptIds
|
||||
*/
|
||||
@Override
|
||||
public List<Long> getDeptAncestors(Long deptId) {
|
||||
List ancestors = CacheUtil.get(SYS_CACHE, DEPT_CACHE_ANCESTORS, deptId, List.class);
|
||||
if (CollectionUtil.isEmpty(ancestors)) {
|
||||
ancestors = jdbcTemplate.queryForList(DataScopeConstant.DATA_BY_DEPT, Long.class, deptId);
|
||||
CacheUtil.put(SYS_CACHE, DEPT_CACHE_ANCESTORS, deptId, ancestors);
|
||||
}
|
||||
return ancestors;
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
package org.springblade.common.handler;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
public class PostgresLongArrayTypeHandler extends BaseTypeHandler<List<Long>> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, List<Long> parameter, JdbcType jdbcType) throws SQLException {
|
||||
java.sql.Array array = ps.getConnection().createArrayOf("bigint", parameter.toArray());
|
||||
ps.setArray(i, array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
Object obj = rs.getObject(columnName);
|
||||
return convertObjectToList(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
Object obj = rs.getObject(columnIndex);
|
||||
return convertObjectToList(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
Object obj = cs.getObject(columnIndex);
|
||||
return convertObjectToList(obj);
|
||||
}
|
||||
|
||||
private List<Long> convertObjectToList(Object obj) {
|
||||
if (obj == null) {
|
||||
return new ArrayList<>(); // 修改:返回空列表而不是null
|
||||
}
|
||||
|
||||
// 处理 List 类型
|
||||
if (obj instanceof List<?> rawList) {
|
||||
return rawList.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::convertToLong)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
}
|
||||
|
||||
// 处理数组类型
|
||||
if (obj.getClass().isArray()) {
|
||||
Object[] array = (Object[]) obj;
|
||||
return Arrays.stream(array)
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::convertToLong)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
}
|
||||
|
||||
// 处理 SQL Array 类型
|
||||
if (obj instanceof Array sqlArray) {
|
||||
try {
|
||||
Object[] array = (Object[]) sqlArray.getArray();
|
||||
return Arrays.stream(array)
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::convertToLong)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
} catch (SQLException e) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理 PostgreSQL 数组字符串格式
|
||||
if (obj instanceof String) {
|
||||
return parsePostgreSQLArrayString((String) obj);
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private List<Long> parsePostgreSQLArrayString(String arrayStr) {
|
||||
if (arrayStr == null || !arrayStr.startsWith("{") || !arrayStr.endsWith("}")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
String content = arrayStr.substring(1, arrayStr.length() - 1);
|
||||
if (content.trim().isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
String[] elements = content.split(",");
|
||||
return Arrays.stream(elements)
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty() && !"null".equalsIgnoreCase(s))
|
||||
.map(this::convertToLong)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
}
|
||||
|
||||
private Long convertToLong(Object obj) {
|
||||
if (obj instanceof Long) {
|
||||
return (Long) obj;
|
||||
} else if (obj instanceof Number) {
|
||||
return ((Number) obj).longValue();
|
||||
} else if (obj instanceof String) {
|
||||
try {
|
||||
return Long.valueOf(((String) obj));
|
||||
} catch (NumberFormatException e) {
|
||||
return 0L;
|
||||
}
|
||||
} else {
|
||||
return Long.valueOf(obj.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.launch;
|
||||
|
||||
import org.springblade.common.constant.LauncherConstant;
|
||||
import org.springblade.core.auto.service.AutoService;
|
||||
import org.springblade.core.launch.service.LauncherService;
|
||||
import org.springblade.core.launch.utils.PropsUtil;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 启动参数拓展
|
||||
*
|
||||
* @author smallchil
|
||||
*/
|
||||
@AutoService(LauncherService.class)
|
||||
public class LauncherServiceImpl implements LauncherService {
|
||||
|
||||
@Override
|
||||
public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) {
|
||||
Properties props = System.getProperties();
|
||||
PropsUtil.setProperty(props, "spring.cloud.sentinel.transport.dashboard", LauncherConstant.sentinelAddr(profile));
|
||||
PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "false");
|
||||
// 开启elk日志
|
||||
//PropsUtil.setProperty(props, "blade.log.elk.destination", LauncherConstant.elkAddr(profile));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.preview;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 演示配置类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(BladePreviewProperties.class)
|
||||
@ConditionalOnProperty(value = "blade.preview.enabled", havingValue = "true")
|
||||
public class BladePreviewConfiguration {
|
||||
|
||||
/**
|
||||
* 演示模式配置
|
||||
*/
|
||||
@Bean
|
||||
public BladePreviewFilter previewFilter() {
|
||||
return new BladePreviewFilter();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.preview;
|
||||
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 演示过滤器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class BladePreviewFilter implements Filter {
|
||||
|
||||
private static final List<String> SKIP_KEYS = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SKIP_KEYS.add("notice");
|
||||
SKIP_KEYS.add("flow");
|
||||
SKIP_KEYS.add("oauth");
|
||||
SKIP_KEYS.add("blade-auth");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
|
||||
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
|
||||
String path = httpServletRequest.getServletPath();
|
||||
String method = httpServletRequest.getMethod();
|
||||
|
||||
String get = "GET";
|
||||
if (method.equals(get) || SKIP_KEYS.stream().anyMatch(path::contains)) {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
} else {
|
||||
throw new ServiceException("演示环境暂时无法操作,请联系官方获取可操作账号!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.common.preview;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* 演示模式 配置
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "blade.preview")
|
||||
public class BladePreviewProperties {
|
||||
|
||||
/**
|
||||
* 开启演示模式
|
||||
*/
|
||||
private boolean enabled;
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package org.springblade.common.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomAmountGenerator {
|
||||
|
||||
/**
|
||||
* 生成指定范围内的随机金额
|
||||
*
|
||||
* @param min 最小值
|
||||
* @param max 最大值
|
||||
* @return 随机金额
|
||||
*/
|
||||
public static BigDecimal generateRandomAmount(BigDecimal min, BigDecimal max) {
|
||||
Random random = new Random();
|
||||
double range = max.subtract(min).doubleValue();
|
||||
double randomValue = random.nextDouble() * range + min.doubleValue();
|
||||
return BigDecimal.valueOf(randomValue).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,438 +0,0 @@
|
||||
package org.springblade.common.utils.date;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class DateUtil {
|
||||
|
||||
private static final ThreadLocal<SimpleDateFormat> SIMPLE_DAY = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd"));
|
||||
private static final ThreadLocal<SimpleDateFormat> SIMPLE_DATE_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
||||
public static final ThreadLocal<DateTimeFormatter> THREAD_LOCAL_FORMAT = ThreadLocal.withInitial(() -> DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.CHINA));
|
||||
|
||||
public static final String yyyyMMddHHmmss = "yyyyMMddHHmmss";
|
||||
public static final String yyyyMMdd = "yyyyMMdd";
|
||||
|
||||
|
||||
/**
|
||||
* 计算天数
|
||||
*
|
||||
* @param beginDate 开始时间
|
||||
* @param endDate 结束时间
|
||||
*/
|
||||
public static Integer getDaySub(Date beginDate, Date endDate) {
|
||||
try {
|
||||
SimpleDateFormat sdf = SIMPLE_DAY.get();
|
||||
Date start = sdf.parse(sdf.format(beginDate));
|
||||
Date end = sdf.parse(sdf.format(endDate));
|
||||
return Math.toIntExact((end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000));
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Date geFirstDayOfThisMonth() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取本月最后一天
|
||||
*/
|
||||
public static Date geLastDayOfThisMonth() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
cal.roll(Calendar.DAY_OF_MONTH, -1);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public static Date getThirtyMinuteLate() {
|
||||
Calendar now = Calendar.getInstance();
|
||||
now.add(Calendar.MINUTE, 30);
|
||||
return now.getTime();
|
||||
}
|
||||
|
||||
public static Date getSecondsLate(Date date, int seconds) {
|
||||
Calendar result = Calendar.getInstance();
|
||||
result.setTime(date);
|
||||
result.add(Calendar.SECOND, seconds);
|
||||
return result.getTime();
|
||||
}
|
||||
|
||||
public static Date getMinutesLate(Date date, int minutes) {
|
||||
Calendar result = Calendar.getInstance();
|
||||
result.setTime(date);
|
||||
result.add(Calendar.MINUTE, minutes);
|
||||
return result.getTime();
|
||||
}
|
||||
|
||||
public static Date getHoursLate(Date date, int hours) {
|
||||
Calendar result = Calendar.getInstance();
|
||||
result.setTime(date);
|
||||
result.add(Calendar.HOUR, hours);
|
||||
return result.getTime();
|
||||
}
|
||||
|
||||
public static Date getDaysLate(Date date, int days) {
|
||||
Calendar result = Calendar.getInstance();
|
||||
result.setTime(date);
|
||||
result.add(Calendar.DAY_OF_MONTH, days);
|
||||
return result.getTime();
|
||||
}
|
||||
|
||||
public static Date getMonthsLate(Date date, int months) {
|
||||
Calendar result = Calendar.getInstance();
|
||||
result.setTime(date);
|
||||
result.add(Calendar.MONTH, months);
|
||||
return result.getTime();
|
||||
}
|
||||
|
||||
public static Date getZeroTime(Date date) {
|
||||
Calendar result = Calendar.getInstance();
|
||||
result.setTime(date);
|
||||
result.set(Calendar.HOUR_OF_DAY, 0);
|
||||
result.set(Calendar.MINUTE, 0);
|
||||
result.set(Calendar.SECOND, 0);
|
||||
result.set(Calendar.MILLISECOND, 0);
|
||||
return result.getTime();
|
||||
}
|
||||
|
||||
public static boolean isExpireDays(Date date, int i) {
|
||||
Calendar createDate = Calendar.getInstance();
|
||||
createDate.setTime(date);
|
||||
createDate.add(Calendar.DATE, i);
|
||||
return createDate.before(new Date());
|
||||
}
|
||||
|
||||
|
||||
public static Integer getPersonAgeFromIdCard(String pensonnelIdCard) {
|
||||
|
||||
//截取身份证中出行人出生日期中的年、月、日
|
||||
Integer personYear = Integer.parseInt(pensonnelIdCard.substring(6, 10));
|
||||
Integer personMonth = Integer.parseInt(pensonnelIdCard.substring(10, 12));
|
||||
Integer personDay = Integer.parseInt(pensonnelIdCard.substring(12, 14));
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
// 得到当前时间的年、月、日
|
||||
Integer yearNow = cal.get(Calendar.YEAR);
|
||||
Integer monthNow = cal.get(Calendar.MONTH) + 1;
|
||||
Integer dayNow = cal.get(Calendar.DATE);
|
||||
|
||||
// 用当前年月日减去生日年月日
|
||||
Integer yearMinus = yearNow - personYear;
|
||||
Integer monthMinus = monthNow - personMonth;
|
||||
Integer dayMinus = dayNow - personDay;
|
||||
|
||||
Integer age = yearMinus; //先大致赋值
|
||||
|
||||
if (yearMinus == 0) { //出生年份为当前年份
|
||||
age = 0;
|
||||
} else { //出生年份大于当前年份
|
||||
if (monthMinus < 0) {//出生月份小于当前月份时,还没满周岁
|
||||
age = age - 1;
|
||||
}
|
||||
if (monthMinus == 0) {//当前月份为出生月份时,判断日期
|
||||
if (dayMinus < 0) {//出生日期小于当前月份时,没满周岁
|
||||
age = age - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return age;
|
||||
}
|
||||
|
||||
public static Date getToday() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Integer getYear() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
return calendar.get(Calendar.YEAR);
|
||||
}
|
||||
|
||||
public static Integer getMonth() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
return calendar.get(Calendar.MONTH) + 1;
|
||||
}
|
||||
|
||||
public static Integer getDay() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
return calendar.get(Calendar.DATE);
|
||||
}
|
||||
|
||||
public static Date getYesterday() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, -1);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getBeForeYesterday() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, -2);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date setDayToNum(int day) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, day);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getLastWeek() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, -7);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getSixDaysAgo() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, -6);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getTomorrow() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
|
||||
public static Integer getTimeHour() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
return calendar.get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
public static Date getTodayHour(String end) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(end));
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Integer getTimeStampSec() {
|
||||
return Integer.valueOf(String.valueOf(Instant.now().getEpochSecond()));
|
||||
}
|
||||
|
||||
public static Date getDayOfMonth(Integer month) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.DAY_OF_MONTH, month);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* "starttime": "11:00",
|
||||
* "endtime": "20:00",
|
||||
*
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
public static int verificationPeriod(String startTime, String endTime) {
|
||||
int status = 0;
|
||||
SimpleDateFormat sdf = SIMPLE_DAY.get();
|
||||
SimpleDateFormat sdtf = SIMPLE_DATE_FORMAT.get();
|
||||
if (StringUtils.hasLength(startTime) && StringUtils.hasLength(endTime) && startTime.length() == 5 && endTime.length() == 5) {
|
||||
String currentDay = sdf.format(new Date());
|
||||
Long current = System.currentTimeMillis();
|
||||
//日期补全
|
||||
String startStr = new StringBuilder(currentDay).append(" ").append(startTime).append(":00").toString();
|
||||
String endStr = new StringBuilder(currentDay).append(" ").append(endTime).append(":00").toString();
|
||||
synchronized (DateUtil.class) {
|
||||
try {
|
||||
Long start = sdtf.parse(startStr).getTime();
|
||||
Long end = sdtf.parse(endStr).getTime();
|
||||
//判断是否跨天
|
||||
if (start > end) {
|
||||
status = current - end >= 0 && current - start <= 0 ? 1 : 0;
|
||||
} else {
|
||||
status = start.equals(end) ? 0 : current - start >= 0 && current - end <= 0 ? 0 : 1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("错误的日期格式 开始时间 {} 结束时间{}", startTime, endTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
public static Date convertFromString(String dateString, String format) {
|
||||
SimpleDateFormat ft = new SimpleDateFormat(format);
|
||||
try {
|
||||
return ft.parse(dateString);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertFromDate(Date date, String format) {
|
||||
SimpleDateFormat ft = new SimpleDateFormat(format);
|
||||
return ft.format(date);
|
||||
}
|
||||
|
||||
public static Date convertLocalDateTimeToDate(LocalDateTime localDateTime) {
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
ZonedDateTime zdt = localDateTime.atZone(zoneId);
|
||||
return Date.from(zdt.toInstant());
|
||||
}
|
||||
|
||||
public static Integer getDays(Integer number, Integer type) {
|
||||
int days = 0;
|
||||
//计算包对应时长
|
||||
switch (type) {
|
||||
case 1: // 天
|
||||
days = number;
|
||||
break;
|
||||
case 2: // 月
|
||||
days = number * 30;
|
||||
break;
|
||||
case 3: //年
|
||||
days = number * 365;
|
||||
break;
|
||||
default:
|
||||
Assert.isTrue(false, "时间类型错误");
|
||||
}
|
||||
return days;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定日期后x天的日期
|
||||
*
|
||||
* @param start 日期
|
||||
* @param day 天数
|
||||
* @return
|
||||
*/
|
||||
public static Date getSpecifyDay(Date start, int day) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(start);
|
||||
calendar.add(Calendar.DATE, day);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getBegin(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getEnd(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.SECOND, 59);
|
||||
calendar.set(Calendar.MINUTE, 59);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
||||
calendar.set(Calendar.MILLISECOND, 999);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getMonthBegin(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.add(Calendar.MONTH, 0);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Date getMonthEnd(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
|
||||
calendar.set(Calendar.SECOND, 59);
|
||||
calendar.set(Calendar.MINUTE, 59);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
||||
calendar.set(Calendar.MILLISECOND, 999);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public static Long getExpireSecondWithTimestamp(int seconds) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.SECOND, seconds);
|
||||
return calendar.getTime().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期是否为周六/周日
|
||||
*
|
||||
* @param day
|
||||
* @return
|
||||
*/
|
||||
public static Boolean dayOfWeek(String day) {
|
||||
DateTimeFormatter formatter = THREAD_LOCAL_FORMAT.get();
|
||||
LocalDate date = LocalDate.parse(day, formatter);
|
||||
switch (date.getDayOfWeek()) {
|
||||
case SATURDAY:
|
||||
case SUNDAY:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.springblade.common.utils.jsonSerialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ArrayToStringDeserializer extends JsonDeserializer<String> {
|
||||
|
||||
@Override
|
||||
public String deserialize(JsonParser p, DeserializationContext ctxt)
|
||||
throws IOException, JsonProcessingException {
|
||||
JsonNode node = p.getCodec().readTree(p);
|
||||
|
||||
if (node.isArray()) {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (JsonNode element : node) {
|
||||
values.add(element.asText());
|
||||
}
|
||||
// 将数组元素用逗号连接成字符串
|
||||
return String.join(",", values);
|
||||
} else if (node.isTextual()) {
|
||||
return node.asText();
|
||||
} else {
|
||||
return node.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package org.springblade.common.utils.string;
|
||||
|
||||
/**
|
||||
* 静态 String 池
|
||||
*
|
||||
* @author L.cm
|
||||
*/
|
||||
public interface StringPool {
|
||||
|
||||
String AMPERSAND = "&";
|
||||
String AND = "and";
|
||||
String AT = "@";
|
||||
String ASTERISK = "*";
|
||||
String STAR = ASTERISK;
|
||||
String SLASH = "/";
|
||||
String BACK_SLASH = "\\";
|
||||
String DOUBLE_SLASH = "#//";
|
||||
String COLON = ":";
|
||||
String COMMA = ",";
|
||||
String DASH = "-";
|
||||
String DOLLAR = "$";
|
||||
String DOT = ".";
|
||||
String EMPTY = "";
|
||||
String EMPTY_JSON = "{}";
|
||||
String EQUALS = "=";
|
||||
String FALSE = "false";
|
||||
String HASH = "#";
|
||||
String HAT = "^";
|
||||
String LEFT_BRACE = "{";
|
||||
String LEFT_BRACKET = "(";
|
||||
String LEFT_CHEV = "<";
|
||||
|
||||
String NEWLINE = "\n";
|
||||
String N = "n";
|
||||
String NO = "no";
|
||||
String NULL = "null";
|
||||
String OFF = "off";
|
||||
String ON = "on";
|
||||
String PERCENT = "%";
|
||||
String PIPE = "|";
|
||||
String PLUS = "+";
|
||||
String QUESTION_MARK = "?";
|
||||
String EXCLAMATION_MARK = "!";
|
||||
String QUOTE = "\"";
|
||||
String RETURN = "\r";
|
||||
String TAB = "\t";
|
||||
String RIGHT_BRACE = "}";
|
||||
String RIGHT_BRACKET = ")";
|
||||
String RIGHT_CHEV = ">";
|
||||
String SEMICOLON = ";";
|
||||
String SINGLE_QUOTE = "'";
|
||||
String BACKTICK = "`";
|
||||
String SPACE = " ";
|
||||
String TILDA = "~";
|
||||
String LEFT_SQ_BRACKET = "[";
|
||||
String RIGHT_SQ_BRACKET = "]";
|
||||
String TRUE = "true";
|
||||
String UNDERSCORE = "_";
|
||||
String UTF_8 = "UTF-8";
|
||||
String GBK = "GBK";
|
||||
String ISO_8859_1 = "ISO-8859-1";
|
||||
String Y = "y";
|
||||
String YES = "yes";
|
||||
String ONE = "1";
|
||||
String ZERO = "0";
|
||||
String MINUS_ONE = "-1";
|
||||
String DOLLAR_LEFT_BRACE = "${";
|
||||
String UNKNOWN = "unknown";
|
||||
String GET = "GET";
|
||||
String POST = "POST";
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user