<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gxwebsoft.ai.mapper.AuditEvidenceMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM audit_evidence a
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.caseIndex != null">
                AND a.case_index = #{param.caseIndex}
            </if>
            <if test="param.projectName != null">
                AND a.project_name LIKE CONCAT('%', #{param.projectName}, '%')
            </if>
            <if test="param.auditedTarget != null">
                AND a.audited_target LIKE CONCAT('%', #{param.auditedTarget}, '%')
            </if>
            <if test="param.auditMatter != null and param.auditMatter != ''">
                AND a.audit_matter LIKE CONCAT('%', #{param.auditMatter}, '%')
            </if>
            <if test="param.summaryTitle != null and param.summaryTitle != ''">
                AND a.summary_title LIKE CONCAT('%', #{param.summaryTitle}, '%')
            </if>
            <if test="param.contentType != null">
                AND a.content_type = #{param.contentType}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.username != null">
                AND a.username LIKE CONCAT('%', #{param.username}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.tenantId != null">
                AND a.tenant_id = #{param.tenantId}
            </if>
            <if test="param.startTime != null">
                AND a.create_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null">
                AND a.create_time &lt;= #{param.endTime}
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.ai.entity.AuditEvidence">
        <include refid="selectSql"></include>
        ORDER BY a.create_time DESC
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.ai.entity.AuditEvidence">
        SELECT a.*
        FROM audit_evidence a
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.caseIndex != null">
                AND a.case_index = #{param.caseIndex}
            </if>
            <if test="param.projectName != null">
                AND a.project_name LIKE CONCAT('%', #{param.projectName}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.tenantId != null">
                AND a.tenant_id = #{param.tenantId}
            </if>
            <if test="param.startTime != null">
                AND a.create_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null">
                AND a.create_time &lt;= #{param.endTime}
            </if>
        </where>
        ORDER BY a.create_time DESC
    </select>

</mapper>