Commit 29fd8c723daeefd574b30b3190404c7ec7221750
1 parent
6c11211fba
Exists in
master
and in
1 other branch
检查医生是否在线
Showing 2 changed files with 74 additions and 7 deletions
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/HXTask.java
View file @
29fd8c7
| 1 | +package com.lyms.talkonlineweb.task; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | |
| 5 | +import com.lyms.talkonlineweb.domain.LymsDoctor; | |
| 6 | +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; | |
| 11 | +import com.lyms.talkonlineweb.util.HXService; | |
| 12 | +import lombok.extern.log4j.Log4j2; | |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | +import org.springframework.scheduling.annotation.Scheduled; | |
| 15 | +import org.springframework.stereotype.Component; | |
| 16 | + | |
| 17 | +import java.util.Arrays; | |
| 18 | +import java.util.Date; | |
| 19 | +import java.util.List; | |
| 20 | +import java.util.stream.Collectors; | |
| 21 | + | |
| 22 | +@Component | |
| 23 | +@Log4j2 | |
| 24 | +public class HXTask { | |
| 25 | + @Autowired | |
| 26 | + private LymsDoctorService lymsDoctorService; | |
| 27 | + | |
| 28 | + @Autowired | |
| 29 | + private HXService hxService; | |
| 30 | + | |
| 31 | +// @Scheduled(initialDelay=1000, fixedRate=5000) | |
| 32 | + 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)); | |
| 37 | + | |
| 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); | |
| 46 | + } | |
| 47 | + updateWrapper.eq("dlogin",json[0].replaceAll("\"","")); | |
| 48 | + boolean f=lymsDoctorService.update(doctor,updateWrapper); | |
| 49 | + | |
| 50 | + }); | |
| 51 | + | |
| 52 | + } | |
| 53 | +} |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/HXService.java
View file @
29fd8c7
| ... | ... | @@ -299,14 +299,28 @@ |
| 299 | 299 | return rs; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | + /** | |
| 303 | + * 批量获取用户状态 | |
| 304 | + * @param usernames | |
| 305 | + * @return | |
| 306 | + */ | |
| 307 | + public JSONObject chkUserStatus(String[] usernames) { | |
| 308 | + JSONObject rs=new JSONObject(); | |
| 309 | + Map<String,Object> param=new HashMap<>(); | |
| 310 | + HttpHeaders headers=new HttpHeaders(); | |
| 302 | 311 | |
| 303 | - public static void main(String[] args) { | |
| 304 | - String url="http://ebs-chatmessage-a1.easemob.com/history/7D/1135210903239178/demo/2021090617.gz?Expires=1630978921&OSSAccessKeyId=LTAI4Fy3Zj6ha5XFZEMdRidM&Signature=DvTfmFwCqE9HcjE5eAZCrBfpJLg%3D"; | |
| 305 | - String preStr=url.split("\\?")[0]; | |
| 306 | - System.out.println(preStr); | |
| 307 | - String[] preArr=preStr.split("/"); | |
| 308 | - System.out.println(preArr[preArr.length-1]); | |
| 309 | -} | |
| 312 | + headers.add("Authorization","Bearer "+getToken()); | |
| 313 | + List lParam=new ArrayList(); | |
| 314 | + param.put("usernames", usernames); | |
| 310 | 315 | |
| 316 | + lParam.add(param); | |
| 317 | + HttpEntity entity=new HttpEntity(param,headers); | |
| 318 | + resp=restTemplate.postForEntity(getUrl()+"users/batch/status",entity,String.class); | |
| 319 | + if (resp.getStatusCodeValue()==200){ | |
| 320 | + rs= JSON.parseObject(resp.getBody()); | |
| 321 | + } | |
| 322 | + log.info(rs); | |
| 323 | + return rs; | |
| 324 | + } | |
| 311 | 325 | } |