<?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.zt.plat.module.qms.resource.record.dal.mapper.RecordRecordMapper">
    <resultMap id="recordRecordResultMap" type="com.zt.plat.module.qms.resource.record.dal.dataobject.recordrecord.RecordRecordDO">
        <!-- 主键 -->
    </resultMap>

    <select id="selectRecordWithApplyPage" resultType="com.zt.plat.module.qms.resource.record.dal.dataobject.recordrecord.RecordRecordDO">
        SELECT DISTINCT trr.ID,trr.CTGR_ID,trr.CD,trr.BSN_TP,trr.FORM_KY,trr.NAME,trr.VER,
        trr.CRNT_FLG,
        trr.MKE_DT,
        trr.CNF_FLG,
        trr.CNF_LVL,
        trr.CNF_WY,
        trr.CNF_KY,
        trr.PMNT,
        trr.SBM_FLG,
        trr.RCD_STS,
        trr.EXPR_DT,
        trr.EFCT_DT,
        trr.EXPR_STS,
        trr.CNL_FLG,
        trr.FORM_DAT,
        trr.DAT_COLT_ID,
        trr.SRC_URL,
        trr.SYS_DEPT_CD,
        trr.RMK,
        trr.COLT_FLG,
        trr.MAIN_ID,
        trr.CREATE_TIME,
        trr.OPTN_FLG,
        trr.TENANT_ID
        FROM t_rcd_rcd trr
        INNER JOIN t_rcd_apl_dtl trad ON trr.ID = trad.DOC_ID
        INNER JOIN t_rcd_apl tra ON trad.APL_ID = tra.ID
        <where>
            <if test="reqVO.categoryId != null">
                AND trr.CTGR_ID = #{reqVO.categoryId}
            </if>
            <if test="reqVO.code != null and reqVO.code != ''">
                AND trr.CD = #{reqVO.code}
            </if>
            <if test="reqVO.name != null and reqVO.name != ''">
                AND trr.NAME LIKE CONCAT('%', #{reqVO.name}, '%')
            </if>
            <if test="reqVO.formKey != null and reqVO.formKey != ''">
                AND trr.FORM_KY = #{reqVO.formKey}
            </if>
            <if test="reqVO.version != null and reqVO.version != ''">
                AND trr.VER = #{reqVO.version}
            </if>
            <if test="reqVO.currentFlag != null">
                AND trr.CRNT_FLG = #{reqVO.currentFlag}
            </if>
            <if test="reqVO.makeDate != null and reqVO.makeDate.length > 0">
                AND trr.MKE_DT BETWEEN #{reqVO.makeDate[0]} AND #{reqVO.makeDate[1]}
            </if>
            <if test="reqVO.confidentialFlag != null">
                AND trr.CNF_FLG = #{reqVO.confidentialFlag}
            </if>
            <if test="reqVO.confidentialLevel != null and reqVO.confidentialLevel != ''">
                AND trr.CNF_LVL = #{reqVO.confidentialLevel}
            </if>
            <if test="reqVO.confidentialWay != null and reqVO.confidentialWay != ''">
                AND trr.CNF_WY = #{reqVO.confidentialWay}
            </if>
            <if test="reqVO.confidentialKey != null and reqVO.confidentialKey != ''">
                AND trr.CNF_KY = #{reqVO.confidentialKey}
            </if>
            <if test="reqVO.permanently != null and reqVO.permanently != ''">
                AND trr.PMNT = #{reqVO.permanently}
            </if>
            <if test="reqVO.expirationDate != null and reqVO.expirationDate.length > 0">
                AND trr.EXPR_DT BETWEEN #{reqVO.expirationDate[0]} AND #{reqVO.expirationDate[1]}
            </if>
            <if test="reqVO.expirationStatus != null">
                AND trr.EXPR_STS = #{reqVO.expirationStatus}
            </if>
            <if test="reqVO.cancelFlag != null">
                AND trr.CNL_FLG = #{reqVO.cancelFlag}
            </if>
            <if test="reqVO.formData != null and reqVO.formData != ''">
                AND trr.FORM_DAT = #{reqVO.formData}
            </if>
            <if test="reqVO.dataCollectionId != null">
                AND trr.DAT_COLT_ID = #{reqVO.dataCollectionId}
            </if>
            <if test="reqVO.sourceUrl != null and reqVO.sourceUrl != ''">
                AND trr.SRC_URL = #{reqVO.sourceUrl}
            </if>
            <if test="reqVO.systemDepartmentCode != null and reqVO.systemDepartmentCode != ''">
                AND trr.SYS_DEPT_CD = #{reqVO.systemDepartmentCode}
            </if>
            <if test="reqVO.remark != null and reqVO.remark != ''">
                AND trr.RMK = #{reqVO.remark}
            </if>
            <if test="reqVO.mainId != null">
                AND trr.MAIN_ID = #{reqVO.mainId}
            </if>
            <if test="reqVO.createTime != null and reqVO.createTime.length > 0">
                AND trr.CREATE_TIME BETWEEN #{reqVO.createTime[0]} AND #{reqVO.createTime[1]}
            </if>
        </where>
        ORDER BY trr.CREATE_TIME ASC
    </select>
</mapper>