Commit a15a89b3c59b809ad62abf3dc915eaa2285aa568

Authored by shiyang
1 parent 97e6a9b254
Exists in master and in 1 other branch dev

自动回访功能。聊天BUG修复

Showing 10 changed files with 671 additions and 94 deletions

talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/ChatGroupController.java View file @ a15a89b
... ... @@ -22,6 +22,7 @@
22 22 import org.apache.commons.lang3.StringUtils;
23 23 import org.springframework.beans.BeanUtils;
24 24 import org.springframework.beans.factory.annotation.Autowired;
  25 +import org.springframework.transaction.annotation.Transactional;
25 26 import org.springframework.web.bind.annotation.*;
26 27  
27 28 import javax.servlet.http.HttpServletRequest;
... ... @@ -77,6 +78,7 @@
77 78 @TokenRequired
78 79 public BaseResponse saveChatGroup(@RequestBody LymsChatgroup group) {
79 80 BaseResponse baseResponse = new BaseResponse();
  81 + String retDlogin=group.getRetDlogin();
80 82 List<LymsChatgroup> gLst = lymsChatgroupService.list(Wrappers.query(group).orderByDesc("id"));
81 83 if (group.getOwnerk() == null) {
82 84 group.setOwnerk("test");
83 85  
84 86  
... ... @@ -88,12 +90,36 @@
88 90 if (gLst.size() > 0) {
89 91 LymsChatgroup group2 = gLst.get(0);
90 92 group = group2;
91   - //回访的状态才去执行
92   - if (1==gLst.get(0).getType()) {
93   - group2.setStat(0);
  93 + //回访的状态才去执行(上次关闭了再次点击会开启)
  94 + if (1==group.getType()&&group.getStat()==1) {
  95 + group.setStat(0);
94 96 //修改群组状态
95   - lymsChatgroupService.updateById(group2);
  97 + lymsChatgroupService.updateById(group);
  98 + //添加回访记录
  99 + LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord();
  100 + returnVisitRecord.setDlogin(retDlogin);//前端传的当前登录医生账号
  101 + returnVisitRecord.setDpid(doctor.getDpid());
  102 + returnVisitRecord.setIdno(patient.getIdno());
  103 + returnVisitRecord.setType(1);
  104 + returnVisitRecord.setPcid(group.getPcid());
  105 + returnVisitRecord.setHxgroupid(group.getHxgroupid());
  106 + lymsReturnVisitRecordService.save(returnVisitRecord);
96 107 }
  108 + //患者消费问诊卡 咨询结束后
  109 + if(0==group.getType()){
  110 +
  111 + group.setType(1);
  112 + lymsChatgroupService.updateById(group);
  113 + //添加回访记录
  114 + LymsReturnVisitRecord returnVisitRecord2 = new LymsReturnVisitRecord();
  115 + returnVisitRecord2.setDlogin(retDlogin);//前端传的当前登录医生账号
  116 + returnVisitRecord2.setDpid(doctor.getDpid());
  117 + returnVisitRecord2.setIdno(patient.getIdno());
  118 + returnVisitRecord2.setType(1);
  119 + returnVisitRecord2.setPcid(group.getPcid());
  120 + returnVisitRecord2.setHxgroupid(group.getHxgroupid());
  121 + lymsReturnVisitRecordService.save(returnVisitRecord2);
  122 + }
97 123 } else {
98 124 List<String> adminDlogins=new ArrayList<>();
99 125 adminDlogins.add(group.getFromp());
... ... @@ -111,7 +137,8 @@
111 137 //查询值班医生
112 138 List<LymsDoctor> doctorAminList= lymsDoctorService.list(new QueryWrapper<LymsDoctor>()
113 139 .lambda().eq(LymsDoctor::getDpid, doctor.getDpid())
114   - .in(LymsDoctor::getAdminType, new int[]{1,2}));
  140 + .in(LymsDoctor::getAdminType, new int[]{1,2})
  141 + .orderByAsc(LymsDoctor::getAdminType));
115 142 //科室值班医生注册环信
116 143 for (LymsDoctor lymsDoctor : doctorAminList) {
117 144 if(StringUtil.isEmpty(lymsDoctor.getHxid())) {
... ... @@ -146,7 +173,6 @@
146 173 group.setDescription(StringUtils.join(adminDlogins.toArray(), ","));
147 174 //环信群组名称更改为姓名串-用于PC端问诊展示
148 175 group.setGroupname(StringUtils.join(groupnames.toArray(), ","));
149   -
150 176 group.setCtime(new Date());
151 177 lymsChatgroupService.saveOrUpdate(group);
152 178 }
... ... @@ -420,7 +446,8 @@
420 446 final LymsChatgroup chatgroup = lymsChatgroupService.getOne(new QueryWrapper<LymsChatgroup>()
421 447 .lambda().eq(LymsChatgroup::getHxgroupid, groupId));
422 448 final LymsTkrecord tkrecord = lymsTkrecordService.getOne(new QueryWrapper<LymsTkrecord>()
423   - .lambda().eq(LymsTkrecord::getHxgroupid, groupId));
  449 + .lambda().eq(LymsTkrecord::getHxgroupid, groupId)
  450 + .groupBy(LymsTkrecord::getHxgroupid));
424 451 Map<String,Object> map= new LinkedHashMap<>();
425 452 map.put("groupStat",null==chatgroup?"":chatgroup.getStat());
426 453 map.put("tkrecordStat",null==tkrecord?"":tkrecord.getStat());
427 454  
428 455  
429 456  
430 457  
... ... @@ -514,20 +541,82 @@
514 541 return baseResponse;
515 542 }
516 543 /**
517   - * 修改环信组状态 开启聊天
  544 + * 有回访记录时。患者消耗问诊卡修改环信组状态 并加问诊记录,开启聊天
518 545 * @param chatgroup
519 546 * @return
520 547 */
521 548 @PostMapping("updateGroupStat")
522 549 @TokenRequired
  550 + @Transactional(rollbackFor = Exception.class)
523 551 public BaseResponse updateGroupStat(@RequestBody LymsChatgroup chatgroup){
524 552 BaseResponse baseResponse =new BaseResponse();
525 553 try {
526 554 final boolean b = lymsChatgroupService.updateById(chatgroup);
527   - baseResponse.setErrorcode(b?0:1);
528   - baseResponse.setErrormsg(b?"成功":"失败");
  555 + if(!b){
  556 + baseResponse.setErrorcode(1);
  557 + throw new RuntimeException("回滚状态,执行失败,请联系管理员");
  558 + }
  559 + final PatientInfo patientInfo = patientInfoService.getOne(new QueryWrapper<PatientInfo>()
  560 + .lambda().eq(PatientInfo::getCid, chatgroup.getPcid()));
  561 + if (null==patientInfo) {
  562 + baseResponse.setErrorcode(1);
  563 + throw new RuntimeException("回滚状态,执行失败,请联系管理员");
  564 + }
  565 + LymsTkrecord tkrecord=new LymsTkrecord();
  566 + LymsTcard tcard = new LymsTcard();
  567 + tcard.setPid(patientInfo.getId());
  568 + tcard.setPcid(patientInfo.getCid());
  569 +// 获取问诊卡按照先从医院购买的问诊卡消费
  570 + List<LymsTcard> rLst = lymsTcardService.list(Wrappers.query(tcard).notInSql("id", "SELECT r.cid FROM lyms_tkrecord r").orderByDesc("fid"));
  571 +
  572 +// 小程序购买的问诊卡
  573 + tcard.setPcid(null);
  574 + tcard.setFid(1);
  575 + List<LymsTcard> xLst = lymsTcardService.list(Wrappers.query(tcard).notInSql("id", "SELECT r.cid FROM lyms_tkrecord r").orderByDesc("fid"));
  576 +
  577 + if (rLst.size() > 0 || xLst.size() > 0) {
  578 + if (rLst.size() > 0) {
  579 + tkrecord.setCid(rLst.get(0).getId());
  580 + tkrecord.setFid((byte) 2);
  581 + } else {
  582 + tkrecord.setCid(xLst.get(0).getId());
  583 + tkrecord.setFid((byte) 1);
  584 + }
  585 +
  586 + } else {
  587 + baseResponse.setErrorcode(1);
  588 + throw new RuntimeException("已经没有咨询卡,请联系客服购买!");
  589 + }
  590 +
  591 + tkrecord.setPid(patientInfo.getId());
  592 + tkrecord.setPcid(patientInfo.getCid());
  593 + tkrecord.setDid(patientInfo.getDtid());
  594 + tkrecord.setDid(patientInfo.getDtid());
  595 + tkrecord.setHxgroupid(chatgroup.getHxgroupid());
  596 + tkrecord.setCreatedtime(new Date());
  597 + final boolean save = lymsTkrecordService.save(tkrecord);
  598 + if (!save) {
  599 + baseResponse.setErrorcode(1);
  600 + throw new RuntimeException("回滚状态,执行失败,请联系管理员");
  601 + }
  602 + //修改同一群组记录的状态
  603 + final List<LymsTkrecord> tkrecordList = lymsTkrecordService.list(new QueryWrapper<LymsTkrecord>()
  604 + .lambda().eq(LymsTkrecord::getHxgroupid, chatgroup.getHxgroupid()));
  605 + for (LymsTkrecord lymsTkrecord : tkrecordList) {
  606 + lymsTkrecord.setStat(0);
  607 + final boolean saveOrUpdate = lymsTkrecordService.updateById(lymsTkrecord);
  608 + if (!saveOrUpdate) {
  609 + baseResponse.setErrorcode(1);
  610 + throw new RuntimeException("回滚状态,执行失败,请联系管理员");
  611 + }
  612 + }
  613 + baseResponse.setErrorcode(0);
  614 + baseResponse.setErrormsg("成功");
529 615 } catch (Exception e) {
  616 + baseResponse.setErrorcode(1);
530 617 e.printStackTrace();
  618 + //这里想触发事务回滚需抛运行时异常
  619 + throw new RuntimeException("回滚状态,执行失败,请联系管理员");
531 620 }
532 621 return baseResponse;
533 622 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/CommonController.java View file @ a15a89b
... ... @@ -63,7 +63,10 @@
63 63 tkrecord.setUpdatedby(updateby);
64 64 tkrecord.setHxgroupid(hxgroupid);
65 65 boolean f=lymsTkrecordService.saveOrUpdate(tkrecord);
66   -
  66 + LymsChatgroup lymsChatgroup= new LymsChatgroup();
  67 + lymsChatgroup.setId(gLst.get(0).getId());
  68 + lymsChatgroup.setStat(1);
  69 + lymsChatgroupService.updateById(lymsChatgroup);
67 70 baseResponse.setErrorcode(f==true?0:1);
68 71 }else {
69 72 if (CollectionUtils.isNotEmpty(gLst) && gLst.get(0).getType()==1) {
talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/TkRecordController.java View file @ a15a89b
... ... @@ -82,86 +82,98 @@
82 82 return baseResponse;
83 83 }
84 84 }
85   -
86 85 LymsChatgroup group =new LymsChatgroup();
87 86 LymsDoctor doctor=lymsDoctorService.getById(tkrecord.getDid());
88 87 LymsPatient patient=lymsPatientService.getById(tkrecord.getPid());
89   - group.setOwnerk("test");
90   - List<String> adminDlogins=new ArrayList<>();
91   - adminDlogins.add(patient.getIdno());
92   - List<String> groupnames=new ArrayList<>();
93   - groupnames.add(patient.getPname());
94   - //患者注册环信
95   - if (StringUtil.isEmpty(patient.getHxid())) {
96   - JSONObject json = hxService.addUser(patient.getIdno(), Constant.COMMON_PASSWD, patient.getPname());
97   - JSONArray rArr = json.getJSONArray("entities");
98   - if (rArr.size() > 0) {
99   - patient.setHxid(rArr.getJSONObject(0).getString("uuid"));
100   - lymsPatientService.updateById(patient);
101   - }
102   - }
103   - //查询值班医生/值班护士
104   - List<LymsDoctor> doctorAminList= lymsDoctorService.list(new QueryWrapper<LymsDoctor>()
105   - .lambda().eq(LymsDoctor::getDpid, doctor.getDpid())
106   - .in(LymsDoctor::getAdminType, Arrays.asList(1,2)));
107   - //科室值班医生注册环信
108   - for (LymsDoctor lymsDoctor : doctorAminList) {
109   - if(StringUtil.isEmpty(lymsDoctor.getHxid())) {
110   - JSONObject json = hxService.addUser(lymsDoctor.getDlogin(), Constant.COMMON_PASSWD, lymsDoctor.getDname());
  88 +
  89 + List<LymsChatgroup> gLst = lymsChatgroupService.list(new QueryWrapper<LymsChatgroup>()
  90 + .lambda().eq(LymsChatgroup::getPcid, tkrecord.getPcid()));
  91 + //之前有这个病例的问诊就不用新创建组
  92 + if (0==gLst.size()) {
  93 + group.setOwnerk("test");
  94 + List<String> adminDlogins=new ArrayList<>();
  95 + adminDlogins.add(patient.getIdno());
  96 + List<String> groupnames=new ArrayList<>();
  97 + groupnames.add(patient.getPname());
  98 + //患者注册环信
  99 + if (StringUtil.isEmpty(patient.getHxid())) {
  100 + JSONObject json = hxService.addUser(patient.getIdno(), Constant.COMMON_PASSWD, patient.getPname());
111 101 JSONArray rArr = json.getJSONArray("entities");
112 102 if (rArr.size() > 0) {
113   - lymsDoctor.setHxid(rArr.getJSONObject(0).getString("uuid"));
114   - lymsDoctorService.updateById(lymsDoctor);
  103 + patient.setHxid(rArr.getJSONObject(0).getString("uuid"));
  104 + lymsPatientService.updateById(patient);
115 105 }
116 106 }
117   - adminDlogins.add(lymsDoctor.getDlogin());
118   - groupnames.add(lymsDoctor.getDname());
119   - }
120   - if ( ! adminDlogins.contains(doctor.getDlogin())) {
121   - //医生注册环信
122   - if (StringUtil.isEmpty(doctor.getHxid())) {
123   - JSONObject json = hxService.addUser(doctor.getDlogin(), Constant.COMMON_PASSWD, doctor.getDname());
124   - JSONArray rArr = json.getJSONArray("entities");
125   - if (rArr.size() > 0) {
126   - doctor.setHxid(rArr.getJSONObject(0).getString("uuid"));
127   - lymsDoctorService.updateById(doctor);
  107 + //查询值班医生/值班护士
  108 + List<LymsDoctor> doctorAminList= lymsDoctorService.list(new QueryWrapper<LymsDoctor>()
  109 + .lambda().eq(LymsDoctor::getDpid, doctor.getDpid())
  110 + .in(LymsDoctor::getAdminType, Arrays.asList(1,2))
  111 + .orderByAsc(LymsDoctor::getAdminType));
  112 + //科室值班医生注册环信
  113 + for (LymsDoctor lymsDoctor : doctorAminList) {
  114 + if(StringUtil.isEmpty(lymsDoctor.getHxid())) {
  115 + JSONObject json = hxService.addUser(lymsDoctor.getDlogin(), Constant.COMMON_PASSWD, lymsDoctor.getDname());
  116 + JSONArray rArr = json.getJSONArray("entities");
  117 + if (rArr.size() > 0) {
  118 + lymsDoctor.setHxid(rArr.getJSONObject(0).getString("uuid"));
  119 + lymsDoctorService.updateById(lymsDoctor);
  120 + }
128 121 }
  122 + adminDlogins.add(lymsDoctor.getDlogin());
  123 + groupnames.add(lymsDoctor.getDname());
129 124 }
130   - adminDlogins.add(doctor.getDlogin());
131   - groupnames.add(doctor.getDname());
132   - }
  125 + if ( ! adminDlogins.contains(doctor.getDlogin())) {
  126 + //医生注册环信
  127 + if (StringUtil.isEmpty(doctor.getHxid())) {
  128 + JSONObject json = hxService.addUser(doctor.getDlogin(), Constant.COMMON_PASSWD, doctor.getDname());
  129 + JSONArray rArr = json.getJSONArray("entities");
  130 + if (rArr.size() > 0) {
  131 + doctor.setHxid(rArr.getJSONObject(0).getString("uuid"));
  132 + lymsDoctorService.updateById(doctor);
  133 + }
  134 + }
  135 + adminDlogins.add(doctor.getDlogin());
  136 + groupnames.add(doctor.getDname());
  137 + }
133 138  
134 139  
135   - log.info("创建环信组:{} description:{}", group.getOwnerk(), StringUtils.join(adminDlogins.toArray(), ","));
136   - JSONObject rJson = hxService.addChatGroups(StringUtils.join(adminDlogins.toArray(), ","), group.getOwnerk(), adminDlogins.toArray(new String[adminDlogins.size()]));
137   - log.info("rJson:" + rJson);
138   - group.setHxgroupid(rJson.getJSONObject("data").getString("groupid"));
139   - group.setDescription(StringUtils.join(adminDlogins.toArray(), ","));
140   - //环信群组名称更改为姓名串-用于PC端问诊展示
141   - group.setGroupname(StringUtils.join(groupnames.toArray(), ","));
142   - group.setFromp(patient.getIdno());
143   - group.setTarget(doctor.getDlogin());
144   - group.setRetDlogin(tkrecord.getRetDlogin());//前端传的当前登录医生账号
145   - group.setPcid(tkrecord.getPcid());
146   - if(null==tkrecord.getType()) {
147   - lymsChatgroupService.saveOrUpdate(group);
148   - lymsTkrecordService.save(tkrecord);
  140 + log.info("创建环信组:{} description:{}", group.getOwnerk(), StringUtils.join(adminDlogins.toArray(), ","));
  141 + JSONObject rJson = hxService.addChatGroups(StringUtils.join(adminDlogins.toArray(), ","), group.getOwnerk(), adminDlogins.toArray(new String[adminDlogins.size()]));
  142 + log.info("rJson:" + rJson);
  143 + group.setHxgroupid(rJson.getJSONObject("data").getString("groupid"));
  144 + group.setDescription(StringUtils.join(adminDlogins.toArray(), ","));
  145 + //环信群组名称更改为姓名串-用于PC端问诊展示
  146 + group.setGroupname(StringUtils.join(groupnames.toArray(), ","));
  147 + group.setFromp(patient.getIdno());
  148 + group.setTarget(doctor.getDlogin());
  149 + group.setPcid(tkrecord.getPcid());
  150 + if(null==tkrecord.getType()) {
  151 + lymsChatgroupService.saveOrUpdate(group);
  152 + tkrecord.setHxgroupid(group.getHxgroupid());
  153 + lymsTkrecordService.save(tkrecord);
  154 + }else {
  155 + group.setType(1);
  156 + lymsChatgroupService.saveOrUpdate(group);
  157 + LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord();
  158 + returnVisitRecord.setDlogin(tkrecord.getRetDlogin());//前端传的当前登录医生账号
  159 + returnVisitRecord.setDpid(doctor.getDpid());
  160 + returnVisitRecord.setIdno(patient.getIdno());
  161 + returnVisitRecord.setType(1);
  162 + returnVisitRecord.setPcid(tkrecord.getPcid());
  163 + returnVisitRecord.setHxgroupid(group.getHxgroupid());
  164 + lymsReturnVisitRecordService.save(returnVisitRecord);
  165 + }
149 166 }else {
150   - group.setType(1);
151   - lymsChatgroupService.saveOrUpdate(group);
152   - LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord();
153   - returnVisitRecord.setDlogin(group.getRetDlogin());
154   - returnVisitRecord.setDpid(doctor.getDpid());
155   - returnVisitRecord.setIdno(patient.getIdno());
156   - returnVisitRecord.setType(1);
157   - returnVisitRecord.setPcid(tkrecord.getPcid());
158   - returnVisitRecord.setHxgroupid(rJson.getJSONObject("data").getString("groupid"));
159   - lymsReturnVisitRecordService.save(returnVisitRecord);
  167 + group=gLst.get(0);
  168 + tkrecord.setHxgroupid(group.getHxgroupid());
  169 + lymsTkrecordService.save(tkrecord);
160 170 }
  171 +
161 172 baseResponse.setObject(group);
162 173  
163 174 baseResponse.setErrormsg("成功");
164 175 } catch (Exception e) {
  176 + baseResponse.setErrorcode(1);
165 177 baseResponse.setErrormsg("失败");
166 178 e.printStackTrace();
167 179 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsChatgroup.java View file @ a15a89b
... ... @@ -74,16 +74,17 @@
74 74 */
75 75 @TableField(value = "stat")
76 76 private Integer stat;
  77 +
77 78 /**
78   - * 回访医生dlogin
79   - */
80   - @TableField(value = "retdlogin")
81   - private String retDlogin;
82   - /**
83 79 * 病例id
84 80 */
85 81 @TableField(value = "pcid")
86 82 private Integer pcid;
  83 + /**
  84 + * 回访医生dlogin
  85 + */
  86 + @TableField(exist = false)
  87 + private String retDlogin;
87 88  
88 89 @TableField(exist = false)
89 90 private static final long serialVersionUID = 1L;
talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPatientMapper.java View file @ a15a89b
... ... @@ -41,5 +41,21 @@
41 41 "GROUP BY p.idno "+
42 42 "</script>"})
43 43 List<Map> getPatient(@Param("ew")QueryWrapper ew);
  44 +
  45 + @Select("SELECT " +
  46 + "p.id," +
  47 + "p.pname," +
  48 + "p.idno," +
  49 + "p.hxid," +
  50 + "pc.pcid," +
  51 + "pc.did," +
  52 + "pc.dname," +
  53 + "dc.dlogin," +
  54 + "pc.createdtime " +
  55 + "FROM " +
  56 + "lyms_patient p " +
  57 + "LEFT JOIN lyms_pcase pc ON pc.pid = p.id " +
  58 + "LEFT JOIN lyms_doctor dc ON dc.did=pc.dtid ")
  59 + List<Map<String,Object>> getPcInfoList();
44 60 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPatientService.java View file @ a15a89b
... ... @@ -11,9 +11,12 @@
11 11 *
12 12 */
13 13 public interface LymsPatientService extends IService<LymsPatient> {
  14 +
14 15  
15 16 List<Map<String,String>> getAppPatientHospital(Integer patientId);
16 17  
17 18 List<Map> getPatient(QueryWrapper queryWrapper);
  19 +
  20 + List<Map<String,Object>> getPcInfoList();
18 21 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPatientServiceImpl.java View file @ a15a89b
... ... @@ -29,5 +29,10 @@
29 29 public List<Map> getPatient(QueryWrapper queryWrapper) {
30 30 return lymsPatientMapper.getPatient(queryWrapper);
31 31 }
  32 +
  33 + @Override
  34 + public List<Map<String,Object>> getPcInfoList() {
  35 + return lymsPatientMapper.getPcInfoList();
  36 + }
32 37 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushChatInfoTask.java View file @ a15a89b
1 1 package com.lyms.talkonlineweb.task;
2 2  
  3 +import com.alibaba.fastjson.JSONArray;
  4 +import com.alibaba.fastjson.JSONObject;
3 5 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 6 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  7 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
5 8 import com.lyms.talkonlineweb.domain.*;
6 9 import com.lyms.talkonlineweb.service.*;
7   -import com.lyms.talkonlineweb.util.Constant;
8   -import com.lyms.talkonlineweb.util.StringUtil;
9   -import com.lyms.talkonlineweb.util.WeiXinUtil;
  10 +import com.lyms.talkonlineweb.util.*;
10 11 import lombok.Data;
11 12 import lombok.extern.log4j.Log4j2;
  13 +import org.apache.commons.lang3.StringUtils;
12 14 import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.beans.factory.annotation.Value;
13 16 import org.springframework.scheduling.annotation.Scheduled;
14 17 import org.springframework.stereotype.Component;
  18 +import org.springframework.transaction.annotation.Transactional;
15 19  
16   -import java.util.Date;
17   -import java.util.HashMap;
18   -import java.util.List;
19   -import java.util.Map;
  20 +import java.util.*;
20 21  
21 22 /**
22 23 * 回访信息回复
... ... @@ -25,7 +26,8 @@
25 26 @Component
26 27 @Log4j2
27 28 public class PushChatInfoTask {
28   -
  29 + @Value("${hx.hxuser}")
  30 + private String hxuser;
29 31 @Autowired
30 32 private LymsArticleService lymsArticleService;
31 33 @Autowired
32 34  
33 35  
34 36  
35 37  
36 38  
37 39  
... ... @@ -41,24 +43,403 @@
41 43 @Autowired
42 44 private LymsPcaseService lymsPcaseService;//病例
43 45 @Autowired
44   - private LymsDictService lymsDictService;
  46 + private LymsDoctorService lymsDoctorService;
45 47 @Autowired
46 48 public LymsPushAttentionRecordService lymsPushAttentionRecordService;
47 49 @Autowired
48 50 private LymsChatgroupService lymsChatgroupService;
49 51 @Autowired
50 52 private LymsReturnVisitRecordService lymsReturnVisitRecordService;
  53 + @Autowired
  54 + private HXService hxService;
  55 + @Autowired
  56 + private LymsIllnessService lymsIllnessService;
  57 + @Autowired
  58 + private LymsChatInfoService lymsChatInfoService;
  59 + @Autowired
  60 + private LymsMessageService lymsMessageService;
51 61  
  62 + @Autowired
  63 + private LymsTkrecordService lymsTkrecordService;
  64 +
52 65 /**
53   - * 每天12点执行回访信息系统回复
  66 + * 每天19点执行回访信息系统回复
54 67 */
55   -// @Scheduled(cron = "0 0 12 * * ?")
  68 +// @Scheduled(cron = "0 0 19 * * ?")
56 69 public void pushChatInfo() {
57   - final List<LymsChatgroup> chatgroupList = lymsChatgroupService.list();
58   - for (LymsChatgroup lymsChatgroup : chatgroupList) {
59   - final List<LymsReturnVisitRecord> lymsReturnVisitRecords = lymsReturnVisitRecordService.list(new QueryWrapper<LymsReturnVisitRecord>()
60   - .lambda().eq(LymsReturnVisitRecord::getHxgroupid, lymsChatgroup.getHxgroupid()));
  70 + List<Map<String,Object>> PcInfoList=lymsPatientService.getPcInfoList();
  71 + for (Map<String, Object> map : PcInfoList) {
  72 + LymsChatgroup chatgroup = lymsChatgroupService.getOne(new QueryWrapper<LymsChatgroup>()
  73 + .lambda().eq(LymsChatgroup::getPcid, (Integer)map.get("pcid")));
  74 + LymsPatient patient= lymsPatientService.getOne(new QueryWrapper<LymsPatient>()
  75 + .lambda().eq(LymsPatient::getIdno, map.get("idno").toString()));
  76 + LymsDoctor doctor= lymsDoctorService.getOne(new QueryWrapper<LymsDoctor>()
  77 + .lambda().eq(LymsDoctor::getDlogin, map.get("dlogin").toString()));
  78 + if(null==chatgroup){
  79 + //创建聊天群组
  80 + chatgroup=addChatGroup(map,patient,doctor);
  81 + }
  82 +
  83 + if (null!=chatgroup) {
  84 + final List<LymsReturnVisitRecord> returnVisitRecords = lymsReturnVisitRecordService.list(new QueryWrapper<LymsReturnVisitRecord>()
  85 + .lambda().eq(LymsReturnVisitRecord::getPcid, (Integer)map.get("pcid")));
  86 + List<LymsDoctor> doctorAminList= lymsDoctorService.list(new QueryWrapper<LymsDoctor>()
  87 + .lambda().eq(LymsDoctor::getDpid, doctor.getDpid())
  88 + .in(LymsDoctor::getAdminType, Arrays.asList(1,2))
  89 + .orderByAsc(LymsDoctor::getAdminType));
  90 + int day = DateUtil.daysBetween(DateUtil.parseYMD(map.get("createdtime").toString()),new Date());
  91 + switch (returnVisitRecords.size()) {
  92 + case 0:
  93 + if (day==2) {
  94 + final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
  95 + .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
  96 + int i=0;
  97 + for (LymsIllness lymsIllness : lymsIllnessList) {
  98 + final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
  99 + .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
  100 + .eq(LymsChatInfo::getType, 1));
  101 + //推送回访
  102 + if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
  103 + JSONObject jsonObject = hxService.sendGroupMsg(new String[]{chatgroup.getHxgroupid()}, chatInfo.getConten(), doctor.getDlogin());
  104 + if (null!=jsonObject) {
  105 + i++;
  106 + //保存发送消息记录
  107 + LymsMessage message=new LymsMessage();
  108 + message.setContent(chatInfo.getConten());
  109 + message.setFromid(doctor.getDlogin());
  110 + message.setTargetid(chatgroup.getHxgroupid());
  111 + message.setMtype("TEXT");
  112 + message.setSendtime(new Date());
  113 + message.setType(1);
  114 + lymsMessageService.save(message);
  115 + }
  116 + }
  117 + }
  118 + if (i!=0) {
  119 + //增加回访记录
  120 + LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord();
  121 + returnVisitRecord.setDlogin(doctor.getDlogin());//第二天,就诊医生自动回复
  122 + returnVisitRecord.setDpid(doctor.getDpid());
  123 + returnVisitRecord.setIdno(patient.getIdno());
  124 + returnVisitRecord.setType(0);
  125 + returnVisitRecord.setHxgroupid(chatgroup.getHxgroupid());
  126 + lymsReturnVisitRecordService.save(returnVisitRecord);
  127 + chatgroup.setStat(0);
  128 + final boolean b = lymsChatgroupService.updateById(chatgroup);
  129 + if (!b) {
  130 + break;
  131 + }
  132 + //修改同一群组记录的状态
  133 + final List<LymsTkrecord> tkrecordList = lymsTkrecordService.list(new QueryWrapper<LymsTkrecord>()
  134 + .lambda().eq(LymsTkrecord::getHxgroupid, chatgroup.getHxgroupid()));
  135 + for (LymsTkrecord lymsTkrecord : tkrecordList) {
  136 + lymsTkrecord.setStat(0);
  137 + final boolean saveOrUpdate = lymsTkrecordService.updateById(lymsTkrecord);
  138 + if (!saveOrUpdate) {
  139 + break;
  140 + }
  141 + }
  142 + }
  143 + }
  144 + break;
  145 + case 1:
  146 + if (day==5) {
  147 + //获取值班护士
  148 + String dlogin="";
  149 + for (LymsDoctor lymsDoctor : doctorAminList) {
  150 + if (lymsDoctor.getAdminType()==2) {
  151 + dlogin=lymsDoctor.getDlogin();
  152 + return;
  153 + }
  154 + }
  155 + final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
  156 + .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
  157 + int i=0;
  158 + for (LymsIllness lymsIllness : lymsIllnessList) {
  159 + final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
  160 + .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
  161 + .eq(LymsChatInfo::getType, 2));
  162 + //推送回访
  163 + if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
  164 + JSONObject jsonObject = hxService.sendGroupMsg(new String[]{chatgroup.getHxgroupid()}, chatInfo.getConten(), StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);
  165 + if (null!=jsonObject) {
  166 + i++;
  167 + //保存发送消息记录
  168 + LymsMessage message=new LymsMessage();
  169 + message.setContent(chatInfo.getConten());
  170 + message.setFromid(StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);
  171 + message.setTargetid(chatgroup.getHxgroupid());
  172 + message.setMtype("TEXT");
  173 + message.setSendtime(new Date());
  174 + message.setType(1);
  175 + lymsMessageService.save(message);
  176 + }
  177 + }
  178 + }
  179 + if (i!=0) {
  180 + //增加回访记录
  181 + LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord();
  182 + returnVisitRecord.setDlogin(StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);//第五天,值班护士自动回复
  183 + returnVisitRecord.setDpid(doctor.getDpid());
  184 + returnVisitRecord.setIdno(patient.getIdno());
  185 + returnVisitRecord.setType(0);
  186 + returnVisitRecord.setHxgroupid(chatgroup.getHxgroupid());
  187 + lymsReturnVisitRecordService.save(returnVisitRecord);
  188 + chatgroup.setStat(0);
  189 + final boolean b = lymsChatgroupService.updateById(chatgroup);
  190 + if (!b) {
  191 + break;
  192 + }
  193 + //修改同一群组记录的状态
  194 + final List<LymsTkrecord> tkrecordList = lymsTkrecordService.list(new QueryWrapper<LymsTkrecord>()
  195 + .lambda().eq(LymsTkrecord::getHxgroupid, chatgroup.getHxgroupid()));
  196 + for (LymsTkrecord lymsTkrecord : tkrecordList) {
  197 + lymsTkrecord.setStat(0);
  198 + final boolean saveOrUpdate = lymsTkrecordService.updateById(lymsTkrecord);
  199 + if (!saveOrUpdate) {
  200 + break;
  201 + }
  202 + }
  203 + }
  204 + }
  205 + break;
  206 + case 2:
  207 + if (day==10) {
  208 + //获取值班医生
  209 + String dlogin="";
  210 + for (LymsDoctor lymsDoctor : doctorAminList) {
  211 + if (lymsDoctor.getAdminType()==1) {
  212 + dlogin=lymsDoctor.getDlogin();
  213 + return;
  214 + }
  215 + }
  216 + final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
  217 + .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
  218 + int i=0;
  219 + for (LymsIllness lymsIllness : lymsIllnessList) {
  220 + final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
  221 + .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
  222 + .eq(LymsChatInfo::getType, 3));
  223 + //推送回访
  224 + if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
  225 + JSONObject jsonObject = hxService.sendGroupMsg(new String[]{chatgroup.getHxgroupid()}, chatInfo.getConten(), StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);
  226 + if (null!=jsonObject) {
  227 + i++;
  228 + //保存发送消息记录
  229 + LymsMessage message=new LymsMessage();
  230 + message.setContent(chatInfo.getConten());
  231 + message.setFromid(StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);
  232 + message.setTargetid(chatgroup.getHxgroupid());
  233 + message.setMtype("TEXT");
  234 + message.setSendtime(new Date());
  235 + message.setType(1);
  236 + lymsMessageService.save(message);
  237 + }
  238 + }
  239 + }
  240 + if (i!=0) {
  241 + //增加回访记录
  242 + LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord();
  243 + returnVisitRecord.setDlogin(StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);//第十天,值班医生自动回复
  244 + returnVisitRecord.setDpid(doctor.getDpid());
  245 + returnVisitRecord.setIdno(patient.getIdno());
  246 + returnVisitRecord.setType(0);
  247 + returnVisitRecord.setHxgroupid(chatgroup.getHxgroupid());
  248 + lymsReturnVisitRecordService.save(returnVisitRecord);
  249 + chatgroup.setStat(0);
  250 + final boolean b = lymsChatgroupService.updateById(chatgroup);
  251 + if (!b) {
  252 + break;
  253 + }
  254 + //修改同一群组记录的状态
  255 + final List<LymsTkrecord> tkrecordList = lymsTkrecordService.list(new QueryWrapper<LymsTkrecord>()
  256 + .lambda().eq(LymsTkrecord::getHxgroupid, chatgroup.getHxgroupid()));
  257 + for (LymsTkrecord lymsTkrecord : tkrecordList) {
  258 + lymsTkrecord.setStat(0);
  259 + final boolean saveOrUpdate = lymsTkrecordService.updateById(lymsTkrecord);
  260 + if (!saveOrUpdate) {
  261 + break;
  262 + }
  263 + }
  264 + }
  265 + }
  266 + break;
  267 + case 3:
  268 + if (day==20) {
  269 + final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
  270 + .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
  271 + int i=0;
  272 + for (LymsIllness lymsIllness : lymsIllnessList) {
  273 + final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
  274 + .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
  275 + .eq(LymsChatInfo::getType, 4));
  276 + //推送回访
  277 + if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
  278 + JSONObject jsonObject = hxService.sendGroupMsg(new String[]{chatgroup.getHxgroupid()}, chatInfo.getConten(), doctor.getDlogin());
  279 + if (null!=jsonObject) {
  280 + i++;
  281 + //保存发送消息记录
  282 + LymsMessage message=new LymsMessage();
  283 + message.setContent(chatInfo.getConten());
  284 + message.setFromid(doctor.getDlogin());
  285 + message.setTargetid(chatgroup.getHxgroupid());
  286 + message.setMtype("TEXT");
  287 + message.setSendtime(new Date());
  288 + message.setType(1);
  289 + lymsMessageService.save(message);
  290 + }
  291 + }
  292 + }
  293 + if (i!=0) {
  294 + //增加回访记录
  295 + LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord();
  296 + returnVisitRecord.setDlogin(doctor.getDlogin());//第二十天,就诊医生自动回复
  297 + returnVisitRecord.setDpid(doctor.getDpid());
  298 + returnVisitRecord.setIdno(patient.getIdno());
  299 + returnVisitRecord.setType(0);
  300 + returnVisitRecord.setHxgroupid(chatgroup.getHxgroupid());
  301 + lymsReturnVisitRecordService.save(returnVisitRecord);
  302 + chatgroup.setStat(0);
  303 + final boolean b = lymsChatgroupService.updateById(chatgroup);
  304 + if (!b) {
  305 + break;
  306 + }
  307 + //修改同一群组记录的状态
  308 + final List<LymsTkrecord> tkrecordList = lymsTkrecordService.list(new QueryWrapper<LymsTkrecord>()
  309 + .lambda().eq(LymsTkrecord::getHxgroupid, chatgroup.getHxgroupid()));
  310 + for (LymsTkrecord lymsTkrecord : tkrecordList) {
  311 + lymsTkrecord.setStat(0);
  312 + final boolean saveOrUpdate = lymsTkrecordService.updateById(lymsTkrecord);
  313 + if (!saveOrUpdate) {
  314 + break;
  315 + }
  316 + }
  317 + }
  318 + }
  319 + break;
  320 + case 4:
  321 + if (day==30) {
  322 + //获取值班医生
  323 + String dlogin="";
  324 + for (LymsDoctor lymsDoctor : doctorAminList) {
  325 + if (lymsDoctor.getAdminType()==1) {
  326 + dlogin=lymsDoctor.getDlogin();
  327 + return;
  328 + }
  329 + }
  330 + final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
  331 + .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
  332 + int i=0;
  333 + for (LymsIllness lymsIllness : lymsIllnessList) {
  334 + final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
  335 + .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
  336 + .eq(LymsChatInfo::getType, 5));
  337 + //推送回访
  338 + if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
  339 + JSONObject jsonObject = hxService.sendGroupMsg(new String[]{chatgroup.getHxgroupid()}, chatInfo.getConten(), StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);
  340 + if (null!=jsonObject) {
  341 + i++;
  342 + //保存发送消息记录
  343 + LymsMessage message=new LymsMessage();
  344 + message.setContent(chatInfo.getConten());
  345 + message.setFromid(StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);
  346 + message.setTargetid(chatgroup.getHxgroupid());
  347 + message.setMtype("TEXT");
  348 + message.setSendtime(new Date());
  349 + message.setType(1);
  350 + lymsMessageService.save(message);
  351 + }
  352 + }
  353 + }
  354 + if (i!=0) {
  355 + //增加回访记录
  356 + LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord();
  357 + returnVisitRecord.setDlogin(StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);//第三十天,值班医生自动回复
  358 + returnVisitRecord.setDpid(doctor.getDpid());
  359 + returnVisitRecord.setIdno(patient.getIdno());
  360 + returnVisitRecord.setType(0);
  361 + returnVisitRecord.setHxgroupid(chatgroup.getHxgroupid());
  362 + lymsReturnVisitRecordService.save(returnVisitRecord);
  363 + chatgroup.setStat(0);
  364 + final boolean b = lymsChatgroupService.updateById(chatgroup);
  365 + if (!b) {
  366 + break;
  367 + }
  368 + //修改同一群组记录的状态
  369 + final List<LymsTkrecord> tkrecordList = lymsTkrecordService.list(new QueryWrapper<LymsTkrecord>()
  370 + .lambda().eq(LymsTkrecord::getHxgroupid, chatgroup.getHxgroupid()));
  371 + for (LymsTkrecord lymsTkrecord : tkrecordList) {
  372 + lymsTkrecord.setStat(0);
  373 + final boolean saveOrUpdate = lymsTkrecordService.updateById(lymsTkrecord);
  374 + if (!saveOrUpdate) {
  375 + break;
  376 + }
  377 + }
  378 + }
  379 + }
  380 + break;
  381 + }
  382 + }
