|
@ -0,0 +1,169 @@
|
|
|
package com.yihu.wlyy.service.app.physicalExamination;
|
|
|
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.service.BaseService;
|
|
|
import com.yihu.wlyy.service.common.SMSService;
|
|
|
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.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
|
|
|
/**
|
|
|
* Created by Reece on 2017/10/19/019.
|
|
|
* <p>
|
|
|
* 65岁以上居民体检提醒(微信模板+短信通知)
|
|
|
*/
|
|
|
@Service
|
|
|
public class PhysicalExaminationRemindService extends BaseService {
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(PhysicalExaminationRemindService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SMSService smsService;
|
|
|
@Autowired
|
|
|
private PushMsgTask pushMsgTask;
|
|
|
@Autowired
|
|
|
private PatientDao patientDao;
|
|
|
@Autowired
|
|
|
private WeiXinAccessTokenUtils accessTokenUtils;
|
|
|
@Autowired
|
|
|
private WeiXinOpenIdUtils openIdUtils;
|
|
|
|
|
|
/**
|
|
|
* 发送单条提醒
|
|
|
*
|
|
|
* @param userCode 居民code
|
|
|
* @param doctName 医生姓名
|
|
|
*/
|
|
|
public void sendSingleNotice(String userCode, String doctName) throws Exception {
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
|
|
String accessToken = accessTokenUtils.getAccessToken();
|
|
|
Patient patient = patientDao.findByCode(userCode);
|
|
|
String mobile = patient.getMobile();
|
|
|
Boolean flag = true;
|
|
|
// 推送消息给微信端
|
|
|
JSONObject json = new org.json.JSONObject();
|
|
|
json.put("first", "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
|
|
|
json.put("keyword1", "健康体检");
|
|
|
json.put("keyword2", format.format(new Date()));
|
|
|
json.put("url", "");
|
|
|
json.put("remark", "为了您和您的家庭医生了解您近期的健康状况,请及时到您签约的社区体检哟~");
|
|
|
if (StringUtils.isNotBlank(patient.getOpenid())) {
|
|
|
pushMsgTask.putWxMsg(accessToken, 11, patient.getOpenid(), patient.getName(), json);
|
|
|
flag = false;
|
|
|
}
|
|
|
//发送代理人
|
|
|
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");
|
|
|
json.remove("toUser");
|
|
|
json.put("toUser", member.getCode());
|
|
|
json.remove("first");
|
|
|
try {
|
|
|
json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(member.getOpenid())) {
|
|
|
pushMsgTask.putWxMsg(accessToken, 11, member.getOpenid(), patient.getName(), json);
|
|
|
flag = false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 微信发送失败发送短信
|
|
|
if (flag&&StringUtils.isNotEmpty(mobile)){
|
|
|
smsService.sendMsg(mobile,"您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送批量提醒
|
|
|
*
|
|
|
* @param teamId 团队ID
|
|
|
* @param doctName 医生姓名
|
|
|
* @return
|
|
|
*/
|
|
|
public void sendBatchNotice(String teamId, String doctName) throws Exception {
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
|
|
String accessToken = accessTokenUtils.getAccessToken();
|
|
|
// 推送消息给微信端
|
|
|
JSONObject json = new org.json.JSONObject();
|
|
|
json.put("first", "您的家庭医生" + doctName + "提醒,您可以到签约社区进行免费的健康体检啦~");
|
|
|
json.put("keyword1", "健康体检");
|
|
|
json.put("keyword2", format.format(new Date()));
|
|
|
json.put("url", "");
|
|
|
json.put("remark", "为了您和您的家庭医生了解您近期的健康状况,请及时到您签约的社区体检哟~");
|
|
|
|
|
|
String sql = "SELECT DISTINCT\n" +
|
|
|
"\tt1.*\n" +
|
|
|
"FROM\n" +
|
|
|
"\twlyy_sign_family t1\n" +
|
|
|
"WHERE\n" +
|
|
|
"\tt1. STATUS > 0\n" +
|
|
|
"AND t1.admin_team_code = 485\n" +
|
|
|
"AND (\n" +
|
|
|
"\tYEAR (curdate()) -\n" +
|
|
|
"\tIF (\n" +
|
|
|
"\t\tlength(idcard) = 18,\n" +
|
|
|
"\t\tsubstring(idcard, 7, 4),\n" +
|
|
|
"\n" +
|
|
|
"\tIF (\n" +
|
|
|
"\t\tlength(idcard) = 15,\n" +
|
|
|
"\t\tconcat('19', substring(idcard, 7, 2)),\n" +
|
|
|
"\t\tNULL\n" +
|
|
|
"\t)\n" +
|
|
|
"\t)\n" +
|
|
|
") > 65\n" +
|
|
|
"AND t1.idcard NOT IN (\n" +
|
|
|
"\tSELECT DISTINCT\n" +
|
|
|
"\t\ts.idcard\n" +
|
|
|
"\tFROM\n" +
|
|
|
"\t\twlyy_sign_family s,\n" +
|
|
|
"\t\twlyy_old_people_physical_examination o\n" +
|
|
|
"\tWHERE\n" +
|
|
|
"\t\ts.admin_team_code =485\n" +
|
|
|
"\tAND s.`status` > 0\n" +
|
|
|
"\tAND s.idcard = o.id_card\n" +
|
|
|
"\tAND o.medical_time >'2016-10-19 15:12:11'\n" +
|
|
|
")\n" +
|
|
|
"ORDER BY\n" +
|
|
|
"\tt1.openid DESC,\n" +
|
|
|
"\tCONVERT (t1. NAME USING gbk)";
|
|
|
Patient patient = patientDao.findByCode("");
|
|
|
if (StringUtils.isNotBlank(patient.getOpenid())) {
|
|
|
pushMsgTask.putWxMsg(accessToken, 11, patient.getOpenid(), patient.getName(), json);
|
|
|
}
|
|
|
//发送代理人
|
|
|
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");
|
|
|
json.remove("toUser");
|
|
|
json.put("toUser", member.getCode());
|
|
|
json.remove("first");
|
|
|
try {
|
|
|
json.put("first", openIdUtils.getTitleMes(patient, j.isNull("relation") ? 1 : j.getInt("relation"), patient.getName()));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(member.getOpenid())) {
|
|
|
pushMsgTask.putWxMsg(accessToken, 11, member.getOpenid(), patient.getName(), json);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|