<?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.hw.ems.base.mapper.BaseBusinessTypeMapper">

    <resultMap type="BaseBusinessType" id="BaseBusinessTypeResult">
        <result property="objid"    column="objid"    />
        <result property="parentId"    column="parent_id"    />
        <result property="businessId"    column="business_id"    />
        <result property="businessName"    column="business_name"    />
        <result property="businessStatus"    column="business_status"    />
        <result property="userId"    column="user_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBaseBusinessTypeVo">
        select objid, parent_id, business_id, business_name, business_status, user_id, dept_id, create_by, create_time, update_by, update_time from base_business_type
    </sql>

    <select id="selectBaseBusinessTypeList" parameterType="BaseBusinessType" resultMap="BaseBusinessTypeResult">
        <include refid="selectBaseBusinessTypeVo"/>
        <where>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="businessId != null  and businessId != ''"> and business_id = #{businessId}</if>
            <if test="businessName != null  and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
            <if test="businessStatus != null "> and business_status = #{businessStatus}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
    </select>

    <select id="selectBaseBusinessTypeByObjid" parameterType="Long" resultMap="BaseBusinessTypeResult">
        <include refid="selectBaseBusinessTypeVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBaseBusinessType" parameterType="BaseBusinessType" useGeneratedKeys="true" keyProperty="objid">
        insert into base_business_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="businessId != null">business_id,</if>
            <if test="businessName != null">business_name,</if>
            <if test="businessStatus != null">business_status,</if>
            <if test="userId != null">user_id,</if>
            <if test="deptId != null">dept_id,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">#{parentId},</if>
            <if test="businessId != null">#{businessId},</if>
            <if test="businessName != null">#{businessName},</if>
            <if test="businessStatus != null">#{businessStatus},</if>
            <if test="userId != null">#{userId},</if>
            <if test="deptId != null">#{deptId},</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>
         </trim>
    </insert>

    <update id="updateBaseBusinessType" parameterType="BaseBusinessType">
        update base_business_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="businessId != null">business_id = #{businessId},</if>
            <if test="businessName != null">business_name = #{businessName},</if>
            <if test="businessStatus != null">business_status = #{businessStatus},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deptId != null">dept_id = #{deptId},</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>
        </trim>
        where objid = #{objid}
    </update>

    <delete id="deleteBaseBusinessTypeByObjid" parameterType="Long">
        delete from base_business_type where objid = #{objid}
    </delete>

    <delete id="deleteBaseBusinessTypeByObjids" parameterType="String">
        delete from base_business_type where objid in
        <foreach item="objid" collection="array" open="(" separator="," close=")">
            #{objid}
        </foreach>
    </delete>
</mapper>
