<?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.information.InformationMapper">

    <resultMap type="Information" id="InformationResult">
        <result property="id" column="id"/>
        <result property="informationCategoryId" column="information_category_id"/>
        <result property="informationTitle" column="information_title"/>
        <result property="informationCode" column="information_code"/>
        <result property="informationContent" column="information_content"/>
        <result property="informationClickCount" column="information_click_count"/>
        <result property="informationJumpLink" column="information_jump_link"/>
        <result property="informationSource" column="information_source"/>
        <result property="leadThumbnailUrl" column="lead_thumbnail_url"/>
        <result property="negativeOneThumbnailUrl" column="negative_one_thumbnail_url"/>
        <result property="negativeTwoThumbnailUrl" column="negative_two_thumbnail_url"/>
        <result property="largePictureUrl" column="large_picture_url"/>
        <result property="informationSort" column="information_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="selectInformationVo">
        select id,
               information_category_id,
               information_title,
               information_code,
               information_content,
               information_click_count,
               information_jump_link,
               information_source,
               lead_thumbnail_url,
               negative_one_thumbnail_url,
               negative_two_thumbnail_url,
               large_picture_url,
               information_sort,
               create_by,
               create_time,
               update_by,
               update_time
        from information
    </sql>

    <select id="selectInformationList" parameterType="Information" resultMap="InformationResult">
        <include refid="selectInformationVo"/>
        <where>
            <if test="informationCategoryId != null ">
                and information_category_id = #{informationCategoryId}
            </if>
            <if test="informationTitle != null  and informationTitle != ''">
                and information_title like concat('%',#{informationTitle}, '%')
            </if>
            <if test="informationCode != null  and informationCode != ''">
                and information_code = #{informationCode}
            </if>
            <if test="informationContent != null  and informationContent != ''">
                and information_content = #{informationContent}
            </if>
            <if test="informationClickCount != null ">
                and information_click_count = #{informationClickCount}
            </if>
            <if test="informationJumpLink != null  and informationJumpLink != ''">
                and information_jump_link = #{informationJumpLink}
            </if>
            <if test="informationSource != null  and informationSource != ''">
                and information_source = #{informationSource}
            </if>
            <if test="leadThumbnailUrl != null  and leadThumbnailUrl != ''">
                and lead_thumbnail_url = #{leadThumbnailUrl}
            </if>
            <if test="negativeOneThumbnailUrl != null  and negativeOneThumbnailUrl != ''">
                and negative_one_thumbnail_url = #{negativeOneThumbnailUrl}
            </if>
            <if test="negativeTwoThumbnailUrl != null  and negativeTwoThumbnailUrl != ''">
                and negative_two_thumbnail_url = #{negativeTwoThumbnailUrl}
            </if>
            <if test="largePictureUrl != null  and largePictureUrl != ''">
                and large_picture_url = #{largePictureUrl}
            </if>
            <if test="informationSort != null ">
                and information_sort = #{informationSort}
            </if>
        </where>
        ORDER BY
        id DESC
    </select>

    <select id="selectInformationById" parameterType="Long"
            resultMap="InformationResult">
        <include refid="selectInformationVo"/>
        where id = #{id}
    </select>

    <insert id="insertInformation" parameterType="Information" useGeneratedKeys="true"
            keyProperty="id">
        insert into information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="informationCategoryId != null">information_category_id,
            </if>
            <if test="informationTitle != null">information_title,
            </if>
            <if test="informationCode != null">information_code,
            </if>
            <if test="informationContent != null">information_content,
            </if>
            <if test="informationClickCount != null">information_click_count,
            </if>
            <if test="informationJumpLink != null">information_jump_link,
            </if>
            <if test="informationSource != null">information_source,
            </if>
            <if test="leadThumbnailUrl != null">lead_thumbnail_url,
            </if>
            <if test="negativeOneThumbnailUrl != null">negative_one_thumbnail_url,
            </if>
            <if test="negativeTwoThumbnailUrl != null">negative_two_thumbnail_url,
            </if>
            <if test="largePictureUrl != null">large_picture_url,
            </if>
            <if test="informationSort != null">information_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="informationCategoryId != null">#{informationCategoryId},
            </if>
            <if test="informationTitle != null">#{informationTitle},
            </if>
            <if test="informationCode != null">#{informationCode},
            </if>
            <if test="informationContent != null">#{informationContent},
            </if>
            <if test="informationClickCount != null">#{informationClickCount},
            </if>
            <if test="informationJumpLink != null">#{informationJumpLink},
            </if>
            <if test="informationSource != null">#{informationSource},
            </if>
            <if test="leadThumbnailUrl != null">#{leadThumbnailUrl},
            </if>
            <if test="negativeOneThumbnailUrl != null">#{negativeOneThumbnailUrl},
            </if>
            <if test="negativeTwoThumbnailUrl != null">#{negativeTwoThumbnailUrl},
            </if>
            <if test="largePictureUrl != null">#{largePictureUrl},
            </if>
            <if test="informationSort != null">#{informationSort},
            </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="updateInformation" parameterType="Information">
        update information
        <trim prefix="SET" suffixOverrides=",">
            <if test="informationCategoryId != null">information_category_id =
                #{informationCategoryId},
            </if>
            <if test="informationTitle != null">information_title =
                #{informationTitle},
            </if>
            <if test="informationCode != null">information_code =
                #{informationCode},
            </if>
            <if test="informationContent != null">information_content =
                #{informationContent},
            </if>
            <if test="informationClickCount != null">information_click_count =
                #{informationClickCount},
            </if>
            <if test="informationJumpLink != null">information_jump_link =
                #{informationJumpLink},
            </if>
            <if test="informationSource != null">information_source =
                #{informationSource},
            </if>
            <if test="leadThumbnailUrl != null">lead_thumbnail_url =
                #{leadThumbnailUrl},
            </if>
            <if test="negativeOneThumbnailUrl != null">negative_one_thumbnail_url =
                #{negativeOneThumbnailUrl},
            </if>
            <if test="negativeTwoThumbnailUrl != null">negative_two_thumbnail_url =
                #{negativeTwoThumbnailUrl},
            </if>
            <if test="largePictureUrl != null">large_picture_url =
                #{largePictureUrl},
            </if>
            <if test="informationSort != null">information_sort =
                #{informationSort},
            </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="deleteInformationById" parameterType="Long">
        delete
        from information
        where id = #{id}
    </delete>

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

    <select id="getInformationById" resultType="com.xinelu.manage.vo.information.InformationVO">
        select im.id,
               im.information_category_id,
               im.information_title,
               im.information_code,
               im.information_content,
               im.information_click_count,
               im.information_jump_link,
               im.information_source,
               im.lead_thumbnail_url,
               im.negative_one_thumbnail_url,
               im.negative_two_thumbnail_url,
               im.large_picture_url,
               im.information_sort,
               ic.information_category_name
        from information im
                 LEFT JOIN information_category ic ON ic.id = im.information_category_id
        where im.id = #{id}
    </select>

    <select id="selectInformationByIds" resultType="com.xinelu.manage.domain.information.Information">
        <include refid="selectInformationVo"/>
        where id in
        <foreach item="ids" collection="array" open="(" separator="," close=")">
            #{ids}
        </foreach>
    </select>

    <select id="selectInformationVoList" resultType="com.xinelu.manage.vo.information.InformationVO">
        SELECT im.id,
        im.information_category_id,
        im.information_title,
        im.information_code,
        im.information_content,
        im.information_click_count,
        im.information_jump_link,
        im.information_source,
        im.lead_thumbnail_url,
        im.negative_one_thumbnail_url,
        im.negative_two_thumbnail_url,
        im.large_picture_url,
        im.information_sort,
        im.create_by,
        im.create_time,
        ic.information_category_name
        from information im
        LEFT JOIN information_category ic ON ic.id = im.information_category_id
        <where>
            <if test="informationCategoryId != null ">
                and im.information_category_id = #{informationCategoryId}
            </if>
            <if test="informationTitle != null  and informationTitle != ''">
                and im.information_title like concat('%',#{informationTitle}, '%')
            </if>
            <if test="informationCode != null  and informationCode != ''">
                and im.information_code = #{informationCode}
            </if>
            <if test="informationContent != null  and informationContent != ''">
                and im.information_content = #{informationContent}
            </if>
            <if test="informationClickCount != null ">
                and im.information_click_count = #{informationClickCount}
            </if>
            <if test="informationJumpLink != null  and informationJumpLink != ''">
                and im.information_jump_link = #{informationJumpLink}
            </if>
            <if test="informationSource != null  and informationSource != ''">
                and im.information_source = #{informationSource}
            </if>
        </where>
        ORDER BY
        im.information_sort ASC,
        im.id DESC
    </select>

    <select id="selectInformationByCategory" resultType="com.xinelu.manage.domain.information.Information">
        select ifn.id,
               ifn.information_title,
               ifn.information_content,
               ifn.lead_thumbnail_url
        from information_category ic
                 LEFT JOIN information ifn ON ic.id = ifn.information_category_id
        where ic.information_category_type = #{informationCategoryType}
    </select>
</mapper>
