admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?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.lable.LabelGoodsMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.lable.LabelGoods">
    <id column="lg_id" property="id" jdbcType="BIGINT"/>
    <result column="lg_weight"  property="weight"   jdbcType="DOUBLE"/>
    <result column="lg_createtime" property="createtime" jdbcType="TIMESTAMP"/>
    <result column="lg_updatetime" property="updatetime" jdbcType="TIMESTAMP"/>
    
    <association property="taoBaoGoodsBrief" column="sg_goods_id" 
         select="com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper.selectByPrimaryKey"> 
    </association>
    
    <association property="label" column="lg_label_id" 
         select="com.yeshi.fanli.dao.mybatis.lable.LabelMapper.selectByPrimaryKey"> 
    </association>
    
     <association property="createUser" column="lg_create_aid" javaType="com.yeshi.fanli.entity.common.AdminUser">
        <id column="lg_create_aid"  property="id" jdbcType="BIGINT" />
    </association>
  </resultMap>
  
   <resultMap id="ResultMap" type="com.yeshi.fanli.entity.bus.lable.LabelGoods">
    <id column="lg_id" property="id" jdbcType="BIGINT"/>
    <result column="lg_weight"  property="weight"   jdbcType="DOUBLE"/>
    <result column="lg_createtime" property="createtime" jdbcType="TIMESTAMP"/>
    <result column="lg_updatetime" property="updatetime" jdbcType="TIMESTAMP"/>
    
     <association property="label" column="lg_label_id" javaType="com.yeshi.fanli.entity.bus.lable.Label">
        <id column="lg_label_id"  property="id" jdbcType="BIGINT" />
    </association>
    
  </resultMap>
  
  
  <sql id="Base_Column_List">lg_id,lg_label_id,lg_goods_id,lg_create_aid,lg_weight,lg_createtime,lg_updatetime</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_label_goods where lg_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_label_goods where lg_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.lable.LabelGoods" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_label_goods (lg_id,lg_label_id,lg_goods_id,lg_create_aid,lg_weight,lg_createtime,lg_updatetime) values (#{id,jdbcType=BIGINT},#{label.id,jdbcType=BIGINT},#{taoBaoGoodsBrief.id,jdbcType=BIGINT},#{createUser.id,jdbcType=BIGINT},#{weight,jdbcType=DOUBLE},#{createtime,jdbcType=TIMESTAMP},#{updatetime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.lable.LabelGoods" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_label_goods
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">lg_id,</if>
      <if test="label != null">lg_label_id,</if>
      <if test="taoBaoGoodsBrief != null">lg_goods_id,</if>
      <if test="createUser != null">lg_create_aid,</if>
      <if test="weight != null">lg_weight,</if>
      <if test="createtime != null">lg_createtime,</if>
      <if test="updatetime != null">lg_updatetime,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="label != null">#{label.id,jdbcType=BIGINT},</if>
      <if test="taoBaoGoodsBrief != null">#{taoBaoGoodsBrief.id,jdbcType=BIGINT},</if>
      <if test="createUser != null">#{createUser.id,jdbcType=BIGINT},</if>
      <if test="weight != null">#{weight,jdbcType=DOUBLE},</if>
      <if test="createtime != null">#{createtime,jdbcType=TIMESTAMP},</if>
      <if test="updatetime != null">#{updatetime,jdbcType=TIMESTAMP},</if>
    </trim>
  </insert>
  
    <insert id="insertBatch" parameterType="java.util.List">
          INSERT IGNORE yeshi_ec_label_goods
         (<include refid="Base_Column_List" />)
        values
          
          <foreach collection="list" item="item" separator=",">
              (
                 #{item.id,jdbcType=BIGINT},
                 #{item.label.id,jdbcType=BIGINT},
                 #{item.taoBaoGoodsBrief.id,jdbcType=BIGINT},
                 #{item.createUser.id,jdbcType=BIGINT},
                 #{item.weight,jdbcType=DOUBLE},
                 #{item.createtime,jdbcType=TIMESTAMP},
                 #{item.updatetime,jdbcType=TIMESTAMP}
             )
           
          </foreach>
  </insert>
  
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.lable.LabelGoods">update yeshi_ec_label_goods set lg_label_id = #{label.id,jdbcType=BIGINT},lg_goods_id = #{taoBaoGoodsBrief.id,jdbcType=BIGINT},lg_create_aid = #{createUser.id,jdbcType=BIGINT},lg_weight = #{weight,jdbcType=DOUBLE},lg_createtime = #{createtime,jdbcType=TIMESTAMP},lg_updatetime = #{updatetime,jdbcType=TIMESTAMP} where lg_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.lable.LabelGoods">update yeshi_ec_label_goods
    <set>
      <if test="label != null">lg_label_id=#{label.id,jdbcType=BIGINT},</if>
      <if test="taoBaoGoodsBrief != null">lg_goods_id=#{taoBaoGoodsBrief.id,jdbcType=BIGINT},</if>
      <if test="createUser != null">lg_create_aid=#{createUser.id,jdbcType=BIGINT},</if>
      <if test="weight != null">lg_weight=#{weight,jdbcType=DOUBLE},</if>
      <if test="createtime != null">lg_createtime=#{createtime,jdbcType=TIMESTAMP},</if>
      <if test="updatetime != null">lg_updatetime=#{updatetime,jdbcType=TIMESTAMP},</if>
    </set> where lg_id = #{id,jdbcType=BIGINT}
  </update>
  
       <delete id="deleteBatchByPrimaryKey" parameterType="int">
        <!-- 批量删除信息 -->
        delete from yeshi_ec_label_goods where lg_id in
        <foreach item="ids" collection="array" open="(" separator=","
            close=")">#{ids}</foreach>
    </delete>
    
    <delete id="deleteBatchByPK"  parameterType="java.util.List">
        delete FROM yeshi_ec_label_goods WHERE lg_id in
        <foreach collection="list" item="item" open="(" close=")"
            separator=",">#{item}</foreach>
    </delete>
      
      
      <delete id="deleteByAuctionIdAndLabIDs">
        delete FROM yeshi_ec_label_goods 
        WHERE lg_goods_id = #{auctionId} AND lg_label_id in
            <foreach collection="list" item="item" open="(" close=")"
                separator=",">#{item}</foreach>
    </delete>
    
      
      
  
    <select id="isExistence" resultType="java.lang.Long">
      <!-- 判断是否已贴过标签 -->
          SELECT ifnull(COUNT(g.`lg_id`),0) FROM `yeshi_ec_label_goods` g 
          WHERE g.`lg_goods_id` = #{goodsId} 
                 AND g.`lg_label_id`= #{labelId}
    </select>
    
    <select id="getCountByGoodsId" resultType="java.lang.Long">
      <!--统计商品的标签个数 -->
          SELECT COUNT(g.`lg_id`) FROM `yeshi_ec_label_goods` g WHERE g.`lg_goods_id` = ${goodsId}
    </select>
    
     <delete id="deleteByGoodsId" parameterType="java.lang.Long">
         delete from yeshi_ec_label_goods where lg_goods_id = #{goodsId,jdbcType=BIGINT}
     </delete>
     
    
    <delete id="deleteBatchByGoodsId"  parameterType="java.util.List">
        delete FROM yeshi_ec_label_goods WHERE lg_goods_id in
        <foreach collection="list" item="item" open="(" close=")"
            separator=",">#{item}</foreach>
    </delete>
     
     <delete id="deleteByLabId" parameterType="java.lang.Long">
         delete from yeshi_ec_label_goods where lg_label_id = #{labId,jdbcType=BIGINT}
     </delete>
     
      <delete id="deleteByGoodsIdAndLabId" parameterType="java.lang.Long">
         delete from yeshi_ec_label_goods where lg_goods_id = #{goodsId,jdbcType=BIGINT} and  lg_label_id = #{labId,jdbcType=BIGINT}
     </delete>
     
     <select id="getRelationNum"  resultType="java.lang.Long">
      <!--查询商品对应标签 -->
          SELECT  COUNT(DISTINCT lb.`lg_goods_id`) FROM   yeshi_ec_label_goods lb WHERE lb.`lg_label_id`=${labelId}  GROUP BY lb.`lg_label_id`
    </select>
    
     <!--查询子类对应标签(分页) -->
   <select id="queryByGoodsId" resultMap="BaseResultMap">
     SELECT  <include refid="Base_Column_List"/> FROM yeshi_ec_label_goods 
         WHERE lg_goods_id = ${goodsId} ORDER BY lg_createtime LIMIT ${start},${count}
   </select>
 
   <select id="getCountQueryByGoodsId" resultType="java.lang.Integer">
        SELECT count(lg_id)  FROM yeshi_ec_label_goods WHERE lg_goods_id = ${goodsId}
  </select>
    
    <select id="listQuery" resultMap="BaseResultMap">
             SELECT DISTINCT a.lg_goods_id FROM (SELECT <include refid="Base_Column_List" />  FROM yeshi_ec_label_goods 
            WHERE  <![CDATA[ 1>0 ]]>
               <if test="labIds != null">
                   AND lg_label_id in
                   <foreach  collection="labIds" item="labId" open="(" separator="," close=")">
                    #{labId}
                </foreach>
                </if>
                
            ORDER BY lg_weight desc
                )A
            LIMIT ${start},${count}    
    </select>
    
    <select id="countQuery" resultType="java.lang.Long">
             SELECT DISTINCT a.lg_goods_id FROM (SELECT IFNULL(count(lg_id),0) FROM yeshi_ec_label_goods 
            WHERE  <![CDATA[ 1>0 ]]>
               <if test="labIds != null">
                   AND lg_label_id in
                   <foreach  collection="labIds" item="labId" open="(" separator="," close=")">
                    #{labId}
                </foreach>
                </if>
                )A
    </select>
    
    
    <select id="listQuery9k9Class" resultMap="ResultMap">
           SELECT  <include refid="Base_Column_List"/> FROM yeshi_ec_label_goods g 
           WHERE g.`lg_goods_id` = #{gid}
                 AND g.`lg_label_id` IN
         <foreach  collection="list" item="labId" open="(" separator="," close=")">
            #{labId}
        </foreach>
    </select>
    
</mapper>