yujian
2019-07-11 e4a56b57d3e10b9b46eaefe5194bbf98fcc45698
fanli/src/main/java/com/yeshi/fanli/mapping/goods/ScanHistoryV2Mapper.xml
@@ -29,29 +29,37 @@
   <!-- 根据UID或者设备号获取浏览记录 -->
   <select id="selectByDeviceOrUid" resultMap="BaseResultMap">
      select * from (SELECT s.* FROM yeshi_ec_scanhistory_v2 s
      WHERE
      <trim prefix="(" suffix=")" suffixOverrides="or">
         <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
         <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
      </trim>
      GROUP BY s.`s_common_goods_id`
      ) s
      order by s.s_createtime DESC
      limit
      #{start},#{count}
      SELECT * FROM (
            SELECT SUBSTRING_INDEX(GROUP_CONCAT(s.s_id ORDER BY s.s_createtime DESC), ',', 1)AS hid
            FROM yeshi_ec_scanhistory_v2 s
         <if test="source != null">
            LEFT JOIN `yeshi_ec_common_goods` g ON s.`s_common_goods_id` = g.`cg_id`
         </if>
            WHERE
               <trim prefix="(" suffix=")" suffixOverrides="or">
                  <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
                  <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
               </trim>
               <if test="source != null">AND g.`cg_goods_type` = #{source}</if>
             GROUP BY s.s_common_goods_id
            )A
      LEFT JOIN yeshi_ec_scanhistory_v2 B ON B.s_id = A.hid
      ORDER BY B.s_createtime DESC
      LIMIT #{start},#{count}
   </select>
   <!-- 根据UID或者设备号获取浏览记录条数 -->
   <select id="selectCountByDeviceOrUid" resultType="java.lang.Long">
      SELECT count(s.`s_id`) FROM yeshi_ec_scanhistory_v2 s
      SELECT IFNULL(COUNT(DISTINCT s.`s_common_goods_id`),0) FROM yeshi_ec_scanhistory_v2 s
      <if test="source != null">
      LEFT JOIN `yeshi_ec_common_goods` g ON s.`s_common_goods_id` = g.`cg_id`
      </if>
      WHERE
      <trim prefix="(" suffix=")" suffixOverrides="or">
         <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
         <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
      </trim>
      <if test="source != null">AND g.`cg_goods_type` = #{source}</if>
   </select>
@@ -62,19 +70,18 @@
   <!-- 根据设备或用户ID删除 -->
   <delete id="deleteByDeviceOrUid">
      delete from
      yeshi_ec_scanhistory_v2 where
   <select id="listDeviceOrUid" resultMap="BaseResultMap">
      SELECT s.* FROM yeshi_ec_scanhistory_v2 s
      WHERE
      <trim prefix="(" suffix=")" suffixOverrides="or">
         <if test="uid != null"> `s_uid`=#{uid,jdbcType=BIGINT} or</if>
         <if test="device != null">`s_device`=#{device,jdbcType=VARCHAR} or</if>
         <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
         <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
      </trim>
   </delete>
   </select>
   <!-- 根据设备或用户ID与商品信息检索 -->
   <select id="selectByDeviceOrUidAndGoodsIdAndGoodsType"
      resultMap="BaseResultMap">
   <select id="selectByDeviceOrUidAndGoodsIdAndGoodsType"   resultMap="BaseResultMap">
      SELECT s.* FROM yeshi_ec_scanhistory_v2 s left join
      yeshi_ec_common_goods g on g.cg_id=s.s_common_goods_id
      WHERE
@@ -82,7 +89,18 @@
         <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
         <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
      </trim>
      and g.cg_goods_id=#{goodsId} and g.cg_goods_type=#{goodsType}
      and g.cg_goods_id=#{goodsId}
   </select>
      <!-- 根据设备或用户ID与商品信息检索 -->
   <select id="getByCommonGoodsId"   resultMap="BaseResultMap">
      SELECT s.* FROM yeshi_ec_scanhistory_v2 s
      WHERE
      <trim prefix="(" suffix=")" suffixOverrides="or">
         <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
         <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
      </trim>
      and s.s_common_goods_id =#{commonId}
   </select>