jyy
2021-01-25 949efdc17fa833f6511c0e5902057f3be0fe72c4
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<?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.matrix.system.hive.dao.ArticleDao">
    
    <resultMap type="Article" id="ArticleMap">
            <id property="id" column="id" />
            <result property="typeId" column="type_id" />
            <result property="articleAuthor" column="article_author" />
            <result property="title" column="title" />
            <result property="isPublish" column="is_publish" />
            <result property="articleAbstract" column="article_abstract" />
            <result property="content" column="content" />
            <result property="image" column="image" />
            <result property="sort" column="sort" />
            <result property="createtiem" column="createtiem" />
            <result property="url" column="url" />
        <result property="shopId" column="shop_id"/>
            
            
            <result property="articleTypeName" column="article_type_name" />
            <result property="type" column="type" />
            <result property="likeNumber" column="like_number" />
            <result property="classify" column="classify" />
            <result property="commentNum" column="commentNum" />
            
    </resultMap>
    <!--  插入方法   -->
    <insert id="insert" parameterType="Article"
        useGeneratedKeys="true" keyProperty="id">
        INSERT INTO article (
            id,
            type_id,
            article_author,
            title,
            is_publish,
            article_abstract,
            content,
            image,
            sort,
            createtiem,
            url,
            like_number,
            classify,
            shop_id
        )
    VALUES (
            #{id},
            #{typeId},
            #{articleAuthor},
            #{title},
            #{isPublish},
            #{articleAbstract},
            #{content},
            #{image},
            #{sort},
            #{createtiem},
            #{url},
            #{likeNumber},
            #{classify},
            #{shopId}
    )
    </insert>
    
    
    <!--  根据id更新 部分更新   -->
    <update id="update" >
        UPDATE article
        <set>
                <if test="typeId != null and typeId !='' ">
                    type_id = #{typeId},
                </if>        
                <if test="articleAuthor != null and articleAuthor !='' ">
                    article_author = #{articleAuthor},
                </if>        
                <if test="title != null and title !='' ">
                    title = #{title},
                </if>        
                <if test="isPublish != null and isPublish !='' ">
                    is_publish = #{isPublish},
                </if>        
                <if test="articleAbstract != null and articleAbstract !='' ">
                    article_abstract = #{articleAbstract},
                </if>        
                <if test="content != null and content !='' ">
                    content = #{content},
                </if>        
                <if test="image != null and image !='' ">
                    image = #{image},
                </if>        
                <if test="sort != null and sort !='' ">
                    sort = #{sort},
                </if>        
                <if test="createtiem != null   ">
                    createtiem = #{createtiem},
                </if>        
                <if test="url != null and url !='' ">
                    url = #{url},
                </if>        
                <if test="likeNumber != null and likeNumber !='' ">
                    like_number = #{likeNumber},
                </if>
                <if test="classify != null and classify !='' ">
                    classify = #{classify},
                </if>
        </set>
        WHERE id=#{id} 
    </update>
    
    
    
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from article where  id in
        <foreach collection="list" index="index" item="item" open="("
            separator="," close=")">
            #{item}
        </foreach>
    </delete>
        
    <!-- 根据id删除-->
    <delete id="deleteById" >
        DELETE FROM article
        where  id=#{id} 
    </delete>
    
    
    
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="ArticleMap">
        select 
            id,
            type_id,
            article_author,
            title,
            is_publish,
            article_abstract,
            content,
            image,
            sort,
            createtiem,
            url,
            classify,
            like_number,
            shop_id,
            (select article_type_name from article_type c where type_id = c.id) articleTypeName,
            (select type from article_type c where type_id = c.id) type
        from article
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and id = #{record.id}
            </if>
            <if test="record.typeId != null and record.typeId !='' ">
                and type_id = #{record.typeId}
            </if>
            <if test="record.articleAuthor != null and record.articleAuthor !='' ">
                and article_author = #{record.articleAuthor}
            </if>
            <if test="record.title != null and record.title !='' ">
                and title like CONCAT('%',#{record.title},'%')
            </if>
            <if test="record.isPublish != null and record.isPublish !='' ">
                and is_publish = #{record.isPublish}
            </if>
            <if test="record.articleAbstract != null and record.articleAbstract !='' ">
                and article_abstract like CONCAT('%',#{ecord.articleAbstract},'%')
            </if>
            <if test="record.content != null and record.content !='' ">
                and content like CONCAT('%',#{record.content},'%')
            </if>
            <if test="record.image != null and record.image !='' ">
                and image = #{record.image}
            </if>
            <if test="record.sort != null and record.sort !='' ">
                and sort = #{record.sort}
            </if>
            <if test="record.createtiem != null   ">
                and createtiem = #{record.createtiem}
            </if>
            <if test="record.url != null and record.url !='' ">
                and url = #{record.url}
            </if>
            <if test="record.classify != null and record.classify !='' ">
                and classify = #{record.classify}
            </if>
            <if test="record.likeNumber != null and record.likeNumber !='' ">
                and like_number = #{record.likeNumber}
            </if>
            <if test="record.shopId != null and record.shopId !='' ">
                and shop_id = #{record.shopId}
            </if>
            <if test="record.type != null and record.type !='' ">
                and (select type from article_type c where type_id = c.id) = #{record.type}
            </if>
            <if test="record.articleTypeName != null and record.url !='' ">
                and (select article_type_name from article_type c where type_id = c.id) = #{record.articleTypeName}
            </if>
        </if>
        order by type_id,sort
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
    
    
    <!-- 分页查询 -->
    <select id="selectInPag" resultMap="ArticleMap">
        select 
            id,
            type_id,
            article_author,
            title,
            is_publish,
            article_abstract,
            content,
            image,
            sort,
            createtiem,
            url,
            classify,
            like_number,
            shop_id,
            (select article_type_name from article_type c where type_id = c.id) articleTypeName,
            (select type from article_type c where type_id = c.id) type
        from article
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and id = #{record.id}
            </if>
            <if test="record.typeId != null and record.typeId !='' ">
                and type_id = #{record.typeId}
            </if>
            <if test="record.articleAuthor != null and record.articleAuthor !='' ">
                and article_author = #{record.articleAuthor}
            </if>
            <if test="record.title != null and record.title !='' ">
                and title like CONCAT('%',#{record.title},'%')
            </if>
            <if test="record.isPublish != null and record.isPublish !='' ">
                and is_publish = #{record.isPublish}
            </if>
            <if test="record.articleAbstract != null and record.articleAbstract !='' ">
                and article_abstract like CONCAT('%',#{ecord.articleAbstract},'%')
            </if>
            <if test="record.content != null and record.content !='' ">
                and content like CONCAT('%',#{record.content},'%')
            </if>
            <if test="record.image != null and record.image !='' ">
                and image = #{record.image}
            </if>
            <if test="record.sort != null and record.sort !='' ">
                and sort = #{record.sort}
            </if>
            <if test="record.createtiem != null  ">
                and createtiem = #{record.createtiem}
            </if>
            <if test="record.url != null and record.url !='' ">
                and url = #{record.url}
            </if>
            <if test="record.classify != null and record.classify !='' ">
                and classify = #{record.classify}
            </if>
            <if test="record.likeNumber != null and record.likeNumber !='' ">
                and like_number = #{record.likeNumber}
            </if>
            <if test="record.type != null and record.type !='' ">
                and (select type from article_type c where type_id = c.id) = #{record.type}
            </if>
            <if test="record.articleTypeName != null and record.url !='' ">
                and (select article_type_name from article_type c where type_id = c.id) = #{record.articleTypeName}
            </if>
            <if test="record.shopId != null and record.shopId !='' ">
                and shop_id = #{record.shopId}
            </if>
        </if>
        order by type_id,sort,createtiem desc
        limit #{staPage},#{endPage}
    </select>
    
    <!-- 查询总条数 -->
    <select id="selectTotalRecord"    resultType="java.lang.Integer">
    select count(*)
    from article
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and id = #{record.id}
            </if>
            <if test="record.typeId != null and record.typeId !='' ">
                and type_id = #{record.typeId}
            </if>
            <if test="record.articleAuthor != null and record.articleAuthor !='' ">
                and article_author = #{record.articleAuthor}
            </if>
            <if test="record.title != null and record.title !='' ">
                and title like CONCAT('%',#{record.title},'%')
            </if>
            <if test="record.isPublish != null and record.isPublish !='' ">
                and is_publish = #{record.isPublish}
            </if>
            <if test="record.articleAbstract != null and record.articleAbstract !='' ">
                and article_abstract like CONCAT('%',#{ecord.articleAbstract},'%')
            </if>
            <if test="record.content != null and record.content !='' ">
                and content like CONCAT('%',#{record.content},'%')
            </if>
            <if test="record.image != null and record.image !='' ">
                and image = #{record.image}
            </if>
            <if test="record.sort != null and record.sort !='' ">
                and sort = #{record.sort}
            </if>
            <if test="record.createtiem != null  ">
                and createtiem = #{record.createtiem}
            </if>
            <if test="record.url != null and record.url !='' ">
                and url = #{record.url}
            </if>
            <if test="record.classify != null and record.classify !='' ">
                and classify = #{record.classify}
            </if>
            <if test="record.likeNumber != null and record.likeNumber !='' ">
                and like_number = #{record.likeNumber}
            </if>
            <if test="record.type != null and record.type !='' ">
                and (select type from article_type c where type_id = c.id) = #{record.type}
            </if>
            <if test="record.articleTypeName != null and record.url !='' ">
                and (select article_type_name from article_type c where type_id = c.id) = #{record.articleTypeName}
            </if>
            <if test="record.shopId != null and record.shopId !='' ">
                and shop_id = #{record.shopId}
            </if>
        </if>
    </select>
 
    <!-- 根据id查询-->
    <select id="selectById" resultMap="ArticleMap">
        select 
            id,
            type_id,
            article_author,
            title,
            is_publish,
            article_abstract,
            content,
            image,
            sort,
            createtiem,
            url,
            like_number,
            classify,
            shop_id,
           (select article_type_name from article_type c where type_id = c.id) articleTypeName<!-- 所属门店名称 -->
        from article
        where  id=#{id} 
    </select>    
    
    
    <!-- 根据对象查询-->
    <select id="selectByModel" resultMap="ArticleMap">
        select 
            a.id,
            a.type_id,
            a.article_author,
            a.title,
            a.is_publish,
            a.article_abstract,
            a.content,
            a.image,
            a.sort,
            a.createtiem,
            a.url,
            a.classify,
            a.like_number,
            a.shop_id,
           (select article_type_name from article_type c where a.type_id = c.id) articleTypeName,<!-- 所属门店名称 -->
           (select count(*) from article_comment ac where ac.article_id=a.id) commentNum
        from article a
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and a.id = #{record.id}
            </if>
            <if test="record.typeId != null and record.typeId !='' ">
                and a.type_id = #{record.typeId}
            </if>
            <if test="record.articleAuthor != null and record.articleAuthor !='' ">
                and a.article_author = #{record.articleAuthor}
            </if>
            <if test="record.title != null and record.title !='' ">
                and a.title like CONCAT('%',#{record.title},'%')
            </if>
            <if test="record.isPublish != null and record.isPublish !='' ">
                and a.is_publish = #{record.isPublish}
            </if>
            <if test="record.articleAbstract != null and record.articleAbstract !='' ">
                and a.article_abstract like CONCAT('%',#{ecord.articleAbstract},'%')
            </if>
            <if test="record.content != null and record.content !='' ">
                and a.content like CONCAT('%',#{record.content},'%')
            </if>
            <if test="record.image != null and record.image !='' ">
                and a.image = #{record.image}
            </if>
            <if test="record.sort != null and record.sort !='' ">
                and a.sort = #{record.sort}
            </if>
            <if test="record.createtiem != null  ">
                and a.createtiem = #{record.createtiem}
            </if>
            <if test="record.url != null and record.url !='' ">
                and a.url = #{record.url}
            </if>
            <if test="record.classify != null and record.classify !='' ">
                and a.classify = #{record.classify}
            </if>
            <if test="record.likeNumber != null and record.likeNumber !='' ">
                and a.like_number = #{record.likeNumber}
            </if>
            <if test="record.articleTypeName != null and record.url !='' ">
                and (select article_type_name from article_type c where a.type_id = c.id) = #{record.articleTypeName}
            </if>
            <if test="record.shopId != null and record.shopId !='' ">
                and a.shop_id = #{record.shopId}
            </if>
        </if>
        order by type_id,sort,createtiem desc
    </select>
 
    <select id="selectApiArticleListInPage" resultMap="ArticleMap">
        select * from article a
        inner join article_type b on a.type_id=b.id
        where  a.type_id=#{record.typeId} or find_in_set(#{record.typeId}, b.parent_ids)
        order by a.createtiem desc
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
 
</mapper>