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

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.log.vo.RobotTaskDetailActionLogPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.log.RobotTaskDetailActionLogDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 车辆动作记录 Mapper
 *
 * @author 陈宾顺
 */
@Mapper
public interface RobotTaskDetailActionLogMapper extends BaseMapperX<RobotTaskDetailActionLogDO> {

    default PageResult<RobotTaskDetailActionLogDO> selectPage(RobotTaskDetailActionLogPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RobotTaskDetailActionLogDO>()
                .eqIfPresent(RobotTaskDetailActionLogDO::getCommandId, reqVO.getCommandId())
                .eqIfPresent(RobotTaskDetailActionLogDO::getCommandType, reqVO.getCommandType())
                .eqIfPresent(RobotTaskDetailActionLogDO::getCommandMsg, reqVO.getCommandMsg())
                .likeIfPresent(RobotTaskDetailActionLogDO::getActionMsg, reqVO.getActionMsg())
                .likeIfPresent(RobotTaskDetailActionLogDO::getTaskNo, reqVO.getTaskNo())
                .eqIfPresent(RobotTaskDetailActionLogDO::getTaskStage, reqVO.getTaskStage())
                .eqIfPresent(RobotTaskDetailActionLogDO::getActionStatus, reqVO.getActionStatus())
                .eqIfPresent(RobotTaskDetailActionLogDO::getRobotNo, reqVO.getRobotNo())
                .betweenIfPresent(RobotTaskDetailActionLogDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RobotTaskDetailActionLogDO::getCreateTime));
    }

    /**
     * 更新任务状态
     * @param taskDetailId
     * @param actionStatus
     */
    void updateActionStatus(@Param("taskDetailId") Long taskDetailId,
                            @Param("actionStatus") int actionStatus,
                            @Param("time") LocalDateTime time);

    /**
     * 获取未完成的任务
     * @param commandTypes
     * @return
     */
    List<RobotTaskDetailActionLogDO> getMistakeTaskByCommandType(@Param("commandTypes") List<String> commandTypes);

    /**
     * 获取未统计过的任务操作日志
     * @return
     */
    List<RobotTaskDetailActionLogDO> getUnStatisticsDurationLog();

    /**
     * 查询机器人最后两条任务
     * @param robotNo
     * @return
     */
    List<RobotTaskDetailActionLogDO> getLastTwoTask(@Param("robotNo") String robotNo);

    void alreadyCounted(@Param("ids") List<Long> ids);
}