<?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.TEnterpriseRankingRiskMapper">
    
    <resultMap type="TEnterpriseRankingRisk" id="TEnterpriseRankingRiskResult">
        <result property="riskId"    column="risk_id"    />
        <result property="yearNum"    column="year_num"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="enterpriseName"    column="enterprise_name"    />
        <result property="indicator"    column="indicator"    />
        <result property="allNum"    column="all_num"    />
        <result property="indicatorNum"    column="indicator_num"    />
        <result property="problem"    column="problem"    />
        <result property="plan"    column="plan"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTEnterpriseRankingRiskVo">
        select risk_id, year_num, beyond_enterprise_id, enterprise_name, indicator, all_num, indicator_num, problem, plan, file_url, status, create_time from t_enterprise_ranking_risk
    </sql>

    <select id="selectTEnterpriseRankingRiskList" parameterType="TEnterpriseRankingRisk" resultMap="TEnterpriseRankingRiskResult">
        <include refid="selectTEnterpriseRankingRiskVo"/>
        <where>  
            <if test="yearNum != null "> and year_num = #{yearNum}</if>
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != ''"> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="enterpriseName != null  and enterpriseName != ''"> and enterprise_name like concat('%', #{enterpriseName}, '%')</if>
        </where>
    </select>
    
    <select id="selectTEnterpriseRankingRiskById" parameterType="Long" resultMap="TEnterpriseRankingRiskResult">
        <include refid="selectTEnterpriseRankingRiskVo"/>
        where risk_id = #{riskId}
    </select>
        
    <insert id="insertTEnterpriseRankingRisk" parameterType="TEnterpriseRankingRisk" useGeneratedKeys="true" keyProperty="riskId">
        insert into t_enterprise_ranking_risk
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="yearNum != null">year_num,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="enterpriseName != null">enterprise_name,</if>
            <if test="indicator != null">indicator,</if>
            <if test="allNum != null">all_num,</if>
            <if test="indicatorNum != null">indicator_num,</if>
            <if test="problem != null">problem,</if>
            <if test="plan != null">plan,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="yearNum != null">#{yearNum},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="enterpriseName != null">#{enterpriseName},</if>
            <if test="indicator != null">#{indicator},</if>
            <if test="allNum != null">#{allNum},</if>
            <if test="indicatorNum != null">#{indicatorNum},</if>
            <if test="problem != null">#{problem},</if>
            <if test="plan != null">#{plan},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTEnterpriseRankingRisk" parameterType="TEnterpriseRankingRisk">
        update t_enterprise_ranking_risk
        <trim prefix="SET" suffixOverrides=",">
            <if test="yearNum != null">year_num = #{yearNum},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="enterpriseName != null">enterprise_name = #{enterpriseName},</if>
            <if test="indicator != null">indicator = #{indicator},</if>
            <if test="allNum != null">all_num = #{allNum},</if>
            <if test="indicatorNum != null">indicator_num = #{indicatorNum},</if>
            <if test="problem != null">problem = #{problem},</if>
            <if test="plan != null">plan = #{plan},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where risk_id = #{riskId}
    </update>

    <delete id="deleteTEnterpriseRankingRiskById" parameterType="Long">
        delete from t_enterprise_ranking_risk where risk_id = #{riskId}
    </delete>

    <delete id="deleteTEnterpriseRankingRiskByIds" parameterType="String">
        delete from t_enterprise_ranking_risk where risk_id in 
        <foreach item="riskId" collection="array" open="(" separator="," close=")">
            #{riskId}
        </foreach>
    </delete>
</mapper>