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
package com.ishop.mobile.api;
 
import com.ishop.merchant.util.VoUtils;
import com.ishop.mobile.BaseApi;
import com.ishop.model.po.EbArticle;
import com.ishop.model.vo.ArticleVo;
import com.walker.db.page.GenericPager;
import com.walker.db.page.ListPageContext;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.ResponseValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.List;
 
@RestController
@RequestMapping("/front/article")
public class ArticleApi extends BaseApi {
 
    // 文章分类列表
    @RequestMapping(value = "/category/list", method = RequestMethod.GET)
    public ResponseValue getCategoryList(){
        return ResponseValue.success(this.getArticleCategoryCache().getList());
    }
 
    /**
     * 文章分页列表
     * @return
     */
    @RequestMapping(value = "/list/{cid}", method = RequestMethod.GET)
    public ResponseValue list(@PathVariable(name = "cid") String cid){
        GenericPager<EbArticle> pager = this.getArticleService().queryPageArticleList(cid, null, null);
        List<EbArticle> data = pager.getDatas();
        if(StringUtils.isEmptyList(data)){
            return ResponseValue.success(pager);
        }
 
//        List<ArticleVo> list = new ArrayList<>(data.size());
//        for(EbArticle article: data){
//            list.add(VoUtils.acquireArticleVo(article));
//        }
        List<ArticleVo> list = this.acquireVoList(data);
        return ResponseValue.success(ListPageContext.createGenericPager(list, pager.getPageIndex(), (int)pager.getTotalRows()));
    }
 
    @RequestMapping(value = "/hot/list", method = RequestMethod.GET)
    public ResponseValue getHotList(){
        List<EbArticle> data = this.getArticleService().queryArticleList(true, null);
        return ResponseValue.success(this.acquireVoList(data));
    }
 
    // 轮播列表
    @RequestMapping(value = "/banner/list", method = RequestMethod.GET)
    public ResponseValue getBannerList(){
        List<EbArticle> data = this.getArticleService().queryArticleList(null, true);
        return ResponseValue.success(this.acquireVoList(data));
    }
 
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public ResponseValue detail(@PathVariable(value = "id") Long id){
//        if(id == null || id.longValue() <= 0){
//            return ResponseValue.error(Constants.ERROR_ARGUMENT);
//        }
//        EbArticle article = this.getArticleService().get(new EbArticle(id));
//        if(article == null){
//            return ResponseValue.success("文章不存在");
//        }
//        return ResponseValue.success(VoUtils.acquireArticleVo(article, getCdnUrl(), true));
        return this.acquireArticleDetailVo(id);
    }
 
    private List<ArticleVo> acquireVoList(List<EbArticle> data){
        String cdnUrl = this.getCdnUrl();
        List<ArticleVo> list = new ArrayList<>(4);
        if(!StringUtils.isEmptyList(data)){
            for(EbArticle article: data){
                list.add(VoUtils.acquireArticleVo(article, cdnUrl, false));
            }
        }
        return list;
    }
}