package net.educoder.ecsonar.dao;

import net.educoder.ecsonar.model.CloudTaskInfoDetail;
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 CloudTaskInfoDetailDao {

    /**
     * 插入数据
     *
     * @param cloudTaskInfoDetail
     */
    @Insert("insert into cloud_task_info_detail(id,task_id,project_name,project_id,language,git_url) values(#{id},#{taskId},#{projectName},#{projectId},#{language},#{gitUrl} )")
    void insertCloudTaskInfoDetail(CloudTaskInfoDetail cloudTaskInfoDetail);


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


    /**
     * 查询完成数
     * @param taskId
     * @return
     */
    @Select("select count(1) from cloud_task_info_detail where task_id=#{taskId} and status!=0")
    Integer selectCountByTaskId(String taskId);


    /**
     * 查询projectNames
     * @param taskId
     * @return
     */
    @Select("select project_name from cloud_task_info_detail where task_id=#{taskId} and status=1")
    String selectProjectNamesByTaskId(String taskId);
}
