ChannelSkuCompareMapper.xml 3.48 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.ChannelSkuCompareMapper">
    <resultMap id="BaseResultMap" type="com.yoho.ufo.model.ChannelSkuCompare">
      <result column="id" property="id" jdbcType="INTEGER" />
      <result column="product_id" property="productId" jdbcType="INTEGER" />
      <result column="sku" property="sku" jdbcType="INTEGER" />
      <result column="size_id" property="sizeId" jdbcType="INTEGER" />
      <result column="channel_price" property="channelPrice" jdbcType="DECIMAL" />
      <result column="low_rate" property="lowRate" jdbcType="DECIMAL" />
      <result column="high_rate" property="highRate" jdbcType="DECIMAL" />
      <result column="update_time" property="updateTime" jdbcType="INTEGER" />
      <result column="channel_url" property="channelUrl" jdbcType="VARCHAR" />
    </resultMap>

    <sql id="Base_Column_List">
        id, product_id, sku, size_id, channel_price, low_rate, high_rate, update_time, channel_url
    </sql>
    
    <select id="selectById" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" /> 
        from channel_sku_compare 
        where id=#{id}
    </select>

    <sql id="Query_Sql" >
     <if test="channelSkuCompareReq.sku != null and channelSkuCompareReq.sku != 0 ">
         and a.sku = #{channelSkuCompareReq.sku}
     </if>
     <if test="channelSkuCompareReq.productId != null and channelSkuCompareReq.productId != 0 ">
         and a.product_id = #{channelSkuCompareReq.productId}
     </if>
     <if test="channelSkuCompareReq.productIdList != null and channelSkuCompareReq.productIdList.size()>0">
         and a.product_id in 
         <foreach collection="channelSkuCompareReq.productIdList" item="productId" open="(" close=")" separator=",">
            #{productId}
         </foreach>
     </if>
     <if test="channelSkuCompareReq.sizeIdList != null and channelSkuCompareReq.sizeIdList.size()>0">
         and a.size_id in 
         <foreach collection="channelSkuCompareReq.sizeIdList" item="sizeId" open="(" close=")" separator=",">
            #{sizeId}
         </foreach>
     </if>
     <if test="channelSkuCompareReq.status != null and channelSkuCompareReq.status == 0 ">
         and b.min_price &lt; a.channel_price
     </if>
     <if test="channelSkuCompareReq.status != null and channelSkuCompareReq.status == 1 ">
         and b.min_price &gt; a.channel_price
     </if>
    </sql>
    
    <select id="selectTotalByCondition" resultType="java.lang.Integer" parameterType="com.yoho.ufo.model.ChannelSkuCompareReq">
        select count(a.id)   
        from channel_sku_compare a  
        <if test="channelSkuCompareReq.status != null">
        LEFT JOIN product b
        ON( b.id=a.product_id) 
        </if>
        where 1=1 
        <include refid="Query_Sql" />
    </select>
    
    <select id="selectByCondition" resultMap="BaseResultMap" parameterType="com.yoho.ufo.model.ChannelSkuCompareReq">
        select a.*
        from channel_sku_compare a
        <if test="channelSkuCompareReq.status != null">
        LEFT JOIN product b
        ON( b.id=a.product_id) 
        </if>
        where 1=1 
        <include refid="Query_Sql" />
        order by a.product_id desc, a.sku asc
        <if test="channelSkuCompareReq.start!=null and channelSkuCompareReq.size != null">
        limit #{channelSkuCompareReq.start},#{channelSkuCompareReq.size}
        </if>
    </select>    
</mapper>