Merge branch 'master' of gitee.com:zhijiantianya/ruoyi-vue-pro into master
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.dashboard.framework.file.config;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.controller.common.SysFileController;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.file.InfFileController;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -13,7 +13,7 @@ import javax.validation.constraints.NotNull;
|
||||
public class FileProperties {
|
||||
|
||||
/**
|
||||
* 对应 {@link SysFileController#}
|
||||
* 对应 {@link InfFileController#}
|
||||
*/
|
||||
@NotNull(message = "基础文件路径不能为空")
|
||||
private String basePath;
|
||||
|
@@ -1,18 +1,35 @@
|
||||
package cn.iocoder.dashboard.framework.jackson.config;
|
||||
|
||||
import cn.iocoder.dashboard.framework.jackson.deser.LocalDateTimeDeserializer;
|
||||
import cn.iocoder.dashboard.framework.jackson.ser.LocalDateTimeSerializer;
|
||||
import cn.iocoder.dashboard.util.json.JsonUtils;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("InstantiationOfUtilityClass")
|
||||
public JsonUtils jsonUtils(ObjectMapper objectMapper) {
|
||||
SimpleModule simpleModule = new SimpleModule();
|
||||
/*
|
||||
* 1. 新增Long类型序列化规则,数值超过2^53-1,在JS会出现精度丢失问题,因此Long自动序列化为字符串类型
|
||||
* 2. 新增LocalDateTime序列化、反序列化规则
|
||||
*/
|
||||
simpleModule
|
||||
// .addSerializer(Long.class, ToStringSerializer.instance)
|
||||
// .addSerializer(Long.TYPE, ToStringSerializer.instance)
|
||||
.addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE)
|
||||
.addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE);
|
||||
|
||||
objectMapper.registerModules(simpleModule);
|
||||
|
||||
JsonUtils.init(objectMapper);
|
||||
return new JsonUtils();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.dashboard.framework.jackson.deser;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
/**
|
||||
* LocalDateTime反序列化规则
|
||||
* <p>
|
||||
* 会将毫秒级时间戳反序列化为LocalDateTime
|
||||
*/
|
||||
public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
|
||||
|
||||
public static final LocalDateTimeDeserializer INSTANCE = new LocalDateTimeDeserializer();
|
||||
|
||||
@Override
|
||||
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
return LocalDateTime.ofInstant(Instant.ofEpochMilli(p.getValueAsLong()), ZoneId.systemDefault());
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package cn.iocoder.dashboard.framework.jackson.ser;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
/**
|
||||
* LocalDateTime序列化规则
|
||||
* <p>
|
||||
* 会将LocalDateTime序列化为毫秒级时间戳
|
||||
*/
|
||||
public class LocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
|
||||
|
||||
public static final LocalDateTimeSerializer INSTANCE = new LocalDateTimeSerializer();
|
||||
|
||||
@Override
|
||||
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
gen.writeNumber(value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
|
||||
}
|
||||
}
|
@@ -81,7 +81,7 @@ public class ApiAccessLogFilter extends OncePerRequestFilter {
|
||||
Map<String, String> queryString, String requestBody, Exception ex) {
|
||||
// 处理用户信息
|
||||
accessLog.setUserId(WebFrameworkUtils.getLoginUserId(request));
|
||||
accessLog.setUserType(WebFrameworkUtils.getUesrType(request));
|
||||
accessLog.setUserType(WebFrameworkUtils.getUserType(request));
|
||||
// 设置访问结果
|
||||
CommonResult<?> result = WebFrameworkUtils.getCommonResult(request);
|
||||
if (result != null) {
|
||||
|
@@ -3,6 +3,7 @@ package cn.iocoder.dashboard.framework.logger.apilog.core.service;
|
||||
import cn.iocoder.dashboard.framework.logger.apilog.core.service.dto.ApiAccessLogCreateDTO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* API 访问日志 Framework Service 接口
|
||||
@@ -15,7 +16,8 @@ public interface ApiAccessLogFrameworkService {
|
||||
* 创建 API 访问日志
|
||||
*
|
||||
* @param createDTO 创建信息
|
||||
* @return 是否创建成功
|
||||
*/
|
||||
void createApiAccessLogAsync(@Valid ApiAccessLogCreateDTO createDTO);
|
||||
Future<Boolean> createApiAccessLogAsync(@Valid ApiAccessLogCreateDTO createDTO);
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package cn.iocoder.dashboard.framework.logger.apilog.core.service;
|
||||
import cn.iocoder.dashboard.framework.logger.apilog.core.service.dto.ApiErrorLogCreateDTO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* API 错误日志 Framework Service 接口
|
||||
@@ -15,7 +16,8 @@ public interface ApiErrorLogFrameworkService {
|
||||
* 创建 API 错误日志
|
||||
*
|
||||
* @param createDTO 创建信息
|
||||
* @return 是否创建成功
|
||||
*/
|
||||
void createApiErrorLogAsync(@Valid ApiErrorLogCreateDTO createDTO);
|
||||
Future<Boolean> createApiErrorLogAsync(@Valid ApiErrorLogCreateDTO createDTO);
|
||||
|
||||
}
|
||||
|
@@ -134,7 +134,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
// 静态资源,可匿名访问
|
||||
.antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js").permitAll()
|
||||
// 文件的获取接口,可匿名访问
|
||||
.antMatchers(webProperties.getApiPrefix() + "/system/file/get/**").anonymous()
|
||||
.antMatchers(webProperties.getApiPrefix() + "/infra/file/get/**").anonymous()
|
||||
// Swagger 接口文档
|
||||
.antMatchers("/swagger-ui.html").anonymous()
|
||||
.antMatchers("/swagger-resources/**").anonymous()
|
||||
|
@@ -269,7 +269,7 @@ public class GlobalExceptionHandler {
|
||||
private void initExceptionLog(ApiErrorLogCreateDTO errorLog, HttpServletRequest request, Throwable e) {
|
||||
// 处理用户信息
|
||||
errorLog.setUserId(WebFrameworkUtils.getLoginUserId(request));
|
||||
errorLog.setUserType(WebFrameworkUtils.getUesrType(request));
|
||||
errorLog.setUserType(WebFrameworkUtils.getUserType(request));
|
||||
// 设置异常字段
|
||||
errorLog.setExceptionName(e.getClass().getName());
|
||||
errorLog.setExceptionMessage(ExceptionUtil.getMessage(e));
|
||||
|
@@ -31,7 +31,7 @@ public class WebFrameworkUtils {
|
||||
return (Long) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID);
|
||||
}
|
||||
|
||||
public static Integer getUesrType(HttpServletRequest request) {
|
||||
public static Integer getUserType(HttpServletRequest request) {
|
||||
return UserTypeEnum.ADMIN.getValue(); // TODO 芋艿:等后续优化
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package cn.iocoder.dashboard.modules.infra.controller.doc;
|
||||
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.iocoder.dashboard.util.servlet.ServletUtils;
|
||||
import cn.smallbun.screw.core.Configuration;
|
||||
import cn.smallbun.screw.core.engine.EngineConfig;
|
||||
import cn.smallbun.screw.core.engine.EngineFileType;
|
||||
@@ -10,18 +12,18 @@ import cn.smallbun.screw.core.process.ProcessConfig;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@Api(tags = "数据库文档")
|
||||
@@ -34,36 +36,79 @@ public class InfDbDocController {
|
||||
|
||||
private static final String FILE_OUTPUT_DIR = System.getProperty("java.io.tmpdir") + File.separator
|
||||
+ "db-doc";
|
||||
private static final EngineFileType FILE_OUTPUT_TYPE = EngineFileType.HTML; // 可以设置 Word 或者 Markdown 格式
|
||||
private static final String DOC_FILE_NAME = "数据库文档";
|
||||
private static final String DOC_VERSION = "1.0.0";
|
||||
private static final String DOC_DESCRIPTION = "文档描述";
|
||||
|
||||
@Resource
|
||||
private DataSource dataSource;
|
||||
|
||||
@GetMapping("/export-html")
|
||||
public synchronized void exportHtml(HttpServletResponse response) throws FileNotFoundException {
|
||||
@ApiOperation("导出 html 格式的数据文档")
|
||||
@ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class)
|
||||
public void exportHtml(@RequestParam(defaultValue = "true") Boolean deleteFile,
|
||||
HttpServletResponse response) throws IOException {
|
||||
doExportFile(EngineFileType.HTML, deleteFile, response);
|
||||
}
|
||||
|
||||
@GetMapping("/export-word")
|
||||
@ApiOperation("导出 word 格式的数据文档")
|
||||
@ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class)
|
||||
public void exportWord(@RequestParam(defaultValue = "true") Boolean deleteFile,
|
||||
HttpServletResponse response) throws IOException {
|
||||
doExportFile(EngineFileType.WORD, deleteFile, response);
|
||||
}
|
||||
|
||||
@GetMapping("/export-markdown")
|
||||
@ApiOperation("导出 markdown 格式的数据文档")
|
||||
@ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class)
|
||||
public void exportMarkdown(@RequestParam(defaultValue = "true") Boolean deleteFile,
|
||||
HttpServletResponse response) throws IOException {
|
||||
doExportFile(EngineFileType.MD, deleteFile, response);
|
||||
}
|
||||
|
||||
private void doExportFile(EngineFileType fileOutputType, Boolean deleteFile,
|
||||
HttpServletResponse response) throws IOException {
|
||||
String docFileName = DOC_FILE_NAME + "_" + IdUtil.fastSimpleUUID();
|
||||
String filePath = doExportFile(fileOutputType, docFileName);
|
||||
String downloadFileName = DOC_FILE_NAME + fileOutputType.getFileSuffix(); //下载后的文件名
|
||||
try {
|
||||
// 读取,返回
|
||||
ServletUtils.writeAttachment(response, downloadFileName, FileUtil.readBytes(filePath));
|
||||
} finally {
|
||||
handleDeleteFile(deleteFile, filePath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出文件,返回文件路径
|
||||
*
|
||||
* @param fileOutputType 文件类型
|
||||
* @param fileName 文件名, 无需 ".docx" 等文件后缀
|
||||
* @return 生成的文件所在路径
|
||||
*/
|
||||
private String doExportFile(EngineFileType fileOutputType, String fileName) {
|
||||
try (HikariDataSource dataSource = buildDataSource()) {
|
||||
// 创建 screw 的配置
|
||||
Configuration config = Configuration.builder()
|
||||
.version(DOC_VERSION) // 版本
|
||||
.description(DOC_DESCRIPTION) // 描述
|
||||
.dataSource(dataSource) // 数据源
|
||||
.engineConfig(buildEngineConfig()) // 引擎配置
|
||||
.engineConfig(buildEngineConfig(fileOutputType, fileName)) // 引擎配置
|
||||
.produceConfig(buildProcessConfig()) // 处理配置
|
||||
.build();
|
||||
|
||||
// 执行 screw,生成数据库文档
|
||||
new DocumentationExecute(config).execute();
|
||||
|
||||
// 读取,返回
|
||||
ServletUtil.write(response,
|
||||
new FileInputStream(FILE_OUTPUT_DIR + File.separator + DOC_FILE_NAME + FILE_OUTPUT_TYPE.getFileSuffix()),
|
||||
MediaType.TEXT_HTML_VALUE);
|
||||
return FILE_OUTPUT_DIR + File.separator + fileName + fileOutputType.getFileSuffix();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeleteFile(Boolean deleteFile, String filePath) {
|
||||
if (!deleteFile) {
|
||||
return;
|
||||
}
|
||||
FileUtil.del(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据源
|
||||
*/
|
||||
@@ -71,7 +116,6 @@ public class InfDbDocController {
|
||||
private HikariDataSource buildDataSource() {
|
||||
// 创建 HikariConfig 配置类
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
// hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||
hikariConfig.setJdbcUrl(dataSourceProperties.getUrl());
|
||||
hikariConfig.setUsername(dataSourceProperties.getUsername());
|
||||
hikariConfig.setPassword(dataSourceProperties.getPassword());
|
||||
@@ -83,13 +127,13 @@ public class InfDbDocController {
|
||||
/**
|
||||
* 创建 screw 的引擎配置
|
||||
*/
|
||||
private static EngineConfig buildEngineConfig() {
|
||||
private static EngineConfig buildEngineConfig(EngineFileType fileOutputType, String docFileName) {
|
||||
return EngineConfig.builder()
|
||||
.fileOutputDir(FILE_OUTPUT_DIR) // 生成文件路径
|
||||
.openOutputDir(false) // 打开目录
|
||||
.fileType(FILE_OUTPUT_TYPE) // 文件类型
|
||||
.fileType(fileOutputType) // 文件类型
|
||||
.produceType(EngineTemplateType.freemarker) // 文件类型
|
||||
.fileName(DOC_FILE_NAME) // 自定义文件名称
|
||||
.fileName(docFileName) // 自定义文件名称
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@@ -1,9 +1,13 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.common;
|
||||
package cn.iocoder.dashboard.modules.infra.controller.file;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.common.SysFileDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.common.SysFileService;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.file.vo.InfFileRespVO;
|
||||
import cn.iocoder.dashboard.modules.infra.convert.file.InfFileConvert;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.dashboard.modules.infra.service.file.InfFileService;
|
||||
import cn.iocoder.dashboard.util.servlet.ServletUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@@ -11,40 +15,53 @@ import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
|
||||
@Api(tags = "文件存储")
|
||||
@RestController
|
||||
@RequestMapping("/system/file")
|
||||
@RequestMapping("/infra/file")
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class SysFileController {
|
||||
public class InfFileController {
|
||||
|
||||
@Resource
|
||||
private SysFileService fileService;
|
||||
private InfFileService fileService;
|
||||
|
||||
@PostMapping("/upload")
|
||||
@ApiOperation("上传文件")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "path", value = "文件附件", required = true, dataTypeClass = MultipartFile.class),
|
||||
@ApiImplicitParam(name = "path", value = "文件路径", required = true, example = "yudaoyuanma.png", dataTypeClass = Long.class)
|
||||
@ApiImplicitParam(name = "file", value = "文件附件", required = true, dataTypeClass = MultipartFile.class),
|
||||
@ApiImplicitParam(name = "path", value = "文件路径", required = false, example = "yudaoyuanma.png", dataTypeClass = String.class)
|
||||
})
|
||||
@PostMapping("/upload")
|
||||
public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("path") String path) throws IOException {
|
||||
return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除文件")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:file:delete')")
|
||||
public CommonResult<Boolean> deleteFile(@RequestParam("id") String id) {
|
||||
fileService.deleteFile(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{path}")
|
||||
@ApiOperation("下载文件")
|
||||
@ApiImplicitParam(name = "path", value = "文件附件", required = true, dataTypeClass = MultipartFile.class)
|
||||
@GetMapping("/get/{path}")
|
||||
public void getFile(HttpServletResponse response, @PathVariable("path") String path) throws IOException {
|
||||
SysFileDO file = fileService.getFile(path);
|
||||
InfFileDO file = fileService.getFile(path);
|
||||
if (file == null) {
|
||||
log.warn("[getFile][path({}) 文件不存在]", path);
|
||||
response.setStatus(HttpStatus.NOT_FOUND.value());
|
||||
@@ -53,4 +70,12 @@ public class SysFileController {
|
||||
ServletUtils.writeAttachment(response, path, file.getContent());
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得文件分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:file:query')")
|
||||
public CommonResult<PageResult<InfFileRespVO>> getFilePage(@Valid InfFilePageReqVO pageVO) {
|
||||
PageResult<InfFileDO> pageResult = fileService.getFilePage(pageVO);
|
||||
return success(InfFileConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.dashboard.modules.infra.controller.file.vo;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("文件分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfFilePageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "文件路径", example = "yudao", notes = "模糊匹配")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "文件类型", example = "jpg", notes = "模糊匹配")
|
||||
private String type;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "开始创建时间")
|
||||
private Date beginCreateTime;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "结束创建时间")
|
||||
private Date endCreateTime;
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package cn.iocoder.dashboard.modules.infra.controller.file.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel(value = "文件 Response VO", description = "不返回 content 字段,太大")
|
||||
@Data
|
||||
public class InfFileRespVO {
|
||||
|
||||
@ApiModelProperty(value = "文件路径", required = true, example = "yudao.jpg")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "文件类型", required = true, example = "jpg")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
}
|
@@ -14,7 +14,7 @@ import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOU
|
||||
public class InfApiErrorLogExportReqVO {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", example = "666")
|
||||
private Integer userId;
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "用户类型", example = "1")
|
||||
private Integer userType;
|
||||
|
@@ -19,7 +19,7 @@ import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOU
|
||||
public class InfApiErrorLogPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", example = "666")
|
||||
private Integer userId;
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "用户类型", example = "1")
|
||||
private Integer userType;
|
||||
|
@@ -30,9 +30,9 @@ public class RedisController {
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@GetMapping("/get-monitor-info")
|
||||
@ApiOperation("获得 Redis 监控信息")
|
||||
@PreAuthorize("@ss.hasPermission('infra:redis:get-monitor-info')")
|
||||
@GetMapping("/get-monitor-info")
|
||||
public CommonResult<InfRedisMonitorRespVO> getRedisMonitorInfo() {
|
||||
// 获得 Redis 统计信息
|
||||
Properties info = stringRedisTemplate.execute((RedisCallback<Properties>) RedisServerCommands::info);
|
||||
@@ -44,9 +44,9 @@ public class RedisController {
|
||||
return success(RedisConvert.INSTANCE.build(info, dbSize, commandStats));
|
||||
}
|
||||
|
||||
@GetMapping("/get-key-list")
|
||||
@ApiOperation("获得 Redis Key 列表")
|
||||
@PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')")
|
||||
@GetMapping("/get-key-list")
|
||||
public CommonResult<List<InfRedisKeyRespVO>> getKeyList() {
|
||||
List<RedisKeyDefine> keyDefines = RedisKeyRegistry.list();
|
||||
return success(RedisConvert.INSTANCE.convertList(keyDefines));
|
||||
|
@@ -0,0 +1,18 @@
|
||||
package cn.iocoder.dashboard.modules.infra.convert.file;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.file.vo.InfFileRespVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface InfFileConvert {
|
||||
|
||||
InfFileConvert INSTANCE = Mappers.getMapper(InfFileConvert.class);
|
||||
|
||||
InfFileRespVO convert(InfFileDO bean);
|
||||
|
||||
PageResult<InfFileRespVO> convertPage(PageResult<InfFileDO> page);
|
||||
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package cn.iocoder.dashboard.modules.infra.dal.dataobject.file;
|
||||
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 文件表
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
@TableName("inf_file")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class InfFileDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
*/
|
||||
@TableId(type = IdType.INPUT)
|
||||
private String id;
|
||||
/**
|
||||
* 文件类型
|
||||
*
|
||||
* 通过 {@link cn.hutool.core.io.FileTypeUtil#getType(InputStream)} 获取
|
||||
*/
|
||||
@TableField(value = "`type`")
|
||||
private String type;
|
||||
/**
|
||||
* 文件内容
|
||||
*/
|
||||
private byte[] content;
|
||||
|
||||
}
|
@@ -37,7 +37,7 @@ public class InfApiAccessLogDO extends BaseDO {
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Integer userId;
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户类型
|
||||
*
|
||||
|
@@ -30,7 +30,7 @@ public class InfApiErrorLogDO extends BaseDO {
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Integer userId;
|
||||
private Long userId;
|
||||
/**
|
||||
* 链路追踪编号
|
||||
*
|
||||
@@ -148,6 +148,6 @@ public class InfApiErrorLogDO extends BaseDO {
|
||||
*
|
||||
* 关联 {@link SysUserDO#getId()}
|
||||
*/
|
||||
private Integer processUserId;
|
||||
private Long processUserId;
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.dashboard.modules.infra.dal.mysql.file;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface InfFileMapper extends BaseMapperX<InfFileDO> {
|
||||
|
||||
default Integer selectCountById(String id) {
|
||||
return selectCount("id", id);
|
||||
}
|
||||
|
||||
default PageResult<InfFileDO> selectPage(InfFilePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<InfFileDO>()
|
||||
.likeIfPresent("id", reqVO.getId())
|
||||
.likeIfPresent("type", reqVO.getType())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
|
||||
.orderByDesc("create_time"));
|
||||
}
|
||||
|
||||
}
|
@@ -27,4 +27,7 @@ public interface InfErrorCodeConstants {
|
||||
ErrorCode API_ERROR_LOG_NOT_FOUND = new ErrorCode(1001002000, "API 错误日志不存在");
|
||||
ErrorCode API_ERROR_LOG_PROCESSED = new ErrorCode(1001002001, "API 错误日志已处理");
|
||||
|
||||
// ========== 文件 1001003000 ==========
|
||||
ErrorCode FILE_NOT_EXISTS = new ErrorCode(1001003000, "文件不存在");
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,46 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.file;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
|
||||
/**
|
||||
* 文件 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfFileService {
|
||||
|
||||
/**
|
||||
* 保存文件,并返回文件的访问路径
|
||||
*
|
||||
* @param path 文件路径
|
||||
* @param content 文件内容
|
||||
* @return 文件路径
|
||||
*/
|
||||
String createFile(String path, byte[] content);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteFile(String id);
|
||||
|
||||
/**
|
||||
* 获得文件
|
||||
*
|
||||
* @param path 文件路径
|
||||
* @return 文件
|
||||
*/
|
||||
InfFileDO getFile(String path);
|
||||
|
||||
/**
|
||||
* 获得文件分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 文件分页
|
||||
*/
|
||||
PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO);
|
||||
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.file.impl;
|
||||
|
||||
import cn.hutool.core.io.FileTypeUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.file.config.FileProperties;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.mysql.file.InfFileMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.service.file.InfFileService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.FILE_NOT_EXISTS;
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS;
|
||||
|
||||
/**
|
||||
* 文件 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
public class InfFileServiceImpl implements InfFileService {
|
||||
|
||||
@Resource
|
||||
private InfFileMapper fileMapper;
|
||||
|
||||
@Resource
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@Override
|
||||
public String createFile(String path, byte[] content) {
|
||||
if (fileMapper.selectCountById(path) > 0) {
|
||||
throw exception(FILE_PATH_EXISTS);
|
||||
}
|
||||
// 保存到数据库
|
||||
InfFileDO file = new InfFileDO();
|
||||
file.setId(path);
|
||||
file.setType(FileTypeUtil.getType(new ByteArrayInputStream(content)));
|
||||
file.setContent(content);
|
||||
fileMapper.insert(file);
|
||||
// 拼接路径返回
|
||||
return fileProperties.getBasePath() + path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFile(String id) {
|
||||
// 校验存在
|
||||
this.validateFileExists(id);
|
||||
// 更新
|
||||
fileMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateFileExists(String id) {
|
||||
if (fileMapper.selectById(id) == null) {
|
||||
throw exception(FILE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfFileDO getFile(String path) {
|
||||
return fileMapper.selectById(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO) {
|
||||
return fileMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
@@ -41,7 +41,7 @@ public class InfJobServiceImpl implements InfJobService {
|
||||
private SchedulerManager schedulerManager;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createJob(InfJobCreateReqVO createReqVO) throws SchedulerException {
|
||||
validateCronExpression(createReqVO.getCronExpression());
|
||||
// 校验唯一性
|
||||
@@ -66,7 +66,7 @@ public class InfJobServiceImpl implements InfJobService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateJob(InfJobUpdateReqVO updateReqVO) throws SchedulerException {
|
||||
validateCronExpression(updateReqVO.getCronExpression());
|
||||
// 校验存在
|
||||
@@ -86,7 +86,7 @@ public class InfJobServiceImpl implements InfJobService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateJobStatus(Long id, Integer status) throws SchedulerException {
|
||||
// 校验 status
|
||||
if (!containsAny(status, InfJobStatusEnum.NORMAL.getStatus(), InfJobStatusEnum.STOP.getStatus())) {
|
||||
@@ -120,7 +120,7 @@ public class InfJobServiceImpl implements InfJobService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteJob(Long id) throws SchedulerException {
|
||||
// 校验存在
|
||||
InfJobDO job = this.validateJobExists(id);
|
||||
|
@@ -9,12 +9,13 @@ import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiAccessLogD
|
||||
import cn.iocoder.dashboard.modules.infra.dal.mysql.logger.InfApiAccessLogMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.service.logger.InfApiAccessLogService;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.AsyncResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* API 访问日志 Service 实现类
|
||||
@@ -30,10 +31,11 @@ public class InfApiAccessLogServiceImpl implements InfApiAccessLogService {
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) {
|
||||
public Future<Boolean> createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) {
|
||||
// 插入
|
||||
InfApiAccessLogDO apiAccessLog = InfApiAccessLogConvert.INSTANCE.convert(createDTO);
|
||||
apiAccessLogMapper.insert(apiAccessLog);
|
||||
int insert = apiAccessLogMapper.insert(apiAccessLog);
|
||||
return new AsyncResult<>(insert == 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -10,12 +10,14 @@ import cn.iocoder.dashboard.modules.infra.dal.mysql.logger.InfApiErrorLogMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum;
|
||||
import cn.iocoder.dashboard.modules.infra.service.logger.InfApiErrorLogService;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.AsyncResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_NOT_FOUND;
|
||||
@@ -35,10 +37,11 @@ public class InfApiErrorLogServiceImpl implements InfApiErrorLogService {
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) {
|
||||
public Future<Boolean> createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) {
|
||||
InfApiErrorLogDO apiErrorLog = InfApiErrorLogConvert.INSTANCE.convert(createDTO);
|
||||
apiErrorLog.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus());
|
||||
apiErrorLogMapper.insert(apiErrorLog);
|
||||
int insert = apiErrorLogMapper.insert(apiErrorLog);
|
||||
return new AsyncResult<>(insert == 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +65,7 @@ public class InfApiErrorLogServiceImpl implements InfApiErrorLogService {
|
||||
}
|
||||
// 标记处理
|
||||
apiErrorLogMapper.updateById(InfApiErrorLogDO.builder().id(id).processStatus(processStatus)
|
||||
.processUserId(processStatus).processTime(new Date()).build());
|
||||
.processUserId(processUserId).processTime(new Date()).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
|
||||
import cn.iocoder.dashboard.util.collection.SetUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -34,6 +35,7 @@ import static cn.iocoder.dashboard.util.servlet.ServletUtils.getUserAgent;
|
||||
@Api(tags = "认证")
|
||||
@RestController
|
||||
@RequestMapping("/")
|
||||
@Validated
|
||||
public class SysAuthController {
|
||||
|
||||
@Resource
|
||||
@@ -45,8 +47,8 @@ public class SysAuthController {
|
||||
@Resource
|
||||
private SysPermissionService permissionService;
|
||||
|
||||
@ApiOperation("使用账号密码登录")
|
||||
@PostMapping("/login")
|
||||
@ApiOperation("使用账号密码登录")
|
||||
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
|
||||
public CommonResult<SysAuthLoginRespVO> login(@RequestBody @Valid SysAuthLoginReqVO reqVO) {
|
||||
String token = authService.login(reqVO, getClientIP(), getUserAgent());
|
||||
@@ -54,8 +56,8 @@ public class SysAuthController {
|
||||
return success(SysAuthLoginRespVO.builder().token(token).build());
|
||||
}
|
||||
|
||||
@ApiOperation("获取登陆用户的权限信息")
|
||||
@GetMapping("/get-permission-info")
|
||||
@ApiOperation("获取登陆用户的权限信息")
|
||||
public CommonResult<SysAuthPermissionInfoRespVO> getPermissionInfo() {
|
||||
// 获得用户信息
|
||||
SysUserDO user = userService.getUser(getLoginUserId());
|
||||
@@ -63,9 +65,9 @@ public class SysAuthController {
|
||||
return null;
|
||||
}
|
||||
// 获得角色列表
|
||||
List<SysRoleDO> roleList = roleService.listRolesFromCache(getLoginUserRoleIds());
|
||||
List<SysRoleDO> roleList = roleService.getRolesFromCache(getLoginUserRoleIds());
|
||||
// 获得菜单列表
|
||||
List<SysMenuDO> menuList = permissionService.listRoleMenusFromCache(
|
||||
List<SysMenuDO> menuList = permissionService.getRoleMenusFromCache(
|
||||
getLoginUserRoleIds(), // 注意,基于登陆的角色,因为后续的权限判断也是基于它
|
||||
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType(), MenuTypeEnum.BUTTON.getType()),
|
||||
SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus()));
|
||||
@@ -73,11 +75,11 @@ public class SysAuthController {
|
||||
return success(SysAuthConvert.INSTANCE.convert(user, roleList, menuList));
|
||||
}
|
||||
|
||||
@ApiOperation("获得登陆用户的菜单列表")
|
||||
@GetMapping("list-menus")
|
||||
public CommonResult<List<SysAuthMenuRespVO>> listMenus() {
|
||||
@ApiOperation("获得登陆用户的菜单列表")
|
||||
public CommonResult<List<SysAuthMenuRespVO>> getMenus() {
|
||||
// 获得用户拥有的菜单列表
|
||||
List<SysMenuDO> menuList = permissionService.listRoleMenusFromCache(
|
||||
List<SysMenuDO> menuList = permissionService.getRoleMenusFromCache(
|
||||
getLoginUserRoleIds(), // 注意,基于登陆的角色,因为后续的权限判断也是基于它
|
||||
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType()), // 只要目录和菜单类型
|
||||
SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus())); // 只要开启的
|
||||
|
@@ -39,9 +39,9 @@ public class SysUserSessionController {
|
||||
@Resource
|
||||
private SysDeptService deptService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得 Session 分页列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:user-session:page')")
|
||||
@GetMapping("/page")
|
||||
public CommonResult<PageResult<SysUserSessionPageItemRespVO>> getUserSessionPage(@Validated SysUserSessionPageReqVO reqVO) {
|
||||
// 获得 Session 分页
|
||||
PageResult<SysUserSessionDO> pageResult = userSessionService.getUserSessionPage(reqVO);
|
||||
@@ -66,12 +66,12 @@ public class SysUserSessionController {
|
||||
return success(new PageResult<>(sessionList, pageResult.getTotal()));
|
||||
}
|
||||
|
||||
@ApiOperation("删除 Session")
|
||||
@PreAuthorize("@ss.hasPermission('system:user-session:delete')")
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除 Session")
|
||||
@ApiImplicitParam(name = "id", value = "Session 编号", required = true, dataTypeClass = String.class,
|
||||
example = "fe50b9f6-d177-44b1-8da9-72ea34f63db7")
|
||||
public CommonResult<Boolean> delete(@RequestParam("id") String id) {
|
||||
@PreAuthorize("@ss.hasPermission('system:user-session:delete')")
|
||||
public CommonResult<Boolean> deleteUserSession(@RequestParam("id") String id) {
|
||||
userSessionService.deleteUserSession(id);
|
||||
return success(true);
|
||||
}
|
||||
|
@@ -21,8 +21,8 @@ public class SysCaptchaController {
|
||||
@Resource
|
||||
private SysCaptchaService captchaService;
|
||||
|
||||
@ApiOperation("生成图片验证码")
|
||||
@GetMapping("/get-image")
|
||||
@ApiOperation("生成图片验证码")
|
||||
public CommonResult<SysCaptchaImageRespVO> getCaptchaImage() {
|
||||
return success(captchaService.getCaptchaImage());
|
||||
}
|
||||
|
@@ -9,10 +9,12 @@ import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,65 +23,64 @@ import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
@Api(tags = "部门")
|
||||
@RestController
|
||||
@RequestMapping("/system/dept")
|
||||
@Validated
|
||||
public class SysDeptController {
|
||||
|
||||
@Resource
|
||||
private SysDeptService deptService;
|
||||
|
||||
@ApiOperation("获取部门列表")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dept:list')")
|
||||
@PostMapping("create")
|
||||
@ApiOperation("创建部门")
|
||||
@PreAuthorize("@ss.hasPermission('system:dept:create')")
|
||||
public CommonResult<Long> createDept(@Valid @RequestBody SysDeptCreateReqVO reqVO) {
|
||||
Long deptId = deptService.createDept(reqVO);
|
||||
return success(deptId);
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
@ApiOperation("更新部门")
|
||||
@PreAuthorize("@ss.hasPermission('system:dept:update')")
|
||||
public CommonResult<Boolean> updateDept(@Valid @RequestBody SysDeptUpdateReqVO reqVO) {
|
||||
deptService.updateDept(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("delete")
|
||||
@ApiOperation("删除部门")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('system:dept:delete')")
|
||||
public CommonResult<Boolean> deleteDept(@RequestParam("id") Long id) {
|
||||
deptService.deleteDept(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获取部门列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:dept:query')")
|
||||
public CommonResult<List<SysDeptRespVO>> listDepts(SysDeptListReqVO reqVO) {
|
||||
List<SysDeptDO> list = deptService.listDepts(reqVO);
|
||||
List<SysDeptDO> list = deptService.getSimpleDepts(reqVO);
|
||||
list.sort(Comparator.comparing(SysDeptDO::getSort));
|
||||
return success(SysDeptConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取部门精简信息列表", notes = "只包含被开启的部门,主要用于前端的下拉选项")
|
||||
@GetMapping("/list-all-simple")
|
||||
public CommonResult<List<SysDeptSimpleRespVO>> listSimpleDepts() {
|
||||
@ApiOperation(value = "获取部门精简信息列表", notes = "只包含被开启的部门,主要用于前端的下拉选项")
|
||||
public CommonResult<List<SysDeptSimpleRespVO>> getSimpleDepts() {
|
||||
// 获得部门列表,只要开启状态的
|
||||
SysDeptListReqVO reqVO = new SysDeptListReqVO();
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
List<SysDeptDO> list = deptService.listDepts(reqVO);
|
||||
List<SysDeptDO> list = deptService.getSimpleDepts(reqVO);
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(SysDeptDO::getSort));
|
||||
return success(SysDeptConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得部门信息")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
// @PreAuthorize("@ss.hasPermi('system:dept:query')")
|
||||
@GetMapping("/get")
|
||||
@PreAuthorize("@ss.hasPermission('system:dept:query')")
|
||||
public CommonResult<SysDeptRespVO> getDept(@RequestParam("id") Long id) {
|
||||
return success(SysDeptConvert.INSTANCE.convert(deptService.getDept(id)));
|
||||
}
|
||||
|
||||
@ApiOperation("新增部门")
|
||||
@PostMapping("create")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dept:add')")
|
||||
// @Log(title = "部门管理", businessType = BusinessType.INSERT)
|
||||
public CommonResult<Long> createDept(@Validated @RequestBody SysDeptCreateReqVO reqVO) {
|
||||
Long deptId = deptService.createDept(reqVO);
|
||||
return success(deptId);
|
||||
}
|
||||
|
||||
@ApiOperation("修改部门")
|
||||
@PostMapping("update")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dept:edit')")
|
||||
// @Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> updateDept(@Validated @RequestBody SysDeptUpdateReqVO reqVO) {
|
||||
deptService.updateDept(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("删除部门")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PostMapping("delete")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dept:remove')")
|
||||
// @Log(title = "部门管理", businessType = BusinessType.DELETE)
|
||||
public CommonResult<Boolean> deleteDept(@RequestParam("id") Long id) {
|
||||
deptService.deleteDept(id);
|
||||
return success(true);
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.*;
|
||||
import cn.iocoder.dashboard.modules.system.convert.dept.SysPostConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysPostDO;
|
||||
@@ -11,88 +12,88 @@ import cn.iocoder.dashboard.modules.system.service.dept.SysPostService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "岗位")
|
||||
@RestController
|
||||
@RequestMapping("/system/post")
|
||||
@Valid
|
||||
public class SysPostController {
|
||||
|
||||
@Resource
|
||||
private SysPostService postService;
|
||||
|
||||
@ApiOperation(value = "获取岗位精简信息列表", notes = "只包含被开启的岗位,主要用于前端的下拉选项")
|
||||
@GetMapping("/list-all-simple")
|
||||
public CommonResult<List<SysPostSimpleRespVO>> listSimplePosts() {
|
||||
// 获得岗位列表,只要开启状态的
|
||||
List<SysPostDO> list = postService.listPosts(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(SysPostDO::getSort));
|
||||
return success(SysPostConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@ApiOperation("获得岗位分页列表")
|
||||
@GetMapping("/page")
|
||||
// @PreAuthorize("@ss.hasPermi('system:post:list')")
|
||||
public CommonResult<PageResult<SysPostRespVO>> pagePosts(@Validated SysPostPageReqVO reqVO) {
|
||||
return success(SysPostConvert.INSTANCE.convertPage(postService.pagePosts(reqVO)));
|
||||
}
|
||||
|
||||
@ApiOperation("新增岗位")
|
||||
@PostMapping("/create")
|
||||
// @PreAuthorize("@ss.hasPermi('system:post:add')")
|
||||
// @Log(title = "岗位管理", businessType = BusinessType.INSERT)
|
||||
public CommonResult<Long> createPost(@Validated @RequestBody SysPostCreateReqVO reqVO) {
|
||||
@ApiOperation("创建岗位")
|
||||
@PreAuthorize("@ss.hasPermission('system:post:create')")
|
||||
public CommonResult<Long> createPost(@Valid @RequestBody SysPostCreateReqVO reqVO) {
|
||||
Long postId = postService.createPost(reqVO);
|
||||
return success(postId);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("修改岗位")
|
||||
@PostMapping("/update")
|
||||
// @PreAuthorize("@ss.hasPermi('system:post:edit')")
|
||||
// @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> updatePost(@Validated @RequestBody SysPostUpdateReqVO reqVO) {
|
||||
@PreAuthorize("@ss.hasPermission('system:post:update')")
|
||||
public CommonResult<Boolean> updatePost(@Valid @RequestBody SysPostUpdateReqVO reqVO) {
|
||||
postService.updatePost(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除岗位")
|
||||
@PostMapping("/delete")
|
||||
// @PreAuthorize("@ss.hasPermi('system:post:remove')")
|
||||
// @Log(title = "岗位管理", businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('system:post:delete')")
|
||||
public CommonResult<Boolean> deletePost(@RequestParam("id") Long id) {
|
||||
postService.deletePost(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/get")
|
||||
@ApiOperation("获得岗位信息")
|
||||
@ApiImplicitParam(name = "id", value = "岗位编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
// @PreAuthorize("@ss.hasPermi('system:post:query')")
|
||||
@GetMapping(value = "/get")
|
||||
@PreAuthorize("@ss.hasPermission('system:post:query')")
|
||||
public CommonResult<SysPostRespVO> getPost(@RequestParam("id") Long id) {
|
||||
return success(SysPostConvert.INSTANCE.convert(postService.getPost(id)));
|
||||
}
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@ApiOperation(value = "获取岗位精简信息列表", notes = "只包含被开启的岗位,主要用于前端的下拉选项")
|
||||
public CommonResult<List<SysPostSimpleRespVO>> getSimplePosts() {
|
||||
// 获得岗位列表,只要开启状态的
|
||||
List<SysPostDO> list = postService.getPosts(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(SysPostDO::getSort));
|
||||
return success(SysPostConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得岗位分页列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:post:query')")
|
||||
public CommonResult<PageResult<SysPostRespVO>> getPostPage(@Validated SysPostPageReqVO reqVO) {
|
||||
return success(SysPostConvert.INSTANCE.convertPage(postService.getPostPage(reqVO)));
|
||||
}
|
||||
|
||||
@GetMapping("/export")
|
||||
@ApiOperation("岗位管理")
|
||||
// @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('system:post:export')")
|
||||
@PreAuthorize("@ss.hasPermission('system:post:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void export(HttpServletResponse response, @Validated SysPostExportReqVO reqVO) throws IOException {
|
||||
List<SysPostDO> posts = postService.listPosts(reqVO);
|
||||
List<SysPostExcelVO> excelDataList = SysPostConvert.INSTANCE.convertList03(posts);
|
||||
List<SysPostDO> posts = postService.getPosts(reqVO);
|
||||
List<SysPostExcelVO> data = SysPostConvert.INSTANCE.convertList03(posts);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "岗位数据.xls", "岗位列表",
|
||||
SysPostExcelVO.class, excelDataList);
|
||||
ExcelUtils.write(response, "岗位数据.xls", "岗位列表", SysPostExcelVO.class, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package cn.iocoder.dashboard.modules.system.controller.dict;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.*;
|
||||
import cn.iocoder.dashboard.modules.system.convert.dict.SysDictDataConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.dict.SysDictDataDO;
|
||||
@@ -10,84 +11,85 @@ import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "字典数据")
|
||||
@RestController
|
||||
@RequestMapping("/system/dict-data")
|
||||
@Validated
|
||||
public class SysDictDataController {
|
||||
|
||||
@Resource
|
||||
private SysDictDataService dictDataService;
|
||||
|
||||
@ApiOperation(value = "获得全部字典数据列表", notes = "一般用于管理后台缓存字典数据在本地")
|
||||
@GetMapping("/list-all-simple")
|
||||
// 无需添加权限认证,因为前端全局都需要
|
||||
public CommonResult<List<SysDictDataSimpleVO>> listSimpleDictDatas() {
|
||||
List<SysDictDataDO> list = dictDataService.getDictDataList();
|
||||
return success(SysDictDataConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@ApiOperation("/获得字典类型的分页列表")
|
||||
@GetMapping("/page")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:list')")
|
||||
public CommonResult<PageResult<SysDictDataRespVO>> pageDictTypes(@Validated SysDictDataPageReqVO reqVO) {
|
||||
return success(SysDictDataConvert.INSTANCE.convertPage(dictDataService.getDictDataPage(reqVO)));
|
||||
}
|
||||
|
||||
@ApiOperation("/查询字典数据详细")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@GetMapping(value = "/get")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:query')")
|
||||
public CommonResult<SysDictDataRespVO> getDictData(@RequestParam("id") Long id) {
|
||||
return success(SysDictDataConvert.INSTANCE.convert(dictDataService.getDictData(id)));
|
||||
}
|
||||
|
||||
@ApiOperation("新增字典数据")
|
||||
@PostMapping("/create")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:add')")
|
||||
// @Log(title = "字典数据", businessData = BusinessData.INSERT)
|
||||
public CommonResult<Long> createDictData(@Validated @RequestBody SysDictDataCreateReqVO reqVO) {
|
||||
@ApiOperation("新增字典数据")
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:create')")
|
||||
public CommonResult<Long> createDictData(@Valid @RequestBody SysDictDataCreateReqVO reqVO) {
|
||||
Long dictDataId = dictDataService.createDictData(reqVO);
|
||||
return success(dictDataId);
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
@ApiOperation("修改字典数据")
|
||||
@PostMapping("update")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:edit')")
|
||||
// @Log(title = "字典数据", businessData = BusinessData.UPDATE)
|
||||
public CommonResult<Boolean> updateDictData(@Validated @RequestBody SysDictDataUpdateReqVO reqVO) {
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:update')")
|
||||
public CommonResult<Boolean> updateDictData(@Valid @RequestBody SysDictDataUpdateReqVO reqVO) {
|
||||
dictDataService.updateDictData(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除字典数据")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PostMapping("/delete")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:remove')")
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:delete')")
|
||||
public CommonResult<Boolean> deleteDictData(Long id) {
|
||||
dictDataService.deleteDictData(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("导出字典数据")
|
||||
@GetMapping("/list-all-simple")
|
||||
@ApiOperation(value = "获得全部字典数据列表", notes = "一般用于管理后台缓存字典数据在本地")
|
||||
// 无需添加权限认证,因为前端全局都需要
|
||||
public CommonResult<List<SysDictDataSimpleVO>> getSimpleDictDatas() {
|
||||
List<SysDictDataDO> list = dictDataService.getDictDatas();
|
||||
return success(SysDictDataConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("/获得字典类型的分页列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:query')")
|
||||
public CommonResult<PageResult<SysDictDataRespVO>> getDictTypePage(@Valid SysDictDataPageReqVO reqVO) {
|
||||
return success(SysDictDataConvert.INSTANCE.convertPage(dictDataService.getDictDataPage(reqVO)));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/get")
|
||||
@ApiOperation("/查询字典数据详细")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:query')")
|
||||
public CommonResult<SysDictDataRespVO> getDictData(@RequestParam("id") Long id) {
|
||||
return success(SysDictDataConvert.INSTANCE.convert(dictDataService.getDictData(id)));
|
||||
}
|
||||
|
||||
@GetMapping("/export")
|
||||
// @Log(title = "字典类型", businessType = BusinessType.EXPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:export')")
|
||||
public void export(HttpServletResponse response, @Validated SysDictDataExportReqVO reqVO) throws IOException {
|
||||
List<SysDictDataDO> list = dictDataService.getDictDataList(reqVO);
|
||||
List<SysDictDataExcelVO> excelDataList = SysDictDataConvert.INSTANCE.convertList02(list);
|
||||
@ApiOperation("导出字典数据")
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void export(HttpServletResponse response, @Valid SysDictDataExportReqVO reqVO) throws IOException {
|
||||
List<SysDictDataDO> list = dictDataService.getDictDatas(reqVO);
|
||||
List<SysDictDataExcelVO> data = SysDictDataConvert.INSTANCE.convertList02(list);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "字典数据.xls", "数据列表",
|
||||
SysDictDataExcelVO.class, excelDataList);
|
||||
ExcelUtils.write(response, "字典数据.xls", "数据列表", SysDictDataExcelVO.class, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package cn.iocoder.dashboard.modules.system.controller.dict;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.*;
|
||||
import cn.iocoder.dashboard.modules.system.convert.dict.SysDictTypeConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.dict.SysDictTypeDO;
|
||||
@@ -10,67 +11,68 @@ import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "字典类型")
|
||||
@RestController
|
||||
@RequestMapping("/system/dict-type")
|
||||
@Validated
|
||||
public class SysDictTypeController {
|
||||
|
||||
@Resource
|
||||
private SysDictTypeService dictTypeService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建字典类型")
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:create')")
|
||||
public CommonResult<Long> createDictType(@Valid @RequestBody SysDictTypeCreateReqVO reqVO) {
|
||||
Long dictTypeId = dictTypeService.createDictType(reqVO);
|
||||
return success(dictTypeId);
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation("修改字典类型")
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:update')")
|
||||
public CommonResult<Boolean> updateDictType(@Valid @RequestBody SysDictTypeUpdateReqVO reqVO) {
|
||||
dictTypeService.updateDictType(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除字典类型")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:delete')")
|
||||
public CommonResult<Boolean> deleteDictType(Long id) {
|
||||
dictTypeService.deleteDictType(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("/获得字典类型的分页列表")
|
||||
@GetMapping("/page")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:list')")
|
||||
public CommonResult<PageResult<SysDictTypeRespVO>> pageDictTypes(@Validated SysDictTypePageReqVO reqVO) {
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:quey')")
|
||||
public CommonResult<PageResult<SysDictTypeRespVO>> pageDictTypes(@Valid SysDictTypePageReqVO reqVO) {
|
||||
return success(SysDictTypeConvert.INSTANCE.convertPage(dictTypeService.getDictTypePage(reqVO)));
|
||||
}
|
||||
|
||||
@ApiOperation("/查询字典类型详细")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@GetMapping(value = "/get")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:query')")
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:quey')")
|
||||
public CommonResult<SysDictTypeRespVO> getDictType(@RequestParam("id") Long id) {
|
||||
return success(SysDictTypeConvert.INSTANCE.convert(dictTypeService.getDictType(id)));
|
||||
}
|
||||
|
||||
@ApiOperation("新增字典类型")
|
||||
@PostMapping("/create")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:add')")
|
||||
// @Log(title = "字典类型", businessType = BusinessType.INSERT)
|
||||
public CommonResult<Long> createDictType(@Validated @RequestBody SysDictTypeCreateReqVO reqVO) {
|
||||
Long dictTypeId = dictTypeService.createDictType(reqVO);
|
||||
return success(dictTypeId);
|
||||
}
|
||||
|
||||
@ApiOperation("修改字典类型")
|
||||
@PostMapping("update")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:edit')")
|
||||
// @Log(title = "字典类型", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> updateDictType(@Validated @RequestBody SysDictTypeUpdateReqVO reqVO) {
|
||||
dictTypeService.updateDictType(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("删除字典类型")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PostMapping("/delete")
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:remove')")
|
||||
public CommonResult<Boolean> deleteDictType(Long id) {
|
||||
dictTypeService.deleteDictType(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@ApiOperation(value = "获得全部字典类型列表", notes = "包括开启 + 禁用的字典类型,主要用于前端的下拉选项")
|
||||
// 无需添加权限认证,因为前端全局都需要
|
||||
@@ -81,14 +83,13 @@ public class SysDictTypeController {
|
||||
|
||||
@ApiOperation("导出数据类型")
|
||||
@GetMapping("/export")
|
||||
// @Log(title = "字典类型", businessType = BusinessType.EXPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('system:dict:export')")
|
||||
public void export(HttpServletResponse response, @Validated SysDictTypeExportReqVO reqVO) throws IOException {
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:quey')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void export(HttpServletResponse response, @Valid SysDictTypeExportReqVO reqVO) throws IOException {
|
||||
List<SysDictTypeDO> list = dictTypeService.getDictTypeList(reqVO);
|
||||
List<SysDictTypeExcelVO> excelTypeList = SysDictTypeConvert.INSTANCE.convertList02(list);
|
||||
List<SysDictTypeExcelVO> data = SysDictTypeConvert.INSTANCE.convertList02(list);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "字典类型.xls", "类型列表",
|
||||
SysDictTypeExcelVO.class, excelTypeList);
|
||||
ExcelUtils.write(response, "字典类型.xls", "类型列表", SysDictTypeExcelVO.class, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package cn.iocoder.dashboard.modules.system.controller.logger;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogExcelVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO;
|
||||
@@ -12,6 +13,7 @@ import cn.iocoder.dashboard.modules.system.dal.dataobject.logger.SysLoginLogDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.logger.SysLoginLogService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -19,36 +21,39 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "登陆日志")
|
||||
@RestController
|
||||
@RequestMapping("/system/login-log")
|
||||
@Validated
|
||||
public class SysLoginLogController {
|
||||
|
||||
@Resource
|
||||
private SysLoginLogService loginLogService;
|
||||
|
||||
@ApiOperation("获得登陆日志分页列表")
|
||||
@GetMapping("/page")
|
||||
// @PreAuthorize("@ss.hasPermi('system:login-log:query')")
|
||||
public CommonResult<PageResult<SysLoginLogRespVO>> getLoginLogPage(@Validated SysLoginLogPageReqVO reqVO) {
|
||||
@ApiOperation("获得登陆日志分页列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:login-log:query')")
|
||||
public CommonResult<PageResult<SysLoginLogRespVO>> getLoginLogPage(@Valid SysLoginLogPageReqVO reqVO) {
|
||||
PageResult<SysLoginLogDO> page = loginLogService.getLoginLogPage(reqVO);
|
||||
return CommonResult.success(SysLoginLogConvert.INSTANCE.convertPage(page));
|
||||
}
|
||||
|
||||
@ApiOperation("导出登陆日志 Excel")
|
||||
@GetMapping("/export")
|
||||
// @Log(title = "登录日志", businessType = BusinessType.EXPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')")
|
||||
public void exportLoginLog(HttpServletResponse response, @Validated SysLoginLogExportReqVO reqVO) throws IOException {
|
||||
@ApiOperation("导出登陆日志 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('system:login-log:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportLoginLog(HttpServletResponse response, @Valid SysLoginLogExportReqVO reqVO) throws IOException {
|
||||
List<SysLoginLogDO> list = loginLogService.getLoginLogList(reqVO);
|
||||
// 拼接数据
|
||||
List<SysLoginLogExcelVO> excelDataList = SysLoginLogConvert.INSTANCE.convertList(list);
|
||||
List<SysLoginLogExcelVO> data = SysLoginLogConvert.INSTANCE.convertList(list);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "登陆日志.xls", "数据列表",
|
||||
SysLoginLogExcelVO.class, excelDataList);
|
||||
ExcelUtils.write(response, "登陆日志.xls", "数据列表", SysLoginLogExcelVO.class, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,8 +4,6 @@ import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum;
|
||||
import cn.iocoder.dashboard.framework.logger.operatelog.core.util.OperateLogUtils;
|
||||
import cn.iocoder.dashboard.modules.system.controller.logger.vo.operatelog.SysOperateLogExcelVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.logger.vo.operatelog.SysOperateLogPageReqVO;
|
||||
@@ -19,6 +17,7 @@ import cn.iocoder.dashboard.util.collection.CollectionUtils;
|
||||
import cn.iocoder.dashboard.util.collection.MapUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -26,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -38,32 +38,18 @@ import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.Operat
|
||||
@Api(tags = "操作日志")
|
||||
@RestController
|
||||
@RequestMapping("/system/operate-log")
|
||||
@Validated
|
||||
public class SysOperateLogController {
|
||||
|
||||
@Resource
|
||||
private SysOperateLogService operateLogService;
|
||||
|
||||
@Resource
|
||||
private SysUserService userService;
|
||||
|
||||
@ApiOperation("示例")
|
||||
@OperateLog(type = OperateTypeEnum.OTHER)
|
||||
@GetMapping("/demo")
|
||||
public CommonResult<Boolean> demo() {
|
||||
// 这里可以调用业务逻辑
|
||||
|
||||
// 补全操作日志的明细
|
||||
OperateLogUtils.setContent("将编号 1 的数据,xxx 字段修改成了 yyyy");
|
||||
OperateLogUtils.addExt("orderId", 1);
|
||||
|
||||
// 响应
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("查看操作日志分页列表")
|
||||
@GetMapping("/page")
|
||||
// @PreAuthorize("@ss.hasPermi('system:operate-log:query')")
|
||||
public CommonResult<PageResult<SysOperateLogRespVO>> pageOperateLog(@Validated SysOperateLogPageReqVO reqVO) {
|
||||
@ApiOperation("查看操作日志分页列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:operate-log:query')")
|
||||
public CommonResult<PageResult<SysOperateLogRespVO>> pageOperateLog(@Valid SysOperateLogPageReqVO reqVO) {
|
||||
PageResult<SysOperateLogDO> pageResult = operateLogService.pageOperateLog(reqVO);
|
||||
|
||||
// 获得拼接需要的数据
|
||||
@@ -82,10 +68,9 @@ public class SysOperateLogController {
|
||||
|
||||
@ApiOperation("导出操作日志")
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@ss.hasPermission('system:operate-log:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('system:operate-log:export')")
|
||||
public void exportOperateLog(HttpServletResponse response, @Validated SysOperateLogExportReqVO reqVO)
|
||||
throws IOException {
|
||||
public void exportOperateLog(HttpServletResponse response, @Valid SysOperateLogExportReqVO reqVO) throws IOException {
|
||||
List<SysOperateLogDO> list = operateLogService.listOperateLogs(reqVO);
|
||||
|
||||
// 获得拼接需要的数据
|
||||
@@ -94,8 +79,7 @@ public class SysOperateLogController {
|
||||
// 拼接数据
|
||||
List<SysOperateLogExcelVO> excelDataList = SysOperateLogConvert.INSTANCE.convertList(list, userMap);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "操作日志.xls", "数据列表",
|
||||
SysOperateLogExcelVO.class, excelDataList);
|
||||
ExcelUtils.write(response, "操作日志.xls", "数据列表", SysOperateLogExcelVO.class, excelDataList);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,62 +11,62 @@ import cn.iocoder.dashboard.modules.system.service.notice.SysNoticeService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
|
||||
@Api(tags = "通知公告")
|
||||
@RestController
|
||||
@RequestMapping("/system/notice")
|
||||
@Validated
|
||||
public class SysNoticeController {
|
||||
|
||||
@Resource
|
||||
private SysNoticeService noticeService;
|
||||
|
||||
@ApiOperation("获取通知公告列表")
|
||||
@GetMapping("/page")
|
||||
// @PreAuthorize("@ss.hasPermi('system:notice:list')")
|
||||
public CommonResult<PageResult<SysNoticeRespVO>> pageNotices(@Validated SysNoticePageReqVO reqVO) {
|
||||
return success(SysNoticeConvert.INSTANCE.convertPage(noticeService.pageNotices(reqVO)));
|
||||
}
|
||||
|
||||
@ApiOperation("获得通知公告")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
// @PreAuthorize("@ss.hasPermi('system:notice:query')")
|
||||
@GetMapping(value = "/get")
|
||||
public CommonResult<SysNoticeRespVO> getNotice(@RequestParam("id") Long id) {
|
||||
return success(SysNoticeConvert.INSTANCE.convert(noticeService.getNotice(id)));
|
||||
}
|
||||
|
||||
@ApiOperation("新增通知公告")
|
||||
// @PreAuthorize("@ss.hasPermi('system:notice:add')")
|
||||
// @Log(title = "通知公告", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/create")
|
||||
public CommonResult<Long> createNotice(@Validated @RequestBody SysNoticeCreateReqVO reqVO) {
|
||||
@ApiOperation("创建通知公告")
|
||||
@PreAuthorize("@ss.hasPermission('system:notice:create')")
|
||||
public CommonResult<Long> createNotice(@Valid @RequestBody SysNoticeCreateReqVO reqVO) {
|
||||
Long noticeId = noticeService.createNotice(reqVO);
|
||||
return success(noticeId);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("修改通知公告")
|
||||
// @PreAuthorize("@ss.hasPermi('system:notice:edit')")
|
||||
// @Log(title = "通知公告", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
public CommonResult<Boolean> updateNotice(@Validated @RequestBody SysNoticeUpdateReqVO reqVO) {
|
||||
@PreAuthorize("@ss.hasPermission('system:notice:update')")
|
||||
public CommonResult<Boolean> updateNotice(@Valid @RequestBody SysNoticeUpdateReqVO reqVO) {
|
||||
noticeService.updateNotice(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除通知公告")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
// @PreAuthorize("@ss.hasPermi('system:notice:remove')")
|
||||
// @Log(title = "通知公告", businessType = BusinessType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@PreAuthorize("@ss.hasPermission('system:notice:delete')")
|
||||
public CommonResult<Boolean> deleteNotice(@RequestParam("id") Long id) {
|
||||
noticeService.deleteNotice(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获取通知公告列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:notice:quey')")
|
||||
public CommonResult<PageResult<SysNoticeRespVO>> pageNotices(@Validated SysNoticePageReqVO reqVO) {
|
||||
return success(SysNoticeConvert.INSTANCE.convertPage(noticeService.pageNotices(reqVO)));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得通知公告")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('system:notice:quey')")
|
||||
public CommonResult<SysNoticeRespVO> getNotice(@RequestParam("id") Long id) {
|
||||
return success(SysNoticeConvert.INSTANCE.convert(noticeService.getNotice(id)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -9,10 +9,12 @@ import cn.iocoder.dashboard.modules.system.service.permission.SysMenuService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,78 +23,64 @@ import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
@Api(tags = "菜单")
|
||||
@RestController
|
||||
@RequestMapping("/system/menu")
|
||||
@Validated
|
||||
public class SysMenuController {
|
||||
|
||||
@Resource
|
||||
private SysMenuService menuService;
|
||||
|
||||
@ApiOperation("获取菜单列表")
|
||||
// @PreAuthorize("@ss.hasPermi('system:menu:list')")
|
||||
@GetMapping("/list")
|
||||
public CommonResult<List<SysMenuRespVO>> listMenus(SysMenuListReqVO reqVO) {
|
||||
List<SysMenuDO> list = menuService.listMenus(reqVO);
|
||||
list.sort(Comparator.comparing(SysMenuDO::getSort));
|
||||
return success(SysMenuConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取菜单精简信息列表", notes = "只包含被开启的菜单,主要用于前端的下拉选项")
|
||||
@GetMapping("/list-all-simple")
|
||||
public CommonResult<List<SysMenuSimpleRespVO>> listSimpleMenus() {
|
||||
// 获得菜单列表,只要开启状态的
|
||||
SysMenuListReqVO reqVO = new SysMenuListReqVO();
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
List<SysMenuDO> list = menuService.listMenus(reqVO);
|
||||
// 排序后,返回个诶前端
|
||||
list.sort(Comparator.comparing(SysMenuDO::getSort));
|
||||
return success(SysMenuConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@ApiOperation("获取菜单信息")
|
||||
@GetMapping("/get")
|
||||
// @PreAuthorize("@ss.hasPermi('system:menu:query')")
|
||||
public CommonResult<SysMenuRespVO> getMenu(Long id) {
|
||||
SysMenuDO menu = menuService.getMenu(id);
|
||||
return success(SysMenuConvert.INSTANCE.convert(menu));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 加载对应角色菜单列表树
|
||||
// */
|
||||
// @GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
||||
// public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
|
||||
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
// List<SysMenu> menus = menuService.selectMenuList(loginUser.getUser().getUserId());
|
||||
// AjaxResult ajax = AjaxResult.success();
|
||||
// ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId));
|
||||
// ajax.put("menus", menuService.buildMenuTreeSelect(menus));
|
||||
// return ajax;
|
||||
// }
|
||||
|
||||
@ApiOperation("创建菜单")
|
||||
// @PreAuthorize("@ss.hasPermi('system:menu:add')")
|
||||
// @Log(title = "菜单管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/create")
|
||||
public CommonResult<Long> createMenu(@Validated @RequestBody SysMenuCreateReqVO reqVO) {
|
||||
@ApiOperation("创建菜单")
|
||||
@PreAuthorize("@ss.hasPermission('system:menu:create')")
|
||||
public CommonResult<Long> createMenu(@Valid @RequestBody SysMenuCreateReqVO reqVO) {
|
||||
Long menuId = menuService.createMenu(reqVO);
|
||||
return success(menuId);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("修改菜单")
|
||||
// @PreAuthorize("@ss.hasPermi('system:menu:edit')")
|
||||
// @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
public CommonResult<Boolean> updateMenu(@Validated @RequestBody SysMenuUpdateReqVO reqVO) {
|
||||
@PreAuthorize("@ss.hasPermission('system:menu:update')")
|
||||
public CommonResult<Boolean> updateMenu(@Valid @RequestBody SysMenuUpdateReqVO reqVO) {
|
||||
menuService.updateMenu(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除菜单")
|
||||
@PostMapping("/delete")
|
||||
@ApiImplicitParam(name = "id", value = "角色编号", required= true, example = "1024", dataTypeClass = Long.class)
|
||||
// @Log(title = "菜单管理", businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('system:menu:delete')")
|
||||
public CommonResult<Boolean> deleteMenu(@RequestParam("id") Long id) {
|
||||
menuService.deleteMenu(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获取菜单列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:menu:query')")
|
||||
public CommonResult<List<SysMenuRespVO>> getMenus(SysMenuListReqVO reqVO) {
|
||||
List<SysMenuDO> list = menuService.getMenus(reqVO);
|
||||
list.sort(Comparator.comparing(SysMenuDO::getSort));
|
||||
return success(SysMenuConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@ApiOperation(value = "获取菜单精简信息列表", notes = "只包含被开启的菜单,主要用于前端的下拉选项")
|
||||
public CommonResult<List<SysMenuSimpleRespVO>> getSimpleMenus() {
|
||||
// 获得菜单列表,只要开启状态的
|
||||
SysMenuListReqVO reqVO = new SysMenuListReqVO();
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
List<SysMenuDO> list = menuService.getMenus(reqVO);
|
||||
// 排序后,返回个诶前端
|
||||
list.sort(Comparator.comparing(SysMenuDO::getSort));
|
||||
return success(SysMenuConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获取菜单信息")
|
||||
@PreAuthorize("@ss.hasPermission('system:menu:query')")
|
||||
public CommonResult<SysMenuRespVO> getMenu(Long id) {
|
||||
SysMenuDO menu = menuService.getMenu(id);
|
||||
return success(SysMenuConvert.INSTANCE.convert(menu));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.*;
|
||||
import cn.iocoder.dashboard.modules.system.convert.permission.SysRoleConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysRoleDO;
|
||||
@@ -11,96 +12,95 @@ import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "角色")
|
||||
@RestController
|
||||
@RequestMapping("/system/role")
|
||||
@Validated
|
||||
public class SysRoleController {
|
||||
|
||||
@Resource
|
||||
private SysRoleService roleService;
|
||||
|
||||
@ApiOperation("获得角色分页")
|
||||
@GetMapping("/page")
|
||||
// @PreAuthorize("@ss.hasPermi('system:role:list')")
|
||||
public CommonResult<PageResult<SysRoleDO>> list(SysRolePageReqVO reqVO) {
|
||||
return success(roleService.pageRole(reqVO));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取角色精简信息列表", notes = "只包含被开启的角色,主要用于前端的下拉选项")
|
||||
@GetMapping("/list-all-simple")
|
||||
public CommonResult<List<SysRoleSimpleRespVO>> listSimpleRoles() {
|
||||
// 获得角色列表,只要开启状态的
|
||||
List<SysRoleDO> list = roleService.listRoles(Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 排序后,返回个诶前端
|
||||
list.sort(Comparator.comparing(SysRoleDO::getSort));
|
||||
return success(SysRoleConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@ApiOperation("创建角色")
|
||||
@PostMapping("/create")
|
||||
// @PreAuthorize("@ss.hasPermi('system:role:add')")
|
||||
// @Log(title = "角色管理", businessType = BusinessType.INSERT)
|
||||
public CommonResult<Long> add(@Validated @RequestBody SysRoleCreateReqVO reqVO) {
|
||||
@ApiOperation("创建角色")
|
||||
@PreAuthorize("@ss.hasPermission('system:role:create')")
|
||||
public CommonResult<Long> createRole(@Valid @RequestBody SysRoleCreateReqVO reqVO) {
|
||||
return success(roleService.createRole(reqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("修改角色")
|
||||
// @PreAuthorize("@ss.hasPermi('system:role:edit')")
|
||||
// @Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
public CommonResult<Boolean> update(@Validated @RequestBody SysRoleUpdateReqVO reqVO) {
|
||||
@PreAuthorize("@ss.hasPermission('system:role:update')")
|
||||
public CommonResult<Boolean> updateRole(@Valid @RequestBody SysRoleUpdateReqVO reqVO) {
|
||||
roleService.updateRole(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-status")
|
||||
@ApiOperation("修改角色状态")
|
||||
@PreAuthorize("@ss.hasPermission('system:role:update')")
|
||||
public CommonResult<Boolean> updateRoleStatus(@Valid @RequestBody SysRoleUpdateStatusReqVO reqVO) {
|
||||
roleService.updateRoleStatus(reqVO.getId(), reqVO.getStatus());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除角色")
|
||||
@PostMapping("/delete")
|
||||
@ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
// @PreAuthorize("@ss.hasPermi('system:role:remove')")
|
||||
// @Log(title = "角色管理", businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('system:role:delete')")
|
||||
public CommonResult<Boolean> deleteRole(@RequestParam("id") Long id) {
|
||||
roleService.deleteRole(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("获得角色信息")
|
||||
@GetMapping("/get")
|
||||
// @PreAuthorize("@ss.hasPermi('system:role:query')")
|
||||
@ApiOperation("获得角色信息")
|
||||
@PreAuthorize("@ss.hasPermission('system:role:query')")
|
||||
public CommonResult<SysRoleRespVO> getRole(@RequestParam("id") Long id) {
|
||||
SysRoleDO role = roleService.getRole(id);
|
||||
return success(SysRoleConvert.INSTANCE.convert(role));
|
||||
}
|
||||
|
||||
@ApiOperation("修改角色状态")
|
||||
@PostMapping("/update-status")
|
||||
// @PreAuthorize("@ss.hasPermi('system:role:edit')")
|
||||
// @Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> updateRoleStatus(@Validated @RequestBody SysRoleUpdateStatusReqVO reqVO) {
|
||||
roleService.updateRoleStatus(reqVO.getId(), reqVO.getStatus());
|
||||
return success(true);
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得角色分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:role:query')")
|
||||
public CommonResult<PageResult<SysRoleDO>> getRolePage(SysRolePageReqVO reqVO) {
|
||||
return success(roleService.getRolePage(reqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@ApiOperation(value = "获取角色精简信息列表", notes = "只包含被开启的角色,主要用于前端的下拉选项")
|
||||
public CommonResult<List<SysRoleSimpleRespVO>> getSimpleRoles() {
|
||||
// 获得角色列表,只要开启状态的
|
||||
List<SysRoleDO> list = roleService.getRoles(Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 排序后,返回个诶前端
|
||||
list.sort(Comparator.comparing(SysRoleDO::getSort));
|
||||
return success(SysRoleConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@GetMapping("/export")
|
||||
// @Log(title = "角色管理", businessType = BusinessType.EXPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('system:role:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
@PreAuthorize("@ss.hasPermission('system:role:export')")
|
||||
public void export(HttpServletResponse response, @Validated SysRoleExportReqVO reqVO) throws IOException {
|
||||
List<SysRoleDO> list = roleService.listRoles(reqVO);
|
||||
List<SysRoleExcelVO> excelDataList = SysRoleConvert.INSTANCE.convertList03(list);
|
||||
List<SysRoleDO> list = roleService.getRoles(reqVO);
|
||||
List<SysRoleExcelVO> data = SysRoleConvert.INSTANCE.convertList03(list);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "角色数据.xls", "角色列表",
|
||||
SysRoleExcelVO.class, excelDataList);
|
||||
ExcelUtils.write(response, "角色数据.xls", "角色列表", SysRoleExcelVO.class, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.*;
|
||||
import cn.iocoder.dashboard.modules.system.convert.user.SysUserConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysDeptDO;
|
||||
@@ -25,14 +26,17 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "用户")
|
||||
@RestController
|
||||
@RequestMapping("/system/user")
|
||||
@Validated
|
||||
public class SysUserController {
|
||||
|
||||
@Resource
|
||||
@@ -40,12 +44,53 @@ public class SysUserController {
|
||||
@Resource
|
||||
private SysDeptService deptService;
|
||||
|
||||
@ApiOperation("获得用户分页列表")
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("新增用户")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:create')")
|
||||
public CommonResult<Long> createUser(@Valid @RequestBody SysUserCreateReqVO reqVO) {
|
||||
Long id = userService.createUser(reqVO);
|
||||
return success(id);
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
@ApiOperation("修改用户")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:update')")
|
||||
public CommonResult<Boolean> updateUser(@Valid @RequestBody SysUserUpdateReqVO reqVO) {
|
||||
userService.updateUser(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除用户")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('system:user:delete')")
|
||||
public CommonResult<Boolean> deleteUser(@RequestParam("id") Long id) {
|
||||
userService.deleteUser(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-password")
|
||||
@ApiOperation("重置用户密码")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:update-password')")
|
||||
public CommonResult<Boolean> updateUserPassword(@Valid @RequestBody SysUserUpdatePasswordReqVO reqVO) {
|
||||
userService.updateUserPassword(reqVO.getId(), reqVO.getPassword());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-status")
|
||||
@ApiOperation("修改用户状态")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:update')")
|
||||
public CommonResult<Boolean> updateUserStatus(@Valid @RequestBody SysUserUpdateStatusReqVO reqVO) {
|
||||
userService.updateUserStatus(reqVO.getId(), reqVO.getStatus());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得用户分页列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:list')")
|
||||
public CommonResult<PageResult<SysUserPageItemRespVO>> pageUsers(@Validated SysUserPageReqVO reqVO) {
|
||||
public CommonResult<PageResult<SysUserPageItemRespVO>> getUserPage(@Valid SysUserPageReqVO reqVO) {
|
||||
// 获得用户分页列表
|
||||
PageResult<SysUserDO> pageResult = userService.pageUsers(reqVO);
|
||||
PageResult<SysUserDO> pageResult = userService.getUserPage(reqVO);
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return success(new PageResult<>(pageResult.getTotal())); // 返回空
|
||||
}
|
||||
@@ -63,71 +108,22 @@ public class SysUserController {
|
||||
return success(new PageResult<>(userList, pageResult.getTotal()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户编号获取详细信息
|
||||
*/
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得用户详情")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@GetMapping("/get")
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:query')")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:query')")
|
||||
public CommonResult<SysUserRespVO> getInfo(@RequestParam("id") Long id) {
|
||||
return success(SysUserConvert.INSTANCE.convert(userService.getUser(id)));
|
||||
}
|
||||
|
||||
@ApiOperation("新增用户")
|
||||
@PostMapping("/create")
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:add')")
|
||||
// @Log(title = "用户管理", businessType = BusinessType.INSERT)
|
||||
public CommonResult<Long> createUser(@Validated @RequestBody SysUserCreateReqVO reqVO) {
|
||||
Long id = userService.createUser(reqVO);
|
||||
return success(id);
|
||||
}
|
||||
|
||||
@ApiOperation("修改用户")
|
||||
@PostMapping("update")
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:edit')")
|
||||
// @Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> updateUser(@Validated @RequestBody SysUserUpdateReqVO reqVO) {
|
||||
userService.updateUser(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("删除用户")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PostMapping("/delete")
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:remove')")
|
||||
// @Log(title = "用户管理", businessType = BusinessType.DELETE)
|
||||
public CommonResult<Boolean> deleteUser(@RequestParam("id") Long id) {
|
||||
userService.deleteUser(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("重置用户密码")
|
||||
@PostMapping("/update-password")
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:resetPwd')")
|
||||
// @Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> updateUserPassword(@Validated @RequestBody SysUserUpdatePasswordReqVO reqVO) {
|
||||
userService.updateUserPassword(reqVO.getId(), reqVO.getPassword());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("修改用户状态")
|
||||
@PostMapping("/update-status")
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:edit')")
|
||||
// @Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
public CommonResult<Boolean> updateUserStatus(@Validated @RequestBody SysUserUpdateStatusReqVO reqVO) {
|
||||
userService.updateUserStatus(reqVO.getId(), reqVO.getStatus());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ApiOperation("导出用户")
|
||||
@GetMapping("/export")
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:export')") , @Validated SysUserExportReqVO reqVO
|
||||
// @Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
||||
@ApiOperation("导出用户")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportUsers(@Validated SysUserExportReqVO reqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
// 获得用户列表
|
||||
List<SysUserDO> users = userService.listUsers(reqVO);
|
||||
List<SysUserDO> users = userService.getUsers(reqVO);
|
||||
|
||||
// 获得拼接需要的数据
|
||||
Collection<Long> deptIds = CollectionUtils.convertList(users, SysUserDO::getDeptId);
|
||||
@@ -147,8 +143,8 @@ public class SysUserController {
|
||||
ExcelUtils.write(response, "用户数据.xls", "用户列表", SysUserExcelVO.class, excelUsers);
|
||||
}
|
||||
|
||||
@ApiOperation("获得导入用户模板")
|
||||
@GetMapping("/get-import-template")
|
||||
@ApiOperation("获得导入用户模板")
|
||||
public void importTemplate(HttpServletResponse response) throws IOException {
|
||||
// 手动创建导出 demo
|
||||
List<SysUserImportExcelVO> list = Arrays.asList(
|
||||
@@ -159,21 +155,18 @@ public class SysUserController {
|
||||
);
|
||||
|
||||
// 输出
|
||||
ExcelUtils.write(response, "用户导入模板.xls", "用户列表",
|
||||
SysUserImportExcelVO.class, list);
|
||||
|
||||
ExcelUtils.write(response, "用户导入模板.xls", "用户列表", SysUserImportExcelVO.class, list);
|
||||
}
|
||||
|
||||
@PostMapping("/import")
|
||||
@ApiOperation("导入用户")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "file", value = "Excel 文件", required = true, dataTypeClass = MultipartFile.class),
|
||||
@ApiImplicitParam(name = "updateSupport", value = "是否支持更新,默认为 false", example = "true", dataTypeClass = Boolean.class)
|
||||
})
|
||||
@PostMapping("/import")
|
||||
// @Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
||||
// @PreAuthorize("@ss.hasPermi('system:user:import')")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:import')")
|
||||
public CommonResult<SysUserImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
|
||||
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
|
||||
List<SysUserImportExcelVO> list = ExcelUtils.raed(file, SysUserImportExcelVO.class);
|
||||
return success(userService.importUsers(list, updateSupport));
|
||||
}
|
||||
|
@@ -1,92 +1,91 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.user;
|
||||
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVo;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.convert.auth.SysAuthConvert;
|
||||
import cn.iocoder.dashboard.modules.system.convert.user.SysUserConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService;
|
||||
import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService;
|
||||
import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
|
||||
import cn.iocoder.dashboard.util.collection.CollectionUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.FILE_IS_EMPTY;
|
||||
|
||||
/**
|
||||
* @author niudehua
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/user/profile")
|
||||
@Api(tags = "用户个人中心")
|
||||
@Slf4j
|
||||
public class SysUserProfileController {
|
||||
|
||||
// /**
|
||||
// * 个人信息
|
||||
// */
|
||||
// @GetMapping
|
||||
// public AjaxResult profile()
|
||||
// {
|
||||
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
// SysUser user = loginUser.getUser();
|
||||
// AjaxResult ajax = AjaxResult.success(user);
|
||||
// ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername()));
|
||||
// ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername()));
|
||||
// return ajax;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改用户
|
||||
// */
|
||||
// @Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||
// @PutMapping
|
||||
// public AjaxResult updateProfile(@RequestBody SysUser user)
|
||||
// {
|
||||
// if (userService.updateUserProfile(user) > 0)
|
||||
// {
|
||||
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
// // 更新缓存用户信息
|
||||
// loginUser.getUser().setNickName(user.getNickName());
|
||||
// loginUser.getUser().setPhonenumber(user.getPhonenumber());
|
||||
// loginUser.getUser().setEmail(user.getEmail());
|
||||
// loginUser.getUser().setSex(user.getSex());
|
||||
// tokenService.setLoginUser(loginUser);
|
||||
// return AjaxResult.success();
|
||||
// }
|
||||
// return AjaxResult.error("修改个人信息异常,请联系管理员");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 重置密码
|
||||
// */
|
||||
// @Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||
// @PutMapping("/updatePwd")
|
||||
// public AjaxResult updatePwd(String oldPassword, String newPassword)
|
||||
// {
|
||||
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
// String userName = loginUser.getUsername();
|
||||
// String password = loginUser.getPassword();
|
||||
// if (!SecurityUtils.matchesPassword(oldPassword, password))
|
||||
// {
|
||||
// return AjaxResult.error("修改密码失败,旧密码错误");
|
||||
// }
|
||||
// if (SecurityUtils.matchesPassword(newPassword, password))
|
||||
// {
|
||||
// return AjaxResult.error("新密码不能与旧密码相同");
|
||||
// }
|
||||
// if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0)
|
||||
// {
|
||||
// // 更新缓存用户密码
|
||||
// loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
|
||||
// tokenService.setLoginUser(loginUser);
|
||||
// return AjaxResult.success();
|
||||
// }
|
||||
// return AjaxResult.error("修改密码异常,请联系管理员");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 头像上传
|
||||
// */
|
||||
// @Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
||||
// @PostMapping("/avatar")
|
||||
// public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException
|
||||
// {
|
||||
// if (!file.isEmpty())
|
||||
// {
|
||||
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
// String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
|
||||
// if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
|
||||
// {
|
||||
// AjaxResult ajax = AjaxResult.success();
|
||||
// ajax.put("imgUrl", avatar);
|
||||
// // 更新缓存用户头像
|
||||
// loginUser.getUser().setAvatar(avatar);
|
||||
// tokenService.setLoginUser(loginUser);
|
||||
// return ajax;
|
||||
// }
|
||||
// }
|
||||
// return AjaxResult.error("上传图片异常,请联系管理员");
|
||||
// }
|
||||
@Resource
|
||||
private SysUserService userService;
|
||||
@Resource
|
||||
private SysPermissionService permissionService;
|
||||
@Resource
|
||||
private SysRoleService roleService;
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得登录用户信息")
|
||||
public CommonResult<SysUserProfileRespVO> profile() {
|
||||
// 获取用户信息
|
||||
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||
SysUserDO user = userService.getUser(userId);
|
||||
SysUserProfileRespVO userProfileRespVO = SysUserConvert.INSTANCE.convert03(user);
|
||||
List<SysRoleDO> userRoles = roleService.getRolesFromCache(permissionService.listUserRoleIs(userId));
|
||||
userProfileRespVO.setRoles(CollectionUtils.convertSet(userRoles, SysUserConvert.INSTANCE::convert));
|
||||
return success(userProfileRespVO);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("修改用户个人信息")
|
||||
public CommonResult<Boolean> updateUserProfile(@Valid @RequestBody SysUserProfileUpdateReqVO reqVO, HttpServletRequest request) {
|
||||
userService.updateUserProfile(reqVO);
|
||||
SecurityFrameworkUtils.setLoginUser(SysAuthConvert.INSTANCE.convert(reqVO), request);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-password")
|
||||
@ApiOperation("修改用户个人密码")
|
||||
public CommonResult<Boolean> updateUserProfilePassword(@Valid @RequestBody SysUserProfileUpdatePasswordReqVo reqVO, HttpServletRequest request) {
|
||||
userService.updateUserPassword(reqVO);
|
||||
SecurityFrameworkUtils.setLoginUser(SysAuthConvert.INSTANCE.convert(reqVO), request);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/upload-avatar")
|
||||
@ApiOperation("上传用户个人头像")
|
||||
public CommonResult<Boolean> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
|
||||
}
|
||||
userService.updateUserAvatar(SecurityFrameworkUtils.getLoginUserId(), file.getInputStream());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,53 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.user.vo.profile;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserBaseVO;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ApiModel("用户个人中心信息 Response VO")
|
||||
public class SysUserProfileRespVO extends SysUserBaseVO {
|
||||
@ApiModelProperty(value = "用户编号", required = true, example = "1")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "最后登陆 IP", required = true, example = "192.168.1.1")
|
||||
private String loginIp;
|
||||
|
||||
@ApiModelProperty(value = "最后登录时间", required = true, example = "时间戳格式")
|
||||
private Date loginDate;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 所属角色
|
||||
*/
|
||||
@ApiModelProperty(value = "所属角色", required = true, example = "123456")
|
||||
private Set<Role> roles;
|
||||
|
||||
@ApiModel("角色")
|
||||
@Data
|
||||
public static class Role {
|
||||
|
||||
@ApiModelProperty(value = "角色编号", required = true, example = "1")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "角色名称", required = true, example = "普通角色")
|
||||
private String name;
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.user.vo.profile;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 类名称:SysUserUpdatePersonalPasswordReqVo
|
||||
* ***********************
|
||||
* <p>
|
||||
* 类描述:更新用户个人密码
|
||||
*
|
||||
* @author deng on 2021/3/15 22:04
|
||||
*/
|
||||
@ApiModel("用户个人中心更新密码 Response VO")
|
||||
@Data
|
||||
public class SysUserProfileUpdatePasswordReqVo {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", required = true, example = "1024")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "旧密码", required = true, example = "123456")
|
||||
@NotEmpty(message = "旧密码不能为空")
|
||||
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
|
||||
private String oldPassword;
|
||||
|
||||
@ApiModelProperty(value = "新密码", required = true, example = "654321")
|
||||
@NotEmpty(message = "新密码不能为空")
|
||||
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
|
||||
private String newPassword;
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.user.vo.profile;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@ApiModel("用户个人信息更新 Request VO")
|
||||
@Data
|
||||
public class SysUserProfileUpdateReqVO {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", required = true, example = "1024")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "用户昵称", required = true, example = "芋艿")
|
||||
@Size(max = 30, message = "用户昵称长度不能超过30个字符")
|
||||
private String nickname;
|
||||
|
||||
@ApiModelProperty(value = "用户邮箱", example = "yudao@iocoder.cn")
|
||||
@Email(message = "邮箱格式不正确")
|
||||
@Size(max = 50, message = "邮箱长度不能超过50个字符")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty(value = "手机号码", example = "15601691300")
|
||||
@Pattern(regexp = "^1(3|4|5|7|8)\\d{9}$",message = "手机号码格式错误")
|
||||
private String mobile;
|
||||
|
||||
@ApiModelProperty(value = "用户性别", example = "1", notes = "参见 SysSexEnum 枚举类")
|
||||
private Integer sex;
|
||||
|
||||
@ApiModelProperty(value = "用户头像", example = "http://www.iocoder.cn/xxx.png")
|
||||
private String avatar;
|
||||
|
||||
}
|
@@ -5,6 +5,7 @@ import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -39,7 +40,7 @@ public class SysUserBaseVO {
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty(value = "手机号码", example = "15601691300")
|
||||
@Size(max = 11, message = "手机号码长度不能超过11个字符")
|
||||
@Pattern(regexp = "^1(3|4|5|7|8)\\d{9}$",message = "手机号码格式错误")
|
||||
private String mobile;
|
||||
|
||||
@ApiModelProperty(value = "用户性别", example = "1", notes = "参见 SysSexEnum 枚举类")
|
||||
@@ -48,5 +49,4 @@ public class SysUserBaseVO {
|
||||
@ApiModelProperty(value = "用户头像", example = "http://www.iocoder.cn/xxx.png")
|
||||
private String avatar;
|
||||
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,8 @@ package cn.iocoder.dashboard.modules.system.convert.auth;
|
||||
import cn.iocoder.dashboard.framework.security.core.LoginUser;
|
||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.auth.SysAuthMenuRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.auth.vo.auth.SysAuthPermissionInfoRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVo;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysMenuDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
||||
@@ -13,26 +15,35 @@ import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface SysAuthConvert {
|
||||
|
||||
SysAuthConvert INSTANCE = Mappers.getMapper(SysAuthConvert.class);
|
||||
|
||||
@Mapping(source = "updateTime", target = "updateTime", ignore = true) // 字段相同,但是含义不同,忽略
|
||||
@Mapping(source = "updateTime", target = "updateTime", ignore = true)
|
||||
// 字段相同,但是含义不同,忽略
|
||||
LoginUser convert(SysUserDO bean);
|
||||
|
||||
default SysAuthPermissionInfoRespVO convert(SysUserDO user, List<SysRoleDO> roleList, List<SysMenuDO> menuList) {
|
||||
return SysAuthPermissionInfoRespVO.builder()
|
||||
.user(SysAuthPermissionInfoRespVO.UserVO.builder().nickname(user.getNickname()).avatar(user.getAvatar()).build())
|
||||
.roles(CollectionUtils.convertSet(roleList, SysRoleDO::getCode))
|
||||
.permissions(CollectionUtils.convertSet(menuList, SysMenuDO::getPermission))
|
||||
.build();
|
||||
.user(SysAuthPermissionInfoRespVO.UserVO.builder().nickname(user.getNickname()).avatar(user.getAvatar()).build())
|
||||
.roles(CollectionUtils.convertSet(roleList, SysRoleDO::getCode))
|
||||
.permissions(CollectionUtils.convertSet(menuList, SysMenuDO::getPermission))
|
||||
.build();
|
||||
}
|
||||
|
||||
SysAuthMenuRespVO convertTreeNode(SysMenuDO menu);
|
||||
|
||||
LoginUser convert(SysUserProfileUpdateReqVO reqVO);
|
||||
|
||||
LoginUser convert(SysUserProfileUpdatePasswordReqVo reqVO);
|
||||
|
||||
/**
|
||||
* 将菜单列表,构建成菜单树
|
||||
*
|
||||
@@ -47,12 +58,12 @@ public interface SysAuthConvert {
|
||||
Map<Long, SysAuthMenuRespVO> treeNodeMap = new LinkedHashMap<>();
|
||||
menuList.forEach(menu -> treeNodeMap.put(menu.getId(), SysAuthConvert.INSTANCE.convertTreeNode(menu)));
|
||||
// 处理父子关系
|
||||
treeNodeMap.values().stream().filter(node -> !node.getParentId().equals(MenuIdEnum.ROOT.getId())).forEach((childNode) -> {
|
||||
treeNodeMap.values().stream().filter(node -> !node.getParentId().equals(MenuIdEnum.ROOT.getId())).forEach(childNode -> {
|
||||
// 获得父节点
|
||||
SysAuthMenuRespVO parentNode = treeNodeMap.get(childNode.getParentId());
|
||||
if (parentNode == null) {
|
||||
LoggerFactory.getLogger(getClass()).error("[buildRouterTree][resource({}) 找不到父资源({})]",
|
||||
childNode.getId(), childNode.getParentId());
|
||||
childNode.getId(), childNode.getParentId());
|
||||
return;
|
||||
}
|
||||
// 将自己添加到父节点中
|
||||
|
@@ -1,7 +1,15 @@
|
||||
package cn.iocoder.dashboard.modules.system.convert.user;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.*;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVo;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserExcelVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserImportExcelVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageItemRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
@@ -23,4 +31,13 @@ public interface SysUserConvert {
|
||||
|
||||
SysUserDO convert(SysUserImportExcelVO bean);
|
||||
|
||||
SysUserProfileRespVO convert03(SysUserDO bean);
|
||||
|
||||
SysUserProfileRespVO.Role convert(SysRoleDO bean);
|
||||
|
||||
SysUserDO convert(SysUserProfileUpdateReqVO bean);
|
||||
|
||||
SysUserDO convert(SysUserProfileUpdatePasswordReqVo bean);
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,30 +0,0 @@
|
||||
package cn.iocoder.dashboard.modules.system.dal.dataobject.common;
|
||||
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 文件表
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_file")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysFileDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
*/
|
||||
@TableId(type = IdType.INPUT)
|
||||
private String id;
|
||||
/**
|
||||
* 文件内容
|
||||
*/
|
||||
private byte[] content;
|
||||
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package cn.iocoder.dashboard.modules.system.dal.mysql.common;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.common.SysFileDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SysFileMapper extends BaseMapper<SysFileDO> {
|
||||
|
||||
default Integer selectCountById(String id) {
|
||||
return selectCount(new QueryWrapper<SysFileDO>().eq("id", id));
|
||||
}
|
||||
|
||||
}
|
@@ -33,6 +33,14 @@ public interface SysRoleMenuMapper extends BaseMapperX<SysRoleMenuDO> {
|
||||
delete(new QueryWrapper<SysRoleMenuDO>().eq("role_id", roleId)
|
||||
.in("menu_id", menuIds));
|
||||
}
|
||||
|
||||
default void deleteListByMenuId(Long menuId) {
|
||||
delete(new QueryWrapper<SysRoleMenuDO>().eq("menu_id", menuId));
|
||||
}
|
||||
|
||||
default void deleteListByRoleId(Long roleId) {
|
||||
delete(new QueryWrapper<SysRoleMenuDO>().eq("role_id", roleId));
|
||||
}
|
||||
|
||||
@Select("SELECT id FROM sys_role_menu WHERE update_time > #{maxUpdateTime} LIMIT 1")
|
||||
Long selectExistsByUpdateTimeAfter(Date maxUpdateTime);
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package cn.iocoder.dashboard.modules.system.dal.mysql.permission;
|
||||
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysUserRoleDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Mapper
|
||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRoleDO> {
|
||||
public interface SysUserRoleMapper extends BaseMapperX<SysUserRoleDO> {
|
||||
|
||||
default List<SysUserRoleDO> selectListByUserId(Long userId) {
|
||||
return selectList(new QueryWrapper<SysUserRoleDO>().eq("user_id", userId));
|
||||
@@ -32,4 +32,12 @@ public interface SysUserRoleMapper extends BaseMapper<SysUserRoleDO> {
|
||||
.in("role_id", roleIds));
|
||||
}
|
||||
|
||||
default void deleteListByUserId(Long userId) {
|
||||
delete(new QueryWrapper<SysUserRoleDO>().eq("user_id", userId));
|
||||
}
|
||||
|
||||
default void deleteListByRoleId(Long roleId) {
|
||||
delete(new QueryWrapper<SysUserRoleDO>().eq("role_id", roleId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -40,6 +40,7 @@ public interface SysErrorCodeConstants {
|
||||
ErrorCode USER_EMAIL_EXISTS = new ErrorCode(1002004002, "邮箱已经存在");
|
||||
ErrorCode USER_NOT_EXISTS = new ErrorCode(1002004003, "用户不存在");
|
||||
ErrorCode USER_IMPORT_LIST_IS_EMPTY = new ErrorCode(1002004004, "导入用户数据不能为空!");
|
||||
ErrorCode USER_PASSWORD_FAILED = new ErrorCode(1002004005, "用户密码校验失败");
|
||||
|
||||
// ========== 部门模块 1002005000 ==========
|
||||
ErrorCode DEPT_NAME_DUPLICATE = new ErrorCode(1002004001, "已经存在该名字的部门");
|
||||
@@ -74,5 +75,7 @@ public interface SysErrorCodeConstants {
|
||||
|
||||
// ========== 文件 1002009000 ==========
|
||||
ErrorCode FILE_PATH_EXISTS = new ErrorCode(1002009001, "文件路径已经存在");
|
||||
ErrorCode FILE_UPLOAD_FAILED = new ErrorCode(1002009002, "文件上传失败");
|
||||
ErrorCode FILE_IS_EMPTY= new ErrorCode(1002009003, "文件为空");
|
||||
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ public class SysAuthServiceImpl implements SysAuthService {
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
// 获取 username 对应的 SysUserDO
|
||||
SysUserDO user = userService.getUserByUserName(username);
|
||||
SysUserDO user = userService.getUserByUsername(username);
|
||||
if (user == null) {
|
||||
throw new UsernameNotFoundException(username);
|
||||
}
|
||||
|
@@ -101,7 +101,7 @@ public class SysUserSessionServiceImpl implements SysUserSessionService {
|
||||
// 处理基于用户昵称的查询
|
||||
Collection<Long> userIds = null;
|
||||
if (StrUtil.isNotEmpty(reqVO.getUsername())) {
|
||||
userIds = convertSet(userService.listUsersByUsername(reqVO.getUsername()), SysUserDO::getId);
|
||||
userIds = convertSet(userService.getUsersByUsername(reqVO.getUsername()), SysUserDO::getId);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return PageResult.empty();
|
||||
}
|
||||
|
@@ -1,29 +0,0 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.common;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.common.SysFileDO;
|
||||
|
||||
/**
|
||||
* 文件 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface SysFileService {
|
||||
|
||||
/**
|
||||
* 保存文件,并返回文件的访问路径
|
||||
*
|
||||
* @param path 文件路径
|
||||
* @param content 文件内容
|
||||
* @return 文件路径
|
||||
*/
|
||||
String createFile(String path, byte[] content);
|
||||
|
||||
/**
|
||||
* 获得文件
|
||||
*
|
||||
* @param path 文件路径
|
||||
* @return 文件
|
||||
*/
|
||||
SysFileDO getFile(String path);
|
||||
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.common.impl;
|
||||
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.framework.file.config.FileProperties;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.common.SysFileDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.common.SysFileMapper;
|
||||
import cn.iocoder.dashboard.modules.system.service.common.SysFileService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS;
|
||||
|
||||
/**
|
||||
* 文件 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
public class SysFileServiceImpl implements SysFileService {
|
||||
|
||||
@Resource
|
||||
private SysFileMapper fileMapper;
|
||||
|
||||
@Resource
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@Override
|
||||
public String createFile(String path, byte[] content) {
|
||||
if (fileMapper.selectCountById(path) > 0) {
|
||||
throw ServiceExceptionUtil.exception(FILE_PATH_EXISTS);
|
||||
}
|
||||
// 保存到数据库
|
||||
SysFileDO file = new SysFileDO();
|
||||
file.setId(path);
|
||||
file.setContent(content);
|
||||
fileMapper.insert(file);
|
||||
// 拼接路径返回
|
||||
return fileProperties.getBasePath() + path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysFileDO getFile(String path) {
|
||||
return fileMapper.selectById(path);
|
||||
}
|
||||
|
||||
}
|
@@ -24,53 +24,6 @@ public interface SysDeptService {
|
||||
*/
|
||||
void initLocalCache();
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门列表
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysDeptDO> listDepts(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门 Map
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门 Map
|
||||
*/
|
||||
default Map<Long, SysDeptDO> getDeptMap(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<SysDeptDO> list = listDepts(ids);
|
||||
return CollectionUtils.convertMap(list, SysDeptDO::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选部门列表
|
||||
*
|
||||
* @param reqVO 筛选条件请求 VO
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysDeptDO> listDepts(SysDeptListReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得所有子部门,从缓存中
|
||||
*
|
||||
* @param parentId 部门编号
|
||||
* @param recursive 是否递归获取所有
|
||||
* @return 子部门列表
|
||||
*/
|
||||
List<SysDeptDO> listDeptsByParentIdFromCache(Long parentId, boolean recursive);
|
||||
|
||||
/**
|
||||
* 获得部门信息
|
||||
*
|
||||
* @param id 部门编号
|
||||
* @return 部门信息
|
||||
*/
|
||||
SysDeptDO getDept(Long id);
|
||||
|
||||
/**
|
||||
* 创建部门
|
||||
*
|
||||
@@ -93,4 +46,51 @@ public interface SysDeptService {
|
||||
*/
|
||||
void deleteDept(Long id);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门列表
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysDeptDO> getSimpleDepts(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定编号的部门 Map
|
||||
*
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门 Map
|
||||
*/
|
||||
default Map<Long, SysDeptDO> getDeptMap(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<SysDeptDO> list = getSimpleDepts(ids);
|
||||
return CollectionUtils.convertMap(list, SysDeptDO::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选部门列表
|
||||
*
|
||||
* @param reqVO 筛选条件请求 VO
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysDeptDO> getSimpleDepts(SysDeptListReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得部门信息
|
||||
*
|
||||
* @param id 部门编号
|
||||
* @return 部门信息
|
||||
*/
|
||||
SysDeptDO getDept(Long id);
|
||||
|
||||
/**
|
||||
* 获得所有子部门,从缓存中
|
||||
*
|
||||
* @param parentId 部门编号
|
||||
* @param recursive 是否递归获取所有
|
||||
* @return 子部门列表
|
||||
*/
|
||||
List<SysDeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive);
|
||||
|
||||
}
|
||||
|
@@ -18,39 +18,6 @@ import java.util.List;
|
||||
*/
|
||||
public interface SysPostService {
|
||||
|
||||
/**
|
||||
* 获得符合条件的岗位列表
|
||||
*
|
||||
* @param ids 岗位编号数组。如果为空,不进行筛选
|
||||
* @param statuses 状态数组。如果为空,不进行筛选
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysPostDO> listPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses);
|
||||
|
||||
/**
|
||||
* 获得岗位分页列表
|
||||
*
|
||||
* @param reqVO 分页条件
|
||||
* @return 部门分页列表
|
||||
*/
|
||||
PageResult<SysPostDO> pagePosts(SysPostPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得岗位列表
|
||||
*
|
||||
* @param reqVO 查询条件
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysPostDO> listPosts(SysPostExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得岗位信息
|
||||
*
|
||||
* @param id 岗位编号
|
||||
* @return 岗位信息
|
||||
*/
|
||||
SysPostDO getPost(Long id);
|
||||
|
||||
/**
|
||||
* 创建岗位
|
||||
*
|
||||
@@ -73,4 +40,37 @@ public interface SysPostService {
|
||||
*/
|
||||
void deletePost(Long id);
|
||||
|
||||
/**
|
||||
* 获得符合条件的岗位列表
|
||||
*
|
||||
* @param ids 岗位编号数组。如果为空,不进行筛选
|
||||
* @param statuses 状态数组。如果为空,不进行筛选
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysPostDO> getPosts(@Nullable Collection<Long> ids, @Nullable Collection<Integer> statuses);
|
||||
|
||||
/**
|
||||
* 获得岗位分页列表
|
||||
*
|
||||
* @param reqVO 分页条件
|
||||
* @return 部门分页列表
|
||||
*/
|
||||
PageResult<SysPostDO> getPostPage(SysPostPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得岗位列表
|
||||
*
|
||||
* @param reqVO 查询条件
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<SysPostDO> getPosts(SysPostExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得岗位信息
|
||||
*
|
||||
* @param id 岗位编号
|
||||
* @return 岗位信息
|
||||
*/
|
||||
SysPostDO getPost(Long id);
|
||||
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import com.google.common.collect.Multimap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
@@ -32,6 +33,7 @@ import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class SysDeptServiceImpl implements SysDeptService {
|
||||
|
||||
@@ -47,6 +49,7 @@ public class SysDeptServiceImpl implements SysDeptService {
|
||||
*
|
||||
* 这里声明 volatile 修饰的原因是,每次刷新时,直接修改指向
|
||||
*/
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private volatile Map<Long, SysDeptDO> deptCache;
|
||||
/**
|
||||
* 父部门缓存
|
||||
@@ -118,17 +121,54 @@ public class SysDeptServiceImpl implements SysDeptService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDeptDO> listDepts(Collection<Long> ids) {
|
||||
public Long createDept(SysDeptCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName());
|
||||
// 插入部门
|
||||
SysDeptDO dept = SysDeptConvert.INSTANCE.convert(reqVO);
|
||||
deptMapper.insert(dept);
|
||||
// 发送刷新消息
|
||||
deptProducer.sendDeptRefreshMessage();
|
||||
return dept.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDept(SysDeptUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName());
|
||||
// 更新部门
|
||||
SysDeptDO updateObj = SysDeptConvert.INSTANCE.convert(reqVO);
|
||||
deptMapper.updateById(updateObj);
|
||||
// 发送刷新消息
|
||||
deptProducer.sendDeptRefreshMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDept(Long id) {
|
||||
// 校验是否存在
|
||||
checkDeptExists(id);
|
||||
// 校验是否有子部门
|
||||
if (deptMapper.selectCountByParentId(id) > 0) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_EXITS_CHILDREN);
|
||||
}
|
||||
// 删除部门
|
||||
deptMapper.deleteById(id);
|
||||
// 发送刷新消息
|
||||
deptProducer.sendDeptRefreshMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDeptDO> getSimpleDepts(Collection<Long> ids) {
|
||||
return deptMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDeptDO> listDepts(SysDeptListReqVO reqVO) {
|
||||
public List<SysDeptDO> getSimpleDepts(SysDeptListReqVO reqVO) {
|
||||
return deptMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDeptDO> listDeptsByParentIdFromCache(Long parentId, boolean recursive) {
|
||||
public List<SysDeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive) {
|
||||
List<SysDeptDO> result = new ArrayList<>();
|
||||
// 递归,简单粗暴
|
||||
this.listDeptsByParentIdFromCache(result, parentId,
|
||||
@@ -167,44 +207,6 @@ public class SysDeptServiceImpl implements SysDeptService {
|
||||
return deptMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createDept(SysDeptCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(null, reqVO.getParentId(), reqVO.getName());
|
||||
// 插入部门
|
||||
SysDeptDO dept = SysDeptConvert.INSTANCE.convert(reqVO);
|
||||
deptMapper.insert(dept);
|
||||
// 发送刷新消息
|
||||
deptProducer.sendDeptRefreshMessage();
|
||||
return dept.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDept(SysDeptUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(reqVO.getId(), reqVO.getParentId(), reqVO.getName());
|
||||
// 更新部门
|
||||
SysDeptDO updateObj = SysDeptConvert.INSTANCE.convert(reqVO);
|
||||
deptMapper.updateById(updateObj);
|
||||
// 发送刷新消息
|
||||
deptProducer.sendDeptRefreshMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDept(Long id) {
|
||||
// 校验是否存在
|
||||
checkDeptExists(id);
|
||||
// 校验是否有子部门
|
||||
if (deptMapper.selectCountByParentId(id) > 0) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_EXITS_CHILDREN);
|
||||
}
|
||||
// 删除部门
|
||||
deptMapper.deleteById(id);
|
||||
// TODO 需要处理下与角色的数据权限关联,等做数据权限一起处理下
|
||||
// 发送刷新消息
|
||||
deptProducer.sendDeptRefreshMessage();
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, Long parentId, String name) {
|
||||
// 校验自己存在
|
||||
checkDeptExists(id);
|
||||
@@ -232,7 +234,7 @@ public class SysDeptServiceImpl implements SysDeptService {
|
||||
throw ServiceExceptionUtil.exception(DEPT_NOT_ENABLE);
|
||||
}
|
||||
// 父部门不能是原来的子部门
|
||||
List<SysDeptDO> children = this.listDeptsByParentIdFromCache(id, true);
|
||||
List<SysDeptDO> children = this.getDeptsByParentIdFromCache(id, true);
|
||||
if (children.stream().anyMatch(dept1 -> dept1.getId().equals(parentId))) {
|
||||
throw ServiceExceptionUtil.exception(DEPT_PARENT_IS_CHILD);
|
||||
}
|
||||
@@ -262,12 +264,6 @@ public class SysDeptServiceImpl implements SysDeptService {
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 查询部门管理数据
|
||||
// *
|
||||
// * @param dept 部门信息
|
||||
// * @return 部门信息集合
|
||||
// */
|
||||
// @Override
|
||||
// @DataScope(deptAlias = "d")
|
||||
// public List<SysDept> selectDeptList(SysDept dept)
|
||||
|
@@ -11,6 +11,7 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.dept.SysPostMapper;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.dept.SysPostService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
@@ -24,31 +25,12 @@ import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class SysPostServiceImpl implements SysPostService {
|
||||
|
||||
@Resource
|
||||
private SysPostMapper postMapper;
|
||||
|
||||
@Override
|
||||
public List<SysPostDO> listPosts(Collection<Long> ids, Collection<Integer> statuses) {
|
||||
return postMapper.selectList(ids, statuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysPostDO> pagePosts(SysPostPageReqVO reqVO) {
|
||||
return postMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysPostDO> listPosts(SysPostExportReqVO reqVO) {
|
||||
return postMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysPostDO getPost(Long id) {
|
||||
return postMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createPost(SysPostCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
@@ -68,6 +50,34 @@ public class SysPostServiceImpl implements SysPostService {
|
||||
postMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePost(Long id) {
|
||||
// 校验是否存在
|
||||
this.checkPostExists(id);
|
||||
// 删除部门
|
||||
postMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysPostDO> getPosts(Collection<Long> ids, Collection<Integer> statuses) {
|
||||
return postMapper.selectList(ids, statuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysPostDO> getPostPage(SysPostPageReqVO reqVO) {
|
||||
return postMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysPostDO> getPosts(SysPostExportReqVO reqVO) {
|
||||
return postMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysPostDO getPost(Long id) {
|
||||
return postMapper.selectById(id);
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String name, String code) {
|
||||
// 校验自己存在
|
||||
checkPostExists(id);
|
||||
@@ -105,14 +115,6 @@ public class SysPostServiceImpl implements SysPostService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePost(Long id) {
|
||||
// 校验是否存在
|
||||
this.checkPostExists(id);
|
||||
// 删除部门
|
||||
postMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void checkPostExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
|
@@ -22,37 +22,6 @@ public interface SysDictDataService extends DictDataFrameworkService {
|
||||
*/
|
||||
void initLocalCache();
|
||||
|
||||
/**
|
||||
* 获得字典数据列表
|
||||
*
|
||||
* @return 字典数据全列表
|
||||
*/
|
||||
List<SysDictDataDO> getDictDataList();
|
||||
|
||||
/**
|
||||
* 获得字典数据分页列表
|
||||
*
|
||||
* @param reqVO 分页请求
|
||||
* @return 字典数据分页列表
|
||||
*/
|
||||
PageResult<SysDictDataDO> getDictDataPage(SysDictDataPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得字典数据列表
|
||||
*
|
||||
* @param reqVO 列表请求
|
||||
* @return 字典数据列表
|
||||
*/
|
||||
List<SysDictDataDO> getDictDataList(SysDictDataExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得字典数据详情
|
||||
*
|
||||
* @param id 字典数据编号
|
||||
* @return 字典数据
|
||||
*/
|
||||
SysDictDataDO getDictData(Long id);
|
||||
|
||||
/**
|
||||
* 创建字典数据
|
||||
*
|
||||
@@ -75,6 +44,37 @@ public interface SysDictDataService extends DictDataFrameworkService {
|
||||
*/
|
||||
void deleteDictData(Long id);
|
||||
|
||||
/**
|
||||
* 获得字典数据列表
|
||||
*
|
||||
* @return 字典数据全列表
|
||||
*/
|
||||
List<SysDictDataDO> getDictDatas();
|
||||
|
||||
/**
|
||||
* 获得字典数据分页列表
|
||||
*
|
||||
* @param reqVO 分页请求
|
||||
* @return 字典数据分页列表
|
||||
*/
|
||||
PageResult<SysDictDataDO> getDictDataPage(SysDictDataPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得字典数据列表
|
||||
*
|
||||
* @param reqVO 列表请求
|
||||
* @return 字典数据列表
|
||||
*/
|
||||
List<SysDictDataDO> getDictDatas(SysDictDataExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得字典数据详情
|
||||
*
|
||||
* @param id 字典数据编号
|
||||
* @return 字典数据
|
||||
*/
|
||||
SysDictDataDO getDictData(Long id);
|
||||
|
||||
/**
|
||||
* 获得指定字典类型的数据数量
|
||||
*
|
||||
|
@@ -16,6 +16,28 @@ import java.util.List;
|
||||
*/
|
||||
public interface SysDictTypeService {
|
||||
|
||||
/**
|
||||
* 创建字典类型
|
||||
*
|
||||
* @param reqVO 字典类型信息
|
||||
* @return 字典类型编号
|
||||
*/
|
||||
Long createDictType(SysDictTypeCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新字典类型
|
||||
*
|
||||
* @param reqVO 字典类型信息
|
||||
*/
|
||||
void updateDictType(SysDictTypeUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 删除字典类型
|
||||
*
|
||||
* @param id 字典类型编号
|
||||
*/
|
||||
void deleteDictType(Long id);
|
||||
|
||||
/**
|
||||
* 获得字典类型分页列表
|
||||
*
|
||||
@@ -48,28 +70,6 @@ public interface SysDictTypeService {
|
||||
*/
|
||||
SysDictTypeDO getDictType(String type);
|
||||
|
||||
/**
|
||||
* 创建字典类型
|
||||
*
|
||||
* @param reqVO 字典类型信息
|
||||
* @return 字典类型编号
|
||||
*/
|
||||
Long createDictType(SysDictTypeCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新字典类型
|
||||
*
|
||||
* @param reqVO 字典类型信息
|
||||
*/
|
||||
void updateDictType(SysDictTypeUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 删除字典类型
|
||||
*
|
||||
* @param id 字典类型编号
|
||||
*/
|
||||
void deleteDictType(Long id);
|
||||
|
||||
/**
|
||||
* 获得全部字典类型列表
|
||||
*
|
||||
|
@@ -131,7 +131,7 @@ public class SysDictDataServiceImpl implements SysDictDataService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDictDataDO> getDictDataList() {
|
||||
public List<SysDictDataDO> getDictDatas() {
|
||||
List<SysDictDataDO> list = dictDataMapper.selectList();
|
||||
list.sort(COMPARATOR_TYPE_AND_SORT);
|
||||
return list;
|
||||
@@ -143,7 +143,7 @@ public class SysDictDataServiceImpl implements SysDictDataService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDictDataDO> getDictDataList(SysDictDataExportReqVO reqVO) {
|
||||
public List<SysDictDataDO> getDictDatas(SysDictDataExportReqVO reqVO) {
|
||||
List<SysDictDataDO> list = dictDataMapper.selectList(reqVO);
|
||||
list.sort(COMPARATOR_TYPE_AND_SORT);
|
||||
return list;
|
||||
|
@@ -59,7 +59,7 @@ public class SysOperateLogServiceImpl implements SysOperateLogService {
|
||||
// 处理基于用户昵称的查询
|
||||
Collection<Long> userIds = null;
|
||||
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
|
||||
userIds = convertSet(userService.listUsersByNickname(reqVO.getUserNickname()), SysUserDO::getId);
|
||||
userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), SysUserDO::getId);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return PageResult.empty();
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class SysOperateLogServiceImpl implements SysOperateLogService {
|
||||
// 处理基于用户昵称的查询
|
||||
Collection<Long> userIds = null;
|
||||
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
|
||||
userIds = convertSet(userService.listUsersByNickname(reqVO.getUserNickname()), SysUserDO::getId);
|
||||
userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), SysUserDO::getId);
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@@ -11,22 +11,6 @@ import cn.iocoder.dashboard.modules.system.dal.dataobject.notice.SysNoticeDO;
|
||||
*/
|
||||
public interface SysNoticeService {
|
||||
|
||||
/**
|
||||
* 获得岗位公告公告分页列表
|
||||
*
|
||||
* @param reqVO 分页条件
|
||||
* @return 部门分页列表
|
||||
*/
|
||||
PageResult<SysNoticeDO> pageNotices(SysNoticePageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得岗位公告公告信息
|
||||
*
|
||||
* @param id 岗位公告公告编号
|
||||
* @return 岗位公告公告信息
|
||||
*/
|
||||
SysNoticeDO getNotice(Long id);
|
||||
|
||||
/**
|
||||
* 创建岗位公告公告
|
||||
*
|
||||
@@ -48,4 +32,21 @@ public interface SysNoticeService {
|
||||
* @param id 岗位公告公告编号
|
||||
*/
|
||||
void deleteNotice(Long id);
|
||||
|
||||
/**
|
||||
* 获得岗位公告公告分页列表
|
||||
*
|
||||
* @param reqVO 分页条件
|
||||
* @return 部门分页列表
|
||||
*/
|
||||
PageResult<SysNoticeDO> pageNotices(SysNoticePageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得岗位公告公告信息
|
||||
*
|
||||
* @param id 岗位公告公告编号
|
||||
* @return 岗位公告公告信息
|
||||
*/
|
||||
SysNoticeDO getNotice(Long id);
|
||||
|
||||
}
|
||||
|
@@ -27,16 +27,6 @@ public class SysNoticeServiceImpl implements SysNoticeService {
|
||||
@Resource
|
||||
private SysNoticeMapper noticeMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<SysNoticeDO> pageNotices(SysNoticePageReqVO reqVO) {
|
||||
return noticeMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysNoticeDO getNotice(Long id) {
|
||||
return noticeMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createNotice(SysNoticeCreateReqVO reqVO) {
|
||||
SysNoticeDO notice = SysNoticeConvert.INSTANCE.convert(reqVO);
|
||||
@@ -61,6 +51,16 @@ public class SysNoticeServiceImpl implements SysNoticeService {
|
||||
noticeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysNoticeDO> pageNotices(SysNoticePageReqVO reqVO) {
|
||||
return noticeMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysNoticeDO getNotice(Long id) {
|
||||
return noticeMapper.selectById(id);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkNoticeExists(Long id) {
|
||||
if (id == null) {
|
||||
|
@@ -20,12 +20,34 @@ public interface SysMenuService {
|
||||
*/
|
||||
void initLocalCache();
|
||||
|
||||
/**
|
||||
* 创建菜单
|
||||
*
|
||||
* @param reqVO 菜单信息
|
||||
* @return 创建出来的菜单编号
|
||||
*/
|
||||
Long createMenu(SysMenuCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
*
|
||||
* @param reqVO 菜单信息
|
||||
*/
|
||||
void updateMenu(SysMenuUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单编号
|
||||
*/
|
||||
void deleteMenu(Long id);
|
||||
|
||||
/**
|
||||
* 获得所有菜单列表
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenuDO> listMenus();
|
||||
List<SysMenuDO> getMenus();
|
||||
|
||||
/**
|
||||
* 筛选菜单列表
|
||||
@@ -33,7 +55,7 @@ public interface SysMenuService {
|
||||
* @param reqVO 筛选条件请求 VO
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenuDO> listMenus(SysMenuListReqVO reqVO);
|
||||
List<SysMenuDO> getMenus(SysMenuListReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得所有菜单,从缓存中
|
||||
@@ -67,28 +89,6 @@ public interface SysMenuService {
|
||||
*/
|
||||
List<SysMenuDO> getMenuListByPermissionFromCache(String permission);
|
||||
|
||||
/*
|
||||
* 创建菜单
|
||||
*
|
||||
* @param reqVO 菜单信息
|
||||
* @return 创建出来的菜单编号
|
||||
*/
|
||||
Long createMenu(SysMenuCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
*
|
||||
* @param reqVO 菜单信息
|
||||
*/
|
||||
void updateMenu(SysMenuUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单编号
|
||||
*/
|
||||
void deleteMenu(Long id);
|
||||
|
||||
/**
|
||||
* 获得菜单
|
||||
*
|
||||
|
@@ -32,8 +32,8 @@ public interface SysPermissionService extends SecurityPermissionFrameworkService
|
||||
* @param menusStatuses 菜单状态数组
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenuDO> listRoleMenusFromCache(Collection<Long> roleIds, Collection<Integer> menuTypes,
|
||||
Collection<Integer> menusStatuses);
|
||||
List<SysMenuDO> getRoleMenusFromCache(Collection<Long> roleIds, Collection<Integer> menuTypes,
|
||||
Collection<Integer> menusStatuses);
|
||||
|
||||
/**
|
||||
* 获得用户拥有的角色编号集合
|
||||
|
@@ -24,48 +24,6 @@ public interface SysRoleService {
|
||||
*/
|
||||
void initLocalCache();
|
||||
|
||||
/**
|
||||
* 获得角色,从缓存中
|
||||
*
|
||||
* @param id 角色编号
|
||||
* @return 角色
|
||||
*/
|
||||
SysRoleDO getRoleFromCache(Long id);
|
||||
|
||||
/**
|
||||
* 获得角色列表
|
||||
*
|
||||
* @param statuses 筛选的状态。允许空,空时不筛选
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRoleDO> listRoles(@Nullable Collection<Integer> statuses);
|
||||
|
||||
/**
|
||||
* 获得角色数组,从缓存中
|
||||
*
|
||||
* @param ids 角色编号数组
|
||||
* @return 角色数组
|
||||
*/
|
||||
List<SysRoleDO> listRolesFromCache(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 判断角色数组中,是否有管理员
|
||||
*
|
||||
* @param roleList 角色数组
|
||||
* @return 是否有管理员
|
||||
*/
|
||||
boolean hasAnyAdmin(Collection<SysRoleDO> roleList);
|
||||
|
||||
/**
|
||||
* 判断角色编号数组中,是否有管理员
|
||||
*
|
||||
* @param ids 角色编号数组
|
||||
* @return 是否有管理员
|
||||
*/
|
||||
default boolean hasAnyAdmin(Set<Long> ids) {
|
||||
return hasAnyAdmin(listRolesFromCache(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建角色
|
||||
*
|
||||
@@ -88,30 +46,6 @@ public interface SysRoleService {
|
||||
*/
|
||||
void deleteRole(Long id);
|
||||
|
||||
/**
|
||||
* 获得角色
|
||||
*
|
||||
* @param id 角色编号
|
||||
* @return 角色
|
||||
*/
|
||||
SysRoleDO getRole(Long id);
|
||||
|
||||
/**
|
||||
* 获得角色分页
|
||||
*
|
||||
* @param reqVO 角色分页查询
|
||||
* @return 角色分页结果
|
||||
*/
|
||||
PageResult<SysRoleDO> pageRole(SysRolePageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得角色列表
|
||||
*
|
||||
* @param reqVO 列表查询
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRoleDO> listRoles(SysRoleExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新角色状态
|
||||
*
|
||||
@@ -129,4 +63,70 @@ public interface SysRoleService {
|
||||
*/
|
||||
void updateRoleDataScope(Long id, Integer dataScope, Set<Long> dataScopeDeptIds);
|
||||
|
||||
/**
|
||||
* 获得角色,从缓存中
|
||||
*
|
||||
* @param id 角色编号
|
||||
* @return 角色
|
||||
*/
|
||||
SysRoleDO getRoleFromCache(Long id);
|
||||
|
||||
/**
|
||||
* 获得角色列表
|
||||
*
|
||||
* @param statuses 筛选的状态。允许空,空时不筛选
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRoleDO> getRoles(@Nullable Collection<Integer> statuses);
|
||||
|
||||
/**
|
||||
* 获得角色数组,从缓存中
|
||||
*
|
||||
* @param ids 角色编号数组
|
||||
* @return 角色数组
|
||||
*/
|
||||
List<SysRoleDO> getRolesFromCache(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 判断角色数组中,是否有管理员
|
||||
*
|
||||
* @param roleList 角色数组
|
||||
* @return 是否有管理员
|
||||
*/
|
||||
boolean hasAnyAdmin(Collection<SysRoleDO> roleList);
|
||||
|
||||
/**
|
||||
* 判断角色编号数组中,是否有管理员
|
||||
*
|
||||
* @param ids 角色编号数组
|
||||
* @return 是否有管理员
|
||||
*/
|
||||
default boolean hasAnyAdmin(Set<Long> ids) {
|
||||
return hasAnyAdmin(getRolesFromCache(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得角色
|
||||
*
|
||||
* @param id 角色编号
|
||||
* @return 角色
|
||||
*/
|
||||
SysRoleDO getRole(Long id);
|
||||
|
||||
/**
|
||||
* 获得角色分页
|
||||
*
|
||||
* @param reqVO 角色分页查询
|
||||
* @return 角色分页结果
|
||||
*/
|
||||
PageResult<SysRoleDO> getRolePage(SysRolePageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得角色列表
|
||||
*
|
||||
* @param reqVO 列表查询
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRoleDO> getRoles(SysRoleExportReqVO reqVO);
|
||||
|
||||
}
|
||||
|
@@ -127,46 +127,6 @@ public class SysMenuServiceImpl implements SysMenuService {
|
||||
return menuMapper.selectList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> listMenus() {
|
||||
return menuMapper.selectList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> listMenus(SysMenuListReqVO reqVO) {
|
||||
return menuMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> listMenusFromCache(Collection<Integer> menuTypes, Collection<Integer> menusStatuses) {
|
||||
// 任一一个参数为空,则返回空
|
||||
if (CollectionUtils.isAnyEmpty(menuTypes, menusStatuses)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 创建新数组,避免缓存被修改
|
||||
return menuCache.values().stream().filter(menu -> menuTypes.contains(menu.getType())
|
||||
&& menusStatuses.contains(menu.getStatus()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> listMenusFromCache(Collection<Long> menuIds, Collection<Integer> menuTypes,
|
||||
Collection<Integer> menusStatuses) {
|
||||
// 任一一个参数为空,则返回空
|
||||
if (CollectionUtils.isAnyEmpty(menuIds, menuTypes, menusStatuses)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return menuCache.values().stream().filter(menu -> menuIds.contains(menu.getId())
|
||||
&& menuTypes.contains(menu.getType())
|
||||
&& menusStatuses.contains(menu.getStatus()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> getMenuListByPermissionFromCache(String permission) {
|
||||
return new ArrayList<>(permissionMenuCache.get(permission));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createMenu(SysMenuCreateReqVO reqVO) {
|
||||
// 校验父菜单存在
|
||||
@@ -206,7 +166,7 @@ public class SysMenuServiceImpl implements SysMenuService {
|
||||
*
|
||||
* @param menuId 菜单编号
|
||||
*/
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMenu(Long menuId) {
|
||||
// 校验更新的菜单是否存在
|
||||
if (menuMapper.selectById(menuId) == null) {
|
||||
@@ -235,6 +195,46 @@ public class SysMenuServiceImpl implements SysMenuService {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> getMenus() {
|
||||
return menuMapper.selectList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> getMenus(SysMenuListReqVO reqVO) {
|
||||
return menuMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> listMenusFromCache(Collection<Integer> menuTypes, Collection<Integer> menusStatuses) {
|
||||
// 任一一个参数为空,则返回空
|
||||
if (CollectionUtils.isAnyEmpty(menuTypes, menusStatuses)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 创建新数组,避免缓存被修改
|
||||
return menuCache.values().stream().filter(menu -> menuTypes.contains(menu.getType())
|
||||
&& menusStatuses.contains(menu.getStatus()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> listMenusFromCache(Collection<Long> menuIds, Collection<Integer> menuTypes,
|
||||
Collection<Integer> menusStatuses) {
|
||||
// 任一一个参数为空,则返回空
|
||||
if (CollectionUtils.isAnyEmpty(menuIds, menuTypes, menusStatuses)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return menuCache.values().stream().filter(menu -> menuIds.contains(menu.getId())
|
||||
&& menuTypes.contains(menu.getType())
|
||||
&& menusStatuses.contains(menu.getStatus()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> getMenuListByPermissionFromCache(String permission) {
|
||||
return new ArrayList<>(permissionMenuCache.get(permission));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysMenuDO getMenu(Long id) {
|
||||
return menuMapper.selectById(id);
|
||||
|
@@ -134,14 +134,14 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuDO> listRoleMenusFromCache(Collection<Long> roleIds, Collection<Integer> menuTypes,
|
||||
Collection<Integer> menusStatuses) {
|
||||
public List<SysMenuDO> getRoleMenusFromCache(Collection<Long> roleIds, Collection<Integer> menuTypes,
|
||||
Collection<Integer> menusStatuses) {
|
||||
// 任一一个参数为空时,不返回任何菜单
|
||||
if (CollectionUtils.isAnyEmpty(roleIds, menusStatuses, menusStatuses)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 判断角色是否包含管理员
|
||||
List<SysRoleDO> roleList = roleService.listRolesFromCache(roleIds);
|
||||
List<SysRoleDO> roleList = roleService.getRolesFromCache(roleIds);
|
||||
boolean hasAdmin = roleService.hasAnyAdmin(roleList);
|
||||
// 获得角色拥有的菜单关联
|
||||
if (hasAdmin) { // 管理员,获取到全部
|
||||
@@ -169,7 +169,7 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
||||
// 如果是管理员的情况下,获取全部菜单编号
|
||||
SysRoleDO role = roleService.getRole(roleId);
|
||||
if (roleService.hasAnyAdmin(Collections.singletonList(role))) {
|
||||
return CollectionUtils.convertSet(menuService.listMenus(), SysMenuDO::getId);
|
||||
return CollectionUtils.convertSet(menuService.getMenus(), SysMenuDO::getId);
|
||||
}
|
||||
// 如果是非管理员的情况下,获得拥有的菜单编号
|
||||
return CollectionUtils.convertSet(roleMenuMapper.selectListByRoleId(roleId),
|
||||
@@ -177,7 +177,7 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void assignRoleMenu(Long roleId, Set<Long> menuIds) {
|
||||
// 获得角色拥有菜单编号
|
||||
Set<Long> dbMenuIds = CollectionUtils.convertSet(roleMenuMapper.selectListByRoleId(roleId),
|
||||
@@ -232,22 +232,41 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void processRoleDeleted(Long roleId) {
|
||||
// TODO 实现我
|
||||
// // 标记删除 RoleResource
|
||||
// roleResourceMapper.deleteByRoleId(roleId);
|
||||
// // 标记删除 AdminRole
|
||||
// adminRoleMapper.deleteByRoleId(roleId);
|
||||
// 标记删除 UserRole
|
||||
userRoleMapper.deleteListByRoleId(roleId);
|
||||
// 标记删除 RoleMenu
|
||||
roleMenuMapper.deleteListByRoleId(roleId);
|
||||
// 发送刷新消息. 注意,需要事务提交后,在进行发送刷新消息。不然 db 还未提交,结果缓存先刷新了
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
permissionProducer.sendRoleMenuRefreshMessage();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void processMenuDeleted(Long menuId) {
|
||||
// TODO 实现我
|
||||
roleMenuMapper.deleteListByMenuId(menuId);
|
||||
// 发送刷新消息. 注意,需要事务提交后,在进行发送刷新消息。不然 db 还未提交,结果缓存先刷新了
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
permissionProducer.sendRoleMenuRefreshMessage();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processUserDeleted(Long userId) {
|
||||
// TODO 实现我
|
||||
userRoleMapper.deleteListByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -306,7 +325,7 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
||||
if (roleService.hasAnyAdmin(roleIds)) {
|
||||
return true;
|
||||
}
|
||||
Set<String> userRoles = CollectionUtils.convertSet(roleService.listRolesFromCache(roleIds),
|
||||
Set<String> userRoles = CollectionUtils.convertSet(roleService.getRolesFromCache(roleIds),
|
||||
SysRoleDO::getCode);
|
||||
return CollUtil.containsAny(userRoles, Sets.newHashSet(roles));
|
||||
}
|
||||
|
@@ -118,33 +118,6 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||
return roleMapper.selectList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysRoleDO getRoleFromCache(Long id) {
|
||||
return roleCache.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleDO> listRoles(@Nullable Collection<Integer> statuses) {
|
||||
return roleMapper.selectListByStatus(statuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleDO> listRolesFromCache(Collection<Long> ids) {
|
||||
if (CollectionUtil.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return roleCache.values().stream().filter(roleDO -> ids.contains(roleDO.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAnyAdmin(Collection<SysRoleDO> roleList) {
|
||||
if (CollectionUtil.isEmpty(roleList)) {
|
||||
return false;
|
||||
}
|
||||
return roleList.stream().anyMatch(roleDO -> RoleCodeEnum.ADMIN.getKey().equals(roleDO.getCode()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createRole(SysRoleCreateReqVO reqVO) {
|
||||
// 校验角色
|
||||
@@ -173,41 +146,6 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||
roleProducer.sendRoleRefreshMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteRole(Long id) {
|
||||
// 校验是否可以更新
|
||||
this.checkUpdateRole(id);
|
||||
// 标记删除
|
||||
roleMapper.deleteById(id);
|
||||
// 删除相关数据
|
||||
permissionService.processRoleDeleted(id);
|
||||
// 发送刷新消息. 注意,需要事务提交后,在进行发送刷新消息。不然 db 还未提交,结果缓存先刷新了
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
roleProducer.sendRoleRefreshMessage();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysRoleDO getRole(Long id) {
|
||||
return roleMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysRoleDO> pageRole(SysRolePageReqVO reqVO) {
|
||||
return roleMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleDO> listRoles(SysRoleExportReqVO reqVO) {
|
||||
return roleMapper.listRoles(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRoleStatus(Long id, Integer status) {
|
||||
// 校验是否可以更新
|
||||
@@ -235,6 +173,68 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||
roleProducer.sendRoleRefreshMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteRole(Long id) {
|
||||
// 校验是否可以更新
|
||||
this.checkUpdateRole(id);
|
||||
// 标记删除
|
||||
roleMapper.deleteById(id);
|
||||
// 删除相关数据
|
||||
permissionService.processRoleDeleted(id);
|
||||
// 发送刷新消息. 注意,需要事务提交后,在进行发送刷新消息。不然 db 还未提交,结果缓存先刷新了
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
roleProducer.sendRoleRefreshMessage();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysRoleDO getRoleFromCache(Long id) {
|
||||
return roleCache.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleDO> getRoles(@Nullable Collection<Integer> statuses) {
|
||||
return roleMapper.selectListByStatus(statuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleDO> getRolesFromCache(Collection<Long> ids) {
|
||||
if (CollectionUtil.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return roleCache.values().stream().filter(roleDO -> ids.contains(roleDO.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAnyAdmin(Collection<SysRoleDO> roleList) {
|
||||
if (CollectionUtil.isEmpty(roleList)) {
|
||||
return false;
|
||||
}
|
||||
return roleList.stream().anyMatch(roleDO -> RoleCodeEnum.ADMIN.getKey().equals(roleDO.getCode()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysRoleDO getRole(Long id) {
|
||||
return roleMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysRoleDO> getRolePage(SysRolePageReqVO reqVO) {
|
||||
return roleMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleDO> getRoles(SysRoleExportReqVO reqVO) {
|
||||
return roleMapper.listRoles(reqVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验角色的唯一字段是否重复
|
||||
*
|
||||
@@ -278,16 +278,10 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 根据条件分页查询角色数据
|
||||
// *
|
||||
// * @param role 角色信息
|
||||
// * @return 角色数据集合信息
|
||||
// */
|
||||
// @Override
|
||||
// @DataScope(deptAlias = "d")
|
||||
// public List<SysRole> selectRoleList(SysRole role) {
|
||||
// return roleMapper.selectRoleList(role);
|
||||
// }
|
||||
|
||||
}
|
||||
|
@@ -2,10 +2,18 @@ package cn.iocoder.dashboard.modules.system.service.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.*;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVo;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserImportExcelVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserImportRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
||||
import cn.iocoder.dashboard.util.collection.CollectionUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -18,75 +26,6 @@ import java.util.Map;
|
||||
*/
|
||||
public interface SysUserService {
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUserDO getUserByUserName(String username);
|
||||
|
||||
/**
|
||||
* 通过用户 ID 查询用户
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUserDO getUser(Long id);
|
||||
|
||||
/**
|
||||
* 获得用户分页列表
|
||||
*
|
||||
* @param reqVO 分页条件
|
||||
* @return 分页列表
|
||||
*/
|
||||
PageResult<SysUserDO> pageUsers(SysUserPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得用户列表
|
||||
*
|
||||
* @param reqVO 列表请求
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<SysUserDO> listUsers(SysUserExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得用户列表
|
||||
*
|
||||
* @param ids 用户编号数组
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<SysUserDO> listUsers(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得用户 Map
|
||||
*
|
||||
* @param ids 用户编号数组
|
||||
* @return 用户 Map
|
||||
*/
|
||||
default Map<Long, SysUserDO> getUserMap(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return CollectionUtils.convertMap(listUsers(ids), SysUserDO::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得用户列表,基于昵称模糊匹配
|
||||
*
|
||||
* @param nickname 昵称
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<SysUserDO> listUsersByNickname(String nickname);
|
||||
|
||||
/**
|
||||
* 获得用户列表,基于用户账号模糊匹配
|
||||
*
|
||||
* @param username 用户账号
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<SysUserDO> listUsersByUsername(String username);
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
*
|
||||
@@ -103,16 +42,32 @@ public interface SysUserService {
|
||||
void updateUser(SysUserUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* 修改用户个人信息
|
||||
*
|
||||
* @param id 用户编号
|
||||
* @param reqVO 用户个人信息
|
||||
*/
|
||||
void deleteUser(Long id);
|
||||
void updateUserProfile(SysUserProfileUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 修改用户个人密码
|
||||
*
|
||||
* @param reqVO 更新用户个人密码
|
||||
*/
|
||||
void updateUserPassword(SysUserProfileUpdatePasswordReqVo reqVO);
|
||||
|
||||
|
||||
/**
|
||||
* 更新用户头像
|
||||
*
|
||||
* @param id 用户 id
|
||||
* @param avatarFile 头像文件
|
||||
*/
|
||||
void updateUserAvatar(Long id, InputStream avatarFile);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*
|
||||
* @param id 用户编号
|
||||
* @param id 用户编号
|
||||
* @param password 密码
|
||||
*/
|
||||
void updateUserPassword(Long id, String password);
|
||||
@@ -120,53 +75,94 @@ public interface SysUserService {
|
||||
/**
|
||||
* 修改密码
|
||||
*
|
||||
* @param id 用户编号
|
||||
* @param id 用户编号
|
||||
* @param status 状态
|
||||
*/
|
||||
void updateUserStatus(Long id, Integer status);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param id 用户编号
|
||||
*/
|
||||
void deleteUser(Long id);
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUserDO getUserByUsername(String username);
|
||||
|
||||
/**
|
||||
* 通过用户 ID 查询用户
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
SysUserDO getUser(Long id);
|
||||
|
||||
/**
|
||||
* 获得用户分页列表
|
||||
*
|
||||
* @param reqVO 分页条件
|
||||
* @return 分页列表
|
||||
*/
|
||||
PageResult<SysUserDO> getUserPage(SysUserPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得用户列表
|
||||
*
|
||||
* @param reqVO 列表请求
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<SysUserDO> getUsers(SysUserExportReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得用户列表
|
||||
*
|
||||
* @param ids 用户编号数组
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<SysUserDO> getUsers(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得用户 Map
|
||||
*
|
||||
* @param ids 用户编号数组
|
||||
* @return 用户 Map
|
||||
*/
|
||||
default Map<Long, SysUserDO> getUserMap(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return CollectionUtils.convertMap(getUsers(ids), SysUserDO::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得用户列表,基于昵称模糊匹配
|
||||
*
|
||||
* @param nickname 昵称
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<SysUserDO> getUsersByNickname(String nickname);
|
||||
|
||||
/**
|
||||
* 获得用户列表,基于用户账号模糊匹配
|
||||
*
|
||||
* @param username 用户账号
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<SysUserDO> getUsersByUsername(String username);
|
||||
|
||||
/**
|
||||
* 批量导入用户
|
||||
*
|
||||
* @param importUsers 导入用户列表
|
||||
* @param importUsers 导入用户列表
|
||||
* @param isUpdateSupport 是否支持更新
|
||||
* @return 导入结果
|
||||
*/
|
||||
SysUserImportRespVO importUsers(List<SysUserImportExcelVO> importUsers, boolean isUpdateSupport);
|
||||
|
||||
//
|
||||
// /**
|
||||
// * 修改用户基本信息
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int updateUserProfile(SysUser user);
|
||||
//
|
||||
// /**
|
||||
// * 修改用户头像
|
||||
// *
|
||||
// * @param userName 用户名
|
||||
// * @param avatar 头像地址
|
||||
// * @return 结果
|
||||
// */
|
||||
// public boolean updateUserAvatar(String userName, String avatar);
|
||||
//
|
||||
// /**
|
||||
// * 重置用户密码
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int resetPwd(SysUser user);
|
||||
//
|
||||
// /**
|
||||
// * 重置用户密码
|
||||
// *
|
||||
// * @param userName 用户名
|
||||
// * @param password 密码
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int resetUserPwd(String userName, String password);
|
||||
|
||||
}
|
||||
|
@@ -1,17 +1,27 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.dashboard.common.exception.ServiceException;
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.*;
|
||||
import cn.iocoder.dashboard.modules.infra.service.file.InfFileService;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVo;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserImportExcelVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserImportRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.convert.user.SysUserConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.user.SysUserMapper;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.user.SysUserMapper;
|
||||
import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService;
|
||||
import cn.iocoder.dashboard.modules.system.service.dept.SysPostService;
|
||||
import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService;
|
||||
@@ -22,7 +32,14 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
||||
|
||||
@@ -45,79 +62,16 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
private SysPostService postService;
|
||||
@Resource
|
||||
private SysPermissionService permissionService;
|
||||
|
||||
@Resource
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
// /**
|
||||
// * 根据条件分页查询用户列表
|
||||
// *
|
||||
// * @param user 用户信息
|
||||
// * @return 用户信息集合信息
|
||||
// */
|
||||
// @Override
|
||||
// @DataScope(deptAlias = "d", userAlias = "u")
|
||||
// public List<SysUser> selectUserList(SysUser user)
|
||||
// {
|
||||
// return userMapper.selectUserList(user);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public SysUserDO getUserByUserName(String username) {
|
||||
return userMapper.selectByUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserDO getUser(Long id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysUserDO> pageUsers(SysUserPageReqVO reqVO) {
|
||||
return userMapper.selectPage(reqVO, this.getDeptCondition(reqVO.getDeptId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserDO> listUsers(SysUserExportReqVO reqVO) {
|
||||
return userMapper.selectList(reqVO, this.getDeptCondition(reqVO.getDeptId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserDO> listUsers(Collection<Long> ids) {
|
||||
return userMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserDO> listUsersByNickname(String nickname) {
|
||||
return userMapper.selectListByNickname(nickname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserDO> listUsersByUsername(String username) {
|
||||
return userMapper.selectListByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门条件:查询指定部门的子部门编号们,包括自身
|
||||
*
|
||||
* @param deptId 部门编号
|
||||
* @return 部门编号集合
|
||||
*/
|
||||
private Set<Long> getDeptCondition(Long deptId) {
|
||||
if (deptId == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<Long> deptIds = CollectionUtils.convertSet(deptService.listDeptsByParentIdFromCache(
|
||||
deptId, true), SysDeptDO::getId);
|
||||
deptIds.add(deptId); // 包括自身
|
||||
return deptIds;
|
||||
}
|
||||
@Resource
|
||||
private InfFileService fileService;
|
||||
|
||||
@Override
|
||||
public Long createUser(SysUserCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
|
||||
reqVO.getDeptId(), reqVO.getPostIds());
|
||||
reqVO.getDeptId(), reqVO.getPostIds());
|
||||
// 插入用户
|
||||
SysUserDO user = SysUserConvert.INSTANCE.convert(reqVO);
|
||||
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
|
||||
@@ -130,18 +84,42 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
public void updateUser(SysUserUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
|
||||
reqVO.getDeptId(), reqVO.getPostIds());
|
||||
reqVO.getDeptId(), reqVO.getPostIds());
|
||||
// 更新用户
|
||||
SysUserDO updateObj = SysUserConvert.INSTANCE.convert(reqVO);
|
||||
userMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUser(Long id) {
|
||||
// 校验用户存在
|
||||
public void updateUserProfile(SysUserProfileUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
this.checkUserExists(reqVO.getId());
|
||||
this.checkEmailUnique(reqVO.getId(), reqVO.getEmail());
|
||||
this.checkMobileUnique(reqVO.getId(), reqVO.getMobile());
|
||||
userMapper.updateById(SysUserConvert.INSTANCE.convert(reqVO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserPassword(SysUserProfileUpdatePasswordReqVo reqVO) {
|
||||
// 校验旧密码密码
|
||||
this.checkOldPassword(reqVO.getId(), reqVO.getOldPassword());
|
||||
SysUserDO updateObj = new SysUserDO();
|
||||
updateObj.setId(reqVO.getId());
|
||||
// 加密密码
|
||||
updateObj.setPassword(passwordEncoder.encode(reqVO.getNewPassword()));
|
||||
userMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserAvatar(Long id, InputStream avatarFile) {
|
||||
this.checkUserExists(id);
|
||||
// 删除用户
|
||||
userMapper.deleteById(id);
|
||||
// 存储文件
|
||||
String avatar = fileService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile));
|
||||
// 更新路径
|
||||
SysUserDO sysUserDO = new SysUserDO();
|
||||
sysUserDO.setId(id);
|
||||
sysUserDO.setAvatar(avatar);
|
||||
userMapper.updateById(sysUserDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -168,6 +146,65 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
permissionService.processUserDeleted(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUser(Long id) {
|
||||
// 校验用户存在
|
||||
this.checkUserExists(id);
|
||||
// 删除用户
|
||||
userMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserDO getUserByUsername(String username) {
|
||||
return userMapper.selectByUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserDO getUser(Long id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SysUserDO> getUserPage(SysUserPageReqVO reqVO) {
|
||||
return userMapper.selectPage(reqVO, this.getDeptCondition(reqVO.getDeptId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserDO> getUsers(SysUserExportReqVO reqVO) {
|
||||
return userMapper.selectList(reqVO, this.getDeptCondition(reqVO.getDeptId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserDO> getUsers(Collection<Long> ids) {
|
||||
return userMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserDO> getUsersByNickname(String nickname) {
|
||||
return userMapper.selectListByNickname(nickname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserDO> getUsersByUsername(String username) {
|
||||
return userMapper.selectListByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门条件:查询指定部门的子部门编号们,包括自身
|
||||
*
|
||||
* @param deptId 部门编号
|
||||
* @return 部门编号集合
|
||||
*/
|
||||
private Set<Long> getDeptCondition(Long deptId) {
|
||||
if (deptId == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<Long> deptIds = CollectionUtils.convertSet(deptService.getDeptsByParentIdFromCache(
|
||||
deptId, true), SysDeptDO::getId);
|
||||
deptIds.add(deptId); // 包括自身
|
||||
return deptIds;
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String username, String mobile, String email,
|
||||
Long deptId, Set<Long> postIds) {
|
||||
// 校验用户存在
|
||||
@@ -262,7 +299,7 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (CollUtil.isEmpty(postIds)) { // 允许不选择
|
||||
return;
|
||||
}
|
||||
List<SysPostDO> posts = postService.listPosts(postIds, null);
|
||||
List<SysPostDO> posts = postService.getPosts(postIds, null);
|
||||
if (CollUtil.isEmpty(posts)) {
|
||||
throw ServiceExceptionUtil.exception(POST_NOT_FOUND);
|
||||
}
|
||||
@@ -278,19 +315,35 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验旧密码
|
||||
*
|
||||
* @param id 用户 id
|
||||
* @param oldPassword 旧密码
|
||||
*/
|
||||
private void checkOldPassword(Long id, String oldPassword) {
|
||||
SysUserDO user = userMapper.selectById(id);
|
||||
if (user == null) {
|
||||
throw ServiceExceptionUtil.exception(USER_NOT_EXISTS);
|
||||
}
|
||||
if (!passwordEncoder.matches(oldPassword, user.getPassword())) {
|
||||
throw ServiceExceptionUtil.exception(USER_PASSWORD_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional // 添加事务,异常则回滚所有导入
|
||||
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
||||
public SysUserImportRespVO importUsers(List<SysUserImportExcelVO> importUsers, boolean isUpdateSupport) {
|
||||
if (CollUtil.isEmpty(importUsers)) {
|
||||
throw ServiceExceptionUtil.exception(USER_IMPORT_LIST_IS_EMPTY);
|
||||
}
|
||||
SysUserImportRespVO respVO = SysUserImportRespVO.builder().createUsernames(new ArrayList<>())
|
||||
.updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build();
|
||||
.updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build();
|
||||
importUsers.forEach(importUser -> {
|
||||
// 校验,判断是否有不符合的原因
|
||||
try {
|
||||
checkCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(),
|
||||
importUser.getDeptId(), null);
|
||||
importUser.getDeptId(), null);
|
||||
} catch (ServiceException ex) {
|
||||
respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage());
|
||||
return;
|
||||
|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 代码生成 column 字段定义
|
||||
@@ -17,7 +18,7 @@ import lombok.EqualsAndHashCode;
|
||||
*/
|
||||
@TableName(value = "tool_codegen_column", autoResultMap = true)
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ToolCodegenColumnDO extends BaseDO {
|
||||
|
||||
|
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 代码生成 table 表定义
|
||||
@@ -15,7 +16,7 @@ import lombok.EqualsAndHashCode;
|
||||
*/
|
||||
@TableName(value = "tool_codegen_table", autoResultMap = true)
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ToolCodegenTableDO extends BaseDO {
|
||||
|
||||
|
@@ -99,6 +99,7 @@ public class ToolCodegenBuilder {
|
||||
.put(String.class.getSimpleName(), Sets.newHashSet("tinytext", "text", "mediumtext", "longtext", // 长文本
|
||||
"char", "varchar", "nvarchar", "varchar2")) // 短文本
|
||||
.put(Date.class.getSimpleName(), Sets.newHashSet("datetime", "time", "date", "timestamp"))
|
||||
.put("byte[]", Sets.newHashSet("blob"))
|
||||
.build();
|
||||
|
||||
static {
|
||||
|
@@ -109,7 +109,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<Long> createCodegenListFromDB(List<String> tableNames) {
|
||||
List<Long> ids = new ArrayList<>(tableNames.size());
|
||||
// 遍历添加。虽然效率会低一点,但是没必要做成完全批量,因为不会这么大量
|
||||
@@ -118,7 +118,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateCodegen(ToolCodegenUpdateReqVO updateReqVO) {
|
||||
// 校验是否已经存在
|
||||
if (codegenTableMapper.selectById(updateReqVO.getTable().getId()) == null) {
|
||||
@@ -134,7 +134,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void syncCodegenFromDB(Long tableId) {
|
||||
// 校验是否已经存在
|
||||
ToolCodegenTableDO table = codegenTableMapper.selectById(tableId);
|
||||
@@ -149,7 +149,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void syncCodegenFromSQL(Long tableId, String sql) {
|
||||
// 校验是否已经存在
|
||||
ToolCodegenTableDO table = codegenTableMapper.selectById(tableId);
|
||||
@@ -201,7 +201,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteCodegen(Long tableId) {
|
||||
// 校验是否已经存在
|
||||
if (codegenTableMapper.selectById(tableId) == null) {
|
||||
|
@@ -145,14 +145,14 @@ yudao:
|
||||
swagger:
|
||||
title: 管理后台
|
||||
description: 提供管理员管理的所有功能
|
||||
version: ${yudao.info.base-package}
|
||||
version: ${yudao.info.version}
|
||||
base-package: ${yudao.info.base-package}.modules
|
||||
captcha:
|
||||
timeout: 5m
|
||||
width: 160
|
||||
height: 60
|
||||
file:
|
||||
base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/
|
||||
base-path: http://127.0.0.1:${server.port}${yudao.web.api-prefix}/system/file/get/
|
||||
codegen:
|
||||
base-package: ${yudao.info.base-package}
|
||||
db-schemas: ${spring.datasource.name}
|
||||
|
@@ -145,14 +145,14 @@ yudao:
|
||||
swagger:
|
||||
title: 管理后台
|
||||
description: 提供管理员管理的所有功能
|
||||
version: ${yudao.info.base-package}
|
||||
version: ${yudao.info.version}
|
||||
base-package: ${yudao.info.base-package}.modules
|
||||
captcha:
|
||||
timeout: 5m
|
||||
width: 160
|
||||
height: 60
|
||||
file:
|
||||
base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/
|
||||
base-path: http://127.0.0.1:${server.port}${yudao.web.api-prefix}/system/file/get/
|
||||
codegen:
|
||||
base-package: ${yudao.info.base-package}
|
||||
db-schemas: ${spring.datasource.name}
|
||||
|
@@ -55,7 +55,7 @@ public class ${table.className}Controller {
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除${table.classComment}")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:delete')")
|
||||
public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
|
||||
${classNameVar}Service.delete${simpleClassName}(id);
|
||||
return success(true);
|
||||
|
@@ -16,6 +16,7 @@ import ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.
|
||||
|
||||
import ${ServiceExceptionUtilClassName};
|
||||
|
||||
import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static ${basePackage}.modules.${table.moduleName}.enums.${simpleModuleName_upperFirst}ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
@@ -58,7 +59,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
||||
|
||||
private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) {
|
||||
if (${classNameVar}Mapper.selectById(id) == null) {
|
||||
throw ServiceExceptionUtil.exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,11 @@
|
||||
package ${basePackage}.modules.${table.moduleName}.service.${table.businessName};
|
||||
|
||||
import ${basePackage}.BaseSpringBootUnitTest;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||
import ${basePackage}.BaseDbUnitTest;
|
||||
import ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.impl.${table.className}ServiceImpl;
|
||||
import ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo.*;
|
||||
import ${basePackage}.modules.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
|
||||
@@ -16,6 +14,7 @@ import ${basePackage}.util.object.ObjectUtils;
|
||||
import ${PageResultClassName};
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
@@ -64,7 +63,8 @@ import static org.mockito.Mockito.*;
|
||||
*
|
||||
* @author ${table.author}
|
||||
*/
|
||||
public class ${table.className}ServiceTest extends BaseSpringBootUnitTest {
|
||||
@Import(${table.className}ServiceImpl.class)
|
||||
public class ${table.className}ServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private ${table.className}ServiceImpl ${classNameVar}Service;
|
||||
@@ -78,7 +78,7 @@ public class ${table.className}ServiceTest extends BaseSpringBootUnitTest {
|
||||
${table.className}CreateReqVO reqVO = randomPojo(${table.className}CreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long ${classNameVar}Id = ${classNameVar}Service.create${simpleClassName}(reqVO);
|
||||
${primaryColumn.javaType} ${classNameVar}Id = ${classNameVar}Service.create${simpleClassName}(reqVO);
|
||||
// 断言
|
||||
assertNotNull(${classNameVar}Id);
|
||||
// 校验记录的属性是否正确
|
||||
@@ -118,7 +118,7 @@ public class ${table.className}ServiceTest extends BaseSpringBootUnitTest {
|
||||
${table.className}DO db${simpleClassName} = randomPojo(${table.className}DO.class);
|
||||
${classNameVar}Mapper.insert(db${simpleClassName});// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = db${simpleClassName}.getId();
|
||||
${primaryColumn.javaType} id = db${simpleClassName}.getId();
|
||||
|
||||
// 调用
|
||||
${classNameVar}Service.delete${simpleClassName}(id);
|
||||
@@ -129,7 +129,7 @@ public class ${table.className}ServiceTest extends BaseSpringBootUnitTest {
|
||||
@Test
|
||||
public void testDelete${simpleClassName}_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
${primaryColumn.javaType} id = random${primaryColumn.javaType}Id();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> ${classNameVar}Service.delete${simpleClassName}(id), ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||
|
@@ -4,7 +4,7 @@ INSERT INTO `sys_menu`(
|
||||
`path`, `icon`, `component`, `status`
|
||||
)
|
||||
VALUES (
|
||||
'${table.classComment}管理', '${permissionPrefix}:query', 2, 0, ${table.parentMenuId},
|
||||
'${table.classComment}管理', '', 2, 0, ${table.parentMenuId},
|
||||
'${simpleClassName_strikeCase}', '', '${table.moduleName}/${classNameVar}/index', 0
|
||||
);
|
||||
|
||||
@@ -12,8 +12,8 @@ VALUES (
|
||||
SELECT @parentId := LAST_INSERT_ID();
|
||||
|
||||
-- 按钮 SQL
|
||||
#set ($functionNames = ['创建', '更新', '删除', '导出'])
|
||||
#set ($functionOps = ['create', 'update', 'delete', 'export'])
|
||||
#set ($functionNames = ['查询', '创建', '更新', '删除', '导出'])
|
||||
#set ($functionOps = ['query', 'create', 'update', 'delete', 'export'])
|
||||
#foreach ($functionName in $functionNames)
|
||||
#set ($index = $foreach.count - 1)
|
||||
INSERT INTO `sys_menu`(
|
||||
@@ -21,7 +21,7 @@ INSERT INTO `sys_menu`(
|
||||
`path`, `icon`, `component`, `status`
|
||||
)
|
||||
VALUES (
|
||||
'${table.tableComment}${functionName}', '${permissionPrefix}:${functionOps.get($index)}', 3, $foreach.count, @parentId,
|
||||
'${table.classComment}${functionName}', '${permissionPrefix}:${functionOps.get($index)}', 3, $foreach.count, @parentId,
|
||||
'', '', '', 0
|
||||
);
|
||||
#end
|
||||
|
@@ -68,7 +68,7 @@
|
||||
#if ($column.javaType == "Date")## 时间类型
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
|
||||
<span>{{ parseTime(scope.row.${javaField}) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif("" != $column.dictType)## 数据字典
|
||||
|
@@ -9,15 +9,16 @@ import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
|
||||
/**
|
||||
* 依赖内存 DB 的单元测试
|
||||
* 依赖内存 DB + Redis 的单元测试
|
||||
*
|
||||
* 注意,Service 层同样适用。对于 Service 层的单元测试,我们针对自己模块的 Mapper 走的是 H2 内存数据库,针对别的模块的 Service 走的是 Mock 方法
|
||||
* 相比 {@link BaseDbUnitTest} 来说,额外增加了内存 Redis
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@@ -30,6 +31,7 @@ public class BaseDbAndRedisUnitTest {
|
||||
// DB 配置类
|
||||
DataSourceConfiguration.class, // 自己的 DB 配置类
|
||||
DataSourceAutoConfiguration.class, // Spring DB 自动配置类
|
||||
DataSourceTransactionManagerAutoConfiguration.class, // Spring 事务自动配置类
|
||||
DruidDataSourceAutoConfigure.class, // Druid 自动配置类
|
||||
// MyBatis 配置类
|
||||
MybatisConfiguration.class, // 自己的 MyBatis 配置类
|
||||
|
@@ -5,6 +5,7 @@ import cn.iocoder.dashboard.framework.mybatis.config.MybatisConfiguration;
|
||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
@@ -26,6 +27,7 @@ public class BaseDbUnitTest {
|
||||
// DB 配置类
|
||||
DataSourceConfiguration.class, // 自己的 DB 配置类
|
||||
DataSourceAutoConfiguration.class, // Spring DB 自动配置类
|
||||
DataSourceTransactionManagerAutoConfiguration.class, // Spring 事务自动配置类
|
||||
DruidDataSourceAutoConfigure.class, // Druid 自动配置类
|
||||
// MyBatis 配置类
|
||||
MybatisConfiguration.class, // 自己的 MyBatis 配置类
|
||||
|
32
src/test/java/cn/iocoder/dashboard/BaseRedisUnitTest.java
Normal file
32
src/test/java/cn/iocoder/dashboard/BaseRedisUnitTest.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package cn.iocoder.dashboard;
|
||||
|
||||
import cn.iocoder.dashboard.config.RedisTestConfiguration;
|
||||
import cn.iocoder.dashboard.framework.redis.config.RedisConfig;
|
||||
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
/**
|
||||
* 依赖内存 Redis 的单元测试
|
||||
*
|
||||
* 相比 {@link BaseDbUnitTest} 来说,从内存 DB 改成了内存 Redis
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseRedisUnitTest.Application.class)
|
||||
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||
public class BaseRedisUnitTest {
|
||||
|
||||
@Import({
|
||||
// Redis 配置类
|
||||
RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer
|
||||
RedisAutoConfiguration.class, // Spring Redis 自动配置类
|
||||
RedisConfig.class, // 自己的 Redis 配置类
|
||||
RedissonAutoConfiguration.class, // Redisson 自动高配置类
|
||||
})
|
||||
public static class Application {
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
package cn.iocoder.dashboard;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB
|
||||
@Deprecated
|
||||
public class BaseSpringBootUnitTest {
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
/**
|
||||
* 每个单元测试结束后,清理 Redis
|
||||
*/
|
||||
@AfterEach
|
||||
public void cleanRedis() {
|
||||
stringRedisTemplate.execute((RedisCallback<Object>) connection -> {
|
||||
connection.flushDb();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -1,19 +1,17 @@
|
||||
package cn.iocoder.dashboard.config;
|
||||
|
||||
import com.github.fppt.jedismock.RedisServer;
|
||||
import org.redisson.spring.starter.RedissonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Lazy(false) // 禁止延迟加载
|
||||
@EnableConfigurationProperties(RedisProperties.class)
|
||||
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化
|
||||
public class RedisTestConfiguration {
|
||||
|
||||
/**
|
||||
|
@@ -1,14 +1,14 @@
|
||||
package cn.iocoder.dashboard.framework.quartz.core.scheduler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.modules.system.job.auth.SysUserSessionTimeoutJob;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
class SchedulerManagerTest extends BaseSpringBootUnitTest {
|
||||
class SchedulerManagerTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private SchedulerManager schedulerManager;
|
||||
|
@@ -0,0 +1,126 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.file;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.file.config.FileProperties;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.mysql.file.InfFileMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.service.file.impl.InfFileServiceImpl;
|
||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.FILE_NOT_EXISTS;
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.FILE_PATH_EXISTS;
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.dashboard.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.dashboard.util.RandomUtils.randomString;
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@Import({InfFileServiceImpl.class, FileProperties.class})
|
||||
public class InfFileServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfFileServiceImpl fileService;
|
||||
|
||||
@Resource
|
||||
private FileProperties fileProperties;
|
||||
@Resource
|
||||
private InfFileMapper fileMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateFile_success() {
|
||||
// 准备参数
|
||||
String path = randomString();
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
|
||||
// 调用
|
||||
String url = fileService.createFile(path, content);
|
||||
// 断言
|
||||
assertEquals(fileProperties.getBasePath() + path, url);
|
||||
// 校验数据
|
||||
InfFileDO file = fileMapper.selectById(path);
|
||||
assertEquals(path, file.getId());
|
||||
assertEquals("jpg", file.getType());
|
||||
assertArrayEquals(content, file.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFile_exists() {
|
||||
// mock 数据
|
||||
InfFileDO dbFile = randomPojo(InfFileDO.class);
|
||||
fileMapper.insert(dbFile);
|
||||
// 准备参数
|
||||
String path = dbFile.getId(); // 模拟已存在
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> fileService.createFile(path, content), FILE_PATH_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFile_success() {
|
||||
// mock 数据
|
||||
InfFileDO dbFile = randomPojo(InfFileDO.class);
|
||||
fileMapper.insert(dbFile);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
String id = dbFile.getId();
|
||||
|
||||
// 调用
|
||||
fileService.deleteFile(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(fileMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFile_notExists() {
|
||||
// 准备参数
|
||||
String id = randomString();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> fileService.deleteFile(id), FILE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFilePage() {
|
||||
// mock 数据
|
||||
InfFileDO dbFile = randomPojo(InfFileDO.class, o -> { // 等会查询到
|
||||
o.setId("yudao");
|
||||
o.setType("jpg");
|
||||
o.setCreateTime(buildTime(2021, 1, 15));
|
||||
});
|
||||
fileMapper.insert(dbFile);
|
||||
// 测试 id 不匹配
|
||||
fileMapper.insert(ObjectUtils.clone(dbFile, o -> o.setId("tudou")));
|
||||
// 测试 type 不匹配
|
||||
fileMapper.insert(ObjectUtils.clone(dbFile, o -> {
|
||||
o.setId("yudao02");
|
||||
o.setType("png");
|
||||
}));
|
||||
// 测试 createTime 不匹配
|
||||
fileMapper.insert(ObjectUtils.clone(dbFile, o -> {
|
||||
o.setId("yudao03");
|
||||
o.setCreateTime(buildTime(2020, 1, 15));
|
||||
}));
|
||||
// 准备参数
|
||||
InfFilePageReqVO reqVO = new InfFilePageReqVO();
|
||||
reqVO.setId("yudao");
|
||||
reqVO.setType("jp");
|
||||
reqVO.setBeginCreateTime(buildTime(2021, 1, 10));
|
||||
reqVO.setEndCreateTime(buildTime(2021, 1, 20));
|
||||
|
||||
// 调用
|
||||
PageResult<InfFileDO> pageResult = fileService.getFilePage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbFile, pageResult.getList().get(0), "content");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,173 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.job;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.dashboard.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.dashboard.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.dashboard.util.RandomUtils.randomString;
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.job.vo.log.InfJobLogExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.job.vo.log.InfJobLogPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.job.InfJobLogDO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.mysql.job.InfJobLogMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.enums.job.InfJobLogStatusEnum;
|
||||
import cn.iocoder.dashboard.modules.infra.service.job.impl.InfJobLogServiceImpl;
|
||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||
|
||||
/**
|
||||
* {@link InfJobLogServiceImpl} 的单元测试
|
||||
*
|
||||
* @author neilz
|
||||
*/
|
||||
@Import(InfJobLogServiceImpl.class)
|
||||
public class InfJobLogServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfJobLogServiceImpl jobLogService;
|
||||
@Resource
|
||||
private InfJobLogMapper jobLogMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateJobLog_success() {
|
||||
// 准备参数
|
||||
InfJobLogDO reqVO = randomPojo(InfJobLogDO.class, o -> {
|
||||
o.setExecuteIndex(1);
|
||||
});
|
||||
// 调用
|
||||
Long jobLogId = jobLogService.createJobLog(reqVO.getJobId(), reqVO.getBeginTime(), reqVO.getHandlerName(), reqVO.getHandlerParam(), reqVO.getExecuteIndex());
|
||||
// 断言
|
||||
assertNotNull(jobLogId);
|
||||
// 校验记录的属性是否正确
|
||||
InfJobLogDO job = jobLogMapper.selectById(jobLogId);
|
||||
assertEquals(InfJobLogStatusEnum.RUNNING.getStatus(), job.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateJobLogResultAsync_success() {
|
||||
// 准备参数
|
||||
InfJobLogDO reqVO = randomPojo(InfJobLogDO.class, o -> {
|
||||
o.setExecuteIndex(1);
|
||||
});
|
||||
InfJobLogDO log = InfJobLogDO.builder().jobId(reqVO.getJobId()).handlerName(reqVO.getHandlerName()).handlerParam(reqVO.getHandlerParam()).executeIndex(reqVO.getExecuteIndex())
|
||||
.beginTime(reqVO.getBeginTime()).status(InfJobLogStatusEnum.RUNNING.getStatus()).build();
|
||||
jobLogMapper.insert(log);
|
||||
// 调用
|
||||
jobLogService.updateJobLogResultAsync(log.getId(), reqVO.getBeginTime(), reqVO.getDuration(), true,reqVO.getResult());
|
||||
// 校验记录的属性是否正确
|
||||
InfJobLogDO job = jobLogMapper.selectById(log.getId());
|
||||
assertEquals(InfJobLogStatusEnum.SUCCESS.getStatus(), job.getStatus());
|
||||
|
||||
// 调用
|
||||
jobLogService.updateJobLogResultAsync(log.getId(), reqVO.getBeginTime(), reqVO.getDuration(), false,reqVO.getResult());
|
||||
// 校验记录的属性是否正确
|
||||
InfJobLogDO job2 = jobLogMapper.selectById(log.getId());
|
||||
assertEquals(InfJobLogStatusEnum.FAILURE.getStatus(), job2.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobLogListByIds_success() {
|
||||
// mock 数据
|
||||
InfJobLogDO dbJobLog = randomPojo(InfJobLogDO.class, o -> {
|
||||
o.setExecuteIndex(1);
|
||||
o.setStatus(randomEle(InfJobLogStatusEnum.values()).getStatus()); // 保证 status 的范围
|
||||
});
|
||||
InfJobLogDO cloneJobLog = ObjectUtils.clone(dbJobLog, o -> o.setHandlerName(randomString()));
|
||||
jobLogMapper.insert(dbJobLog);
|
||||
// 测试 handlerName 不匹配
|
||||
jobLogMapper.insert(cloneJobLog);
|
||||
// 准备参数
|
||||
ArrayList ids = new ArrayList<>();
|
||||
ids.add(dbJobLog.getId());
|
||||
ids.add(cloneJobLog.getId());
|
||||
// 调用
|
||||
List<InfJobLogDO> list = jobLogService.getJobLogList(ids);
|
||||
// 断言
|
||||
assertEquals(2, list.size());
|
||||
assertPojoEquals(dbJobLog, list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobPage_success() {
|
||||
// mock 数据
|
||||
InfJobLogDO dbJobLog = randomPojo(InfJobLogDO.class, o -> {
|
||||
o.setExecuteIndex(1);
|
||||
o.setHandlerName("handlerName 单元测试");
|
||||
o.setStatus(InfJobLogStatusEnum.SUCCESS.getStatus());
|
||||
o.setBeginTime(buildTime(2021, 1, 8));
|
||||
o.setEndTime(buildTime(2021, 1, 8));
|
||||
});
|
||||
jobLogMapper.insert(dbJobLog);
|
||||
// 测试 jobId 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.clone(dbJobLog, o -> o.setJobId(randomLongId())));
|
||||
// 测试 handlerName 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.clone(dbJobLog, o -> o.setHandlerName(randomString())));
|
||||
// 测试 beginTime 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.clone(dbJobLog, o -> o.setBeginTime(buildTime(2021, 1, 7))));
|
||||
// 测试 endTime 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.clone(dbJobLog, o -> o.setEndTime(buildTime(2021, 1, 9))));
|
||||
// 测试 status 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.clone(dbJobLog, o -> o.setStatus(InfJobLogStatusEnum.FAILURE.getStatus())));
|
||||
// 准备参数
|
||||
InfJobLogPageReqVO reqVo = new InfJobLogPageReqVO();
|
||||
reqVo.setJobId(dbJobLog.getJobId());
|
||||
reqVo.setHandlerName("单元");
|
||||
reqVo.setBeginTime(dbJobLog.getBeginTime());
|
||||
reqVo.setEndTime(dbJobLog.getEndTime());
|
||||
reqVo.setStatus(InfJobLogStatusEnum.SUCCESS.getStatus());
|
||||
// 调用
|
||||
PageResult<InfJobLogDO> pageResult = jobLogService.getJobLogPage(reqVo);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbJobLog, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobListForExport_success() {
|
||||
// mock 数据
|
||||
InfJobLogDO dbJobLog = randomPojo(InfJobLogDO.class, o -> {
|
||||
o.setExecuteIndex(1);
|
||||
o.setHandlerName("handlerName 单元测试");
|
||||
o.setStatus(InfJobLogStatusEnum.SUCCESS.getStatus());
|
||||
o.setBeginTime(buildTime(2021, 1, 8));
|
||||
o.setEndTime(buildTime(2021, 1, 8));
|
||||
});
|
||||
jobLogMapper.insert(dbJobLog);
|
||||
// 测试 jobId 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.clone(dbJobLog, o -> o.setJobId(randomLongId())));
|
||||
// 测试 handlerName 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.clone(dbJobLog, o -> o.setHandlerName(randomString())));
|
||||
// 测试 beginTime 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.clone(dbJobLog, o -> o.setBeginTime(buildTime(2021, 1, 7))));
|
||||
// 测试 endTime 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.clone(dbJobLog, o -> o.setEndTime(buildTime(2021, 1, 9))));
|
||||
// 测试 status 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.clone(dbJobLog, o -> o.setStatus(InfJobLogStatusEnum.FAILURE.getStatus())));
|
||||
// 准备参数
|
||||
InfJobLogExportReqVO reqVo = new InfJobLogExportReqVO();
|
||||
reqVo.setJobId(dbJobLog.getJobId());
|
||||
reqVo.setHandlerName("单元");
|
||||
reqVo.setBeginTime(dbJobLog.getBeginTime());
|
||||
reqVo.setEndTime(dbJobLog.getEndTime());
|
||||
reqVo.setStatus(InfJobLogStatusEnum.SUCCESS.getStatus());
|
||||
// 调用
|
||||
List<InfJobLogDO> list = jobLogService.getJobLogList(reqVo);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbJobLog, list.get(0));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,309 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.job;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.JOB_CHANGE_STATUS_EQUALS;
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.JOB_CHANGE_STATUS_INVALID;
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.JOB_CRON_EXPRESSION_VALID;
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.JOB_HANDLER_EXISTS;
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.JOB_NOT_EXISTS;
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.JOB_UPDATE_ONLY_NORMAL_STATUS;
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.dashboard.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.dashboard.util.RandomUtils.randomString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.quartz.core.scheduler.SchedulerManager;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobCreateReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.job.vo.job.InfJobUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.convert.job.InfJobConvert;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.job.InfJobDO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.mysql.job.InfJobMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.enums.job.InfJobStatusEnum;
|
||||
import cn.iocoder.dashboard.modules.infra.service.job.impl.InfJobServiceImpl;
|
||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||
|
||||
/**
|
||||
* {@link InfJobServiceImpl} 的单元测试
|
||||
*
|
||||
* @author neilz
|
||||
*/
|
||||
@Import(InfJobServiceImpl.class)
|
||||
public class InfJobServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfJobServiceImpl jobService;
|
||||
@Resource
|
||||
private InfJobMapper jobMapper;
|
||||
@MockBean
|
||||
private SchedulerManager schedulerManager;
|
||||
|
||||
@Test
|
||||
public void testCreateJob_cronExpressionValid() {
|
||||
// 准备参数。Cron 表达式为 String 类型,默认随机字符串。
|
||||
InfJobCreateReqVO reqVO = randomPojo(InfJobCreateReqVO.class);
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> jobService.createJob(reqVO), JOB_CRON_EXPRESSION_VALID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJob_jobHandlerExists() throws SchedulerException {
|
||||
// 准备参数 指定 Cron 表达式
|
||||
InfJobCreateReqVO reqVO = randomPojo(InfJobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *"));
|
||||
// 调用
|
||||
jobService.createJob(reqVO);
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> jobService.createJob(reqVO), JOB_HANDLER_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJob_success() throws SchedulerException {
|
||||
// 准备参数 指定 Cron 表达式
|
||||
InfJobCreateReqVO reqVO = randomPojo(InfJobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *"));
|
||||
// 调用
|
||||
Long jobId = jobService.createJob(reqVO);
|
||||
// 断言
|
||||
assertNotNull(jobId);
|
||||
// 校验记录的属性是否正确
|
||||
InfJobDO job = jobMapper.selectById(jobId);
|
||||
assertPojoEquals(reqVO, job);
|
||||
assertEquals(InfJobStatusEnum.NORMAL.getStatus(), job.getStatus());
|
||||
// 校验调用
|
||||
verify(schedulerManager, times(1)).addJob(eq(job.getId()), eq(job.getHandlerName()), eq(job.getHandlerParam()), eq(job.getCronExpression()),
|
||||
eq(reqVO.getRetryCount()), eq(reqVO.getRetryInterval()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateJob_jobNotExists(){
|
||||
// 准备参数
|
||||
InfJobUpdateReqVO reqVO = randomPojo(InfJobUpdateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *"));
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> jobService.updateJob(reqVO), JOB_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateJob_onlyNormalStatus(){
|
||||
// mock 数据
|
||||
InfJobCreateReqVO createReqVO = randomPojo(InfJobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *"));
|
||||
InfJobDO job = InfJobConvert.INSTANCE.convert(createReqVO);
|
||||
job.setStatus(InfJobStatusEnum.INIT.getStatus());
|
||||
fillJobMonitorTimeoutEmpty(job);
|
||||
jobMapper.insert(job);
|
||||
// 准备参数
|
||||
InfJobUpdateReqVO updateReqVO = randomPojo(InfJobUpdateReqVO.class, o -> {
|
||||
o.setId(job.getId());
|
||||
o.setName(createReqVO.getName());
|
||||
o.setCronExpression(createReqVO.getCronExpression());
|
||||
});
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> jobService.updateJob(updateReqVO), JOB_UPDATE_ONLY_NORMAL_STATUS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateJob_success() throws SchedulerException {
|
||||
// mock 数据
|
||||
InfJobCreateReqVO createReqVO = randomPojo(InfJobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *"));
|
||||
InfJobDO job = InfJobConvert.INSTANCE.convert(createReqVO);
|
||||
job.setStatus(InfJobStatusEnum.NORMAL.getStatus());
|
||||
fillJobMonitorTimeoutEmpty(job);
|
||||
jobMapper.insert(job);
|
||||
// 准备参数
|
||||
InfJobUpdateReqVO updateReqVO = randomPojo(InfJobUpdateReqVO.class, o -> {
|
||||
o.setId(job.getId());
|
||||
o.setName(createReqVO.getName());
|
||||
o.setCronExpression(createReqVO.getCronExpression());
|
||||
});
|
||||
// 调用
|
||||
jobService.updateJob(updateReqVO);
|
||||
// 校验记录的属性是否正确
|
||||
InfJobDO updateJob = jobMapper.selectById(updateReqVO.getId());
|
||||
assertPojoEquals(updateReqVO, updateJob);
|
||||
// 校验调用
|
||||
verify(schedulerManager, times(1)).updateJob(eq(job.getHandlerName()), eq(updateReqVO.getHandlerParam()), eq(updateReqVO.getCronExpression()),
|
||||
eq(updateReqVO.getRetryCount()), eq(updateReqVO.getRetryInterval()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateJobStatus_changeStatusInvalid() {
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> jobService.updateJobStatus(1l, InfJobStatusEnum.INIT.getStatus()), JOB_CHANGE_STATUS_INVALID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateJobStatus_changeStatusEquals() {
|
||||
// mock 数据
|
||||
InfJobCreateReqVO createReqVO = randomPojo(InfJobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *"));
|
||||
InfJobDO job = InfJobConvert.INSTANCE.convert(createReqVO);
|
||||
job.setStatus(InfJobStatusEnum.NORMAL.getStatus());
|
||||
fillJobMonitorTimeoutEmpty(job);
|
||||
jobMapper.insert(job);
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> jobService.updateJobStatus(job.getId(), job.getStatus()), JOB_CHANGE_STATUS_EQUALS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateJobStatus_NormalToStop_success() throws SchedulerException {
|
||||
// mock 数据
|
||||
InfJobCreateReqVO createReqVO = randomPojo(InfJobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *"));
|
||||
InfJobDO job = InfJobConvert.INSTANCE.convert(createReqVO);
|
||||
job.setStatus(InfJobStatusEnum.NORMAL.getStatus());
|
||||
fillJobMonitorTimeoutEmpty(job);
|
||||
jobMapper.insert(job);
|
||||
// 调用
|
||||
jobService.updateJobStatus(job.getId(), InfJobStatusEnum.STOP.getStatus());
|
||||
// 校验记录的属性是否正确
|
||||
InfJobDO updateJob = jobMapper.selectById(job.getId());
|
||||
assertEquals(InfJobStatusEnum.STOP.getStatus(), updateJob.getStatus());
|
||||
// 校验调用
|
||||
verify(schedulerManager, times(1)).pauseJob(eq(job.getHandlerName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateJobStatus_StopToNormal_success() throws SchedulerException {
|
||||
// mock 数据
|
||||
InfJobCreateReqVO createReqVO = randomPojo(InfJobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *"));
|
||||
InfJobDO job = InfJobConvert.INSTANCE.convert(createReqVO);
|
||||
job.setStatus(InfJobStatusEnum.STOP.getStatus());
|
||||
fillJobMonitorTimeoutEmpty(job);
|
||||
jobMapper.insert(job);
|
||||
// 调用
|
||||
jobService.updateJobStatus(job.getId(), InfJobStatusEnum.NORMAL.getStatus());
|
||||
// 校验记录的属性是否正确
|
||||
InfJobDO updateJob = jobMapper.selectById(job.getId());
|
||||
assertEquals(InfJobStatusEnum.NORMAL.getStatus(), updateJob.getStatus());
|
||||
// 校验调用
|
||||
verify(schedulerManager, times(1)).resumeJob(eq(job.getHandlerName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTriggerJob_success() throws SchedulerException {
|
||||
// mock 数据
|
||||
InfJobCreateReqVO createReqVO = randomPojo(InfJobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *"));
|
||||
InfJobDO job = InfJobConvert.INSTANCE.convert(createReqVO);
|
||||
job.setStatus(InfJobStatusEnum.NORMAL.getStatus());
|
||||
fillJobMonitorTimeoutEmpty(job);
|
||||
jobMapper.insert(job);
|
||||
// 调用
|
||||
jobService.triggerJob(job.getId());
|
||||
// 校验调用
|
||||
verify(schedulerManager, times(1)).triggerJob(eq(job.getId()), eq(job.getHandlerName()), eq(job.getHandlerParam()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteJob_success() throws SchedulerException {
|
||||
// mock 数据
|
||||
InfJobCreateReqVO createReqVO = randomPojo(InfJobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *"));
|
||||
InfJobDO job = InfJobConvert.INSTANCE.convert(createReqVO);
|
||||
job.setStatus(InfJobStatusEnum.NORMAL.getStatus());
|
||||
fillJobMonitorTimeoutEmpty(job);
|
||||
jobMapper.insert(job);
|
||||
// 调用 UPDATE inf_job SET deleted=1 WHERE id=? AND deleted=0
|
||||
jobService.deleteJob(job.getId());
|
||||
// 校验数据不存在了 WHERE id=? AND deleted=0 查询为空正常
|
||||
assertNull(jobMapper.selectById(job.getId()));
|
||||
// 校验调用
|
||||
verify(schedulerManager, times(1)).deleteJob(eq(job.getHandlerName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobListByIds_success() {
|
||||
// mock 数据
|
||||
InfJobDO dbJob = randomPojo(InfJobDO.class, o -> {
|
||||
o.setStatus(randomEle(InfJobStatusEnum.values()).getStatus()); // 保证 status 的范围
|
||||
});
|
||||
InfJobDO cloneJob = ObjectUtils.clone(dbJob, o -> o.setHandlerName(randomString()));
|
||||
jobMapper.insert(dbJob);
|
||||
// 测试 handlerName 不匹配
|
||||
jobMapper.insert(cloneJob);
|
||||
// 准备参数
|
||||
ArrayList ids = new ArrayList<>();
|
||||
ids.add(dbJob.getId());
|
||||
ids.add(cloneJob.getId());
|
||||
// 调用
|
||||
List<InfJobDO> list = jobService.getJobList(ids);
|
||||
// 断言
|
||||
assertEquals(2, list.size());
|
||||
assertPojoEquals(dbJob, list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobPage_success() {
|
||||
// mock 数据
|
||||
InfJobDO dbJob = randomPojo(InfJobDO.class, o -> {
|
||||
o.setName("定时任务测试");
|
||||
o.setHandlerName("handlerName 单元测试");
|
||||
o.setStatus(InfJobStatusEnum.INIT.getStatus());
|
||||
});
|
||||
jobMapper.insert(dbJob);
|
||||
// 测试 name 不匹配
|
||||
jobMapper.insert(ObjectUtils.clone(dbJob, o -> o.setName("土豆")));
|
||||
// 测试 status 不匹配
|
||||
jobMapper.insert(ObjectUtils.clone(dbJob, o -> o.setStatus(InfJobStatusEnum.NORMAL.getStatus())));
|
||||
// 测试 handlerName 不匹配
|
||||
jobMapper.insert(ObjectUtils.clone(dbJob, o -> o.setHandlerName(randomString())));
|
||||
// 准备参数
|
||||
InfJobPageReqVO reqVo = new InfJobPageReqVO();
|
||||
reqVo.setName("定时");
|
||||
reqVo.setStatus(InfJobStatusEnum.INIT.getStatus());
|
||||
reqVo.setHandlerName("单元");
|
||||
// 调用
|
||||
PageResult<InfJobDO> pageResult = jobService.getJobPage(reqVo);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbJob, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobListForExport_success() {
|
||||
// mock 数据
|
||||
InfJobDO dbJob = randomPojo(InfJobDO.class, o -> {
|
||||
o.setName("定时任务测试");
|
||||
o.setHandlerName("handlerName 单元测试");
|
||||
o.setStatus(InfJobStatusEnum.INIT.getStatus());
|
||||
});
|
||||
jobMapper.insert(dbJob);
|
||||
// 测试 name 不匹配
|
||||
jobMapper.insert(ObjectUtils.clone(dbJob, o -> o.setName("土豆")));
|
||||
// 测试 status 不匹配
|
||||
jobMapper.insert(ObjectUtils.clone(dbJob, o -> o.setStatus(InfJobStatusEnum.NORMAL.getStatus())));
|
||||
// 测试 handlerName 不匹配
|
||||
jobMapper.insert(ObjectUtils.clone(dbJob, o -> o.setHandlerName(randomString())));
|
||||
// 准备参数
|
||||
InfJobExportReqVO reqVo = new InfJobExportReqVO();
|
||||
reqVo.setName("定时");
|
||||
reqVo.setStatus(InfJobStatusEnum.INIT.getStatus());
|
||||
reqVo.setHandlerName("单元");
|
||||
// 调用
|
||||
List<InfJobDO> list = jobService.getJobList(reqVo);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbJob, list.get(0));
|
||||
}
|
||||
|
||||
private static void fillJobMonitorTimeoutEmpty(InfJobDO job) {
|
||||
if (job.getMonitorTimeout() == null) {
|
||||
job.setMonitorTimeout(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,177 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.logger;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.dashboard.common.exception.enums.GlobalErrorCodeConstants;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.logger.apilog.core.service.dto.ApiAccessLogCreateDTO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.mysql.logger.InfApiAccessLogMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.service.logger.impl.InfApiAccessLogServiceImpl;
|
||||
import cn.iocoder.dashboard.util.RandomUtils;
|
||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* {@link InfApiAccessLogServiceImpl} 单元测试
|
||||
*/
|
||||
@Import(InfApiAccessLogServiceImpl.class)
|
||||
public class InfApiAccessLogServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfApiAccessLogService infApiAccessLogServiceImpl;
|
||||
|
||||
@Resource
|
||||
private InfApiAccessLogMapper infApiAccessLogMapper;
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateApiAccessLogAsync() throws Exception {
|
||||
ApiAccessLogCreateDTO createDTO = RandomUtils.randomPojo(
|
||||
ApiAccessLogCreateDTO.class,
|
||||
dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue())
|
||||
);
|
||||
|
||||
// 执行service方法
|
||||
Future<Boolean> future = infApiAccessLogServiceImpl.createApiAccessLogAsync(createDTO);
|
||||
|
||||
// 等异步执行完
|
||||
future.get();
|
||||
|
||||
InfApiAccessLogDO infApiAccessLogDO = infApiAccessLogMapper.selectOne(null);
|
||||
// 断言
|
||||
assertNotNull(infApiAccessLogDO);
|
||||
// 断言,忽略基本字段
|
||||
assertPojoEquals(createDTO, infApiAccessLogDO);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetApiAccessLogPage() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "ruoyi-test";
|
||||
String requestUrl = "foo";
|
||||
Date beginTime = buildTime(2021, 3, 13);
|
||||
int duration = 1000;
|
||||
int resultCode = GlobalErrorCodeConstants.SUCCESS.getCode();
|
||||
|
||||
InfApiAccessLogDO infApiAccessLogDO = RandomUtils.randomPojo(InfApiAccessLogDO.class, dto -> {
|
||||
dto.setUserId(userId);
|
||||
dto.setUserType(userType);
|
||||
dto.setApplicationName(applicationName);
|
||||
dto.setRequestUrl(requestUrl);
|
||||
dto.setBeginTime(beginTime);
|
||||
dto.setDuration(duration);
|
||||
dto.setResultCode(resultCode);
|
||||
});
|
||||
infApiAccessLogMapper.insert(infApiAccessLogDO);
|
||||
|
||||
// 下面几个都是不匹配的数据
|
||||
// userId 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setBeginTime(buildTime(2021, 2, 6))));
|
||||
// duration 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setDuration(100)));
|
||||
// resultCode 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setResultCode(2)));
|
||||
|
||||
// 构造调用参数
|
||||
InfApiAccessLogPageReqVO reqVO = new InfApiAccessLogPageReqVO();
|
||||
reqVO.setUserId(userId);
|
||||
reqVO.setUserType(userType);
|
||||
reqVO.setApplicationName(applicationName);
|
||||
reqVO.setRequestUrl(requestUrl);
|
||||
reqVO.setBeginBeginTime(buildTime(2021, 3, 12));
|
||||
reqVO.setEndBeginTime(buildTime(2021, 3, 14));
|
||||
reqVO.setDuration(duration);
|
||||
reqVO.setResultCode(resultCode);
|
||||
|
||||
// 调用service方法
|
||||
PageResult<InfApiAccessLogDO> pageResult = infApiAccessLogServiceImpl.getApiAccessLogPage(reqVO);
|
||||
|
||||
// 断言,只查到了一条符合条件的
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(infApiAccessLogDO, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetApiAccessLogList() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "ruoyi-test";
|
||||
String requestUrl = "foo";
|
||||
Date beginTime = buildTime(2021, 3, 13);
|
||||
int duration = 1000;
|
||||
int resultCode = GlobalErrorCodeConstants.SUCCESS.getCode();
|
||||
|
||||
InfApiAccessLogDO infApiAccessLogDO = RandomUtils.randomPojo(InfApiAccessLogDO.class, dto -> {
|
||||
dto.setUserId(userId);
|
||||
dto.setUserType(userType);
|
||||
dto.setApplicationName(applicationName);
|
||||
dto.setRequestUrl(requestUrl);
|
||||
dto.setBeginTime(beginTime);
|
||||
dto.setDuration(duration);
|
||||
dto.setResultCode(resultCode);
|
||||
});
|
||||
infApiAccessLogMapper.insert(infApiAccessLogDO);
|
||||
|
||||
// 下面几个都是不匹配的数据
|
||||
// userId 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setBeginTime(buildTime(2021, 2, 6))));
|
||||
// duration 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setDuration(100)));
|
||||
// resultCode 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setResultCode(2)));
|
||||
|
||||
// 构造调用参数
|
||||
InfApiAccessLogExportReqVO reqVO = new InfApiAccessLogExportReqVO();
|
||||
reqVO.setUserId(userId);
|
||||
reqVO.setUserType(userType);
|
||||
reqVO.setApplicationName(applicationName);
|
||||
reqVO.setRequestUrl(requestUrl);
|
||||
reqVO.setBeginBeginTime(buildTime(2021, 3, 12));
|
||||
reqVO.setEndBeginTime(buildTime(2021, 3, 14));
|
||||
reqVO.setDuration(duration);
|
||||
reqVO.setResultCode(resultCode);
|
||||
|
||||
// 调用service方法
|
||||
List<InfApiAccessLogDO> list = infApiAccessLogServiceImpl.getApiAccessLogList(reqVO);
|
||||
|
||||
// 断言,只查到了一条符合条件的
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(infApiAccessLogDO, list.get(0));
|
||||
}
|
||||
}
|
@@ -0,0 +1,207 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.logger;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.logger.apilog.core.service.dto.ApiErrorLogCreateDTO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.mysql.logger.InfApiErrorLogMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum;
|
||||
import cn.iocoder.dashboard.modules.infra.service.logger.impl.InfApiErrorLogServiceImpl;
|
||||
import cn.iocoder.dashboard.util.RandomUtils;
|
||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_NOT_FOUND;
|
||||
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_PROCESSED;
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* {@link InfApiErrorLogServiceImpl} 单元测试
|
||||
*/
|
||||
@Import(InfApiErrorLogServiceImpl.class)
|
||||
public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfApiErrorLogService infApiErrorLogServiceImpl;
|
||||
|
||||
@Resource
|
||||
private InfApiErrorLogMapper infApiErrorLogMapper;
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateApiErrorLogAsync() throws Exception {
|
||||
ApiErrorLogCreateDTO createDTO = RandomUtils.randomPojo(
|
||||
ApiErrorLogCreateDTO.class,
|
||||
dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue())
|
||||
);
|
||||
|
||||
// 执行service方法
|
||||
Future<Boolean> future = infApiErrorLogServiceImpl.createApiErrorLogAsync(createDTO);
|
||||
|
||||
// 等异步执行完
|
||||
future.get();
|
||||
|
||||
InfApiErrorLogDO infApiErrorLogDO = infApiErrorLogMapper.selectOne(null);
|
||||
// 断言
|
||||
assertNotNull(infApiErrorLogDO);
|
||||
// 断言,忽略基本字段
|
||||
assertPojoEquals(createDTO, infApiErrorLogDO);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetApiErrorLogPage() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "ruoyi-test";
|
||||
String requestUrl = "foo";
|
||||
Date beginTime = buildTime(2021, 3, 13);
|
||||
int progressStatus = InfApiErrorLogProcessStatusEnum.INIT.getStatus();
|
||||
|
||||
InfApiErrorLogDO infApiErrorLogDO = RandomUtils.randomPojo(InfApiErrorLogDO.class, logDO -> {
|
||||
logDO.setUserId(userId);
|
||||
logDO.setUserType(userType);
|
||||
logDO.setApplicationName(applicationName);
|
||||
logDO.setRequestUrl(requestUrl);
|
||||
logDO.setExceptionTime(beginTime);
|
||||
logDO.setProcessStatus(progressStatus);
|
||||
});
|
||||
infApiErrorLogMapper.insert(infApiErrorLogDO);
|
||||
|
||||
// 下面几个都是不匹配的数据
|
||||
// userId 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setExceptionTime(buildTime(2021, 2, 6))));
|
||||
// progressStatus 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setProcessStatus(InfApiErrorLogProcessStatusEnum.DONE.getStatus())));
|
||||
|
||||
// 构造调用参数
|
||||
InfApiErrorLogPageReqVO reqVO = new InfApiErrorLogPageReqVO();
|
||||
reqVO.setUserId(userId);
|
||||
reqVO.setUserType(userType);
|
||||
reqVO.setApplicationName(applicationName);
|
||||
reqVO.setRequestUrl(requestUrl);
|
||||
reqVO.setBeginExceptionTime(buildTime(2021, 3, 12));
|
||||
reqVO.setEndExceptionTime(buildTime(2021, 3, 14));
|
||||
reqVO.setProcessStatus(progressStatus);
|
||||
|
||||
// 调用service方法
|
||||
PageResult<InfApiErrorLogDO> pageResult = infApiErrorLogServiceImpl.getApiErrorLogPage(reqVO);
|
||||
|
||||
// 断言,只查到了一条符合条件的
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(infApiErrorLogDO, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetApiErrorLogList() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "ruoyi-test";
|
||||
String requestUrl = "foo";
|
||||
Date beginTime = buildTime(2021, 3, 13);
|
||||
int progressStatus = InfApiErrorLogProcessStatusEnum.INIT.getStatus();
|
||||
|
||||
InfApiErrorLogDO infApiErrorLogDO = RandomUtils.randomPojo(InfApiErrorLogDO.class, logDO -> {
|
||||
logDO.setUserId(userId);
|
||||
logDO.setUserType(userType);
|
||||
logDO.setApplicationName(applicationName);
|
||||
logDO.setRequestUrl(requestUrl);
|
||||
logDO.setExceptionTime(beginTime);
|
||||
logDO.setProcessStatus(progressStatus);
|
||||
});
|
||||
infApiErrorLogMapper.insert(infApiErrorLogDO);
|
||||
|
||||
// 下面几个都是不匹配的数据
|
||||
// userId 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setExceptionTime(buildTime(2021, 2, 6))));
|
||||
// progressStatus 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.clone(infApiErrorLogDO, logDO -> logDO.setProcessStatus(InfApiErrorLogProcessStatusEnum.DONE.getStatus())));
|
||||
|
||||
// 构造调用参数
|
||||
InfApiErrorLogExportReqVO reqVO = new InfApiErrorLogExportReqVO();
|
||||
reqVO.setUserId(userId);
|
||||
reqVO.setUserType(userType);
|
||||
reqVO.setApplicationName(applicationName);
|
||||
reqVO.setRequestUrl(requestUrl);
|
||||
reqVO.setBeginExceptionTime(buildTime(2021, 3, 12));
|
||||
reqVO.setEndExceptionTime(buildTime(2021, 3, 14));
|
||||
reqVO.setProcessStatus(progressStatus);
|
||||
|
||||
// 调用service方法
|
||||
List<InfApiErrorLogDO> list = infApiErrorLogServiceImpl.getApiErrorLogList(reqVO);
|
||||
|
||||
// 断言,只查到了一条符合条件的
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(infApiErrorLogDO, list.get(0));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUpdateApiErrorLogProcess() {
|
||||
// 先构造两条数据,第一条用于抛出异常,第二条用于正常的执行update操作
|
||||
Long processUserId = 2233L;
|
||||
|
||||
InfApiErrorLogDO first = RandomUtils.randomPojo(InfApiErrorLogDO.class, logDO -> {
|
||||
logDO.setProcessUserId(processUserId);
|
||||
logDO.setUserType(UserTypeEnum.ADMIN.getValue());
|
||||
logDO.setProcessStatus(InfApiErrorLogProcessStatusEnum.DONE.getStatus());
|
||||
});
|
||||
infApiErrorLogMapper.insert(first);
|
||||
|
||||
InfApiErrorLogDO second = RandomUtils.randomPojo(InfApiErrorLogDO.class, logDO -> {
|
||||
logDO.setProcessUserId(1122L);
|
||||
logDO.setUserType(UserTypeEnum.ADMIN.getValue());
|
||||
logDO.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus());
|
||||
});
|
||||
infApiErrorLogMapper.insert(second);
|
||||
|
||||
Long firstId = first.getId();
|
||||
Long secondId = second.getId();
|
||||
|
||||
// 执行正常的 update 操作
|
||||
infApiErrorLogServiceImpl.updateApiErrorLogProcess(secondId, InfApiErrorLogProcessStatusEnum.DONE.getStatus(), processUserId);
|
||||
InfApiErrorLogDO secondSelect = infApiErrorLogMapper.selectOne("id", secondId);
|
||||
|
||||
// id 为 0 查询不到,应该抛出异常 API_ERROR_LOG_NOT_FOUND
|
||||
assertServiceException(() -> infApiErrorLogServiceImpl.updateApiErrorLogProcess(0L, InfApiErrorLogProcessStatusEnum.DONE.getStatus(), processUserId), API_ERROR_LOG_NOT_FOUND);
|
||||
// id 为 first 的 progressStatus 为 DONE ,应该抛出 API_ERROR_LOG_PROCESSED
|
||||
assertServiceException(() -> infApiErrorLogServiceImpl.updateApiErrorLogProcess(firstId, InfApiErrorLogProcessStatusEnum.DONE.getStatus(), processUserId), API_ERROR_LOG_PROCESSED);
|
||||
// 验证 progressStatus 是否修改成功
|
||||
assertEquals(InfApiErrorLogProcessStatusEnum.DONE.getStatus(), secondSelect.getProcessStatus());
|
||||
// 验证 progressUserId 是否修改成功
|
||||
assertEquals(processUserId, secondSelect.getProcessUserId());
|
||||
}
|
||||
}
|
@@ -55,7 +55,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest {
|
||||
String username = randomString();
|
||||
// mock 方法
|
||||
SysUserDO user = randomUserDO(o -> o.setUsername(username));
|
||||
when(userService.getUserByUserName(eq(username))).thenReturn(user);
|
||||
when(userService.getUserByUsername(eq(username))).thenReturn(user);
|
||||
|
||||
// 调用
|
||||
LoginUser loginUser = (LoginUser) authService.loadUserByUsername(username);
|
||||
|
@@ -2,7 +2,6 @@ package cn.iocoder.dashboard.modules.system.service.auth;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.iocoder.dashboard.BaseDbAndRedisUnitTest;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.dashboard.framework.security.config.SecurityProperties;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.auth.SysUserSessionDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.auth.SysUserSessionMapper;
|
||||
@@ -32,24 +31,24 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
* @version 1.0
|
||||
* @since <pre>3月 8, 2021</pre>
|
||||
*/
|
||||
@Import(
|
||||
SysUserSessionServiceImpl.class)
|
||||
@Import(SysUserSessionServiceImpl.class)
|
||||
public class SysUserSessionServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
|
||||
@Resource
|
||||
SysUserSessionServiceImpl sysUserSessionService;
|
||||
private SysUserSessionServiceImpl sysUserSessionService;
|
||||
@Resource
|
||||
SysUserSessionMapper sysUserSessionMapper;
|
||||
private SysUserSessionMapper sysUserSessionMapper;
|
||||
|
||||
@MockBean
|
||||
SecurityProperties securityProperties;
|
||||
private SecurityProperties securityProperties;
|
||||
@MockBean
|
||||
SysDeptServiceImpl sysDeptService;
|
||||
private SysDeptServiceImpl sysDeptService;
|
||||
@MockBean
|
||||
SysUserServiceImpl sysUserService;
|
||||
private SysUserServiceImpl sysUserService;
|
||||
@MockBean
|
||||
SysLoginLogServiceImpl sysLoginLogService;
|
||||
private SysLoginLogServiceImpl sysLoginLogService;
|
||||
@MockBean
|
||||
SysLoginUserRedisDAO sysLoginUserRedisDAO;
|
||||
private SysLoginUserRedisDAO sysLoginUserRedisDAO;
|
||||
|
||||
@Test
|
||||
public void testClearSessionTimeout_success() throws Exception {
|
||||
@@ -75,4 +74,4 @@ public class SysUserSessionServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
AssertUtils.assertPojoEquals(sessionDO, userSessionDOS.get(0), "updateTime");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,66 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.common;
|
||||
|
||||
import cn.iocoder.dashboard.BaseRedisUnitTest;
|
||||
import cn.iocoder.dashboard.framework.captcha.config.CaptchaProperties;
|
||||
import cn.iocoder.dashboard.modules.system.controller.common.vo.SysCaptchaImageRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.redis.common.SysCaptchaRedisDAO;
|
||||
import cn.iocoder.dashboard.modules.system.service.common.impl.SysCaptchaServiceImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.dashboard.util.RandomUtils.randomString;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@Import({SysCaptchaServiceImpl.class, CaptchaProperties.class, SysCaptchaRedisDAO.class})
|
||||
public class SysCaptchaServiceTest extends BaseRedisUnitTest {
|
||||
|
||||
@Resource
|
||||
private SysCaptchaServiceImpl captchaService;
|
||||
|
||||
@Resource
|
||||
private SysCaptchaRedisDAO captchaRedisDAO;
|
||||
@Resource
|
||||
private CaptchaProperties captchaProperties;
|
||||
|
||||
@Test
|
||||
public void testGetCaptchaImage() {
|
||||
// 调用
|
||||
SysCaptchaImageRespVO respVO = captchaService.getCaptchaImage();
|
||||
// 断言
|
||||
assertNotNull(respVO.getUuid());
|
||||
assertNotNull(respVO.getImg());
|
||||
String captchaCode = captchaRedisDAO.get(respVO.getUuid());
|
||||
assertNotNull(captchaCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCaptchaCode() {
|
||||
// 准备参数
|
||||
String uuid = randomString();
|
||||
String code = randomString();
|
||||
// mock 数据
|
||||
captchaRedisDAO.set(uuid, code, captchaProperties.getTimeout());
|
||||
|
||||
// 调用
|
||||
String resultCode = captchaService.getCaptchaCode(uuid);
|
||||
// 断言
|
||||
assertEquals(code, resultCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCaptchaCode() {
|
||||
// 准备参数
|
||||
String uuid = randomString();
|
||||
String code = randomString();
|
||||
// mock 数据
|
||||
captchaRedisDAO.set(uuid, code, captchaProperties.getTimeout());
|
||||
|
||||
// 调用
|
||||
captchaService.deleteCaptchaCode(uuid);
|
||||
// 断言
|
||||
assertNull(captchaRedisDAO.get(uuid));
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user