ArticleController.java 8.49 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
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
package com.lyms.talkonlineweb.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyms.talkonlineweb.domain.*;
import com.lyms.talkonlineweb.result.BaseResponse;
import com.lyms.talkonlineweb.service.ArticleInfoService;
import com.lyms.talkonlineweb.service.GetpushartInfoService;
import com.lyms.talkonlineweb.service.LymsArticleService;
import com.lyms.talkonlineweb.service.LymsPushedartService;
import com.lyms.talkonlineweb.service.impl.PushedartlogsInfoServiceImpl;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.codec.multipart.Part;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;

@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;//推送记录

@Autowired
private PushedartlogsInfoServiceImpl pushedartlogsInfoService;

@Autowired
private GetpushartInfoService getpushartInfoService;//小程序用户端-根据患者获取推送的文章-视图
/**
* 上传文件
*
* @return
*/
@PostMapping("upFile")
public String upFile(MultipartFile imgFile) {
String furl = "";
if (Objects.nonNull(imgFile)) {
try {
String[] orginaF=imgFile.getOriginalFilename().split("\\.");

File file = new File(uploadPath + File.separator + System.currentTimeMillis() +"."+ orginaF[orginaF.length-1]);
imgFile.transferTo(file);
furl = file.getAbsolutePath();
log.info("上传文件:" + furl);
furl = imgUrlPre + file.getName();
} catch (Exception e) {
log.error(e.getMessage());
e.printStackTrace();
}
}

return furl;
}

/**
* 显示图片
* @return
*/
@GetMapping("showPic/{fileName}")
public void showPic(@PathVariable("fileName") String fileName, HttpServletResponse response) {
try(InputStream in=new FileInputStream(new File(uploadPath + File.separator +fileName));
OutputStream out=response.getOutputStream();
){
IOUtils.copy(in,out);
out.flush();
}catch (Exception e){
e.printStackTrace();
}
}

/**
* 更新或插入文章文章
*
* @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
* @param sort
* @return
*/
@GetMapping("sltArticleLst")
public BaseResponse sltArticleLst(ArticleInfo article, int current, int size, int sort) {
BaseResponse baseResponse = new BaseResponse();
Page<ArticleInfo> page = new Page<>(current, size);
Page<ArticleInfo> articlePagePage = new Page<>();
QueryWrapper query=new QueryWrapper();
if(StringUtils.isEmpty(article.getTitle())){
article.setTitle(null);
}else{
query.like("title",article.getTitle());
}

if (sort == 1) {
query.orderByDesc("createdtime");
}
if (sort == 2) {
query.orderByAsc("createdtime");
}
articlePagePage = articleInfoService.page(page, query);
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;
}

/**
* 根据患者获取推送的文章
*/
@PostMapping("getPushArt")
// public BaseResponse getPushArt(LymsPushedart pushedart) {
// BaseResponse baseResponse = new BaseResponse();
// List<LymsPushedart> pLst = lymsPushedartService.list(Wrappers.query(pushedart).orderByDesc("createdtime"));
// List idLst = new ArrayList();
// pLst.forEach(e -> {
// idLst.add(e.getAid());
// });
// if (idLst.size() > 0) {
// List<LymsArticle> aLst = lymsArticleService.listByIds(idLst);
//
// //赋值已读未读
// pLst.forEach(p->{
// aLst.forEach(a->{
// if(p.getAid()==a.getAid()){
// a.setStat(p.getIsread());
// }
// });
// });
//
// baseResponse.setObject(aLst);
// }
// return baseResponse;
// }
public BaseResponse getPushArt(@RequestBody GetpushartInfo getpushartInfo) {
BaseResponse baseResponse = new BaseResponse();
List<GetpushartInfo> getpushartInfoList= getpushartInfoService.list(Wrappers.query(getpushartInfo).orderByDesc("createdtime"));
baseResponse.setObject(getpushartInfoList);
return baseResponse;
}

/**
* 统计文章
*
* @return
*/
@GetMapping("getArtStat")
public BaseResponse getArtStat() {
BaseResponse baseResponse = new BaseResponse();
List<Map<String, Object>> aLst = lymsArticleService.getArtStat();
baseResponse.setObject(aLst);
return baseResponse;
}

/**
* 专家组推荐统计
* @return
*/
@GetMapping("getArtPushStat")
public BaseResponse getArtPushStat(){
BaseResponse baseResponse=new BaseResponse();

Map<String, Object> pMap = lymsArticleService.getArtPushStat();
baseResponse.setObject(pMap);

return baseResponse;
}
/**
* 专家组推荐-推荐记录
*
* @return
*/
@GetMapping("getPushedartlogsInfo")
public BaseResponse getPushedartlogsInfo(PushedartlogsInfo pushedartlogsInfo, Integer current, Integer size){
BaseResponse baseResponse=new BaseResponse();
try {
Page<PushedartlogsInfo> page=new Page<>(current,size);
Page<PushedartlogsInfo> pushedartlogsInfoPage=pushedartlogsInfoService.page(page,Wrappers.query(pushedartlogsInfo).orderByDesc("createdtime"));
baseResponse.setObject(pushedartlogsInfoPage);
baseResponse.setErrormsg("成功");
} catch (Exception e) {
baseResponse.setErrormsg("失败");
e.printStackTrace();
}
return baseResponse;
}
/**
* 根据患者id,问诊id,状态类型1为已读更新推送文章记录
*/
@PostMapping("updatePushedartlogs")
public BaseResponse updatePushedartlogs(@RequestBody LymsPushedart pushedart) {
BaseResponse baseResponse=new BaseResponse();
try {
UpdateWrapper<LymsPushedart> updateWrapper = new UpdateWrapper<>();
pushedart.setReadtime(new Date());
updateWrapper.eq("pid",pushedart.getPid()).eq("aid", pushedart.getAid());
boolean f=lymsPushedartService.update(pushedart,updateWrapper);
baseResponse.setErrorcode(f==true?0:1);
baseResponse.setErrormsg(f==true?"成功":"失败");
} catch (Exception e) {
baseResponse.setErrorcode(1);
baseResponse.setErrormsg("失败");
e.printStackTrace();
}

return baseResponse;
}

}