Commit b4274a13811bb20e9903faf9d7ea5c5724955046

Authored by shiyang
1 parent 985dd0ce9e
Exists in master and in 1 other branch dev

自动回访功能代码优化

Showing 1 changed file with 85 additions and 181 deletions

talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/PushChatInfoTask.java View file @ b4274a1
... ... @@ -77,7 +77,45 @@
77 77 for (Map<String, Object> map : PcInfoList) {
78 78  
79 79 try {
80   - getPcInfoList( map);
  80 + //患者信息
  81 + LymsPatient patient= lymsPatientService.getOne(new QueryWrapper<LymsPatient>()
  82 + .lambda().eq(LymsPatient::getIdno, map.get("idno").toString()));
  83 + //医生信息
  84 + LymsDoctor doctor= lymsDoctorService.getOne(new QueryWrapper<LymsDoctor>()
  85 + .lambda().eq(LymsDoctor::getDlogin, map.get("dlogin").toString()));
  86 + //回访记录
  87 + final List<LymsReturnVisitRecord> returnVisitRecords = lymsReturnVisitRecordService.list(new QueryWrapper<LymsReturnVisitRecord>()
  88 + .lambda().eq(LymsReturnVisitRecord::getPcid, (Integer)map.get("pcid"))
  89 + .eq(LymsReturnVisitRecord::getType, 0));
  90 + //计算(自动回复周期上传病例后- 1:第二天2:第五天3:第十天4:第二十天5:第三十天)
  91 + int day = DateUtil.daysBetween(DateUtil.parseYMD(map.get("createdtime").toString()),new Date());
  92 + switch (returnVisitRecords.size()) {
  93 + case 0:
  94 + if (day==1) {
  95 + getEverydayInfo(map,patient,doctor,0,1);
  96 + }
  97 + break;
  98 + case 1:
  99 + if (day==4) {
  100 + getEverydayInfo(map,patient,doctor,2,2);
  101 + }
  102 + break;
  103 + case 2:
  104 + if (day==9) {
  105 + getEverydayInfo(map,patient,doctor,1,3);
  106 + }
  107 + break;
  108 + case 3:
  109 + if (day==19) {
  110 + getEverydayInfo(map,patient,doctor,0,4);
  111 + }
  112 + break;
  113 + case 4:
  114 + if (day==29) {
  115 + getEverydayInfo(map,patient,doctor,1,5);
  116 + }
  117 + break;
  118 + }
81 119 } catch (Exception e) {
82 120 e.printStackTrace();
83 121 }
84 122  
85 123  
86 124  
87 125  
... ... @@ -85,192 +123,58 @@
85 123 }
86 124 }
87 125  
  126 + /**
  127 + * 每天推送逻辑
  128 + * @param map
  129 + * @param patient
  130 + * @param doctor
  131 + * @param adminType 0:就诊医生 1:值班医生 2:值班护士
  132 + * @param ChatInfoType 自动回复周期上传病例后- 1:第二天2:第五天3:第十天4:第二十天5:第三十天
  133 + */
