🔨 批量执行日志.

This commit is contained in:
lijiahang
2024-03-11 11:42:34 +08:00
parent f4c5517f9f
commit 67e434dc2f
12 changed files with 595 additions and 4 deletions

View File

@@ -45,11 +45,9 @@ public class CodeGenerators {
// .color("blue", "gray", "red", "green", "white")
// .valueUseFields()
// .build(),
Template.create("exec_template", "执行模板", "exec")
Template.create("exec_log", "执行日志", "exec")
.disableUnitTest()
.cache("exec:template:list", "执行模板列表")
.expire(1, TimeUnit.DAYS)
.vue("exec", "exec-template")
.vue("exec", "exec-log")
.enableDrawerForm()
.build(),
};

View File

@@ -0,0 +1,93 @@
### 创建执行日志
POST {{baseUrl}}/asset/exec-log/create
Content-Type: application/json
Authorization: {{token}}
{
"userId": "",
"source": "",
"sourceId": "",
"desc": "",
"command": "",
"status": "",
"startTime": "",
"finishTime": ""
}
### 更新执行日志
PUT {{baseUrl}}/asset/exec-log/update
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"userId": "",
"source": "",
"sourceId": "",
"desc": "",
"command": "",
"status": "",
"startTime": "",
"finishTime": ""
}
### 查询执行日志
GET {{baseUrl}}/asset/exec-log/get?id=1
Authorization: {{token}}
### 批量查询执行日志
GET {{baseUrl}}/asset/exec-log/batch-get?idList=1,2,3
Authorization: {{token}}
### 查询全部执行日志
POST {{baseUrl}}/asset/exec-log/list
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"userId": "",
"source": "",
"sourceId": "",
"desc": "",
"command": "",
"status": "",
"startTime": "",
"finishTime": ""
}
### 分页查询执行日志
POST {{baseUrl}}/asset/exec-log/query
Content-Type: application/json
Authorization: {{token}}
{
"page": 1,
"limit": 10,
"id": "",
"userId": "",
"source": "",
"sourceId": "",
"desc": "",
"command": "",
"status": "",
"startTime": "",
"finishTime": ""
}
### 删除执行日志
DELETE {{baseUrl}}/asset/exec-log/delete?id=1
Authorization: {{token}}
### 批量删除执行日志
DELETE {{baseUrl}}/asset/exec-log/batch-delete?idList=1,2,3
Authorization: {{token}}
###

View File

@@ -0,0 +1,79 @@
package com.orion.ops.module.asset.controller;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
import com.orion.ops.framework.common.validator.group.Page;
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
import com.orion.ops.framework.web.core.annotation.RestWrapper;
import com.orion.ops.module.asset.define.operator.ExecLogOperatorType;
import com.orion.ops.module.asset.entity.request.exec.ExecLogQueryRequest;
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
import com.orion.ops.module.asset.service.ExecLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 执行日志 api
*
* @author Jiahang Li
* @version 1.0.1
* @since 2024-3-11 11:31
*/
@Tag(name = "asset - 执行日志服务")
@Slf4j
@Validated
@RestWrapper
@RestController
@RequestMapping("/asset/exec-log")
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
public class ExecLogController {
@Resource
private ExecLogService execLogService;
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/get")
@Operation(summary = "查询执行日志")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-log:query')")
public ExecLogVO getExecLog(@RequestParam("id") Long id) {
return execLogService.getExecLogById(id);
}
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/query")
@Operation(summary = "分页查询执行日志")
@PreAuthorize("@ss.hasPermission('asset:exec-log:query')")
public DataGrid<ExecLogVO> getExecLogPage(@Validated(Page.class) @RequestBody ExecLogQueryRequest request) {
return execLogService.getExecLogPage(request);
}
@OperatorLog(ExecLogOperatorType.DELETE)
@DeleteMapping("/delete")
@Operation(summary = "删除执行日志")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-log:delete')")
public Integer deleteExecLog(@RequestParam("id") Long id) {
return execLogService.deleteExecLogById(id);
}
@OperatorLog(ExecLogOperatorType.DELETE)
@DeleteMapping("/batch-delete")
@Operation(summary = "批量删除执行日志")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-log:delete')")
public Integer batchDeleteExecLog(@RequestParam("idList") List<Long> idList) {
return execLogService.deleteExecLogByIdList(idList);
}
}

View File

