| <?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.ShopCollectionDao"> | 
|     <!-- 定义ShopCollection 的复杂关联map --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopCollection" id="ShopCollectionMap"> | 
|         <id property="collId" column="coll_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="collUserid" column="coll_userid" /> | 
|             <result property="collProductid" column="coll_productid" /> | 
|             <result property="categoryId" column="category_id" /> | 
|             <result property="title" column="title" /> | 
|             <result property="briefIntroduction" column="brief_introduction" /> | 
|             <result property="carriage" column="carriage" /> | 
|             <result property="imgPc" column="img_pc" /> | 
|             <result property="imgMobile" column="img_mobile" /> | 
|             <result property="brand" column="brand" /> | 
|             <result property="price" column="price" /> | 
|             <result property="pcDetails" column="pc_details" /> | 
|             <result property="mobileDetails" column="mobile_details" /> | 
|             <result property="buyLimit" column="buy_limit" /> | 
|             <result property="limitCycle" column="limit_cycle" /> | 
|             <result property="isCanComment" column="is_can_comment" /> | 
|             <result property="mnemonicCode" column="mnemonic_code" /> | 
|             <result property="status" column="status" /> | 
|             <result property="dsVolume" column="ds_volume" /> | 
|             <result property="rsVolume" column="rs_volume" /> | 
|             <result property="delFlag" column="del_flag" /> | 
|             <result property="userName" column="user_name" /> | 
|             <result property="nickName" column="nick_name" /> | 
|             <result property="phoneNumber" column="phone_number" /> | 
|         <result property="companyId" column="company_id" /> | 
|     </resultMap> | 
|      | 
|      | 
|     <!-- 定义ShopCollection 的简单map  ,本map不添加其他的关联属性 --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopCollection" id="ShopCollectionSimpleMap"> | 
|         <id property="collId" column="coll_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="collUserid" column="coll_userid" /> | 
|             <result property="collProductid" column="coll_productid" /> | 
|         <result property="companyId" column="company_id" /> | 
|     </resultMap> | 
|      | 
|     <!-- 字段sql --> | 
|     <sql id="columns"> | 
|         create_by, | 
|         create_time, | 
|         update_by, | 
|         update_time, | 
|             coll_id, | 
|             coll_userid, | 
|             coll_productid, | 
|             company_id | 
|     </sql> | 
|      | 
|     <!-- 属性sql --> | 
|     <sql id="propertys"> | 
|         #{item.createBy}, | 
|         now(), | 
|         #{item.updateBy}, | 
|         now(), | 
|             #{item.collId}, | 
|             #{item.collUserid}, | 
|             #{item.collProductid}, | 
|         #{item.companyId} | 
|     </sql> | 
|      | 
|     <!-- where sql --> | 
|     <sql id="where_sql"> | 
|           | 
|          <if test="record!=null"> | 
|             <if test="(record.collId!=null and record.collId!='') or  (record.collId!='' and record.collId==0)  "> | 
|                 and coll_id  = #{record.collId}  | 
|             </if> | 
|             <if test="(record.collUserid!=null and record.collUserid!='') or  (record.collUserid!='' and record.collUserid==0)  "> | 
|                 and coll_userid  = #{record.collUserid}  | 
|             </if> | 
|             <if test="(record.collProductid!=null and record.collProductid!='') or  (record.collProductid!='' and record.collProductid==0)  "> | 
|                 and coll_productid  = #{record.collProductid}  | 
|             </if> | 
|              <if test="(record.nickName!=null and record.nickName!='') or  (record.nickName!='' and record.nickName==0)  "> | 
|                  and u.nick_name like concat('%',#{record.nickName},'%') | 
|              </if> | 
|              <if test="(record.title!=null and record.title!='') or  (record.title!='' and record.title==0)  "> | 
|                  and p.title like concat('%',#{record.title},'%') | 
|              </if> | 
|              <if test="(record.collectionBeginTime!=null and record.collectionBeginTime!='')"> | 
|                  and date_format(c.create_time, '%Y-%m-%d') >= #{record.collectionBeginTime} | 
|              </if> | 
|              <if test="(record.collectionEndTime!=null and record.collectionEndTime!='')"> | 
|                  and  #{record.collectionEndTime} >= date_format(c.create_time, '%Y-%m-%d') | 
|              </if> | 
|              <if test="record.companyId != null and record.companyId !='' "> | 
|                  and c.company_id = #{record.companyId} | 
|              </if> | 
|   | 
|          </if> | 
|           | 
|     </sql> | 
|      | 
|     <!--  插入方法   --> | 
|     <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopCollection" | 
|         useGeneratedKeys="true" keyProperty="item.collId"> | 
|         INSERT INTO shop_collection ( | 
|              <include refid="columns"></include> | 
|         ) | 
|     VALUES ( | 
|          <include refid="propertys"></include> | 
|     ) | 
|     </insert> | 
|      | 
|      | 
|      | 
|     <!--  批量插入   --> | 
|     <insert id="batchInsert" parameterType="java.util.List"> | 
|         INSERT INTO shop_collection ( | 
|         <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_collection | 
|         <set> | 
|             <if test="_parameter.containsKey('collUserid')"> | 
|                     coll_userid = #{collUserid}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('collProductid')"> | 
|                     coll_productid = #{collProductid}, | 
|                 </if>         | 
|         </set> | 
|         WHERE coll_id=#{collId}  | 
|     </update>  | 
|      | 
|      | 
|     <!--  根据对象更新 部分更新   --> | 
|     <update id="updateByModel" parameterType="Integer"> | 
|         UPDATE shop_collection | 
|         <set> | 
|             <if test="record.collUserid != null and record.collUserid != '' "> | 
|                 coll_userid  = #{record.collUserid},  | 
|             </if> | 
|             <if test="record.collProductid != null "> | 
|                 coll_productid  = #{record.collProductid},  | 
|             </if> | 
|         </set> | 
|         WHERE coll_id=#{record.collId}  | 
|     </update> | 
|      | 
|     <!-- 批量删除 --> | 
|     <delete id="deleteByIds" parameterType="java.util.List"> | 
|         delete from shop_collection where  coll_id in | 
|         <foreach collection="list" index="index" item="item" open="(" | 
|             separator="," close=")"> | 
|             #{item} | 
|         </foreach> | 
|     </delete> | 
|          | 
|     <!-- 根据id删除--> | 
|     <delete id="deleteById" parameterType="Integer"> | 
|         DELETE FROM shop_collection | 
|         where  coll_id=#{collId}  | 
|     </delete> | 
|   | 
|     <!-- 根据用户下的产品id删除--> | 
|     <delete id="deleteByProductId" parameterType="java.util.HashMap"> | 
|         DELETE FROM shop_collection | 
|         where  1=1 | 
|         <if test="_parameter.containsKey('collUserid')"> | 
|             and coll_userid = #{collUserid} | 
|         </if> | 
|         <if test="_parameter.containsKey('collProductid')"> | 
|             and coll_productid = #{collProductid} | 
|         </if> | 
|   | 
|   | 
|   | 
|     </delete> | 
|      | 
|     <!-- 根据对象删除--> | 
|     <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopCollection"> | 
|         DELETE FROM shop_collection | 
|         <where> | 
|         <include refid="where_sql" ></include> | 
|         </where> | 
|     </delete> | 
|      | 
|      | 
|      | 
|     <!-- 分页查询 --> | 
|     <select id="selectInPage" resultMap="ShopCollectionMap"> | 
|         select | 
|         c.create_by, | 
|         c.create_time, | 
|         c.update_by, | 
|         c.update_time, | 
|         c.coll_id, | 
|         c.coll_userid, | 
|         c.coll_productid, | 
|         u.user_name, | 
|         u.nick_name, | 
|         u.phone_number, | 
|         p.title | 
|         from shop_collection c | 
|         LEFT JOIN biz_user u ON c.coll_userid = u.open_id | 
|         LEFT JOIN shop_product p ON c.coll_productid = p.id | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|         <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> | 
|             order by c.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_collection c | 
|         LEFT JOIN biz_user u ON c.coll_userid = u.open_id | 
|         LEFT JOIN shop_product p ON c.coll_productid = p.id | 
|         <where> | 
|            <include refid="where_sql"></include> | 
|         </where> | 
|     </select> | 
|   | 
|     <!-- 根据id查询--> | 
|     <select id="selectById" resultMap="ShopCollectionMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_collection | 
|         where  coll_id=#{collId}  | 
|     </select> | 
|   | 
|     <!-- 根据用户id查询--> | 
|     <select id="selectByUserId" resultMap="ShopCollectionMap"> | 
|         SELECT | 
|             c.create_by, | 
|             c.create_time, | 
|             c.update_by, | 
|             c.update_time, | 
|             c.coll_id, | 
|             c.coll_userid, | 
|             c.coll_productid, | 
|             p.category_id, | 
|             p.title, | 
|             p.brief_introduction, | 
|             p.carriage, | 
|             p.img_pc, | 
|             p.img_mobile, | 
|             p.brand, | 
|             p.price, | 
|             p.pc_details, | 
|             p.mobile_details, | 
|             p.buy_limit, | 
|             p.limit_cycle, | 
|             p.is_can_comment, | 
|             p.mnemonic_code, | 
|             p.status, | 
|             p.ds_volume, | 
|             p.rs_volume, | 
|             p.del_flag | 
|         FROM | 
|             shop_collection c | 
|         LEFT JOIN shop_product p ON c.coll_productid = p.id | 
|         <where> | 
|             <if test="record!=null"> | 
|                 <if test="(record.collUserid!=null and record.collUserid!='') or  (record.collUserid!='' and record.collUserid==0)  "> | 
|                     c.coll_productid IN ( SELECT n.coll_productid FROM shop_collection n WHERE n.coll_userid = #{record.collUserid} ) | 
|                     and c.coll_userid = #{record.collUserid} | 
|                 </if> | 
|             </if> | 
|         </where> | 
|         order by c.create_time desc | 
|         <if test="record.offset >=0  and record.limit >0"> | 
|             limit | 
|             #{record.offset},#{record.limit} | 
|         </if> | 
|     </select> | 
|   | 
|     <!-- 根据用户id和产品ID查询--> | 
|     <select id="selectByUserIdAndProid" resultMap="ShopCollectionMap"> | 
|         SELECT | 
|             c.create_by, | 
|             c.create_time, | 
|             c.update_by, | 
|             c.update_time, | 
|             c.coll_id, | 
|             c.coll_userid, | 
|             c.coll_productid, | 
|             p.category_id, | 
|             p.title, | 
|             p.brief_introduction, | 
|             p.carriage, | 
|             p.img_pc, | 
|             p.img_mobile, | 
|             p.brand, | 
|             p.price, | 
|             p.pc_details, | 
|             p.mobile_details, | 
|             p.buy_limit, | 
|             p.limit_cycle, | 
|             p.is_can_comment, | 
|             p.mnemonic_code, | 
|             p.status, | 
|             p.ds_volume, | 
|             p.rs_volume, | 
|             p.del_flag | 
|         FROM | 
|             shop_collection c | 
|         LEFT JOIN shop_product p ON c.coll_productid = p.id | 
|         WHERE | 
|         c.coll_productid = #{collProductid} | 
|         and c.coll_userid = #{collUserId} | 
|     </select> | 
|      | 
|      | 
|     <!-- 根据id 锁表查询--> | 
|     <select id="selectForUpdate" resultMap="ShopCollectionMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_collection | 
|         where  coll_id=#{coll_id}  | 
|         for update | 
|     </select>     | 
|      | 
|      | 
|      | 
|     <!-- 根据对象查询--> | 
|     <select id="selectByModel" resultMap="ShopCollectionMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_collection c | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|     </select> | 
| </mapper> |