<?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.contentcomment.IContentCommentDao">

    <resultMap id="contentCommentDTO" type="cn.com.tenlion.configcontent.pojo.dtos.contentcomment.ContentCommentDTO">
        <result column="content_comment_id" property="contentCommentId"/>
        <result column="business_id" property="businessId"/>
        <result column="project_id" property="projectId"/>
        <result column="content_comment_dislike" property="contentCommentDislike"/>
        <result column="content_comment_like" property="contentCommentLike"/>
        <result column="content_comment_content" property="contentCommentContent"/>
        <result column="content_comment_content_file" property="contentCommentContentFile"/>
        <result column="content_comment_parent_id" property="contentCommentParentId"/>
        <result column="content_comment_user_name" property="contentCommentUserName"/>
        <result column="content_comment_user_icon" property="contentCommentUserIcon"/>
        <result column="content_comment_status" property="contentCommentStatus"/>
        <result column="content_comment_remark" property="contentCommentRemark"/>
        <result column="content_comment_violation" property="contentCommentViolation"/>
        <result column="content_comment_ip" property="contentCommentIp"/>
        <result column="content_comment_address" property="contentCommentAddress"/>
        <result column="content_comment_device" property="contentCommentDevice"/>
        <result column="content_comment_longitude" property="contentCommentLongitude"/>
        <result column="content_comment_latitude" property="contentCommentLatitude"/>
        <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="contentCommentBO" type="cn.com.tenlion.configcontent.pojo.bos.contentcomment.ContentCommentBO">
        <result column="content_comment_id" property="contentCommentId"/>
        <result column="business_id" property="businessId"/>
        <result column="content_comment_dislike" property="contentCommentDislike"/>
        <result column="content_comment_like" property="contentCommentLike"/>
        <result column="content_comment_content" property="contentCommentContent"/>
        <result column="content_comment_content_file" property="contentCommentContentFile"/>
        <result column="content_comment_parent_id" property="contentCommentParentId"/>
        <result column="content_comment_user_name" property="contentCommentUserName"/>
        <result column="content_comment_user_icon" property="contentCommentUserIcon"/>
        <result column="content_comment_status" property="contentCommentStatus"/>
        <result column="content_comment_remark" property="contentCommentRemark"/>
        <result column="content_comment_violation" property="contentCommentViolation"/>
        <result column="content_comment_ip" property="contentCommentIp"/>
        <result column="content_comment_address" property="contentCommentAddress"/>
        <result column="content_comment_device" property="contentCommentDevice"/>
        <result column="content_comment_longitude" property="contentCommentLongitude"/>
        <result column="content_comment_latitude" property="contentCommentLatitude"/>
        <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="contentCommentPO" type="cn.com.tenlion.configcontent.pojo.pos.contentcomment.ContentCommentPO">
        <result column="content_comment_id" property="contentCommentId"/>
        <result column="business_id" property="businessId"/>
        <result column="content_comment_dislike" property="contentCommentDislike"/>
        <result column="content_comment_like" property="contentCommentLike"/>
        <result column="content_comment_content" property="contentCommentContent"/>
        <result column="content_comment_content_file" property="contentCommentContentFile"/>
        <result column="content_comment_parent_id" property="contentCommentParentId"/>
        <result column="content_comment_user_name" property="contentCommentUserName"/>
        <result column="content_comment_user_icon" property="contentCommentUserIcon"/>
        <result column="content_comment_status" property="contentCommentStatus"/>
        <result column="content_comment_remark" property="contentCommentRemark"/>
        <result column="content_comment_violation" property="contentCommentViolation"/>
        <result column="content_comment_ip" property="contentCommentIp"/>
        <result column="content_comment_address" property="contentCommentAddress"/>
        <result column="content_comment_device" property="contentCommentDevice"/>
        <result column="content_comment_longitude" property="contentCommentLongitude"/>
        <result column="content_comment_latitude" property="contentCommentLatitude"/>
        <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>

    <update id="updateLike" parameterType="map">
        UPDATE
            m_content_comment t1
        SET
            t1.content_comment_like = t1.content_comment_like + ${count}
        WHERE
            t1.is_delete = 0 AND t1.content_comment_id = #{contentCommentId}
    </update>

    <select id="getCommentByBusinessIdAndCommentContent" parameterType="map" resultMap="contentCommentDTO">
        SELECT
            t1.business_id,
            t1.project_id,
            t1.content_comment_dislike,
            t1.content_comment_like,
            t1.content_comment_content,
            t1.content_comment_content_file,
            t1.content_comment_parent_id,
            t1.content_comment_user_name,
            t1.content_comment_user_icon,
            t1.content_comment_status,
            t1.content_comment_remark,
            t1.content_comment_violation,
            t1.content_comment_ip,
            t1.content_comment_address,
            t1.content_comment_device,
            t1.content_comment_longitude,
            t1.content_comment_latitude,
            t1.content_comment_id
        FROM
            m_content_comment t1
        WHERE
            t1.is_delete = 0 AND t1.business_id = #{businessId} AND t1.creator = #{creator} AND t1.content_comment_content = #{contentCommentContent}
    </select>

    <!-- 新增CBC内容管理评论记录表 -->
    <insert id="save" parameterType="map">
        INSERT INTO m_content_comment(
            content_comment_id,
            business_id,
            project_id,
            content_comment_dislike,
            content_comment_like,
            content_comment_content,
            content_comment_content_file,
            content_comment_parent_id,
            content_comment_user_name,
            content_comment_user_icon,
            content_comment_status,
            content_comment_remark,
            content_comment_violation,
            content_comment_ip,
            content_comment_address,
            content_comment_device,
            content_comment_longitude,
            content_comment_latitude,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{contentCommentId},
            #{businessId},
            #{projectId},
            #{contentCommentDislike},
            #{contentCommentLike},
            #{contentCommentContent},
            #{contentCommentContentFile},
            #{contentCommentParentId},
            #{contentCommentUserName},
            #{contentCommentUserIcon},
            #{contentCommentStatus},
            #{contentCommentRemark},
            #{contentCommentViolation},
            #{contentCommentIp},
            #{contentCommentAddress},
            #{contentCommentDevice},
            #{contentCommentLongitude},
            #{contentCommentLatitude},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除CBC内容管理评论记录表 -->
    <update id="remove" parameterType="map">
        UPDATE
            m_content_comment
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            content_comment_id IN
        <foreach collection="contentCommentIds" index="index" open="(" separator="," close=")">
            #{contentCommentIds[${index}]}
        </foreach>
    </update>

    <!-- 删除CBC内容管理评论记录表（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            m_content_comment
        WHERE
            content_comment_id IN
        <foreach collection="contentCommentIds" index="index" open="(" separator="," close=")">
            #{contentCommentIds[${index}]}
        </foreach>
    </update>

    <!-- 修改CBC内容管理评论记录表 -->
    <update id="update" parameterType="map">
        UPDATE
            m_content_comment
        SET
        <if test="businessId != null and businessId != ''">
            business_id = #{businessId},
        </if>
        <if test="contentCommentDislike != null">
            content_comment_dislike = #{contentCommentDislike},
        </if>
        <if test="contentCommentLike != null">
            content_comment_like = #{contentCommentLike},
        </if>
        <if test="contentCommentContent != null and contentCommentContent != ''">
            content_comment_content = #{contentCommentContent},
        </if>
        <if test="contentCommentContentFile != null and contentCommentContentFile != ''">
            content_comment_content_file = #{contentCommentContentFile},
        </if>
        <if test="contentCommentParentId != null and contentCommentParentId != ''">
            content_comment_parent_id = #{contentCommentParentId},
        </if>
        <if test="contentCommentUserName != null and contentCommentUserName != ''">
            content_comment_user_name = #{contentCommentUserName},
        </if>
        <if test="contentCommentUserIcon != null and contentCommentUserIcon != ''">
            content_comment_user_icon = #{contentCommentUserIcon},
        </if>
        <if test="contentCommentStatus != null and contentCommentStatus != ''">
            content_comment_status = #{contentCommentStatus},
        </if>
        <if test="contentCommentRemark != null and contentCommentRemark != ''">
            content_comment_remark = #{contentCommentRemark},
        </if>
        <if test="contentCommentViolation != null and contentCommentViolation != ''">
            content_comment_violation = #{contentCommentViolation},
        </if>
        <if test="contentCommentIp != null and contentCommentIp != ''">
            content_comment_ip = #{contentCommentIp},
        </if>
        <if test="contentCommentAddress != null and contentCommentAddress != ''">
            content_comment_address = #{contentCommentAddress},
        </if>
        <if test="contentCommentDevice != null and contentCommentDevice != ''">
            content_comment_device = #{contentCommentDevice},
        </if>
        <if test="contentCommentLongitude != null">
            content_comment_longitude = #{contentCommentLongitude},
        </if>
        <if test="contentCommentLatitude != null">
            content_comment_latitude = #{contentCommentLatitude},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            content_comment_id = content_comment_id
        WHERE
            content_comment_id = #{contentCommentId}
    </update>

    <!-- CBC内容管理评论记录表详情 -->
    <select id="get" parameterType="map" resultMap="contentCommentDTO">
        SELECT
            t1.business_id,
            t1.content_comment_dislike,
            t1.content_comment_like,
            t1.content_comment_content,
            t1.content_comment_content_file,
            t1.content_comment_parent_id,
            t1.content_comment_user_name,
            t1.content_comment_user_icon,
            t1.content_comment_status,
            t1.content_comment_remark,
            t1.content_comment_violation,
            t1.content_comment_ip,
            t1.content_comment_address,
            t1.content_comment_device,
            t1.content_comment_longitude,
            t1.content_comment_latitude,
            t1.content_comment_id
        FROM
            m_content_comment t1
        WHERE
            t1.is_delete = 0
            <if test="contentCommentId != null and contentCommentId != ''">
        AND
            t1.content_comment_id = #{contentCommentId}
            </if>
    </select>

    <!-- CBC内容管理评论记录表详情 -->
    <select id="getBO" parameterType="map" resultMap="contentCommentBO">
        SELECT
            t1.content_comment_id,
            t1.business_id,
            t1.content_comment_dislike,
            t1.content_comment_like,
            t1.content_comment_content,
            t1.content_comment_content_file,
            t1.content_comment_parent_id,
            t1.content_comment_user_name,
            t1.content_comment_user_icon,
            t1.content_comment_status,
            t1.content_comment_remark,
            t1.content_comment_violation,
            t1.content_comment_ip,
            t1.content_comment_address,
            t1.content_comment_device,
            t1.content_comment_longitude,
            t1.content_comment_latitude,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_comment t1
        WHERE
            t1.is_delete = 0
            <if test="contentCommentId != null and contentCommentId != ''">
        AND
            t1.content_comment_id = #{contentCommentId}
            </if>
    </select>

    <!-- CBC内容管理评论记录表详情 -->
    <select id="getPO" parameterType="map" resultMap="contentCommentPO">
        SELECT
            t1.content_comment_id,
            t1.business_id,
            t1.content_comment_dislike,
            t1.content_comment_like,
            t1.content_comment_content,
            t1.content_comment_content_file,
            t1.content_comment_parent_id,
            t1.content_comment_user_name,
            t1.content_comment_user_icon,
            t1.content_comment_status,
            t1.content_comment_remark,
            t1.content_comment_violation,
            t1.content_comment_ip,
            t1.content_comment_address,
            t1.content_comment_device,
            t1.content_comment_longitude,
            t1.content_comment_latitude,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_comment t1
        WHERE
            t1.is_delete = 0
            <if test="contentCommentId != null and contentCommentId != ''">
        AND
            t1.content_comment_id = #{contentCommentId}
            </if>
    </select>

    <!-- CBC内容管理评论记录表列表 -->
    <select id="list" parameterType="map" resultMap="contentCommentDTO">
        SELECT
            t1.content_comment_id,
            t1.business_id,
            t1.project_id,
            t1.content_comment_dislike,
            t1.content_comment_like,
            t1.content_comment_content,
            t1.content_comment_content_file,
            t1.content_comment_parent_id,
            t1.content_comment_user_name,
            t1.content_comment_user_icon,
            t1.content_comment_status,
            t1.content_comment_remark,
            t1.content_comment_violation,
            t1.content_comment_ip,
            t1.content_comment_address,
            t1.content_comment_device,
            t1.content_comment_longitude,
            t1.content_comment_latitude,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            1
        FROM
            m_content_comment 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="businessId != null and businessId != ''">
            AND t1.business_id = #{businessId}
        </if>
        <if test="projectId != null and projectId != ''">
            AND t1.project_id = #{projectId}
        </if>
        <if test="contentCommentStatus != null and contentCommentStatus != ''">
            AND t1.content_comment_status = #{contentCommentStatus}
        </if>
        <if test="creator != null and creator != ''">
            AND t1.creator = #{creator}
        </if>
        <if test="contentCommentId != null and contentCommentId != ''">
            AND t1.content_comment_id = #{contentCommentId}
        </if>
        <if test="contentCommentParentId != null and contentCommentParentId != ''">
            AND t1.content_comment_parent_id = #{contentCommentParentId}
        </if>
        <if test="contentCommentIds != null and contentCommentIds.size > 0">
        AND
            t1.content_comment_id IN
            <foreach collection="contentCommentIds" index="index" open="(" separator="," close=")">
                #{contentCommentIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.gmt_create DESC
    </select>

    <!-- CBC内容管理评论记录表列表 -->
    <select id="listBO" parameterType="map" resultMap="contentCommentBO">
        SELECT
            t1.content_comment_id,
            t1.business_id,
            t1.content_comment_dislike,
            t1.content_comment_like,
            t1.content_comment_content,
            t1.content_comment_content_file,
            t1.content_comment_parent_id,
            t1.content_comment_user_name,
            t1.content_comment_user_icon,
            t1.content_comment_status,
            t1.content_comment_remark,
            t1.content_comment_violation,
            t1.content_comment_ip,
            t1.content_comment_address,
            t1.content_comment_device,
            t1.content_comment_longitude,
            t1.content_comment_latitude,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_comment 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="contentCommentIds != null and contentCommentIds.size > 0">
        AND
            t1.content_comment_id IN
            <foreach collection="contentCommentIds" index="index" open="(" separator="," close=")">
                #{contentCommentIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- CBC内容管理评论记录表列表 -->
    <select id="listPO" parameterType="map" resultMap="contentCommentPO">
        SELECT
            t1.content_comment_id,
            t1.business_id,
            t1.content_comment_dislike,
            t1.content_comment_like,
            t1.content_comment_content,
            t1.content_comment_content_file,
            t1.content_comment_parent_id,
            t1.content_comment_user_name,
            t1.content_comment_user_icon,
            t1.content_comment_status,
            t1.content_comment_remark,
            t1.content_comment_violation,
            t1.content_comment_ip,
            t1.content_comment_address,
            t1.content_comment_device,
            t1.content_comment_longitude,
            t1.content_comment_latitude,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_comment 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="contentCommentIds != null and contentCommentIds.size > 0">
        AND
            t1.content_comment_id IN
            <foreach collection="contentCommentIds" index="index" open="(" separator="," close=")">
                #{contentCommentIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- CBC内容管理评论记录表统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_content_comment t1
        WHERE
            t1.is_delete = 0
        <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="contentCommentStatus != null and contentCommentStatus != ''">
            AND t1.content_comment_status = #{contentCommentStatus}
        </if>
        <if test="contentCommentParentId != null and contentCommentParentId != ''">
            AND t1.content_comment_parent_id = #{contentCommentParentId}
        </if>
    </select>

</mapper>