Commit 4c5354c1c192b89631beed8d8477efdb4a0ed498

Authored by changpengfei
1 parent a3b2e42eea
Exists in master

添加定时任务开关

Showing 2 changed files with 60 additions and 39 deletions

talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/HXTask.java View file @ 4c5354c
... ... @@ -2,21 +2,17 @@
2 2  
3 3 import com.alibaba.fastjson.JSONObject;
4 4 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  5 +import com.lyms.talkonlineweb.domain.LymsDict;
5 6 import com.lyms.talkonlineweb.domain.LymsDoctor;
6 7 import com.lyms.talkonlineweb.domain.LymsPushedart;
7   -import com.lyms.talkonlineweb.service.LymsArticleService;
8   -import com.lyms.talkonlineweb.service.LymsDoctorService;
9   -import com.lyms.talkonlineweb.service.LymsPushedartService;
10   -import com.lyms.talkonlineweb.service.PatientInfoService;
  8 +import com.lyms.talkonlineweb.service.*;
11 9 import com.lyms.talkonlineweb.util.HXService;
12 10 import lombok.extern.log4j.Log4j2;
13 11 import org.springframework.beans.factory.annotation.Autowired;
14 12 import org.springframework.scheduling.annotation.Scheduled;
15 13 import org.springframework.stereotype.Component;
16 14  
17   -import java.util.Arrays;
18   -import java.util.Date;
19   -import java.util.List;
  15 +import java.util.*;
20 16 import java.util.stream.Collectors;
21 17  
22 18 @Component
23 19  
24 20  
25 21  
26 22  
... ... @@ -28,26 +24,36 @@
28 24 @Autowired
29 25 private HXService hxService;
30 26  
  27 + @Autowired
  28 + private LymsDictService lymsDictService;
  29 +
