潘志宝
2024-12-25 8a6b19bf5c50ebb54e965645a9366f6cfea02351
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.infra.dal.mysql.logger;
H 2
3 import com.iailab.framework.common.pojo.PageResult;
4 import com.iailab.framework.mybatis.core.mapper.BaseMapperX;
5 import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX;
6 import com.iailab.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
7 import com.iailab.module.infra.dal.dataobject.logger.ApiAccessLogDO;
8 import org.apache.ibatis.annotations.Delete;
9 import org.apache.ibatis.annotations.Mapper;
10 import org.apache.ibatis.annotations.Param;
11
12 import java.time.LocalDateTime;
13
14 /**
15  * API 访问日志 Mapper
16  *
17  * @author iailab
18  */
19 @Mapper
20 public interface ApiAccessLogMapper extends BaseMapperX<ApiAccessLogDO> {
21
22     default PageResult<ApiAccessLogDO> selectPage(ApiAccessLogPageReqVO reqVO) {
23         return selectPage(reqVO, new LambdaQueryWrapperX<ApiAccessLogDO>()
24                 .eqIfPresent(ApiAccessLogDO::getUserId, reqVO.getUserId())
25                 .eqIfPresent(ApiAccessLogDO::getUserType, reqVO.getUserType())
26                 .eqIfPresent(ApiAccessLogDO::getApplicationName, reqVO.getApplicationName())
27                 .likeIfPresent(ApiAccessLogDO::getRequestUrl, reqVO.getRequestUrl())
28                 .betweenIfPresent(ApiAccessLogDO::getBeginTime, reqVO.getBeginTime())
29                 .geIfPresent(ApiAccessLogDO::getDuration, reqVO.getDuration())
30                 .eqIfPresent(ApiAccessLogDO::getResultCode, reqVO.getResultCode())
31                 .orderByDesc(ApiAccessLogDO::getId)
32         );
33     }
34
35     /**
36      * 物理删除指定时间之前的日志
37      *
38      * @param createTime 最大时间
39      * @param limit 删除条数,防止一次删除太多
40      * @return 删除条数
41      */
42     @Delete("DELETE FROM infra_api_access_log WHERE create_time < #{createTime} LIMIT #{limit}")
43     Integer deleteByCreateTimeLt(@Param("createTime") LocalDateTime createTime, @Param("limit") Integer limit);
44
45 }