<?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.ruixuan.jiaoyang.mapper.JyMaterialListMapper">

    <resultMap type="com.ruixuan.jiaoyang.entity.JyMaterialList" id="JyMaterialListResult">
        <result property="id" column="id"/>
        <result property="signature" column="signature"/>
        <result property="materialName" column="material_name"/>
        <result property="coverUrl" column="cover_url"/>
        <result property="materialUrl" column="material_url"/>
        <result property="userId" column="user_id"/>
        <result property="userName" column="user_name"/>
        <result property="materialStatus" column="material_status"/>
        <result property="materialText" column="material_text"/>
        <result property="violatingText" column="violating_text"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectJyMaterialListVo">
        select id, signature, material_name, cover_url, material_url, user_id, user_name, material_status, material_text, violating_text, create_time, update_time from jy_material_list
    </sql>

    <select id="selectJyMaterialListList" parameterType="com.ruixuan.jiaoyang.entity.JyMaterialList"
            resultMap="JyMaterialListResult">
        <include refid="selectJyMaterialListVo"/>
        where 1 = 1
        <if test="signature != null  and signature != ''">and signature = #{signature}</if>
        <if test="materialName != null  and materialName != ''">and material_name like concat('%', #{materialName},
            '%')
        </if>

        <if test="userId != null  and userId != ''">and user_id = #{userId}</if>
        <if test="userName != null  and userName != ''">and user_name like concat('%', #{userName}, '%')</if>
        <if test="materialStatus != null ">and material_status = #{materialStatus}</if>
        <if test="startDate != null ">and create_time &gt;= str_to_date(concat(#{startDate},' 00:00:01'),'%Y-%m-%d
            %H:%i:%s')
        </if>
        <if test="endDate != null ">and create_time &lt;= str_to_date(concat(#{startDate},' 23:59:59'),'%Y-%m-%d
            %H:%i:%s')
        </if>
        order by create_time desc
    </select>

    <select id="selectJyMaterialListById" parameterType="Long" resultMap="JyMaterialListResult">
        <include refid="selectJyMaterialListVo"/>
        where id = #{id}
    </select>
    <select id="checkMaterial" resultType="java.lang.Integer" parameterType="java.lang.String">
        select  count(1)  from jy_material_list where signature = #{signature}

    </select>
    <select id="jyMaterialListMapper" resultType="com.alibaba.fastjson.JSONObject">
        select  type as 'type',key_word as 'keyWord'  from sensitive_key_word
    </select>
    <select id="getKeyWordList" resultType="com.alibaba.fastjson.JSONObject">
        select  *  from  sensitive_key_word
    </select>

    <insert id="insertJyMaterialList" parameterType="com.ruixuan.jiaoyang.entity.JyMaterialList" useGeneratedKeys="true"
            keyProperty="id">
        insert into jy_material_list
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="signature != null">signature,</if>
            <if test="materialName != null">material_name,</if>
            <if test="coverUrl != null">cover_url,</if>
            <if test="materialUrl != null">material_url,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="materialStatus != null">material_status,</if>
            <if test="materialText != null">material_text,</if>
            <if test="violatingText != null">violating_text,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="signature != null">#{signature},</if>
            <if test="materialName != null">#{materialName},</if>
            <if test="coverUrl != null">#{coverUrl},</if>
            <if test="materialUrl != null">#{materialUrl},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="materialStatus != null">#{materialStatus},</if>
            <if test="materialText != null">#{materialText},</if>
            <if test="violatingText != null">#{violatingText},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>
    <insert id="insertKeyWord">
        insert into  sensitive_key_word(`type`,key_word) values (
        #{type},
        #{keyWord}
        )
    </insert>

    <update id="updateJyMaterialList" parameterType="com.ruixuan.jiaoyang.entity.JyMaterialList">
        update jy_material_list
        <trim prefix="SET" suffixOverrides=",">
            <if test="signature != null">signature = #{signature},</if>
            <if test="materialName != null">material_name = #{materialName},</if>
            <if test="coverUrl != null">cover_url = #{coverUrl},</if>
            <if test="materialUrl != null">material_url = #{materialUrl},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="materialStatus != null">material_status = #{materialStatus},</if>
            <if test="materialText != null">material_text = #{materialText},</if>
            <if test="violatingText != null">violating_text = #{violatingText},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateJyMaterialListBySignature" parameterType="com.ruixuan.jiaoyang.entity.JyMaterialList">
        update jy_material_list
        <trim prefix="SET" suffixOverrides=",">
            <if test="materialName != null">material_name = #{materialName},</if>
            <if test="coverUrl != null">cover_url = #{coverUrl},</if>
            <if test="materialUrl != null">material_url = #{materialUrl},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="materialStatus != null">material_status = #{materialStatus},</if>
            <if test="materialText != null">material_text = #{materialText},</if>
            <if test="violatingText != null">violating_text = #{violatingText},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where signature = #{signature}

    </update>

    <delete id="deleteJyMaterialListById" parameterType="Long">
        delete from jy_material_list where id = #{id}
    </delete>

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