ProductMapper.xml 7.37 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" />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from product
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <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)
    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})
  </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},
      create_time = #{createTime,jdbcType=INTEGER},
      update_time = #{updateTime,jdbcType=INTEGER},
      shelve_time = #{shelveTime,jdbcType=INTEGER},
      edit_time = #{editTime,jdbcType=INTEGER},
      shelve_status = #{shelveStatus,jdbcType=INTEGER},
      storage = #{storage,jdbcType=INTEGER},
      key_words = #{keyWords,jdbcType=VARCHAR},
      del_status = #{delStatus,jdbcType=INTEGER}
    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
    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
    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
    from product where 1=1 and <include refid="pageCondition" />  order by product.id desc limit #{start},#{rows}
  </select>
  <select id="selectCount" resultMap="java.lang.Integer">
    select count(*) from product where 1=1 and <include refid="pageCondition" />
  </select>
  
  <sql id="pageCondition" >
    <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>
  </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" resultMap="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>
</mapper>