admin
2020-05-19 744594ef1a2f530fc3e86ea9dc48b62247f79420
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?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.share.UserShareGoodsGroupMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup">
    <id column="gu_id" property="id" jdbcType="BIGINT"/>
    <result column="gu_record_id" property="recordId" jdbcType="BIGINT"/>
    <result column="gu_today_browse" property="todayBrowse" jdbcType="INTEGER"/>
    <result column="gu_total_browse" property="totalBrowse" jdbcType="INTEGER"/>
    <result column="gu_total_order" property="totalOrder" jdbcType="INTEGER"/>
    <result column="gu_total_money" property="totalMoney" jdbcType="DECIMAL"/>
    <result column="gu_browse_time" property="browseTime" jdbcType="TIMESTAMP"/>
    <result column="gu_createtime" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="gu_updatetime" property="updateTime" jdbcType="TIMESTAMP"/>
          <!-- 记录组中的总商品数量 -->
    <result column="totalGoods" property="totalGoods" jdbcType="INTEGER"/>
    
    <association property="commonGoods" column="gu_common_goods_id"
        resultMap="com.yeshi.fanli.dao.mybatis.goods.CommonGoodsMapper.BaseResultMap" />
        
  </resultMap>
  <sql id="Base_Column_List">gu_id,gu_record_id,gu_common_goods_id,gu_today_browse,gu_total_browse,gu_total_order,gu_total_money,gu_browse_time,gu_createtime,gu_updatetime</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_share_goods_group where gu_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_share_goods_group where gu_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_share_goods_group (gu_id,gu_record_id,gu_common_goods_id,gu_today_browse,gu_total_browse,gu_total_order,gu_total_money,gu_browse_time,gu_createtime,gu_updatetime) values (#{id,jdbcType=BIGINT},#{recordId,jdbcType=BIGINT},#{commonGoods.id,jdbcType=BIGINT},#{todayBrowse,jdbcType=INTEGER},#{totalBrowse,jdbcType=INTEGER},#{totalOrder,jdbcType=INTEGER},#{totalMoney,jdbcType=DECIMAL},#{browseTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_share_goods_group
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">gu_id,</if>
      <if test="recordId != null">gu_record_id,</if>
      <if test="commonGoods != null">gu_common_goods_id,</if>
      <if test="todayBrowse != null">gu_today_browse,</if>
      <if test="totalBrowse != null">gu_total_browse,</if>
      <if test="totalOrder != null">gu_total_order,</if>
      <if test="totalMoney != null">gu_total_money,</if>
      <if test="browseTime != null">gu_browse_time,</if>
      <if test="createTime != null">gu_createtime,</if>
      <if test="updateTime != null">gu_updatetime,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="recordId != null">#{recordId,jdbcType=BIGINT},</if>
      <if test="commonGoods != null">#{commonGoods.id,jdbcType=BIGINT},</if>
      <if test="todayBrowse != null">#{todayBrowse,jdbcType=INTEGER},</if>
      <if test="totalBrowse != null">#{totalBrowse,jdbcType=INTEGER},</if>
      <if test="totalOrder != null">#{totalOrder,jdbcType=INTEGER},</if>
      <if test="totalMoney != null">#{totalMoney,jdbcType=DECIMAL},</if>
      <if test="browseTime != null">#{browseTime,jdbcType=TIMESTAMP},</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.bus.share.UserShareGoodsGroup">update yeshi_ec_share_goods_group set gu_record_id = #{recordId,jdbcType=BIGINT},gu_common_goods_id = #{commonGoods.id,jdbcType=BIGINT},gu_today_browse = #{todayBrowse,jdbcType=INTEGER},gu_total_browse = #{totalBrowse,jdbcType=INTEGER},gu_total_order = #{totalOrder,jdbcType=INTEGER},gu_total_money = #{totalMoney,jdbcType=DECIMAL},gu_browse_time = #{browseTime,jdbcType=TIMESTAMP},gu_createtime = #{createTime,jdbcType=TIMESTAMP},gu_updatetime = #{updateTime,jdbcType=TIMESTAMP} where gu_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup">update yeshi_ec_share_goods_group
    <set>
      <if test="recordId != null">gu_record_id=#{recordId,jdbcType=BIGINT},</if>
      <if test="commonGoods != null">gu_common_goods_id=#{commonGoods.id,jdbcType=BIGINT},</if>
      <if test="todayBrowse != null">gu_today_browse=#{todayBrowse,jdbcType=INTEGER},</if>
      <if test="totalBrowse != null">gu_total_browse=#{totalBrowse,jdbcType=INTEGER},</if>
      <if test="totalOrder != null">gu_total_order=#{totalOrder,jdbcType=INTEGER},</if>
      <if test="totalMoney != null">gu_total_money=#{totalMoney,jdbcType=DECIMAL},</if>
      <if test="browseTime != null">gu_browse_time=#{browseTime,jdbcType=TIMESTAMP},</if>
      <if test="createTime != null">gu_createtime=#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">gu_updatetime=#{updateTime,jdbcType=TIMESTAMP},</if>
    </set> where gu_id = #{id,jdbcType=BIGINT}
  </update>
  
    
   <insert id="insertBatch"  useGeneratedKeys="true" keyProperty="id"  parameterType="java.util.List">
          insert into yeshi_ec_share_goods_group
         (<include refid="Base_Column_List" />)
        values
          
          <foreach collection="list" item="item" separator=",">
          (
             #{item.id,jdbcType=BIGINT},
             #{item.recordId,jdbcType=BIGINT},
             #{item.commonGoods.id,jdbcType=BIGINT},
             #{item.todayBrowse,jdbcType=INTEGER},
             #{item.totalBrowse,jdbcType=INTEGER},
             #{item.totalOrder,jdbcType=INTEGER},
             #{item.totalMoney,jdbcType=DECIMAL},
             #{item.browseTime,jdbcType=TIMESTAMP},
             #{item.createTime,jdbcType=TIMESTAMP},
             #{item.updateTime,jdbcType=TIMESTAMP}
         )
          </foreach>
  </insert>
  
  
  <update id="updateBatchSelective" parameterType="java.util.List">
        update yeshi_ec_share_goods_group 
        <trim prefix="set" suffixOverrides=",">
             <trim prefix="gu_today_browse =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                        <if test="item.todayBrowse !=null">
                     when gu_id=#{item.id} then #{item.todayBrowse}
                     </if>
                </foreach>
            </trim>
            <trim prefix="gu_total_browse =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                        <if test="item.totalBrowse !=null">
                     when gu_id=#{item.id} then #{item.totalBrowse}
                     </if>
                </foreach>
            </trim>
             <trim prefix="gu_total_order =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                        <if test="item.totalOrder !=null">
                     when gu_id=#{item.id} then #{item.totalOrder}
                     </if>
                </foreach>
            </trim>
             <trim prefix="gu_total_money =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                        <if test="item.totalMoney !=null">
                     when gu_id=#{item.id} then #{item.totalMoney}
                     </if>
                </foreach>
            </trim>
            <trim prefix="gu_browse_time =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                        <if test="item.browseTime !=null">
                     when gu_id=#{item.id} then #{item.browseTime}
                     </if>
                </foreach>
            </trim>
        </trim>
        where gu_id in
        <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
            #{item.id,jdbcType=BIGINT}
        </foreach>
     </update>
  
  
   <select id="listByRecordId" resultMap="BaseResultMap">
     SELECT * FROM yeshi_ec_share_goods_group  tg
     LEFT JOIN  `yeshi_ec_common_goods` cg ON tg.`gu_common_goods_id` = cg.`cg_id`
     WHERE tg.`gu_record_id` = #{recordId}
     ORDER BY tg.`gu_createtime`
   </select>
    
  <select id="getSingleGoods" resultMap="BaseResultMap">
    SELECT * FROM yeshi_ec_share_goods_group g  
    LEFT JOIN `yeshi_ec_share_goods_record` r ON g.`gu_record_id` = r.`sgr_id`
    WHERE  r.sgr_share_state = 1 AND  r.`sgr_source` = #{source}
           AND  g.`gu_common_goods_id` = #{cid} AND r.`sgr_uid` = #{uid}
    ORDER BY g.gu_updatetime desc LIMIT 1
   </select>
   
   <select id="getNewestRecord" resultMap="BaseResultMap">
    SELECT tg.* FROM yeshi_ec_share_goods_group tg 
    RIGHT JOIN `yeshi_ec_share_goods_record` r ON tg.`gu_record_id` = r.`sgr_id`
    LEFT JOIN  `yeshi_ec_common_goods` cg ON tg.`gu_common_goods_id` = cg.`cg_id`
    WHERE r.`sgr_uid` = #{uid} AND cg.`cg_goods_id` = #{goodsId}  AND r.sgr_share_state = 1 
        AND cg.`cg_goods_type` = #{goodsType}
    ORDER BY tg.gu_updatetime desc LIMIT 1
   </select>
   
</mapper>