StoragePriceMapper.xml 8.49 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.yoho.ufo.dal.StoragePriceMapper">
    <resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.StoragePrice">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="skup" jdbcType="INTEGER" property="skup"/>
        <result column="product_id" jdbcType="INTEGER" property="productId"/>
        <result column="goods_id" jdbcType="INTEGER" property="goodsId"/>
        <result column="storage_id" jdbcType="INTEGER" property="storageId"/>
        <result column="depot_num" jdbcType="INTEGER" property="depotNum"/>
        <result column="seller_uid" jdbcType="INTEGER" property="sellerUid"/>
        <result column="price" jdbcType="DECIMAL" property="price"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="update_time" jdbcType="INTEGER" property="updateTime"/>
        <result column="create_time" jdbcType="INTEGER" property="createTime"/>
    </resultMap>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from storage_price
    where id = #{id,jdbcType=INTEGER}
  </delete>
    <insert id="insert" parameterType="com.yoho.ufo.dal.model.StoragePrice">
    insert into storage_price (id, skup, product_id, 
      goods_id, storage_id, depot_num, 
      seller_uid, price, status, 
      update_time, create_time)
    values (#{id,jdbcType=INTEGER}, #{skup,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, 
      #{goodsId,jdbcType=INTEGER}, #{storageId,jdbcType=INTEGER}, #{depotNum,jdbcType=INTEGER}, 
      #{sellerUid,jdbcType=INTEGER}, #{price,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER}, 
      #{updateTime,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER})
  </insert>
    <update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.StoragePrice">
    update storage_price
    set skup = #{skup,jdbcType=INTEGER},
      product_id = #{productId,jdbcType=INTEGER},
      goods_id = #{goodsId,jdbcType=INTEGER},
      storage_id = #{storageId,jdbcType=INTEGER},
      depot_num = #{depotNum,jdbcType=INTEGER},
      seller_uid = #{sellerUid,jdbcType=INTEGER},
      price = #{price,jdbcType=DECIMAL},
      status = #{status,jdbcType=INTEGER},
      update_time = #{updateTime,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, 
    status, update_time, create_time
    from storage_price
    where id = #{id,jdbcType=INTEGER}
  </select>
    <select id="selectAll" resultMap="BaseResultMap">
    select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, 
    status, update_time, create_time
    from storage_price
  </select>

    <select id="selectMinPriceByProductIdList" resultMap="BaseResultMap">
        select product_id, min(price) as price
        from storage_price where product_id in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
        and status = 1 group by product_id
    </select>
    <select id="selectByGoodsIdList" resultMap="BaseResultMap">
        select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price,
        status, update_time, create_time
        from storage_price where goods_id in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectPage" resultMap="BaseResultMap">
        select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price,
        status, update_time, create_time
        from storage_price where storage_id = #{storageId}
        <include refid="skupPageCondition"/>
        order by id desc limit #{start},#{rows}
    </select>

    <select id="selectCount" resultType="java.lang.Integer">
        select count(*)
        from storage_price where storage_id = #{storageId}
        <include refid="skupPageCondition"/>
    </select>

    <sql id="skupPageCondition">
        <if test="sellerUid != null and sellerUid > 0">
            and seller_uid = #{sellerUid}
        </if>
        <if test="status != null">
            and status = #{status}
        </if>
        <if test="skup != null and skup > 0">
            and skup = #{skup}
        </if>
    </sql>

    <update id="cancelSaleSkup" parameterType="java.lang.Integer">
    update storage_price set status = 200,
      update_time = unix_timestamp()
    where skup = #{skup,jdbcType=INTEGER} and status = 1
  </update>
    <select id="selectBySkup" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, status,
    update_time, create_time
    from storage_price
    where skup = #{skup,jdbcType=INTEGER}
  </select>

    <select id="selectStoragePriceCount" resultType="java.lang.Integer">
        select count(*) from storage_price sp, storage s where sp.storage_id = s.id
        <include refid="skupPageCondition2"/>
    </select>

    <select id="selectStoragePriceList" resultMap="BaseResultMap">
        select sp.id, sp.skup, sp.product_id, s.goods_id, sp.storage_id, sp.depot_num, sp.seller_uid, sp.price, sp.status,
        sp.update_time, sp.create_time
        from storage_price sp, storage s where sp.storage_id = s.id
        <include refid="skupPageCondition2"/>
        order by sp.id desc limit #{start},#{rows}
    </select>

    <sql id="skupPageCondition2">
        <if test="storagePrice.status != null and storagePrice.status > -1">
            and sp.status = #{storagePrice.status}
        </if>
        <if test="storagePrice.storageId != null and storagePrice.storageId > 0">
            and sp.storage_id = #{storagePrice.storageId}
        </if>
        <if test="storagePrice.sellerUid != null and storagePrice.sellerUid > 0">
            and sp.seller_uid = #{storagePrice.sellerUid}
        </if>
        <if test="storagePrice.productId != null and storagePrice.productId > 0">
            and sp.product_id = #{storagePrice.productId}
        </if>
        <if test="storagePrice.skup != null and storagePrice.skup > 0">
            and sp.skup = #{storagePrice.skup}
        </if>
        <if test="storagePrice.sizeId != null and storagePrice.sizeId > 0">
            and s.size_id = #{storagePrice.sizeId}
        </if>
    </sql>

    <select id="selectByProductIds" resultMap="BaseResultMap">
        select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, status,
        update_time, create_time
        from storage_price
        where product_id in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
        limit 5000            <!-- 防止太多的数据,导致内存扛不住 -->
    </select>
    <select id="selectProductIdsBySkupInfo" resultType="java.lang.Integer">
        select DISTINCT product_id from storage_price where 1 = 1
        <if test="storagePrice.sellerUid != null and storagePrice.sellerUid > 0">
            and seller_uid = #{storagePrice.sellerUid}
        </if>
        <if test="storagePrice.storageId != null and storagePrice.storageId > 0">
            and storage_id = #{storagePrice.storageId}
        </if>
        <if test="storagePrice.skup != null and storagePrice.skup > 0">
            and skup = #{storagePrice.skup}
        </if>
        order by create_time desc limit 300
    </select>

    <select id="selectMinPriceByStorageIdList" resultMap="BaseResultMap">
        select storage_id, min(price) as price
        from storage_price where storage_id in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
        and status = 1 group by storage_id
    </select>


    <select id="selectByProductIdsAndSellerUid" resultMap="BaseResultMap">
        select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, status,
        update_time, create_time
        from storage_price
        where seller_uid = #{sellerUid,jdbcType=INTEGER}
        and status = #{status,jdbcType=INTEGER}
        and product_id in
        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

</mapper>