88 134 @Transactional(rollbackFor = Exception.class)
89   - public void getPcInfoList(Map<String,Object> map){
90   - //患者信息
91   - LymsPatient patient= lymsPatientService.getOne(new QueryWrapper<LymsPatient>()
92   - .lambda().eq(LymsPatient::getIdno, map.get("idno").toString()));
93   - //医生信息
94   - LymsDoctor doctor= lymsDoctorService.getOne(new QueryWrapper<LymsDoctor>()
95   - .lambda().eq(LymsDoctor::getDlogin, map.get("dlogin").toString()));
  135 + public void getEverydayInfo(Map<String,Object> map,LymsPatient patient,LymsDoctor doctor,int adminType,int ChatInfoType){
96 136 //值班医生/值班护士信息
97 137 List<LymsDoctor> doctorAminList= lymsDoctorService.list(new QueryWrapper<LymsDoctor>()
98 138 .lambda().eq(LymsDoctor::getDpid, doctor.getDpid())
99 139 .in(LymsDoctor::getAdminType, Arrays.asList(1,2))
100 140 .orderByAsc(LymsDoctor::getAdminType));
101   - //回访记录
102   - final List<LymsReturnVisitRecord> returnVisitRecords = lymsReturnVisitRecordService.list(new QueryWrapper<LymsReturnVisitRecord>()
103   - .lambda().eq(LymsReturnVisitRecord::getPcid, (Integer)map.get("pcid"))
104   - .eq(LymsReturnVisitRecord::getType, 0));
105   - //计算(自动回复周期上传病例后- 1:第二天2:第五天3:第十天4:第二十天5:第三十天)
106   - int day = DateUtil.daysBetween(DateUtil.parseYMD(map.get("createdtime").toString()),new Date());
107   - switch (returnVisitRecords.size()) {
108   - case 0:
109   - if (day==1) {
110   - //环信聊天群组信息
111   - LymsChatgroup chatgroup = lymsChatgroupService.getOne(new QueryWrapper<LymsChatgroup>()
112   - .lambda().eq(LymsChatgroup::getPcid, (Integer)map.get("pcid")));
113   - if(null==chatgroup){
114   - //创建聊天群组
115   - chatgroup=addChatGroup(map,patient,doctor);
116   - }
117   - //就诊医生回复
118   - final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
119   - .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
120   -
121   - for (LymsIllness lymsIllness : lymsIllnessList) {
122   - final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
123   - .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
124   - .eq(LymsChatInfo::getType, 1));
125   - //推送回访
126   - if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
127   - //推送回访消息和保存发送记录
128   - pushOrMessage(null,chatgroup,chatInfo,doctor);
129   - }else {
130   - throw new RuntimeException("参数不符合");
131   - }
132   - }
133   - //增加回访记录,修改环信群组状态,修改问诊记录状态
134   - addReturnVisitRecordOrUpdate(null,chatgroup ,patient,doctor);
  141 + //环信群组信息
  142 + LymsChatgroup chatgroup = lymsChatgroupService.getOne(new QueryWrapper<LymsChatgroup>()
  143 + .lambda().eq(LymsChatgroup::getPcid, (Integer)map.get("pcid")));
  144 + if(null==chatgroup){
  145 + //创建聊天群组
  146 + chatgroup=addChatGroup(map,patient,doctor);
  147 + }
  148 + //获取 就诊医生/值班医生/值班护士账号
  149 + String dlogin="";
  150 + if(adminType!=0) {
  151 + for (LymsDoctor lymsDoctor : doctorAminList) {
  152 + if (lymsDoctor.getAdminType() == adminType) {
  153 + dlogin = lymsDoctor.getDlogin();
  154 + break;
135 155 }
136   - break;
137   - case 1:
138   - if (day==4) {
139   - //环信群组信息
140   - LymsChatgroup chatgroup = lymsChatgroupService.getOne(new QueryWrapper<LymsChatgroup>()
141   - .lambda().eq(LymsChatgroup::getPcid, (Integer)map.get("pcid")));
142   - if(null==chatgroup){
143   - //创建聊天群组
144   - chatgroup=addChatGroup(map,patient,doctor);
145   - }
146   - //获取值班护士回复
147   - String dlogin="";
148   - for (LymsDoctor lymsDoctor : doctorAminList) {
149   - if (lymsDoctor.getAdminType()==2) {
150   - dlogin=lymsDoctor.getDlogin();
151   - return;
152   - }
153   - }
154   - final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
155   - .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
156   - for (LymsIllness lymsIllness : lymsIllnessList) {
157   - final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
158   - .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
159   - .eq(LymsChatInfo::getType, 2));
160   - //推送回访
161   - if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
162   - //推送回访消息和保存发送记录
163   - pushOrMessage(dlogin,chatgroup,chatInfo,doctor);
164   - }else {
165   - throw new RuntimeException("参数不符合");
166   - }
167   - }
168   - //增加回访记录,修改环信群组状态,修改问诊记录状态
169   - addReturnVisitRecordOrUpdate(dlogin,chatgroup ,patient,doctor);
170   - }
171   - break;
172   - case 2:
173   - if (day==9) {
174   - //环信群组信息
175   - LymsChatgroup chatgroup = lymsChatgroupService.getOne(new QueryWrapper<LymsChatgroup>()
176   - .lambda().eq(LymsChatgroup::getPcid, (Integer)map.get("pcid")));
177   - if(null==chatgroup){
178   - //创建聊天群组
179   - chatgroup=addChatGroup(map,patient,doctor);
180   - }
181   - //获取值班医生回复
182   - String dlogin="";
183   - for (LymsDoctor lymsDoctor : doctorAminList) {
184   - if (lymsDoctor.getAdminType()==1) {
185   - dlogin=lymsDoctor.getDlogin();
186   - return;
187   - }
188   - }
189   - final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
190   - .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
191   - int i=0;
192   - for (LymsIllness lymsIllness : lymsIllnessList) {
193   - final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
194   - .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
195   - .eq(LymsChatInfo::getType, 3));
196   - //推送回访
197   - if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
198   - //推送回访消息和保存发送记录
199   - pushOrMessage(dlogin,chatgroup,chatInfo,doctor);
200   - }else {
201   - throw new RuntimeException("参数不符合");
202   - }
203   - }
204   - //增加回访记录,修改环信群组状态,修改问诊记录状态
205   - addReturnVisitRecordOrUpdate(dlogin,chatgroup ,patient,doctor);
206   - }
207   - break;
208   - case 3:
209   - if (day==19) {
210   - //环信群组信息
211   - LymsChatgroup chatgroup = lymsChatgroupService.getOne(new QueryWrapper<LymsChatgroup>()
212   - .lambda().eq(LymsChatgroup::getPcid, (Integer)map.get("pcid")));
213   - if(null==chatgroup){
214   - //创建聊天群组
215   - chatgroup=addChatGroup(map,patient,doctor);
216   - }
217   - //就诊医生回复
218   - final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
219   - .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
220   - int i=0;
221   - for (LymsIllness lymsIllness : lymsIllnessList) {
222   - final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
223   - .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
224   - .eq(LymsChatInfo::getType, 4));
225   - //推送回访
226   - if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
227   - //推送回访消息和保存发送记录
228   - pushOrMessage(null,chatgroup,chatInfo,doctor);
229   - }else {
230   - throw new RuntimeException("参数不符合");
231   - }
232   - }
233   - //增加回访记录,修改环信群组状态,修改问诊记录状态
234   - addReturnVisitRecordOrUpdate(null,chatgroup ,patient,doctor);
235   - }
236   - break;
237   - case 4:
238   - if (day==29) {
239   - //环信群组信息
240   - LymsChatgroup chatgroup = lymsChatgroupService.getOne(new QueryWrapper<LymsChatgroup>()
241   - .lambda().eq(LymsChatgroup::getPcid, (Integer)map.get("pcid")));
242   - if(null==chatgroup){
243   - //创建聊天群组
244   - chatgroup=addChatGroup(map,patient,doctor);
245   - }
246   - //获取值班医生回复
247   - String dlogin="";
248   - for (LymsDoctor lymsDoctor : doctorAminList) {
249   - if (lymsDoctor.getAdminType()==1) {
250   - dlogin=lymsDoctor.getDlogin();
251   - return;
252   - }
253   - }
254   - final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
255   - .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
256   - int i=0;
257   - for (LymsIllness lymsIllness : lymsIllnessList) {
258   - final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
259   - .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
260   - .eq(LymsChatInfo::getType, 5));
261   - ///推送回访
262   - if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
263   - //推送回访消息和保存发送记录
264   - pushOrMessage(dlogin,chatgroup,chatInfo,doctor);
265   - }else {
266   - throw new RuntimeException("参数不符合");
267   - }
268   - }
269   - //增加回访记录,修改环信群组状态,修改问诊记录状态
270   - addReturnVisitRecordOrUpdate(dlogin,chatgroup ,patient,doctor);
271   - }
272   - break;
  156 + }
  157 + }else {
  158 + dlogin=doctor.getDlogin();
273 159 }
  160 + //病例下的疾病
  161 + final List<LymsIllness> lymsIllnessList = lymsIllnessService.list(new QueryWrapper<LymsIllness>()
  162 + .lambda().eq(LymsIllness::getPcid, (Integer) map.get("pcid")));
  163 + for (LymsIllness lymsIllness : lymsIllnessList) {
  164 + //要推送的疾病对应的话术
  165 + final LymsChatInfo chatInfo = lymsChatInfoService.getOne(new QueryWrapper<LymsChatInfo>()
  166 + .lambda().eq(LymsChatInfo::getIllid, lymsIllness.getIid())
  167 + .eq(LymsChatInfo::getType, ChatInfoType));
  168 + ///推送回访
  169 + if (null!=chatInfo && StringUtil.isNotEmpty(chatgroup.getHxgroupid()) && null!=doctor) {
  170 + //推送回访消息和保存发送记录
  171 + pushOrMessage(dlogin,chatgroup,chatInfo,doctor);
  172 + }else {
  173 + throw new RuntimeException("参数不符合");
  174 + }
  175 + }
  176 + //增加回访记录,修改环信群组状态,修改问诊记录状态
  177 + addReturnVisitRecordOrUpdate(dlogin,chatgroup ,patient,doctor);
274 178 }
275 179  
276 180 /**
... ... @@ -369,7 +273,7 @@
369 273 //保存发送消息记录
370 274 LymsMessage message=new LymsMessage();
371 275 message.setContent(chatInfo.getConten());
372   - message.setFromid(StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);
  276 + message.setFromid(dlogin);
373 277 message.setTargetid(chatgroup.getHxgroupid());
374 278 message.setMtype("TEXT");
375 279 message.setSendtime(new Date());
... ... @@ -394,7 +298,7 @@
394 298 public void addReturnVisitRecordOrUpdate(String dlogin,LymsChatgroup chatgroup ,LymsPatient patient,LymsDoctor doctor) {
395 299 //增加回访记录
396 300 LymsReturnVisitRecord returnVisitRecord=new LymsReturnVisitRecord();
397   - returnVisitRecord.setDlogin(StringUtil.isEmpty(dlogin)? doctor.getDlogin():dlogin);
  301 + returnVisitRecord.setDlogin(dlogin);
398 302 returnVisitRecord.setDpid(doctor.getDpid());
399 303 returnVisitRecord.setIdno(patient.getIdno());
400 304 returnVisitRecord.setType(0);