<?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.huiju.estateagents.sample.mapper.TaNoticeMapper">

    <select id="listNoticeByCondition" resultType="com.huiju.estateagents.sample.entity.TaNotice">
        SELECT
            t.*,
            t2.sample_name targetName
        FROM
            ta_notice t
            LEFT JOIN ta_h5_sample t2 ON t.target_id = t2.sample_id
        where
            t.`status` != -1
            <if test="title != null and title != ''">
                AND t.title like CONCAT('%',#{title}, '%')
            </if>
            <if test="targetName != null and targetName != ''">
                AND t2.sample_name like CONCAT('%',#{targetName}, '%')
            </if>
            <if test="targetType != null and targetType != ''">
                AND t.target_type = #{targetType}
            </if>
            <if test="status != null">
                AND t.`status` = #{status}
            </if>
        ORDER BY
            t.order_no DESC,t.create_date DESC
    </select>

    <select id="listNoticeByConditionForAdmin" resultType="com.huiju.estateagents.sample.entity.TaNotice">
        SELECT
            t.*,
            t2.sample_name targetName
        FROM
            ta_notice t
            LEFT JOIN ta_h5_sample t2 ON t.target_id = t2.sample_id
        WHERE
            t.`status` = 1
            AND t.invalid_time >= NOW( )
        ORDER BY
            t.order_no DESC,
            t.create_date DESC
    </select>

    <update id="updateStatusByInvalidTime">
        UPDATE ta_notice t
            SET t.`status` = 0
        WHERE
            t.invalid_time &lt; NOW( )
    </update>
</mapper>
