<?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.matrix.system.shopXcx.dao.ShopActivitiesDao"> 
 | 
    <!-- 定义ShopActivities 的复杂关联map --> 
 | 
    <resultMap type="com.matrix.system.shopXcx.bean.ShopActivities" id="ShopActivitiesMap"> 
 | 
        <id property="id" column="id" /> 
 | 
            <result property="actName" column="act_name" /> 
 | 
            <result property="actCode" column="act_code" /> 
 | 
            <result property="actType" column="act_type" /> 
 | 
            <result property="actBeginTime" column="act_begin_time" /> 
 | 
            <result property="actEndTime" column="act_end_time" /> 
 | 
            <result property="createBy" column="create_by" /> 
 | 
            <result property="actStatus" column="act_status" /> 
 | 
            <result property="shopIds" column="shop_ids" /> 
 | 
            <result property="actRemark" column="act_remark" /> 
 | 
            <result property="actMax" column="act_max" /> 
 | 
        <result property="remainTime" column="remainTime" /> 
 | 
        <result property="isStart" column="isStart" /> 
 | 
        <result property="title" column="title" /> 
 | 
        <result property="actImg" column="act_img" /> 
 | 
        <result property="actContent" column="act_content" /> 
 | 
        <result property="companyId" column="company_id" /> 
 | 
        <association property="groupInfo" javaType="com.matrix.system.shopXcx.bean.ShopActivitiesGroupInfo" column="act_id"> 
 | 
            <id property="id" column="giId"/> 
 | 
            <result property="goodsId" column="goods_id" /> 
 | 
            <result property="goodsName" column="goods_name" /> 
 | 
            <result property="giType" column="gi_type" /> 
 | 
            <result property="giHeadDiscount" column="gi_head_discount" /> 
 | 
            <result property="giLimitBuy" column="gi_limit_buy" /> 
 | 
            <result property="giVirtualGroup" column="gi_virtual_group" /> 
 | 
        </association> 
 | 
        <association property="salonRecord" javaType="com.matrix.system.shopXcx.bean.ShopActivitiesSalonRecord" column="act_id"> 
 | 
            <id property="id" column="asr_id" /> 
 | 
            <result property="status" column="status" /> 
 | 
            <result property="remark" column="remark" /> 
 | 
            <result property="shopId" column="shop_id" /> 
 | 
        </association> 
 | 
        <collection property="attributes" ofType="com.matrix.system.shopXcx.bean.ShopActivitiesSalonDistribute" column="act_id"> 
 | 
            <id property="id" column="sd_id" /> 
 | 
            <result property="attrName" column="attr_name" /> 
 | 
        </collection> 
 | 
    </resultMap> 
 | 
     
 | 
     
 | 
    <!-- 定义ShopActivities 的简单map  ,本map不添加其他的关联属性 --> 
 | 
    <resultMap type="com.matrix.system.shopXcx.bean.ShopActivities" id="ShopActivitiesSimpleMap"> 
 | 
        <id property="id" column="id" /> 
 | 
            <result property="actName" column="act_name" /> 
 | 
            <result property="actCode" column="act_code" /> 
 | 
            <result property="actType" column="act_type" /> 
 | 
            <result property="actBeginTime" column="act_begin_time" /> 
 | 
            <result property="actEndTime" column="act_end_time" /> 
 | 
            <result property="createBy" column="create_by" /> 
 | 
            <result property="actStatus" column="act_status" /> 
 | 
            <result property="shopIds" column="shop_ids" /> 
 | 
            <result property="actRemark" column="act_remark" /> 
 | 
            <result property="actMax" column="act_max" /> 
 | 
    </resultMap> 
 | 
     
 | 
    <!-- 字段sql --> 
 | 
    <sql id="columns"> 
 | 
        create_by, 
 | 
        create_time, 
 | 
        update_by, 
 | 
        update_time, 
 | 
            id, 
 | 
            act_name, 
 | 
            act_code, 
 | 
            act_type, 
 | 
            act_begin_time, 
 | 
            act_end_time, 
 | 
            act_status, 
 | 
            shop_ids, 
 | 
            act_remark, 
 | 
            act_max, 
 | 
            act_img, 
 | 
            act_content, 
 | 
            company_id 
 | 
    </sql> 
 | 
     
 | 
    <!-- 属性sql --> 
 | 
    <sql id="propertys"> 
 | 
        #{item.createBy}, 
 | 
        now(), 
 | 
        #{item.updateBy}, 
 | 
        now(), 
 | 
            #{item.id}, 
 | 
            #{item.actName}, 
 | 
            #{item.actCode}, 
 | 
            #{item.actType}, 
 | 
            #{item.actBeginTime}, 
 | 
            #{item.actEndTime}, 
 | 
            #{item.actStatus}, 
 | 
            #{item.shopIds}, 
 | 
            #{item.actRemark}, 
 | 
            #{item.actMax}, 
 | 
            #{item.actImg}, 
 | 
            #{item.actContent}, 
 | 
            #{item.companyId} 
 | 
    </sql> 
 | 
     
 | 
    <!-- where sql --> 
 | 
    <sql id="where_sql"> 
 | 
          
 | 
         <if test="record!=null"> 
 | 
            <if test="(record.id!=null and record.id!='') or  (record.id!='' and record.id==0)  "> 
 | 
                and id  = #{record.id}  
 | 
            </if> 
 | 
             <if test="(record.companyId!=null and record.companyId!='') or  (record.companyId!='' and record.companyId==0)  "> 
 | 
                 and company_id  = #{record.companyId} 
 | 
             </if> 
 | 
            <if test="(record.actName!=null and record.actName!='') or  (record.actName!='' and record.actName==0)  "> 
 | 
                and act_name  like  CONCAT(CONCAT('%',#{record.actName}),'%') 
 | 
            </if> 
 | 
            <if test="(record.actType!=null and record.actType!='') or  (record.actType!='' and record.actType==0)  "> 
 | 
                and act_type  = #{record.actType}  
 | 
            </if> 
 | 
            <if test="record.beginTime!=null and record.beginTime!=''  "> 
 | 
                and DATE_FORMAT(act_begin_time,'%Y-%m-%d %H:%i:%s')  >= DATE_FORMAT(#{record.beginTime} ,'%Y-%m-%d %H:%i:%s') 
 | 
            </if> 
 | 
            <if test="record.endTime!=null and record.endTime!='' "> 
 | 
                and DATE_FORMAT(#{record.endTime} ,'%Y-%m-%d %H:%i:%s') >= DATE_FORMAT(act_end_time,'%Y-%m-%d %H:%i:%s') 
 | 
            </if> 
 | 
            <if test="(record.createBy!=null and record.createBy!='') or  (record.createBy!='' and record.createBy==0)  "> 
 | 
                and create_by  = #{record.createBy}  
 | 
            </if> 
 | 
            <if test="(record.actStatus!=null and record.actStatus!='') or  (record.actStatus!='' and record.actStatus==0)  "> 
 | 
                and act_status  = #{record.actStatus}  
 | 
            </if> 
 | 
            <if test="(record.shopIds!=null and record.shopIds!='') or  (record.shopIds!='' and record.shopIds==0)  "> 
 | 
                and find_in_set(#{record.shopIds}, shop_ids) 
 | 
            </if> 
 | 
            <if test="(record.actRemark!=null and record.actRemark!='') or  (record.actRemark!='' and record.actRemark==0)  "> 
 | 
                and act_remark  = #{record.actRemark}  
 | 
            </if> 
 | 
            <if test="(record.actMax!=null and record.actMax!='') or  (record.actMax!='' and record.actMax==0)  "> 
 | 
                and act_max  = #{record.actMax}  
 | 
            </if> 
 | 
        </if> 
 | 
          
 | 
    </sql> 
 | 
     
 | 
    <!--  插入方法   --> 
 | 
    <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopActivities" 
 | 
        useGeneratedKeys="true" keyProperty="item.id"> 
 | 
        INSERT INTO shop_activities ( 
 | 
             <include refid="columns"></include> 
 | 
        ) 
 | 
    VALUES ( 
 | 
         <include refid="propertys"></include> 
 | 
    ) 
 | 
    </insert> 
 | 
     
 | 
     
 | 
     
 | 
    <!--  批量插入   --> 
 | 
    <insert id="batchInsert" parameterType="java.util.List"> 
 | 
        INSERT INTO shop_activities ( 
 | 
        <include refid="columns"></include>     
 | 
        ) 
 | 
    VALUES  
 | 
    <foreach collection="list" item="item" index="index" separator=",">( 
 | 
        <include refid="propertys"></include>     
 | 
    )</foreach> 
 | 
    </insert> 
 | 
     
 | 
     
 | 
     
 | 
     
 | 
     
 | 
    <!--  根据Map更新 部分更新   --> 
 | 
    <update id="updateByMap" parameterType="java.util.HashMap" > 
 | 
        UPDATE shop_activities 
 | 
        <set> 
 | 
            <if test="_parameter.containsKey('actName')"> 
 | 
                    act_name = #{actName}, 
 | 
                </if>         
 | 
            <if test="_parameter.containsKey('actType')"> 
 | 
                    act_type = #{actType}, 
 | 
                </if>         
 | 
            <if test="_parameter.containsKey('actBeginTime')"> 
 | 
                    act_begin_time = #{actBeginTime}, 
 | 
                </if>         
 | 
            <if test="_parameter.containsKey('actEndTime')"> 
 | 
                    act_end_time = #{actEndTime}, 
 | 
                </if>         
 | 
            <if test="_parameter.containsKey('createBy')"> 
 | 
                    create_by = #{createBy}, 
 | 
                </if>         
 | 
            <if test="_parameter.containsKey('actStatus')"> 
 | 
                    act_status = #{actStatus}, 
 | 
                </if>         
 | 
            <if test="_parameter.containsKey('shopIds')"> 
 | 
                    shop_ids = #{shopIds}, 
 | 
                </if>         
 | 
            <if test="_parameter.containsKey('actRemark')"> 
 | 
                    act_remark = #{actRemark}, 
 | 
                </if>         
 | 
            <if test="_parameter.containsKey('actMax')"> 
 | 
                    act_max = #{actMax}, 
 | 
                </if>         
 | 
        </set> 
 | 
        WHERE id=#{id}  
 | 
    </update>  
 | 
     
 | 
     
 | 
    <!--  根据对象更新 部分更新   --> 
 | 
    <update id="updateByModel" parameterType="Long"> 
 | 
        UPDATE shop_activities 
 | 
        <set> 
 | 
            <if test="record.actName != null and record.actName != '' "> 
 | 
                act_name  = #{record.actName}, 
 | 
            </if> 
 | 
            <if test="record.actCode != null "> 
 | 
                act_code  = #{record.actCode}, 
 | 
            </if> 
 | 
  
 | 
            <if test="record.actContent != null "> 
 | 
                act_content  = #{record.actContent}, 
 | 
            </if> 
 | 
            <if test="record.actType != null "> 
 | 
                act_type  = #{record.actType},  
 | 
            </if> 
 | 
            <if test="record.actBeginTime != null "> 
 | 
                act_begin_time  = #{record.actBeginTime},  
 | 
            </if> 
 | 
            <if test="record.actEndTime != null "> 
 | 
                act_end_time  = #{record.actEndTime},  
 | 
            </if> 
 | 
            <if test="record.createBy != null and record.createBy != '' "> 
 | 
                create_by  = #{record.createBy},  
 | 
            </if> 
 | 
            <if test="record.actStatus != null "> 
 | 
                act_status  = #{record.actStatus},  
 | 
            </if> 
 | 
            <if test="record.shopIds != null and record.shopIds != '' "> 
 | 
                shop_ids  = #{record.shopIds},  
 | 
            </if> 
 | 
            <if test="record.actRemark != null and record.actRemark != '' "> 
 | 
                act_remark  = #{record.actRemark},  
 | 
            </if> 
 | 
            <if test="record.actMax != null "> 
 | 
                act_max  = #{record.actMax},  
 | 
            </if> 
 | 
        </set> 
 | 
        WHERE id=#{record.id}  
 | 
    </update> 
 | 
     
 | 
    <!-- 批量删除 --> 
 | 
    <delete id="deleteByIds" parameterType="java.util.List"> 
 | 
        delete from shop_activities where  id in 
 | 
        <foreach collection="list" index="index" item="item" open="(" 
 | 
            separator="," close=")"> 
 | 
            #{item} 
 | 
        </foreach> 
 | 
    </delete> 
 | 
         
 | 
    <!-- 根据id删除--> 
 | 
    <delete id="deleteById" parameterType="Long"> 
 | 
        DELETE FROM shop_activities 
 | 
        where  id=#{id}  
 | 
    </delete> 
 | 
     
 | 
    <!-- 根据对象删除--> 
 | 
    <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopActivities"> 
 | 
        DELETE FROM shop_activities 
 | 
        <where> 
 | 
        <include refid="where_sql" ></include> 
 | 
        </where> 
 | 
    </delete> 
 | 
     
 | 
     
 | 
     
 | 
    <!-- 分页查询 --> 
 | 
    <select id="selectInPage" resultMap="ShopActivitiesMap"> 
 | 
        select  
 | 
        <include refid="columns" ></include> 
 | 
        from shop_activities 
 | 
        <where> 
 | 
          <include refid="where_sql"></include> 
 | 
         </where> 
 | 
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> 
 | 
            order by create_time desc 
 | 
            <if test="pageVo.offset >=0  and pageVo.limit >0"> 
 | 
                limit 
 | 
                #{pageVo.offset},#{pageVo.limit} 
 | 
            </if> 
 | 
        </if> 
 | 
    </select> 
 | 
     
 | 
    <!-- 查询总条数 --> 
 | 
    <select id="selectTotalRecord" parameterType="long"   resultType="java.lang.Integer"> 
 | 
    select count(*) 
 | 
    from shop_activities 
 | 
        <where> 
 | 
           <include refid="where_sql"></include> 
 | 
        </where> 
 | 
    </select> 
 | 
  
 | 
    <!-- 根据id查询--> 
 | 
    <select id="selectById" resultMap="ShopActivitiesMap"> 
 | 
        select *, 
 | 
               if(now()>act_begin_time, 1, 2) isStart, 
 | 
            TIMESTAMPDIFF(SECOND, now(), act_end_time) remainTime 
 | 
        from shop_activities 
 | 
        where  id=#{id}  
 | 
    </select>     
 | 
     
 | 
     
 | 
    <!-- 根据id 锁表查询--> 
 | 
    <select id="selectForUpdate" resultMap="ShopActivitiesMap"> 
 | 
        select  
 | 
        <include refid="columns" ></include> 
 | 
        from shop_activities 
 | 
        where  id=#{id}  
 | 
        for update 
 | 
    </select>     
 | 
     
 | 
     
 | 
     
 | 
    <!-- 根据对象查询--> 
 | 
    <select id="selectByModel" resultMap="ShopActivitiesMap"> 
 | 
        select  
 | 
        <include refid="columns" ></include> 
 | 
        from shop_activities 
 | 
        <where> 
 | 
          <include refid="where_sql"></include> 
 | 
         </where> 
 | 
    </select> 
 | 
  
 | 
    <select id="selectShopActivitiesById" resultMap="ShopActivitiesMap"> 
 | 
        select 
 | 
            t1.*, 
 | 
            t2.id giId, 
 | 
            t2.goods_id, 
 | 
            t3.title goods_name, 
 | 
            t2.gi_type, 
 | 
            t2.gi_head_discount, 
 | 
            t2.gi_limit_buy, 
 | 
            t2.gi_virtual_group 
 | 
        from shop_activities t1 
 | 
        inner join shop_activities_group_info t2 on t1.id=t2.act_id 
 | 
        left join shop_product t3 on t2.goods_id=t3.id 
 | 
        where t1.id=#{id} 
 | 
    </select> 
 | 
  
 | 
  
 | 
    <select id="selectShopActivitiesHasEnd" resultMap="ShopActivitiesMap"> 
 | 
        select 
 | 
            t1.*, 
 | 
            t2.id giId, 
 | 
            t2.goods_id, 
 | 
            t2.gi_type, 
 | 
            t2.gi_head_discount, 
 | 
            t2.gi_virtual_group 
 | 
        from shop_activities t1 
 | 
        inner join shop_activities_group_info t2 on t1.id=t2.act_id 
 | 
        where now() >= t1.act_end_time and act_status=1 
 | 
    </select> 
 | 
  
 | 
    <update id="batchUpdateActStatus"> 
 | 
        <foreach collection="list" index="index" item="item" separator=";"> 
 | 
            update shop_activities set act_status=#{status} 
 | 
            where id=#{item.id} 
 | 
        </foreach> 
 | 
    </update> 
 | 
  
 | 
    <select id="selectSecKillActivitiesForIng" resultMap="ShopActivitiesMap"> 
 | 
        select 
 | 
            *, 
 | 
            if(now()>act_begin_time, 1, 2) isStart, 
 | 
            TIMESTAMPDIFF(SECOND, now(), act_end_time) remainTime, 
 | 
            act_begin_time title 
 | 
        from shop_activities 
 | 
        where act_type=2 and act_end_time > now() and find_in_set(#{shopId}, shop_ids) and act_status = 1 
 | 
    </select> 
 | 
  
 | 
    <select id="selectSalonActivityById" resultMap="ShopActivitiesMap"> 
 | 
        select t1.*, t2.id sd_id, t2.attr_name 
 | 
        from shop_activities t1 
 | 
        inner join shop_activities_salon_distribute t2 on t1.id=t2.act_id 
 | 
        where t1.id= #{id} 
 | 
    </select> 
 | 
  
 | 
    <select id="selectSalonActivityByUser" resultMap="ShopActivitiesMap"> 
 | 
        select t1.*, t2.id asr_id,t2.user_id,t2.shop_id,t2.remark,t2.status 
 | 
        from shop_activities t1 
 | 
        inner join shop_activities_salon_record t2 on t1.id=t2.act_id 
 | 
        where t2.user_id=#{record.userId} 
 | 
        <if test="record!=null"> 
 | 
            order by t1.create_time desc 
 | 
            <if test="record.offset >=0  and record.limit >0"> 
 | 
                limit 
 | 
                #{record.offset},#{record.limit} 
 | 
            </if> 
 | 
        </if> 
 | 
    </select> 
 | 
  
 | 
    <select id="findActivitiesList" resultType="com.matrix.system.activity.vo.ActivitiesListVo"> 
 | 
        SELECT 
 | 
            * 
 | 
        FROM 
 | 
        shop_activities a 
 | 
        <where> 
 | 
            a.company_id=#{record.companyId} 
 | 
            <if test="record.hdzt != null and record.hdzt != ''"> 
 | 
                and a.act_status=#{record.hdzt} 
 | 
            </if> 
 | 
            <if test="record.hdmc != null and record.hdmc != ''"> 
 | 
                and a.act_name like concat('%',#{record.hdmc},'%') 
 | 
            </if> 
 | 
        </where> 
 | 
        <if test="record.sort !=null"> 
 | 
            order by 
 | 
            a.${record.sort} ${record.order} 
 | 
        </if> 
 | 
    </select> 
 | 
  
 | 
    <select id="selectOneByCompanyIdAndActTypeAndActStatus" resultType="com.matrix.system.shopXcx.bean.ShopActivities"> 
 | 
        SELECT 
 | 
        * 
 | 
        FROM 
 | 
        shop_activities a 
 | 
        where 
 | 
            a.company_id=#{companyId} 
 | 
            and a.act_type=#{activitiesTypeSign} 
 | 
            and a.act_status=#{actstatusStatusIng} 
 | 
    </select> 
 | 
  
 | 
    <select id="selectOneByCompanyIdAndActType" resultType="com.matrix.system.shopXcx.bean.ShopActivities"> 
 | 
        SELECT 
 | 
            * 
 | 
        FROM 
 | 
            shop_activities a 
 | 
        where 
 | 
            a.company_id=#{companyId} 
 | 
          and a.act_type=#{activitiesTypeSign} 
 | 
          and a.act_status != 5 
 | 
    </select> 
 | 
</mapper> 
 |