shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
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
package com.ishop.merchant.service;
 
import com.ishop.model.po.EbArticle;
import com.ishop.model.po.EbArticleCategory;
import com.walker.db.Sorts;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.infrastructure.utils.UrlUtils;
import com.walker.jdbc.service.BaseServiceImpl;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class ArticleServiceImpl extends BaseServiceImpl {
 
    private final Sorts.Sort articleSort = Sorts.DESC().setField("id");
 
    public void execDeleteArticle(long id){
        this.execute("delete from eb_article where id=?", new Object[]{id});
    }
 
    /**
     * 给定文章分类,是否被引用?
     * @param categoryId
     * @return
     * @date 2023-08-06
     */
    public boolean queryCategoryUsed(long categoryId){
        return this.sqlMathQuery("select count(id) total from eb_article where cid=?", new Object[]{categoryId}, Integer.class) > 0;
    }
 
    public GenericPager<EbArticleCategory> queryPageCategoryList(){
        EbArticleCategory category = new EbArticleCategory();
        category.setIsDel(0);
        return this.selectSplit(category, Sorts.DESC().setField("id"));
    }
 
    public GenericPager<EbArticle> queryPageAdminList(Long cid, String title, String author){
        EbArticle param = new EbArticle();
        param.setIsDel(0);
        if(cid != null && cid > 0){
            param.setCid(cid);
        }
        if(StringUtils.isNotEmpty(title)){
            param.setTitle(StringUtils.CHAR_PERCENT + UrlUtils.decode(title) + StringUtils.CHAR_PERCENT);
        }
        if(StringUtils.isNotEmpty(author)){
            param.setAuthor(StringUtils.CHAR_PERCENT + UrlUtils.decode(author) + StringUtils.CHAR_PERCENT);
        }
        return this.selectSplit(param, articleSort);
    }
 
    /**
     * 查询文章列表
     * @param cid 分类ID,可选
     * @return
     * @date 2023-07-18
     */
    public GenericPager<EbArticle> queryPageArticleList(String cid, Boolean hot, Boolean banner){
        Map<String, Object> param = new HashMap<>(2);
        StringBuilder sql = new StringBuilder(SQL_PAGE_LIST);
        if(StringUtils.isNotEmpty(cid)){
            sql.append(" and cid=:cid");
            param.put("cid", cid);
        }
        if(hot != null){
            sql.append(" and is_hot=:hot");
            param.put("hot", hot? 1:0);
        }
        if(banner != null){
            sql.append(" and is_banner=:banner");
            param.put("banner", banner? 1:0);
        }
        sql.append(" order by sort desc");
        return this.selectSplit(sql.toString(), param, new EbArticle());
    }
 
    public List<EbArticle> queryArticleList(Boolean hot, Boolean banner){
        Map<String, Object> param = new HashMap<>(2);
        StringBuilder sql = new StringBuilder(SQL_PAGE_LIST);
        if(hot != null){
            sql.append(" and is_hot=:hot");
            param.put("hot", hot? 1:0);
        }
        if(banner != null){
            sql.append(" and is_banner=:banner");
            param.put("banner", banner? 1:0);
        }
        sql.append(" order by sort desc");
        return this.select(sql.toString(), param, new EbArticle());
    }
 
    private static final String SQL_PAGE_LIST = "select * from eb_article where is_del=0 and status=1";
 
    /**
     * 返回首页热点文章集合。
     * @param limit 限制几条
     * @return
     * @date 2023-06-23
     */
    public List<EbArticle> queryIndexHeadLine(int limit){
        return this.select("select id,title from eb_article where is_del=0 and status=1 and is_hot=1 order by sort desc limit ?", new Object[]{limit}, new EbArticle());
    }
}