@@ -0,0 +1,29 @@
package com.orion.ops.module.asset.convert;
import com.orion.ops.module.asset.entity.domain.ExecLogDO;
import com.orion.ops.module.asset.entity.request.exec.ExecLogQueryRequest;
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 执行日志 内部对象转换器
*
* @author Jiahang Li
* @version 1.0.1
* @since 2024-3-11 11:31
*/
@Mapper
public interface ExecLogConvert {
ExecLogConvert MAPPER = Mappers.getMapper(ExecLogConvert.class);
ExecLogDO to(ExecLogQueryRequest request);
ExecLogVO to(ExecLogDO domain);
List<ExecLogVO> to(List<ExecLogDO> list);
}

View File

@@ -0,0 +1,17 @@
package com.orion.ops.module.asset.dao;
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
import com.orion.ops.module.asset.entity.domain.ExecLogDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 执行日志 Mapper 接口
*
* @author Jiahang Li
* @version 1.0.1
* @since 2024-3-11 11:31
*/
@Mapper
public interface ExecLogDAO extends IMapper<ExecLogDO> {
}

View File

@@ -0,0 +1,28 @@
package com.orion.ops.module.asset.define.operator;
import com.orion.ops.framework.biz.operator.log.core.annotation.Module;
import com.orion.ops.framework.biz.operator.log.core.factory.InitializingOperatorTypes;
import com.orion.ops.framework.biz.operator.log.core.model.OperatorType;
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.H;
/**
* 执行日志 操作日志类型
*
* @author Jiahang Li
* @version 1.0.1
* @since 2024-3-11 11:31
*/
@Module("asset:exec-log")
public class ExecLogOperatorType extends InitializingOperatorTypes {
public static final String DELETE = "exec-log:delete";
@Override
public OperatorType[] types() {
return new OperatorType[]{
new OperatorType(H, DELETE, "删除执行日志"),
};
}
}

View File

@@ -0,0 +1,67 @@
package com.orion.ops.module.asset.entity.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.Date;
/**
* 执行日志 实体对象
*
* @author Jiahang Li
* @version 1.0.1
* @since 2024-3-11 11:31
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "exec_log", autoResultMap = true)
@Schema(name = "ExecLogDO", description = "执行日志 实体对象")
public class ExecLogDO extends BaseDO {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@Schema(description = "执行用户id")
@TableField("user_id")
private Long userId;
@Schema(description = "执行来源")
@TableField("source")
private String source;
@Schema(description = "执行来源id")
@TableField("source_id")
private Long sourceId;
@Schema(description = "执行描述")
@TableField("desc")
private String desc;
@Schema(description = "执行命令")
@TableField("command")
private String command;
@Schema(description = "执行状态")
@TableField("status")
private String status;
@Schema(description = "执行开始时间")
@TableField("start_time")
private Date startTime;
@Schema(description = "执行完成时间")
@TableField("finish_time")
private Date finishTime;
}

View File

@@ -0,0 +1,54 @@
package com.orion.ops.module.asset.entity.request.exec;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.orion.ops.framework.common.entity.PageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.Size;
import java.util.Date;
/**
* 执行日志 查询请求对象
*
* @author Jiahang Li
* @version 1.0.1
* @since 2024-3-11 11:31
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "ExecLogQueryRequest", description = "执行日志 查询请求对象")
public class ExecLogQueryRequest extends PageRequest {
@Schema(description = "id")
private Long id;
@Schema(description = "执行用户id")
private Long userId;
@Size(max = 12)
@Schema(description = "执行来源")
private String source;
@Schema(description = "执行来源id")
private Long sourceId;
@Size(max = 128)
@Schema(description = "执行描述")
private String desc;
@Schema(description = "执行命令")
private String command;
@Size(max = 12)
@Schema(description = "执行状态")
private String status;
@Schema(description = "开始时间-区间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date[] startTimeRange;
}

View File

@@ -0,0 +1,55 @@
package com.orion.ops.module.asset.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
* 执行日志 视图响应对象
*
* @author Jiahang Li
* @version 1.0.1
* @since 2024-3-11 11:31
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "ExecLogVO", description = "执行日志 视图响应对象")
public class ExecLogVO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
private Long id;
@Schema(description = "执行用户id")
private Long userId;
@Schema(description = "执行来源")
private String source;
@Schema(description = "执行来源id")
private Long sourceId;
@Schema(description = "执行描述")
private String desc;
@Schema(description = "执行命令")
private String command;
@Schema(description = "执行状态")
private String status;
@Schema(description = "执行开始时间")
private Date startTime;
@Schema(description = "执行完成时间")
private Date finishTime;
}

View File

@@ -0,0 +1,50 @@
package com.orion.ops.module.asset.service;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.module.asset.entity.request.exec.ExecLogQueryRequest;
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
import java.util.List;
/**
* 执行日志 服务类
*
* @author Jiahang Li
* @version 1.0.1
* @since 2024-3-11 11:31
*/
public interface ExecLogService {
/**
* 查询执行日志
*
* @param id id
* @return row
*/
ExecLogVO getExecLogById(Long id);
/**
* 分页查询执行日志
*
* @param request request
* @return rows
*/
DataGrid<ExecLogVO> getExecLogPage(ExecLogQueryRequest request);
/**
* 删除执行日志
*
* @param id id
* @return effect
*/
Integer deleteExecLogById(Long id);
/**
* 批量删除执行日志
*
* @param idList idList
* @return effect
*/
Integer deleteExecLogByIdList(List<Long> idList);
}

