<?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.ruoyi.clock.mapper.ActivityMapper">

    <resultMap type="com.ruoyi.clock.domain.vo.ActivityVo" id="ActivityResult">
        <result property="activityId" column="activity_id"/>
        <result property="activityName" column="activity_name"/>
        <result property="type" column="type"/>
        <result property="startDate" column="start_date"/>
        <result property="endDate" column="end_date"/>
        <result property="image" column="image" typeHandler="com.ruoyi.common.typehandler.ListToStringTypeHandler"/>
        <result property="unit" column="unit"/>
        <result property="activityRules" column="activity_rules"/>
        <result property="activityRewards" column="activity_rewards"/>
        <result property="status" column="status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="selectActivityList" resultMap="ActivityResult">
        SELECT * FROM tb_activity a
        <where>
            a.del_flag = 0
            <if test="bo.activityName != null and bo.activityName != ''">
                AND a.activity_name like concat('%',#{bo.activityName},'%')
            </if>
            <if test="bo.status != null">
                AND a.status =#{bo.status}
            </if>
            <if test="bo.productName != null and bo.productName != ''">
                AND a.activity_id in (SELECT activity_id FROM tb_activity_product WHERE product_name like concat('%',#{bo.productName},'%'))
            </if>
            <if test="bo.progressStatus">
               AND CURDATE() BETWEEN a.start_date AND a.end_date
               AND a.status = 0
            </if>
        </where>
        ORDER BY a.start_date DESC
    </select>

    <select id="selectActivityById" resultMap="ActivityResult">
        SELECT * FROM tb_activity a
        <where>
             a.activity_id = #{activityId}
        </where>

    </select>


</mapper>
