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

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.controller.admin.robot.vo.RobotWarnMsgPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.statistics.dto.RobotWarnMsgClassificationDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.robot.RobotWarnMsgDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 机器人告警信息 Mapper
 *
 * @author 陈宾顺
 */
@Mapper
public interface RobotWarnMsgMapper extends BaseMapperX<RobotWarnMsgDO> {

    default PageResult<RobotWarnMsgDO> selectPage(RobotWarnMsgPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RobotWarnMsgDO>()
                .eqIfPresent(RobotWarnMsgDO::getRobotNo, reqVO.getRobotNo())
                .eqIfPresent(RobotWarnMsgDO::getWarnLevel, reqVO.getWarnLevel())
                .eqIfPresent(RobotWarnMsgDO::getReadStatus, reqVO.getReadStatus())
                .likeIfPresent(RobotWarnMsgDO::getWarnCode, reqVO.getWarnCode())
                .eqIfPresent(RobotWarnMsgDO::getWarnMsg, reqVO.getWarnMsg())
                .eqIfPresent(RobotWarnMsgDO::getWarnSolve, reqVO.getWarnSolve())
                .betweenIfPresent(RobotWarnMsgDO::getSolveTime, reqVO.getSolveTime())
                .betweenIfPresent(RobotWarnMsgDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RobotWarnMsgDO::getId));
    }

    default PageResult<RobotWarnMsgDO> selectReadPage(RobotWarnMsgPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RobotWarnMsgDO>()
                .eqIfPresent(RobotWarnMsgDO::getReadStatus, reqVO.getReadStatus())
                .orderByDesc(RobotWarnMsgDO::getCreateTime));
    }

    /**
     * 全部标记为已读
     */
    void updateAllRead();

    /**
     * 查询这些明细最新的4级告警信息
     * @param detailIds
     * @return
     */
    List<RobotWarnMsgDO> getFourLevelWarnMsgByDetailIds(@Param("detailIds") List<Long> detailIds);

    /**
     * 统计故障根因分析   type  1:周, 2:月,  3:季度
     * @param type
     * @return
     */
    List<RobotWarnMsgClassificationDTO> getRobotWarnMsgClassification(@Param("type") String type);

    /**
     * 查询某个时间段的故障原因
     * @param startTime
     * @param endTime
     * @return
     */
    List<RobotWarnMsgClassificationDTO> getRobotWarnMsgByTime(@Param("startTime") String startTime,
                                                              @Param("endTime") String endTime);
}