| <?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.ShopActivitiesGroupJoinUserDao"> | 
|     <!-- 定义ShopActivitiesGroupJoinUser 的复杂关联map --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoinUser" id="ShopActivitiesGroupJoinUserMap"> | 
|         <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="gjId" column="gj_id" /> | 
|             <result property="giId" column="gi_id" /> | 
|             <result property="userId" column="user_id" /> | 
|             <result property="orderId" column="order_id" /> | 
|             <result property="isHead" column="is_head" /> | 
|         <result property="isHasPay" column="is_has_pay" /> | 
|         <result property="payEndTime" column="pay_end_time" /> | 
|         <result property="remainTime" column="remainTime" /> | 
|     </resultMap> | 
|      | 
|      | 
|     <!-- 定义ShopActivitiesGroupJoinUser 的简单map  ,本map不添加其他的关联属性 --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoinUser" id="ShopActivitiesGroupJoinUserSimpleMap"> | 
|         <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="gjId" column="gj_id" /> | 
|             <result property="giId" column="gi_id" /> | 
|             <result property="userId" column="user_id" /> | 
|             <result property="orderId" column="order_id" /> | 
|             <result property="isHead" column="is_head" /> | 
|         <result property="isHasPay" column="is_has_pay" /> | 
|         <result property="isHasCancel" column="is_has_cancel" /> | 
|         <result property="payEndTime" column="pay_end_time" /> | 
|         <result property="orderNo" column="order_no" /> | 
|         <result property="orderMoney" column="order_money" /> | 
|         <result property="count" column="purchase_quantity" /> | 
|         <result property="orderStatus" column="order_status" /> | 
|         <result property="payStatus" column="pay_status" /> | 
|         <result property="userName" column="nick_name" /> | 
|     </resultMap> | 
|      | 
|     <!-- 字段sql --> | 
|     <sql id="columns"> | 
|         create_by, | 
|         create_time, | 
|         update_by, | 
|         update_time, | 
|         id, | 
|         gj_id, | 
|         gi_id, | 
|         user_id, | 
|         order_id, | 
|         is_head, | 
|         is_has_pay, | 
|         pay_end_time, | 
|         is_new_user, | 
|         is_has_cancel | 
|     </sql> | 
|      | 
|     <!-- 属性sql --> | 
|     <sql id="propertys"> | 
|         #{item.createBy}, | 
|         now(), | 
|         #{item.updateBy}, | 
|         now(), | 
|         #{item.id}, | 
|         #{item.gjId}, | 
|         #{item.giId}, | 
|         #{item.userId}, | 
|         #{item.orderId}, | 
|         #{item.isHead}, | 
|         #{item.isHasPay}, | 
|         #{item.payEndTime}, | 
|         #{item.isNewUser}, | 
|         #{item.isHasCancel} | 
|     </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.gjId!=null and record.gjId!='') or  (record.gjId!='' and record.gjId==0)  "> | 
|                 and gj_id  = #{record.gjId}  | 
|             </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.userId!=null and record.userId!='') or  (record.userId!='' and record.userId==0)  "> | 
|                 and user_id  = #{record.userId}  | 
|             </if> | 
|             <if test="(record.orderId!=null and record.orderId!='') or  (record.orderId!='' and record.orderId==0)  "> | 
|                 and order_id  = #{record.orderId}  | 
|             </if> | 
|             <if test="(record.isHead!=null and record.isHead!='') or  (record.isHead!='' and record.isHead==0)  "> | 
|                 and is_head  = #{record.isHead}  | 
|             </if> | 
|              <if test="(record.isHasCancel!=null and record.isHasCancel!='') or  (record.isHasCancel!='' and record.isHasCancel==0)  "> | 
|                  and is_has_cancel  = #{record.isHasCancel} | 
|              </if> | 
|         </if> | 
|           | 
|     </sql> | 
|      | 
|     <!--  插入方法   --> | 
|     <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoinUser" | 
|         useGeneratedKeys="true" keyProperty="item.id"> | 
|         INSERT INTO shop_activities_group_join_user ( | 
|              <include refid="columns"></include> | 
|         ) | 
|     VALUES ( | 
|          <include refid="propertys"></include> | 
|     ) | 
|     </insert> | 
|      | 
|      | 
|      | 
|     <!--  批量插入   --> | 
|     <insert id="batchInsert" parameterType="java.util.List"> | 
|         INSERT INTO shop_activities_group_join_user ( | 
|         <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_user | 
|         <set> | 
|             <if test="_parameter.containsKey('gjId')"> | 
|                     gj_id = #{gjId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('giId')"> | 
|                     gi_id = #{giId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('userId')"> | 
|                     user_id = #{userId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('orderId')"> | 
|                     order_id = #{orderId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('isHead')"> | 
|                     is_head = #{isHead}, | 
|                 </if>         | 
|         </set> | 
|         WHERE id=#{id}  | 
|     </update>  | 
|      | 
|      | 
|     <!--  根据对象更新 部分更新   --> | 
|     <update id="updateByModel" parameterType="Long"> | 
|         UPDATE shop_activities_group_join_user | 
|         <set> | 
|             <if test="record.gjId != null "> | 
|                 gj_id  = #{record.gjId},  | 
|             </if> | 
|             <if test="record.giId != null "> | 
|                 gi_id  = #{record.giId},  | 
|             </if> | 
|             <if test="record.userId != null "> | 
|                 user_id  = #{record.userId},  | 
|             </if> | 
|             <if test="record.orderId != null "> | 
|                 order_id  = #{record.orderId},  | 
|             </if> | 
|             <if test="record.isHead != null "> | 
|                 is_head  = #{record.isHead},  | 
|             </if> | 
|             <if test="record.isHasPay != null"> | 
|                 is_has_pay = #{record.isHasPay}, | 
|             </if> | 
|             <if test="record.isHasCancel != null"> | 
|                 is_has_cancel = #{record.isHasCancel} | 
|             </if> | 
|         </set> | 
|         WHERE id=#{record.id}  | 
|     </update> | 
|      | 
|     <!-- 批量删除 --> | 
|     <delete id="deleteByIds" parameterType="java.util.List"> | 
|         delete from shop_activities_group_join_user 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_user | 
|         where  id=#{id}  | 
|     </delete> | 
|      | 
|     <!-- 根据对象删除--> | 
|     <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoinUser"> | 
|         DELETE FROM shop_activities_group_join_user | 
|         <where> | 
|         <include refid="where_sql" ></include> | 
|         </where> | 
|     </delete> | 
|      | 
|      | 
|      | 
|     <!-- 分页查询 --> | 
|     <select id="selectInPage" resultMap="ShopActivitiesGroupJoinUserMap"> | 
|         select | 
|         <include refid="columns" ></include> | 
|         from shop_activities_group_join_user | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|         <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_user | 
|         <where> | 
|            <include refid="where_sql"></include> | 
|         </where> | 
|     </select> | 
|   | 
|     <!-- 根据id查询--> | 
|     <select id="selectById" resultMap="ShopActivitiesGroupJoinUserMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_activities_group_join_user | 
|         where  id=#{id}  | 
|     </select>     | 
|      | 
|      | 
|     <!-- 根据id 锁表查询--> | 
|     <select id="selectForUpdate" resultMap="ShopActivitiesGroupJoinUserMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_activities_group_join_user | 
|         where  id=#{id}  | 
|         for update | 
|     </select>     | 
|      | 
|      | 
|      | 
|     <!-- 根据对象查询--> | 
|     <select id="selectByModel" resultMap="ShopActivitiesGroupJoinUserMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_activities_group_join_user | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|     </select> | 
|   | 
|     <select id="selectGroupJoinUserByUserIdAndGjId" resultMap="ShopActivitiesGroupJoinUserMap"> | 
|         select | 
|             *, | 
|             TIMESTAMPDIFF(SECOND, now(), pay_end_time) remainTime | 
|         from shop_activities_group_join_user | 
|         where user_id=#{userId} and gj_id=#{gjId} and is_has_cancel=2 | 
|     </select> | 
|   | 
|     <select id="selectGroupJoinUserByOrderId" resultMap="ShopActivitiesGroupJoinUserMap"> | 
|         select * from shop_activities_group_join_user where order_id=#{orderId} | 
|     </select> | 
|   | 
|     <select id="selectGroupJoinUserListByGjId" resultMap="ShopActivitiesGroupJoinUserMap"> | 
|         select * from shop_activities_group_join_user where gj_id=#{gjId} and is_has_pay=1 and is_has_cancel=2 | 
|     </select> | 
|   | 
|     <select id="selectNewUserRecordByGjId" resultMap="ShopActivitiesGroupJoinUserMap"> | 
|         select * from shop_activities_group_join_user | 
|         where gj_id=#{gjId} and is_new_user=1 and is_has_cancel=2 | 
|     </select> | 
|   | 
|     <select id="selectGroupJoinUserEnd" resultMap="ShopActivitiesGroupJoinUserMap"> | 
|         select * from shop_activities_group_join_user | 
|         where now() >= pay_end_time and is_has_pay=2 | 
|     </select> | 
|   | 
|     <select id="selectGroupJoinUserByPayingAndUnCancel" resultMap="ShopActivitiesGroupJoinUserMap"> | 
|         select * from shop_activities_group_join_user | 
|         where gj_id=#{gjId} and is_has_pay=2 and is_has_cancel=2 | 
|         order by id | 
|     </select> | 
|   | 
|     <select id="selectGroupJoinUserInfo" resultMap="ShopActivitiesGroupJoinUserSimpleMap"> | 
|         select | 
|            t1.*, | 
|            t2.order_no, | 
|            t2.order_money, | 
|            t2.purchase_quantity, | 
|            t2.order_status, | 
|            t2.pay_status, | 
|            t3.nick_name | 
|         from shop_activities_group_join_user t1 | 
|         inner join shop_order t2 on t1.order_id=t2.id | 
|         inner join biz_user t3 on t1.user_id=t3.open_id | 
|         where t1.gj_id=#{gjId} | 
|     </select> | 
|   | 
|     <select id="selectCountHasBuy" resultType="java.lang.Integer"> | 
|         select IFNULL(sum(t2.purchase_quantity), 0) | 
|         from shop_activities_group_join_user t1 | 
|         inner join shop_order t2 on t1.order_id=t2.id | 
|         where t1.gi_id=#{giId} and t1.user_id=#{userId} and t1.is_has_cancel=2 | 
|     </select> | 
| </mapper> |