package com.xunmei.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xunmei.common.core.utils.DateUtils;
import com.xunmei.common.core.web.page.TableDataInfo;
import com.xunmei.system.api.domain.SysArea;
import com.xunmei.system.api.domain.SysDictData;
import com.xunmei.system.api.domain.SysDictType;
import com.xunmei.system.api.domain.SysLogininfor;
import com.xunmei.system.mapper.SysDictTypeMapper;
import com.xunmei.system.mapper.SysLogininforMapper;
import com.xunmei.system.service.ISysLogininforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统访问日志情况信息 服务层处理
 *
 * @author xunmei
 */
@Service
public class SysLogininforServiceImpl extends ServiceImpl<SysLogininforMapper, SysLogininfor> implements ISysLogininforService {

    @Autowired
    private SysLogininforMapper logininforMapper;

    @Override
    public TableDataInfo<SysLogininfor> selectPage(SysLogininfor logininfor) {
        Page<SysLogininfor> page;
        if (logininfor.getPageNum() != null && logininfor.getPageSize() != null) {
            page = new Page<>(logininfor.getPageNum(), logininfor.getPageSize());
        } else {
            page = new Page<>();
        }

        QueryWrapper<SysLogininfor> where = new QueryWrapper<>(logininfor);
        Object beginTime = logininfor.getParams().get("beginTime");
        Object endTime = logininfor.getParams().get("endTime");
        if(beginTime != null){
            where.lambda().ge(SysLogininfor::getAccessTime, DateUtils.parseDate(beginTime));
        }
        if(endTime != null){
            where.lambda().le(SysLogininfor::getAccessTime, DateUtils.parseDate(endTime));
        }
        baseMapper.selectPage(page, where);
        return TableDataInfo.build(page);
    }

    /**
     * 新增系统登录日志
     *
     * @param logininfor 访问日志对象
     */
    @Override
    public int insertLogininfor(SysLogininfor logininfor) {
        return logininforMapper.insertLogininfor(logininfor);
    }

    /**
     * 查询系统登录日志集合
     *
     * @param logininfor 访问日志对象
     * @return 登录记录集合
     */
    @Override
    public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor) {
        return logininforMapper.selectLogininforList(logininfor);
    }

    /**
     * 批量删除系统登录日志
     *
     * @param infoIds 需要删除的登录日志ID
     * @return 结果
     */
    @Override
    public int deleteLogininforByIds(Long[] infoIds) {
        return logininforMapper.deleteLogininforByIds(infoIds);
    }

    /**
     * 清空系统登录日志
     */
    @Override
    public void cleanLogininfor() {
        logininforMapper.cleanLogininfor();
    }
}
