package net.educoder.ecsonar.dao;

import net.educoder.ecsonar.model.GraduationProjectTaskInfoDetail;
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: 2023/8/31
 * @Description: 毕设质量分析任务详情dao
 */
public interface GraduationProjectTaskInfoDetailDao {

    /**
     * 插入数据
     *
     * @param taskInfoDetail
     */
    @Insert("insert into graduation_project_task_info_detail(id,task_id,project_name,language,student_id,user_id,name,git_url) " +
            "values(#{id},#{taskId},#{projectName},#{language},#{studentId},#{userId} ,#{name},#{gitUrl})")
    void insertTaskInfoDetail(GraduationProjectTaskInfoDetail taskInfoDetail);

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

    /**
     * 查询taskId执行完的sonar任务数
     *
     * @param taskId
     * @return
     */
    @Select("select count(1) from graduation_project_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,language,student_id studentId,user_id " +
            "userId,name,git_url gitUrl,status,create_time createTime,update_time updateTime " +
            "from graduation_project_task_info_detail where id=#{id}")
    GraduationProjectTaskInfoDetail selectById(String id);

    /**
     * count
     *
     * @param taskId
     * @param pageSize
     * @param offset
     * @return
     */
    @Select("select count(1) from graduation_project_task_info_detail " +
            "where task_id=#{taskId} limit #{pageSize} offset #{offset}")
    Integer selectGraduationProjectTaskInfoDetailPageCount(@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,language,student_id studentId,user_id userId," +
            "name,git_url gitUrl,status,create_time createTime,update_time updateTime " +
            "from graduation_project_task_info_detail where task_id=#{taskId} limit #{pageSize} offset #{position}")
    List<GraduationProjectTaskInfoDetail> selectGraduationProjectTaskInfoDetailPageList(@Param("taskId") String taskId,
                                                                                        @Param("pageSize") Integer pageSize,
                                                                                        @Param("position") Integer position);
}
