package com.jiayue.ssi.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiayue.ssi.entity.SysLogininfor;
import com.jiayue.ssi.entity.SysMenu;
import com.jiayue.ssi.entity.SysUser;
import com.jiayue.ssi.mapper.SysLogininforMapper;
import com.jiayue.ssi.mapper.SysMenuMapper;
import com.jiayue.ssi.service.SysLogininforService;
import com.jiayue.ssi.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
*
*
* @author xsl
* @since 2023/03/29
*/
@Service
public class SysLogininforServiceImpl  extends ServiceImpl<SysLogininforMapper, SysLogininfor> implements SysLogininforService {
    @Autowired
    private SysLogininforMapper logininforMapper;

    /**
     * 新增系统登录日志
     *
     * @param logininfor 访问日志对象
     */
    @Override
    @Transactional(propagation= Propagation.REQUIRED, rollbackFor = Exception.class)
    public void insertLogininfor(SysLogininfor logininfor) {
        logininforMapper.insertLogininfor(logininfor);
    }
    /**
     * 删除登录信息
     * @param infoId
     * @return
     */
    @Override
    @Transactional(propagation= Propagation.REQUIRED, rollbackFor = Exception.class)
    public boolean removeLoginInfoById(Long infoId) {
        LambdaUpdateWrapper<SysLogininfor> updateWrapper = new UpdateWrapper<SysLogininfor>().lambda();
        updateWrapper.eq(SysLogininfor::getInfoId, infoId).set(SysLogininfor::getDelFlag, 1);
        int count = logininforMapper.update(new SysLogininfor(), updateWrapper);
        if (count > 0) {
            return true;
        }
        return false;
    }
    /**
     * 清空系统登录日志
     */
    @Override
    @Transactional(propagation= Propagation.REQUIRED, rollbackFor = Exception.class)
    public boolean cleanLogininfor() {
        LambdaUpdateWrapper<SysLogininfor> updateWrapper = new UpdateWrapper<SysLogininfor>().lambda();
        updateWrapper.eq(SysLogininfor::getDelFlag,0).set(SysLogininfor::getDelFlag, 1);
        int count = logininforMapper.update(new SysLogininfor(), updateWrapper);
        if (count > 0) {
            return true;
        }
        return false;
    }
    /**
     * 批量真实删除登录日志
     * @param infoIds 主键id集合
     * @return
     */
    @Override
    @Transactional(propagation= Propagation.REQUIRED, rollbackFor = Exception.class)
    public boolean deleteLogininforByIds(Long[] infoIds) {
        int count = logininforMapper.deleteLogininforByIds(infoIds);
        if (count > 0) {
            return  true;
        }
        return false;
    }
}
