init
commit
befb80ab8a
@ -0,0 +1,18 @@
|
|||||||
|
# http://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# 空格替代Tab缩进在各种编辑工具下效果一致
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.{json,yml,yaml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
insert_final_newline = false
|
||||||
|
trim_trailing_whitespace = false
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
######################################################################
|
||||||
|
# 本地环境配置
|
||||||
|
|
||||||
|
*-local.*
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# Build Tools
|
||||||
|
|
||||||
|
.gradle
|
||||||
|
/build/
|
||||||
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# IDE
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
|
||||||
|
### JRebel ###
|
||||||
|
rebel.xml
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
nbproject/private/
|
||||||
|
build/*
|
||||||
|
nbbuild/
|
||||||
|
nbdist/
|
||||||
|
.nb-gradle/
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# Others
|
||||||
|
*.log
|
||||||
|
*.xml.versionsBackup
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
!*/build/*.java
|
||||||
|
!*/build/*.html
|
||||||
|
!*/build/*.xml
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2019 RuoYi-Vue-Plus
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
FROM anapsix/alpine-java:8_server-jre_unlimited
|
||||||
|
|
||||||
|
MAINTAINER Lion Li
|
||||||
|
|
||||||
|
RUN mkdir -p /ruoyi/server/logs \
|
||||||
|
/ruoyi/server/temp \
|
||||||
|
/ruoyi/skywalking/agent
|
||||||
|
|
||||||
|
WORKDIR /ruoyi/server
|
||||||
|
|
||||||
|
ENV SERVER_PORT=8080
|
||||||
|
|
||||||
|
EXPOSE ${SERVER_PORT}
|
||||||
|
|
||||||
|
ADD ./target/ruoyi-admin.jar ./app.jar
|
||||||
|
|
||||||
|
ENTRYPOINT ["java", \
|
||||||
|
"-Djava.security.egd=file:/dev/./urandom", \
|
||||||
|
"-Dserver.port=${SERVER_PORT}", \
|
||||||
|
# 应用名称 如果想区分集群节点监控 改成不同的名称即可
|
||||||
|
# "-Dskywalking.agent.service_name=ruoyi-server", \
|
||||||
|
# "-javaagent:/ruoyi/skywalking/agent/skywalking-agent.jar", \
|
||||||
|
"-jar", "app.jar"]
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package com.ruoyi;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动程序
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class RuoYiApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.setProperty("spring.devtools.restart.enabled", "false");
|
||||||
|
SpringApplication application = new SpringApplication(RuoYiApplication.class);
|
||||||
|
application.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||||
|
application.run(args);
|
||||||
|
System.out.println("(♥◠‿◠)ノ゙ RuoYi-Vue-Plus启动成功 ლ(´ڡ`ლ)゙");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.ruoyi;
|
||||||
|
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* web容器中进行部署
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class RuoYiServletInitializer extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
|
return application.sources(RuoYiApplication.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,112 @@
|
|||||||
|
package com.ruoyi.web.controller.common;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
|
import cn.hutool.captcha.AbstractCaptcha;
|
||||||
|
import cn.hutool.captcha.generator.CodeGenerator;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.enums.CaptchaType;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.utils.redis.RedisUtils;
|
||||||
|
import com.ruoyi.common.utils.reflect.ReflectUtils;
|
||||||
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
|
import com.ruoyi.framework.config.properties.CaptchaProperties;
|
||||||
|
import com.ruoyi.sms.config.properties.SmsProperties;
|
||||||
|
import com.ruoyi.sms.core.SmsTemplate;
|
||||||
|
import com.ruoyi.sms.entity.SmsResult;
|
||||||
|
import com.ruoyi.system.service.ISysConfigService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.expression.Expression;
|
||||||
|
import org.springframework.expression.ExpressionParser;
|
||||||
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码操作处理
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@SaIgnore
|
||||||
|
@Slf4j
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
public class CaptchaController {
|
||||||
|
|
||||||
|
private final CaptchaProperties captchaProperties;
|
||||||
|
private final SmsProperties smsProperties;
|
||||||
|
private final ISysConfigService configService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信验证码
|
||||||
|
*
|
||||||
|
* @param phonenumber 用户手机号
|
||||||
|
*/
|
||||||
|
@GetMapping("/captchaSms")
|
||||||
|
public R<Void> smsCaptcha(@NotBlank(message = "{user.phonenumber.not.blank}")
|
||||||
|
String phonenumber) {
|
||||||
|
if (!smsProperties.getEnabled()) {
|
||||||
|
return R.fail("当前系统没有开启短信功能!");
|
||||||
|
}
|
||||||
|
String key = CacheConstants.CAPTCHA_CODE_KEY + phonenumber;
|
||||||
|
String code = RandomUtil.randomNumbers(4);
|
||||||
|
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||||
|
// 验证码模板id 自行处理 (查数据库或写死均可)
|
||||||
|
String templateId = "";
|
||||||
|
Map<String, String> map = new HashMap<>(1);
|
||||||
|
map.put("code", code);
|
||||||
|
SmsTemplate smsTemplate = SpringUtils.getBean(SmsTemplate.class);
|
||||||
|
SmsResult result = smsTemplate.send(phonenumber, templateId, map);
|
||||||
|
if (!result.isSuccess()) {
|
||||||
|
log.error("验证码短信发送异常 => {}", result);
|
||||||
|
return R.fail(result.getMessage());
|
||||||
|
}
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成验证码
|
||||||
|
*/
|
||||||
|
@GetMapping("/captchaImage")
|
||||||
|
public R<Map<String, Object>> getCode() {
|
||||||
|
Map<String, Object> ajax = new HashMap<>();
|
||||||
|
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
||||||
|
ajax.put("captchaEnabled", captchaEnabled);
|
||||||
|
if (!captchaEnabled) {
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
// 保存验证码信息
|
||||||
|
String uuid = IdUtil.simpleUUID();
|
||||||
|
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
|
||||||
|
// 生成验证码
|
||||||
|
CaptchaType captchaType = captchaProperties.getType();
|
||||||
|
boolean isMath = CaptchaType.MATH == captchaType;
|
||||||
|
Integer length = isMath ? captchaProperties.getNumberLength() : captchaProperties.getCharLength();
|
||||||
|
CodeGenerator codeGenerator = ReflectUtils.newInstance(captchaType.getClazz(), length);
|
||||||
|
AbstractCaptcha captcha = SpringUtils.getBean(captchaProperties.getCategory().getClazz());
|
||||||
|
captcha.setGenerator(codeGenerator);
|
||||||
|
captcha.createCode();
|
||||||
|
String code = captcha.getCode();
|
||||||
|
if (isMath) {
|
||||||
|
ExpressionParser parser = new SpelExpressionParser();
|
||||||
|
Expression exp = parser.parseExpression(StringUtils.remove(code, "="));
|
||||||
|
code = exp.getValue(String.class);
|
||||||
|
}
|
||||||
|
RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||||
|
ajax.put("uuid", uuid);
|
||||||
|
ajax.put("img", captcha.getImageBase64());
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,169 @@
|
|||||||
|
package com.ruoyi.web.controller.monitor;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
|
import com.ruoyi.common.constant.CacheNames;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.utils.JsonUtils;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.utils.redis.CacheUtils;
|
||||||
|
import com.ruoyi.common.utils.redis.RedisUtils;
|
||||||
|
import com.ruoyi.system.domain.SysCache;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.redisson.spring.data.connection.RedissonConnectionFactory;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnection;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存监控
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/monitor/cache")
|
||||||
|
public class CacheController {
|
||||||
|
|
||||||
|
private final RedissonConnectionFactory connectionFactory;
|
||||||
|
|
||||||
|
private final static List<SysCache> CACHES = new ArrayList<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CACHES.add(new SysCache(CacheConstants.LOGIN_TOKEN_KEY, "用户信息"));
|
||||||
|
CACHES.add(new SysCache(CacheConstants.ONLINE_TOKEN_KEY, "在线用户"));
|
||||||
|
CACHES.add(new SysCache(CacheNames.SYS_CONFIG, "配置信息"));
|
||||||
|
CACHES.add(new SysCache(CacheNames.SYS_DICT, "数据字典"));
|
||||||
|
CACHES.add(new SysCache(CacheConstants.CAPTCHA_CODE_KEY, "验证码"));
|
||||||
|
CACHES.add(new SysCache(CacheConstants.REPEAT_SUBMIT_KEY, "防重提交"));
|
||||||
|
CACHES.add(new SysCache(CacheConstants.RATE_LIMIT_KEY, "限流处理"));
|
||||||
|
CACHES.add(new SysCache(CacheNames.SYS_OSS_CONFIG, "OSS配置"));
|
||||||
|
CACHES.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存监控列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:cache:list")
|
||||||
|
@GetMapping()
|
||||||
|
public R<Map<String, Object>> getInfo() throws Exception {
|
||||||
|
RedisConnection connection = connectionFactory.getConnection();
|
||||||
|
Properties info = connection.info();
|
||||||
|
Properties commandStats = connection.info("commandstats");
|
||||||
|
Long dbSize = connection.dbSize();
|
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(3);
|
||||||
|
result.put("info", info);
|
||||||
|
result.put("dbSize", dbSize);
|
||||||
|
|
||||||
|
List<Map<String, String>> pieList = new ArrayList<>();
|
||||||
|
if (commandStats != null) {
|
||||||
|
commandStats.stringPropertyNames().forEach(key -> {
|
||||||
|
Map<String, String> data = new HashMap<>(2);
|
||||||
|
String property = commandStats.getProperty(key);
|
||||||
|
data.put("name", StringUtils.removeStart(key, "cmdstat_"));
|
||||||
|
data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
|
||||||
|
pieList.add(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
result.put("commandStats", pieList);
|
||||||
|
return R.ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存监控缓存名列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:cache:list")
|
||||||
|
@GetMapping("/getNames")
|
||||||
|
public R<List<SysCache>> cache() {
|
||||||
|
return R.ok(CACHES);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存监控Key列表
|
||||||
|
*
|
||||||
|
* @param cacheName 缓存名
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:cache:list")
|
||||||
|
@GetMapping("/getKeys/{cacheName}")
|
||||||
|
public R<Collection<String>> getCacheKeys(@PathVariable String cacheName) {
|
||||||
|
Collection<String> cacheKeys = new HashSet<>(0);
|
||||||
|
if (isCacheNames(cacheName)) {
|
||||||
|
Set<Object> keys = CacheUtils.keys(cacheName);
|
||||||
|
if (CollUtil.isNotEmpty(keys)) {
|
||||||
|
cacheKeys = keys.stream().map(Object::toString).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cacheKeys = RedisUtils.keys(cacheName + "*");
|
||||||
|
}
|
||||||
|
return R.ok(cacheKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存监控缓存值详情
|
||||||
|
*
|
||||||
|
* @param cacheName 缓存名
|
||||||
|
* @param cacheKey 缓存key
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:cache:list")
|
||||||
|
@GetMapping("/getValue/{cacheName}/{cacheKey}")
|
||||||
|
public R<SysCache> getCacheValue(@PathVariable String cacheName, @PathVariable String cacheKey) {
|
||||||
|
Object cacheValue;
|
||||||
|
if (isCacheNames(cacheName)) {
|
||||||
|
cacheValue = CacheUtils.get(cacheName, cacheKey);
|
||||||
|
} else {
|
||||||
|
cacheValue = RedisUtils.getCacheObject(cacheKey);
|
||||||
|
}
|
||||||
|
SysCache sysCache = new SysCache(cacheName, cacheKey, JsonUtils.toJsonString(cacheValue));
|
||||||
|
return R.ok(sysCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理缓存监控缓存名
|
||||||
|
*
|
||||||
|
* @param cacheName 缓存名
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:cache:list")
|
||||||
|
@DeleteMapping("/clearCacheName/{cacheName}")
|
||||||
|
public R<Void> clearCacheName(@PathVariable String cacheName) {
|
||||||
|
if (isCacheNames(cacheName)) {
|
||||||
|
CacheUtils.clear(cacheName);
|
||||||
|
} else {
|
||||||
|
RedisUtils.deleteKeys(cacheName + "*");
|
||||||
|
}
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理缓存监控Key
|
||||||
|
*
|
||||||
|
* @param cacheKey key名
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:cache:list")
|
||||||
|
@DeleteMapping("/clearCacheKey/{cacheName}/{cacheKey}")
|
||||||
|
public R<Void> clearCacheKey(@PathVariable String cacheName, @PathVariable String cacheKey) {
|
||||||
|
if (isCacheNames(cacheName)) {
|
||||||
|
CacheUtils.evict(cacheName, cacheKey);
|
||||||
|
} else {
|
||||||
|
RedisUtils.deleteObject(cacheKey);
|
||||||
|
}
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理全部缓存监控
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:cache:list")
|
||||||
|
@DeleteMapping("/clearCacheAll")
|
||||||
|
public R<Void> clearCacheAll() {
|
||||||
|
RedisUtils.deleteKeys("*");
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCacheNames(String cacheName) {
|
||||||
|
return !StringUtils.contains(cacheName, ":");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,88 @@
|
|||||||
|
package com.ruoyi.web.controller.monitor;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.common.utils.redis.RedisUtils;
|
||||||
|
import com.ruoyi.system.domain.SysLogininfor;
|
||||||
|
import com.ruoyi.system.service.ISysLogininforService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统访问记录
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/monitor/logininfor")
|
||||||
|
public class SysLogininforController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysLogininforService logininforService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统访问记录列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:logininfor:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysLogininfor> list(SysLogininfor logininfor, PageQuery pageQuery) {
|
||||||
|
return logininforService.selectPageLogininforList(logininfor, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出系统访问记录列表
|
||||||
|
*/
|
||||||
|
@Log(title = "登录日志", businessType = BusinessType.EXPORT)
|
||||||
|
@SaCheckPermission("monitor:logininfor:export")
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(SysLogininfor logininfor, HttpServletResponse response) {
|
||||||
|
List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
|
||||||
|
ExcelUtil.exportExcel(list, "登录日志", SysLogininfor.class, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除登录日志
|
||||||
|
* @param infoIds 日志ids
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:logininfor:remove")
|
||||||
|
@Log(title = "登录日志", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{infoIds}")
|
||||||
|
public R<Void> remove(@PathVariable Long[] infoIds) {
|
||||||
|
return toAjax(logininforService.deleteLogininforByIds(infoIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理系统访问记录
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:logininfor:remove")
|
||||||
|
@Log(title = "登录日志", businessType = BusinessType.CLEAN)
|
||||||
|
@DeleteMapping("/clean")
|
||||||
|
public R<Void> clean() {
|
||||||
|
logininforService.cleanLogininfor();
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SaCheckPermission("monitor:logininfor:unlock")
|
||||||
|
@Log(title = "账户解锁", businessType = BusinessType.OTHER)
|
||||||
|
@GetMapping("/unlock/{userName}")
|
||||||
|
public R<Void> unlock(@PathVariable("userName") String userName) {
|
||||||
|
String loginName = CacheConstants.PWD_ERR_CNT_KEY + userName;
|
||||||
|
if (RedisUtils.hasKey(loginName)) {
|
||||||
|
RedisUtils.deleteObject(loginName);
|
||||||
|
}
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
package com.ruoyi.web.controller.monitor;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.system.domain.SysOperLog;
|
||||||
|
import com.ruoyi.system.service.ISysOperLogService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作日志记录
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/monitor/operlog")
|
||||||
|
public class SysOperlogController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysOperLogService operLogService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取操作日志记录列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:operlog:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysOperLog> list(SysOperLog operLog, PageQuery pageQuery) {
|
||||||
|
return operLogService.selectPageOperLogList(operLog, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出操作日志记录列表
|
||||||
|
*/
|
||||||
|
@Log(title = "操作日志", businessType = BusinessType.EXPORT)
|
||||||
|
@SaCheckPermission("monitor:operlog:export")
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(SysOperLog operLog, HttpServletResponse response) {
|
||||||
|
List<SysOperLog> list = operLogService.selectOperLogList(operLog);
|
||||||
|
ExcelUtil.exportExcel(list, "操作日志", SysOperLog.class, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除操作日志记录
|
||||||
|
* @param operIds 日志ids
|
||||||
|
*/
|
||||||
|
@Log(title = "操作日志", businessType = BusinessType.DELETE)
|
||||||
|
@SaCheckPermission("monitor:operlog:remove")
|
||||||
|
@DeleteMapping("/{operIds}")
|
||||||
|
public R<Void> remove(@PathVariable Long[] operIds) {
|
||||||
|
return toAjax(operLogService.deleteOperLogByIds(operIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理操作日志记录
|
||||||
|
*/
|
||||||
|
@Log(title = "操作日志", businessType = BusinessType.CLEAN)
|
||||||
|
@SaCheckPermission("monitor:operlog:remove")
|
||||||
|
@DeleteMapping("/clean")
|
||||||
|
public R<Void> clean() {
|
||||||
|
operLogService.cleanOperLog();
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,90 @@
|
|||||||
|
package com.ruoyi.web.controller.monitor;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.dev33.satoken.exception.NotLoginException;
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.domain.dto.UserOnlineDTO;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.utils.StreamUtils;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.utils.redis.RedisUtils;
|
||||||
|
import com.ruoyi.system.domain.SysUserOnline;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在线用户监控
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/monitor/online")
|
||||||
|
public class SysUserOnlineController extends BaseController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取在线用户监控列表
|
||||||
|
*
|
||||||
|
* @param ipaddr IP地址
|
||||||
|
* @param userName 用户名
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:online:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysUserOnline> list(String ipaddr, String userName) {
|
||||||
|
// 获取所有未过期的 token
|
||||||
|
List<String> keys = StpUtil.searchTokenValue("", 0, -1, false);
|
||||||
|
List<UserOnlineDTO> userOnlineDTOList = new ArrayList<>();
|
||||||
|
for (String key : keys) {
|
||||||
|
String token = key.replace(CacheConstants.LOGIN_TOKEN_KEY, "");
|
||||||
|
// 如果已经过期则跳过
|
||||||
|
if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
userOnlineDTOList.add(RedisUtils.getCacheObject(CacheConstants.ONLINE_TOKEN_KEY + token));
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) {
|
||||||
|
userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline ->
|
||||||
|
StringUtils.equals(ipaddr, userOnline.getIpaddr()) &&
|
||||||
|
StringUtils.equals(userName, userOnline.getUserName())
|
||||||
|
);
|
||||||
|
} else if (StringUtils.isNotEmpty(ipaddr)) {
|
||||||
|
userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline ->
|
||||||
|
StringUtils.equals(ipaddr, userOnline.getIpaddr())
|
||||||
|
);
|
||||||
|
} else if (StringUtils.isNotEmpty(userName)) {
|
||||||
|
userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline ->
|
||||||
|
StringUtils.equals(userName, userOnline.getUserName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Collections.reverse(userOnlineDTOList);
|
||||||
|
userOnlineDTOList.removeAll(Collections.singleton(null));
|
||||||
|
List<SysUserOnline> userOnlineList = BeanUtil.copyToList(userOnlineDTOList, SysUserOnline.class);
|
||||||
|
return TableDataInfo.build(userOnlineList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 强退用户
|
||||||
|
*
|
||||||
|
* @param tokenId token值
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("monitor:online:forceLogout")
|
||||||
|
@Log(title = "在线用户", businessType = BusinessType.FORCE)
|
||||||
|
@DeleteMapping("/{tokenId}")
|
||||||
|
public R<Void> forceLogout(@PathVariable String tokenId) {
|
||||||
|
try {
|
||||||
|
StpUtil.kickoutByTokenValue(tokenId);
|
||||||
|
} catch (NotLoginException ignored) {
|
||||||
|
}
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,137 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.system.domain.SysConfig;
|
||||||
|
import com.ruoyi.system.service.ISysConfigService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数配置 信息操作处理
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/config")
|
||||||
|
public class SysConfigController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysConfigService configService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取参数配置列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:config:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysConfig> list(SysConfig config, PageQuery pageQuery) {
|
||||||
|
return configService.selectPageConfigList(config, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出参数配置列表
|
||||||
|
*/
|
||||||
|
@Log(title = "参数管理", businessType = BusinessType.EXPORT)
|
||||||
|
@SaCheckPermission("system:config:export")
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(SysConfig config, HttpServletResponse response) {
|
||||||
|
List<SysConfig> list = configService.selectConfigList(config);
|
||||||
|
ExcelUtil.exportExcel(list, "参数数据", SysConfig.class, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据参数编号获取详细信息
|
||||||
|
*
|
||||||
|
* @param configId 参数ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:config:query")
|
||||||
|
@GetMapping(value = "/{configId}")
|
||||||
|
public R<SysConfig> getInfo(@PathVariable Long configId) {
|
||||||
|
return R.ok(configService.selectConfigById(configId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据参数键名查询参数值
|
||||||
|
*
|
||||||
|
* @param configKey 参数Key
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/configKey/{configKey}")
|
||||||
|
public R<Void> getConfigKey(@PathVariable String configKey) {
|
||||||
|
return R.ok(configService.selectConfigByKey(configKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增参数配置
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:config:add")
|
||||||
|
@Log(title = "参数管理", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public R<Void> add(@Validated @RequestBody SysConfig config) {
|
||||||
|
if (!configService.checkConfigKeyUnique(config)) {
|
||||||
|
return R.fail("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
||||||
|
}
|
||||||
|
configService.insertConfig(config);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改参数配置
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:config:edit")
|
||||||
|
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public R<Void> edit(@Validated @RequestBody SysConfig config) {
|
||||||
|
if (!configService.checkConfigKeyUnique(config)) {
|
||||||
|
return R.fail("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
||||||
|
}
|
||||||
|
configService.updateConfig(config);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据参数键名修改参数配置
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:config:edit")
|
||||||
|
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping("/updateByKey")
|
||||||
|
public R<Void> updateByKey(@RequestBody SysConfig config) {
|
||||||
|
configService.updateConfig(config);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除参数配置
|
||||||
|
*
|
||||||
|
* @param configIds 参数ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:config:remove")
|
||||||
|
@Log(title = "参数管理", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{configIds}")
|
||||||
|
public R<Void> remove(@PathVariable Long[] configIds) {
|
||||||
|
configService.deleteConfigByIds(configIds);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新参数缓存
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:config:remove")
|
||||||
|
@Log(title = "参数管理", businessType = BusinessType.CLEAN)
|
||||||
|
@DeleteMapping("/refreshCache")
|
||||||
|
public R<Void> refreshCache() {
|
||||||
|
configService.resetConfigCache();
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,116 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.system.service.ISysDictDataService;
|
||||||
|
import com.ruoyi.system.service.ISysDictTypeService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据字典信息
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/dict/data")
|
||||||
|
public class SysDictDataController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysDictDataService dictDataService;
|
||||||
|
private final ISysDictTypeService dictTypeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询字典数据列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysDictData> list(SysDictData dictData, PageQuery pageQuery) {
|
||||||
|
return dictDataService.selectPageDictDataList(dictData, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出字典数据列表
|
||||||
|
*/
|
||||||
|
@Log(title = "字典数据", businessType = BusinessType.EXPORT)
|
||||||
|
@SaCheckPermission("system:dict:export")
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(SysDictData dictData, HttpServletResponse response) {
|
||||||
|
List<SysDictData> list = dictDataService.selectDictDataList(dictData);
|
||||||
|
ExcelUtil.exportExcel(list, "字典数据", SysDictData.class, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询字典数据详细
|
||||||
|
*
|
||||||
|
* @param dictCode 字典code
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:query")
|
||||||
|
@GetMapping(value = "/{dictCode}")
|
||||||
|
public R<SysDictData> getInfo(@PathVariable Long dictCode) {
|
||||||
|
return R.ok(dictDataService.selectDictDataById(dictCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据字典类型查询字典数据信息
|
||||||
|
*
|
||||||
|
* @param dictType 字典类型
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/type/{dictType}")
|
||||||
|
public R<List<SysDictData>> dictType(@PathVariable String dictType) {
|
||||||
|
List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
|
||||||
|
if (ObjectUtil.isNull(data)) {
|
||||||
|
data = new ArrayList<>();
|
||||||
|
}
|
||||||
|
return R.ok(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增字典类型
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:add")
|
||||||
|
@Log(title = "字典数据", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public R<Void> add(@Validated @RequestBody SysDictData dict) {
|
||||||
|
dictDataService.insertDictData(dict);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改保存字典类型
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:edit")
|
||||||
|
@Log(title = "字典数据", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public R<Void> edit(@Validated @RequestBody SysDictData dict) {
|
||||||
|
dictDataService.updateDictData(dict);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除字典类型
|
||||||
|
*
|
||||||
|
* @param dictCodes 字典code串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:remove")
|
||||||
|
@Log(title = "字典类型", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{dictCodes}")
|
||||||
|
public R<Void> remove(@PathVariable Long[] dictCodes) {
|
||||||
|
dictDataService.deleteDictDataByIds(dictCodes);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,125 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysDictType;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.system.service.ISysDictTypeService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据字典信息
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/dict/type")
|
||||||
|
public class SysDictTypeController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysDictTypeService dictTypeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询字典类型列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysDictType> list(SysDictType dictType, PageQuery pageQuery) {
|
||||||
|
return dictTypeService.selectPageDictTypeList(dictType, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出字典类型列表
|
||||||
|
*/
|
||||||
|
@Log(title = "字典类型", businessType = BusinessType.EXPORT)
|
||||||
|
@SaCheckPermission("system:dict:export")
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(SysDictType dictType, HttpServletResponse response) {
|
||||||
|
List<SysDictType> list = dictTypeService.selectDictTypeList(dictType);
|
||||||
|
ExcelUtil.exportExcel(list, "字典类型", SysDictType.class, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询字典类型详细
|
||||||
|
*
|
||||||
|
* @param dictId 字典ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:query")
|
||||||
|
@GetMapping(value = "/{dictId}")
|
||||||
|
public R<SysDictType> getInfo(@PathVariable Long dictId) {
|
||||||
|
return R.ok(dictTypeService.selectDictTypeById(dictId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增字典类型
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:add")
|
||||||
|
@Log(title = "字典类型", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public R<Void> add(@Validated @RequestBody SysDictType dict) {
|
||||||
|
if (!dictTypeService.checkDictTypeUnique(dict)) {
|
||||||
|
return R.fail("新增字典'" + dict.getDictName() + "'失败,字典类型已存在");
|
||||||
|
}
|
||||||
|
dictTypeService.insertDictType(dict);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改字典类型
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:edit")
|
||||||
|
@Log(title = "字典类型", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public R<Void> edit(@Validated @RequestBody SysDictType dict) {
|
||||||
|
if (!dictTypeService.checkDictTypeUnique(dict)) {
|
||||||
|
return R.fail("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
|
||||||
|
}
|
||||||
|
dictTypeService.updateDictType(dict);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除字典类型
|
||||||
|
*
|
||||||
|
* @param dictIds 字典ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:remove")
|
||||||
|
@Log(title = "字典类型", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{dictIds}")
|
||||||
|
public R<Void> remove(@PathVariable Long[] dictIds) {
|
||||||
|
dictTypeService.deleteDictTypeByIds(dictIds);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新字典缓存
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:dict:remove")
|
||||||
|
@Log(title = "字典类型", businessType = BusinessType.CLEAN)
|
||||||
|
@DeleteMapping("/refreshCache")
|
||||||
|
public R<Void> refreshCache() {
|
||||||
|
dictTypeService.resetDictCache();
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典选择框列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/optionselect")
|
||||||
|
public R<List<SysDictType>> optionselect() {
|
||||||
|
List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll();
|
||||||
|
return R.ok(dictTypes);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,128 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysMenu;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
|
import com.ruoyi.common.core.domain.model.LoginBody;
|
||||||
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
|
import com.ruoyi.common.core.domain.model.SmsLoginBody;
|
||||||
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
|
import com.ruoyi.system.domain.vo.RouterVo;
|
||||||
|
import com.ruoyi.system.service.ISysMenuService;
|
||||||
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
|
import com.ruoyi.system.service.SysLoginService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录验证
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
public class SysLoginController {
|
||||||
|
|
||||||
|
private final SysLoginService loginService;
|
||||||
|
private final ISysMenuService menuService;
|
||||||
|
private final ISysUserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录方法
|
||||||
|
*
|
||||||
|
* @param loginBody 登录信息
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@SaIgnore
|
||||||
|
@PostMapping("/login")
|
||||||
|
public R<Map<String, Object>> login(@Validated @RequestBody LoginBody loginBody) {
|
||||||
|
Map<String, Object> ajax = new HashMap<>();
|
||||||
|
// 生成令牌
|
||||||
|
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
|
||||||
|
loginBody.getUuid());
|
||||||
|
ajax.put(Constants.TOKEN, token);
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信登录(示例)
|
||||||
|
*
|
||||||
|
* @param smsLoginBody 登录信息
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@SaIgnore
|
||||||
|
@PostMapping("/smsLogin")
|
||||||
|
public R<Map<String, Object>> smsLogin(@Validated @RequestBody SmsLoginBody smsLoginBody) {
|
||||||
|
Map<String, Object> ajax = new HashMap<>();
|
||||||
|
// 生成令牌
|
||||||
|
String token = loginService.smsLogin(smsLoginBody.getPhonenumber(), smsLoginBody.getSmsCode());
|
||||||
|
ajax.put(Constants.TOKEN, token);
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小程序登录(示例)
|
||||||
|
*
|
||||||
|
* @param xcxCode 小程序code
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@SaIgnore
|
||||||
|
@PostMapping("/xcxLogin")
|
||||||
|
public R<Map<String, Object>> xcxLogin(@NotBlank(message = "{xcx.code.not.blank}") String xcxCode) {
|
||||||
|
Map<String, Object> ajax = new HashMap<>();
|
||||||
|
// 生成令牌
|
||||||
|
String token = loginService.xcxLogin(xcxCode);
|
||||||
|
ajax.put(Constants.TOKEN, token);
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出登录
|
||||||
|
*/
|
||||||
|
@SaIgnore
|
||||||
|
@PostMapping("/logout")
|
||||||
|
public R<Void> logout() {
|
||||||
|
loginService.logout();
|
||||||
|
return R.ok("退出成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
*
|
||||||
|
* @return 用户信息
|
||||||
|
*/
|
||||||
|
@GetMapping("getInfo")
|
||||||
|
public R<Map<String, Object>> getInfo() {
|
||||||
|
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||||
|
SysUser user = userService.selectUserById(loginUser.getUserId());
|
||||||
|
Map<String, Object> ajax = new HashMap<>();
|
||||||
|
ajax.put("user", user);
|
||||||
|
ajax.put("roles", loginUser.getRolePermission());
|
||||||
|
ajax.put("permissions", loginUser.getMenuPermission());
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取路由信息
|
||||||
|
*
|
||||||
|
* @return 路由信息
|
||||||
|
*/
|
||||||
|
@GetMapping("getRouters")
|
||||||
|
public R<List<RouterVo>> getRouters() {
|
||||||
|
Long userId = LoginHelper.getUserId();
|
||||||
|
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
|
||||||
|
return R.ok(menuService.buildMenus(menus));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.system.domain.SysNotice;
|
||||||
|
import com.ruoyi.system.service.ISysNoticeService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公告 信息操作处理
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/notice")
|
||||||
|
public class SysNoticeController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysNoticeService noticeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取通知公告列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:notice:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysNotice> list(SysNotice notice, PageQuery pageQuery) {
|
||||||
|
return noticeService.selectPageNoticeList(notice, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据通知公告编号获取详细信息
|
||||||
|
*
|
||||||
|
* @param noticeId 公告ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:notice:query")
|
||||||
|
@GetMapping(value = "/{noticeId}")
|
||||||
|
public R<SysNotice> getInfo(@PathVariable Long noticeId) {
|
||||||
|
return R.ok(noticeService.selectNoticeById(noticeId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增通知公告
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:notice:add")
|
||||||
|
@Log(title = "通知公告", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public R<Void> add(@Validated @RequestBody SysNotice notice) {
|
||||||
|
return toAjax(noticeService.insertNotice(notice));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改通知公告
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:notice:edit")
|
||||||
|
@Log(title = "通知公告", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public R<Void> edit(@Validated @RequestBody SysNotice notice) {
|
||||||
|
return toAjax(noticeService.updateNotice(notice));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除通知公告
|
||||||
|
*
|
||||||
|
* @param noticeIds 公告ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:notice:remove")
|
||||||
|
@Log(title = "通知公告", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{noticeIds}")
|
||||||
|
public R<Void> remove(@PathVariable Long[] noticeIds) {
|
||||||
|
return toAjax(noticeService.deleteNoticeByIds(noticeIds));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,105 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.annotation.RepeatSubmit;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import com.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import com.ruoyi.common.core.validate.QueryGroup;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.system.domain.bo.SysOssConfigBo;
|
||||||
|
import com.ruoyi.system.domain.vo.SysOssConfigVo;
|
||||||
|
import com.ruoyi.system.service.ISysOssConfigService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象存储配置
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @author 孤舟烟雨
|
||||||
|
* @date 2021-08-13
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/oss/config")
|
||||||
|
public class SysOssConfigController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysOssConfigService iSysOssConfigService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询对象存储配置列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysOssConfigVo> list(@Validated(QueryGroup.class) SysOssConfigBo bo, PageQuery pageQuery) {
|
||||||
|
return iSysOssConfigService.queryPageList(bo, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取对象存储配置详细信息
|
||||||
|
*
|
||||||
|
* @param ossConfigId OSS配置ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:query")
|
||||||
|
@GetMapping("/{ossConfigId}")
|
||||||
|
public R<SysOssConfigVo> getInfo(@NotNull(message = "主键不能为空")
|
||||||
|
@PathVariable Long ossConfigId) {
|
||||||
|
return R.ok(iSysOssConfigService.queryById(ossConfigId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增对象存储配置
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:add")
|
||||||
|
@Log(title = "对象存储配置", businessType = BusinessType.INSERT)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PostMapping()
|
||||||
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody SysOssConfigBo bo) {
|
||||||
|
return toAjax(iSysOssConfigService.insertByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改对象存储配置
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:edit")
|
||||||
|
@Log(title = "对象存储配置", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PutMapping()
|
||||||
|
public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysOssConfigBo bo) {
|
||||||
|
return toAjax(iSysOssConfigService.updateByBo(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除对象存储配置
|
||||||
|
*
|
||||||
|
* @param ossConfigIds OSS配置ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:remove")
|
||||||
|
@Log(title = "对象存储配置", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ossConfigIds}")
|
||||||
|
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||||
|
@PathVariable Long[] ossConfigIds) {
|
||||||
|
return toAjax(iSysOssConfigService.deleteWithValidByIds(Arrays.asList(ossConfigIds), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态修改
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:edit")
|
||||||
|
@Log(title = "对象存储状态修改", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping("/changeStatus")
|
||||||
|
public R<Void> changeStatus(@RequestBody SysOssConfigBo bo) {
|
||||||
|
return toAjax(iSysOssConfigService.updateOssConfigStatus(bo));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,117 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.http.HttpException;
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.core.validate.QueryGroup;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
|
import com.ruoyi.common.utils.file.FileUtils;
|
||||||
|
import com.ruoyi.oss.core.OssClient;
|
||||||
|
import com.ruoyi.oss.factory.OssFactory;
|
||||||
|
import com.ruoyi.system.domain.SysOss;
|
||||||
|
import com.ruoyi.system.domain.bo.SysOssBo;
|
||||||
|
import com.ruoyi.system.domain.vo.SysOssVo;
|
||||||
|
import com.ruoyi.system.service.ISysOssService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传 控制层
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/oss")
|
||||||
|
public class SysOssController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysOssService iSysOssService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询OSS对象存储列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysOssVo> list(@Validated(QueryGroup.class) SysOssBo bo, PageQuery pageQuery) {
|
||||||
|
return iSysOssService.queryPageList(bo, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询OSS对象基于id串
|
||||||
|
*
|
||||||
|
* @param ossIds OSS对象ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:list")
|
||||||
|
@GetMapping("/listByIds/{ossIds}")
|
||||||
|
public R<List<SysOssVo>> listByIds(@NotEmpty(message = "主键不能为空")
|
||||||
|
@PathVariable Long[] ossIds) {
|
||||||
|
List<SysOssVo> list = iSysOssService.listByIds(Arrays.asList(ossIds));
|
||||||
|
return R.ok(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传OSS对象存储
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:upload")
|
||||||
|
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
public R<Map<String, String>> upload(@RequestPart("file") MultipartFile file) {
|
||||||
|
if (ObjectUtil.isNull(file)) {
|
||||||
|
throw new ServiceException("上传文件不能为空");
|
||||||
|
}
|
||||||
|
SysOssVo oss = iSysOssService.upload(file);
|
||||||
|
Map<String, String> map = new HashMap<>(2);
|
||||||
|
map.put("url", oss.getUrl());
|
||||||
|
map.put("fileName", oss.getOriginalName());
|
||||||
|
map.put("ossId", oss.getOssId().toString());
|
||||||
|
return R.ok(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载OSS对象
|
||||||
|
*
|
||||||
|
* @param ossId OSS对象ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:download")
|
||||||
|
@GetMapping("/download/{ossId}")
|
||||||
|
public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException {
|
||||||
|
iSysOssService.download(ossId,response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除OSS对象存储
|
||||||
|
*
|
||||||
|
* @param ossIds OSS对象ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:oss:remove")
|
||||||
|
@Log(title = "OSS对象存储", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ossIds}")
|
||||||
|
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||||
|
@PathVariable Long[] ossIds) {
|
||||||
|
return toAjax(iSysOssService.deleteWithValidByIds(Arrays.asList(ossIds), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,115 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.system.domain.SysPost;
|
||||||
|
import com.ruoyi.system.service.ISysPostService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 岗位信息操作处理
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/post")
|
||||||
|
public class SysPostController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysPostService postService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取岗位列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:post:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysPost> list(SysPost post, PageQuery pageQuery) {
|
||||||
|
return postService.selectPagePostList(post, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出岗位列表
|
||||||
|
*/
|
||||||
|
@Log(title = "岗位管理", businessType = BusinessType.EXPORT)
|
||||||
|
@SaCheckPermission("system:post:export")
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(SysPost post, HttpServletResponse response) {
|
||||||
|
List<SysPost> list = postService.selectPostList(post);
|
||||||
|
ExcelUtil.exportExcel(list, "岗位数据", SysPost.class, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据岗位编号获取详细信息
|
||||||
|
*
|
||||||
|
* @param postId 岗位ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:post:query")
|
||||||
|
@GetMapping(value = "/{postId}")
|
||||||
|
public R<SysPost> getInfo(@PathVariable Long postId) {
|
||||||
|
return R.ok(postService.selectPostById(postId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增岗位
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:post:add")
|
||||||
|
@Log(title = "岗位管理", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public R<Void> add(@Validated @RequestBody SysPost post) {
|
||||||
|
if (!postService.checkPostNameUnique(post)) {
|
||||||
|
return R.fail("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
|
||||||
|
} else if (!postService.checkPostCodeUnique(post)) {
|
||||||
|
return R.fail("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
|
||||||
|
}
|
||||||
|
return toAjax(postService.insertPost(post));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改岗位
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:post:edit")
|
||||||
|
@Log(title = "岗位管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public R<Void> edit(@Validated @RequestBody SysPost post) {
|
||||||
|
if (!postService.checkPostNameUnique(post)) {
|
||||||
|
return R.fail("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
|
||||||
|
} else if (!postService.checkPostCodeUnique(post)) {
|
||||||
|
return R.fail("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
|
||||||
|
}
|
||||||
|
return toAjax(postService.updatePost(post));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除岗位
|
||||||
|
*
|
||||||
|
* @param postIds 岗位ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:post:remove")
|
||||||
|
@Log(title = "岗位管理", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{postIds}")
|
||||||
|
public R<Void> remove(@PathVariable Long[] postIds) {
|
||||||
|
return toAjax(postService.deletePostByIds(postIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取岗位选择框列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/optionselect")
|
||||||
|
public R<List<SysPost>> optionselect() {
|
||||||
|
List<SysPost> posts = postService.selectPostAll();
|
||||||
|
return R.ok(posts);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,126 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.secure.BCrypt;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.utils.file.MimeTypeUtils;
|
||||||
|
import com.ruoyi.system.domain.SysOss;
|
||||||
|
import com.ruoyi.system.domain.vo.SysOssVo;
|
||||||
|
import com.ruoyi.system.service.ISysOssService;
|
||||||
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个人信息 业务处理
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/user/profile")
|
||||||
|
public class SysProfileController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysUserService userService;
|
||||||
|
private final ISysOssService iSysOssService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个人信息
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public R<Map<String, Object>> profile() {
|
||||||
|
SysUser user = userService.selectUserById(getUserId());
|
||||||
|
Map<String, Object> ajax = new HashMap<>();
|
||||||
|
ajax.put("user", user);
|
||||||
|
ajax.put("roleGroup", userService.selectUserRoleGroup(user.getUserName()));
|
||||||
|
ajax.put("postGroup", userService.selectUserPostGroup(user.getUserName()));
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户
|
||||||
|
*/
|
||||||
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public R<Void> updateProfile(@RequestBody SysUser user) {
|
||||||
|
if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
||||||
|
return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
||||||
|
return R.fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||||
|
}
|
||||||
|
user.setUserId(getUserId());
|
||||||
|
user.setUserName(null);
|
||||||
|
user.setPassword(null);
|
||||||
|
user.setAvatar(null);
|
||||||
|
user.setDeptId(null);
|
||||||
|
if (userService.updateUserProfile(user) > 0) {
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
return R.fail("修改个人信息异常,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置密码
|
||||||
|
*
|
||||||
|
* @param newPassword 旧密码
|
||||||
|
* @param oldPassword 新密码
|
||||||
|
*/
|
||||||
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping("/updatePwd")
|
||||||
|
public R<Void> updatePwd(String oldPassword, String newPassword) {
|
||||||
|
SysUser user = userService.selectUserById(LoginHelper.getUserId());
|
||||||
|
String userName = user.getUserName();
|
||||||
|
String password = user.getPassword();
|
||||||
|
if (!BCrypt.checkpw(oldPassword, password)) {
|
||||||
|
return R.fail("修改密码失败,旧密码错误");
|
||||||
|
}
|
||||||
|
if (BCrypt.checkpw(newPassword, password)) {
|
||||||
|
return R.fail("新密码不能与旧密码相同");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userService.resetUserPwd(userName, BCrypt.hashpw(newPassword)) > 0) {
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
return R.fail("修改密码异常,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像上传
|
||||||
|
*
|
||||||
|
* @param avatarfile 用户头像
|
||||||
|
*/
|
||||||
|
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
||||||
|
@PostMapping(value = "/avatar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
public R<Map<String, Object>> avatar(@RequestPart("avatarfile") MultipartFile avatarfile) {
|
||||||
|
Map<String, Object> ajax = new HashMap<>();
|
||||||
|
if (!avatarfile.isEmpty()) {
|
||||||
|
String extension = FileUtil.extName(avatarfile.getOriginalFilename());
|
||||||
|
if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.IMAGE_EXTENSION)) {
|
||||||
|
return R.fail("文件格式不正确,请上传" + Arrays.toString(MimeTypeUtils.IMAGE_EXTENSION) + "格式");
|
||||||
|
}
|
||||||
|
SysOssVo oss = iSysOssService.upload(avatarfile);
|
||||||
|
String avatar = oss.getUrl();
|
||||||
|
if (userService.updateUserAvatar(getUsername(), avatar)) {
|
||||||
|
ajax.put("imgUrl", avatar);
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return R.fail("上传图片异常,请联系管理员");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.domain.model.RegisterBody;
|
||||||
|
import com.ruoyi.system.service.ISysConfigService;
|
||||||
|
import com.ruoyi.system.service.SysRegisterService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册验证
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
public class SysRegisterController extends BaseController {
|
||||||
|
|
||||||
|
private final SysRegisterService registerService;
|
||||||
|
private final ISysConfigService configService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户注册
|
||||||
|
*/
|
||||||
|
@SaIgnore
|
||||||
|
@PostMapping("/register")
|
||||||
|
public R<Void> register(@Validated @RequestBody RegisterBody user) {
|
||||||
|
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
|
||||||
|
return R.fail("当前系统没有开启注册功能!");
|
||||||
|
}
|
||||||
|
registerService.register(user);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,252 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.dev33.satoken.exception.NotLoginException;
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.constant.CacheConstants;
|
||||||
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.system.domain.SysUserRole;
|
||||||
|
import com.ruoyi.system.service.ISysDeptService;
|
||||||
|
import com.ruoyi.system.service.ISysRoleService;
|
||||||
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
|
import com.ruoyi.system.service.SysPermissionService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色信息
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/role")
|
||||||
|
public class SysRoleController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysRoleService roleService;
|
||||||
|
private final ISysUserService userService;
|
||||||
|
private final ISysDeptService deptService;
|
||||||
|
private final SysPermissionService permissionService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色信息列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysRole> list(SysRole role, PageQuery pageQuery) {
|
||||||
|
return roleService.selectPageRoleList(role, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出角色信息列表
|
||||||
|
*/
|
||||||
|
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
|
||||||
|
@SaCheckPermission("system:role:export")
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(SysRole role, HttpServletResponse response) {
|
||||||
|
List<SysRole> list = roleService.selectRoleList(role);
|
||||||
|
ExcelUtil.exportExcel(list, "角色数据", SysRole.class, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色编号获取详细信息
|
||||||
|
*
|
||||||
|
* @param roleId 角色ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:query")
|
||||||
|
@GetMapping(value = "/{roleId}")
|
||||||
|
public R<SysRole> getInfo(@PathVariable Long roleId) {
|
||||||
|
roleService.checkRoleDataScope(roleId);
|
||||||
|
return R.ok(roleService.selectRoleById(roleId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增角色
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:add")
|
||||||
|
@Log(title = "角色管理", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public R<Void> add(@Validated @RequestBody SysRole role) {
|
||||||
|
if (!roleService.checkRoleNameUnique(role)) {
|
||||||
|
return R.fail("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||||
|
} else if (!roleService.checkRoleKeyUnique(role)) {
|
||||||
|
return R.fail("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||||
|
}
|
||||||
|
return toAjax(roleService.insertRole(role));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改保存角色
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:edit")
|
||||||
|
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public R<Void> edit(@Validated @RequestBody SysRole role) {
|
||||||
|
roleService.checkRoleAllowed(role);
|
||||||
|
roleService.checkRoleDataScope(role.getRoleId());
|
||||||
|
if (!roleService.checkRoleNameUnique(role)) {
|
||||||
|
return R.fail("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||||
|
} else if (!roleService.checkRoleKeyUnique(role)) {
|
||||||
|
return R.fail("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (roleService.updateRole(role) > 0) {
|
||||||
|
List<String> keys = StpUtil.searchTokenValue("", 0, -1, false);
|
||||||
|
if (CollUtil.isEmpty(keys)) {
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
// 角色关联的在线用户量过大会导致redis阻塞卡顿 谨慎操作
|
||||||
|
keys.parallelStream().forEach(key -> {
|
||||||
|
String token = key.replace(CacheConstants.LOGIN_TOKEN_KEY, "");
|
||||||
|
// 如果已经过期则跳过
|
||||||
|
if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LoginUser loginUser = LoginHelper.getLoginUser(token);
|
||||||
|
if (loginUser.getRoles().stream().anyMatch(r -> r.getRoleId().equals(role.getRoleId()))) {
|
||||||
|
try {
|
||||||
|
StpUtil.logoutByTokenValue(token);
|
||||||
|
} catch (NotLoginException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
return R.fail("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改保存数据权限
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:edit")
|
||||||
|
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping("/dataScope")
|
||||||
|
public R<Void> dataScope(@RequestBody SysRole role) {
|
||||||
|
roleService.checkRoleAllowed(role);
|
||||||
|
roleService.checkRoleDataScope(role.getRoleId());
|
||||||
|
return toAjax(roleService.authDataScope(role));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态修改
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:edit")
|
||||||
|
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping("/changeStatus")
|
||||||
|
public R<Void> changeStatus(@RequestBody SysRole role) {
|
||||||
|
roleService.checkRoleAllowed(role);
|
||||||
|
roleService.checkRoleDataScope(role.getRoleId());
|
||||||
|
return toAjax(roleService.updateRoleStatus(role));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除角色
|
||||||
|
*
|
||||||
|
* @param roleIds 角色ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:remove")
|
||||||
|
@Log(title = "角色管理", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{roleIds}")
|
||||||
|
public R<Void> remove(@PathVariable Long[] roleIds) {
|
||||||
|
return toAjax(roleService.deleteRoleByIds(roleIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色选择框列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:query")
|
||||||
|
@GetMapping("/optionselect")
|
||||||
|
public R<List<SysRole>> optionselect() {
|
||||||
|
return R.ok(roleService.selectRoleAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询已分配用户角色列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:list")
|
||||||
|
@GetMapping("/authUser/allocatedList")
|
||||||
|
public TableDataInfo<SysUser> allocatedList(SysUser user, PageQuery pageQuery) {
|
||||||
|
return userService.selectAllocatedList(user, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询未分配用户角色列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:list")
|
||||||
|
@GetMapping("/authUser/unallocatedList")
|
||||||
|
public TableDataInfo<SysUser> unallocatedList(SysUser user, PageQuery pageQuery) {
|
||||||
|
return userService.selectUnallocatedList(user, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消授权用户
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:edit")
|
||||||
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
||||||
|
@PutMapping("/authUser/cancel")
|
||||||
|
public R<Void> cancelAuthUser(@RequestBody SysUserRole userRole) {
|
||||||
|
return toAjax(roleService.deleteAuthUser(userRole));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量取消授权用户
|
||||||
|
*
|
||||||
|
* @param roleId 角色ID
|
||||||
|
* @param userIds 用户ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:edit")
|
||||||
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
||||||
|
@PutMapping("/authUser/cancelAll")
|
||||||
|
public R<Void> cancelAuthUserAll(Long roleId, Long[] userIds) {
|
||||||
|
return toAjax(roleService.deleteAuthUsers(roleId, userIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量选择用户授权
|
||||||
|
*
|
||||||
|
* @param roleId 角色ID
|
||||||
|
* @param userIds 用户ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:edit")
|
||||||
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
||||||
|
@PutMapping("/authUser/selectAll")
|
||||||
|
public R<Void> selectAuthUserAll(Long roleId, Long[] userIds) {
|
||||||
|
roleService.checkRoleDataScope(roleId);
|
||||||
|
return toAjax(roleService.insertAuthUsers(roleId, userIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取对应角色部门树列表
|
||||||
|
*
|
||||||
|
* @param roleId 角色ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:role:list")
|
||||||
|
@GetMapping(value = "/deptTree/{roleId}")
|
||||||
|
public R<Map<String, Object>> roleDeptTreeselect(@PathVariable("roleId") Long roleId) {
|
||||||
|
Map<String, Object> ajax = new HashMap<>();
|
||||||
|
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
|
||||||
|
ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,249 @@
|
|||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import cn.dev33.satoken.secure.BCrypt;
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.lang.tree.Tree;
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||||
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.excel.ExcelResult;
|
||||||
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
|
import com.ruoyi.common.utils.StreamUtils;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.system.domain.vo.SysUserExportVo;
|
||||||
|
import com.ruoyi.system.domain.vo.SysUserImportVo;
|
||||||
|
import com.ruoyi.system.listener.SysUserImportListener;
|
||||||
|
import com.ruoyi.system.service.ISysDeptService;
|
||||||
|
import com.ruoyi.system.service.ISysPostService;
|
||||||
|
import com.ruoyi.system.service.ISysRoleService;
|
||||||
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户信息
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/user")
|
||||||
|
public class SysUserController extends BaseController {
|
||||||
|
|
||||||
|
private final ISysUserService userService;
|
||||||
|
private final ISysRoleService roleService;
|
||||||
|
private final ISysPostService postService;
|
||||||
|
private final ISysDeptService deptService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:user:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<SysUser> list(SysUser user, PageQuery pageQuery) {
|
||||||
|
return userService.selectPageUserList(user, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出用户列表
|
||||||
|
*/
|
||||||
|
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
||||||
|
@SaCheckPermission("system:user:export")
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(SysUser user, HttpServletResponse response) {
|
||||||
|
List<SysUser> list = userService.selectUserList(user);
|
||||||
|
List<SysUserExportVo> listVo = BeanUtil.copyToList(list, SysUserExportVo.class);
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
SysDept dept = list.get(i).getDept();
|
||||||
|
SysUserExportVo vo = listVo.get(i);
|
||||||
|
if (ObjectUtil.isNotEmpty(dept)) {
|
||||||
|
vo.setDeptName(dept.getDeptName());
|
||||||
|
vo.setLeader(dept.getLeader());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入数据
|
||||||
|
*
|
||||||
|
* @param file 导入文件
|
||||||
|
* @param updateSupport 是否更新已存在数据
|
||||||
|
*/
|
||||||
|
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
||||||
|
@SaCheckPermission("system:user:import")
|
||||||
|
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception {
|
||||||
|
ExcelResult<SysUserImportVo> result = ExcelUtil.importExcel(file.getInputStream(), SysUserImportVo.class, new SysUserImportListener(updateSupport));
|
||||||
|
return R.ok(result.getAnalysis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取导入模板
|
||||||
|
*/
|
||||||
|
@PostMapping("/importTemplate")
|
||||||
|
public void importTemplate(HttpServletResponse response) {
|
||||||
|
ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户编号获取详细信息
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:user:query")
|
||||||
|
@GetMapping(value = {"/", "/{userId}"})
|
||||||
|
public R<Map<String, Object>> getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
||||||
|
userService.checkUserDataScope(userId);
|
||||||
|
Map<String, Object> ajax = new HashMap<>();
|
||||||
|
List<SysRole> roles = roleService.selectRoleAll();
|
||||||
|
ajax.put("roles", LoginHelper.isAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isAdmin()));
|
||||||
|
ajax.put("posts", postService.selectPostAll());
|
||||||
|
if (ObjectUtil.isNotNull(userId)) {
|
||||||
|
SysUser sysUser = userService.selectUserById(userId);
|
||||||
|
ajax.put("user", sysUser);
|
||||||
|
ajax.put("postIds", postService.selectPostListByUserId(userId));
|
||||||
|
ajax.put("roleIds", StreamUtils.toList(sysUser.getRoles(), SysRole::getRoleId));
|
||||||
|
}
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增用户
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:user:add")
|
||||||
|
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public R<Void> add(@Validated @RequestBody SysUser user) {
|
||||||
|
if (!userService.checkUserNameUnique(user)) {
|
||||||
|
return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||||
|
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
||||||
|
return R.fail("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||||
|
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
||||||
|
return R.fail("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||||
|
}
|
||||||
|
user.setPassword(BCrypt.hashpw(user.getPassword()));
|
||||||
|
return toAjax(userService.insertUser(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:user:edit")
|
||||||
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public R<Void> edit(@Validated @RequestBody SysUser user) {
|
||||||
|
userService.checkUserAllowed(user);
|
||||||
|
userService.checkUserDataScope(user.getUserId());
|
||||||
|
if (!userService.checkUserNameUnique(user)) {
|
||||||
|
return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||||
|
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
||||||
|
return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
||||||
|
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
||||||
|
return R.fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||||
|
}
|
||||||
|
return toAjax(userService.updateUser(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户
|
||||||
|
*
|
||||||
|
* @param userIds 角色ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:user:remove")
|
||||||
|
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{userIds}")
|
||||||
|
public R<Void> remove(@PathVariable Long[] userIds) {
|
||||||
|
if (ArrayUtil.contains(userIds, getUserId())) {
|
||||||
|
return R.fail("当前用户不能删除");
|
||||||
|
}
|
||||||
|
return toAjax(userService.deleteUserByIds(userIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置密码
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:user:resetPwd")
|
||||||
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping("/resetPwd")
|
||||||
|
public R<Void> resetPwd(@RequestBody SysUser user) {
|
||||||
|
userService.checkUserAllowed(user);
|
||||||
|
userService.checkUserDataScope(user.getUserId());
|
||||||
|
user.setPassword(BCrypt.hashpw(user.getPassword()));
|
||||||
|
return toAjax(userService.resetPwd(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态修改
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:user:edit")
|
||||||
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping("/changeStatus")
|
||||||
|
public R<Void> changeStatus(@RequestBody SysUser user) {
|
||||||
|
userService.checkUserAllowed(user);
|
||||||
|
userService.checkUserDataScope(user.getUserId());
|
||||||
|
return toAjax(userService.updateUserStatus(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户编号获取授权角色
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:user:query")
|
||||||
|
@GetMapping("/authRole/{userId}")
|
||||||
|
public R<Map<String, Object>> authRole(@PathVariable Long userId) {
|
||||||
|
SysUser user = userService.selectUserById(userId);
|
||||||
|
List<SysRole> roles = roleService.selectRolesByUserId(userId);
|
||||||
|
Map<String, Object> ajax = new HashMap<>();
|
||||||
|
ajax.put("user", user);
|
||||||
|
ajax.put("roles", LoginHelper.isAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isAdmin()));
|
||||||
|
return R.ok(ajax);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户授权角色
|
||||||
|
*
|
||||||
|
* @param userId 用户Id
|
||||||
|
* @param roleIds 角色ID串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:user:edit")
|
||||||
|
@Log(title = "用户管理", businessType = BusinessType.GRANT)
|
||||||
|
@PutMapping("/authRole")
|
||||||
|
public R<Void> insertAuthRole(Long userId, Long[] roleIds) {
|
||||||
|
userService.checkUserDataScope(userId);
|
||||||
|
userService.insertUserAuth(userId, roleIds);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门树列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("system:user:list")
|
||||||
|
@GetMapping("/deptTree")
|
||||||
|
public R<List<Tree<Long>>> deptTree(SysDept dept) {
|
||||||
|
return R.ok(deptService.selectDeptTreeList(dept));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
Application Version: ${ruoyi-vue-plus.version}
|
||||||
|
Spring Boot Version: ${spring-boot.version}
|
||||||
|
__________ _____.___.__ ____ ____ __________.__
|
||||||
|
\______ \__ __ ____\__ | |__| \ \ / /_ __ ____ \______ \ | __ __ ______
|
||||||
|
| _/ | \/ _ \/ | | | ______ \ Y / | \_/ __ \ ______ | ___/ | | | \/ ___/
|
||||||
|
| | \ | ( <_> )____ | | /_____/ \ /| | /\ ___/ /_____/ | | | |_| | /\___ \
|
||||||
|
|____|_ /____/ \____// ______|__| \___/ |____/ \___ > |____| |____/____//____ >
|
||||||
|
\/ \/ \/ \/
|
||||||
@ -0,0 +1,129 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<property name="log.path" value="./logs"/>
|
||||||
|
<property name="console.log.pattern"
|
||||||
|
value="%red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}%n) - %msg%n"/>
|
||||||
|
<property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"/>
|
||||||
|
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${console.log.pattern}</pattern>
|
||||||
|
<charset>utf-8</charset>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender name="file_console" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/sys-console.log</file>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/sys-console.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大 1天 -->
|
||||||
|
<maxHistory>1</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
<charset>utf-8</charset>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>INFO</level>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统日志输出 -->
|
||||||
|
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/sys-info.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>INFO</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/sys-error.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>ERROR</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- info异步输出 -->
|
||||||
|
<appender name="async_info" class="ch.qos.logback.classic.AsyncAppender">
|
||||||
|
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
|
||||||
|
<discardingThreshold>0</discardingThreshold>
|
||||||
|
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
|
||||||
|
<queueSize>512</queueSize>
|
||||||
|
<!-- 添加附加的appender,最多只能添加一个 -->
|
||||||
|
<appender-ref ref="file_info"/>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- error异步输出 -->
|
||||||
|
<appender name="async_error" class="ch.qos.logback.classic.AsyncAppender">
|
||||||
|
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
|
||||||
|
<discardingThreshold>0</discardingThreshold>
|
||||||
|
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
|
||||||
|
<queueSize>512</queueSize>
|
||||||
|
<!-- 添加附加的appender,最多只能添加一个 -->
|
||||||
|
<appender-ref ref="file_error"/>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 整合 skywalking 控制台输出 tid -->
|
||||||
|
<!-- <appender name="console" class="ch.qos.logback.core.ConsoleAppender">-->
|
||||||
|
<!-- <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">-->
|
||||||
|
<!-- <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">-->
|
||||||
|
<!-- <pattern>[%tid] ${console.log.pattern}</pattern>-->
|
||||||
|
<!-- </layout>-->
|
||||||
|
<!-- <charset>utf-8</charset>-->
|
||||||
|
<!-- </encoder>-->
|
||||||
|
<!-- </appender>-->
|
||||||
|
|
||||||
|
<!-- 整合 skywalking 推送采集日志 -->
|
||||||
|
<!-- <appender name="sky_log" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">-->
|
||||||
|
<!-- <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">-->
|
||||||
|
<!-- <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">-->
|
||||||
|
<!-- <pattern>[%tid] ${console.log.pattern}</pattern>-->
|
||||||
|
<!-- </layout>-->
|
||||||
|
<!-- <charset>utf-8</charset>-->
|
||||||
|
<!-- </encoder>-->
|
||||||
|
<!-- </appender>-->
|
||||||
|
|
||||||
|
<!--系统操作日志-->
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="console" />
|
||||||
|
<appender-ref ref="async_info" />
|
||||||
|
<appender-ref ref="async_error" />
|
||||||
|
<appender-ref ref="file_console" />
|
||||||
|
<!-- <appender-ref ref="sky_log"/>-->
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
# p6spy 性能分析插件配置文件
|
||||||
|
modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
|
||||||
|
# 自定义日志打印
|
||||||
|
logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
|
||||||
|
#日志输出到控制台
|
||||||
|
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
|
||||||
|
# 使用日志系统记录 sql
|
||||||
|
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
|
||||||
|
# 设置 p6spy driver 代理
|
||||||
|
#deregisterdrivers=true
|
||||||
|
# 取消JDBC URL前缀
|
||||||
|
useprefix=true
|
||||||
|
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
|
||||||
|
excludecategories=info,debug,result,commit,resultset
|
||||||
|
# 日期格式
|
||||||
|
dateformat=yyyy-MM-dd HH:mm:ss
|
||||||
|
# SQL语句打印时间格式
|
||||||
|
databaseDialectTimestampFormat=yyyy-MM-dd HH:mm:ss
|
||||||
|
# 实际驱动可多个
|
||||||
|
#driverlist=org.h2.Driver
|
||||||
|
# 是否开启慢SQL记录
|
||||||
|
outagedetection=true
|
||||||
|
# 慢SQL记录标准 2 秒
|
||||||
|
outagedetectioninterval=2
|
||||||
|
# 是否过滤 Log
|
||||||
|
filter=true
|
||||||
|
# 过滤 Log 时所排除的 sql 关键字,以逗号分隔
|
||||||
|
exclude=SELECT 1
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
package com.ruoyi.test;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 断言单元测试案例
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@DisplayName("断言单元测试案例")
|
||||||
|
public class AssertUnitTest {
|
||||||
|
|
||||||
|
@DisplayName("测试 assertEquals 方法")
|
||||||
|
@Test
|
||||||
|
public void testAssertEquals() {
|
||||||
|
Assertions.assertEquals("666", new String("666"));
|
||||||
|
Assertions.assertNotEquals("666", new String("666"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("测试 assertSame 方法")
|
||||||
|
@Test
|
||||||
|
public void testAssertSame() {
|
||||||
|
Object obj = new Object();
|
||||||
|
Object obj1 = obj;
|
||||||
|
Assertions.assertSame(obj, obj1);
|
||||||
|
Assertions.assertNotSame(obj, obj1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("测试 assertTrue 方法")
|
||||||
|
@Test
|
||||||
|
public void testAssertTrue() {
|
||||||
|
Assertions.assertTrue(true);
|
||||||
|
Assertions.assertFalse(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("测试 assertNull 方法")
|
||||||
|
@Test
|
||||||
|
public void testAssertNull() {
|
||||||
|
Assertions.assertNull(null);
|
||||||
|
Assertions.assertNotNull(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
package com.ruoyi.test;
|
||||||
|
|
||||||
|
import com.ruoyi.common.config.RuoYiConfig;
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单元测试案例
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@SpringBootTest // 此注解只能在 springboot 主包下使用 需包含 main 方法与 yml 配置文件
|
||||||
|
@DisplayName("单元测试案例")
|
||||||
|
public class DemoUnitTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RuoYiConfig ruoYiConfig;
|
||||||
|
|
||||||
|
@DisplayName("测试 @SpringBootTest @Test @DisplayName 注解")
|
||||||
|
@Test
|
||||||
|
public void testTest() {
|
||||||
|
System.out.println(ruoYiConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Disabled
|
||||||
|
@DisplayName("测试 @Disabled 注解")
|
||||||
|
@Test
|
||||||
|
public void testDisabled() {
|
||||||
|
System.out.println(ruoYiConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Timeout(value = 2L, unit = TimeUnit.SECONDS)
|
||||||
|
@DisplayName("测试 @Timeout 注解")
|
||||||
|
@Test
|
||||||
|
public void testTimeout() throws InterruptedException {
|
||||||
|
Thread.sleep(3000);
|
||||||
|
System.out.println(ruoYiConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@DisplayName("测试 @RepeatedTest 注解")
|
||||||
|
@RepeatedTest(3)
|
||||||
|
public void testRepeatedTest() {
|
||||||
|
System.out.println(666);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void testBeforeAll() {
|
||||||
|
System.out.println("@BeforeAll ==================");
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void testBeforeEach() {
|
||||||
|
System.out.println("@BeforeEach ==================");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void testAfterEach() {
|
||||||
|
System.out.println("@AfterEach ==================");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
public static void testAfterAll() {
|
||||||
|
System.out.println("@AfterAll ==================");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
package com.ruoyi.test;
|
||||||
|
|
||||||
|
import com.ruoyi.common.enums.UserType;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import org.junit.jupiter.params.provider.NullSource;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带参数单元测试案例
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@DisplayName("带参数单元测试案例")
|
||||||
|
public class ParamUnitTest {
|
||||||
|
|
||||||
|
@DisplayName("测试 @ValueSource 注解")
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"t1", "t2", "t3"})
|
||||||
|
public void testValueSource(String str) {
|
||||||
|
System.out.println(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("测试 @NullSource 注解")
|
||||||
|
@ParameterizedTest
|
||||||
|
@NullSource
|
||||||
|
public void testNullSource(String str) {
|
||||||
|
System.out.println(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("测试 @EnumSource 注解")
|
||||||
|
@ParameterizedTest
|
||||||
|
@EnumSource(UserType.class)
|
||||||
|
public void testEnumSource(UserType type) {
|
||||||
|
System.out.println(type.getUserType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("测试 @MethodSource 注解")
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("getParam")
|
||||||
|
public void testMethodSource(String str) {
|
||||||
|
System.out.println(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream<String> getParam() {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
list.add("t1");
|
||||||
|
list.add("t2");
|
||||||
|
list.add("t3");
|
||||||
|
return list.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void testBeforeEach() {
|
||||||
|
System.out.println("@BeforeEach ==================");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void testAfterEach() {
|
||||||
|
System.out.println("@AfterEach ==================");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
package com.ruoyi.test;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签单元测试案例
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@SpringBootTest
|
||||||
|
@DisplayName("标签单元测试案例")
|
||||||
|
public class TagUnitTest {
|
||||||
|
|
||||||
|
@Tag("dev")
|
||||||
|
@DisplayName("测试 @Tag dev")
|
||||||
|
@Test
|
||||||
|
public void testTagDev() {
|
||||||
|
System.out.println("dev");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tag("prod")
|
||||||
|
@DisplayName("测试 @Tag prod")
|
||||||
|
@Test
|
||||||
|
public void testTagProd() {
|
||||||
|
System.out.println("prod");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tag("local")
|
||||||
|
@DisplayName("测试 @Tag local")
|
||||||
|
@Test
|
||||||
|
public void testTagLocal() {
|
||||||
|
System.out.println("local");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Tag("exclude")
|
||||||
|
@DisplayName("测试 @Tag exclude")
|
||||||
|
@Test
|
||||||
|
public void testTagExclude() {
|
||||||
|
System.out.println("exclude");
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void testBeforeEach() {
|
||||||
|
System.out.println("@BeforeEach ==================");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void testAfterEach() {
|
||||||
|
System.out.println("@AfterEach ==================");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import com.ruoyi.common.excel.CellMergeStrategy;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* excel 列单元格合并(合并列相同项)
|
||||||
|
*
|
||||||
|
* 需搭配 {@link CellMergeStrategy} 策略使用
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Inherited
|
||||||
|
public @interface CellMerge {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* col index
|
||||||
|
*/
|
||||||
|
int index() default -1;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据权限
|
||||||
|
*
|
||||||
|
* 一个注解只能对应一个模板
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @version 3.5.0
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface DataColumn {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 占位符关键字
|
||||||
|
*/
|
||||||
|
String[] key() default "deptName";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 占位符替换值
|
||||||
|
*/
|
||||||
|
String[] value() default "dept_id";
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据权限组
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @version 3.5.0
|
||||||
|
*/
|
||||||
|
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface DataPermission {
|
||||||
|
|
||||||
|
DataColumn[] value();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.ruoyi.common.jackson.DictDataJsonSerializer;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典数据映射注解
|
||||||
|
*
|
||||||
|
* @author itino
|
||||||
|
* @deprecated 建议使用通用翻译注解
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD, ElementType.METHOD})
|
||||||
|
@JacksonAnnotationsInside
|
||||||
|
@JsonSerialize(using = DictDataJsonSerializer.class)
|
||||||
|
public @interface DictDataMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置字典的type值 (如: sys_user_sex)
|
||||||
|
*/
|
||||||
|
String dictType() default "";
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import com.ruoyi.common.enums.AlgorithmType;
|
||||||
|
import com.ruoyi.common.enums.EncodeType;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段加密注解
|
||||||
|
*
|
||||||
|
* @author 老马
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Inherited
|
||||||
|
@Target({ElementType.FIELD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface EncryptField {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密算法
|
||||||
|
*/
|
||||||
|
AlgorithmType algorithm() default AlgorithmType.DEFAULT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 秘钥。AES、SM4需要
|
||||||
|
*/
|
||||||
|
String password() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥。RSA、SM2需要
|
||||||
|
*/
|
||||||
|
String publicKey() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公钥。RSA、SM2需要
|
||||||
|
*/
|
||||||
|
String privateKey() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编码方式。对加密算法为BASE64的不起作用
|
||||||
|
*/
|
||||||
|
EncodeType encode() default EncodeType.DEFAULT;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.enums.OperatorType;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义操作日志记录注解
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@Target({ElementType.PARAMETER, ElementType.METHOD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface Log {
|
||||||
|
/**
|
||||||
|
* 模块
|
||||||
|
*/
|
||||||
|
String title() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能
|
||||||
|
*/
|
||||||
|
BusinessType businessType() default BusinessType.OTHER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作人类别
|
||||||
|
*/
|
||||||
|
OperatorType operatorType() default OperatorType.MANAGE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否保存请求的参数
|
||||||
|
*/
|
||||||
|
boolean isSaveRequestData() default true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否保存响应的参数
|
||||||
|
*/
|
||||||
|
boolean isSaveResponseData() default true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排除指定的请求参数
|
||||||
|
*/
|
||||||
|
String[] excludeParamNames() default {};
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import com.ruoyi.common.enums.LimitType;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限流注解
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface RateLimiter {
|
||||||
|
/**
|
||||||
|
* 限流key,支持使用Spring el表达式来动态获取方法上的参数值
|
||||||
|
* 格式类似于 #code.id #{#code}
|
||||||
|
*/
|
||||||
|
String key() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限流时间,单位秒
|
||||||
|
*/
|
||||||
|
int time() default 60;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限流次数
|
||||||
|
*/
|
||||||
|
int count() default 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限流类型
|
||||||
|
*/
|
||||||
|
LimitType limitType() default LimitType.DEFAULT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示消息 支持国际化 格式为 {code}
|
||||||
|
*/
|
||||||
|
String message() default "{rate.limiter.message}";
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.ruoyi.common.enums.SensitiveStrategy;
|
||||||
|
import com.ruoyi.common.jackson.SensitiveJsonSerializer;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据脱敏注解
|
||||||
|
*
|
||||||
|
* @author zhujie
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@JacksonAnnotationsInside
|
||||||
|
@JsonSerialize(using = SensitiveJsonSerializer.class)
|
||||||
|
public @interface Sensitive {
|
||||||
|
SensitiveStrategy strategy();
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.ruoyi.common.translation.handler.TranslationHandler;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用翻译注解
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Inherited
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD, ElementType.METHOD})
|
||||||
|
@Documented
|
||||||
|
@JacksonAnnotationsInside
|
||||||
|
@JsonSerialize(using = TranslationHandler.class)
|
||||||
|
public @interface Translation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型 (需与实现类上的 {@link com.ruoyi.common.annotation.TranslationType} 注解type对应)
|
||||||
|
* <p>
|
||||||
|
* 默认取当前字段的值 如果设置了 @{@link Translation#mapper()} 则取映射字段的值
|
||||||
|
*/
|
||||||
|
String type();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 映射字段 (如果不为空则取此字段的值)
|
||||||
|
*/
|
||||||
|
String mapper() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 其他条件 例如: 字典type(sys_user_sex)
|
||||||
|
*/
|
||||||
|
String other() default "";
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 翻译类型注解 (标注到{@link com.ruoyi.common.translation.TranslationInterface} 的实现类)
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Inherited
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE})
|
||||||
|
@Documented
|
||||||
|
public @interface TranslationType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
String type();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
package com.ruoyi.common.captcha;
|
||||||
|
|
||||||
|
import cn.hutool.captcha.generator.CodeGenerator;
|
||||||
|
import cn.hutool.core.math.Calculator;
|
||||||
|
import cn.hutool.core.util.CharUtil;
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无符号计算生成器
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public class UnsignedMathGenerator implements CodeGenerator {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -5514819971774091076L;
|
||||||
|
|
||||||
|
private static final String OPERATORS = "+-*";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参与计算数字最大长度
|
||||||
|
*/
|
||||||
|
private final int numberLength;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*/
|
||||||
|
public UnsignedMathGenerator() {
|
||||||
|
this(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param numberLength 参与计算最大数字位数
|
||||||
|
*/
|
||||||
|
public UnsignedMathGenerator(int numberLength) {
|
||||||
|
this.numberLength = numberLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generate() {
|
||||||
|
final int limit = getLimit();
|
||||||
|
int a = RandomUtil.randomInt(limit);
|
||||||
|
int b = RandomUtil.randomInt(limit);
|
||||||
|
String max = Integer.toString(Math.max(a,b));
|
||||||
|
String min = Integer.toString(Math.min(a,b));
|
||||||
|
max = StringUtils.rightPad(max, this.numberLength, CharUtil.SPACE);
|
||||||
|
min = StringUtils.rightPad(min, this.numberLength, CharUtil.SPACE);
|
||||||
|
|
||||||
|
return max + RandomUtil.randomChar(OPERATORS) + min + '=';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean verify(String code, String userInputCode) {
|
||||||
|
int result;
|
||||||
|
try {
|
||||||
|
result = Integer.parseInt(userInputCode);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// 用户输入非数字
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int calculateResult = (int) Calculator.conversion(code);
|
||||||
|
return result == calculateResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取验证码长度
|
||||||
|
*
|
||||||
|
* @return 验证码长度
|
||||||
|
*/
|
||||||
|
public int getLength() {
|
||||||
|
return this.numberLength * 2 + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据长度获取参与计算数字最大值
|
||||||
|
*
|
||||||
|
* @return 最大值
|
||||||
|
*/
|
||||||
|
private int getLimit() {
|
||||||
|
return Integer.parseInt("1" + StringUtils.repeat('0', this.numberLength));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
package com.ruoyi.common.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取项目相关配置
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "ruoyi")
|
||||||
|
public class RuoYiConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本
|
||||||
|
*/
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版权年份
|
||||||
|
*/
|
||||||
|
private String copyrightYear;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例演示开关
|
||||||
|
*/
|
||||||
|
private boolean demoEnabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存懒加载
|
||||||
|
*/
|
||||||
|
private boolean cacheLazy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取地址开关
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private static boolean addressEnabled;
|
||||||
|
|
||||||
|
public void setAddressEnabled(boolean addressEnabled) {
|
||||||
|
RuoYiConfig.addressEnabled = addressEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
package com.ruoyi.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存的key 常量
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public interface CacheConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录用户 redis key
|
||||||
|
*/
|
||||||
|
String LOGIN_TOKEN_KEY = "Authorization:login:token:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在线用户 redis key
|
||||||
|
*/
|
||||||
|
String ONLINE_TOKEN_KEY = "online_tokens:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码 redis key
|
||||||
|
*/
|
||||||
|
String CAPTCHA_CODE_KEY = "captcha_codes:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数管理 cache key
|
||||||
|
*/
|
||||||
|
String SYS_CONFIG_KEY = "sys_config:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典管理 cache key
|
||||||
|
*/
|
||||||
|
String SYS_DICT_KEY = "sys_dict:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 防重提交 redis key
|
||||||
|
*/
|
||||||
|
String REPEAT_SUBMIT_KEY = "repeat_submit:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限流 redis key
|
||||||
|
*/
|
||||||
|
String RATE_LIMIT_KEY = "rate_limit:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录账户密码错误次数 redis key
|
||||||
|
*/
|
||||||
|
String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
|
||||||
|
}
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
package com.ruoyi.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存组名称常量
|
||||||
|
* <p>
|
||||||
|
* key 格式为 cacheNames#ttl#maxIdleTime#maxSize
|
||||||
|
* <p>
|
||||||
|
* ttl 过期时间 如果设置为0则不过期 默认为0
|
||||||
|
* maxIdleTime 最大空闲时间 根据LRU算法清理空闲数据 如果设置为0则不检测 默认为0
|
||||||
|
* maxSize 组最大长度 根据LRU算法清理溢出数据 如果设置为0则无限长 默认为0
|
||||||
|
* <p>
|
||||||
|
* 例子: test#60s、test#0#60s、test#0#1m#1000、test#1h#0#500
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public interface CacheNames {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 演示案例
|
||||||
|
*/
|
||||||
|
String DEMO_CACHE = "demo:cache#60s#10m#20";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统配置
|
||||||
|
*/
|
||||||
|
String SYS_CONFIG = "sys_config";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据字典
|
||||||
|
*/
|
||||||
|
String SYS_DICT = "sys_dict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户账户
|
||||||
|
*/
|
||||||
|
String SYS_USER_NAME = "sys_user_name#30d";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门
|
||||||
|
*/
|
||||||
|
String SYS_DEPT = "sys_dept#30d";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OSS内容
|
||||||
|
*/
|
||||||
|
String SYS_OSS = "sys_oss#30d";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OSS配置
|
||||||
|
*/
|
||||||
|
String SYS_OSS_CONFIG = "sys_oss_config";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在线用户
|
||||||
|
*/
|
||||||
|
String ONLINE_TOKEN = "online_tokens";
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package com.ruoyi.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 翻译常量
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public interface TransConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id转账号
|
||||||
|
*/
|
||||||
|
String USER_ID_TO_NAME = "user_id_to_name";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门id转名称
|
||||||
|
*/
|
||||||
|
String DEPT_ID_TO_NAME = "dept_id_to_name";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典type转label
|
||||||
|
*/
|
||||||
|
String DICT_TYPE_TO_LABEL = "dict_type_to_label";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ossId转url
|
||||||
|
*/
|
||||||
|
String OSS_ID_TO_URL = "oss_id_to_url";
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
package com.ruoyi.common.convert;
|
||||||
|
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.alibaba.excel.converters.Converter;
|
||||||
|
import com.alibaba.excel.enums.CellDataTypeEnum;
|
||||||
|
import com.alibaba.excel.metadata.GlobalConfiguration;
|
||||||
|
import com.alibaba.excel.metadata.data.ReadCellData;
|
||||||
|
import com.alibaba.excel.metadata.data.WriteCellData;
|
||||||
|
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大数值转换
|
||||||
|
* Excel 数值长度位15位 大于15位的数值转换位字符串
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class ExcelBigNumberConvert implements Converter<Long> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Long> supportJavaTypeKey() {
|
||||||
|
return Long.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CellDataTypeEnum supportExcelTypeKey() {
|
||||||
|
return CellDataTypeEnum.STRING;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||||
|
return Convert.toLong(cellData.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WriteCellData<Object> convertToExcelData(Long object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||||
|
if (ObjectUtil.isNotNull(object)) {
|
||||||
|
String str = Convert.toStr(object);
|
||||||
|
if (str.length() > 15) {
|
||||||
|
return new WriteCellData<>(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WriteCellData<Object> cellData = new WriteCellData<>(new BigDecimal(object));
|
||||||
|
cellData.setType(CellDataTypeEnum.NUMBER);
|
||||||
|
return cellData;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,73 @@
|
|||||||
|
package com.ruoyi.common.convert;
|
||||||
|
|
||||||
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.alibaba.excel.converters.Converter;
|
||||||
|
import com.alibaba.excel.enums.CellDataTypeEnum;
|
||||||
|
import com.alibaba.excel.metadata.GlobalConfiguration;
|
||||||
|
import com.alibaba.excel.metadata.data.ReadCellData;
|
||||||
|
import com.alibaba.excel.metadata.data.WriteCellData;
|
||||||
|
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||||
|
import com.ruoyi.common.annotation.ExcelDictFormat;
|
||||||
|
import com.ruoyi.common.core.service.DictService;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典格式化转换处理
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class ExcelDictConvert implements Converter<Object> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Object> supportJavaTypeKey() {
|
||||||
|
return Object.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CellDataTypeEnum supportExcelTypeKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||||
|
ExcelDictFormat anno = getAnnotation(contentProperty.getField());
|
||||||
|
String type = anno.dictType();
|
||||||
|
String label = cellData.getStringValue();
|
||||||
|
String value;
|
||||||
|
if (StringUtils.isBlank(type)) {
|
||||||
|
value = ExcelUtil.reverseByExp(label, anno.readConverterExp(), anno.separator());
|
||||||
|
} else {
|
||||||
|
value = SpringUtils.getBean(DictService.class).getDictValue(type, label, anno.separator());
|
||||||
|
}
|
||||||
|
return Convert.convert(contentProperty.getField().getType(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WriteCellData<String> convertToExcelData(Object object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||||
|
if (ObjectUtil.isNull(object)) {
|
||||||
|
return new WriteCellData<>("");
|
||||||
|
}
|
||||||
|
ExcelDictFormat anno = getAnnotation(contentProperty.getField());
|
||||||
|
String type = anno.dictType();
|
||||||
|
String value = Convert.toStr(object);
|
||||||
|
String label;
|
||||||
|
if (StringUtils.isBlank(type)) {
|
||||||
|
label = ExcelUtil.convertByExp(value, anno.readConverterExp(), anno.separator());
|
||||||
|
} else {
|
||||||
|
label = SpringUtils.getBean(DictService.class).getDictLabel(type, value, anno.separator());
|
||||||
|
}
|
||||||
|
return new WriteCellData<>(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExcelDictFormat getAnnotation(Field field) {
|
||||||
|
return AnnotationUtil.getAnnotation(field, ExcelDictFormat.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
package com.ruoyi.common.convert;
|
||||||
|
|
||||||
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.alibaba.excel.converters.Converter;
|
||||||
|
import com.alibaba.excel.enums.CellDataTypeEnum;
|
||||||
|
import com.alibaba.excel.metadata.GlobalConfiguration;
|
||||||
|
import com.alibaba.excel.metadata.data.ReadCellData;
|
||||||
|
import com.alibaba.excel.metadata.data.WriteCellData;
|
||||||
|
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||||
|
import com.ruoyi.common.annotation.ExcelEnumFormat;
|
||||||
|
import com.ruoyi.common.utils.reflect.ReflectUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 枚举格式化转换处理
|
||||||
|
*
|
||||||
|
* @author Liang
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class ExcelEnumConvert implements Converter<Object> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Object> supportJavaTypeKey() {
|
||||||
|
return Object.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CellDataTypeEnum supportExcelTypeKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||||
|
Object codeValue = cellData.getData();
|
||||||
|
// 如果是空值
|
||||||
|
if (ObjectUtil.isNull(codeValue)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<Object, String> enumValueMap = beforeConvert(contentProperty);
|
||||||
|
String textValue = enumValueMap.get(codeValue);
|
||||||
|
return Convert.convert(contentProperty.getField().getType(), textValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WriteCellData<String> convertToExcelData(Object object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||||
|
if (ObjectUtil.isNull(object)) {
|
||||||
|
return new WriteCellData<>("");
|
||||||
|
}
|
||||||
|
Map<Object, String> enumValueMap = beforeConvert(contentProperty);
|
||||||
|
String value = Convert.toStr(enumValueMap.get(object), "");
|
||||||
|
return new WriteCellData<>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Object, String> beforeConvert(ExcelContentProperty contentProperty) {
|
||||||
|
ExcelEnumFormat anno = getAnnotation(contentProperty.getField());
|
||||||
|
Map<Object, String> enumValueMap = new HashMap<>();
|
||||||
|
Enum<?>[] enumConstants = anno.enumClass().getEnumConstants();
|
||||||
|
for (Enum<?> enumConstant : enumConstants) {
|
||||||
|
Object codeValue = ReflectUtils.invokeGetter(enumConstant, anno.codeField());
|
||||||
|
String textValue = ReflectUtils.invokeGetter(enumConstant, anno.textField());
|
||||||
|
enumValueMap.put(codeValue, textValue);
|
||||||
|
}
|
||||||
|
return enumValueMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExcelEnumFormat getAnnotation(Field field) {
|
||||||
|
return AnnotationUtil.getAnnotation(field, ExcelEnumFormat.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
package com.ruoyi.common.core.controller;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* web层通用数据处理
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public class BaseController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应返回结果
|
||||||
|
*
|
||||||
|
* @param rows 影响行数
|
||||||
|
* @return 操作结果
|
||||||
|
*/
|
||||||
|
protected R<Void> toAjax(int rows) {
|
||||||
|
return rows > 0 ? R.ok() : R.fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应返回结果
|
||||||
|
*
|
||||||
|
* @param result 结果
|
||||||
|
* @return 操作结果
|
||||||
|
*/
|
||||||
|
protected R<Void> toAjax(boolean result) {
|
||||||
|
return result ? R.ok() : R.fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面跳转
|
||||||
|
*/
|
||||||
|
public String redirect(String url) {
|
||||||
|
return StringUtils.format("redirect:{}", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户缓存信息
|
||||||
|
*/
|
||||||
|
public LoginUser getLoginUser() {
|
||||||
|
return LoginHelper.getLoginUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取登录用户id
|
||||||
|
*/
|
||||||
|
public Long getUserId() {
|
||||||
|
return LoginHelper.getUserId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取登录部门id
|
||||||
|
*/
|
||||||
|
public Long getDeptId() {
|
||||||
|
return LoginHelper.getDeptId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取登录用户名
|
||||||
|
*/
|
||||||
|
public String getUsername() {
|
||||||
|
return LoginHelper.getUsername();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
package com.ruoyi.common.core.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity基类
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BaseEntity implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索值
|
||||||
|
*/
|
||||||
|
@JsonIgnore
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String searchValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建者
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新者
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求参数
|
||||||
|
*/
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Map<String, Object> params = new HashMap<>();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,112 @@
|
|||||||
|
package com.ruoyi.common.core.domain;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.utils.sql.SqlUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询实体类
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PageQuery implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页大小
|
||||||
|
*/
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前页数
|
||||||
|
*/
|
||||||
|
private Integer pageNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序列
|
||||||
|
*/
|
||||||
|
private String orderByColumn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序的方向desc或者asc
|
||||||
|
*/
|
||||||
|
private String isAsc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前记录起始索引 默认值
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_PAGE_NUM = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每页显示记录数 默认值 默认查全部
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
|
||||||
|
|
||||||
|
public <T> Page<T> build() {
|
||||||
|
Integer pageNum = ObjectUtil.defaultIfNull(getPageNum(), DEFAULT_PAGE_NUM);
|
||||||
|
Integer pageSize = ObjectUtil.defaultIfNull(getPageSize(), DEFAULT_PAGE_SIZE);
|
||||||
|
if (pageNum <= 0) {
|
||||||
|
pageNum = DEFAULT_PAGE_NUM;
|
||||||
|
}
|
||||||
|
Page<T> page = new Page<>(pageNum, pageSize);
|
||||||
|
List<OrderItem> orderItems = buildOrderItem();
|
||||||
|
if (CollUtil.isNotEmpty(orderItems)) {
|
||||||
|
page.addOrder(orderItems);
|
||||||
|
}
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建排序
|
||||||
|
*
|
||||||
|
* 支持的用法如下:
|
||||||
|
* {isAsc:"asc",orderByColumn:"id"} order by id asc
|
||||||
|
* {isAsc:"asc",orderByColumn:"id,createTime"} order by id asc,create_time asc
|
||||||
|
* {isAsc:"desc",orderByColumn:"id,createTime"} order by id desc,create_time desc
|
||||||
|
* {isAsc:"asc,desc",orderByColumn:"id,createTime"} order by id asc,create_time desc
|
||||||
|
*/
|
||||||
|
private List<OrderItem> buildOrderItem() {
|
||||||
|
if (StringUtils.isBlank(orderByColumn) || StringUtils.isBlank(isAsc)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String orderBy = SqlUtil.escapeOrderBySql(orderByColumn);
|
||||||
|
orderBy = StringUtils.toUnderScoreCase(orderBy);
|
||||||
|
|
||||||
|
// 兼容前端排序类型
|
||||||
|
isAsc = StringUtils.replaceEach(isAsc, new String[]{"ascending", "descending"}, new String[]{"asc", "desc"});
|
||||||
|
|
||||||
|
String[] orderByArr = orderBy.split(StringUtils.SEPARATOR);
|
||||||
|
String[] isAscArr = isAsc.split(StringUtils.SEPARATOR);
|
||||||
|
if (isAscArr.length != 1 && isAscArr.length != orderByArr.length) {
|
||||||
|
throw new ServiceException("排序参数有误");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<OrderItem> list = new ArrayList<>();
|
||||||
|
// 每个字段各自排序
|
||||||
|
for (int i = 0; i < orderByArr.length; i++) {
|
||||||
|
String orderByStr = orderByArr[i];
|
||||||
|
String isAscStr = isAscArr.length == 1 ? isAscArr[0] : isAscArr[i];
|
||||||
|
if ("asc".equals(isAscStr)) {
|
||||||
|
list.add(OrderItem.asc(orderByStr));
|
||||||
|
} else if ("desc".equals(isAscStr)) {
|
||||||
|
list.add(OrderItem.desc(orderByStr));
|
||||||
|
} else {
|
||||||
|
throw new ServiceException("排序参数有误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,107 @@
|
|||||||
|
package com.ruoyi.common.core.domain;
|
||||||
|
|
||||||
|
import com.ruoyi.common.constant.HttpStatus;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应信息主体
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class R<T> implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*/
|
||||||
|
public static final int SUCCESS = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*/
|
||||||
|
public static final int FAIL = 500;
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public static <T> R<T> ok() {
|
||||||
|
return restResult(null, SUCCESS, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> ok(T data) {
|
||||||
|
return restResult(data, SUCCESS, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> ok(String msg) {
|
||||||
|
return restResult(null, SUCCESS, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> ok(String msg, T data) {
|
||||||
|
return restResult(data, SUCCESS, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> fail() {
|
||||||
|
return restResult(null, FAIL, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> fail(String msg) {
|
||||||
|
return restResult(null, FAIL, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> fail(T data) {
|
||||||
|
return restResult(data, FAIL, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> fail(String msg, T data) {
|
||||||
|
return restResult(data, FAIL, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> fail(int code, String msg) {
|
||||||
|
return restResult(null, code, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回警告消息
|
||||||
|
*
|
||||||
|
* @param msg 返回内容
|
||||||
|
* @return 警告消息
|
||||||
|
*/
|
||||||
|
public static <T> R<T> warn(String msg) {
|
||||||
|
return restResult(null, HttpStatus.WARN, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回警告消息
|
||||||
|
*
|
||||||
|
* @param msg 返回内容
|
||||||
|
* @param data 数据对象
|
||||||
|
* @return 警告消息
|
||||||
|
*/
|
||||||
|
public static <T> R<T> warn(String msg, T data) {
|
||||||
|
return restResult(data, HttpStatus.WARN, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> R<T> restResult(T data, int code, String msg) {
|
||||||
|
R<T> r = new R<>();
|
||||||
|
r.setCode(code);
|
||||||
|
r.setData(data);
|
||||||
|
r.setMsg(msg);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Boolean isError(R<T> ret) {
|
||||||
|
return !isSuccess(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Boolean isSuccess(R<T> ret) {
|
||||||
|
return R.SUCCESS == ret.getCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package com.ruoyi.common.core.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tree基类
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class TreeEntity<T> extends BaseEntity {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父菜单名称
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String parentName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父菜单ID
|
||||||
|
*/
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子部门
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<T> children = new ArrayList<>();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
package com.ruoyi.common.core.domain.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前在线会话
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserOnlineDTO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话编号
|
||||||
|
*/
|
||||||
|
private String tokenId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门名称
|
||||||
|
*/
|
||||||
|
private String deptName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名称
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录IP地址
|
||||||
|
*/
|
||||||
|
private String ipaddr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录地址
|
||||||
|
*/
|
||||||
|
private String loginLocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 浏览器类型
|
||||||
|
*/
|
||||||
|
private String browser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作系统
|
||||||
|
*/
|
||||||
|
private String os;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录时间
|
||||||
|
*/
|
||||||
|
private Long loginTime;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package com.ruoyi.common.core.domain.event;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录事件
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LogininforEvent implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户账号
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录状态 0成功 1失败
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示消息
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求体
|
||||||
|
*/
|
||||||
|
private HttpServletRequest request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 其他参数
|
||||||
|
*/
|
||||||
|
private Object[] args;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package com.ruoyi.common.core.domain.model;
|
||||||
|
|
||||||
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.hibernate.validator.constraints.Length;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户登录对象
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LoginBody {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "{user.username.not.blank}")
|
||||||
|
@Length(min = UserConstants.USERNAME_MIN_LENGTH, max = UserConstants.USERNAME_MAX_LENGTH, message = "{user.username.length.valid}")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户密码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "{user.password.not.blank}")
|
||||||
|
@Length(min = UserConstants.PASSWORD_MIN_LENGTH, max = UserConstants.PASSWORD_MAX_LENGTH, message = "{user.password.length.valid}")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 唯一标识
|
||||||
|
*/
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,116 @@
|
|||||||
|
package com.ruoyi.common.core.domain.model;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.dto.RoleDTO;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录用户身份权限
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class LoginUser implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门ID
|
||||||
|
*/
|
||||||
|
private Long deptId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门名
|
||||||
|
*/
|
||||||
|
private String deptName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户唯一标识
|
||||||
|
*/
|
||||||
|
private String token;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户类型
|
||||||
|
*/
|
||||||
|
private String userType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录时间
|
||||||
|
*/
|
||||||
|
private Long loginTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过期时间
|
||||||
|
*/
|
||||||
|
private Long expireTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录IP地址
|
||||||
|
*/
|
||||||
|
private String ipaddr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录地点
|
||||||
|
*/
|
||||||
|
private String loginLocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 浏览器类型
|
||||||
|
*/
|
||||||
|
private String browser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作系统
|
||||||
|
*/
|
||||||
|
private String os;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单权限
|
||||||
|
*/
|
||||||
|
private Set<String> menuPermission;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色权限
|
||||||
|
*/
|
||||||
|
private Set<String> rolePermission;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色对象
|
||||||
|
*/
|
||||||
|
private List<RoleDTO> roles;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据权限 当前角色ID
|
||||||
|
*/
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取登录id
|
||||||
|
*/
|
||||||
|
public String getLoginId() {
|
||||||
|
if (userType == null) {
|
||||||
|
throw new IllegalArgumentException("用户类型不能为空");
|
||||||
|
}
|
||||||
|
if (userId == null) {
|
||||||
|
throw new IllegalArgumentException("用户ID不能为空");
|
||||||
|
}
|
||||||
|
return userType + ":" + userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.ruoyi.common.core.domain.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户注册对象
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class RegisterBody extends LoginBody {
|
||||||
|
|
||||||
|
private String userType;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package com.ruoyi.common.core.domain.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信登录对象
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SmsLoginBody {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "{user.phonenumber.not.blank}")
|
||||||
|
private String phonenumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户密码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "{sms.code.not.blank}")
|
||||||
|
private String smsCode;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package com.ruoyi.common.core.domain.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小程序登录用户身份权限
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class XcxLoginUser extends LoginUser {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* openid
|
||||||
|
*/
|
||||||
|
private String openid;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,78 @@
|
|||||||
|
package com.ruoyi.common.core.page;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpStatus;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表格分页数据对象
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class TableDataInfo<T> implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总记录数
|
||||||
|
*/
|
||||||
|
private long total;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表数据
|
||||||
|
*/
|
||||||
|
private List<T> rows;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息状态码
|
||||||
|
*/
|
||||||
|
private int code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息内容
|
||||||
|
*/
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页
|
||||||
|
*
|
||||||
|
* @param list 列表数据
|
||||||
|
* @param total 总记录数
|
||||||
|
*/
|
||||||
|
public TableDataInfo(List<T> list, long total) {
|
||||||
|
this.rows = list;
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> TableDataInfo<T> build(IPage<T> page) {
|
||||||
|
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||||
|
rspData.setCode(HttpStatus.HTTP_OK);
|
||||||
|
rspData.setMsg("查询成功");
|
||||||
|
rspData.setRows(page.getRecords());
|
||||||
|
rspData.setTotal(page.getTotal());
|
||||||
|
return rspData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> TableDataInfo<T> build(List<T> list) {
|
||||||
|
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||||
|
rspData.setCode(HttpStatus.HTTP_OK);
|
||||||
|
rspData.setMsg("查询成功");
|
||||||
|
rspData.setRows(list);
|
||||||
|
rspData.setTotal(list.size());
|
||||||
|
return rspData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> TableDataInfo<T> build() {
|
||||||
|
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||||
|
rspData.setCode(HttpStatus.HTTP_OK);
|
||||||
|
rspData.setMsg("查询成功");
|
||||||
|
return rspData;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.ruoyi.common.core.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用 参数配置服务
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public interface ConfigService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据参数 key 获取参数值
|
||||||
|
*
|
||||||
|
* @param configKey 参数 key
|
||||||
|
* @return 参数值
|
||||||
|
*/
|
||||||
|
String getConfigValue(String configKey);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.ruoyi.common.core.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用 部门服务
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public interface DeptService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过部门ID查询部门名称
|
||||||
|
*
|
||||||
|
* @param deptIds 部门ID串逗号分隔
|
||||||
|
* @return 部门名称串逗号分隔
|
||||||
|
*/
|
||||||
|
String selectDeptNameByIds(String deptIds);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package com.ruoyi.common.core.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用 字典服务
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public interface DictService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分隔符
|
||||||
|
*/
|
||||||
|
String SEPARATOR = ",";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据字典类型和字典值获取字典标签
|
||||||
|
*
|
||||||
|
* @param dictType 字典类型
|
||||||
|
* @param dictValue 字典值
|
||||||
|
* @return 字典标签
|
||||||
|
*/
|
||||||
|
default String getDictLabel(String dictType, String dictValue) {
|
||||||
|
return getDictLabel(dictType, dictValue, SEPARATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据字典类型和字典标签获取字典值
|
||||||
|
*
|
||||||
|
* @param dictType 字典类型
|
||||||
|
* @param dictLabel 字典标签
|
||||||
|
* @return 字典值
|
||||||
|
*/
|
||||||
|
default String getDictValue(String dictType, String dictLabel) {
|
||||||
|
return getDictValue(dictType, dictLabel, SEPARATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据字典类型和字典值获取字典标签
|
||||||
|
*
|
||||||
|
* @param dictType 字典类型
|
||||||
|
* @param dictValue 字典值
|
||||||
|
* @param separator 分隔符
|
||||||
|
* @return 字典标签
|
||||||
|
*/
|
||||||
|
String getDictLabel(String dictType, String dictValue, String separator);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据字典类型和字典标签获取字典值
|
||||||
|
*
|
||||||
|
* @param dictType 字典类型
|
||||||
|
* @param dictLabel 字典标签
|
||||||
|
* @param separator 分隔符
|
||||||
|
* @return 字典值
|
||||||
|
*/
|
||||||
|
String getDictValue(String dictType, String dictLabel, String separator);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.ruoyi.common.core.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用 OSS服务
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public interface OssService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ossId查询对应的url
|
||||||
|
*
|
||||||
|
* @param ossIds ossId串逗号分隔
|
||||||
|
* @return url串逗号分隔
|
||||||
|
*/
|
||||||
|
String selectUrlByIds(String ossIds);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.ruoyi.common.core.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 脱敏服务
|
||||||
|
* 默认管理员不过滤
|
||||||
|
* 需自行根据业务重写实现
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
* @version 3.6.0
|
||||||
|
*/
|
||||||
|
public interface SensitiveService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否脱敏
|
||||||
|
*/
|
||||||
|
boolean isSensitive();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.ruoyi.common.core.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用 用户服务
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public interface UserService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户ID查询用户账户
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 用户账户
|
||||||
|
*/
|
||||||
|
String selectUserNameById(Long userId);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package com.ruoyi.common.core.validate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验分组 add
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public interface AddGroup {
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package com.ruoyi.common.core.validate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验分组 edit
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public interface EditGroup {
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package com.ruoyi.common.core.validate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验分组 query
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
public interface QueryGroup {
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue