ArticleController.java 4.22 KB
   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
package com.lyms.talkonlineweb.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyms.talkonlineweb.domain.ArticleInfo;
import com.lyms.talkonlineweb.domain.LymsArticle;
import com.lyms.talkonlineweb.domain.LymsDoctor;
import com.lyms.talkonlineweb.domain.LymsPushedart;
import com.lyms.talkonlineweb.result.BaseResponse;
import com.lyms.talkonlineweb.service.ArticleInfoService;
import com.lyms.talkonlineweb.service.LymsArticleService;
import com.lyms.talkonlineweb.service.LymsPushedartService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.codec.multipart.Part;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("art")
@Log4j2
public class ArticleController {

@Value("${uploadPath}")
private String uploadPath;//上传路径

@Value("${imgUrlPre}")
private String imgUrlPre;//图片查看路径

@Autowired
private LymsArticleService lymsArticleService;

@Autowired
private ArticleInfoService articleInfoService;

@Autowired
private LymsPushedartService lymsPushedartService;//推送记录

/**
* 上传文件
* @return
*/
@PostMapping("upFile")
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){
log.error(e.getMessage());
e.printStackTrace();
}
}

return furl;
}

/**
* 更新或插入文章文章
* @param article
* @return
*/
@PostMapping("saveArticle")
public BaseResponse saveArticle(LymsArticle article){
BaseResponse baseResponse=new BaseResponse();
if(article.getAid()==null){
article.setCreatedtime(new Date());
}else{
article.setUpdatedTime(new Date());
}
boolean f=lymsArticleService.saveOrUpdate(article);
return baseResponse;
}
/**
* 获取文章列表
* @param article
* @param current
* @param size
* @return
*/
@GetMapping("sltArticleLst")
public BaseResponse sltArticleLst(ArticleInfo article, int current, int size){
BaseResponse baseResponse=new BaseResponse();
Page<ArticleInfo> page=new Page<>(current,size);
Page<ArticleInfo> articlePagePage=articleInfoService.page(page, Wrappers.query(article).orderByDesc("updated_time","createdtime"));

baseResponse.setObject(articlePagePage);

return baseResponse;
}

/**
* 删除文章
* @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);
return baseResponse;
}

/**
* 根据患者获取推送的文章
*/

@GetMapping("getPushArt")
public BaseResponse getPushArt(LymsPushedart pushedart){
BaseResponse baseResponse=new BaseResponse();
List<LymsPushedart> pLst=lymsPushedartService.list(Wrappers.query(pushedart));
List idLst=new ArrayList();
pLst.forEach(e->{
idLst.add(e.getAid());
});
if(idLst.size()>0){
List<LymsArticle> aLst=lymsArticleService.listByIds(idLst);
baseResponse.setObject(aLst);

}
return baseResponse;
}

}