<?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.informationcategory.InformationCategoryMapper">

    <resultMap type="InformationCategory" id="InformationCategoryResult">
        <result property="id" column="id"/>
        <result property="informationCategoryCode" column="information_category_code"/>
        <result property="informationCategoryName" column="information_category_name"/>
        <result property="informationCategoryType" column="information_category_type"/>
        <result property="sort" column="sort"/>
        <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="selectInformationCategoryVo">
        select id,
               information_category_code,
               information_category_name,
               information_category_type,
               sort,
               create_by,
               create_time,
               update_by,
               update_time
        from information_category
    </sql>

    <select id="selectInformationCategoryList" parameterType="InformationCategory"
            resultMap="InformationCategoryResult">
        <include refid="selectInformationCategoryVo"/>
        <where>
            <if test="informationCategoryCode != null  and informationCategoryCode != ''">
                and information_category_code = #{informationCategoryCode}
            </if>
            <if test="informationCategoryName != null  and informationCategoryName != ''">
                and information_category_name like concat('%', #{informationCategoryName}, '%')
            </if>
            <if test="informationCategoryType != null  and informationCategoryType != ''">
                and information_category_type = #{informationCategoryType}
            </if>
            <if test="sort != null ">
                and sort = #{sort}
            </if>
        </where>
        ORDER BY sort asc,id DESC
    </select>

    <select id="selectInformationCategoryById" parameterType="Long"
            resultMap="InformationCategoryResult">
        <include refid="selectInformationCategoryVo"/>
        where id = #{id}
    </select>

    <insert id="insertInformationCategory" parameterType="InformationCategory" useGeneratedKeys="true"
            keyProperty="id">
        insert into information_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="informationCategoryCode != null">information_category_code,
            </if>
            <if test="informationCategoryName != null">information_category_name,
            </if>
            <if test="informationCategoryType != null">information_category_type,
            </if>
            <if test="sort != null">sort,
            </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="informationCategoryCode != null">#{informationCategoryCode},
            </if>
            <if test="informationCategoryName != null">#{informationCategoryName},
            </if>
            <if test="informationCategoryType != null">#{informationCategoryType},
            </if>
            <if test="sort != null">#{sort},
            </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="updateInformationCategory" parameterType="InformationCategory">
        update information_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="informationCategoryCode != null">information_category_code =
                #{informationCategoryCode},
            </if>
            <if test="informationCategoryName != null">information_category_name =
                #{informationCategoryName},
            </if>
            <if test="informationCategoryType != null">information_category_type =
                #{informationCategoryType},
            </if>
            <if test="sort != null">sort =
                #{sort},
            </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="deleteInformationCategoryById" parameterType="Long">
        delete
        from information_category
        where id = #{id}
    </delete>

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

    <insert id="insertInformationCategoryList">
        insert into information_category(
        information_category_code,
        information_category_name,
        information_category_type,
        sort,
        create_by,
        create_time
        )values
        <foreach item="informationCategoryList" index="index" collection="list" separator=",">
            (
            #{informationCategoryList.informationCategoryCode},
            #{informationCategoryList.informationCategoryName},
            #{informationCategoryList.informationCategoryType},
            #{informationCategoryList.sort},
            #{informationCategoryList.createBy},
            #{informationCategoryList.createTime}
            )
        </foreach>
    </insert>

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


    <select id="selectInformationCategoryCount" resultType="int">
        SELECT
        count( 1 )
        FROM
        information_category
        <where>
            <if test="informationCategoryName != null  and informationCategoryName != ''">
                and information_category_name = #{informationCategoryName}
            </if>
        </where>
    </select>
</mapper>
