From 50d212e234614b2f9f49e53da8fe57eb0ba870af Mon Sep 17 00:00:00 2001 From: changpengfei Date: Thu, 9 Sep 2021 10:37:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E5=8A=A8=E6=80=81=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ArticleController.java | 84 ++++++++++++---------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/ArticleController.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/ArticleController.java index bed4ec8..7386c81 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/ArticleController.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/ArticleController.java @@ -45,19 +45,20 @@ public class ArticleController { /** * 上传文件 + * * @return */ @PostMapping("upFile") - public String upFile(MultipartFile imgFile){ - String furl=""; - if(Objects.nonNull(imgFile)){ + public String upFile(MultipartFile imgFile) { + String furl = ""; + if (Objects.nonNull(imgFile)) { try { - File file=new File(uploadPath+File.separator+System.currentTimeMillis()+imgFile.getOriginalFilename()); - imgFile.transferTo(file); - furl=file.getAbsolutePath(); - log.info("上传文件:"+furl); - furl=imgUrlPre+file.getName(); - }catch (Exception e){ + File file = new File(uploadPath + File.separator + System.currentTimeMillis() + imgFile.getOriginalFilename()); + imgFile.transferTo(file); + furl = file.getAbsolutePath(); + log.info("上传文件:" + furl); + furl = imgUrlPre + file.getName(); + } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } @@ -68,33 +69,42 @@ public class ArticleController { /** * 更新或插入文章文章 + * * @param article * @return */ @PostMapping("saveArticle") - public BaseResponse saveArticle(LymsArticle article){ - BaseResponse baseResponse=new BaseResponse(); - if(article.getAid()==null){ + public BaseResponse saveArticle(LymsArticle article) { + BaseResponse baseResponse = new BaseResponse(); + if (article.getAid() == null) { article.setCreatedtime(new Date()); - }else{ + } else { article.setUpdatedTime(new Date()); } - boolean f=lymsArticleService.saveOrUpdate(article); + boolean f = lymsArticleService.saveOrUpdate(article); return baseResponse; } + /** * 获取文章列表 + * * @param article * @param current * @param size + * @param sort * @return */ @GetMapping("sltArticleLst") - public BaseResponse sltArticleLst(ArticleInfo article, int current, int size){ - BaseResponse baseResponse=new BaseResponse(); - Page page=new Page<>(current,size); - Page articlePagePage=articleInfoService.page(page, Wrappers.query(article).orderByDesc("updated_time","createdtime")); - + public BaseResponse sltArticleLst(ArticleInfo article, int current, int size, int sort) { + BaseResponse baseResponse = new BaseResponse(); + Page page = new Page<>(current, size); + Page articlePagePage = new Page<>(); + if (sort == 1) { + articlePagePage = articleInfoService.page(page, Wrappers.query(article).orderByDesc("updated_time", "createdtime")); + } + if (sort == 2) { + articlePagePage = articleInfoService.page(page, Wrappers.query(article).orderByAsc("updated_time", "createdtime")); + } baseResponse.setObject(articlePagePage); return baseResponse; @@ -102,14 +112,15 @@ public class ArticleController { /** * 删除文章 + * * @param aid * @return */ @GetMapping("delArticle") - public BaseResponse delArticle(int aid){ - BaseResponse baseResponse=new BaseResponse(); - boolean f=lymsArticleService.removeById(aid); - baseResponse.setErrorcode(f==true?0:1); + public BaseResponse delArticle(int aid) { + BaseResponse baseResponse = new BaseResponse(); + boolean f = lymsArticleService.removeById(aid); + baseResponse.setErrorcode(f == true ? 0 : 1); return baseResponse; } @@ -117,31 +128,32 @@ public class ArticleController { * 根据患者获取推送的文章 */ @GetMapping("getPushArt") - public BaseResponse getPushArt(LymsPushedart pushedart){ - BaseResponse baseResponse=new BaseResponse(); - List pLst=lymsPushedartService.list(Wrappers.query(pushedart)); - List idLst=new ArrayList(); - pLst.forEach(e->{ + public BaseResponse getPushArt(LymsPushedart pushedart) { + BaseResponse baseResponse = new BaseResponse(); + List pLst = lymsPushedartService.list(Wrappers.query(pushedart)); + List idLst = new ArrayList(); + pLst.forEach(e -> { idLst.add(e.getAid()); }); - if(idLst.size()>0){ - List aLst=lymsArticleService.listByIds(idLst); - baseResponse.setObject(aLst); + if (idLst.size() > 0) { + List aLst = lymsArticleService.listByIds(idLst); + baseResponse.setObject(aLst); } - return baseResponse; + return baseResponse; } /** * 统计文章 + * * @return */ @GetMapping("getArtStat") - public BaseResponse getArtStat(){ - BaseResponse baseResponse=new BaseResponse(); - List> aLst=lymsArticleService.getArtStat(); + public BaseResponse getArtStat() { + BaseResponse baseResponse = new BaseResponse(); + List> aLst = lymsArticleService.getArtStat(); baseResponse.setObject(aLst); - return baseResponse; + return baseResponse; } } -- 1.8.3.1