package com.muyu.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.web.page.PageQueryModel;
import com.muyu.common.system.domain.SysLogininfor;
import com.muyu.common.system.domain.SysOperLog;
import com.muyu.system.domain.model.SysOperlogPageQueryModel;
import com.muyu.system.mapper.SysOperLogMapper;
import com.muyu.system.service.SysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 操作日志 服务层处理
 *
 * @author muyu
 */
@Service
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements SysOperLogService {
    @Autowired
    private SysOperLogMapper operLogMapper;

    /**
     * 新增操作日志
     *
     * @param operLog 操作日志对象
     *
     * @return 结果
     */
    @Override
    public int insertOperlog (SysOperLog operLog) {
        return operLogMapper.insertOperlog(operLog);
    }

    /**
     * 查询系统操作日志集合
     *
     * @param operLog 操作日志对象
     *
     * @return 操作日志集合
     */
    @Override
    public List<SysOperLog> selectOperLogList (SysOperLog operLog) {
        return operLogMapper.selectOperLogList(operLog);
    }

    /**
     * 批量删除系统操作日志
     *
     * @param operIds 需要删除的操作日志ID
     *
     * @return 结果
     */
    @Override
    public int deleteOperLogByIds (Long[] operIds) {
        return operLogMapper.deleteOperLogByIds(operIds);
    }

    /**
     * 查询操作日志详细
     *
     * @param operId 操作ID
     *
     * @return 操作日志对象
     */
    @Override
    public SysOperLog selectOperLogById (Long operId) {
        return operLogMapper.selectOperLogById(operId);
    }

    /**
     * 清空操作日志
     */
    @Override
    public void cleanOperLog () {
        operLogMapper.cleanOperLog();
    }

    @Override
    public PageQueryModel<SysOperLog> pageQuery(SysOperlogPageQueryModel sysOperlogPageQueryModel) {
        LambdaQueryWrapper<SysOperLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(sysOperlogPageQueryModel.getOperIp()),SysOperLog::getOperIp, sysOperlogPageQueryModel.getOperIp());
        queryWrapper.like(StringUtils.isNotEmpty(sysOperlogPageQueryModel.getTitle()),SysOperLog::getTitle, sysOperlogPageQueryModel.getTitle());
        queryWrapper.like(StringUtils.isNotEmpty(sysOperlogPageQueryModel.getOperName()),SysOperLog::getOperName, sysOperlogPageQueryModel.getOperName());
        queryWrapper.eq(Objects.nonNull(sysOperlogPageQueryModel.getBusinessType()),SysOperLog::getBusinessType, sysOperlogPageQueryModel.getBusinessType());
        queryWrapper.eq(Objects.nonNull(sysOperlogPageQueryModel.getStatus()),SysOperLog::getStatus, sysOperlogPageQueryModel.getStatus());
        queryWrapper.gt(Objects.nonNull(sysOperlogPageQueryModel.getBeginTime()),SysOperLog::getOperTime, sysOperlogPageQueryModel.getBeginTime());
        queryWrapper.lt(Objects.nonNull(sysOperlogPageQueryModel.getEndTime()),SysOperLog::getOperTime, sysOperlogPageQueryModel.getEndTime());
        Page<SysOperLog> page = this.page(sysOperlogPageQueryModel.buildPage(), queryWrapper);
        return PageQueryModel.of(page);
    }
}
