package com.jd.lightapplication.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jd.lightapplication.model.InspectionRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jd.lightapplication.model.dto.InspectionRecordQueryDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface InspectionRecordMapper extends BaseMapper<InspectionRecord> {

    @Select("<script>" +
            "SELECT ir.*,mi.title as meetingTitle FROM inspection_record ir" +
            " LEFT JOIN meeting_info mi" +
            " ON ir.meeting_id = mi.id" +
            " WHERE 1 = 1" +
            "<if test=\"@org.apache.commons.lang3.StringUtils@isNotBlank(inspectionRecordQueryDto.inspectionPersonnel)\">" +
            " and ir.inspection_personnel LIKE CONCAT('%',#{inspectionRecordQueryDto.inspectionPersonnel},'%')" +
            "</if>" +
            "<if test=\"@org.apache.commons.lang3.StringUtils@isNotBlank(inspectionRecordQueryDto.meetingTitle)\">" +
            " and mi.title LIKE CONCAT('%',#{inspectionRecordQueryDto.meetingTitle},'%')" +
            "</if>" +
            "<if test=\"inspectionRecordQueryDto.inspectionType != null and inspectionRecordQueryDto.inspectionType > 0\">" +
            " and ir.inspection_type = #{inspectionRecordQueryDto.inspectionType}" +
            "</if>" +
            "<if test=\"inspectionRecordQueryDto.meetingId != null and inspectionRecordQueryDto.meetingId > 0\">" +
            " and ir.meeting_id = #{inspectionRecordQueryDto.meetingId}" +
            "</if>" +
            " ORDER BY ir.create_time DESC" +
            "</script>")
    IPage<InspectionRecord> queryByPage(@Param("page") Page page, @Param("inspectionRecordQueryDto") InspectionRecordQueryDto inspectionRecordQueryDto);
}
