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

    <resultMap type="BaseSubentryType" id="BaseSubentryTypeResult">
        <result property="objid"    column="objid"    />
        <result property="parentId"    column="parent_id"    />
        <result property="subentryId"    column="subentry_id"    />
        <result property="subentryName"    column="subentry_name"    />
        <result property="subentryStatus"    column="subentry_status"    />
        <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="selectBaseSubentryTypeVo">
        select objid, parent_id, subentry_id, subentry_name, subentry_status, dept_id, user_id, create_by, create_time, update_by, update_time from base_subentry_type
    </sql>

    <select id="selectBaseSubentryTypeList" parameterType="BaseSubentryType" resultMap="BaseSubentryTypeResult">
        <include refid="selectBaseSubentryTypeVo"/>
        <where>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="subentryId != null  and subentryId != ''"> and subentry_id = #{subentryId}</if>
            <if test="subentryName != null  and subentryName != ''"> and subentry_name like concat('%', #{subentryName}, '%')</if>
            <if test="subentryStatus != null "> and subentry_status = #{subentryStatus}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>

    <select id="selectBaseSubentryTypeByObjid" parameterType="Long" resultMap="BaseSubentryTypeResult">
        <include refid="selectBaseSubentryTypeVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBaseSubentryType" parameterType="BaseSubentryType" useGeneratedKeys="true" keyProperty="objid">
        insert into base_subentry_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="subentryId != null">subentry_id,</if>
            <if test="subentryName != null">subentry_name,</if>
            <if test="subentryStatus != null">subentry_status,</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="subentryId != null">#{subentryId},</if>
            <if test="subentryName != null">#{subentryName},</if>
            <if test="subentryStatus != null">#{subentryStatus},</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>
    <insert id="insertBaseLineLoss" parameterType="BaseLineLoss" useGeneratedKeys="true" keyProperty="objid">
        insert into base_line_loss
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="lineLossId != null">line_loss_id,</if>
            <if test="lineLossName != null">line_loss_name,</if>
            <if test="monitorId != null">monitor_id,</if>
            <if test="monitorName != null">monitor_name,</if>
            <if test="monitorType != null">monitor_type,</if>
            <if test="grade != null">grade,</if>
            <if test="lineLossStatus != null">line_loss_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="lineLossId != null">#{lineLossId},</if>
            <if test="lineLossName != null">#{lineLossName},</if>
            <if test="monitorId != null">#{monitorId},</if>
            <if test="monitorName != null">#{monitorName},</if>
            <if test="monitorType != null">#{monitorType},</if>
            <if test="grade != null">#{grade},</if>
            <if test="lineLossStatus != null">#{lineLossStatus},</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="updateBaseSubentryType" parameterType="BaseSubentryType">
        update base_subentry_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="subentryId != null">subentry_id = #{subentryId},</if>
            <if test="subentryName != null">subentry_name = #{subentryName},</if>
            <if test="subentryStatus != null">subentry_status = #{subentryStatus},</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="deleteBaseSubentryTypeByObjid" parameterType="Long">
        delete from base_subentry_type where objid = #{objid}
    </delete>

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