From 5bf07843b5d2bf99ac6783236fed0f5589f88b68 Mon Sep 17 00:00:00 2001 From: shiyang <316555390@qq.com> Date: Tue, 24 May 2022 18:08:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=9B=9E=E8=AE=BF=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=A2=9E=E5=8A=A0=E6=8E=A8=E9=80=81=E5=85=AC=E4=BC=97?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LymsHisInfoController.java | 16 +- .../controller/PatientController.java | 26 ++ .../talkonlineweb/controller/TestController.java | 38 +- .../talkonlineweb/domain/LymsPushVisitRecord.java | 169 +++++++++ .../com/lyms/talkonlineweb/enums/VisitEnum.java | 35 ++ .../mapper/LymsPushVisitRecordMapper.java | 15 + .../talkonlineweb/service/LymsHisInfoService.java | 2 +- .../service/LymsPushVisitRecordService.java | 11 + .../service/impl/LymsHisInfoServiceImpl.java | 6 +- .../impl/LymsPushVisitRecordServiceImpl.java | 20 ++ .../lyms/talkonlineweb/task/PushChatInfoTask.java | 398 ++++++++++----------- .../java/com/lyms/talkonlineweb/util/Constant.java | 6 +- .../com/lyms/talkonlineweb/util/WeiXinUtil.java | 2 +- .../resources/mapper/LymsPushVisitRecordMapper.xml | 30 ++ 14 files changed, 549 insertions(+), 225 deletions(-) create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushVisitRecord.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/enums/VisitEnum.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPushVisitRecordMapper.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPushVisitRecordService.java create mode 100644 talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsPushVisitRecordServiceImpl.java create mode 100644 talkonlineweb/src/main/resources/mapper/LymsPushVisitRecordMapper.xml diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsHisInfoController.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsHisInfoController.java index b3f59b9..ab48d65 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsHisInfoController.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsHisInfoController.java @@ -79,12 +79,16 @@ public class LymsHisInfoController { @TokenRequired public BaseResponse upHisInfo( @RequestBody @Validated LymsHisInfo lymsHisInfo){ BaseResponse baseResponse=new BaseResponse(); - baseResponse.setErrorcode(0); - baseResponse.setErrormsg("患者上传成功"); - String result = lymsHisInfoService.upHisInfo(lymsHisInfo); - if(StringUtil.isNotEmpty(result)){ - baseResponse.setErrorcode(1); - baseResponse.setErrormsg(result); + try { + baseResponse.setErrorcode(0); + baseResponse.setErrormsg("患者上传成功"); + String result = lymsHisInfoService.upHisInfo(lymsHisInfo); + if(StringUtil.isNotEmpty(result)){ + baseResponse.setErrorcode(1); + baseResponse.setErrormsg(result); + } + } catch (Exception e) { + e.printStackTrace(); } return baseResponse; } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java index 52bcdae..e704003 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/PatientController.java @@ -83,6 +83,8 @@ public class PatientController { @Autowired private RegisterPatientInfoService registerPatientInfoService; + @Autowired + private LymsPushVisitRecordService lymsPushVisitRecordService; /** * 获取患者列表 @@ -1164,4 +1166,28 @@ public class PatientController { } return baseResponse; } + + /** + * PC-查看医生回访推送公众号记录 + * @param getPushVisitRecord + * @param current + * @param size + * @return + */ + @GetMapping("getPushVisitRecord") + @TokenRequired + public BaseResponse getPushVisitRecord(LymsPushVisitRecord visitRecord, int current, int size) { + BaseResponse baseResponse = new BaseResponse(); + try { + QueryWrapper query=new QueryWrapper(); + query.orderByDesc("createdtime"); + Page page= new Page<>(current,size); + Page visitRecordPage = lymsPushVisitRecordService.page(page,query); + baseResponse.setObject(visitRecordPage); + } catch (Exception e) { + e.printStackTrace(); + } + return baseResponse; + } + } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/TestController.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/TestController.java index 772b476..e8344ef 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/TestController.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/TestController.java @@ -1,19 +1,30 @@ package com.lyms.talkonlineweb.controller; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.lyms.talkonlineweb.annotation.TokenRequired; +import com.lyms.talkonlineweb.domain.LymsGroupOrder; +import com.lyms.talkonlineweb.domain.LymsPatient; import com.lyms.talkonlineweb.domain.LymsPcase; +import com.lyms.talkonlineweb.domain.LymsTcard; +import com.lyms.talkonlineweb.service.LymsGroupOrderService; +import com.lyms.talkonlineweb.service.LymsPatientService; import com.lyms.talkonlineweb.service.LymsPcaseService; +import com.lyms.talkonlineweb.service.LymsTcardService; import com.lyms.talkonlineweb.task.*; +import com.lyms.talkonlineweb.util.Constant; +import com.lyms.talkonlineweb.util.HXService; +import com.lyms.talkonlineweb.util.StringUtil; import lombok.extern.java.Log; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.lang.reflect.Array; +import java.util.*; @RestController @Log @@ -30,11 +41,24 @@ public class TestController { private PushIllnessTypeData pushIllnessTypeData; @Autowired private PushIllnessTypeTask pushIllnessTypeTask; + @Autowired + private LymsGroupOrderService lymsGroupOrderService; + @Autowired + private LymsPatientService lymsPatientService;//患者 + @Autowired + private LymsTcardService lymsTcardService;//问诊卡信息 + @Autowired + private HXService hxService; + @Autowired + private PushChatInfoTask pushChatInfoTask; @GetMapping("test") @TokenRequired public void test() throws Exception { - getPatientInfoTask.getPatientInfo(); + LymsGroupOrder a=new LymsGroupOrder(); + a.setTotalPrices(465); + lymsGroupOrderService.save(a); + System.out.println(a); } @GetMapping("test9") @@ -60,6 +84,12 @@ public class TestController { pushIllnessTypeTask.PushIllnessTypeTask(); } + @GetMapping("test3") + @TokenRequired + public void test3() { + pushChatInfoTask.pushChatInfo(); + } + // @Autowired // private LymsUserService lymsUserService; diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushVisitRecord.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushVisitRecord.java new file mode 100644 index 0000000..fbca1de --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsPushVisitRecord.java @@ -0,0 +1,169 @@ +package com.lyms.talkonlineweb.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + +/** + * + * @TableName lyms_push_visit_record + */ +@TableName(value ="lyms_push_visit_record") +@Data +public class LymsPushVisitRecord implements Serializable { + /** + * + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + /** + * 患者id + */ + @TableField(value = "pid") + private Integer pid; + + /** + * 患者姓名 + */ + @TableField(value = "pname") + private String pname; + + /** + * 疾病id + */ + @TableField(value = "iid") + private Integer iid; + + /** + * 疾病名称 + */ + @TableField(value = "iiname") + private String iiname; + + /** + * 回访医生id + */ + @TableField(value = "did") + private Integer did; + + /** + * 回访医生姓名 + */ + @TableField(value = "dname") + private String dname; + + /** + * 自动回复类型-1:第二天2:第五天3:第十天4:第二十天5:第三十天 + */ + @TableField(value = "type") + private Integer type; + + /** + * 回访内容 + */ + @TableField(value = "content") + private String content; + + /** + * 推送状态: 1成功 2失败。(在备注写失败原因) + */ + @TableField(value = "state") + private Integer state; + + /** + * 备注 + */ + @TableField(value = "remark") + private String remark; + + /** + * 创建时间 + */ + @TableField(value = "createdtime") + private Date createdtime; + + /** + * 修改时间 + */ + @TableField(value = "update_time") + private Date updateTime; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + LymsPushVisitRecord other = (LymsPushVisitRecord) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getPid() == null ? other.getPid() == null : this.getPid().equals(other.getPid())) + && (this.getPname() == null ? other.getPname() == null : this.getPname().equals(other.getPname())) + && (this.getIid() == null ? other.getIid() == null : this.getIid().equals(other.getIid())) + && (this.getIiname() == null ? other.getIiname() == null : this.getIiname().equals(other.getIiname())) + && (this.getDid() == null ? other.getDid() == null : this.getDid().equals(other.getDid())) + && (this.getDname() == null ? other.getDname() == null : this.getDname().equals(other.getDname())) + && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType())) + && (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent())) + && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState())) + && (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark())) + && (this.getCreatedtime() == null ? other.getCreatedtime() == null : this.getCreatedtime().equals(other.getCreatedtime())) + && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getPid() == null) ? 0 : getPid().hashCode()); + result = prime * result + ((getPname() == null) ? 0 : getPname().hashCode()); + result = prime * result + ((getIid() == null) ? 0 : getIid().hashCode()); + result = prime * result + ((getIiname() == null) ? 0 : getIiname().hashCode()); + result = prime * result + ((getDid() == null) ? 0 : getDid().hashCode()); + result = prime * result + ((getDname() == null) ? 0 : getDname().hashCode()); + result = prime * result + ((getType() == null) ? 0 : getType().hashCode()); + result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode()); + result = prime * result + ((getState() == null) ? 0 : getState().hashCode()); + result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode()); + result = prime * result + ((getCreatedtime() == null) ? 0 : getCreatedtime().hashCode()); + result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", pid=").append(pid); + sb.append(", pname=").append(pname); + sb.append(", iid=").append(iid); + sb.append(", iiname=").append(iiname); + sb.append(", did=").append(did); + sb.append(", dname=").append(dname); + sb.append(", type=").append(type); + sb.append(", content=").append(content); + sb.append(", state=").append(state); + sb.append(", remark=").append(remark); + sb.append(", createdtime=").append(createdtime); + sb.append(", updateTime=").append(updateTime); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/enums/VisitEnum.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/enums/VisitEnum.java new file mode 100644 index 0000000..79aaf8e --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/enums/VisitEnum.java @@ -0,0 +1,35 @@ +package com.lyms.talkonlineweb.enums; + +import lombok.Getter; + +/** + * 回访状态 + * 自动回复周期上传病例后- 1:第二天 2:第五天 3:第十天 4:第二十天 5:第三十天 + */ +@Getter +public enum VisitEnum { + + a(1, "第二天"), + b(2, "第五天"), + c(3, "第十天"), + d(4, "第十天"), + e(5, "第三十天"); + + private Integer code; + private String name; + + VisitEnum(Integer code, String name){ + this.code = code; + this.name = name; + } + + public static String getName(Integer code) { + VisitEnum[] values = VisitEnum.values(); + for (VisitEnum value : values) { + if (value.getCode().equals(code)) { + return value.getName(); + } + } + return ""; + } +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPushVisitRecordMapper.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPushVisitRecordMapper.java new file mode 100644 index 0000000..49e9e96 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/mapper/LymsPushVisitRecordMapper.java @@ -0,0 +1,15 @@ +package com.lyms.talkonlineweb.mapper; + +import com.lyms.talkonlineweb.domain.LymsPushVisitRecord; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + * @Entity com.lyms.talkonlineweb.domain.LymsPushVisitRecord + */ +public interface LymsPushVisitRecordMapper extends BaseMapper { + +} + + + + diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsHisInfoService.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsHisInfoService.java index 85ac5af..a44b56a 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsHisInfoService.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsHisInfoService.java @@ -8,5 +8,5 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface LymsHisInfoService extends IService { - String upHisInfo(LymsHisInfo lymsHisInfo); + String upHisInfo(LymsHisInfo lymsHisInfo) throws Exception; } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPushVisitRecordService.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPushVisitRecordService.java new file mode 100644 index 0000000..b96cc60 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/LymsPushVisitRecordService.java @@ -0,0 +1,11 @@ +package com.lyms.talkonlineweb.service; + +import com.lyms.talkonlineweb.domain.LymsPushVisitRecord; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * + */ +public interface LymsPushVisitRecordService extends IService { + +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsHisInfoServiceImpl.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsHisInfoServiceImpl.java index 9a4ff24..694bcb3 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsHisInfoServiceImpl.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsHisInfoServiceImpl.java @@ -51,8 +51,8 @@ public class LymsHisInfoServiceImpl extends ServiceImpl + implements LymsPushVisitRecordService{ + +} + + + + diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushChatInfoTask.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushChatInfoTask.java index db1bbf4..4e766e8 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushChatInfoTask.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushChatInfoTask.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.lyms.talkonlineweb.domain.*; +import com.lyms.talkonlineweb.enums.VisitEnum; import com.lyms.talkonlineweb.service.*; import com.lyms.talkonlineweb.util.*; import lombok.Data; @@ -61,6 +62,10 @@ public class PushChatInfoTask { @Autowired private LymsTkrecordService lymsTkrecordService; + @Autowired + private LymsPushVisitRecordService lymsPushVisitRecordService; + @Autowired + private PushArticleTask pushArticleTask; /** * 每天19点执行自动回访功能 @@ -70,7 +75,7 @@ public class PushChatInfoTask { * 第二十天:就诊医生 * 第三十天:值班医生 */ - @Scheduled(cron = "0 0 19 * * ?") +// @Scheduled(cron = "0 0 19 * * ?") public void pushChatInfo() { //用户下的病例信息。每个环信群组代表一个病例,一个病例下有多个疾病种类。 List> PcInfoList=lymsPatientService.getPcInfoList(); @@ -83,37 +88,24 @@ public class PushChatInfoTask { //医生信息 LymsDoctor doctor= lymsDoctorService.getOne(new QueryWrapper() .lambda().eq(LymsDoctor::getDlogin, map.get("dlogin").toString())); - //回访记录 - final List returnVisitRecords = lymsReturnVisitRecordService.list(new QueryWrapper() - .lambda().eq(LymsReturnVisitRecord::getPcid, (Integer)map.get("pcid")) - .eq(LymsReturnVisitRecord::getType, 0)); + //计算(自动回复周期上传病例后- 1:第二天2:第五天3:第十天4:第二十天5:第三十天) int day = DateUtil.daysBetween(DateUtil.parseYMD(map.get("createdtime").toString()),new Date()); - switch (returnVisitRecords.size()) { - case 0: - if (day==1) { - getEverydayInfo(map,patient,doctor,0,1); - } - break; + switch (day) { case 1: - if (day==4) { - getEverydayInfo(map,patient,doctor,2,2); - } + getEverydayInfo(map,patient,doctor,0,1); break; - case 2: - if (day==9) { - getEverydayInfo(map,patient,doctor,1,3); - } + case 4: + getEverydayInfo(map,patient,doctor,2,2); break; - case 3: - if (day==19) { - getEverydayInfo(map,patient,doctor,0,4); - } + case 9: + getEverydayInfo(map,patient,doctor,1,3); break; - case 4: - if (day==29) { - getEverydayInfo(map,patient,doctor,1,5); - } + case 19: + getEverydayInfo(map,patient,doctor,0,4); + break; + case 20: + getEverydayInfo(map,patient,doctor,1,5); break; } } catch (Exception e) { @@ -131,199 +123,187 @@ public class PushChatInfoTask { * @param adminType 0:就诊医生 1:值班医生 2:值班护士 * @param ChatInfoType 自动回复周期上传病例后- 1:第二天2:第五天3:第十天4:第二十天5:第三十天 */ - @Transactional(rollbackFor = Exception.class) - public void getEverydayInfo(Map map,LymsPatient patient,LymsDoctor doctor,int adminType,int ChatInfoType){ - //值班医生/值班护士信息 - List doctorAminList= lymsDoctorService.list(new QueryWrapper() - .lambda().eq(LymsDoctor::getDpid, doctor.getDpid()) - .in(LymsDoctor::getAdminType, Arrays.asList(1,2)) - .orderByAsc(LymsDoctor::getAdminType)); - //环信群组信息 - LymsChatgroup chatgroup = lymsChatgroupService.getOne(new QueryWrapper() - .lambda().eq(LymsChatgroup::getPcid, (Integer)map.get("pcid"))); - if(null==chatgroup){ - //创建聊天群组 - chatgroup=addChatGroup(map,patient,doctor); - } - //获取 就诊医生/值班医生/值班护士账号 - String dlogin=""; - if(adminType!=0) { - for (LymsDoctor lymsDoctor : doctorAminList) { - if (lymsDoctor.getAdminType() == adminType) { - dlogin = lymsDoctor.getDlogin(); - break; - } - } - }else { - dlogin=doctor.getDlogin(); - } - //病例下的疾病 - final List lymsIllnessList = lymsIllnessService.list(new QueryWrapper() - .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid"))); - for (LymsIllness lymsIllness : lymsIllnessList) { - //要推送的疾病对应的话术 - final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper() - .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid()) - .eq(LymsChatInfo::getType, ChatInfoType)); - ///推送回访 - if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) { - //推送回访消息和保存发送记录 - pushOrMessage(dlogin,chatgroup,chatInfo,doctor); - }else { - throw new RuntimeException("参数不符合"); - } - } - //增加回访记录,修改环信群组状态,修改问诊记录状态 - addReturnVisitRecordOrUpdate(dlogin,chatgroup ,patient,doctor); - } - - /** - * 创建环信群组 - * @param map - * @param patient - * @param doctor - * @return - */ - @Transactional(rollbackFor = Exception.class) - public LymsChatgroup addChatGroup(Map map,LymsPatient patient,LymsDoctor doctor){ - List adminDlogins=new ArrayList<>(); - adminDlogins.add(patient.getIdno()); - List groupnames=new ArrayList<>(); - groupnames.add(patient.getPname()); - //患者注册环信 - if (StringUtil.isEmpty(patient.getHxid())) { - JSONObject json = hxService.addUser(patient.getIdno(), Constant.COMMON_PASSWD, patient.getPname()); - JSONArray rArr = json.getJSONArray("entities"); - if (rArr.size() > 0) { - patient.setHxid(rArr.getJSONObject(0).getString("uuid")); - final boolean b = lymsPatientService.updateById(patient); - if (!b) { - throw new RuntimeException("回滚状态,执行失败,请联系管理员"); + @Transactional(rollbackFor = {Exception.class,RuntimeException.class}) + public void getEverydayInfo(Map map,LymsPatient patient,LymsDoctor doctor,int adminType,int ChatInfoType) throws Exception,RuntimeException { + try { + //值班医生/值班护士信息 + List doctorAminList= lymsDoctorService.list(new QueryWrapper() + .lambda().eq(LymsDoctor::getDpid, doctor.getDpid()) + .in(LymsDoctor::getAdminType, Arrays.asList(1,2)) + .orderByAsc(LymsDoctor::getAdminType)); + //获取 就诊医生/值班医生/值班护士账号 + LymsDoctor doctor2=new LymsDoctor(); + if(adminType!=0) { + for (LymsDoctor lymsDoctor : doctorAminList) { + if (lymsDoctor.getAdminType() == adminType) { + doctor2 = lymsDoctor; + break; + } } }else { - throw new RuntimeException("回滚状态,执行失败,请联系管理员"); + doctor2=doctor; } - } - //查询值班医生/值班护士 - List doctorAminList= lymsDoctorService.list(new QueryWrapper() - .lambda().eq(LymsDoctor::getDpid, doctor.getDpid()) - .in(LymsDoctor::getAdminType, Arrays.asList(1,2)) - .orderByAsc(LymsDoctor::getAdminType)); - //科室值班医生注册环信 - for (LymsDoctor lymsDoctor : doctorAminList) { - if(StringUtil.isEmpty(lymsDoctor.getHxid())) { - JSONObject json = hxService.addUser(lymsDoctor.getDlogin(), Constant.COMMON_PASSWD, lymsDoctor.getDname()); - JSONArray rArr = json.getJSONArray("entities"); - if (rArr.size() > 0) { - lymsDoctor.setHxid(rArr.getJSONObject(0).getString("uuid")); - final boolean b = lymsDoctorService.updateById(lymsDoctor); - if (!b) { - throw new RuntimeException("回滚状态,执行失败,请联系管理员"); + //环信群组 + LymsChatgroup chatgroup=null; + //病例下的疾病 + final List lymsIllnessList = lymsIllnessService.list(new QueryWrapper() + .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid"))); + for (LymsIllness lymsIllness : lymsIllnessList) { + //要推送的疾病对应的话术 + final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper() + .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid()) + .eq(LymsChatInfo::getType, ChatInfoType)); + ///推送回访 + if (null!=chatInfo && null!=doctor2) { + //环信群组信息 + chatgroup = lymsChatgroupService.getOne(new QueryWrapper() + .lambda().eq(LymsChatgroup::getPcid, (Integer)map.get("pcid"))); + if(null==chatgroup){ + //创建聊天群组 + List adminDlogins=new ArrayList<>(); + adminDlogins.add(patient.getIdno()); + List groupnames=new ArrayList<>(); + groupnames.add(patient.getPname()); + //患者注册环信 + if (StringUtil.isEmpty(patient.getHxid())) { + JSONObject json = hxService.addUser(patient.getIdno(), Constant.COMMON_PASSWD, patient.getPname()); + JSONArray rArr = json.getJSONArray("entities"); + if (rArr.size() > 0) { + patient.setHxid(rArr.getJSONObject(0).getString("uuid")); + final boolean b = lymsPatientService.updateById(patient); + if (!b) { + throw new Exception("回滚状态,执行失败,请联系管理员"); + } + }else { + throw new Exception("回滚状态,执行失败,请联系管理员"); + } + } + //科室值班医生注册环信 + for (LymsDoctor lymsDoctor : doctorAminList) { + if(StringUtil.isEmpty(lymsDoctor.getHxid())) { + JSONObject json = hxService.addUser(lymsDoctor.getDlogin(), Constant.COMMON_PASSWD, lymsDoctor.getDname()); + JSONArray rArr = json.getJSONArray("entities"); + if (rArr.size() > 0) { + lymsDoctor.setHxid(rArr.getJSONObject(0).getString("uuid")); + final boolean b = lymsDoctorService.updateById(lymsDoctor); + if (!b) { + throw new Exception("回滚状态,执行失败,请联系管理员"); + } + } + } + adminDlogins.add(lymsDoctor.getDlogin()); + groupnames.add(lymsDoctor.getDname()); + } + if ( ! adminDlogins.contains(doctor.getDlogin())) { + //医生注册环信 + if (StringUtil.isEmpty(doctor.getHxid())) { + JSONObject json = hxService.addUser(doctor.getDlogin(), Constant.COMMON_PASSWD, doctor.getDname()); + JSONArray rArr = json.getJSONArray("entities"); + if (rArr.size() > 0) { + doctor.setHxid(rArr.getJSONObject(0).getString("uuid")); + final boolean b = lymsDoctorService.updateById(doctor); + if (!b) { + throw new Exception("回滚状态,执行失败,请联系管理员"); + } + } + } + adminDlogins.add(doctor.getDlogin()); + groupnames.add(doctor.getDname()); + } + JSONObject rJson = hxService.addChatGroups(StringUtils.join(adminDlogins.toArray(), ","), hxuser, adminDlogins.toArray(new String[adminDlogins.size()])); + LymsChatgroup group =new LymsChatgroup(); + group.setGroupname(StringUtils.join(groupnames.toArray(), ",")); + group.setDescription(StringUtils.join(adminDlogins.toArray(), ",")); + group.setOwnerk(hxuser); + group.setFromp(patient.getIdno()); + group.setHxgroupid(rJson.getJSONObject("data").getString("groupid")); + group.setTarget(doctor.getDlogin()); + group.setType(1); + group.setStat(0); + group.setPcid((Integer)map.get("pcid")); + final boolean save = lymsChatgroupService.save(group); + if (!save) { + throw new Exception("回滚状态,执行失败,请联系管理员"); + } + chatgroup=group; } - } - } - adminDlogins.add(lymsDoctor.getDlogin()); - groupnames.add(lymsDoctor.getDname()); - } - if ( ! adminDlogins.contains(doctor.getDlogin())) { - //医生注册环信 - if (StringUtil.isEmpty(doctor.getHxid())) { - JSONObject json = hxService.addUser(doctor.getDlogin(), Constant.COMMON_PASSWD, doctor.getDname()); - JSONArray rArr = json.getJSONArray("entities"); - if (rArr.size() > 0) { - doctor.setHxid(rArr.getJSONObject(0).getString("uuid")); - final boolean b = lymsDoctorService.updateById(doctor); - if (!b) { - throw new RuntimeException("回滚状态,执行失败,请联系管理员"); + //推送回访消息和保存发送记录 + JSONObject jsonObject = hxService.sendGroupMsg(new String[]{chatgroup.getHxgroupid()}, chatInfo.getConten(), doctor2.getDlogin()); + if (null!=jsonObject) { + //保存发送消息记录 + LymsMessage message=new LymsMessage(); + message.setContent(chatInfo.getConten()); + message.setFromid(doctor2.getDlogin()); + message.setTargetid(chatgroup.getHxgroupid()); + message.setMtype("TEXT"); + message.setSendtime(new Date()); + message.setType(1); + final boolean save = lymsMessageService.save(message); + if (! save) { + throw new Exception("回滚状态,执行失败,请联系管理员"); + } + }else { + throw new Exception("回滚状态,执行失败,请联系管理员"); } + //同时推送公众号消息 + Map mapTemplate=new HashMap<>(); + String content=chatInfo.getConten().substring(0,50)+"..."; + mapTemplate.put("first",new DataEntity(content,"#173177")); + mapTemplate.put("keyword1",new DataEntity(doctor2.getDname(),"#173177")); + mapTemplate.put("keyword2",new DataEntity(DateUtil.getyyyy_MM_dd1(new Date()),"#173177")); + mapTemplate.put("remark",new DataEntity("请点击下方进入小程序,根据病例点咨询查看医生回访信息。","#173177")); + Map mapInfo = pushArticleTask.pLoginInfo(patient.getId()); + Integer code= WeiXinUtil.SendWeChatMsg(patient.getGzopenid(),Constant.GZ_TEMPLATE_ID_DOCTOR_VISIT,mapTemplate,mapInfo); + //保存推送记录 + LymsPushVisitRecord lymsPushVisitRecord=new LymsPushVisitRecord(); + lymsPushVisitRecord.setPid(patient.getId()); + lymsPushVisitRecord.setPname(patient.getPname()); + lymsPushVisitRecord.setIid(lymsIllness.getIid()); + lymsPushVisitRecord.setIiname(lymsIllness.getIname()); + lymsPushVisitRecord.setDid(doctor2.getDid()); + lymsPushVisitRecord.setDname(doctor2.getDname()); + lymsPushVisitRecord.setType(chatInfo.getType()); + lymsPushVisitRecord.setContent(chatInfo.getConten()); + lymsPushVisitRecord.setState((null==code||code!=0)?2:1);//推送状态: 1成功 2失败。 + lymsPushVisitRecord.setRemark("推送短消息-> " + VisitEnum.getName(chatInfo.getType())+" - "+patient.getPname()+" ;回访医生:"+doctor2.getDname()+";疾病名称:"+ lymsIllness.getIname() + "; [ "+(lymsPushVisitRecord.getState()==1?"成功":"失败")+"]; code:" + code); + lymsPushVisitRecordService.save(lymsPushVisitRecord); + }else { + throw new Exception("回滚操作,没有疾病话术。"); } } - adminDlogins.add(doctor.getDlogin()); - groupnames.add(doctor.getDname()); - } - JSONObject rJson = hxService.addChatGroups(StringUtils.join(adminDlogins.toArray(), ","), hxuser, adminDlogins.toArray(new String[adminDlogins.size()])); - LymsChatgroup group =new LymsChatgroup(); - group.setGroupname(StringUtils.join(groupnames.toArray(), ",")); - group.setDescription(StringUtils.join(adminDlogins.toArray(), ",")); - group.setOwnerk(hxuser); - group.setFromp(patient.getIdno()); - group.setHxgroupid(rJson.getJSONObject("data").getString("groupid")); - group.setTarget(doctor.getDlogin()); - group.setType(1); - group.setStat(0); - group.setPcid((Integer)map.get("pcid")); - final boolean save = lymsChatgroupService.save(group); - if (!save) { - throw new RuntimeException("回滚状态,执行失败,请联系管理员"); - } - return group; - } - - /** - * 推送回访消息和保存发送记录 - * @param dlogin 发送医生 - * @param chatgroup - * @param chatInfo - * @param doctor - */ - @Transactional(rollbackFor = Exception.class) - public void pushOrMessage(String dlogin,LymsChatgroup chatgroup,LymsChatInfo chatInfo,LymsDoctor doctor) { - JSONObject jsonObject = hxService.sendGroupMsg(new String[]{chatgroup.getHxgroupid()}, chatInfo.getConten(), StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin); - if (null!=jsonObject) { - //保存发送消息记录 - LymsMessage message=new LymsMessage(); - message.setContent(chatInfo.getConten()); - message.setFromid(dlogin); - message.setTargetid(chatgroup.getHxgroupid()); - message.setMtype("TEXT"); - message.setSendtime(new Date()); - message.setType(1); - final boolean save = lymsMessageService.save(message); - if (! save) { - throw new RuntimeException("回滚状态,执行失败,请联系管理员"); + //增加回访记录,修改环信群组状态,修改问诊记录状态 + LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord(); + returnVisitRecord.setDlogin(doctor2.getDlogin()); + returnVisitRecord.setDpid(doctor2.getDpid()); + returnVisitRecord.setIdno(patient.getIdno()); + returnVisitRecord.setType(0); + returnVisitRecord.setHxgroupid(chatgroup.getHxgroupid()); + returnVisitRecord.setPcid(chatgroup.getPcid()); + final boolean save = lymsReturnVisitRecordService.save(returnVisitRecord); + if (!save) { + throw new Exception("回滚状态,执行失败,请联系管理员"); } - }else { - throw new RuntimeException("回滚状态,执行失败,请联系管理员"); - } - } - - /** - * 增加回访记录,修改环信群组状态,修改问诊记录状态 - * @param dlogin - * @param chatgroup - * @param patient - * @param doctor - */ - @Transactional(rollbackFor = Exception.class) - public void addReturnVisitRecordOrUpdate(String dlogin,LymsChatgroup chatgroup ,LymsPatient patient,LymsDoctor doctor) { - //增加回访记录 - LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord(); - returnVisitRecord.setDlogin(dlogin); - returnVisitRecord.setDpid(doctor.getDpid()); - returnVisitRecord.setIdno(patient.getIdno()); - returnVisitRecord.setType(0); - returnVisitRecord.setHxgroupid(chatgroup.getHxgroupid()); - returnVisitRecord.setPcid(chatgroup.getPcid()); - final boolean save = lymsReturnVisitRecordService.save(returnVisitRecord); - if (!save) { - throw new RuntimeException("回滚状态,执行失败,请联系管理员"); - } - chatgroup.setType(1); - chatgroup.setStat(0); - final boolean b = lymsChatgroupService.updateById(chatgroup); - if (!b) { - throw new RuntimeException("回滚状态,执行失败,请联系管理员"); - } - //修改同一群组记录的状态 - final List tkrecordList = lymsTkrecordService.list(new QueryWrapper() - .lambda().eq(LymsTkrecord::getHxgroupid, chatgroup.getHxgroupid())); - for (LymsTkrecord lymsTkrecord : tkrecordList) { - lymsTkrecord.setStat(0); - final boolean saveOrUpdate = lymsTkrecordService.updateById(lymsTkrecord); - if (!saveOrUpdate) { - throw new RuntimeException("回滚状态,执行失败,请联系管理员"); + chatgroup.setType(1); + chatgroup.setStat(0); + final boolean b = lymsChatgroupService.updateById(chatgroup); + if (!b) { + throw new Exception("回滚状态,执行失败,请联系管理员"); } + //修改同一群组记录的状态 + final List tkrecordList = lymsTkrecordService.list(new QueryWrapper() + .lambda().eq(LymsTkrecord::getHxgroupid, chatgroup.getHxgroupid())); + for (LymsTkrecord lymsTkrecord : tkrecordList) { + lymsTkrecord.setStat(0); + final boolean saveOrUpdate = lymsTkrecordService.updateById(lymsTkrecord); + if (!saveOrUpdate) { + throw new Exception("回滚状态,执行失败,请联系管理员"); + } + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception("回滚状态,执行失败,请联系管理员"); } } + } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java index 886249b..74f7de5 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/Constant.java @@ -14,11 +14,11 @@ public class Constant { */ public static final String MCHID = "1426009502"; + /** * 患者小程序appid */ public static final String PAT_APP_ID = "wxe3b5c34317a0f85b"; - /** * 签名加密 key */ @@ -55,6 +55,10 @@ public class Constant { */ public static final String GZ_TEMPLATE_ID_RETURN_VISIT ="1xjLJ7LzI-v7qy12QBOKqfv0j3sbN-2lmeXH5GHz7YA"; /** + * 公众号发送消息模板-医生回访提醒消息 + */ + public static final String GZ_TEMPLATE_ID_DOCTOR_VISIT ="81VRsOtBixUDZV2_XRTIPYPNnFjzo6X_d4jN5D4JVb8"; + /** * 公众号的appid */ public static final String GZ_APP_ID ="wxd3c36244d006cb90"; diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java index 8cb5544..73ad05f 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/util/WeiXinUtil.java @@ -93,7 +93,7 @@ public class WeiXinUtil { miniprogram.put("appid",Constant.PAT_APP_ID); //登录数据 if(CollectionUtils.isNotEmpty(mapInfo) && null!=mapInfo.get("plogin") && null!=mapInfo.get("passwd")){ - if(null==mapInfo.get("type") || 1==(int) mapInfo.get("type")) {//null是正常推送状态。 有值是亲属关注时的状态 + if(null==mapInfo.get("type") || 1==(int) mapInfo.get("type")) {//null是正常推送状态。 1有值是亲属关注时的状态 2没有病例的时候 miniprogram.put("pagepath", "pages/news/news?plogin=" + mapInfo.get("plogin") + "&passwd=" + mapInfo.get("passwd"));// 注意,这里是支持传参的!!! }else { miniprogram.put("pagepath","pages/concernList/concernList?plogin="+mapInfo.get("plogin")+"&passwd="+mapInfo.get("passwd"));// 没有病例跳转地址 diff --git a/talkonlineweb/src/main/resources/mapper/LymsPushVisitRecordMapper.xml b/talkonlineweb/src/main/resources/mapper/LymsPushVisitRecordMapper.xml new file mode 100644 index 0000000..d936f4d --- /dev/null +++ b/talkonlineweb/src/main/resources/mapper/LymsPushVisitRecordMapper.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + id,pid,pname, + iid,iiname,did, + dname,type,content, + state,remark,createdtime, + update_time + + -- 1.8.3.1