fix():格式规范修改
parent
44a9e29996
commit
782ec652ed
|
@ -25,17 +25,22 @@ import org.springframework.stereotype.Component;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SysLoginService {
|
public class SysLoginService {
|
||||||
@Autowired
|
|
||||||
private RemoteUserService remoteUserService;
|
private final RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
private final SysPasswordService passwordService;
|
||||||
|
|
||||||
|
private final SysRecordLogService recordLogService;
|
||||||
|
|
||||||
|
private final RedisService redisService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysPasswordService passwordService;
|
public SysLoginService(RemoteUserService remoteUserService, SysPasswordService passwordService, SysRecordLogService recordLogService, RedisService redisService) {
|
||||||
|
this.remoteUserService = remoteUserService;
|
||||||
@Autowired
|
this.passwordService = passwordService;
|
||||||
private SysRecordLogService recordLogService;
|
this.recordLogService = recordLogService;
|
||||||
|
this.redisService = redisService;
|
||||||
@Autowired
|
}
|
||||||
private RedisService redisService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
|
|
|
@ -18,15 +18,15 @@ import java.util.concurrent.TimeUnit;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SysPasswordService {
|
public class SysPasswordService {
|
||||||
@Autowired
|
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
private int maxRetryCount = CacheConstants.PASSWORD_MAX_RETRY_COUNT;
|
private SysRecordLogService recordLogService;
|
||||||
|
|
||||||
private Long lockTime = CacheConstants.PASSWORD_LOCK_TIME;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysRecordLogService recordLogService;
|
public SysPasswordService(RedisService redisService, SysRecordLogService recordLogService) {
|
||||||
|
this.redisService = redisService;
|
||||||
|
this.recordLogService = recordLogService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录账户密码错误次数缓存键名
|
* 登录账户密码错误次数缓存键名
|
||||||
|
@ -48,8 +48,10 @@ public class SysPasswordService {
|
||||||
retryCount = 0;
|
retryCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retryCount >= Integer.valueOf(maxRetryCount).intValue()) {
|
int passwordMaxRetryCount = CacheConstants.PASSWORD_MAX_RETRY_COUNT;
|
||||||
String errMsg = String.format("密码输入错误%s次,帐户锁定%s分钟", maxRetryCount, lockTime);
|
Long lockTime = CacheConstants.PASSWORD_LOCK_TIME;
|
||||||
|
if (retryCount >= passwordMaxRetryCount) {
|
||||||
|
String errMsg = String.format("密码输入错误%s次,帐户锁定%s分钟", passwordMaxRetryCount, lockTime);
|
||||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, errMsg);
|
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, errMsg);
|
||||||
throw new ServiceException(errMsg);
|
throw new ServiceException(errMsg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,12 @@ import org.springframework.stereotype.Component;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SysRecordLogService {
|
public class SysRecordLogService {
|
||||||
|
private final RemoteLogService remoteLogService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RemoteLogService remoteLogService;
|
public SysRecordLogService(RemoteLogService remoteLogService) {
|
||||||
|
this.remoteLogService = remoteLogService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 记录登录信息
|
* 记录登录信息
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义导出Excel数据注解
|
* 自定义导出Excel数据注解
|
||||||
|
@ -51,7 +52,7 @@ public @interface Excel {
|
||||||
/**
|
/**
|
||||||
* BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
|
* BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
|
||||||
*/
|
*/
|
||||||
int roundingMode () default BigDecimal.ROUND_HALF_EVEN;
|
RoundingMode roundingMode () default RoundingMode.HALF_UP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出时在excel中每个列的高度
|
* 导出时在excel中每个列的高度
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
package com.muyu.common.core.constant;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 任务调度通用常量
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public class ScheduleConstants {
|
|
||||||
public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行目标key
|
|
||||||
*/
|
|
||||||
public static final String TASK_PROPERTIES = "TASK_PROPERTIES";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认
|
|
||||||
*/
|
|
||||||
public static final String MISFIRE_DEFAULT = "0";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 立即触发执行
|
|
||||||
*/
|
|
||||||
public static final String MISFIRE_IGNORE_MISFIRES = "1";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 触发一次执行
|
|
||||||
*/
|
|
||||||
public static final String MISFIRE_FIRE_AND_PROCEED = "2";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 不触发立即执行
|
|
||||||
*/
|
|
||||||
public static final String MISFIRE_DO_NOTHING = "3";
|
|
||||||
|
|
||||||
public enum Status {
|
|
||||||
/**
|
|
||||||
* 正常
|
|
||||||
*/
|
|
||||||
NORMAL("0"),
|
|
||||||
/**
|
|
||||||
* 暂停
|
|
||||||
*/
|
|
||||||
PAUSE("1");
|
|
||||||
|
|
||||||
private String value;
|
|
||||||
|
|
||||||
private Status (String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue () {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -35,7 +35,7 @@ public class SecurityContextHolder {
|
||||||
public static Map<String, Object> getLocalMap () {
|
public static Map<String, Object> getLocalMap () {
|
||||||
Map<String, Object> map = THREAD_LOCAL.get();
|
Map<String, Object> map = THREAD_LOCAL.get();
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
map = new ConcurrentHashMap<String, Object>();
|
map = new ConcurrentHashMap<>();
|
||||||
THREAD_LOCAL.set(map);
|
THREAD_LOCAL.set(map);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.muyu.common.core.exception;
|
package com.muyu.common.core.exception;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局异常
|
* 全局异常
|
||||||
*
|
*
|
||||||
|
@ -16,7 +19,7 @@ public class GlobalException extends RuntimeException {
|
||||||
/**
|
/**
|
||||||
* 错误明细,内部调试错误
|
* 错误明细,内部调试错误
|
||||||
* <p>
|
* <p>
|
||||||
* 和 {@link CommonResult#getDetailMessage()} 一致的设计
|
* 和 {@link Result#getMsg()} ()} 一致的设计
|
||||||
*/
|
*/
|
||||||
private String detailMessage;
|
private String detailMessage;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.muyu.common.core.exception;
|
package com.muyu.common.core.exception;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务异常
|
* 业务异常
|
||||||
*
|
*
|
||||||
|
@ -21,7 +23,7 @@ public final class ServiceException extends RuntimeException {
|
||||||
/**
|
/**
|
||||||
* 错误明细,内部调试错误
|
* 错误明细,内部调试错误
|
||||||
* <p>
|
* <p>
|
||||||
* 和 {@link CommonResult#getDetailMessage()} 一致的设计
|
* 和 {@link Result#getMsg()} 一致的设计
|
||||||
*/
|
*/
|
||||||
private String detailMessage;
|
private String detailMessage;
|
||||||
|
|
||||||
|
|
|
@ -11,22 +11,22 @@ public class BaseException extends RuntimeException {
|
||||||
/**
|
/**
|
||||||
* 所属模块
|
* 所属模块
|
||||||
*/
|
*/
|
||||||
private String module;
|
private final String module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误码
|
* 错误码
|
||||||
*/
|
*/
|
||||||
private String code;
|
private final String code;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误码对应的参数
|
* 错误码对应的参数
|
||||||
*/
|
*/
|
||||||
private Object[] args;
|
private final Object[] args;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误消息
|
* 错误消息
|
||||||
*/
|
*/
|
||||||
private String defaultMessage;
|
private final String defaultMessage;
|
||||||
|
|
||||||
public BaseException (String module, String code, Object[] args, String defaultMessage) {
|
public BaseException (String module, String code, Object[] args, String defaultMessage) {
|
||||||
this.module = module;
|
this.module = module;
|
||||||
|
|
|
@ -10,9 +10,9 @@ import java.util.Arrays;
|
||||||
public class InvalidExtensionException extends FileUploadException {
|
public class InvalidExtensionException extends FileUploadException {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private String[] allowedExtension;
|
private final String[] allowedExtension;
|
||||||
private String extension;
|
private final String extension;
|
||||||
private String filename;
|
private final String filename;
|
||||||
|
|
||||||
public InvalidExtensionException (String[] allowedExtension, String extension, String filename) {
|
public InvalidExtensionException (String[] allowedExtension, String extension, String filename) {
|
||||||
super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]");
|
super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]");
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package com.muyu.common.core.exception.job;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 计划策略异常
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public class TaskException extends Exception {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
private Code code;
|
|
||||||
|
|
||||||
public TaskException (String msg, Code code) {
|
|
||||||
this(msg, code, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TaskException (String msg, Code code, Exception nestedEx) {
|
|
||||||
super(msg, nestedEx);
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Code getCode () {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Code {
|
|
||||||
TASK_EXISTS, NO_TASK_EXISTS, TASK_ALREADY_STARTED, UNKNOWN, CONFIG_ERROR, TASK_NODE_NOT_AVAILABLE
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,12 +5,12 @@ import org.springframework.cloud.openfeign.support.SpringMvcContract;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义OpenFigen契约
|
||||||
|
* @author dongzeliang
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class FeginConfig {
|
public class FeginConfig {
|
||||||
// @Bean
|
|
||||||
// public Contract feignConfiguration() {
|
|
||||||
// return new feign.Contract.Default();
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Contract feignConfiguration() {
|
public Contract feignConfiguration() {
|
||||||
|
|
|
@ -511,19 +511,11 @@ public class Convert {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
valueStr = valueStr.trim().toLowerCase();
|
valueStr = valueStr.trim().toLowerCase();
|
||||||
switch (valueStr) {
|
return switch (valueStr) {
|
||||||
case "true":
|
case "true", "yes", "ok", "1" -> true;
|
||||||
case "yes":
|
case "false", "no", "0" -> false;
|
||||||
case "ok":
|
default -> defaultValue;
|
||||||
case "1":
|
};
|
||||||
return true;
|
|
||||||
case "false":
|
|
||||||
case "no":
|
|
||||||
case "0":
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,17 +14,17 @@ import java.util.Date;
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||||
public static String YYYY = "yyyy";
|
public static final String YYYY = "yyyy";
|
||||||
|
|
||||||
public static String YYYY_MM = "yyyy-MM";
|
public static final String YYYY_MM = "yyyy-MM";
|
||||||
|
|
||||||
public static String YYYY_MM_DD = "yyyy-MM-dd";
|
public static final String YYYY_MM_DD = "yyyy-MM-dd";
|
||||||
|
|
||||||
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
||||||
|
|
||||||
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
|
||||||
private static String[] parsePatterns = {
|
private static final String[] PARSE_PATTERNS = {
|
||||||
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
||||||
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
||||||
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
|
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
|
||||||
|
@ -99,7 +99,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return parseDate(str.toString(), parsePatterns);
|
return parseDate(str.toString(), PARSE_PATTERNS);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,17 +487,13 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
final int len = s.length();
|
final int len = s.length();
|
||||||
if (s.length() <= size) {
|
if (s.length() <= size) {
|
||||||
for (int i = size - len ; i > 0 ; i--) {
|
sb.append(String.valueOf(c).repeat(size - len));
|
||||||
sb.append(c);
|
|
||||||
}
|
|
||||||
sb.append(s);
|
sb.append(s);
|
||||||
} else {
|
} else {
|
||||||
return s.substring(len - size, len);
|
return s.substring(len - size, len);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = size ; i > 0 ; i--) {
|
sb.append(String.valueOf(c).repeat(Math.max(0, size)));
|
||||||
sb.append(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class BeanUtils extends org.springframework.beans.BeanUtils {
|
||||||
*/
|
*/
|
||||||
public static List<Method> getSetterMethods (Object obj) {
|
public static List<Method> getSetterMethods (Object obj) {
|
||||||
// setter方法列表
|
// setter方法列表
|
||||||
List<Method> setterMethods = new ArrayList<Method>();
|
List<Method> setterMethods = new ArrayList<>();
|
||||||
|
|
||||||
// 获取所有方法
|
// 获取所有方法
|
||||||
Method[] methods = obj.getClass().getMethods();
|
Method[] methods = obj.getClass().getMethods();
|
||||||
|
@ -77,7 +77,7 @@ public class BeanUtils extends org.springframework.beans.BeanUtils {
|
||||||
|
|
||||||
public static List<Method> getGetterMethods (Object obj) {
|
public static List<Method> getGetterMethods (Object obj) {
|
||||||
// getter方法列表
|
// getter方法列表
|
||||||
List<Method> getterMethods = new ArrayList<Method>();
|
List<Method> getterMethods = new ArrayList<>();
|
||||||
// 获取所有方法
|
// 获取所有方法
|
||||||
Method[] methods = obj.getClass().getMethods();
|
Method[] methods = obj.getClass().getMethods();
|
||||||
// 查找getter方法
|
// 查找getter方法
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class FileUtils {
|
||||||
*/
|
*/
|
||||||
public static final char BACKSLASH = '\\';
|
public static final char BACKSLASH = '\\';
|
||||||
|
|
||||||
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
|
public final static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 输出指定文件的byte数组
|
* 输出指定文件的byte数组
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class ImageUtils {
|
||||||
try {
|
try {
|
||||||
return IOUtils.toByteArray(is);
|
return IOUtils.toByteArray(is);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("图片加载异常 {}", e);
|
log.error("图片加载异常 {}", e.getMessage(), e);
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(is);
|
IOUtils.closeQuietly(is);
|
||||||
|
@ -36,7 +36,7 @@ public class ImageUtils {
|
||||||
result = Arrays.copyOf(result, result.length);
|
result = Arrays.copyOf(result, result.length);
|
||||||
return new ByteArrayInputStream(result);
|
return new ByteArrayInputStream(result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("获取图片异常 {}", e);
|
log.error("获取图片异常 {}", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public class ImageUtils {
|
||||||
in = urlConnection.getInputStream();
|
in = urlConnection.getInputStream();
|
||||||
return IOUtils.toByteArray(in);
|
return IOUtils.toByteArray(in);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("访问文件异常 {}", e);
|
log.error("访问文件异常 {}", e.getMessage(), e);
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(in);
|
IOUtils.closeQuietly(in);
|
||||||
|
|
|
@ -38,19 +38,13 @@ public class MimeTypeUtils {
|
||||||
"pdf"};
|
"pdf"};
|
||||||
|
|
||||||
public static String getExtension (String prefix) {
|
public static String getExtension (String prefix) {
|
||||||
switch (prefix) {
|
return switch (prefix) {
|
||||||
case IMAGE_PNG:
|
case IMAGE_PNG -> "png";
|
||||||
return "png";
|
case IMAGE_JPG -> "jpg";
|
||||||
case IMAGE_JPG:
|
case IMAGE_JPEG -> "jpeg";
|
||||||
return "jpg";
|
case IMAGE_BMP -> "bmp";
|
||||||
case IMAGE_JPEG:
|
case IMAGE_GIF -> "gif";
|
||||||
return "jpeg";
|
default -> "";
|
||||||
case IMAGE_BMP:
|
};
|
||||||
return "bmp";
|
|
||||||
case IMAGE_GIF:
|
|
||||||
return "gif";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,9 +140,6 @@ public class EscapeUtil {
|
||||||
public static void main (String[] args) {
|
public static void main (String[] args) {
|
||||||
String html = "<script>alert(1);</script>";
|
String html = "<script>alert(1);</script>";
|
||||||
String escape = EscapeUtil.escape(html);
|
String escape = EscapeUtil.escape(html);
|
||||||
// String html = "<scr<script>ipt>alert(\"XSS\")</scr<script>ipt>";
|
|
||||||
// String html = "<123";
|
|
||||||
// String html = "123>";
|
|
||||||
System.out.println("clean: " + EscapeUtil.clean(html));
|
System.out.println("clean: " + EscapeUtil.clean(html));
|
||||||
System.out.println("escape: " + escape);
|
System.out.println("escape: " + escape);
|
||||||
System.out.println("unescape: " + EscapeUtil.unescape(escape));
|
System.out.println("unescape: " + EscapeUtil.unescape(escape));
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.muyu.common.core.utils.html;
|
package com.muyu.common.core.utils.html;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
@ -15,15 +17,14 @@ public final class HTMLFilter {
|
||||||
/**
|
/**
|
||||||
* regex flag union representing /si modifiers in php
|
* regex flag union representing /si modifiers in php
|
||||||
**/
|
**/
|
||||||
private static final int REGEX_FLAGS_SI = Pattern.CASE_INSENSITIVE | Pattern.DOTALL;
|
|
||||||
private static final Pattern P_COMMENTS = Pattern.compile("<!--(.*?)-->", Pattern.DOTALL);
|
private static final Pattern P_COMMENTS = Pattern.compile("<!--(.*?)-->", Pattern.DOTALL);
|
||||||
private static final Pattern P_COMMENT = Pattern.compile("^!--(.*)--$", REGEX_FLAGS_SI);
|
private static final Pattern P_COMMENT = Pattern.compile("^!--(.*)--$", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
|
||||||
private static final Pattern P_TAGS = Pattern.compile("<(.*?)>", Pattern.DOTALL);
|
private static final Pattern P_TAGS = Pattern.compile("<(.*?)>", Pattern.DOTALL);
|
||||||
private static final Pattern P_END_TAG = Pattern.compile("^/([a-z0-9]+)", REGEX_FLAGS_SI);
|
private static final Pattern P_END_TAG = Pattern.compile("^/([a-z0-9]+)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
|
||||||
private static final Pattern P_START_TAG = Pattern.compile("^([a-z0-9]+)(.*?)(/?)$", REGEX_FLAGS_SI);
|
private static final Pattern P_START_TAG = Pattern.compile("^([a-z0-9]+)(.*?)(/?)$", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
|
||||||
private static final Pattern P_QUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)=([\"'])(.*?)\\2", REGEX_FLAGS_SI);
|
private static final Pattern P_QUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)=([\"'])(.*?)\\2", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
|
||||||
private static final Pattern P_UNQUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)(=)([^\"\\s']+)", REGEX_FLAGS_SI);
|
private static final Pattern P_UNQUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)(=)([^\"\\s']+)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
|
||||||
private static final Pattern P_PROTOCOL = Pattern.compile("^([^:]+):", REGEX_FLAGS_SI);
|
private static final Pattern P_PROTOCOL = Pattern.compile("^([^:]+):", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
|
||||||
private static final Pattern P_ENTITY = Pattern.compile("&#(\\d+);?");
|
private static final Pattern P_ENTITY = Pattern.compile("&#(\\d+);?");
|
||||||
private static final Pattern P_ENTITY_UNICODE = Pattern.compile("&#x([0-9a-f]+);?");
|
private static final Pattern P_ENTITY_UNICODE = Pattern.compile("&#x([0-9a-f]+);?");
|
||||||
private static final Pattern P_ENCODE = Pattern.compile("%([0-9a-f]{2});?");
|
private static final Pattern P_ENCODE = Pattern.compile("%([0-9a-f]{2});?");
|
||||||
|
@ -90,6 +91,7 @@ public final class HTMLFilter {
|
||||||
* flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "<b text </b>"
|
* flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "<b text </b>"
|
||||||
* becomes "<b> text </b>"). If set to false, unbalanced angle brackets will be html escaped.
|
* becomes "<b> text </b>"). If set to false, unbalanced angle brackets will be html escaped.
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
private final boolean alwaysMakeTags;
|
private final boolean alwaysMakeTags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,23 +100,23 @@ public final class HTMLFilter {
|
||||||
public HTMLFilter () {
|
public HTMLFilter () {
|
||||||
vAllowed = new HashMap<>();
|
vAllowed = new HashMap<>();
|
||||||
|
|
||||||
final ArrayList<String> a_atts = new ArrayList<>();
|
final List<String> aAttList = new ArrayList<>();
|
||||||
a_atts.add("href");
|
aAttList.add("href");
|
||||||
a_atts.add("target");
|
aAttList.add("target");
|
||||||
vAllowed.put("a", a_atts);
|
vAllowed.put("a", aAttList);
|
||||||
|
|
||||||
final ArrayList<String> img_atts = new ArrayList<>();
|
final List<String> imgAttList = new ArrayList<>();
|
||||||
img_atts.add("src");
|
imgAttList.add("src");
|
||||||
img_atts.add("width");
|
imgAttList.add("width");
|
||||||
img_atts.add("height");
|
imgAttList.add("height");
|
||||||
img_atts.add("alt");
|
imgAttList.add("alt");
|
||||||
vAllowed.put("img", img_atts);
|
vAllowed.put("img", imgAttList);
|
||||||
|
|
||||||
final ArrayList<String> no_atts = new ArrayList<>();
|
final List<String> noAttList = new ArrayList<>();
|
||||||
vAllowed.put("b", no_atts);
|
vAllowed.put("b", noAttList);
|
||||||
vAllowed.put("strong", no_atts);
|
vAllowed.put("strong", noAttList);
|
||||||
vAllowed.put("i", no_atts);
|
vAllowed.put("i", noAttList);
|
||||||
vAllowed.put("em", no_atts);
|
vAllowed.put("em", noAttList);
|
||||||
|
|
||||||
vSelfClosingTags = new String[]{"img"};
|
vSelfClosingTags = new String[]{"img"};
|
||||||
vNeedClosingTags = new String[]{"a", "b", "strong", "i", "em"};
|
vNeedClosingTags = new String[]{"a", "b", "strong", "i", "em"};
|
||||||
|
@ -174,8 +176,8 @@ public final class HTMLFilter {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String regexReplace (final Pattern regex_pattern, final String replacement, final String s) {
|
private static String regexReplace (final Pattern regexPattern, final String replacement, final String s) {
|
||||||
Matcher m = regex_pattern.matcher(s);
|
Matcher m = regexPattern.matcher(s);
|
||||||
return m.replaceAll(replacement);
|
return m.replaceAll(replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,10 +220,6 @@ public final class HTMLFilter {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlwaysMakeTags () {
|
|
||||||
return alwaysMakeTags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStripComments () {
|
public boolean isStripComments () {
|
||||||
return stripComment;
|
return stripComment;
|
||||||
}
|
}
|
||||||
|
@ -270,7 +268,7 @@ public final class HTMLFilter {
|
||||||
private String checkTags (String s) {
|
private String checkTags (String s) {
|
||||||
Matcher m = P_TAGS.matcher(s);
|
Matcher m = P_TAGS.matcher(s);
|
||||||
|
|
||||||
final StringBuffer buf = new StringBuffer();
|
final StringBuilder buf = new StringBuilder();
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
String replaceStr = m.group(1);
|
String replaceStr = m.group(1);
|
||||||
replaceStr = processTag(replaceStr);
|
replaceStr = processTag(replaceStr);
|
||||||
|
@ -354,11 +352,6 @@ public final class HTMLFilter {
|
||||||
for (int ii = 0 ; ii < paramNames.size() ; ii++) {
|
for (int ii = 0 ; ii < paramNames.size() ; ii++) {
|
||||||
paramName = paramNames.get(ii).toLowerCase();
|
paramName = paramNames.get(ii).toLowerCase();
|
||||||
paramValue = paramValues.get(ii);
|
paramValue = paramValues.get(ii);
|
||||||
|
|
||||||
// debug( "paramName='" + paramName + "'" );
|
|
||||||
// debug( "paramValue='" + paramValue + "'" );
|
|
||||||
// debug( "allowed? " + vAllowed.get( name ).contains( paramName ) );
|
|
||||||
|
|
||||||
if (allowedAttribute(name, paramName)) {
|
if (allowedAttribute(name, paramName)) {
|
||||||
if (inArray(paramName, vProtocolAtts)) {
|
if (inArray(paramName, vProtocolAtts)) {
|
||||||
paramValue = processParamProtocol(paramValue);
|
paramValue = processParamProtocol(paramValue);
|
||||||
|
@ -375,7 +368,7 @@ public final class HTMLFilter {
|
||||||
ending = "";
|
ending = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ending == null || ending.length() < 1) {
|
if (ending == null || ending.isEmpty()) {
|
||||||
if (vTagCounts.containsKey(name)) {
|
if (vTagCounts.containsKey(name)) {
|
||||||
vTagCounts.put(name, vTagCounts.get(name) + 1);
|
vTagCounts.put(name, vTagCounts.get(name) + 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -417,32 +410,32 @@ public final class HTMLFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String decodeEntities (String s) {
|
private String decodeEntities (String s) {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
|
|
||||||
Matcher m = P_ENTITY.matcher(s);
|
Matcher m = P_ENTITY.matcher(s);
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
final String match = m.group(1);
|
final String match = m.group(1);
|
||||||
final int decimal = Integer.decode(match).intValue();
|
final int decimal = Integer.decode(match);
|
||||||
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
||||||
}
|
}
|
||||||
m.appendTail(buf);
|
m.appendTail(buf);
|
||||||
s = buf.toString();
|
s = buf.toString();
|
||||||
|
|
||||||
buf = new StringBuffer();
|
buf = new StringBuilder();
|
||||||
m = P_ENTITY_UNICODE.matcher(s);
|
m = P_ENTITY_UNICODE.matcher(s);
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
final String match = m.group(1);
|
final String match = m.group(1);
|
||||||
final int decimal = Integer.valueOf(match, 16).intValue();
|
final int decimal = Integer.valueOf(match, 16);
|
||||||
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
||||||
}
|
}
|
||||||
m.appendTail(buf);
|
m.appendTail(buf);
|
||||||
s = buf.toString();
|
s = buf.toString();
|
||||||
|
|
||||||
buf = new StringBuffer();
|
buf = new StringBuilder();
|
||||||
m = P_ENCODE.matcher(s);
|
m = P_ENCODE.matcher(s);
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
final String match = m.group(1);
|
final String match = m.group(1);
|
||||||
final int decimal = Integer.valueOf(match, 16).intValue();
|
final int decimal = Integer.valueOf(match, 16);
|
||||||
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
|
||||||
}
|
}
|
||||||
m.appendTail(buf);
|
m.appendTail(buf);
|
||||||
|
@ -453,7 +446,7 @@ public final class HTMLFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String validateEntities (final String s) {
|
private String validateEntities (final String s) {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
|
|
||||||
// validate entities throughout the string
|
// validate entities throughout the string
|
||||||
Matcher m = P_VALID_ENTITIES.matcher(s);
|
Matcher m = P_VALID_ENTITIES.matcher(s);
|
||||||
|
@ -471,7 +464,7 @@ public final class HTMLFilter {
|
||||||
|
|
||||||
private String encodeQuotes (final String s) {
|
private String encodeQuotes (final String s) {
|
||||||
if (encodeQuotes) {
|
if (encodeQuotes) {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
Matcher m = P_VALID_QUOTES.matcher(s);
|
Matcher m = P_VALID_QUOTES.matcher(s);
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
// (>|^)
|
// (>|^)
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class ExcelUtil<T> {
|
||||||
/**
|
/**
|
||||||
* 实体对象
|
* 实体对象
|
||||||
*/
|
*/
|
||||||
public Class<T> clazz;
|
public final Class<T> clazz;
|
||||||
/**
|
/**
|
||||||
* 需要排除列属性
|
* 需要排除列属性
|
||||||
*/
|
*/
|
||||||
|
@ -121,7 +121,7 @@ public class ExcelUtil<T> {
|
||||||
/**
|
/**
|
||||||
* 统计列表
|
* 统计列表
|
||||||
*/
|
*/
|
||||||
private Map<Integer, Double> statistics = new HashMap<Integer, Double>();
|
private final Map<Integer, Double> statistics = new HashMap<>();
|
||||||
|
|
||||||
public ExcelUtil (Class<T> clazz) {
|
public ExcelUtil (Class<T> clazz) {
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
|
@ -210,7 +210,7 @@ public class ExcelUtil<T> {
|
||||||
|
|
||||||
public void init (List<T> list, String sheetName, String title, Type type) {
|
public void init (List<T> list, String sheetName, String title, Type type) {
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new ArrayList<T>();
|
list = new ArrayList<>();
|
||||||
}
|
}
|
||||||
this.list = list;
|
this.list = list;
|
||||||
this.sheetName = sheetName;
|
this.sheetName = sheetName;
|
||||||
|
@ -311,7 +311,7 @@ public class ExcelUtil<T> {
|
||||||
public List<T> importExcel (String sheetName, InputStream is, int titleNum) throws Exception {
|
public List<T> importExcel (String sheetName, InputStream is, int titleNum) throws Exception {
|
||||||
this.type = Type.IMPORT;
|
this.type = Type.IMPORT;
|
||||||
this.wb = WorkbookFactory.create(is);
|
this.wb = WorkbookFactory.create(is);
|
||||||
List<T> list = new ArrayList<T>();
|
List<T> list = new ArrayList<>();
|
||||||
// 如果指定sheet名,则取指定sheet中的内容 否则默认指向第1个sheet
|
// 如果指定sheet名,则取指定sheet中的内容 否则默认指向第1个sheet
|
||||||
Sheet sheet = StringUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0);
|
Sheet sheet = StringUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0);
|
||||||
if (sheet == null) {
|
if (sheet == null) {
|
||||||
|
@ -322,7 +322,7 @@ public class ExcelUtil<T> {
|
||||||
int rows = sheet.getLastRowNum();
|
int rows = sheet.getLastRowNum();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
// 定义一个map用于存放excel列的序号和field.
|
// 定义一个map用于存放excel列的序号和field.
|
||||||
Map<String, Integer> cellMap = new HashMap<String, Integer>();
|
Map<String, Integer> cellMap = new HashMap<>();
|
||||||
// 获取表头
|
// 获取表头
|
||||||
Row heard = sheet.getRow(titleNum);
|
Row heard = sheet.getRow(titleNum);
|
||||||
for (int i = 0 ; i < heard.getPhysicalNumberOfCells() ; i++) {
|
for (int i = 0 ; i < heard.getPhysicalNumberOfCells() ; i++) {
|
||||||
|
@ -336,7 +336,7 @@ public class ExcelUtil<T> {
|
||||||
}
|
}
|
||||||
// 有数据时才处理 得到类的所有field.
|
// 有数据时才处理 得到类的所有field.
|
||||||
List<Object[]> fields = this.getFields();
|
List<Object[]> fields = this.getFields();
|
||||||
Map<Integer, Object[]> fieldsMap = new HashMap<Integer, Object[]>();
|
Map<Integer, Object[]> fieldsMap = new HashMap<>();
|
||||||
for (Object[] objects : fields) {
|
for (Object[] objects : fields) {
|
||||||
Excel attr = (Excel) objects[1];
|
Excel attr = (Excel) objects[1];
|
||||||
Integer column = cellMap.get(attr.name());
|
Integer column = cellMap.get(attr.name());
|
||||||
|
@ -356,7 +356,7 @@ public class ExcelUtil<T> {
|
||||||
Object val = this.getCellValue(row, entry.getKey());
|
Object val = this.getCellValue(row, entry.getKey());
|
||||||
|
|
||||||
// 如果不存在实例则新建.
|
// 如果不存在实例则新建.
|
||||||
entity = (entity == null ? clazz.newInstance() : entity);
|
entity = (entity == null ? clazz.getDeclaredConstructor().newInstance() : entity);
|
||||||
// 从map中得到对应列的field.
|
// 从map中得到对应列的field.
|
||||||
Field field = (Field) entry.getValue()[0];
|
Field field = (Field) entry.getValue()[0];
|
||||||
Excel attr = (Excel) entry.getValue()[1];
|
Excel attr = (Excel) entry.getValue()[1];
|
||||||
|
@ -582,7 +582,7 @@ public class ExcelUtil<T> {
|
||||||
*/
|
*/
|
||||||
private Map<String, CellStyle> createStyles (Workbook wb) {
|
private Map<String, CellStyle> createStyles (Workbook wb) {
|
||||||
// 写入各条记录,每条记录对应excel表中的一行
|
// 写入各条记录,每条记录对应excel表中的一行
|
||||||
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
|
Map<String, CellStyle> styles = new HashMap<>();
|
||||||
CellStyle style = wb.createCellStyle();
|
CellStyle style = wb.createCellStyle();
|
||||||
style.setAlignment(HorizontalAlignment.CENTER);
|
style.setAlignment(HorizontalAlignment.CENTER);
|
||||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
@ -634,7 +634,7 @@ public class ExcelUtil<T> {
|
||||||
* @return 自定义样式列表
|
* @return 自定义样式列表
|
||||||
*/
|
*/
|
||||||
private Map<String, CellStyle> annotationHeaderStyles (Workbook wb, Map<String, CellStyle> styles) {
|
private Map<String, CellStyle> annotationHeaderStyles (Workbook wb, Map<String, CellStyle> styles) {
|
||||||
Map<String, CellStyle> headerStyles = new HashMap<String, CellStyle>();
|
Map<String, CellStyle> headerStyles = new HashMap<>();
|
||||||
for (Object[] os : fields) {
|
for (Object[] os : fields) {
|
||||||
Excel excel = (Excel) os[1];
|
Excel excel = (Excel) os[1];
|
||||||
String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor());
|
String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor());
|
||||||
|
@ -665,7 +665,7 @@ public class ExcelUtil<T> {
|
||||||
* @return 自定义样式列表
|
* @return 自定义样式列表
|
||||||
*/
|
*/
|
||||||
private Map<String, CellStyle> annotationDataStyles (Workbook wb) {
|
private Map<String, CellStyle> annotationDataStyles (Workbook wb) {
|
||||||
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
|
Map<String, CellStyle> styles = new HashMap<>();
|
||||||
for (Object[] os : fields) {
|
for (Object[] os : fields) {
|
||||||
Excel excel = (Excel) os[1];
|
Excel excel = (Excel) os[1];
|
||||||
String key = StringUtils.format("data_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor());
|
String key = StringUtils.format("data_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor());
|
||||||
|
@ -697,7 +697,7 @@ public class ExcelUtil<T> {
|
||||||
/**
|
/**
|
||||||
* 创建单元格
|
* 创建单元格
|
||||||
*/
|
*/
|
||||||
public Cell createHeadCell (Excel attr, Row row, int column) {
|
public void createHeadCell (Excel attr, Row row, int column) {
|
||||||
// 创建列
|
// 创建列
|
||||||
Cell cell = row.createCell(column);
|
Cell cell = row.createCell(column);
|
||||||
// 写入列信息
|
// 写入列信息
|
||||||
|
@ -711,7 +711,6 @@ public class ExcelUtil<T> {
|
||||||
sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column));
|
sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cell;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -764,7 +763,7 @@ public class ExcelUtil<T> {
|
||||||
* 创建表格样式
|
* 创建表格样式
|
||||||
*/
|
*/
|
||||||
public void setDataValidation (Excel attr, Row row, int column) {
|
public void setDataValidation (Excel attr, Row row, int column) {
|
||||||
if (attr.name().indexOf("注:") >= 0) {
|
if (attr.name().contains("注:")) {
|
||||||
sheet.setColumnWidth(column, 6000);
|
sheet.setColumnWidth(column, 6000);
|
||||||
} else {
|
} else {
|
||||||
// 设置列宽
|
// 设置列宽
|
||||||
|
@ -784,7 +783,7 @@ public class ExcelUtil<T> {
|
||||||
/**
|
/**
|
||||||
* 添加单元格
|
* 添加单元格
|
||||||
*/
|
*/
|
||||||
public Cell addCell (Excel attr, Row row, T vo, Field field, int column) {
|
public void addCell (Excel attr, Row row, T vo, Field field, int column) {
|
||||||
Cell cell = null;
|
Cell cell = null;
|
||||||
try {
|
try {
|
||||||
// 设置行高
|
// 设置行高
|
||||||
|
@ -819,9 +818,8 @@ public class ExcelUtil<T> {
|
||||||
addStatisticsData(column, Convert.toStr(value), attr);
|
addStatisticsData(column, Convert.toStr(value), attr);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("导出Excel失败{}", e);
|
log.error("导出Excel失败{}", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return cell;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -913,11 +911,11 @@ public class ExcelUtil<T> {
|
||||||
*/
|
*/
|
||||||
public String dataFormatHandlerAdapter (Object value, Excel excel, Cell cell) {
|
public String dataFormatHandlerAdapter (Object value, Excel excel, Cell cell) {
|
||||||
try {
|
try {
|
||||||
Object instance = excel.handler().newInstance();
|
Object instance = excel.handler().getDeclaredConstructor().newInstance();
|
||||||
Method formatMethod = excel.handler().getMethod("format", new Class[]{Object.class, String[].class, Cell.class, Workbook.class});
|
Method formatMethod = excel.handler().getMethod("format", new Class[]{Object.class, String[].class, Cell.class, Workbook.class});
|
||||||
value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
|
value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("不能格式化数据 " + excel.handler(), e.getMessage());
|
log.error("不能格式化数据 「{}-{}」", excel.handler() , e.getMessage());
|
||||||
}
|
}
|
||||||
return Convert.toStr(value);
|
return Convert.toStr(value);
|
||||||
}
|
}
|
||||||
|
@ -1019,7 +1017,7 @@ public class ExcelUtil<T> {
|
||||||
* 获取字段注解信息
|
* 获取字段注解信息
|
||||||
*/
|
*/
|
||||||
public List<Object[]> getFields () {
|
public List<Object[]> getFields () {
|
||||||
List<Object[]> fields = new ArrayList<Object[]>();
|
List<Object[]> fields = new ArrayList<>();
|
||||||
List<Field> tempFields = new ArrayList<>();
|
List<Field> tempFields = new ArrayList<>();
|
||||||
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
|
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
|
||||||
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
||||||
|
@ -1204,7 +1202,7 @@ public class ExcelUtil<T> {
|
||||||
try {
|
try {
|
||||||
value = subMethod.invoke(obj, new Object[]{});
|
value = subMethod.invoke(obj, new Object[]{});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new ArrayList<Object>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
return (Collection<?>) value;
|
return (Collection<?>) value;
|
||||||
}
|
}
|
||||||
|
@ -1218,7 +1216,7 @@ public class ExcelUtil<T> {
|
||||||
* @return 子列表方法
|
* @return 子列表方法
|
||||||
*/
|
*/
|
||||||
public Method getSubMethod (String name, Class<?> pojoClass) {
|
public Method getSubMethod (String name, Class<?> pojoClass) {
|
||||||
StringBuffer getMethodName = new StringBuffer("get");
|
StringBuilder getMethodName = new StringBuilder("get");
|
||||||
getMethodName.append(name.substring(0, 1).toUpperCase());
|
getMethodName.append(name.substring(0, 1).toUpperCase());
|
||||||
getMethodName.append(name.substring(1));
|
getMethodName.append(name.substring(1));
|
||||||
Method method = null;
|
Method method = null;
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class ReflectUtils {
|
||||||
Method method = getAccessibleMethodByName(obj, methodName, args.length);
|
Method method = getAccessibleMethodByName(obj, methodName, args.length);
|
||||||
if (method == null) {
|
if (method == null) {
|
||||||
// 如果为空不报错,直接返回空。
|
// 如果为空不报错,直接返回空。
|
||||||
log.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 ");
|
log.debug("在 [{}] 中,没有找到 [{}}] 方法 ", obj.getClass(), methodName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -238,7 +238,7 @@ public class ReflectUtils {
|
||||||
*/
|
*/
|
||||||
public static void makeAccessible (Method method) {
|
public static void makeAccessible (Method method) {
|
||||||
if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
|
if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
|
||||||
&& !method.isAccessible()) {
|
&& !method.canAccess(null)) {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ public class ReflectUtils {
|
||||||
*/
|
*/
|
||||||
public static void makeAccessible (Field field) {
|
public static void makeAccessible (Field field) {
|
||||||
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
|
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
|
||||||
|| Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) {
|
|| Modifier.isFinal(field.getModifiers())) && !field.canAccess(null)) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@ public class SqlUtil {
|
||||||
/**
|
/**
|
||||||
* 定义常用的 sql关键字
|
* 定义常用的 sql关键字
|
||||||
*/
|
*/
|
||||||
public static String SQL_REGEX = "and |extractvalue|updatexml|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |+|user()";
|
public final static String SQL_REGEX = "and |extractvalue|updatexml|exec |insert |select |delete |update |drop |count |chr |mid |master |truncate |char |declare |or |+|user()";
|
||||||
/**
|
/**
|
||||||
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
||||||
*/
|
*/
|
||||||
public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+";
|
public final static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查字符,防止注入绕过
|
* 检查字符,防止注入绕过
|
||||||
|
|
|
@ -10,16 +10,16 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
*/
|
*/
|
||||||
public class Seq {
|
public class Seq {
|
||||||
// 通用序列类型
|
// 通用序列类型
|
||||||
public static final String commSeqType = "COMMON";
|
public static final String COMM_SEQ_TYPE = "COMMON";
|
||||||
|
|
||||||
// 上传序列类型
|
// 上传序列类型
|
||||||
public static final String uploadSeqType = "UPLOAD";
|
public static final String UPLOAD_SEQ_TYPE = "UPLOAD";
|
||||||
// 机器标识
|
// 机器标识
|
||||||
private static final String machineCode = "A";
|
private static final String MACHINE_CODE = "A";
|
||||||
// 通用接口序列数
|
// 通用接口序列数
|
||||||
private static AtomicInteger commSeq = new AtomicInteger(1);
|
private final static AtomicInteger COMM_SEQ = new AtomicInteger(1);
|
||||||
// 上传接口序列数
|
// 上传接口序列数
|
||||||
private static AtomicInteger uploadSeq = new AtomicInteger(1);
|
private final static AtomicInteger UPLOAD_SEQ = new AtomicInteger(1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取通用序列号
|
* 获取通用序列号
|
||||||
|
@ -27,7 +27,7 @@ public class Seq {
|
||||||
* @return 序列值
|
* @return 序列值
|
||||||
*/
|
*/
|
||||||
public static String getId () {
|
public static String getId () {
|
||||||
return getId(commSeqType);
|
return getId(COMM_SEQ_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,9 +36,9 @@ public class Seq {
|
||||||
* @return 序列值
|
* @return 序列值
|
||||||
*/
|
*/
|
||||||
public static String getId (String type) {
|
public static String getId (String type) {
|
||||||
AtomicInteger atomicInt = commSeq;
|
AtomicInteger atomicInt = COMM_SEQ;
|
||||||
if (uploadSeqType.equals(type)) {
|
if (UPLOAD_SEQ_TYPE.equals(type)) {
|
||||||
atomicInt = uploadSeq;
|
atomicInt = UPLOAD_SEQ;
|
||||||
}
|
}
|
||||||
return getId(atomicInt, 3);
|
return getId(atomicInt, 3);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class Seq {
|
||||||
*/
|
*/
|
||||||
public static String getId (AtomicInteger atomicInt, int length) {
|
public static String getId (AtomicInteger atomicInt, int length) {
|
||||||
String result = DateUtils.dateTimeNow();
|
String result = DateUtils.dateTimeNow();
|
||||||
result += machineCode;
|
result += MACHINE_CODE;
|
||||||
result += getSeq(atomicInt, length);
|
result += getSeq(atomicInt, length);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,15 +139,15 @@ public final class UUID implements java.io.Serializable, Comparable<UUID> {
|
||||||
components[i] = "0x" + components[i];
|
components[i] = "0x" + components[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
long mostSigBits = Long.decode(components[0]).longValue();
|
long mostSigBits = Long.decode(components[0]);
|
||||||
mostSigBits <<= 16;
|
mostSigBits <<= 16;
|
||||||
mostSigBits |= Long.decode(components[1]).longValue();
|
mostSigBits |= Long.decode(components[1]);
|
||||||
mostSigBits <<= 16;
|
mostSigBits <<= 16;
|
||||||
mostSigBits |= Long.decode(components[2]).longValue();
|
mostSigBits |= Long.decode(components[2]);
|
||||||
|
|
||||||
long leastSigBits = Long.decode(components[3]).longValue();
|
long leastSigBits = Long.decode(components[3]);
|
||||||
leastSigBits <<= 48;
|
leastSigBits <<= 48;
|
||||||
leastSigBits |= Long.decode(components[4]).longValue();
|
leastSigBits |= Long.decode(components[4]);
|
||||||
|
|
||||||
return new UUID(mostSigBits, leastSigBits);
|
return new UUID(mostSigBits, leastSigBits);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class DataScopeAspect {
|
||||||
*/
|
*/
|
||||||
public static void dataScopeFilter (JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String permission) {
|
public static void dataScopeFilter (JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String permission) {
|
||||||
StringBuilder sqlString = new StringBuilder();
|
StringBuilder sqlString = new StringBuilder();
|
||||||
List<String> conditions = new ArrayList<String>();
|
List<String> conditions = new ArrayList<>();
|
||||||
|
|
||||||
for (SysRole role : user.getRoles()) {
|
for (SysRole role : user.getRoles()) {
|
||||||
String dataScope = role.getDataScope();
|
String dataScope = role.getDataScope();
|
||||||
|
@ -116,7 +116,7 @@ public class DataScopeAspect {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before("@annotation(controllerDataScope)")
|
@Before("@annotation(controllerDataScope)")
|
||||||
public void doBefore (JoinPoint point, DataScope controllerDataScope) throws Throwable {
|
public void doBefore (JoinPoint point, DataScope controllerDataScope) {
|
||||||
clearDataScope(point);
|
clearDataScope(point);
|
||||||
handleDataScope(point, controllerDataScope);
|
handleDataScope(point, controllerDataScope);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class LogAspect {
|
||||||
/**
|
/**
|
||||||
* 计算操作消耗时间
|
* 计算操作消耗时间
|
||||||
*/
|
*/
|
||||||
private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
|
private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<>("Cost Time");
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AsyncLogService asyncLogService;
|
private AsyncLogService asyncLogService;
|
||||||
|
@ -150,9 +150,8 @@ public class LogAspect {
|
||||||
*
|
*
|
||||||
* @param operLog 操作日志
|
* @param operLog 操作日志
|
||||||
*
|
*
|
||||||
* @throws Exception 异常
|
|
||||||
*/
|
*/
|
||||||
private void setRequestValue (JoinPoint joinPoint, SysOperLog operLog, String[] excludeParamNames) throws Exception {
|
private void setRequestValue (JoinPoint joinPoint, SysOperLog operLog, String[] excludeParamNames) {
|
||||||
String requestMethod = operLog.getRequestMethod();
|
String requestMethod = operLog.getRequestMethod();
|
||||||
Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
||||||
if (StringUtils.isEmpty(paramsMap)
|
if (StringUtils.isEmpty(paramsMap)
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||||
|
|
||||||
static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(Constants.JSON_WHITELIST_STR);
|
static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(Constants.JSON_WHITELIST_STR);
|
||||||
|
|
||||||
private Class<T> clazz;
|
private final Class<T> clazz;
|
||||||
|
|
||||||
public FastJson2JsonRedisSerializer (Class<T> clazz) {
|
public FastJson2JsonRedisSerializer (Class<T> clazz) {
|
||||||
super();
|
super();
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.muyu.common.redis.configure;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -18,7 +17,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
@AutoConfigureBefore(RedisAutoConfiguration.class)
|
@AutoConfigureBefore(RedisAutoConfiguration.class)
|
||||||
public class RedisConfig extends CachingConfigurerSupport {
|
public class RedisConfig {
|
||||||
@Bean
|
@Bean
|
||||||
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||||
public RedisTemplate<Object, Object> redisTemplate (RedisConnectionFactory connectionFactory) {
|
public RedisTemplate<Object, Object> redisTemplate (RedisConnectionFactory connectionFactory) {
|
||||||
|
|
|
@ -156,9 +156,8 @@ public class RedisService {
|
||||||
*/
|
*/
|
||||||
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final Set<T> dataSet) {
|
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final Set<T> dataSet) {
|
||||||
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
||||||
Iterator<T> it = dataSet.iterator();
|
for (T t : dataSet) {
|
||||||
while (it.hasNext()) {
|
setOperation.add(t);
|
||||||
setOperation.add(it.next());
|
|
||||||
}
|
}
|
||||||
return setOperation;
|
return setOperation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,13 +55,8 @@ public class PreAuthorizeAspect {
|
||||||
// 注解鉴权
|
// 注解鉴权
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
checkMethodAnnotation(signature.getMethod());
|
checkMethodAnnotation(signature.getMethod());
|
||||||
try {
|
// 执行原有逻辑
|
||||||
// 执行原有逻辑
|
return joinPoint.proceed();
|
||||||
Object obj = joinPoint.proceed();
|
|
||||||
return obj;
|
|
||||||
} catch (Throwable e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class AuthLogic {
|
||||||
*/
|
*/
|
||||||
private static final String SUPER_ADMIN = "admin";
|
private static final String SUPER_ADMIN = "admin";
|
||||||
|
|
||||||
public TokenService tokenService = SpringUtils.getBean(TokenService.class);
|
public final TokenService tokenService = SpringUtils.getBean(TokenService.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会话注销
|
* 会话注销
|
||||||
|
@ -114,8 +114,6 @@ public class AuthLogic {
|
||||||
* 验证用户是否具备某权限, 如果验证未通过,则抛出异常: NotPermissionException
|
* 验证用户是否具备某权限, 如果验证未通过,则抛出异常: NotPermissionException
|
||||||
*
|
*
|
||||||
* @param permission 权限字符串
|
* @param permission 权限字符串
|
||||||
*
|
|
||||||
* @return 用户是否具备某权限
|
|
||||||
*/
|
*/
|
||||||
public void checkPermi (String permission) {
|
public void checkPermi (String permission) {
|
||||||
if (!hasPermi(getPermiList(), permission)) {
|
if (!hasPermi(getPermiList(), permission)) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class AuthUtil {
|
||||||
/**
|
/**
|
||||||
* 底层的 AuthLogic 对象
|
* 底层的 AuthLogic 对象
|
||||||
*/
|
*/
|
||||||
public static AuthLogic authLogic = new AuthLogic();
|
public final static AuthLogic authLogic = new AuthLogic();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会话注销
|
* 会话注销
|
||||||
|
|
|
@ -20,6 +20,8 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchExcep
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局异常处理器
|
* 全局异常处理器
|
||||||
*
|
*
|
||||||
|
@ -33,9 +35,9 @@ public class GlobalExceptionHandler {
|
||||||
* 权限码异常
|
* 权限码异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(NotPermissionException.class)
|
@ExceptionHandler(NotPermissionException.class)
|
||||||
public Result handleNotPermissionException (NotPermissionException e, HttpServletRequest request) {
|
public Result<String> handleNotPermissionException (NotPermissionException e, HttpServletRequest request) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestUri = request.getRequestURI();
|
||||||
log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage());
|
log.error("请求地址'{}',权限码校验失败'{}'", requestUri, e.getMessage());
|
||||||
return Result.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
|
return Result.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,9 +45,9 @@ public class GlobalExceptionHandler {
|
||||||
* 角色权限异常
|
* 角色权限异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(NotRoleException.class)
|
@ExceptionHandler(NotRoleException.class)
|
||||||
public Result handleNotRoleException (NotRoleException e, HttpServletRequest request) {
|
public Result<String> handleNotRoleException (NotRoleException e, HttpServletRequest request) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestUri = request.getRequestURI();
|
||||||
log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage());
|
log.error("请求地址'{}',角色权限校验失败'{}'", requestUri, e.getMessage());
|
||||||
return Result.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
|
return Result.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,9 +55,9 @@ public class GlobalExceptionHandler {
|
||||||
* 请求方式不支持
|
* 请求方式不支持
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||||
public Result handleHttpRequestMethodNotSupported (HttpRequestMethodNotSupportedException e, HttpServletRequest request) {
|
public Result<String> handleHttpRequestMethodNotSupported (HttpRequestMethodNotSupportedException e, HttpServletRequest request) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestUri = request.getRequestURI();
|
||||||
log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
|
log.error("请求地址'{}',不支持'{}'请求", requestUri, e.getMethod());
|
||||||
return Result.error(e.getMessage());
|
return Result.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,19 +65,19 @@ public class GlobalExceptionHandler {
|
||||||
* 业务异常
|
* 业务异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(ServiceException.class)
|
@ExceptionHandler(ServiceException.class)
|
||||||
public Result handleServiceException (ServiceException e, HttpServletRequest request) {
|
public Result<String> handleServiceException (ServiceException e, HttpServletRequest request) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
Integer code = e.getCode();
|
Integer code = e.getCode();
|
||||||
return StringUtils.isNotNull(code) ? Result.error(code, e.getMessage()) : Result.error(e.getMessage());
|
return StringUtils.isNotNull(code) ? Result.error(code.intValue(), e.getMessage()) : Result.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求路径中缺少必需的路径变量
|
* 请求路径中缺少必需的路径变量
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(MissingPathVariableException.class)
|
@ExceptionHandler(MissingPathVariableException.class)
|
||||||
public Result handleMissingPathVariableException (MissingPathVariableException e, HttpServletRequest request) {
|
public Result<String> handleMissingPathVariableException (MissingPathVariableException e, HttpServletRequest request) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestUri = request.getRequestURI();
|
||||||
log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
|
log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestUri, e);
|
||||||
return Result.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
|
return Result.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,9 +85,9 @@ public class GlobalExceptionHandler {
|
||||||
* 请求参数类型不匹配
|
* 请求参数类型不匹配
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
|
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
|
||||||
public Result handleMethodArgumentTypeMismatchException (MethodArgumentTypeMismatchException e, HttpServletRequest request) {
|
public Result<String> handleMethodArgumentTypeMismatchException (MethodArgumentTypeMismatchException e, HttpServletRequest request) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestUri = request.getRequestURI();
|
||||||
log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
|
log.error("请求参数类型不匹配'{}',发生系统异常.", requestUri, e);
|
||||||
return Result.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
|
return Result.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +95,9 @@ public class GlobalExceptionHandler {
|
||||||
* 拦截未知的运行时异常
|
* 拦截未知的运行时异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(RuntimeException.class)
|
@ExceptionHandler(RuntimeException.class)
|
||||||
public Result handleRuntimeException (RuntimeException e, HttpServletRequest request) {
|
public Result<String> handleRuntimeException (RuntimeException e, HttpServletRequest request) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestUri = request.getRequestURI();
|
||||||
log.error("请求地址'{}',发生未知异常.", requestURI, e);
|
log.error("请求地址'{}',发生未知异常.", requestUri, e);
|
||||||
return Result.error(e.getMessage());
|
return Result.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,9 +105,9 @@ public class GlobalExceptionHandler {
|
||||||
* 系统异常
|
* 系统异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public Result handleException (Exception e, HttpServletRequest request) {
|
public Result<String> handleException (Exception e, HttpServletRequest request) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestUri = request.getRequestURI();
|
||||||
log.error("请求地址'{}',发生系统异常.", requestURI, e);
|
log.error("请求地址'{}',发生系统异常.", requestUri, e);
|
||||||
return Result.error(e.getMessage());
|
return Result.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +115,7 @@ public class GlobalExceptionHandler {
|
||||||
* 自定义验证异常
|
* 自定义验证异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(BindException.class)
|
@ExceptionHandler(BindException.class)
|
||||||
public Result handleBindException (BindException e) {
|
public Result<String> handleBindException (BindException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
String message = e.getAllErrors().get(0).getDefaultMessage();
|
String message = e.getAllErrors().get(0).getDefaultMessage();
|
||||||
return Result.error(message);
|
return Result.error(message);
|
||||||
|
@ -125,7 +127,7 @@ public class GlobalExceptionHandler {
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
public Object handleMethodArgumentNotValidException (MethodArgumentNotValidException e) {
|
public Object handleMethodArgumentNotValidException (MethodArgumentNotValidException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
String message = e.getBindingResult().getFieldError().getDefaultMessage();
|
String message = Objects.requireNonNull(e.getBindingResult().getFieldError()).getDefaultMessage();
|
||||||
return Result.error(message);
|
return Result.error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +135,7 @@ public class GlobalExceptionHandler {
|
||||||
* 内部认证异常
|
* 内部认证异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(InnerAuthException.class)
|
@ExceptionHandler(InnerAuthException.class)
|
||||||
public Result handleInnerAuthException (InnerAuthException e) {
|
public Result<String> handleInnerAuthException (InnerAuthException e) {
|
||||||
return Result.error(e.getMessage());
|
return Result.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +143,7 @@ public class GlobalExceptionHandler {
|
||||||
* 演示模式异常
|
* 演示模式异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(DemoModeException.class)
|
@ExceptionHandler(DemoModeException.class)
|
||||||
public Result handleDemoModeException (DemoModeException e) {
|
public Result<String> handleDemoModeException (DemoModeException e) {
|
||||||
return Result.error("演示模式,不允许操作");
|
return Result.error("演示模式,不允许操作");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||||
public class HeaderInterceptor implements AsyncHandlerInterceptor {
|
public class HeaderInterceptor implements AsyncHandlerInterceptor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||||
if (!(handler instanceof HandlerMethod)) {
|
if (!(handler instanceof HandlerMethod)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,7 @@ public class HeaderInterceptor implements AsyncHandlerInterceptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterCompletion (HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
public void afterCompletion (HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||||
throws Exception {
|
|
||||||
SecurityContextHolder.remove();
|
SecurityContextHolder.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,13 +51,13 @@ public class TokenService {
|
||||||
refreshToken(loginUser);
|
refreshToken(loginUser);
|
||||||
|
|
||||||
// Jwt存储信息
|
// Jwt存储信息
|
||||||
Map<String, Object> claimsMap = new HashMap<String, Object>();
|
Map<String, Object> claimsMap = new HashMap<>();
|
||||||
claimsMap.put(SecurityConstants.USER_KEY, token);
|
claimsMap.put(SecurityConstants.USER_KEY, token);
|
||||||
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
||||||
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
||||||
|
|
||||||
// 接口返回信息
|
// 接口返回信息
|
||||||
Map<String, Object> rspMap = new HashMap<String, Object>();
|
Map<String, Object> rspMap = new HashMap<>();
|
||||||
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
||||||
rspMap.put("expires_in", expireTime);
|
rspMap.put("expires_in", expireTime);
|
||||||
return rspMap;
|
return rspMap;
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class SysDept extends BaseEntity {
|
||||||
* 子部门
|
* 子部门
|
||||||
*/
|
*/
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<SysDept> children = new ArrayList<SysDept>();
|
private List<SysDept> children = new ArrayList<>();
|
||||||
|
|
||||||
@NotBlank(message = "部门名称不能为空")
|
@NotBlank(message = "部门名称不能为空")
|
||||||
@Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
|
@Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
|
||||||
|
|
|
@ -27,7 +27,7 @@ public interface RemoteLogService {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("/operlog")
|
@PostMapping("/operlog")
|
||||||
public Result<Boolean> saveLog (@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source) throws Exception;
|
public Result<Boolean> saveLog (@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存访问记录
|
* 保存访问记录
|
||||||
|
|
|
@ -21,11 +21,6 @@ public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileServ
|
||||||
@Override
|
@Override
|
||||||
public RemoteFileService create (Throwable throwable) {
|
public RemoteFileService create (Throwable throwable) {
|
||||||
log.error("文件服务调用失败:{}", throwable.getMessage());
|
log.error("文件服务调用失败:{}", throwable.getMessage());
|
||||||
return new RemoteFileService() {
|
return file -> Result.error("上传文件失败:" + throwable.getMessage());
|
||||||
@Override
|
|
||||||
public Result<SysFile> upload (MultipartFile file) {
|
|
||||||
return Result.error("上传文件失败:" + throwable.getMessage());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class BlackListUrlFilter extends AbstractGatewayFilterFactory<BlackListUr
|
||||||
public static class Config {
|
public static class Config {
|
||||||
private List<String> blacklistUrl;
|
private List<String> blacklistUrl;
|
||||||
|
|
||||||
private List<Pattern> blacklistUrlPattern = new ArrayList<>();
|
private final List<Pattern> blacklistUrlPattern = new ArrayList<>();
|
||||||
|
|
||||||
public boolean matchBlacklist (String url) {
|
public boolean matchBlacklist (String url) {
|
||||||
return !blacklistUrlPattern.isEmpty() && blacklistUrlPattern.stream().anyMatch(p -> p.matcher(url).find());
|
return !blacklistUrlPattern.isEmpty() && blacklistUrlPattern.stream().anyMatch(p -> p.matcher(url).find());
|
||||||
|
@ -49,9 +49,7 @@ public class BlackListUrlFilter extends AbstractGatewayFilterFactory<BlackListUr
|
||||||
public void setBlacklistUrl (List<String> blacklistUrl) {
|
public void setBlacklistUrl (List<String> blacklistUrl) {
|
||||||
this.blacklistUrl = blacklistUrl;
|
this.blacklistUrl = blacklistUrl;
|
||||||
this.blacklistUrlPattern.clear();
|
this.blacklistUrlPattern.clear();
|
||||||
this.blacklistUrl.forEach(url -> {
|
this.blacklistUrl.forEach(url -> this.blacklistUrlPattern.add(Pattern.compile(url.replaceAll("\\*\\*", "(.*?)"), Pattern.CASE_INSENSITIVE)));
|
||||||
this.blacklistUrlPattern.add(Pattern.compile(url.replaceAll("\\*\\*", "(.*?)"), Pattern.CASE_INSENSITIVE));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,10 @@ import com.muyu.gateway.service.ValidateCodeService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
||||||
import org.springframework.core.io.buffer.DataBuffer;
|
|
||||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
|
|
||||||
import java.nio.CharBuffer;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码过滤器
|
* 验证码过滤器
|
||||||
|
@ -29,10 +24,22 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object> {
|
||||||
private final static String[] VALIDATE_URL = new String[]{"/auth/login", "/auth/register"};
|
private final static String[] VALIDATE_URL = new String[]{"/auth/login", "/auth/register"};
|
||||||
private static final String CODE = "code";
|
private static final String CODE = "code";
|
||||||
private static final String UUID = "uuid";
|
private static final String UUID = "uuid";
|
||||||
|
|
||||||
|
private final ValidateCodeService validateCodeService;
|
||||||
|
|
||||||
|
private final CaptchaProperties captchaProperties;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ValidateCodeService validateCodeService;
|
public ValidateCodeFilter(ValidateCodeService validateCodeService, CaptchaProperties captchaProperties) {
|
||||||
@Autowired
|
this.validateCodeService = validateCodeService;
|
||||||
private CaptchaProperties captchaProperties;
|
this.captchaProperties = captchaProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValidateCodeFilter(Class<Object> configClass, ValidateCodeService validateCodeService, CaptchaProperties captchaProperties) {
|
||||||
|
super(configClass);
|
||||||
|
this.validateCodeService = validateCodeService;
|
||||||
|
this.captchaProperties = captchaProperties;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GatewayFilter apply (Object config) {
|
public GatewayFilter apply (Object config) {
|
||||||
|
@ -57,13 +64,13 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object> {
|
||||||
|
|
||||||
private String resolveBodyFromRequest (ServerHttpRequest serverHttpRequest) {
|
private String resolveBodyFromRequest (ServerHttpRequest serverHttpRequest) {
|
||||||
// 获取请求体
|
// 获取请求体
|
||||||
Flux<DataBuffer> body = serverHttpRequest.getBody();
|
return DataBufferUtils.join(serverHttpRequest.getBody())
|
||||||
AtomicReference<String> bodyRef = new AtomicReference<>();
|
.map(dataBuffer -> {
|
||||||
body.subscribe(buffer -> {
|
byte[] bytes = new byte[dataBuffer.readableByteCount()];
|
||||||
CharBuffer charBuffer = StandardCharsets.UTF_8.decode(buffer.asByteBuffer());
|
dataBuffer.read(bytes);
|
||||||
DataBufferUtils.release(buffer);
|
DataBufferUtils.release(dataBuffer);
|
||||||
bodyRef.set(charBuffer.toString());
|
return new String(bytes, StandardCharsets.UTF_8);
|
||||||
});
|
})
|
||||||
return bodyRef.get();
|
.block();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,7 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
|
||||||
|
|
||||||
if (ex instanceof NotFoundException) {
|
if (ex instanceof NotFoundException) {
|
||||||
msg = "服务未找到";
|
msg = "服务未找到";
|
||||||
} else if (ex instanceof ResponseStatusException) {
|
} else if (ex instanceof ResponseStatusException responseStatusException) {
|
||||||
ResponseStatusException responseStatusException = (ResponseStatusException) ex;
|
|
||||||
msg = responseStatusException.getMessage();
|
msg = responseStatusException.getMessage();
|
||||||
} else {
|
} else {
|
||||||
msg = "内部服务器错误";
|
msg = "内部服务器错误";
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.gateway.handler;
|
||||||
|
|
||||||
import com.muyu.common.core.exception.CaptchaException;
|
import com.muyu.common.core.exception.CaptchaException;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.gateway.model.resp.CaptchaCodeResp;
|
||||||
import com.muyu.gateway.service.ValidateCodeService;
|
import com.muyu.gateway.service.ValidateCodeService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -26,10 +27,10 @@ public class ValidateCodeHandler implements HandlerFunction<ServerResponse> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<ServerResponse> handle (ServerRequest serverRequest) {
|
public Mono<ServerResponse> handle (ServerRequest serverRequest) {
|
||||||
Result ajax;
|
Result<CaptchaCodeResp> ajax;
|
||||||
try {
|
try {
|
||||||
ajax = validateCodeService.createCaptcha();
|
ajax = validateCodeService.createCaptcha();
|
||||||
} catch (CaptchaException | IOException e) {
|
} catch (CaptchaException e) {
|
||||||
return Mono.error(e);
|
return Mono.error(e);
|
||||||
}
|
}
|
||||||
return ServerResponse.status(HttpStatus.OK).body(BodyInserters.fromValue(ajax));
|
return ServerResponse.status(HttpStatus.OK).body(BodyInserters.fromValue(ajax));
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.gateway.service;
|
||||||
|
|
||||||
import com.muyu.common.core.exception.CaptchaException;
|
import com.muyu.common.core.exception.CaptchaException;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.gateway.model.resp.CaptchaCodeResp;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ public interface ValidateCodeService {
|
||||||
/**
|
/**
|
||||||
* 生成验证码
|
* 生成验证码
|
||||||
*/
|
*/
|
||||||
public Result createCaptcha () throws IOException, CaptchaException;
|
public Result<CaptchaCodeResp> createCaptcha () throws CaptchaException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验验证码
|
* 校验验证码
|
||||||
|
|
|
@ -45,12 +45,12 @@ public class ValidateCodeServiceImpl implements ValidateCodeService {
|
||||||
* 生成验证码
|
* 生成验证码
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result createCaptcha () throws IOException, CaptchaException {
|
public Result<CaptchaCodeResp> createCaptcha () throws CaptchaException {
|
||||||
boolean captchaEnabled = captchaProperties.getEnabled();
|
boolean captchaEnabled = captchaProperties.getEnabled();
|
||||||
CaptchaCodeResp.CaptchaCodeRespBuilder respBuilder = CaptchaCodeResp.builder()
|
CaptchaCodeResp.CaptchaCodeRespBuilder respBuilder = CaptchaCodeResp.builder()
|
||||||
.captchaEnabled(captchaEnabled);
|
.captchaEnabled(captchaEnabled);
|
||||||
if (!captchaEnabled) {
|
if (!captchaEnabled) {
|
||||||
return Result.success(respBuilder);
|
return Result.success(respBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存验证码信息
|
// 保存验证码信息
|
||||||
|
|
|
@ -20,6 +20,7 @@ import reactor.core.publisher.Mono;
|
||||||
* Web 工具类
|
* Web 工具类
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
* @author dongzeliang
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class WebFrameworkUtils {
|
public class WebFrameworkUtils {
|
||||||
|
|
|
@ -89,10 +89,10 @@ public class FileUploadUtils {
|
||||||
*/
|
*/
|
||||||
public static final String extractFilename (MultipartFile file) {
|
public static final String extractFilename (MultipartFile file) {
|
||||||
return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(),
|
return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(),
|
||||||
FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), FileTypeUtils.getExtension(file));
|
FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.UPLOAD_SEQ_TYPE), FileTypeUtils.getExtension(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final File getAbsoluteFile (String uploadDir, String fileName) throws IOException {
|
private static final File getAbsoluteFile (String uploadDir, String fileName) {
|
||||||
File desc = new File(uploadDir + File.separator + fileName);
|
File desc = new File(uploadDir + File.separator + fileName);
|
||||||
|
|
||||||
if (!desc.exists()) {
|
if (!desc.exists()) {
|
||||||
|
@ -103,7 +103,7 @@ public class FileUploadUtils {
|
||||||
return desc.isAbsolute() ? desc : desc.getAbsoluteFile();
|
return desc.isAbsolute() ? desc : desc.getAbsoluteFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String getPathFileName (String fileName) throws IOException {
|
private static final String getPathFileName (String fileName) {
|
||||||
String pathFileName = "/" + fileName;
|
String pathFileName = "/" + fileName;
|
||||||
return pathFileName;
|
return pathFileName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,12 +65,6 @@
|
||||||
<artifactId>cloud-common-api-doc</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- XllJob定时任务 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-xxl</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -51,11 +51,11 @@ public class GenController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("tool:gen:query")
|
@RequiresPermissions("tool:gen:query")
|
||||||
@GetMapping(value = "/{tableId}")
|
@GetMapping(value = "/{tableId}")
|
||||||
public Result getInfo (@PathVariable("tableId") Long tableId) {
|
public Result<Map<String, Object>> getInfo (@PathVariable("tableId") Long tableId) {
|
||||||
GenTable table = genTableService.selectGenTableById(tableId);
|
GenTable table = genTableService.selectGenTableById(tableId);
|
||||||
List<GenTable> tables = genTableService.selectGenTableAll();
|
List<GenTable> tables = genTableService.selectGenTableAll();
|
||||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
map.put("info", table);
|
map.put("info", table);
|
||||||
map.put("rows", list);
|
map.put("rows", list);
|
||||||
map.put("tables", tables);
|
map.put("tables", tables);
|
||||||
|
@ -92,7 +92,7 @@ public class GenController extends BaseController {
|
||||||
@RequiresPermissions("tool:gen:import")
|
@RequiresPermissions("tool:gen:import")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
|
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
|
||||||
@PostMapping("/importTable")
|
@PostMapping("/importTable")
|
||||||
public Result importTableSave (String tables) {
|
public Result<String> importTableSave (String tables) {
|
||||||
String[] tableNames = Convert.toStrArray(tables);
|
String[] tableNames = Convert.toStrArray(tables);
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
|
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
|
||||||
|
@ -106,7 +106,7 @@ public class GenController extends BaseController {
|
||||||
@RequiresPermissions("tool:gen:edit")
|
@RequiresPermissions("tool:gen:edit")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public Result editSave (@Validated @RequestBody GenTable genTable) {
|
public Result<String> editSave (@Validated @RequestBody GenTable genTable) {
|
||||||
genTableService.validateEdit(genTable);
|
genTableService.validateEdit(genTable);
|
||||||
genTableService.updateGenTable(genTable);
|
genTableService.updateGenTable(genTable);
|
||||||
return success();
|
return success();
|
||||||
|
@ -118,7 +118,7 @@ public class GenController extends BaseController {
|
||||||
@RequiresPermissions("tool:gen:remove")
|
@RequiresPermissions("tool:gen:remove")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.DELETE)
|
@Log(title = "代码生成", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{tableIds}")
|
@DeleteMapping("/{tableIds}")
|
||||||
public Result remove (@PathVariable("tableIds")List<Long> tableIds) {
|
public Result<String> remove (@PathVariable("tableIds")List<Long> tableIds) {
|
||||||
genTableService.deleteGenTableByIds(tableIds);
|
genTableService.deleteGenTableByIds(tableIds);
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public class GenController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("tool:gen:preview")
|
@RequiresPermissions("tool:gen:preview")
|
||||||
@GetMapping("/preview/{tableId}")
|
@GetMapping("/preview/{tableId}")
|
||||||
public Result preview (@PathVariable("tableId") Long tableId) throws IOException {
|
public Result<Map<String, String>> preview (@PathVariable("tableId") Long tableId) {
|
||||||
Map<String, String> dataMap = genTableService.previewCode(tableId);
|
Map<String, String> dataMap = genTableService.previewCode(tableId);
|
||||||
return success(dataMap);
|
return success(dataMap);
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ public class GenController extends BaseController {
|
||||||
@RequiresPermissions("tool:gen:code")
|
@RequiresPermissions("tool:gen:code")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||||
@GetMapping("/genCode/{tableName}")
|
@GetMapping("/genCode/{tableName}")
|
||||||
public Result genCode (@PathVariable("tableName") String tableName) {
|
public Result<String> genCode (@PathVariable("tableName") String tableName) {
|
||||||
genTableService.generatorCode(tableName);
|
genTableService.generatorCode(tableName);
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ public class GenController extends BaseController {
|
||||||
@RequiresPermissions("tool:gen:edit")
|
@RequiresPermissions("tool:gen:edit")
|
||||||
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
||||||
@GetMapping("/synchDb/{tableName}")
|
@GetMapping("/synchDb/{tableName}")
|
||||||
public Result synchDb (@PathVariable("tableName") String tableName) {
|
public Result<String> synchDb (@PathVariable("tableName") String tableName) {
|
||||||
genTableService.synchDb(tableName);
|
genTableService.synchDb(tableName);
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
|
@ -341,7 +341,7 @@ public class GenTableColumn extends BaseEntity {
|
||||||
|
|
||||||
public String readConverterExp () {
|
public String readConverterExp () {
|
||||||
String remarks = StringUtils.substringBetween(this.columnComment, "(", ")");
|
String remarks = StringUtils.substringBetween(this.columnComment, "(", ")");
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
if (StringUtils.isNotEmpty(remarks)) {
|
if (StringUtils.isNotEmpty(remarks)) {
|
||||||
for (String value : remarks.split(" ")) {
|
for (String value : remarks.split(" ")) {
|
||||||
if (StringUtils.isNotEmpty(value)) {
|
if (StringUtils.isNotEmpty(value)) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.gen.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.gen.domain.GenTableColumn;
|
import com.muyu.gen.domain.GenTableColumn;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> {
|
public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> {
|
||||||
/**
|
/**
|
||||||
* 根据表名称查询列信息
|
* 根据表名称查询列信息
|
||||||
|
|
|
@ -47,11 +47,15 @@ import java.util.zip.ZipOutputStream;
|
||||||
public class GenTableServiceImpl implements IGenTableService {
|
public class GenTableServiceImpl implements IGenTableService {
|
||||||
private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
|
private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
private final GenTableMapper genTableMapper;
|
||||||
private GenTableMapper genTableMapper;
|
|
||||||
|
private final GenTableColumnMapper genTableColumnMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private GenTableColumnMapper genTableColumnMapper;
|
public GenTableServiceImpl(GenTableMapper genTableMapper, GenTableColumnMapper genTableColumnMapper) {
|
||||||
|
this.genTableMapper = genTableMapper;
|
||||||
|
this.genTableColumnMapper = genTableColumnMapper;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取代码生成地址
|
* 获取代码生成地址
|
||||||
|
@ -370,7 +374,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||||
zip.flush();
|
zip.flush();
|
||||||
zip.closeEntry();
|
zip.closeEntry();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("渲染模板失败,表名:" + table.getTableName(), e);
|
log.error("渲染模板失败,表名:{}", table.getTableName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class VelocityUtils {
|
||||||
* @return 模板列表
|
* @return 模板列表
|
||||||
*/
|
*/
|
||||||
public static List<String> getTemplateList (String tplCategory) {
|
public static List<String> getTemplateList (String tplCategory) {
|
||||||
List<String> templates = new ArrayList<String>();
|
List<String> templates = new ArrayList<>();
|
||||||
templates.add("vm/java/domain.java.vm");
|
templates.add("vm/java/domain.java.vm");
|
||||||
templates.add("vm/java/mapper.java.vm");
|
templates.add("vm/java/mapper.java.vm");
|
||||||
templates.add("vm/java/service.java.vm");
|
templates.add("vm/java/service.java.vm");
|
||||||
|
@ -213,7 +213,7 @@ public class VelocityUtils {
|
||||||
public static HashSet<String> getImportList (GenTable genTable) {
|
public static HashSet<String> getImportList (GenTable genTable) {
|
||||||
List<GenTableColumn> columns = genTable.getColumns();
|
List<GenTableColumn> columns = genTable.getColumns();
|
||||||
GenTable subGenTable = genTable.getSubTable();
|
GenTable subGenTable = genTable.getSubTable();
|
||||||
HashSet<String> importList = new HashSet<String>();
|
HashSet<String> importList = new HashSet<>();
|
||||||
if (StringUtils.isNotNull(subGenTable)) {
|
if (StringUtils.isNotNull(subGenTable)) {
|
||||||
importList.add("java.util.List");
|
importList.add("java.util.List");
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ public class VelocityUtils {
|
||||||
*/
|
*/
|
||||||
public static String getDicts (GenTable genTable) {
|
public static String getDicts (GenTable genTable) {
|
||||||
List<GenTableColumn> columns = genTable.getColumns();
|
List<GenTableColumn> columns = genTable.getColumns();
|
||||||
Set<String> dicts = new HashSet<String>();
|
Set<String> dicts = new HashSet<>();
|
||||||
addDicts(dicts, columns);
|
addDicts(dicts, columns);
|
||||||
if (StringUtils.isNotNull(genTable.getSubTable())) {
|
if (StringUtils.isNotNull(genTable.getSubTable())) {
|
||||||
List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();
|
List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class SysDeptController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("system:dept:list")
|
@RequiresPermissions("system:dept:list")
|
||||||
@GetMapping("/list/exclude/{deptId}")
|
@GetMapping("/list/exclude/{deptId}")
|
||||||
public Result excludeChild (@PathVariable(value = "deptId", required = false) Long deptId) {
|
public Result<List<SysDept>> excludeChild (@PathVariable(value = "deptId", required = false) Long deptId) {
|
||||||
List<SysDept> deptList = deptService.queryList(SysDeptPageQueryModel.builder().build());
|
List<SysDept> deptList = deptService.queryList(SysDeptPageQueryModel.builder().build());
|
||||||
deptList.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId));
|
deptList.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId));
|
||||||
return success(deptList);
|
return success(deptList);
|
||||||
|
@ -61,7 +61,7 @@ public class SysDeptController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("system:dept:query")
|
@RequiresPermissions("system:dept:query")
|
||||||
@GetMapping(value = "/{deptId}")
|
@GetMapping(value = "/{deptId}")
|
||||||
public Result getInfo (@PathVariable("deptId") Long deptId) {
|
public Result<SysDept> getInfo (@PathVariable("deptId") Long deptId) {
|
||||||
deptService.checkDeptDataScope(deptId);
|
deptService.checkDeptDataScope(deptId);
|
||||||
return success(deptService.selectDeptById(deptId));
|
return success(deptService.selectDeptById(deptId));
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class SysDictDataController extends BaseController {
|
||||||
public Result<DataPageResp<SysDictDataListResp>> list (@RequestBody SysDictDataListReq sysDictDataListReq) {
|
public Result<DataPageResp<SysDictDataListResp>> list (@RequestBody SysDictDataListReq sysDictDataListReq) {
|
||||||
List<SysDictData> sysDictDataList = dictDataService.selectDictDataList(SysDictDataPageQueryModel.reqBuild(sysDictDataListReq)).getDataList();
|
List<SysDictData> sysDictDataList = dictDataService.selectDictDataList(SysDictDataPageQueryModel.reqBuild(sysDictDataListReq)).getDataList();
|
||||||
List<SysDictDataListResp> sysDictDataListRespList = sysDictDataList.stream().map(
|
List<SysDictDataListResp> sysDictDataListRespList = sysDictDataList.stream().map(
|
||||||
sysDictData -> SysDictDataListResp.buildResp(sysDictData)
|
SysDictDataListResp::buildResp
|
||||||
).distinct().collect(Collectors.toList());
|
).distinct().collect(Collectors.toList());
|
||||||
PageQueryModel<SysDictDataListResp> sysDictDataListRespPageQueryModel = new PageQueryModel<>();
|
PageQueryModel<SysDictDataListResp> sysDictDataListRespPageQueryModel = new PageQueryModel<>();
|
||||||
sysDictDataListRespPageQueryModel.setTotal(sysDictDataListRespList.size());
|
sysDictDataListRespPageQueryModel.setTotal(sysDictDataListRespList.size());
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class SysDictTypeController extends BaseController {
|
||||||
.stream()
|
.stream()
|
||||||
.map(SysDictTypeListResp::buildResp)
|
.map(SysDictTypeListResp::buildResp)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
ExcelUtil<SysDictTypeListResp> util = new ExcelUtil<SysDictTypeListResp>(SysDictTypeListResp.class);
|
ExcelUtil<SysDictTypeListResp> util = new ExcelUtil<>(SysDictTypeListResp.class);
|
||||||
util.exportExcel(response, dictTypeListResps, "字典类型");
|
util.exportExcel(response, dictTypeListResps, "字典类型");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class SysDictTypeController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("system:dict:query")
|
@RequiresPermissions("system:dict:query")
|
||||||
@GetMapping(value = "/{dictId}")
|
@GetMapping(value = "/{dictId}")
|
||||||
public Result getInfo (@PathVariable("dictId") Long dictId) {
|
public Result<SysDictType> getInfo (@PathVariable("dictId") Long dictId) {
|
||||||
return success(dictTypeService.selectDictTypeById(dictId));
|
return success(dictTypeService.selectDictTypeById(dictId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class SysDictTypeController extends BaseController {
|
||||||
@RequiresPermissions("system:dict:add")
|
@RequiresPermissions("system:dict:add")
|
||||||
@Log(title = "字典类型", businessType = BusinessType.INSERT)
|
@Log(title = "字典类型", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public Result add (@Validated @RequestBody SysDictTypeAddReq sysDictTypeAddReq) {
|
public Result<String> add (@Validated @RequestBody SysDictTypeAddReq sysDictTypeAddReq) {
|
||||||
if (!dictTypeService.checkDictTypeUnique(SysDictTypeAddModel.buildModel(sysDictTypeAddReq))) {
|
if (!dictTypeService.checkDictTypeUnique(SysDictTypeAddModel.buildModel(sysDictTypeAddReq))) {
|
||||||
return error("新增字典'" + sysDictTypeAddReq.getDictName() + "'失败,字典类型已存在");
|
return error("新增字典'" + sysDictTypeAddReq.getDictName() + "'失败,字典类型已存在");
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class SysDictTypeController extends BaseController {
|
||||||
@RequiresPermissions("system:dict:edit")
|
@RequiresPermissions("system:dict:edit")
|
||||||
@Log(title = "字典类型", businessType = BusinessType.UPDATE)
|
@Log(title = "字典类型", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public Result edit (@Validated @RequestBody SysDictTypeUpdReq sysDictTypeUpdReq) {
|
public Result<String> edit (@Validated @RequestBody SysDictTypeUpdReq sysDictTypeUpdReq) {
|
||||||
if (!dictTypeService.checkDictTypeUnique(SysDictTypeUpdModel.buildUpdModel(sysDictTypeUpdReq))) {
|
if (!dictTypeService.checkDictTypeUnique(SysDictTypeUpdModel.buildUpdModel(sysDictTypeUpdReq))) {
|
||||||
return error("修改字典'" + sysDictTypeUpdReq.getDictName() + "'失败,字典类型已存在");
|
return error("修改字典'" + sysDictTypeUpdReq.getDictName() + "'失败,字典类型已存在");
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ public class SysDictTypeController extends BaseController {
|
||||||
@RequiresPermissions("system:dict:remove")
|
@RequiresPermissions("system:dict:remove")
|
||||||
@Log(title = "字典类型", businessType = BusinessType.DELETE)
|
@Log(title = "字典类型", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{dictIds}")
|
@DeleteMapping("/{dictIds}")
|
||||||
public Result remove (@PathVariable("dictIds") List<Long> dictIds) {
|
public Result<String> remove (@PathVariable("dictIds") List<Long> dictIds) {
|
||||||
dictTypeService.deleteDictTypeByIds(dictIds);
|
dictTypeService.deleteDictTypeByIds(dictIds);
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ public class SysDictTypeController extends BaseController {
|
||||||
@RequiresPermissions("system:dict:remove")
|
@RequiresPermissions("system:dict:remove")
|
||||||
@Log(title = "字典类型", businessType = BusinessType.CLEAN)
|
@Log(title = "字典类型", businessType = BusinessType.CLEAN)
|
||||||
@DeleteMapping("/refreshCache")
|
@DeleteMapping("/refreshCache")
|
||||||
public Result refreshCache () {
|
public Result<String> refreshCache () {
|
||||||
dictTypeService.resetDictCache();
|
dictTypeService.resetDictCache();
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ public class SysDictTypeController extends BaseController {
|
||||||
* 获取字典选择框列表
|
* 获取字典选择框列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/optionselect")
|
@GetMapping("/optionselect")
|
||||||
public Result optionselect () {
|
public Result<List<SysDictType>> optionselect () {
|
||||||
List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll();
|
List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll();
|
||||||
return success(dictTypes);
|
return success(dictTypes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,11 +33,15 @@ import java.util.List;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/logininfor")
|
@RequestMapping("/logininfor")
|
||||||
public class SysLogininforController extends BaseController {
|
public class SysLogininforController extends BaseController {
|
||||||
@Autowired
|
private final SysLogininforService logininforService;
|
||||||
private SysLogininforService logininforService;
|
|
||||||
|
private final RedisService redisService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
public SysLogininforController(SysLogininforService logininforService, RedisService redisService) {
|
||||||
|
this.logininforService = logininforService;
|
||||||
|
this.redisService = redisService;
|
||||||
|
}
|
||||||
|
|
||||||
@RequiresPermissions("system:logininfor:list")
|
@RequiresPermissions("system:logininfor:list")
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
|
@ -60,14 +64,14 @@ public class SysLogininforController extends BaseController {
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export (HttpServletResponse response, SysLogininforListReq sysLogininforListReq) {
|
public void export (HttpServletResponse response, SysLogininforListReq sysLogininforListReq) {
|
||||||
List<SysLogininfor> sysLogininforList = logininforService.exportQuery(SysLogininforExportModel.reqBuild(sysLogininforListReq));
|
List<SysLogininfor> sysLogininforList = logininforService.exportQuery(SysLogininforExportModel.reqBuild(sysLogininforListReq));
|
||||||
ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
|
ExcelUtil<SysLogininfor> util = new ExcelUtil<>(SysLogininfor.class);
|
||||||
util.exportExcel(response, sysLogininforList, "登录日志");
|
util.exportExcel(response, sysLogininforList, "登录日志");
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresPermissions("system:logininfor:remove")
|
@RequiresPermissions("system:logininfor:remove")
|
||||||
@Log(title = "登录日志", businessType = BusinessType.DELETE)
|
@Log(title = "登录日志", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{infoIds}")
|
@DeleteMapping("/{infoIds}")
|
||||||
public Result remove (@PathVariable("infoIds") List<Long> infoIds) {
|
public Result<String> remove (@PathVariable("infoIds") List<Long> infoIds) {
|
||||||
logininforService.deleteLogininforByIds(infoIds);
|
logininforService.deleteLogininforByIds(infoIds);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
@ -75,22 +79,22 @@ public class SysLogininforController extends BaseController {
|
||||||
@RequiresPermissions("system:logininfor:remove")
|
@RequiresPermissions("system:logininfor:remove")
|
||||||
@Log(title = "登录日志", businessType = BusinessType.DELETE)
|
@Log(title = "登录日志", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/clean")
|
@DeleteMapping("/clean")
|
||||||
public Result clean () {
|
public Result<String> clean () {
|
||||||
logininforService.cleanLogininfor();
|
logininforService.cleanLogininfor();
|
||||||
return success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresPermissions("system:logininfor:unlock")
|
@RequiresPermissions("system:logininfor:unlock")
|
||||||
@Log(title = "账户解锁", businessType = BusinessType.OTHER)
|
@Log(title = "账户解锁", businessType = BusinessType.OTHER)
|
||||||
@GetMapping("/unlock/{userName}")
|
@GetMapping("/unlock/{userName}")
|
||||||
public Result unlock (@PathVariable("userName") String userName) {
|
public Result<String> unlock (@PathVariable("userName") String userName) {
|
||||||
redisService.deleteObject(CacheConstants.PWD_ERR_CNT_KEY + userName);
|
redisService.deleteObject(CacheConstants.PWD_ERR_CNT_KEY + userName);
|
||||||
return success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@InnerAuth*/
|
/*@InnerAuth*/
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public Result add (@RequestBody SysLogininforAddReq logininforAddReq) {
|
public Result<String> add (@RequestBody SysLogininforAddReq logininforAddReq) {
|
||||||
logininforService.insertLogininfor(SysLogininforAddModel.of(logininforAddReq));
|
logininforService.insertLogininfor(SysLogininforAddModel.of(logininforAddReq));
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import com.muyu.system.domain.rep.SysMenuListReq;
|
||||||
import com.muyu.system.domain.rep.SysMenuUpdReq;
|
import com.muyu.system.domain.rep.SysMenuUpdReq;
|
||||||
import com.muyu.system.domain.resp.RoleMenuTreeResp;
|
import com.muyu.system.domain.resp.RoleMenuTreeResp;
|
||||||
import com.muyu.system.domain.resp.SysMenuListResp;
|
import com.muyu.system.domain.resp.SysMenuListResp;
|
||||||
|
import com.muyu.system.domain.vo.RouterVo;
|
||||||
|
import com.muyu.system.domain.vo.TreeSelect;
|
||||||
import com.muyu.system.service.SysMenuService;
|
import com.muyu.system.service.SysMenuService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -53,7 +55,7 @@ public class SysMenuController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("system:menu:query")
|
@RequiresPermissions("system:menu:query")
|
||||||
@GetMapping(value = "/{menuId}")
|
@GetMapping(value = "/{menuId}")
|
||||||
public Result getInfo (@PathVariable("menuId") Long menuId) {
|
public Result<SysMenu> getInfo (@PathVariable("menuId") Long menuId) {
|
||||||
return success(menuService.selectMenuById(menuId));
|
return success(menuService.selectMenuById(menuId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +63,7 @@ public class SysMenuController extends BaseController {
|
||||||
* 获取菜单下拉树列表
|
* 获取菜单下拉树列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/treeselect")
|
@GetMapping("/treeselect")
|
||||||
public Result treeselect (SysMenuListReq sysMenuListReq) {
|
public Result<List<TreeSelect>> treeselect (SysMenuListReq sysMenuListReq) {
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
List<SysMenuListModel> sysMenus = menuService.selectMenuList(SysMenuListModel.of(sysMenuListReq), userId);
|
List<SysMenuListModel> sysMenus = menuService.selectMenuList(SysMenuListModel.of(sysMenuListReq), userId);
|
||||||
return success(menuService.buildMenuTreeSelect(sysMenus));
|
return success(menuService.buildMenuTreeSelect(sysMenus));
|
||||||
|
@ -71,7 +73,7 @@ public class SysMenuController extends BaseController {
|
||||||
* 加载对应角色菜单列表树
|
* 加载对应角色菜单列表树
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
||||||
public Result roleMenuTreeselect (@PathVariable("roleId") Long roleId) {
|
public Result<RoleMenuTreeResp> roleMenuTreeselect (@PathVariable("roleId") Long roleId) {
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
List<SysMenuListModel> menus = menuService.selectMenuList(userId);
|
List<SysMenuListModel> menus = menuService.selectMenuList(userId);
|
||||||
return Result.success(
|
return Result.success(
|
||||||
|
@ -88,7 +90,7 @@ public class SysMenuController extends BaseController {
|
||||||
@RequiresPermissions("system:menu:add")
|
@RequiresPermissions("system:menu:add")
|
||||||
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
|
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public Result add (@Validated @RequestBody SysMenuAddReq sysMenuAddReq) {
|
public Result<String> add (@Validated @RequestBody SysMenuAddReq sysMenuAddReq) {
|
||||||
SysMenuAddModel sysMenuAddModel = SysMenuAddModel.of(sysMenuAddReq);
|
SysMenuAddModel sysMenuAddModel = SysMenuAddModel.of(sysMenuAddReq);
|
||||||
if (!menuService.checkMenuNameUnique(sysMenuAddModel)) {
|
if (!menuService.checkMenuNameUnique(sysMenuAddModel)) {
|
||||||
return error("新增菜单'" + sysMenuAddModel.getMenuName() + "'失败,菜单名称已存在");
|
return error("新增菜单'" + sysMenuAddModel.getMenuName() + "'失败,菜单名称已存在");
|
||||||
|
@ -107,7 +109,7 @@ public class SysMenuController extends BaseController {
|
||||||
@RequiresPermissions("system:menu:edit")
|
@RequiresPermissions("system:menu:edit")
|
||||||
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
|
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public Result edit (@Validated @RequestBody SysMenuUpdReq sysMenuUpdReq) {
|
public Result<String> edit (@Validated @RequestBody SysMenuUpdReq sysMenuUpdReq) {
|
||||||
SysMenuAddModel sysMenuAddModel = SysMenuAddModel.buildSysMenuAddModel(sysMenuUpdReq);
|
SysMenuAddModel sysMenuAddModel = SysMenuAddModel.buildSysMenuAddModel(sysMenuUpdReq);
|
||||||
if (!menuService.checkMenuNameUnique(sysMenuAddModel)) {
|
if (!menuService.checkMenuNameUnique(sysMenuAddModel)) {
|
||||||
return error("新增菜单'" + sysMenuAddModel.getMenuName() + "'失败,菜单名称已存在");
|
return error("新增菜单'" + sysMenuAddModel.getMenuName() + "'失败,菜单名称已存在");
|
||||||
|
@ -127,7 +129,7 @@ public class SysMenuController extends BaseController {
|
||||||
@RequiresPermissions("system:menu:remove")
|
@RequiresPermissions("system:menu:remove")
|
||||||
@Log(title = "菜单管理", businessType = BusinessType.DELETE)
|
@Log(title = "菜单管理", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{menuId}")
|
@DeleteMapping("/{menuId}")
|
||||||
public Result remove (@PathVariable("menuId") Long menuId) {
|
public Result<String> remove (@PathVariable("menuId") Long menuId) {
|
||||||
if (menuService.hasChildByMenuId(menuId)) {
|
if (menuService.hasChildByMenuId(menuId)) {
|
||||||
return warn("存在子菜单,不允许删除");
|
return warn("存在子菜单,不允许删除");
|
||||||
}
|
}
|
||||||
|
@ -144,7 +146,7 @@ public class SysMenuController extends BaseController {
|
||||||
* @return 路由信息
|
* @return 路由信息
|
||||||
*/
|
*/
|
||||||
@GetMapping("getRouters")
|
@GetMapping("getRouters")
|
||||||
public Result getRouters () {
|
public Result<List<RouterVo>> getRouters () {
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
|
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
|
||||||
return success(menuService.buildMenus(menus));
|
return success(menuService.buildMenus(menus));
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class SysPostController extends BaseController {
|
||||||
public void export (HttpServletResponse response, SysPostListReq postListReq) {
|
public void export (HttpServletResponse response, SysPostListReq postListReq) {
|
||||||
// TODO 导出重写
|
// TODO 导出重写
|
||||||
PageQueryModel<SysPostListModel> sysPostPageQueryModel = postService.getList(SysPostPageQueryModel.reqBuild(postListReq));
|
PageQueryModel<SysPostListModel> sysPostPageQueryModel = postService.getList(SysPostPageQueryModel.reqBuild(postListReq));
|
||||||
ExcelUtil<SysPostListResp> util = new ExcelUtil<SysPostListResp>(SysPostListResp.class);
|
ExcelUtil<SysPostListResp> util = new ExcelUtil<>(SysPostListResp.class);
|
||||||
util.exportExcel(response, sysPostPageQueryModel.getDataList().stream().map(SysPostListResp::listBuild).toList(), "岗位数据");
|
util.exportExcel(response, sysPostPageQueryModel.getDataList().stream().map(SysPostListResp::listBuild).toList(), "岗位数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,20 +29,24 @@ import java.util.Arrays;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/user/profile")
|
@RequestMapping("/user/profile")
|
||||||
public class SysProfileController extends BaseController {
|
public class SysProfileController extends BaseController {
|
||||||
@Autowired
|
private final SysUserService userService;
|
||||||
private SysUserService userService;
|
|
||||||
|
private final TokenService tokenService;
|
||||||
|
|
||||||
|
private final RemoteFileService remoteFileService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenService tokenService;
|
public SysProfileController(SysUserService userService, TokenService tokenService, RemoteFileService remoteFileService) {
|
||||||
|
this.userService = userService;
|
||||||
@Autowired
|
this.tokenService = tokenService;
|
||||||
private RemoteFileService remoteFileService;
|
this.remoteFileService = remoteFileService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 个人信息
|
* 个人信息
|
||||||
*/
|
*/
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public Result profile () {
|
public Result<ProfileResp> profile () {
|
||||||
String username = SecurityUtils.getUsername();
|
String username = SecurityUtils.getUsername();
|
||||||
SysUser user = userService.selectUserByUserName(username);
|
SysUser user = userService.selectUserByUserName(username);
|
||||||
return Result.success(
|
return Result.success(
|
||||||
|
@ -106,7 +110,7 @@ public class SysProfileController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
||||||
@PostMapping("/avatar")
|
@PostMapping("/avatar")
|
||||||
public Result avatar (@RequestParam("avatarfile") MultipartFile file) {
|
public Result<String> avatar (@RequestParam("avatarfile") MultipartFile file) {
|
||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty()) {
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
String extension = FileTypeUtils.getExtension(file);
|
String extension = FileTypeUtils.getExtension(file);
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class SysRoleController extends BaseController {
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export (HttpServletResponse response, SysRole role) {
|
public void export (HttpServletResponse response, SysRole role) {
|
||||||
List<SysRole> list = roleService.selectRoleList(role);
|
List<SysRole> list = roleService.selectRoleList(role);
|
||||||
ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
|
ExcelUtil<SysRole> util = new ExcelUtil<>(SysRole.class);
|
||||||
util.exportExcel(response, list, "角色数据");
|
util.exportExcel(response, list, "角色数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class SysRoleController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("system:role:query")
|
@RequiresPermissions("system:role:query")
|
||||||
@GetMapping(value = "/{roleId}")
|
@GetMapping(value = "/{roleId}")
|
||||||
public Result getInfo (@PathVariable("roleId") Long roleId) {
|
public Result<SysRole> getInfo (@PathVariable("roleId") Long roleId) {
|
||||||
roleService.checkRoleDataScope(roleId);
|
roleService.checkRoleDataScope(roleId);
|
||||||
return success(roleService.selectRoleById(roleId));
|
return success(roleService.selectRoleById(roleId));
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ public class SysRoleController extends BaseController {
|
||||||
@RequiresPermissions("system:role:edit")
|
@RequiresPermissions("system:role:edit")
|
||||||
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public Result edit (@Validated @RequestBody SysRole role) {
|
public Result<String> edit (@Validated @RequestBody SysRole role) {
|
||||||
roleService.checkRoleAllowed(role);
|
roleService.checkRoleAllowed(role);
|
||||||
roleService.checkRoleDataScope(role.getRoleId());
|
roleService.checkRoleDataScope(role.getRoleId());
|
||||||
if (!roleService.checkRoleNameUnique(role)) {
|
if (!roleService.checkRoleNameUnique(role)) {
|
||||||
|
@ -173,7 +173,7 @@ public class SysRoleController extends BaseController {
|
||||||
@RequiresPermissions("system:role:edit")
|
@RequiresPermissions("system:role:edit")
|
||||||
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
||||||
@PutMapping("/authUser/cancel")
|
@PutMapping("/authUser/cancel")
|
||||||
public Result cancelAuthUser (@RequestBody SysUserRole userRole) {
|
public Result<String> cancelAuthUser (@RequestBody SysUserRole userRole) {
|
||||||
roleService.deleteAuthUser(userRole);
|
roleService.deleteAuthUser(userRole);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.muyu.common.redis.service.RedisService;
|
||||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||||
import com.muyu.common.system.domain.LoginUser;
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
import com.muyu.system.domain.SysUserOnline;
|
import com.muyu.system.domain.SysUserOnline;
|
||||||
|
import com.muyu.system.domain.rep.SysUserOnlineListReq;
|
||||||
import com.muyu.system.service.SysUserOnlineService;
|
import com.muyu.system.service.SysUserOnlineService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -36,9 +37,11 @@ public class SysUserOnlineController extends BaseController {
|
||||||
|
|
||||||
@RequiresPermissions("monitor:online:list")
|
@RequiresPermissions("monitor:online:list")
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
public Result<DataPageResp<SysUserOnline>> list (@RequestBody String ipaddr, String userName) {
|
public Result<DataPageResp<SysUserOnline>> list (@RequestBody SysUserOnlineListReq sysUserOnlineListReq) {
|
||||||
|
String ipaddr = sysUserOnlineListReq.getIpaddr();
|
||||||
|
String userName = sysUserOnlineListReq.getUserName();
|
||||||
Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
|
Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
|
||||||
List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
|
List<SysUserOnline> userOnlineList = new ArrayList<>();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
LoginUser user = redisService.getCacheObject(key);
|
LoginUser user = redisService.getCacheObject(key);
|
||||||
if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) {
|
if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) {
|
||||||
|
@ -53,7 +56,7 @@ public class SysUserOnlineController extends BaseController {
|
||||||
}
|
}
|
||||||
Collections.reverse(userOnlineList);
|
Collections.reverse(userOnlineList);
|
||||||
userOnlineList.removeAll(Collections.singleton(null));
|
userOnlineList.removeAll(Collections.singleton(null));
|
||||||
return Result.success(new DataPageResp(0, userOnlineList));
|
return Result.success(new DataPageResp<>(userOnlineList.size(), userOnlineList));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +65,7 @@ public class SysUserOnlineController extends BaseController {
|
||||||
@RequiresPermissions("monitor:online:forceLogout")
|
@RequiresPermissions("monitor:online:forceLogout")
|
||||||
@Log(title = "在线用户", businessType = BusinessType.FORCE)
|
@Log(title = "在线用户", businessType = BusinessType.FORCE)
|
||||||
@DeleteMapping("/{tokenId}")
|
@DeleteMapping("/{tokenId}")
|
||||||
public Result forceLogout (@PathVariable("tokenId") String tokenId) {
|
public Result<String> forceLogout (@PathVariable("tokenId") String tokenId) {
|
||||||
redisService.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
|
redisService.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class SysMenu extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<SysMenu> children = new ArrayList<SysMenu>();
|
private List<SysMenu> children = new ArrayList<>();
|
||||||
|
|
||||||
@NotBlank(message = "菜单名称不能为空")
|
@NotBlank(message = "菜单名称不能为空")
|
||||||
@Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符")
|
@Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符")
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class SysMenuAddModel {
|
||||||
/**
|
/**
|
||||||
* 子菜单
|
* 子菜单
|
||||||
*/
|
*/
|
||||||
private List<SysMenu> children = new ArrayList<SysMenu>();
|
private List<SysMenu> children = new ArrayList<>();
|
||||||
|
|
||||||
public static SysMenuAddModel of(SysMenuAddReq sysMenuAddReq) {
|
public static SysMenuAddModel of(SysMenuAddReq sysMenuAddReq) {
|
||||||
return SysMenuAddModel.builder()
|
return SysMenuAddModel.builder()
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class SysMenuListModel {
|
||||||
/**
|
/**
|
||||||
* 子菜单
|
* 子菜单
|
||||||
*/
|
*/
|
||||||
private List<SysMenu> children = new ArrayList<SysMenu>();
|
private List<SysMenu> children = new ArrayList<>();
|
||||||
public static SysMenuListModel of(SysMenuListReq sysMenuListReq) {
|
public static SysMenuListModel of(SysMenuListReq sysMenuListReq) {
|
||||||
return SysMenuListModel.builder()
|
return SysMenuListModel.builder()
|
||||||
.menuId(sysMenuListReq.getMenuId())
|
.menuId(sysMenuListReq.getMenuId())
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class SysMenuUpdModel {
|
||||||
/**
|
/**
|
||||||
* 子菜单
|
* 子菜单
|
||||||
*/
|
*/
|
||||||
private List<SysMenu> children = new ArrayList<SysMenu>();
|
private List<SysMenu> children = new ArrayList<>();
|
||||||
|
|
||||||
public static SysMenuUpdModel of(SysMenuUpdReq sysMenuUpdReq) {
|
public static SysMenuUpdModel of(SysMenuUpdReq sysMenuUpdReq) {
|
||||||
return SysMenuUpdModel.builder()
|
return SysMenuUpdModel.builder()
|
||||||
|
|
|
@ -108,6 +108,6 @@ public class SysMenuAddReq {
|
||||||
/**
|
/**
|
||||||
* 子菜单
|
* 子菜单
|
||||||
*/
|
*/
|
||||||
private List<SysMenu> children = new ArrayList<SysMenu>();
|
private List<SysMenu> children = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,5 +104,5 @@ public class SysMenuListReq extends PageReq {
|
||||||
/**
|
/**
|
||||||
* 子菜单
|
* 子菜单
|
||||||
*/
|
*/
|
||||||
private List<SysMenu> children = new ArrayList<SysMenu>();
|
private List<SysMenu> children = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,6 @@ public class SysMenuUpdReq {
|
||||||
/**
|
/**
|
||||||
* 子菜单
|
* 子菜单
|
||||||
*/
|
*/
|
||||||
private List<SysMenu> children = new ArrayList<SysMenu>();
|
private List<SysMenu> children = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.muyu.system.domain.rep;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dongzeliang
|
||||||
|
* @version 1.0
|
||||||
|
* @description: 在线用户列表查询
|
||||||
|
* @date 2025/2/26 21:57
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SysUserOnlineListReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IP地址
|
||||||
|
*/
|
||||||
|
private String ipaddr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名称
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
}
|
|
@ -102,7 +102,7 @@ public class SysMenuListResp {
|
||||||
/**
|
/**
|
||||||
* 子菜单
|
* 子菜单
|
||||||
*/
|
*/
|
||||||
private List<SysMenu> children = new ArrayList<SysMenu>();
|
private List<SysMenu> children = new ArrayList<>();
|
||||||
|
|
||||||
public static SysMenuListResp buildSysMenuListResp(SysMenuListModel sysMenuListModel){
|
public static SysMenuListResp buildSysMenuListResp(SysMenuListModel sysMenuListModel){
|
||||||
return SysMenuListResp.builder()
|
return SysMenuListResp.builder()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.system.domain.resp;
|
||||||
|
|
||||||
import com.muyu.common.system.domain.SysRole;
|
import com.muyu.common.system.domain.SysRole;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
|
import com.muyu.system.domain.SysPost;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
@ -28,7 +29,7 @@ public class UserDetailInfoResp {
|
||||||
/**
|
/**
|
||||||
* 岗位集合
|
* 岗位集合
|
||||||
*/
|
*/
|
||||||
private List posts;
|
private List<SysPost> posts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户信息
|
* 用户信息
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.common.system.domain.SysDept;
|
import com.muyu.common.system.domain.SysDept;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -11,6 +12,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface SysDeptMapper extends BaseMapper<SysDept> {
|
public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,12 +2,14 @@ package com.muyu.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.common.system.domain.SysLogininfor;
|
import com.muyu.common.system.domain.SysLogininfor;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统访问日志情况信息 数据层
|
* 系统访问日志情况信息 数据层
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface SysLogininforMapper extends BaseMapper<SysLogininfor> {
|
public interface SysLogininforMapper extends BaseMapper<SysLogininfor> {
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.system.domain.SysMenu;
|
import com.muyu.system.domain.SysMenu;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -11,6 +12,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,12 +2,15 @@ package com.muyu.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.common.system.domain.SysOperLog;
|
import com.muyu.common.system.domain.SysOperLog;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作日志 数据层
|
* 操作日志 数据层
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface SysOperLogMapper extends BaseMapper<SysOperLog> {
|
public interface SysOperLogMapper extends BaseMapper<SysOperLog> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.system.domain.SysPost;
|
import com.muyu.system.domain.SysPost;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface SysPostMapper extends BaseMapper<SysPost> {
|
public interface SysPostMapper extends BaseMapper<SysPost> {
|
||||||
/**
|
/**
|
||||||
* 查询岗位数据集合
|
* 查询岗位数据集合
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.common.system.domain.SysRole;
|
import com.muyu.common.system.domain.SysRole;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface SysRoleMapper extends BaseMapper<SysRole> {
|
public interface SysRoleMapper extends BaseMapper<SysRole> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface SysUserMapper extends BaseMapper<SysUser> {
|
public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||||
/**
|
/**
|
||||||
* 根据条件分页查询用户列表
|
* 根据条件分页查询用户列表
|
||||||
|
|
|
@ -2,12 +2,15 @@ package com.muyu.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.system.domain.SysUserRole;
|
import com.muyu.system.domain.SysUserRole;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户与角色关联表 数据层
|
* 用户与角色关联表 数据层
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
|
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,18 +13,18 @@ public interface SysPermissionService {
|
||||||
/**
|
/**
|
||||||
* 获取角色数据权限
|
* 获取角色数据权限
|
||||||
*
|
*
|
||||||
* @param userId 用户Id
|
* @param sysUser 用户
|
||||||
*
|
*
|
||||||
* @return 角色权限信息
|
* @return 角色权限信息
|
||||||
*/
|
*/
|
||||||
public Set<String> getRolePermission (SysUser user);
|
public Set<String> getRolePermission (SysUser sysUser);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取菜单数据权限
|
* 获取菜单数据权限
|
||||||
*
|
*
|
||||||
* @param userId 用户Id
|
* @param sysUser 用户
|
||||||
*
|
*
|
||||||
* @return 菜单权限信息
|
* @return 菜单权限信息
|
||||||
*/
|
*/
|
||||||
public Set<String> getMenuPermission (SysUser user);
|
public Set<String> getMenuPermission (SysUser sysUser);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,18 @@ import java.util.stream.Collectors;
|
||||||
@Service
|
@Service
|
||||||
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
implements SysDeptService {
|
implements SysDeptService {
|
||||||
@Autowired
|
private final SysDeptMapper deptMapper;
|
||||||
private SysDeptMapper deptMapper;
|
|
||||||
|
private final SysRoleMapper roleMapper;
|
||||||
|
|
||||||
|
private final SysUserService sysUserService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysRoleMapper roleMapper;
|
public SysDeptServiceImpl(SysDeptMapper deptMapper, SysRoleMapper roleMapper, SysUserService sysUserService) {
|
||||||
|
this.deptMapper = deptMapper;
|
||||||
@Autowired
|
this.roleMapper = roleMapper;
|
||||||
private SysUserService sysUserService;
|
this.sysUserService = sysUserService;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysDept> queryList(SysDeptPageQueryModel sysDeptPageQueryModel) {
|
public List<SysDept> queryList(SysDeptPageQueryModel sysDeptPageQueryModel) {
|
||||||
|
|
|
@ -26,8 +26,12 @@ import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class SysLogininforServiceImpl extends ServiceImpl<SysLogininforMapper, SysLogininfor> implements SysLogininforService {
|
public class SysLogininforServiceImpl extends ServiceImpl<SysLogininforMapper, SysLogininfor> implements SysLogininforService {
|
||||||
|
|
||||||
|
private final SysLogininforMapper logininforMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysLogininforMapper logininforMapper;
|
public SysLogininforServiceImpl(SysLogininforMapper logininforMapper) {
|
||||||
|
this.logininforMapper = logininforMapper;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增系统登录日志
|
* 新增系统登录日志
|
||||||
|
|
|
@ -34,14 +34,18 @@ import java.util.stream.Collectors;
|
||||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||||
public static final String PREMISSION_STRING = "perms[\"{0}\"]";
|
public static final String PREMISSION_STRING = "perms[\"{0}\"]";
|
||||||
|
|
||||||
@Autowired
|
private final SysMenuMapper menuMapper;
|
||||||
private SysMenuMapper menuMapper;
|
|
||||||
|
private final SysRoleMapper roleMapper;
|
||||||
|
|
||||||
|
private final SysRoleMenuService sysRoleMenuService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysRoleMapper roleMapper;
|
public SysMenuServiceImpl(SysMenuMapper menuMapper, SysRoleMapper roleMapper, SysRoleMenuService sysRoleMenuService) {
|
||||||
|
this.menuMapper = menuMapper;
|
||||||
@Autowired
|
this.roleMapper = roleMapper;
|
||||||
private SysRoleMenuService sysRoleMenuService;
|
this.sysRoleMenuService = sysRoleMenuService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户查询系统菜单列表
|
* 根据用户查询系统菜单列表
|
||||||
|
@ -164,7 +168,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<RouterVo> buildMenus (List<SysMenu> menus) {
|
public List<RouterVo> buildMenus (List<SysMenu> menus) {
|
||||||
List<RouterVo> routers = new LinkedList<RouterVo>();
|
List<RouterVo> routers = new LinkedList<>();
|
||||||
for (SysMenu menu : menus) {
|
for (SysMenu menu : menus) {
|
||||||
RouterVo router = new RouterVo();
|
RouterVo router = new RouterVo();
|
||||||
router.setHidden("1".equals(menu.getVisible()));
|
router.setHidden("1".equals(menu.getVisible()));
|
||||||
|
@ -187,7 +191,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
router.setChildren(buildMenus(cMenus));
|
router.setChildren(buildMenus(cMenus));
|
||||||
} else if (isMenuFrame(menu)) {
|
} else if (isMenuFrame(menu)) {
|
||||||
router.setMeta(null);
|
router.setMeta(null);
|
||||||
List<RouterVo> childrenList = new ArrayList<RouterVo>();
|
List<RouterVo> childrenList = new ArrayList<>();
|
||||||
RouterVo children = new RouterVo();
|
RouterVo children = new RouterVo();
|
||||||
children.setPath(menu.getPath());
|
children.setPath(menu.getPath());
|
||||||
children.setComponent(menu.getComponent());
|
children.setComponent(menu.getComponent());
|
||||||
|
@ -206,7 +210,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
} else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) {
|
} else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) {
|
||||||
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
|
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
|
||||||
router.setPath("/");
|
router.setPath("/");
|
||||||
List<RouterVo> childrenList = new ArrayList<RouterVo>();
|
List<RouterVo> childrenList = new ArrayList<>();
|
||||||
RouterVo children = new RouterVo();
|
RouterVo children = new RouterVo();
|
||||||
String routerPath = innerLinkReplaceEach(menu.getPath());
|
String routerPath = innerLinkReplaceEach(menu.getPath());
|
||||||
children.setPath(routerPath);
|
children.setPath(routerPath);
|
||||||
|
@ -230,10 +234,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysMenu> buildMenuTree (List<SysMenu> menus) {
|
public List<SysMenu> buildMenuTree (List<SysMenu> menus) {
|
||||||
List<SysMenu> returnList = new ArrayList<SysMenu>();
|
List<SysMenu> returnList = new ArrayList<>();
|
||||||
List<Long> tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList());
|
List<Long> tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList());
|
||||||
for (Iterator<SysMenu> iterator = menus.iterator() ; iterator.hasNext() ; ) {
|
for (SysMenu menu : menus) {
|
||||||
SysMenu menu = (SysMenu) iterator.next();
|
|
||||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
// 如果是顶级节点, 遍历该父节点的所有子节点
|
||||||
if (!tempList.contains(menu.getParentId())) {
|
if (!tempList.contains(menu.getParentId())) {
|
||||||
recursionFn(menus, menu);
|
recursionFn(menus, menu);
|
||||||
|
@ -461,9 +464,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public List<SysMenu> getChildPerms (List<SysMenu> list, int parentId) {
|
public List<SysMenu> getChildPerms (List<SysMenu> list, int parentId) {
|
||||||
List<SysMenu> returnList = new ArrayList<SysMenu>();
|
List<SysMenu> returnList = new ArrayList<>();
|
||||||
for (Iterator<SysMenu> iterator = list.iterator() ; iterator.hasNext() ; ) {
|
for (SysMenu t : list) {
|
||||||
SysMenu t = iterator.next();
|
|
||||||
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
||||||
if (t.getParentId() == parentId) {
|
if (t.getParentId() == parentId) {
|
||||||
recursionFn(list, t);
|
recursionFn(list, t);
|
||||||
|
@ -494,10 +496,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
* 得到子节点列表
|
* 得到子节点列表
|
||||||
*/
|
*/
|
||||||
private List<SysMenu> getChildList (List<SysMenu> list, SysMenu t) {
|
private List<SysMenu> getChildList (List<SysMenu> list, SysMenu t) {
|
||||||
List<SysMenu> tlist = new ArrayList<SysMenu>();
|
List<SysMenu> tlist = new ArrayList<>();
|
||||||
Iterator<SysMenu> it = list.iterator();
|
for (SysMenu n : list) {
|
||||||
while (it.hasNext()) {
|
|
||||||
SysMenu n = (SysMenu) it.next();
|
|
||||||
if (n.getParentId().longValue() == t.getMenuId().longValue()) {
|
if (n.getParentId().longValue() == t.getMenuId().longValue()) {
|
||||||
tlist.add(n);
|
tlist.add(n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,6 @@ import com.muyu.system.service.SysOperLogService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@ -26,8 +24,12 @@ import java.util.Objects;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements SysOperLogService {
|
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements SysOperLogService {
|
||||||
|
private final SysOperLogMapper operLogMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysOperLogMapper operLogMapper;
|
public SysOperLogServiceImpl(SysOperLogMapper operLogMapper) {
|
||||||
|
this.operLogMapper = operLogMapper;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增操作日志
|
* 新增操作日志
|
||||||
|
|
|
@ -29,18 +29,18 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
||||||
/**
|
/**
|
||||||
* 获取角色数据权限
|
* 获取角色数据权限
|
||||||
*
|
*
|
||||||
* @param userId 用户Id
|
* @param sysUser 用户Id
|
||||||
*
|
*
|
||||||
* @return 角色权限信息
|
* @return 角色权限信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getRolePermission (SysUser user) {
|
public Set<String> getRolePermission (SysUser sysUser) {
|
||||||
Set<String> roles = new HashSet<String>();
|
Set<String> roles = new HashSet<String>();
|
||||||
// 管理员拥有所有权限
|
// 管理员拥有所有权限
|
||||||
if (user.isAdmin()) {
|
if (sysUser.isAdmin()) {
|
||||||
roles.add("admin");
|
roles.add("admin");
|
||||||
} else {
|
} else {
|
||||||
roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId()));
|
roles.addAll(roleService.selectRolePermissionByUserId(sysUser.getUserId()));
|
||||||
}
|
}
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
@ -48,18 +48,18 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
||||||
/**
|
/**
|
||||||
* 获取菜单数据权限
|
* 获取菜单数据权限
|
||||||
*
|
*
|
||||||
* @param userId 用户Id
|
* @param sysUser 用户Id
|
||||||
*
|
*
|
||||||
* @return 菜单权限信息
|
* @return 菜单权限信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getMenuPermission (SysUser user) {
|
public Set<String> getMenuPermission (SysUser sysUser) {
|
||||||
Set<String> perms = new HashSet<String>();
|
Set<String> perms = new HashSet<>();
|
||||||
// 管理员拥有所有权限
|
// 管理员拥有所有权限
|
||||||
if (user.isAdmin()) {
|
if (sysUser.isAdmin()) {
|
||||||
perms.add("*:*:*");
|
perms.add("*:*:*");
|
||||||
} else {
|
} else {
|
||||||
List<SysRole> roles = user.getRoles();
|
List<SysRole> roles = sysUser.getRoles();
|
||||||
if (!CollectionUtils.isEmpty(roles)) {
|
if (!CollectionUtils.isEmpty(roles)) {
|
||||||
// 多角色设置permissions属性,以便数据权限匹配权限
|
// 多角色设置permissions属性,以便数据权限匹配权限
|
||||||
for (SysRole role : roles) {
|
for (SysRole role : roles) {
|
||||||
|
@ -68,7 +68,7 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
||||||
perms.addAll(rolePerms);
|
perms.addAll(rolePerms);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId()));
|
perms.addAll(menuService.selectMenuPermsByUserId(sysUser.getUserId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return perms;
|
return perms;
|
||||||
|
|
|
@ -27,14 +27,15 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements SysPostService {
|
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements SysPostService {
|
||||||
@Autowired
|
private final SysPostMapper postMapper;
|
||||||
private SysPostMapper postMapper;
|
|
||||||
|
private final SysUserPostService sysUserPostService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysUserPostMapper userPostMapper;
|
public SysPostServiceImpl(SysPostMapper postMapper, SysUserPostService sysUserPostService) {
|
||||||
|
this.postMapper = postMapper;
|
||||||
@Autowired
|
this.sysUserPostService = sysUserPostService;
|
||||||
private SysUserPostService sysUserPostService;
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有岗位
|
* 查询所有岗位
|
||||||
|
|
|
@ -36,17 +36,21 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
|
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
|
||||||
@Autowired
|
private final SysRoleMapper roleMapper;
|
||||||
private SysRoleMapper roleMapper;
|
|
||||||
|
private final SysUserRoleService sysUserRoleService;
|
||||||
|
|
||||||
|
private final SysRoleMenuService sysRoleMenuService;
|
||||||
|
|
||||||
|
private final SysRoleDeptService sysRoleDeptService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysUserRoleService sysUserRoleService;
|
public SysRoleServiceImpl(SysRoleMapper roleMapper, SysUserRoleService sysUserRoleService, SysRoleMenuService sysRoleMenuService, SysRoleDeptService sysRoleDeptService) {
|
||||||
|
this.roleMapper = roleMapper;
|
||||||
@Autowired
|
this.sysUserRoleService = sysUserRoleService;
|
||||||
private SysRoleMenuService sysRoleMenuService;
|
this.sysRoleMenuService = sysRoleMenuService;
|
||||||
|
this.sysRoleDeptService = sysRoleDeptService;
|
||||||
@Autowired
|
}
|
||||||
private SysRoleDeptService sysRoleDeptService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据条件分页查询角色数据
|
* 根据条件分页查询角色数据
|
||||||
|
@ -322,7 +326,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// 新增用户与角色管理
|
// 新增用户与角色管理
|
||||||
List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
|
List<SysRoleMenu> list = new ArrayList<>();
|
||||||
for (Long menuId : role.getMenuIds()) {
|
for (Long menuId : role.getMenuIds()) {
|
||||||
SysRoleMenu rm = new SysRoleMenu();
|
SysRoleMenu rm = new SysRoleMenu();
|
||||||
rm.setRoleId(role.getRoleId());
|
rm.setRoleId(role.getRoleId());
|
||||||
|
@ -344,7 +348,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||||
public int insertRoleDept (SysRole role) {
|
public int insertRoleDept (SysRole role) {
|
||||||
int rows = 1;
|
int rows = 1;
|
||||||
// 新增角色与部门(数据权限)管理
|
// 新增角色与部门(数据权限)管理
|
||||||
List<SysRoleDept> list = new ArrayList<SysRoleDept>();
|
List<SysRoleDept> list = new ArrayList<>();
|
||||||
for (Long deptId : role.getDeptIds()) {
|
for (Long deptId : role.getDeptIds()) {
|
||||||
SysRoleDept rd = new SysRoleDept();
|
SysRoleDept rd = new SysRoleDept();
|
||||||
rd.setRoleId(role.getRoleId());
|
rd.setRoleId(role.getRoleId());
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
||||||
// from sys_user_role
|
// from sys_user_role
|
||||||
// where user_id = #{userId}
|
// where user_id = #{userId}
|
||||||
// and role_id = #{roleId}
|
// and role_id = #{roleId}
|
||||||
LambdaUpdateWrapper<SysUserRole> lambdaUpdateWrapper = new LambdaUpdateWrapper<SysUserRole>();
|
LambdaUpdateWrapper<SysUserRole> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
lambdaUpdateWrapper.eq(SysUserRole::getUserId, userRole.getUserId());
|
lambdaUpdateWrapper.eq(SysUserRole::getUserId, userRole.getUserId());
|
||||||
lambdaUpdateWrapper.eq(SysUserRole::getRoleId, userRole.getRoleId());
|
lambdaUpdateWrapper.eq(SysUserRole::getRoleId, userRole.getRoleId());
|
||||||
this.remove(lambdaUpdateWrapper);
|
this.remove(lambdaUpdateWrapper);
|
||||||
|
@ -85,7 +85,7 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteUserRole(List<Long> userIds) {
|
public void deleteUserRole(List<Long> userIds) {
|
||||||
LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper = new LambdaQueryWrapper<SysUserRole>();
|
LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
lambdaQueryWrapper.in(SysUserRole::getUserId, userIds);
|
lambdaQueryWrapper.in(SysUserRole::getUserId, userIds);
|
||||||
this.remove(lambdaQueryWrapper);
|
this.remove(lambdaQueryWrapper);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,23 +45,24 @@ import java.util.stream.Collectors;
|
||||||
@Service
|
@Service
|
||||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
||||||
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
|
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
|
||||||
@Autowired
|
protected final Validator validator;
|
||||||
protected Validator validator;
|
private final SysUserMapper userMapper;
|
||||||
@Autowired
|
private final SysRoleMapper roleMapper;
|
||||||
private SysUserMapper userMapper;
|
private final SysPostMapper postMapper;
|
||||||
@Autowired
|
private final SysUserRoleService sysUserRoleService;
|
||||||
private SysRoleMapper roleMapper;
|
private final SysUserPostService sysUserPostService;
|
||||||
@Autowired
|
private final SysConfigService configService;
|
||||||
private SysPostMapper postMapper;
|
|
||||||
@Autowired
|
|
||||||
private SysUserRoleMapper userRoleMapper;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysUserRoleService sysUserRoleService;
|
public SysUserServiceImpl(Validator validator, SysUserMapper userMapper, SysRoleMapper roleMapper, SysPostMapper postMapper, SysUserRoleService sysUserRoleService, SysUserPostService sysUserPostService, SysConfigService configService) {
|
||||||
@Autowired
|
this.validator = validator;
|
||||||
private SysUserPostService sysUserPostService;
|
this.userMapper = userMapper;
|
||||||
@Autowired
|
this.roleMapper = roleMapper;
|
||||||
private SysConfigService configService;
|
this.postMapper = postMapper;
|
||||||
|
this.sysUserRoleService = sysUserRoleService;
|
||||||
|
this.sysUserPostService = sysUserPostService;
|
||||||
|
this.configService = configService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据条件分页查询用户列表
|
* 根据条件分页查询用户列表
|
||||||
|
@ -404,7 +405,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
Long[] posts = user.getPostIds();
|
Long[] posts = user.getPostIds();
|
||||||
if (StringUtils.isNotEmpty(posts)) {
|
if (StringUtils.isNotEmpty(posts)) {
|
||||||
// 新增用户与岗位管理
|
// 新增用户与岗位管理
|
||||||
List<SysUserPost> list = new ArrayList<SysUserPost>();
|
List<SysUserPost> list = new ArrayList<>();
|
||||||
for (Long postId : posts) {
|
for (Long postId : posts) {
|
||||||
SysUserPost up = new SysUserPost();
|
SysUserPost up = new SysUserPost();
|
||||||
up.setUserId(user.getUserId());
|
up.setUserId(user.getUserId());
|
||||||
|
@ -424,7 +425,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
public void insertUserRole (Long userId, Long[] roleIds) {
|
public void insertUserRole (Long userId, Long[] roleIds) {
|
||||||
if (StringUtils.isNotEmpty(roleIds)) {
|
if (StringUtils.isNotEmpty(roleIds)) {
|
||||||
// 新增用户与角色管理
|
// 新增用户与角色管理
|
||||||
List<SysUserRole> list = new ArrayList<SysUserRole>();
|
List<SysUserRole> list = new ArrayList<>();
|
||||||
for (Long roleId : roleIds) {
|
for (Long roleId : roleIds) {
|
||||||
SysUserRole ur = new SysUserRole();
|
SysUserRole ur = new SysUserRole();
|
||||||
ur.setUserId(userId);
|
ur.setUserId(userId);
|
||||||
|
|
Loading…
Reference in New Issue