<?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.contentscans.IContentScansDao">

    <resultMap id="contentScansDTO" type="cn.com.tenlion.configcontent.pojo.dtos.contentscans.ContentScansDTO">
        <result column="content_scans_id" property="contentScansId"/>
        <result column="business_id" property="businessId"/>
        <result column="project_id" property="projectId"/>
        <result column="content_scans_user_name" property="contentScansUserName"/>
        <result column="content_scans_user_icon" property="contentScansUserIcon"/>
        <result column="content_dispatch_id" property="contentDispatchId"/>
        <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="contentScansBO" type="cn.com.tenlion.configcontent.pojo.bos.contentscans.ContentScansBO">
        <result column="content_scans_id" property="contentScansId"/>
        <result column="business_id" property="businessId"/>
        <result column="content_scans_user_name" property="contentScansUserName"/>
        <result column="content_scans_user_icon" property="contentScansUserIcon"/>
        <result column="content_dispatch_id" property="contentDispatchId"/>
        <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="contentScansPO" type="cn.com.tenlion.configcontent.pojo.pos.contentscans.ContentScansPO">
        <result column="content_scans_id" property="contentScansId"/>
        <result column="business_id" property="businessId"/>
        <result column="content_scans_user_name" property="contentScansUserName"/>
        <result column="content_scans_user_icon" property="contentScansUserIcon"/>
        <result column="content_dispatch_id" property="contentDispatchId"/>
        <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="updateGmtCreate" parameterType="map">
        UPDATE
            m_content_scans
        SET
            gmt_create = #{gmtCreate}
        WHERE
            is_delete = 0 AND content_scans_id = #{contentScansId}
    </update>

    <!-- 新增CBC内容管理查看记录表 -->
    <insert id="save" parameterType="map">
        INSERT INTO m_content_scans(
            content_scans_id,
            business_id,
            content_scans_user_name,
            content_scans_user_icon,
            content_dispatch_id,
            project_id,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{contentScansId},
            #{businessId},
            #{contentScansUserName},
            #{contentScansUserIcon},
            #{contentDispatchId},
            #{projectId},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

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

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

    <!-- 修改CBC内容管理查看记录表 -->
    <update id="update" parameterType="map">
        UPDATE
            m_content_scans
        SET
        <if test="businessId != null and businessId != ''">
            business_id = #{businessId},
        </if>
        <if test="contentScansUserName != null and contentScansUserName != ''">
            content_scans_user_name = #{contentScansUserName},
        </if>
        <if test="contentScansUserIcon != null and contentScansUserIcon != ''">
            content_scans_user_icon = #{contentScansUserIcon},
        </if>
        <if test="contentDispatchId != null and contentDispatchId != ''">
            content_dispatch_id = #{contentDispatchId},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            content_scans_id = content_scans_id
        WHERE
            content_scans_id = #{contentScansId}
    </update>

    <!-- CBC内容管理查看记录表详情 -->
    <select id="get" parameterType="map" resultMap="contentScansDTO">
        SELECT
            t1.business_id,
            t1.content_scans_user_name,
            t1.content_scans_user_icon,
            t1.content_dispatch_id,
            t1.content_scans_id,
            t1.project_id
        FROM
            m_content_scans t1
        WHERE
            t1.is_delete = 0
            <if test="contentScansId != null and contentScansId != ''">
        AND
            t1.content_scans_id = #{contentScansId}
            </if>
    </select>

    <!-- CBC内容管理查看记录表详情 -->
    <select id="getBO" parameterType="map" resultMap="contentScansBO">
        SELECT
            t1.content_scans_id,
            t1.business_id,
            t1.content_scans_user_name,
            t1.content_scans_user_icon,
            t1.content_dispatch_id,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_scans t1
        WHERE
            t1.is_delete = 0
            <if test="contentScansId != null and contentScansId != ''">
        AND
            t1.content_scans_id = #{contentScansId}
            </if>
    </select>

    <!-- CBC内容管理查看记录表详情 -->
    <select id="getPO" parameterType="map" resultMap="contentScansPO">
        SELECT
            t1.content_scans_id,
            t1.business_id,
            t1.content_scans_user_name,
            t1.content_scans_user_icon,
            t1.content_dispatch_id,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_scans t1
        WHERE
            t1.is_delete = 0
            <if test="contentScansId != null and contentScansId != ''">
        AND
            t1.content_scans_id = #{contentScansId}
            </if>
    </select>

    <!-- CBC内容管理查看记录表列表 -->
    <select id="list" parameterType="map" resultMap="contentScansDTO">
        SELECT
            t1.content_scans_id,
            t1.business_id,
            t1.content_scans_user_name,
            t1.content_scans_user_icon,
            t1.content_dispatch_id,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.project_id
        FROM
            m_content_scans 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="contentScansIds != null and contentScansIds.size > 0">
        AND
            t1.content_scans_id IN
            <foreach collection="contentScansIds" index="index" open="(" separator="," close=")">
                #{contentScansIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.gmt_create DESC
    </select>

    <!-- CBC内容管理查看记录表列表 -->
    <select id="listBO" parameterType="map" resultMap="contentScansBO">
        SELECT
            t1.content_scans_id,
            t1.business_id,
            t1.content_scans_user_name,
            t1.content_scans_user_icon,
            t1.content_dispatch_id,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_scans 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="contentScansIds != null and contentScansIds.size > 0">
        AND
            t1.content_scans_id IN
            <foreach collection="contentScansIds" index="index" open="(" separator="," close=")">
                #{contentScansIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- CBC内容管理查看记录表列表 -->
    <select id="listPO" parameterType="map" resultMap="contentScansPO">
        SELECT
            t1.content_scans_id,
            t1.business_id,
            t1.content_scans_user_name,
            t1.content_scans_user_icon,
            t1.content_dispatch_id,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_content_scans 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="contentScansIds != null and contentScansIds.size > 0">
        AND
            t1.content_scans_id IN
            <foreach collection="contentScansIds" index="index" open="(" separator="," close=")">
                #{contentScansIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- CBC内容管理查看记录表统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_content_scans 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>