| <?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.ShopOrderDetailsDao"> | 
|     <!-- 定义ShopOrderDetails 的简单map  ,本map不添加其他的关联属性 --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopOrderDetails" id="ShopOrderDetailsMap"> | 
|         <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="orderId" column="order_id" /> | 
|             <result property="pId" column="p_id" /> | 
|             <result property="sId" column="s_id" /> | 
|             <result property="price" column="price" /> | 
|             <result property="count" column="count" /> | 
|             <result property="totalPrice" column="total_price" /> | 
|             <result property="sTitle" column="s_title" /> | 
|             <result property="discountExplain" column="discount_explain" /> | 
|             <result property="discountAmount" column="discount_amount" /> | 
|             <result property="payType" column="pay_type" /> | 
|             <result property="scoreCount" column="score_count" /> | 
|             <result property="totalScoreCount" column="total_score_count" /> | 
|     </resultMap> | 
|   | 
|     <!-- 定义ShopOrderDetails 的复杂map --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopOrderDetails" id="ShopOrderDetailsComplexMap"> | 
|         <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="orderId" column="order_id" /> | 
|             <result property="pId" column="p_id" /> | 
|             <result property="sId" column="s_id" /> | 
|             <result property="price" column="price" /> | 
|             <result property="count" column="count" /> | 
|             <result property="totalPrice" column="total_price" /> | 
|             <result property="sTitle" column="s_title" /> | 
|             <result property="discountExplain" column="discount_explain" /> | 
|             <result property="discountAmount" column="discount_amount" /> | 
|         <result property="payType" column="pay_type" /> | 
|         <result property="scoreCount" column="score_count" /> | 
|         <result property="totalScoreCount" column="total_score_count" /> | 
|   | 
|         <!--产品信息--> | 
|         <association property="shopProduct" column="p_id" | 
|             select="com.matrix.system.shopXcx.dao.ShopProductDao.selectById"/> | 
|         <!--规格信息--> | 
|         <association property="shopSku" column="s_id" | 
|             select="com.matrix.system.shopXcx.dao.ShopSkuDao.selectById"/> | 
|   | 
|     </resultMap> | 
|   | 
|      | 
|     <!-- 字段sql --> | 
|     <sql id="columns"> | 
|         create_by, | 
|         create_time, | 
|         update_by, | 
|         update_time, | 
|             id, | 
|             order_id, | 
|             p_id, | 
|             s_id, | 
|             price, | 
|             count, | 
|             total_price, | 
|             s_title, | 
|             discount_explain, | 
|             discount_amount, | 
|             pay_type, | 
|         score_count, | 
|         total_score_count | 
|     </sql> | 
|      | 
|     <!-- 属性sql --> | 
|     <sql id="propertys"> | 
|         #{item.createBy}, | 
|         now(), | 
|         #{item.updateBy}, | 
|         now(), | 
|             #{item.id}, | 
|             #{item.orderId}, | 
|             #{item.pId}, | 
|             #{item.sId}, | 
|             #{item.price}, | 
|             #{item.count}, | 
|             #{item.totalPrice}, | 
|             #{item.sTitle}, | 
|             #{item.discountExplain}, | 
|             #{item.discountAmount}, | 
|             #{item.payType}, | 
|             #{item.scoreCount}, | 
|             #{item.totalScoreCount} | 
|     </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.orderId!=null and record.orderId!='') or  (record.orderId!='' and record.orderId==0)  "> | 
|                 and order_id  = #{record.orderId}  | 
|             </if> | 
|             <if test="(record.pId!=null and record.pId!='') or  (record.pId!='' and record.pId==0)  "> | 
|                 and p_id  = #{record.pId}  | 
|             </if> | 
|             <if test="(record.sId!=null and record.sId!='') or  (record.sId!='' and record.sId==0)  "> | 
|                 and s_id  = #{record.sId}  | 
|             </if> | 
|             <if test="(record.price!=null and record.price!='') or  (record.price!='' and record.price==0)  "> | 
|                 and price  = #{record.price}  | 
|             </if> | 
|             <if test="(record.count!=null and record.count!='') or  (record.count!='' and record.count==0)  "> | 
|                 and count  = #{record.count}  | 
|             </if> | 
|             <if test="(record.totalPrice!=null and record.totalPrice!='') or  (record.totalPrice!='' and record.totalPrice==0)  "> | 
|                 and total_price  = #{record.totalPrice}  | 
|             </if> | 
|             <if test="(record.sTitle!=null and record.sTitle!='') or  (record.sTitle!='' and record.sTitle==0)  "> | 
|                 and s_title  = #{record.sTitle}  | 
|             </if> | 
|             <if test="(record.discountExplain!=null and record.discountExplain!='') or  (record.discountExplain!='' and record.discountExplain==0)  "> | 
|                 and discount_explain  = #{record.discountExplain}  | 
|             </if> | 
|             <if test="(record.discountAmount!=null and record.discountAmount!='') or  (record.discountAmount!='' and record.discountAmount==0)  "> | 
|                 and discount_amount  = #{record.discountAmount}  | 
|             </if> | 
|             <if test="(record.payType!=null and record.payType!='') or  (record.payType!='' and record.payType==0)  "> | 
|                 and pay_type  = #{record.payType} | 
|             </if> | 
|   | 
|             <if test="(record.scoreCount!=null and record.scoreCount!='') or  (record.scoreCount!='' and record.scoreCount==0)  "> | 
|                 and score_count  = #{record.scoreCount} | 
|             </if> | 
|   | 
|             <if test="(record.totalScoreCount!=null and record.totalScoreCount!='') or  (record.totalScoreCount!='' and record.totalScoreCount==0)  "> | 
|                 and total_score_count  = #{record.totalScoreCount} | 
|             </if> | 
|         </if> | 
|           | 
|     </sql> | 
|      | 
|     <!--  插入方法   --> | 
|     <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopOrderDetails" | 
|         useGeneratedKeys="true" keyProperty="item.id"> | 
|         INSERT INTO shop_order_details ( | 
|              <include refid="columns"></include> | 
|         ) | 
|     VALUES ( | 
|          <include refid="propertys"></include> | 
|     ) | 
|     </insert> | 
|      | 
|      | 
|      | 
|     <!--  批量插入   --> | 
|     <insert id="batchInsert" parameterType="java.util.List"> | 
|         INSERT INTO shop_order_details ( | 
|         <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_order_details | 
|         <set> | 
|             <if test="_parameter.containsKey('orderId')"> | 
|                     order_id = #{orderId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('pId')"> | 
|                     p_id = #{pId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('sId')"> | 
|                     s_id = #{sId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('price')"> | 
|                     price = #{price}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('count')"> | 
|                     count = #{count}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('totalPrice')"> | 
|                     total_price = #{totalPrice}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('sTitle')"> | 
|                     s_title = #{sTitle}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('discountExplain')"> | 
|                     discount_explain = #{discountExplain}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('discountAmount')"> | 
|                     discount_amount = #{discountAmount}, | 
|                 </if> | 
|   | 
|             <if test="_parameter.containsKey('payType')"> | 
|                 pay_type = #{payType}, | 
|                 </if> | 
|   | 
|             <if test="_parameter.containsKey('scoreCount')"> | 
|                 score_count = #{scoreCount}, | 
|                 </if> | 
|   | 
|             <if test="_parameter.containsKey('totalScoreCount')"> | 
|                 total_score_count = #{totalScoreCount}, | 
|                 </if> | 
|   | 
|         </set> | 
|         WHERE id=#{id}  | 
|     </update>  | 
|      | 
|      | 
|     <!--  根据对象更新 部分更新   --> | 
|     <update id="updateByModel" parameterType="Integer"> | 
|         UPDATE shop_order_details | 
|         <set> | 
|             <if test="record.orderId != null "> | 
|                 order_id  = #{record.orderId},  | 
|             </if> | 
|             <if test="record.pId != null "> | 
|                 p_id  = #{record.pId},  | 
|             </if> | 
|             <if test="record.sId != null "> | 
|                 s_id  = #{record.sId},  | 
|             </if> | 
|             <if test="record.price != null "> | 
|                 price  = #{record.price},  | 
|             </if> | 
|             <if test="record.count != null "> | 
|                 count  = #{record.count},  | 
|             </if> | 
|             <if test="record.totalPrice != null "> | 
|                 total_price  = #{record.totalPrice},  | 
|             </if> | 
|             <if test="record.sTitle != null and record.sTitle != '' "> | 
|                 s_title  = #{record.sTitle},  | 
|             </if> | 
|             <if test="record.discountExplain != null and record.discountExplain != '' "> | 
|                 discount_explain  = #{record.discountExplain},  | 
|             </if> | 
|             <if test="record.discountAmount != null "> | 
|                 discount_amount  = #{record.discountAmount},  | 
|             </if> | 
|             <if test="record.payType != null "> | 
|                 pay_type  = #{record.payType}, | 
|             </if> | 
|             <if test="record.scoreCount != null "> | 
|                 score_count  = #{record.scoreCount}, | 
|             </if> | 
|             <if test="record.totalScoreCount != null "> | 
|                 total_score_count  = #{record.totalScoreCount}, | 
|             </if> | 
|         </set> | 
|         WHERE id=#{record.id}  | 
|     </update> | 
|     <!-- 批量删除 --> | 
|     <delete id="deleteByIds" parameterType="java.util.List"> | 
|         delete from shop_order_details where  id in | 
|         <foreach collection="list" index="index" item="item" open="(" | 
|             separator="," close=")"> | 
|             #{item} | 
|         </foreach> | 
|     </delete> | 
|          | 
|     <!-- 根据id删除--> | 
|     <delete id="deleteById" parameterType="Integer"> | 
|         DELETE FROM shop_order_details | 
|         where  id=#{id}  | 
|     </delete> | 
|      | 
|     <!-- 根据对象删除--> | 
|     <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopOrderDetails"> | 
|         DELETE FROM shop_order_details | 
|         <where> | 
|         <include refid="where_sql" ></include> | 
|         </where> | 
|     </delete> | 
|      | 
|      | 
|      | 
|     <!-- 分页查询 --> | 
|     <select id="selectInPage" resultMap="ShopOrderDetailsMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_order_details | 
|         <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_order_details | 
|         <where> | 
|            <include refid="where_sql"></include> | 
|         </where> | 
|     </select> | 
|   | 
|     <!-- 根据id查询--> | 
|     <select id="selectById" resultMap="ShopOrderDetailsMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_order_details | 
|         where  id=#{id}  | 
|     </select>     | 
|      | 
|      | 
|     <!-- 根据id 锁表查询--> | 
|     <select id="selectForUpdate" resultMap="ShopOrderDetailsMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_order_details | 
|         where  id=#{id}  | 
|         for update | 
|     </select>     | 
|      | 
|      | 
|      | 
|     <!-- 根据对象查询--> | 
|     <select id="selectByModel" resultMap="ShopOrderDetailsMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_order_details | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|     </select> | 
|   | 
|     <!-- 根据订单id查询--> | 
|     <select id="selectByOrderId" resultMap="ShopOrderDetailsComplexMap"> | 
|         select | 
|         <include refid="columns" ></include> | 
|         from shop_order_details | 
|         where  order_id = #{orderId} | 
|     </select> | 
|   | 
|     <select id="selectBuyCountByProductId" resultType="java.lang.Integer"> | 
|         select ifnull(sum(count), 0) from shop_order so, shop_order_details sod | 
|         where so.id = sod.order_id | 
|         and so.user_id = #{userId} | 
|         and  date_format(order_time, '%Y-%m-%d') >= date_format(date_sub(curdate(), INTERVAL ${days} DAY),'%Y-%m-%d') | 
|         and sod.p_id = #{productId} and so.order_status != 9 | 
|     </select> | 
|   | 
| </mapper> |