yujian
2019-05-29 0588d6be74335f41c79a8d8e32dbd1c3d3e47fa3
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?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.LabelMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.lable.Label">
    <id column="lab_id" property="id" jdbcType="BIGINT"/>
    <result column="lab_title" property="title" jdbcType="VARCHAR"/>
    <result column="lab_picture" property="picture" jdbcType="VARCHAR"/>
    <result column="lab_ios_click" property="iosClick" jdbcType="BIGINT"/>
    <result column="lab_android_click" property="androidClick" jdbcType="BIGINT"/>
    <result column="lab_entry_mode" property="entrymode" jdbcType="INTEGER"/>
    <result column="lab_remark" property="remark" jdbcType="VARCHAR"/>
    <result column="lab_createtime" property="createtime" jdbcType="TIMESTAMP"/>
    <result column="lab_updatetime" property="updatetime" jdbcType="TIMESTAMP"/>
    
     <association property="createUser" column="lab_entry_aid" 
        select="com.yeshi.fanli.dao.mybatis.AdminUserMapper.selectByPrimaryKey"> 
    </association>
 
  </resultMap>
  
   <resultMap id="ResultMap" type="com.yeshi.fanli.entity.bus.lable.Label">
    <id column="lab_id" property="id" jdbcType="BIGINT"/>
    <result column="lab_title" property="title" jdbcType="VARCHAR"/>
    <result column="lab_picture" property="picture" jdbcType="VARCHAR"/>
  </resultMap>
  
  <sql id="Base_Column_List">lab_id,lab_title,lab_picture,lab_ios_click,lab_android_click,lab_entry_aid,lab_entry_mode,lab_remark,lab_createtime,lab_updatetime</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_label where lab_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_label where lab_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.lable.Label" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_label (lab_id,lab_title,lab_picture,lab_ios_click,lab_android_click,lab_entry_aid,lab_entry_mode,lab_remark,lab_createtime,lab_updatetime) values (#{id,jdbcType=BIGINT},#{title,jdbcType=VARCHAR},#{picture,jdbcType=VARCHAR},#{iosClick,jdbcType=BIGINT},#{androidClick,jdbcType=BIGINT},#{createUser.id,jdbcType=BIGINT},#{entrymode,jdbcType=INTEGER},#{remark,jdbcType=VARCHAR},#{createtime,jdbcType=TIMESTAMP},#{updatetime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.lable.Label" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_label
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">lab_id,</if>
      <if test="title != null">lab_title,</if>
      <if test="picture != null">lab_picture,</if>
      <if test="iosClick != null">lab_ios_click,</if>
      <if test="androidClick != null">lab_android_click,</if>
      <if test="createUser != null">lab_entry_aid,</if>
      <if test="entrymode != null">lab_entry_mode,</if>
      <if test="remark != null">lab_remark,</if>
      <if test="createtime != null">lab_createtime,</if>
      <if test="updatetime != null">lab_updatetime,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="title != null">#{title,jdbcType=VARCHAR},</if>
      <if test="picture != null">#{picture,jdbcType=VARCHAR},</if>
      <if test="iosClick != null">#{iosClick,jdbcType=BIGINT},</if>
      <if test="androidClick != null">#{androidClick,jdbcType=BIGINT},</if>
      <if test="createUser != null">#{createUser.id,jdbcType=BIGINT},</if>
      <if test="entrymode != null">#{entrymode,jdbcType=INTEGER},</if>
      <if test="remark != null">#{remark,jdbcType=VARCHAR},</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.lable.Label">update yeshi_ec_label set lab_title = #{title,jdbcType=VARCHAR},lab_picture = #{picture,jdbcType=VARCHAR},lab_ios_click = #{iosClick,jdbcType=BIGINT},lab_android_click = #{androidClick,jdbcType=BIGINT},lab_entry_aid = #{createUser.id,jdbcType=BIGINT},lab_entry_mode = #{entrymode,jdbcType=INTEGER},lab_remark = #{remark,jdbcType=VARCHAR},lab_createtime = #{createtime,jdbcType=TIMESTAMP},lab_updatetime = #{updatetime,jdbcType=TIMESTAMP} where lab_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.lable.Label">update yeshi_ec_label
    <set>
      <if test="title != null">lab_title=#{title,jdbcType=VARCHAR},</if>
      <if test="picture != null">lab_picture=#{picture,jdbcType=VARCHAR},</if>
      <if test="iosClick != null">lab_ios_click=#{iosClick,jdbcType=BIGINT},</if>
      <if test="androidClick != null">lab_android_click=#{androidClick,jdbcType=BIGINT},</if>
      <if test="createUser != null">lab_entry_aid=#{createUser.id,jdbcType=BIGINT},</if>
      <if test="entrymode != null">lab_entry_mode=#{entrymode,jdbcType=INTEGER},</if>
      <if test="remark != null">lab_remark=#{remark,jdbcType=VARCHAR},</if>
      <if test="createtime != null">lab_createtime=#{createtime,jdbcType=TIMESTAMP},</if>
      <if test="updatetime != null">lab_updatetime=#{updatetime,jdbcType=TIMESTAMP},</if>
    </set> where lab_id = #{id,jdbcType=BIGINT}
  </update>
  
    <select id="query" resultMap="BaseResultMap">
      <!-- 根据条件查询所有标签 -->
    SELECT  <include refid="Base_Column_List" />  FROM yeshi_ec_label lb    
        LEFT JOIN yeshi_ec_adminuser ur ON lb.lab_entry_aid=ur.id
    WHERE     <![CDATA[1>0]]>
       <if test='key != null and key != ""'>
              AND (lb.lab_title like '%${key}%' OR ur.id like '%${key}%' OR ur.name like '%${key}%' ) 
       </if>
          <if test='startTime != null and startTime != ""'>
               <![CDATA[ AND lb.lab_createtime >= '${startTime}' ]]>
          </if>
          <if test='endTime != null and endTime != ""'>
               <![CDATA[ AND lb.lab_createtime <= '${endTime}' ]]>
          </if>
             ORDER BY (lb.lab_ios_click + lb.lab_android_click) 
         <if test='orderMode == 1'> DESC </if>
         ,lb.lab_createtime DESC  LIMIT ${start},${count}
   </select>
 
   <select id="getQueryCount" resultType="java.lang.Integer">
       <!-- 根据条件统计所有标签数量 -->
      SELECT count(lab_id)  FROM yeshi_ec_label lb    
          LEFT JOIN yeshi_ec_adminuser ur ON lb.lab_entry_aid=ur.id
      WHERE <![CDATA[1>0]]>
       <if test='key != null and key != ""'>
              AND (lb.lab_title like '%${key}%' OR ur.id like '%${key}%' OR ur.name like '%${key}%' ) 
       </if>
          <if test='startTime != null and startTime != ""'>
               <![CDATA[ AND lb.lab_createtime >= '${startTime}' ]]>
          </if>
          <if test='endTime != null and endTime != ""'>
               <![CDATA[ AND lb.lab_createtime <= '${endTime}' ]]>
          </if>
    </select>
    
    <select id="getCount" resultType="java.lang.Long">
      <!-- 统计标签总数数量 -->
          SELECT count(lab_id)  FROM yeshi_ec_label lb    
    </select>
    
    <select id="getCountToday" resultType="java.lang.Long">
      <!-- 统计今日各种方式录入数量 -->
         SELECT  count(lab_id)  FROM yeshi_ec_label
            WHERE  lab_createtime>= CURDATE();
    </select>
    
    <select id="getCountByEntryMode" resultType="java.util.HashMap">
      <!-- 统计今日各种方式录入数量 -->
         SELECT  IFNULL(count(lab_id),0) AS total, 
             IFNULL(SUM(CASE WHEN lab_entry_mode = 1 THEN 1 ELSE 0 END),0) AS totalBack,
            IFNULL(SUM(CASE WHEN lab_entry_mode = 2 THEN 1 ELSE 0 END),0) AS totalExcel
        FROM yeshi_ec_label
    </select>
    
    <delete id="deleteBatchByPrimaryKey" parameterType="int">
        <!-- 批量删除动态信息 -->
        delete from yeshi_ec_label where lab_id in
        <foreach item="ids" collection="array" open="(" separator=","
            close=")">#{ids}</foreach>
   </delete>
   
    <select id="selectByTitle" resultMap="ResultMap">
        select <include refid="Base_Column_List"/> from yeshi_ec_label 
            where lab_title = #{title}
    </select>
    
    
     <select id="listByTitles" parameterType="java.util.List" resultMap="ResultMap">
        select * from yeshi_ec_label 
        where lab_title  in <foreach collection="list" item="item" open="(" separator="," close=")">#{item}</foreach>
    </select>
    
    
    <select id="getByTitle" resultMap="ResultMap">
        select * from yeshi_ec_label 
        WHERE lab_title = #{title}
        limit 1
    </select>
    
      <!-- 查询商品标 签候选项 -->
    <select id="queryGoodsCandidate" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" /> FROM `yeshi_ec_label` 
        WHERE lab_id NOT IN (SELECT L.`lg_label_id` FROM `yeshi_ec_label_goods` L WHERE  L.`lg_goods_id` = #{goodsId})
            <if test='key != null and key != ""'>
                AND lab_title like '%#{key}%'  
            </if>
        ORDER BY lab_createtime  LIMIT #{start},#{count}
   </select>
   <!-- 查询商品标 签候选项统计 -->
    <select id="getCountQueryGoodsCandidate" resultType="java.lang.Integer">
        SELECT count(lab_id) FROM `yeshi_ec_label` 
        WHERE lab_id NOT IN (SELECT L.`lg_label_id` FROM `yeshi_ec_label_goods` L WHERE  L.`lg_goods_id` = #{goodsId})
            <if test='key != null and key != ""'>
                AND lab_title like '%#{key}%'  
            </if>
   </select>
   
   
   <!-- 查询一级分类 标签候选项 -->
    <select id="queryClassCandidate" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" /> FROM `yeshi_ec_label` 
        WHERE lab_id NOT IN ( SELECT lc_label_id  FROM yeshi_ec_label_class WHERE lc_class_id = ${classId})
         <if test='key != null and key != ""'>
               AND lab_title like '%${key}%' 
         </if>
        ORDER BY lab_createtime  LIMIT ${start},${count}
   </select>
   <!-- 查询一级分类 标签候选项 -->
    <select id="getCountQueryClassCandidate" resultType="java.lang.Integer">
        SELECT count(lab_id)  FROM `yeshi_ec_label` 
        WHERE lab_id NOT IN ( SELECT lc_label_id  FROM yeshi_ec_label_class WHERE lc_class_id = ${classId})
         <if test='key != null and key != ""'>
               AND lab_title like '%${key}%' 
         </if>
   </select>
   
   
   <!-- 查询子集分类 标签候选项 -->
    <select id="querySubClassCandidate" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" /> FROM `yeshi_ec_label` 
        WHERE lab_id NOT IN (SELECT lc_label_id  FROM yeshi_ec_label_class WHERE lc_subclass_id = ${subClassId})
           <if test='key != null and key != ""'>
               AND lab_title like '%${key}%' 
         </if>
        ORDER BY lab_createtime  LIMIT ${start},${count}
   </select>
   <!-- 查询子集分类 标签候选项 -->
    <select id="getCountQuerySubClassCandidate" resultType="java.lang.Integer">
        SELECT count(lab_id) FROM `yeshi_ec_label` 
        WHERE lab_id NOT IN (SELECT lc_label_id  FROM yeshi_ec_label_class WHERE lc_subclass_id = ${subClassId})
           <if test='key != null and key != ""'>
               AND lab_title like '%${key}%' 
         </if>
   </select>
   
   <!-- 查询子集分类 标签候选项 -->
    <select id="getSecondClassLables" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" /> FROM `yeshi_ec_label` 
        WHERE lab_id NOT IN (SELECT lc_label_id  FROM yeshi_ec_label_class WHERE lc_subclass_id = ${subClassId})
        ORDER BY lab_createtime
   </select>
   
   
    <select id="getByGoodsId" resultMap="ResultMap">
          SELECT * FROM `yeshi_ec_label` l
            RIGHT JOIN `yeshi_ec_label_goods` g ON g.`lg_label_id` = l.`lab_id`
             WHERE g.`lg_goods_id` = ${goodsId}
    </select>
    
   
   
</mapper>