package com.jd.lightapplication.mapper;

import com.jd.lightapplication.model.InspectionProject;
import com.jd.lightapplication.model.InspectionTemplate;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface InspectionTemplateMapper extends BaseMapper<InspectionTemplate> {

    @Select("SELECT * FROM inspection_project" +
            " WHERE id IN (" +
            " SELECT project_id FROM inspection_template_project WHERE template_id = #{templateId}" +
            ")")
    List<InspectionProject> getProjectByTemplateId(@Param("templateId") Long templateId);

    @Update("UPDATE inspection_template SET is_enable = 20 WHERE type = 10 AND is_enable = 10")
    void disableCurrentDailyInspectionTemplate();
}
