<?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.inspect.metadata.alg.mapper.BasedataAlgSubtypeMapper">
    
    <resultMap type="com.inspect.metadata.alg.domain.BasedataAlgSubtype" id="BasedataAlgSubtypeResult">
        <result property="algSubtypeId"    column="alg_subtype_id"    />
        <result property="algId"    column="alg_id"    />
        <result property="algSubtypeCode"    column="alg_subtype_code"    />
        <result property="algSubtypeName"    column="alg_subtype_name"    />
        <result property="lowerValue"    column="lower_value"    />
        <result property="upperValue"    column="upper_value"    />
        <result property="delFlag"    column="del_flag"    />
        <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="lowerFlag"    column="lower_flag"    />
        <result property="upperFlag"    column="upper_flag"    />
    </resultMap>

    <sql id="selectBasedataAlgSubtypeVo">
        select alg_subtype_id, alg_id, alg_subtype_name, alg_subtype_code,lower_value, upper_value, del_flag, create_by, create_time, update_by, update_time, lower_flag, upper_flag from basedata_alg_subtype
    </sql>

    <select id="selectBasedataAlgSubtypeList" parameterType="com.inspect.metadata.alg.domain.BasedataAlgSubtype" resultMap="BasedataAlgSubtypeResult">
        <include refid="selectBasedataAlgSubtypeVo"/>
        <where>  
            <if test="algSubtypeName != null  and algSubtypeName != ''"> and alg_subtype_name like concat('%', #{algSubtypeName}, '%')</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="algId != null and algId != '' "> and alg_id = #{algId}</if>
            <if test="delFlag != null and delFlag != '' "> and del_flag = #{delFlag}</if>
            <if test="algSubtypeCode != null and algSubtypeCode != '' "> and alg_subtype_code = #{algSubtypeCode}</if>
        </where>
    </select>
    
    <select id="selectBasedataAlgSubtypeByAlgSubtypeId" parameterType="Long" resultMap="BasedataAlgSubtypeResult">
        <include refid="selectBasedataAlgSubtypeVo"/>
        where alg_subtype_id = #{algSubtypeId}
    </select>
        
    <insert id="insertBasedataAlgSubtype" parameterType="com.inspect.metadata.alg.domain.BasedataAlgSubtype" useGeneratedKeys="true" keyProperty="algSubtypeId">
        insert into basedata_alg_subtype
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="algId != null">alg_id,</if>
            <if test="algSubtypeName != null">alg_subtype_name,</if>
            <if test="algSubtypeCode != null">alg_subtype_code,</if>
            <if test="lowerValue != null">lower_value,</if>
            <if test="upperValue != null">upper_value,</if>
            <if test="delFlag != null">del_flag,</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="lowerFlag != null">lower_flag,</if>
            <if test="upperFlag != null">upper_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="algId != null">#{algId},</if>
            <if test="algSubtypeName != null">#{algSubtypeName},</if>
            <if test="algSubtypeCode != null">#{algSubtypeCode},</if>
            <if test="lowerValue != null">#{lowerValue},</if>
            <if test="upperValue != null">#{upperValue},</if>
            <if test="delFlag != null">#{delFlag},</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="lowerFlag != null">#{lowerFlag},</if>
            <if test="upperFlag != null">#{upperFlag},</if>
         </trim>
    </insert>

    <update id="updateBasedataAlgSubtype" parameterType="com.inspect.metadata.alg.domain.BasedataAlgSubtype">
        update basedata_alg_subtype
        <trim prefix="SET" suffixOverrides=",">
            <if test="algId != null">alg_id = #{algId},</if>
            <if test="algSubtypeName != null">alg_subtype_name = #{algSubtypeName},</if>
            <if test="algSubtypeCode != null">alg_subtype_code = #{algSubtypeCode},</if>
            <if test="lowerValue != null">lower_value = #{lowerValue},</if>
            <if test="upperValue != null">upper_value = #{upperValue},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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="lowerFlag != null">lower_flag = #{lowerFlag},</if>
            <if test="upperFlag != null">upper_flag = #{upperFlag},</if>
            <if test="lowerFlag != null and lowerFlag == 0">lower_value = null,</if>
            <if test="upperFlag != null and upperFlag == 0">upper_value = null,</if>
        </trim>
        where alg_subtype_id = #{algSubtypeId}
    </update>

    <delete id="deleteBasedataAlgSubtypeByAlgSubtypeId" parameterType="Long">
        delete from basedata_alg_subtype where alg_subtype_id = #{algSubtypeId}
    </delete>

    <delete id="deleteBasedataAlgSubtypeByAlgSubtypeIds" parameterType="String">
        delete from basedata_alg_subtype where alg_subtype_id in 
        <foreach item="algSubtypeId" collection="array" open="(" separator="," close=")">
            #{algSubtypeId}
        </foreach>
    </delete>

    <select id="checkAlgSubtypeNameIsExit" parameterType="String" resultType="int">
        SELECT
            COUNT( 0 )
        FROM
            basedata_alg_subtype
        <where>
            <if test="algSubtypeName != null  and algSubtypeName != ''"> and alg_subtype_name = #{algSubtypeName} </if>
            <if test="algId != null and algId != '' "> and alg_id = #{algId} </if>
            <if test="algSubtypeId != null and algSubtypeId != '' "> and alg_subtype_id != #{algSubtypeId} </if>
        </where>
    </select>


</mapper>