<?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="org.springblade.modules.ldt.activity.mapper.ActivityMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="activityResultMap" type="org.springblade.modules.ldt.activity.entity.Activity">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="title" property="title"/>
        <result column="address" property="address"/>
        <result column="supply_price" property="supplyPrice"/>
        <result column="label_ids" property="labelIds"/>
        <result column="label_names" property="labelNames"/>
        <result column="begin_time" property="beginTime"/>
        <result column="end_time" property="endTime"/>
        <result column="detail" property="detail"/>
        <result column="subsidy" property="subsidy"/>
        <result column="hundred_point_value" property="hundredPointValue"/>
        <result column="sponsor_type" property="sponsorType"/>
        <result column="sponsor_id" property="sponsorId"/>
        <result column="audit_status" property="auditStatus"/>
        <result column="audit_advice" property="auditAdvice"/>
        <result column="sponsor_name" property="sponsorName"/>
    </resultMap>


    <select id="selectActivityPage" resultMap="activityResultMap">
        select * from ldt_activity where is_deleted = 0
    </select>
    <select id="getCanJoinActicityByMallId" resultMap="activityResultMap">
        select * from ldt_activity where is_deleted = 0 and audit_status = 1
            and id in (
                select id   from ldt_activity where is_deleted = 0 and sponsor_type = 2
                    and sponsor_id in (
		                select id from ldt_shop where is_deleted = 0 and mall_id = ${mallId}
                    )
                    and id not in (
                        select activity_id from ldt_activity_join_record where is_deleted = 0 and join_type = 1 and join_id = ${mallId}
                    )
                )
    </select>

    <select id="getHadJoinActivityByMallId" resultMap="activityResultMap">
        select * from ldt_activity where is_deleted = 0
            and id in (
                select activity_id   from ldt_activity_join_record where is_deleted = 0 and join_type = 1 and join_id = ${mallId}

             )
    </select>

    <select id="getCanJoinActicityByShopId" resultMap="activityResultMap">
        select * from ldt_activity where is_deleted = 0 and audit_status = 1
            and id in (
                select id   from ldt_activity where is_deleted = 0 and sponsor_type = 1
                    and sponsor_id in (
		                select mall_id from ldt_shop where is_deleted = 0 and id = ${sponsorId}
                    )
                    and id not in (
                        select activity_id from ldt_activity_join_record where is_deleted = 0 and join_type = 2 and join_id = ${sponsorId}
                    )
                )
    </select>

    <select id="getHadJoinActivityByShopId" resultMap="activityResultMap">
        select * from ldt_activity where is_deleted = 0
            and id in (
                select activity_id   from ldt_activity_join_record where is_deleted = 0 and join_type = 2 and join_id = ${sponsorId}

             )
    </select>


</mapper>
