<?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="cn.com.tenlion.configcontent.dao.contentcollect.IContentCollectDao">

    <resultMap id="contentCollectDTO" type="cn.com.tenlion.configcontent.pojo.dtos.contentcollect.ContentCollectDTO">
        <result column="content_collect_id" property="contentCollectId"/>
        <result column="business_id" property="businessId"/>
        <result column="project_id" property="projectId"/>
        <result column="content_collect_user_name" property="contentCollectUserName"/>
        <result column="content_collect_user_icon" property="contentCollectUserIcon"/>
        <result column="content_collect_tag" property="contentCollectTag"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="contentCollectBO" type="cn.com.tenlion.configcontent.pojo.bos.contentcollect.ContentCollectBO">
        <result column="content_collect_id" property="contentCollectId"/>
        <result column="business_id" property="businessId"/>
        <result column="content_collect_user_name" property="contentCollectUserName"/>
        <result column="content_collect_user_icon" property="contentCollectUserIcon"/>
        <result column="content_collect_tag" property="contentCollectTag"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="contentCollectPO" type="cn.com.tenlion.configcontent.pojo.pos.contentcollect.ContentCollectPO">
        <result column="content_collect_id" property="contentCollectId"/>
        <result column="business_id" property="businessId"/>
        <result column="content_collect_user_name" property="contentCollectUserName"/>
        <result column="content_collect_user_icon" property="contentCollectUserIcon"/>
        <result column="content_collect_tag" property="contentCollectTag"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <!-- 新增 -->
    <insert id="save" parameterType="map">
        INSERT INTO m_content_collect(
            content_collect_id,
            business_id,
            content_collect_user_name,
            content_collect_user_icon,
            content_collect_tag,
            project_id,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{contentCollectId},
            #{businessId},
            #{contentCollectUserName},
            #{contentCollectUserIcon},
            #{contentCollectTag},
            #{projectId},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除 -->
    <update id="remove" parameterType="map">
        UPDATE
            m_content_collect
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            content_collect_id IN
        <foreach collection="contentCollectIds" index="index" open="(" separator="," close=")">
            #{contentCollectIds[${index}]}
        </foreach>
    </update>

    <!-- 删除（物理） -->
    <update id="delete" parameterType="java.lang.String">
        DELETE FROM
            m_content_collect
        WHERE
            content_collect_id = #{contentCollectId}
    </update>

    <!-- 修改 -->
    <update id="update" parameterType="map">
        UPDATE
            m_content_collect
        SET
        <if test="businessId != null and businessId != ''">
            business_id = #{businessId},
        </if>
        <if test="contentCollectUserName != null and contentCollectUserName != ''">
            content_collect_user_name = #{contentCollectUserName},
        </if>
        <if test="contentCollectUserIcon != null and contentCollectUserIcon != ''">
            content_collect_user_icon = #{contentCollectUserIcon},
        </if>
        <if test="contentCollectTag != null and contentCollectTag != ''">
            content_collect_tag = #{contentCollectTag},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            content_collect_id = content_collect_id
        WHERE
            content_collect_id = #{contentCollectId}
    </update>

    <!-- 详情 -->
    <select id="get" parameterType="map" resultMap="contentCollectDTO">
        SELECT
            t1.business_id,
            t1.content_collect_user_name,
            t1.content_collect_user_icon,
            t1.content_collect_tag,
            t1.content_collect_id,
            t1.project_id
        FROM
            m_content_collect t1
        WHERE
            t1.is_delete = 0
            <if test="contentCollectId != null and contentCollectId != ''">
        AND
            t1.content_collect_id = #{contentCollectId}
            </if>
    </select>

    <!-- 详情 -->
    <select id="getBO" parameterType="map" resultMap="contentCollectBO">
        SELECT
            t1.content_collect_id,
            t1.business_id,
            t1.content_collect_user_name,
            t1.content_collect_user_icon,
            t1.content_collect_tag,
            t1.project_id,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_collect t1
        WHERE
            t1.is_delete = 0
            <if test="contentCollectId != null and contentCollectId != ''">
        AND
            t1.content_collect_id = #{contentCollectId}
            </if>
    </select>

    <!-- 详情 -->
    <select id="getPO" parameterType="map" resultMap="contentCollectPO">
        SELECT
            t1.content_collect_id,
            t1.business_id,
            t1.content_collect_user_name,
            t1.content_collect_user_icon,
            t1.content_collect_tag,
            t1.project_id,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_collect t1
        WHERE
            t1.is_delete = 0
            <if test="contentCollectId != null and contentCollectId != ''">
        AND
            t1.content_collect_id = #{contentCollectId}
            </if>
    </select>

    <!-- 列表 -->
    <select id="list" parameterType="map" resultMap="contentCollectDTO">
        SELECT
            t1.content_collect_id,
            t1.business_id,
            t1.content_collect_user_name,
            t1.content_collect_user_icon,
            t1.content_collect_tag,
            t1.project_id,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            1
        FROM
            m_content_collect t1
        WHERE
            t1.is_delete = 0
        <if test="creator != null and creator != ''">
            AND t1.creator = #{creator}
        </if>
        <if test="businessId != null and businessId != ''">
            AND t1.business_id = #{businessId}
        </if>
        <if test="projectId != null and projectId != ''">
            AND t1.project_id = #{projectId}
        </if>
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="contentCollectIds != null and contentCollectIds.size > 0">
        AND
            t1.content_collect_id IN
            <foreach collection="contentCollectIds" index="index" open="(" separator="," close=")">
                #{contentCollectIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.gmt_create DESC
    </select>

    <!-- 列表 -->
    <select id="listBO" parameterType="map" resultMap="contentCollectBO">
        SELECT
            t1.content_collect_id,
            t1.business_id,
            t1.content_collect_user_name,
            t1.content_collect_user_icon,
            t1.content_collect_tag,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_collect t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="contentCollectIds != null and contentCollectIds.size > 0">
        AND
            t1.content_collect_id IN
            <foreach collection="contentCollectIds" index="index" open="(" separator="," close=")">
                #{contentCollectIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 列表 -->
    <select id="listPO" parameterType="map" resultMap="contentCollectPO">
        SELECT
            t1.content_collect_id,
            t1.business_id,
            t1.content_collect_user_name,
            t1.content_collect_user_icon,
            t1.content_collect_tag,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_collect t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="contentCollectIds != null and contentCollectIds.size > 0">
        AND
            t1.content_collect_id IN
            <foreach collection="contentCollectIds" index="index" open="(" separator="," close=")">
                #{contentCollectIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_content_collect t1
        WHERE
            t1.is_delete = 0
        <if test="creator != null and creator != ''">
            AND t1.creator = #{creator}
        </if>
        <if test="businessId != null and businessId != ''">
            AND t1.business_id = #{businessId}
        </if>
        <if test="projectId != null and projectId != ''">
            AND t1.project_id = #{projectId}
        </if>
    </select>

</mapper>