61 383 }
  384 + }
  385 + public LymsChatgroup addChatGroup(Map<String,Object> map,LymsPatient patient,LymsDoctor doctor) {
  386 + List<String> adminDlogins=new ArrayList<>();
  387 + adminDlogins.add(patient.getIdno());
  388 + List<String> groupnames=new ArrayList<>();
  389 + groupnames.add(patient.getPname());
  390 + //患者注册环信
  391 + if (StringUtil.isEmpty(patient.getHxid())) {
  392 + JSONObject json = hxService.addUser(patient.getIdno(), Constant.COMMON_PASSWD, patient.getPname());
  393 + JSONArray rArr = json.getJSONArray("entities");
  394 + if (rArr.size() > 0) {
  395 + patient.setHxid(rArr.getJSONObject(0).getString("uuid"));
  396 + lymsPatientService.updateById(patient);
  397 + }
  398 + }
  399 + //查询值班医生/值班护士
  400 + List<LymsDoctor> doctorAminList= lymsDoctorService.list(new QueryWrapper<LymsDoctor>()
  401 + .lambda().eq(LymsDoctor::getDpid, doctor.getDpid())
  402 + .in(LymsDoctor::getAdminType, Arrays.asList(1,2))
  403 + .orderByAsc(LymsDoctor::getAdminType));
  404 + //科室值班医生注册环信
  405 + for (LymsDoctor lymsDoctor : doctorAminList) {
  406 + if(StringUtil.isEmpty(lymsDoctor.getHxid())) {
  407 + JSONObject json = hxService.addUser(lymsDoctor.getDlogin(), Constant.COMMON_PASSWD, lymsDoctor.getDname());
  408 + JSONArray rArr = json.getJSONArray("entities");
  409 + if (rArr.size() > 0) {
  410 + lymsDoctor.setHxid(rArr.getJSONObject(0).getString("uuid"));
  411 + lymsDoctorService.updateById(lymsDoctor);
  412 + }
  413 + }
  414 + adminDlogins.add(lymsDoctor.getDlogin());
  415 + groupnames.add(lymsDoctor.getDname());
  416 + }
  417 + if ( ! adminDlogins.contains(doctor.getDlogin())) {
  418 + //医生注册环信
  419 + if (StringUtil.isEmpty(doctor.getHxid())) {
  420 + JSONObject json = hxService.addUser(doctor.getDlogin(), Constant.COMMON_PASSWD, doctor.getDname());
  421 + JSONArray rArr = json.getJSONArray("entities");
  422 + if (rArr.size() > 0) {
  423 + doctor.setHxid(rArr.getJSONObject(0).getString("uuid"));
  424 + lymsDoctorService.updateById(doctor);
  425 + }
  426 + }
  427 + adminDlogins.add(doctor.getDlogin());
  428 + groupnames.add(doctor.getDname());
  429 + }
  430 + JSONObject rJson = hxService.addChatGroups(StringUtils.join(adminDlogins.toArray(), ","), hxuser, adminDlogins.toArray(new String[adminDlogins.size()]));
  431 + LymsChatgroup group =new LymsChatgroup();
  432 + group.setGroupname(StringUtils.join(groupnames.toArray(), ","));
  433 + group.setDescription(StringUtils.join(adminDlogins.toArray(), ","));
  434 + group.setOwnerk(hxuser);
  435 + group.setFromp(patient.getIdno());
  436 + group.setHxgroupid(rJson.getJSONObject("data").getString("groupid"));
  437 + group.setTarget(doctor.getDlogin());
  438 + group.setType(1);
  439 + group.setStat(0);
  440 + group.setPcid((Integer)map.get("pcid"));
  441 + lymsChatgroupService.save(group);
  442 + return group;
62 443 }
63 444 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/DateUtil.java View file @ a15a89b
... ... @@ -3,6 +3,7 @@
3 3 import lombok.extern.slf4j.Slf4j;
4 4  
5 5 import java.text.DateFormat;
  6 +import java.text.ParseException;
