upd: 编码规范
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
package cn.odboy.base;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结果封装类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class BaseResult<T> extends MyObject {
|
||||||
|
private T content;
|
||||||
|
private long totalElements;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package cn.odboy.constant;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum FileTypeEnum {
|
||||||
|
/* 文件类型 */
|
||||||
|
IMAGE("image", "图片"),
|
||||||
|
DOC("doc", "文档"),
|
||||||
|
VOICE("voice", "音频"),
|
||||||
|
VIDEO("video", "视频"),
|
||||||
|
OTHER("other", "其他");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String description;
|
||||||
|
}
|
||||||
+11
-1
@@ -3,7 +3,7 @@ package cn.odboy.constant;
|
|||||||
/**
|
/**
|
||||||
* 关于缓存的Key集合
|
* 关于缓存的Key集合
|
||||||
*/
|
*/
|
||||||
public interface CacheKey {
|
public interface SystemRedisKey {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户
|
* 用户
|
||||||
@@ -46,4 +46,14 @@ public interface CacheKey {
|
|||||||
* 数据字典
|
* 数据字典
|
||||||
*/
|
*/
|
||||||
String DICT_NAME = "dict::name:";
|
String DICT_NAME = "dict::name:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在线用户
|
||||||
|
*/
|
||||||
|
String ONLINE_USER = "online::token:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录验证码
|
||||||
|
*/
|
||||||
|
String CAPTCHA_LOGIN = "captcha::login:";
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package cn.odboy.constant;
|
||||||
|
|
||||||
|
public interface TransferProtocolConst {
|
||||||
|
String PREFIX_HTTP = "http://";
|
||||||
|
String PREFIX_HTTPS = "https://";
|
||||||
|
String PREFIX_HTTPS_BAD_REQUEST = "外链必须以http://或者https://开头";
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package cn.odboy.util;
|
||||||
|
|
||||||
|
import cn.hutool.http.useragent.UserAgent;
|
||||||
|
import cn.hutool.http.useragent.UserAgentUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 浏览器 相关
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class BrowserUtil {
|
||||||
|
private static final String UNKNOWN = "unknown";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取ip地址
|
||||||
|
*/
|
||||||
|
public static String getIp(HttpServletRequest request) {
|
||||||
|
String ip = request.getHeader("x-forwarded-for");
|
||||||
|
if (ip == null || ip.isEmpty() || UNKNOWN.equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (ip == null || ip.isEmpty() || UNKNOWN.equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (ip == null || ip.isEmpty() || UNKNOWN.equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getRemoteAddr();
|
||||||
|
}
|
||||||
|
String comma = ",";
|
||||||
|
String localhost = "127.0.0.1";
|
||||||
|
if (ip.contains(comma)) {
|
||||||
|
ip = ip.split(",")[0];
|
||||||
|
}
|
||||||
|
if (localhost.equals(ip)) {
|
||||||
|
// 获取本机真正的ip地址
|
||||||
|
try {
|
||||||
|
ip = InetAddress.getLocalHost().getHostAddress();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
log.error("获取本机地址失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取浏览器
|
||||||
|
*/
|
||||||
|
public static String getVersion(HttpServletRequest request) {
|
||||||
|
UserAgent ua = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
||||||
|
String browser = ua.getBrowser().toString() + " " + ua.getVersion();
|
||||||
|
return browser.replace(".0.0.0", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package cn.odboy.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类 相关
|
||||||
|
*/
|
||||||
|
public class ClassUtil {
|
||||||
|
@SuppressWarnings({"unchecked", "all"})
|
||||||
|
public static List<Field> getAllFields(Class clazz, List<Field> fields) {
|
||||||
|
if (clazz != null) {
|
||||||
|
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
||||||
|
getAllFields(clazz.getSuperclass(), fields);
|
||||||
|
}
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,63 +36,6 @@ import java.util.stream.Collectors;
|
|||||||
* @date 2022-11-09
|
* @date 2022-11-09
|
||||||
*/
|
*/
|
||||||
public class CollUtil extends cn.hutool.core.collection.CollUtil {
|
public class CollUtil extends cn.hutool.core.collection.CollUtil {
|
||||||
/**
|
|
||||||
* 连接器
|
|
||||||
*/
|
|
||||||
private static final Joiner JOINER = Joiner.on(",").skipNulls();
|
|
||||||
/**
|
|
||||||
* 分割器
|
|
||||||
*/
|
|
||||||
private static final Splitter SPLITTER = Splitter.on(",").trimResults().omitEmptyStrings();
|
|
||||||
|
|
||||||
public static String join(Object[] parts) {
|
|
||||||
return JOINER.join(parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String join(Iterable<?> parts) {
|
|
||||||
return JOINER.join(parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String join(Iterator<?> parts) {
|
|
||||||
return JOINER.join(parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> splitToList(String parts) {
|
|
||||||
return SPLITTER.splitToList(parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分几份
|
|
||||||
*
|
|
||||||
* @param parts /
|
|
||||||
* @param size /
|
|
||||||
* @param <T> /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static <T> List<List<T>> splitToSize(List<T> parts, int size) {
|
|
||||||
return Lists.partition(parts, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 一份几个
|
|
||||||
*
|
|
||||||
* @param parts /
|
|
||||||
* @param groupNum /
|
|
||||||
* @param <T> /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static <T> List<List<T>> splitToSegment(List<T> parts, int groupNum) {
|
|
||||||
List<List<T>> result = new ArrayList<>(1);
|
|
||||||
int i = 0;
|
|
||||||
for (; i < parts.size() / groupNum; i++) {
|
|
||||||
result.add(parts.subList(i * groupNum, (i + 1) * groupNum));
|
|
||||||
}
|
|
||||||
if (parts.size() % groupNum != 0) {
|
|
||||||
result.add(parts.subList(i * groupNum, i * groupNum + parts.size() % groupNum));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T, K> Predicate<T> distinctPredicate(Function<? super T, ? extends K> keyMapper) {
|
private static <T, K> Predicate<T> distinctPredicate(Function<? super T, ? extends K> keyMapper) {
|
||||||
Map<Object, Boolean> map = new HashMap<>();
|
Map<Object, Boolean> map = new HashMap<>();
|
||||||
return (t) -> null == map.putIfAbsent(keyMapper.apply(t), true);
|
return (t) -> null == map.putIfAbsent(keyMapper.apply(t), true);
|
||||||
|
|||||||
+3
-4
@@ -8,9 +8,9 @@ import javax.crypto.spec.IvParameterSpec;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加密
|
* DES加密
|
||||||
*/
|
*/
|
||||||
public class EncryptUtil {
|
public class DESEncryptUtil {
|
||||||
|
|
||||||
private static final String STR_PARAM = "Passw0rd";
|
private static final String STR_PARAM = "Passw0rd";
|
||||||
private static final IvParameterSpec IV = new IvParameterSpec(STR_PARAM.getBytes(StandardCharsets.UTF_8));
|
private static final IvParameterSpec IV = new IvParameterSpec(STR_PARAM.getBytes(StandardCharsets.UTF_8));
|
||||||
@@ -19,8 +19,7 @@ public class EncryptUtil {
|
|||||||
if (source == null || source.isEmpty()) {
|
if (source == null || source.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String strKey = "Passw0rd";
|
return new DESKeySpec(STR_PARAM.getBytes(StandardCharsets.UTF_8));
|
||||||
return new DESKeySpec(strKey.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,152 +0,0 @@
|
|||||||
package cn.odboy.util;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.time.*;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JDK 8 新日期类 格式化与字符串转换 工具类
|
|
||||||
*/
|
|
||||||
public class DateUtil {
|
|
||||||
|
|
||||||
public static final DateTimeFormatter DFY_MD_HMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
public static final DateTimeFormatter DFY_MD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LocalDateTime 转时间戳
|
|
||||||
*
|
|
||||||
* @param localDateTime /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static Long getTimeStamp(LocalDateTime localDateTime) {
|
|
||||||
return localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时间戳转LocalDateTime
|
|
||||||
*
|
|
||||||
* @param timeStamp /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static LocalDateTime fromTimeStamp(Long timeStamp) {
|
|
||||||
return LocalDateTime.ofEpochSecond(timeStamp, 0, OffsetDateTime.now().getOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LocalDateTime 转 Date
|
|
||||||
* Jdk8 后 不推荐使用 {@link Date} Date
|
|
||||||
*
|
|
||||||
* @param localDateTime /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static Date toDate(LocalDateTime localDateTime) {
|
|
||||||
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LocalDate 转 Date
|
|
||||||
* Jdk8 后 不推荐使用 {@link Date} Date
|
|
||||||
*
|
|
||||||
* @param localDate /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static Date toDate(LocalDate localDate) {
|
|
||||||
return toDate(localDate.atTime(LocalTime.now(ZoneId.systemDefault())));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Date转 LocalDateTime
|
|
||||||
* Jdk8 后 不推荐使用 {@link Date} Date
|
|
||||||
*
|
|
||||||
* @param date /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static LocalDateTime toLocalDateTime(Date date) {
|
|
||||||
return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日期 格式化
|
|
||||||
*
|
|
||||||
* @param localDateTime /
|
|
||||||
* @param patten /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static String localDateTimeFormat(LocalDateTime localDateTime, String patten) {
|
|
||||||
DateTimeFormatter df = DateTimeFormatter.ofPattern(patten);
|
|
||||||
return df.format(localDateTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日期 格式化
|
|
||||||
*
|
|
||||||
* @param localDateTime /
|
|
||||||
* @param df /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static String localDateTimeFormat(LocalDateTime localDateTime, DateTimeFormatter df) {
|
|
||||||
return df.format(localDateTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日期格式化 yyyy-MM-dd HH:mm:ss
|
|
||||||
*
|
|
||||||
* @param localDateTime /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static String localDateTimeFormatyMdHms(LocalDateTime localDateTime) {
|
|
||||||
return DFY_MD_HMS.format(localDateTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前时间
|
|
||||||
*
|
|
||||||
* @return 、
|
|
||||||
*/
|
|
||||||
public static Timestamp getTimeStamp() {
|
|
||||||
return Timestamp.valueOf(LocalDateTime.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 日期格式化 yyyy-MM-dd
|
|
||||||
*
|
|
||||||
* @param localDateTime /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public String localDateTimeFormatyMd(LocalDateTime localDateTime) {
|
|
||||||
return DFY_MD.format(localDateTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd
|
|
||||||
*
|
|
||||||
* @param localDateTime /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, String pattern) {
|
|
||||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
|
|
||||||
return LocalDateTime.from(dateTimeFormatter.parse(localDateTime));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd
|
|
||||||
*
|
|
||||||
* @param localDateTime /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, DateTimeFormatter dateTimeFormatter) {
|
|
||||||
return LocalDateTime.from(dateTimeFormatter.parse(localDateTime));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字符串转 LocalDateTime ,字符串格式 yyyy-MM-dd HH:mm:ss
|
|
||||||
*
|
|
||||||
* @param localDateTime /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static LocalDateTime parseLocalDateTimeFormatyMdHms(String localDateTime) {
|
|
||||||
return LocalDateTime.from(DFY_MD_HMS.parse(localDateTime));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@ import cn.hutool.core.io.IoUtil;
|
|||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.poi.excel.BigExcelWriter;
|
import cn.hutool.poi.excel.BigExcelWriter;
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
|
import cn.odboy.constant.FileTypeEnum;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
@@ -61,21 +62,17 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
*/
|
*/
|
||||||
private static final DecimalFormat DF = new DecimalFormat("0.00");
|
private static final DecimalFormat DF = new DecimalFormat("0.00");
|
||||||
|
|
||||||
public static final String IMAGE = "图片";
|
public static void main(String[] args) {
|
||||||
public static final String TXT = "文档";
|
}
|
||||||
public static final String MUSIC = "音乐";
|
|
||||||
public static final String VIDEO = "视频";
|
|
||||||
public static final String OTHER = "其他";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MultipartFile转File
|
* MultipartFile转File -> ok
|
||||||
*/
|
*/
|
||||||
public static File toFile(MultipartFile multipartFile) {
|
public static File toFile(MultipartFile multipartFile) {
|
||||||
// 获取文件名
|
// 获取文件名
|
||||||
String fileName = multipartFile.getOriginalFilename();
|
String fileName = multipartFile.getOriginalFilename();
|
||||||
// 获取文件后缀
|
// 获取文件后缀
|
||||||
String prefix = "." + getExtensionName(fileName);
|
String prefix = "." + getSuffix(fileName);
|
||||||
File file = null;
|
File file = null;
|
||||||
try {
|
try {
|
||||||
// 用uuid作为文件名,防止生成的临时文件重复
|
// 用uuid作为文件名,防止生成的临时文件重复
|
||||||
@@ -83,39 +80,13 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
// MultipartFile to File
|
// MultipartFile to File
|
||||||
multipartFile.transferTo(file);
|
multipartFile.transferTo(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error("保存临时文件失败", e);
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件扩展名,不带 .
|
* 文件大小转换 -> ok
|
||||||
*/
|
|
||||||
public static String getExtensionName(String filename) {
|
|
||||||
if ((filename != null) && (!filename.isEmpty())) {
|
|
||||||
int dot = filename.lastIndexOf('.');
|
|
||||||
if ((dot > -1) && (dot < (filename.length() - 1))) {
|
|
||||||
return filename.substring(dot + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Java文件操作 获取不带扩展名的文件名
|
|
||||||
*/
|
|
||||||
public static String getFileNameNoEx(String filename) {
|
|
||||||
if ((filename != null) && (!filename.isEmpty())) {
|
|
||||||
int dot = filename.lastIndexOf('.');
|
|
||||||
if (dot > -1) {
|
|
||||||
return filename.substring(0, dot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件大小转换
|
|
||||||
*/
|
*/
|
||||||
public static String getSize(long size) {
|
public static String getSize(long size) {
|
||||||
String resultSize;
|
String resultSize;
|
||||||
@@ -135,9 +106,9 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inputStream 转 File
|
* inputStream 转 File -> ok
|
||||||
*/
|
*/
|
||||||
static File inputStreamToFile(InputStream ins, String name) {
|
public static File inputStreamToFile(InputStream ins, String name) {
|
||||||
File file = new File(SYS_TEM_DIR + name);
|
File file = new File(SYS_TEM_DIR + name);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return file;
|
return file;
|
||||||
@@ -161,14 +132,14 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将文件名解析成文件的上传路径
|
* 将文件名解析成文件的上传路径 -> ok
|
||||||
*/
|
*/
|
||||||
public static File upload(MultipartFile file, String filePath) {
|
public static File upload(MultipartFile file, String filePath) {
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
|
||||||
// 过滤非法文件名
|
// 过滤非法文件名
|
||||||
String name = getFileNameNoEx(verifyFilename(file.getOriginalFilename()));
|
String name = getPrefix(verifyFilename(file.getOriginalFilename()));
|
||||||
String suffix = getExtensionName(file.getOriginalFilename());
|
String suffix = getSuffix(file.getOriginalFilename());
|
||||||
String nowStr = "-" + format.format(date);
|
String nowStr = "-" + format.format(date);
|
||||||
try {
|
try {
|
||||||
String fileName = name + nowStr + "." + suffix;
|
String fileName = name + nowStr + "." + suffix;
|
||||||
@@ -178,20 +149,20 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
// 检测是否存在目录
|
// 检测是否存在目录
|
||||||
if (!dest.getParentFile().exists()) {
|
if (!dest.getParentFile().exists()) {
|
||||||
if (!dest.getParentFile().mkdirs()) {
|
if (!dest.getParentFile().mkdirs()) {
|
||||||
System.out.println("was not successful.");
|
log.error("创建目录失败, {}", dest.getParentFile().getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 文件写入
|
// 文件写入
|
||||||
file.transferTo(dest);
|
file.transferTo(dest);
|
||||||
return dest;
|
return dest;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error("文件上传失败", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出excel
|
* 导出excel -> ok
|
||||||
*/
|
*/
|
||||||
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
|
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
|
||||||
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx";
|
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx";
|
||||||
@@ -233,24 +204,30 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
IoUtil.close(out);
|
IoUtil.close(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件类型 -> ok
|
||||||
|
*/
|
||||||
public static String getFileType(String type) {
|
public static String getFileType(String type) {
|
||||||
String documents = "txt doc pdf ppt pps xlsx xls docx";
|
String documents = "txt doc pdf ppt pps xlsx xls docx";
|
||||||
String music = "mp3 wav wma mpa ram ra aac aif m4a";
|
String voice = "mp3 wav wma mpa ram ra aac aif m4a";
|
||||||
String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg";
|
String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg";
|
||||||
String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg";
|
String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg";
|
||||||
if (image.contains(type)) {
|
if (image.contains(type)) {
|
||||||
return IMAGE;
|
return FileTypeEnum.IMAGE.getCode();
|
||||||
} else if (documents.contains(type)) {
|
} else if (documents.contains(type)) {
|
||||||
return TXT;
|
return FileTypeEnum.DOC.getCode();
|
||||||
} else if (music.contains(type)) {
|
} else if (voice.contains(type)) {
|
||||||
return MUSIC;
|
return FileTypeEnum.VOICE.getCode();
|
||||||
} else if (video.contains(type)) {
|
} else if (video.contains(type)) {
|
||||||
return VIDEO;
|
return FileTypeEnum.VIDEO.getCode();
|
||||||
} else {
|
} else {
|
||||||
return OTHER;
|
return FileTypeEnum.OTHER.getCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查文件大小是否超出最大值 -> ok
|
||||||
|
*/
|
||||||
public static void checkSize(long maxSize, long size) {
|
public static void checkSize(long maxSize, long size) {
|
||||||
// 1M
|
// 1M
|
||||||
int len = 1024 * 1024;
|
int len = 1024 * 1024;
|
||||||
@@ -260,7 +237,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断两个文件是否相同
|
* 判断两个文件是否相同 -> ok
|
||||||
*/
|
*/
|
||||||
public static boolean check(File file1, File file2) {
|
public static boolean check(File file1, File file2) {
|
||||||
String img1Md5 = getMd5(file1);
|
String img1Md5 = getMd5(file1);
|
||||||
@@ -272,23 +249,22 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断两个文件是否相同
|
* 判断两个文件是否相同 -> ok
|
||||||
*/
|
*/
|
||||||
public static boolean check(String file1Md5, String file2Md5) {
|
public static boolean check(String file1Md5, String file2Md5) {
|
||||||
return file1Md5.equals(file2Md5);
|
return file1Md5.equals(file2Md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件字节数组 -> ok
|
||||||
|
*/
|
||||||
private static byte[] getByte(File file) {
|
private static byte[] getByte(File file) {
|
||||||
// 得到文件长度
|
|
||||||
byte[] b = new byte[(int) file.length()];
|
byte[] b = new byte[(int) file.length()];
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
try {
|
try {
|
||||||
in = Files.newInputStream(file.toPath());
|
in = Files.newInputStream(file.toPath());
|
||||||
try {
|
// 忽略read值
|
||||||
System.out.println(in.read(b));
|
int read = in.read(b);
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
return null;
|
return null;
|
||||||
@@ -298,6 +274,9 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件MD5值 -> ok
|
||||||
|
*/
|
||||||
private static String getMd5(byte[] bytes) {
|
private static String getMd5(byte[] bytes) {
|
||||||
// 16进制字符
|
// 16进制字符
|
||||||
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
@@ -315,7 +294,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
}
|
}
|
||||||
return new String(str);
|
return new String(str);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error("获取文件MD5值失败", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -337,7 +316,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
IOUtils.copy(fis, response.getOutputStream());
|
IOUtils.copy(fis, response.getOutputStream());
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error("下载文件失败", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (fis != null) {
|
if (fis != null) {
|
||||||
try {
|
try {
|
||||||
@@ -346,7 +325,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error("关闭IO流失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package cn.odboy.util;
|
||||||
|
|
||||||
|
import cn.odboy.context.SpringBeanHolder;
|
||||||
|
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
|
||||||
|
import net.dreamlu.mica.ip2region.core.IpInfo;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IP地址 相关
|
||||||
|
*/
|
||||||
|
public class IPUtil {
|
||||||
|
/**
|
||||||
|
* 注入bean
|
||||||
|
*/
|
||||||
|
private final static Ip2regionSearcher IP_SEARCHER = SpringBeanHolder.getBean(Ip2regionSearcher.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ip获取详细地址
|
||||||
|
*/
|
||||||
|
public static String getCityInfo(String ip) {
|
||||||
|
IpInfo ipInfo = IP_SEARCHER.memorySearch(ip);
|
||||||
|
if (ipInfo != null) {
|
||||||
|
return ipInfo.getAddress();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前机器的IP
|
||||||
|
*
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public static String getLocalIp() {
|
||||||
|
try {
|
||||||
|
InetAddress candidateAddress = null;
|
||||||
|
// 遍历所有的网络接口
|
||||||
|
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements(); ) {
|
||||||
|
NetworkInterface anInterface = interfaces.nextElement();
|
||||||
|
// 在所有的接口下再遍历IP
|
||||||
|
for (Enumeration<InetAddress> inetAddresses = anInterface.getInetAddresses(); inetAddresses.hasMoreElements(); ) {
|
||||||
|
InetAddress inetAddr = inetAddresses.nextElement();
|
||||||
|
// 排除loopback类型地址
|
||||||
|
if (!inetAddr.isLoopbackAddress()) {
|
||||||
|
if (inetAddr.isSiteLocalAddress()) {
|
||||||
|
// 如果是site-local地址,就是它了
|
||||||
|
return inetAddr.getHostAddress();
|
||||||
|
} else if (candidateAddress == null) {
|
||||||
|
// site-local类型的地址未被发现,先记录候选地址
|
||||||
|
candidateAddress = inetAddr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (candidateAddress != null) {
|
||||||
|
return candidateAddress.getHostAddress();
|
||||||
|
}
|
||||||
|
// 如果没有发现 non-loopback地址.只能用最次选的方案
|
||||||
|
InetAddress jdkSuppliedAddress = InetAddress.getLocalHost();
|
||||||
|
if (jdkSuppliedAddress == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return jdkSuppliedAddress.getHostAddress();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,9 +16,10 @@ public class PageUtil extends cn.hutool.core.util.PageUtil {
|
|||||||
/**
|
/**
|
||||||
* List 分页
|
* List 分页
|
||||||
*/
|
*/
|
||||||
public static <T> List<T> paging(int page, int size, List<T> list) {
|
public static <T> List<T> softPaging(int page, int size, List<T> list) {
|
||||||
int fromIndex = (page - 1) * size;
|
int pageIndex = page - 1;
|
||||||
int toIndex = (page - 1) * size + size;
|
int fromIndex = pageIndex * size;
|
||||||
|
int toIndex = pageIndex * size + size;
|
||||||
if (fromIndex > list.size()) {
|
if (fromIndex > list.size()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
} else if (toIndex >= list.size()) {
|
} else if (toIndex >= list.size()) {
|
||||||
|
|||||||
+7
-7
@@ -13,7 +13,7 @@ import java.security.spec.X509EncodedKeySpec;
|
|||||||
/**
|
/**
|
||||||
* Rsa 工具类,公钥私钥生成,加解密
|
* Rsa 工具类,公钥私钥生成,加解密
|
||||||
*/
|
*/
|
||||||
public class RsaUtil {
|
public class RSAEncryptUtil {
|
||||||
|
|
||||||
private static final String SRC = "123456";
|
private static final String SRC = "123456";
|
||||||
|
|
||||||
@@ -34,12 +34,12 @@ public class RsaUtil {
|
|||||||
*/
|
*/
|
||||||
private static void test1(RsaKeyPair keyPair) throws Exception {
|
private static void test1(RsaKeyPair keyPair) throws Exception {
|
||||||
System.out.println("***************** 公钥加密私钥解密开始 *****************");
|
System.out.println("***************** 公钥加密私钥解密开始 *****************");
|
||||||
String text1 = encryptByPublicKey(keyPair.getPublicKey(), RsaUtil.SRC);
|
String text1 = encryptByPublicKey(keyPair.getPublicKey(), RSAEncryptUtil.SRC);
|
||||||
String text2 = decryptByPrivateKey(keyPair.getPrivateKey(), text1);
|
String text2 = decryptByPrivateKey(keyPair.getPrivateKey(), text1);
|
||||||
System.out.println("加密前:" + RsaUtil.SRC);
|
System.out.println("加密前:" + RSAEncryptUtil.SRC);
|
||||||
System.out.println("加密后:" + text1);
|
System.out.println("加密后:" + text1);
|
||||||
System.out.println("解密后:" + text2);
|
System.out.println("解密后:" + text2);
|
||||||
if (RsaUtil.SRC.equals(text2)) {
|
if (RSAEncryptUtil.SRC.equals(text2)) {
|
||||||
System.out.println("解密字符串和原始字符串一致,解密成功");
|
System.out.println("解密字符串和原始字符串一致,解密成功");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("解密字符串和原始字符串不一致,解密失败");
|
System.out.println("解密字符串和原始字符串不一致,解密失败");
|
||||||
@@ -54,12 +54,12 @@ public class RsaUtil {
|
|||||||
*/
|
*/
|
||||||
private static void test2(RsaKeyPair keyPair) throws Exception {
|
private static void test2(RsaKeyPair keyPair) throws Exception {
|
||||||
System.out.println("***************** 私钥加密公钥解密开始 *****************");
|
System.out.println("***************** 私钥加密公钥解密开始 *****************");
|
||||||
String text1 = encryptByPrivateKey(keyPair.getPrivateKey(), RsaUtil.SRC);
|
String text1 = encryptByPrivateKey(keyPair.getPrivateKey(), RSAEncryptUtil.SRC);
|
||||||
String text2 = decryptByPublicKey(keyPair.getPublicKey(), text1);
|
String text2 = decryptByPublicKey(keyPair.getPublicKey(), text1);
|
||||||
System.out.println("加密前:" + RsaUtil.SRC);
|
System.out.println("加密前:" + RSAEncryptUtil.SRC);
|
||||||
System.out.println("加密后:" + text1);
|
System.out.println("加密后:" + text1);
|
||||||
System.out.println("解密后:" + text2);
|
System.out.println("解密后:" + text2);
|
||||||
if (RsaUtil.SRC.equals(text2)) {
|
if (RSAEncryptUtil.SRC.equals(text2)) {
|
||||||
System.out.println("解密字符串和原始字符串一致,解密成功");
|
System.out.println("解密字符串和原始字符串一致,解密成功");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("解密字符串和原始字符串不一致,解密失败");
|
System.out.println("解密字符串和原始字符串不一致,解密失败");
|
||||||
@@ -64,18 +64,16 @@ public class ScriptUtil {
|
|||||||
});
|
});
|
||||||
newContext.setBindings(engineScope, ScriptContext.ENGINE_SCOPE);
|
newContext.setBindings(engineScope, ScriptContext.ENGINE_SCOPE);
|
||||||
}
|
}
|
||||||
if (script.contains(FUNCTION_TAG)) {
|
// if (script.contains(FUNCTION_TAG)) {
|
||||||
// 由ScriptEngines实现的接口, 其方法允许调用以前已执行的脚本中的过程
|
// // 由ScriptEngines实现的接口, 其方法允许调用以前已执行的脚本中的过程
|
||||||
Invocable inv = (Invocable) engine;
|
// Invocable inv = (Invocable) engine;
|
||||||
// 调用全局函数, 并传入参数
|
// // 调用全局函数, 并传入参数
|
||||||
inv.invokeFunction("hello", "测试");
|
// inv.invokeFunction("hello", "测试");
|
||||||
}
|
// }
|
||||||
// 执行脚本, 注意这里指定新的执行作用域上下文
|
// 执行脚本, 注意这里指定新的执行作用域上下文
|
||||||
return engine.eval(script, newContext);
|
return engine.eval(script, newContext);
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
throw new ScriptRuntimeException(e);
|
throw new ScriptRuntimeException(e);
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
throw new ScriptRuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,20 +26,14 @@ import java.util.Objects;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class SecurityUtil {
|
public class SecurityUtil {
|
||||||
|
/**
|
||||||
public static String header;
|
* 请求头名称
|
||||||
|
*/
|
||||||
public static String tokenStartWith;
|
public static final String HEADER = "Authorization";
|
||||||
|
/**
|
||||||
@Value("${jwt.header}")
|
* Token前缀
|
||||||
public void setHeader(String header) {
|
*/
|
||||||
SecurityUtil.header = header;
|
public static final String TOKEN_PREFIX = "Bearer";
|
||||||
}
|
|
||||||
|
|
||||||
@Value("${jwt.token-start-with}")
|
|
||||||
public void setTokenStartWith(String tokenStartWith) {
|
|
||||||
SecurityUtil.tokenStartWith = tokenStartWith;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前登录的用户
|
* 获取当前登录的用户
|
||||||
@@ -123,10 +117,10 @@ public class SecurityUtil {
|
|||||||
public static String getToken() {
|
public static String getToken() {
|
||||||
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder
|
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder
|
||||||
.getRequestAttributes())).getRequest();
|
.getRequestAttributes())).getRequest();
|
||||||
String bearerToken = request.getHeader(header);
|
String bearerToken = request.getHeader(HEADER);
|
||||||
if (bearerToken != null && bearerToken.startsWith(tokenStartWith)) {
|
if (bearerToken != null && bearerToken.startsWith(TOKEN_PREFIX)) {
|
||||||
// 去掉令牌前缀
|
// 去掉令牌前缀
|
||||||
return bearerToken.replace(tokenStartWith, "");
|
return bearerToken.replace(TOKEN_PREFIX, "");
|
||||||
} else {
|
} else {
|
||||||
log.debug("非法Token:{}", bearerToken);
|
log.debug("非法Token:{}", bearerToken);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,8 +118,8 @@ public class SqlUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String executeFile(String jdbcUrl, String userName, String password, File sqlFile) {
|
public static String executeFile(String jdbcUrl, String username, String password, File sqlFile) {
|
||||||
Connection connection = getConnection(jdbcUrl, userName, password);
|
Connection connection = getConnection(jdbcUrl, username, password);
|
||||||
try {
|
try {
|
||||||
batchExecute(connection, readSqlList(sqlFile));
|
batchExecute(connection, readSqlList(sqlFile));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1,18 +1,9 @@
|
|||||||
package cn.odboy.util;
|
package cn.odboy.util;
|
||||||
|
|
||||||
import cn.hutool.http.useragent.UserAgent;
|
|
||||||
import cn.hutool.http.useragent.UserAgentUtil;
|
|
||||||
import cn.odboy.context.SpringBeanHolder;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
|
|
||||||
import net.dreamlu.mica.ip2region.core.IpInfo;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import java.util.Calendar;
|
||||||
import java.lang.reflect.Field;
|
import java.util.Date;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
|
* 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
|
||||||
@@ -21,12 +12,6 @@ import java.util.*;
|
|||||||
public class StringUtil extends org.apache.commons.lang3.StringUtils {
|
public class StringUtil extends org.apache.commons.lang3.StringUtils {
|
||||||
|
|
||||||
private static final char SEPARATOR = '_';
|
private static final char SEPARATOR = '_';
|
||||||
private static final String UNKNOWN = "unknown";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注入bean
|
|
||||||
*/
|
|
||||||
private final static Ip2regionSearcher IP_SEARCHER = SpringBeanHolder.getBean(Ip2regionSearcher.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 驼峰命名法工具
|
* 驼峰命名法工具
|
||||||
@@ -113,117 +98,19 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取ip地址
|
|
||||||
*/
|
|
||||||
public static String getIp(HttpServletRequest request) {
|
|
||||||
String ip = request.getHeader("x-forwarded-for");
|
|
||||||
if (ip == null || ip.isEmpty() || UNKNOWN.equalsIgnoreCase(ip)) {
|
|
||||||
ip = request.getHeader("Proxy-Client-IP");
|
|
||||||
}
|
|
||||||
if (ip == null || ip.isEmpty() || UNKNOWN.equalsIgnoreCase(ip)) {
|
|
||||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
|
||||||
}
|
|
||||||
if (ip == null || ip.isEmpty() || UNKNOWN.equalsIgnoreCase(ip)) {
|
|
||||||
ip = request.getRemoteAddr();
|
|
||||||
}
|
|
||||||
String comma = ",";
|
|
||||||
String localhost = "127.0.0.1";
|
|
||||||
if (ip.contains(comma)) {
|
|
||||||
ip = ip.split(",")[0];
|
|
||||||
}
|
|
||||||
if (localhost.equals(ip)) {
|
|
||||||
// 获取本机真正的ip地址
|
|
||||||
try {
|
|
||||||
ip = InetAddress.getLocalHost().getHostAddress();
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据ip获取详细地址
|
|
||||||
*/
|
|
||||||
public static String getCityInfo(String ip) {
|
|
||||||
IpInfo ipInfo = IP_SEARCHER.memorySearch(ip);
|
|
||||||
if (ipInfo != null) {
|
|
||||||
return ipInfo.getAddress();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取浏览器
|
|
||||||
*/
|
|
||||||
public static String getBrowser(HttpServletRequest request) {
|
|
||||||
UserAgent ua = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
|
||||||
String browser = ua.getBrowser().toString() + " " + ua.getVersion();
|
|
||||||
return browser.replace(".0.0.0", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得当天是周几
|
* 获得当天是周几
|
||||||
*/
|
*/
|
||||||
public static String getWeekDay() {
|
public static String getWeekDay() {
|
||||||
String[] weekDays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
// String[] weekDays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||||
|
String[] weekDays = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"};
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.setTime(new Date());
|
cal.setTime(new Date());
|
||||||
|
|
||||||
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||||||
if (w < 0) {
|
if (w < 0) {
|
||||||
w = 0;
|
w = 0;
|
||||||
}
|
}
|
||||||
return weekDays[w];
|
return weekDays[w];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前机器的IP
|
|
||||||
*
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
public static String getLocalIp() {
|
|
||||||
try {
|
|
||||||
InetAddress candidateAddress = null;
|
|
||||||
// 遍历所有的网络接口
|
|
||||||
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements(); ) {
|
|
||||||
NetworkInterface anInterface = interfaces.nextElement();
|
|
||||||
// 在所有的接口下再遍历IP
|
|
||||||
for (Enumeration<InetAddress> inetAddresses = anInterface.getInetAddresses(); inetAddresses.hasMoreElements(); ) {
|
|
||||||
InetAddress inetAddr = inetAddresses.nextElement();
|
|
||||||
// 排除loopback类型地址
|
|
||||||
if (!inetAddr.isLoopbackAddress()) {
|
|
||||||
if (inetAddr.isSiteLocalAddress()) {
|
|
||||||
// 如果是site-local地址,就是它了
|
|
||||||
return inetAddr.getHostAddress();
|
|
||||||
} else if (candidateAddress == null) {
|
|
||||||
// site-local类型的地址未被发现,先记录候选地址
|
|
||||||
candidateAddress = inetAddr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (candidateAddress != null) {
|
|
||||||
return candidateAddress.getHostAddress();
|
|
||||||
}
|
|
||||||
// 如果没有发现 non-loopback地址.只能用最次选的方案
|
|
||||||
InetAddress jdkSuppliedAddress = InetAddress.getLocalHost();
|
|
||||||
if (jdkSuppliedAddress == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return jdkSuppliedAddress.getHostAddress();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "all"})
|
|
||||||
public static List<Field> getAllFields(Class clazz, List<Field> fields) {
|
|
||||||
if (clazz != null) {
|
|
||||||
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
|
||||||
getAllFields(clazz.getSuperclass(), fields);
|
|
||||||
}
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -19,10 +19,7 @@ public class WebSocketServerFactory implements WebServerFactoryCustomizer<Undert
|
|||||||
public void customize(UndertowServletWebServerFactory factory) {
|
public void customize(UndertowServletWebServerFactory factory) {
|
||||||
factory.addDeploymentInfoCustomizers(deploymentInfo -> {
|
factory.addDeploymentInfoCustomizers(deploymentInfo -> {
|
||||||
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
|
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
|
||||||
webSocketDeploymentInfo.setBuffers(
|
webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(false, 1024));
|
||||||
new DefaultByteBufferPool(false, 1024)
|
|
||||||
// new DefaultByteBufferPool(false, 1024,20,4)
|
|
||||||
);
|
|
||||||
deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
|
deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package cn.odboy.model.system.dto;
|
package cn.odboy.model.system.dto;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -11,10 +9,7 @@ import java.util.Date;
|
|||||||
* 在线用户
|
* 在线用户
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class OnlineUserDto {
|
public class OnlineUserDto {
|
||||||
|
|
||||||
@ApiModelProperty(value = "Token编号")
|
@ApiModelProperty(value = "Token编号")
|
||||||
private String uid;
|
private String uid;
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class EmailConfig extends MyObject {
|
|||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@ApiModelProperty(value = "密码")
|
@ApiModelProperty(value = "密码")
|
||||||
private String pass;
|
private String password;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@ApiModelProperty(value = "收件人")
|
@ApiModelProperty(value = "收件人")
|
||||||
|
|||||||
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
package cn.odboy.config;
|
package cn.odboy.application.job.config;
|
||||||
|
|
||||||
import cn.odboy.mapper.QuartzJobMapper;
|
import cn.odboy.application.job.mapper.QuartzJobMapper;
|
||||||
|
import cn.odboy.application.job.util.QuartzManage;
|
||||||
import cn.odboy.model.job.domain.QuartzJob;
|
import cn.odboy.model.job.domain.QuartzJob;
|
||||||
import cn.odboy.util.QuartzManage;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
@@ -25,7 +25,7 @@ public class JobRunner implements ApplicationRunner {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments applicationArguments) {
|
public void run(ApplicationArguments applicationArguments) {
|
||||||
List<QuartzJob> quartzJobs = quartzJobMapper.findActiveQuartzJob();
|
List<QuartzJob> quartzJobs = quartzJobMapper.selectActiveQuartzJob();
|
||||||
quartzJobs.forEach(quartzManage::addJob);
|
quartzJobs.forEach(quartzManage::addJob);
|
||||||
log.info("Timing task injection complete");
|
log.info("Timing task injection complete");
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.config;
|
package cn.odboy.application.job.config;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.quartz.spi.TriggerFiredBundle;
|
import org.quartz.spi.TriggerFiredBundle;
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.mapper;
|
package cn.odboy.application.job.mapper;
|
||||||
|
|
||||||
import cn.odboy.model.job.domain.QuartzJob;
|
import cn.odboy.model.job.domain.QuartzJob;
|
||||||
import cn.odboy.model.job.dto.QuartzJobQueryCriteria;
|
import cn.odboy.model.job.dto.QuartzJobQueryCriteria;
|
||||||
@@ -12,7 +12,7 @@ import java.util.List;
|
|||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface QuartzJobMapper extends BaseMapper<QuartzJob> {
|
public interface QuartzJobMapper extends BaseMapper<QuartzJob> {
|
||||||
IPage<QuartzJob> findQuartzJobPage(@Param("criteria") QuartzJobQueryCriteria criteria, Page<Object> page);
|
IPage<QuartzJob> queryQuartzJobPage(@Param("criteria") QuartzJobQueryCriteria criteria, Page<Object> page);
|
||||||
|
|
||||||
List<QuartzJob> findActiveQuartzJob();
|
List<QuartzJob> selectActiveQuartzJob();
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.mapper;
|
package cn.odboy.application.job.mapper;
|
||||||
|
|
||||||
import cn.odboy.model.job.domain.QuartzLog;
|
import cn.odboy.model.job.domain.QuartzLog;
|
||||||
import cn.odboy.model.job.dto.QuartzJobQueryCriteria;
|
import cn.odboy.model.job.dto.QuartzJobQueryCriteria;
|
||||||
@@ -11,5 +11,5 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface QuartzLogMapper extends BaseMapper<QuartzLog> {
|
public interface QuartzLogMapper extends BaseMapper<QuartzLog> {
|
||||||
IPage<QuartzLog> findQuartzLogPage(@Param("criteria") QuartzJobQueryCriteria criteria, Page<Object> page);
|
IPage<QuartzLog> queryQuartzLogPage(@Param("criteria") QuartzJobQueryCriteria criteria, Page<Object> page);
|
||||||
}
|
}
|
||||||
+11
-11
@@ -1,12 +1,12 @@
|
|||||||
package cn.odboy.rest;
|
package cn.odboy.application.job.rest;
|
||||||
|
|
||||||
|
import cn.odboy.application.job.service.QuartzJobService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.context.SpringBeanHolder;
|
import cn.odboy.context.SpringBeanHolder;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.job.domain.QuartzJob;
|
import cn.odboy.model.job.domain.QuartzJob;
|
||||||
import cn.odboy.model.job.domain.QuartzLog;
|
import cn.odboy.model.job.domain.QuartzLog;
|
||||||
import cn.odboy.model.job.dto.QuartzJobQueryCriteria;
|
import cn.odboy.model.job.dto.QuartzJobQueryCriteria;
|
||||||
import cn.odboy.service.QuartzJobService;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -38,21 +38,21 @@ public class QuartzJobController {
|
|||||||
@PreAuthorize("@el.check('timing:list')")
|
@PreAuthorize("@el.check('timing:list')")
|
||||||
public ResponseEntity<PageResult<QuartzJob>> queryQuartzJob(QuartzJobQueryCriteria criteria) {
|
public ResponseEntity<PageResult<QuartzJob>> queryQuartzJob(QuartzJobQueryCriteria criteria) {
|
||||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||||
return new ResponseEntity<>(quartzJobService.queryAll(criteria, page), HttpStatus.OK);
|
return new ResponseEntity<>(quartzJobService.queryJobPage(criteria, page), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("导出任务数据")
|
@ApiOperation("导出任务数据")
|
||||||
@GetMapping(value = "/download")
|
@GetMapping(value = "/download")
|
||||||
@PreAuthorize("@el.check('timing:list')")
|
@PreAuthorize("@el.check('timing:list')")
|
||||||
public void exportQuartzJob(HttpServletResponse response, QuartzJobQueryCriteria criteria) throws IOException {
|
public void exportQuartzJob(HttpServletResponse response, QuartzJobQueryCriteria criteria) throws IOException {
|
||||||
quartzJobService.download(quartzJobService.queryAll(criteria), response);
|
quartzJobService.downloadJobExcel(quartzJobService.selectJobByCriteria(criteria), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("导出日志数据")
|
@ApiOperation("导出日志数据")
|
||||||
@GetMapping(value = "/logs/download")
|
@GetMapping(value = "/logs/download")
|
||||||
@PreAuthorize("@el.check('timing:list')")
|
@PreAuthorize("@el.check('timing:list')")
|
||||||
public void exportQuartzJobLog(HttpServletResponse response, QuartzJobQueryCriteria criteria) throws IOException {
|
public void exportQuartzJobLog(HttpServletResponse response, QuartzJobQueryCriteria criteria) throws IOException {
|
||||||
quartzJobService.downloadLog(quartzJobService.queryAllLog(criteria), response);
|
quartzJobService.downloadLogExcel(quartzJobService.selectLogByCriteria(criteria), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("查询任务执行日志")
|
@ApiOperation("查询任务执行日志")
|
||||||
@@ -60,7 +60,7 @@ public class QuartzJobController {
|
|||||||
@PreAuthorize("@el.check('timing:list')")
|
@PreAuthorize("@el.check('timing:list')")
|
||||||
public ResponseEntity<PageResult<QuartzLog>> queryQuartzJobLog(QuartzJobQueryCriteria criteria) {
|
public ResponseEntity<PageResult<QuartzLog>> queryQuartzJobLog(QuartzJobQueryCriteria criteria) {
|
||||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||||
return new ResponseEntity<>(quartzJobService.queryAllLog(criteria, page), HttpStatus.OK);
|
return new ResponseEntity<>(quartzJobService.queryLogPage(criteria, page), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("新增定时任务")
|
@ApiOperation("新增定时任务")
|
||||||
@@ -72,7 +72,7 @@ public class QuartzJobController {
|
|||||||
}
|
}
|
||||||
// 验证Bean是不是合法的,合法的定时任务 Bean 需要用 @Service 定义
|
// 验证Bean是不是合法的,合法的定时任务 Bean 需要用 @Service 定义
|
||||||
checkBean(resources.getBeanName());
|
checkBean(resources.getBeanName());
|
||||||
quartzJobService.create(resources);
|
quartzJobService.createJob(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ public class QuartzJobController {
|
|||||||
public ResponseEntity<Object> updateQuartzJob(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources) {
|
public ResponseEntity<Object> updateQuartzJob(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources) {
|
||||||
// 验证Bean是不是合法的,合法的定时任务 Bean 需要用 @Service 定义
|
// 验证Bean是不是合法的,合法的定时任务 Bean 需要用 @Service 定义
|
||||||
checkBean(resources.getBeanName());
|
checkBean(resources.getBeanName());
|
||||||
quartzJobService.update(resources);
|
quartzJobService.updateJob(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public class QuartzJobController {
|
|||||||
@PutMapping(value = "/{id}")
|
@PutMapping(value = "/{id}")
|
||||||
@PreAuthorize("@el.check('timing:edit')")
|
@PreAuthorize("@el.check('timing:edit')")
|
||||||
public ResponseEntity<Object> updateQuartzJobStatus(@PathVariable Long id) {
|
public ResponseEntity<Object> updateQuartzJobStatus(@PathVariable Long id) {
|
||||||
quartzJobService.updateIsPause(quartzJobService.getById(id));
|
quartzJobService.switchJobPauseStatus(quartzJobService.getById(id));
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ public class QuartzJobController {
|
|||||||
@PutMapping(value = "/exec/{id}")
|
@PutMapping(value = "/exec/{id}")
|
||||||
@PreAuthorize("@el.check('timing:edit')")
|
@PreAuthorize("@el.check('timing:edit')")
|
||||||
public ResponseEntity<Object> executionQuartzJob(@PathVariable Long id) {
|
public ResponseEntity<Object> executionQuartzJob(@PathVariable Long id) {
|
||||||
quartzJobService.execution(quartzJobService.getById(id));
|
quartzJobService.executionJob(quartzJobService.getById(id));
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ public class QuartzJobController {
|
|||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@PreAuthorize("@el.check('timing:del')")
|
@PreAuthorize("@el.check('timing:del')")
|
||||||
public ResponseEntity<Object> deleteQuartzJob(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> deleteQuartzJob(@RequestBody Set<Long> ids) {
|
||||||
quartzJobService.delete(ids);
|
quartzJobService.deleteJobByIds(ids);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
+12
-12
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.service;
|
package cn.odboy.application.job.service;
|
||||||
|
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.model.job.domain.QuartzJob;
|
import cn.odboy.model.job.domain.QuartzJob;
|
||||||
@@ -22,7 +22,7 @@ public interface QuartzJobService extends IService<QuartzJob> {
|
|||||||
* @param page 分页参数
|
* @param page 分页参数
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
PageResult<QuartzJob> queryAll(QuartzJobQueryCriteria criteria, Page<Object> page);
|
PageResult<QuartzJob> queryJobPage(QuartzJobQueryCriteria criteria, Page<Object> page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询全部
|
* 查询全部
|
||||||
@@ -30,7 +30,7 @@ public interface QuartzJobService extends IService<QuartzJob> {
|
|||||||
* @param criteria 条件
|
* @param criteria 条件
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<QuartzJob> queryAll(QuartzJobQueryCriteria criteria);
|
List<QuartzJob> selectJobByCriteria(QuartzJobQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询日志
|
* 分页查询日志
|
||||||
@@ -39,7 +39,7 @@ public interface QuartzJobService extends IService<QuartzJob> {
|
|||||||
* @param page 分页参数
|
* @param page 分页参数
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
PageResult<QuartzLog> queryAllLog(QuartzJobQueryCriteria criteria, Page<Object> page);
|
PageResult<QuartzLog> queryLogPage(QuartzJobQueryCriteria criteria, Page<Object> page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询全部
|
* 查询全部
|
||||||
@@ -47,42 +47,42 @@ public interface QuartzJobService extends IService<QuartzJob> {
|
|||||||
* @param criteria 条件
|
* @param criteria 条件
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<QuartzLog> queryAllLog(QuartzJobQueryCriteria criteria);
|
List<QuartzLog> selectLogByCriteria(QuartzJobQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建
|
* 创建
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void create(QuartzJob resources);
|
void createJob(QuartzJob resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑
|
* 编辑
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void update(QuartzJob resources);
|
void updateJob(QuartzJob resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除任务
|
* 删除任务
|
||||||
*
|
*
|
||||||
* @param ids /
|
* @param ids /
|
||||||
*/
|
*/
|
||||||
void delete(Set<Long> ids);
|
void deleteJobByIds(Set<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更改定时任务状态
|
* 更改定时任务状态
|
||||||
*
|
*
|
||||||
* @param quartzJob /
|
* @param quartzJob /
|
||||||
*/
|
*/
|
||||||
void updateIsPause(QuartzJob quartzJob);
|
void switchJobPauseStatus(QuartzJob quartzJob);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 立即执行定时任务
|
* 立即执行定时任务
|
||||||
*
|
*
|
||||||
* @param quartzJob /
|
* @param quartzJob /
|
||||||
*/
|
*/
|
||||||
void execution(QuartzJob quartzJob);
|
void executionJob(QuartzJob quartzJob);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出定时任务
|
* 导出定时任务
|
||||||
@@ -91,7 +91,7 @@ public interface QuartzJobService extends IService<QuartzJob> {
|
|||||||
* @param response /
|
* @param response /
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void download(List<QuartzJob> queryAll, HttpServletResponse response) throws IOException;
|
void downloadJobExcel(List<QuartzJob> queryAll, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出定时任务日志
|
* 导出定时任务日志
|
||||||
@@ -100,7 +100,7 @@ public interface QuartzJobService extends IService<QuartzJob> {
|
|||||||
* @param response /
|
* @param response /
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void downloadLog(List<QuartzLog> queryAllLog, HttpServletResponse response) throws IOException;
|
void downloadLogExcel(List<QuartzLog> queryAllLog, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行子任务
|
* 执行子任务
|
||||||
+25
-21
@@ -1,16 +1,20 @@
|
|||||||
package cn.odboy.service.impl;
|
package cn.odboy.application.job.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.odboy.application.job.mapper.QuartzJobMapper;
|
||||||
|
import cn.odboy.application.job.mapper.QuartzLogMapper;
|
||||||
|
import cn.odboy.application.job.service.QuartzJobService;
|
||||||
|
import cn.odboy.application.job.util.QuartzManage;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.mapper.QuartzJobMapper;
|
|
||||||
import cn.odboy.mapper.QuartzLogMapper;
|
|
||||||
import cn.odboy.model.job.domain.QuartzJob;
|
import cn.odboy.model.job.domain.QuartzJob;
|
||||||
import cn.odboy.model.job.domain.QuartzLog;
|
import cn.odboy.model.job.domain.QuartzLog;
|
||||||
import cn.odboy.model.job.dto.QuartzJobQueryCriteria;
|
import cn.odboy.model.job.dto.QuartzJobQueryCriteria;
|
||||||
import cn.odboy.service.QuartzJobService;
|
import cn.odboy.util.FileUtil;
|
||||||
import cn.odboy.util.*;
|
import cn.odboy.util.PageUtil;
|
||||||
|
import cn.odboy.util.RedisUtil;
|
||||||
|
import cn.odboy.util.StringUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -32,28 +36,28 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<QuartzJob> queryAll(QuartzJobQueryCriteria criteria, Page<Object> page) {
|
public PageResult<QuartzJob> queryJobPage(QuartzJobQueryCriteria criteria, Page<Object> page) {
|
||||||
return PageUtil.toPage(quartzJobMapper.findQuartzJobPage(criteria, page));
|
return PageUtil.toPage(quartzJobMapper.queryQuartzJobPage(criteria, page));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<QuartzLog> queryAllLog(QuartzJobQueryCriteria criteria, Page<Object> page) {
|
public PageResult<QuartzLog> queryLogPage(QuartzJobQueryCriteria criteria, Page<Object> page) {
|
||||||
return PageUtil.toPage(quartzLogMapper.findQuartzLogPage(criteria, page));
|
return PageUtil.toPage(quartzLogMapper.queryQuartzLogPage(criteria, page));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<QuartzJob> queryAll(QuartzJobQueryCriteria criteria) {
|
public List<QuartzJob> selectJobByCriteria(QuartzJobQueryCriteria criteria) {
|
||||||
return quartzJobMapper.findQuartzJobPage(criteria, PageUtil.getCount(quartzJobMapper)).getRecords();
|
return quartzJobMapper.queryQuartzJobPage(criteria, PageUtil.getCount(quartzJobMapper)).getRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<QuartzLog> queryAllLog(QuartzJobQueryCriteria criteria) {
|
public List<QuartzLog> selectLogByCriteria(QuartzJobQueryCriteria criteria) {
|
||||||
return quartzLogMapper.findQuartzLogPage(criteria, PageUtil.getCount(quartzLogMapper)).getRecords();
|
return quartzLogMapper.queryQuartzLogPage(criteria, PageUtil.getCount(quartzLogMapper)).getRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(QuartzJob resources) {
|
public void createJob(QuartzJob resources) {
|
||||||
if (!CronExpression.isValidExpression(resources.getCronExpression())) {
|
if (!CronExpression.isValidExpression(resources.getCronExpression())) {
|
||||||
throw new BadRequestException("cron表达式格式错误");
|
throw new BadRequestException("cron表达式格式错误");
|
||||||
}
|
}
|
||||||
@@ -63,7 +67,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(QuartzJob resources) {
|
public void updateJob(QuartzJob resources) {
|
||||||
if (!CronExpression.isValidExpression(resources.getCronExpression())) {
|
if (!CronExpression.isValidExpression(resources.getCronExpression())) {
|
||||||
throw new BadRequestException("cron表达式格式错误");
|
throw new BadRequestException("cron表达式格式错误");
|
||||||
}
|
}
|
||||||
@@ -79,7 +83,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateIsPause(QuartzJob quartzJob) {
|
public void switchJobPauseStatus(QuartzJob quartzJob) {
|
||||||
// 置换暂停状态
|
// 置换暂停状态
|
||||||
if (quartzJob.getIsPause()) {
|
if (quartzJob.getIsPause()) {
|
||||||
quartzManage.resumeJob(quartzJob);
|
quartzManage.resumeJob(quartzJob);
|
||||||
@@ -92,13 +96,13 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execution(QuartzJob quartzJob) {
|
public void executionJob(QuartzJob quartzJob) {
|
||||||
quartzManage.runJobNow(quartzJob);
|
quartzManage.runJobNow(quartzJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<Long> ids) {
|
public void deleteJobByIds(Set<Long> ids) {
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
QuartzJob quartzJob = getById(id);
|
QuartzJob quartzJob = getById(id);
|
||||||
quartzManage.deleteJob(quartzJob);
|
quartzManage.deleteJob(quartzJob);
|
||||||
@@ -119,7 +123,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
String uuid = IdUtil.simpleUUID();
|
String uuid = IdUtil.simpleUUID();
|
||||||
quartzJob.setUuid(uuid);
|
quartzJob.setUuid(uuid);
|
||||||
// 执行任务
|
// 执行任务
|
||||||
execution(quartzJob);
|
executionJob(quartzJob);
|
||||||
// 获取执行状态,如果执行失败则停止后面的子任务执行
|
// 获取执行状态,如果执行失败则停止后面的子任务执行
|
||||||
Boolean result = redisUtil.get(uuid, Boolean.class);
|
Boolean result = redisUtil.get(uuid, Boolean.class);
|
||||||
while (result == null) {
|
while (result == null) {
|
||||||
@@ -135,7 +139,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<QuartzJob> quartzJobs, HttpServletResponse response) throws IOException {
|
public void downloadJobExcel(List<QuartzJob> quartzJobs, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (QuartzJob quartzJob : quartzJobs) {
|
for (QuartzJob quartzJob : quartzJobs) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
@@ -153,7 +157,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadLog(List<QuartzLog> queryAllLog, HttpServletResponse response) throws IOException {
|
public void downloadLogExcel(List<QuartzLog> queryAllLog, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (QuartzLog quartzLog : queryAllLog) {
|
for (QuartzLog quartzLog : queryAllLog) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.task;
|
package cn.odboy.application.job.task;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
+24
-20
@@ -1,17 +1,19 @@
|
|||||||
package cn.odboy.util;
|
package cn.odboy.application.job.util;
|
||||||
|
|
||||||
import cn.hutool.extra.template.Template;
|
import cn.hutool.extra.template.Template;
|
||||||
import cn.hutool.extra.template.TemplateConfig;
|
import cn.hutool.extra.template.TemplateConfig;
|
||||||
import cn.hutool.extra.template.TemplateEngine;
|
import cn.hutool.extra.template.TemplateEngine;
|
||||||
import cn.hutool.extra.template.TemplateUtil;
|
import cn.hutool.extra.template.TemplateUtil;
|
||||||
|
import cn.odboy.application.job.mapper.QuartzLogMapper;
|
||||||
|
import cn.odboy.application.job.service.QuartzJobService;
|
||||||
|
import cn.odboy.application.tools.service.EmailService;
|
||||||
import cn.odboy.context.SpringBeanHolder;
|
import cn.odboy.context.SpringBeanHolder;
|
||||||
import cn.odboy.exception.util.ThrowableUtil;
|
import cn.odboy.exception.util.ThrowableUtil;
|
||||||
import cn.odboy.mapper.QuartzLogMapper;
|
|
||||||
import cn.odboy.model.job.domain.QuartzJob;
|
import cn.odboy.model.job.domain.QuartzJob;
|
||||||
import cn.odboy.model.job.domain.QuartzLog;
|
import cn.odboy.model.job.domain.QuartzLog;
|
||||||
import cn.odboy.model.tools.dto.EmailDto;
|
import cn.odboy.model.tools.dto.EmailDto;
|
||||||
import cn.odboy.service.EmailService;
|
import cn.odboy.util.RedisUtil;
|
||||||
import cn.odboy.service.QuartzJobService;
|
import cn.odboy.util.StringUtil;
|
||||||
import org.quartz.JobExecutionContext;
|
import org.quartz.JobExecutionContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -26,7 +28,9 @@ import java.util.concurrent.Future;
|
|||||||
|
|
||||||
public class ExecutionJob extends QuartzJobBean {
|
public class ExecutionJob extends QuartzJobBean {
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
// 此处仅供参考,可根据任务执行情况自定义线程池参数
|
/**
|
||||||
|
* 此处仅供参考,可根据任务执行情况自定义线程池参数
|
||||||
|
*/
|
||||||
private final ThreadPoolTaskExecutor executor = SpringBeanHolder.getBean("taskAsync");
|
private final ThreadPoolTaskExecutor executor = SpringBeanHolder.getBean("taskAsync");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,25 +44,25 @@ public class ExecutionJob extends QuartzJobBean {
|
|||||||
|
|
||||||
String uuid = quartzJob.getUuid();
|
String uuid = quartzJob.getUuid();
|
||||||
|
|
||||||
QuartzLog log = new QuartzLog();
|
QuartzLog quartzLog = new QuartzLog();
|
||||||
log.setJobName(quartzJob.getJobName());
|
quartzLog.setJobName(quartzJob.getJobName());
|
||||||
log.setBeanName(quartzJob.getBeanName());
|
quartzLog.setBeanName(quartzJob.getBeanName());
|
||||||
log.setMethodName(quartzJob.getMethodName());
|
quartzLog.setMethodName(quartzJob.getMethodName());
|
||||||
log.setParams(quartzJob.getParams());
|
quartzLog.setParams(quartzJob.getParams());
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
log.setCronExpression(quartzJob.getCronExpression());
|
quartzLog.setCronExpression(quartzJob.getCronExpression());
|
||||||
try {
|
try {
|
||||||
// 执行任务
|
// 执行任务
|
||||||
QuartzRunnable task = new QuartzRunnable(quartzJob.getBeanName(), quartzJob.getMethodName(), quartzJob.getParams());
|
QuartzRunnable task = new QuartzRunnable(quartzJob.getBeanName(), quartzJob.getMethodName(), quartzJob.getParams());
|
||||||
Future<?> future = executor.submit(task);
|
Future<?> future = executor.submit(task);
|
||||||
future.get();
|
future.get();
|
||||||
long times = System.currentTimeMillis() - startTime;
|
long times = System.currentTimeMillis() - startTime;
|
||||||
log.setTime(times);
|
quartzLog.setTime(times);
|
||||||
if (StringUtil.isNotBlank(uuid)) {
|
if (StringUtil.isNotBlank(uuid)) {
|
||||||
redisUtil.set(uuid, true);
|
redisUtil.set(uuid, true);
|
||||||
}
|
}
|
||||||
// 任务状态
|
// 任务状态
|
||||||
log.setIsSuccess(true);
|
quartzLog.setIsSuccess(true);
|
||||||
logger.info("任务执行成功,任务名称:{}, 执行时间:{}毫秒", quartzJob.getJobName(), times);
|
logger.info("任务执行成功,任务名称:{}, 执行时间:{}毫秒", quartzJob.getJobName(), times);
|
||||||
// 判断是否存在子任务
|
// 判断是否存在子任务
|
||||||
if (StringUtil.isNotBlank(quartzJob.getSubTask())) {
|
if (StringUtil.isNotBlank(quartzJob.getSubTask())) {
|
||||||
@@ -72,26 +76,26 @@ public class ExecutionJob extends QuartzJobBean {
|
|||||||
}
|
}
|
||||||
logger.error("任务执行失败,任务名称:{}", quartzJob.getJobName());
|
logger.error("任务执行失败,任务名称:{}", quartzJob.getJobName());
|
||||||
long times = System.currentTimeMillis() - startTime;
|
long times = System.currentTimeMillis() - startTime;
|
||||||
log.setTime(times);
|
quartzLog.setTime(times);
|
||||||
// 任务状态 0:成功 1:失败
|
// 任务状态 0:成功 1:失败
|
||||||
log.setIsSuccess(false);
|
quartzLog.setIsSuccess(false);
|
||||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(e));
|
quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
|
||||||
// 任务如果失败了则暂停
|
// 任务如果失败了则暂停
|
||||||
if (quartzJob.getPauseAfterFailure() != null && quartzJob.getPauseAfterFailure()) {
|
if (quartzJob.getPauseAfterFailure() != null && quartzJob.getPauseAfterFailure()) {
|
||||||
quartzJob.setIsPause(false);
|
quartzJob.setIsPause(false);
|
||||||
//更新状态
|
// 更新状态
|
||||||
quartzJobService.updateIsPause(quartzJob);
|
quartzJobService.switchJobPauseStatus(quartzJob);
|
||||||
}
|
}
|
||||||
if (quartzJob.getEmail() != null) {
|
if (quartzJob.getEmail() != null) {
|
||||||
EmailService emailService = SpringBeanHolder.getBean(EmailService.class);
|
EmailService emailService = SpringBeanHolder.getBean(EmailService.class);
|
||||||
// 邮箱报警
|
// 邮箱报警
|
||||||
if (StringUtil.isNoneBlank(quartzJob.getEmail())) {
|
if (StringUtil.isNoneBlank(quartzJob.getEmail())) {
|
||||||
EmailDto emailDto = taskAlarm(quartzJob, ThrowableUtil.getStackTrace(e));
|
EmailDto emailDto = taskAlarm(quartzJob, ThrowableUtil.getStackTrace(e));
|
||||||
emailService.send(emailDto, emailService.find());
|
emailService.sendEmail(emailDto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
quartzLogMapper.insert(log);
|
quartzLogMapper.insert(quartzLog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+5
-5
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.util;
|
package cn.odboy.application.job.util;
|
||||||
|
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.job.domain.QuartzJob;
|
import cn.odboy.model.job.domain.QuartzJob;
|
||||||
@@ -25,7 +25,7 @@ public class QuartzManage {
|
|||||||
JobDetail jobDetail = JobBuilder.newJob(ExecutionJob.class).
|
JobDetail jobDetail = JobBuilder.newJob(ExecutionJob.class).
|
||||||
withIdentity(JOB_NAME + quartzJob.getId()).build();
|
withIdentity(JOB_NAME + quartzJob.getId()).build();
|
||||||
|
|
||||||
//通过触发器名和cron 表达式创建 Trigger
|
// 通过触发器名和cron 表达式创建 Trigger
|
||||||
Trigger cronTrigger = TriggerBuilder.newTrigger()
|
Trigger cronTrigger = TriggerBuilder.newTrigger()
|
||||||
.withIdentity(JOB_NAME + quartzJob.getId())
|
.withIdentity(JOB_NAME + quartzJob.getId())
|
||||||
.startNow()
|
.startNow()
|
||||||
@@ -34,10 +34,10 @@ public class QuartzManage {
|
|||||||
|
|
||||||
cronTrigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob);
|
cronTrigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob);
|
||||||
|
|
||||||
//重置启动时间
|
// 重置启动时间
|
||||||
((CronTriggerImpl) cronTrigger).setStartTime(new Date());
|
((CronTriggerImpl) cronTrigger).setStartTime(new Date());
|
||||||
|
|
||||||
//执行定时任务,如果是持久化的,这里会报错,捕获输出
|
// 执行定时任务,如果是持久化的,这里会报错,捕获输出
|
||||||
try {
|
try {
|
||||||
scheduler.scheduleJob(jobDetail, cronTrigger);
|
scheduler.scheduleJob(jobDetail, cronTrigger);
|
||||||
} catch (ObjectAlreadyExistsException e) {
|
} catch (ObjectAlreadyExistsException e) {
|
||||||
@@ -70,7 +70,7 @@ public class QuartzManage {
|
|||||||
}
|
}
|
||||||
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression());
|
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression());
|
||||||
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
|
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
|
||||||
//重置启动时间
|
// 重置启动时间
|
||||||
((CronTriggerImpl) trigger).setStartTime(new Date());
|
((CronTriggerImpl) trigger).setStartTime(new Date());
|
||||||
trigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob);
|
trigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob);
|
||||||
|
|
||||||
+2
-4
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.util;
|
package cn.odboy.application.job.util;
|
||||||
|
|
||||||
import cn.odboy.context.SpringBeanHolder;
|
import cn.odboy.context.SpringBeanHolder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -13,13 +13,11 @@ import java.util.concurrent.Callable;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class QuartzRunnable implements Callable<Object> {
|
public class QuartzRunnable implements Callable<Object> {
|
||||||
|
|
||||||
private final Object target;
|
private final Object target;
|
||||||
private final Method method;
|
private final Method method;
|
||||||
private final String params;
|
private final String params;
|
||||||
|
|
||||||
QuartzRunnable(String beanName, String methodName, String params)
|
protected QuartzRunnable(String beanName, String methodName, String params) throws NoSuchMethodException, SecurityException {
|
||||||
throws NoSuchMethodException, SecurityException {
|
|
||||||
this.target = SpringBeanHolder.getBean(beanName);
|
this.target = SpringBeanHolder.getBean(beanName);
|
||||||
this.params = params;
|
this.params = params;
|
||||||
if (StringUtils.isNotBlank(params)) {
|
if (StringUtils.isNotBlank(params)) {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="cn.odboy.mapper.QuartzJobMapper">
|
<mapper namespace="cn.odboy.application.job.mapper.QuartzJobMapper">
|
||||||
<select id="findQuartzJobPage" resultType="cn.odboy.model.job.domain.QuartzJob">
|
<select id="queryQuartzJobPage" resultType="cn.odboy.model.job.domain.QuartzJob">
|
||||||
SELECT
|
SELECT
|
||||||
*
|
*
|
||||||
FROM sys_quartz_job
|
FROM sys_quartz_job
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
</where>
|
</where>
|
||||||
ORDER BY id DESC
|
ORDER BY id DESC
|
||||||
</select>
|
</select>
|
||||||
<select id="findActiveQuartzJob" resultType="cn.odboy.model.job.domain.QuartzJob">
|
<select id="selectActiveQuartzJob" resultType="cn.odboy.model.job.domain.QuartzJob">
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM sys_quartz_job
|
FROM sys_quartz_job
|
||||||
WHERE is_pause = 0
|
WHERE is_pause = 0
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="cn.odboy.mapper.QuartzLogMapper">
|
<mapper namespace="cn.odboy.application.job.mapper.QuartzLogMapper">
|
||||||
<select id="findQuartzLogPage" resultType="cn.odboy.model.job.domain.QuartzLog">
|
<select id="queryQuartzLogPage" resultType="cn.odboy.model.job.domain.QuartzLog">
|
||||||
SELECT
|
SELECT
|
||||||
*
|
*
|
||||||
FROM sys_quartz_log
|
FROM sys_quartz_log
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ spring:
|
|||||||
max-idle: 20
|
max-idle: 20
|
||||||
# 连接池中的最小空闲连接数
|
# 连接池中的最小空闲连接数
|
||||||
min-idle: 1
|
min-idle: 1
|
||||||
|
|
||||||
# 持久层
|
# 持久层
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
configuration:
|
configuration:
|
||||||
@@ -162,10 +161,6 @@ mybatis-plus:
|
|||||||
login:
|
login:
|
||||||
# 是否限制单用户登录
|
# 是否限制单用户登录
|
||||||
single-login: false
|
single-login: false
|
||||||
# Redis用户登录缓存配置
|
|
||||||
user-cache:
|
|
||||||
# 存活时间/秒
|
|
||||||
idle-time: 21600
|
|
||||||
# 验证码
|
# 验证码
|
||||||
code:
|
code:
|
||||||
# 验证码类型配置 查看 LoginProperties 类
|
# 验证码类型配置 查看 LoginProperties 类
|
||||||
@@ -185,17 +180,10 @@ login:
|
|||||||
|
|
||||||
# 鉴权
|
# 鉴权
|
||||||
jwt:
|
jwt:
|
||||||
header: Authorization
|
|
||||||
# 令牌前缀
|
|
||||||
token-start-with: Bearer
|
|
||||||
# 必须使用最少88位的Base64对该令牌进行编码
|
# 必须使用最少88位的Base64对该令牌进行编码
|
||||||
base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
|
base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
|
||||||
# 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
|
# 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
|
||||||
token-validity-in-seconds: 14400000
|
token-validity-in-seconds: 14400000
|
||||||
# 在线用户key
|
|
||||||
online-key: "online_token:"
|
|
||||||
# 验证码
|
|
||||||
code-key: "captcha_code:"
|
|
||||||
# token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
|
# token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
|
||||||
detect: 1800000
|
detect: 1800000
|
||||||
# 续期时间范围,默认1小时,单位毫秒
|
# 续期时间范围,默认1小时,单位毫秒
|
||||||
|
|||||||
@@ -147,10 +147,6 @@ mybatis-plus:
|
|||||||
login:
|
login:
|
||||||
# 是否限制单用户登录
|
# 是否限制单用户登录
|
||||||
single-login: true
|
single-login: true
|
||||||
# Redis用户登录缓存配置
|
|
||||||
user-cache:
|
|
||||||
# 存活时间/秒
|
|
||||||
idle-time: 21600
|
|
||||||
# 验证码
|
# 验证码
|
||||||
code:
|
code:
|
||||||
# 验证码类型配置 查看 LoginProperties 类
|
# 验证码类型配置 查看 LoginProperties 类
|
||||||
@@ -170,17 +166,10 @@ login:
|
|||||||
|
|
||||||
# 鉴权
|
# 鉴权
|
||||||
jwt:
|
jwt:
|
||||||
header: Authorization
|
|
||||||
# 令牌前缀
|
|
||||||
token-start-with: Bearer
|
|
||||||
# 必须使用最少88位的Base64对该令牌进行编码
|
# 必须使用最少88位的Base64对该令牌进行编码
|
||||||
base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
|
base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
|
||||||
# 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
|
# 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
|
||||||
token-validity-in-seconds: 14400000
|
token-validity-in-seconds: 14400000
|
||||||
# 在线用户key
|
|
||||||
online-key: "online_token:"
|
|
||||||
# 验证码
|
|
||||||
code-key: "captcha_code:"
|
|
||||||
# token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
|
# token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
|
||||||
detect: 1800000
|
detect: 1800000
|
||||||
# 续期时间范围,默认1小时,单位毫秒
|
# 续期时间范围,默认1小时,单位毫秒
|
||||||
|
|||||||
+3
-3
@@ -3,11 +3,11 @@ package cn.odboy.util;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static cn.odboy.util.EncryptUtil.desDecrypt;
|
import static cn.odboy.util.DESEncryptUtil.desDecrypt;
|
||||||
import static cn.odboy.util.EncryptUtil.desEncrypt;
|
import static cn.odboy.util.DESEncryptUtil.desEncrypt;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class EncryptUtilTest {
|
public class DESEncryptUtilTest {
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package cn.odboy.util;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class DateUtilTest {
|
|
||||||
@Test
|
|
||||||
public void test1() {
|
|
||||||
long l = System.currentTimeMillis() / 1000;
|
|
||||||
LocalDateTime localDateTime = DateUtil.fromTimeStamp(l);
|
|
||||||
System.out.print(DateUtil.localDateTimeFormatyMdHms(localDateTime));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test2() {
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
|
||||||
System.out.println(DateUtil.localDateTimeFormatyMdHms(now));
|
|
||||||
Date date = DateUtil.toDate(now);
|
|
||||||
LocalDateTime localDateTime = DateUtil.toLocalDateTime(date);
|
|
||||||
System.out.println(DateUtil.localDateTimeFormatyMdHms(localDateTime));
|
|
||||||
LocalDateTime localDateTime1 = DateUtil.fromTimeStamp(date.getTime() / 1000);
|
|
||||||
System.out.println(DateUtil.localDateTimeFormatyMdHms(localDateTime1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,14 +16,14 @@ public class FileUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetExtensionName() {
|
public void testGetExtensionName() {
|
||||||
assertEquals("foo", getExtensionName("foo"));
|
assertEquals("foo", getSuffix("foo"));
|
||||||
assertEquals("exe", getExtensionName("bar.exe"));
|
assertEquals("exe", getSuffix("bar.exe"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFileNameNoEx() {
|
public void testGetFileNameNoEx() {
|
||||||
assertEquals("foo", getFileNameNoEx("foo"));
|
assertEquals("foo", getPrefix("foo"));
|
||||||
assertEquals("bar", getFileNameNoEx("bar.txt"));
|
assertEquals("bar", getPrefix("bar.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -39,6 +39,6 @@ public class StringUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetIP() {
|
public void testGetIP() {
|
||||||
assertEquals("127.0.0.1", getIp(new MockHttpServletRequest()));
|
assertEquals("127.0.0.1", BrowserUtil.getIp(new MockHttpServletRequest()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
package cn.odboy.modules.security.config;
|
package cn.odboy.application.core.config;
|
||||||
|
|
||||||
|
import cn.odboy.application.core.constant.LoginCodeEnum;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.modules.security.constant.LoginCodeEnum;
|
|
||||||
import cn.odboy.util.StringUtil;
|
import cn.odboy.util.StringUtil;
|
||||||
import com.wf.captcha.*;
|
import com.wf.captcha.*;
|
||||||
import com.wf.captcha.base.Captcha;
|
import com.wf.captcha.base.Captcha;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.security.config;
|
package cn.odboy.application.core.config;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
+1
-11
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.security.config;
|
package cn.odboy.application.core.config;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@@ -32,16 +32,6 @@ public class SecurityProperties {
|
|||||||
*/
|
*/
|
||||||
private Long tokenValidityInSeconds;
|
private Long tokenValidityInSeconds;
|
||||||
|
|
||||||
/**
|
|
||||||
* 在线用户 key,根据 key 查询 redis 中在线用户的数据
|
|
||||||
*/
|
|
||||||
private String onlineKey;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证码 key
|
|
||||||
*/
|
|
||||||
private String codeKey;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* token 续期检查
|
* token 续期检查
|
||||||
*/
|
*/
|
||||||
+6
-6
@@ -1,11 +1,11 @@
|
|||||||
package cn.odboy.modules.security.config;
|
package cn.odboy.application.core.config;
|
||||||
|
|
||||||
|
import cn.odboy.application.core.context.JwtAccessDeniedHandler;
|
||||||
|
import cn.odboy.application.core.context.JwtAuthenticationEntryPoint;
|
||||||
|
import cn.odboy.application.core.context.TokenConfigurer;
|
||||||
|
import cn.odboy.application.core.context.TokenProvider;
|
||||||
|
import cn.odboy.application.core.service.impl.OnlineUserServiceImpl;
|
||||||
import cn.odboy.constant.RequestMethodEnum;
|
import cn.odboy.constant.RequestMethodEnum;
|
||||||
import cn.odboy.modules.security.context.JwtAccessDeniedHandler;
|
|
||||||
import cn.odboy.modules.security.context.JwtAuthenticationEntryPoint;
|
|
||||||
import cn.odboy.modules.security.context.TokenConfigurer;
|
|
||||||
import cn.odboy.modules.security.context.TokenProvider;
|
|
||||||
import cn.odboy.modules.security.service.impl.OnlineUserServiceImpl;
|
|
||||||
import cn.odboy.util.AnonTagUtil;
|
import cn.odboy.util.AnonTagUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.security.constant;
|
package cn.odboy.application.core.constant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码配置枚举
|
* 验证码配置枚举
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.security.context;
|
package cn.odboy.application.core.context;
|
||||||
|
|
||||||
import cn.odboy.exception.handler.ApiError;
|
import cn.odboy.exception.handler.ApiError;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.security.context;
|
package cn.odboy.application.core.context;
|
||||||
|
|
||||||
import cn.odboy.exception.handler.ApiError;
|
import cn.odboy.exception.handler.ApiError;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
package cn.odboy.modules.security.context;
|
package cn.odboy.application.core.context;
|
||||||
|
|
||||||
import cn.odboy.modules.security.config.SecurityProperties;
|
import cn.odboy.application.core.config.SecurityProperties;
|
||||||
import cn.odboy.modules.security.service.impl.OnlineUserServiceImpl;
|
import cn.odboy.application.core.service.impl.OnlineUserServiceImpl;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
+4
-4
@@ -1,9 +1,9 @@
|
|||||||
package cn.odboy.modules.security.context;
|
package cn.odboy.application.core.context;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.odboy.application.core.config.SecurityProperties;
|
||||||
|
import cn.odboy.application.core.service.impl.OnlineUserServiceImpl;
|
||||||
import cn.odboy.model.system.dto.OnlineUserDto;
|
import cn.odboy.model.system.dto.OnlineUserDto;
|
||||||
import cn.odboy.modules.security.config.SecurityProperties;
|
|
||||||
import cn.odboy.modules.security.service.impl.OnlineUserServiceImpl;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
@@ -43,7 +43,7 @@ public class TokenFilter extends GenericFilterBean {
|
|||||||
if (StrUtil.isNotBlank(token)) {
|
if (StrUtil.isNotBlank(token)) {
|
||||||
// 获取用户Token的Key
|
// 获取用户Token的Key
|
||||||
String loginKey = tokenProvider.loginKey(token);
|
String loginKey = tokenProvider.loginKey(token);
|
||||||
OnlineUserDto onlineUserDto = onlineUserService.getOne(loginKey);
|
OnlineUserDto onlineUserDto = onlineUserService.getOnlineUserByKey(loginKey);
|
||||||
// 判断用户在线信息是否为空
|
// 判断用户在线信息是否为空
|
||||||
if (onlineUserDto != null) {
|
if (onlineUserDto != null) {
|
||||||
// Token 续期判断
|
// Token 续期判断
|
||||||
+4
-3
@@ -1,10 +1,11 @@
|
|||||||
package cn.odboy.modules.security.context;
|
package cn.odboy.application.core.context;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateField;
|
import cn.hutool.core.date.DateField;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.odboy.application.core.config.SecurityProperties;
|
||||||
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.model.system.dto.JwtUserDto;
|
import cn.odboy.model.system.dto.JwtUserDto;
|
||||||
import cn.odboy.modules.security.config.SecurityProperties;
|
|
||||||
import cn.odboy.util.RedisUtil;
|
import cn.odboy.util.RedisUtil;
|
||||||
import io.jsonwebtoken.*;
|
import io.jsonwebtoken.*;
|
||||||
import io.jsonwebtoken.io.Decoders;
|
import io.jsonwebtoken.io.Decoders;
|
||||||
@@ -120,7 +121,7 @@ public class TokenProvider implements InitializingBean {
|
|||||||
*/
|
*/
|
||||||
public String loginKey(String token) {
|
public String loginKey(String token) {
|
||||||
Claims claims = getClaims(token);
|
Claims claims = getClaims(token);
|
||||||
return properties.getOnlineKey() + claims.getSubject() + ":" + getId(token);
|
return SystemRedisKey.ONLINE_USER + claims.getSubject() + ":" + getId(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
+8
-8
@@ -1,13 +1,13 @@
|
|||||||
package cn.odboy.modules.security.context;
|
package cn.odboy.application.core.context;
|
||||||
|
|
||||||
|
import cn.odboy.application.core.service.UserCacheService;
|
||||||
|
import cn.odboy.application.system.service.DataService;
|
||||||
|
import cn.odboy.application.system.service.RoleService;
|
||||||
|
import cn.odboy.application.system.service.UserService;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.system.domain.User;
|
import cn.odboy.model.system.domain.User;
|
||||||
import cn.odboy.model.system.dto.AuthorityDto;
|
import cn.odboy.model.system.dto.AuthorityDto;
|
||||||
import cn.odboy.model.system.dto.JwtUserDto;
|
import cn.odboy.model.system.dto.JwtUserDto;
|
||||||
import cn.odboy.modules.security.service.UserCacheService;
|
|
||||||
import cn.odboy.modules.system.service.DataService;
|
|
||||||
import cn.odboy.modules.system.service.RoleService;
|
|
||||||
import cn.odboy.modules.system.service.UserService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
@@ -26,9 +26,9 @@ public class UserDetailsHelper implements UserDetailsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JwtUserDto loadUserByUsername(String username) {
|
public JwtUserDto loadUserByUsername(String username) {
|
||||||
JwtUserDto jwtUserDto = userCacheService.getUserCache(username);
|
JwtUserDto jwtUserDto = userCacheService.getUserCacheByUsername(username);
|
||||||
if (jwtUserDto == null) {
|
if (jwtUserDto == null) {
|
||||||
User user = userService.getLoginData(username);
|
User user = userService.getUserByUsername(username);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new BadRequestException("用户不存在");
|
throw new BadRequestException("用户不存在");
|
||||||
} else {
|
} else {
|
||||||
@@ -38,7 +38,7 @@ public class UserDetailsHelper implements UserDetailsService {
|
|||||||
// 获取用户的权限
|
// 获取用户的权限
|
||||||
List<AuthorityDto> authorities = roleService.buildPermissions(user);
|
List<AuthorityDto> authorities = roleService.buildPermissions(user);
|
||||||
// 初始化JwtUserDto
|
// 初始化JwtUserDto
|
||||||
jwtUserDto = new JwtUserDto(user, dataService.getDeptIds(user), authorities);
|
jwtUserDto = new JwtUserDto(user, dataService.selectDeptIdByUserIdWithDeptId(user), authorities);
|
||||||
// 添加缓存数据
|
// 添加缓存数据
|
||||||
userCacheService.addUserCache(username, jwtUserDto);
|
userCacheService.addUserCache(username, jwtUserDto);
|
||||||
}
|
}
|
||||||
+14
-13
@@ -1,22 +1,23 @@
|
|||||||
package cn.odboy.modules.security.rest;
|
package cn.odboy.application.core.rest;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.odboy.annotation.AnonymousDeleteMapping;
|
import cn.odboy.annotation.AnonymousDeleteMapping;
|
||||||
import cn.odboy.annotation.AnonymousGetMapping;
|
import cn.odboy.annotation.AnonymousGetMapping;
|
||||||
import cn.odboy.annotation.AnonymousPostMapping;
|
import cn.odboy.annotation.AnonymousPostMapping;
|
||||||
|
import cn.odboy.application.core.config.CaptchaConfig;
|
||||||
|
import cn.odboy.application.core.config.LoginProperties;
|
||||||
|
import cn.odboy.application.core.config.SecurityProperties;
|
||||||
|
import cn.odboy.application.core.constant.LoginCodeEnum;
|
||||||
|
import cn.odboy.application.core.context.TokenProvider;
|
||||||
|
import cn.odboy.application.core.context.UserDetailsHelper;
|
||||||
|
import cn.odboy.application.core.service.impl.OnlineUserServiceImpl;
|
||||||
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.system.dto.AuthUserDto;
|
import cn.odboy.model.system.dto.AuthUserDto;
|
||||||
import cn.odboy.model.system.dto.JwtUserDto;
|
import cn.odboy.model.system.dto.JwtUserDto;
|
||||||
import cn.odboy.modules.security.config.CaptchaConfig;
|
|
||||||
import cn.odboy.modules.security.config.LoginProperties;
|
|
||||||
import cn.odboy.modules.security.config.SecurityProperties;
|
|
||||||
import cn.odboy.modules.security.constant.LoginCodeEnum;
|
|
||||||
import cn.odboy.modules.security.context.TokenProvider;
|
|
||||||
import cn.odboy.modules.security.context.UserDetailsHelper;
|
|
||||||
import cn.odboy.modules.security.service.impl.OnlineUserServiceImpl;
|
|
||||||
import cn.odboy.properties.RsaProperties;
|
import cn.odboy.properties.RsaProperties;
|
||||||
import cn.odboy.util.RedisUtil;
|
import cn.odboy.util.RedisUtil;
|
||||||
import cn.odboy.util.RsaUtil;
|
import cn.odboy.util.RSAEncryptUtil;
|
||||||
import cn.odboy.util.SecurityUtil;
|
import cn.odboy.util.SecurityUtil;
|
||||||
import cn.odboy.util.StringUtil;
|
import cn.odboy.util.StringUtil;
|
||||||
import com.wf.captcha.base.Captcha;
|
import com.wf.captcha.base.Captcha;
|
||||||
@@ -64,7 +65,7 @@ public class AuthController {
|
|||||||
@AnonymousPostMapping(value = "/login")
|
@AnonymousPostMapping(value = "/login")
|
||||||
public ResponseEntity<Object> login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception {
|
public ResponseEntity<Object> login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception {
|
||||||
// 密码解密
|
// 密码解密
|
||||||
String password = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
String password = RSAEncryptUtil.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
||||||
// 查询验证码
|
// 查询验证码
|
||||||
String code = redisUtil.get(authUser.getUuid(), String.class);
|
String code = redisUtil.get(authUser.getUuid(), String.class);
|
||||||
// 清除验证码
|
// 清除验证码
|
||||||
@@ -92,7 +93,7 @@ public class AuthController {
|
|||||||
}};
|
}};
|
||||||
if (loginProperties.isSingleLogin()) {
|
if (loginProperties.isSingleLogin()) {
|
||||||
// 踢掉之前已经登录的token
|
// 踢掉之前已经登录的token
|
||||||
onlineUserService.kickOutForUsername(authUser.getUsername());
|
onlineUserService.kickOutByUsername(authUser.getUsername());
|
||||||
}
|
}
|
||||||
// 保存在线信息
|
// 保存在线信息
|
||||||
onlineUserService.save(jwtUser, token, request);
|
onlineUserService.save(jwtUser, token, request);
|
||||||
@@ -112,7 +113,7 @@ public class AuthController {
|
|||||||
public ResponseEntity<Object> getCode() {
|
public ResponseEntity<Object> getCode() {
|
||||||
// 获取运算的结果
|
// 获取运算的结果
|
||||||
Captcha captcha = captchaConfig.getCaptcha();
|
Captcha captcha = captchaConfig.getCaptcha();
|
||||||
String uuid = properties.getCodeKey() + IdUtil.simpleUUID();
|
String uuid = SystemRedisKey.CAPTCHA_LOGIN + IdUtil.simpleUUID();
|
||||||
//当验证码类型为 arithmetic时且长度 >= 2 时,captcha.text()的结果有几率为浮点型
|
//当验证码类型为 arithmetic时且长度 >= 2 时,captcha.text()的结果有几率为浮点型
|
||||||
String captchaValue = captcha.text();
|
String captchaValue = captcha.text();
|
||||||
if (captcha.getCharType() - 1 == LoginCodeEnum.ARITHMETIC.ordinal() && captchaValue.contains(".")) {
|
if (captcha.getCharType() - 1 == LoginCodeEnum.ARITHMETIC.ordinal() && captchaValue.contains(".")) {
|
||||||
@@ -132,7 +133,7 @@ public class AuthController {
|
|||||||
@AnonymousDeleteMapping(value = "/logout")
|
@AnonymousDeleteMapping(value = "/logout")
|
||||||
public ResponseEntity<Object> logout(HttpServletRequest request) {
|
public ResponseEntity<Object> logout(HttpServletRequest request) {
|
||||||
String token = tokenProvider.getToken(request);
|
String token = tokenProvider.getToken(request);
|
||||||
onlineUserService.logout(token);
|
onlineUserService.logoutByToken(token);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+7
-7
@@ -1,9 +1,9 @@
|
|||||||
package cn.odboy.modules.security.rest;
|
package cn.odboy.application.core.rest;
|
||||||
|
|
||||||
|
import cn.odboy.application.core.service.OnlineUserService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.model.system.dto.OnlineUserDto;
|
import cn.odboy.model.system.dto.OnlineUserDto;
|
||||||
import cn.odboy.modules.security.service.OnlineUserService;
|
import cn.odboy.util.DESEncryptUtil;
|
||||||
import cn.odboy.util.EncryptUtil;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -29,14 +29,14 @@ public class OnlineController {
|
|||||||
@GetMapping
|
@GetMapping
|
||||||
@PreAuthorize("@el.check()")
|
@PreAuthorize("@el.check()")
|
||||||
public ResponseEntity<PageResult<OnlineUserDto>> queryOnlineUser(String username, Pageable pageable) {
|
public ResponseEntity<PageResult<OnlineUserDto>> queryOnlineUser(String username, Pageable pageable) {
|
||||||
return new ResponseEntity<>(onlineUserService.getAll(username, pageable), HttpStatus.OK);
|
return new ResponseEntity<>(onlineUserService.queryOnlineUserPage(username, pageable), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("导出数据")
|
@ApiOperation("导出数据")
|
||||||
@GetMapping(value = "/download")
|
@GetMapping(value = "/download")
|
||||||
@PreAuthorize("@el.check()")
|
@PreAuthorize("@el.check()")
|
||||||
public void exportOnlineUser(HttpServletResponse response, String username) throws IOException {
|
public void exportOnlineUser(HttpServletResponse response, String username) throws IOException {
|
||||||
onlineUserService.download(onlineUserService.getAll(username), response);
|
onlineUserService.downloadExcel(onlineUserService.selectOnlineUserByUsername(username), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("踢出用户")
|
@ApiOperation("踢出用户")
|
||||||
@@ -45,8 +45,8 @@ public class OnlineController {
|
|||||||
public ResponseEntity<Object> deleteOnlineUser(@RequestBody Set<String> keys) throws Exception {
|
public ResponseEntity<Object> deleteOnlineUser(@RequestBody Set<String> keys) throws Exception {
|
||||||
for (String token : keys) {
|
for (String token : keys) {
|
||||||
// 解密Key
|
// 解密Key
|
||||||
token = EncryptUtil.desDecrypt(token);
|
token = DESEncryptUtil.desDecrypt(token);
|
||||||
onlineUserService.logout(token);
|
onlineUserService.logoutByToken(token);
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
+7
-7
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.security.service;
|
package cn.odboy.application.core.service;
|
||||||
|
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.model.system.dto.JwtUserDto;
|
import cn.odboy.model.system.dto.JwtUserDto;
|
||||||
@@ -27,7 +27,7 @@ public interface OnlineUserService {
|
|||||||
* @param pageable /
|
* @param pageable /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
PageResult<OnlineUserDto> getAll(String username, Pageable pageable);
|
PageResult<OnlineUserDto> queryOnlineUserPage(String username, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询全部数据,不分页
|
* 查询全部数据,不分页
|
||||||
@@ -35,14 +35,14 @@ public interface OnlineUserService {
|
|||||||
* @param username /
|
* @param username /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<OnlineUserDto> getAll(String username);
|
List<OnlineUserDto> selectOnlineUserByUsername(String username);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出登录
|
* 退出登录
|
||||||
*
|
*
|
||||||
* @param token /
|
* @param token /
|
||||||
*/
|
*/
|
||||||
void logout(String token);
|
void logoutByToken(String token);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出
|
* 导出
|
||||||
@@ -51,7 +51,7 @@ public interface OnlineUserService {
|
|||||||
* @param response /
|
* @param response /
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void download(List<OnlineUserDto> all, HttpServletResponse response) throws IOException;
|
void downloadExcel(List<OnlineUserDto> all, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询用户
|
* 查询用户
|
||||||
@@ -59,12 +59,12 @@ public interface OnlineUserService {
|
|||||||
* @param key /
|
* @param key /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
OnlineUserDto getOne(String key);
|
OnlineUserDto getOnlineUserByKey(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户名强退用户
|
* 根据用户名强退用户
|
||||||
*
|
*
|
||||||
* @param username /
|
* @param username /
|
||||||
*/
|
*/
|
||||||
void kickOutForUsername(String username);
|
void kickOutByUsername(String username);
|
||||||
}
|
}
|
||||||
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.security.service;
|
package cn.odboy.application.core.service;
|
||||||
|
|
||||||
import cn.odboy.model.system.dto.JwtUserDto;
|
import cn.odboy.model.system.dto.JwtUserDto;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
@@ -7,10 +7,10 @@ public interface UserCacheService {
|
|||||||
/**
|
/**
|
||||||
* 返回用户缓存
|
* 返回用户缓存
|
||||||
*
|
*
|
||||||
* @param userName 用户名
|
* @param username 用户名
|
||||||
* @return JwtUserDto
|
* @return JwtUserDto
|
||||||
*/
|
*/
|
||||||
JwtUserDto getUserCache(String userName);
|
JwtUserDto getUserCacheByUsername(String username);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加缓存到Redis
|
* 添加缓存到Redis
|
||||||
@@ -27,5 +27,5 @@ public interface UserCacheService {
|
|||||||
* @param userName 用户名
|
* @param userName 用户名
|
||||||
*/
|
*/
|
||||||
@Async
|
@Async
|
||||||
void cleanUserCache(String userName);
|
void cleanUserCacheByUsername(String userName);
|
||||||
}
|
}
|
||||||
+33
-25
@@ -1,11 +1,12 @@
|
|||||||
package cn.odboy.modules.security.service.impl;
|
package cn.odboy.application.core.service.impl;
|
||||||
|
|
||||||
|
import cn.odboy.application.core.config.SecurityProperties;
|
||||||
|
import cn.odboy.application.core.context.TokenProvider;
|
||||||
|
import cn.odboy.application.core.service.OnlineUserService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.model.system.dto.JwtUserDto;
|
import cn.odboy.model.system.dto.JwtUserDto;
|
||||||
import cn.odboy.model.system.dto.OnlineUserDto;
|
import cn.odboy.model.system.dto.OnlineUserDto;
|
||||||
import cn.odboy.modules.security.config.SecurityProperties;
|
|
||||||
import cn.odboy.modules.security.context.TokenProvider;
|
|
||||||
import cn.odboy.modules.security.service.OnlineUserService;
|
|
||||||
import cn.odboy.util.*;
|
import cn.odboy.util.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -23,7 +24,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class OnlineUserServiceImpl implements OnlineUserService {
|
public class OnlineUserServiceImpl implements OnlineUserService {
|
||||||
|
|
||||||
private final SecurityProperties properties;
|
private final SecurityProperties properties;
|
||||||
private final TokenProvider tokenProvider;
|
private final TokenProvider tokenProvider;
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
@@ -31,13 +31,22 @@ public class OnlineUserServiceImpl implements OnlineUserService {
|
|||||||
@Override
|
@Override
|
||||||
public void save(JwtUserDto jwtUserDto, String token, HttpServletRequest request) {
|
public void save(JwtUserDto jwtUserDto, String token, HttpServletRequest request) {
|
||||||
String dept = jwtUserDto.getUser().getDept().getName();
|
String dept = jwtUserDto.getUser().getDept().getName();
|
||||||
String ip = StringUtil.getIp(request);
|
String ip = BrowserUtil.getIp(request);
|
||||||
String id = tokenProvider.getId(token);
|
String id = tokenProvider.getId(token);
|
||||||
String browser = StringUtil.getBrowser(request);
|
String version = BrowserUtil.getVersion(request);
|
||||||
String address = StringUtil.getCityInfo(ip);
|
String address = IPUtil.getCityInfo(ip);
|
||||||
OnlineUserDto onlineUserDto = null;
|
OnlineUserDto onlineUserDto = null;
|
||||||
try {
|
try {
|
||||||
onlineUserDto = new OnlineUserDto(id, jwtUserDto.getUsername(), jwtUserDto.getUser().getNickName(), dept, browser, ip, address, EncryptUtil.desEncrypt(token), new Date());
|
onlineUserDto = new OnlineUserDto();
|
||||||
|
onlineUserDto.setUid(id);
|
||||||
|
onlineUserDto.setUserName(jwtUserDto.getUsername());
|
||||||
|
onlineUserDto.setNickName(jwtUserDto.getUser().getNickName());
|
||||||
|
onlineUserDto.setDept(dept);
|
||||||
|
onlineUserDto.setBrowser(version);
|
||||||
|
onlineUserDto.setIp(ip);
|
||||||
|
onlineUserDto.setAddress(address);
|
||||||
|
onlineUserDto.setKey(DESEncryptUtil.desEncrypt(token));
|
||||||
|
onlineUserDto.setLoginTime(new Date());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
@@ -46,34 +55,33 @@ public class OnlineUserServiceImpl implements OnlineUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<OnlineUserDto> getAll(String username, Pageable pageable) {
|
public PageResult<OnlineUserDto> queryOnlineUserPage(String username, Pageable pageable) {
|
||||||
List<OnlineUserDto> onlineUserDtos = getAll(username);
|
List<OnlineUserDto> onlineUserList = selectOnlineUserByUsername(username);
|
||||||
List<OnlineUserDto> paging = PageUtil.paging(pageable.getPageNumber(), pageable.getPageSize(), onlineUserDtos);
|
List<OnlineUserDto> paging = PageUtil.softPaging(pageable.getPageNumber(), pageable.getPageSize(), onlineUserList);
|
||||||
return PageUtil.toPage(paging, onlineUserDtos.size());
|
return PageUtil.toPage(paging, onlineUserList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<OnlineUserDto> getAll(String username) {
|
public List<OnlineUserDto> selectOnlineUserByUsername(String username) {
|
||||||
String loginKey = properties.getOnlineKey() +
|
String loginKey = SystemRedisKey.ONLINE_USER + (StringUtil.isBlank(username) ? "" : "*" + username);
|
||||||
(StringUtil.isBlank(username) ? "" : "*" + username);
|
|
||||||
List<String> keys = redisUtil.scan(loginKey + "*");
|
List<String> keys = redisUtil.scan(loginKey + "*");
|
||||||
Collections.reverse(keys);
|
Collections.reverse(keys);
|
||||||
List<OnlineUserDto> onlineUserDtos = new ArrayList<>();
|
List<OnlineUserDto> onlineUserList = new ArrayList<>();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
onlineUserDtos.add(redisUtil.get(key, OnlineUserDto.class));
|
onlineUserList.add(redisUtil.get(key, OnlineUserDto.class));
|
||||||
}
|
}
|
||||||
onlineUserDtos.sort((o1, o2) -> o2.getLoginTime().compareTo(o1.getLoginTime()));
|
onlineUserList.sort((o1, o2) -> o2.getLoginTime().compareTo(o1.getLoginTime()));
|
||||||
return onlineUserDtos;
|
return onlineUserList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logout(String token) {
|
public void logoutByToken(String token) {
|
||||||
String loginKey = tokenProvider.loginKey(token);
|
String loginKey = tokenProvider.loginKey(token);
|
||||||
redisUtil.del(loginKey);
|
redisUtil.del(loginKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<OnlineUserDto> all, HttpServletResponse response) throws IOException {
|
public void downloadExcel(List<OnlineUserDto> all, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (OnlineUserDto user : all) {
|
for (OnlineUserDto user : all) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
@@ -89,13 +97,13 @@ public class OnlineUserServiceImpl implements OnlineUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OnlineUserDto getOne(String key) {
|
public OnlineUserDto getOnlineUserByKey(String key) {
|
||||||
return redisUtil.get(key, OnlineUserDto.class);
|
return redisUtil.get(key, OnlineUserDto.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kickOutForUsername(String username) {
|
public void kickOutByUsername(String username) {
|
||||||
String loginKey = properties.getOnlineKey() + username + "*";
|
String loginKey = SystemRedisKey.ONLINE_USER + username + "*";
|
||||||
redisUtil.scanDel(loginKey);
|
redisUtil.scanDel(loginKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+10
-13
@@ -1,12 +1,11 @@
|
|||||||
package cn.odboy.modules.security.service.impl;
|
package cn.odboy.application.core.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import cn.odboy.application.core.config.LoginProperties;
|
||||||
|
import cn.odboy.application.core.service.UserCacheService;
|
||||||
import cn.odboy.model.system.dto.JwtUserDto;
|
import cn.odboy.model.system.dto.JwtUserDto;
|
||||||
import cn.odboy.modules.security.config.LoginProperties;
|
|
||||||
import cn.odboy.modules.security.service.UserCacheService;
|
|
||||||
import cn.odboy.util.RedisUtil;
|
import cn.odboy.util.RedisUtil;
|
||||||
import cn.odboy.util.StringUtil;
|
import cn.odboy.util.StringUtil;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -18,16 +17,14 @@ import javax.annotation.Resource;
|
|||||||
public class UserCacheServiceImpl implements UserCacheService {
|
public class UserCacheServiceImpl implements UserCacheService {
|
||||||
@Resource
|
@Resource
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
@Value("${login.user-cache.idle-time}")
|
|
||||||
private long idleTime;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JwtUserDto getUserCache(String userName) {
|
public JwtUserDto getUserCacheByUsername(String username) {
|
||||||
// 转小写
|
// 转小写
|
||||||
userName = StringUtil.lowerCase(userName);
|
username = StringUtil.lowerCase(username);
|
||||||
if (StringUtil.isNotEmpty(userName)) {
|
if (StringUtil.isNotEmpty(username)) {
|
||||||
// 获取数据
|
// 获取数据
|
||||||
return redisUtil.get(LoginProperties.cacheKey + userName, JwtUserDto.class);
|
return redisUtil.get(LoginProperties.cacheKey + username, JwtUserDto.class);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -38,15 +35,15 @@ public class UserCacheServiceImpl implements UserCacheService {
|
|||||||
// 转小写
|
// 转小写
|
||||||
userName = StringUtil.lowerCase(userName);
|
userName = StringUtil.lowerCase(userName);
|
||||||
if (StringUtil.isNotEmpty(userName)) {
|
if (StringUtil.isNotEmpty(userName)) {
|
||||||
// 添加数据, 避免数据同时过期
|
// 添加数据, 避免数据同时过期(2小时左右)
|
||||||
long time = idleTime + RandomUtil.randomInt(900, 1800);
|
long time = 7200 + RandomUtil.randomInt(900, 1800);
|
||||||
redisUtil.set(LoginProperties.cacheKey + userName, user, time);
|
redisUtil.set(LoginProperties.cacheKey + userName, user, time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cleanUserCache(String userName) {
|
public void cleanUserCacheByUsername(String userName) {
|
||||||
// 转小写
|
// 转小写
|
||||||
userName = StringUtil.lowerCase(userName);
|
userName = StringUtil.lowerCase(userName);
|
||||||
if (StringUtil.isNotEmpty(userName)) {
|
if (StringUtil.isNotEmpty(userName)) {
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
|
import cn.odboy.model.system.domain.Dept;
|
||||||
|
import cn.odboy.model.system.dto.DeptQueryCriteria;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface DeptMapper extends BaseMapper<Dept> {
|
||||||
|
List<Dept> selectDeptByCriteria(@Param("criteria") DeptQueryCriteria criteria);
|
||||||
|
|
||||||
|
List<Dept> selectDeptByPid(@Param("pid") Long pid);
|
||||||
|
|
||||||
|
int getDeptCountByPid(@Param("pid") Long pid);
|
||||||
|
|
||||||
|
List<Dept> selectDeptByPidIsNull();
|
||||||
|
|
||||||
|
Set<Dept> selectDeptByRoleId(@Param("roleId") Long roleId);
|
||||||
|
|
||||||
|
void updateSubCountById(@Param("count") Integer count, @Param("id") Long id);
|
||||||
|
}
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.DictDetail;
|
import cn.odboy.model.system.domain.DictDetail;
|
||||||
import cn.odboy.model.system.dto.DictDetailQueryCriteria;
|
import cn.odboy.model.system.dto.DictDetailQueryCriteria;
|
||||||
@@ -14,9 +14,9 @@ import java.util.Set;
|
|||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DictDetailMapper extends BaseMapper<DictDetail> {
|
public interface DictDetailMapper extends BaseMapper<DictDetail> {
|
||||||
List<DictDetail> findDictDetailByDictName(@Param("name") String name);
|
List<DictDetail> selectDictDetailByDictName(@Param("name") String name);
|
||||||
|
|
||||||
IPage<DictDetail> findDictDetail(@Param("criteria") DictDetailQueryCriteria criteria, Page<Object> page);
|
IPage<DictDetail> queryDictDetail(@Param("criteria") DictDetailQueryCriteria criteria, Page<Object> page);
|
||||||
|
|
||||||
void deleteDictDetailsByDictIds(@Param("dictIds") Set<Long> dictIds);
|
void deleteDictDetailsByDictIds(@Param("dictIds") Set<Long> dictIds);
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.Dict;
|
import cn.odboy.model.system.domain.Dict;
|
||||||
import cn.odboy.model.system.dto.DictQueryCriteria;
|
import cn.odboy.model.system.dto.DictQueryCriteria;
|
||||||
@@ -10,5 +10,5 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DictMapper extends BaseMapper<Dict> {
|
public interface DictMapper extends BaseMapper<Dict> {
|
||||||
IPage<Dict> findDictPage(@Param("criteria") DictQueryCriteria criteria, Page<Object> page);
|
IPage<Dict> queryDictPage(@Param("criteria") DictQueryCriteria criteria, Page<Object> page);
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.Job;
|
import cn.odboy.model.system.domain.Job;
|
||||||
import cn.odboy.model.system.dto.JobQueryCriteria;
|
import cn.odboy.model.system.dto.JobQueryCriteria;
|
||||||
@@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface JobMapper extends BaseMapper<Job> {
|
public interface JobMapper extends BaseMapper<Job> {
|
||||||
Job findJobByName(@Param("name") String name);
|
Job getJobByName(@Param("name") String name);
|
||||||
|
|
||||||
IPage<Job> findJobPage(@Param("criteria") JobQueryCriteria criteria, Page<Object> page);
|
IPage<Job> queryJobPage(@Param("criteria") JobQueryCriteria criteria, Page<Object> page);
|
||||||
}
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
|
import cn.odboy.model.system.domain.Menu;
|
||||||
|
import cn.odboy.model.system.dto.MenuQueryCriteria;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface MenuMapper extends BaseMapper<Menu> {
|
||||||
|
|
||||||
|
List<Menu> selectMenuByCriteria(@Param("criteria") MenuQueryCriteria criteria);
|
||||||
|
|
||||||
|
LinkedHashSet<Menu> selectMenuByRoleIdsAndType(@Param("roleIds") Set<Long> roleIds, @Param("type") Integer type);
|
||||||
|
|
||||||
|
List<Menu> selectMenuByPidIsNullOrderByMenuSort();
|
||||||
|
|
||||||
|
List<Menu> selectMenuByPidOrderByMenuSort(@Param("pid") Long pid);
|
||||||
|
|
||||||
|
Menu getMenuByTitle(@Param("title") String title);
|
||||||
|
|
||||||
|
Menu getMenuByComponentName(@Param("name") String name);
|
||||||
|
|
||||||
|
int getMenuCountByPid(@Param("pid") Long pid);
|
||||||
|
|
||||||
|
void updateSubCntById(@Param("count") int count, @Param("menuId") Long menuId);
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.Dept;
|
import cn.odboy.model.system.domain.Dept;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
|
import cn.odboy.model.system.domain.Role;
|
||||||
|
import cn.odboy.model.system.dto.RoleQueryCriteria;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface RoleMapper extends BaseMapper<Role> {
|
||||||
|
List<Role> selectRole();
|
||||||
|
|
||||||
|
List<Role> selectRoleByCriteria(@Param("criteria") RoleQueryCriteria criteria);
|
||||||
|
|
||||||
|
Long getRoleCountByCriteria(@Param("criteria") RoleQueryCriteria criteria);
|
||||||
|
|
||||||
|
Role getRoleByName(@Param("name") String name);
|
||||||
|
|
||||||
|
Role getRoleById(@Param("roleId") Long roleId);
|
||||||
|
|
||||||
|
List<Role> selectRoleByUserId(@Param("userId") Long userId);
|
||||||
|
|
||||||
|
int getRoleCountByDeptIds(@Param("deptIds") Set<Long> deptIds);
|
||||||
|
|
||||||
|
List<Role> selectRoleByMenuId(@Param("menuId") Long menuId);
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.Menu;
|
import cn.odboy.model.system.domain.Menu;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.Job;
|
import cn.odboy.model.system.domain.Job;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
|
import cn.odboy.model.system.domain.User;
|
||||||
|
import cn.odboy.model.system.dto.UserQueryCriteria;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
|
|
||||||
|
Long getUserCountByCriteria(@Param("criteria") UserQueryCriteria criteria);
|
||||||
|
|
||||||
|
IPage<User> queryUserPage(@Param("criteria") UserQueryCriteria criteria, Page<Object> page);
|
||||||
|
|
||||||
|
User getUserByUsername(@Param("username") String username);
|
||||||
|
|
||||||
|
User getUserByEmail(@Param("email") String email);
|
||||||
|
|
||||||
|
User getUserByPhone(@Param("phone") String phone);
|
||||||
|
|
||||||
|
void updatePasswordByUsername(@Param("username") String username, @Param("password") String password, @Param("lastPasswordResetTime") Date lastPasswordResetTime);
|
||||||
|
|
||||||
|
void updateEmailByUsername(@Param("username") String username, @Param("email") String email);
|
||||||
|
|
||||||
|
List<User> selectUserByRoleId(@Param("roleId") Long roleId);
|
||||||
|
|
||||||
|
List<User> selectUserByRoleDeptId(@Param("deptId") Long deptId);
|
||||||
|
|
||||||
|
List<User> selectUserByMenuId(@Param("menuId") Long menuId);
|
||||||
|
|
||||||
|
int getCountByJobs(@Param("jobIds") Set<Long> jobIds);
|
||||||
|
|
||||||
|
int getCountByDepts(@Param("deptIds") Set<Long> deptIds);
|
||||||
|
|
||||||
|
int getCountByRoles(@Param("roleIds") Set<Long> roleIds);
|
||||||
|
|
||||||
|
void resetPasswordByUserIds(@Param("userIds") Set<Long> userIds, @Param("pwd") String password);
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
package cn.odboy.application.system.mapper;
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.Role;
|
import cn.odboy.model.system.domain.Role;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
+12
-18
@@ -1,11 +1,10 @@
|
|||||||
package cn.odboy.modules.system.rest;
|
package cn.odboy.application.system.rest;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.odboy.application.system.service.DeptService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.system.domain.Dept;
|
import cn.odboy.model.system.domain.Dept;
|
||||||
import cn.odboy.model.system.dto.DeptQueryCriteria;
|
import cn.odboy.model.system.dto.DeptQueryCriteria;
|
||||||
import cn.odboy.modules.system.service.DeptService;
|
|
||||||
import cn.odboy.util.PageUtil;
|
import cn.odboy.util.PageUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -33,14 +32,14 @@ public class DeptController {
|
|||||||
@GetMapping(value = "/download")
|
@GetMapping(value = "/download")
|
||||||
@PreAuthorize("@el.check('dept:list')")
|
@PreAuthorize("@el.check('dept:list')")
|
||||||
public void exportDept(HttpServletResponse response, DeptQueryCriteria criteria) throws Exception {
|
public void exportDept(HttpServletResponse response, DeptQueryCriteria criteria) throws Exception {
|
||||||
deptService.download(deptService.queryAll(criteria, false), response);
|
deptService.downloadExcel(deptService.selectDeptByCriteria(criteria, false), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("查询部门")
|
@ApiOperation("查询部门")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@PreAuthorize("@el.check('user:list','dept:list')")
|
@PreAuthorize("@el.check('user:list','dept:list')")
|
||||||
public ResponseEntity<PageResult<Dept>> queryDept(DeptQueryCriteria criteria) throws Exception {
|
public ResponseEntity<PageResult<Dept>> queryDept(DeptQueryCriteria criteria) throws Exception {
|
||||||
List<Dept> depts = deptService.queryAll(criteria, true);
|
List<Dept> depts = deptService.selectDeptByCriteria(criteria, true);
|
||||||
return new ResponseEntity<>(PageUtil.toPage(depts), HttpStatus.OK);
|
return new ResponseEntity<>(PageUtil.toPage(depts), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +49,8 @@ public class DeptController {
|
|||||||
public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids, @RequestParam(defaultValue = "false") Boolean exclude) {
|
public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids, @RequestParam(defaultValue = "false") Boolean exclude) {
|
||||||
Set<Dept> deptSet = new LinkedHashSet<>();
|
Set<Dept> deptSet = new LinkedHashSet<>();
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
Dept dept = deptService.findById(id);
|
Dept dept = deptService.getDeptById(id);
|
||||||
List<Dept> depts = deptService.getSuperior(dept, new ArrayList<>());
|
List<Dept> depts = deptService.selectSuperiorDeptByPid(dept, new ArrayList<>());
|
||||||
if (exclude) {
|
if (exclude) {
|
||||||
for (Dept data : depts) {
|
for (Dept data : depts) {
|
||||||
if (data.getId().equals(dept.getPid())) {
|
if (data.getId().equals(dept.getPid())) {
|
||||||
@@ -73,7 +72,7 @@ public class DeptController {
|
|||||||
if (resources.getId() != null) {
|
if (resources.getId() != null) {
|
||||||
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
||||||
}
|
}
|
||||||
deptService.create(resources);
|
deptService.createDept(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +80,7 @@ public class DeptController {
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
@PreAuthorize("@el.check('dept:edit')")
|
@PreAuthorize("@el.check('dept:edit')")
|
||||||
public ResponseEntity<Object> updateDept(@Validated(Dept.Update.class) @RequestBody Dept resources) {
|
public ResponseEntity<Object> updateDept(@Validated(Dept.Update.class) @RequestBody Dept resources) {
|
||||||
deptService.update(resources);
|
deptService.updateDept(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,16 +89,11 @@ public class DeptController {
|
|||||||
@PreAuthorize("@el.check('dept:del')")
|
@PreAuthorize("@el.check('dept:del')")
|
||||||
public ResponseEntity<Object> deleteDept(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> deleteDept(@RequestBody Set<Long> ids) {
|
||||||
Set<Dept> depts = new HashSet<>();
|
Set<Dept> depts = new HashSet<>();
|
||||||
for (Long id : ids) {
|
// 获取部门,和其所有子部门
|
||||||
List<Dept> deptList = deptService.findByPid(id);
|
deptService.traverseDeptByIdWithPids(ids, depts);
|
||||||
depts.add(deptService.findById(id));
|
|
||||||
if (CollectionUtil.isNotEmpty(deptList)) {
|
|
||||||
depts = deptService.getDeleteDepts(deptList, depts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 验证是否被角色或用户关联
|
// 验证是否被角色或用户关联
|
||||||
deptService.verification(depts);
|
deptService.verifyBindRelationByIds(depts);
|
||||||
deptService.delete(depts);
|
deptService.deleteDeptByIds(depts);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-8
@@ -1,10 +1,10 @@
|
|||||||
package cn.odboy.modules.system.rest;
|
package cn.odboy.application.system.rest;
|
||||||
|
|
||||||
|
import cn.odboy.application.system.service.DictService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.system.domain.Dict;
|
import cn.odboy.model.system.domain.Dict;
|
||||||
import cn.odboy.model.system.dto.DictQueryCriteria;
|
import cn.odboy.model.system.dto.DictQueryCriteria;
|
||||||
import cn.odboy.modules.system.service.DictService;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -33,14 +33,14 @@ public class DictController {
|
|||||||
@GetMapping(value = "/download")
|
@GetMapping(value = "/download")
|
||||||
@PreAuthorize("@el.check('dict:list')")
|
@PreAuthorize("@el.check('dict:list')")
|
||||||
public void exportDict(HttpServletResponse response, DictQueryCriteria criteria) throws IOException {
|
public void exportDict(HttpServletResponse response, DictQueryCriteria criteria) throws IOException {
|
||||||
dictService.download(dictService.queryAll(criteria), response);
|
dictService.downloadExcel(dictService.selectDictByCriteria(criteria), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("查询字典")
|
@ApiOperation("查询字典")
|
||||||
@GetMapping(value = "/all")
|
@GetMapping(value = "/all")
|
||||||
@PreAuthorize("@el.check('dict:list')")
|
@PreAuthorize("@el.check('dict:list')")
|
||||||
public ResponseEntity<List<Dict>> queryAllDict() {
|
public ResponseEntity<List<Dict>> queryAllDict() {
|
||||||
return new ResponseEntity<>(dictService.queryAll(new DictQueryCriteria()), HttpStatus.OK);
|
return new ResponseEntity<>(dictService.selectDictByCriteria(new DictQueryCriteria()), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("查询字典")
|
@ApiOperation("查询字典")
|
||||||
@@ -48,7 +48,7 @@ public class DictController {
|
|||||||
@PreAuthorize("@el.check('dict:list')")
|
@PreAuthorize("@el.check('dict:list')")
|
||||||
public ResponseEntity<PageResult<Dict>> queryDict(DictQueryCriteria criteria) {
|
public ResponseEntity<PageResult<Dict>> queryDict(DictQueryCriteria criteria) {
|
||||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||||
return new ResponseEntity<>(dictService.queryAll(criteria, page), HttpStatus.OK);
|
return new ResponseEntity<>(dictService.queryDictPage(criteria, page), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("新增字典")
|
@ApiOperation("新增字典")
|
||||||
@@ -58,7 +58,7 @@ public class DictController {
|
|||||||
if (resources.getId() != null) {
|
if (resources.getId() != null) {
|
||||||
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
||||||
}
|
}
|
||||||
dictService.create(resources);
|
dictService.saveDict(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class DictController {
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
@PreAuthorize("@el.check('dict:edit')")
|
@PreAuthorize("@el.check('dict:edit')")
|
||||||
public ResponseEntity<Object> updateDict(@Validated(Dict.Update.class) @RequestBody Dict resources) {
|
public ResponseEntity<Object> updateDict(@Validated(Dict.Update.class) @RequestBody Dict resources) {
|
||||||
dictService.update(resources);
|
dictService.updateDictById(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ public class DictController {
|
|||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@PreAuthorize("@el.check('dict:del')")
|
@PreAuthorize("@el.check('dict:del')")
|
||||||
public ResponseEntity<Object> deleteDict(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> deleteDict(@RequestBody Set<Long> ids) {
|
||||||
dictService.delete(ids);
|
dictService.deleteDictByIds(ids);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+7
-7
@@ -1,10 +1,10 @@
|
|||||||
package cn.odboy.modules.system.rest;
|
package cn.odboy.application.system.rest;
|
||||||
|
|
||||||
|
import cn.odboy.application.system.service.DictDetailService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.system.domain.DictDetail;
|
import cn.odboy.model.system.domain.DictDetail;
|
||||||
import cn.odboy.model.system.dto.DictDetailQueryCriteria;
|
import cn.odboy.model.system.dto.DictDetailQueryCriteria;
|
||||||
import cn.odboy.modules.system.service.DictDetailService;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -32,7 +32,7 @@ public class DictDetailController {
|
|||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseEntity<PageResult<DictDetail>> queryDictDetail(DictDetailQueryCriteria criteria) {
|
public ResponseEntity<PageResult<DictDetail>> queryDictDetail(DictDetailQueryCriteria criteria) {
|
||||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||||
return new ResponseEntity<>(dictDetailService.queryAll(criteria, page), HttpStatus.OK);
|
return new ResponseEntity<>(dictDetailService.queryDictDetailPage(criteria, page), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("查询多个字典详情")
|
@ApiOperation("查询多个字典详情")
|
||||||
@@ -41,7 +41,7 @@ public class DictDetailController {
|
|||||||
String[] names = dictName.split("[,,]");
|
String[] names = dictName.split("[,,]");
|
||||||
Map<String, List<DictDetail>> dictMap = new HashMap<>(16);
|
Map<String, List<DictDetail>> dictMap = new HashMap<>(16);
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
dictMap.put(name, dictDetailService.getDictByName(name));
|
dictMap.put(name, dictDetailService.selectDictDetailByName(name));
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>(dictMap, HttpStatus.OK);
|
return new ResponseEntity<>(dictMap, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ public class DictDetailController {
|
|||||||
if (resources.getId() != null) {
|
if (resources.getId() != null) {
|
||||||
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
||||||
}
|
}
|
||||||
dictDetailService.create(resources);
|
dictDetailService.saveDictDetail(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ public class DictDetailController {
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
@PreAuthorize("@el.check('dict:edit')")
|
@PreAuthorize("@el.check('dict:edit')")
|
||||||
public ResponseEntity<Object> updateDictDetail(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources) {
|
public ResponseEntity<Object> updateDictDetail(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources) {
|
||||||
dictDetailService.update(resources);
|
dictDetailService.updateDictDetailById(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class DictDetailController {
|
|||||||
@DeleteMapping(value = "/{id}")
|
@DeleteMapping(value = "/{id}")
|
||||||
@PreAuthorize("@el.check('dict:del')")
|
@PreAuthorize("@el.check('dict:del')")
|
||||||
public ResponseEntity<Object> deleteDictDetail(@PathVariable Long id) {
|
public ResponseEntity<Object> deleteDictDetail(@PathVariable Long id) {
|
||||||
dictDetailService.delete(id);
|
dictDetailService.deleteDictDetailById(id);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-8
@@ -1,10 +1,10 @@
|
|||||||
package cn.odboy.modules.system.rest;
|
package cn.odboy.application.system.rest;
|
||||||
|
|
||||||
|
import cn.odboy.application.system.service.JobService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.system.domain.Job;
|
import cn.odboy.model.system.domain.Job;
|
||||||
import cn.odboy.model.system.dto.JobQueryCriteria;
|
import cn.odboy.model.system.dto.JobQueryCriteria;
|
||||||
import cn.odboy.modules.system.service.JobService;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -33,7 +33,7 @@ public class JobController {
|
|||||||
@GetMapping(value = "/download")
|
@GetMapping(value = "/download")
|
||||||
@PreAuthorize("@el.check('job:list')")
|
@PreAuthorize("@el.check('job:list')")
|
||||||
public void exportJob(HttpServletResponse response, JobQueryCriteria criteria) throws IOException {
|
public void exportJob(HttpServletResponse response, JobQueryCriteria criteria) throws IOException {
|
||||||
jobService.download(jobService.queryAll(criteria), response);
|
jobService.downloadExcel(jobService.selectJobByCriteria(criteria), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("查询岗位")
|
@ApiOperation("查询岗位")
|
||||||
@@ -41,7 +41,7 @@ public class JobController {
|
|||||||
@PreAuthorize("@el.check('job:list','user:list')")
|
@PreAuthorize("@el.check('job:list','user:list')")
|
||||||
public ResponseEntity<PageResult<Job>> queryJob(JobQueryCriteria criteria) {
|
public ResponseEntity<PageResult<Job>> queryJob(JobQueryCriteria criteria) {
|
||||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||||
return new ResponseEntity<>(jobService.queryAll(criteria, page), HttpStatus.OK);
|
return new ResponseEntity<>(jobService.queryJobPage(criteria, page), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("新增岗位")
|
@ApiOperation("新增岗位")
|
||||||
@@ -51,7 +51,7 @@ public class JobController {
|
|||||||
if (resources.getId() != null) {
|
if (resources.getId() != null) {
|
||||||
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
||||||
}
|
}
|
||||||
jobService.create(resources);
|
jobService.saveJob(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public class JobController {
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
@PreAuthorize("@el.check('job:edit')")
|
@PreAuthorize("@el.check('job:edit')")
|
||||||
public ResponseEntity<Object> updateJob(@Validated(Job.Update.class) @RequestBody Job resources) {
|
public ResponseEntity<Object> updateJob(@Validated(Job.Update.class) @RequestBody Job resources) {
|
||||||
jobService.update(resources);
|
jobService.updateJobById(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,8 +68,8 @@ public class JobController {
|
|||||||
@PreAuthorize("@el.check('job:del')")
|
@PreAuthorize("@el.check('job:del')")
|
||||||
public ResponseEntity<Object> deleteJob(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> deleteJob(@RequestBody Set<Long> ids) {
|
||||||
// 验证是否被用户关联
|
// 验证是否被用户关联
|
||||||
jobService.verification(ids);
|
jobService.verifyBindRelationByIds(ids);
|
||||||
jobService.delete(ids);
|
jobService.deleteJobByIds(ids);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+16
-16
@@ -1,12 +1,12 @@
|
|||||||
package cn.odboy.modules.system.rest;
|
package cn.odboy.application.system.rest;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.odboy.application.system.service.MenuService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.system.domain.Menu;
|
import cn.odboy.model.system.domain.Menu;
|
||||||
import cn.odboy.model.system.dto.MenuQueryCriteria;
|
import cn.odboy.model.system.dto.MenuQueryCriteria;
|
||||||
import cn.odboy.model.system.dto.MenuVo;
|
import cn.odboy.model.system.dto.MenuVo;
|
||||||
import cn.odboy.modules.system.service.MenuService;
|
|
||||||
import cn.odboy.util.PageUtil;
|
import cn.odboy.util.PageUtil;
|
||||||
import cn.odboy.util.SecurityUtil;
|
import cn.odboy.util.SecurityUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -36,13 +36,13 @@ public class MenuController {
|
|||||||
@GetMapping(value = "/download")
|
@GetMapping(value = "/download")
|
||||||
@PreAuthorize("@el.check('menu:list')")
|
@PreAuthorize("@el.check('menu:list')")
|
||||||
public void exportMenu(HttpServletResponse response, MenuQueryCriteria criteria) throws Exception {
|
public void exportMenu(HttpServletResponse response, MenuQueryCriteria criteria) throws Exception {
|
||||||
menuService.download(menuService.queryAll(criteria, false), response);
|
menuService.downloadExcel(menuService.selectMenuByCriteria(criteria, false), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/build")
|
@GetMapping(value = "/build")
|
||||||
@ApiOperation("获取前端所需菜单")
|
@ApiOperation("获取前端所需菜单")
|
||||||
public ResponseEntity<List<MenuVo>> buildMenus() {
|
public ResponseEntity<List<MenuVo>> buildMenus() {
|
||||||
List<Menu> menuList = menuService.findByUser(SecurityUtil.getCurrentUserId());
|
List<Menu> menuList = menuService.selectMenuByUserId(SecurityUtil.getCurrentUserId());
|
||||||
List<Menu> menus = menuService.buildTree(menuList);
|
List<Menu> menus = menuService.buildTree(menuList);
|
||||||
return new ResponseEntity<>(menuService.buildMenus(menus), HttpStatus.OK);
|
return new ResponseEntity<>(menuService.buildMenus(menus), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ public class MenuController {
|
|||||||
@GetMapping(value = "/lazy")
|
@GetMapping(value = "/lazy")
|
||||||
@PreAuthorize("@el.check('menu:list','roles:list')")
|
@PreAuthorize("@el.check('menu:list','roles:list')")
|
||||||
public ResponseEntity<List<Menu>> queryAllMenu(@RequestParam Long pid) {
|
public ResponseEntity<List<Menu>> queryAllMenu(@RequestParam Long pid) {
|
||||||
return new ResponseEntity<>(menuService.getMenus(pid), HttpStatus.OK);
|
return new ResponseEntity<>(menuService.selectMenuByPid(pid), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("根据菜单ID返回所有子节点ID,包含自身ID")
|
@ApiOperation("根据菜单ID返回所有子节点ID,包含自身ID")
|
||||||
@@ -59,9 +59,9 @@ public class MenuController {
|
|||||||
@PreAuthorize("@el.check('menu:list','roles:list')")
|
@PreAuthorize("@el.check('menu:list','roles:list')")
|
||||||
public ResponseEntity<Object> childMenu(@RequestParam Long id) {
|
public ResponseEntity<Object> childMenu(@RequestParam Long id) {
|
||||||
Set<Menu> menuSet = new HashSet<>();
|
Set<Menu> menuSet = new HashSet<>();
|
||||||
List<Menu> menuList = menuService.getMenus(id);
|
List<Menu> menuList = menuService.selectMenuByPid(id);
|
||||||
menuSet.add(menuService.getById(id));
|
menuSet.add(menuService.getById(id));
|
||||||
menuSet = menuService.getChildMenus(menuList, menuSet);
|
menuSet = menuService.selectChildMenus(menuList, menuSet);
|
||||||
Set<Long> ids = menuSet.stream().map(Menu::getId).collect(Collectors.toSet());
|
Set<Long> ids = menuSet.stream().map(Menu::getId).collect(Collectors.toSet());
|
||||||
return new ResponseEntity<>(ids, HttpStatus.OK);
|
return new ResponseEntity<>(ids, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ public class MenuController {
|
|||||||
@ApiOperation("查询菜单")
|
@ApiOperation("查询菜单")
|
||||||
@PreAuthorize("@el.check('menu:list')")
|
@PreAuthorize("@el.check('menu:list')")
|
||||||
public ResponseEntity<PageResult<Menu>> queryMenu(MenuQueryCriteria criteria) throws Exception {
|
public ResponseEntity<PageResult<Menu>> queryMenu(MenuQueryCriteria criteria) throws Exception {
|
||||||
List<Menu> menuList = menuService.queryAll(criteria, true);
|
List<Menu> menuList = menuService.selectMenuByCriteria(criteria, true);
|
||||||
return new ResponseEntity<>(PageUtil.toPage(menuList), HttpStatus.OK);
|
return new ResponseEntity<>(PageUtil.toPage(menuList), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +81,8 @@ public class MenuController {
|
|||||||
Set<Menu> menus = new LinkedHashSet<>();
|
Set<Menu> menus = new LinkedHashSet<>();
|
||||||
if (CollectionUtil.isNotEmpty(ids)) {
|
if (CollectionUtil.isNotEmpty(ids)) {
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
Menu menu = menuService.findById(id);
|
Menu menu = menuService.getMenuById(id);
|
||||||
List<Menu> menuList = menuService.getSuperior(menu, new ArrayList<>());
|
List<Menu> menuList = menuService.selectSuperiorMenu(menu, new ArrayList<>());
|
||||||
for (Menu data : menuList) {
|
for (Menu data : menuList) {
|
||||||
if (data.getId().equals(menu.getPid())) {
|
if (data.getId().equals(menu.getPid())) {
|
||||||
data.setSubCount(data.getSubCount() - 1);
|
data.setSubCount(data.getSubCount() - 1);
|
||||||
@@ -94,7 +94,7 @@ public class MenuController {
|
|||||||
menus = menus.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toSet());
|
menus = menus.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toSet());
|
||||||
return new ResponseEntity<>(menuService.buildTree(new ArrayList<>(menus)), HttpStatus.OK);
|
return new ResponseEntity<>(menuService.buildTree(new ArrayList<>(menus)), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>(menuService.getMenus(null), HttpStatus.OK);
|
return new ResponseEntity<>(menuService.selectMenuByPid(null), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("新增菜单")
|
@ApiOperation("新增菜单")
|
||||||
@@ -104,7 +104,7 @@ public class MenuController {
|
|||||||
if (resources.getId() != null) {
|
if (resources.getId() != null) {
|
||||||
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
||||||
}
|
}
|
||||||
menuService.create(resources);
|
menuService.saveMenu(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ public class MenuController {
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
@PreAuthorize("@el.check('menu:edit')")
|
@PreAuthorize("@el.check('menu:edit')")
|
||||||
public ResponseEntity<Object> updateMenu(@Validated(Menu.Update.class) @RequestBody Menu resources) {
|
public ResponseEntity<Object> updateMenu(@Validated(Menu.Update.class) @RequestBody Menu resources) {
|
||||||
menuService.update(resources);
|
menuService.updateMenuById(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,11 +122,11 @@ public class MenuController {
|
|||||||
public ResponseEntity<Object> deleteMenu(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> deleteMenu(@RequestBody Set<Long> ids) {
|
||||||
Set<Menu> menuSet = new HashSet<>();
|
Set<Menu> menuSet = new HashSet<>();
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
List<Menu> menuList = menuService.getMenus(id);
|
List<Menu> menuList = menuService.selectMenuByPid(id);
|
||||||
menuSet.add(menuService.getById(id));
|
menuSet.add(menuService.getById(id));
|
||||||
menuSet = menuService.getChildMenus(menuList, menuSet);
|
menuSet = menuService.selectChildMenus(menuList, menuSet);
|
||||||
}
|
}
|
||||||
menuService.delete(menuSet);
|
menuService.deleteMenuByIds(menuSet);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
package cn.odboy.modules.system.rest;
|
package cn.odboy.application.system.rest;
|
||||||
|
|
||||||
import cn.odboy.modules.system.service.MonitorService;
|
import cn.odboy.application.system.service.MonitorService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -23,6 +23,6 @@ public class MonitorController {
|
|||||||
@ApiOperation("查询服务监控")
|
@ApiOperation("查询服务监控")
|
||||||
@PreAuthorize("@el.check('monitor:list')")
|
@PreAuthorize("@el.check('monitor:list')")
|
||||||
public ResponseEntity<Object> queryMonitor() {
|
public ResponseEntity<Object> queryMonitor() {
|
||||||
return new ResponseEntity<>(serverService.getServers(), HttpStatus.OK);
|
return new ResponseEntity<>(serverService.getServerInfo(), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-12
@@ -1,11 +1,11 @@
|
|||||||
package cn.odboy.modules.system.rest;
|
package cn.odboy.application.system.rest;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
|
import cn.odboy.application.system.service.RoleService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.system.domain.Role;
|
import cn.odboy.model.system.domain.Role;
|
||||||
import cn.odboy.model.system.dto.RoleQueryCriteria;
|
import cn.odboy.model.system.dto.RoleQueryCriteria;
|
||||||
import cn.odboy.modules.system.service.RoleService;
|
|
||||||
import cn.odboy.util.SecurityUtil;
|
import cn.odboy.util.SecurityUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -39,21 +39,21 @@ public class RoleController {
|
|||||||
@GetMapping(value = "/{id}")
|
@GetMapping(value = "/{id}")
|
||||||
@PreAuthorize("@el.check('roles:list')")
|
@PreAuthorize("@el.check('roles:list')")
|
||||||
public ResponseEntity<Role> findRoleById(@PathVariable Long id) {
|
public ResponseEntity<Role> findRoleById(@PathVariable Long id) {
|
||||||
return new ResponseEntity<>(roleService.findById(id), HttpStatus.OK);
|
return new ResponseEntity<>(roleService.getRoleById(id), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("导出角色数据")
|
@ApiOperation("导出角色数据")
|
||||||
@GetMapping(value = "/download")
|
@GetMapping(value = "/download")
|
||||||
@PreAuthorize("@el.check('role:list')")
|
@PreAuthorize("@el.check('role:list')")
|
||||||
public void exportRole(HttpServletResponse response, RoleQueryCriteria criteria) throws IOException {
|
public void exportRole(HttpServletResponse response, RoleQueryCriteria criteria) throws IOException {
|
||||||
roleService.download(roleService.queryAll(criteria), response);
|
roleService.downloadExcel(roleService.selectRoleByCriteria(criteria), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("返回全部的角色")
|
@ApiOperation("返回全部的角色")
|
||||||
@GetMapping(value = "/all")
|
@GetMapping(value = "/all")
|
||||||
@PreAuthorize("@el.check('roles:list','user:add','user:edit')")
|
@PreAuthorize("@el.check('roles:list','user:add','user:edit')")
|
||||||
public ResponseEntity<List<Role>> queryAllRole() {
|
public ResponseEntity<List<Role>> queryAllRole() {
|
||||||
return new ResponseEntity<>(roleService.queryAll(), HttpStatus.OK);
|
return new ResponseEntity<>(roleService.selectRole(), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("查询角色")
|
@ApiOperation("查询角色")
|
||||||
@@ -61,7 +61,7 @@ public class RoleController {
|
|||||||
@PreAuthorize("@el.check('roles:list')")
|
@PreAuthorize("@el.check('roles:list')")
|
||||||
public ResponseEntity<PageResult<Role>> queryRole(RoleQueryCriteria criteria) {
|
public ResponseEntity<PageResult<Role>> queryRole(RoleQueryCriteria criteria) {
|
||||||
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||||
return new ResponseEntity<>(roleService.queryAll(criteria, page), HttpStatus.OK);
|
return new ResponseEntity<>(roleService.queryRolePage(criteria, page), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("获取用户级别")
|
@ApiOperation("获取用户级别")
|
||||||
@@ -78,7 +78,7 @@ public class RoleController {
|
|||||||
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
|
||||||
}
|
}
|
||||||
getLevels(resources.getLevel());
|
getLevels(resources.getLevel());
|
||||||
roleService.create(resources);
|
roleService.createRole(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class RoleController {
|
|||||||
@PreAuthorize("@el.check('roles:edit')")
|
@PreAuthorize("@el.check('roles:edit')")
|
||||||
public ResponseEntity<Object> updateRole(@Validated(Role.Update.class) @RequestBody Role resources) {
|
public ResponseEntity<Object> updateRole(@Validated(Role.Update.class) @RequestBody Role resources) {
|
||||||
getLevels(resources.getLevel());
|
getLevels(resources.getLevel());
|
||||||
roleService.update(resources);
|
roleService.updateRoleById(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public class RoleController {
|
|||||||
public ResponseEntity<Object> updateRoleMenu(@RequestBody Role resources) {
|
public ResponseEntity<Object> updateRoleMenu(@RequestBody Role resources) {
|
||||||
Role role = roleService.getById(resources.getId());
|
Role role = roleService.getById(resources.getId());
|
||||||
getLevels(role.getLevel());
|
getLevels(role.getLevel());
|
||||||
roleService.updateMenu(resources);
|
roleService.updateMenuById(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,8 +110,8 @@ public class RoleController {
|
|||||||
getLevels(role.getLevel());
|
getLevels(role.getLevel());
|
||||||
}
|
}
|
||||||
// 验证是否被用户关联
|
// 验证是否被用户关联
|
||||||
roleService.verification(ids);
|
roleService.verifyBindRelationByIds(ids);
|
||||||
roleService.delete(ids);
|
roleService.deleteRoleByIds(ids);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ public class RoleController {
|
|||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
private int getLevels(Integer level) {
|
private int getLevels(Integer level) {
|
||||||
List<Integer> levels = roleService.findByUsersId(SecurityUtil.getCurrentUserId()).stream().map(Role::getLevel).collect(Collectors.toList());
|
List<Integer> levels = roleService.selectRoleByUsersId(SecurityUtil.getCurrentUserId()).stream().map(Role::getLevel).collect(Collectors.toList());
|
||||||
int min = Collections.min(levels);
|
int min = Collections.min(levels);
|
||||||
if (level != null) {
|
if (level != null) {
|
||||||
if (level < min) {
|
if (level < min) {
|
||||||
+30
-30
@@ -1,6 +1,7 @@
|
|||||||
package cn.odboy.modules.system.rest;
|
package cn.odboy.application.system.rest;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.odboy.application.system.service.*;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.constant.CodeEnum;
|
import cn.odboy.constant.CodeEnum;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
@@ -9,10 +10,9 @@ import cn.odboy.model.system.domain.Role;
|
|||||||
import cn.odboy.model.system.domain.User;
|
import cn.odboy.model.system.domain.User;
|
||||||
import cn.odboy.model.system.dto.UserPassVo;
|
import cn.odboy.model.system.dto.UserPassVo;
|
||||||
import cn.odboy.model.system.dto.UserQueryCriteria;
|
import cn.odboy.model.system.dto.UserQueryCriteria;
|
||||||
import cn.odboy.modules.system.service.*;
|
|
||||||
import cn.odboy.properties.RsaProperties;
|
import cn.odboy.properties.RsaProperties;
|
||||||
import cn.odboy.util.PageUtil;
|
import cn.odboy.util.PageUtil;
|
||||||
import cn.odboy.util.RsaUtil;
|
import cn.odboy.util.RSAEncryptUtil;
|
||||||
import cn.odboy.util.SecurityUtil;
|
import cn.odboy.util.SecurityUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -52,7 +52,7 @@ public class UserController {
|
|||||||
@GetMapping(value = "/download")
|
@GetMapping(value = "/download")
|
||||||
@PreAuthorize("@el.check('user:list')")
|
@PreAuthorize("@el.check('user:list')")
|
||||||
public void exportUser(HttpServletResponse response, UserQueryCriteria criteria) throws IOException {
|
public void exportUser(HttpServletResponse response, UserQueryCriteria criteria) throws IOException {
|
||||||
userService.download(userService.queryAll(criteria), response);
|
userService.downloadExcel(userService.selectUserByCriteria(criteria), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("查询用户")
|
@ApiOperation("查询用户")
|
||||||
@@ -63,23 +63,23 @@ public class UserController {
|
|||||||
if (!ObjectUtils.isEmpty(criteria.getDeptId())) {
|
if (!ObjectUtils.isEmpty(criteria.getDeptId())) {
|
||||||
criteria.getDeptIds().add(criteria.getDeptId());
|
criteria.getDeptIds().add(criteria.getDeptId());
|
||||||
// 先查找是否存在子节点
|
// 先查找是否存在子节点
|
||||||
List<Dept> data = deptService.findByPid(criteria.getDeptId());
|
List<Dept> data = deptService.selectDeptByPid(criteria.getDeptId());
|
||||||
// 然后把子节点的ID都加入到集合中
|
// 然后把子节点的ID都加入到集合中
|
||||||
criteria.getDeptIds().addAll(deptService.getDeptChildren(data));
|
criteria.getDeptIds().addAll(deptService.selectChildDeptIdByDeptIds(data));
|
||||||
}
|
}
|
||||||
// 数据权限
|
// 数据权限
|
||||||
List<Long> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtil.getCurrentUsername()));
|
List<Long> dataScopes = dataService.selectDeptIdByUserIdWithDeptId(userService.getUserByUsername(SecurityUtil.getCurrentUsername()));
|
||||||
// criteria.getDeptIds() 不为空并且数据权限不为空则取交集
|
// criteria.getDeptIds() 不为空并且数据权限不为空则取交集
|
||||||
if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)) {
|
if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)) {
|
||||||
// 取交集
|
// 取交集
|
||||||
criteria.getDeptIds().retainAll(dataScopes);
|
criteria.getDeptIds().retainAll(dataScopes);
|
||||||
if (!CollectionUtil.isEmpty(criteria.getDeptIds())) {
|
if (!CollectionUtil.isEmpty(criteria.getDeptIds())) {
|
||||||
return new ResponseEntity<>(userService.queryAll(criteria, page), HttpStatus.OK);
|
return new ResponseEntity<>(userService.queryUserPage(criteria, page), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 否则取并集
|
// 否则取并集
|
||||||
criteria.getDeptIds().addAll(dataScopes);
|
criteria.getDeptIds().addAll(dataScopes);
|
||||||
return new ResponseEntity<>(userService.queryAll(criteria, page), HttpStatus.OK);
|
return new ResponseEntity<>(userService.queryUserPage(criteria, page), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>(PageUtil.noData(), HttpStatus.OK);
|
return new ResponseEntity<>(PageUtil.noData(), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ public class UserController {
|
|||||||
checkLevel(resources);
|
checkLevel(resources);
|
||||||
// 默认密码 123456
|
// 默认密码 123456
|
||||||
resources.setPassword(passwordEncoder.encode("123456"));
|
resources.setPassword(passwordEncoder.encode("123456"));
|
||||||
userService.create(resources);
|
userService.saveUser(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ public class UserController {
|
|||||||
@PreAuthorize("@el.check('user:edit')")
|
@PreAuthorize("@el.check('user:edit')")
|
||||||
public ResponseEntity<Object> updateUser(@Validated(User.Update.class) @RequestBody User resources) throws Exception {
|
public ResponseEntity<Object> updateUser(@Validated(User.Update.class) @RequestBody User resources) throws Exception {
|
||||||
checkLevel(resources);
|
checkLevel(resources);
|
||||||
userService.update(resources);
|
userService.updateUserById(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ public class UserController {
|
|||||||
if (!resources.getId().equals(SecurityUtil.getCurrentUserId())) {
|
if (!resources.getId().equals(SecurityUtil.getCurrentUserId())) {
|
||||||
throw new BadRequestException("不能修改他人资料");
|
throw new BadRequestException("不能修改他人资料");
|
||||||
}
|
}
|
||||||
userService.updateCenter(resources);
|
userService.updateCenterInfoById(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,56 +119,56 @@ public class UserController {
|
|||||||
@PreAuthorize("@el.check('user:del')")
|
@PreAuthorize("@el.check('user:del')")
|
||||||
public ResponseEntity<Object> deleteUser(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> deleteUser(@RequestBody Set<Long> ids) {
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
Integer currentLevel = Collections.min(roleService.findByUsersId(SecurityUtil.getCurrentUserId()).stream().map(Role::getLevel).collect(Collectors.toList()));
|
Integer currentLevel = Collections.min(roleService.selectRoleByUsersId(SecurityUtil.getCurrentUserId()).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||||
Integer optLevel = Collections.min(roleService.findByUsersId(id).stream().map(Role::getLevel).collect(Collectors.toList()));
|
Integer optLevel = Collections.min(roleService.selectRoleByUsersId(id).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||||
if (currentLevel > optLevel) {
|
if (currentLevel > optLevel) {
|
||||||
throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername());
|
throw new BadRequestException("角色权限不足,不能删除:" + userService.getUserById(id).getUsername());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userService.delete(ids);
|
userService.deleteUserByIds(ids);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("修改密码")
|
@ApiOperation("修改密码")
|
||||||
@PostMapping(value = "/updatePass")
|
@PostMapping(value = "/updatePass")
|
||||||
public ResponseEntity<Object> updateUserPass(@RequestBody UserPassVo passVo) throws Exception {
|
public ResponseEntity<Object> updateUserPassword(@RequestBody UserPassVo passVo) throws Exception {
|
||||||
String oldPass = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, passVo.getOldPass());
|
String oldPass = RSAEncryptUtil.decryptByPrivateKey(RsaProperties.privateKey, passVo.getOldPass());
|
||||||
String newPass = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, passVo.getNewPass());
|
String newPass = RSAEncryptUtil.decryptByPrivateKey(RsaProperties.privateKey, passVo.getNewPass());
|
||||||
User user = userService.findByName(SecurityUtil.getCurrentUsername());
|
User user = userService.getUserByUsername(SecurityUtil.getCurrentUsername());
|
||||||
if (!passwordEncoder.matches(oldPass, user.getPassword())) {
|
if (!passwordEncoder.matches(oldPass, user.getPassword())) {
|
||||||
throw new BadRequestException("修改失败,旧密码错误");
|
throw new BadRequestException("修改失败,旧密码错误");
|
||||||
}
|
}
|
||||||
if (passwordEncoder.matches(newPass, user.getPassword())) {
|
if (passwordEncoder.matches(newPass, user.getPassword())) {
|
||||||
throw new BadRequestException("新密码不能与旧密码相同");
|
throw new BadRequestException("新密码不能与旧密码相同");
|
||||||
}
|
}
|
||||||
userService.updatePass(user.getUsername(), passwordEncoder.encode(newPass));
|
userService.updatePasswordByUsername(user.getUsername(), passwordEncoder.encode(newPass));
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("重置密码")
|
@ApiOperation("重置密码")
|
||||||
@PutMapping(value = "/resetPwd")
|
@PutMapping(value = "/resetPwd")
|
||||||
public ResponseEntity<Object> resetPwd(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> resetPwd(@RequestBody Set<Long> ids) {
|
||||||
String pwd = passwordEncoder.encode("123456");
|
String defaultPwd = passwordEncoder.encode("123456");
|
||||||
userService.resetPwd(ids, pwd);
|
userService.resetPasswordByIds(ids, defaultPwd);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("修改头像")
|
@ApiOperation("修改头像")
|
||||||
@PostMapping(value = "/updateAvatar")
|
@PostMapping(value = "/updateAvatar")
|
||||||
public ResponseEntity<Object> updateUserAvatar(@RequestParam MultipartFile avatar) {
|
public ResponseEntity<Object> updateUserAvatar(@RequestParam MultipartFile avatar) {
|
||||||
return new ResponseEntity<>(userService.updateAvatar(avatar), HttpStatus.OK);
|
return new ResponseEntity<>(userService.updateAvatarFile(avatar), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("修改邮箱")
|
@ApiOperation("修改邮箱")
|
||||||
@PostMapping(value = "/updateEmail/{code}")
|
@PostMapping(value = "/updateEmail/{code}")
|
||||||
public ResponseEntity<Object> updateUserEmail(@PathVariable String code, @RequestBody User resources) throws Exception {
|
public ResponseEntity<Object> updateUserEmail(@PathVariable String code, @RequestBody User resources) throws Exception {
|
||||||
String password = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, resources.getPassword());
|
String password = RSAEncryptUtil.decryptByPrivateKey(RsaProperties.privateKey, resources.getPassword());
|
||||||
User user = userService.findByName(SecurityUtil.getCurrentUsername());
|
User user = userService.getUserByUsername(SecurityUtil.getCurrentUsername());
|
||||||
if (!passwordEncoder.matches(password, user.getPassword())) {
|
if (!passwordEncoder.matches(password, user.getPassword())) {
|
||||||
throw new BadRequestException("密码错误");
|
throw new BadRequestException("密码错误");
|
||||||
}
|
}
|
||||||
verificationCodeService.validated(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey() + resources.getEmail(), code);
|
verificationCodeService.validateEmailCode(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey(), resources.getEmail(), code);
|
||||||
userService.updateEmail(user.getUsername(), resources.getEmail());
|
userService.updateEmailByUsername(user.getUsername(), resources.getEmail());
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,8 +178,8 @@ public class UserController {
|
|||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
private void checkLevel(User resources) {
|
private void checkLevel(User resources) {
|
||||||
Integer currentLevel = Collections.min(roleService.findByUsersId(SecurityUtil.getCurrentUserId()).stream().map(Role::getLevel).collect(Collectors.toList()));
|
Integer currentLevel = Collections.min(roleService.selectRoleByUsersId(SecurityUtil.getCurrentUserId()).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||||
Integer optLevel = roleService.findByRoles(resources.getRoles());
|
Integer optLevel = roleService.getDeptLevelByRoles(resources.getRoles());
|
||||||
if (currentLevel > optLevel) {
|
if (currentLevel > optLevel) {
|
||||||
throw new BadRequestException("角色权限不足");
|
throw new BadRequestException("角色权限不足");
|
||||||
}
|
}
|
||||||
+9
-9
@@ -1,10 +1,10 @@
|
|||||||
package cn.odboy.modules.system.rest;
|
package cn.odboy.application.system.rest;
|
||||||
|
|
||||||
|
import cn.odboy.application.system.service.VerifyService;
|
||||||
|
import cn.odboy.application.tools.service.EmailService;
|
||||||
import cn.odboy.constant.CodeBiEnum;
|
import cn.odboy.constant.CodeBiEnum;
|
||||||
import cn.odboy.constant.CodeEnum;
|
import cn.odboy.constant.CodeEnum;
|
||||||
import cn.odboy.model.tools.dto.EmailDto;
|
import cn.odboy.model.tools.dto.EmailDto;
|
||||||
import cn.odboy.modules.system.service.VerifyService;
|
|
||||||
import cn.odboy.service.EmailService;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -27,16 +27,16 @@ public class VerifyController {
|
|||||||
@PostMapping(value = "/resetEmail")
|
@PostMapping(value = "/resetEmail")
|
||||||
@ApiOperation("重置邮箱,发送验证码")
|
@ApiOperation("重置邮箱,发送验证码")
|
||||||
public ResponseEntity<Object> resetEmail(@RequestParam String email) {
|
public ResponseEntity<Object> resetEmail(@RequestParam String email) {
|
||||||
EmailDto emailDto = verificationCodeService.sendEmail(email, CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey());
|
EmailDto emailDto = verificationCodeService.sendEmailCode(email, CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey());
|
||||||
emailService.send(emailDto, emailService.find());
|
emailService.sendEmail(emailDto);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/email/resetPass")
|
@PostMapping(value = "/email/resetPass")
|
||||||
@ApiOperation("重置密码,发送验证码")
|
@ApiOperation("重置密码,发送验证码")
|
||||||
public ResponseEntity<Object> resetPass(@RequestParam String email) {
|
public ResponseEntity<Object> resetPass(@RequestParam String email) {
|
||||||
EmailDto emailDto = verificationCodeService.sendEmail(email, CodeEnum.EMAIL_RESET_PWD_CODE.getKey());
|
EmailDto emailDto = verificationCodeService.sendEmailCode(email, CodeEnum.EMAIL_RESET_PWD_CODE.getKey());
|
||||||
emailService.send(emailDto, emailService.find());
|
emailService.sendEmail(emailDto);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,10 +46,10 @@ public class VerifyController {
|
|||||||
CodeBiEnum biEnum = CodeBiEnum.find(codeBi);
|
CodeBiEnum biEnum = CodeBiEnum.find(codeBi);
|
||||||
switch (Objects.requireNonNull(biEnum)) {
|
switch (Objects.requireNonNull(biEnum)) {
|
||||||
case ONE:
|
case ONE:
|
||||||
verificationCodeService.validated(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey() + email, code);
|
verificationCodeService.validateEmailCode(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey(), email, code);
|
||||||
break;
|
break;
|
||||||
case TWO:
|
case TWO:
|
||||||
verificationCodeService.validated(CodeEnum.EMAIL_RESET_PWD_CODE.getKey() + email, code);
|
verificationCodeService.validateEmailCode(CodeEnum.EMAIL_RESET_PWD_CODE.getKey(), email, code);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.service;
|
package cn.odboy.application.system.service;
|
||||||
|
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.User;
|
import cn.odboy.model.system.domain.User;
|
||||||
@@ -16,5 +16,5 @@ public interface DataService {
|
|||||||
* @param user /
|
* @param user /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Long> getDeptIds(User user);
|
List<Long> selectDeptIdByUserIdWithDeptId(User user);
|
||||||
}
|
}
|
||||||
+25
-15
@@ -1,5 +1,6 @@
|
|||||||
package cn.odboy.modules.system.service;
|
package cn.odboy.application.system.service;
|
||||||
|
|
||||||
|
import cn.odboy.base.BaseResult;
|
||||||
import cn.odboy.model.system.domain.Dept;
|
import cn.odboy.model.system.domain.Dept;
|
||||||
import cn.odboy.model.system.dto.DeptQueryCriteria;
|
import cn.odboy.model.system.dto.DeptQueryCriteria;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
@@ -7,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface DeptService extends IService<Dept> {
|
public interface DeptService extends IService<Dept> {
|
||||||
@@ -19,7 +21,7 @@ public interface DeptService extends IService<Dept> {
|
|||||||
* @return /
|
* @return /
|
||||||
* @throws Exception /
|
* @throws Exception /
|
||||||
*/
|
*/
|
||||||
List<Dept> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception;
|
List<Dept> selectDeptByCriteria(DeptQueryCriteria criteria, Boolean isQuery) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID查询
|
* 根据ID查询
|
||||||
@@ -27,28 +29,28 @@ public interface DeptService extends IService<Dept> {
|
|||||||
* @param id /
|
* @param id /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Dept findById(Long id);
|
Dept getDeptById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建
|
* 创建
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void create(Dept resources);
|
void createDept(Dept resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑
|
* 编辑
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void update(Dept resources);
|
void updateDept(Dept resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
*
|
*
|
||||||
* @param depts /
|
* @param depts /
|
||||||
*/
|
*/
|
||||||
void delete(Set<Dept> depts);
|
void deleteDeptByIds(Set<Dept> depts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据PID查询
|
* 根据PID查询
|
||||||
@@ -56,7 +58,7 @@ public interface DeptService extends IService<Dept> {
|
|||||||
* @param pid /
|
* @param pid /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Dept> findByPid(long pid);
|
List<Dept> selectDeptByPid(long pid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色ID查询
|
* 根据角色ID查询
|
||||||
@@ -64,7 +66,7 @@ public interface DeptService extends IService<Dept> {
|
|||||||
* @param id /
|
* @param id /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Set<Dept> findByRoleId(Long id);
|
Set<Dept> selectDeptByRoleId(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出数据
|
* 导出数据
|
||||||
@@ -73,16 +75,16 @@ public interface DeptService extends IService<Dept> {
|
|||||||
* @param response /
|
* @param response /
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void download(List<Dept> depts, HttpServletResponse response) throws IOException;
|
void downloadExcel(List<Dept> depts, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取待删除的部门
|
* 获取部门下所有关联的部门
|
||||||
*
|
*
|
||||||
* @param deptList /
|
* @param deptList /
|
||||||
* @param depts /
|
* @param depts /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Set<Dept> getDeleteDepts(List<Dept> deptList, Set<Dept> depts);
|
Set<Dept> selectRelationDept(List<Dept> deptList, Set<Dept> depts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID获取同级与上级数据
|
* 根据ID获取同级与上级数据
|
||||||
@@ -91,7 +93,7 @@ public interface DeptService extends IService<Dept> {
|
|||||||
* @param depts /
|
* @param depts /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Dept> getSuperior(Dept dept, List<Dept> depts);
|
List<Dept> selectSuperiorDeptByPid(Dept dept, List<Dept> depts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建树形数据
|
* 构建树形数据
|
||||||
@@ -99,7 +101,7 @@ public interface DeptService extends IService<Dept> {
|
|||||||
* @param depts /
|
* @param depts /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Object buildTree(List<Dept> depts);
|
BaseResult<Object> buildTree(List<Dept> depts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取
|
* 获取
|
||||||
@@ -107,12 +109,20 @@ public interface DeptService extends IService<Dept> {
|
|||||||
* @param deptList 、
|
* @param deptList 、
|
||||||
* @return 、
|
* @return 、
|
||||||
*/
|
*/
|
||||||
List<Long> getDeptChildren(List<Dept> deptList);
|
List<Long> selectChildDeptIdByDeptIds(List<Dept> deptList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证是否被角色或用户关联
|
* 验证是否被角色或用户关联
|
||||||
*
|
*
|
||||||
* @param depts /
|
* @param depts /
|
||||||
*/
|
*/
|
||||||
void verification(Set<Dept> depts);
|
void verifyBindRelationByIds(Set<Dept> depts);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 遍历所有部门和子部门
|
||||||
|
*
|
||||||
|
* @param ids /
|
||||||
|
* @param depts /
|
||||||
|
*/
|
||||||
|
void traverseDeptByIdWithPids(Set<Long> ids, Set<Dept> depts);
|
||||||
}
|
}
|
||||||
+6
-6
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.service;
|
package cn.odboy.application.system.service;
|
||||||
|
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.model.system.domain.DictDetail;
|
import cn.odboy.model.system.domain.DictDetail;
|
||||||
@@ -16,21 +16,21 @@ public interface DictDetailService extends IService<DictDetail> {
|
|||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void create(DictDetail resources);
|
void saveDictDetail(DictDetail resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑
|
* 编辑
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void update(DictDetail resources);
|
void updateDictDetailById(DictDetail resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
*
|
*
|
||||||
* @param id /
|
* @param id /
|
||||||
*/
|
*/
|
||||||
void delete(Long id);
|
void deleteDictDetailById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
@@ -39,7 +39,7 @@ public interface DictDetailService extends IService<DictDetail> {
|
|||||||
* @param page 分页参数
|
* @param page 分页参数
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
PageResult<DictDetail> queryAll(DictDetailQueryCriteria criteria, Page<Object> page);
|
PageResult<DictDetail> queryDictDetailPage(DictDetailQueryCriteria criteria, Page<Object> page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据字典名称获取字典详情
|
* 根据字典名称获取字典详情
|
||||||
@@ -47,5 +47,5 @@ public interface DictDetailService extends IService<DictDetail> {
|
|||||||
* @param name 字典名称
|
* @param name 字典名称
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<DictDetail> getDictByName(String name);
|
List<DictDetail> selectDictDetailByName(String name);
|
||||||
}
|
}
|
||||||
+7
-7
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.service;
|
package cn.odboy.application.system.service;
|
||||||
|
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.model.system.domain.Dict;
|
import cn.odboy.model.system.domain.Dict;
|
||||||
@@ -21,7 +21,7 @@ public interface DictService extends IService<Dict> {
|
|||||||
* @param page 分页参数
|
* @param page 分页参数
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
PageResult<Dict> queryAll(DictQueryCriteria criteria, Page<Object> page);
|
PageResult<Dict> queryDictPage(DictQueryCriteria criteria, Page<Object> page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询全部数据
|
* 查询全部数据
|
||||||
@@ -29,28 +29,28 @@ public interface DictService extends IService<Dict> {
|
|||||||
* @param criteria /
|
* @param criteria /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Dict> queryAll(DictQueryCriteria criteria);
|
List<Dict> selectDictByCriteria(DictQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建
|
* 创建
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void create(Dict resources);
|
void saveDict(Dict resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑
|
* 编辑
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void update(Dict resources);
|
void updateDictById(Dict resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
*
|
*
|
||||||
* @param ids /
|
* @param ids /
|
||||||
*/
|
*/
|
||||||
void delete(Set<Long> ids);
|
void deleteDictByIds(Set<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出数据
|
* 导出数据
|
||||||
@@ -59,5 +59,5 @@ public interface DictService extends IService<Dict> {
|
|||||||
* @param response /
|
* @param response /
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void download(List<Dict> queryAll, HttpServletResponse response) throws IOException;
|
void downloadExcel(List<Dict> queryAll, HttpServletResponse response) throws IOException;
|
||||||
}
|
}
|
||||||
+9
-9
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.service;
|
package cn.odboy.application.system.service;
|
||||||
|
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.model.system.domain.Job;
|
import cn.odboy.model.system.domain.Job;
|
||||||
@@ -20,28 +20,28 @@ public interface JobService extends IService<Job> {
|
|||||||
* @param id /
|
* @param id /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Job findById(Long id);
|
Job getJobById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建
|
* 创建
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void create(Job resources);
|
void saveJob(Job resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑
|
* 编辑
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void update(Job resources);
|
void updateJobById(Job resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
*
|
*
|
||||||
* @param ids /
|
* @param ids /
|
||||||
*/
|
*/
|
||||||
void delete(Set<Long> ids);
|
void deleteJobByIds(Set<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
@@ -50,7 +50,7 @@ public interface JobService extends IService<Job> {
|
|||||||
* @param page 分页参数
|
* @param page 分页参数
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
PageResult<Job> queryAll(JobQueryCriteria criteria, Page<Object> page);
|
PageResult<Job> queryJobPage(JobQueryCriteria criteria, Page<Object> page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询全部数据
|
* 查询全部数据
|
||||||
@@ -58,7 +58,7 @@ public interface JobService extends IService<Job> {
|
|||||||
* @param criteria /
|
* @param criteria /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Job> queryAll(JobQueryCriteria criteria);
|
List<Job> selectJobByCriteria(JobQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出数据
|
* 导出数据
|
||||||
@@ -67,12 +67,12 @@ public interface JobService extends IService<Job> {
|
|||||||
* @param response /
|
* @param response /
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void download(List<Job> jobs, HttpServletResponse response) throws IOException;
|
void downloadExcel(List<Job> jobs, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证是否被用户关联
|
* 验证是否被用户关联
|
||||||
*
|
*
|
||||||
* @param ids /
|
* @param ids /
|
||||||
*/
|
*/
|
||||||
void verification(Set<Long> ids);
|
void verifyBindRelationByIds(Set<Long> ids);
|
||||||
}
|
}
|
||||||
+11
-11
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.service;
|
package cn.odboy.application.system.service;
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.Menu;
|
import cn.odboy.model.system.domain.Menu;
|
||||||
import cn.odboy.model.system.dto.MenuQueryCriteria;
|
import cn.odboy.model.system.dto.MenuQueryCriteria;
|
||||||
@@ -20,7 +20,7 @@ public interface MenuService extends IService<Menu> {
|
|||||||
* @return /
|
* @return /
|
||||||
* @throws Exception /
|
* @throws Exception /
|
||||||
*/
|
*/
|
||||||
List<Menu> queryAll(MenuQueryCriteria criteria, Boolean isQuery) throws Exception;
|
List<Menu> selectMenuByCriteria(MenuQueryCriteria criteria, Boolean isQuery) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID查询
|
* 根据ID查询
|
||||||
@@ -28,21 +28,21 @@ public interface MenuService extends IService<Menu> {
|
|||||||
* @param id /
|
* @param id /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Menu findById(long id);
|
Menu getMenuById(long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建
|
* 创建
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void create(Menu resources);
|
void saveMenu(Menu resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑
|
* 编辑
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void update(Menu resources);
|
void updateMenuById(Menu resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有子节点,包含自身ID
|
* 获取所有子节点,包含自身ID
|
||||||
@@ -51,7 +51,7 @@ public interface MenuService extends IService<Menu> {
|
|||||||
* @param menuSet /
|
* @param menuSet /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Set<Menu> getChildMenus(List<Menu> menuList, Set<Menu> menuSet);
|
Set<Menu> selectChildMenus(List<Menu> menuList, Set<Menu> menuSet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建菜单树
|
* 构建菜单树
|
||||||
@@ -74,7 +74,7 @@ public interface MenuService extends IService<Menu> {
|
|||||||
*
|
*
|
||||||
* @param menuSet /
|
* @param menuSet /
|
||||||
*/
|
*/
|
||||||
void delete(Set<Menu> menuSet);
|
void deleteMenuByIds(Set<Menu> menuSet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出
|
* 导出
|
||||||
@@ -83,7 +83,7 @@ public interface MenuService extends IService<Menu> {
|
|||||||
* @param response /
|
* @param response /
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void download(List<Menu> menus, HttpServletResponse response) throws IOException;
|
void downloadExcel(List<Menu> menus, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 懒加载菜单数据
|
* 懒加载菜单数据
|
||||||
@@ -91,7 +91,7 @@ public interface MenuService extends IService<Menu> {
|
|||||||
* @param pid /
|
* @param pid /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Menu> getMenus(Long pid);
|
List<Menu> selectMenuByPid(Long pid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID获取同级与上级数据
|
* 根据ID获取同级与上级数据
|
||||||
@@ -100,7 +100,7 @@ public interface MenuService extends IService<Menu> {
|
|||||||
* @param objects /
|
* @param objects /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Menu> getSuperior(Menu menu, List<Menu> objects);
|
List<Menu> selectSuperiorMenu(Menu menu, List<Menu> objects);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据当前用户获取菜单
|
* 根据当前用户获取菜单
|
||||||
@@ -108,5 +108,5 @@ public interface MenuService extends IService<Menu> {
|
|||||||
* @param currentUserId /
|
* @param currentUserId /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Menu> findByUser(Long currentUserId);
|
List<Menu> selectMenuByUserId(Long currentUserId);
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.service;
|
package cn.odboy.application.system.service;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -9,5 +9,5 @@ public interface MonitorService {
|
|||||||
*
|
*
|
||||||
* @return Map<String, Object>
|
* @return Map<String, Object>
|
||||||
*/
|
*/
|
||||||
Map<String, Object> getServers();
|
Map<String, Object> getServerInfo();
|
||||||
}
|
}
|
||||||
+60
-60
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.service;
|
package cn.odboy.application.system.service;
|
||||||
|
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.model.system.domain.Role;
|
import cn.odboy.model.system.domain.Role;
|
||||||
@@ -21,59 +21,15 @@ public interface RoleService extends IService<Role> {
|
|||||||
*
|
*
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Role> queryAll();
|
List<Role> selectRole();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID查询
|
* 查询全部
|
||||||
*
|
*
|
||||||
* @param id /
|
* @param criteria 条件
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Role findById(long id);
|
List<Role> selectRoleByCriteria(RoleQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建
|
|
||||||
*
|
|
||||||
* @param resources /
|
|
||||||
*/
|
|
||||||
void create(Role resources);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编辑
|
|
||||||
*
|
|
||||||
* @param resources /
|
|
||||||
*/
|
|
||||||
void update(Role resources);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除
|
|
||||||
*
|
|
||||||
* @param ids /
|
|
||||||
*/
|
|
||||||
void delete(Set<Long> ids);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据用户ID查询
|
|
||||||
*
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
List<Role> findByUsersId(Long userId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据角色查询角色级别
|
|
||||||
*
|
|
||||||
* @param roles /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
Integer findByRoles(Set<Role> roles);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改绑定的菜单
|
|
||||||
*
|
|
||||||
* @param resources /
|
|
||||||
*/
|
|
||||||
void updateMenu(Role resources);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 待条件分页查询
|
* 待条件分页查询
|
||||||
@@ -82,24 +38,59 @@ public interface RoleService extends IService<Role> {
|
|||||||
* @param page 分页参数
|
* @param page 分页参数
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
PageResult<Role> queryAll(RoleQueryCriteria criteria, Page<Object> page);
|
PageResult<Role> queryRolePage(RoleQueryCriteria criteria, Page<Object> page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询全部
|
* 根据ID查询
|
||||||
*
|
*
|
||||||
* @param criteria 条件
|
* @param id /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Role> queryAll(RoleQueryCriteria criteria);
|
Role getRoleById(long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出数据
|
* 创建
|
||||||
*
|
*
|
||||||
* @param roles 待导出的数据
|
* @param resources /
|
||||||
* @param response /
|
|
||||||
* @throws IOException /
|
|
||||||
*/
|
*/
|
||||||
void download(List<Role> roles, HttpServletResponse response) throws IOException;
|
void createRole(Role resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑
|
||||||
|
*
|
||||||
|
* @param resources /
|
||||||
|
*/
|
||||||
|
void updateRoleById(Role resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改绑定的菜单
|
||||||
|
*
|
||||||
|
* @param resources /
|
||||||
|
*/
|
||||||
|
void updateMenuById(Role resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*
|
||||||
|
* @param ids /
|
||||||
|
*/
|
||||||
|
void deleteRoleByIds(Set<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID查询
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
List<Role> selectRoleByUsersId(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色查询角色级别
|
||||||
|
*
|
||||||
|
* @param roles /
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
Integer getDeptLevelByRoles(Set<Role> roles);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户权限信息
|
* 获取用户权限信息
|
||||||
@@ -109,12 +100,21 @@ public interface RoleService extends IService<Role> {
|
|||||||
*/
|
*/
|
||||||
List<AuthorityDto> buildPermissions(User user);
|
List<AuthorityDto> buildPermissions(User user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出数据
|
||||||
|
*
|
||||||
|
* @param roles 待导出的数据
|
||||||
|
* @param response /
|
||||||
|
* @throws IOException /
|
||||||
|
*/
|
||||||
|
void downloadExcel(List<Role> roles, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证是否被用户关联
|
* 验证是否被用户关联
|
||||||
*
|
*
|
||||||
* @param ids /
|
* @param ids /
|
||||||
*/
|
*/
|
||||||
void verification(Set<Long> ids);
|
void verifyBindRelationByIds(Set<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据菜单Id查询
|
* 根据菜单Id查询
|
||||||
@@ -122,5 +122,5 @@ public interface RoleService extends IService<Role> {
|
|||||||
* @param menuId /
|
* @param menuId /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Role> findByMenuId(Long menuId);
|
List<Role> selectRoleByMenuId(Long menuId);
|
||||||
}
|
}
|
||||||
+17
-25
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.service;
|
package cn.odboy.application.system.service;
|
||||||
|
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.model.system.domain.User;
|
import cn.odboy.model.system.domain.User;
|
||||||
@@ -21,14 +21,14 @@ public interface UserService extends IService<User> {
|
|||||||
* @param id ID
|
* @param id ID
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
User findById(long id);
|
User getUserById(long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增用户
|
* 新增用户
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void create(User resources);
|
void saveUser(User resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑用户
|
* 编辑用户
|
||||||
@@ -36,30 +36,22 @@ public interface UserService extends IService<User> {
|
|||||||
* @param resources /
|
* @param resources /
|
||||||
* @throws Exception /
|
* @throws Exception /
|
||||||
*/
|
*/
|
||||||
void update(User resources) throws Exception;
|
void updateUserById(User resources) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除用户
|
* 删除用户
|
||||||
*
|
*
|
||||||
* @param ids /
|
* @param ids /
|
||||||
*/
|
*/
|
||||||
void delete(Set<Long> ids);
|
void deleteUserByIds(Set<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户名查询
|
* 根据用户名查询
|
||||||
*
|
*
|
||||||
* @param userName /
|
* @param username /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
User findByName(String userName);
|
User getUserByUsername(String username);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据用户名查询
|
|
||||||
*
|
|
||||||
* @param userName /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
User getLoginData(String userName);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改密码
|
* 修改密码
|
||||||
@@ -67,7 +59,7 @@ public interface UserService extends IService<User> {
|
|||||||
* @param username 用户名
|
* @param username 用户名
|
||||||
* @param encryptPassword 密码
|
* @param encryptPassword 密码
|
||||||
*/
|
*/
|
||||||
void updatePass(String username, String encryptPassword);
|
void updatePasswordByUsername(String username, String encryptPassword);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改头像
|
* 修改头像
|
||||||
@@ -75,7 +67,7 @@ public interface UserService extends IService<User> {
|
|||||||
* @param file 文件
|
* @param file 文件
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Map<String, String> updateAvatar(MultipartFile file);
|
Map<String, String> updateAvatarFile(MultipartFile file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改邮箱
|
* 修改邮箱
|
||||||
@@ -83,7 +75,7 @@ public interface UserService extends IService<User> {
|
|||||||
* @param username 用户名
|
* @param username 用户名
|
||||||
* @param email 邮箱
|
* @param email 邮箱
|
||||||
*/
|
*/
|
||||||
void updateEmail(String username, String email);
|
void updateEmailByUsername(String username, String email);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询全部
|
* 查询全部
|
||||||
@@ -92,7 +84,7 @@ public interface UserService extends IService<User> {
|
|||||||
* @param page 分页参数
|
* @param page 分页参数
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
PageResult<User> queryAll(UserQueryCriteria criteria, Page<Object> page);
|
PageResult<User> queryUserPage(UserQueryCriteria criteria, Page<Object> page);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询全部不分页
|
* 查询全部不分页
|
||||||
@@ -100,7 +92,7 @@ public interface UserService extends IService<User> {
|
|||||||
* @param criteria 条件
|
* @param criteria 条件
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<User> queryAll(UserQueryCriteria criteria);
|
List<User> selectUserByCriteria(UserQueryCriteria criteria);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出数据
|
* 导出数据
|
||||||
@@ -109,20 +101,20 @@ public interface UserService extends IService<User> {
|
|||||||
* @param response /
|
* @param response /
|
||||||
* @throws IOException /
|
* @throws IOException /
|
||||||
*/
|
*/
|
||||||
void download(List<User> queryAll, HttpServletResponse response) throws IOException;
|
void downloadExcel(List<User> queryAll, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户自助修改资料
|
* 用户自助修改资料
|
||||||
*
|
*
|
||||||
* @param resources /
|
* @param resources /
|
||||||
*/
|
*/
|
||||||
void updateCenter(User resources);
|
void updateCenterInfoById(User resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置密码
|
* 重置密码
|
||||||
*
|
*
|
||||||
* @param ids 用户id
|
* @param ids 用户id
|
||||||
* @param pwd 密码
|
* @param password 密码
|
||||||
*/
|
*/
|
||||||
void resetPwd(Set<Long> ids, String pwd);
|
void resetPasswordByIds(Set<Long> ids, String password);
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.service;
|
package cn.odboy.application.system.service;
|
||||||
|
|
||||||
|
|
||||||
import cn.odboy.model.tools.dto.EmailDto;
|
import cn.odboy.model.tools.dto.EmailDto;
|
||||||
@@ -11,7 +11,7 @@ public interface VerifyService {
|
|||||||
* @param key /
|
* @param key /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
EmailDto sendEmail(String email, String key);
|
EmailDto sendEmailCode(String email, String key);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,5 +20,5 @@ public interface VerifyService {
|
|||||||
* @param code /
|
* @param code /
|
||||||
* @param key /
|
* @param key /
|
||||||
*/
|
*/
|
||||||
void validated(String key, String code);
|
void validateEmailCode(String key, String email, String code);
|
||||||
}
|
}
|
||||||
+12
-12
@@ -1,14 +1,14 @@
|
|||||||
package cn.odboy.modules.system.service.impl;
|
package cn.odboy.application.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.odboy.constant.CacheKey;
|
import cn.odboy.application.system.service.DataService;
|
||||||
|
import cn.odboy.application.system.service.DeptService;
|
||||||
|
import cn.odboy.application.system.service.RoleService;
|
||||||
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.constant.DataScopeEnum;
|
import cn.odboy.constant.DataScopeEnum;
|
||||||
import cn.odboy.model.system.domain.Dept;
|
import cn.odboy.model.system.domain.Dept;
|
||||||
import cn.odboy.model.system.domain.Role;
|
import cn.odboy.model.system.domain.Role;
|
||||||
import cn.odboy.model.system.domain.User;
|
import cn.odboy.model.system.domain.User;
|
||||||
import cn.odboy.modules.system.service.DataService;
|
|
||||||
import cn.odboy.modules.system.service.DeptService;
|
|
||||||
import cn.odboy.modules.system.service.RoleService;
|
|
||||||
import cn.odboy.util.RedisUtil;
|
import cn.odboy.util.RedisUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -33,13 +33,13 @@ public class DataServiceImpl implements DataService {
|
|||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Long> getDeptIds(User user) {
|
public List<Long> selectDeptIdByUserIdWithDeptId(User user) {
|
||||||
String key = CacheKey.DATA_USER + user.getId();
|
String key = SystemRedisKey.DATA_USER + user.getId();
|
||||||
List<Long> ids = redisUtil.getList(key, Long.class);
|
List<Long> ids = redisUtil.getList(key, Long.class);
|
||||||
if (CollUtil.isEmpty(ids)) {
|
if (CollUtil.isEmpty(ids)) {
|
||||||
Set<Long> deptIds = new HashSet<>();
|
Set<Long> deptIds = new HashSet<>();
|
||||||
// 查询用户角色
|
// 查询用户角色
|
||||||
List<Role> roleList = roleService.findByUsersId(user.getId());
|
List<Role> roleList = roleService.selectRoleByUsersId(user.getId());
|
||||||
// 获取对应的部门ID
|
// 获取对应的部门ID
|
||||||
for (Role role : roleList) {
|
for (Role role : roleList) {
|
||||||
DataScopeEnum dataScopeEnum = DataScopeEnum.find(role.getDataScope());
|
DataScopeEnum dataScopeEnum = DataScopeEnum.find(role.getDataScope());
|
||||||
@@ -68,12 +68,12 @@ public class DataServiceImpl implements DataService {
|
|||||||
* @return 数据权限ID
|
* @return 数据权限ID
|
||||||
*/
|
*/
|
||||||
public Set<Long> getCustomize(Set<Long> deptIds, Role role) {
|
public Set<Long> getCustomize(Set<Long> deptIds, Role role) {
|
||||||
Set<Dept> depts = deptService.findByRoleId(role.getId());
|
Set<Dept> deptList = deptService.selectDeptByRoleId(role.getId());
|
||||||
for (Dept dept : depts) {
|
for (Dept dept : deptList) {
|
||||||
deptIds.add(dept.getId());
|
deptIds.add(dept.getId());
|
||||||
List<Dept> deptChildren = deptService.findByPid(dept.getId());
|
List<Dept> deptChildren = deptService.selectDeptByPid(dept.getId());
|
||||||
if (CollUtil.isNotEmpty(deptChildren)) {
|
if (CollUtil.isNotEmpty(deptChildren)) {
|
||||||
deptIds.addAll(deptService.getDeptChildren(deptChildren));
|
deptIds.addAll(deptService.selectChildDeptIdByDeptIds(deptChildren));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deptIds;
|
return deptIds;
|
||||||
+82
-73
@@ -1,22 +1,20 @@
|
|||||||
package cn.odboy.modules.system.service.impl;
|
package cn.odboy.application.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.odboy.constant.CacheKey;
|
import cn.odboy.application.system.mapper.DeptMapper;
|
||||||
|
import cn.odboy.application.system.mapper.RoleMapper;
|
||||||
|
import cn.odboy.application.system.mapper.UserMapper;
|
||||||
|
import cn.odboy.application.system.service.DeptService;
|
||||||
|
import cn.odboy.base.BaseResult;
|
||||||
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.constant.DataScopeEnum;
|
import cn.odboy.constant.DataScopeEnum;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.system.domain.Dept;
|
import cn.odboy.model.system.domain.Dept;
|
||||||
import cn.odboy.model.system.domain.User;
|
import cn.odboy.model.system.domain.User;
|
||||||
import cn.odboy.model.system.dto.DeptQueryCriteria;
|
import cn.odboy.model.system.dto.DeptQueryCriteria;
|
||||||
import cn.odboy.modules.system.mapper.DeptMapper;
|
import cn.odboy.util.*;
|
||||||
import cn.odboy.modules.system.mapper.RoleMapper;
|
|
||||||
import cn.odboy.modules.system.mapper.UserMapper;
|
|
||||||
import cn.odboy.modules.system.service.DeptService;
|
|
||||||
import cn.odboy.util.FileUtil;
|
|
||||||
import cn.odboy.util.RedisUtil;
|
|
||||||
import cn.odboy.util.SecurityUtil;
|
|
||||||
import cn.odboy.util.StringUtil;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -38,19 +36,19 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
|||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Dept> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception {
|
public List<Dept> selectDeptByCriteria(DeptQueryCriteria criteria, Boolean isQuery) throws Exception {
|
||||||
String dataScopeType = SecurityUtil.getDataScopeType();
|
String dataScopeType = SecurityUtil.getDataScopeType();
|
||||||
if (isQuery) {
|
if (isQuery) {
|
||||||
if (dataScopeType.equals(DataScopeEnum.ALL.getValue())) {
|
if (dataScopeType.equals(DataScopeEnum.ALL.getValue())) {
|
||||||
criteria.setPidIsNull(true);
|
criteria.setPidIsNull(true);
|
||||||
}
|
}
|
||||||
List<Field> fields = StringUtil.getAllFields(criteria.getClass(), new ArrayList<>());
|
List<Field> fields = ClassUtil.getAllFields(criteria.getClass(), new ArrayList<>());
|
||||||
List<String> fieldNames = new ArrayList<String>() {{
|
List<String> fieldNames = new ArrayList<>() {{
|
||||||
add("pidIsNull");
|
add("pidIsNull");
|
||||||
add("enabled");
|
add("enabled");
|
||||||
}};
|
}};
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
//设置对象的访问权限,保证对private的属性的访问
|
// 设置对象的访问权限,保证对private的属性的访问
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Object val = field.get(criteria);
|
Object val = field.get(criteria);
|
||||||
if (fieldNames.contains(field.getName())) {
|
if (fieldNames.contains(field.getName())) {
|
||||||
@@ -64,7 +62,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
|||||||
}
|
}
|
||||||
// 数据权限
|
// 数据权限
|
||||||
criteria.setIds(SecurityUtil.getCurrentUserDataScope());
|
criteria.setIds(SecurityUtil.getCurrentUserDataScope());
|
||||||
List<Dept> list = deptMapper.findDept(criteria);
|
List<Dept> list = deptMapper.selectDeptByCriteria(criteria);
|
||||||
// 如果为空,就代表为自定义权限或者本级权限,就需要去重,不理解可以注释掉,看查询结果
|
// 如果为空,就代表为自定义权限或者本级权限,就需要去重,不理解可以注释掉,看查询结果
|
||||||
if (StringUtil.isBlank(dataScopeType)) {
|
if (StringUtil.isBlank(dataScopeType)) {
|
||||||
return deduplication(list);
|
return deduplication(list);
|
||||||
@@ -73,8 +71,8 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dept findById(Long id) {
|
public Dept getDeptById(Long id) {
|
||||||
String key = CacheKey.DEPT_ID + id;
|
String key = SystemRedisKey.DEPT_ID + id;
|
||||||
Dept dept = redisUtil.get(key, Dept.class);
|
Dept dept = redisUtil.get(key, Dept.class);
|
||||||
if (dept == null) {
|
if (dept == null) {
|
||||||
dept = deptMapper.selectById(id);
|
dept = deptMapper.selectById(id);
|
||||||
@@ -84,30 +82,30 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Dept> findByPid(long pid) {
|
public List<Dept> selectDeptByPid(long pid) {
|
||||||
return deptMapper.findDeptByPid(pid);
|
return deptMapper.selectDeptByPid(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Dept> findByRoleId(Long id) {
|
public Set<Dept> selectDeptByRoleId(Long id) {
|
||||||
return deptMapper.findDeptByRoleId(id);
|
return deptMapper.selectDeptByRoleId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(Dept resources) {
|
public void createDept(Dept resources) {
|
||||||
save(resources);
|
save(resources);
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
updateSubCnt(resources.getPid());
|
updateSubCnt(resources.getPid());
|
||||||
// 清理自定义角色权限的datascope缓存
|
// 清理自定义角色权限的DataScope缓存
|
||||||
delCaches(resources.getPid());
|
delCaches(resources.getPid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(Dept resources) {
|
public void updateDept(Dept resources) {
|
||||||
// 旧的部门
|
// 旧的部门
|
||||||
Long oldPid = findById(resources.getId()).getPid();
|
Long oldPid = getDeptById(resources.getId()).getPid();
|
||||||
Long newPid = resources.getPid();
|
Long newPid = resources.getPid();
|
||||||
if (resources.getPid() != null && resources.getId().equals(resources.getPid())) {
|
if (resources.getPid() != null && resources.getId().equals(resources.getPid())) {
|
||||||
throw new BadRequestException("上级不能为自己");
|
throw new BadRequestException("上级不能为自己");
|
||||||
@@ -124,8 +122,8 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<Dept> depts) {
|
public void deleteDeptByIds(Set<Dept> deptSet) {
|
||||||
for (Dept dept : depts) {
|
for (Dept dept : deptSet) {
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
delCaches(dept.getId());
|
delCaches(dept.getId());
|
||||||
deptMapper.deleteById(dept.getId());
|
deptMapper.deleteById(dept.getId());
|
||||||
@@ -134,9 +132,9 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<Dept> depts, HttpServletResponse response) throws IOException {
|
public void downloadExcel(List<Dept> deptList, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (Dept dept : depts) {
|
for (Dept dept : deptList) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("部门名称", dept.getName());
|
map.put("部门名称", dept.getName());
|
||||||
map.put("部门状态", dept.getEnabled() ? "启用" : "停用");
|
map.put("部门状态", dept.getEnabled() ? "启用" : "停用");
|
||||||
@@ -147,25 +145,25 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Dept> getDeleteDepts(List<Dept> menuList, Set<Dept> deptSet) {
|
public Set<Dept> selectRelationDept(List<Dept> menuList, Set<Dept> deptSet) {
|
||||||
for (Dept dept : menuList) {
|
for (Dept dept : menuList) {
|
||||||
deptSet.add(dept);
|
deptSet.add(dept);
|
||||||
List<Dept> depts = deptMapper.findDeptByPid(dept.getId());
|
List<Dept> deptList = deptMapper.selectDeptByPid(dept.getId());
|
||||||
if (CollUtil.isNotEmpty(depts)) {
|
if (CollUtil.isNotEmpty(deptList)) {
|
||||||
getDeleteDepts(depts, deptSet);
|
selectRelationDept(deptList, deptSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deptSet;
|
return deptSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Long> getDeptChildren(List<Dept> deptList) {
|
public List<Long> selectChildDeptIdByDeptIds(List<Dept> deptList) {
|
||||||
List<Long> list = new ArrayList<>();
|
List<Long> list = new ArrayList<>();
|
||||||
deptList.forEach(dept -> {
|
deptList.forEach(dept -> {
|
||||||
if (dept != null && dept.getEnabled()) {
|
if (dept != null && dept.getEnabled()) {
|
||||||
List<Dept> depts = deptMapper.findDeptByPid(dept.getId());
|
List<Dept> deptList1 = deptMapper.selectDeptByPid(dept.getId());
|
||||||
if (CollUtil.isNotEmpty(depts)) {
|
if (CollUtil.isNotEmpty(deptList1)) {
|
||||||
list.addAll(getDeptChildren(depts));
|
list.addAll(selectChildDeptIdByDeptIds(deptList1));
|
||||||
}
|
}
|
||||||
list.add(dept.getId());
|
list.add(dept.getId());
|
||||||
}
|
}
|
||||||
@@ -175,19 +173,19 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Dept> getSuperior(Dept dept, List<Dept> depts) {
|
public List<Dept> selectSuperiorDeptByPid(Dept dept, List<Dept> deptList) {
|
||||||
if (dept.getPid() == null) {
|
if (dept.getPid() == null) {
|
||||||
depts.addAll(deptMapper.findDeptByPidIsNull());
|
deptList.addAll(deptMapper.selectDeptByPidIsNull());
|
||||||
return depts;
|
return deptList;
|
||||||
}
|
}
|
||||||
depts.addAll(deptMapper.findDeptByPid(dept.getPid()));
|
deptList.addAll(deptMapper.selectDeptByPid(dept.getPid()));
|
||||||
return getSuperior(findById(dept.getPid()), depts);
|
return selectSuperiorDeptByPid(getDeptById(dept.getPid()), deptList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object buildTree(List<Dept> deptList) {
|
public BaseResult<Object> buildTree(List<Dept> deptList) {
|
||||||
Set<Dept> trees = new LinkedHashSet<>();
|
Set<Dept> trees = new LinkedHashSet<>();
|
||||||
Set<Dept> depts = new LinkedHashSet<>();
|
Set<Dept> deptSet = new LinkedHashSet<>();
|
||||||
List<String> deptNames = deptList.stream().map(Dept::getName).collect(Collectors.toList());
|
List<String> deptNames = deptList.stream().map(Dept::getName).collect(Collectors.toList());
|
||||||
boolean isChild;
|
boolean isChild;
|
||||||
for (Dept dept : deptList) {
|
for (Dept dept : deptList) {
|
||||||
@@ -205,54 +203,65 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isChild) {
|
if (isChild) {
|
||||||
depts.add(dept);
|
deptSet.add(dept);
|
||||||
} else if (dept.getPid() != null && !deptNames.contains(findById(dept.getPid()).getName())) {
|
} else if (dept.getPid() != null && !deptNames.contains(getDeptById(dept.getPid()).getName())) {
|
||||||
depts.add(dept);
|
deptSet.add(dept);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CollectionUtil.isEmpty(trees)) {
|
if (CollectionUtil.isEmpty(trees)) {
|
||||||
trees = depts;
|
trees = deptSet;
|
||||||
}
|
}
|
||||||
Map<String, Object> map = new HashMap<>(2);
|
BaseResult<Object> baseResult = new BaseResult<>();
|
||||||
map.put("totalElements", depts.size());
|
baseResult.setContent(CollectionUtil.isEmpty(trees) ? deptSet : trees);
|
||||||
map.put("content", CollectionUtil.isEmpty(trees) ? depts : trees);
|
baseResult.setTotalElements(deptSet.size());
|
||||||
return map;
|
return baseResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void verification(Set<Dept> depts) {
|
public void verifyBindRelationByIds(Set<Dept> deptSet) {
|
||||||
Set<Long> deptIds = depts.stream().map(Dept::getId).collect(Collectors.toSet());
|
Set<Long> deptIds = deptSet.stream().map(Dept::getId).collect(Collectors.toSet());
|
||||||
if (userMapper.countByDepts(deptIds) > 0) {
|
if (userMapper.getCountByDepts(deptIds) > 0) {
|
||||||
throw new BadRequestException("所选部门存在用户关联,请解除后再试!");
|
throw new BadRequestException("所选部门存在用户关联,请解除后再试!");
|
||||||
}
|
}
|
||||||
if (roleMapper.countRolesByDeptIds(deptIds) > 0) {
|
if (roleMapper.getRoleCountByDeptIds(deptIds) > 0) {
|
||||||
throw new BadRequestException("所选部门存在角色关联,请解除后再试!");
|
throw new BadRequestException("所选部门存在角色关联,请解除后再试!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void traverseDeptByIdWithPids(Set<Long> ids, Set<Dept> depts) {
|
||||||
|
for (Long id : ids) {
|
||||||
|
// 根部门
|
||||||
|
depts.add(getDeptById(id));
|
||||||
|
// 子部门
|
||||||
|
List<Dept> deptList = selectDeptByPid(id);
|
||||||
|
if (CollectionUtil.isNotEmpty(deptList)) {
|
||||||
|
depts = selectRelationDept(deptList, depts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateSubCnt(Long deptId) {
|
private void updateSubCnt(Long deptId) {
|
||||||
if (deptId != null) {
|
if (deptId != null) {
|
||||||
int count = deptMapper.countDeptByPid(deptId);
|
int count = deptMapper.getDeptCountByPid(deptId);
|
||||||
deptMapper.updateDeptSubCountById(count, deptId);
|
deptMapper.updateSubCountById(count, deptId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 筛选出 list 中没有父部门(即 pid 不在其他部门 id 列表中的部门)的部门列表
|
||||||
|
*/
|
||||||
private List<Dept> deduplication(List<Dept> list) {
|
private List<Dept> deduplication(List<Dept> list) {
|
||||||
List<Dept> depts = new ArrayList<>();
|
List<Dept> deptList = new ArrayList<>();
|
||||||
|
// 使用 Set 存储所有部门的 id
|
||||||
|
Set<Long> idSet = list.stream().map(Dept::getId).collect(Collectors.toSet());
|
||||||
|
// 遍历部门列表,筛选出没有父部门的部门
|
||||||
for (Dept dept : list) {
|
for (Dept dept : list) {
|
||||||
boolean flag = true;
|
if (!idSet.contains(dept.getPid())) {
|
||||||
for (Dept dept1 : list) {
|
deptList.add(dept);
|
||||||
if (dept1.getId().equals(dept.getPid())) {
|
|
||||||
flag = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (flag) {
|
|
||||||
depts.add(dept);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return depts;
|
return deptList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -261,9 +270,9 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
|||||||
* @param id /
|
* @param id /
|
||||||
*/
|
*/
|
||||||
public void delCaches(Long id) {
|
public void delCaches(Long id) {
|
||||||
List<User> users = userMapper.findByRoleDeptId(id);
|
List<User> users = userMapper.selectUserByRoleDeptId(id);
|
||||||
// 删除数据权限
|
// 删除数据权限
|
||||||
redisUtil.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|
redisUtil.delByKeys(SystemRedisKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||||
redisUtil.del(CacheKey.DEPT_ID + id);
|
redisUtil.del(SystemRedisKey.DEPT_ID + id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+14
-14
@@ -1,14 +1,14 @@
|
|||||||
package cn.odboy.modules.system.service.impl;
|
package cn.odboy.application.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.odboy.application.system.mapper.DictDetailMapper;
|
||||||
|
import cn.odboy.application.system.mapper.DictMapper;
|
||||||
|
import cn.odboy.application.system.service.DictDetailService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.constant.CacheKey;
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.model.system.domain.Dict;
|
import cn.odboy.model.system.domain.Dict;
|
||||||
import cn.odboy.model.system.domain.DictDetail;
|
import cn.odboy.model.system.domain.DictDetail;
|
||||||
import cn.odboy.model.system.dto.DictDetailQueryCriteria;
|
import cn.odboy.model.system.dto.DictDetailQueryCriteria;
|
||||||
import cn.odboy.modules.system.mapper.DictDetailMapper;
|
|
||||||
import cn.odboy.modules.system.mapper.DictMapper;
|
|
||||||
import cn.odboy.modules.system.service.DictDetailService;
|
|
||||||
import cn.odboy.util.PageUtil;
|
import cn.odboy.util.PageUtil;
|
||||||
import cn.odboy.util.RedisUtil;
|
import cn.odboy.util.RedisUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@@ -28,13 +28,13 @@ public class DictDetailServiceImpl extends ServiceImpl<DictDetailMapper, DictDet
|
|||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<DictDetail> queryAll(DictDetailQueryCriteria criteria, Page<Object> page) {
|
public PageResult<DictDetail> queryDictDetailPage(DictDetailQueryCriteria criteria, Page<Object> page) {
|
||||||
return PageUtil.toPage(dictDetailMapper.findDictDetail(criteria, page));
|
return PageUtil.toPage(dictDetailMapper.queryDictDetail(criteria, page));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(DictDetail resources) {
|
public void saveDictDetail(DictDetail resources) {
|
||||||
resources.setDictId(resources.getDict().getId());
|
resources.setDictId(resources.getDict().getId());
|
||||||
save(resources);
|
save(resources);
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
@@ -43,7 +43,7 @@ public class DictDetailServiceImpl extends ServiceImpl<DictDetailMapper, DictDet
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(DictDetail resources) {
|
public void updateDictDetailById(DictDetail resources) {
|
||||||
DictDetail dictDetail = getById(resources.getId());
|
DictDetail dictDetail = getById(resources.getId());
|
||||||
resources.setId(dictDetail.getId());
|
resources.setId(dictDetail.getId());
|
||||||
// 更新数据
|
// 更新数据
|
||||||
@@ -53,11 +53,11 @@ public class DictDetailServiceImpl extends ServiceImpl<DictDetailMapper, DictDet
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DictDetail> getDictByName(String name) {
|
public List<DictDetail> selectDictDetailByName(String name) {
|
||||||
String key = CacheKey.DICT_NAME + name;
|
String key = SystemRedisKey.DICT_NAME + name;
|
||||||
List<DictDetail> dictDetails = redisUtil.getList(key, DictDetail.class);
|
List<DictDetail> dictDetails = redisUtil.getList(key, DictDetail.class);
|
||||||
if (CollUtil.isEmpty(dictDetails)) {
|
if (CollUtil.isEmpty(dictDetails)) {
|
||||||
dictDetails = dictDetailMapper.findDictDetailByDictName(name);
|
dictDetails = dictDetailMapper.selectDictDetailByDictName(name);
|
||||||
redisUtil.set(key, dictDetails, 1, TimeUnit.DAYS);
|
redisUtil.set(key, dictDetails, 1, TimeUnit.DAYS);
|
||||||
}
|
}
|
||||||
return dictDetails;
|
return dictDetails;
|
||||||
@@ -65,7 +65,7 @@ public class DictDetailServiceImpl extends ServiceImpl<DictDetailMapper, DictDet
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Long id) {
|
public void deleteDictDetailById(Long id) {
|
||||||
DictDetail dictDetail = getById(id);
|
DictDetail dictDetail = getById(id);
|
||||||
removeById(id);
|
removeById(id);
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
@@ -74,6 +74,6 @@ public class DictDetailServiceImpl extends ServiceImpl<DictDetailMapper, DictDet
|
|||||||
|
|
||||||
public void delCaches(DictDetail dictDetail) {
|
public void delCaches(DictDetail dictDetail) {
|
||||||
Dict dict = dictMapper.selectById(dictDetail.getDictId());
|
Dict dict = dictMapper.selectById(dictDetail.getDictId());
|
||||||
redisUtil.del(CacheKey.DICT_NAME + dict.getName());
|
redisUtil.del(SystemRedisKey.DICT_NAME + dict.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+15
-15
@@ -1,14 +1,14 @@
|
|||||||
package cn.odboy.modules.system.service.impl;
|
package cn.odboy.application.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.odboy.application.system.mapper.DictDetailMapper;
|
||||||
|
import cn.odboy.application.system.mapper.DictMapper;
|
||||||
|
import cn.odboy.application.system.service.DictService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.constant.CacheKey;
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.model.system.domain.Dict;
|
import cn.odboy.model.system.domain.Dict;
|
||||||
import cn.odboy.model.system.domain.DictDetail;
|
import cn.odboy.model.system.domain.DictDetail;
|
||||||
import cn.odboy.model.system.dto.DictQueryCriteria;
|
import cn.odboy.model.system.dto.DictQueryCriteria;
|
||||||
import cn.odboy.modules.system.mapper.DictDetailMapper;
|
|
||||||
import cn.odboy.modules.system.mapper.DictMapper;
|
|
||||||
import cn.odboy.modules.system.service.DictService;
|
|
||||||
import cn.odboy.util.FileUtil;
|
import cn.odboy.util.FileUtil;
|
||||||
import cn.odboy.util.PageUtil;
|
import cn.odboy.util.PageUtil;
|
||||||
import cn.odboy.util.RedisUtil;
|
import cn.odboy.util.RedisUtil;
|
||||||
@@ -31,25 +31,25 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements Di
|
|||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<Dict> queryAll(DictQueryCriteria criteria, Page<Object> page) {
|
public PageResult<Dict> queryDictPage(DictQueryCriteria criteria, Page<Object> page) {
|
||||||
IPage<Dict> dicts = dictMapper.findDictPage(criteria, page);
|
IPage<Dict> dicts = dictMapper.queryDictPage(criteria, page);
|
||||||
return PageUtil.toPage(dicts);
|
return PageUtil.toPage(dicts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Dict> queryAll(DictQueryCriteria criteria) {
|
public List<Dict> selectDictByCriteria(DictQueryCriteria criteria) {
|
||||||
return dictMapper.findDictPage(criteria, PageUtil.getCount(dictMapper)).getRecords();
|
return dictMapper.queryDictPage(criteria, PageUtil.getCount(dictMapper)).getRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(Dict resources) {
|
public void saveDict(Dict resources) {
|
||||||
save(resources);
|
save(resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(Dict resources) {
|
public void updateDictById(Dict resources) {
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
delCaches(resources);
|
delCaches(resources);
|
||||||
Dict dict = getById(resources.getId());
|
Dict dict = getById(resources.getId());
|
||||||
@@ -60,7 +60,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements Di
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<Long> ids) {
|
public void deleteDictByIds(Set<Long> ids) {
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
List<Dict> dicts = dictMapper.selectByIds(ids);
|
List<Dict> dicts = dictMapper.selectByIds(ids);
|
||||||
for (Dict dict : dicts) {
|
for (Dict dict : dicts) {
|
||||||
@@ -73,10 +73,10 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements Di
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<Dict> dicts, HttpServletResponse response) throws IOException {
|
public void downloadExcel(List<Dict> dicts, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (Dict dict : dicts) {
|
for (Dict dict : dicts) {
|
||||||
List<DictDetail> dictDetails = dictDetailMapper.findDictDetailByDictName(dict.getName());
|
List<DictDetail> dictDetails = dictDetailMapper.selectDictDetailByDictName(dict.getName());
|
||||||
if (CollectionUtil.isNotEmpty(dictDetails)) {
|
if (CollectionUtil.isNotEmpty(dictDetails)) {
|
||||||
for (DictDetail dictDetail : dictDetails) {
|
for (DictDetail dictDetail : dictDetails) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
@@ -101,6 +101,6 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements Di
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delCaches(Dict dict) {
|
public void delCaches(Dict dict) {
|
||||||
redisUtil.del(CacheKey.DICT_NAME + dict.getName());
|
redisUtil.del(SystemRedisKey.DICT_NAME + dict.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+20
-20
@@ -1,14 +1,14 @@
|
|||||||
package cn.odboy.modules.system.service.impl;
|
package cn.odboy.application.system.service.impl;
|
||||||
|
|
||||||
|
import cn.odboy.application.system.mapper.JobMapper;
|
||||||
|
import cn.odboy.application.system.mapper.UserMapper;
|
||||||
|
import cn.odboy.application.system.service.JobService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.constant.CacheKey;
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.exception.EntityExistException;
|
import cn.odboy.exception.EntityExistException;
|
||||||
import cn.odboy.model.system.domain.Job;
|
import cn.odboy.model.system.domain.Job;
|
||||||
import cn.odboy.model.system.dto.JobQueryCriteria;
|
import cn.odboy.model.system.dto.JobQueryCriteria;
|
||||||
import cn.odboy.modules.system.mapper.JobMapper;
|
|
||||||
import cn.odboy.modules.system.mapper.UserMapper;
|
|
||||||
import cn.odboy.modules.system.service.JobService;
|
|
||||||
import cn.odboy.util.FileUtil;
|
import cn.odboy.util.FileUtil;
|
||||||
import cn.odboy.util.PageUtil;
|
import cn.odboy.util.PageUtil;
|
||||||
import cn.odboy.util.RedisUtil;
|
import cn.odboy.util.RedisUtil;
|
||||||
@@ -31,18 +31,18 @@ public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobSe
|
|||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<Job> queryAll(JobQueryCriteria criteria, Page<Object> page) {
|
public PageResult<Job> queryJobPage(JobQueryCriteria criteria, Page<Object> page) {
|
||||||
return PageUtil.toPage(jobMapper.findJobPage(criteria, page));
|
return PageUtil.toPage(jobMapper.queryJobPage(criteria, page));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Job> queryAll(JobQueryCriteria criteria) {
|
public List<Job> selectJobByCriteria(JobQueryCriteria criteria) {
|
||||||
return jobMapper.findJobPage(criteria, PageUtil.getCount(jobMapper)).getRecords();
|
return jobMapper.queryJobPage(criteria, PageUtil.getCount(jobMapper)).getRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Job findById(Long id) {
|
public Job getJobById(Long id) {
|
||||||
String key = CacheKey.JOB_ID + id;
|
String key = SystemRedisKey.JOB_ID + id;
|
||||||
Job job = redisUtil.get(key, Job.class);
|
Job job = redisUtil.get(key, Job.class);
|
||||||
if (job == null) {
|
if (job == null) {
|
||||||
job = getById(id);
|
job = getById(id);
|
||||||
@@ -53,8 +53,8 @@ public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobSe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(Job resources) {
|
public void saveJob(Job resources) {
|
||||||
Job job = jobMapper.findJobByName(resources.getName());
|
Job job = jobMapper.getJobByName(resources.getName());
|
||||||
if (job != null) {
|
if (job != null) {
|
||||||
throw new EntityExistException(Job.class, "name", resources.getName());
|
throw new EntityExistException(Job.class, "name", resources.getName());
|
||||||
}
|
}
|
||||||
@@ -63,9 +63,9 @@ public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobSe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(Job resources) {
|
public void updateJobById(Job resources) {
|
||||||
Job job = getById(resources.getId());
|
Job job = getById(resources.getId());
|
||||||
Job old = jobMapper.findJobByName(resources.getName());
|
Job old = jobMapper.getJobByName(resources.getName());
|
||||||
if (old != null && !old.getId().equals(resources.getId())) {
|
if (old != null && !old.getId().equals(resources.getId())) {
|
||||||
throw new EntityExistException(Job.class, "name", resources.getName());
|
throw new EntityExistException(Job.class, "name", resources.getName());
|
||||||
}
|
}
|
||||||
@@ -77,14 +77,14 @@ public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobSe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<Long> ids) {
|
public void deleteJobByIds(Set<Long> ids) {
|
||||||
removeBatchByIds(ids);
|
removeBatchByIds(ids);
|
||||||
// 删除缓存
|
// 删除缓存
|
||||||
ids.forEach(this::delCaches);
|
ids.forEach(this::delCaches);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<Job> jobs, HttpServletResponse response) throws IOException {
|
public void downloadExcel(List<Job> jobs, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (Job job : jobs) {
|
for (Job job : jobs) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
@@ -97,13 +97,13 @@ public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void verification(Set<Long> ids) {
|
public void verifyBindRelationByIds(Set<Long> ids) {
|
||||||
if (userMapper.countByJobs(ids) > 0) {
|
if (userMapper.getCountByJobs(ids) > 0) {
|
||||||
throw new BadRequestException("所选的岗位中存在用户关联,请解除关联再试!");
|
throw new BadRequestException("所选的岗位中存在用户关联,请解除关联再试!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delCaches(Long id) {
|
public void delCaches(Long id) {
|
||||||
redisUtil.del(CacheKey.JOB_ID + id);
|
redisUtil.del(SystemRedisKey.JOB_ID + id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+46
-47
@@ -1,9 +1,15 @@
|
|||||||
package cn.odboy.modules.system.service.impl;
|
package cn.odboy.application.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.odboy.constant.CacheKey;
|
import cn.odboy.application.system.mapper.MenuMapper;
|
||||||
|
import cn.odboy.application.system.mapper.RoleMenuMapper;
|
||||||
|
import cn.odboy.application.system.mapper.UserMapper;
|
||||||
|
import cn.odboy.application.system.service.MenuService;
|
||||||
|
import cn.odboy.application.system.service.RoleService;
|
||||||
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
|
import cn.odboy.constant.TransferProtocolConst;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.exception.EntityExistException;
|
import cn.odboy.exception.EntityExistException;
|
||||||
import cn.odboy.model.system.domain.Menu;
|
import cn.odboy.model.system.domain.Menu;
|
||||||
@@ -12,11 +18,7 @@ import cn.odboy.model.system.domain.User;
|
|||||||
import cn.odboy.model.system.dto.MenuMetaVo;
|
import cn.odboy.model.system.dto.MenuMetaVo;
|
||||||
import cn.odboy.model.system.dto.MenuQueryCriteria;
|
import cn.odboy.model.system.dto.MenuQueryCriteria;
|
||||||
import cn.odboy.model.system.dto.MenuVo;
|
import cn.odboy.model.system.dto.MenuVo;
|
||||||
import cn.odboy.modules.system.mapper.MenuMapper;
|
import cn.odboy.util.ClassUtil;
|
||||||
import cn.odboy.modules.system.mapper.RoleMenuMapper;
|
|
||||||
import cn.odboy.modules.system.mapper.UserMapper;
|
|
||||||
import cn.odboy.modules.system.service.MenuService;
|
|
||||||
import cn.odboy.modules.system.service.RoleService;
|
|
||||||
import cn.odboy.util.FileUtil;
|
import cn.odboy.util.FileUtil;
|
||||||
import cn.odboy.util.RedisUtil;
|
import cn.odboy.util.RedisUtil;
|
||||||
import cn.odboy.util.StringUtil;
|
import cn.odboy.util.StringUtil;
|
||||||
@@ -42,17 +44,14 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
private static final String HTTP_PRE = "http://";
|
|
||||||
private static final String HTTPS_PRE = "https://";
|
|
||||||
private static final String YES_STR = "是";
|
private static final String YES_STR = "是";
|
||||||
private static final String NO_STR = "否";
|
private static final String NO_STR = "否";
|
||||||
private static final String BAD_REQUEST = "外链必须以http://或者https://开头";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Menu> queryAll(MenuQueryCriteria criteria, Boolean isQuery) throws Exception {
|
public List<Menu> selectMenuByCriteria(MenuQueryCriteria criteria, Boolean isQuery) throws Exception {
|
||||||
if (Boolean.TRUE.equals(isQuery)) {
|
if (Boolean.TRUE.equals(isQuery)) {
|
||||||
criteria.setPidIsNull(true);
|
criteria.setPidIsNull(true);
|
||||||
List<Field> fields = StringUtil.getAllFields(criteria.getClass(), new ArrayList<>());
|
List<Field> fields = ClassUtil.getAllFields(criteria.getClass(), new ArrayList<>());
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
//设置对象的访问权限,保证对private的属性的访问
|
//设置对象的访问权限,保证对private的属性的访问
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
@@ -67,12 +66,12 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return menuMapper.findAll(criteria);
|
return menuMapper.selectMenuByCriteria(criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Menu findById(long id) {
|
public Menu getMenuById(long id) {
|
||||||
String key = CacheKey.MENU_ID + id;
|
String key = SystemRedisKey.MENU_ID + id;
|
||||||
Menu menu = redisUtil.get(key, Menu.class);
|
Menu menu = redisUtil.get(key, Menu.class);
|
||||||
if (menu == null) {
|
if (menu == null) {
|
||||||
menu = getById(id);
|
menu = getById(id);
|
||||||
@@ -88,13 +87,13 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Menu> findByUser(Long currentUserId) {
|
public List<Menu> selectMenuByUserId(Long currentUserId) {
|
||||||
String key = CacheKey.MENU_USER + currentUserId;
|
String key = SystemRedisKey.MENU_USER + currentUserId;
|
||||||
List<Menu> menus = redisUtil.getList(key, Menu.class);
|
List<Menu> menus = redisUtil.getList(key, Menu.class);
|
||||||
if (CollUtil.isEmpty(menus)) {
|
if (CollUtil.isEmpty(menus)) {
|
||||||
List<Role> roles = roleService.findByUsersId(currentUserId);
|
List<Role> roles = roleService.selectRoleByUsersId(currentUserId);
|
||||||
Set<Long> roleIds = roles.stream().map(Role::getId).collect(Collectors.toSet());
|
Set<Long> roleIds = roles.stream().map(Role::getId).collect(Collectors.toSet());
|
||||||
menus = new ArrayList<>(menuMapper.findByRoleIdsAndTypeNot(roleIds, 2));
|
menus = new ArrayList<>(menuMapper.selectMenuByRoleIdsAndType(roleIds, 2));
|
||||||
redisUtil.set(key, menus, 1, TimeUnit.DAYS);
|
redisUtil.set(key, menus, 1, TimeUnit.DAYS);
|
||||||
}
|
}
|
||||||
return menus;
|
return menus;
|
||||||
@@ -102,12 +101,12 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(Menu resources) {
|
public void saveMenu(Menu resources) {
|
||||||
if (menuMapper.findByTitle(resources.getTitle()) != null) {
|
if (menuMapper.getMenuByTitle(resources.getTitle()) != null) {
|
||||||
throw new EntityExistException(Menu.class, "title", resources.getTitle());
|
throw new EntityExistException(Menu.class, "title", resources.getTitle());
|
||||||
}
|
}
|
||||||
if (StringUtil.isNotBlank(resources.getComponentName())) {
|
if (StringUtil.isNotBlank(resources.getComponentName())) {
|
||||||
if (menuMapper.findByComponentName(resources.getComponentName()) != null) {
|
if (menuMapper.getMenuByComponentName(resources.getComponentName()) != null) {
|
||||||
throw new EntityExistException(Menu.class, "componentName", resources.getComponentName());
|
throw new EntityExistException(Menu.class, "componentName", resources.getComponentName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,8 +114,8 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
resources.setPid(null);
|
resources.setPid(null);
|
||||||
}
|
}
|
||||||
if (resources.getIFrame()) {
|
if (resources.getIFrame()) {
|
||||||
if (!(resources.getPath().toLowerCase().startsWith(HTTP_PRE) || resources.getPath().toLowerCase().startsWith(HTTPS_PRE))) {
|
if (!(resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTP) || resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTPS))) {
|
||||||
throw new BadRequestException(BAD_REQUEST);
|
throw new BadRequestException(TransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
save(resources);
|
save(resources);
|
||||||
@@ -128,17 +127,17 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(Menu resources) {
|
public void updateMenuById(Menu resources) {
|
||||||
if (resources.getId().equals(resources.getPid())) {
|
if (resources.getId().equals(resources.getPid())) {
|
||||||
throw new BadRequestException("上级不能为自己");
|
throw new BadRequestException("上级不能为自己");
|
||||||
}
|
}
|
||||||
Menu menu = getById(resources.getId());
|
Menu menu = getById(resources.getId());
|
||||||
if (resources.getIFrame()) {
|
if (resources.getIFrame()) {
|
||||||
if (!(resources.getPath().toLowerCase().startsWith(HTTP_PRE) || resources.getPath().toLowerCase().startsWith(HTTPS_PRE))) {
|
if (!(resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTP) || resources.getPath().toLowerCase().startsWith(TransferProtocolConst.PREFIX_HTTPS))) {
|
||||||
throw new BadRequestException(BAD_REQUEST);
|
throw new BadRequestException(TransferProtocolConst.PREFIX_HTTPS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Menu menu1 = menuMapper.findByTitle(resources.getTitle());
|
Menu menu1 = menuMapper.getMenuByTitle(resources.getTitle());
|
||||||
|
|
||||||
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
|
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
|
||||||
throw new EntityExistException(Menu.class, "title", resources.getTitle());
|
throw new EntityExistException(Menu.class, "title", resources.getTitle());
|
||||||
@@ -153,7 +152,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
Long newPid = resources.getPid();
|
Long newPid = resources.getPid();
|
||||||
|
|
||||||
if (StringUtil.isNotBlank(resources.getComponentName())) {
|
if (StringUtil.isNotBlank(resources.getComponentName())) {
|
||||||
menu1 = menuMapper.findByComponentName(resources.getComponentName());
|
menu1 = menuMapper.getMenuByComponentName(resources.getComponentName());
|
||||||
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
|
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
|
||||||
throw new EntityExistException(Menu.class, "componentName", resources.getComponentName());
|
throw new EntityExistException(Menu.class, "componentName", resources.getComponentName());
|
||||||
}
|
}
|
||||||
@@ -179,12 +178,12 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Menu> getChildMenus(List<Menu> menuList, Set<Menu> menuSet) {
|
public Set<Menu> selectChildMenus(List<Menu> menuList, Set<Menu> menuSet) {
|
||||||
for (Menu menu : menuList) {
|
for (Menu menu : menuList) {
|
||||||
menuSet.add(menu);
|
menuSet.add(menu);
|
||||||
List<Menu> menus = menuMapper.findByPidOrderByMenuSort(menu.getId());
|
List<Menu> menus = menuMapper.selectMenuByPidOrderByMenuSort(menu.getId());
|
||||||
if (CollUtil.isNotEmpty(menus)) {
|
if (CollUtil.isNotEmpty(menus)) {
|
||||||
getChildMenus(menus, menuSet);
|
selectChildMenus(menus, menuSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return menuSet;
|
return menuSet;
|
||||||
@@ -192,7 +191,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<Menu> menuSet) {
|
public void deleteMenuByIds(Set<Menu> menuSet) {
|
||||||
for (Menu menu : menuSet) {
|
for (Menu menu : menuSet) {
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
delCaches(menu.getId());
|
delCaches(menu.getId());
|
||||||
@@ -203,24 +202,24 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Menu> getMenus(Long pid) {
|
public List<Menu> selectMenuByPid(Long pid) {
|
||||||
List<Menu> menus;
|
List<Menu> menus;
|
||||||
if (pid != null && !pid.equals(0L)) {
|
if (pid != null && !pid.equals(0L)) {
|
||||||
menus = menuMapper.findByPidOrderByMenuSort(pid);
|
menus = menuMapper.selectMenuByPidOrderByMenuSort(pid);
|
||||||
} else {
|
} else {
|
||||||
menus = menuMapper.findByPidIsNullOrderByMenuSort();
|
menus = menuMapper.selectMenuByPidIsNullOrderByMenuSort();
|
||||||
}
|
}
|
||||||
return menus;
|
return menus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Menu> getSuperior(Menu menu, List<Menu> menus) {
|
public List<Menu> selectSuperiorMenu(Menu menu, List<Menu> menus) {
|
||||||
if (menu.getPid() == null) {
|
if (menu.getPid() == null) {
|
||||||
menus.addAll(menuMapper.findByPidIsNullOrderByMenuSort());
|
menus.addAll(menuMapper.selectMenuByPidIsNullOrderByMenuSort());
|
||||||
return menus;
|
return menus;
|
||||||
}
|
}
|
||||||
menus.addAll(menuMapper.findByPidOrderByMenuSort(menu.getPid()));
|
menus.addAll(menuMapper.selectMenuByPidOrderByMenuSort(menu.getPid()));
|
||||||
return getSuperior(findById(menu.getPid()), menus);
|
return selectSuperiorMenu(getMenuById(menu.getPid()), menus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -292,7 +291,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<Menu> menus, HttpServletResponse response) throws IOException {
|
public void downloadExcel(List<Menu> menus, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (Menu menu : menus) {
|
for (Menu menu : menus) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
@@ -310,7 +309,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
|
|
||||||
private void updateSubCnt(Long menuId) {
|
private void updateSubCnt(Long menuId) {
|
||||||
if (menuId != null) {
|
if (menuId != null) {
|
||||||
int count = menuMapper.countByPid(menuId);
|
int count = menuMapper.getMenuCountByPid(menuId);
|
||||||
menuMapper.updateSubCntById(count, menuId);
|
menuMapper.updateSubCntById(count, menuId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,12 +320,12 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
* @param id 菜单ID
|
* @param id 菜单ID
|
||||||
*/
|
*/
|
||||||
public void delCaches(Long id) {
|
public void delCaches(Long id) {
|
||||||
List<User> users = userMapper.findByMenuId(id);
|
List<User> users = userMapper.selectUserByMenuId(id);
|
||||||
redisUtil.del(CacheKey.MENU_ID + id);
|
redisUtil.del(SystemRedisKey.MENU_ID + id);
|
||||||
redisUtil.delByKeys(CacheKey.MENU_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|
redisUtil.delByKeys(SystemRedisKey.MENU_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||||
// 清除 Role 缓存
|
// 清除 Role 缓存
|
||||||
List<Role> roles = roleService.findByMenuId(id);
|
List<Role> roles = roleService.selectRoleByMenuId(id);
|
||||||
redisUtil.delByKeys(CacheKey.ROLE_ID, roles.stream().map(Role::getId).collect(Collectors.toSet()));
|
redisUtil.delByKeys(SystemRedisKey.ROLE_ID, roles.stream().map(Role::getId).collect(Collectors.toSet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
+8
-7
@@ -1,9 +1,9 @@
|
|||||||
package cn.odboy.modules.system.service.impl;
|
package cn.odboy.application.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.date.BetweenFormatter.Level;
|
import cn.hutool.core.date.BetweenFormatter.Level;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.odboy.application.system.service.MonitorService;
|
||||||
import cn.odboy.constant.SystemConstant;
|
import cn.odboy.constant.SystemConstant;
|
||||||
import cn.odboy.modules.system.service.MonitorService;
|
|
||||||
import cn.odboy.util.FileUtil;
|
import cn.odboy.util.FileUtil;
|
||||||
import cn.odboy.util.StringUtil;
|
import cn.odboy.util.StringUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -29,7 +29,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
private final DecimalFormat df = new DecimalFormat("0.00");
|
private final DecimalFormat df = new DecimalFormat("0.00");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getServers() {
|
public Map<String, Object> getServerInfo() {
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>(8);
|
Map<String, Object> resultMap = new LinkedHashMap<>(8);
|
||||||
try {
|
try {
|
||||||
SystemInfo si = new SystemInfo();
|
SystemInfo si = new SystemInfo();
|
||||||
@@ -142,7 +142,8 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
long time = 300;
|
long time = 300;
|
||||||
Util.sleep(time);
|
Util.sleep(time);
|
||||||
long[] ticks = processor.getSystemCpuLoadTicks();
|
long[] ticks = processor.getSystemCpuLoadTicks();
|
||||||
while (Arrays.toString(prevTicks).equals(Arrays.toString(ticks)) && time < 1000) {
|
long minCpuLoadTick = 1000;
|
||||||
|
while (Arrays.toString(prevTicks).equals(Arrays.toString(ticks)) && time < minCpuLoadTick) {
|
||||||
time += 25;
|
time += 25;
|
||||||
Util.sleep(25);
|
Util.sleep(25);
|
||||||
ticks = processor.getSystemCpuLoadTicks();
|
ticks = processor.getSystemCpuLoadTicks();
|
||||||
@@ -151,11 +152,11 @@ public class MonitorServiceImpl implements MonitorService {
|
|||||||
long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];
|
long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];
|
||||||
long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
|
long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
|
||||||
long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
|
long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
|
||||||
long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
|
long ioWait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
|
||||||
long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];
|
long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];
|
||||||
long softirq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
|
long softIrq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
|
||||||
long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];
|
long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];
|
||||||
long totalCpu = user + nice + sys + idle + iowait + irq + softirq + steal;
|
long totalCpu = user + nice + sys + idle + ioWait + irq + softIrq + steal;
|
||||||
cpuInfo.put("used", df.format(100d * user / totalCpu + 100d * sys / totalCpu));
|
cpuInfo.put("used", df.format(100d * user / totalCpu + 100d * sys / totalCpu));
|
||||||
cpuInfo.put("idle", df.format(100d * idle / totalCpu));
|
cpuInfo.put("idle", df.format(100d * idle / totalCpu));
|
||||||
return cpuInfo;
|
return cpuInfo;
|
||||||
+48
-48
@@ -1,9 +1,15 @@
|
|||||||
package cn.odboy.modules.system.service.impl;
|
package cn.odboy.application.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.odboy.application.core.service.UserCacheService;
|
||||||
|
import cn.odboy.application.system.mapper.RoleDeptMapper;
|
||||||
|
import cn.odboy.application.system.mapper.RoleMapper;
|
||||||
|
import cn.odboy.application.system.mapper.RoleMenuMapper;
|
||||||
|
import cn.odboy.application.system.mapper.UserMapper;
|
||||||
|
import cn.odboy.application.system.service.RoleService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.constant.CacheKey;
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.exception.EntityExistException;
|
import cn.odboy.exception.EntityExistException;
|
||||||
import cn.odboy.model.system.domain.Menu;
|
import cn.odboy.model.system.domain.Menu;
|
||||||
@@ -11,12 +17,6 @@ import cn.odboy.model.system.domain.Role;
|
|||||||
import cn.odboy.model.system.domain.User;
|
import cn.odboy.model.system.domain.User;
|
||||||
import cn.odboy.model.system.dto.AuthorityDto;
|
import cn.odboy.model.system.dto.AuthorityDto;
|
||||||
import cn.odboy.model.system.dto.RoleQueryCriteria;
|
import cn.odboy.model.system.dto.RoleQueryCriteria;
|
||||||
import cn.odboy.modules.security.service.UserCacheService;
|
|
||||||
import cn.odboy.modules.system.mapper.RoleDeptMapper;
|
|
||||||
import cn.odboy.modules.system.mapper.RoleMapper;
|
|
||||||
import cn.odboy.modules.system.mapper.RoleMenuMapper;
|
|
||||||
import cn.odboy.modules.system.mapper.UserMapper;
|
|
||||||
import cn.odboy.modules.system.service.RoleService;
|
|
||||||
import cn.odboy.util.FileUtil;
|
import cn.odboy.util.FileUtil;
|
||||||
import cn.odboy.util.PageUtil;
|
import cn.odboy.util.PageUtil;
|
||||||
import cn.odboy.util.RedisUtil;
|
import cn.odboy.util.RedisUtil;
|
||||||
@@ -44,26 +44,26 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Role> queryAll() {
|
public List<Role> selectRole() {
|
||||||
return roleMapper.findAllRoles();
|
return roleMapper.selectRole();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Role> queryAll(RoleQueryCriteria criteria) {
|
public List<Role> selectRoleByCriteria(RoleQueryCriteria criteria) {
|
||||||
return roleMapper.findRoles(criteria);
|
return roleMapper.selectRoleByCriteria(criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<Role> queryAll(RoleQueryCriteria criteria, Page<Object> page) {
|
public PageResult<Role> queryRolePage(RoleQueryCriteria criteria, Page<Object> page) {
|
||||||
criteria.setOffset(page.offset());
|
criteria.setOffset(page.offset());
|
||||||
List<Role> roles = roleMapper.findRoles(criteria);
|
List<Role> roles = roleMapper.selectRoleByCriteria(criteria);
|
||||||
Long total = roleMapper.countRoles(criteria);
|
Long total = roleMapper.getRoleCountByCriteria(criteria);
|
||||||
return PageUtil.toPage(roles, total);
|
return PageUtil.toPage(roles, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Role findById(long id) {
|
public Role getRoleById(long id) {
|
||||||
String key = CacheKey.ROLE_ID + id;
|
String key = SystemRedisKey.ROLE_ID + id;
|
||||||
Role role = redisUtil.get(key, Role.class);
|
Role role = redisUtil.get(key, Role.class);
|
||||||
if (role == null) {
|
if (role == null) {
|
||||||
role = roleMapper.selectById(id);
|
role = roleMapper.selectById(id);
|
||||||
@@ -74,8 +74,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(Role resources) {
|
public void createRole(Role resources) {
|
||||||
if (roleMapper.findRoleByName(resources.getName()) != null) {
|
if (roleMapper.getRoleByName(resources.getName()) != null) {
|
||||||
throw new EntityExistException(Role.class, "username", resources.getName());
|
throw new EntityExistException(Role.class, "username", resources.getName());
|
||||||
}
|
}
|
||||||
save(resources);
|
save(resources);
|
||||||
@@ -87,9 +87,9 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(Role resources) {
|
public void updateRoleById(Role resources) {
|
||||||
Role role = getById(resources.getId());
|
Role role = getById(resources.getId());
|
||||||
Role role1 = roleMapper.findRoleByName(resources.getName());
|
Role role1 = roleMapper.getRoleByName(resources.getName());
|
||||||
if (role1 != null && !role1.getId().equals(role.getId())) {
|
if (role1 != null && !role1.getId().equals(role.getId())) {
|
||||||
throw new EntityExistException(Role.class, "username", resources.getName());
|
throw new EntityExistException(Role.class, "username", resources.getName());
|
||||||
}
|
}
|
||||||
@@ -111,8 +111,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMenu(Role role) {
|
public void updateMenuById(Role role) {
|
||||||
List<User> users = userMapper.findByRoleId(role.getId());
|
List<User> users = userMapper.selectUserByRoleId(role.getId());
|
||||||
// 更新菜单
|
// 更新菜单
|
||||||
roleMenuMapper.deleteByRoleId(role.getId());
|
roleMenuMapper.deleteByRoleId(role.getId());
|
||||||
// 判断是否为空
|
// 判断是否为空
|
||||||
@@ -125,7 +125,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<Long> ids) {
|
public void deleteRoleByIds(Set<Long> ids) {
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
// 更新相关缓存
|
// 更新相关缓存
|
||||||
delCaches(id, null);
|
delCaches(id, null);
|
||||||
@@ -137,33 +137,33 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Role> findByUsersId(Long userId) {
|
public List<Role> selectRoleByUsersId(Long userId) {
|
||||||
String key = CacheKey.ROLE_USER + userId;
|
String key = SystemRedisKey.ROLE_USER + userId;
|
||||||
List<Role> roles = redisUtil.getList(key, Role.class);
|
List<Role> roles = redisUtil.getList(key, Role.class);
|
||||||
if (CollUtil.isEmpty(roles)) {
|
if (CollUtil.isEmpty(roles)) {
|
||||||
roles = roleMapper.findRolesByUserId(userId);
|
roles = roleMapper.selectRoleByUserId(userId);
|
||||||
redisUtil.set(key, roles, 1, TimeUnit.DAYS);
|
redisUtil.set(key, roles, 1, TimeUnit.DAYS);
|
||||||
}
|
}
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer findByRoles(Set<Role> roles) {
|
public Integer getDeptLevelByRoles(Set<Role> roles) {
|
||||||
if (CollUtil.isEmpty(roles)) {
|
if (CollUtil.isEmpty(roles)) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
Set<Role> roleSet = new HashSet<>();
|
Set<Role> roleSet = new HashSet<>();
|
||||||
for (Role role : roles) {
|
for (Role role : roles) {
|
||||||
roleSet.add(findById(role.getId()));
|
roleSet.add(getRoleById(role.getId()));
|
||||||
}
|
}
|
||||||
return Collections.min(roleSet.stream().map(Role::getLevel).collect(Collectors.toList()));
|
return Collections.min(roleSet.stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AuthorityDto> buildPermissions(User user) {
|
public List<AuthorityDto> buildPermissions(User user) {
|
||||||
String key = CacheKey.ROLE_AUTH + user.getId();
|
String key = SystemRedisKey.ROLE_AUTH + user.getId();
|
||||||
List<AuthorityDto> authorityDtos = redisUtil.getList(key, AuthorityDto.class);
|
List<AuthorityDto> authorityList = redisUtil.getList(key, AuthorityDto.class);
|
||||||
if (CollUtil.isEmpty(authorityDtos)) {
|
if (CollUtil.isEmpty(authorityList)) {
|
||||||
Set<String> permissions = new HashSet<>();
|
Set<String> permissions = new HashSet<>();
|
||||||
// 如果是管理员直接返回
|
// 如果是管理员直接返回
|
||||||
if (user.getIsAdmin()) {
|
if (user.getIsAdmin()) {
|
||||||
@@ -171,19 +171,19 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||||||
return permissions.stream().map(AuthorityDto::new)
|
return permissions.stream().map(AuthorityDto::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
List<Role> roles = roleMapper.findRolesByUserId(user.getId());
|
List<Role> roles = roleMapper.selectRoleByUserId(user.getId());
|
||||||
permissions = roles.stream().flatMap(role -> role.getMenus().stream())
|
permissions = roles.stream().flatMap(role -> role.getMenus().stream())
|
||||||
.map(Menu::getPermission)
|
.map(Menu::getPermission)
|
||||||
.filter(StringUtil::isNotBlank).collect(Collectors.toSet());
|
.filter(StringUtil::isNotBlank).collect(Collectors.toSet());
|
||||||
authorityDtos = permissions.stream().map(AuthorityDto::new)
|
authorityList = permissions.stream().map(AuthorityDto::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
redisUtil.set(key, authorityDtos, 1, TimeUnit.HOURS);
|
redisUtil.set(key, authorityList, 1, TimeUnit.HOURS);
|
||||||
}
|
}
|
||||||
return authorityDtos;
|
return authorityList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<Role> roles, HttpServletResponse response) throws IOException {
|
public void downloadExcel(List<Role> roles, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (Role role : roles) {
|
for (Role role : roles) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
@@ -197,15 +197,15 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void verification(Set<Long> ids) {
|
public void verifyBindRelationByIds(Set<Long> ids) {
|
||||||
if (userMapper.countByRoles(ids) > 0) {
|
if (userMapper.getCountByRoles(ids) > 0) {
|
||||||
throw new BadRequestException("所选角色存在用户关联,请解除关联再试!");
|
throw new BadRequestException("所选角色存在用户关联,请解除关联再试!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Role> findByMenuId(Long menuId) {
|
public List<Role> selectRoleByMenuId(Long menuId) {
|
||||||
return roleMapper.findRolesByMenuId(menuId);
|
return roleMapper.selectRoleByMenuId(menuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,15 +214,15 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||||||
* @param id /
|
* @param id /
|
||||||
*/
|
*/
|
||||||
public void delCaches(Long id, List<User> users) {
|
public void delCaches(Long id, List<User> users) {
|
||||||
users = CollectionUtil.isEmpty(users) ? userMapper.findByRoleId(id) : users;
|
users = CollectionUtil.isEmpty(users) ? userMapper.selectUserByRoleId(id) : users;
|
||||||
if (CollectionUtil.isNotEmpty(users)) {
|
if (CollectionUtil.isNotEmpty(users)) {
|
||||||
users.forEach(item -> userCacheService.cleanUserCache(item.getUsername()));
|
users.forEach(item -> userCacheService.cleanUserCacheByUsername(item.getUsername()));
|
||||||
Set<Long> userIds = users.stream().map(User::getId).collect(Collectors.toSet());
|
Set<Long> userIds = users.stream().map(User::getId).collect(Collectors.toSet());
|
||||||
redisUtil.delByKeys(CacheKey.DATA_USER, userIds);
|
redisUtil.delByKeys(SystemRedisKey.DATA_USER, userIds);
|
||||||
redisUtil.delByKeys(CacheKey.MENU_USER, userIds);
|
redisUtil.delByKeys(SystemRedisKey.MENU_USER, userIds);
|
||||||
redisUtil.delByKeys(CacheKey.ROLE_AUTH, userIds);
|
redisUtil.delByKeys(SystemRedisKey.ROLE_AUTH, userIds);
|
||||||
redisUtil.delByKeys(CacheKey.ROLE_USER, userIds);
|
redisUtil.delByKeys(SystemRedisKey.ROLE_USER, userIds);
|
||||||
}
|
}
|
||||||
redisUtil.del(CacheKey.ROLE_ID + id);
|
redisUtil.del(SystemRedisKey.ROLE_ID + id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+50
-55
@@ -1,19 +1,19 @@
|
|||||||
package cn.odboy.modules.system.service.impl;
|
package cn.odboy.application.system.service.impl;
|
||||||
|
|
||||||
|
import cn.odboy.application.core.service.OnlineUserService;
|
||||||
|
import cn.odboy.application.core.service.UserCacheService;
|
||||||
|
import cn.odboy.application.system.mapper.UserJobMapper;
|
||||||
|
import cn.odboy.application.system.mapper.UserMapper;
|
||||||
|
import cn.odboy.application.system.mapper.UserRoleMapper;
|
||||||
|
import cn.odboy.application.system.service.UserService;
|
||||||
import cn.odboy.base.PageResult;
|
import cn.odboy.base.PageResult;
|
||||||
import cn.odboy.constant.CacheKey;
|
import cn.odboy.constant.SystemRedisKey;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.exception.EntityExistException;
|
import cn.odboy.exception.EntityExistException;
|
||||||
import cn.odboy.model.system.domain.Job;
|
import cn.odboy.model.system.domain.Job;
|
||||||
import cn.odboy.model.system.domain.Role;
|
import cn.odboy.model.system.domain.Role;
|
||||||
import cn.odboy.model.system.domain.User;
|
import cn.odboy.model.system.domain.User;
|
||||||
import cn.odboy.model.system.dto.UserQueryCriteria;
|
import cn.odboy.model.system.dto.UserQueryCriteria;
|
||||||
import cn.odboy.modules.security.service.OnlineUserService;
|
|
||||||
import cn.odboy.modules.security.service.UserCacheService;
|
|
||||||
import cn.odboy.modules.system.mapper.UserJobMapper;
|
|
||||||
import cn.odboy.modules.system.mapper.UserMapper;
|
|
||||||
import cn.odboy.modules.system.mapper.UserRoleMapper;
|
|
||||||
import cn.odboy.modules.system.service.UserService;
|
|
||||||
import cn.odboy.properties.FileProperties;
|
import cn.odboy.properties.FileProperties;
|
||||||
import cn.odboy.util.*;
|
import cn.odboy.util.*;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@@ -43,22 +43,22 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
private final OnlineUserService onlineUserService;
|
private final OnlineUserService onlineUserService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<User> queryAll(UserQueryCriteria criteria, Page<Object> page) {
|
public PageResult<User> queryUserPage(UserQueryCriteria criteria, Page<Object> page) {
|
||||||
criteria.setOffset(page.offset());
|
criteria.setOffset(page.offset());
|
||||||
List<User> users = userMapper.findAll(criteria, PageUtil.getCount(userMapper)).getRecords();
|
List<User> users = userMapper.queryUserPage(criteria, PageUtil.getCount(userMapper)).getRecords();
|
||||||
Long total = userMapper.countAll(criteria);
|
Long total = userMapper.getUserCountByCriteria(criteria);
|
||||||
return PageUtil.toPage(users, total);
|
return PageUtil.toPage(users, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<User> queryAll(UserQueryCriteria criteria) {
|
public List<User> selectUserByCriteria(UserQueryCriteria criteria) {
|
||||||
return userMapper.findAll(criteria, PageUtil.getCount(userMapper)).getRecords();
|
return userMapper.queryUserPage(criteria, PageUtil.getCount(userMapper)).getRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public User findById(long id) {
|
public User getUserById(long id) {
|
||||||
String key = CacheKey.USER_ID + id;
|
String key = SystemRedisKey.USER_ID + id;
|
||||||
User user = redisUtil.get(key, User.class);
|
User user = redisUtil.get(key, User.class);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
user = getById(id);
|
user = getById(id);
|
||||||
@@ -69,15 +69,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(User resources) {
|
public void saveUser(User resources) {
|
||||||
resources.setDeptId(resources.getDept().getId());
|
resources.setDeptId(resources.getDept().getId());
|
||||||
if (userMapper.findByUsername(resources.getUsername()) != null) {
|
if (userMapper.getUserByUsername(resources.getUsername()) != null) {
|
||||||
throw new EntityExistException(User.class, "username", resources.getUsername());
|
throw new EntityExistException(User.class, "username", resources.getUsername());
|
||||||
}
|
}
|
||||||
if (userMapper.findByEmail(resources.getEmail()) != null) {
|
if (userMapper.getUserByEmail(resources.getEmail()) != null) {
|
||||||
throw new EntityExistException(User.class, "email", resources.getEmail());
|
throw new EntityExistException(User.class, "email", resources.getEmail());
|
||||||
}
|
}
|
||||||
if (userMapper.findByPhone(resources.getPhone()) != null) {
|
if (userMapper.getUserByPhone(resources.getPhone()) != null) {
|
||||||
throw new EntityExistException(User.class, "phone", resources.getPhone());
|
throw new EntityExistException(User.class, "phone", resources.getPhone());
|
||||||
}
|
}
|
||||||
save(resources);
|
save(resources);
|
||||||
@@ -89,11 +89,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(User resources) throws Exception {
|
public void updateUserById(User resources) {
|
||||||
User user = getById(resources.getId());
|
User user = getById(resources.getId());
|
||||||
User user1 = userMapper.findByUsername(resources.getUsername());
|
User user1 = userMapper.getUserByUsername(resources.getUsername());
|
||||||
User user2 = userMapper.findByEmail(resources.getEmail());
|
User user2 = userMapper.getUserByEmail(resources.getEmail());
|
||||||
User user3 = userMapper.findByPhone(resources.getPhone());
|
User user3 = userMapper.getUserByPhone(resources.getPhone());
|
||||||
if (user1 != null && !user.getId().equals(user1.getId())) {
|
if (user1 != null && !user.getId().equals(user1.getId())) {
|
||||||
throw new EntityExistException(User.class, "username", resources.getUsername());
|
throw new EntityExistException(User.class, "username", resources.getUsername());
|
||||||
}
|
}
|
||||||
@@ -105,18 +105,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
}
|
}
|
||||||
// 如果用户的角色改变
|
// 如果用户的角色改变
|
||||||
if (!resources.getRoles().equals(user.getRoles())) {
|
if (!resources.getRoles().equals(user.getRoles())) {
|
||||||
redisUtil.del(CacheKey.DATA_USER + resources.getId());
|
redisUtil.del(SystemRedisKey.DATA_USER + resources.getId());
|
||||||
redisUtil.del(CacheKey.MENU_USER + resources.getId());
|
redisUtil.del(SystemRedisKey.MENU_USER + resources.getId());
|
||||||
redisUtil.del(CacheKey.ROLE_AUTH + resources.getId());
|
redisUtil.del(SystemRedisKey.ROLE_AUTH + resources.getId());
|
||||||
redisUtil.del(CacheKey.ROLE_USER + resources.getId());
|
redisUtil.del(SystemRedisKey.ROLE_USER + resources.getId());
|
||||||
}
|
}
|
||||||
// 修改部门会影响 数据权限
|
// 修改部门会影响 数据权限
|
||||||
if (!Objects.equals(resources.getDept(), user.getDept())) {
|
if (!Objects.equals(resources.getDept(), user.getDept())) {
|
||||||
redisUtil.del(CacheKey.DATA_USER + resources.getId());
|
redisUtil.del(SystemRedisKey.DATA_USER + resources.getId());
|
||||||
}
|
}
|
||||||
// 如果用户被禁用,则清除用户登录信息
|
// 如果用户被禁用,则清除用户登录信息
|
||||||
if (!resources.getEnabled()) {
|
if (!resources.getEnabled()) {
|
||||||
onlineUserService.kickOutForUsername(resources.getUsername());
|
onlineUserService.kickOutByUsername(resources.getUsername());
|
||||||
}
|
}
|
||||||
user.setDeptId(resources.getDept().getId());
|
user.setDeptId(resources.getDept().getId());
|
||||||
user.setUsername(resources.getUsername());
|
user.setUsername(resources.getUsername());
|
||||||
@@ -141,9 +141,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateCenter(User resources) {
|
public void updateCenterInfoById(User resources) {
|
||||||
User user = getById(resources.getId());
|
User user = getById(resources.getId());
|
||||||
User user1 = userMapper.findByPhone(resources.getPhone());
|
User user1 = userMapper.getUserByPhone(resources.getPhone());
|
||||||
if (user1 != null && !user.getId().equals(user1.getId())) {
|
if (user1 != null && !user.getId().equals(user1.getId())) {
|
||||||
throw new EntityExistException(User.class, "phone", resources.getPhone());
|
throw new EntityExistException(User.class, "phone", resources.getPhone());
|
||||||
}
|
}
|
||||||
@@ -157,13 +157,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<Long> ids) {
|
public void deleteUserByIds(Set<Long> ids) {
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
User user = getById(id);
|
User user = getById(id);
|
||||||
delCaches(user.getId(), user.getUsername());
|
delCaches(user.getId(), user.getUsername());
|
||||||
}
|
}
|
||||||
userMapper.deleteBatchIds(ids);
|
userMapper.deleteByIds(ids);
|
||||||
// 删除用户岗位
|
// 删除用户岗位
|
||||||
userJobMapper.deleteByUserIds(ids);
|
userJobMapper.deleteByUserIds(ids);
|
||||||
// 删除用户角色
|
// 删除用户角色
|
||||||
@@ -171,49 +171,44 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User findByName(String userName) {
|
public User getUserByUsername(String username) {
|
||||||
return userMapper.findByUsername(userName);
|
return userMapper.getUserByUsername(username);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public User getLoginData(String userName) {
|
|
||||||
return userMapper.findByUsername(userName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updatePass(String username, String pass) {
|
public void updatePasswordByUsername(String username, String pass) {
|
||||||
userMapper.updatePass(username, pass, new Date());
|
userMapper.updatePasswordByUsername(username, pass, new Date());
|
||||||
flushCache(username);
|
flushCache(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void resetPwd(Set<Long> ids, String pwd) {
|
public void resetPasswordByIds(Set<Long> ids, String password) {
|
||||||
List<User> users = userMapper.selectBatchIds(ids);
|
List<User> users = userMapper.selectByIds(ids);
|
||||||
// 清除缓存
|
// 清除缓存
|
||||||
users.forEach(user -> {
|
users.forEach(user -> {
|
||||||
// 清除缓存
|
// 清除缓存
|
||||||
flushCache(user.getUsername());
|
flushCache(user.getUsername());
|
||||||
// 强制退出
|
// 强制退出
|
||||||
onlineUserService.kickOutForUsername(user.getUsername());
|
onlineUserService.kickOutByUsername(user.getUsername());
|
||||||
});
|
});
|
||||||
// 重置密码
|
// 重置密码
|
||||||
userMapper.resetPwd(ids, pwd);
|
userMapper.resetPasswordByUserIds(ids, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Map<String, String> updateAvatar(MultipartFile multipartFile) {
|
public Map<String, String> updateAvatarFile(MultipartFile multipartFile) {
|
||||||
// 文件大小验证
|
// 文件大小验证
|
||||||
FileUtil.checkSize(fileProperties.getAvatarMaxSize(), multipartFile.getSize());
|
FileUtil.checkSize(fileProperties.getAvatarMaxSize(), multipartFile.getSize());
|
||||||
// 验证文件上传的格式
|
// 验证文件上传的格式
|
||||||
String image = "gif jpg png jpeg";
|
String image = "gif jpg png jpeg";
|
||||||
String fileType = FileUtil.getExtensionName(multipartFile.getOriginalFilename());
|
String fileType = FileUtil.getSuffix(multipartFile.getOriginalFilename());
|
||||||
if (fileType != null && !image.contains(fileType)) {
|
if (fileType != null && !image.contains(fileType)) {
|
||||||
throw new BadRequestException("文件格式错误!, 仅支持 " + image + " 格式");
|
throw new BadRequestException("文件格式错误!, 仅支持 " + image + " 格式");
|
||||||
}
|
}
|
||||||
User user = userMapper.findByUsername(SecurityUtil.getCurrentUsername());
|
User user = userMapper.getUserByUsername(SecurityUtil.getCurrentUsername());
|
||||||
String oldPath = user.getAvatarPath();
|
String oldPath = user.getAvatarPath();
|
||||||
File file = FileUtil.upload(multipartFile, fileProperties.getPath().getAvatar());
|
File file = FileUtil.upload(multipartFile, fileProperties.getPath().getAvatar());
|
||||||
user.setAvatarPath(Objects.requireNonNull(file).getPath());
|
user.setAvatarPath(Objects.requireNonNull(file).getPath());
|
||||||
@@ -224,20 +219,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
}
|
}
|
||||||
@NotBlank String username = user.getUsername();
|
@NotBlank String username = user.getUsername();
|
||||||
flushCache(username);
|
flushCache(username);
|
||||||
return new HashMap<String, String>(1) {{
|
return new HashMap<>(1) {{
|
||||||
put("avatar", file.getName());
|
put("avatar", file.getName());
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateEmail(String username, String email) {
|
public void updateEmailByUsername(String username, String email) {
|
||||||
userMapper.updateEmail(username, email);
|
userMapper.updateEmailByUsername(username, email);
|
||||||
flushCache(username);
|
flushCache(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<User> users, HttpServletResponse response) throws IOException {
|
public void downloadExcel(List<User> users, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (User user : users) {
|
for (User user : users) {
|
||||||
List<String> roles = user.getRoles().stream().map(Role::getName).collect(Collectors.toList());
|
List<String> roles = user.getRoles().stream().map(Role::getName).collect(Collectors.toList());
|
||||||
@@ -262,7 +257,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
* @param id /
|
* @param id /
|
||||||
*/
|
*/
|
||||||
public void delCaches(Long id, String username) {
|
public void delCaches(Long id, String username) {
|
||||||
redisUtil.del(CacheKey.USER_ID + id);
|
redisUtil.del(SystemRedisKey.USER_ID + id);
|
||||||
flushCache(username);
|
flushCache(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,6 +267,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
* @param username /
|
* @param username /
|
||||||
*/
|
*/
|
||||||
private void flushCache(String username) {
|
private void flushCache(String username) {
|
||||||
userCacheService.cleanUserCache(username);
|
userCacheService.cleanUserCacheByUsername(username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
-5
@@ -1,4 +1,4 @@
|
|||||||
package cn.odboy.modules.system.service.impl;
|
package cn.odboy.application.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
@@ -6,9 +6,9 @@ import cn.hutool.extra.template.Template;
|
|||||||
import cn.hutool.extra.template.TemplateConfig;
|
import cn.hutool.extra.template.TemplateConfig;
|
||||||
import cn.hutool.extra.template.TemplateEngine;
|
import cn.hutool.extra.template.TemplateEngine;
|
||||||
import cn.hutool.extra.template.TemplateUtil;
|
import cn.hutool.extra.template.TemplateUtil;
|
||||||
|
import cn.odboy.application.system.service.VerifyService;
|
||||||
import cn.odboy.exception.BadRequestException;
|
import cn.odboy.exception.BadRequestException;
|
||||||
import cn.odboy.model.tools.dto.EmailDto;
|
import cn.odboy.model.tools.dto.EmailDto;
|
||||||
import cn.odboy.modules.system.service.VerifyService;
|
|
||||||
import cn.odboy.util.RedisUtil;
|
import cn.odboy.util.RedisUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -27,7 +27,7 @@ public class VerifyServiceImpl implements VerifyService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public EmailDto sendEmail(String email, String key) {
|
public EmailDto sendEmailCode(String email, String key) {
|
||||||
EmailDto emailDto;
|
EmailDto emailDto;
|
||||||
String content;
|
String content;
|
||||||
String redisKey = key + email;
|
String redisKey = key + email;
|
||||||
@@ -51,8 +51,8 @@ public class VerifyServiceImpl implements VerifyService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validated(String key, String code) {
|
public void validateEmailCode(String key, String email, String code) {
|
||||||
String value = redisUtil.get(key, String.class);
|
String value = redisUtil.get(key + email, String.class);
|
||||||
if (value == null || !value.equals(code)) {
|
if (value == null || !value.equals(code)) {
|
||||||
throw new BadRequestException("无效验证码");
|
throw new BadRequestException("无效验证码");
|
||||||
} else {
|
} else {
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.Dept;
|
|
||||||
import cn.odboy.model.system.dto.DeptQueryCriteria;
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface DeptMapper extends BaseMapper<Dept> {
|
|
||||||
List<Dept> findDept(@Param("criteria") DeptQueryCriteria criteria);
|
|
||||||
|
|
||||||
List<Dept> findDeptByPid(@Param("pid") Long pid);
|
|
||||||
|
|
||||||
int countDeptByPid(@Param("pid") Long pid);
|
|
||||||
|
|
||||||
List<Dept> findDeptByPidIsNull();
|
|
||||||
|
|
||||||
Set<Dept> findDeptByRoleId(@Param("roleId") Long roleId);
|
|
||||||
|
|
||||||
void updateDeptSubCountById(@Param("count") Integer count, @Param("id") Long id);
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.Menu;
|
|
||||||
import cn.odboy.model.system.dto.MenuQueryCriteria;
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface MenuMapper extends BaseMapper<Menu> {
|
|
||||||
|
|
||||||
List<Menu> findAll(@Param("criteria") MenuQueryCriteria criteria);
|
|
||||||
|
|
||||||
LinkedHashSet<Menu> findByRoleIdsAndTypeNot(@Param("roleIds") Set<Long> roleIds, @Param("type") Integer type);
|
|
||||||
|
|
||||||
List<Menu> findByPidIsNullOrderByMenuSort();
|
|
||||||
|
|
||||||
List<Menu> findByPidOrderByMenuSort(@Param("pid") Long pid);
|
|
||||||
|
|
||||||
@Select("SELECT menu_id id FROM sys_menu WHERE title = #{title}")
|
|
||||||
Menu findByTitle(@Param("title") String title);
|
|
||||||
|
|
||||||
@Select("SELECT menu_id id FROM sys_menu WHERE name = #{name}")
|
|
||||||
Menu findByComponentName(@Param("name") String name);
|
|
||||||
|
|
||||||
@Select("SELECT count(*) FROM sys_menu WHERE pid = #{pid}")
|
|
||||||
int countByPid(@Param("pid") Long pid);
|
|
||||||
|
|
||||||
@Select("update sys_menu set sub_count = #{count} where menu_id = #{menuId} ")
|
|
||||||
void updateSubCntById(@Param("count") int count, @Param("menuId") Long menuId);
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.Role;
|
|
||||||
import cn.odboy.model.system.dto.RoleQueryCriteria;
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface RoleMapper extends BaseMapper<Role> {
|
|
||||||
List<Role> findAllRoles();
|
|
||||||
|
|
||||||
Long countRoles(@Param("criteria") RoleQueryCriteria criteria);
|
|
||||||
|
|
||||||
List<Role> findRoles(@Param("criteria") RoleQueryCriteria criteria);
|
|
||||||
|
|
||||||
Role findRoleById(@Param("roleId") Long roleId);
|
|
||||||
|
|
||||||
Role findRoleByName(@Param("name") String name);
|
|
||||||
|
|
||||||
List<Role> findRolesByUserId(@Param("userId") Long userId);
|
|
||||||
|
|
||||||
int countRolesByDeptIds(@Param("deptIds") Set<Long> deptIds);
|
|
||||||
|
|
||||||
List<Role> findRolesByMenuId(@Param("menuId") Long menuId);
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package cn.odboy.modules.system.mapper;
|
|
||||||
|
|
||||||
import cn.odboy.model.system.domain.User;
|
|
||||||
import cn.odboy.model.system.dto.UserQueryCriteria;
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface UserMapper extends BaseMapper<User> {
|
|
||||||
|
|
||||||
Long countAll(@Param("criteria") UserQueryCriteria criteria);
|
|
||||||
|
|
||||||
IPage<User> findAll(@Param("criteria") UserQueryCriteria criteria, Page<Object> page);
|
|
||||||
|
|
||||||
User findByUsername(@Param("username") String username);
|
|
||||||
|
|
||||||
User findByEmail(@Param("email") String email);
|
|
||||||
|
|
||||||
User findByPhone(@Param("phone") String phone);
|
|
||||||
|
|
||||||
@Select("update sys_user set password = #{password} , pwd_reset_time = #{lastPasswordResetTime} where username = #{username}")
|
|
||||||
void updatePass(@Param("username") String username, @Param("password") String password, @Param("lastPasswordResetTime") Date lastPasswordResetTime);
|
|
||||||
|
|
||||||
@Select("update sys_user set email = #{email} where username = #{username}")
|
|
||||||
void updateEmail(@Param("username") String username, @Param("email") String email);
|
|
||||||
|
|
||||||
List<User> findByRoleId(@Param("roleId") Long roleId);
|
|
||||||
|
|
||||||
List<User> findByRoleDeptId(@Param("deptId") Long deptId);
|
|
||||||
|
|
||||||
List<User> findByMenuId(@Param("menuId") Long menuId);
|
|
||||||
|
|
||||||
int countByJobs(@Param("jobIds") Set<Long> jobIds);
|
|
||||||
|
|
||||||
int countByDepts(@Param("deptIds") Set<Long> deptIds);
|
|
||||||
|
|
||||||
int countByRoles(@Param("roleIds") Set<Long> roleIds);
|
|
||||||
|
|
||||||
void resetPwd(@Param("userIds") Set<Long> userIds, @Param("pwd") String pwd);
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user