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
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
<?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.goods.CollectionGoodsV2Mapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.goods.CollectionGoodsV2">
        <id column="cg_id" property="id" jdbcType="BIGINT" />
        <result column="cg_createtime" property="createTime" jdbcType="TIMESTAMP" />
        <result column="cg_updatetime" property="updateTime" jdbcType="TIMESTAMP" />
        <association property="userInfo" column="cg_uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="cg_uid" property="id" jdbcType="BIGINT" />
        </association>
 
        <association property="commonGoods" column="cg_common_goods_id"
            select="com.yeshi.fanli.dao.mybatis.goods.CommonGoodsMapper.selectByPrimaryKey">
        </association>
 
    </resultMap>
    <sql id="Base_Column_List">cg_id,cg_uid,cg_common_goods_id,cg_createtime,cg_updatetime
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_collection_goods_v2 where cg_id = #{id,jdbcType=BIGINT}
    </select>
 
 
 
    <!-- 根据用户ID和商品ID获取收藏记录 -->
    <select id="selectByUidAndCommonGoodsId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_collection_goods_v2 where cg_uid = #{uid} and
        cg_common_goods_id=#{commonGoodsId} limit 1
    </select>
 
 
    <!-- 根据用户ID获取收藏记录,按照收藏时间倒叙 -->
    <select id="selectByUidOrderByCreateTimeDesc" resultMap="BaseResultMap">
        select t.* from yeshi_ec_collection_goods_v2 t
        <if test="source != null">
            LEFT JOIN `yeshi_ec_common_goods` g ON t.`cg_common_goods_id` = g.`cg_id`
        </if>
        where t.cg_uid = #{uid} <if test="source != null">AND g.`cg_goods_type` = #{source}</if>
        order by t.cg_createtime desc
        limit #{start},#{count}
    </select>
 
 
    <!-- 获取收藏的数量 -->
    <select id="selectCountByUid" resultType="java.lang.Long"     parameterType="java.lang.Long">
        select     count(t.cg_id) from yeshi_ec_collection_goods_v2 t
        <if test="source != null">
                LEFT JOIN `yeshi_ec_common_goods` g ON t.`cg_common_goods_id` = g.`cg_id`
        </if>
        where t.cg_uid = #{uid} <if test="source != null">AND g.`cg_goods_type` = #{source}</if>
    </select>
 
 
    <select id="selectByUidAndGoodsId" resultMap="BaseResultMap">
        select
        v2.*
        from yeshi_ec_collection_goods_v2 v2 left join
        yeshi_ec_common_goods g
        on g.cg_id=v2.cg_common_goods_id
        where v2.cg_uid
        = #{uid} and
        g.cg_goods_id=#{goodsId} 
        limit 1
    </select>
 
    
    <select id="selectByUidAndGoodsType" resultMap="BaseResultMap">
        select     v2.* from yeshi_ec_collection_goods_v2 v2 
        left join yeshi_ec_common_goods g on g.cg_id=v2.cg_common_goods_id
        where v2.cg_uid    = #{uid} and g.cg_goods_id=#{goodsId}  
            <if test="goodsType != null">AND g.`cg_goods_type` = #{goodsType}</if>
        limit 1
    </select>
    
 
    <select id="getByUidAndCommonId" resultMap="BaseResultMap">
        select v2.* from yeshi_ec_collection_goods_v2 v2 
        where v2.cg_uid    = #{uid} and v2.cg_common_goods_id = #{commonId} 
        limit 1
    </select>
 
 
    <!-- 根据UID删除收藏 -->
    <delete id="deleteByUid" parameterType="java.lang.Long">delete from
        yeshi_ec_collection_goods_v2 where cg_uid = #{uid}
    </delete>
 
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_collection_goods_v2 where cg_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.goods.CollectionGoodsV2"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_collection_goods_v2
        (cg_id,cg_uid,cg_common_goods_id,cg_createtime,cg_updatetime) values
        (#{id,jdbcType=BIGINT},#{userInfo.id,jdbcType=BIGINT},#{commonGoods.id,jdbcType=BIGINT},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.goods.CollectionGoodsV2"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_collection_goods_v2
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">cg_id,</if>
            <if test="userInfo != null">cg_uid,</if>
            <if test="commonGoods != null">cg_common_goods_id,</if>
            <if test="createTime != null">cg_createtime,</if>
            <if test="updateTime != null">cg_updatetime,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="userInfo != null">#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="commonGoods != null">#{commonGoods.id,jdbcType=BIGINT},</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.goods.CollectionGoodsV2">update
        yeshi_ec_collection_goods_v2 set cg_uid =
        #{userInfo.id,jdbcType=BIGINT},cg_common_goods_id =
        #{commonGoods.id,jdbcType=BIGINT},cg_createtime =
        #{createTime,jdbcType=TIMESTAMP},cg_updatetime =
        #{updateTime,jdbcType=TIMESTAMP} where cg_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.goods.CollectionGoodsV2">
        update yeshi_ec_collection_goods_v2
        <set>
            <if test="userInfo != null">cg_uid=#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="commonGoods != null">cg_common_goods_id=#{commonGoods.id,jdbcType=BIGINT},
            </if>
            <if test="createTime != null">cg_createtime=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">cg_updatetime=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where cg_id = #{id,jdbcType=BIGINT}
    </update>
</mapper>