View File

@@ -0,0 +1,93 @@
package com.orion.ops.module.asset.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.Arrays1;
import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.module.asset.convert.ExecLogConvert;
import com.orion.ops.module.asset.dao.ExecLogDAO;
import com.orion.ops.module.asset.entity.domain.ExecLogDO;
import com.orion.ops.module.asset.entity.request.exec.ExecLogQueryRequest;
import com.orion.ops.module.asset.entity.vo.ExecLogVO;
import com.orion.ops.module.asset.service.ExecLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 执行日志 服务实现类
*
* @author Jiahang Li
* @version 1.0.1
* @since 2024-3-11 11:31
*/
@Slf4j
@Service
public class ExecLogServiceImpl implements ExecLogService {
@Resource
private ExecLogDAO execLogDAO;
@Override
public ExecLogVO getExecLogById(Long id) {
// 查询
ExecLogDO record = execLogDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 转换
return ExecLogConvert.MAPPER.to(record);
}
@Override
public DataGrid<ExecLogVO> getExecLogPage(ExecLogQueryRequest request) {
// 条件
LambdaQueryWrapper<ExecLogDO> wrapper = this.buildQueryWrapper(request);
// 查询
return execLogDAO.of(wrapper)
.page(request)
.dataGrid(ExecLogConvert.MAPPER::to);
}
@Override
public Integer deleteExecLogById(Long id) {
log.info("ExecLogService-deleteExecLogById id: {}", id);
// 检查数据是否存在
ExecLogDO record = execLogDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 删除
int effect = execLogDAO.deleteById(id);
log.info("ExecLogService-deleteExecLogById id: {}, effect: {}", id, effect);
return effect;
}
@Override
public Integer deleteExecLogByIdList(List<Long> idList) {
log.info("ExecLogService-deleteExecLogByIdList idList: {}", idList);
int effect = execLogDAO.deleteBatchIds(idList);
log.info("ExecLogService-deleteExecLogByIdList effect: {}", effect);
return effect;
}
/**
* 构建查询 wrapper
*
* @param request request
* @return wrapper
*/
private LambdaQueryWrapper<ExecLogDO> buildQueryWrapper(ExecLogQueryRequest request) {
return execLogDAO.wrapper()
.eq(ExecLogDO::getId, request.getId())
.eq(ExecLogDO::getUserId, request.getUserId())
.eq(ExecLogDO::getSource, request.getSource())
.eq(ExecLogDO::getSourceId, request.getSourceId())
.eq(ExecLogDO::getDesc, request.getDesc())
.eq(ExecLogDO::getCommand, request.getCommand())
.eq(ExecLogDO::getStatus, request.getStatus())
.ge(ExecLogDO::getStartTime, Arrays1.getIfPresent(request.getStartTimeRange(), 0))
.le(ExecLogDO::getStartTime, Arrays1.getIfPresent(request.getStartTimeRange(), 1))
.orderByDesc(ExecLogDO::getId);
}
}

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.orion.ops.module.asset.dao.ExecLogDAO">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.orion.ops.module.asset.entity.domain.ExecLogDO">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="source" property="source"/>
<result column="source_id" property="sourceId"/>
<result column="desc" property="desc"/>
<result column="command" property="command"/>
<result column="status" property="status"/>
<result column="start_time" property="startTime"/>
<result column="finish_time" property="finishTime"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="creator" property="creator"/>
<result column="updater" property="updater"/>
<result column="deleted" property="deleted"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, user_id, source, source_id, desc, command, status, start_time, finish_time, create_time, update_time, creator, updater, deleted
</sql>
</mapper>