ArticleController.java 15.1 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
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
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.*;
import com.lyms.talkonlineweb.service.impl.PushedartlogsInfoServiceImpl;
import com.lyms.talkonlineweb.util.StringUtil;
import com.lyms.talkonlineweb.util.WeiXinUtil;
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.context.annotation.RequestScope;
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;//小程序用户端-根据患者获取推送的文章-视图

@Autowired
private LymsPushMessagesService lymsPushMessagesService;

@Autowired
private LymsPatientService lymsPatientService;

/**
* 上传文件
*
* @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);
baseResponse.setErrorcode(f == true ? 0 : 1);
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.getIid())){
query.eq("iid",article.getIid());
}
if(!StringUtils.isEmpty(article.getAid())){
query.eq("aid",article.getAid());
}

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;
}
/**
* 文章标题是否重复
* @param aid 修改时用
* @param iid 疾病id
* @param title 文章标题
* @return true 可以使用,false已经存在
*/
@GetMapping("getTitleYn")
public BaseResponse getTitleYn(@RequestParam(required = false) Integer aid,
@RequestParam(required = true) Integer iid,
@RequestParam(required = true) String title){//加@RequestParam 能解决乱码问题
BaseResponse baseResponse=new BaseResponse();
try {
QueryWrapper<LymsArticle> queryWrapper=new QueryWrapper<>();
queryWrapper.eq("iid", iid);
queryWrapper.eq("title", title);
if(null!=aid){//修改的时候判断是否重复
LymsArticle Article=lymsArticleService.getOne(queryWrapper);
QueryWrapper<LymsArticle> queryWrapper2=new QueryWrapper<>();
queryWrapper2.eq("aid", aid);
LymsArticle Article2=lymsArticleService.getOne(queryWrapper2);
baseResponse.setObject(null==Article?true:(Article2.getTitle().equals(title)?true:false));
}else {
LymsArticle Article=lymsArticleService.getOne(queryWrapper);
baseResponse.setObject(null==Article?true:false);
}
baseResponse.setErrormsg("成功");
} catch (Exception e) {
baseResponse.setErrormsg("失败");
e.printStackTrace();
}
return baseResponse;
}
/**
* 文章序号是否重复
* @param aid 修改时用
* @param iid 疾病id
* @param serialNumber 序号(1-100)
* @return true 可以使用,false已经存在
*/
@GetMapping("getSerialNumberYn")
public BaseResponse getSerialNumberYn(@RequestParam(required = false) Integer aid, Integer iid,Integer serialNumber){
BaseResponse baseResponse=new BaseResponse();
try {
QueryWrapper<LymsArticle> queryWrapper=new QueryWrapper<>();
queryWrapper.eq("iid", iid);
queryWrapper.eq("serial_number", serialNumber);
if(null!=aid){//修改的时候判断是否重复
LymsArticle Article=lymsArticleService.getOne(queryWrapper);
QueryWrapper<LymsArticle> queryWrapper2=new QueryWrapper<>();
queryWrapper2.eq("aid", aid);
LymsArticle Article2=lymsArticleService.getOne(queryWrapper2);
baseResponse.setObject(null==Article?true:(Article2.getSerialNumber().equals(serialNumber)?true:false));
}else {
LymsArticle Article=lymsArticleService.getOne(queryWrapper);
baseResponse.setObject(null==Article?true:false);
}
baseResponse.setErrormsg("成功");
} catch (Exception e) {
baseResponse.setErrormsg("失败");
e.printStackTrace();
}
return baseResponse;
}
/**
* 根据疾病iid获取文章序号
* @param iid 疾病id
* @return int serialNumber(0-100)
*/
@GetMapping("getSerialNumber")
public BaseResponse getSerialNumber(Integer iid){
BaseResponse baseResponse=new BaseResponse();
try {
Integer serialNumber=lymsArticleService.getSerialNumber(iid);
if(null==serialNumber){
baseResponse.setObject(1);
}else {
if(serialNumber<100){//序号100的时候返回null(前端处理不许再添加)
baseResponse.setObject(serialNumber+1);
}
}
baseResponse.setErrorcode(0);
baseResponse.setErrormsg("成功");
} catch (Exception e) {
baseResponse.setErrorcode(1);
baseResponse.setErrormsg("失败");
e.printStackTrace();
}
return baseResponse;
}

/**
* 新推送记录列表
*
* @return
*/
@GetMapping("getLymsPushMessages")
public BaseResponse getLymsPushMessages(LymsPushMessages lymsPushMessages, Integer current, Integer size){
BaseResponse baseResponse=new BaseResponse();
try {
Page<LymsPushMessages> page=new Page<>(current,size);
QueryWrapper<LymsPushMessages> queryWrapper = new QueryWrapper<>();
queryWrapper.setEntity(lymsPushMessages);
if(null!=lymsPushMessages.getStartDate()&&null!=lymsPushMessages.getEndDate()){
queryWrapper.ge("push_time", lymsPushMessages.getStartDate()).le("push_time",lymsPushMessages.getEndDate());
}
queryWrapper.orderByDesc("push_time");
Page<LymsPushMessages> lymsPushMessagesPage=lymsPushMessagesService.page(page,queryWrapper);
baseResponse.setObject(lymsPushMessagesPage);
baseResponse.setErrormsg("成功");
} catch (Exception e) {
baseResponse.setErrormsg("失败");
e.printStackTrace();
}
return baseResponse;
}

/**
* 登录小程序后获取小程序关联公众号的OpenId
* 同时检查是否关注了公众号
* @return
*/
@GetMapping("getGZOpenId")
public BaseResponse getGZOpenId(LymsPatient patient){
BaseResponse baseResponse=new BaseResponse();
try {
if(StringUtil.isNotEmpty(patient.getCode())&&null!=patient.getId()){
String openid = WeiXinUtil.getWxGzOpenId(patient.getCode());
if(StringUtil.isNotEmpty(openid)){
patient.setGzopenid(openid);
//更新到登录患者的gzopenid
lymsPatientService.updateById(patient);
//检查是否关注了公众号
String subscribe = WeiXinUtil.getIsWxGZH(openid);
if(StringUtil.isNotEmpty(subscribe)){
baseResponse.setObject(subscribe);
baseResponse.setErrormsg("成功");
return baseResponse;
}
}
}
} catch (Exception e) {
baseResponse.setErrorcode(1);
baseResponse.setErrormsg("失败");
e.printStackTrace();
}
baseResponse.setErrorcode(1);
baseResponse.setErrormsg("失败");
return baseResponse;
}

}