admin
2020-04-13 dd5b15229cb15459fa7c31ccea77dac28cbfafbd
fanli/src/main/java/com/yeshi/fanli/mapping/lable/QualityFactoryMapper.xml
@@ -1,1375 +1,1426 @@
<?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.yeshi.fanli.dao.mybatis.lable.QualityFactoryMapper">
   <resultMap id="BaseResultMap"
      type="com.yeshi.fanli.entity.bus.lable.QualityFactory">
      <id column="sg_id" property="id" jdbcType="BIGINT" />
      <result column="sg_class_id" property="systemCid" jdbcType="BIGINT" />
      <result column="sg_entry_mode" property="entryMode" jdbcType="INTEGER" />
      <result column="sg_goods_source" property="goodsSource"
         jdbcType="INTEGER" />
      <result column="sg_source_calss" property="sourceCalss"
         jdbcType="VARCHAR" />
      <result column="sg_weight" property="weight" jdbcType="INTEGER" />
      <result column="sg_createtime" property="createtime" jdbcType="TIMESTAMP" />
      <result column="sg_updatetime" property="updatetime" jdbcType="TIMESTAMP" />
      <association property="taoBaoGoodsBrief" column="sg_goods_id"
         select="com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper.selectByPrimaryKey">
      </association>
      <association property="boutiqueAutoRule" column="sg_rule_id"
         javaType="com.yeshi.fanli.entity.bus.lable.BoutiqueAutoRule">
         <id column="sg_rule_id" property="id" jdbcType="BIGINT" />
      </association>
      <association property="createUser" column="sg_create_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_create_aid" property="id" jdbcType="BIGINT" />
      </association>
      <association property="updateUser" column="sg_update_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_update_aid" property="id" jdbcType="BIGINT" />
      </association>
   </resultMap>
   <resultMap id="ResultMap"
      type="com.yeshi.fanli.entity.bus.lable.QualityFactory">
      <id column="sg_id" property="id" jdbcType="BIGINT" />
      <result column="sg_class_id" property="systemCid" jdbcType="BIGINT" />
      <result column="sg_entry_mode" property="entryMode" jdbcType="INTEGER" />
      <result column="sg_goods_source" property="goodsSource"
         jdbcType="INTEGER" />
      <result column="sg_source_calss" property="sourceCalss"
         jdbcType="VARCHAR" />
      <result column="sg_weight" property="weight" jdbcType="INTEGER" />
      <result column="sg_createtime" property="createtime" jdbcType="TIMESTAMP" />
      <result column="sg_updatetime" property="updatetime" jdbcType="TIMESTAMP" />
      <association property="boutiqueAutoRule" column="sg_rule_id"
         select="com.yeshi.fanli.dao.mybatis.lable.BoutiqueAutoRuleMapper.selectByPrimaryKey">
      </association>
      <association property="taoBaoGoodsBrief" column="sg_goods_id"
         select="com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper.selectByPrimaryKey">
      </association>
      <association property="createUser" column="sg_create_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_create_aid" property="id" jdbcType="BIGINT" />
      </association>
      <association property="updateUser" column="sg_update_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_update_aid" property="id" jdbcType="BIGINT" />
      </association>
   </resultMap>
   <resultMap id="GoodsResultMap"   type="com.yeshi.fanli.entity.bus.lable.QualityFactory">
      <id column="sg_id" property="id" jdbcType="BIGINT" />
      <result column="sg_class_id" property="systemCid" jdbcType="BIGINT" />
      <result column="sg_entry_mode" property="entryMode" jdbcType="INTEGER" />
      <result column="sg_goods_source" property="goodsSource"
         jdbcType="INTEGER" />
      <result column="sg_source_calss" property="sourceCalss"
         jdbcType="VARCHAR" />
      <result column="sg_weight" property="weight" jdbcType="INTEGER" />
      <result column="sg_createtime" property="createtime" jdbcType="TIMESTAMP" />
      <result column="sg_updatetime" property="updatetime" jdbcType="TIMESTAMP" />
      <association property="boutiqueAutoRule" column="sg_rule_id"
         javaType="com.yeshi.fanli.entity.bus.lable.BoutiqueAutoRule">
         <id column="sg_rule_id" property="id" jdbcType="BIGINT" />
      </association>
      <association property="taoBaoGoodsBrief" column="sg_goods_id"
         resultMap="com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper.BaseResultMap" />
      <association property="createUser" column="sg_create_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_create_aid" property="id" jdbcType="BIGINT" />
      </association>
      <association property="updateUser" column="sg_update_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_update_aid" property="id" jdbcType="BIGINT" />
      </association>
   </resultMap>
   <sql id="Base_Column_List">sg_id,sg_class_id,sg_goods_id,sg_entry_mode,sg_goods_source,sg_source_calss,sg_rule_id,sg_weight,sg_create_aid,sg_createtime,sg_update_aid,sg_updatetime
   </sql>
   <select id="selectByPrimaryKey" resultMap="BaseResultMap"
      parameterType="java.lang.Long">
      select
      <include refid="Base_Column_List" />
      from yeshi_ec_quality_factory where sg_id = #{id,jdbcType=BIGINT}
   </select>
   <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
      yeshi_ec_quality_factory where sg_id = #{id,jdbcType=BIGINT}
   </delete>
   <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.lable.QualityFactory"
      useGeneratedKeys="true" keyProperty="id">insert into
      yeshi_ec_quality_factory
      (sg_id,sg_class_id,sg_goods_id,sg_entry_mode,sg_goods_source,sg_source_calss,sg_rule_id,sg_weight,sg_create_aid,sg_createtime,sg_update_aid,sg_updatetime)
      values
      (#{id,jdbcType=BIGINT},#{systemCid,jdbcType=BIGINT},#{taoBaoGoodsBrief.id,jdbcType=BIGINT},#{entryMode,jdbcType=INTEGER},#{goodsSource,jdbcType=INTEGER},#{sourceCalss,jdbcType=VARCHAR},#{boutiqueAutoRule.id,jdbcType=BIGINT},#{weight,jdbcType=INTEGER},#{createUser.id,jdbcType=BIGINT},#{createtime,jdbcType=TIMESTAMP},#{updateUser.id,jdbcType=BIGINT},#{updatetime,jdbcType=TIMESTAMP})
   </insert>
   <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.lable.QualityFactory"
      useGeneratedKeys="true" keyProperty="id">
      insert into yeshi_ec_quality_factory
      <trim prefix="(" suffix=")" suffixOverrides=",">
         <if test="id != null">sg_id,</if>
         <if test="systemCid != null">sg_class_id,</if>
         <if test="taoBaoGoodsBrief != null">sg_goods_id,</if>
         <if test="entryMode != null">sg_entry_mode,</if>
         <if test="goodsSource != null">sg_goods_source,</if>
         <if test="sourceCalss != null">sg_source_calss,</if>
         <if test="boutiqueAutoRule != null">sg_rule_id,</if>
         <if test="weight != null">sg_weight,</if>
         <if test="createUser != null">sg_create_aid,</if>
         <if test="createtime != null">sg_createtime,</if>
         <if test="updateUser != null">sg_update_aid,</if>
         <if test="updatetime != null">sg_updatetime,</if>
      </trim>
      values
      <trim prefix="(" suffix=")" suffixOverrides=",">
         <if test="id != null">#{id,jdbcType=BIGINT},</if>
         <if test="systemCid != null">#{systemCid,jdbcType=BIGINT},</if>
         <if test="taoBaoGoodsBrief != null">#{taoBaoGoodsBrief.id,jdbcType=BIGINT},</if>
         <if test="entryMode != null">#{entryMode,jdbcType=INTEGER},</if>
         <if test="goodsSource != null">#{goodsSource,jdbcType=INTEGER},</if>
         <if test="sourceCalss != null">#{sourceCalss,jdbcType=VARCHAR},</if>
         <if test="boutiqueAutoRule != null">#{boutiqueAutoRule.id,jdbcType=BIGINT},</if>
         <if test="weight != null">#{weight,jdbcType=INTEGER},</if>
         <if test="createUser != null">#{createUser.id,jdbcType=BIGINT},</if>
         <if test="createtime != null">#{createtime,jdbcType=TIMESTAMP},</if>
         <if test="updateUser != null">#{updateUser.id,jdbcType=BIGINT},</if>
         <if test="updatetime != null">#{updatetime,jdbcType=TIMESTAMP},</if>
      </trim>
   </insert>
   <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.lable.QualityFactory">update
      yeshi_ec_quality_factory set sg_class_id =
      #{systemCid,jdbcType=BIGINT},sg_goods_id =
      #{taoBaoGoodsBrief.id,jdbcType=BIGINT},sg_entry_mode =
      #{entryMode,jdbcType=INTEGER},sg_goods_source =
      #{goodsSource,jdbcType=INTEGER},sg_source_calss =
      #{sourceCalss,jdbcType=VARCHAR},sg_rule_id =
      #{boutiqueAutoRule.id,jdbcType=BIGINT},sg_weight =
      #{weight,jdbcType=INTEGER},sg_create_aid =
      #{createUser.id,jdbcType=BIGINT},sg_createtime =
      #{createtime,jdbcType=TIMESTAMP},sg_update_aid =
      #{updateUser.id,jdbcType=BIGINT},sg_updatetime =
      #{updatetime,jdbcType=TIMESTAMP} where sg_id = #{id,jdbcType=BIGINT}
   </update>
   <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.lable.QualityFactory">
      update yeshi_ec_quality_factory
      <set>
         <if test="systemCid != null">sg_class_id=#{systemCid,jdbcType=BIGINT},</if>
         <if test="taoBaoGoodsBrief != null">sg_goods_id=#{taoBaoGoodsBrief.id,jdbcType=BIGINT},</if>
         <if test="entryMode != null">sg_entry_mode=#{entryMode,jdbcType=INTEGER},</if>
         <if test="goodsSource != null">sg_goods_source=#{goodsSource,jdbcType=INTEGER},</if>
         <if test="sourceCalss != null">sg_source_calss=#{sourceCalss,jdbcType=VARCHAR},</if>
         <if test="boutiqueAutoRule != null">sg_rule_id=#{boutiqueAutoRule.id,jdbcType=BIGINT},</if>
         <if test="weight != null">sg_weight=#{weight,jdbcType=INTEGER},</if>
         <if test="createUser != null">sg_create_aid=#{createUser.id,jdbcType=BIGINT},</if>
         <if test="createtime != null">sg_createtime=#{createtime,jdbcType=TIMESTAMP},</if>
         <if test="updateUser != null">sg_update_aid=#{updateUser.id,jdbcType=BIGINT},</if>
         <if test="updatetime != null">sg_updatetime=#{updatetime,jdbcType=TIMESTAMP},</if>
      </set>
      where sg_id = #{id,jdbcType=BIGINT}
   </update>
   <!-- 查询超过4个小时未更新商品,进行更新 -->
   <update id="updateWeight">
      UPDATE yeshi_ec_quality_factory SET sg_weight = #{weight}
      WHERE <![CDATA[TO_DAYS(`sg_updatetime`) < TO_DAYS(NOW()) OR (HOUR(NOW()) -HOUR(`sg_updatetime`)) >= #{time} ]]>
   </update>
   <delete id="deleteBatchByPrimaryKey" parameterType="java.util.List">
      DELETE FROM yeshi_ec_quality_factory WHERE sg_id in
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
   </delete>
   <delete id="deleteBatchByGoodsId" parameterType="java.util.List">
      DELETE FROM yeshi_ec_quality_factory WHERE sg_goods_id in
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
   </delete>
   <insert id="insertBatch" useGeneratedKeys="true" keyProperty="id"
      parameterType="java.util.List">
      INSERT IGNORE yeshi_ec_quality_factory
      (
      <include refid="Base_Column_List" />
      )
      values
      <foreach collection="list" item="item" separator=",">
         (
         #{item.id,jdbcType=BIGINT},
         #{item.systemCid,jdbcType=BIGINT},
         #{item.taoBaoGoodsBrief.id,jdbcType=BIGINT},
         #{item.entryMode,jdbcType=INTEGER},
         #{item.goodsSource,jdbcType=INTEGER},
         #{item.sourceCalss,jdbcType=VARCHAR},
         #{item.boutiqueAutoRule.id,jdbcType=BIGINT},
         #{item.weight,jdbcType=INTEGER},
         #{item.createUser.id,jdbcType=BIGINT},
         #{item.createtime,jdbcType=TIMESTAMP},
         #{item.updateUser.id,jdbcType=BIGINT},
         #{item.updatetime,jdbcType=TIMESTAMP}
         )
      </foreach>
   </insert>
   <update id="updateBatchSelective" parameterType="java.util.List">
      update yeshi_ec_quality_factory
      <trim prefix="set" suffixOverrides=",">
         <trim prefix="sg_weight =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.weight !=null">
                  when sg_id=#{item.id} then #{item.weight}
               </if>
            </foreach>
         </trim>
         <trim prefix="sg_goods_source =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.goodsSource !=null">
                  when sg_id=#{item.id} then #{item.goodsSource}
               </if>
            </foreach>
         </trim>
         <trim prefix="sg_rule_id =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.boutiqueAutoRule !=null">
                  when sg_id=#{item.id} then #{item.boutiqueAutoRule.id}
               </if>
            </foreach>
         </trim>
         <trim prefix="sg_source_calss =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.sourceCalss !=null">
                  when sg_id=#{item.id} then #{item.sourceCalss}
               </if>
            </foreach>
         </trim>
         <trim prefix="sg_createtime =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.createtime !=null">
                  when sg_id=#{item.id} then #{item.createtime}
               </if>
            </foreach>
         </trim>
         <trim prefix="sg_updatetime =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.updatetime !=null">
                  when sg_id=#{item.id} then #{item.updatetime}
               </if>
            </foreach>
         </trim>
      </trim>
      where sg_id in
      <foreach collection="list" index="index" item="item"
         separator="," open="(" close=")">
         #{item.id,jdbcType=BIGINT}
      </foreach>
   </update>
   <!-- 查询所有商品信息 更新时间较早在前 -->
   <select id="queryAll" resultMap="BaseResultMap">
      SELECT * FROM yeshi_ec_quality_factory
      <if test="days != null">
         WHERE DATE_SUB(CURDATE(), INTERVAL ${days} DAY) >
         DATE(lab_updatetime);
      </if>
      order by sg_updatetime LIMIT ${start},${count}
   </select>
   <!-- 查询精选商品信息 -->
   <select id="query" parameterType="com.yeshi.fanli.vo.quality.QualityFactoryVO" resultMap="ResultMap">
      SELECT ts.* FROM (
      SELECT DISTINCT( tt.`sg_id`) AS id FROM
      yeshi_ec_quality_factory tt
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      tt.`sg_goods_id`= tb.`id`
      <if test='keyType == 3'>
         LEFT JOIN yeshi_ec_label_goods lg ON tt.`sg_goods_id` =
         lg.`lg_goods_id`
         LEFT JOIN yeshi_ec_label lab ON lg.`lg_label_id` =
         lab.`lab_id`
      </if>
      WHERE 1=1
      <if test="goodsSource != null">
         <!-- 来源 -->
         AND tt.`sg_goods_source` = ${goodsSource}
      </if>
      <if test="days != null">
         <!-- 入库时间 -->
         AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) >= tt.`sg_createtime`]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startZkPrice != null'>
         AND <![CDATA[  tb.`zkPrice` >= ${startZkPrice} ]]>
      </if>
      <if test='endZkPrice != null'>
         AND <![CDATA[  tb.`zkPrice` <= ${endZkPrice} ]]>
      </if>
      <!-- 月销量 -->
      <if test='startBiz30day != null'>
         AND <![CDATA[  tb.`biz30day` >= ${startBiz30day} ]]>
      </if>
      <if test='endBiz30day != null'>
         AND <![CDATA[  tb.`biz30day` <= ${endBiz30day} ]]>
      </if>
      <!-- 权重范围 -->
      <if test='startWeight != null'>
         AND <![CDATA[   tt.`sg_weight` >= ${startWeight} ]]>
      </if>
      <if test='endWeight != null'>
         AND <![CDATA[   tt.`sg_weight` <= ${endWeight} ]]>
      </if>
      <!-- 佣金比例范围 -->
      <if test='startTkRate != null'>
         AND <![CDATA[   tb.`tkRate` >= ${startTkRate} ]]>
      </if>
      <if test='endTkRate != null'>
         AND <![CDATA[   tb.`tkRate` <= ${endTkRate} ]]>
      </if>
      <!-- 券面额:减多少 -->
      <if test='startAmount != null'>
         AND <![CDATA[   tb.`couponAmount` >= ${startAmount} ]]>
      </if>
      <if test='endAmount != null'>
         AND <![CDATA[   tb.`couponAmount` <= ${endAmount} ]]>
      </if>
      <!-- 券比例 -->
      <if test='startPropor != null'>
         AND <![CDATA[   ROUND(tb.couponAmount/tb.`zkPrice`*100,2) >= ${startPropor} ]]>
      </if>
      <!-- 券比例 -->
      <if test='endPropor != null'>
         AND <![CDATA[  ROUND(tb.couponAmount/tb.`zkPrice`*100,2) <= ${endPropor} ]]>
      </if>
      <!-- 有优惠券 -->
      <if test='hasCoupon == 1'>
         AND <![CDATA[  tb.`couponAmount` > 0 ]]>
      </if>
      <!-- 包邮 -->
      <if test='freeShipment == 1'>
         AND tb.`freeShipment` = 1
      </if>
      <!-- 消费者保障 -->
      <if test='isPrepay == 1'>
         AND tb.`isPrepay` = 1
      </if>
      <!-- 成交转化 -->
      <if test='payRate30 == 1'>
         AND tb.`payRate30` = 1
      </if>
      <!-- 好评率 -->
      <if test='goodRate == 1'>
         AND tb.`goodRate` = 1
      </if>
      <!-- 退款率 -->
      <if test='rfdRate == 1'>
         AND tb.`rfdRate` = 1
      </if>
      <!-- 分类id -->
      <if test='gcid != null'>
         AND tt.sg_class_id = #{gcid}
      </if>
      <!-- 搜索条件: 商品名称、商品id、标签名称 -->
      <if test='key != null and key != ""'>
         <if test='keyType == 1'>
            AND tb.`auctionId` = '${key}'
         </if>
         <if test='keyType == 2'>
            AND tb.`title` LIKE '%${key}%'
         </if>
         <if test='keyType == 3'>
            AND lab.`lab_title` = '${key}'
         </if>
         <if test='keyType == 4'>
            AND tb.`shopTitle` = '${key}'
         </if>
      </if>
      ORDER BY
      <!-- 销量 -->
      <if test='totalSales == 1'>
         tb.`biz30day`,
      </if>
      <if test='totalSales == 2'>
         tb.`biz30day` desc,
      </if>
      <!-- 价格 -->
      <if test='price == 1'>
         tb.`zkPrice`,
      </if>
      <if test='price == 2'>
         tb.`zkPrice` desc,
      </if>
      <!-- 价格 -->
      <if test='tkRate == 1'>
         tb.`tkRate`,
      </if>
      <if test='tkRate == 2'>
         tb.`tkRate` desc,
      </if>
      <!-- 券比例 -->
      <if test='propor == 1'>
         ROUND(tb.couponAmount/tb.`zkPrice` *100,2),
      </if>
      <if test='propor == 2'>
         ROUND(tb.couponAmount/tb.`zkPrice` *100,2) desc,
      </if>
      tt.`sg_updatetime` desc
      LIMIT ${start},${count}
      ) a LEFT JOIN
      yeshi_ec_quality_factory ts ON ts.`sg_id`=a.id
   </select>
   <select id="queryCount" parameterType="com.yeshi.fanli.vo.quality.QualityFactoryVO"  resultType="java.lang.Long">
      <!-- 根据条件统计所有标签数量 -->
      SELECT count(ts.sg_id) FROM (
      SELECT DISTINCT( tt.`sg_id`) AS id FROM
      yeshi_ec_quality_factory tt
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      tt.`sg_goods_id`= tb.`id`
      <if test='keyType == 3'>
         LEFT JOIN yeshi_ec_label_goods lg ON tt.`sg_goods_id` =
         lg.`lg_goods_id`
         LEFT JOIN yeshi_ec_label lab ON lg.`lg_label_id` =
         lab.`lab_id`
      </if>
      WHERE 1=1
      <if test="goodsSource != null">
         <!-- 来源 -->
         AND tt.`sg_goods_source` = ${goodsSource}
      </if>
      <if test="days != null">
         <!-- 入库时间 -->
         AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) >= tt.`sg_createtime`]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startZkPrice != null'>
         AND <![CDATA[  tb.`zkPrice` >= ${startZkPrice} ]]>
      </if>
      <if test='endZkPrice != null'>
         AND <![CDATA[  tb.`zkPrice` <= ${endZkPrice} ]]>
      </if>
      <!-- 月销量 -->
      <if test='startBiz30day != null'>
         AND <![CDATA[  tb.`biz30day` >= ${startBiz30day} ]]>
      </if>
      <if test='endBiz30day != null'>
         AND <![CDATA[  tb.`biz30day` <= ${endBiz30day} ]]>
      </if>
      <!-- 权重范围 -->
      <if test='startWeight != null'>
         AND <![CDATA[   tt.`sg_weight` >= ${startWeight} ]]>
      </if>
      <if test='endWeight != null'>
         AND <![CDATA[   tt.`sg_weight` <= ${endWeight} ]]>
      </if>
      <!-- 佣金比例范围 -->
      <if test='startTkRate != null'>
         AND <![CDATA[   tb.`tkRate` >= ${startTkRate} ]]>
      </if>
      <if test='endTkRate != null'>
         AND <![CDATA[   tb.`tkRate` <= ${endTkRate} ]]>
      </if>
      <!-- 券面额:减多少 -->
      <if test='startAmount != null'>
         AND <![CDATA[   tb.`couponAmount` >= ${startAmount} ]]>
      </if>
      <if test='endAmount != null'>
         AND <![CDATA[   tb.`couponAmount` <= ${endAmount} ]]>
      </if>
      <!-- 券比例 -->
      <if test='startPropor != null'>
         AND <![CDATA[   ROUND(tb.couponAmount/tb.`zkPrice`*100,2) >= ${startPropor} ]]>
      </if>
      <!-- 券比例 -->
      <if test='endPropor != null'>
         AND <![CDATA[  ROUND(tb.couponAmount/tb.`zkPrice`*100,2) <= ${endPropor} ]]>
      </if>
      <!-- 有优惠券 -->
      <if test='hasCoupon == 1'>
         AND <![CDATA[  tb.`couponAmount` > 0 ]]>
      </if>
      <!-- 包邮 -->
      <if test='freeShipment == 1'>
         AND tb.`freeShipment` = 1
      </if>
      <!-- 消费者保障 -->
      <if test='isPrepay == 1'>
         AND tb.`isPrepay` = 1
      </if>
      <!-- 成交转化 -->
      <if test='payRate30 == 1'>
         AND tb.`payRate30` = 1
      </if>
      <!-- 好评率 -->
      <if test='goodRate == 1'>
         AND tb.`goodRate` = 1
      </if>
      <!-- 退款率 -->
      <if test='rfdRate == 1'>
         AND tb.`rfdRate` = 1
      </if>
      <!-- 分类id -->
      <if test='gcid != null'>
         AND tt.sg_class_id = #{gcid}
      </if>
      <!-- 搜索条件: 商品名称、商品id、标签名称 -->
      <if test='key != null and key != ""'>
         <if test='keyType == 1'>
            AND tb.`auctionId` = '${key}'
         </if>
         <if test='keyType == 2'>
            AND tb.`title` LIKE '%${key}%'
         </if>
         <if test='keyType == 3'>
            AND lab.`lab_title` = '${key}'
         </if>
         <if test='keyType == 4'>
            AND tb.`shopTitle` = '${key}'
         </if>
      </if>
      ) a LEFT JOIN yeshi_ec_quality_factory ts ON ts.`sg_id`=a.id
   </select>
   <!--查询精选商品信息 -->
   <select id="queryByGoodsId" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM yeshi_ec_quality_factory WHERE sg_goods_id = ${goodsId}
   </select>
   <!--查询精选商品信息 -->
   <select id="getByAuctionId" resultMap="BaseResultMap">
      SELECT * FROM yeshi_ec_quality_factory
      WHERE sg_goods_id = ${auctionId}
      limit 1
   </select>
   <select id="queryCountByGoodsId" resultType="java.lang.Long">
      SELECT COUNT(sg_id)
      FROM yeshi_ec_quality_factory WHERE sg_goods_id =
      ${goodsId}
   </select>
   <select id="getCountAll" resultType="java.util.HashMap">
      <!-- 统计今日各种方式录入数量 -->
      SELECT COUNT(sg_id) AS total, IFNULL(SUM(CASE WHEN sg_entry_mode = 1
      THEN 1 ELSE 0 END),0) AS totalMANUAL,
      IFNULL(SUM(CASE WHEN
      sg_entry_mode = 2 THEN 1 ELSE 0 END),0) AS totalSYSTEM,
      IFNULL(SUM(CASE WHEN sg_entry_mode = 3 THEN 1 ELSE 0 END),0) AS
      totalSEARCH,
      IFNULL(SUM(CASE WHEN sg_goods_source = 1 THEN 1 ELSE 0
      END),0) AS totalTB,
      IFNULL(SUM(CASE WHEN sg_goods_source = 2 THEN 1
      ELSE 0 END),0) AS
      totalJD,
      IFNULL(SUM(CASE WHEN sg_goods_source = 3 THEN
      1 ELSE 0 END),0) AS totalPDD,
      IFNULL(SUM(CASE WHEN sg_goods_source = 4
      THEN 1 ELSE 0 END),0) AS
      totalWPH
      FROM yeshi_ec_quality_factory
   </select>
   <delete id="deleteByGoodsId" parameterType="java.lang.Long">
      delete from  yeshi_ec_quality_factory where sg_goods_id =
      #{goodsId,jdbcType=BIGINT}
   </delete>
   <select id="countTotalRows" resultType="java.lang.Long">
      SELECT COUNT(sg_id) FROM yeshi_ec_quality_factory
      <if test="days != null">
         WHERE DATE_SUB(CURDATE(), INTERVAL ${days} DAY) >
         DATE(lab_updatetime);
      </if>
   </select>
   <select id="listQuery" resultMap="BaseResultMap">
      <!-- 移动查询 -->
      SELECT * FROM `yeshi_ec_quality_factory` h
      <if test="labId != null">
         LEFT JOIN `yeshi_ec_label_goods` g ON h.`sg_goods_id` =
         g.`lg_goods_id`
      </if>
      <!-- 商品关键词 -->
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      1=1
      <!-- 商品关键词 -->
      <if test='key != null and key != ""'>
         AND tb.`title` LIKE '%${key}%'
      </if>
      <!-- 分类id -->
      <if test="systemCid != null">
         AND h.`sg_class_id` = ${systemCid}
      </if>
      <!-- 标签id -->
      <if test="labId != null">
         AND g.`lg_label_id`= ${labId}
      </if>
      <!-- 多个分类id -->
      <if test='cids != null and cids != ""'>
         AND h.`sg_class_id` in (${cids})
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <> '']]>
      </if>
      <!-- 排序:权重 销量 -->
      ORDER BY h.sg_weight desc,tb.`biz30day`desc
      LIMIT ${start},${count}
   </select>
   <select id="countQuery" resultType="java.lang.Long">
      <!-- 移动统计 -->
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      <if test="labId != null">
         LEFT JOIN `yeshi_ec_label_goods` g ON h.`sg_goods_id` =
         g.`lg_goods_id`
      </if>
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      1=1
      <!-- 商品关键词 -->
      <if test='key != null and key != ""'>
         AND tb.`title` LIKE '%${key}%'
      </if>
      <!-- 分类id -->
      <if test="systemCid != null">
         AND h.`sg_class_id` = #{systemCid}
      </if>
      <!-- 标签id -->
      <if test="labId != null">
         AND g.`lg_label_id`= #{labId}
      </if>
      <if test='cids != null and cids != ""'>
         AND h.`sg_class_id` in (#{cids})
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <>'']]>
      </if>
   </select>
   <delete id="removeStorageGoods" parameterType="java.lang.Long">
      DELETE FROM yeshi_ec_quality_factory h
      WHERE h.`sg_class_id`= #{gcids}
      AND <![CDATA[ h.`sg_createtime` < #{doTime} ]]>
      AND h.`sg_goods_id` NOT extsts(SELECT DISTINCT lg.`lg_goods_id` FROM
      yeshi_ec_label_goods lg)
   </delete>
   <select id="listQueryGoodsByGoodsId" resultMap="BaseResultMap">
      <!-- 根据auctionId 查询商品信息 -->
      SELECT
      <include refid="Base_Column_List" />
      FROM yeshi_ec_quality_factory
      WHERE sg_goods_id in
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
   </select>
   <select id="listQueryByKey" resultMap="BaseResultMap">
      <!-- 移动查询 -->
      SELECT
      <include refid="Base_Column_List" />
      FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      h.`sg_goods_id`= tb.`id`
      WHERE tb.`title` LIKE '%${key}%'
      <if test="systemCid != null">
         AND h.`sg_class_id` = #{systemCid}
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <>'']]>
      </if>
      <!-- 天猫 -->
      <if test="userType == 1 ">
         AND tb.userType = #{userType}
      </if>
      <!-- 销量以上 -->
      <if test="biz30day != null ">
         AND <![CDATA[tb.biz30day >= #{biz30day} ]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice} ]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice} ]]>
      </if>
      ORDER BY
      <!-- 销量高到低 -->
      <if test='sort == 1'>
         tb.`biz30day` desc,
      </if>
      <!-- 价格 -->
      <if test='sort == 3'>
         tb.`zkPrice`,
      </if>
      <if test='sort == 2'>
         tb.`zkPrice` desc,
      </if>
      h.`sg_weight` desc
      LIMIT #{start},#{count}
   </select>
   <select id="countQueryByKey" resultType="java.lang.Long">
      <!-- 移动统计 -->
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      tb.`title` LIKE '%${key}%'
      <if test="systemCid != null">
         AND h.`sg_class_id` = #{systemCid}
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <>'']]>
      </if>
      <!-- 天猫 -->
      <if test="userType == 1 ">
         AND tb.userType = #{userType}
      </if>
      <!-- 销量以上 -->
      <if test="biz30day != null ">
         AND <![CDATA[tb.biz30day >= #{biz30day} ]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice} ]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice} ]]>
      </if>
   </select>
   <select id="listQueryByAuctionId" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM yeshi_ec_quality_factory h
      left join yeshi_ec_taobao_goods tb ON
      h.`sg_goods_id`= tb.`id` WHERE
      tb.auctionId in
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
   </select>
   <select id="listQueryByCouponAmount" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      h.`sg_goods_id`= tb.`id`
      WHERE 1=1
      <if test="startAmount != null">
         AND <![CDATA[ tb.`couponAmount` >= #{startAmount}]]>
      </if>
      <if test="endAmount != null">
         AND <![CDATA[ tb.`couponAmount` < #{endAmount}]]>
      </if>
      <!-- 券比例 -->
      <if test='startPropor != null'>
         AND <![CDATA[   ROUND(tb.couponAmount/tb.`zkPrice`*100,2) >= #{startPropor} ]]>
      </if>
      ORDER BY h.sg_weight desc,tb.`biz30day`desc
      LIMIT #{start},#{count}
   </select>
   <select id="countQueryByCouponAmount" resultType="java.lang.Long">
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      1=1
      <if test="startAmount != null">
         AND <![CDATA[ tb.`couponAmount` >= #{startAmount}]]>
      </if>
      <if test="endAmount != null">
         AND <![CDATA[ tb.`couponAmount` < #{endAmount}]]>
      </if>
      <!-- 券比例 -->
      <if test='startPropor != null'>
         AND <![CDATA[   ROUND(tb.couponAmount/tb.`zkPrice`*100,2) >= #{startPropor} ]]>
      </if>
   </select>
   <select id="listQueryByFlashSale" resultMap="BaseResultMap">
      SELECT    <include refid="Base_Column_List" /> FROM yeshi_ec_quality_flash_sale s
      LEFT JOIN yeshi_ec_quality_factory h ON  h.`sg_goods_id` = s.`fs_qfgoods_id`
      LEFT JOIN yeshi_ec_taobao_goods tb    ON h.`sg_goods_id`= tb.`id`
      WHERE <![CDATA[ tb.`couponTotalCount` > 0 AND tb.couponLeftCount<tb.couponTotalCount ]]>
      ORDER BY (tb.couponLeftCount/tb.couponTotalCount),s.fs_weight desc
      LIMIT ${start},${count}
   </select>
   <select id="countQueryByFlashSale" resultType="java.lang.Long">
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM yeshi_ec_quality_factory h
      RIGHT JOIN yeshi_ec_quality_flash_sale s ON h.`sg_goods_id` =   s.`fs_qfgoods_id`
      LEFT JOIN yeshi_ec_taobao_goods tb ON   h.`sg_goods_id`= tb.`id`
      WHERE <![CDATA[ tb.`couponTotalCount` > 0  AND tb.couponLeftCount<tb.couponTotalCount]]>
   </select>
   <select id="listFlashSaleRandGoods" resultMap="GoodsResultMap">
      SELECT h.*, tb.* FROM yeshi_ec_quality_factory h
      RIGHT JOIN yeshi_ec_quality_flash_sale s ON h.`sg_goods_id` = s.`fs_qfgoods_id`
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE  s.`fs_id` IS NOT NULL AND tb.`biz30day` <![CDATA[>=]]> 10000
           AND tb.`couponTotalCount` <![CDATA[>]]>10
           AND tb.couponLeftCount <![CDATA[<]]> tb.couponTotalCount
      ORDER BY RAND()
      LIMIT 3
   </select>
   <!-- 查询精选商品信息 -->
   <select id="listQueryByKeyAndlabIDs" resultMap="BaseResultMap">
      SELECT ts.* FROM (
      SELECT DISTINCT( tt.`sg_id`) AS id FROM
      yeshi_ec_quality_factory tt
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      tt.`sg_goods_id`= tb.`id`
      LEFT JOIN yeshi_ec_label_goods lg ON
      tt.`sg_goods_id` = lg.`lg_goods_id`
      WHERE (tb.`title` LIKE '%${key}%'
      OR lg.`lg_label_id` IN
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
      )
      <if test="systemCid != null">
         AND tt.`sg_class_id` = #{systemCid}
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <>'']]>
      </if>
      <!-- 天猫 -->
      <if test="userType == 1 ">
         AND tb.userType = #{userType}
      </if>
      <!-- 销量以上 -->
      <if test="biz30day != null ">
         AND <![CDATA[tb.biz30day >= #{biz30day} ]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice} ]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice} ]]>
      </if>
      ORDER BY
      <!-- 销量高到低 -->
      <if test='sort == 1'>
         tb.`biz30day` desc,
      </if>
      <!-- 价格 -->
      <if test='sort == 3'>
         tb.`zkPrice`,
      </if>
      <if test='sort == 2'>
         tb.`zkPrice` desc,
      </if>
      <if test='sort == 4'>
         tb.`tkRate` desc,
      </if>
      tt.`sg_weight` desc
      LIMIT ${start},${count}
      ) a LEFT JOIN
      yeshi_ec_quality_factory ts ON ts.`sg_id`=a.id
   </select>
   <select id="countQueryKeyAndlabIDs" resultType="java.lang.Long">
      <!-- 根据条件统计所有标签数量 -->
      SELECT count(ts.sg_id) FROM (
      SELECT DISTINCT(tt.`sg_id`) AS id FROM
      yeshi_ec_quality_factory tt
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      tt.`sg_goods_id`= tb.`id`
      LEFT JOIN yeshi_ec_label_goods lg ON
      tt.`sg_goods_id` = lg.`lg_goods_id`
      WHERE (tb.`title` LIKE '%${key}%'
      OR lg.`lg_label_id` IN
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
      )
      <if test="systemCid != null">
         AND tt.`sg_class_id` = #{systemCid}
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <>'']]>
      </if>
      <!-- 天猫 -->
      <if test="userType == 1 ">
         AND tb.userType = #{userType}
      </if>
      <!-- 销量以上 -->
      <if test="biz30day != null ">
         AND <![CDATA[tb.biz30day >= #{biz30day} ]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice} ]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice} ]]>
      </if>
      ) a LEFT JOIN yeshi_ec_quality_factory ts ON ts.`sg_id`=a.id
   </select>
   <select id="listQueryByRebateAmount" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM `yeshi_ec_quality_factory` h
      LEFT JOIN
      (SELECT
      tb.`id`,tb.biz30day,(CASE WHEN<![CDATA[ tb.`zkPrice` < tb.`couponStartFee`]]>
      THEN tb.`zkPrice` * tb.`tkRate`/10000*#{proportion}
      ELSE
      (tb.`zkPrice`-tb.`couponAmount`) * tb.`tkRate`/10000*#{proportion}
      END)AS RateAmount FROM yeshi_ec_taobao_goods tb
      where tb.tkRate >
      #{tkRate})g
      ON h.`sg_goods_id`= g.`id`
      WHERE 1=1
      <if test="startAmount != null">
         AND <![CDATA[ g.rateAmount >= #{startAmount} ]]>
      </if>
      <if test="endAmount != null">
         AND <![CDATA[ g.rateAmount < #{endAmount} ]]>
      </if>
      ORDER BY g.biz30day desc
      LIMIT #{start},#{count}
   </select>
   <select id="countQueryByRebateAmount" resultType="java.lang.Long">
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN
      (SELECT tb.`id`,(CASE WHEN <![CDATA[tb.`zkPrice` < tb.`couponStartFee`]]>
      THEN tb.`zkPrice` * tb.`tkRate`/10000*#{proportion}
      ELSE
      (tb.`zkPrice`-tb.`couponAmount`) * tb.`tkRate`/10000*#{proportion}
      END)AS RateAmount FROM yeshi_ec_taobao_goods tb
      where tb.tkRate >
      #{tkRate})g
      ON h.`sg_goods_id`= g.`id`
      WHERE 1=1
      <if test="startAmount != null">
         AND <![CDATA[ g.rateAmount >= #{startAmount} ]]>
      </if>
      <if test="endAmount != null">
         AND <![CDATA[ g.rateAmount < #{endAmount} ]]>
      </if>
   </select>
   <select id="getAuctionIdbyClassId" resultType="java.lang.Long">
      SELECT h.`sg_goods_id` FROM `yeshi_ec_quality_factory` h
      WHERE  h.`sg_goods_source` = #{goodsSource}
         AND h.`sg_updatetime` <![CDATA[<]]> #{beforeTime}
         <if test="systemCid != null">AND h.`sg_class_id` = #{systemCid}</if>
   </select>
   <select id="listRecommendToIndex" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM `yeshi_ec_quality_factory` h
      LEFT JOIN
      (SELECT tb.`id`,tb.tkRate,
            <![CDATA[(CASE WHEN  tb.`zkPrice` < tb.`couponStartFee`  THEN tb.`zkPrice` * tb.`tkRate`/10000*#{proportion}
              ELSE (tb.`zkPrice`-tb.`couponAmount`) * tb.`tkRate`/10000*#{proportion} END)AS rateAmount
              FROM  yeshi_ec_taobao_goods tb
              WHERE tb.tkRate >=  #{tkRate}
                 AND tb.`couponAmount` >=  #{couponAmount}
                 AND (tb.`couponAmount`/ tb.zkPrice)*100 > #{couponRatio}
              ]]>
      )g
      ON h.`sg_goods_id`= g.`id`
      WHERE  <![CDATA[ g.rateAmount >= #{commision} ]]>
      ORDER BY h.sg_weight DESC
      LIMIT #{start},#{count}
   </select>
   <select id="countRecommendToIndex" resultType="java.lang.Long">
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN
      (SELECT tb.`id`,tb.tkRate,
             <![CDATA[(CASE WHEN  tb.`zkPrice` < tb.`couponStartFee`  THEN tb.`zkPrice` * tb.`tkRate`/10000*${proportion}
              ELSE (tb.`zkPrice`-tb.`couponAmount`) * tb.`tkRate`/10000*${proportion} END)AS RateAmount
              FROM  yeshi_ec_taobao_goods tb
              WHERE tb.tkRate >=  #{tkRate}
                   AND tb.`couponAmount` >=  #{couponAmount}
                    AND (tb.`couponAmount`/ tb.zkPrice)*100 > #{couponRatio}
              ]]>
      )g
      ON h.`sg_goods_id`= g.`id`
      WHERE  <![CDATA[ g.rateAmount >= #{commision} ]]>
   </select>
   <select id="listRecommendBykey" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      h.`sg_goods_id`= tb.`id`
      WHERE 1=1
      <!-- 关键词搜索 -->
      <if test='key != null and key != ""'> AND tb.`title` LIKE '%${key}%' </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice}]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice}]]>
      </if>
      <!-- 返利比范围 -->
      <if test='startTkRate != null'>
         AND <![CDATA[  tb.`tkRate` >= #{startTkRate}]]>
      </if>
      <if test='endTkRate != null'>
         AND <![CDATA[  tb.`tkRate` <= #{endTkRate}]]>
      </if>
      <!-- 有券 -->
      <if test='hasQuan != null'>
         AND <![CDATA[  tb.`couponLeftCount` > 1]]>
      </if>
      <!-- 天猫商品 -->
      <if test='userType != null'>
         AND <![CDATA[  tb.`userType` = 1]]>
      </if>
      ORDER BY
      <!-- 销量高到低 -->
      <if test='sort == 1'>
         tb.`biz30day` desc,
      </if>
      <!-- 价格 低到高 -->
      <if test='sort == 3'>
         tb.`zkPrice`,
      </if>
      <!-- 价格 高到低 -->
      <if test='sort == 2'>
         tb.`zkPrice` desc,
      </if>
      <!-- 推广量 高到低 -->
      <if test='sort == 4'>
         tb.`totalSales` desc,
      </if>
      <!-- 佣金比例 -->
      <if test='sort == 5'>
         tb.`tkRate` desc,
      </if>
      <!-- 佣金比例 -->
      <if test='sort == 6'>
         tb.`tkRate`,
      </if>
      <!-- 默认:权重高到低 -->
      h.sg_weight DESC
      LIMIT #{start},#{count}
   </select>
   <select id="countRecommendBykey" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      1=1
      <!-- 关键词搜索 -->
      <if test='key != null and key != ""'> AND tb.`title` LIKE '%${key}%' </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice}]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice}]]>
      </if>
      <!-- 返利比范围 -->
      <if test='startTkRate != null'>
         AND <![CDATA[  tb.`tkRate` >= #{startTkRate}]]>
      </if>
      <if test='endTkRate != null'>
         AND <![CDATA[  tb.`tkRate` <= #{endTkRate}]]>
      </if>
      <!-- 有券 -->
      <if test='hasQuan != null'>
         AND <![CDATA[  tb.`couponLeftCount` > 1]]>
      </if>
      <!-- 天猫商品 -->
      <if test='userType != null'>
         AND <![CDATA[  tb.`userType` = 1]]>
      </if>
   </select>
   <select id="listQueryBylabIDs" resultMap="GoodsResultMap">
      SELECT * FROM (
      SELECT DISTINCT( tt.`sg_id`) AS tbid FROM
      yeshi_ec_quality_factory tt
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      tt.`sg_goods_id`= tb.`id`
      LEFT JOIN yeshi_ec_label_goods lg ON
      tt.`sg_goods_id` = lg.`lg_goods_id`
      WHERE tb.`id` != #{gid}
      <if test='systemCid != null'>
         AND tt.`sg_class_id` = #{systemCid}
      </if>
      AND lg.`lg_label_id` IN
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
      LIMIT ${start},${count}
      ) a LEFT JOIN yeshi_ec_quality_factory ts ON
      ts.`sg_id`=a.tbid
      LEFT JOIN yeshi_ec_taobao_goods tbb ON
      ts.`sg_goods_id`= tbb.`id`
   </select>
   <select id="listByMinSalesCountOrderByCreateTimeDesc" resultMap="BaseResultMap">
      SELECT f.* FROM `yeshi_ec_quality_factory` f LEFT JOIN
      yeshi_ec_taobao_goods t ON f.`sg_goods_id`=t.`id` WHERE
      t.`biz30day`>=#{salesCount} ORDER BY f.`sg_createtime` DESC limit
      #{start},#{count}
   </select>
   <select id="listByShopId" resultMap="GoodsResultMap">
      SELECT * FROM  yeshi_ec_quality_factory q
      LEFT JOIN `yeshi_ec_taobao_goods` t ON q.`sg_goods_id` = t.`id`
      WHERE t.`sellerId` = #{shopId}
      ORDER BY q.`sg_weight` DESC
      LIMIT #{start},#{count}
   </select>
    <select id="countByShopId" resultType="java.lang.Long">
      SELECT  ifnull(count(sg_id),0) FROM  yeshi_ec_quality_factory q
      LEFT JOIN `yeshi_ec_taobao_goods` t ON q.`sg_goods_id` = t.`id`
      WHERE t.`sellerId` = #{shopId}
    </select>
   <select id="get9k9ClassGoods" resultMap="GoodsResultMap">
      SELECT * FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE tb.`couponAmount` > 0 AND tb.`couponTotalCount` > 0
          AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
          AND tb.`zkPrice` <![CDATA[<=]]> #{zkPrice}
          AND tb.`biz30day` <![CDATA[>=]]> #{biz30day}
          <!--  券后价范围 -->
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]> #{minQuanPrice}
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<= ]]> #{maxQuanPrice}
          <!-- 多个分类id -->
         <if test='cids != null and cids != ""'>
            AND h.`sg_class_id` in (${cids})
         </if>
      ORDER BY h.sg_weight desc,tb.`biz30day`desc
      LIMIT ${start},${count}
   </select>
   <select id="count9k9ClassGoods" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE tb.`couponAmount` > 0 AND tb.`couponTotalCount` > 0
          AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
          AND tb.`zkPrice` <![CDATA[<=]]> #{zkPrice}
          AND tb.`biz30day` <![CDATA[>=]]> #{biz30day}
          <!--  券后价范围 -->
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]> #{minQuanPrice}
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<= ]]> #{maxQuanPrice}
          <!-- 多个分类id -->
         <if test='cids != null and cids != ""'>
            AND h.`sg_class_id` in (${cids})
         </if>
   </select>
   <!-- 每日必抢 -->
   <select id="listQueryEverydayRob" resultMap="GoodsResultMap">
      SELECT * FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE tb.`couponTotalCount` > 0  AND tb.couponAmount <![CDATA[>]]> 1 AND tb.couponAmount <![CDATA[<=]]> 50
          AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
          AND tb.`zkPrice` <![CDATA[<=]]> #{zkPrice}
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]> #{minQuanPrice}
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<=]]> #{maxQuanPrice}
      ORDER BY h.sg_createtime desc
      LIMIT ${start},${count}
   </select>
   <select id="countQueryEverydayRob" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE tb.`couponTotalCount` > 0  AND tb.couponAmount <![CDATA[>]]> 1 AND tb.couponAmount <![CDATA[<=]]> 50
          AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
          AND tb.`zkPrice` <![CDATA[<=]]> #{zkPrice}
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]> #{minQuanPrice}
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<=]]> #{maxQuanPrice}
   </select>
    <select id="listFreeGoods" resultMap="GoodsResultMap">
       SELECT * FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE tb.`couponAmount` > 0 AND tb.`couponTotalCount` > 0
          AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
          <!-- 在售价  209.9 -->
          AND tb.`zkPrice` <![CDATA[<=]]> 209.9
          <!--  券后价范围  0~9.9 -->
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]> 0
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<= ]]> 9.9
          <!-- 比例  20 -->
          AND  tb.`tkRate` <![CDATA[>=]]> 20
      ORDER BY h.sg_weight desc
      LIMIT ${start},${count}
   </select>
   <select id="countFreeGoods" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(h.`sg_id`),0)  FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE tb.`couponAmount` > 0 AND tb.`couponTotalCount` > 0
          AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
          <!-- 在售价  209.9 -->
          AND tb.`zkPrice` <![CDATA[<=]]> 209.9
          <!--  券后价范围  0~9.9 -->
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]> 0
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<= ]]> 9.9
          <!-- 比例  20 -->
          AND  tb.`tkRate` <![CDATA[>=]]> 20
   </select>
</mapper>
<?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.yeshi.fanli.dao.mybatis.lable.QualityFactoryMapper">
   <resultMap id="BaseResultMap"
      type="com.yeshi.fanli.entity.bus.lable.QualityFactory">
      <id column="sg_id" property="id" jdbcType="BIGINT" />
      <result column="sg_class_id" property="systemCid" jdbcType="BIGINT" />
      <result column="sg_entry_mode" property="entryMode" jdbcType="INTEGER" />
      <result column="sg_goods_source" property="goodsSource"
         jdbcType="INTEGER" />
      <result column="sg_source_calss" property="sourceCalss"
         jdbcType="VARCHAR" />
      <result column="sg_weight" property="weight" jdbcType="INTEGER" />
      <result column="sg_createtime" property="createtime" jdbcType="TIMESTAMP" />
      <result column="sg_updatetime" property="updatetime" jdbcType="TIMESTAMP" />
      <association property="taoBaoGoodsBrief" column="sg_goods_id"
         select="com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper.selectByPrimaryKey">
      </association>
      <association property="boutiqueAutoRule" column="sg_rule_id"
         javaType="com.yeshi.fanli.entity.bus.lable.BoutiqueAutoRule">
         <id column="sg_rule_id" property="id" jdbcType="BIGINT" />
      </association>
      <association property="createUser" column="sg_create_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_create_aid" property="id" jdbcType="BIGINT" />
      </association>
      <association property="updateUser" column="sg_update_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_update_aid" property="id" jdbcType="BIGINT" />
      </association>
   </resultMap>
   <resultMap id="ResultMap"
      type="com.yeshi.fanli.entity.bus.lable.QualityFactory">
      <id column="sg_id" property="id" jdbcType="BIGINT" />
      <result column="sg_class_id" property="systemCid" jdbcType="BIGINT" />
      <result column="sg_entry_mode" property="entryMode" jdbcType="INTEGER" />
      <result column="sg_goods_source" property="goodsSource"
         jdbcType="INTEGER" />
      <result column="sg_source_calss" property="sourceCalss"
         jdbcType="VARCHAR" />
      <result column="sg_weight" property="weight" jdbcType="INTEGER" />
      <result column="sg_createtime" property="createtime" jdbcType="TIMESTAMP" />
      <result column="sg_updatetime" property="updatetime" jdbcType="TIMESTAMP" />
      <association property="boutiqueAutoRule" column="sg_rule_id"
         select="com.yeshi.fanli.dao.mybatis.lable.BoutiqueAutoRuleMapper.selectByPrimaryKey">
      </association>
      <association property="taoBaoGoodsBrief" column="sg_goods_id"
         select="com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper.selectByPrimaryKey">
      </association>
      <association property="createUser" column="sg_create_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_create_aid" property="id" jdbcType="BIGINT" />
      </association>
      <association property="updateUser" column="sg_update_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_update_aid" property="id" jdbcType="BIGINT" />
      </association>
   </resultMap>
   <resultMap id="GoodsResultMap"
      type="com.yeshi.fanli.entity.bus.lable.QualityFactory">
      <id column="sg_id" property="id" jdbcType="BIGINT" />
      <result column="sg_class_id" property="systemCid" jdbcType="BIGINT" />
      <result column="sg_entry_mode" property="entryMode" jdbcType="INTEGER" />
      <result column="sg_goods_source" property="goodsSource"
         jdbcType="INTEGER" />
      <result column="sg_source_calss" property="sourceCalss"
         jdbcType="VARCHAR" />
      <result column="sg_weight" property="weight" jdbcType="INTEGER" />
      <result column="sg_createtime" property="createtime" jdbcType="TIMESTAMP" />
      <result column="sg_updatetime" property="updatetime" jdbcType="TIMESTAMP" />
      <association property="boutiqueAutoRule" column="sg_rule_id"
         javaType="com.yeshi.fanli.entity.bus.lable.BoutiqueAutoRule">
         <id column="sg_rule_id" property="id" jdbcType="BIGINT" />
      </association>
      <association property="taoBaoGoodsBrief" column="sg_goods_id"
         resultMap="com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper.BaseResultMap" />
      <association property="createUser" column="sg_create_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_create_aid" property="id" jdbcType="BIGINT" />
      </association>
      <association property="updateUser" column="sg_update_aid"
         javaType="com.yeshi.fanli.entity.common.AdminUser">
         <id column="sg_update_aid" property="id" jdbcType="BIGINT" />
      </association>
   </resultMap>
   <sql id="Base_Column_List">sg_id,sg_class_id,sg_goods_id,sg_entry_mode,sg_goods_source,sg_source_calss,sg_rule_id,sg_weight,sg_create_aid,sg_createtime,sg_update_aid,sg_updatetime
   </sql>
   <select id="selectByPrimaryKey" resultMap="BaseResultMap"
      parameterType="java.lang.Long">
      select
      <include refid="Base_Column_List" />
      from yeshi_ec_quality_factory where sg_id = #{id,jdbcType=BIGINT}
   </select>
   <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
      yeshi_ec_quality_factory where sg_id = #{id,jdbcType=BIGINT}
   </delete>
   <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.lable.QualityFactory"
      useGeneratedKeys="true" keyProperty="id">insert into
      yeshi_ec_quality_factory
      (sg_id,sg_class_id,sg_goods_id,sg_entry_mode,sg_goods_source,sg_source_calss,sg_rule_id,sg_weight,sg_create_aid,sg_createtime,sg_update_aid,sg_updatetime)
      values
      (#{id,jdbcType=BIGINT},#{systemCid,jdbcType=BIGINT},#{taoBaoGoodsBrief.id,jdbcType=BIGINT},#{entryMode,jdbcType=INTEGER},#{goodsSource,jdbcType=INTEGER},#{sourceCalss,jdbcType=VARCHAR},#{boutiqueAutoRule.id,jdbcType=BIGINT},#{weight,jdbcType=INTEGER},#{createUser.id,jdbcType=BIGINT},#{createtime,jdbcType=TIMESTAMP},#{updateUser.id,jdbcType=BIGINT},#{updatetime,jdbcType=TIMESTAMP})
   </insert>
   <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.lable.QualityFactory"
      useGeneratedKeys="true" keyProperty="id">
      insert into yeshi_ec_quality_factory
      <trim prefix="(" suffix=")" suffixOverrides=",">
         <if test="id != null">sg_id,</if>
         <if test="systemCid != null">sg_class_id,</if>
         <if test="taoBaoGoodsBrief != null">sg_goods_id,</if>
         <if test="entryMode != null">sg_entry_mode,</if>
         <if test="goodsSource != null">sg_goods_source,</if>
         <if test="sourceCalss != null">sg_source_calss,</if>
         <if test="boutiqueAutoRule != null">sg_rule_id,</if>
         <if test="weight != null">sg_weight,</if>
         <if test="createUser != null">sg_create_aid,</if>
         <if test="createtime != null">sg_createtime,</if>
         <if test="updateUser != null">sg_update_aid,</if>
         <if test="updatetime != null">sg_updatetime,</if>
      </trim>
      values
      <trim prefix="(" suffix=")" suffixOverrides=",">
         <if test="id != null">#{id,jdbcType=BIGINT},</if>
         <if test="systemCid != null">#{systemCid,jdbcType=BIGINT},</if>
         <if test="taoBaoGoodsBrief != null">#{taoBaoGoodsBrief.id,jdbcType=BIGINT},</if>
         <if test="entryMode != null">#{entryMode,jdbcType=INTEGER},</if>
         <if test="goodsSource != null">#{goodsSource,jdbcType=INTEGER},</if>
         <if test="sourceCalss != null">#{sourceCalss,jdbcType=VARCHAR},</if>
         <if test="boutiqueAutoRule != null">#{boutiqueAutoRule.id,jdbcType=BIGINT},</if>
         <if test="weight != null">#{weight,jdbcType=INTEGER},</if>
         <if test="createUser != null">#{createUser.id,jdbcType=BIGINT},</if>
         <if test="createtime != null">#{createtime,jdbcType=TIMESTAMP},</if>
         <if test="updateUser != null">#{updateUser.id,jdbcType=BIGINT},</if>
         <if test="updatetime != null">#{updatetime,jdbcType=TIMESTAMP},</if>
      </trim>
   </insert>
   <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.lable.QualityFactory">update
      yeshi_ec_quality_factory set sg_class_id =
      #{systemCid,jdbcType=BIGINT},sg_goods_id =
      #{taoBaoGoodsBrief.id,jdbcType=BIGINT},sg_entry_mode =
      #{entryMode,jdbcType=INTEGER},sg_goods_source =
      #{goodsSource,jdbcType=INTEGER},sg_source_calss =
      #{sourceCalss,jdbcType=VARCHAR},sg_rule_id =
      #{boutiqueAutoRule.id,jdbcType=BIGINT},sg_weight =
      #{weight,jdbcType=INTEGER},sg_create_aid =
      #{createUser.id,jdbcType=BIGINT},sg_createtime =
      #{createtime,jdbcType=TIMESTAMP},sg_update_aid =
      #{updateUser.id,jdbcType=BIGINT},sg_updatetime =
      #{updatetime,jdbcType=TIMESTAMP} where sg_id = #{id,jdbcType=BIGINT}
   </update>
   <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.lable.QualityFactory">
      update yeshi_ec_quality_factory
      <set>
         <if test="systemCid != null">sg_class_id=#{systemCid,jdbcType=BIGINT},</if>
         <if test="taoBaoGoodsBrief != null">sg_goods_id=#{taoBaoGoodsBrief.id,jdbcType=BIGINT},</if>
         <if test="entryMode != null">sg_entry_mode=#{entryMode,jdbcType=INTEGER},</if>
         <if test="goodsSource != null">sg_goods_source=#{goodsSource,jdbcType=INTEGER},</if>
         <if test="sourceCalss != null">sg_source_calss=#{sourceCalss,jdbcType=VARCHAR},</if>
         <if test="boutiqueAutoRule != null">sg_rule_id=#{boutiqueAutoRule.id,jdbcType=BIGINT},</if>
         <if test="weight != null">sg_weight=#{weight,jdbcType=INTEGER},</if>
         <if test="createUser != null">sg_create_aid=#{createUser.id,jdbcType=BIGINT},</if>
         <if test="createtime != null">sg_createtime=#{createtime,jdbcType=TIMESTAMP},</if>
         <if test="updateUser != null">sg_update_aid=#{updateUser.id,jdbcType=BIGINT},</if>
         <if test="updatetime != null">sg_updatetime=#{updatetime,jdbcType=TIMESTAMP},</if>
      </set>
      where sg_id = #{id,jdbcType=BIGINT}
   </update>
   <!-- 查询超过4个小时未更新商品,进行更新 -->
   <update id="updateWeight">
      UPDATE yeshi_ec_quality_factory SET sg_weight = #{weight}
      WHERE <![CDATA[TO_DAYS(`sg_updatetime`) < TO_DAYS(NOW()) OR (HOUR(NOW()) -HOUR(`sg_updatetime`)) >= #{time} ]]>
   </update>
   <delete id="deleteBatchByPrimaryKey" parameterType="java.util.List">
      DELETE FROM yeshi_ec_quality_factory WHERE sg_id in
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
   </delete>
   <delete id="deleteBatchByGoodsId" parameterType="java.util.List">
      DELETE FROM yeshi_ec_quality_factory WHERE sg_goods_id in
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
   </delete>
   <insert id="insertBatch" useGeneratedKeys="true" keyProperty="id"
      parameterType="java.util.List">
      INSERT IGNORE yeshi_ec_quality_factory
      (
      <include refid="Base_Column_List" />
      )
      values
      <foreach collection="list" item="item" separator=",">
         (
         #{item.id,jdbcType=BIGINT},
         #{item.systemCid,jdbcType=BIGINT},
         #{item.taoBaoGoodsBrief.id,jdbcType=BIGINT},
         #{item.entryMode,jdbcType=INTEGER},
         #{item.goodsSource,jdbcType=INTEGER},
         #{item.sourceCalss,jdbcType=VARCHAR},
         #{item.boutiqueAutoRule.id,jdbcType=BIGINT},
         #{item.weight,jdbcType=INTEGER},
         #{item.createUser.id,jdbcType=BIGINT},
         #{item.createtime,jdbcType=TIMESTAMP},
         #{item.updateUser.id,jdbcType=BIGINT},
         #{item.updatetime,jdbcType=TIMESTAMP}
         )
      </foreach>
   </insert>
   <update id="updateBatchSelective" parameterType="java.util.List">
      update yeshi_ec_quality_factory
      <trim prefix="set" suffixOverrides=",">
         <trim prefix="sg_weight =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.weight !=null">
                  when sg_id=#{item.id} then #{item.weight}
               </if>
            </foreach>
         </trim>
         <trim prefix="sg_goods_source =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.goodsSource !=null">
                  when sg_id=#{item.id} then #{item.goodsSource}
               </if>
            </foreach>
         </trim>
         <trim prefix="sg_rule_id =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.boutiqueAutoRule !=null">
                  when sg_id=#{item.id} then #{item.boutiqueAutoRule.id}
               </if>
            </foreach>
         </trim>
         <trim prefix="sg_source_calss =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.sourceCalss !=null">
                  when sg_id=#{item.id} then #{item.sourceCalss}
               </if>
            </foreach>
         </trim>
         <trim prefix="sg_createtime =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.createtime !=null">
                  when sg_id=#{item.id} then #{item.createtime}
               </if>
            </foreach>
         </trim>
         <trim prefix="sg_updatetime =case" suffix="end,">
            <foreach collection="list" item="item" index="index">
               <if test="item.updatetime !=null">
                  when sg_id=#{item.id} then #{item.updatetime}
               </if>
            </foreach>
         </trim>
      </trim>
      where sg_id in
      <foreach collection="list" index="index" item="item"
         separator="," open="(" close=")">
         #{item.id,jdbcType=BIGINT}
      </foreach>
   </update>
   <!-- 查询所有商品信息 更新时间较早在前 -->
   <select id="queryAll" resultMap="BaseResultMap">
      SELECT * FROM yeshi_ec_quality_factory
      <if test="days != null">
         WHERE DATE_SUB(CURDATE(), INTERVAL ${days} DAY) >
         DATE(lab_updatetime);
      </if>
      order by sg_updatetime LIMIT ${start},${count}
   </select>
   <!-- 查询精选商品信息 -->
   <select id="query" parameterType="com.yeshi.fanli.vo.quality.QualityFactoryVO"
      resultMap="ResultMap">
      SELECT ts.* FROM (
      SELECT DISTINCT( tt.`sg_id`) AS id FROM
      yeshi_ec_quality_factory tt
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      tt.`sg_goods_id`= tb.`id`
      <if test='keyType == 3'>
         LEFT JOIN yeshi_ec_label_goods lg ON tt.`sg_goods_id` =
         lg.`lg_goods_id`
         LEFT JOIN yeshi_ec_label lab ON lg.`lg_label_id` =
         lab.`lab_id`
      </if>
      WHERE 1=1
      <if test="goodsSource != null">
         <!-- 来源 -->
         AND tt.`sg_goods_source` = ${goodsSource}
      </if>
      <if test="days != null">
         <!-- 入库时间 -->
         AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) >= tt.`sg_createtime`]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startZkPrice != null'>
         AND <![CDATA[  tb.`zkPrice` >= ${startZkPrice} ]]>
      </if>
      <if test='endZkPrice != null'>
         AND <![CDATA[  tb.`zkPrice` <= ${endZkPrice} ]]>
      </if>
      <!-- 月销量 -->
      <if test='startBiz30day != null'>
         AND <![CDATA[  tb.`biz30day` >= ${startBiz30day} ]]>
      </if>
      <if test='endBiz30day != null'>
         AND <![CDATA[  tb.`biz30day` <= ${endBiz30day} ]]>
      </if>
      <!-- 权重范围 -->
      <if test='startWeight != null'>
         AND <![CDATA[   tt.`sg_weight` >= ${startWeight} ]]>
      </if>
      <if test='endWeight != null'>
         AND <![CDATA[   tt.`sg_weight` <= ${endWeight} ]]>
      </if>
      <!-- 佣金比例范围 -->
      <if test='startTkRate != null'>
         AND <![CDATA[   tb.`tkRate` >= ${startTkRate} ]]>
      </if>
      <if test='endTkRate != null'>
         AND <![CDATA[   tb.`tkRate` <= ${endTkRate} ]]>
      </if>
      <!-- 券面额:减多少 -->
      <if test='startAmount != null'>
         AND <![CDATA[   tb.`couponAmount` >= ${startAmount} ]]>
      </if>
      <if test='endAmount != null'>
         AND <![CDATA[   tb.`couponAmount` <= ${endAmount} ]]>
      </if>
      <!-- 券比例 -->
      <if test='startPropor != null'>
         AND <![CDATA[   ROUND(tb.couponAmount/tb.`zkPrice`*100,2) >= ${startPropor} ]]>
      </if>
      <!-- 券比例 -->
      <if test='endPropor != null'>
         AND <![CDATA[  ROUND(tb.couponAmount/tb.`zkPrice`*100,2) <= ${endPropor} ]]>
      </if>
      <!-- 有优惠券 -->
      <if test='hasCoupon == 1'>
         AND <![CDATA[  tb.`couponAmount` > 0 ]]>
      </if>
      <!-- 包邮 -->
      <if test='freeShipment == 1'>
         AND tb.`freeShipment` = 1
      </if>
      <!-- 消费者保障 -->
      <if test='isPrepay == 1'>
         AND tb.`isPrepay` = 1
      </if>
      <!-- 成交转化 -->
      <if test='payRate30 == 1'>
         AND tb.`payRate30` = 1
      </if>
      <!-- 好评率 -->
      <if test='goodRate == 1'>
         AND tb.`goodRate` = 1
      </if>
      <!-- 退款率 -->
      <if test='rfdRate == 1'>
         AND tb.`rfdRate` = 1
      </if>
      <!-- 分类id -->
      <if test='gcid != null'>
         AND tt.sg_class_id = #{gcid}
      </if>
      <!-- 搜索条件: 商品名称、商品id、标签名称 -->
      <if test='key != null and key != ""'>
         <if test='keyType == 1'>
            AND tb.`auctionId` = '${key}'
         </if>
         <if test='keyType == 2'>
            AND tb.`title` LIKE '%${key}%'
         </if>
         <if test='keyType == 3'>
            AND lab.`lab_title` = '${key}'
         </if>
         <if test='keyType == 4'>
            AND tb.`shopTitle` = '${key}'
         </if>
      </if>
      ORDER BY
      <!-- 销量 -->
      <if test='totalSales == 1'>
         tb.`biz30day`,
      </if>
      <if test='totalSales == 2'>
         tb.`biz30day` desc,
      </if>
      <!-- 价格 -->
      <if test='price == 1'>
         tb.`zkPrice`,
      </if>
      <if test='price == 2'>
         tb.`zkPrice` desc,
      </if>
      <!-- 价格 -->
      <if test='tkRate == 1'>
         tb.`tkRate`,
      </if>
      <if test='tkRate == 2'>
         tb.`tkRate` desc,
      </if>
      <!-- 券比例 -->
      <if test='propor == 1'>
         ROUND(tb.couponAmount/tb.`zkPrice` *100,2),
      </if>
      <if test='propor == 2'>
         ROUND(tb.couponAmount/tb.`zkPrice` *100,2) desc,
      </if>
      tt.`sg_updatetime` desc
      LIMIT ${start},${count}
      ) a LEFT JOIN
      yeshi_ec_quality_factory ts ON ts.`sg_id`=a.id
   </select>
   <select id="queryCount" parameterType="com.yeshi.fanli.vo.quality.QualityFactoryVO"
      resultType="java.lang.Long">
      <!-- 根据条件统计所有标签数量 -->
      SELECT count(ts.sg_id) FROM (
      SELECT DISTINCT( tt.`sg_id`) AS id FROM
      yeshi_ec_quality_factory tt
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      tt.`sg_goods_id`= tb.`id`
      <if test='keyType == 3'>
         LEFT JOIN yeshi_ec_label_goods lg ON tt.`sg_goods_id` =
         lg.`lg_goods_id`
         LEFT JOIN yeshi_ec_label lab ON lg.`lg_label_id` =
         lab.`lab_id`
      </if>
      WHERE 1=1
      <if test="goodsSource != null">
         <!-- 来源 -->
         AND tt.`sg_goods_source` = ${goodsSource}
      </if>
      <if test="days != null">
         <!-- 入库时间 -->
         AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) >= tt.`sg_createtime`]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startZkPrice != null'>
         AND <![CDATA[  tb.`zkPrice` >= ${startZkPrice} ]]>
      </if>
      <if test='endZkPrice != null'>
         AND <![CDATA[  tb.`zkPrice` <= ${endZkPrice} ]]>
      </if>
      <!-- 月销量 -->
      <if test='startBiz30day != null'>
         AND <![CDATA[  tb.`biz30day` >= ${startBiz30day} ]]>
      </if>
      <if test='endBiz30day != null'>
         AND <![CDATA[  tb.`biz30day` <= ${endBiz30day} ]]>
      </if>
      <!-- 权重范围 -->
      <if test='startWeight != null'>
         AND <![CDATA[   tt.`sg_weight` >= ${startWeight} ]]>
      </if>
      <if test='endWeight != null'>
         AND <![CDATA[   tt.`sg_weight` <= ${endWeight} ]]>
      </if>
      <!-- 佣金比例范围 -->
      <if test='startTkRate != null'>
         AND <![CDATA[   tb.`tkRate` >= ${startTkRate} ]]>
      </if>
      <if test='endTkRate != null'>
         AND <![CDATA[   tb.`tkRate` <= ${endTkRate} ]]>
      </if>
      <!-- 券面额:减多少 -->
      <if test='startAmount != null'>
         AND <![CDATA[   tb.`couponAmount` >= ${startAmount} ]]>
      </if>
      <if test='endAmount != null'>
         AND <![CDATA[   tb.`couponAmount` <= ${endAmount} ]]>
      </if>
      <!-- 券比例 -->
      <if test='startPropor != null'>
         AND <![CDATA[   ROUND(tb.couponAmount/tb.`zkPrice`*100,2) >= ${startPropor} ]]>
      </if>
      <!-- 券比例 -->
      <if test='endPropor != null'>
         AND <![CDATA[  ROUND(tb.couponAmount/tb.`zkPrice`*100,2) <= ${endPropor} ]]>
      </if>
      <!-- 有优惠券 -->
      <if test='hasCoupon == 1'>
         AND <![CDATA[  tb.`couponAmount` > 0 ]]>
      </if>
      <!-- 包邮 -->
      <if test='freeShipment == 1'>
         AND tb.`freeShipment` = 1
      </if>
      <!-- 消费者保障 -->
      <if test='isPrepay == 1'>
         AND tb.`isPrepay` = 1
      </if>
      <!-- 成交转化 -->
      <if test='payRate30 == 1'>
         AND tb.`payRate30` = 1
      </if>
      <!-- 好评率 -->
      <if test='goodRate == 1'>
         AND tb.`goodRate` = 1
      </if>
      <!-- 退款率 -->
      <if test='rfdRate == 1'>
         AND tb.`rfdRate` = 1
      </if>
      <!-- 分类id -->
      <if test='gcid != null'>
         AND tt.sg_class_id = #{gcid}
      </if>
      <!-- 搜索条件: 商品名称、商品id、标签名称 -->
      <if test='key != null and key != ""'>
         <if test='keyType == 1'>
            AND tb.`auctionId` = '${key}'
         </if>
         <if test='keyType == 2'>
            AND tb.`title` LIKE '%${key}%'
         </if>
         <if test='keyType == 3'>
            AND lab.`lab_title` = '${key}'
         </if>
         <if test='keyType == 4'>
            AND tb.`shopTitle` = '${key}'
         </if>
      </if>
      ) a LEFT JOIN yeshi_ec_quality_factory ts ON ts.`sg_id`=a.id
   </select>
   <!--查询精选商品信息 -->
   <select id="queryByGoodsId" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM yeshi_ec_quality_factory WHERE sg_goods_id = ${goodsId}
   </select>
   <!--查询精选商品信息 -->
   <select id="getByAuctionId" resultMap="BaseResultMap">
      SELECT * FROM
      yeshi_ec_quality_factory
      WHERE sg_goods_id = ${auctionId}
      limit 1
   </select>
   <select id="queryCountByGoodsId" resultType="java.lang.Long">
      SELECT COUNT(sg_id)
      FROM yeshi_ec_quality_factory WHERE sg_goods_id =
      ${goodsId}
   </select>
   <select id="getCountAll" resultType="java.util.HashMap">
      <!-- 统计今日各种方式录入数量 -->
      SELECT COUNT(sg_id) AS total, IFNULL(SUM(CASE WHEN sg_entry_mode = 1
      THEN 1 ELSE 0 END),0) AS totalMANUAL,
      IFNULL(SUM(CASE WHEN
      sg_entry_mode = 2 THEN 1 ELSE 0 END),0) AS totalSYSTEM,
      IFNULL(SUM(CASE WHEN sg_entry_mode = 3 THEN 1 ELSE 0 END),0) AS
      totalSEARCH,
      IFNULL(SUM(CASE WHEN sg_goods_source = 1 THEN 1 ELSE 0
      END),0) AS totalTB,
      IFNULL(SUM(CASE WHEN sg_goods_source = 2 THEN 1
      ELSE 0 END),0) AS
      totalJD,
      IFNULL(SUM(CASE WHEN sg_goods_source = 3 THEN
      1 ELSE 0 END),0) AS totalPDD,
      IFNULL(SUM(CASE WHEN sg_goods_source = 4
      THEN 1 ELSE 0 END),0) AS
      totalWPH
      FROM yeshi_ec_quality_factory
   </select>
   <delete id="deleteByGoodsId" parameterType="java.lang.Long">
      delete from
      yeshi_ec_quality_factory where sg_goods_id =
      #{goodsId,jdbcType=BIGINT}
   </delete>
   <select id="countTotalRows" resultType="java.lang.Long">
      SELECT COUNT(sg_id) FROM yeshi_ec_quality_factory
      <if test="days != null">
         WHERE DATE_SUB(CURDATE(), INTERVAL ${days} DAY) >
         DATE(lab_updatetime);
      </if>
   </select>
   <select id="listQuery" resultMap="BaseResultMap">
      <!-- 移动查询 -->
      SELECT * FROM `yeshi_ec_quality_factory` h
      <if test="labId != null">
         LEFT JOIN `yeshi_ec_label_goods` g ON h.`sg_goods_id` =
         g.`lg_goods_id`
      </if>
      <!-- 商品关键词 -->
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      1=1
      <!-- 商品关键词 -->
      <if test='key != null and key != ""'>
         AND tb.`title` LIKE '%${key}%'
      </if>
      <!-- 分类id -->
      <if test="systemCid != null">
         AND h.`sg_class_id` = ${systemCid}
      </if>
      <!-- 标签id -->
      <if test="labId != null">
         AND g.`lg_label_id`= ${labId}
      </if>
      <!-- 多个分类id -->
      <if test='cids != null and cids != ""'>
         AND h.`sg_class_id` in (${cids})
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <> '']]>
      </if>
      <!-- 排序:权重 销量 -->
      ORDER BY h.sg_weight desc,tb.`biz30day`desc
      LIMIT ${start},${count}
   </select>
   <select id="countQuery" resultType="java.lang.Long">
      <!-- 移动统计 -->
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      <if test="labId != null">
         LEFT JOIN `yeshi_ec_label_goods` g ON h.`sg_goods_id` =
         g.`lg_goods_id`
      </if>
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      1=1
      <!-- 商品关键词 -->
      <if test='key != null and key != ""'>
         AND tb.`title` LIKE '%${key}%'
      </if>
      <!-- 分类id -->
      <if test="systemCid != null">
         AND h.`sg_class_id` = #{systemCid}
      </if>
      <!-- 标签id -->
      <if test="labId != null">
         AND g.`lg_label_id`= #{labId}
      </if>
      <if test='cids != null and cids != ""'>
         AND h.`sg_class_id` in (#{cids})
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <>'']]>
      </if>
   </select>
   <delete id="removeStorageGoods" parameterType="java.lang.Long">
      DELETE FROM yeshi_ec_quality_factory h
      WHERE h.`sg_class_id`= #{gcids}
      AND <![CDATA[ h.`sg_createtime` < #{doTime} ]]>
      AND h.`sg_goods_id` NOT extsts(SELECT DISTINCT lg.`lg_goods_id` FROM
      yeshi_ec_label_goods lg)
   </delete>
   <select id="listQueryGoodsByGoodsId" resultMap="BaseResultMap">
      <!-- 根据auctionId 查询商品信息 -->
      SELECT
      <include refid="Base_Column_List" />
      FROM yeshi_ec_quality_factory
      WHERE sg_goods_id in
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
   </select>
   <select id="listQueryByKey" resultMap="BaseResultMap">
      <!-- 移动查询 -->
      SELECT
      <include refid="Base_Column_List" />
      FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      h.`sg_goods_id`= tb.`id`
      WHERE tb.`title` LIKE '%${key}%'
      <if test="systemCid != null">
         AND h.`sg_class_id` = #{systemCid}
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <>'']]>
      </if>
      <!-- 天猫 -->
      <if test="userType == 1 ">
         AND tb.userType = #{userType}
      </if>
      <!-- 销量以上 -->
      <if test="biz30day != null ">
         AND <![CDATA[tb.biz30day >= #{biz30day} ]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice} ]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice} ]]>
      </if>
      ORDER BY
      <!-- 销量高到低 -->
      <if test='sort == 1'>
         tb.`biz30day` desc,
      </if>
      <!-- 价格 -->
      <if test='sort == 3'>
         tb.`zkPrice`,
      </if>
      <if test='sort == 2'>
         tb.`zkPrice` desc,
      </if>
      h.`sg_weight` desc
      LIMIT #{start},#{count}
   </select>
   <select id="countQueryByKey" resultType="java.lang.Long">
      <!-- 移动统计 -->
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      tb.`title` LIKE '%${key}%'
      <if test="systemCid != null">
         AND h.`sg_class_id` = #{systemCid}
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <>'']]>
      </if>
      <!-- 天猫 -->
      <if test="userType == 1 ">
         AND tb.userType = #{userType}
      </if>
      <!-- 销量以上 -->
      <if test="biz30day != null ">
         AND <![CDATA[tb.biz30day >= #{biz30day} ]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice} ]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice} ]]>
      </if>
   </select>
   <select id="listQueryByAuctionId" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM yeshi_ec_quality_factory h
      left join yeshi_ec_taobao_goods tb ON
      h.`sg_goods_id`= tb.`id` WHERE
      tb.auctionId in
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
   </select>
   <select id="listQueryByCouponAmount" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      h.`sg_goods_id`= tb.`id`
      WHERE 1=1
      <if test="startAmount != null">
         AND <![CDATA[ tb.`couponAmount` >= #{startAmount}]]>
      </if>
      <if test="endAmount != null">
         AND <![CDATA[ tb.`couponAmount` < #{endAmount}]]>
      </if>
      <!-- 券比例 -->
      <if test='startPropor != null'>
         AND <![CDATA[   ROUND(tb.couponAmount/tb.`zkPrice`*100,2) >= #{startPropor} ]]>
      </if>
      ORDER BY h.sg_weight desc,tb.`biz30day`desc
      LIMIT #{start},#{count}
   </select>
   <select id="countQueryByCouponAmount" resultType="java.lang.Long">
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      1=1
      <if test="startAmount != null">
         AND <![CDATA[ tb.`couponAmount` >= #{startAmount}]]>
      </if>
      <if test="endAmount != null">
         AND <![CDATA[ tb.`couponAmount` < #{endAmount}]]>
      </if>
      <!-- 券比例 -->
      <if test='startPropor != null'>
         AND <![CDATA[   ROUND(tb.couponAmount/tb.`zkPrice`*100,2) >= #{startPropor} ]]>
      </if>
   </select>
   <select id="listQueryByFlashSale" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM yeshi_ec_quality_flash_sale s
      LEFT JOIN yeshi_ec_quality_factory h ON h.`sg_goods_id` =
      s.`fs_qfgoods_id`
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      h.`sg_goods_id`= tb.`id`
      WHERE <![CDATA[ tb.`couponTotalCount` > 0 AND tb.couponLeftCount<tb.couponTotalCount ]]>
      ORDER BY (tb.couponLeftCount/tb.couponTotalCount),s.fs_weight desc
      LIMIT ${start},${count}
   </select>
   <select id="countQueryByFlashSale" resultType="java.lang.Long">
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM yeshi_ec_quality_factory h
      RIGHT JOIN yeshi_ec_quality_flash_sale s ON h.`sg_goods_id` =
      s.`fs_qfgoods_id`
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      h.`sg_goods_id`= tb.`id`
      WHERE <![CDATA[ tb.`couponTotalCount` > 0  AND tb.couponLeftCount<tb.couponTotalCount]]>
   </select>
   <select id="listFlashSaleRandGoods" resultMap="GoodsResultMap">
      SELECT h.*, tb.* FROM yeshi_ec_quality_factory h
      RIGHT JOIN
      yeshi_ec_quality_flash_sale s ON h.`sg_goods_id` = s.`fs_qfgoods_id`
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE s.`fs_id` IS NOT NULL AND tb.`biz30day` <![CDATA[>=]]>
      10000
      AND tb.`couponTotalCount` <![CDATA[>]]>10
      AND tb.couponLeftCount <![CDATA[<]]>
      tb.couponTotalCount
      ORDER BY RAND()
      LIMIT 3
   </select>
   <!-- 查询精选商品信息 -->
   <select id="listQueryByKeyAndlabIDs" resultMap="BaseResultMap">
      SELECT ts.* FROM (
      SELECT DISTINCT( tt.`sg_id`) AS id FROM
      yeshi_ec_quality_factory tt
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      tt.`sg_goods_id`= tb.`id`
      LEFT JOIN yeshi_ec_label_goods lg ON
      tt.`sg_goods_id` = lg.`lg_goods_id`
      WHERE (tb.`title` LIKE '%${key}%'
      OR lg.`lg_label_id` IN
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
      )
      <if test="systemCid != null">
         AND tt.`sg_class_id` = #{systemCid}
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <>'']]>
      </if>
      <!-- 天猫 -->
      <if test="userType == 1 ">
         AND tb.userType = #{userType}
      </if>
      <!-- 销量以上 -->
      <if test="biz30day != null ">
         AND <![CDATA[tb.biz30day >= #{biz30day} ]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice} ]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice} ]]>
      </if>
      ORDER BY
      <!-- 销量高到低 -->
      <if test='sort == 1'>
         tb.`biz30day` desc,
      </if>
      <!-- 价格 -->
      <if test='sort == 3'>
         tb.`zkPrice`,
      </if>
      <if test='sort == 2'>
         tb.`zkPrice` desc,
      </if>
      <if test='sort == 4'>
         tb.`tkRate` desc,
      </if>
      tt.`sg_weight` desc
      LIMIT ${start},${count}
      ) a LEFT JOIN
      yeshi_ec_quality_factory ts ON ts.`sg_id`=a.id
   </select>
   <select id="countQueryKeyAndlabIDs" resultType="java.lang.Long">
      <!-- 根据条件统计所有标签数量 -->
      SELECT count(ts.sg_id) FROM (
      SELECT DISTINCT(tt.`sg_id`) AS id FROM
      yeshi_ec_quality_factory tt
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      tt.`sg_goods_id`= tb.`id`
      LEFT JOIN yeshi_ec_label_goods lg ON
      tt.`sg_goods_id` = lg.`lg_goods_id`
      WHERE (tb.`title` LIKE '%${key}%'
      OR lg.`lg_label_id` IN
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
      )
      <if test="systemCid != null">
         AND tt.`sg_class_id` = #{systemCid}
      </if>
      <!-- 有券 -->
      <if test="hasQuan == 1 ">
         AND <![CDATA[tb.couponInfo is not null AND tb.couponInfo <>'']]>
      </if>
      <!-- 天猫 -->
      <if test="userType == 1 ">
         AND tb.userType = #{userType}
      </if>
      <!-- 销量以上 -->
      <if test="biz30day != null ">
         AND <![CDATA[tb.biz30day >= #{biz30day} ]]>
      </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice} ]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice} ]]>
      </if>
      ) a LEFT JOIN yeshi_ec_quality_factory ts ON ts.`sg_id`=a.id
   </select>
   <select id="listQueryByRebateAmount" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM `yeshi_ec_quality_factory` h
      LEFT JOIN
      (SELECT
      tb.`id`,tb.biz30day,(CASE WHEN<![CDATA[ tb.`zkPrice` < tb.`couponStartFee`]]>
      THEN tb.`zkPrice` * tb.`tkRate`/10000*#{proportion}
      ELSE
      (tb.`zkPrice`-tb.`couponAmount`) * tb.`tkRate`/10000*#{proportion}
      END)AS RateAmount FROM yeshi_ec_taobao_goods tb
      where tb.tkRate >
      #{tkRate})g
      ON h.`sg_goods_id`= g.`id`
      WHERE 1=1
      <if test="startAmount != null">
         AND <![CDATA[ g.rateAmount >= #{startAmount} ]]>
      </if>
      <if test="endAmount != null">
         AND <![CDATA[ g.rateAmount < #{endAmount} ]]>
      </if>
      ORDER BY g.biz30day desc
      LIMIT #{start},#{count}
   </select>
   <select id="countQueryByRebateAmount" resultType="java.lang.Long">
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN
      (SELECT tb.`id`,(CASE WHEN <![CDATA[tb.`zkPrice` < tb.`couponStartFee`]]>
      THEN tb.`zkPrice` * tb.`tkRate`/10000*#{proportion}
      ELSE
      (tb.`zkPrice`-tb.`couponAmount`) * tb.`tkRate`/10000*#{proportion}
      END)AS RateAmount FROM yeshi_ec_taobao_goods tb
      where tb.tkRate >
      #{tkRate})g
      ON h.`sg_goods_id`= g.`id`
      WHERE 1=1
      <if test="startAmount != null">
         AND <![CDATA[ g.rateAmount >= #{startAmount} ]]>
      </if>
      <if test="endAmount != null">
         AND <![CDATA[ g.rateAmount < #{endAmount} ]]>
      </if>
   </select>
   <select id="getAuctionIdbyClassId" resultType="java.lang.Long">
      SELECT h.`sg_goods_id` FROM `yeshi_ec_quality_factory` h
      WHERE h.`sg_goods_source` = #{goodsSource}
      AND h.`sg_updatetime` <![CDATA[<]]>
      #{beforeTime}
      <if test="systemCid != null">AND h.`sg_class_id` = #{systemCid}</if>
   </select>
   <select id="listRecommendToIndex" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM `yeshi_ec_quality_factory` h
      LEFT JOIN
      (SELECT tb.`id`,tb.tkRate,
            <![CDATA[(CASE WHEN  tb.`zkPrice` < tb.`couponStartFee`  THEN tb.`zkPrice` * tb.`tkRate`/10000*#{proportion}
              ELSE (tb.`zkPrice`-tb.`couponAmount`) * tb.`tkRate`/10000*#{proportion} END)AS rateAmount
              FROM  yeshi_ec_taobao_goods tb
              WHERE tb.tkRate >=  #{tkRate}
                 AND tb.`couponAmount` >=  #{couponAmount}
                 AND (tb.`couponAmount`/ tb.zkPrice)*100 > #{couponRatio}
              ]]>
      )g
      ON h.`sg_goods_id`= g.`id`
      WHERE  <![CDATA[ g.rateAmount >= #{commision} ]]>
      ORDER BY h.sg_weight DESC
      LIMIT #{start},#{count}
   </select>
   <select id="countRecommendToIndex" resultType="java.lang.Long">
      SELECT IFNULL(COUNT( h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN
      (SELECT tb.`id`,tb.tkRate,
             <![CDATA[(CASE WHEN  tb.`zkPrice` < tb.`couponStartFee`  THEN tb.`zkPrice` * tb.`tkRate`/10000*${proportion}
              ELSE (tb.`zkPrice`-tb.`couponAmount`) * tb.`tkRate`/10000*${proportion} END)AS RateAmount
              FROM  yeshi_ec_taobao_goods tb
              WHERE tb.tkRate >=  #{tkRate}
                   AND tb.`couponAmount` >=  #{couponAmount}
                    AND (tb.`couponAmount`/ tb.zkPrice)*100 > #{couponRatio}
              ]]>
      )g
      ON h.`sg_goods_id`= g.`id`
      WHERE  <![CDATA[ g.rateAmount >= #{commision} ]]>
   </select>
   <select id="listRecommendBykey" resultMap="BaseResultMap">
      SELECT
      <include refid="Base_Column_List" />
      FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      h.`sg_goods_id`= tb.`id`
      WHERE 1=1
      <!-- 关键词搜索 -->
      <if test='key != null and key != ""'> AND tb.`title` LIKE '%${key}%' </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice}]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice}]]>
      </if>
      <!-- 返利比范围 -->
      <if test='startTkRate != null'>
         AND <![CDATA[  tb.`tkRate` >= #{startTkRate}]]>
      </if>
      <if test='endTkRate != null'>
         AND <![CDATA[  tb.`tkRate` <= #{endTkRate}]]>
      </if>
      <!-- 有券 -->
      <if test='hasQuan != null'>
         AND <![CDATA[  tb.`couponLeftCount` > 1]]>
      </if>
      <!-- 天猫商品 -->
      <if test='userType != null'>
         AND <![CDATA[  tb.`userType` = 1]]>
      </if>
      ORDER BY
      <!-- 销量高到低 -->
      <if test='sort == 1'>
         tb.`biz30day` desc,
      </if>
      <!-- 价格 低到高 -->
      <if test='sort == 3'>
         tb.`zkPrice`,
      </if>
      <!-- 价格 高到低 -->
      <if test='sort == 2'>
         tb.`zkPrice` desc,
      </if>
      <!-- 推广量 高到低 -->
      <if test='sort == 4'>
         tb.`totalSales` desc,
      </if>
      <!-- 佣金比例 -->
      <if test='sort == 5'>
         tb.`tkRate` desc,
      </if>
      <!-- 佣金比例 -->
      <if test='sort == 6'>
         tb.`tkRate`,
      </if>
      <!-- 默认:权重高到低 -->
      h.sg_weight DESC
      LIMIT #{start},#{count}
   </select>
   <select id="countRecommendBykey" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      1=1
      <!-- 关键词搜索 -->
      <if test='key != null and key != ""'> AND tb.`title` LIKE '%${key}%' </if>
      <!-- 在售价范围 -->
      <if test='startprice != null'>
         AND <![CDATA[  tb.`zkPrice` >= #{startprice}]]>
      </if>
      <if test='endprice != null'>
         AND <![CDATA[  tb.`zkPrice` <= #{endprice}]]>
      </if>
      <!-- 返利比范围 -->
      <if test='startTkRate != null'>
         AND <![CDATA[  tb.`tkRate` >= #{startTkRate}]]>
      </if>
      <if test='endTkRate != null'>
         AND <![CDATA[  tb.`tkRate` <= #{endTkRate}]]>
      </if>
      <!-- 有券 -->
      <if test='hasQuan != null'>
         AND <![CDATA[  tb.`couponLeftCount` > 1]]>
      </if>
      <!-- 天猫商品 -->
      <if test='userType != null'>
         AND <![CDATA[  tb.`userType` = 1]]>
      </if>
   </select>
   <select id="listQueryBylabIDs" resultMap="GoodsResultMap">
      SELECT * FROM (
      SELECT DISTINCT( tt.`sg_id`) AS tbid FROM
      yeshi_ec_quality_factory tt
      LEFT JOIN yeshi_ec_taobao_goods tb ON
      tt.`sg_goods_id`= tb.`id`
      LEFT JOIN yeshi_ec_label_goods lg ON
      tt.`sg_goods_id` = lg.`lg_goods_id`
      WHERE tb.`id` != #{gid}
      <if test='systemCid != null'>
         AND tt.`sg_class_id` = #{systemCid}
      </if>
      AND lg.`lg_label_id` IN
      <foreach collection="list" item="item" open="(" close=")"
         separator=",">#{item}</foreach>
      LIMIT ${start},${count}
      ) a LEFT JOIN yeshi_ec_quality_factory ts ON
      ts.`sg_id`=a.tbid
      LEFT JOIN yeshi_ec_taobao_goods tbb ON
      ts.`sg_goods_id`= tbb.`id`
   </select>
   <select id="listByMinSalesCountOrderByCreateTimeDesc" resultMap="BaseResultMap">
      SELECT f.* FROM `yeshi_ec_quality_factory` f LEFT JOIN
      yeshi_ec_taobao_goods t ON f.`sg_goods_id`=t.`id` WHERE
      t.`biz30day`>=#{salesCount} ORDER BY f.`sg_createtime` DESC limit
      #{start},#{count}
   </select>
   <select id="listByShopId" resultMap="GoodsResultMap">
      SELECT * FROM
      yeshi_ec_quality_factory q
      LEFT JOIN `yeshi_ec_taobao_goods` t ON
      q.`sg_goods_id` = t.`id`
      WHERE t.`sellerId` = #{shopId}
      ORDER BY
      q.`sg_weight` DESC
      LIMIT #{start},#{count}
   </select>
   <select id="countByShopId" resultType="java.lang.Long">
      SELECT
      ifnull(count(sg_id),0) FROM yeshi_ec_quality_factory q
      LEFT JOIN
      `yeshi_ec_taobao_goods` t ON q.`sg_goods_id` = t.`id`
      WHERE
      t.`sellerId` = #{shopId}
   </select>
   <select id="get9k9ClassGoods" resultMap="GoodsResultMap">
      SELECT * FROM `yeshi_ec_quality_factory` h
      LEFT JOIN
      yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      tb.`couponAmount` > 0 AND tb.`couponTotalCount` > 0
      AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
      AND tb.`zkPrice` <![CDATA[<=]]>
      #{zkPrice}
      AND tb.`biz30day` <![CDATA[>=]]>
      #{biz30day}
      <!-- 券后价范围 -->
      AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]>
      #{minQuanPrice}
      AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<= ]]>
      #{maxQuanPrice}
      <!-- 多个分类id -->
      <if test='cids != null and cids != ""'>
         AND h.`sg_class_id` in (${cids})
      </if>
      ORDER BY h.sg_weight desc,tb.`biz30day`desc
      LIMIT ${start},${count}
   </select>
   <select id="count9k9ClassGoods" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      tb.`couponAmount` > 0 AND tb.`couponTotalCount` > 0
      AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
      AND tb.`zkPrice` <![CDATA[<=]]>
      #{zkPrice}
      AND tb.`biz30day` <![CDATA[>=]]>
      #{biz30day}
      <!-- 券后价范围 -->
      AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]>
      #{minQuanPrice}
      AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<= ]]>
      #{maxQuanPrice}
      <!-- 多个分类id -->
      <if test='cids != null and cids != ""'>
         AND h.`sg_class_id` in (${cids})
      </if>
   </select>
   <!-- 每日必抢 -->
   <select id="listQueryEverydayRob" resultMap="GoodsResultMap">
      SELECT * FROM `yeshi_ec_quality_factory` h
      LEFT JOIN
      yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      tb.`couponTotalCount` > 0 AND tb.couponAmount <![CDATA[>]]>
      1 AND tb.couponAmount <![CDATA[<=]]>
      50
      AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
      AND tb.`zkPrice` <![CDATA[<=]]>
      #{zkPrice}
      AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]>
      #{minQuanPrice}
      AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<=]]>
      #{maxQuanPrice}
      ORDER BY h.sg_createtime desc
      LIMIT ${start},${count}
   </select>
   <select id="countQueryEverydayRob" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      tb.`couponTotalCount` > 0 AND tb.couponAmount <![CDATA[>]]>
      1 AND tb.couponAmount <![CDATA[<=]]>
      50
      AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
      AND tb.`zkPrice` <![CDATA[<=]]>
      #{zkPrice}
      AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]>
      #{minQuanPrice}
      AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<=]]>
      #{maxQuanPrice}
   </select>
   <select id="listFreeGoods" resultMap="GoodsResultMap">
       SELECT * FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE tb.`couponAmount` > 0 AND tb.`couponTotalCount` > 0
          AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
          <!-- 在售价  209.9 -->
          AND tb.`zkPrice` <![CDATA[<=]]> 209.9
          <!--  券后价范围  0~9.9 -->
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]> 0
          AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<= ]]> 9.9
          <!-- 比例  20 -->
          AND  tb.`tkRate` <![CDATA[>=]]> 20
      ORDER BY h.sg_weight desc
      LIMIT ${start},${count}
   </select>
   <select id="countFreeGoods" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(h.`sg_id`),0) FROM `yeshi_ec_quality_factory` h
      LEFT JOIN yeshi_ec_taobao_goods tb ON h.`sg_goods_id`= tb.`id`
      WHERE
      tb.`couponAmount` > 0 AND tb.`couponTotalCount` > 0
      AND IF(tb.`zkPrice` - tb.`couponStartFee`>=0, TRUE, FALSE)
      <!-- 在售价 209.9 -->
      AND tb.`zkPrice` <![CDATA[<=]]>
      209.9
      <!-- 券后价范围 0~9.9 -->
      AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[>]]>
      0
      AND (tb.`zkPrice` - tb.`couponAmount`) <![CDATA[<= ]]>
      9.9
      <!-- 比例 20 -->
      AND tb.`tkRate` <![CDATA[>=]]>
      20
   </select>
</mapper>