<?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="cn.cecep.talroad.mapper.analysis.SRaActionReportsAuditResultMapper">

    <resultMap type="cn.cecep.talroad.domain.analysis.SRaActionReportsAuditResult" id="SRaActionReportsAuditResultResult">
        <result property="id"    column="id"    />
        <result property="recordId"    column="record_id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="reportTime"    column="report_time"    />
        <result property="pollDisLicenseCode"    column="poll_dis_license_code"    />
        <result property="reportSubmissionTime"    column="report_submission_time"    />
        <result property="auditTime"    column="audit_time"  />
        <result property="factoryBasicInfo"    column="factory_basic_info"    />
        <result property="waterPreventionFacilities"    column="water_prevention_facilities"    />
        <result property="gasPreventionFacilities"    column="gas_prevention_facilities"    />
        <result property="preventionFacilities"    column="prevention_facilities"    />
        <result property="abnormalSituation"    column="abnormal_situation"    />
        <result property="organizedGasMonitoringData"    column="organized_gas_monitoring_data"    />
        <result property="waterMonitoringData"    column="water_monitoring_data"    />
        <result property="exceedingRate"    column="exceeding_rate"    />
        <result property="abnormalOrganizedGasMonitoringData"    column="abnormal_organized_gas_monitoring_data"    />
        <result property="monitoringFrequency"    column="monitoring_frequency"    />
        <result property="actualEmissions"    column="actual_emissions"    />
        <result property="excessiveEmissions"    column="excessive_emissions"    />
        <result property="attachment"    column="attachment"    />
        <result property="calculationProcess"    column="calculation_process"    />
        <result property="remark"    column="remark"    />
        <result property="checklist"    column="checklist"    />
<!--        <result property="questionList"    column="question_list"    />-->
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>


    <sql id="selectSRaActionReportsAuditResultVo">
        select id, record_id, factory_id, report_time, poll_dis_license_code, report_submission_time, audit_time, factory_basic_info, water_prevention_facilities, gas_prevention_facilities, prevention_facilities, abnormal_situation, organized_gas_monitoring_data, water_monitoring_data, exceeding_rate, abnormal_organized_gas_monitoring_data, monitoring_frequency, actual_emissions, excessive_emissions, attachment, calculation_process, remark, checklist, update_time, create_time, create_by, update_by from s_ra_action_reports_audit_result
    </sql>

    <select id="selectSRaActionReportsAuditResultList" parameterType="cn.cecep.talroad.domain.analysis.SRaActionReportsAuditResult" resultMap="SRaActionReportsAuditResultResult">
        <include refid="selectSRaActionReportsAuditResultVo"/>
        <where>
            <if test="recordId != null  and recordId != ''"> and record_id = #{recordId}</if>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="reportTime != null  and reportTime != ''"> and report_time = #{reportTime}</if>
            <if test="pollDisLicenseCode != null  and pollDisLicenseCode != ''"> and poll_dis_license_code = #{pollDisLicenseCode}</if>
            <if test="reportSubmissionTime != null "> and report_submission_time = #{reportSubmissionTime}</if>
            <if test="auditTime != null "> and audit_time = #{auditTime}</if>
            <if test="factoryBasicInfo != null  and factoryBasicInfo != ''"> and factory_basic_info = #{factoryBasicInfo}</if>
            <if test="waterPreventionFacilities != null  and waterPreventionFacilities != ''"> and water_prevention_facilities = #{waterPreventionFacilities}</if>
            <if test="gasPreventionFacilities != null  and gasPreventionFacilities != ''"> and gas_prevention_facilities = #{gasPreventionFacilities}</if>
            <if test="preventionFacilities != null  and preventionFacilities != ''"> and prevention_facilities = #{preventionFacilities}</if>
            <if test="abnormalSituation != null  and abnormalSituation != ''"> and abnormal_situation = #{abnormalSituation}</if>
            <if test="organizedGasMonitoringData != null  and organizedGasMonitoringData != ''"> and organized_gas_monitoring_data = #{organizedGasMonitoringData}</if>
            <if test="waterMonitoringData != null  and waterMonitoringData != ''"> and water_monitoring_data = #{waterMonitoringData}</if>
            <if test="exceedingRate != null  and exceedingRate != ''"> and exceeding_rate = #{exceedingRate}</if>
            <if test="abnormalOrganizedGasMonitoringData != null  and abnormalOrganizedGasMonitoringData != ''"> and abnormal_organized_gas_monitoring_data = #{abnormalOrganizedGasMonitoringData}</if>
            <if test="monitoringFrequency != null  and monitoringFrequency != ''"> and monitoring_frequency = #{monitoringFrequency}</if>
            <if test="actualEmissions != null  and actualEmissions != ''"> and actual_emissions = #{actualEmissions}</if>
            <if test="excessiveEmissions != null  and excessiveEmissions != ''"> and excessive_emissions = #{excessiveEmissions}</if>
            <if test="attachment != null  and attachment != ''"> and attachment = #{attachment}</if>
            <if test="calculationProcess != null  and calculationProcess != ''"> and calculation_process = #{calculationProcess}</if>
            <if test="checklist != null  and checklist != ''"> and checklist = #{checklist}</if>
             <!-- <if test="questionList != null  and questionList != ''"> and question_list = #{questionList}</if> -->
        </where>
    </select>
    <select id="resultList" resultType="cn.cecep.talroad.domain.analysis.SRaActionReportsAuditResult">
        select
            factory.factory_name,
            factory.city_name ,
            factory.country_name,
            factory.industry_category as industryCategoryName,
            factory.license_man_type as manType,
            factory.poll_dis_license_code as licenseCode,
            results.*
        from s_ra_action_reports_audit_result results
                 inner join pc_factory factory on results.factory_id = factory.id
                 inner join s_ra_action_reports_audit_record record on results.record_id = record.id
       <where>
           ${ew.sqlSegment}
       </where>
        order by results.create_time,results.update_time desc

    </select>

    <update id="batchUpdate">
        <foreach collection="list" item="item" separator=";">
            update s_ra_action_reports_audit_result
            <set>
                <if test="item.waterPreventionFacilities != null">
                    water_prevention_facilities = #{item.waterPreventionFacilities,jdbcType=VARCHAR},
                </if>
                <if test="item.gasPreventionFacilities != null">
                    gas_prevention_facilities = #{item.gasPreventionFacilities,jdbcType=VARCHAR},
                </if>
                <if test="item.preventionFacilities != null">
                    prevention_facilities = #{item.preventionFacilities,jdbcType=VARCHAR},
                </if>
                <if test="item.abnormalSituation != null">
                    abnormal_situation = #{item.abnormalSituation,jdbcType=VARCHAR},
                </if>
                <if test="item.organizedGasMonitoringData != null">
                    organized_gas_monitoring_data = #{item.organizedGasMonitoringData,jdbcType=VARCHAR},
                </if>
                <if test="item.waterMonitoringData != null">
                    water_monitoring_data = #{item.waterMonitoringData,jdbcType=VARCHAR},
                </if>
            </set>
            where id = #{item.id,jdbcType=VARCHAR}
        </foreach>
    </update>
</mapper>
