HXTask.java 4.02 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
package com.lyms.talkonlineweb.task;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyms.talkonlineweb.domain.LymsDict;
import com.lyms.talkonlineweb.domain.LymsDoctor;
import com.lyms.talkonlineweb.domain.LymsPushedart;
import com.lyms.talkonlineweb.service.*;
import com.lyms.talkonlineweb.util.HXService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.stream.Collectors;

/**
* 医生状态
*/
@Component
@Log4j2
public class HXTask {
@Value("${getAccessToken.on_off}")
public boolean on_off;//配置yml 微信公众号获取access_token(测试环境部署不要开启。会与线上环境冲突)

@Autowired
private LymsDoctorService lymsDoctorService;

@Autowired
private HXService hxService;

@Autowired
private LymsDictService lymsDictService;

@Scheduled(initialDelay=10000, fixedRate=60000)
public void checkDoctorStat(){
if(!on_off){
return;
}

Map<String,Object> param=new HashMap<>();

param.put("vtype",999);
List<LymsDict> dcLst=lymsDictService.listByMap(param);
if (dcLst.size()>0 && dcLst.get(0).getCode()==1){
/*List<LymsDoctor> dLst=lymsDoctorService.list();
List<String> dlLst=dLst.stream().map(d->d.getDlogin()).collect(Collectors.toList());
String[] usernames = new String[dlLst.size()];
JSONObject jsonObject=hxService.chkUserStatus(dlLst.toArray(usernames));

jsonObject.getJSONArray("data").stream().forEach(e->{
UpdateWrapper<LymsDoctor> updateWrapper = new UpdateWrapper<>();
LymsDoctor doctor=new LymsDoctor();
String[] json=e.toString().replaceAll("\\{","").replaceAll("}","").split(":");
if("online".equals(json[1].replaceAll("\"",""))){
doctor.setStat((byte) 1);
}else {
doctor.setStat((byte)0);
}
updateWrapper.eq("dlogin",json[0].replaceAll("\"",""));
boolean f=lymsDoctorService.update(doctor,updateWrapper);

});*/

QueryWrapper<LymsDoctor> query = new QueryWrapper();
query.isNotNull("hxid");
query.orderByAsc("updated_time");
int count = this.lymsDoctorService.count(query);

int page = (int)Math.ceil((double)count / 50.0);

for(int i = 1; i <= page; ++i) {
Page<LymsDoctor> pageC = new Page((long)i, 50L);
Page<LymsDoctor> pageDoctors = (Page)this.lymsDoctorService.page(pageC, query);
List<LymsDoctor> dLst = pageDoctors.getRecords();
List<String> dlLst=dLst.stream().map(d->d.getDlogin()).collect(Collectors.toList());
String[] usernames = new String[dlLst.size()];
JSONObject jsonObject = this.hxService.chkUserStatus((String[])dlLst.toArray(usernames));
jsonObject.getJSONArray("data").stream().forEach((e) -> {
UpdateWrapper<LymsDoctor> updateWrapper = new UpdateWrapper();
LymsDoctor doctor = new LymsDoctor();
String[] json = e.toString().replaceAll("\\{", "").replaceAll("}", "").split(":");
if ("online".equals(json[1].replaceAll("\"", ""))) {
doctor.setStat((byte)1);
} else {
doctor.setStat((byte)0);
}

updateWrapper.eq("dlogin", json[0].replaceAll("\"", ""));
this.lymsDoctorService.update(doctor, updateWrapper);
});
}
}


}
}