<?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.srs.comprehensive.mapper.CphRulesMapper">
    
    <resultMap type="CphRules" id="CphRulesResult">
        <result property="ruleId"    column="rule_id"    />
        <result property="ruleName"    column="rule_name"    />
        <result property="parentId"    column="parent_id"    />
        <result property="maxScore"    column="max_score"    />
        <result property="minScore"    column="min_score"    />
        <result property="initialScore"    column="initial_score"    />
        <result property="description"    column="description"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectCphRulesVo">
        select rule_id, rule_name, parent_id, initial_score,max_score, min_score, description, status, create_by, create_time, update_by, update_time, del_flag from cph_rules
    </sql>

    <select id="selectIamChildType" resultMap="CphRulesResult">
        <include refid="selectCphRulesVo"/>
        <where>
            parent_id = 1
        </where>
    </select>

    <select id="listAllRules" resultType="com.srs.comprehensive.domain.CphRules">
        select * from cph_rules
    </select>

    <select id="selectClassTwoChildType" resultMap="CphRulesResult">
        <include refid="selectCphRulesVo"/>
        <where>
            parent_id = 3
        </where>
    </select>

    <select id="selectCphRulesList" parameterType="CphRules" resultMap="CphRulesResult">
        <include refid="selectCphRulesVo"/>
        <where>  
            <if test="ruleName != null  and ruleName != ''"> and rule_name like concat('%', #{ruleName}, '%')</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="maxScore != null "> and max_score = #{maxScore}</if>
            <if test="minScore != null "> and min_score = #{minScore}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="status != null "> and status = #{status}</if>

        </where>
    </select>
    
    <select id="selectCphRulesByRuleId" parameterType="Long" resultMap="CphRulesResult">
        <include refid="selectCphRulesVo"/>
        where rule_id = #{ruleId}
    </select>
    <select id="selectCphRulesByParentId" parameterType="Long" resultMap="CphRulesResult">
        <include refid="selectCphRulesVo"/>
        where parent_id = #{parentId}
    </select>
        
    <insert id="insertCphRules" parameterType="CphRules">
        insert into cph_rules
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ruleId != null">rule_id,</if>
            <if test="ruleName != null and ruleName != ''">rule_name,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="maxScore != null">max_score,</if>
            <if test="minScore != null">min_score,</if>
            <if test="description != null">description,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="initialScore != null">initial_score,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ruleId != null">#{ruleId},</if>
            <if test="ruleName != null and ruleName != ''">#{ruleName},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="maxScore != null">#{maxScore},</if>
            <if test="minScore != null">#{minScore},</if>
            <if test="description != null">#{description},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="initialScore != null">#{initialScore},</if>
         </trim>
    </insert>

    <update id="updateCphRules" parameterType="CphRules">
        update cph_rules
        <trim prefix="SET" suffixOverrides=",">
            <if test="ruleName != null and ruleName != ''">rule_name = #{ruleName},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="maxScore != null">max_score = #{maxScore},</if>
            <if test="minScore != null">min_score = #{minScore},</if>
            <if test="description != null">description = #{description},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="initialScore != null">initial_score = #{initialScore},</if>
        </trim>
        where rule_id = #{ruleId}
    </update>

    <delete id="deleteCphRulesByRuleId" parameterType="Long">
        delete from cph_rules where rule_id = #{ruleId}
    </delete>

    <delete id="deleteCphRulesByRuleIds" parameterType="String">
        delete from cph_rules where rule_id in 
        <foreach item="ruleId" collection="array" open="(" separator="," close=")">
            #{ruleId}
        </foreach>
    </delete>
</mapper>