SellerOrderGoodsViewMapper.xml 10.4 KB
<?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.yohoufo.dal.order.SellerOrderGoodsViewMapper">
  <resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.SellerOrderGoods">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="product_id" jdbcType="INTEGER" property="productId" />
    <result column="uid" jdbcType="INTEGER" property="uid" />
    <result column="product_name" jdbcType="VARCHAR" property="productName" />
    <result column="storage_id" jdbcType="INTEGER" property="storageId" />
    <result column="depot_no" jdbcType="INTEGER" property="depotNo" />
    <result column="size_id" jdbcType="INTEGER" property="sizeId" />
    <result column="size_name" jdbcType="VARCHAR" property="sizeName" />
    <result column="color_id" jdbcType="SMALLINT" property="colorId" />
    <result column="color_name" jdbcType="VARCHAR" property="colorName" />
    <result column="goods_price" jdbcType="DECIMAL" property="goodsPrice" />
    <result column="status" jdbcType="TINYINT" property="status" />
    <result column="image_url" jdbcType="VARCHAR" property="imageUrl" />
    <result column="is_del" jdbcType="TINYINT" property="isDel" />
    <result column="batch_no" jdbcType="BIGINT" property="batchNo" />
    <result column="storage_num" jdbcType="INTEGER" property="storageNum" />
    <result column="size_num" jdbcType="INTEGER" property="sizeNum" />
    <result column="attributes" jdbcType="INTEGER" property="attributes" />
    <result column="region" jdbcType="INTEGER" property="region" />
  </resultMap>
  <sql id="Base_Column_List">
    id, uid, product_id, product_name, storage_id, depot_no, size_id, size_name,
    color_id, color_name, goods_price, status, image_url, is_del, batch_no,attributes,region
  </sql>

  <select id="selectEntryCntByUidStatusGBSkc" resultType="java.lang.Integer">
    SELECT COUNT(*) from (select sog.id FROM seller_order_goods sog,seller_order so
    WHERE sog.id = so.skup and sog.uid = #{uid,jdbcType=INTEGER}
    and sog.is_del = 1 AND so.payment = 11
    <include refid="sql_where_skupTyps_scope" />
    <if test="statusList != null">
      and sog.status in
      <foreach item="status" index="index" collection="statusList" open="(" separator="," close=")">
        #{status, jdbcType=TINYINT}
      </foreach>
    </if>
    GROUP BY sog.uid,product_id) t
  </select>

  <select id="selectCntByUidStatusGBSkc" resultType="java.lang.Integer">
    SELECT COUNT(*) from (select sog.id FROM seller_order_goods sog,seller_order so
    WHERE sog.id = so.skup and sog.uid = #{uid,jdbcType=INTEGER}
    and sog.is_del = 1
    <include refid="sql_where_skupTyps_scope" />
    <if test="statusList != null">
      and sog.status in
      <foreach item="status" index="index" collection="statusList" open="(" separator="," close=")">
        #{status, jdbcType=TINYINT}
      </foreach>
    </if>
    GROUP BY sog.uid,product_id) t
  </select>

  <sql id="Base_Column_List_with_table_name">
    sog.id as id, sog.uid as uid, product_id, product_name,storage_id,depot_no,sog.size_id,sog.size_name,
    color_id, color_name, goods_price, sog.status as status, image_url, sog.is_del as is_del, batch_no,
    sog.attributes as attributes, sog.region as region
  </sql>

  <select id="selectEntryListByUidStatusGBSkc" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List_with_table_name" /> FROM seller_order_goods sog,seller_order so
    WHERE sog.id = so.skup and sog.uid = #{uid,jdbcType=INTEGER}
    and sog.is_del = 1 AND so.payment = 11
    <include refid="sql_where_skupTyps_scope" />
    <if test="statusList != null">
      and sog.status in
      <foreach item="status" index="index" collection="statusList" open="(" separator="," close=")">
        #{status, jdbcType=TINYINT}
      </foreach>
    </if>
    GROUP BY sog.uid,product_id ORDER BY id DESC
    limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}
  </select>

  <select id="selectListByUidStatusGBSkc" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List_with_table_name" /> FROM seller_order_goods sog,seller_order so
    WHERE sog.id = so.skup and sog.uid = #{uid,jdbcType=INTEGER}
    and sog.is_del = 1
    <include refid="sql_where_skupTyps_scope" />
    <if test="statusList != null">
      and sog.status in
      <foreach item="status" index="index" collection="statusList" open="(" separator="," close=")">
        #{status, jdbcType=TINYINT}
      </foreach>
    </if>
    GROUP BY sog.uid,product_id ORDER BY id DESC
    limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}
  </select>

  <select id="selectByUidStatusGBSkc" resultMap="BaseResultMap">
    SELECT `uid`,`product_id`,`product_name`,`color_id`,`color_name`,COUNT(size_id) size_num,SUM(size_storage) storage_num FROM
    (
    SELECT sog.`uid`,`product_id`,`product_name`,`color_id`,`color_name`,size_id,COUNT(`size_id`) size_storage
    FROM seller_order_goods sog,seller_order so
    WHERE sog.id = so.skup and sog.uid = #{uid,jdbcType=INTEGER}
    and sog.is_del = 1
    <if test="isEntry">
      AND so.payment = 11
    </if>
    <include refid="sql_where_skupTyps_scope" />
    <if test="statusList != null">
      and sog.status in
      <foreach item="status" index="index" collection="statusList" open="(" separator="," close=")">
        #{status, jdbcType=TINYINT}
      </foreach>
    </if>
     AND product_id = #{productId,jdbcType=INTEGER}
    GROUP BY sog.uid,size_id
    ) t
  </select>

  <select id="selectNotEntryCntByUidStatus" resultType="java.lang.Integer">
    SELECT COUNT(*) from (select sog.id FROM seller_order_goods sog,seller_order so
    WHERE sog.id = so.skup and sog.uid = #{uid,jdbcType=INTEGER} and sog.is_del = 1
    AND (so.payment != 11 or so.payment is null)
    <include refid="sql_where_skupTyps_scope" />
    <if test="statusList != null">
      and sog.status in
      <foreach item="status" index="index" collection="statusList" open="(" separator="," close=")">
        #{status, jdbcType=TINYINT}
      </foreach>
    </if>
    ) t
  </select>

  <select id="selectNotEntryListByUidStatus" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List_with_table_name" /> FROM seller_order_goods sog,seller_order so
    WHERE sog.id = so.skup and sog.uid = #{uid,jdbcType=INTEGER} and sog.is_del = 1
    AND (so.payment != 11 or so.payment is null)
    <include refid="sql_where_skupTyps_scope" />
    <if test="statusList != null">
      and sog.status in
      <foreach item="status" index="index" collection="statusList" open="(" separator="," close=")">
        #{status, jdbcType=TINYINT}
      </foreach>
    </if>
     ORDER BY id DESC
    limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}
  </select>

  <select id="selectEntryListByUidStatusGBSku" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List_with_table_name" />,COUNT(sog.size_id) storage_num
    FROM seller_order_goods sog
    join seller_order so on sog.id = so.skup
    left join product_size ps on sog.size_id = ps.size_id
    WHERE sog.uid = #{condition.uid,jdbcType=INTEGER}
    <if test="isEntry">
      AND so.payment = 11
    </if>
    <include refid="sql_where_skupTyps_scope" />
    AND sog.status = #{condition.status, jdbcType=TINYINT}
    AND product_id = #{condition.productId,jdbcType=INTEGER}
    GROUP BY sog.attributes,sog.size_id,`goods_price`
    order by ps.order_by,sog.size_id,goods_price
    limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}
  </select>

  <select id="selectEntryCntByUidStatusGBSku" resultType="java.lang.Integer">
    select count(*) FROM
    (
    SELECT size_id ,goods_price
    FROM seller_order_goods sog,seller_order so WHERE sog.id = so.skup
    AND sog.uid = #{condition.uid,jdbcType=INTEGER}
    <if test="isEntry">
    AND so.payment = 11
    </if>
    <include refid="sql_where_skupTyps_scope" />
    AND sog.status = #{condition.status, jdbcType=TINYINT}
    AND product_id = #{condition.productId,jdbcType=INTEGER}

    GROUP BY sog.attributes,size_id,`goods_price`
    ) t
  </select>

  <sql id="sql_where_skupTyps_scope" >
    and attributes in
    <foreach collection="skupTypes" item="skupType" open="(" close=")" separator=",">
      #{skupType,jdbcType=INTEGER}
    </foreach>
  </sql>

  <select id="selectCanSellByStorageId" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List" />
    FROM seller_order_goods
    WHERE storage_id = #{storageId,jdbcType=INTEGER} and status = 1
  </select>


  <select id="selectCntByUidTypeStatus" resultType="java.lang.Integer">
    SELECT COUNT(*) from (select sog.id FROM seller_order_goods sog,seller_order so
    WHERE sog.id = so.skup and sog.uid = #{uid,jdbcType=INTEGER} and sog.is_del = 1
    <include refid="sql_where_skupTyps_scope" />
    <if test="statusList != null">
      and sog.status in
      <foreach item="status" index="index" collection="statusList" open="(" separator="," close=")">
        #{status, jdbcType=TINYINT}
      </foreach>
    </if>
    ) t
  </select>

  <select id="selectAllByUidTypeStatus" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List_with_table_name" /> FROM seller_order_goods sog,seller_order so
    WHERE sog.id = so.skup and sog.uid = #{uid,jdbcType=INTEGER} and sog.is_del = 1
    <include refid="sql_where_skupTyps_scope" />
    <if test="statusList != null">
      and sog.status in
      <foreach item="status" index="index" collection="statusList" open="(" separator="," close=")">
        #{status, jdbcType=TINYINT}
      </foreach>
    </if>
    ORDER BY id DESC
    limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}
  </select>

  <select id="selectAvgPriceOfPrdWithTimeRange" resultMap="BaseResultMap">
      select avg(sog.goods_price) goods_price from seller_order_goods sog,buyer_order bo,buyer_order_goods bog
          where sog.id = bog.skup
          and bo.order_code = bog.order_code
          and sog.storage_id = #{storageId,jdbcType=INTEGER}
          and bo.status = 5
          and bo.update_time between #{startTime} and #{endTime}
  </select>

  <select id="selectAvgPriceOfPrd" resultMap="BaseResultMap">
      select avg(sog.goods_price) goods_price from seller_order_goods sog,buyer_order bo,buyer_order_goods bog
          where sog.id = bog.skup
          and bo.order_code = bog.order_code
          and sog.storage_id = #{storageId,jdbcType=INTEGER}
          and bo.status = 5
          order by bo.id desc
          limit #{limit}
  </select>

</mapper>