<?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.CostAuditPeriodRecordDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hotent.enterpriseDeclare.model.CostAuditPeriodRecord">
        <id column="id" property="id" />
        <result column="upload_id" property="uploadId" />
        <result column="audited_unit_id" property="auditedUnitId" />
        <result column="audit_period" property="auditPeriod" />
        <result column="reporting_time" property="reportingTime" />
        <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, upload_id, audited_unit_id, audit_period, reporting_time, is_deleted, create_time, create_by, update_time, update_by
    </sql>

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

    <!-- 根据上传记录ID和企业ID查询记录列表 -->
    <select id="selectByUploadIdAndAuditedUnitId" resultMap="BaseResultMap">
        SELECT
            id, upload_id, audited_unit_id, audit_period, reporting_time, is_deleted, create_time, create_by, update_time, update_by
        FROM 
            cost_audit_period_record
        WHERE 
            upload_id = #{uploadId}
            AND audited_unit_id = #{auditedUnitId}
            AND type = #{type}
            AND is_deleted = '0'
        ORDER BY audit_period DESC, create_time DESC
    </select>

</mapper>

