yujian
2020-06-08 b3da9f82b7740d39742fef1a81a56c22fe1c8b9c
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
<?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.user.cloud.UserCloudGoodsMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.cloud.UserCloudGoods">
    <id column="ug_id" property="id" jdbcType="BIGINT"/>
    <result column="ug_uid" property="uid" jdbcType="BIGINT"/>
    <result column="ug_state" property="state" jdbcType="INTEGER"/>
    <result column="ug_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="ug_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    <association property="commonGoods" column="ug_common_id" javaType="com.yeshi.fanli.entity.goods.CommonGoods"
        select="com.yeshi.fanli.dao.mybatis.goods.CommonGoodsMapper.selectByPrimaryKey" />
  </resultMap>
  <sql id="Base_Column_List">ug_id,ug_uid,ug_common_id,ug_state,ug_create_time,ug_update_time</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_user_cloud_goods where ug_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_user_cloud_goods where ug_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.cloud.UserCloudGoods" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_cloud_goods (ug_id,ug_uid,ug_common_id,ug_state,ug_create_time,ug_update_time) values (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{commonGoods.id,jdbcType=BIGINT},#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.cloud.UserCloudGoods" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_cloud_goods
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">ug_id,</if>
      <if test="uid != null">ug_uid,</if>
      <if test="commonGoods != null">ug_common_id,</if>
      <if test="state != null">ug_state,</if>
      <if test="createTime != null">ug_create_time,</if>
      <if test="updateTime != null">ug_update_time,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
      <if test="commonGoods != null">#{commonGoods.id,jdbcType=BIGINT},</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.bus.user.cloud.UserCloudGoods">update yeshi_ec_user_cloud_goods set ug_uid = #{uid,jdbcType=BIGINT},ug_common_id = #{commonGoods.id,jdbcType=BIGINT},ug_state = #{state,jdbcType=INTEGER},ug_create_time = #{createTime,jdbcType=TIMESTAMP},ug_update_time = #{updateTime,jdbcType=TIMESTAMP} where ug_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.cloud.UserCloudGoods">update yeshi_ec_user_cloud_goods
    <set>
      <if test="uid != null">ug_uid=#{uid,jdbcType=BIGINT},</if>
      <if test="commonGoods != null">ug_common_id=#{commonGoods.id,jdbcType=BIGINT},</if>
      <if test="state != null">ug_state=#{state,jdbcType=INTEGER},</if>
      <if test="createTime != null">ug_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">ug_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
    </set> where ug_id = #{id,jdbcType=BIGINT}
  </update>
  
   <delete id="deleteByPrimaryKeyAndUid">
           delete from yeshi_ec_user_cloud_goods where ug_id = #{id} AND ug_uid = #{uid}
   </delete>
  
  
   <select id="query" resultMap="BaseResultMap">
     SELECT * FROM yeshi_ec_user_cloud_goods  tg
     LEFT JOIN  `yeshi_ec_common_goods` cg ON tg.`ug_common_id` = cg.`cg_id`
     WHERE 1=1
         <if test="key != null and key != ''">AND tg.`ug_uid` = #{key}</if>
     ORDER BY tg.ug_id  DESC
     LIMIT #{start},#{count}
   </select>
   
   <select id="count" resultType="java.lang.Long">
     SELECT IFNULL(count(ug_id),0) FROM yeshi_ec_user_cloud_goods  tg
     WHERE 1=1
         <if test="key != null and key != ''"> AND tg.`ug_uid` = #{key}</if>
   </select>
   
  
   <select id="listByUid" resultMap="BaseResultMap">
     SELECT * FROM yeshi_ec_user_cloud_goods  tg
     LEFT JOIN  `yeshi_ec_common_goods` cg ON tg.`ug_common_id` = cg.`cg_id`
     WHERE tg.`ug_uid` = #{uid}
     ORDER BY  cg.cg_state, tg.ug_state, tg.`ug_update_time` DESC
     LIMIT #{start},#{count}
   </select>
   
   <select id="countByUid" resultType="java.lang.Long">
     SELECT IFNULL(count(ug_id),0) FROM yeshi_ec_user_cloud_goods  tg
     WHERE tg.`ug_uid` = #{uid}
   </select>
   
   <select id="getByUidAndGoods" resultMap="BaseResultMap">
        SELECT *  FROM `yeshi_ec_user_cloud_goods` g 
        LEFT JOIN  `yeshi_ec_common_goods` c ON g.`ug_common_id` = c.`cg_id`
        WHERE g.`ug_uid` = #{uid} AND c.`cg_goods_id`= #{goodsId}  AND c.cg_goods_type = #{goodsType}
        LIMIT 1
   </select>
    
    <select id="getByUidAndCommonGoodsId" resultMap="BaseResultMap">
        SELECT *  FROM `yeshi_ec_user_cloud_goods` g 
        WHERE g.`ug_uid` = #{uid} AND  g.ug_common_id = #{commonId}
        LIMIT 1
   </select>
   
   
    <select id="listByNotShare" resultMap="BaseResultMap">
        SELECT *  FROM `yeshi_ec_user_cloud_goods` g 
        WHERE g.`ug_uid` = #{uid} AND  g.ug_state = 0
   </select>
</mapper>