yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
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
<?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
        <include refid="Base_Column_List" />
        from yeshi_ec_collection_goods_v2 where cg_uid = #{uid} order by
        cg_createtime desc limit #{start},#{count}
    </select>
 
 
    <!-- 获取收藏的数量 -->
    <select id="selectCountByUid" resultType="java.lang.Long"
        parameterType="java.lang.Long">
        select
        count(cg_id)
        from yeshi_ec_collection_goods_v2
        where cg_uid = #{uid}
    </select>
 
 
    <select id="selectByUidAndGoodsTypeAndGoodsId" 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} and g.cg_goods_type=#{goodsType}
        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>