6 7 import java.text.ParsePosition;
7 8 import java.text.SimpleDateFormat;
8 9 import java.util.Calendar;
... ... @@ -231,5 +232,34 @@
231 232  
232 233 return (Math.abs(year1 - year2) + i);
233 234 }
  235 +
  236 + /**
  237 + * 时间差
  238 + * @param start
  239 + * @param end
  240 + * @return
  241 + */
  242 + public static int daysBetween(Date smdate, Date bdate) {
  243 + if (smdate == null || bdate == null) {
  244 + return -1;
  245 + }
  246 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  247 + try {
  248 + smdate = sdf.parse(sdf.format(smdate));
  249 + bdate = sdf.parse(sdf.format(bdate));
  250 + Calendar cal = Calendar.getInstance();
  251 + cal.setTime(smdate);
  252 + long time1 = cal.getTimeInMillis();
  253 + cal.setTime(bdate);
  254 + long time2 = cal.getTimeInMillis();
  255 + long between_days = (time2 - time1) / (1000 * 3600 * 24);
  256 + return Integer.parseInt(String.valueOf(between_days));
  257 + } catch (ParseException e) {
  258 + e.printStackTrace();
  259 + }
  260 +
  261 + return 0;
  262 + }
  263 +
234 264 }
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/HXService.java View file @ a15a89b
... ... @@ -160,6 +160,43 @@
160 160 }
161 161  
162 162 /**
  163 + * 群组发送消息
  164 + * @param target hxgroupid
  165 + * @param target_type 发送的目标类型:
  166 + * • users:给用户发消息;
  167 + * • chatgroups:给群发消息;
  168 + * • chatrooms:给聊天室发消息。
  169 + * @param msgContent
  170 + * @param from
  171 + * @return
  172 + */
  173 + public JSONObject sendGroupMsg(String[] target ,String msgContent,String from){
  174 + JSONObject rs=new JSONObject();
  175 + Map<String,Object> param=new HashMap<>();
  176 + HttpHeaders headers=new HttpHeaders();
  177 +
  178 + headers.add("Authorization","Bearer "+getToken());
  179 + List lParam=new ArrayList();
  180 + param.put("target_type","chatgroups");
  181 + param.put("target",target);
  182 + Map<String,Object> msg=new HashMap<>();
  183 + msg.put("type","txt");
  184 + msg.put("msg",msgContent);
  185 +
  186 + param.put("msg",msg);
  187 + param.put("from",from);
  188 +
  189 + lParam.add(param);
  190 + HttpEntity entity=new HttpEntity(param,headers);
  191 + resp=restTemplate.postForEntity(getUrl()+"messages",entity,String.class);
  192 + if (resp.getStatusCodeValue()==200){
  193 + rs= JSON.parseObject(resp.getBody());
  194 + }
  195 + log.info(rs);
  196 + return rs;
  197 + }
  198 +
  199 + /**
163 200 * 获取聊天记录
164 201 * @param time 查询的时间格式为10位数字形式(YYYYMMDDHH)
165 202 * @return