diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/HXTask.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/HXTask.java new file mode 100644 index 0000000..721922e --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/HXTask.java @@ -0,0 +1,53 @@ +package com.lyms.talkonlineweb.task; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.lyms.talkonlineweb.domain.LymsDoctor; +import com.lyms.talkonlineweb.domain.LymsPushedart; +import com.lyms.talkonlineweb.service.LymsArticleService; +import com.lyms.talkonlineweb.service.LymsDoctorService; +import com.lyms.talkonlineweb.service.LymsPushedartService; +import com.lyms.talkonlineweb.service.PatientInfoService; +import com.lyms.talkonlineweb.util.HXService; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +@Component +@Log4j2 +public class HXTask { + @Autowired + private LymsDoctorService lymsDoctorService; + + @Autowired + private HXService hxService; + +// @Scheduled(initialDelay=1000, fixedRate=5000) + public void checkDoctorStat(){ + List dLst=lymsDoctorService.list(); + List 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 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); + + }); + + } +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/HXService.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/HXService.java index 545950b..480ba52 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/HXService.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/HXService.java @@ -299,13 +299,27 @@ public class HXService { return rs; } + /** + * 批量获取用户状态 + * @param usernames + * @return + */ + public JSONObject chkUserStatus(String[] usernames) { + JSONObject rs=new JSONObject(); + Map param=new HashMap<>(); + HttpHeaders headers=new HttpHeaders(); - public static void main(String[] args) { - String url="http://ebs-chatmessage-a1.easemob.com/history/7D/1135210903239178/demo/2021090617.gz?Expires=1630978921&OSSAccessKeyId=LTAI4Fy3Zj6ha5XFZEMdRidM&Signature=DvTfmFwCqE9HcjE5eAZCrBfpJLg%3D"; - String preStr=url.split("\\?")[0]; - System.out.println(preStr); - String[] preArr=preStr.split("/"); - System.out.println(preArr[preArr.length-1]); -} + headers.add("Authorization","Bearer "+getToken()); + List lParam=new ArrayList(); + param.put("usernames", usernames); + lParam.add(param); + HttpEntity entity=new HttpEntity(param,headers); + resp=restTemplate.postForEntity(getUrl()+"users/batch/status",entity,String.class); + if (resp.getStatusCodeValue()==200){ + rs= JSON.parseObject(resp.getBody()); + } + log.info(rs); + return rs; + } }