admin
2020-04-13 dd5b15229cb15459fa7c31ccea77dac28cbfafbd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?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.brand.TaoBaoShopHistoryMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.brand.TaoBaoShopHistory">
    <id column="tsh_id" property="id" jdbcType="BIGINT"/>
    <result column="tsh_uid" property="uid" jdbcType="BIGINT"/>
    <result column="tsh_device" property="device" jdbcType="VARCHAR"/>
    <result column="tsh_state" property="state" jdbcType="INTEGER"/>
    <result column="tsh_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="tsh_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    <association column="tsh_shop_id" property="taoBaoShop" 
        resultMap="com.yeshi.fanli.dao.mybatis.taobao.TaoBaoShopMapper.BaseResultMap">
    </association>
  </resultMap>
  <sql id="Base_Column_List">tsh_id,tsh_shop_id,tsh_uid,tsh_device,tsh_state,tsh_create_time,tsh_update_time</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_taobao_shop_history where tsh_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_taobao_shop_history where tsh_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.brand.TaoBaoShopHistory" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_taobao_shop_history (tsh_id,tsh_shop_id,tsh_uid,tsh_device,tsh_state,tsh_create_time,tsh_update_time) values (#{id,jdbcType=BIGINT},#{taoBaoShop.id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{device,jdbcType=VARCHAR},#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.brand.TaoBaoShopHistory" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_taobao_shop_history
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">tsh_id,</if>
      <if test="taoBaoShop != null">tsh_shop_id,</if>
      <if test="uid != null">tsh_uid,</if>
      <if test="device != null">tsh_device,</if>
      <if test="state != null">tsh_state,</if>
      <if test="createTime != null">tsh_create_time,</if>
      <if test="updateTime != null">tsh_update_time,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="taoBaoShop != null">#{taoBaoShop.id,jdbcType=BIGINT},</if>
      <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
      <if test="device != null">#{device,jdbcType=VARCHAR},</if>
      <if test="state != null">#{state,jdbcType=INTEGER},</if>
      <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.brand.TaoBaoShopHistory">update yeshi_ec_taobao_shop_history set tsh_shop_id = #{taoBaoShop.id,jdbcType=BIGINT},tsh_uid = #{uid,jdbcType=BIGINT},tsh_device = #{device,jdbcType=VARCHAR},tsh_state = #{state,jdbcType=INTEGER},tsh_create_time = #{createTime,jdbcType=TIMESTAMP},tsh_update_time = #{updateTime,jdbcType=TIMESTAMP} where tsh_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.brand.TaoBaoShopHistory">update yeshi_ec_taobao_shop_history
    <set>
      <if test="taoBaoShop != null">tsh_shop_id=#{taoBaoShop.id,jdbcType=BIGINT},</if>
      <if test="uid != null">tsh_uid=#{uid,jdbcType=BIGINT},</if>
      <if test="device != null">tsh_device=#{device,jdbcType=VARCHAR},</if>
      <if test="state != null">tsh_state=#{state,jdbcType=VARCHAR},</if>
      <if test="createTime != null">tsh_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">tsh_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
    </set> where tsh_id = #{id,jdbcType=BIGINT}
  </update>
  
  <update id="updateByUid">
        update yeshi_ec_taobao_shop_history set tsh_state = 1
        where  tsh_uid = #{uid} AND tsh_shop_id = #{shopId}
  </update>
    
  <update id="updateByDevice">
        update yeshi_ec_taobao_shop_history set tsh_state = 1
        where  tsh_device = #{device} AND tsh_shop_id = #{shopId}
  </update>
  
  
  <select id="getByUid" resultMap="BaseResultMap">
      SELECT * FROM yeshi_ec_taobao_shop_history h 
    WHERE h.tsh_uid = #{uid} AND h.tsh_shop_id = #{shopId}
    ORDER BY  h.tsh_update_time DESC
    LIMIT 1
  </select>
  
  <select id="getByDevice" resultMap="BaseResultMap">
      SELECT * FROM yeshi_ec_taobao_shop_history h 
    WHERE  h.tsh_device = #{device} AND h.tsh_shop_id = #{shopId}
    ORDER BY  h.tsh_update_time DESC
    LIMIT 1
  </select>
  
  <select id="listByUid" resultMap="BaseResultMap">
    SELECT * FROM (SELECT `tsh_id` FROM yeshi_ec_taobao_shop_history
        WHERE tsh_uid = #{uid} AND tsh_state = 0
        GROUP BY `tsh_shop_id`) A 
    LEFT JOIN yeshi_ec_taobao_shop_history h on  A.tsh_id = h.tsh_id
    LEFT JOIN `yeshi_ec_taobao_shop_info` p ON h.`tsh_shop_id` = p.`tsi_id`
    ORDER BY  h.tsh_update_time DESC
    LIMIT ${start},${count}
  </select>
  
  <select id="countByUid" resultType="Long">
      SELECT IFNULL(COUNT(DISTINCT tsh_shop_id),0) FROM yeshi_ec_taobao_shop_history 
    WHERE tsh_uid = #{uid} AND tsh_state = 0
  </select>
  
   <select id="listByDevice" resultMap="BaseResultMap">
      SELECT * FROM (SELECT `tsh_id` FROM yeshi_ec_taobao_shop_history
        WHERE tsh_device = #{device} AND tsh_state = 0
        GROUP BY `tsh_shop_id`) A 
    LEFT JOIN yeshi_ec_taobao_shop_history h on  A.tsh_id = h.tsh_id
      LEFT JOIN `yeshi_ec_taobao_shop_info` p ON h.`tsh_shop_id` = p.`tsi_id`
    ORDER BY h.tsh_update_time DESC
    LIMIT ${start},${count}
  </select>
  
   <select id="countByDevice" resultType="Long">
      SELECT IFNULL(COUNT(DISTINCT tsh_shop_id),0) FROM yeshi_ec_taobao_shop_history 
    WHERE tsh_device = #{device} AND tsh_state = 0
  </select>
  
  <select id="countByShopId" resultType="Long">
      SELECT IFNULL(COUNT(tsh_id),0) FROM `yeshi_ec_taobao_shop_history`
    WHERE tsh_shop_id = #{shopId} 
  </select>
  
</mapper>