<?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.infocategory.InfoCategoryMapper">

    <resultMap type="InfoCategory" id="InfoCategoryResult">
        <result property="id" column="id"/>
        <result property="infoCategoryCode" column="info_category_code"/>
        <result property="infoCategoryName" column="info_category_name"/>
        <result property="infoCategoryType" column="info_category_type"/>
        <result property="infoCategorySort" column="info_category_sort"/>
        <result property="infoCategoryCreator" column="info_category_creator"/>
        <result property="infoCategoryCreateTime" column="info_category_create_time"/>
    </resultMap>

    <sql id="selectInfoCategoryVo">
        select id,
               info_category_code,
               info_category_name,
               info_category_type,
               info_category_sort,
               info_category_creator,
               info_category_create_time
        from info_category
    </sql>

    <select id="selectInfoCategoryList" parameterType="InfoCategory" resultMap="InfoCategoryResult">
        <include refid="selectInfoCategoryVo"/>
        <where>
            <if test="infoCategoryCode != null  and infoCategoryCode != ''">
                and info_category_code like concat('%', #{infoCategoryCode}, '%')
            </if>
            <if test="infoCategoryName != null  and infoCategoryName != ''">
                and info_category_name like concat('%', #{infoCategoryName}, '%')
            </if>
            <if test="infoCategoryType != null  and infoCategoryType != ''">
                and info_category_type = #{infoCategoryType}
            </if>
            <if test="infoCategorySort != null ">
                and info_category_sort = #{infoCategorySort}
            </if>
            <if test="infoCategoryCreator != null  and infoCategoryCreator != ''">
                and info_category_creator = #{infoCategoryCreator}
            </if>
            <if test="infoCategoryCreateTime != null ">
                and info_category_create_time = #{infoCategoryCreateTime}
            </if>
        </where>
        order by info_category_sort
    </select>

    <select id="selectInfoCategoryByName" parameterType="String" resultMap="InfoCategoryResult">
        <include refid="selectInfoCategoryVo"/>
        where info_category_name = #{info_category_name}
    </select>

    <select id="selectInfoCategoryById" parameterType="Long" resultMap="InfoCategoryResult">
        <include refid="selectInfoCategoryVo"/>
        where id = #{id}
    </select>

    <insert id="insertInfoCategory" parameterType="InfoCategory" useGeneratedKeys="true"
            keyProperty="id">
        insert into info_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="infoCategoryCode != null">info_category_code,
            </if>
            <if test="infoCategoryName != null">info_category_name,
            </if>
            <if test="e != null">info_category_type,
            </if>
            <if test="infoCategorySort != null">info_category_sort,
            </if>
            <if test="infoCategoryCreator != null">info_category_creator,
            </if>
            <if test="infoCategoryCreateTime != null">info_category_create_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="infoCategoryCode != null">#{infoCategoryCode},
            </if>
            <if test="infoCategoryName != null">#{infoCategoryName},
            </if>
            <if test="infoCategoryType != null">#{infoCategoryType},
            </if>
            <if test="infoCategorySort != null">#{infoCategorySort},
            </if>
            <if test="infoCategoryCreator != null">#{infoCategoryCreator},
            </if>
            <if test="infoCategoryCreateTime != null">#{infoCategoryCreateTime},
            </if>
        </trim>
    </insert>

    <update id="updateInfoCategory" parameterType="InfoCategory">
        update info_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="infoCategoryCode != null">info_category_code =
                #{infoCategoryCode},
            </if>
            <if test="infoCategoryName != null">info_category_name =
                #{infoCategoryName},
            </if>
            <if test="infoCategoryType != null">info_category_type =
                #{infoCategoryType},
            </if>
            <if test="infoCategorySort != null">info_category_sort =
                #{infoCategorySort},
            </if>
            <if test="infoCategoryCreator != null">info_category_creator =
                #{infoCategoryCreator},
            </if>
            <if test="infoCategoryCreateTime != null">info_category_create_time =
                #{infoCategoryCreateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInfoCategoryById" parameterType="Long">
        delete
        from info_category
        where id = #{id}
    </delete>

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

    <select id="selectInfoCategoryName" resultType="java.lang.String">
        select info_category_name from info_category where info_category_name in
        <foreach item="categoryNameList" collection="list" open="(" separator="," close=")">
            #{categoryNameList}
        </foreach>
    </select>


    <insert id="insertInfoCategoryList">
        insert into info_category(
        info_category_code,
        info_category_name,
        info_category_type,
        info_category_sort,
        info_category_creator,
        info_category_create_time
        )values
        <foreach item="infoCategoryList" index="index" collection="list" separator=",">
            (
            #{infoCategoryList.infoCategoryCode},
            #{infoCategoryList.infoCategoryName},
            #{infoCategoryList.infoCategoryType},
            #{infoCategoryList.infoCategorySort},
            #{infoCategoryList.infoCategoryCreator},
            #{infoCategoryList.infoCategoryCreateTime}
            )
        </foreach>
    </insert>

    <select id="selectInfoCategoryCount" resultType="int">
        SELECT
        count( 1 )
        FROM
        info_category
        <where>
            <if test="infoCategoryName != null  and infoCategoryName != ''">
                and info_category_name = #{infoCategoryName}
            </if>
        </where>
    </select>
</mapper>