package org.jeecg.modules.itdmGongDan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.itdmGongDan.entity.ItdmGongdanMaster;
import org.jeecg.modules.itdmGongDan.vo.ShijiDate;

import java.util.Date;
import java.util.List;

/**
 * @Description: 工单master
 * @Author: jeecg-boot
 * @Date:   2023-05-28
 * @Version: V1.0
 */
public interface ItdmGongdanMasterMapper extends BaseMapper<ItdmGongdanMaster> {

    @Select("select m.id from itdm_gongdan_master m " +
            "right join itdm_test_plan t on t.id = m.jihua_shiyan_id " +
            "where t.weituo_id = #{weituoId}")
    public List<String> selectWoIdListByWeituoId(@Param("weituoId") String weituoId);

    /**
     * 根据委托id查工单master
     */
    @Select("select * from itdm_gongdan_master where jihua_shiyan_id in " +
            "(select id from itdm_test_plan where weituo_id = #{weituoId})")
    public List<ItdmGongdanMaster> listByWeituoId(@Param("weituoId") String weituoId);

    /**
     * 根据计划试验id查所有工单master的最早实绩开始日期和最晚实绩结束日期
     */
    @Select("select max(shiji_end_date) as shijiEndDate, min(shiji_start_date) as shijiStartDate from itdm_gongdan_master " +
            "where jihua_shiyan_id = #{testPlanId}")
    public ShijiDate getShijiDateByTestPlanId(@Param("testPlanId") String testPlanId);

    /**
     * 根据计划试验id查所有实绩结束日期为空的工单master
     */
    @Select("select * from itdm_gongdan_master " +
            "where jihua_shiyan_id = #{testPlanId} and shiji_end_date IS NULL")
    public List<ItdmGongdanMaster> getShijiEndDateListByTestPlanId(@Param("testPlanId") String testPlanId);

}
