package net.educoder.ecsonar.dao;

import net.educoder.ecsonar.model.TaskInfoDetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: youys
 * @Date: 2022/1/18
 * @Description:
 */
public interface TaskInfoDetailDao {

    /**
     * 插入数据
     *
     * @param taskInfoDetail
     */
    @Insert("insert into task_info_detail(id,task_id,project_name,student_id,user_id,name,code_ids) values(#{id},#{taskId},#{projectName},#{studentId},#{userId} ,#{name},#{codeIds})")
    void insertTaskInfoDetail(TaskInfoDetail taskInfoDetail);

    /**
     * 更新状态
     *
     * @param id
     * @param status
     */
    @Update("update task_info_detail set status=#{status},update_time=current_timestamp where id=#{id}")
    void updateTaskInfoDetailStatus(@Param("id") String id, @Param("status") Integer status);

    /**
     * 查询taskId执行完的sonar任务数
     *
     * @param taskId
     * @return
     */
    @Select("select count(1) from task_info_detail where task_id=#{taskId} and status != 0")
    Integer selectCountByTaskId(@Param("taskId") String taskId);

    /**
     * 根据id查TaskInfoDetail
     *
     * @param id
     * @return
     */
    @Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name,code_ids codeIds,status,create_time createTime,update_time updateTime from task_info_detail where id=#{id}")
    TaskInfoDetail selectById(String id);

    /**
     * count
     *
     * @param taskId
     * @param pageSize
     * @param offset
     * @return
     */
    @Select("select count(1) from task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{offset}")
    Integer selectTaskInfoDetailPageCount(@Param("taskId") String taskId, @Param("pageSize") Integer pageSize, @Param("offset") Integer offset);

    /**
     * 分页查询
     *
     * @param taskId
     * @param pageSize
     * @param position
     * @return
     */
    @Select("select id,task_id taskId,project_name projectName,student_id studentId,user_id userId,name,code_ids codeIds,status,create_time createTime,update_time updateTime  from task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{position}")
    List<TaskInfoDetail> selectTaskInfoDetailPageList(@Param("taskId") String taskId, @Param("pageSize") Integer pageSize, @Param("position") Integer position);
}
