diff --git a/orion-ops-service/src/main/java/com/orion/ops/consts/clear/DataClearRange.java b/orion-ops-service/src/main/java/com/orion/ops/consts/clear/DataClearRange.java new file mode 100644 index 00000000..91299b34 --- /dev/null +++ b/orion-ops-service/src/main/java/com/orion/ops/consts/clear/DataClearRange.java @@ -0,0 +1,48 @@ +package com.orion.ops.consts.clear; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 数据清理区间 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2022/5/24 16:29 + */ +@Getter +@AllArgsConstructor +public enum DataClearRange { + + /** + * 保留天数 + */ + DAY(10), + + /** + * 保留条数 + */ + TOTAL(20), + + /** + * 关联数据 + */ + REL_ID(30), + + ; + + private final Integer range; + + public static DataClearRange of(Integer range) { + if (range == null) { + return null; + } + for (DataClearRange value : values()) { + if (value.range.equals(range)) { + return value; + } + } + return null; + } + +} diff --git a/orion-ops-service/src/main/java/com/orion/ops/consts/event/EventClassify.java b/orion-ops-service/src/main/java/com/orion/ops/consts/event/EventClassify.java index 3cff2fb9..70268e50 100644 --- a/orion-ops-service/src/main/java/com/orion/ops/consts/event/EventClassify.java +++ b/orion-ops-service/src/main/java/com/orion/ops/consts/event/EventClassify.java @@ -114,6 +114,11 @@ public enum EventClassify { */ SYSTEM(95), + /** + * 数据清理 + */ + DATA_CLEAR(97), + /** * 调度操作 */ diff --git a/orion-ops-service/src/main/java/com/orion/ops/consts/event/EventType.java b/orion-ops-service/src/main/java/com/orion/ops/consts/event/EventType.java index f38aa546..6d73e118 100644 --- a/orion-ops-service/src/main/java/com/orion/ops/consts/event/EventType.java +++ b/orion-ops-service/src/main/java/com/orion/ops/consts/event/EventType.java @@ -574,6 +574,49 @@ public enum EventType { */ UPDATE_SYSTEM_OPTION(6120, EventClassify.SYSTEM, "修改系统配置项 ${label} 原始值:${before} 修改为:${after}"), + + // -------------------- 数据清理 -------------------- + + /** + * 清理 批量执行数据 + */ + DATA_CLEAR_BATCH_EXEC(6205, EventClassify.DATA_CLEAR, "清理批量执行数据 ${count}条"), + + /** + * 清理 终端日志 + */ + DATA_CLEAR_TERMINAL_LOG(6210, EventClassify.DATA_CLEAR, "清理终端日志 ${count}条"), + + /** + * 清理 调度记录 + */ + DATA_CLEAR_SCHEDULER_RECORD(6215, EventClassify.DATA_CLEAR, "清理任务调度记录 ${count}条"), + + /** + * 清理 应用构建 + */ + DATA_CLEAR_APP_BUILD(6220, EventClassify.DATA_CLEAR, "清理应用构建任务数据 ${count}条"), + + /** + * 清理 应用发布 + */ + DATA_CLEAR_APP_RELEASE(6225, EventClassify.DATA_CLEAR, "清理应用发布任务数据 ${count}条"), + + /** + * 清理 应用流水线 + */ + DATA_CLEAR_APP_PIPELINE(6230, EventClassify.DATA_CLEAR, "清理应用流水线执行数据 ${count}条"), + + /** + * 清理 站内信 + */ + DATA_CLEAR_WEB_SIDE_MESSAGE(6235, EventClassify.DATA_CLEAR, "清理站内信 ${count}条"), + + /** + * 清理 操作日志 + */ + DATA_CLEAR_EVENT_LOG(6240, EventClassify.DATA_CLEAR, "清理操作日志 ${count}条"), + // -------------------- 调度操作 -------------------- /** diff --git a/orion-ops-service/src/main/java/com/orion/ops/controller/DataClearController.java b/orion-ops-service/src/main/java/com/orion/ops/controller/DataClearController.java new file mode 100644 index 00000000..034be4b2 --- /dev/null +++ b/orion-ops-service/src/main/java/com/orion/ops/controller/DataClearController.java @@ -0,0 +1,144 @@ +package com.orion.ops.controller; + +import com.orion.ops.annotation.EventLog; +import com.orion.ops.annotation.RequireRole; +import com.orion.ops.annotation.RestWrapper; +import com.orion.ops.consts.Const; +import com.orion.ops.consts.clear.DataClearRange; +import com.orion.ops.consts.event.EventType; +import com.orion.ops.consts.user.RoleType; +import com.orion.ops.entity.request.sftp.DataClearRequest; +import com.orion.ops.service.api.DataClearService; +import com.orion.ops.utils.Currents; +import com.orion.ops.utils.Valid; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 数据清理 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2022/5/24 16:50 + */ +@RestController +@RestWrapper +@RequestMapping("/orion/api/data-clear") +public class DataClearController { + + @Resource + private DataClearService dataClearService; + + /** + * 清理 批量执行 + */ + @RequestMapping("/batch-exec") + @EventLog(EventType.DATA_CLEAR_BATCH_EXEC) + public Integer clearBatchExec(@RequestBody DataClearRequest request) { + this.validParams(request); + if (!Currents.isAdministrator()) { + request.setICreated(Const.ENABLE); + } + return dataClearService.clearBatchExec(request); + } + + /** + * 清理 终端日志 + */ + @RequestMapping("/terminal-log") + @RequireRole(RoleType.ADMINISTRATOR) + @EventLog(EventType.DATA_CLEAR_TERMINAL_LOG) + public Integer clearTerminalLog(@RequestBody DataClearRequest request) { + this.validParams(request); + return dataClearService.clearTerminalLog(request); + } + + /** + * 清理 调度记录 + */ + @RequestMapping("/scheduler-record") + @EventLog(EventType.DATA_CLEAR_SCHEDULER_RECORD) + public Integer clearSchedulerRecord(@RequestBody DataClearRequest request) { + this.validParams(request); + return dataClearService.clearSchedulerRecord(request); + } + + /** + * 清理 应用构建 + */ + @RequestMapping("/app-build") + @EventLog(EventType.DATA_CLEAR_APP_BUILD) + public Integer clearAppBuild(@RequestBody DataClearRequest request) { + this.validParams(request); + Valid.notNull(request.getProfileId()); + return dataClearService.clearAppBuild(request); + } + + /** + * 清理 应用发布 + */ + @RequestMapping("/app-release") + @EventLog(EventType.DATA_CLEAR_APP_RELEASE) + public Integer clearAppRelease(@RequestBody DataClearRequest request) { + this.validParams(request); + Valid.notNull(request.getProfileId()); + return dataClearService.clearAppRelease(request); + } + + /** + * 清理 应用流水线 + */ + @RequestMapping("/app-pipeline") + @EventLog(EventType.DATA_CLEAR_APP_PIPELINE) + public Integer clearAppPipeline(@RequestBody DataClearRequest request) { + this.validParams(request); + Valid.notNull(request.getProfileId()); + return dataClearService.clearAppPipeline(request); + } + + /** + * 清理 站内信 + */ + @RequestMapping("/web-side-message") + @EventLog(EventType.DATA_CLEAR_WEB_SIDE_MESSAGE) + public Integer clearWebSideMessage(@RequestBody DataClearRequest request) { + this.validParams(request); + return dataClearService.clearWebSideMessage(request); + } + + /** + * 清理 操作日志 + */ + @RequestMapping("/event-log") + @RequireRole(RoleType.ADMINISTRATOR) + @EventLog(EventType.DATA_CLEAR_EVENT_LOG) + public Integer clearEventLog(@RequestBody DataClearRequest request) { + this.validParams(request); + return dataClearService.clearEventLog(request); + } + + /** + * 验证参数 + * + * @param request request + */ + private void validParams(DataClearRequest request) { + DataClearRange range = Valid.notNull(DataClearRange.of(request.getRange())); + switch (range) { + case DAY: + Valid.gte(request.getReserveDay(), 0); + return; + case TOTAL: + Valid.gte(request.getReserveTotal(), 0); + return; + case REL_ID: + Valid.notEmpty(request.getRelIdList()); + return; + default: + } + } + +} diff --git a/orion-ops-service/src/main/java/com/orion/ops/entity/domain/UserEventLogDO.java b/orion-ops-service/src/main/java/com/orion/ops/entity/domain/UserEventLogDO.java index 3c086275..0784935a 100644 --- a/orion-ops-service/src/main/java/com/orion/ops/entity/domain/UserEventLogDO.java +++ b/orion-ops-service/src/main/java/com/orion/ops/entity/domain/UserEventLogDO.java @@ -1,9 +1,6 @@ package com.orion.ops.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.baomidou.mybatisplus.annotation.*; import lombok.Data; import lombok.EqualsAndHashCode; @@ -80,6 +77,15 @@ public class UserEventLogDO implements Serializable { @TableField("exec_result") private Integer execResult; + /** + * 是否删除 1未删除 2已删除 + * + * @see com.orion.ops.consts.Const#NOT_DELETED + * @see com.orion.ops.consts.Const#IS_DELETED + */ + @TableLogic + private Integer deleted; + /** * 创建时间 */ diff --git a/orion-ops-service/src/main/java/com/orion/ops/entity/request/sftp/DataClearRequest.java b/orion-ops-service/src/main/java/com/orion/ops/entity/request/sftp/DataClearRequest.java new file mode 100644 index 00000000..c1ff5d8a --- /dev/null +++ b/orion-ops-service/src/main/java/com/orion/ops/entity/request/sftp/DataClearRequest.java @@ -0,0 +1,81 @@ +package com.orion.ops.entity.request.sftp; + +import lombok.Data; + +import java.util.List; + +/** + * 数据清理请求 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2022/5/24 16:36 + */ +@Data +public class DataClearRequest { + + /** + * 保留天数 + */ + private Integer reserveDay; + + /** + * 保留条数 + */ + private Integer reserveTotal; + + /** + * 清理区间 + * + * @see com.orion.ops.consts.clear.DataClearRange + */ + private Integer range; + + /** + * 清理的引用id + */ + private List relIdList; + + /** + * 引用id + */ + private Long relId; + + /** + * profile id + */ + private Long profileId; + + /** + * 只清理我创建的 + * + * @see com.orion.ops.consts.Const#ENABLE + * @see com.orion.ops.consts.Const#DISABLE + */ + private Integer iCreated; + + /** + * 只清理我审核的 + * + * @see com.orion.ops.consts.Const#ENABLE + * @see com.orion.ops.consts.Const#DISABLE + */ + private Integer iAudited; + + /** + * 只清理我执行的 + * + * @see com.orion.ops.consts.Const#ENABLE + * @see com.orion.ops.consts.Const#DISABLE + */ + private Integer iExecute; + + /** + * 只清理未读的 + * + * @see com.orion.ops.consts.Const#ENABLE + * @see com.orion.ops.consts.Const#DISABLE + */ + private Integer onlyRead; + +} diff --git a/orion-ops-service/src/main/java/com/orion/ops/handler/app/action/ScpTransferActionHandler.java b/orion-ops-service/src/main/java/com/orion/ops/handler/app/action/ScpTransferActionHandler.java index f1f01254..43e12f34 100644 --- a/orion-ops-service/src/main/java/com/orion/ops/handler/app/action/ScpTransferActionHandler.java +++ b/orion-ops-service/src/main/java/com/orion/ops/handler/app/action/ScpTransferActionHandler.java @@ -58,6 +58,7 @@ public class ScpTransferActionHandler extends AbstractActionHandler { String scpCommand = Strings.def(action.getActionCommand(), CommandConst.SCP_TRANSFER_DEFAULT); Map params = Maps.newMap(); params.put(EnvConst.BUNDLE_PATH, bundlePath); + // 目标文件有空格需要转义空格为 \\ params.put(EnvConst.TRANSFER_PATH, store.getTransferPath().replaceAll(Strings.SPACE, "\\\\\\\\ ")); params.put(EnvConst.TARGET_USERNAME, store.getMachineUsername()); params.put(EnvConst.TARGET_HOST, store.getMachineHost()); diff --git a/orion-ops-service/src/main/java/com/orion/ops/service/api/DataClearService.java b/orion-ops-service/src/main/java/com/orion/ops/service/api/DataClearService.java new file mode 100644 index 00000000..a235396d --- /dev/null +++ b/orion-ops-service/src/main/java/com/orion/ops/service/api/DataClearService.java @@ -0,0 +1,78 @@ +package com.orion.ops.service.api; + +import com.orion.ops.entity.request.sftp.DataClearRequest; + +/** + * 数据清理服务 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2022/5/24 17:01 + */ +public interface DataClearService { + + /** + * 清理 批量执行数据 + * + * @param request request + * @return 删除数量 + */ + Integer clearBatchExec(DataClearRequest request); + + /** + * 清理 终端日志 + * + * @param request request + * @return 删除数量 + */ + Integer clearTerminalLog(DataClearRequest request); + + /** + * 清理 调度记录 + * + * @param request request + * @return 删除数量 + */ + Integer clearSchedulerRecord(DataClearRequest request); + + /** + * 清理 应用构建 + * + * @param request request + * @return 删除数量 + */ + Integer clearAppBuild(DataClearRequest request); + + /** + * 清理 应用发布 + * + * @param request request + * @return 删除数量 + */ + Integer clearAppRelease(DataClearRequest request); + + /** + * 清理 应用流水线 + * + * @param request request + * @return 删除数量 + */ + Integer clearAppPipeline(DataClearRequest request); + + /** + * 清理 站内信 + * + * @param request request + * @return 删除数量 + */ + Integer clearWebSideMessage(DataClearRequest request); + + /** + * 清理 操作日志 + * + * @param request request + * @return 删除数量 + */ + Integer clearEventLog(DataClearRequest request); + +} diff --git a/orion-ops-service/src/main/java/com/orion/ops/service/impl/DataClearServiceImpl.java b/orion-ops-service/src/main/java/com/orion/ops/service/impl/DataClearServiceImpl.java new file mode 100644 index 00000000..d4d8bf80 --- /dev/null +++ b/orion-ops-service/src/main/java/com/orion/ops/service/impl/DataClearServiceImpl.java @@ -0,0 +1,290 @@ +package com.orion.ops.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import com.orion.ops.consts.Const; +import com.orion.ops.consts.app.BuildStatus; +import com.orion.ops.consts.app.PipelineStatus; +import com.orion.ops.consts.app.ReleaseStatus; +import com.orion.ops.consts.clear.DataClearRange; +import com.orion.ops.consts.command.ExecStatus; +import com.orion.ops.consts.event.EventKeys; +import com.orion.ops.consts.event.EventParamsHolder; +import com.orion.ops.consts.message.ReadStatus; +import com.orion.ops.consts.scheduler.SchedulerTaskStatus; +import com.orion.ops.dao.*; +import com.orion.ops.entity.domain.*; +import com.orion.ops.entity.request.sftp.DataClearRequest; +import com.orion.ops.service.api.DataClearService; +import com.orion.ops.utils.Currents; +import com.orion.utils.time.Dates; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; + +/** + * 数据清理服务实现 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2022/5/24 17:04 + */ +@Service("dataClearService") +public class DataClearServiceImpl implements DataClearService { + + @Resource + private CommandExecDAO commandExecDAO; + + @Resource + private MachineTerminalLogDAO machineTerminalLogDAO; + + @Resource + private SchedulerTaskRecordDAO schedulerTaskRecordDAO; + + @Resource + private ApplicationBuildDAO applicationBuildDAO; + + @Resource + private ApplicationReleaseDAO applicationReleaseDAO; + + @Resource + private ApplicationPipelineTaskDAO applicationPipelineTaskDAO; + + @Resource + private WebSideMessageDAO webSideMessageDAO; + + @Resource + private UserEventLogDAO userEventLogDAO; + + @Override + public Integer clearBatchExec(DataClearRequest request) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .ne(CommandExecDO::getExecStatus, ExecStatus.RUNNABLE.getStatus()) + .eq(Const.ENABLE.equals(request.getICreated()), CommandExecDO::getUserId, Currents.getUserId()); + // 设置删除筛选条件 + this.setDeleteWrapper(commandExecDAO, wrapper, + CommandExecDO::getId, + CommandExecDO::getCreateTime, + CommandExecDO::getMachineId, + request); + int count = commandExecDAO.delete(wrapper); + // 设置日志参数 + EventParamsHolder.addParams(request); + EventParamsHolder.addParam(EventKeys.COUNT, count); + return count; + } + + @Override + public Integer clearTerminalLog(DataClearRequest request) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + // 设置删除筛选条件 + this.setDeleteWrapper(machineTerminalLogDAO, wrapper, + MachineTerminalLogDO::getId, + MachineTerminalLogDO::getCreateTime, + MachineTerminalLogDO::getMachineId, + request); + int count = machineTerminalLogDAO.delete(wrapper); + // 设置日志参数 + EventParamsHolder.addParams(request); + EventParamsHolder.addParam(EventKeys.COUNT, count); + return count; + } + + @Override + public Integer clearSchedulerRecord(DataClearRequest request) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .ne(SchedulerTaskRecordDO::getTaskStatus, SchedulerTaskStatus.RUNNABLE.getStatus()) + .eq(SchedulerTaskRecordDO::getTaskId, request.getRelId()); + // 设置删除筛选条件 + this.setDeleteWrapper(schedulerTaskRecordDAO, wrapper, + SchedulerTaskRecordDO::getId, + SchedulerTaskRecordDO::getCreateTime, + SchedulerTaskRecordDO::getTaskId, + request); + int count = schedulerTaskRecordDAO.delete(wrapper); + // 设置日志参数 + EventParamsHolder.addParams(request); + EventParamsHolder.addParam(EventKeys.COUNT, count); + return count; + } + + @Override + public Integer clearAppBuild(DataClearRequest request) { + Long userId = Currents.getUserId(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .ne(ApplicationBuildDO::getBuildStatus, BuildStatus.RUNNABLE.getStatus()) + .eq(ApplicationBuildDO::getProfileId, request.getProfileId()) + .eq(Const.ENABLE.equals(request.getICreated()), ApplicationBuildDO::getCreateUserId, userId); + // 设置筛选条件 + this.setDeleteWrapper(applicationBuildDAO, wrapper, + ApplicationBuildDO::getId, + ApplicationBuildDO::getCreateTime, + ApplicationBuildDO::getAppId, + request); + int count = applicationBuildDAO.delete(wrapper); + // 设置日志参数 + EventParamsHolder.addParams(request); + EventParamsHolder.addParam(EventKeys.COUNT, count); + return count; + } + + @Override + public Integer clearAppRelease(DataClearRequest request) { + Long userId = Currents.getUserId(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .ne(ApplicationReleaseDO::getReleaseStatus, ReleaseStatus.RUNNABLE.getStatus()) + .eq(ApplicationReleaseDO::getProfileId, request.getProfileId()) + .eq(Const.ENABLE.equals(request.getICreated()), ApplicationReleaseDO::getCreateUserId, userId) + .eq(Const.ENABLE.equals(request.getIAudited()), ApplicationReleaseDO::getAuditUserId, userId) + .eq(Const.ENABLE.equals(request.getIExecute()), ApplicationReleaseDO::getReleaseUserId, userId); + // 设置筛选条件 + this.setDeleteWrapper(applicationReleaseDAO, wrapper, + ApplicationReleaseDO::getId, + ApplicationReleaseDO::getCreateTime, + ApplicationReleaseDO::getAppId, + request); + int count = applicationReleaseDAO.delete(wrapper); + // 设置日志参数 + EventParamsHolder.addParams(request); + EventParamsHolder.addParam(EventKeys.COUNT, count); + return count; + } + + @Override + public Integer clearAppPipeline(DataClearRequest request) { + Long userId = Currents.getUserId(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .ne(ApplicationPipelineTaskDO::getExecStatus, PipelineStatus.RUNNABLE.getStatus()) + .eq(ApplicationPipelineTaskDO::getProfileId, request.getProfileId()) + .eq(Const.ENABLE.equals(request.getICreated()), ApplicationPipelineTaskDO::getCreateUserId, userId) + .eq(Const.ENABLE.equals(request.getIAudited()), ApplicationPipelineTaskDO::getAuditUserId, userId) + .eq(Const.ENABLE.equals(request.getIExecute()), ApplicationPipelineTaskDO::getExecUserId, userId); + // 设置筛选条件 + this.setDeleteWrapper(applicationPipelineTaskDAO, wrapper, + ApplicationPipelineTaskDO::getId, + ApplicationPipelineTaskDO::getCreateTime, + ApplicationPipelineTaskDO::getPipelineId, + request); + int count = applicationPipelineTaskDAO.delete(wrapper); + // 设置日志参数 + EventParamsHolder.addParams(request); + EventParamsHolder.addParam(EventKeys.COUNT, count); + return count; + } + + @Override + public Integer clearWebSideMessage(DataClearRequest request) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .eq(WebSideMessageDO::getToUserId, Currents.getUserId()) + .eq(Const.ENABLE.equals(request.getOnlyRead()), WebSideMessageDO::getReadStatus, ReadStatus.READ.getStatus()); + // 设置删除筛选条件 + this.setDeleteWrapper(webSideMessageDAO, wrapper, + WebSideMessageDO::getId, + WebSideMessageDO::getCreateTime, + WebSideMessageDO::getMessageClassify, + request); + int count = webSideMessageDAO.delete(wrapper); + // 设置日志参数 + EventParamsHolder.addParams(request); + EventParamsHolder.addParam(EventKeys.COUNT, count); + return count; + } + + @Override + public Integer clearEventLog(DataClearRequest request) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .eq(UserEventLogDO::getExecResult, Const.ENABLE); + // 设置删除筛选条件 + this.setDeleteWrapper(userEventLogDAO, wrapper, + UserEventLogDO::getId, + UserEventLogDO::getCreateTime, + UserEventLogDO::getEventClassify, + request); + int count = userEventLogDAO.delete(wrapper); + // 设置日志参数 + EventParamsHolder.addParams(request); + EventParamsHolder.addParam(EventKeys.COUNT, count); + return count; + } + + /** + * 设置删除的筛选条件 + * + * @param mapper mapper + * @param wrapper wrapper + * @param idGetterFun idGetterFun + * @param dateGetterFun dateGetterFun + * @param relGetterFun relGetterFun + * @param request request + * @param + */ + private void setDeleteWrapper(BaseMapper mapper, + LambdaQueryWrapper wrapper, + SFunction idGetterFun, + SFunction dateGetterFun, + SFunction relGetterFun, + DataClearRequest request) { + if (DataClearRange.DAY.getRange().equals(request.getRange())) { + // 仅保留几天 + Integer day = request.getReserveDay(); + if (!day.equals(0)) { + this.setReverseDateWhere(wrapper, dateGetterFun, day); + } + } else if (DataClearRange.TOTAL.getRange().equals(request.getRange())) { + // 保留几条 + Integer total = request.getReserveTotal(); + if (!total.equals(0)) { + this.setReverseTotalWhere(mapper, wrapper, idGetterFun, total); + } + } else if (DataClearRange.REL_ID.getRange().equals(request.getRange())) { + // 删除机器id + wrapper.in(relGetterFun, request.getRelIdList()); + } + } + + /** + * 设置保留多少天的筛选条件 + * + * @param wrapper wrapper + * @param dateGetterFun dateGetterFun + * @param day day + * @param T + */ + private void setReverseDateWhere(LambdaQueryWrapper wrapper, + SFunction dateGetterFun, + Integer day) { + Date lessDayDate = Dates.stream().subDay(day).get(); + wrapper.lt(dateGetterFun, lessDayDate); + } + + /** + * 设置保留条数的筛选条件 + * + * @param mapper mapper + * @param wrapper wrapper + * @param idGetterFun idGetterFun + * @param total total + * @param T + */ + private void setReverseTotalWhere(BaseMapper mapper, + LambdaQueryWrapper wrapper, + SFunction idGetterFun, + Integer total) { + // 查询删除的最大id + LambdaQueryWrapper maxIdWrapper = wrapper.clone() + .orderByDesc(idGetterFun) + .last(Const.LIMIT + Const.SPACE + total + ", 1"); + T maxEntity = mapper.selectOne(maxIdWrapper); + // 未查询到则代表条数不满足, 设置一个 false 条件 从而达到不执行的目的 + if (maxEntity == null) { + wrapper.eq(idGetterFun, Const.N_N_L_1); + return; + } + Long maxId = idGetterFun.apply(maxEntity); + // 设置最大id阈值 + wrapper.le(idGetterFun, maxId); + } + +} diff --git a/orion-ops-service/src/main/java/com/orion/ops/utils/Currents.java b/orion-ops-service/src/main/java/com/orion/ops/utils/Currents.java index ce4628ab..c9db733a 100644 --- a/orion-ops-service/src/main/java/com/orion/ops/utils/Currents.java +++ b/orion-ops-service/src/main/java/com/orion/ops/utils/Currents.java @@ -1,9 +1,12 @@ package com.orion.ops.utils; +import com.orion.lang.wrapper.HttpWrapper; import com.orion.ops.consts.Const; +import com.orion.ops.consts.ResultCode; import com.orion.ops.consts.user.RoleType; import com.orion.ops.consts.user.UserHolder; import com.orion.ops.entity.dto.UserDTO; +import com.orion.utils.Exceptions; import javax.servlet.http.HttpServletRequest; import java.util.Optional; @@ -88,4 +91,13 @@ public class Currents { return RoleType.isAdministrator(roleType); } + /** + * 检查是否为管理员权限 + */ + public static void requireAdministrator() { + if (!isAdministrator()) { + throw Exceptions.httpWrapper(HttpWrapper.of(ResultCode.NO_PERMISSION)); + } + } + } diff --git a/orion-ops-service/src/main/resources/mapper/UserEventLogMapper.xml b/orion-ops-service/src/main/resources/mapper/UserEventLogMapper.xml index 6a65cec6..5718d1b7 100644 --- a/orion-ops-service/src/main/resources/mapper/UserEventLogMapper.xml +++ b/orion-ops-service/src/main/resources/mapper/UserEventLogMapper.xml @@ -12,12 +12,13 @@ + - id, user_id, username, event_classify, event_type, log_info, params_json, exec_result, create_time + id, user_id, username, event_classify, event_type, log_info, params_json, exec_result, deleted, create_time