<?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.willalp.number.mapper.HsSysNumberRuleMapper">

    <resultMap type="HsSysNumberRule" id="HsSysNumberRuleResult">
        <result property="ruleId" column="rule_id"/>
        <result property="ruleName" column="rule_name"/>
        <result property="partOneId" column="part_one_id"/>
        <result property="partOneName" column="part_one_name"/>
        <result property="partOneLength" column="part_one_length"/>
        <result property="partOneValue" column="part_one_value"/>
        <result property="partTwoId" column="part_two_id"/>
        <result property="partTwoName" column="part_two_name"/>
        <result property="partTwoLength" column="part_two_length"/>
        <result property="partTwoValue" column="part_two_value"/>
        <result property="partThreeId" column="part_three_id"/>
        <result property="partThreeName" column="part_three_name"/>
        <result property="partThreeLength" column="part_three_length"/>
        <result property="partThreeValue" column="part_three_value"/>
        <result property="jgid" column="jgid"/>
        <result property="qybz" column="qybz"/>
        <result property="isDelete" column="is_delete"/>
        <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="remark" column="remark"/>
    </resultMap>

    <sql id="selectHsSysNumberRuleVo">
        select rule_id,
               rule_name,
               part_one_id,
               part_one_name,
               part_one_length,
               part_one_value,
               part_two_id,
               part_two_name,
               part_two_length,
               part_two_value,
               part_three_id,
               part_three_name,
               part_three_length,
               part_three_value,
               jgid,
               qybz,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from hs_sys_number_rule
    </sql>

    <select id="selectHsSysNumberRuleList" parameterType="HsSysNumberRule" resultMap="HsSysNumberRuleResult">
        <include refid="selectHsSysNumberRuleVo"/>
        <where>
            is_delete = 0
            <if test="ruleName != null  and ruleName != ''">and rule_name like concat('%', #{ruleName}, '%')</if>
            <if test="qybz != null  and qybz != ''">and qybz = #{qybz}</if>
        </where>
    </select>

    <select id="selectHsSysNumberRuleByRuleId" resultMap="HsSysNumberRuleResult">
        <include refid="selectHsSysNumberRuleVo"/>
        <where>
            is_delete = 0 and rule_id = #{ruleId}
        </where>
    </select>

    <update id="updatePartOneValue">
        update hs_sys_number_rule
        set part_one_value = #{value}
        where rule_id = #{ruleId}
    </update>

    <update id="updatePartTwoValue">
        update hs_sys_number_rule
        set part_two_value = #{value}
        where rule_id = #{ruleId}
    </update>

    <update id="updatePartThreeValue">
        update hs_sys_number_rule
        set part_three_value = #{value}
        where rule_id = #{ruleId}
    </update>
</mapper>
