|
@ -0,0 +1,120 @@
|
|
|
package com.yihu.wlyy.service.app.physicalExamination;
|
|
|
|
|
|
import com.yihu.wlyy.entity.organization.Hospital;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.entity.patient.PatientRemindRecords;
|
|
|
import com.yihu.wlyy.entity.patient.PhysicalExaminationRecords;
|
|
|
import com.yihu.wlyy.entity.patient.SignFamily;
|
|
|
import com.yihu.wlyy.repository.organization.HospitalDao;
|
|
|
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.repository.patient.SignFamilyDao;
|
|
|
import com.yihu.wlyy.repository.physicalExamination.PatientPhysicalExaminationDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.util.IdCardUtil;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by Reece on 2017/10/18/018.
|
|
|
* <p>
|
|
|
* 居民近365天无体检记录时,系统自动发送一条体检提醒信息。使用“代办事项通知”模板
|
|
|
* 代理机制还存在
|
|
|
*/
|
|
|
public class PatientPhysicalExaminationService extends BaseService {
|
|
|
@Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
@Autowired
|
|
|
private PatientDao patientDao;
|
|
|
@Autowired
|
|
|
private WeiXinOpenIdUtils openIdUtils;
|
|
|
@Autowired
|
|
|
private HospitalDao hospitalDao;
|
|
|
@Autowired
|
|
|
private SignFamilyDao familyDao;
|
|
|
@Autowired
|
|
|
private WeiXinAccessTokenUtils accessTokenUtils;
|
|
|
@Autowired
|
|
|
private PatientPhysicalExaminationDao examinationDao;
|
|
|
|
|
|
|
|
|
public void sendExaminationTemplate() throws Exception {
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
c.setTime(new Date());
|
|
|
c.add(Calendar.YEAR, -1);
|
|
|
Date yesteryear = c.getTime();
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
String first = "温馨提醒,您已经超过一年没有到社区进行健康体检啦,为了您和您的家庭医生了解您近期的健康状况,请及时到签约社区进行免费的健康体检哟~";
|
|
|
json.put("remark", "");
|
|
|
json.put("keyword1", "健康体检");
|
|
|
json.put("keyword2", format.format(new Date()));
|
|
|
|
|
|
String accessToken = accessTokenUtils.getAccessToken();
|
|
|
// 1.找出符合条件的居民信息
|
|
|
List<Hospital> hospitals = hospitalDao.findAllHospital();
|
|
|
for (Hospital hospital : hospitals) {
|
|
|
Boolean flag = false;
|
|
|
List<SignFamily> signFamilies = familyDao.findExaminationByHospital(hospital.getCode(), yesteryear);
|
|
|
for (SignFamily signFamilie : signFamilies) {
|
|
|
String patientCode = signFamilie.getPatient();
|
|
|
Patient patient = patientDao.findByCode(patientCode);
|
|
|
String url = "huanzhe/html/jiankangtijian.html?openid=" + patient.getOpenid() + "&toUser=" + patient.getCode() + "&toName=" + patient.getName();
|
|
|
json.put("url", url);
|
|
|
String mobile = patient.getMobile();
|
|
|
|
|
|
if (StringUtils.isNotBlank(patient.getOpenid())) {
|
|
|
json.put("first", first);
|
|
|
pushMsgTask.putWxMsg(accessToken, 11, patient.getOpenid(), patient.getName(), json);
|
|
|
flag = true;
|
|
|
}
|
|
|
//发送代理人
|
|
|
JSONArray jsonArray = openIdUtils.getAgentOpenId(patient.getCode(), patient.getOpenid());
|
|
|
if (jsonArray != null && jsonArray.length() > 0) {
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
org.json.JSONObject j = jsonArray.getJSONObject(i);
|
|
|
Patient member = (Patient) j.get("member");
|
|
|
int start = url.indexOf("&toUser=");
|
|
|
int end = url.indexOf("&", start + 1);
|
|
|
String touser = url.substring(start, end);
|
|
|
url = url.replace(touser, "&toUser=" + member.getCode());
|
|
|
json.remove("first");
|
|
|
try {
|
|
|
json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()) + first);
|
|
|
json.put("url", url);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(member.getOpenid())) {
|
|
|
pushMsgTask.putWxMsg(accessToken, 11, member.getOpenid(), patient.getName(), json);
|
|
|
flag = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (flag){
|
|
|
//发送成功保存发送记录
|
|
|
PhysicalExaminationRecords records = new PhysicalExaminationRecords();
|
|
|
records.setCode(getCode());
|
|
|
records.setType(1);
|
|
|
records.setPatientCode(patientCode);
|
|
|
records.setStatus(1);
|
|
|
records.setCreateTime(new Date());
|
|
|
records.setRemindTime(new Date());
|
|
|
examinationDao.save(records);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|