package cn.iocoder.yudao.module.system.dal.mysql.worklog;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceDeptUnReadCountVO;
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogReadDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 日志查看 Mapper
 *
 * @author 符溶馨
 */
@Mapper
public interface LogReadMapper extends BaseMapperX<LogReadDO> {

    default List<LogReadDO> selectUserByLogId(Long logId, Integer readStatus) {

        return selectList(new LambdaQueryWrapperX<LogReadDO>()
                .eq(LogReadDO::getLogInstanceId, logId)
                .eq(LogReadDO::getReadStatus, readStatus));
    }

    default void updateReadStatus(Long logId, Long userId){

        update(new LogReadDO().setReadStatus(1),
                new LambdaQueryWrapperX<LogReadDO>()
                        .eq(LogReadDO::getLogInstanceId, logId)
                        .eq(LogReadDO::getReadUserId, userId));
    }

    List<LogInstanceDeptUnReadCountVO> selectDeptUnReadCount(@Param("userId") Long userId,
                                                             @Param("deptIds") List<Long> deptIds);
}
