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.SysOperLog;
import com.jiayue.ssi.mapper.SysOperLogMapper;
import com.jiayue.ssi.service.SysOperLogService;
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 ruoyi
 */
@Service
public class SysOperLogServiceImpl  extends ServiceImpl<SysOperLogMapper, SysOperLog> implements SysOperLogService {
    @Autowired
    private SysOperLogMapper operLogMapper;

    /**
     * 新增操作日志
     *
     * @param operLog 操作日志对象
     */
    @Override
    @Transactional(propagation= Propagation.REQUIRED, rollbackFor = Exception.class)
    public void insertOperlog(SysOperLog operLog)
    {
        operLogMapper.insertOperlog(operLog);
    }
    /**
     * 删除操作日志
     * @param operId
     * @return
     */
    @Override
    @Transactional(propagation= Propagation.REQUIRED, rollbackFor = Exception.class)
    public boolean removeOperlogById(Long operId) {
        LambdaUpdateWrapper<SysOperLog> updateWrapper = new UpdateWrapper<SysOperLog>().lambda();
        updateWrapper.eq(SysOperLog::getOperId, operId).set(SysOperLog::getDelFlag, 1);
        int count = operLogMapper.update(new SysOperLog(), updateWrapper);
        if (count > 0) {
            return true;
        }
        return false;
    }
    /**
     * 清空操作日志
     */
    @Override
    @Transactional(propagation= Propagation.REQUIRED, rollbackFor = Exception.class)
    public boolean cleanOperLog() {
        LambdaUpdateWrapper<SysOperLog> updateWrapper = new UpdateWrapper<SysOperLog>().lambda();
        updateWrapper.eq(SysOperLog::getDelFlag,0).set(SysOperLog::getDelFlag, 1);
        int count = operLogMapper.update(new SysOperLog(), updateWrapper);
        if (count > 0) {
            return true;
        }
        return false;
    }
    /**
     * 批量真实删除操作日志
     * @param operIds 主键id集合
     * @return
     */
    @Override
    @Transactional(propagation= Propagation.REQUIRED, rollbackFor = Exception.class)
    public boolean deleteOperLogByIds(Long[] operIds) {
        int count = operLogMapper.deleteOperLogByIds(operIds);
        if (count > 0) {
            return  true;
        }
        return false;
    }
}
