| <?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.ShopActivitiesGroupJoinDao"> | 
|     <!-- 定义ShopActivitiesGroupJoin 的复杂关联map --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoin" id="ShopActivitiesGroupJoinMap"> | 
|         <id property="id" column="id" /> | 
|         <result property="createBy" column="create_by" /> | 
|         <result property="createTime" column="create_time" /> | 
|         <result property="updateBy" column="update_by" /> | 
|         <result property="updateTime" column="update_time" /> | 
|             <result property="actId" column="act_id" /> | 
|             <result property="giId" column="gi_id" /> | 
|             <result property="gjNo" column="gj_no" /> | 
|             <result property="gjBeginTime" column="gj_begin_time" /> | 
|             <result property="gjEndTime" column="gj_end_time" /> | 
|             <result property="gjStatus" column="gj_status" /> | 
|             <result property="gjHeadId" column="gj_head_id" /> | 
|         <result property="companyId" column="company_id" /> | 
|         <result property="gpId" column="gp_id"/> | 
|         <result property="remainingTime" column="remainingTime" /> | 
|         <result property="avatarUrl" column="avatar_url"/> | 
|         <result property="headName" column="headName" /> | 
|         <association property="groupPrice" javaType="com.matrix.system.shopXcx.bean.ShopActivitiesGroupPrice" column="gp_id"> | 
|             <id property="id" column="gpId"/> | 
|             <result property="gpCount" column="gp_count"/> | 
|             <result property="gpPrice" column="gp_price" /> | 
|             <result property="gpHeadPrice" column="gp_head_price" /> | 
|         </association> | 
|         <collection property="joinUserList" ofType="com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoinUser" column="gj_id"> | 
|             <id property="id" column="gjuId"/> | 
|             <result property="createBy" column="createBy" /> | 
|             <result property="createTime" column="createTime"/> | 
|             <result property="userId" column="user_id"/> | 
|             <result property="isHead" column="is_head"/> | 
|             <result property="orderId" column="order_id" /> | 
|             <result property="avatarUrl" column="avatarUrl" /> | 
|             <result property="isHasPay" column="is_has_pay" /> | 
|         </collection> | 
|     </resultMap> | 
|      | 
|      | 
|     <!-- 定义ShopActivitiesGroupJoin 的简单map  ,本map不添加其他的关联属性 --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoin" id="ShopActivitiesGroupJoinSimpleMap"> | 
|         <id property="id" column="id" /> | 
|         <result property="createBy" column="create_by" /> | 
|         <result property="createTime" column="create_time" /> | 
|         <result property="updateBy" column="update_by" /> | 
|         <result property="updateTime" column="update_time" /> | 
|             <result property="actId" column="act_id" /> | 
|             <result property="giId" column="gi_id" /> | 
|             <result property="gjNo" column="gj_no" /> | 
|             <result property="gjBeginTime" column="gj_begin_time" /> | 
|             <result property="gjEndTime" column="gj_end_time" /> | 
|             <result property="gjStatus" column="gj_status" /> | 
|             <result property="gjHeadId" column="gj_head_id" /> | 
|     </resultMap> | 
|      | 
|     <!-- 字段sql --> | 
|     <sql id="columns"> | 
|         create_by, | 
|         create_time, | 
|         update_by, | 
|         update_time, | 
|             id, | 
|             act_id, | 
|             gi_id, | 
|             gj_no, | 
|             gj_begin_time, | 
|             gj_end_time, | 
|             gj_status, | 
|             gj_head_id, | 
|             gp_id, | 
|             company_id | 
|     </sql> | 
|      | 
|     <!-- 属性sql --> | 
|     <sql id="propertys"> | 
|         #{item.createBy}, | 
|         now(), | 
|         #{item.updateBy}, | 
|         now(), | 
|             #{item.id}, | 
|             #{item.actId}, | 
|             #{item.giId}, | 
|             #{item.gjNo}, | 
|             #{item.gjBeginTime}, | 
|             #{item.gjEndTime}, | 
|             #{item.gjStatus}, | 
|             #{item.gjHeadId}, | 
|             #{item.gpId}, | 
|             #{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.actId!=null and record.actId!='') or  (record.actId!='' and record.actId==0)  "> | 
|                 and act_id  = #{record.actId} | 
|             </if> | 
|             <if test="(record.giId!=null and record.giId!='') or  (record.giId!='' and record.giId==0)  "> | 
|                 and gi_id  = #{record.giId}  | 
|             </if> | 
|             <if test="(record.gjNo!=null and record.gjNo!='') or  (record.gjNo!='' and record.gjNo==0)  "> | 
|                 and gj_no  = #{record.gjNo}  | 
|             </if> | 
|             <if test="(record.gjBeginTime!=null and record.gjBeginTime!='') or  (record.gjBeginTime!='' and record.gjBeginTime==0)  "> | 
|                 and gj_begin_time  = #{record.gjBeginTime}  | 
|             </if> | 
|             <if test="(record.gjEndTime!=null and record.gjEndTime!='') or  (record.gjEndTime!='' and record.gjEndTime==0)  "> | 
|                 and gj_end_time  = #{record.gjEndTime}  | 
|             </if> | 
|             <if test="(record.gjStatus!=null and record.gjStatus!='') or  (record.gjStatus!='' and record.gjStatus==0)  "> | 
|                 and gj_status  = #{record.gjStatus}  | 
|             </if> | 
|             <if test="(record.gjHeadId!=null and record.gjHeadId!='') or  (record.gjHeadId!='' and record.gjHeadId==0)  "> | 
|                 and gj_head_id  = #{record.gjHeadId}  | 
|             </if> | 
|         </if> | 
|           | 
|     </sql> | 
|      | 
|     <!--  插入方法   --> | 
|     <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoin" | 
|         useGeneratedKeys="true" keyProperty="item.id"> | 
|         INSERT INTO shop_activities_group_join ( | 
|              <include refid="columns"></include> | 
|         ) | 
|     VALUES ( | 
|          <include refid="propertys"></include> | 
|     ) | 
|     </insert> | 
|      | 
|      | 
|      | 
|     <!--  批量插入   --> | 
|     <insert id="batchInsert" parameterType="java.util.List"> | 
|         INSERT INTO shop_activities_group_join ( | 
|         <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_group_join | 
|         <set> | 
|             <if test="_parameter.containsKey('actId')"> | 
|                     act_id = #{actId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('giId')"> | 
|                     gi_id = #{giId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('gjNo')"> | 
|                     gj_no = #{gjNo}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('gjBeginTime')"> | 
|                     gj_begin_time = #{gjBeginTime}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('gjEndTime')"> | 
|                     gj_end_time = #{gjEndTime}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('gjStatus')"> | 
|                     gj_status = #{gjStatus}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('gjHeadId')"> | 
|                     gj_head_id = #{gjHeadId}, | 
|                 </if>         | 
|         </set> | 
|         WHERE id=#{id}  | 
|     </update>  | 
|      | 
|      | 
|     <!--  根据对象更新 部分更新   --> | 
|     <update id="updateByModel" parameterType="Long"> | 
|         UPDATE shop_activities_group_join | 
|         <set> | 
|             <if test="record.actId != null "> | 
|                 act_id  = #{record.actId},  | 
|             </if> | 
|             <if test="record.giId != null "> | 
|                 gi_id  = #{record.giId},  | 
|             </if> | 
|             <if test="record.gjNo != null "> | 
|                 gj_no  = #{record.gjNo},  | 
|             </if> | 
|             <if test="record.gjBeginTime != null "> | 
|                 gj_begin_time  = #{record.gjBeginTime},  | 
|             </if> | 
|             <if test="record.gjEndTime != null "> | 
|                 gj_end_time  = #{record.gjEndTime},  | 
|             </if> | 
|             <if test="record.gjStatus != null "> | 
|                 gj_status  = #{record.gjStatus},  | 
|             </if> | 
|             <if test="record.gjHeadId != null "> | 
|                 gj_head_id  = #{record.gjHeadId},  | 
|             </if> | 
|         </set> | 
|         WHERE id=#{record.id}  | 
|     </update> | 
|      | 
|     <!-- 批量删除 --> | 
|     <delete id="deleteByIds" parameterType="java.util.List"> | 
|         delete from shop_activities_group_join 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_group_join | 
|         where  id=#{id}  | 
|     </delete> | 
|      | 
|     <!-- 根据对象删除--> | 
|     <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoin"> | 
|         DELETE FROM shop_activities_group_join | 
|         <where> | 
|         <include refid="where_sql" ></include> | 
|         </where> | 
|     </delete> | 
|      | 
|      | 
|      | 
|     <!-- 分页查询 --> | 
|     <select id="selectInPage" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select | 
|             t1.*, | 
|             t2.gp_count, | 
|             t2.gp_price, | 
|             t2.gp_head_price, | 
|             t3.nick_name headName | 
|         from shop_activities_group_join t1 | 
|         inner join shop_activities_group_price t2 on t1.gp_id=t2.id | 
|         inner join sys_vip_info t3 on t1.gj_head_id=t3.id | 
|         where t1.act_id  = #{record.actId} | 
|         <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> | 
|             <if test="pageVo.sort !=null  and pageVo.order !=null"> | 
|                 order by | 
|                 ${pageVo.sort} ${pageVo.order} | 
|             </if> | 
|             <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_group_join | 
|     where act_id  = #{record.actId} | 
|     </select> | 
|   | 
|     <!-- 根据id查询--> | 
|     <select id="selectById" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_activities_group_join | 
|         where  id=#{id}  | 
|     </select>     | 
|      | 
|      | 
|     <!-- 根据id 锁表查询--> | 
|     <select id="selectForUpdate" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_activities_group_join | 
|         where  id=#{id}  | 
|         for update | 
|     </select>     | 
|      | 
|      | 
|      | 
|     <!-- 根据对象查询--> | 
|     <select id="selectByModel" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_activities_group_join | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|     </select> | 
|   | 
|     <select id="selectOwnerGroupJoinInfo" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select | 
|             t1.*, | 
|             TIMESTAMPDIFF(SECOND, now(), t1.gj_end_time) remainingTime, | 
|             t2.id gjuId, | 
|             t2.is_head, | 
|             t2.create_by createBy, | 
|             t2.create_time createTime, | 
|             t2.user_id, | 
|             t3.avatar_url avatarUrl | 
|         from shop_activities_group_join t1 | 
|         inner join shop_activities_group_join_user t2 on t1.id=t2.gj_id and t2.is_has_cancel=2 and t2.is_has_pay=1 | 
|         left join sys_vip_info t3 on t2.user_id=t3.id | 
|         where t1.id=#{gjId} | 
|     </select> | 
|   | 
|     <select id="selectOwnerGroupJoinInfoWithNoPay" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select | 
|             t1.*, | 
|             TIMESTAMPDIFF(SECOND, now(), t1.gj_end_time) remainingTime, | 
|             t2.id gjuId, | 
|             t2.is_head, | 
|             t2.create_by createBy, | 
|             t2.create_time createTime, | 
|             t2.user_id, | 
|             t2.is_has_pay, | 
|             t3.avatar_url avatarUrl | 
|         from shop_activities_group_join t1 | 
|         inner join shop_activities_group_join_user t2 on t1.id=t2.gj_id and t2.is_has_cancel=2 | 
|         left join sys_vip_info t3 on t2.user_id=t3.id | 
|         where t1.id=#{gjId} | 
|     </select> | 
|   | 
|     <select id="selectIsExistGroupInfoByUserId" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select t1.* | 
|         from shop_activities_group_join t1 | 
|         inner join shop_activities_group_join_user t2 on t1.id=t2.gj_id and t2.is_has_cancel=2 | 
|         where t1.act_id=#{actId} and t2.user_id=#{userId} and t1.gj_status in (3,4) | 
|     </select> | 
|   | 
|   | 
|   | 
|     <select id="selectGroupingListByActId" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select | 
|             t1.*, | 
|             TIMESTAMPDIFF(SECOND, now(), t1.gj_end_time) remainingTime, | 
|             t2.id gpId, | 
|             t2.gp_count, | 
|             t2.gp_price, | 
|             t3.avatar_url | 
|         from shop_activities_group_join t1 | 
|         inner join shop_activities_group_price t2 on t1.gp_id=t2.id | 
|         left join sys_vip_info t3 on t1.gj_head_id=t3.id | 
|         where t1.act_id=#{actId} and t1.gj_status=3 | 
|     </select> | 
|   | 
|     <select id="selectGroupAndPriceById" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select | 
|             t1.*, | 
|             t2.id gpId, | 
|             t2.gp_count, | 
|             t2.gp_price | 
|         from shop_activities_group_join t1 | 
|         inner join shop_activities_group_price t2 on t1.gp_id=t2.id | 
|         where t1.id=#{gjId} | 
|     </select> | 
|   | 
|     <select id="selectExistGroupingJoinByUser" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select * from shop_activities_group_join | 
|         where act_id=#{actId} and gj_head_id=#{userId} and gj_status in (3,4) | 
|     </select> | 
|   | 
|     <select id="selectAllGroupBuyByActId" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select * from shop_activities_group_join | 
|         where act_id=#{actId} | 
|     </select> | 
|   | 
|     <select id="selectAllGroupBuyWithUserByActId" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select | 
|             t1.*, | 
|             t2.id gjuId, | 
|             t2.is_head, | 
|             t2.create_by createBy, | 
|             t2.create_time createTime, | 
|             t2.user_id, | 
|             t2.order_id, | 
|             t2.is_has_pay | 
|         from shop_activities_group_join t1 | 
|         inner join shop_activities_group_join_user t2 on t1.id=t2.gj_id and t2.is_has_cancel=2 | 
|         where act_id=#{actId} | 
|         <if test="status != null"> | 
|             and gj_status=#{status} | 
|         </if> | 
|     </select> | 
|   | 
|     <select id="selectGroupJoinWithEnd" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select | 
|         t1.*, | 
|         t2.id gjuId, | 
|         t2.is_head, | 
|         t2.create_by createBy, | 
|         t2.create_time createTime, | 
|         t2.user_id, | 
|         t2.order_id, | 
|         t2.is_has_pay | 
|         from shop_activities_group_join t1 | 
|         inner join shop_activities_group_join_user t2 on t1.id=t2.gj_id and t2.is_has_cancel=2 | 
|         where now() >= t1.gj_end_time and gj_status=3 | 
|     </select> | 
|   | 
|   | 
|     <select id="selectGroupBuyByOrderId" resultMap="ShopActivitiesGroupJoinMap"> | 
|         select t1.* | 
|         from shop_activities_group_join t1 | 
|         inner join shop_activities_group_join_user t2 on t1.id=t2.gj_id | 
|         where t2.order_id=#{orderId} | 
|     </select> | 
|   | 
|     <select id="selectCreateGroupBuyCount" resultType="java.lang.Integer"> | 
|         select count(1) | 
|         from shop_activities_group_join t1 | 
|         inner join shop_activities_group_join_user t2 on t1.id=t2.gj_id and t1.gj_head_id=t2.user_id and t2.is_has_cancel=2 | 
|         where t1.act_id=#{actId} and t1.gj_head_id=#{userId} | 
|     </select> | 
| </mapper> |