SystemLogMapper.java 3.77 KB
package com.uccc.log.mapper;

import com.uccc.pretty.common.SystemLog;
import com.uccc.pretty.common.SystemLogEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created by bert on 2021-09-15 13:20
 */
public interface SystemLogMapper {

    static final String TABLE_NAME = "system_log";

    @Insert({
            "<script>",
            "insert into " + TABLE_NAME,
            "(",
            "cts",
            "<when test='systemLog.operatorId!=null'>",
            ",operator_id",
            "</when>",
            "<when test='systemLog.action!=null'>",
            ",action",
            "</when>",
            "<when test='systemLog.remark!=null'>",
            ",remark",
            "</when>",
            "<when test='systemLog.extra!=null'>",
            ",extra",
            "</when>",
            "<when test='systemLog.ip!=null'>",
            ",ip",
            "</when>",
            ")",
            "values",
            "(",
            "#{systemLog.cts}",
            "<when test='systemLog.operatorId!=null'>",
            ",#{systemLog.operatorId}",
            "</when>",
            "<when test='systemLog.action!=null'>",
            ",#{systemLog.action}",
            "</when>",
            "<when test='systemLog.remark!=null'>",
            ",#{systemLog.remark}",
            "</when>",
            "<when test='systemLog.extra!=null'>",
            ",#{systemLog.extra}",
            "</when>",
            "<when test='systemLog.ip!=null'>",
            ",#{systemLog.ip}",
            "</when>",

            ")",
            "</script>"
    })
    int insertLog(@Param("systemLog") SystemLog systemLog);


    @Select({
            "<script>",
            "SELECT s.operator_id as operator_id, s.action as action, s.cts as cts,s.remark as remark,s.ip as ip, s.extra as extra, u.name as name,u.phone as phone, u.admin_level as admin_level from system_log s left JOIN users u on s.operator_id = u.id",
            "where 1=1",
            "<when test='endTime!=null'>",
            "and cts between #{startTime} and #{endTime}",
            "</when>",
            "<when test='ip!=null'>",
            "and ip = #{ip}",
            "</when>",
            "<when test='action!=null'>",
            "and action = #{action}",
            "</when>",
            "<when test='operator!=null'>",
            "and operator_id = #{operator}",
            "</when>",
            "order by cts desc",
            "limit #{limit}",
            "offset #{page}-1",
            "</script>"
    })
    List<SystemLogEntity> selectSysLogByCondition(@Param("limit") Integer limit, @Param("page")Integer page,
                                                  @Param("operator")Long operator, @Param("action")String action, @Param("ip")String ip,
                                                  @Param("startTime")String startTime, @Param("endTime")String endTime);


    @Select({
            "<script>",
            "SELECT count(*) from system_log s left JOIN users u on s.operator_id = u.id",
            "where 1=1",
            "<when test='endTime!=null'>",
            "and cts between #{startTime} and #{endTime}",
            "</when>",
            "<when test='ip!=null'>",
            "and ip = #{ip}",
            "</when>",
            "<when test='action!=null'>",
            "and action = #{action}",
            "</when>",
            "<when test='operator!=null'>",
            "and operator_id = #{operator}",
            "</when>",
            "</script>"
    })
    int selectSysLogCountByCondition(@Param("operator")Long operator, @Param("action")String action, @Param("ip")String ip,
                                     @Param("startTime")String startTime, @Param("endTime")String endTime);
}