<?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.zehong.system.mapper.TRiskDevMajInforMapper">
    
    <resultMap type="TRiskDevMajInfor" id="TRiskDevMajInforResult">
        <result property="fRiskDevMajInforId"    column="f_risk_dev_maj_infor_id"    />
        <result property="fRiskCode"    column="f_risk_code"    />
        <result property="fRiskName"    column="f_risk_name"    />
        <result property="fCompanyId"    column="f_company_id"    />
        <result property="fRegionId"    column="f_region_id"    />
        <result property="fRiskType"    column="f_risk_type"    />
        <result property="fRiskPlaceDetail"    column="f_risk_place_detail"    />
        <result property="fLon"    column="f_lon"    />
        <result property="fLat"    column="f_lat"    />
        <result property="fRiskStructure"    column="f_risk_structure"    />
        <result property="fRiskControlMeasures"    column="f_risk_control_measures"    />
        <result property="fRemark"    column="f_remark"    />
        <result property="fUpdateTime"    column="f_update_time"    />

        <result property="entUploadTime"    column="f_ent_upload_time"    />
        <result property="entUploadState"    column="f_ent_upload_state"    />
        <result property="govUploadTime"    column="f_gov_upload_time"    />
        <result property="govUploadState"    column="f_gov_upload_state"    />
    </resultMap>

    <sql id="selectTRiskDevMajInforVo">
        select f_risk_dev_maj_infor_id,
               f_risk_code,
               f_risk_name,
               f_company_id,
               f_region_id,
               f_risk_type,
               f_risk_place_detail,
               f_lon,
               f_lat,
               f_risk_structure,
               f_risk_control_measures,
               f_remark,
               f_update_time,
               f_ent_upload_time,
               f_ent_upload_state,
               f_gov_upload_time,
               f_gov_upload_state
               from t_risk_dev_maj_infor
    </sql>

    <sql id="exportRiskDevMajInforVo">
        select f_risk_dev_maj_infor_id,
               f_risk_code,
               f_risk_name,
               enterprise.enterprise_name as companyName,
               region.f_name as regionName,
               f_risk_type,
               f_risk_place_detail,
               f_lon,
               f_lat,
               f_risk_structure,
               f_risk_control_measures,
               f_remark,
               f_update_time,
               f_ent_upload_time,
               f_ent_upload_state,
               f_gov_upload_time,
               f_gov_upload_state
        from t_risk_dev_maj_infor riskInfor
        left join t_enterprise_info enterprise on riskInfor.f_company_id = enterprise.enterprise_id
        left join t_county_level_region region on region.f_id = riskInfor.f_region_id

    </sql>

    <select id="selectTRiskDevMajInforList" parameterType="TRiskDevMajInfor" resultMap="TRiskDevMajInforResult">
        <include refid="selectTRiskDevMajInforVo"/>
        <where>  
            <if test="fRiskCode != null  and fRiskCode != ''"> and f_risk_code like concat('%', #{fRiskCode}, '%')</if>
            <if test="fRiskName != null  and fRiskName != ''"> and f_risk_name like concat('%', #{fRiskName}, '%')</if>
            <if test="fRiskType != null "> and f_risk_type = #{fRiskType}</if>
            <if test="entUploadState != null "> and f_ent_upload_state = #{entUploadState}</if>
            <if test="fCompanyId != null and fCompanyId != '' "> and f_company_id = #{fCompanyId}</if>
            <if test="govUploadState != null and govUploadState !='' "> and f_gov_upload_state = #{govUploadState}</if>
        </where>
        order by f_update_time desc
    </select>

    <select id="exportRiskDevMajInforList" parameterType="TRiskDevMajInfor" resultMap="TRiskDevMajInforResult">
        <include refid="exportRiskDevMajInforVo"/>
        <where>
            <if test="fRiskCode != null  and fRiskCode != ''"> and f_risk_code like concat('%', #{fRiskCode}, '%')</if>
            <if test="fRiskName != null  and fRiskName != ''"> and f_risk_name like concat('%', #{fRiskName}, '%')</if>
            <if test="fRiskType != null "> and f_risk_type = #{fRiskType}</if>
            <if test="entUploadState != null "> and f_ent_upload_state = #{entUploadState}</if>
            <if test="fCompanyId != null and fCompanyId != '' "> and f_company_id = #{fCompanyId}</if>
            <if test="govUploadState != null and govUploadState !='' "> and f_gov_upload_state = #{govUploadState}</if>
        </where>
        order by f_update_time desc
    </select>
    
    <select id="selectTRiskDevMajInforById" parameterType="Long" resultMap="TRiskDevMajInforResult">
        <include refid="selectTRiskDevMajInforVo"/>
        where f_risk_dev_maj_infor_id = #{fRiskDevMajInforId}
    </select>

    <select id="selectTRiskDevMajInforByIdForDetail" parameterType="Long" resultMap="TRiskDevMajInforResult">
        <include refid="exportRiskDevMajInforVo"/>
        where f_risk_dev_maj_infor_id = #{fRiskDevMajInforId}
    </select>
        
    <insert id="insertTRiskDevMajInfor" parameterType="TRiskDevMajInfor" useGeneratedKeys="true" keyProperty="fRiskDevMajInforId">
        insert into t_risk_dev_maj_infor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fRiskCode != null and fRiskCode != ''">f_risk_code,</if>
            <if test="fRiskName != null and fRiskName != ''">f_risk_name,</if>
            <if test="fCompanyId != null and fCompanyId != ''">f_company_id,</if>
            <if test="fRegionId != null">f_region_id,</if>
            <if test="fRiskType != null">f_risk_type,</if>
            <if test="fRiskPlaceDetail != null and fRiskPlaceDetail != ''">f_risk_place_detail,</if>
            <if test="fLon != null and fLon != ''">f_lon,</if>
            <if test="fLat != null and fLat != ''">f_lat,</if>
            <if test="fRiskStructure != null and fRiskStructure != ''">f_risk_structure,</if>
            <if test="fRiskControlMeasures != null and fRiskControlMeasures != ''">f_risk_control_measures,</if>
            <if test="fRemark != null and fRemark != ''">f_remark,</if>
            <if test="fUpdateTime != null and fUpdateTime != ''">f_update_time,</if>

            <if test="entUploadTime != null ">f_ent_upload_time,</if>
            <if test="entUploadState != null and entUploadState != ''">f_ent_upload_state,</if>
            <if test="govUploadTime != null">f_gov_upload_time,</if>
            <if test="govUploadState != null and govUploadState != ''">f_gov_upload_state,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fRiskCode != null and fRiskCode != ''">#{fRiskCode},</if>
            <if test="fRiskName != null and fRiskName != ''">#{fRiskName},</if>
            <if test="fCompanyId != null and fCompanyId != ''">#{fCompanyId},</if>
            <if test="fRegionId != null">#{fRegionId},</if>
            <if test="fRiskType != null">#{fRiskType},</if>
            <if test="fRiskPlaceDetail != null and fRiskPlaceDetail != ''">#{fRiskPlaceDetail},</if>
            <if test="fLon != null and fLon != ''">#{fLon},</if>
            <if test="fLat != null and fLat != ''">#{fLat},</if>
            <if test="fRiskStructure != null and fRiskStructure != ''">#{fRiskStructure},</if>
            <if test="fRiskControlMeasures != null and fRiskControlMeasures != ''">#{fRiskControlMeasures},</if>
            <if test="fRemark != null and fRemark != ''">#{fRemark},</if>
            <if test="fUpdateTime != null and fUpdateTime != ''">#{fUpdateTime},</if>

            <if test="entUploadTime != null">#{entUploadTime},</if>
            <if test="entUploadState != null and entUploadState != ''">#{entUploadState},</if>
            <if test="govUploadTime != null">#{govUploadTime},</if>
            <if test="govUploadState != null and govUploadState != ''">#{govUploadState},</if>
         </trim>
    </insert>

    <update id="updateTRiskDevMajInfor" parameterType="TRiskDevMajInfor">
        update t_risk_dev_maj_infor
        <trim prefix="SET" suffixOverrides=",">
            <if test="fRiskCode != null and fRiskCode != ''">f_risk_code = #{fRiskCode},</if>
            <if test="fRiskName != null and fRiskName != ''">f_risk_name = #{fRiskName},</if>
            <if test="fCompanyId != null and fCompanyId != ''">f_company_id = #{fCompanyId},</if>
            <if test="fRegionId != null">f_region_id = #{fRegionId},</if>
            <if test="fRiskType != null">f_risk_type = #{fRiskType},</if>
            <if test="fRiskPlaceDetail != null and fRiskPlaceDetail != ''">f_risk_place_detail = #{fRiskPlaceDetail},</if>
            <if test="fLon != null and fLon != ''">f_lon = #{fLon},</if>
            <if test="fLat != null and fLat != ''">f_lat = #{fLat},</if>
            <if test="fRiskStructure != null and fRiskStructure != ''">f_risk_structure = #{fRiskStructure},</if>
            <if test="fRiskControlMeasures != null and fRiskControlMeasures != ''">f_risk_control_measures = #{fRiskControlMeasures},</if>
            <if test="fRemark != null and fRemark != ''">f_remark = #{fRemark},</if>
            <if test="fUpdateTime != null and fUpdateTime != ''">f_update_time = #{fUpdateTime},</if>

            <if test="entUploadTime != null">f_ent_upload_time = #{entUploadTime},</if>
            <if test="entUploadState != null and entUploadState != ''">f_ent_upload_state = #{entUploadState},</if>
            <if test="govUploadTime != null">f_gov_upload_time = #{govUploadTime},</if>
            <if test="govUploadState != null and govUploadState != ''">f_gov_upload_state = #{govUploadState},</if>
        </trim>
        where f_risk_dev_maj_infor_id = #{fRiskDevMajInforId}
    </update>

    <update id="entReportRiskDevMajInfor">
        update t_risk_dev_maj_infor set f_ent_upload_state = #{state}, f_ent_upload_time = #{entUploadTime} where  f_risk_dev_maj_infor_id = #{fRiskDevMajInforId}

    </update>
    <delete id="deleteTRiskDevMajInforById" parameterType="Long">
        delete from t_risk_dev_maj_infor where f_risk_dev_maj_infor_id = #{fRiskDevMajInforId}
    </delete>

    <delete id="deleteTRiskDevMajInforByIds" parameterType="String">
        delete from t_risk_dev_maj_infor where f_risk_dev_maj_infor_id in 
        <foreach item="fRiskDevMajInforId" collection="array" open="(" separator="," close=")">
            #{fRiskDevMajInforId}
        </foreach>
    </delete>
</mapper>