<?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.xinelu.manage.mapper.subdivisioncategory.SubdivisionCategoryMapper">

    <resultMap type="SubdivisionCategory" id="SubdivisionCategoryResult">
        <result property="id" column="id"/>
        <result property="subdivisionCategoryName" column="subdivision_category_name"/>
        <result property="subdivisionCategoryCode" column="subdivision_category_code"/>
        <result property="sort" column="sort"/>
        <result property="remark" column="remark"/>
        <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="selectSubdivisionCategoryVo">
        select id,
               subdivision_category_name,
               subdivision_category_code,
               sort,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from subdivision_category
    </sql>

    <select id="selectSubdivisionCategoryList" parameterType="SubdivisionCategory"
            resultMap="SubdivisionCategoryResult">
        <include refid="selectSubdivisionCategoryVo"/>
        <where>
            <if test="subdivisionCategoryName != null  and subdivisionCategoryName != ''">
                and subdivision_category_name like concat('%', #{subdivisionCategoryName}, '%')
            </if>
            <if test="subdivisionCategoryCode != null  and subdivisionCategoryCode != ''">
                and subdivision_category_code = #{subdivisionCategoryCode}
            </if>
            <if test="sort != null ">
                and sort = #{sort}
            </if>
        </where>
    </select>

    <select id="selectSubdivisionCategoryById" parameterType="Long"
            resultMap="SubdivisionCategoryResult">
        <include refid="selectSubdivisionCategoryVo"/>
        where id = #{id}
    </select>

    <insert id="insertSubdivisionCategory" parameterType="SubdivisionCategory" useGeneratedKeys="true"
            keyProperty="id">
        insert into subdivision_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="subdivisionCategoryName != null">subdivision_category_name,
            </if>
            <if test="subdivisionCategoryCode != null">subdivision_category_code,
            </if>
            <if test="sort != null">sort,
            </if>
            <if test="remark != null">remark,
            </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="subdivisionCategoryName != null">#{subdivisionCategoryName},
            </if>
            <if test="subdivisionCategoryCode != null">#{subdivisionCategoryCode},
            </if>
            <if test="sort != null">#{sort},
            </if>
            <if test="remark != null">#{remark},
            </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="updateSubdivisionCategory" parameterType="SubdivisionCategory">
        update subdivision_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="subdivisionCategoryName != null">subdivision_category_name =
                #{subdivisionCategoryName},
            </if>
            <if test="subdivisionCategoryCode != null">subdivision_category_code =
                #{subdivisionCategoryCode},
            </if>
            <if test="sort != null">sort =
                #{sort},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </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 id = #{id}
    </update>

    <delete id="deleteSubdivisionCategoryById" parameterType="Long">
        delete
        from subdivision_category
        where id = #{id}
    </delete>

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