|
@ -6,7 +6,13 @@ import com.yihu.wlyy.entity.patient.prescription.PrescriptionLog;
|
|
|
import com.yihu.wlyy.repository.dict.SystemDictDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
|
|
|
import com.yihu.wlyy.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.util.DateUtil;
|
|
|
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.quartz.Job;
|
|
|
import org.quartz.JobExecutionContext;
|
|
|
import org.quartz.JobExecutionException;
|
|
@ -14,6 +20,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@ -33,6 +40,12 @@ public class PatientConfirmReceiptJob implements Job {
|
|
|
private PatientDao patientDao;
|
|
|
@Autowired
|
|
|
private SystemDictDao systemDictDao;
|
|
|
@Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
@Autowired
|
|
|
private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
|
|
|
@Autowired
|
|
|
private WeiXinOpenIdUtils weiXinOpenIdUtils;
|
|
|
|
|
|
@Override
|
|
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
|
@ -58,12 +71,14 @@ public class PatientConfirmReceiptJob implements Job {
|
|
|
long days = DateUtil.getDays(today,payTime);
|
|
|
if(days == 3){
|
|
|
//支付后第三天发送自动确认预提醒
|
|
|
sendWechatTemplate(1,patient);
|
|
|
}
|
|
|
int result = today.compareTo(confirm);
|
|
|
if (result >= 0) {
|
|
|
prescription.setStatus(PrescriptionLog.PrescriptionLogStatus.finish.getValue());
|
|
|
list.add(prescription);
|
|
|
//发送自动确认提醒
|
|
|
sendWechatTemplate(2,patient);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -77,4 +92,80 @@ public class PatientConfirmReceiptJob implements Job {
|
|
|
logger.info("PatientConfirmReceiptJob error ..........,message:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 自动确认收货推送信息变更通知消息提醒
|
|
|
*
|
|
|
* @param type 监测类型 2立即提醒,1预提醒
|
|
|
* @param patient 居民code
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public void sendWechatTemplate(int type, String patient) throws Exception {
|
|
|
Patient people = patientDao.findByCode(patient);
|
|
|
String openId = people.getOpenid();
|
|
|
String name = people.getName();
|
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
JSONArray jsonArray = null;
|
|
|
JSONObject sendJson = new JSONObject();
|
|
|
|
|
|
if (type == 1) {
|
|
|
String url = "prescription/html/order_tracking.html?represented="+patient;
|
|
|
|
|
|
String first = name + "您好,您的续方订单将在4天后自动确认收药,如您已经取药,请点击本消息完成确认收药操作,结束订单";
|
|
|
String remark = "如果您希望延长自动确认收药时间,请点击本消息后进行延长收药操作。";
|
|
|
sendJson.put("keyword1", name);
|
|
|
sendJson.put("keyword2", dateFormat.format(new Date()));
|
|
|
sendJson.put("keyword3", "续方订单状态");
|
|
|
sendJson.put("first", first);
|
|
|
sendJson.put("remark", remark);
|
|
|
sendJson.put("url", url+ "&openid=" + openId +"&toUser=" + patient + "&toName=" +name);//带参数的模板跳转链接
|
|
|
sendJson.put("toUser", patient);//带参数的模板跳转链接
|
|
|
pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 11, openId, name, sendJson);
|
|
|
//发送代理人
|
|
|
if (StringUtils.isEmpty(openId)){
|
|
|
jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openId);
|
|
|
if (jsonArray != null && jsonArray.length() > 0) {
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
JSONObject j = jsonArray.getJSONObject(i);
|
|
|
Patient member = (Patient) j.get("member");
|
|
|
JSONObject newJson = new JSONObject();
|
|
|
newJson.put("toUser", member.getCode());//带参数的模板跳转链接
|
|
|
newJson.put("url", url+ "&openid=" + member.getOpenid() +"&toUser=" + member.getCode() + "&toName=" +name);
|
|
|
//name患者姓名
|
|
|
newJson.put("first", weiXinOpenIdUtils.getTitleMes(people, (int) j.get("relation"), name) + first);
|
|
|
pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 11, member.getOpenid(), name, newJson);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
logger.info("sendJson: " + sendJson);
|
|
|
}else if (type == 2) {
|
|
|
String first = name + "您好,您的续方订单已自动确认收药";
|
|
|
String remark = "如果您未收到续方药品,请及时与社区药房工作人员联系。";
|
|
|
sendJson.put("keyword1", name);
|
|
|
sendJson.put("keyword2", dateFormat.format(new Date()));
|
|
|
sendJson.put("keyword3", "续方订单状态");
|
|
|
sendJson.put("first", first);
|
|
|
sendJson.put("remark", remark);
|
|
|
sendJson.put("toUser", patient);//带参数的模板跳转链接
|
|
|
pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 11, openId, name, sendJson);
|
|
|
//发送代理人
|
|
|
if (StringUtils.isEmpty(openId)){
|
|
|
jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openId);
|
|
|
if (jsonArray != null && jsonArray.length() > 0) {
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
JSONObject j = jsonArray.getJSONObject(i);
|
|
|
Patient member = (Patient) j.get("member");
|
|
|
JSONObject newJson = new JSONObject();
|
|
|
newJson.put("toUser", member.getCode());//带参数的模板跳转链接
|
|
|
//name患者姓名
|
|
|
newJson.put("first", weiXinOpenIdUtils.getTitleMes(people, (int) j.get("relation"), name) + first);
|
|
|
pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 11, member.getOpenid(), name, newJson);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
logger.info("sendJson: " + sendJson);
|
|
|
}
|
|
|
}
|
|
|
}
|