Commit 50d212e234614b2f9f49e53da8fe57eb0ba870af

Authored by changpengfei
1 parent 0e77e7d716
Exists in master and in 1 other branch dev

文章动态排序

Showing 1 changed file with 48 additions and 36 deletions

talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/ArticleController.java View file @ 50d212e
... ... @@ -45,19 +45,20 @@
45 45  
46 46 /**
47 47 * 上传文件
  48 + *
48 49 * @return
49 50 */
50 51 @PostMapping("upFile")
51   - public String upFile(MultipartFile imgFile){
52   - String furl="";
53   - if(Objects.nonNull(imgFile)){
  52 + public String upFile(MultipartFile imgFile) {
  53 + String furl = "";
  54 + if (Objects.nonNull(imgFile)) {
54 55 try {
55   - File file=new File(uploadPath+File.separator+System.currentTimeMillis()+imgFile.getOriginalFilename());
56   - imgFile.transferTo(file);
57   - furl=file.getAbsolutePath();
58   - log.info("上传文件:"+furl);
59   - furl=imgUrlPre+file.getName();
60   - }catch (Exception e){
  56 + File file = new File(uploadPath + File.separator + System.currentTimeMillis() + imgFile.getOriginalFilename());
  57 + imgFile.transferTo(file);
  58 + furl = file.getAbsolutePath();
  59 + log.info("上传文件:" + furl);
  60 + furl = imgUrlPre + file.getName();
  61 + } catch (Exception e) {
61 62 log.error(e.getMessage());
62 63 e.printStackTrace();
63 64 }
64 65  
65 66  
66 67  
67 68  
68 69  
69 70  
70 71  
... ... @@ -68,33 +69,42 @@
68 69  
69 70 /**
70 71 * 更新或插入文章文章
  72 + *
71 73 * @param article
72 74 * @return
73 75 */
74 76 @PostMapping("saveArticle")
75   - public BaseResponse saveArticle(LymsArticle article){
76   - BaseResponse baseResponse=new BaseResponse();
77   - if(article.getAid()==null){
  77 + public BaseResponse saveArticle(LymsArticle article) {
  78 + BaseResponse baseResponse = new BaseResponse();
  79 + if (article.getAid() == null) {
78 80 article.setCreatedtime(new Date());
79   - }else{
  81 + } else {
80 82 article.setUpdatedTime(new Date());
81 83 }
82   - boolean f=lymsArticleService.saveOrUpdate(article);
  84 + boolean f = lymsArticleService.saveOrUpdate(article);
83 85 return baseResponse;
84 86 }
  87 +
85 88 /**
86 89 * 获取文章列表
  90 + *
87 91 * @param article
88 92 * @param current
89 93 * @param size
  94 + * @param sort
90 95 * @return
91 96 */
92 97 @GetMapping("sltArticleLst")
93   - public BaseResponse sltArticleLst(ArticleInfo article, int current, int size){
94   - BaseResponse baseResponse=new BaseResponse();
95   - Page<ArticleInfo> page=new Page<>(current,size);
96   - Page<ArticleInfo> articlePagePage=articleInfoService.page(page, Wrappers.query(article).orderByDesc("updated_time","createdtime"));
97   -
  98 + public BaseResponse sltArticleLst(ArticleInfo article, int current, int size, int sort) {
  99 + BaseResponse baseResponse = new BaseResponse();
  100 + Page<ArticleInfo> page = new Page<>(current, size);
  101 + Page<ArticleInfo> articlePagePage = new Page<>();
  102 + if (sort == 1) {
  103 + articlePagePage = articleInfoService.page(page, Wrappers.query(article).orderByDesc("updated_time", "createdtime"));
  104 + }
  105 + if (sort == 2) {
  106 + articlePagePage = articleInfoService.page(page, Wrappers.query(article).orderByAsc("updated_time", "createdtime"));
  107 + }
98 108 baseResponse.setObject(articlePagePage);
99 109  
100 110 return baseResponse;
101 111  
... ... @@ -102,14 +112,15 @@
102 112  
103 113 /**
104 114 * 删除文章
  115 + *
105 116 * @param aid
106 117 * @return
107 118 */
108 119 @GetMapping("delArticle")
109   - public BaseResponse delArticle(int aid){
110   - BaseResponse baseResponse=new BaseResponse();
111   - boolean f=lymsArticleService.removeById(aid);
112   - baseResponse.setErrorcode(f==true?0:1);
  120 + public BaseResponse delArticle(int aid) {
  121 + BaseResponse baseResponse = new BaseResponse();
  122 + boolean f = lymsArticleService.removeById(aid);
  123 + baseResponse.setErrorcode(f == true ? 0 : 1);
113 124 return baseResponse;
114 125 }
115 126  
116 127  
117 128  
118 129  
119 130  
120 131  
... ... @@ -117,31 +128,32 @@
117 128 * 根据患者获取推送的文章
118 129 */
119 130 @GetMapping("getPushArt")
120   - public BaseResponse getPushArt(LymsPushedart pushedart){
121   - BaseResponse baseResponse=new BaseResponse();
122   - List<LymsPushedart> pLst=lymsPushedartService.list(Wrappers.query(pushedart));
123   - List idLst=new ArrayList();
124   - pLst.forEach(e->{
  131 + public BaseResponse getPushArt(LymsPushedart pushedart) {
  132 + BaseResponse baseResponse = new BaseResponse();
  133 + List<LymsPushedart> pLst = lymsPushedartService.list(Wrappers.query(pushedart));
  134 + List idLst = new ArrayList();
  135 + pLst.forEach(e -> {
125 136 idLst.add(e.getAid());
126 137 });
127   - if(idLst.size()>0){
128   - List<LymsArticle> aLst=lymsArticleService.listByIds(idLst);
129   - baseResponse.setObject(aLst);
  138 + if (idLst.size() > 0) {
  139 + List<LymsArticle> aLst = lymsArticleService.listByIds(idLst);
  140 + baseResponse.setObject(aLst);
130 141  
131 142 }
132   - return baseResponse;
  143 + return baseResponse;
133 144 }
134 145  
135 146 /**
136 147 * 统计文章
  148 + *
137 149 * @return
138 150 */
139 151 @GetMapping("getArtStat")
140   - public BaseResponse getArtStat(){
141   - BaseResponse baseResponse=new BaseResponse();
142   - List<Map<String,Object>> aLst=lymsArticleService.getArtStat();
  152 + public BaseResponse getArtStat() {
  153 + BaseResponse baseResponse = new BaseResponse();
  154 + List<Map<String, Object>> aLst = lymsArticleService.getArtStat();
143 155 baseResponse.setObject(aLst);
144   - return baseResponse;
  156 + return baseResponse;
145 157 }
146 158  
147 159 }