<?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.bonus.zlpt.equip.mapper.TypeInfoMapper">
    
    <resultMap type="com.bonus.zlpt.common.core.domain.equip.TypeInfo" id="TypeInfoResult">
        <result property="typeId"    column="type_id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="typeName"    column="type_name"    />
        <result property="unitName"    column="unit_name"    />
        <result property="level"    column="level"    />
        <result property="sort"    column="sort"    />
        <result property="isActive"    column="is_active"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectTypeInfoVo">
        select type_id, parent_id, type_name, unit_name, level, sort, is_active, create_time, update_time, update_by from ma_type_info
    </sql>

    <select id="selectTypeInfoList" parameterType="com.bonus.zlpt.common.core.domain.equip.TypeInfo" resultMap="TypeInfoResult">
        <include refid="selectTypeInfoVo"/>
        <where>  
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="typeName != null  and typeName != ''"> and type_name like concat('%', #{typeName}, '%')</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="level != null  and level != ''"> and level = #{level}</if>
            <if test="sort != null  and sort != ''"> and sort = #{sort}</if>
            <if test="isActive != null  and isActive != ''"> and is_active = #{isActive}</if>
        </where>
    </select>
    
    <select id="selectTypeInfoByTypeId" parameterType="Long" resultMap="TypeInfoResult">
        <include refid="selectTypeInfoVo"/>
        where type_id = #{typeId}
    </select>
    <select id="selectCountByTypeId" resultType="java.lang.Integer">
        select COUNT(*) from ma_type_info where parent_id = #{typeId}
    </select>

    <insert id="insertTypeInfo" parameterType="com.bonus.zlpt.common.core.domain.equip.TypeInfo">
        insert into ma_type_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeId != null">type_id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="typeName != null">type_name,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="level != null">level,</if>
            <if test="sort != null">sort,</if>
            <if test="isActive != null">is_active,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="typeId != null">#{typeId},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="typeName != null">#{typeName},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="level != null">#{level},</if>
            <if test="sort != null">#{sort},</if>
            <if test="isActive != null">#{isActive},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateTypeInfo" parameterType="com.bonus.zlpt.common.core.domain.equip.TypeInfo">
        update ma_type_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="typeName != null">type_name = #{typeName},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="level != null">level = #{level},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="isActive != null">is_active = #{isActive},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where type_id = #{typeId}
    </update>

    <delete id="deleteTypeInfoByTypeId" parameterType="Long">
        delete from ma_type_info where type_id = #{typeId}
    </delete>

    <delete id="deleteTypeInfoByTypeIds" parameterType="String">
        delete from ma_type_info where type_id in 
        <foreach item="typeId" collection="array" open="(" separator="," close=")">
            #{typeId}
        </foreach>
    </delete>
</mapper>