多模块重构 5:infra 模块的初始化
This commit is contained in:
@@ -1,105 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.config;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.*;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService;
|
||||
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.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_SENSITIVE;
|
||||
|
||||
@Api(tags = "参数配置")
|
||||
@RestController
|
||||
@RequestMapping("/infra/config")
|
||||
@Validated
|
||||
public class InfConfigController {
|
||||
|
||||
@Resource
|
||||
private InfConfigService configService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建参数配置")
|
||||
@PreAuthorize("@ss.hasPermission('infra:config:create')")
|
||||
public CommonResult<Long> createConfig(@Valid @RequestBody InfConfigCreateReqVO reqVO) {
|
||||
return success(configService.createConfig(reqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("修改参数配置")
|
||||
@PreAuthorize("@ss.hasPermission('infra:config:update')")
|
||||
public CommonResult<Boolean> updateConfig(@Valid @RequestBody InfConfigUpdateReqVO reqVO) {
|
||||
configService.updateConfig(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除参数配置")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('infra:config:delete')")
|
||||
public CommonResult<Boolean> deleteConfig(@RequestParam("id") Long id) {
|
||||
configService.deleteConfig(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/get")
|
||||
@ApiOperation("获得参数配置")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('infra:config:query')")
|
||||
public CommonResult<InfConfigRespVO> getConfig(@RequestParam("id") Long id) {
|
||||
return success(InfConfigConvert.INSTANCE.convert(configService.getConfig(id)));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/get-value-by-key")
|
||||
@ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端")
|
||||
@ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class)
|
||||
public CommonResult<String> getConfigKey(@RequestParam("key") String key) {
|
||||
InfConfigDO config = configService.getConfigByKey(key);
|
||||
if (config == null) {
|
||||
return null;
|
||||
}
|
||||
if (config.getSensitive()) {
|
||||
throw exception(CONFIG_GET_VALUE_ERROR_IF_SENSITIVE);
|
||||
}
|
||||
return success(config.getValue());
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获取参数配置分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:config:query')")
|
||||
public CommonResult<PageResult<InfConfigRespVO>> getConfigPage(@Valid InfConfigPageReqVO reqVO) {
|
||||
PageResult<InfConfigDO> page = configService.getConfigPage(reqVO);
|
||||
return success(InfConfigConvert.INSTANCE.convertPage(page));
|
||||
}
|
||||
|
||||
@GetMapping("/export")
|
||||
@ApiOperation("导出参数配置")
|
||||
@PreAuthorize("@ss.hasPermission('infra:config:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportSysConfig(@Valid InfConfigExportReqVO reqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<InfConfigDO> list = configService.getConfigList(reqVO);
|
||||
// 拼接数据
|
||||
List<InfConfigExcelVO> datas = InfConfigConvert.INSTANCE.convertList(list);
|
||||
// 输出
|
||||
ExcelUtils.write(response, "参数配置.xls", "数据", InfConfigExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* 参数配置 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class InfConfigBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "参数分组", required = true, example = "biz")
|
||||
@NotEmpty(message = "参数分组不能为空")
|
||||
@Size(max = 50, message = "参数名称不能超过50个字符")
|
||||
private String group;
|
||||
|
||||
@ApiModelProperty(value = "参数名称", required = true, example = "数据库名")
|
||||
@NotBlank(message = "参数名称不能为空")
|
||||
@Size(max = 100, message = "参数名称不能超过100个字符")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "参数键值", required = true, example = "1024")
|
||||
@NotBlank(message = "参数键值不能为空")
|
||||
@Size(max = 500, message = "参数键值长度不能超过500个字符")
|
||||
private String value;
|
||||
|
||||
@ApiModelProperty(value = "是否敏感", required = true, example = "true")
|
||||
@NotNull(message = "是否敏感不能为空")
|
||||
private Boolean sensitive;
|
||||
|
||||
@ApiModelProperty(value = "备注", example = "备注一下很帅气!")
|
||||
private String remark;
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@ApiModel("参数配置创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class InfConfigCreateReqVO extends InfConfigBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "参数键名", required = true, example = "yunai.db.username")
|
||||
@NotBlank(message = "参数键名长度不能为空")
|
||||
@Size(max = 100, message = "参数键名长度不能超过100个字符")
|
||||
private String key;
|
||||
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 参数配置 Excel 导出响应 VO
|
||||
*/
|
||||
@Data
|
||||
public class InfConfigExcelVO {
|
||||
|
||||
@ExcelProperty("参数配置序号")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("参数键名")
|
||||
private String key;
|
||||
|
||||
@ExcelProperty("参数分组")
|
||||
private String group;
|
||||
|
||||
@ExcelProperty("参数名称")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty("参数键值")
|
||||
private String value;
|
||||
|
||||
@ExcelProperty(value = "参数类型", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.CONFIG_TYPE)
|
||||
private Integer type;
|
||||
|
||||
@ExcelProperty(value = "是否敏感", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
|
||||
private Boolean sensitive;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("参数配置导出 Request VO")
|
||||
@Data
|
||||
public class InfConfigExportReqVO {
|
||||
|
||||
@ApiModelProperty(value = "参数名称", example = "模糊匹配")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "参数键名", example = "yunai.db.username", notes = "模糊匹配")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "开始时间", example = "2020-10-24 00:00:00")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date beginTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间", example = "2020-10-24 23:59:59")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.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.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("参数配置分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfConfigPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "参数名称", example = "模糊匹配")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "参数键名", example = "yunai.db.username", notes = "模糊匹配")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "开始时间", example = "2020-10-24 00:00:00")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date beginTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间", example = "2020-10-24 23:59:59")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("参数配置信息 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class InfConfigRespVO extends InfConfigBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "参数配置序号", required = true, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "参数键名", required = true, example = "yunai.db.username")
|
||||
@NotBlank(message = "参数键名长度不能为空")
|
||||
@Size(max = 100, message = "参数键名长度不能超过100个字符")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "参数类型", required = true, example = "1", notes = "参见 SysConfigTypeEnum 枚举")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
|
||||
private Date createTime;
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("参数配置创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfConfigUpdateReqVO extends InfConfigBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "参数配置序号", required = true, example = "1024")
|
||||
@NotNull(message = "参数配置编号不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
@@ -1,155 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.doc;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
|
||||
import cn.smallbun.screw.core.Configuration;
|
||||
import cn.smallbun.screw.core.engine.EngineConfig;
|
||||
import cn.smallbun.screw.core.engine.EngineFileType;
|
||||
import cn.smallbun.screw.core.engine.EngineTemplateType;
|
||||
import cn.smallbun.screw.core.execute.DocumentationExecute;
|
||||
import cn.smallbun.screw.core.process.ProcessConfig;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
|
||||
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.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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@Api(tags = "数据库文档")
|
||||
@RestController
|
||||
@RequestMapping("/infra/db-doc")
|
||||
public class InfDbDocController {
|
||||
|
||||
@Resource
|
||||
private DynamicDataSourceProperties dynamicDataSourceProperties;
|
||||
|
||||
private static final String FILE_OUTPUT_DIR = System.getProperty("java.io.tmpdir") + File.separator
|
||||
+ "db-doc";
|
||||
private static final String DOC_FILE_NAME = "数据库文档";
|
||||
private static final String DOC_VERSION = "1.0.0";
|
||||
private static final String DOC_DESCRIPTION = "文档描述";
|
||||
|
||||
@GetMapping("/export-html")
|
||||
@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(fileOutputType, fileName)) // 引擎配置
|
||||
.produceConfig(buildProcessConfig()) // 处理配置
|
||||
.build();
|
||||
|
||||
// 执行 screw,生成数据库文档
|
||||
new DocumentationExecute(config).execute();
|
||||
|
||||
return FILE_OUTPUT_DIR + File.separator + fileName + fileOutputType.getFileSuffix();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeleteFile(Boolean deleteFile, String filePath) {
|
||||
if (!deleteFile) {
|
||||
return;
|
||||
}
|
||||
FileUtil.del(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据源
|
||||
*/
|
||||
// TODO 芋艿:screw 暂时不支持 druid,尴尬
|
||||
private HikariDataSource buildDataSource() {
|
||||
// 获得 DataSource 数据源,目前只支持首个
|
||||
String primary = dynamicDataSourceProperties.getPrimary();
|
||||
DataSourceProperty dataSourceProperty = dynamicDataSourceProperties.getDatasource().get(primary);
|
||||
// 创建 HikariConfig 配置类
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
hikariConfig.setJdbcUrl(dataSourceProperty.getUrl());
|
||||
hikariConfig.setUsername(dataSourceProperty.getUsername());
|
||||
hikariConfig.setPassword(dataSourceProperty.getPassword());
|
||||
hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息
|
||||
// 创建数据源
|
||||
return new HikariDataSource(hikariConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 screw 的引擎配置
|
||||
*/
|
||||
private static EngineConfig buildEngineConfig(EngineFileType fileOutputType, String docFileName) {
|
||||
return EngineConfig.builder()
|
||||
.fileOutputDir(FILE_OUTPUT_DIR) // 生成文件路径
|
||||
.openOutputDir(false) // 打开目录
|
||||
.fileType(fileOutputType) // 文件类型
|
||||
.produceType(EngineTemplateType.freemarker) // 文件类型
|
||||
.fileName(docFileName) // 自定义文件名称
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 screw 的处理配置,一般可忽略
|
||||
* 指定生成逻辑、当存在指定表、指定表前缀、指定表后缀时,将生成指定表,其余表不生成、并跳过忽略表配置
|
||||
*/
|
||||
private static ProcessConfig buildProcessConfig() {
|
||||
return ProcessConfig.builder()
|
||||
.ignoreTablePrefix(Collections.singletonList("QRTZ_")) // 忽略表前缀
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.file;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFileRespVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.file.InfFileConvert;
|
||||
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
|
||||
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
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.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Api(tags = "文件存储")
|
||||
@RestController
|
||||
@RequestMapping("/infra/file")
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class InfFileController {
|
||||
|
||||
@Resource
|
||||
private InfFileService fileService;
|
||||
@Resource
|
||||
private InfFileCoreService fileCoreService;
|
||||
|
||||
@PostMapping("/upload")
|
||||
@ApiOperation("上传文件")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "file", value = "文件附件", required = true, dataTypeClass = MultipartFile.class),
|
||||
@ApiImplicitParam(name = "path", value = "文件路径", example = "yudaoyuanma.png", dataTypeClass = String.class)
|
||||
})
|
||||
public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("path") String path) throws IOException {
|
||||
return success(fileCoreService.createFile(path, IoUtil.readBytes(file.getInputStream())));
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除文件")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
|
||||
@PreAuthorize("@ss.hasPermission('infra:file:delete')")
|
||||
public CommonResult<Boolean> deleteFile(@RequestParam("id") String id) {
|
||||
fileCoreService.deleteFile(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{path}")
|
||||
@ApiOperation("下载文件")
|
||||
@ApiImplicitParam(name = "path", value = "文件附件", required = true, dataTypeClass = MultipartFile.class)
|
||||
public void getFile(HttpServletResponse response, @PathVariable("path") String path) throws IOException {
|
||||
TenantContextHolder.setNullTenantId();
|
||||
InfFileDO file = fileCoreService.getFile(path);
|
||||
if (file == null) {
|
||||
log.warn("[getFile][path({}) 文件不存在]", path);
|
||||
response.setStatus(HttpStatus.NOT_FOUND.value());
|
||||
return;
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.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.yudao.framework.common.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;
|
||||
|
||||
}
|
@@ -1,145 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.framework.quartz.core.util.CronUtils;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.*;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.job.InfJobConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.job.InfJobService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.quartz.SchedulerException;
|
||||
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.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "定时任务")
|
||||
@RestController
|
||||
@RequestMapping("/infra/job")
|
||||
@Validated
|
||||
public class InfJobController {
|
||||
|
||||
@Resource
|
||||
private InfJobService jobService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建定时任务")
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:create')")
|
||||
public CommonResult<Long> createJob(@Valid @RequestBody InfJobCreateReqVO createReqVO)
|
||||
throws SchedulerException {
|
||||
return success(jobService.createJob(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("更新定时任务")
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:update')")
|
||||
public CommonResult<Boolean> updateJob(@Valid @RequestBody InfJobUpdateReqVO updateReqVO)
|
||||
throws SchedulerException {
|
||||
jobService.updateJob(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-status")
|
||||
@ApiOperation("更新定时任务的状态")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class),
|
||||
@ApiImplicitParam(name = "status", value = "状态", required = true, example = "1", dataTypeClass = Integer.class),
|
||||
})
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:update')")
|
||||
public CommonResult<Boolean> updateJobStatus(@RequestParam(value = "id") Long id, @RequestParam("status") Integer status)
|
||||
throws SchedulerException {
|
||||
jobService.updateJobStatus(id, status);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除定时任务")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:delete')")
|
||||
public CommonResult<Boolean> deleteJob(@RequestParam("id") Long id)
|
||||
throws SchedulerException {
|
||||
jobService.deleteJob(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/trigger")
|
||||
@ApiOperation("触发定时任务")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:trigger')")
|
||||
public CommonResult<Boolean> triggerJob(@RequestParam("id") Long id) throws SchedulerException {
|
||||
jobService.triggerJob(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得定时任务")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:query')")
|
||||
public CommonResult<InfJobRespVO> getJob(@RequestParam("id") Long id) {
|
||||
InfJobDO job = jobService.getJob(id);
|
||||
return success(InfJobConvert.INSTANCE.convert(job));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得定时任务列表")
|
||||
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, dataTypeClass = List.class)
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:query')")
|
||||
public CommonResult<List<InfJobRespVO>> getJobList(@RequestParam("ids") Collection<Long> ids) {
|
||||
List<InfJobDO> list = jobService.getJobList(ids);
|
||||
return success(InfJobConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得定时任务分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:query')")
|
||||
public CommonResult<PageResult<InfJobRespVO>> getJobPage(@Valid InfJobPageReqVO pageVO) {
|
||||
PageResult<InfJobDO> pageResult = jobService.getJobPage(pageVO);
|
||||
return success(InfJobConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@ApiOperation("导出定时任务 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportJobExcel(@Valid InfJobExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<InfJobDO> list = jobService.getJobList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<InfJobExcelVO> datas = InfJobConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "定时任务.xls", "数据", InfJobExcelVO.class, datas);
|
||||
}
|
||||
|
||||
@GetMapping("/get_next_times")
|
||||
@ApiOperation("获得定时任务的下 n 次执行时间")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class),
|
||||
@ApiImplicitParam(name = "count", value = "数量", example = "5", dataTypeClass = Long.class)
|
||||
})
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:query')")
|
||||
public CommonResult<List<Date>> getJobNextTimes(@RequestParam("id") Long id,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "5") Integer count) {
|
||||
InfJobDO job = jobService.getJob(id);
|
||||
if (job == null) {
|
||||
return success(Collections.emptyList());
|
||||
}
|
||||
return success(CronUtils.getNextTimes(job.getCronExpression(), count));
|
||||
}
|
||||
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogExcelVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.job.InfJobLogConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobLogDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.job.InfJobLogService;
|
||||
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.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.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "定时任务日志")
|
||||
@RestController
|
||||
@RequestMapping("/infra/job-log")
|
||||
@Validated
|
||||
public class InfJobLogController {
|
||||
|
||||
@Resource
|
||||
private InfJobLogService jobLogService;
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得定时任务日志")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:query')")
|
||||
public CommonResult<InfJobLogRespVO> getJobLog(@RequestParam("id") Long id) {
|
||||
InfJobLogDO jobLog = jobLogService.getJobLog(id);
|
||||
return success(InfJobLogConvert.INSTANCE.convert(jobLog));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得定时任务日志列表")
|
||||
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:query')")
|
||||
public CommonResult<List<InfJobLogRespVO>> getJobLogList(@RequestParam("ids") Collection<Long> ids) {
|
||||
List<InfJobLogDO> list = jobLogService.getJobLogList(ids);
|
||||
return success(InfJobLogConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得定时任务日志分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:query')")
|
||||
public CommonResult<PageResult<InfJobLogRespVO>> getJobLogPage(@Valid InfJobLogPageReqVO pageVO) {
|
||||
PageResult<InfJobLogDO> pageResult = jobLogService.getJobLogPage(pageVO);
|
||||
return success(InfJobLogConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@ApiOperation("导出定时任务日志 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('infra:job:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportJobLogExcel(@Valid InfJobLogExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<InfJobLogDO> list = jobLogService.getJobLogList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<InfJobLogExcelVO> datas = InfJobLogConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "任务日志.xls", "数据", InfJobLogExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 定时任务 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class InfJobBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "任务名称", required = true, example = "测试任务")
|
||||
@NotNull(message = "任务名称不能为空")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "处理器的参数", example = "yudao")
|
||||
private String handlerParam;
|
||||
|
||||
@ApiModelProperty(value = "CRON 表达式", required = true, example = "0/10 * * * * ? *")
|
||||
@NotNull(message = "CRON 表达式不能为空")
|
||||
private String cronExpression;
|
||||
|
||||
@ApiModelProperty(value = "重试次数", required = true, example = "3")
|
||||
@NotNull(message = "重试次数不能为空")
|
||||
private Integer retryCount;
|
||||
|
||||
@ApiModelProperty(value = "重试间隔", required = true, example = "1000")
|
||||
@NotNull(message = "重试间隔不能为空")
|
||||
private Integer retryInterval;
|
||||
|
||||
@ApiModelProperty(value = "监控超时时间", example = "1000")
|
||||
private Integer monitorTimeout;
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("定时任务创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfJobCreateReqVO extends InfJobBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "处理器的名字", required = true, example = "sysUserSessionTimeoutJob")
|
||||
@NotNull(message = "处理器的名字不能为空")
|
||||
private String handlerName;
|
||||
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.InfDictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 定时任务 Excel VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class InfJobExcelVO {
|
||||
|
||||
@ExcelProperty("任务编号")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("任务名称")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty(value = "任务状态", converter = DictConvert.class)
|
||||
@DictFormat(InfDictTypeConstants.JOB_STATUS)
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty("处理器的名字")
|
||||
private String handlerName;
|
||||
|
||||
@ExcelProperty("处理器的参数")
|
||||
private String handlerParam;
|
||||
|
||||
@ExcelProperty("CRON 表达式")
|
||||
private String cronExpression;
|
||||
|
||||
@ExcelProperty("最后一次执行的开始时间")
|
||||
private Date executeBeginTime;
|
||||
|
||||
@ExcelProperty("最后一次执行的结束时间")
|
||||
private Date executeEndTime;
|
||||
|
||||
@ExcelProperty("上一次触发时间")
|
||||
private Date firePrevTime;
|
||||
|
||||
@ExcelProperty("下一次触发时间")
|
||||
private Date fireNextTime;
|
||||
|
||||
@ExcelProperty("监控超时时间")
|
||||
private Integer monitorTimeout;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel(value = "定时任务 Excel 导出 Request VO", description = "参数和 InfJobPageReqVO 是一致的")
|
||||
@Data
|
||||
public class InfJobExportReqVO {
|
||||
|
||||
@ApiModelProperty(value = "任务名称", example = "测试任务", notes = "模糊匹配")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "任务状态", example = "1", notes = "参见 InfJobStatusEnum 枚举")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "处理器的名字", example = "sysUserSessionTimeoutJob", notes = "模糊匹配")
|
||||
private String handlerName;
|
||||
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@ApiModel("定时任务分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfJobPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "任务名称", example = "测试任务", notes = "模糊匹配")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "任务状态", example = "1", notes = "参见 InfJobStatusEnum 枚举")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "处理器的名字", example = "sysUserSessionTimeoutJob", notes = "模糊匹配")
|
||||
private String handlerName;
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("定时任务 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfJobRespVO extends InfJobBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "任务编号", required = true, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "任务状态", required = true, example = "1")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "处理器的名字", required = true, example = "sysUserSessionTimeoutJob")
|
||||
@NotNull(message = "处理器的名字不能为空")
|
||||
private String handlerName;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("定时任务更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfJobUpdateReqVO extends InfJobBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "任务编号", required = true, example = "1024")
|
||||
@NotNull(message = "任务编号不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
/**
|
||||
* 定时任务日志 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class InfJobLogBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "任务编号", required = true, example = "1024")
|
||||
@NotNull(message = "任务编号不能为空")
|
||||
private Long jobId;
|
||||
|
||||
@ApiModelProperty(value = "处理器的名字", required = true, example = "sysUserSessionTimeoutJob")
|
||||
@NotNull(message = "处理器的名字不能为空")
|
||||
private String handlerName;
|
||||
|
||||
@ApiModelProperty(value = "处理器的参数", example = "yudao")
|
||||
private String handlerParam;
|
||||
|
||||
@ApiModelProperty(value = "第几次执行", required = true, example = "1")
|
||||
@NotNull(message = "第几次执行不能为空")
|
||||
private Integer executeIndex;
|
||||
|
||||
@ApiModelProperty(value = "开始执行时间", required = true)
|
||||
@NotNull(message = "开始执行时间不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date beginTime;
|
||||
|
||||
@ApiModelProperty(value = "结束执行时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
|
||||
@ApiModelProperty(value = "执行时长", example = "123")
|
||||
private Integer duration;
|
||||
|
||||
@ApiModelProperty(value = "任务状态", required = true, example = "1", notes = "参见 InfJobLogStatusEnum 枚举")
|
||||
@NotNull(message = "任务状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "结果数据", example = "执行成功")
|
||||
private String result;
|
||||
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.InfDictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 定时任务 Excel VO
|
||||
*
|
||||
* @author 芋艿
|
||||
*/
|
||||
@Data
|
||||
public class InfJobLogExcelVO {
|
||||
|
||||
@ExcelProperty("日志编号")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("任务编号")
|
||||
private Long jobId;
|
||||
|
||||
@ExcelProperty("处理器的名字")
|
||||
private String handlerName;
|
||||
|
||||
@ExcelProperty("处理器的参数")
|
||||
private String handlerParam;
|
||||
|
||||
@ExcelProperty("第几次执行")
|
||||
private Integer executeIndex;
|
||||
|
||||
@ExcelProperty("开始执行时间")
|
||||
private Date beginTime;
|
||||
|
||||
@ExcelProperty("结束执行时间")
|
||||
private Date endTime;
|
||||
|
||||
@ExcelProperty("执行时长")
|
||||
private Integer duration;
|
||||
|
||||
@ExcelProperty(value = "任务状态", converter = DictConvert.class)
|
||||
@DictFormat(InfDictTypeConstants.JOB_STATUS)
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty("结果数据")
|
||||
private String result;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel(value = "定时任务 Excel 导出 Request VO", description = "参数和 InfJobLogPageReqVO 是一致的")
|
||||
@Data
|
||||
public class InfJobLogExportReqVO {
|
||||
|
||||
@ApiModelProperty(value = "任务编号", example = "10")
|
||||
private Long jobId;
|
||||
|
||||
@ApiModelProperty(value = "处理器的名字", notes = "模糊匹配")
|
||||
private String handlerName;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "开始执行时间")
|
||||
private Date beginTime;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "结束执行时间")
|
||||
private Date endTime;
|
||||
|
||||
@ApiModelProperty(value = "任务状态", notes = "参见 InfJobLogStatusEnum 枚举")
|
||||
private Integer status;
|
||||
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log;
|
||||
|
||||
import cn.iocoder.yudao.framework.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.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("定时任务日志分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfJobLogPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "任务编号", example = "10")
|
||||
private Long jobId;
|
||||
|
||||
@ApiModelProperty(value = "处理器的名字", notes = "模糊匹配")
|
||||
private String handlerName;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "开始执行时间")
|
||||
private Date beginTime;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "结束执行时间")
|
||||
private Date endTime;
|
||||
|
||||
@ApiModelProperty(value = "任务状态", notes = "参见 InfJobLogStatusEnum 枚举")
|
||||
private Integer status;
|
||||
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("定时任务日志 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfJobLogRespVO extends InfJobLogBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "日志编号", required = true, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExcelVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiAccessLogConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiAccessLogService;
|
||||
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;
|
||||
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.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Api(tags = "API 访问日志")
|
||||
@RestController
|
||||
@RequestMapping("/infra/api-access-log")
|
||||
@Validated
|
||||
public class InfApiAccessLogController {
|
||||
|
||||
@Resource
|
||||
private InfApiAccessLogService apiAccessLogService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得API 访问日志分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:api-access-log:query')")
|
||||
public CommonResult<PageResult<InfApiAccessLogRespVO>> getApiAccessLogPage(@Valid InfApiAccessLogPageReqVO pageVO) {
|
||||
PageResult<InfApiAccessLogDO> pageResult = apiAccessLogService.getApiAccessLogPage(pageVO);
|
||||
return success(InfApiAccessLogConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@ApiOperation("导出API 访问日志 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('infra:api-access-log:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportApiAccessLogExcel(@Valid InfApiAccessLogExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<InfApiAccessLogDO> list = apiAccessLogService.getApiAccessLogList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<InfApiAccessLogExcelVO> datas = InfApiAccessLogConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "API 访问日志.xls", "数据", InfApiAccessLogExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExcelVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.logger.InfApiErrorLogConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiErrorLogService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
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.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Api(tags = "API 错误日志")
|
||||
@RestController
|
||||
@RequestMapping("/infra/api-error-log")
|
||||
@Validated
|
||||
public class InfApiErrorLogController {
|
||||
|
||||
@Resource
|
||||
private InfApiErrorLogService apiErrorLogService;
|
||||
|
||||
@PutMapping("/update-status")
|
||||
@ApiOperation("更新 API 错误日志的状态")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class),
|
||||
@ApiImplicitParam(name = "processStatus", value = "处理状态", required = true, example = "1", dataTypeClass = Integer.class)
|
||||
})
|
||||
@PreAuthorize("@ss.hasPermission('infra:api-error-log:update-status')")
|
||||
public CommonResult<Boolean> updateApiErrorLogProcess(@RequestParam("id") Long id,
|
||||
@RequestParam("processStatus") Integer processStatus) {
|
||||
apiErrorLogService.updateApiErrorLogProcess(id, processStatus, getLoginUserId());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得 API 错误日志分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:api-error-log:query')")
|
||||
public CommonResult<PageResult<InfApiErrorLogRespVO>> getApiErrorLogPage(@Valid InfApiErrorLogPageReqVO pageVO) {
|
||||
PageResult<InfApiErrorLogDO> pageResult = apiErrorLogService.getApiErrorLogPage(pageVO);
|
||||
return success(InfApiErrorLogConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@ApiOperation("导出 API 错误日志 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('infra:api-error-log:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportApiErrorLogExcel(@Valid InfApiErrorLogExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<InfApiErrorLogDO> list = apiErrorLogService.getApiErrorLogList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<InfApiErrorLogExcelVO> datas = InfApiErrorLogConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "API 错误日志.xls", "数据", InfApiErrorLogExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
@@ -1,75 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
/**
|
||||
* API 访问日志 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class InfApiAccessLogBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "链路追踪编号", required = true, example = "66600cb6-7852-11eb-9439-0242ac130002")
|
||||
@NotNull(message = "链路追踪编号不能为空")
|
||||
private String traceId;
|
||||
|
||||
@ApiModelProperty(value = "用户编号", required = true, example = "666")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "用户类型", required = true, example = "2", notes = "参见 UserTypeEnum 枚举")
|
||||
@NotNull(message = "用户类型不能为空")
|
||||
private Integer userType;
|
||||
|
||||
@ApiModelProperty(value = "应用名", required = true, example = "dashboard")
|
||||
@NotNull(message = "应用名不能为空")
|
||||
private String applicationName;
|
||||
|
||||
@ApiModelProperty(value = "请求方法名", required = true, example = "GET")
|
||||
@NotNull(message = "请求方法名不能为空")
|
||||
private String requestMethod;
|
||||
|
||||
@ApiModelProperty(value = "请求地址", required = true, example = "/xxx/yyy")
|
||||
@NotNull(message = "请求地址不能为空")
|
||||
private String requestUrl;
|
||||
|
||||
@ApiModelProperty(value = "请求参数")
|
||||
private String requestParams;
|
||||
|
||||
@ApiModelProperty(value = "用户 IP", required = true, example = "127.0.0.1")
|
||||
@NotNull(message = "用户 IP不能为空")
|
||||
private String userIp;
|
||||
|
||||
@ApiModelProperty(value = "浏览器 UA", required = true, example = "Mozilla/5.0")
|
||||
@NotNull(message = "浏览器 UA不能为空")
|
||||
private String userAgent;
|
||||
|
||||
@ApiModelProperty(value = "开始请求时间", required = true)
|
||||
@NotNull(message = "开始请求时间不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date beginTime;
|
||||
|
||||
@ApiModelProperty(value = "结束请求时间", required = true)
|
||||
@NotNull(message = "结束请求时间不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endTime;
|
||||
|
||||
@ApiModelProperty(value = "执行时长", required = true, example = "100")
|
||||
@NotNull(message = "执行时长不能为空")
|
||||
private Integer duration;
|
||||
|
||||
@ApiModelProperty(value = "结果码", required = true, example = "0")
|
||||
@NotNull(message = "结果码不能为空")
|
||||
private Integer resultCode;
|
||||
|
||||
@ApiModelProperty(value = "结果提示", example = "芋道源码,牛逼!")
|
||||
private String resultMsg;
|
||||
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* API 访问日志 Excel VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class InfApiAccessLogExcelVO {
|
||||
|
||||
@ExcelProperty("日志主键")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("链路追踪编号")
|
||||
private String traceId;
|
||||
|
||||
@ExcelProperty("用户编号")
|
||||
private Long userId;
|
||||
|
||||
@ExcelProperty(value = "用户类型", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.USER_TYPE)
|
||||
private Integer userType;
|
||||
|
||||
@ExcelProperty("应用名")
|
||||
private String applicationName;
|
||||
|
||||
@ExcelProperty("请求方法名")
|
||||
private String requestMethod;
|
||||
|
||||
@ExcelProperty("请求地址")
|
||||
private String requestUrl;
|
||||
|
||||
@ExcelProperty("请求参数")
|
||||
private String requestParams;
|
||||
|
||||
@ExcelProperty("用户 IP")
|
||||
private String userIp;
|
||||
|
||||
@ExcelProperty("浏览器 UA")
|
||||
private String userAgent;
|
||||
|
||||
@ExcelProperty("开始请求时间")
|
||||
private Date beginTime;
|
||||
|
||||
@ExcelProperty("结束请求时间")
|
||||
private Date endTime;
|
||||
|
||||
@ExcelProperty("执行时长")
|
||||
private Integer duration;
|
||||
|
||||
@ExcelProperty("结果码")
|
||||
private Integer resultCode;
|
||||
|
||||
@ExcelProperty("结果提示")
|
||||
private String resultMsg;
|
||||
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel(value = "API 访问日志 Excel 导出 Request VO", description = "参数和 InfApiAccessLogPageReqVO 是一致的")
|
||||
@Data
|
||||
public class InfApiAccessLogExportReqVO {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", example = "666")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "用户类型", example = "2")
|
||||
private Integer userType;
|
||||
|
||||
@ApiModelProperty(value = "应用名", example = "dashboard")
|
||||
private String applicationName;
|
||||
|
||||
@ApiModelProperty(value = "请求地址", example = "/xxx/yyy", notes = "模糊匹配")
|
||||
private String requestUrl;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "开始开始请求时间")
|
||||
private Date beginBeginTime;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "结束开始请求时间")
|
||||
private Date endBeginTime;
|
||||
|
||||
@ApiModelProperty(value = "执行时长", example = "100", notes = "大于等于,单位:毫秒")
|
||||
private Integer duration;
|
||||
|
||||
@ApiModelProperty(value = "结果码", example = "0")
|
||||
private Integer resultCode;
|
||||
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog;
|
||||
|
||||
import cn.iocoder.yudao.framework.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.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("API 访问日志分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfApiAccessLogPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", example = "666")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "用户类型", example = "2")
|
||||
private Integer userType;
|
||||
|
||||
@ApiModelProperty(value = "应用名", example = "dashboard")
|
||||
private String applicationName;
|
||||
|
||||
@ApiModelProperty(value = "请求地址", example = "/xxx/yyy", notes = "模糊匹配")
|
||||
private String requestUrl;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "开始开始请求时间")
|
||||
private Date beginBeginTime;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "结束开始请求时间")
|
||||
private Date endBeginTime;
|
||||
|
||||
@ApiModelProperty(value = "执行时长", example = "100", notes = "大于等于,单位:毫秒")
|
||||
private Integer duration;
|
||||
|
||||
@ApiModelProperty(value = "结果码", example = "0")
|
||||
private Integer resultCode;
|
||||
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("API 访问日志 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfApiAccessLogRespVO extends InfApiAccessLogBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "日志主键", required = true, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
/**
|
||||
* API 错误日志 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class InfApiErrorLogBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "链路追踪编号", required = true, example = "66600cb6-7852-11eb-9439-0242ac130002")
|
||||
@NotNull(message = "链路追踪编号不能为空")
|
||||
private String traceId;
|
||||
|
||||
@ApiModelProperty(value = "用户编号", required = true, example = "666")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Integer userId;
|
||||
|
||||
@ApiModelProperty(value = "用户类型", required = true, example = "1")
|
||||
@NotNull(message = "用户类型不能为空")
|
||||
private Integer userType;
|
||||
|
||||
@ApiModelProperty(value = "应用名", required = true, example = "dashboard")
|
||||
@NotNull(message = "应用名不能为空")
|
||||
private String applicationName;
|
||||
|
||||
@ApiModelProperty(value = "请求方法名", required = true, example = "GET")
|
||||
@NotNull(message = "请求方法名不能为空")
|
||||
private String requestMethod;
|
||||
|
||||
@ApiModelProperty(value = "请求地址", required = true, example = "/xx/yy")
|
||||
@NotNull(message = "请求地址不能为空")
|
||||
private String requestUrl;
|
||||
|
||||
@ApiModelProperty(value = "请求参数", required = true)
|
||||
@NotNull(message = "请求参数不能为空")
|
||||
private String requestParams;
|
||||
|
||||
@ApiModelProperty(value = "用户 IP", required = true, example = "127.0.0.1")
|
||||
@NotNull(message = "用户 IP不能为空")
|
||||
private String userIp;
|
||||
|
||||
@ApiModelProperty(value = "浏览器 UA", required = true, example = "Mozilla/5.0")
|
||||
@NotNull(message = "浏览器 UA不能为空")
|
||||
private String userAgent;
|
||||
|
||||
@ApiModelProperty(value = "异常发生时间", required = true)
|
||||
@NotNull(message = "异常发生时间不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date exceptionTime;
|
||||
|
||||
@ApiModelProperty(value = "异常名", required = true)
|
||||
@NotNull(message = "异常名不能为空")
|
||||
private String exceptionName;
|
||||
|
||||
@ApiModelProperty(value = "异常导致的消息", required = true)
|
||||
@NotNull(message = "异常导致的消息不能为空")
|
||||
private String exceptionMessage;
|
||||
|
||||
@ApiModelProperty(value = "异常导致的根消息", required = true)
|
||||
@NotNull(message = "异常导致的根消息不能为空")
|
||||
private String exceptionRootCauseMessage;
|
||||
|
||||
@ApiModelProperty(value = "异常的栈轨迹", required = true)
|
||||
@NotNull(message = "异常的栈轨迹不能为空")
|
||||
private String exceptionStackTrace;
|
||||
|
||||
@ApiModelProperty(value = "异常发生的类全名", required = true)
|
||||
@NotNull(message = "异常发生的类全名不能为空")
|
||||
private String exceptionClassName;
|
||||
|
||||
@ApiModelProperty(value = "异常发生的类文件", required = true)
|
||||
@NotNull(message = "异常发生的类文件不能为空")
|
||||
private String exceptionFileName;
|
||||
|
||||
@ApiModelProperty(value = "异常发生的方法名", required = true)
|
||||
@NotNull(message = "异常发生的方法名不能为空")
|
||||
private String exceptionMethodName;
|
||||
|
||||
@ApiModelProperty(value = "异常发生的方法所在行", required = true)
|
||||
@NotNull(message = "异常发生的方法所在行不能为空")
|
||||
private Integer exceptionLineNumber;
|
||||
|
||||
@ApiModelProperty(value = "处理状态", required = true, example = "0")
|
||||
@NotNull(message = "处理状态不能为空")
|
||||
private Integer processStatus;
|
||||
|
||||
}
|
@@ -1,91 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.InfDictTypeConstants;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* API 错误日志 Excel VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class InfApiErrorLogExcelVO {
|
||||
|
||||
@ExcelProperty("编号")
|
||||
private Integer id;
|
||||
|
||||
@ExcelProperty("链路追踪编号")
|
||||
private String traceId;
|
||||
|
||||
@ExcelProperty("用户编号")
|
||||
private Integer userId;
|
||||
|
||||
@ExcelProperty(value = "用户类型", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.USER_TYPE)
|
||||
private Integer userType;
|
||||
|
||||
@ExcelProperty("应用名")
|
||||
private String applicationName;
|
||||
|
||||
@ExcelProperty("请求方法名")
|
||||
private String requestMethod;
|
||||
|
||||
@ExcelProperty("请求地址")
|
||||
private String requestUrl;
|
||||
|
||||
@ExcelProperty("请求参数")
|
||||
private String requestParams;
|
||||
|
||||
@ExcelProperty("用户 IP")
|
||||
private String userIp;
|
||||
|
||||
@ExcelProperty("浏览器 UA")
|
||||
private String userAgent;
|
||||
|
||||
@ExcelProperty("异常发生时间")
|
||||
private Date exceptionTime;
|
||||
|
||||
@ExcelProperty("异常名")
|
||||
private String exceptionName;
|
||||
|
||||
@ExcelProperty("异常导致的消息")
|
||||
private String exceptionMessage;
|
||||
|
||||
@ExcelProperty("异常导致的根消息")
|
||||
private String exceptionRootCauseMessage;
|
||||
|
||||
@ExcelProperty("异常的栈轨迹")
|
||||
private String exceptionStackTrace;
|
||||
|
||||
@ExcelProperty("异常发生的类全名")
|
||||
private String exceptionClassName;
|
||||
|
||||
@ExcelProperty("异常发生的类文件")
|
||||
private String exceptionFileName;
|
||||
|
||||
@ExcelProperty("异常发生的方法名")
|
||||
private String exceptionMethodName;
|
||||
|
||||
@ExcelProperty("异常发生的方法所在行")
|
||||
private Integer exceptionLineNumber;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ExcelProperty(value = "处理状态", converter = DictConvert.class)
|
||||
@DictFormat(InfDictTypeConstants.API_ERROR_LOG_PROCESS_STATUS)
|
||||
private Integer processStatus;
|
||||
|
||||
@ExcelProperty("处理时间")
|
||||
private Date processTime;
|
||||
|
||||
@ExcelProperty("处理用户编号")
|
||||
private Integer processUserId;
|
||||
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel(value = "API 错误日志 Excel 导出 Request VO", description = "参数和 InfApiErrorLogPageReqVO 是一致的")
|
||||
@Data
|
||||
public class InfApiErrorLogExportReqVO {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", example = "666")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "用户类型", example = "1")
|
||||
private Integer userType;
|
||||
|
||||
@ApiModelProperty(value = "应用名", example = "dashboard")
|
||||
private String applicationName;
|
||||
|
||||
@ApiModelProperty(value = "请求地址", example = "/xx/yy")
|
||||
private String requestUrl;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "开始异常发生时间")
|
||||
private Date beginExceptionTime;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "结束异常发生时间")
|
||||
private Date endExceptionTime;
|
||||
|
||||
@ApiModelProperty(value = "处理状态", example = "0")
|
||||
private Integer processStatus;
|
||||
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog;
|
||||
|
||||
import cn.iocoder.yudao.framework.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.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("API 错误日志分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfApiErrorLogPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", example = "666")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "用户类型", example = "1")
|
||||
private Integer userType;
|
||||
|
||||
@ApiModelProperty(value = "应用名", example = "dashboard")
|
||||
private String applicationName;
|
||||
|
||||
@ApiModelProperty(value = "请求地址", example = "/xx/yy")
|
||||
private String requestUrl;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "开始异常发生时间")
|
||||
private Date beginExceptionTime;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "结束异常发生时间")
|
||||
private Date endExceptionTime;
|
||||
|
||||
@ApiModelProperty(value = "处理状态", example = "0")
|
||||
private Integer processStatus;
|
||||
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("API 错误日志 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfApiErrorLogRespVO extends InfApiErrorLogBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1024")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "处理时间", required = true)
|
||||
private Date processTime;
|
||||
|
||||
@ApiModelProperty(value = "处理用户编号", example = "233")
|
||||
private Integer processUserId;
|
||||
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
### 请求 /infra/redis/get-monitor-info 接口 => 成功
|
||||
GET {{baseUrl}}/infra/redis/get-monitor-info
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
### 请求 /infra/redis/get-key-list 接口 => 成功
|
||||
GET {{baseUrl}}/infra/redis/get-key-list
|
||||
Authorization: Bearer {{token}}
|
@@ -1,55 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.redis;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.redis.core.RedisKeyDefine;
|
||||
import cn.iocoder.yudao.framework.redis.core.RedisKeyRegistry;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.redis.vo.InfRedisKeyRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.redis.vo.InfRedisMonitorRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.redis.RedisConvert;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.redis.connection.RedisServerCommands;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Api(tags = "Redis 监控")
|
||||
@RestController
|
||||
@RequestMapping("/infra/redis")
|
||||
public class RedisController {
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@GetMapping("/get-monitor-info")
|
||||
@ApiOperation("获得 Redis 监控信息")
|
||||
@PreAuthorize("@ss.hasPermission('infra:redis:get-monitor-info')")
|
||||
public CommonResult<InfRedisMonitorRespVO> getRedisMonitorInfo() {
|
||||
// 获得 Redis 统计信息
|
||||
Properties info = stringRedisTemplate.execute((RedisCallback<Properties>) RedisServerCommands::info);
|
||||
Long dbSize = stringRedisTemplate.execute(RedisServerCommands::dbSize);
|
||||
Properties commandStats = stringRedisTemplate.execute((
|
||||
RedisCallback<Properties>) connection -> connection.info("commandstats"));
|
||||
assert commandStats != null; // 断言,避免警告
|
||||
// 拼接结果返回
|
||||
return success(RedisConvert.INSTANCE.build(info, dbSize, commandStats));
|
||||
}
|
||||
|
||||
@GetMapping("/get-key-list")
|
||||
@ApiOperation("获得 Redis Key 列表")
|
||||
@PreAuthorize("@ss.hasPermission('infra:redis:get-key-list')")
|
||||
public CommonResult<List<InfRedisKeyRespVO>> getKeyList() {
|
||||
List<RedisKeyDefine> keyDefines = RedisKeyRegistry.list();
|
||||
return success(RedisConvert.INSTANCE.convertList(keyDefines));
|
||||
}
|
||||
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.redis.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.redis.core.RedisKeyDefine;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@ApiModel("Redis Key 信息 Response VO")
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class InfRedisKeyRespVO {
|
||||
|
||||
@ApiModelProperty(value = "login_user:%s", required = true, example = "String")
|
||||
private String keyTemplate;
|
||||
|
||||
@ApiModelProperty(value = "Key 类型的枚举", required = true, example = "String")
|
||||
private RedisKeyDefine.KeyTypeEnum keyType;
|
||||
|
||||
@ApiModelProperty(value = "Value 类型", required = true, example = "java.lang.String")
|
||||
private Class valueType;
|
||||
|
||||
@ApiModelProperty(value = "超时类型", required = true, example = "1")
|
||||
private RedisKeyDefine.TimeoutTypeEnum timeoutType;
|
||||
|
||||
@ApiModelProperty(value = "过期时间,单位:毫秒", required = true, example = "1024")
|
||||
private Duration timeout;
|
||||
|
||||
@ApiModelProperty(value = "备注", required = true, example = "啦啦啦啦~")
|
||||
private String memo;
|
||||
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.controller.redis.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
@ApiModel("Redis 监控信息 Response VO")
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class InfRedisMonitorRespVO {
|
||||
|
||||
@ApiModelProperty(value = "Redis info 指令结果", required = true, notes = "具体字段,查看 Redis 文档")
|
||||
private Properties info;
|
||||
|
||||
@ApiModelProperty(value = "Redis key 数量", required = true, example = "1024")
|
||||
private Long dbSize;
|
||||
|
||||
@ApiModelProperty(value = "CommandStat 数组", required = true)
|
||||
private List<CommandStat> commandStats;
|
||||
|
||||
@ApiModel("Redis 命令统计结果")
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public static class CommandStat {
|
||||
|
||||
@ApiModelProperty(value = "Redis 命令", required = true, example = "get")
|
||||
private String command;
|
||||
|
||||
@ApiModelProperty(value = "调用次数", required = true, example = "1024")
|
||||
private Integer calls;
|
||||
|
||||
@ApiModelProperty(value = "消耗 CPU 秒数", required = true, example = "666")
|
||||
private Long usec;
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.convert.config;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExcelVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface InfConfigConvert {
|
||||
|
||||
InfConfigConvert INSTANCE = Mappers.getMapper(InfConfigConvert.class);
|
||||
|
||||
PageResult<InfConfigRespVO> convertPage(PageResult<InfConfigDO> page);
|
||||
|
||||
InfConfigRespVO convert(InfConfigDO bean);
|
||||
|
||||
InfConfigDO convert(InfConfigCreateReqVO bean);
|
||||
|
||||
InfConfigDO convert(InfConfigUpdateReqVO bean);
|
||||
|
||||
List<InfConfigExcelVO> convertList(List<InfConfigDO> list);
|
||||
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.convert.file;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.controller.file.vo.InfFileRespVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
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);
|
||||
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.convert.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobExcelVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobUpdateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定时任务 Convert
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfJobConvert {
|
||||
|
||||
InfJobConvert INSTANCE = Mappers.getMapper(InfJobConvert.class);
|
||||
|
||||
InfJobDO convert(InfJobCreateReqVO bean);
|
||||
|
||||
InfJobDO convert(InfJobUpdateReqVO bean);
|
||||
|
||||
InfJobRespVO convert(InfJobDO bean);
|
||||
|
||||
List<InfJobRespVO> convertList(List<InfJobDO> list);
|
||||
|
||||
PageResult<InfJobRespVO> convertPage(PageResult<InfJobDO> page);
|
||||
|
||||
List<InfJobExcelVO> convertList02(List<InfJobDO> list);
|
||||
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.convert.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogExcelVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobLogDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定时任务日志 Convert
|
||||
*
|
||||
* @author 芋艿
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfJobLogConvert {
|
||||
|
||||
InfJobLogConvert INSTANCE = Mappers.getMapper(InfJobLogConvert.class);
|
||||
|
||||
InfJobLogRespVO convert(InfJobLogDO bean);
|
||||
|
||||
List<InfJobLogRespVO> convertList(List<InfJobLogDO> list);
|
||||
|
||||
PageResult<InfJobLogRespVO> convertPage(PageResult<InfJobLogDO> page);
|
||||
|
||||
List<InfJobLogExcelVO> convertList02(List<InfJobLogDO> list);
|
||||
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.convert.logger;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExcelVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogRespVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API 访问日志 Convert
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfApiAccessLogConvert {
|
||||
|
||||
InfApiAccessLogConvert INSTANCE = Mappers.getMapper(InfApiAccessLogConvert.class);
|
||||
|
||||
InfApiAccessLogRespVO convert(InfApiAccessLogDO bean);
|
||||
|
||||
List<InfApiAccessLogRespVO> convertList(List<InfApiAccessLogDO> list);
|
||||
|
||||
PageResult<InfApiAccessLogRespVO> convertPage(PageResult<InfApiAccessLogDO> page);
|
||||
|
||||
List<InfApiAccessLogExcelVO> convertList02(List<InfApiAccessLogDO> list);
|
||||
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.convert.logger;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExcelVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogRespVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API 错误日志 Convert
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfApiErrorLogConvert {
|
||||
|
||||
InfApiErrorLogConvert INSTANCE = Mappers.getMapper(InfApiErrorLogConvert.class);
|
||||
|
||||
InfApiErrorLogRespVO convert(InfApiErrorLogDO bean);
|
||||
|
||||
PageResult<InfApiErrorLogRespVO> convertPage(PageResult<InfApiErrorLogDO> page);
|
||||
|
||||
List<InfApiErrorLogExcelVO> convertList02(List<InfApiErrorLogDO> list);
|
||||
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
/**
|
||||
* 提供 POJO 类的实体转换
|
||||
*
|
||||
* 目前使用 MapStruct 框架
|
||||
*/
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.convert;
|
@@ -1,34 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.convert.redis;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.redis.core.RedisKeyDefine;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.redis.vo.InfRedisKeyRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.redis.vo.InfRedisMonitorRespVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
@Mapper
|
||||
public interface RedisConvert {
|
||||
|
||||
RedisConvert INSTANCE = Mappers.getMapper(RedisConvert.class);
|
||||
|
||||
default InfRedisMonitorRespVO build(Properties info, Long dbSize, Properties commandStats) {
|
||||
InfRedisMonitorRespVO respVO = InfRedisMonitorRespVO.builder().info(info).dbSize(dbSize)
|
||||
.commandStats(new ArrayList<>(commandStats.size())).build();
|
||||
commandStats.forEach((key, value) -> {
|
||||
respVO.getCommandStats().add(InfRedisMonitorRespVO.CommandStat.builder()
|
||||
.command(StrUtil.subAfter((String) key, "cmdstat_", false))
|
||||
.calls(Integer.valueOf(StrUtil.subBetween((String) value, "calls=", ",")))
|
||||
.usec(Long.valueOf(StrUtil.subBetween((String) value, "usec=", ",")))
|
||||
.build());
|
||||
});
|
||||
return respVO;
|
||||
}
|
||||
|
||||
List<InfRedisKeyRespVO> convertList(List<RedisKeyDefine> list);
|
||||
|
||||
}
|
@@ -1 +0,0 @@
|
||||
<http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao>
|
@@ -1,72 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.job.InfJobStatusEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 定时任务 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("inf_job")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class InfJobDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 任务编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 任务名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 任务状态
|
||||
*
|
||||
* 枚举 {@link InfJobStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 处理器的名字
|
||||
*/
|
||||
private String handlerName;
|
||||
/**
|
||||
* 处理器的参数
|
||||
*/
|
||||
private String handlerParam;
|
||||
/**
|
||||
* CRON 表达式
|
||||
*/
|
||||
private String cronExpression;
|
||||
|
||||
// ========== 重试相关字段 ==========
|
||||
/**
|
||||
* 重试次数
|
||||
* 如果不重试,则设置为 0
|
||||
*/
|
||||
private Integer retryCount;
|
||||
/**
|
||||
* 重试间隔,单位:毫秒
|
||||
* 如果没有间隔,则设置为 0
|
||||
*/
|
||||
private Integer retryInterval;
|
||||
|
||||
// ========== 监控相关字段 ==========
|
||||
/**
|
||||
* 监控超时时间,单位:毫秒
|
||||
* 为空时,表示不监控
|
||||
*
|
||||
* 注意,这里的超时的目的,不是进行任务的取消,而是告警任务的执行时间过长
|
||||
*/
|
||||
private Integer monitorTimeout;
|
||||
|
||||
}
|
@@ -1,80 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.job.InfJobLogStatusEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 定时任务的执行日志
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("inf_job_log")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class InfJobLogDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 日志编号
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 任务编号
|
||||
*
|
||||
* 关联 {@link InfJobDO#getId()}
|
||||
*/
|
||||
private Long jobId;
|
||||
/**
|
||||
* 处理器的名字
|
||||
*
|
||||
* 冗余字段 {@link InfJobDO#getHandlerName()}
|
||||
*/
|
||||
private String handlerName;
|
||||
/**
|
||||
* 处理器的参数
|
||||
*
|
||||
* 冗余字段 {@link InfJobDO#getHandlerParam()}
|
||||
*/
|
||||
private String handlerParam;
|
||||
/**
|
||||
* 第几次执行
|
||||
*
|
||||
* 用于区分是不是重试执行。如果是重试执行,则 index 大于 1
|
||||
*/
|
||||
private Integer executeIndex;
|
||||
|
||||
/**
|
||||
* 开始执行时间
|
||||
*/
|
||||
private Date beginTime;
|
||||
/**
|
||||
* 结束执行时间
|
||||
*/
|
||||
private Date endTime;
|
||||
/**
|
||||
* 执行时长,单位:毫秒
|
||||
*/
|
||||
private Integer duration;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link InfJobLogStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 结果数据
|
||||
*
|
||||
* 成功时,使用 {@link JobHandler#execute(String)} 的结果
|
||||
* 失败时,使用 {@link JobHandler#execute(String)} 的异常堆栈
|
||||
*/
|
||||
private String result;
|
||||
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface InfConfigMapper extends BaseMapperX<InfConfigDO> {
|
||||
|
||||
default InfConfigDO selectByKey(String key) {
|
||||
return selectOne(new QueryWrapper<InfConfigDO>().eq("`key`", key));
|
||||
}
|
||||
|
||||
default PageResult<InfConfigDO> selectPage(InfConfigPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<InfConfigDO>()
|
||||
.likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("`key`", reqVO.getKey())
|
||||
.eqIfPresent("`type`", reqVO.getType())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
}
|
||||
|
||||
default List<InfConfigDO> selectList(InfConfigExportReqVO reqVO) {
|
||||
return selectList(new QueryWrapperX<InfConfigDO>()
|
||||
.likeIfPresent("name", reqVO.getName())
|
||||
.likeIfPresent("`key`", reqVO.getKey())
|
||||
.eqIfPresent("`type`", reqVO.getType())
|
||||
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
|
||||
}
|
||||
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* admin 文件操作 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfFileMapper extends BaseMapperX<InfFileDO> {
|
||||
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"));
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobLogDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 任务日志 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfJobLogMapper extends BaseMapperX<InfJobLogDO> {
|
||||
|
||||
default PageResult<InfJobLogDO> selectPage(InfJobLogPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<InfJobLogDO>()
|
||||
.eqIfPresent("job_id", reqVO.getJobId())
|
||||
.likeIfPresent("handler_name", reqVO.getHandlerName())
|
||||
.geIfPresent("begin_time", reqVO.getBeginTime())
|
||||
.leIfPresent("end_time", reqVO.getEndTime())
|
||||
.eqIfPresent("status", reqVO.getStatus())
|
||||
.orderByDesc("id") // ID 倒序
|
||||
);
|
||||
}
|
||||
|
||||
default List<InfJobLogDO> selectList(InfJobLogExportReqVO reqVO) {
|
||||
return selectList(new QueryWrapperX<InfJobLogDO>()
|
||||
.eqIfPresent("job_id", reqVO.getJobId())
|
||||
.likeIfPresent("handler_name", reqVO.getHandlerName())
|
||||
.geIfPresent("begin_time", reqVO.getBeginTime())
|
||||
.leIfPresent("end_time", reqVO.getEndTime())
|
||||
.eqIfPresent("status", reqVO.getStatus())
|
||||
.orderByDesc("id") // ID 倒序
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.job;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定时任务 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfJobMapper extends BaseMapperX<InfJobDO> {
|
||||
|
||||
default InfJobDO selectByHandlerName(String handlerName) {
|
||||
return selectOne(InfJobDO::getHandlerName, handlerName);
|
||||
}
|
||||
|
||||
default PageResult<InfJobDO> selectPage(InfJobPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<InfJobDO>()
|
||||
.likeIfPresent(InfJobDO::getName, reqVO.getName())
|
||||
.eqIfPresent(InfJobDO::getStatus, reqVO.getStatus())
|
||||
.likeIfPresent(InfJobDO::getHandlerName, reqVO.getHandlerName())
|
||||
);
|
||||
}
|
||||
|
||||
default List<InfJobDO> selectList(InfJobExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<InfJobDO>()
|
||||
.likeIfPresent(InfJobDO::getName, reqVO.getName())
|
||||
.eqIfPresent(InfJobDO::getStatus, reqVO.getStatus())
|
||||
.likeIfPresent(InfJobDO::getHandlerName, reqVO.getHandlerName())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API 访问日志 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfApiAccessLogMapper extends BaseMapperX<InfApiAccessLogDO> {
|
||||
|
||||
default PageResult<InfApiAccessLogDO> selectPage(InfApiAccessLogPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<InfApiAccessLogDO>()
|
||||
.eqIfPresent("user_id", reqVO.getUserId())
|
||||
.eqIfPresent("user_type", reqVO.getUserType())
|
||||
.eqIfPresent("application_name", reqVO.getApplicationName())
|
||||
.likeIfPresent("request_url", reqVO.getRequestUrl())
|
||||
.betweenIfPresent("begin_time", reqVO.getBeginBeginTime(), reqVO.getEndBeginTime())
|
||||
.geIfPresent("duration", reqVO.getDuration())
|
||||
.eqIfPresent("result_code", reqVO.getResultCode())
|
||||
.orderByDesc("id")
|
||||
);
|
||||
}
|
||||
|
||||
default List<InfApiAccessLogDO> selectList(InfApiAccessLogExportReqVO reqVO) {
|
||||
return selectList(new QueryWrapperX<InfApiAccessLogDO>()
|
||||
.eqIfPresent("user_id", reqVO.getUserId())
|
||||
.eqIfPresent("user_type", reqVO.getUserType())
|
||||
.eqIfPresent("application_name", reqVO.getApplicationName())
|
||||
.likeIfPresent("request_url", reqVO.getRequestUrl())
|
||||
.betweenIfPresent("begin_time", reqVO.getBeginBeginTime(), reqVO.getEndBeginTime())
|
||||
.geIfPresent("duration", reqVO.getDuration())
|
||||
.eqIfPresent("result_code", reqVO.getResultCode())
|
||||
.orderByDesc("id")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API 错误日志 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InfApiErrorLogMapper extends BaseMapperX<InfApiErrorLogDO> {
|
||||
|
||||
default PageResult<InfApiErrorLogDO> selectPage(InfApiErrorLogPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new QueryWrapperX<InfApiErrorLogDO>()
|
||||
.eqIfPresent("user_id", reqVO.getUserId())
|
||||
.eqIfPresent("user_type", reqVO.getUserType())
|
||||
.eqIfPresent("application_name", reqVO.getApplicationName())
|
||||
.likeIfPresent("request_url", reqVO.getRequestUrl())
|
||||
.betweenIfPresent("exception_time", reqVO.getBeginExceptionTime(), reqVO.getEndExceptionTime())
|
||||
.eqIfPresent("process_status", reqVO.getProcessStatus())
|
||||
.orderByDesc("id")
|
||||
);
|
||||
}
|
||||
|
||||
default List<InfApiErrorLogDO> selectList(InfApiErrorLogExportReqVO reqVO) {
|
||||
return selectList(new QueryWrapperX<InfApiErrorLogDO>()
|
||||
.eqIfPresent("user_id", reqVO.getUserId())
|
||||
.eqIfPresent("user_type", reqVO.getUserType())
|
||||
.eqIfPresent("application_name", reqVO.getApplicationName())
|
||||
.likeIfPresent("request_url", reqVO.getRequestUrl())
|
||||
.betweenIfPresent("exception_time", reqVO.getBeginExceptionTime(), reqVO.getEndExceptionTime())
|
||||
.eqIfPresent("process_status", reqVO.getProcessStatus())
|
||||
.orderByDesc("id")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.enums;
|
||||
|
||||
/**
|
||||
* Infra 字典类型的枚举类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfDictTypeConstants {
|
||||
|
||||
String REDIS_TIMEOUT_TYPE = "inf_redis_timeout_type"; // Redis 超时类型
|
||||
|
||||
String JOB_STATUS = "inf_job_status"; // 定时任务状态的枚举
|
||||
String JOB_LOG_STATUS = "inf_job_log_status"; // 定时任务日志状态的枚举
|
||||
|
||||
String API_ERROR_LOG_PROCESS_STATUS = "inf_api_error_log_process_status"; // API 错误日志的处理状态的枚举
|
||||
|
||||
String ERROR_CODE_TYPE = "inf_error_code_type"; // 错误码的类型枚举
|
||||
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
|
||||
/**
|
||||
* Infra 错误码枚举类
|
||||
*
|
||||
* infra 系统,使用 1-001-000-000 段
|
||||
*/
|
||||
public interface InfErrorCodeConstants {
|
||||
|
||||
// ========== 参数配置 1001000000 ==========
|
||||
ErrorCode CONFIG_NOT_EXISTS = new ErrorCode(1001000001, "参数配置不存在");
|
||||
ErrorCode CONFIG_KEY_DUPLICATE = new ErrorCode(1001000002, "参数配置 key 重复");
|
||||
ErrorCode CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE = new ErrorCode(1001000003, "不能删除类型为系统内置的参数配置");
|
||||
ErrorCode CONFIG_GET_VALUE_ERROR_IF_SENSITIVE = new ErrorCode(1001000004, "不允许获取敏感配置到前端");
|
||||
|
||||
// ========== 定时任务 1001001000 ==========
|
||||
ErrorCode JOB_NOT_EXISTS = new ErrorCode(1001001000, "定时任务不存在");
|
||||
ErrorCode JOB_HANDLER_EXISTS = new ErrorCode(1001001001, "定时任务的处理器已经存在");
|
||||
ErrorCode JOB_CHANGE_STATUS_INVALID = new ErrorCode(1001001002, "只允许修改为开启或者关闭状态");
|
||||
ErrorCode JOB_CHANGE_STATUS_EQUALS = new ErrorCode(1001001003, "定时任务已经处于该状态,无需修改");
|
||||
ErrorCode JOB_UPDATE_ONLY_NORMAL_STATUS = new ErrorCode(1001001004, "只有开启状态的任务,才可以修改");
|
||||
ErrorCode JOB_CRON_EXPRESSION_VALID = new ErrorCode(1001001005, "CRON 表达式不正确");
|
||||
|
||||
// ========== API 错误日志 1001002000 ==========
|
||||
ErrorCode API_ERROR_LOG_NOT_FOUND = new ErrorCode(1001002000, "API 错误日志不存在");
|
||||
ErrorCode API_ERROR_LOG_PROCESSED = new ErrorCode(1001002001, "API 错误日志已处理");
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.enums.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum InfConfigTypeEnum {
|
||||
|
||||
/**
|
||||
* 系统配置
|
||||
*/
|
||||
SYSTEM(1),
|
||||
/**
|
||||
* 自定义配置
|
||||
*/
|
||||
CUSTOM(2);
|
||||
|
||||
private final Integer type;
|
||||
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.enums.job;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 任务日志的状态枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum InfJobLogStatusEnum {
|
||||
|
||||
RUNNING(0), // 运行中
|
||||
SUCCESS(1), // 成功
|
||||
FAILURE(2); // 失败
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private final Integer status;
|
||||
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.enums.job;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.quartz.impl.jdbcjobstore.Constants.*;
|
||||
|
||||
/**
|
||||
* 任务状态的枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum InfJobStatusEnum {
|
||||
|
||||
/**
|
||||
* 初始化中
|
||||
*/
|
||||
INIT(0, Collections.emptySet()),
|
||||
/**
|
||||
* 开启
|
||||
*/
|
||||
NORMAL(1, Sets.newHashSet(STATE_WAITING, STATE_ACQUIRED, STATE_BLOCKED)),
|
||||
/**
|
||||
* 暂停
|
||||
*/
|
||||
STOP(2, Sets.newHashSet(STATE_PAUSED, STATE_PAUSED_BLOCKED));
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private final Integer status;
|
||||
/**
|
||||
* 对应的 Quartz 触发器的状态集合
|
||||
*/
|
||||
private final Set<String> quartzStates;
|
||||
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.enums.logger;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* API 异常数据的处理状态
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum InfApiErrorLogProcessStatusEnum {
|
||||
|
||||
INIT(0, "未处理"),
|
||||
DONE(1, "已处理"),
|
||||
IGNORE(2, "已忽略");
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private final Integer status;
|
||||
/**
|
||||
* 资源类型名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
/**
|
||||
* 属于 infra 模块的 framework 封装
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.framework;
|
@@ -1,24 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.mq.consumer.config;
|
||||
|
||||
import cn.iocoder.yudao.framework.apollo.internals.DBConfigRepository;
|
||||
import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.mq.message.config.InfConfigRefreshMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 针对 {@link InfConfigRefreshMessage} 的消费者
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class InfConfigRefreshConsumer extends AbstractChannelMessageListener<InfConfigRefreshMessage> {
|
||||
|
||||
@Override
|
||||
public void onMessage(InfConfigRefreshMessage message) {
|
||||
log.info("[onMessage][收到 Config 刷新消息]");
|
||||
DBConfigRepository.noticeSync();
|
||||
}
|
||||
|
||||
}
|
@@ -1 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.mq.consumer;
|
@@ -1,17 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.mq.message.config;
|
||||
|
||||
import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 配置数据刷新 Message
|
||||
*/
|
||||
@Data
|
||||
public class InfConfigRefreshMessage extends AbstractChannelMessage {
|
||||
|
||||
@Override
|
||||
public String getChannel() {
|
||||
return "infra.config.refresh";
|
||||
}
|
||||
|
||||
}
|
@@ -1 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.mq.message;
|
@@ -1,26 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.mq.message.config.InfConfigRefreshMessage;
|
||||
import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Config 配置相关消息的 Producer
|
||||
*/
|
||||
@Component
|
||||
public class InfConfigProducer {
|
||||
|
||||
@Resource
|
||||
private RedisMQTemplate redisMQTemplate;
|
||||
|
||||
/**
|
||||
* 发送 {@link InfConfigRefreshMessage} 消息
|
||||
*/
|
||||
public void sendConfigRefreshMessage() {
|
||||
InfConfigRefreshMessage message = new InfConfigRefreshMessage();
|
||||
redisMQTemplate.send(message);
|
||||
}
|
||||
|
||||
}
|
@@ -1 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.mq.producer;
|
@@ -1,7 +0,0 @@
|
||||
/**
|
||||
* infra 包下,我们放基础设施的运维与管理,支撑上层的通用与核心业务。
|
||||
* 例如说:定时任务的管理、服务器的信息等等
|
||||
*
|
||||
* 缩写:inf
|
||||
*/
|
||||
package cn.iocoder.yudao.adminserver.modules.infra;
|
@@ -1,75 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.config;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 参数配置 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfConfigService {
|
||||
|
||||
/**
|
||||
* 创建参数配置
|
||||
*
|
||||
* @param reqVO 创建信息
|
||||
* @return 配置编号
|
||||
*/
|
||||
Long createConfig(@Valid InfConfigCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 更新参数配置
|
||||
*
|
||||
* @param reqVO 更新信息
|
||||
*/
|
||||
void updateConfig(@Valid InfConfigUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 删除参数配置
|
||||
*
|
||||
* @param id 配置编号
|
||||
*/
|
||||
void deleteConfig(Long id);
|
||||
|
||||
/**
|
||||
* 获得参数配置
|
||||
*
|
||||
* @param id 配置编号
|
||||
* @return 参数配置
|
||||
*/
|
||||
InfConfigDO getConfig(Long id);
|
||||
|
||||
/**
|
||||
* 根据参数键,获得参数配置
|
||||
*
|
||||
* @param key 配置键
|
||||
* @return 参数配置
|
||||
*/
|
||||
InfConfigDO getConfigByKey(String key);
|
||||
|
||||
/**
|
||||
* 获得参数配置分页列表
|
||||
*
|
||||
* @param reqVO 分页条件
|
||||
* @return 分页列表
|
||||
*/
|
||||
PageResult<InfConfigDO> getConfigPage(@Valid InfConfigPageReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得参数配置列表
|
||||
*
|
||||
* @param reqVO 列表
|
||||
* @return 列表
|
||||
*/
|
||||
List<InfConfigDO> getConfigList(@Valid InfConfigExportReqVO reqVO);
|
||||
|
||||
|
||||
}
|
@@ -1,132 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.config.impl;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO;
|
||||
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.config.InfConfigConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config.InfConfigProducer;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.config.InfConfigService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 参数配置 Service 实现类
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@Validated
|
||||
public class InfConfigServiceImpl implements InfConfigService {
|
||||
|
||||
@Resource
|
||||
private InfConfigMapper configMapper;
|
||||
|
||||
@Resource
|
||||
private InfConfigProducer configProducer;
|
||||
|
||||
@Override
|
||||
public Long createConfig(InfConfigCreateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(null, reqVO.getKey());
|
||||
// 插入参数配置
|
||||
InfConfigDO config = InfConfigConvert.INSTANCE.convert(reqVO);
|
||||
config.setType(InfConfigTypeEnum.CUSTOM.getType());
|
||||
configMapper.insert(config);
|
||||
// 发送刷新消息
|
||||
configProducer.sendConfigRefreshMessage();
|
||||
return config.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConfig(InfConfigUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key
|
||||
// 更新参数配置
|
||||
InfConfigDO updateObj = InfConfigConvert.INSTANCE.convert(reqVO);
|
||||
configMapper.updateById(updateObj);
|
||||
// 发送刷新消息
|
||||
configProducer.sendConfigRefreshMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteConfig(Long id) {
|
||||
// 校验配置存在
|
||||
InfConfigDO config = checkConfigExists(id);
|
||||
// 内置配置,不允许删除
|
||||
if (InfConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
|
||||
}
|
||||
// 删除
|
||||
configMapper.deleteById(id);
|
||||
// 发送刷新消息
|
||||
configProducer.sendConfigRefreshMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfConfigDO getConfig(Long id) {
|
||||
return configMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfConfigDO getConfigByKey(String key) {
|
||||
return configMapper.selectByKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<InfConfigDO> getConfigPage(InfConfigPageReqVO reqVO) {
|
||||
return configMapper.selectPage(reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfConfigDO> getConfigList(InfConfigExportReqVO reqVO) {
|
||||
return configMapper.selectList(reqVO);
|
||||
}
|
||||
|
||||
private void checkCreateOrUpdate(Long id, String key) {
|
||||
// 校验自己存在
|
||||
checkConfigExists(id);
|
||||
// 校验参数配置 key 的唯一性
|
||||
checkConfigKeyUnique(id, key);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public InfConfigDO checkConfigExists(Long id) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
InfConfigDO config = configMapper.selectById(id);
|
||||
if (config == null) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_NOT_EXISTS);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void checkConfigKeyUnique(Long id, String key) {
|
||||
InfConfigDO config = configMapper.selectByKey(key);
|
||||
if (config == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的参数配置
|
||||
if (id == null) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_KEY_DUPLICATE);
|
||||
}
|
||||
if (!config.getId().equals(id)) {
|
||||
throw ServiceExceptionUtil.exception(CONFIG_KEY_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.file;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 文件 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfFileService {
|
||||
|
||||
/**
|
||||
* 获得文件分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 文件分页
|
||||
*/
|
||||
PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO);
|
||||
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.file.impl;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.file.InfFileMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 文件 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
public class InfFileServiceImpl implements InfFileService {
|
||||
|
||||
@Resource
|
||||
private InfFileMapper fileMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<InfFileDO> getFilePage(InfFilePageReqVO pageReqVO) {
|
||||
return fileMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.quartz.core.service.JobLogFrameworkService;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobLogDO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Job 日志 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfJobLogService extends JobLogFrameworkService {
|
||||
|
||||
/**
|
||||
* 获得定时任务
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 定时任务
|
||||
*/
|
||||
InfJobLogDO getJobLog(Long id);
|
||||
|
||||
/**
|
||||
* 获得定时任务列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 定时任务列表
|
||||
*/
|
||||
List<InfJobLogDO> getJobLogList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得定时任务分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 定时任务分页
|
||||
*/
|
||||
PageResult<InfJobLogDO> getJobLogPage(InfJobLogPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得定时任务列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 定时任务分页
|
||||
*/
|
||||
List<InfJobLogDO> getJobLogList(InfJobLogExportReqVO exportReqVO);
|
||||
|
||||
}
|
@@ -1,91 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobUpdateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobDO;
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定时任务 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfJobService {
|
||||
|
||||
/**
|
||||
* 创建定时任务
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createJob(@Valid InfJobCreateReqVO createReqVO) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 更新定时任务
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateJob(@Valid InfJobUpdateReqVO updateReqVO) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 更新定时任务的状态
|
||||
*
|
||||
* @param id 任务编号
|
||||
* @param status 状态
|
||||
*/
|
||||
void updateJobStatus(Long id, Integer status) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 触发定时任务
|
||||
*
|
||||
* @param id 任务编号
|
||||
*/
|
||||
void triggerJob(Long id) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 删除定时任务
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteJob(Long id) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 获得定时任务
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 定时任务
|
||||
*/
|
||||
InfJobDO getJob(Long id);
|
||||
|
||||
/**
|
||||
* 获得定时任务列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 定时任务列表
|
||||
*/
|
||||
List<InfJobDO> getJobList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得定时任务分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 定时任务分页
|
||||
*/
|
||||
PageResult<InfJobDO> getJobPage(InfJobPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得定时任务列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 定时任务分页
|
||||
*/
|
||||
List<InfJobDO> getJobList(InfJobExportReqVO exportReqVO);
|
||||
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.job.impl;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobLogDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.job.InfJobLogMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.job.InfJobLogStatusEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.job.InfJobLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Job 日志 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class InfJobLogServiceImpl implements InfJobLogService {
|
||||
|
||||
@Resource
|
||||
private InfJobLogMapper jobLogMapper;
|
||||
|
||||
@Override
|
||||
public Long createJobLog(Long jobId, Date beginTime, String jobHandlerName, String jobHandlerParam, Integer executeIndex) {
|
||||
InfJobLogDO log = InfJobLogDO.builder().jobId(jobId).handlerName(jobHandlerName).handlerParam(jobHandlerParam).executeIndex(executeIndex)
|
||||
.beginTime(beginTime).status(InfJobLogStatusEnum.RUNNING.getStatus()).build();
|
||||
jobLogMapper.insert(log);
|
||||
return log.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void updateJobLogResultAsync(Long logId, Date endTime, Integer duration, boolean success, String result) {
|
||||
try {
|
||||
InfJobLogDO updateObj = InfJobLogDO.builder().id(logId).endTime(endTime).duration(duration)
|
||||
.status(success ? InfJobLogStatusEnum.SUCCESS.getStatus() : InfJobLogStatusEnum.FAILURE.getStatus()).result(result).build();
|
||||
jobLogMapper.updateById(updateObj);
|
||||
} catch (Exception ex) {
|
||||
log.error("[updateJobLogResultAsync][logId({}) endTime({}) duration({}) success({}) result({})]",
|
||||
logId, endTime, duration, success, result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfJobLogDO getJobLog(Long id) {
|
||||
return jobLogMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfJobLogDO> getJobLogList(Collection<Long> ids) {
|
||||
return jobLogMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<InfJobLogDO> getJobLogPage(InfJobLogPageReqVO pageReqVO) {
|
||||
return jobLogMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfJobLogDO> getJobLogList(InfJobLogExportReqVO exportReqVO) {
|
||||
return jobLogMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
@@ -1,174 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.job.impl;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.quartz.core.scheduler.SchedulerManager;
|
||||
import cn.iocoder.yudao.framework.quartz.core.util.CronUtils;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobUpdateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.job.InfJobConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.job.InfJobMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.job.InfJobStatusEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.job.InfJobService;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.containsAny;
|
||||
|
||||
/**
|
||||
* 定时任务 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class InfJobServiceImpl implements InfJobService {
|
||||
|
||||
@Resource
|
||||
private InfJobMapper jobMapper;
|
||||
|
||||
@Resource
|
||||
private SchedulerManager schedulerManager;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createJob(InfJobCreateReqVO createReqVO) throws SchedulerException {
|
||||
validateCronExpression(createReqVO.getCronExpression());
|
||||
// 校验唯一性
|
||||
if (jobMapper.selectByHandlerName(createReqVO.getHandlerName()) != null) {
|
||||
throw exception(JOB_HANDLER_EXISTS);
|
||||
}
|
||||
// 插入
|
||||
InfJobDO job = InfJobConvert.INSTANCE.convert(createReqVO);
|
||||
job.setStatus(InfJobStatusEnum.INIT.getStatus());
|
||||
fillJobMonitorTimeoutEmpty(job);
|
||||
jobMapper.insert(job);
|
||||
|
||||
// 添加 Job 到 Quartz 中
|
||||
schedulerManager.addJob(job.getId(), job.getHandlerName(), job.getHandlerParam(), job.getCronExpression(),
|
||||
createReqVO.getRetryCount(), createReqVO.getRetryInterval());
|
||||
// 更新
|
||||
InfJobDO updateObj = InfJobDO.builder().id(job.getId()).status(InfJobStatusEnum.NORMAL.getStatus()).build();
|
||||
jobMapper.updateById(updateObj);
|
||||
|
||||
// 返回
|
||||
return job.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateJob(InfJobUpdateReqVO updateReqVO) throws SchedulerException {
|
||||
validateCronExpression(updateReqVO.getCronExpression());
|
||||
// 校验存在
|
||||
InfJobDO job = this.validateJobExists(updateReqVO.getId());
|
||||
// 只有开启状态,才可以修改.原因是,如果出暂停状态,修改 Quartz Job 时,会导致任务又开始执行
|
||||
if (!job.getStatus().equals(InfJobStatusEnum.NORMAL.getStatus())) {
|
||||
throw exception(JOB_UPDATE_ONLY_NORMAL_STATUS);
|
||||
}
|
||||
// 更新
|
||||
InfJobDO updateObj = InfJobConvert.INSTANCE.convert(updateReqVO);
|
||||
fillJobMonitorTimeoutEmpty(updateObj);
|
||||
jobMapper.updateById(updateObj);
|
||||
|
||||
// 更新 Job 到 Quartz 中
|
||||
schedulerManager.updateJob(job.getHandlerName(), updateReqVO.getHandlerParam(), updateReqVO.getCronExpression(),
|
||||
updateReqVO.getRetryCount(), updateReqVO.getRetryInterval());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateJobStatus(Long id, Integer status) throws SchedulerException {
|
||||
// 校验 status
|
||||
if (!containsAny(status, InfJobStatusEnum.NORMAL.getStatus(), InfJobStatusEnum.STOP.getStatus())) {
|
||||
throw exception(JOB_CHANGE_STATUS_INVALID);
|
||||
}
|
||||
// 校验存在
|
||||
InfJobDO job = this.validateJobExists(id);
|
||||
// 校验是否已经为当前状态
|
||||
if (job.getStatus().equals(status)) {
|
||||
throw exception(JOB_CHANGE_STATUS_EQUALS);
|
||||
}
|
||||
// 更新 Job 状态
|
||||
InfJobDO updateObj = InfJobDO.builder().id(id).status(status).build();
|
||||
jobMapper.updateById(updateObj);
|
||||
|
||||
// 更新状态 Job 到 Quartz 中
|
||||
if (InfJobStatusEnum.NORMAL.getStatus().equals(status)) { // 开启
|
||||
schedulerManager.resumeJob(job.getHandlerName());
|
||||
} else { // 暂停
|
||||
schedulerManager.pauseJob(job.getHandlerName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerJob(Long id) throws SchedulerException {
|
||||
// 校验存在
|
||||
InfJobDO job = this.validateJobExists(id);
|
||||
|
||||
// 触发 Quartz 中的 Job
|
||||
schedulerManager.triggerJob(job.getId(), job.getHandlerName(), job.getHandlerParam());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteJob(Long id) throws SchedulerException {
|
||||
// 校验存在
|
||||
InfJobDO job = this.validateJobExists(id);
|
||||
// 更新
|
||||
jobMapper.deleteById(id);
|
||||
|
||||
// 删除 Job 到 Quartz 中
|
||||
schedulerManager.deleteJob(job.getHandlerName());
|
||||
}
|
||||
|
||||
private InfJobDO validateJobExists(Long id) {
|
||||
InfJobDO job = jobMapper.selectById(id);
|
||||
if (job == null) {
|
||||
throw exception(JOB_NOT_EXISTS);
|
||||
}
|
||||
return job;
|
||||
}
|
||||
|
||||
private void validateCronExpression(String cronExpression) {
|
||||
if (!CronUtils.isValid(cronExpression)) {
|
||||
throw exception(JOB_CRON_EXPRESSION_VALID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfJobDO getJob(Long id) {
|
||||
return jobMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfJobDO> getJobList(Collection<Long> ids) {
|
||||
return jobMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<InfJobDO> getJobPage(InfJobPageReqVO pageReqVO) {
|
||||
return jobMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfJobDO> getJobList(InfJobExportReqVO exportReqVO) {
|
||||
return jobMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
private static void fillJobMonitorTimeoutEmpty(InfJobDO job) {
|
||||
if (job.getMonitorTimeout() == null) {
|
||||
job.setMonitorTimeout(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.logger;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API 访问日志 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfApiAccessLogService {
|
||||
|
||||
/**
|
||||
* 获得 API 访问日志分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return API 访问日志分页
|
||||
*/
|
||||
PageResult<InfApiAccessLogDO> getApiAccessLogPage(InfApiAccessLogPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得 API 访问日志列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return API 访问日志分页
|
||||
*/
|
||||
List<InfApiAccessLogDO> getApiAccessLogList(InfApiAccessLogExportReqVO exportReqVO);
|
||||
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.logger;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API 错误日志 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InfApiErrorLogService {
|
||||
|
||||
/**
|
||||
* 获得 API 错误日志分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return API 错误日志分页
|
||||
*/
|
||||
PageResult<InfApiErrorLogDO> getApiErrorLogPage(InfApiErrorLogPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得 API 错误日志列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return API 错误日志分页
|
||||
*/
|
||||
List<InfApiErrorLogDO> getApiErrorLogList(InfApiErrorLogExportReqVO exportReqVO);
|
||||
|
||||
/**
|
||||
* 更新 API 错误日志已处理
|
||||
*
|
||||
* @param id API 日志编号
|
||||
* @param processStatus 处理结果
|
||||
* @param processUserId 处理人
|
||||
*/
|
||||
void updateApiErrorLogProcess(Long id, Integer processStatus, Long processUserId);
|
||||
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiAccessLogService;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* API 访问日志 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class InfApiAccessLogServiceImpl implements InfApiAccessLogService {
|
||||
|
||||
@Resource
|
||||
private InfApiAccessLogMapper apiAccessLogMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<InfApiAccessLogDO> getApiAccessLogPage(InfApiAccessLogPageReqVO pageReqVO) {
|
||||
return apiAccessLogMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfApiAccessLogDO> getApiAccessLogList(InfApiAccessLogExportReqVO exportReqVO) {
|
||||
return apiAccessLogMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.logger.InfApiErrorLogService;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_NOT_FOUND;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_PROCESSED;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* API 错误日志 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class InfApiErrorLogServiceImpl implements InfApiErrorLogService {
|
||||
|
||||
@Resource
|
||||
private InfApiErrorLogMapper apiErrorLogMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<InfApiErrorLogDO> getApiErrorLogPage(InfApiErrorLogPageReqVO pageReqVO) {
|
||||
return apiErrorLogMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfApiErrorLogDO> getApiErrorLogList(InfApiErrorLogExportReqVO exportReqVO) {
|
||||
return apiErrorLogMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateApiErrorLogProcess(Long id, Integer processStatus, Long processUserId) {
|
||||
InfApiErrorLogDO errorLog = apiErrorLogMapper.selectById(id);
|
||||
if (errorLog == null) {
|
||||
throw exception(API_ERROR_LOG_NOT_FOUND);
|
||||
}
|
||||
if (!InfApiErrorLogProcessStatusEnum.INIT.getStatus().equals(errorLog.getProcessStatus())) {
|
||||
throw exception(API_ERROR_LOG_PROCESSED);
|
||||
}
|
||||
// 标记处理
|
||||
apiErrorLogMapper.updateById(InfApiErrorLogDO.builder().id(id).processStatus(processStatus)
|
||||
.processUserId(processUserId).processTime(new Date()).build());
|
||||
}
|
||||
|
||||
}
|
@@ -2,8 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.InfDictTypeConstants;
|
||||
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
|
||||
import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -24,15 +23,15 @@ public class ToolTestDemoExcelVO {
|
||||
private String name;
|
||||
|
||||
@ExcelProperty(value = "状态", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.COMMON_STATUS)
|
||||
@DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.COMMON_STATUS)
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty(value = "类型", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.OPERATE_TYPE)
|
||||
@DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.OPERATE_TYPE)
|
||||
private Integer type;
|
||||
|
||||
@ExcelProperty(value = "分类", converter = DictConvert.class)
|
||||
@DictFormat(InfDictTypeConstants.REDIS_TIMEOUT_TYPE)
|
||||
@DictFormat(DictTypeConstants.REDIS_TIMEOUT_TYPE)
|
||||
private Integer category;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
|
@@ -1,16 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.config;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.quartz.Scheduler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class QuartzTestConfiguration {
|
||||
|
||||
@Bean
|
||||
public Scheduler scheduler() {
|
||||
return Mockito.mock(Scheduler.class);
|
||||
}
|
||||
|
||||
}
|
@@ -1,256 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.config;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.config.InfConfigDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.config.vo.InfConfigUpdateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.config.InfConfigMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.config.InfConfigTypeEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.mq.producer.config.InfConfigProducer;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.config.impl.InfConfigServiceImpl;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* {@link InfConfigServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(InfConfigServiceImpl.class)
|
||||
public class InfConfigServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfConfigServiceImpl configService;
|
||||
|
||||
@Resource
|
||||
private InfConfigMapper configMapper;
|
||||
@MockBean
|
||||
private InfConfigProducer configProducer;
|
||||
|
||||
@Test
|
||||
public void testCreateConfig_success() {
|
||||
// 准备参数
|
||||
InfConfigCreateReqVO reqVO = randomPojo(InfConfigCreateReqVO.class);
|
||||
|
||||
// 调用
|
||||
Long configId = configService.createConfig(reqVO);
|
||||
// 断言
|
||||
assertNotNull(configId);
|
||||
// 校验记录的属性是否正确
|
||||
InfConfigDO config = configMapper.selectById(configId);
|
||||
assertPojoEquals(reqVO, config);
|
||||
assertEquals(InfConfigTypeEnum.CUSTOM.getType(), config.getType());
|
||||
// 校验调用
|
||||
verify(configProducer, times(1)).sendConfigRefreshMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConfig_success() {
|
||||
// mock 数据
|
||||
InfConfigDO dbConfig = randomInfConfigDO();
|
||||
configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
InfConfigUpdateReqVO reqVO = randomPojo(InfConfigUpdateReqVO.class, o -> {
|
||||
o.setId(dbConfig.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
configService.updateConfig(reqVO);
|
||||
// 校验是否更新正确
|
||||
InfConfigDO config = configMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, config);
|
||||
// 校验调用
|
||||
verify(configProducer, times(1)).sendConfigRefreshMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteConfig_success() {
|
||||
// mock 数据
|
||||
InfConfigDO dbConfig = randomInfConfigDO(o -> {
|
||||
o.setType(InfConfigTypeEnum.CUSTOM.getType()); // 只能删除 CUSTOM 类型
|
||||
});
|
||||
configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbConfig.getId();
|
||||
|
||||
// 调用
|
||||
configService.deleteConfig(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(configMapper.selectById(id));
|
||||
// 校验调用
|
||||
verify(configProducer, times(1)).sendConfigRefreshMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteConfig_canNotDeleteSystemType() {
|
||||
// mock 数据
|
||||
InfConfigDO dbConfig = randomInfConfigDO(o -> {
|
||||
o.setType(InfConfigTypeEnum.SYSTEM.getType()); // SYSTEM 不允许删除
|
||||
});
|
||||
configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbConfig.getId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> configService.deleteConfig(id), CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckConfigExists_success() {
|
||||
// mock 数据
|
||||
InfConfigDO dbConfigDO = randomInfConfigDO();
|
||||
configMapper.insert(dbConfigDO);// @Sql: 先插入出一条存在的数据
|
||||
|
||||
// 调用成功
|
||||
configService.checkConfigExists(dbConfigDO.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckConfigExist_notExists() {
|
||||
assertServiceException(() -> configService.checkConfigExists(randomLongId()), CONFIG_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckConfigKeyUnique_success() {
|
||||
// 调用,成功
|
||||
configService.checkConfigKeyUnique(randomLongId(), randomString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckConfigKeyUnique_keyDuplicateForCreate() {
|
||||
// 准备参数
|
||||
String key = randomString();
|
||||
// mock 数据
|
||||
configMapper.insert(randomInfConfigDO(o -> o.setKey(key)));
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> configService.checkConfigKeyUnique(null, key),
|
||||
CONFIG_KEY_DUPLICATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckConfigKeyUnique_keyDuplicateForUpdate() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
String key = randomString();
|
||||
// mock 数据
|
||||
configMapper.insert(randomInfConfigDO(o -> o.setKey(key)));
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> configService.checkConfigKeyUnique(id, key),
|
||||
CONFIG_KEY_DUPLICATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigPage() {
|
||||
// mock 数据
|
||||
InfConfigDO dbConfig = randomInfConfigDO(o -> { // 等会查询到
|
||||
o.setName("芋艿");
|
||||
o.setKey("yunai");
|
||||
o.setType(InfConfigTypeEnum.SYSTEM.getType());
|
||||
o.setCreateTime(buildTime(2021, 2, 1));
|
||||
});
|
||||
configMapper.insert(dbConfig);
|
||||
// 测试 name 不匹配
|
||||
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setName("土豆")));
|
||||
// 测试 key 不匹配
|
||||
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setKey("tudou")));
|
||||
// 测试 type 不匹配
|
||||
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setType(InfConfigTypeEnum.CUSTOM.getType())));
|
||||
// 测试 createTime 不匹配
|
||||
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
||||
// 准备参数
|
||||
InfConfigPageReqVO reqVO = new InfConfigPageReqVO();
|
||||
reqVO.setName("艿");
|
||||
reqVO.setKey("nai");
|
||||
reqVO.setType(InfConfigTypeEnum.SYSTEM.getType());
|
||||
reqVO.setBeginTime(buildTime(2021, 1, 15));
|
||||
reqVO.setEndTime(buildTime(2021, 2, 15));
|
||||
|
||||
// 调用
|
||||
PageResult<InfConfigDO> pageResult = configService.getConfigPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbConfig, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigList() {
|
||||
// mock 数据
|
||||
InfConfigDO dbConfig = randomInfConfigDO(o -> { // 等会查询到
|
||||
o.setName("芋艿");
|
||||
o.setKey("yunai");
|
||||
o.setType(InfConfigTypeEnum.SYSTEM.getType());
|
||||
o.setCreateTime(buildTime(2021, 2, 1));
|
||||
});
|
||||
configMapper.insert(dbConfig);
|
||||
// 测试 name 不匹配
|
||||
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setName("土豆")));
|
||||
// 测试 key 不匹配
|
||||
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setKey("tudou")));
|
||||
// 测试 type 不匹配
|
||||
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setType(InfConfigTypeEnum.CUSTOM.getType())));
|
||||
// 测试 createTime 不匹配
|
||||
configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
||||
// 准备参数
|
||||
InfConfigExportReqVO reqVO = new InfConfigExportReqVO();
|
||||
reqVO.setName("艿");
|
||||
reqVO.setKey("nai");
|
||||
reqVO.setType(InfConfigTypeEnum.SYSTEM.getType());
|
||||
reqVO.setBeginTime(buildTime(2021, 1, 15));
|
||||
reqVO.setEndTime(buildTime(2021, 2, 15));
|
||||
|
||||
// 调用
|
||||
List<InfConfigDO> list = configService.getConfigList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbConfig, list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigByKey() {
|
||||
// mock 数据
|
||||
InfConfigDO dbConfig = randomInfConfigDO();
|
||||
configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
String key = dbConfig.getKey();
|
||||
|
||||
// 调用
|
||||
InfConfigDO config = configService.getConfigByKey(key);
|
||||
// 断言
|
||||
assertNotNull(config);
|
||||
assertPojoEquals(dbConfig, config);
|
||||
}
|
||||
|
||||
// ========== 随机对象 ==========
|
||||
|
||||
@SafeVarargs
|
||||
private static InfConfigDO randomInfConfigDO(Consumer<InfConfigDO>... consumers) {
|
||||
Consumer<InfConfigDO> consumer = (o) -> {
|
||||
o.setType(randomEle(InfConfigTypeEnum.values()).getType()); // 保证 key 的范围
|
||||
};
|
||||
return randomPojo(InfConfigDO.class, ArrayUtils.append(consumer, consumers));
|
||||
}
|
||||
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.file;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.file.vo.InfFilePageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.file.impl.InfFileServiceImpl;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.mysql.file.InfFileCoreMapper;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.framework.file.config.FileProperties;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@Import({InfFileServiceImpl.class, FileProperties.class})
|
||||
public class InfFileServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfFileService fileService;
|
||||
|
||||
@MockBean
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@Resource
|
||||
private InfFileCoreMapper fileMapper;
|
||||
|
||||
@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.cloneIgnoreId(dbFile, o -> o.setId("tudou")));
|
||||
// 测试 type 不匹配
|
||||
fileMapper.insert(ObjectUtils.cloneIgnoreId(dbFile, o -> {
|
||||
o.setId("yudao02");
|
||||
o.setType("png");
|
||||
}));
|
||||
// 测试 createTime 不匹配
|
||||
fileMapper.insert(ObjectUtils.cloneIgnoreId(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");
|
||||
}
|
||||
|
||||
}
|
@@ -1,173 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.job;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString;
|
||||
import static cn.iocoder.yudao.framework.common.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.yudao.adminserver.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.log.InfJobLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobLogDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.job.InfJobLogMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.job.InfJobLogStatusEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.job.impl.InfJobLogServiceImpl;
|
||||
import cn.iocoder.yudao.framework.common.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.cloneIgnoreId(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.cloneIgnoreId(dbJobLog, o -> o.setJobId(randomLongId())));
|
||||
// 测试 handlerName 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.cloneIgnoreId(dbJobLog, o -> o.setHandlerName(randomString())));
|
||||
// 测试 beginTime 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.cloneIgnoreId(dbJobLog, o -> o.setBeginTime(buildTime(2021, 1, 7))));
|
||||
// 测试 endTime 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.cloneIgnoreId(dbJobLog, o -> o.setEndTime(buildTime(2021, 1, 9))));
|
||||
// 测试 status 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.cloneIgnoreId(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.cloneIgnoreId(dbJobLog, o -> o.setJobId(randomLongId())));
|
||||
// 测试 handlerName 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.cloneIgnoreId(dbJobLog, o -> o.setHandlerName(randomString())));
|
||||
// 测试 beginTime 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.cloneIgnoreId(dbJobLog, o -> o.setBeginTime(buildTime(2021, 1, 7))));
|
||||
// 测试 endTime 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.cloneIgnoreId(dbJobLog, o -> o.setEndTime(buildTime(2021, 1, 9))));
|
||||
// 测试 status 不匹配
|
||||
jobLogMapper.insert(ObjectUtils.cloneIgnoreId(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));
|
||||
}
|
||||
|
||||
}
|
@@ -1,309 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.job;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.JOB_CHANGE_STATUS_EQUALS;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.JOB_CHANGE_STATUS_INVALID;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.JOB_CRON_EXPRESSION_VALID;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.JOB_HANDLER_EXISTS;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.JOB_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.JOB_UPDATE_ONLY_NORMAL_STATUS;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.framework.test.core.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.yudao.adminserver.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.quartz.core.scheduler.SchedulerManager;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobUpdateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.convert.job.InfJobConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.job.InfJobMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.job.InfJobStatusEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.job.impl.InfJobServiceImpl;
|
||||
import cn.iocoder.yudao.framework.common.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.cloneIgnoreId(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.cloneIgnoreId(dbJob, o -> o.setName("土豆")));
|
||||
// 测试 status 不匹配
|
||||
jobMapper.insert(ObjectUtils.cloneIgnoreId(dbJob, o -> o.setStatus(InfJobStatusEnum.NORMAL.getStatus())));
|
||||
// 测试 handlerName 不匹配
|
||||
jobMapper.insert(ObjectUtils.cloneIgnoreId(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.cloneIgnoreId(dbJob, o -> o.setName("土豆")));
|
||||
// 测试 status 不匹配
|
||||
jobMapper.insert(ObjectUtils.cloneIgnoreId(dbJob, o -> o.setStatus(InfJobStatusEnum.NORMAL.getStatus())));
|
||||
// 测试 handlerName 不匹配
|
||||
jobMapper.insert(ObjectUtils.cloneIgnoreId(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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,153 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.logger;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl.InfApiAccessLogServiceImpl;
|
||||
import cn.iocoder.yudao.framework.test.core.util.RandomUtils;
|
||||
import cn.iocoder.yudao.framework.common.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 static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.common.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 testGetApiAccessLogPage() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "yudao-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.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setBeginTime(buildTime(2021, 2, 6))));
|
||||
// duration 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setDuration(100)));
|
||||
// resultCode 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(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 = "yudao-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.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setBeginTime(buildTime(2021, 2, 6))));
|
||||
// duration 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiAccessLogDO, logDO -> logDO.setDuration(100)));
|
||||
// resultCode 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.cloneIgnoreId(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));
|
||||
}
|
||||
|
||||
}
|
@@ -1,182 +0,0 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.infra.service.logger;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogExportReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.controller.logger.vo.apierrorlog.InfApiErrorLogPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.logger.impl.InfApiErrorLogServiceImpl;
|
||||
import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||
import cn.iocoder.yudao.framework.test.core.util.RandomUtils;
|
||||
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 static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_NOT_FOUND;
|
||||
import static cn.iocoder.yudao.adminserver.modules.infra.enums.InfErrorCodeConstants.API_ERROR_LOG_PROCESSED;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* {@link InfApiErrorLogServiceImpl} 单元测试
|
||||
*/
|
||||
@Import(InfApiErrorLogServiceImpl.class)
|
||||
public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfApiErrorLogService infApiErrorLogServiceImpl;
|
||||
|
||||
@Resource
|
||||
private InfApiErrorLogMapper infApiErrorLogMapper;
|
||||
|
||||
@Test
|
||||
public void testGetApiErrorLogPage() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "yudao-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.cloneIgnoreId(infApiErrorLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiErrorLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiErrorLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiErrorLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiErrorLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiErrorLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiErrorLogDO, logDO -> logDO.setExceptionTime(buildTime(2021, 2, 6))));
|
||||
// progressStatus 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.cloneIgnoreId(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 = "yudao-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.cloneIgnoreId(infApiErrorLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiErrorLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiErrorLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiErrorLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiErrorLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiErrorLogMapper.insert(ObjectUtils.cloneIgnoreId(infApiErrorLogDO, logDO -> logDO.setExceptionTime(buildTime(2021, 2, 6))));
|
||||
// progressStatus 不同的
|
||||
infApiErrorLogMapper.insert(ObjectUtils.cloneIgnoreId(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());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user