ShyLogServiceImpl.java 2.39 KB
package com.cnlive.shenhe.service.serviceImpl;

import com.alibaba.fastjson.JSON;
import com.cnlive.shenhe.dto.ShyLogDTO;
import com.cnlive.shenhe.entity.ShyLog;
import com.cnlive.shenhe.mapper.ShyLogMapper;
import com.cnlive.shenhe.service.ShyLogService;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author 王言钊
 * @author shkstart
 * @create 2022-05-16 11:09
 */
@Service
public class ShyLogServiceImpl implements ShyLogService {

    private static Logger logger = LoggerFactory.getLogger(ShyLogServiceImpl.class);

    @Autowired
    private ShyLogMapper shyLogMapper;

    /**
     * 查询所有的日志
     *
     * @return
     */
    @Override
    public PageInfo<ShyLog> selectByExample(ShyLogDTO shyLogDTO) {
        logger.info("进入日志查询方法,参数接受对象为,ShyLogDTO:{}", JSON.toJSONString(shyLogDTO));
        Example example = new Example(ShyLog.class);
        //如果为空 按照倒序排序  分页查询所有
        //以创建时间为条件进行倒序
        Example.Criteria criteria = example.createCriteria();
        Example.Criteria criteria2 = example.createCriteria();
        example.setOrderByClause("`operation_time` desc");
        // 如果查询条件不为空  按照条件走模糊查询
        if (CommonUtils.isNotEmpty(shyLogDTO.getKeyword())) {
            criteria.andLike("videoId", "%" + shyLogDTO.getKeyword() + "%");
            criteria2.andLike("operator", "%" + shyLogDTO.getKeyword() + "%");
            example.or(criteria2);
        }
        PageHelper.startPage(shyLogDTO.getPageNum(), shyLogDTO.getPageSize());
        List<ShyLog> shyLogs = shyLogMapper.selectByExample(example);
        PageInfo<ShyLog> shyLogPageInfo = new PageInfo<>(shyLogs);
        return shyLogPageInfo;
    }

    /**
     * 添加日志记录
     *
     * @param shyLog
     * @return
     */
    @Override
    public Boolean addShyLog(ShyLog shyLog) {
        logger.info("进入日志添加方法 接受日志对象为,ShyLog:{}", JSON.toJSONString(shyLog));
        int result = shyLogMapper.insertSelective(shyLog);
        return result > 0;
    }
}