<?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.BaseBuildInfoMapper">

    <resultMap type="BaseBuildInfo" id="BaseBuildInfoResult">
        <result property="objid"    column="objid"    />
        <result property="parentId"    column="parent_id"    />
        <result property="buildId"    column="build_id"    />
        <result property="buildName"    column="build_name"    />
        <result property="buildStatus"    column="build_status"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="grade"    column="grade"    />
        <result property="remark"    column="remark"    />
        <result property="deptId"    column="dept_id"    />
        <result property="userId"    column="user_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="selectBaseBuildInfoVo">
        select objid, parent_id, build_id, build_name, build_status, ancestors, grade, remark, dept_id, user_id, create_by, create_time, update_by, update_time from base_build_info
    </sql>

    <select id="selectBaseBuildInfoList" parameterType="BaseBuildInfo" resultMap="BaseBuildInfoResult">
        <include refid="selectBaseBuildInfoVo"/>
        <where>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="buildId != null  and buildId != ''"> and build_id = #{buildId}</if>
            <if test="buildName != null  and buildName != ''"> and build_name like concat('%', #{buildName}, '%')</if>
            <if test="buildStatus != null "> and build_status = #{buildStatus}</if>
            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
            <if test="grade != null "> and grade = #{grade}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>

    <select id="selectBaseBuildInfoByObjid" parameterType="Long" resultMap="BaseBuildInfoResult">
        <include refid="selectBaseBuildInfoVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBaseBuildInfo" parameterType="BaseBuildInfo" useGeneratedKeys="true" keyProperty="objid">
        insert into base_build_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="buildId != null">build_id,</if>
            <if test="buildName != null">build_name,</if>
            <if test="buildStatus != null">build_status,</if>
            <if test="ancestors != null">ancestors,</if>
            <if test="grade != null">grade,</if>
            <if test="remark != null">remark,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="userId != null">user_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="buildId != null">#{buildId},</if>
            <if test="buildName != null">#{buildName},</if>
            <if test="buildStatus != null">#{buildStatus},</if>
            <if test="ancestors != null">#{ancestors},</if>
            <if test="grade != null">#{grade},</if>
            <if test="remark != null">#{remark},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="userId != null">#{userId},</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="updateBaseBuildInfo" parameterType="BaseBuildInfo">
        update base_build_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="buildId != null">build_id = #{buildId},</if>
            <if test="buildName != null">build_name = #{buildName},</if>
            <if test="buildStatus != null">build_status = #{buildStatus},</if>
            <if test="ancestors != null">ancestors = #{ancestors},</if>
            <if test="grade != null">grade = #{grade},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="userId != null">user_id = #{userId},</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="deleteBaseBuildInfoByObjid" parameterType="Long">
        delete from base_build_info where objid = #{objid}
    </delete>

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