package com.njcn.gather.aireport.testreportmulti.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.gather.aireport.testreportmulti.pojo.param.TestReportMultiParam;
import com.njcn.gather.aireport.testreportmulti.pojo.po.TestReportMultiPO;
import com.njcn.gather.aireport.testreportmulti.pojo.vo.TestReportMultiVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface TestReportMultiMapper extends BaseMapper<TestReportMultiPO> {

    @Select({
            "<script>",
            "select m.id, m.no, m.zip_file_name as zipFileName, m.summary_file_name as summaryFileName,",
            "m.dir_count as dirCount, m.child_report_count as childReportCount, m.point_count as pointCount,",
            "m.import_state as importState, m.generate_state as generateState, m.status,",
            "m.create_by as createBy, creator.name as createByName, m.create_time as createTime,",
            "m.update_by as updateBy, updater.name as updateByName, m.update_time as updateTime",
            "from ai_testreport_multi m",
            "left join sys_user creator on m.create_by = creator.id",
            "left join sys_user updater on m.update_by = updater.id",
            "where m.status = 1",
            "<if test='param.keyword != null and param.keyword != \"\"'>",
            "and (m.no like concat('%', #{param.keyword}, '%')",
            "or m.zip_file_name like concat('%', #{param.keyword}, '%')",
            "or m.summary_file_name like concat('%', #{param.keyword}, '%'))",
            "</if>",
            "<if test='param.searchBeginTime != null and param.searchBeginTime != \"\"'>",
            "and m.create_time &gt;= #{param.searchBeginTime}",
            "</if>",
            "<if test='param.searchEndTime != null and param.searchEndTime != \"\"'>",
            "and m.create_time &lt;= #{param.searchEndTime}",
            "</if>",
            "<if test='param.generateState != null'>",
            "and m.generate_state = #{param.generateState}",
            "</if>",
            "order by m.create_time desc",
            "</script>"
    })
    Page<TestReportMultiVO> selectPage(Page<TestReportMultiVO> page, @Param("param") TestReportMultiParam.QueryParam param);

    @Select({
            "select m.id, m.no, m.zip_file_name as zipFileName, m.summary_file_name as summaryFileName,",
            "m.dir_count as dirCount, m.child_report_count as childReportCount, m.point_count as pointCount,",
            "m.import_state as importState, m.generate_state as generateState, m.status,",
            "m.create_by as createBy, creator.name as createByName, m.create_time as createTime,",
            "m.update_by as updateBy, updater.name as updateByName, m.update_time as updateTime",
            "from ai_testreport_multi m",
            "left join sys_user creator on m.create_by = creator.id",
            "left join sys_user updater on m.update_by = updater.id",
            "where m.id = #{id} and m.status = 1"
    })
    TestReportMultiVO selectDetail(@Param("id") String id);
}
