ProductMapper.xml 14.7 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.ProductMapper">
  <resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.Product">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="product_name" jdbcType="VARCHAR" property="productName" />
    <result column="product_code" jdbcType="VARCHAR" property="productCode" />
    <result column="max_sort_id" jdbcType="INTEGER" property="maxSortId" />
    <result column="mid_sort_id" jdbcType="INTEGER" property="midSortId" />
    <result column="brand_id" jdbcType="INTEGER" property="brandId" />
    <result column="series_id" jdbcType="INTEGER" property="seriesId" />
    <result column="gender" jdbcType="CHAR" property="gender" />
    <result column="sale_time" jdbcType="INTEGER" property="saleTime" />
    <result column="min_price" jdbcType="DECIMAL" property="minPrice" />
    <result column="max_price" jdbcType="DECIMAL" property="maxPrice" />
    <result column="create_time" jdbcType="INTEGER" property="createTime" />
    <result column="update_time" jdbcType="INTEGER" property="updateTime" />
    <result column="shelve_time" jdbcType="INTEGER" property="shelveTime" />
    <result column="edit_time" jdbcType="INTEGER" property="editTime" />
    <result column="shelve_status" jdbcType="INTEGER" property="shelveStatus" />
    <result column="storage" jdbcType="INTEGER" property="storage" />
    <result column="key_words" jdbcType="VARCHAR" property="keyWords" />
    <result column="del_status" jdbcType="INTEGER" property="delStatus" />
    <result column="age_level" jdbcType="VARCHAR" property="ageLevel" />
    <result column="is_syn_calender" jdbcType="INTEGER" property="isSynCalender" />
    <result column="offer_price" jdbcType="DECIMAL" property="offerPrice" />
  </resultMap>

  <insert id="insert" parameterType="com.yoho.ufo.dal.model.Product" useGeneratedKeys="true" keyProperty="id" >
    insert into product (id, product_name, product_code, 
      max_sort_id, mid_sort_id, brand_id, 
      series_id, gender, sale_time, 
      min_price, max_price, create_time, 
      update_time, shelve_time, edit_time, 
      shelve_status, storage, key_words, 
      del_status, age_level, is_syn_calender, offer_price)
    values (#{id,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR}, #{productCode,jdbcType=VARCHAR}, 
      #{maxSortId,jdbcType=INTEGER}, #{midSortId,jdbcType=INTEGER}, #{brandId,jdbcType=INTEGER}, 
      #{seriesId,jdbcType=INTEGER}, #{gender,jdbcType=CHAR}, #{saleTime,jdbcType=INTEGER}, 
      #{minPrice,jdbcType=DECIMAL}, #{maxPrice,jdbcType=DECIMAL}, #{createTime,jdbcType=INTEGER}, 
      #{updateTime,jdbcType=INTEGER}, #{shelveTime,jdbcType=INTEGER}, #{editTime,jdbcType=INTEGER}, 
      #{shelveStatus,jdbcType=INTEGER}, #{storage,jdbcType=INTEGER}, #{keyWords,jdbcType=VARCHAR}, 
      #{delStatus,jdbcType=INTEGER}, #{ageLevel,jdbcType=VARCHAR},
      #{isSynCalender,jdbcType=INTEGER}, #{offerPrice,jdbcType=DECIMAL})
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.Product">
    update product
    set product_name = #{productName,jdbcType=VARCHAR},
      product_code = #{productCode,jdbcType=VARCHAR},
      max_sort_id = #{maxSortId,jdbcType=INTEGER},
      mid_sort_id = #{midSortId,jdbcType=INTEGER},
      brand_id = #{brandId,jdbcType=INTEGER},
      series_id = #{seriesId,jdbcType=INTEGER},
      gender = #{gender,jdbcType=CHAR},
      sale_time = #{saleTime,jdbcType=INTEGER},
      min_price = #{minPrice,jdbcType=DECIMAL},
      max_price = #{maxPrice,jdbcType=DECIMAL},
      update_time = unix_timestamp(),
      edit_time = unix_timestamp(),
      age_level = #{ageLevel,jdbcType=VARCHAR},
      key_words = #{keyWords,jdbcType=VARCHAR},
      is_syn_calender = #{isSynCalender,jdbcType=INTEGER},
      offer_price = #{offerPrice,jdbcType=DECIMAL}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id, 
    gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time, 
    shelve_status, storage, key_words, del_status, age_level, is_syn_calender, offer_price 
    from product
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectAll" resultMap="BaseResultMap">
    select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id, 
    gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time, 
    shelve_status, storage, key_words, del_status, age_level, is_syn_calender, offer_price 
    from product
  </select>
  
  <select id="selectPage" resultMap="BaseResultMap">
    select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id, 
    gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time, 
    shelve_status, storage, key_words, del_status, age_level, is_syn_calender, offer_price 
    from product where del_status=0 <include refid="pageCondition" />  order by product.id desc limit #{start},#{rows}
  </select>
  <select id="selectCount" resultType="java.lang.Integer">
    select count(*) from product where del_status=0 <include refid="pageCondition" />
  </select>
  
  <sql id="pageCondition" >
    <if test="id != null and id > 0">
      and id = #{id}
    </if>
    <if test="productName != null and productName !=''">
      and product_name like "%"#{productName}"%"
    </if>
    <if test="maxSortId != null and maxSortId > 0">
      and max_sort_id = #{maxSortId}
    </if>
    <if test="midSortId != null and midSortId > 0">
      and mid_sort_id = #{midSortId}
    </if>
    <if test="brandId != null and brandId > 0">
      and brand_id = #{brandId}
    </if>
    <if test="shelveStatus != null and shelveStatus > -1">
      and shelve_status = #{shelveStatus}
    </if>
    <if test="productCode != null and productCode != ''">
      and product_code like concat(concat('%',#{productCode}),'%')
    </if>
    <if test="storageId != null and storageId > 0">
      and id in (select product_id from storage where id = #{storageId})
    </if>
    <if test="isSynCalender != null and isSynCalender > -1">
      and is_syn_calender = #{isSynCalender}
    </if>
    <if test="saleTimeStart != null and saleTimeEnd != null">
      and sale_time &gt;=#{saleTimeStart} and sale_time &lt;= #{saleTimeEnd}
    </if>
  </sql>
  
  <select id="selectSkuPage" resultMap="BaseResultMap">
    select distinct p.id from product p <include refid="skuPageCondition" />  order by p.id desc limit #{start},#{rows}
  </select>
  <select id="selectSkuCount" resultType="java.lang.Integer">
    select count(*) from (select distinct p.id from product p <include refid="skuPageCondition" /> ) sub
  </select>
  
  <sql id="skuPageCondition" >
    <if test="skuCondition == 1">
      inner join storage s on p.id = s.product_id
    </if>
    <if test="skupCondition == 1">
      inner join storage_price sp on p.id = sp.product_id
    </if>
    <if test="productCode != null and productCode !=''">
      and product_code = #{productCode}
    </if>
    <if test="productName != null and productName !=''">
      and product_name like "%"#{productName}"%"
    </if>
    <if test="maxSortId != null and maxSortId > 0">
      and max_sort_id = #{maxSortId}
    </if>
    <if test="midSortId != null and midSortId > 0">
      and mid_sort_id = #{midSortId}
    </if>
    <if test="brandId != null and brandId > 0">
      and brand_id = #{brandId}
    </if>
    <if test="shelveStatus != null and shelveStatus > -1">
      and shelve_status = #{shelveStatus}
    </if>
    <if test="storageId != null and storageId > 0">
      and s.id = #{storageId}
    </if>
    <if test="sellerUid != null and sellerUid > 0">
      and sp.seller_uid = #{sellerUid}
    </if>
    <if test="hasStock != null and hasStock == 0">
      and s.storage_num = 0
    </if>
    <if test="hasStock != null and hasStock == 1">
      and s.storage_num &gt; 0
    </if>
    <if test="skup != null and skup > 0">
      and sp.skup = #{skup}
    </if>
  </sql>

  <select id="selectProductListByIds" resultMap="BaseResultMap">
    select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id,
    gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time,
    shelve_status, storage, key_words, del_status, age_level, is_syn_calender, offer_price 
    from product where id in
    <foreach item="item" index="index" collection="productIdList" open="(" separator="," close=")">
      #{item}
    </foreach>
  </select>

  <update id="updateStatusByPrimaryKey">
    update product set 
      edit_time = unix_timestamp(),
      update_time = unix_timestamp(),
      shelve_status = #{shelveStatus,jdbcType=INTEGER}
        <if test="shelveStatus != null and shelveStatus == 1">
	      ,shelve_time = unix_timestamp()
	    </if>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectProductStorageCount" resultType="java.lang.Integer">
    select
    <if test="product.storageNum != null"> count(DISTINCT p.id) </if>
    <if test="product.storageNum == null"> count(p.id) </if>
    from product p where
    <include refid="skcPageCondition" />
  </select>

  <select id="selectProductStorageList" resultMap="BaseResultMap">
    select
    <if test="product.storageNum != null"> DISTINCT p.id, p.brand_id, p.product_name, p.max_sort_id, p.mid_sort_id </if>
    <if test="product.storageNum == null"> p.id, p.brand_id, p.product_name, p.max_sort_id, p.mid_sort_id </if>
    from product p
    where <include refid="skcPageCondition" /> limit #{start},#{rows}
  </select>

  <sql id="skcPageCondition">
    1 = 1
    <if test="product.storageNum != null">
      <if test="product.storageNum == 0">
        And exists(SELECT 1  FROM storage s WHERE s.storage_num = 0 AND s.product_id= p.id)
      </if>
      <if test="product.storageNum != 0">
        And exists(SELECT 1  FROM storage s WHERE s.storage_num >= 1 AND s.product_id= p.id)
      </if>
    </if>
    <if test="product.id != null and product.id > 0">
      and p.id = #{product.id}
    </if>
    <if test="product.productName != null and product.productName != ''">
      and p.product_name like concat('%', #{product.productName}, '%')
    </if>
    <if test="product.maxSortId != null and product.maxSortId > 0">
      and p.max_sort_id = #{product.maxSortId}
    </if>
    <if test="product.midSortId != null and product.midSortId > 0">
      and p.mid_sort_id = #{product.midSortId}
    </if>
    <if test="product.brandId != null and product.brandId > 0">
      and p.brand_id = #{product.brandId}
    </if>
    <if test="product.productIdList != null and product.productIdList.size()>0">
      And p.id in
      <foreach collection="product.productIdList" item="productID" open="(" close=")" separator=",">
        #{productID}
      </foreach>
    </if>
  </sql>
  <select id="selectByProductName" resultMap="BaseResultMap">
     select id, product_name from product where product_name like "%"#{productName}"%"
  </select>
  <select id="selectByProductCode" resultMap="BaseResultMap">
     select id, product_name from product where product_code = #{productCode} and del_status=0
  </select>
  <select id="selectProductListByProductCodes" resultMap="BaseResultMap">
    select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id,
    gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time,
    shelve_status, storage, key_words, del_status, age_level
    from product where shelve_status = 1 and del_status=0 and product_code in
    <foreach item="item" index="index" collection="productCodeList" open="(" separator="," close=")">
      #{item}
    </foreach>
  </select>


    <select id="selectProductStockNotZeroCount" resultType="java.lang.Integer">
        select count(p.id)
        from product p
        where 1 = 1
        and p.id in (
            select distinct product_id
            from storage_price s
            where 1 = 1
            and s.status = #{status}
            and s.seller_uid in
            <foreach item="sellerItem" index="index" collection="sellerList" open="(" separator="," close=")">
                #{sellerItem}
            </foreach>
            <if test="product.storageId != null and product.storageId > 0">
                and s.storage_id = #{product.storageId}
            </if>
            <if test="product.skup != null and product.skup > 0">
                and s.skup = #{product.skup}
            </if>
        )
        <if test="product.id != null and product.id > 0">
            and p.id = #{product.id}
        </if>
        <if test="product.productName != null and product.productName != '' ">
            and p.product_name like concat('%', #{product.productName}, '%')
        </if>
        <if test="product.maxSortId != null and product.maxSortId > 0">
            and p.max_sort_id = #{product.maxSortId}
        </if>
        <if test="product.midSortId != null and product.midSortId > 0">
            and p.mid_sort_id = #{product.midSortId}
        </if>
        <if test="product.brandId != null and product.brandId > 0">
            and p.brand_id = #{product.brandId}
        </if>
    </select>


    <select id="selectProductStockNotZeroList" resultMap="BaseResultMap">
        select p.id, p.brand_id, p.product_name, p.max_sort_id, p.mid_sort_id
        from product p
        where 1 = 1
        and p.id in (
            select distinct product_id
            from storage_price s
            where 1 = 1
            and s.status = #{status}
            and s.seller_uid in
            <foreach item="sellerItem" index="index" collection="sellerList" open="(" separator="," close=")">
                #{sellerItem}
            </foreach>
            <if test="product.storageId != null and product.storageId > 0">
                and s.storage_id = #{product.storageId}
            </if>
            <if test="product.skup != null and product.skup > 0">
                and s.skup = #{product.skup}
            </if>
        )
        <if test="product.id != null and product.id > 0">
            and p.id = #{product.id}
        </if>
        <if test="product.productName != null and product.productName != '' ">
            and p.product_name like concat('%', #{product.productName}, '%')
        </if>
        <if test="product.maxSortId != null and product.maxSortId > 0">
            and p.max_sort_id = #{product.maxSortId}
        </if>
        <if test="product.midSortId != null and product.midSortId > 0">
            and p.mid_sort_id = #{product.midSortId}
        </if>
        <if test="product.brandId != null and product.brandId > 0">
            and p.brand_id = #{product.brandId}
        </if>
        limit #{start}, #{rows}
    </select>


</mapper>