package thyyxxk.webserver.dao.his.dictionary.clinicalPathway;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.dictionary.pathwayTemplates.dto.ClinicalPathwayDay;
import thyyxxk.webserver.entity.dictionary.pathwayTemplates.dto.ClinicalPathwayWork;
import thyyxxk.webserver.entity.dictionary.pathwayTemplates.vo.TemplateDayVo;

import java.util.List;

@Mapper
public interface ClinicalPathwayDayDao extends BaseMapper<ClinicalPathwayDay> {


    @Select("select *\n" +
            "from clinical_pathway_day where template_id = #{templateId}  ")
    List<TemplateDayVo> getDayByTemplateId(String templateId);

    @Select("select b.*\n" +
            "from clinical_pathway_day a,\n" +
            "     clinical_pathway_work b\n" +
            "where a.id = b.day_id\n" +
            "  and a.template_id = #{templateId}\n" +
            "order by b.sort")
    List<ClinicalPathwayWork> getWorkByTemplateId(String templateId);


    @Select("select count(1) from clinical_pathway_day where template_id = #{templateId}")
    Integer getSort(@Param("templateId") String templateId);

    @Delete("delete clinical_pathway_day where id = #{id};" +
            "delete clinical_pathway_order where work_id in (select clinical_pathway_work.id from clinical_pathway_work where clinical_pathway_work.day_id = #{id});" +
            "delete clinical_pathway_work where day_id = #{id};")
    void delDayByTemplateId(String id);

}