31 30 @Scheduled(initialDelay=1000, fixedRate=5000)
32 31 public void checkDoctorStat(){
33   - List<LymsDoctor> dLst=lymsDoctorService.list();
34   - List<String> dlLst=dLst.stream().map(d->d.getDlogin()).collect(Collectors.toList());
35   - String[] usernames = new String[dlLst.size()];
36   - JSONObject jsonObject=hxService.chkUserStatus(dlLst.toArray(usernames));
  32 + Map<String,Object> param=new HashMap<>();
37 33  
38   - jsonObject.getJSONArray("data").stream().forEach(e->{
39   - UpdateWrapper<LymsDoctor> updateWrapper = new UpdateWrapper<>();
40   - LymsDoctor doctor=new LymsDoctor();
41   - String[] json=e.toString().replaceAll("\\{","").replaceAll("}","").split(":");
42   - if("online".equals(json[1].replaceAll("\"",""))){
43   - doctor.setStat((byte) 1);
44   - }else {
45   - doctor.setStat((byte)0);
  34 + param.put("vtype",999);
  35 + List<LymsDict> dcLst=lymsDictService.listByMap(param);
  36 + if (dcLst.size()>0 && dcLst.get(0).getCode()==1){
  37 + List<LymsDoctor> dLst=lymsDoctorService.list();
  38 + List<String> dlLst=dLst.stream().map(d->d.getDlogin()).collect(Collectors.toList());
  39 + String[] usernames = new String[dlLst.size()];
  40 + JSONObject jsonObject=hxService.chkUserStatus(dlLst.toArray(usernames));
  41 +
  42 + jsonObject.getJSONArray("data").stream().forEach(e->{
  43 + UpdateWrapper<LymsDoctor> updateWrapper = new UpdateWrapper<>();
  44 + LymsDoctor doctor=new LymsDoctor();
  45 + String[] json=e.toString().replaceAll("\\{","").replaceAll("}","").split(":");
  46 + if("online".equals(json[1].replaceAll("\"",""))){
  47 + doctor.setStat((byte) 1);
  48 + }else {
  49 + doctor.setStat((byte)0);
  50 + }
  51 + updateWrapper.eq("dlogin",json[0].replaceAll("\"",""));
  52 + boolean f=lymsDoctorService.update(doctor,updateWrapper);
  53 +
  54 + });
46 55 }
47   - updateWrapper.eq("dlogin",json[0].replaceAll("\"",""));
48   - boolean f=lymsDoctorService.update(doctor,updateWrapper);
49 56  
50   - });
51 57  
52 58 }
53 59 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushArticleTask.java View file @ 4c5354c
... ... @@ -2,9 +2,11 @@
2 2  
3 3 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
4 4 import com.lyms.talkonlineweb.domain.LymsArticle;
  5 +import com.lyms.talkonlineweb.domain.LymsDict;
5 6 import com.lyms.talkonlineweb.domain.LymsPushedart;
6 7 import com.lyms.talkonlineweb.domain.PatientInfo;
7 8 import com.lyms.talkonlineweb.service.LymsArticleService;
  9 +import com.lyms.talkonlineweb.service.LymsDictService;
8 10 import com.lyms.talkonlineweb.service.LymsPushedartService;
9 11 import com.lyms.talkonlineweb.service.PatientInfoService;
10 12 import lombok.extern.log4j.Log4j2;
11 13  
... ... @@ -13,7 +15,9 @@
13 15 import org.springframework.stereotype.Component;
14 16  
15 17 import java.util.Date;
  18 +import java.util.HashMap;
16 19 import java.util.List;
  20 +import java.util.Map;
17 21  
18 22 /**
19 23 * 推送文章任务
20 24  
21 25  
22 26  
23 27  
24 28  
... ... @@ -30,26 +34,37 @@
30 34 @Autowired
31 35 private LymsPushedartService lymsPushedartService;//推送的历史记录
32 36  
  37 + @Autowired
  38 + private LymsDictService lymsDictService;
  39 +
33 40 @Scheduled(initialDelay=1000, fixedRate=5000)
34 41 public void pushArtcle(){
35   - log.debug("开始给患者推送文章>>>>>>");
36   - List<LymsArticle> aLst=lymsArticleService.sltNeedPush();//获取待推送文章
37 42  
38   - aLst.forEach(e->{
39   - PatientInfo patientInfo=new PatientInfo();
40   - patientInfo.setIid(e.getIid());//针对特定疾病人群推送文章
41   - List<PatientInfo> pLst=patientInfoService.list(Wrappers.query(patientInfo));
  43 + Map<String,Object> param=new HashMap<>();
42 44  
43   - pLst.forEach(p->{
44   - LymsPushedart pushedart=new LymsPushedart();
45   - pushedart.setPid(p.getId());
46   - pushedart.setAid(e.getAid());
47   - pushedart.setCreatedtime(new Date());
48   - pushedart.setIsread((byte) 0);
49   - lymsPushedartService.save(pushedart);//插入到提送记录
  45 + param.put("vtype",999);
  46 + List<LymsDict> dcLst=lymsDictService.listByMap(param);
  47 + if (dcLst.size()>0 && dcLst.get(0).getCode()==1){
  48 + log.debug("开始给患者推送文章>>>>>>");
  49 + List<LymsArticle> aLst=lymsArticleService.sltNeedPush();//获取待推送文章
  50 +
  51 + aLst.forEach(e->{
  52 + PatientInfo patientInfo=new PatientInfo();
  53 + patientInfo.setIid(e.getIid());//针对特定疾病人群推送文章
  54 + List<PatientInfo> pLst=patientInfoService.list(Wrappers.query(patientInfo));
  55 +
  56 + pLst.forEach(p->{
  57 + LymsPushedart pushedart=new LymsPushedart();
  58 + pushedart.setPid(p.getId());
  59 + pushedart.setAid(e.getAid());
  60 + pushedart.setCreatedtime(new Date());
  61 + pushedart.setIsread((byte) 0);
  62 + lymsPushedartService.save(pushedart);//插入到提送记录
  63 + });
  64 +
50 65 });
  66 + }
51 67  
52   - });
53 68 }
54 69 }