Commit b4b4678fc43d1247d1362c48837d37dc5b042710
1 parent
f0aa28dc29
Exists in
dev
消息增加撤回接口,环信聊天增加组标识
Showing 15 changed files with 361 additions and 42 deletions
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/ChatGroupController.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/DoctorController.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/DoctorChatCount.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsMessage.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsDoctorWorktimeMapper.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/request/MsgDelParam.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsDoctorWorktimeService.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsDoctorWorktimeServiceImpl.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/DoctorMsgNotifyTask.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/HXTask.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/HXService.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java
- talkonlineweb/src/main/resources/mapper/LymsDoctorWorktimeMapper.xml
talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/ChatGroupController.java
View file @
b4b4678
| ... | ... | @@ -12,6 +12,7 @@ |
| 12 | 12 | import com.lyms.talkonlineweb.constants.ErrorCodeConstants; |
| 13 | 13 | import com.lyms.talkonlineweb.domain.*; |
| 14 | 14 | import com.lyms.talkonlineweb.enums.MessageEnum; |
| 15 | +import com.lyms.talkonlineweb.request.MsgDelParam; | |
| 15 | 16 | import com.lyms.talkonlineweb.result.BaseResponse; |
| 16 | 17 | import com.lyms.talkonlineweb.service.*; |
| 17 | 18 | import com.lyms.talkonlineweb.util.Constant; |
| 18 | 19 | |
| ... | ... | @@ -181,11 +182,34 @@ |
| 181 | 182 | public BaseResponse saveMsg(@RequestBody LymsMessage message) { |
| 182 | 183 | BaseResponse baseResponse = new BaseResponse(); |
| 183 | 184 | message.setSendtime(new Date()); |
| 185 | + message.setYn(1); | |
| 184 | 186 | boolean f = lymsMessageService.saveOrUpdate(message); |
| 185 | 187 | baseResponse.setErrorcode(f == true ? 0 : 1); |
| 186 | 188 | return baseResponse; |
| 187 | 189 | } |
| 188 | 190 | |
| 191 | + @PostMapping("delMsg") | |
| 192 | + @TokenRequired | |
| 193 | + public BaseResponse delMsg(@RequestBody MsgDelParam msgDelParam) { | |
| 194 | + | |
| 195 | + | |
| 196 | + boolean b = hxService.recallMsg(msgDelParam); | |
| 197 | + if(b){ | |
| 198 | + QueryWrapper<LymsMessage> queryWrapper = new QueryWrapper<>(); | |
| 199 | + queryWrapper.eq("hx_msg_id",msgDelParam.getMsg_id()); | |
| 200 | + queryWrapper.eq("yn",1); | |
| 201 | + LymsMessage lymsMessage = lymsMessageService.getOne(queryWrapper,false); | |
| 202 | + if(lymsMessage != null){ | |
| 203 | + LymsMessage m = new LymsMessage(); | |
| 204 | + m.setId(lymsMessage.getId()); | |
| 205 | + m.setYn(0); | |
| 206 | + lymsMessageService.updateById(m); | |
| 207 | + } | |
| 208 | + return BaseResponse.ok(); | |
| 209 | + } | |
| 210 | + return BaseResponse.error("消息撤回失败"); | |
| 211 | + } | |
| 212 | + | |
| 189 | 213 | /** |
| 190 | 214 | * 根据群组ID获取患者和医生信息 |
| 191 | 215 | * @param chatgroup |
| ... | ... | @@ -380,6 +404,7 @@ |
| 380 | 404 | //聊天记录 |
| 381 | 405 | LambdaQueryWrapper<LymsMessage> messageQueryWrapper=new QueryWrapper().lambda(); |
| 382 | 406 | messageQueryWrapper.eq(LymsMessage::getTargetid, lymsChatgroup.getHxgroupid()) |
| 407 | + .eq(LymsMessage::getYn,1) | |
| 383 | 408 | .orderByDesc(LymsMessage::getSendtime) |
| 384 | 409 | .last(" limit 1"); |
| 385 | 410 | final List<LymsMessage> lymsMessageList = lymsMessageService.list(messageQueryWrapper); |
| ... | ... | @@ -532,7 +557,8 @@ |
| 532 | 557 | //聊天记录 |
| 533 | 558 | LambdaQueryWrapper<LymsMessage> messageQueryWrapper=new QueryWrapper().lambda(); |
| 534 | 559 | messageQueryWrapper.eq(LymsMessage::getTargetid, lymsChatgroup.getHxgroupid()); |
| 535 | - messageQueryWrapper.orderByDesc(LymsMessage::getSendtime); | |
| 560 | + messageQueryWrapper.eq(LymsMessage::getYn,1); | |
| 561 | + messageQueryWrapper.orderByDesc(LymsMessage::getSendtime).last(" limit 1"); | |
| 536 | 562 | final List<LymsMessage> lymsMessageList = lymsMessageService.list(messageQueryWrapper); |
| 537 | 563 | Map map=new HashMap(); |
| 538 | 564 | map.put("msg",lymsMessageList.size()>0?lymsMessageList.get(0).getContent():""); |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/DoctorController.java
View file @
b4b4678
| ... | ... | @@ -238,6 +238,7 @@ |
| 238 | 238 | Map<String,Object> map=new HashMap<>(); |
| 239 | 239 | map.put("doctor",doctor); |
| 240 | 240 | map.put("token",jwt); |
| 241 | + map.put("hxuser",hxService.getHxuser()); | |
| 241 | 242 | // if (StringUtil.isEmpty(doctor.getHxid())) { |
| 242 | 243 | // JSONObject json = hxService.addUser(doctor.getDlogin(), Constant.COMMON_PASSWD, doctor.getDname()); |
| 243 | 244 | // JSONArray rArr = json.getJSONArray("entities"); |
| ... | ... | @@ -416,7 +417,7 @@ |
| 416 | 417 | } |
| 417 | 418 | /** |
| 418 | 419 | * 小程序回访统计,按医生 |
| 419 | - * @param groupId 群组ID | |
| 420 | + * @param | |
| 420 | 421 | * @return |
| 421 | 422 | */ |
| 422 | 423 | @GetMapping("getReturnVisit") |
| ... | ... | @@ -532,12 +533,7 @@ |
| 532 | 533 | if (!descriptionList.contains(doctor.getDlogin())) { |
| 533 | 534 | //注册环信 |
| 534 | 535 | if (StringUtil.isEmpty(doctor.getHxid())) { |
| 535 | - JSONObject json = hxService.addUser(doctor.getDlogin(), Constant.COMMON_PASSWD, doctor.getDname()); | |
| 536 | - JSONArray rArr = json.getJSONArray("entities"); | |
| 537 | - if (rArr.size() > 0) { | |
| 538 | - doctor.setHxid(rArr.getJSONObject(0).getString("uuid")); | |
| 539 | - lymsDoctorService.updateById(doctor); | |
| 540 | - } | |
| 536 | + lymsDoctorService.addDoctorHxId(doctor); | |
| 541 | 537 | } |
| 542 | 538 | //添加到环信群组中 |
| 543 | 539 | JSONObject json = hxService.addUserHxGroup(lymsChatgroup.getHxgroupid(), doctor.getDlogin()); |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java
View file @
b4b4678
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/DoctorChatCount.java
View file @
b4b4678
| 1 | +package com.lyms.talkonlineweb.domain; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 5 | +@Data | |
| 6 | +public class DoctorChatCount { | |
| 7 | + | |
| 8 | + private Integer did; | |
| 9 | + | |
| 10 | + private String dlogin; | |
| 11 | + | |
| 12 | + private String dpasswd; | |
| 13 | + | |
| 14 | + private String dname; | |
| 15 | + | |
| 16 | + private String mobile; | |
| 17 | + | |
| 18 | + private String gzopenid; | |
| 19 | + | |
| 20 | + private Integer count; | |
| 21 | +} |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsMessage.java
View file @
b4b4678
| ... | ... | @@ -62,6 +62,15 @@ |
| 62 | 62 | @TableField(exist = false) |
| 63 | 63 | private static final long serialVersionUID = 1L; |
| 64 | 64 | |
| 65 | + @TableField(value = "hx_msg_id") | |
| 66 | + private String hxMsgId; | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * 1 有效 0 删除 | |
| 70 | + */ | |
| 71 | + @TableField(value = "del_status") | |
| 72 | + private int yn; | |
| 73 | + | |
| 65 | 74 | @Override |
| 66 | 75 | public boolean equals(Object that) { |
| 67 | 76 | if (this == that) { |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsDoctorWorktimeMapper.java
View file @
b4b4678
| 1 | 1 | package com.lyms.talkonlineweb.mapper; |
| 2 | 2 | |
| 3 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| 4 | +import com.lyms.talkonlineweb.domain.DoctorChatCount; | |
| 4 | 5 | import com.lyms.talkonlineweb.domain.LymsDoctor; |
| 5 | 6 | import com.lyms.talkonlineweb.domain.LymsDoctorWorkTime; |
| 6 | 7 | import org.apache.ibatis.annotations.Param; |
| 7 | 8 | import org.apache.ibatis.annotations.Select; |
| 8 | 9 | |
| 10 | +import java.util.List; | |
| 9 | 11 | import java.util.Map; |
| 10 | 12 | |
| 11 | 13 | |
| 12 | 14 | public interface LymsDoctorWorktimeMapper extends BaseMapper<LymsDoctorWorkTime> { |
| 15 | + | |
| 16 | + List<DoctorChatCount> selectDoctorChatCount(@Param("startTime") String startTime); | |
| 17 | + | |
| 13 | 18 | } |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/request/MsgDelParam.java
View file @
b4b4678
| 1 | +package com.lyms.talkonlineweb.request; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | +import lombok.ToString; | |
| 5 | + | |
| 6 | +@Data | |
| 7 | +@ToString | |
| 8 | +public class MsgDelParam { | |
| 9 | + | |
| 10 | + private String msg_id; | |
| 11 | + | |
| 12 | + private String to; | |
| 13 | + | |
| 14 | + private String chat_type; | |
| 15 | + | |
| 16 | + private String from; | |
| 17 | + | |
| 18 | + private Boolean force; | |
| 19 | +} |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsDoctorWorktimeService.java
View file @
b4b4678
| 1 | 1 | package com.lyms.talkonlineweb.service; |
| 2 | 2 | |
| 3 | 3 | import com.baomidou.mybatisplus.extension.service.IService; |
| 4 | +import com.lyms.talkonlineweb.domain.DoctorChatCount; | |
| 4 | 5 | import com.lyms.talkonlineweb.domain.LymsDoctorWorkTime; |
| 6 | +import org.apache.ibatis.annotations.Param; | |
| 5 | 7 | |
| 8 | +import java.util.List; | |
| 6 | 9 | import java.util.Map; |
| 7 | 10 | |
| 8 | 11 | /** |
| 9 | 12 | * |
| 10 | 13 | */ |
| 11 | 14 | public interface LymsDoctorWorktimeService extends IService<LymsDoctorWorkTime> { |
| 12 | - | |
| 15 | + List<DoctorChatCount> selectDoctorChatCount(String startTime); | |
| 13 | 16 | } |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsDoctorWorktimeServiceImpl.java
View file @
b4b4678
| ... | ... | @@ -2,12 +2,17 @@ |
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| 5 | +import com.lyms.talkonlineweb.domain.DoctorChatCount; | |
| 5 | 6 | import com.lyms.talkonlineweb.domain.LymsDoctorWorkTime; |
| 6 | 7 | import com.lyms.talkonlineweb.mapper.LymsDoctorWorktimeMapper; |
| 7 | 8 | import com.lyms.talkonlineweb.service.LymsDoctorWorktimeService; |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | 10 | import org.springframework.stereotype.Service; |
| 9 | 11 | |
| 12 | +import javax.annotation.Resource; | |
| 13 | +import java.util.List; | |
| 10 | 14 | |
| 15 | + | |
| 11 | 16 | /** |
| 12 | 17 | * |
| 13 | 18 | */ |
| ... | ... | @@ -15,5 +20,12 @@ |
| 15 | 20 | public class LymsDoctorWorktimeServiceImpl extends ServiceImpl<LymsDoctorWorktimeMapper, LymsDoctorWorkTime> |
| 16 | 21 | implements LymsDoctorWorktimeService{ |
| 17 | 22 | |
| 23 | + | |
| 24 | + @Resource | |
| 25 | + LymsDoctorWorktimeMapper doctorWorktimeMapper; | |
| 26 | + @Override | |
| 27 | + public List<DoctorChatCount> selectDoctorChatCount(String startTime) { | |
| 28 | + return doctorWorktimeMapper.selectDoctorChatCount(startTime); | |
| 29 | + } | |
| 18 | 30 | } |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/DoctorMsgNotifyTask.java
View file @
b4b4678
| 1 | +package com.lyms.talkonlineweb.task; | |
| 2 | + | |
| 3 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
| 4 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |
| 5 | +import com.lyms.talkonlineweb.domain.DoctorChatCount; | |
| 6 | +import com.lyms.talkonlineweb.domain.LymsDoctor; | |
| 7 | +import com.lyms.talkonlineweb.domain.LymsDoctorWorkTime; | |
| 8 | +import com.lyms.talkonlineweb.service.LymsDoctorWorktimeService; | |
| 9 | +import com.lyms.talkonlineweb.util.Constant; | |
| 10 | +import com.lyms.talkonlineweb.util.DateUtil; | |
| 11 | +import com.lyms.talkonlineweb.util.StringUtil; | |
| 12 | +import com.lyms.talkonlineweb.util.WeiXinUtil; | |
| 13 | +import lombok.extern.log4j.Log4j2; | |
| 14 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | +import org.springframework.beans.factory.annotation.Value; | |
| 16 | +import org.springframework.scheduling.annotation.Scheduled; | |
| 17 | +import org.springframework.stereotype.Component; | |
| 18 | + | |
| 19 | +import java.text.DateFormat; | |
| 20 | +import java.text.SimpleDateFormat; | |
| 21 | +import java.util.Date; | |
| 22 | +import java.util.HashMap; | |
| 23 | +import java.util.List; | |
| 24 | +import java.util.Map; | |
| 25 | + | |
| 26 | +@Component | |
| 27 | +@Log4j2 | |
| 28 | +public class DoctorMsgNotifyTask { | |
| 29 | + | |
| 30 | + @Value("${getAccessToken.on_off}") | |
| 31 | + public boolean on_off;//配置yml 微信公众号获取access_token(测试环境部署不要开启。会与线上环境冲突) | |
| 32 | + | |
| 33 | + @Autowired | |
| 34 | + LymsDoctorWorktimeService doctorWorktimeService; | |
| 35 | + | |
| 36 | + @Scheduled(initialDelay=10000, fixedRate=60000) | |
| 37 | + public void doctorMsgNotify(){ | |
| 38 | + if(!on_off){ | |
| 39 | + return; | |
| 40 | + } | |
| 41 | + String startTime = DateUtil.getDateTime(new Date(),"HH:mm"); | |
| 42 | + log.info("医生消息提醒,时间:{}",startTime); | |
| 43 | + List<DoctorChatCount> doctorChatCounts = doctorWorktimeService.selectDoctorChatCount(startTime); | |
| 44 | + int size = doctorChatCounts.size(); | |
| 45 | + log.info("医生消息提醒,数量:{}",size); | |
| 46 | + for(DoctorChatCount doctorChatCount: doctorChatCounts) { | |
| 47 | + if(StringUtil.isEmpty(doctorChatCount.getGzopenid())){ | |
| 48 | + log.warn("医生消息提醒,未获取到公众号openid:{}",doctorChatCount); | |
| 49 | + continue; | |
| 50 | + } | |
| 51 | + Map<String,Object> mapTemplate=new HashMap<>(); | |
| 52 | + mapTemplate.put("first","医生消息提醒"); | |
| 53 | + mapTemplate.put("keyword1","尊敬的医生:"+doctorChatCount.getDname()); | |
| 54 | + mapTemplate.put("keyword2","您有患者消息"+doctorChatCount.getCount()+"条,请及时查看"); | |
| 55 | + mapTemplate.put("remark","请点击下方进入小程序,根据病例点咨询查看医生回访信息。"); | |
| 56 | + Map<String,Object> map=new HashMap<>(); | |
| 57 | + map.put("plogin", doctorChatCount.getDlogin()); | |
| 58 | + map.put("passwd", doctorChatCount.getDpasswd()); | |
| 59 | + try { | |
| 60 | + Integer code= WeiXinUtil.DoctorSendWeChatMsg(doctorChatCount.getGzopenid(), Constant.GZ_TEMPLATE_ID_DOCTOR_VISIT,mapTemplate,map); | |
| 61 | + log.info("医生消息提醒,code:{},{}",code,doctorChatCount); | |
| 62 | + } catch (Exception e) { | |
| 63 | + log.error("医生消息提醒异常,{}",doctorChatCount,e); | |
| 64 | + } | |
| 65 | + | |
| 66 | + } | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + } | |
| 71 | +} |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/HXTask.java
View file @
b4b4678
| 1 | 1 | package com.lyms.talkonlineweb.task; |
| 2 | 2 | |
| 3 | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
| 4 | 5 | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| 6 | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |
| 5 | 7 | import com.lyms.talkonlineweb.domain.LymsDict; |
| 6 | 8 | import com.lyms.talkonlineweb.domain.LymsDoctor; |
| 7 | 9 | import com.lyms.talkonlineweb.domain.LymsPushedart; |
| ... | ... | @@ -45,7 +47,7 @@ |
| 45 | 47 | param.put("vtype",999); |
| 46 | 48 | List<LymsDict> dcLst=lymsDictService.listByMap(param); |
| 47 | 49 | if (dcLst.size()>0 && dcLst.get(0).getCode()==1){ |
| 48 | - List<LymsDoctor> dLst=lymsDoctorService.list(); | |
| 50 | + /*List<LymsDoctor> dLst=lymsDoctorService.list(); | |
| 49 | 51 | List<String> dlLst=dLst.stream().map(d->d.getDlogin()).collect(Collectors.toList()); |
| 50 | 52 | String[] usernames = new String[dlLst.size()]; |
| 51 | 53 | JSONObject jsonObject=hxService.chkUserStatus(dlLst.toArray(usernames)); |
| ... | ... | @@ -62,7 +64,36 @@ |
| 62 | 64 | updateWrapper.eq("dlogin",json[0].replaceAll("\"","")); |
| 63 | 65 | boolean f=lymsDoctorService.update(doctor,updateWrapper); |
| 64 | 66 | |
| 65 | - }); | |
| 67 | + });*/ | |
| 68 | + | |
| 69 | + QueryWrapper<LymsDoctor> query = new QueryWrapper(); | |
| 70 | + query.isNotNull("hxid"); | |
| 71 | + query.orderByAsc("updated_time"); | |
| 72 | + int count = this.lymsDoctorService.count(query); | |
| 73 | + | |
| 74 | + int page = (int)Math.ceil((double)count / 50.0); | |
| 75 | + | |
| 76 | + for(int i = 1; i <= page; ++i) { | |
| 77 | + Page<LymsDoctor> pageC = new Page((long)i, 50L); | |
| 78 | + Page<LymsDoctor> pageDoctors = (Page)this.lymsDoctorService.page(pageC, query); | |
| 79 | + List<LymsDoctor> dLst = pageDoctors.getRecords(); | |
| 80 | + List<String> dlLst=dLst.stream().map(d->d.getDlogin()).collect(Collectors.toList()); | |
| 81 | + String[] usernames = new String[dlLst.size()]; | |
| 82 | + JSONObject jsonObject = this.hxService.chkUserStatus((String[])dlLst.toArray(usernames)); | |
| 83 | + jsonObject.getJSONArray("data").stream().forEach((e) -> { | |
| 84 | + UpdateWrapper<LymsDoctor> updateWrapper = new UpdateWrapper(); | |
| 85 | + LymsDoctor doctor = new LymsDoctor(); | |
| 86 | + String[] json = e.toString().replaceAll("\\{", "").replaceAll("}", "").split(":"); | |
| 87 | + if ("online".equals(json[1].replaceAll("\"", ""))) { | |
| 88 | + doctor.setStat((byte)1); | |
| 89 | + } else { | |
| 90 | + doctor.setStat((byte)0); | |
| 91 | + } | |
| 92 | + | |
| 93 | + updateWrapper.eq("dlogin", json[0].replaceAll("\"", "")); | |
| 94 | + this.lymsDoctorService.update(doctor, updateWrapper); | |
| 95 | + }); | |
| 96 | + } | |
| 66 | 97 | } |
| 67 | 98 | |
| 68 | 99 |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java
View file @
b4b4678
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/HXService.java
View file @
b4b4678
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | import com.alibaba.fastjson.JSONArray; |
| 5 | 5 | import com.alibaba.fastjson.JSONObject; |
| 6 | 6 | import com.alibaba.fastjson.util.IOUtils; |
| 7 | +import com.lyms.talkonlineweb.request.MsgDelParam; | |
| 7 | 8 | import lombok.extern.log4j.Log4j2; |
| 8 | 9 | import org.apache.commons.io.FileUtils; |
| 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | 11 | |
| ... | ... | @@ -43,9 +44,14 @@ |
| 43 | 44 | @Value("${hx.app_name}") |
| 44 | 45 | private String appName; |
| 45 | 46 | |
| 47 | + @Value("${hx.hxuser}") | |
| 48 | + private String hxuser; | |
| 49 | + @Value("${hx.hxpasswd}") | |
| 50 | + private String hxpasswd; | |
| 51 | + | |
| 46 | 52 | @Autowired |
| 47 | 53 | private RestTemplate restTemplate; |
| 48 | - private ResponseEntity<String> resp; | |
| 54 | + //private ResponseEntity<String> resp; | |
| 49 | 55 | |
| 50 | 56 | // @Autowired |
| 51 | 57 | // private RestTemplate restTemplate; |
| ... | ... | @@ -62,6 +68,23 @@ |
| 62 | 68 | // return service; |
| 63 | 69 | // } |
| 64 | 70 | |
| 71 | + public String getHxuser(){ | |
| 72 | + return hxuser; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public String getHxpasswd() { | |
| 76 | + return hxpasswd; | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * 在环信注册的账号,增加前缀 | |
| 81 | + * @param username | |
| 82 | + * @return | |
| 83 | + */ | |
| 84 | + public String assembleHxLoginAccout(String username){ | |
| 85 | + return hxuser+"_"+username; | |
| 86 | + } | |
| 87 | + | |
| 65 | 88 | public String getUrl(){ |
| 66 | 89 | return String.format("http://a1.easemob.com/%s/%s/",orgName,appName); |
| 67 | 90 | } |
| ... | ... | @@ -81,6 +104,7 @@ |
| 81 | 104 | } |
| 82 | 105 | |
| 83 | 106 | public JSONObject getUser(String username){ |
| 107 | + username = assembleHxLoginAccout(username); | |
| 84 | 108 | JSONObject user=new JSONObject(); |
| 85 | 109 | String token=getToken(); |
| 86 | 110 | HttpHeaders headers=new HttpHeaders(); |
| ... | ... | @@ -101,6 +125,7 @@ |
| 101 | 125 | } |
| 102 | 126 | |
| 103 | 127 | public JSONObject addUser(String username,String passwd,String nickname){ |
| 128 | + username = assembleHxLoginAccout(username); | |
| 104 | 129 | JSONObject rs=new JSONObject(); |
| 105 | 130 | Map<String,Object> param=new HashMap<>(); |
| 106 | 131 | HttpHeaders headers=new HttpHeaders(); |
| ... | ... | @@ -114,7 +139,7 @@ |
| 114 | 139 | lParam.add(param); |
| 115 | 140 | log.info("注册环信用户:"+param); |
| 116 | 141 | HttpEntity entity=new HttpEntity(param,headers); |
| 117 | - resp=restTemplate.postForEntity(getUrl()+"users",entity,String.class); | |
| 142 | + ResponseEntity<String> resp=restTemplate.postForEntity(getUrl()+"users",entity,String.class); | |
| 118 | 143 | if (resp.getStatusCodeValue()==200){ |
| 119 | 144 | rs= JSON.parseObject(resp.getBody()); |
| 120 | 145 | } |
| 121 | 146 | |
| ... | ... | @@ -128,12 +153,13 @@ |
| 128 | 153 | * @return |
| 129 | 154 | */ |
| 130 | 155 | public JSONObject delUser(String username){ |
| 156 | + username = assembleHxLoginAccout(username); | |
| 131 | 157 | JSONObject user=new JSONObject(); |
| 132 | 158 | String token=getToken(); |
| 133 | 159 | HttpHeaders headers=new HttpHeaders(); |
| 134 | 160 | headers.add("Authorization","Bearer "+token); |
| 135 | 161 | HttpEntity param=new HttpEntity(headers); |
| 136 | - resp=restTemplate.exchange(getUrl()+"users/"+username, HttpMethod.DELETE,param,String.class); | |
| 162 | + ResponseEntity<String> resp=restTemplate.exchange(getUrl()+"users/"+username, HttpMethod.DELETE,param,String.class); | |
| 137 | 163 | if (resp.getStatusCodeValue()==200){ |
| 138 | 164 | user= JSON.parseObject(resp.getBody()); |
| 139 | 165 | } |
| ... | ... | @@ -158,7 +184,7 @@ |
| 158 | 184 | |
| 159 | 185 | lParam.add(param); |
| 160 | 186 | HttpEntity entity=new HttpEntity(param,headers); |
| 161 | - resp=restTemplate.postForEntity(getUrl()+"messages",entity,String.class); | |
| 187 | + ResponseEntity<String> resp = restTemplate.postForEntity(getUrl()+"messages",entity,String.class); | |
| 162 | 188 | if (resp.getStatusCodeValue()==200){ |
| 163 | 189 | rs= JSON.parseObject(resp.getBody()); |
| 164 | 190 | } |
| ... | ... | @@ -168,11 +194,7 @@ |
| 168 | 194 | |
| 169 | 195 | /** |
| 170 | 196 | * 群组发送消息 |
| 171 | - * @param target hxgroupid | |
| 172 | - * @param target_type 发送的目标类型: | |
| 173 | - * • users:给用户发消息; | |
| 174 | - * • chatgroups:给群发消息; | |
| 175 | - * • chatrooms:给聊天室发消息。 | |
| 197 | + * @param target | |
| 176 | 198 | * @param msgContent |
| 177 | 199 | * @param from |
| 178 | 200 | * @return |
| ... | ... | @@ -195,7 +217,7 @@ |
| 195 | 217 | |
| 196 | 218 | lParam.add(param); |
| 197 | 219 | HttpEntity entity=new HttpEntity(param,headers); |
| 198 | - resp=restTemplate.postForEntity(getUrl()+"messages",entity,String.class); | |
| 220 | + ResponseEntity<String> resp =restTemplate.postForEntity(getUrl()+"messages",entity,String.class); | |
| 199 | 221 | if (resp.getStatusCodeValue()==200){ |
| 200 | 222 | rs= JSON.parseObject(resp.getBody()); |
| 201 | 223 | } |
| 202 | 224 | |
| ... | ... | @@ -216,22 +238,21 @@ |
| 216 | 238 | headers.add("Authorization","Bearer "+token); |
| 217 | 239 | HttpEntity param=new HttpEntity(headers); |
| 218 | 240 | try { |
| 219 | - resp = restTemplate.exchange(getUrl() + "chatmessages/" + time, HttpMethod.GET, param, String.class); | |
| 220 | - | |
| 221 | - if (resp.getStatusCodeValue()==200){ | |
| 222 | - msg= JSON.parseObject(resp.getBody()); | |
| 223 | - log.info(msg); | |
| 224 | - JSONArray data=msg.getJSONArray("data"); | |
| 225 | - if(data.size()>0){ | |
| 226 | - for (int i = 0; i < data.size() ; i++) { | |
| 227 | - String url=data.getJSONObject(i).getString("url"); | |
| 228 | - File file=getFileFromUrl(url); | |
| 229 | - FileUtils.copyURLToFile(new URL(url),file); | |
| 230 | - file=doUncompressFile(file); | |
| 231 | - cLst=FileUtils.readLines(file,"utf-8"); | |
| 241 | + ResponseEntity<String> resp = restTemplate.exchange(getUrl() + "chatmessages/" + time, HttpMethod.GET, param, String.class); | |
| 242 | + if (resp.getStatusCodeValue()==200){ | |
| 243 | + msg= JSON.parseObject(resp.getBody()); | |
| 244 | + log.info(msg); | |
| 245 | + JSONArray data=msg.getJSONArray("data"); | |
| 246 | + if(data.size()>0){ | |
| 247 | + for (int i = 0; i < data.size() ; i++) { | |
| 248 | + String url=data.getJSONObject(i).getString("url"); | |
| 249 | + File file=getFileFromUrl(url); | |
| 250 | + FileUtils.copyURLToFile(new URL(url),file); | |
| 251 | + file=doUncompressFile(file); | |
| 252 | + cLst=FileUtils.readLines(file,"utf-8"); | |
| 253 | + } | |
| 232 | 254 | } |
| 233 | 255 | } |
| 234 | - } | |
| 235 | 256 | }catch (Exception e){ |
| 236 | 257 | log.error(e.getMessage()); |
| 237 | 258 | e.printStackTrace(); |
| ... | ... | @@ -324,7 +345,9 @@ |
| 324 | 345 | JSONObject rs=new JSONObject(); |
| 325 | 346 | Map<String,Object> param=new HashMap<>(); |
| 326 | 347 | HttpHeaders headers=new HttpHeaders(); |
| 327 | - | |
| 348 | + for(int i = 0 ;i < members.length;i++){ | |
| 349 | + members[i] = assembleHxLoginAccout(members[i]); | |
| 350 | + } | |
| 328 | 351 | headers.add("Authorization","Bearer "+getToken()); |
| 329 | 352 | List lParam=new ArrayList(); |
| 330 | 353 | param.put("groupname", Arrays.toString(members)); |
| ... | ... | @@ -335,7 +358,7 @@ |
| 335 | 358 | |
| 336 | 359 | lParam.add(param); |
| 337 | 360 | HttpEntity entity=new HttpEntity(param,headers); |
| 338 | - resp=restTemplate.postForEntity(getUrl()+"chatgroups",entity,String.class); | |
| 361 | + ResponseEntity<String> resp=restTemplate.postForEntity(getUrl()+"chatgroups",entity,String.class); | |
| 339 | 362 | if (resp.getStatusCodeValue()==200){ |
| 340 | 363 | rs= JSON.parseObject(resp.getBody()); |
| 341 | 364 | } |
| 342 | 365 | |
| 343 | 366 | |
| ... | ... | @@ -359,16 +382,18 @@ |
| 359 | 382 | |
| 360 | 383 | lParam.add(param); |
| 361 | 384 | HttpEntity entity=new HttpEntity(param,headers); |
| 362 | - resp=restTemplate.postForEntity(getUrl()+"users/batch/status",entity,String.class); | |
| 385 | + ResponseEntity<String> resp=restTemplate.postForEntity(getUrl()+"users/batch/status",entity,String.class); | |
| 363 | 386 | if (resp.getStatusCodeValue()==200){ |
| 364 | 387 | rs= JSON.parseObject(resp.getBody()); |
| 365 | 388 | } |
| 366 | 389 | log.info(rs); |
| 367 | 390 | return rs; |
| 368 | 391 | } |
| 392 | + | |
| 369 | 393 | /** |
| 370 | 394 | * 环信群组增加用户 |
| 371 | - * @param usernames | |
| 395 | + * @param hxgid | |
| 396 | + * @param dlogin | |
| 372 | 397 | * @return |
| 373 | 398 | */ |
| 374 | 399 | public JSONObject addUserHxGroup(String hxgid,String dlogin) { |
| 375 | 400 | |
| 376 | 401 | |
| ... | ... | @@ -379,16 +404,18 @@ |
| 379 | 404 | headers.add("Authorization","Bearer "+getToken()); |
| 380 | 405 | |
| 381 | 406 | HttpEntity entity=new HttpEntity(param,headers); |
| 382 | - resp=restTemplate.postForEntity(getUrl()+"chatgroups/"+hxgid+"/users/"+dlogin,entity,String.class); | |
| 407 | + ResponseEntity<String> resp=restTemplate.postForEntity(getUrl()+"chatgroups/"+hxgid+"/users/"+dlogin,entity,String.class); | |
| 383 | 408 | if (resp.getStatusCodeValue()==200){ |
| 384 | 409 | rs= JSON.parseObject(resp.getBody()); |
| 385 | 410 | } |
| 386 | 411 | log.info(rs); |
| 387 | 412 | return rs; |
| 388 | 413 | } |
| 414 | + | |
| 389 | 415 | /** |
| 390 | 416 | * 环信群组移除组用户 |
| 391 | - * @param usernames | |
| 417 | + * @param hxgid | |
| 418 | + * @param dlogin | |
| 392 | 419 | * @return |
| 393 | 420 | */ |
| 394 | 421 | public JSONObject delUserHxGroup(String hxgid,String dlogin) { |
| 395 | 422 | |
| ... | ... | @@ -397,11 +424,31 @@ |
| 397 | 424 | HttpHeaders headers=new HttpHeaders(); |
| 398 | 425 | headers.add("Authorization","Bearer "+token); |
| 399 | 426 | HttpEntity param=new HttpEntity(headers); |
| 400 | - resp=restTemplate.exchange(getUrl()+"chatgroups/"+hxgid+"/users/"+dlogin, HttpMethod.DELETE,param,String.class); | |
| 427 | + ResponseEntity<String> resp=restTemplate.exchange(getUrl()+"chatgroups/"+hxgid+"/users/"+dlogin, HttpMethod.DELETE,param,String.class); | |
| 401 | 428 | if (resp.getStatusCodeValue()==200){ |
| 402 | 429 | rs= JSON.parseObject(resp.getBody()); |
| 403 | 430 | } |
| 404 | 431 | return rs; |
| 432 | + } | |
| 433 | + | |
| 434 | + /** | |
| 435 | + * 消息撤回接口 | |
| 436 | + * @param param | |
| 437 | + * @return | |
| 438 | + */ | |
| 439 | + public boolean recallMsg(MsgDelParam param){ | |
| 440 | + HttpHeaders headers=new HttpHeaders(); | |
| 441 | + headers.add("Authorization","Bearer "+getToken()); | |
| 442 | + HttpEntity entity=new HttpEntity(JSON.toJSON(param),headers); | |
| 443 | + ResponseEntity<String> resp=restTemplate.postForEntity(getUrl()+"messages/msg_recall",entity,String.class); | |
| 444 | + log.info("消息撤回接口返回:{},{}",param,resp); | |
| 445 | + if (resp.getStatusCodeValue()==200){ | |
| 446 | + JSONObject json = JSON.parseObject(resp.getBody()); | |
| 447 | + if("yes".equals(json.getJSONObject("data").getString("recalled"))){ | |
| 448 | + return true; | |
| 449 | + } | |
| 450 | + } | |
| 451 | + return false; | |
| 405 | 452 | } |
| 406 | 453 | } |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java
View file @
b4b4678
| ... | ... | @@ -126,6 +126,58 @@ |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | + * 医生端公众号消息 | |
| 130 | + * @param openid | |
| 131 | + * @param template_id | |
| 132 | + * @param dataMap | |
| 133 | + * @param mapInfo | |
| 134 | + * @return | |
| 135 | + * @throws Exception | |
| 136 | + */ | |
| 137 | + public static Integer DoctorSendWeChatMsg(String openid, String template_id, Map<String,Object> dataMap, Map<String,Object> mapInfo)throws Exception { | |
| 138 | + //整体参数map | |
| 139 | + Map<String, Object> paramMap = new HashMap<String, Object>(); | |
| 140 | + paramMap.put("touser", openid); | |
| 141 | + paramMap.put("template_id", template_id); | |
| 142 | + //跳转到小程序用到miniprogram集合参数 | |
| 143 | + paramMap.put("url", "http://weixin.qq.com"); | |
| 144 | + TreeMap<String, String> miniprogram = new TreeMap<String, String>(); | |
| 145 | + miniprogram.put("appid",Constant.DOCTOR_APP_ID); | |
| 146 | + //登录数据 | |
| 147 | + if(CollectionUtils.isNotEmpty(mapInfo) && null!=mapInfo.get("plogin") && null!=mapInfo.get("passwd")){ | |
| 148 | + if(null==mapInfo.get("type") || 1==(int) mapInfo.get("type")) {//null是正常推送状态。 1有值是亲属关注时的状态 2没有病例的时候 | |
| 149 | + miniprogram.put("pagepath", "pages/news/news?plogin=" + mapInfo.get("plogin") + "&passwd=" + mapInfo.get("passwd"));// 注意,这里是支持传参的!!! | |
| 150 | + }else { | |
| 151 | + miniprogram.put("pagepath","pages/concernList/concernList?plogin="+mapInfo.get("plogin")+"&passwd="+mapInfo.get("passwd"));// 没有病例跳转地址 | |
| 152 | + } | |
| 153 | + | |
| 154 | + }else { | |
| 155 | + //意外情况自行登录 | |
| 156 | + miniprogram.put("pagepath","pages/enroll/enroll");// 注意,这里是支持传参的!!! | |
| 157 | + } | |
| 158 | + paramMap.put("miniprogram", miniprogram); | |
| 159 | + paramMap.put("data", dataMap); | |
| 160 | + // 接口地址 | |
| 161 | + //处理access_token失效报40001 | |
| 162 | + Integer code=null; | |
| 163 | + for(int i=0;i<3;i++) { | |
| 164 | + String sendMsgApi = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + AccessTokenServlet.accessToken; | |
| 165 | + String result = repeatDoGetPost(sendMsgApi, "POST", paramMap); | |
| 166 | + log.info("template push result: {}",result); | |
| 167 | + if (StringUtil.isEmpty(result)) { | |
| 168 | + break; | |
| 169 | + } | |
| 170 | + Map<String, Object> resultMap = JSON.parseObject(result, HashMap.class); | |
| 171 | + code=Integer.parseInt(resultMap.get("errcode").toString()); | |
| 172 | + if(!code.equals(40001)){ | |
| 173 | + break; | |
| 174 | + } | |
| 175 | + Thread.sleep(1000 * 1);//解决access_token替换时间差保证access_token长期有效 | |
| 176 | + } | |
| 177 | + return code; | |
| 178 | + } | |
| 179 | + | |
| 180 | + /** | |
| 129 | 181 | * 获取微信用户的公众号openid |
| 130 | 182 | * |
| 131 | 183 | * @param code 登录时获取的code |
talkonlineweb/src/main/resources/mapper/LymsDoctorWorktimeMapper.xml
View file @
b4b4678
| ... | ... | @@ -14,5 +14,26 @@ |
| 14 | 14 | <result property="updatedtime" column="updatedtime" jdbcType="TIMESTAMP"/> |
| 15 | 15 | </resultMap> |
| 16 | 16 | |
| 17 | + <select id = "selectDoctorChatCount" parameterType="java.lang.String" resultType="com.lyms.talkonlineweb.domain.DoctorChatCount"> | |
| 18 | + | |
| 19 | + select | |
| 20 | + d.did, | |
| 21 | + d.dlogin, | |
| 22 | + d.dpasswd, | |
| 23 | + d.dname, | |
| 24 | + d.mobile, | |
| 25 | + d.gzopenid, | |
| 26 | + c.count | |
| 27 | + from | |
| 28 | + lyms_doctor d, | |
| 29 | + lyms_doctor_worktime w, | |
| 30 | + v_doctor_chat_count c | |
| 31 | + where d.did = w.did | |
| 32 | + and d.did = c.did | |
| 33 | + and w.start_time = #{startTime} | |
| 34 | + and c.count > 0 | |
| 35 | + | |
| 36 | + </select> | |
| 37 | + | |
| 17 | 38 | </mapper> |