<?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.hotent.enterpriseDeclare.dao.CostSurveyTemplateUploadDataDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hotent.enterpriseDeclare.model.CostSurveyTemplateUploadData">
        <id column="id" property="id" />
        <result column="ref_id" property="refId" />
        <result column="type" property="type" />
        <result column="audited_unit_id" property="auditedUnitId" />
        <result column="rowid" property="rowid" />
        <result column="rkey" property="rkey" />
        <result column="rvalue" property="rvalue" />
        <result column="period_record_id" property="periodRecordId" />
        <result column="parent_id" property="parentId" />
        <result column="is_deleted" property="isDeleted" />
        <result column="create_time" property="createTime" />
        <result column="create_by" property="createBy" />
        <result column="update_time" property="updateTime" />
        <result column="update_by" property="updateBy" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, ref_id, type, audited_unit_id, rowid, parent_id, rkey, rvalue, period_record_id, is_deleted, create_time, create_by, update_time, update_by
    </sql>

    <select id="selectPage" resultMap="BaseResultMap">
        select 
            <include refid="Base_Column_List"/> 
        from
            cost_survey_template_upload_data
        ${ew.customSqlSegment}
    </select>
    
    <select id="selectList" resultMap="BaseResultMap">
        select 
            <include refid="Base_Column_List"/> 
        from
            cost_survey_template_upload_data
        ${ew.customSqlSegment}
    </select>
    
    <select id="selectById" resultMap="BaseResultMap">
        select 
            <include refid="Base_Column_List"/> 
        from
            cost_survey_template_upload_data
        where 
            id = #{id}
    </select>

    <!-- 根据上传记录ID查询数据列表 -->
    <select id="selectByUploadId" resultMap="BaseResultMap">
        SELECT 
            <include refid="Base_Column_List"/>
        FROM 
            cost_survey_template_upload_data
        WHERE 
            ref_id = #{uploadId}
            AND type = '1'
            AND is_deleted = '0'
        ORDER BY rowid, rkey
    </select>

    <!-- 根据上传记录ID和企业ID查询数据列表 -->
    <select id="selectByUploadIdAndAuditedUnitId" resultMap="BaseResultMap">
        SELECT 
            <include refid="Base_Column_List"/>
        FROM 
            cost_survey_template_upload_data
        WHERE 
            ref_id = #{uploadId}
            AND type = '1'
            AND is_deleted = '0'
            <if test="periodRecordId != null">
                AND period_record_id = #{periodRecordId}
            </if>
        ORDER BY rowid, rkey
    </select>

    <!-- 根据行数据ID查询数据列表 -->
    <select id="selectByRowid" resultMap="BaseResultMap">
        SELECT 
            <include refid="Base_Column_List"/>
        FROM 
            cost_survey_template_upload_data
        WHERE 
            rowid = #{rowid}
            AND is_deleted = '0'
        ORDER BY rkey
    </select>

</mapper>

