|
@ -7,6 +7,7 @@ import com.yihu.wlyy.statistics.model.doctor.Doctor;
|
|
|
import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
|
|
|
import com.yihu.wlyy.statistics.service.DoctorWorkTimeService;
|
|
|
import com.yihu.wlyy.statistics.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.statistics.util.HttpClientUtil;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.quartz.Job;
|
|
@ -15,6 +16,7 @@ import org.quartz.JobExecutionException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@ -27,14 +29,15 @@ import java.util.Map;
|
|
|
* Created by Administrator on 2016/11/7.
|
|
|
*/
|
|
|
|
|
|
//@Component
|
|
|
//@Scope("prototype")
|
|
|
@Component
|
|
|
@Scope("prototype")
|
|
|
public class NoticeJob implements Job {
|
|
|
public static String jobKey = "Notice_JOB";
|
|
|
public static String jobCron = "0 0 9,15,20 * * ?"; //每天9点,15点,20 点执行一次
|
|
|
private static String[] noticeKey = {"no", "NO_ZX", "NO_QY", "NO_JKZD"};
|
|
|
private static String[] noticeTitle = {"no", "咨询消息", "签约消息", "体征指标"};
|
|
|
private static String[] noticeContent = {"no", "您有[SIZE]条新的咨询消息", "您有[SIZE]条新的签约消息", "您有[SIZE]条新的体征指标"};
|
|
|
private static String noticeKey1 = "D_ST_01";//专科
|
|
|
private static String noticeKey2 = "D_ST_02";//全科
|
|
|
private static String noticeKey3 = "D_ST_03";//健康管理师
|
|
|
private static String noticeTitle = "系统消息";
|
|
|
|
|
|
@Autowired
|
|
|
private DoctorWorkTimeService doctorWorkTimeService;
|
|
@ -44,6 +47,8 @@ public class NoticeJob implements Job {
|
|
|
private DoctorDao doctorDao;
|
|
|
@Value("${systemConfig.msg_push_server}")
|
|
|
private String url;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Transactional
|
|
|
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
@ -55,42 +60,51 @@ public class NoticeJob implements Job {
|
|
|
try {
|
|
|
List<Doctor> doctors = doctorDao.findAllDoctors();
|
|
|
//得到所有未发送的医生的通知
|
|
|
Map<String, Map<String, Integer>> maps = new HashMap<>();
|
|
|
Map<String, JSONObject> maps = new HashMap<>();
|
|
|
//发送通知
|
|
|
for (Doctor doctor : doctors) {
|
|
|
//判断医生是不是在工作时间内
|
|
|
String noticeContent1 = " 您当前有[zxsize]条未处理消息,其中有[qysize]条签约消息。请尽快处理~";
|
|
|
String noticeContent2 = " 您当前有[zxsize]条未处理消息,请尽快处理~";
|
|
|
if ("1".equals(doctorWorkTimeService.isDoctorWorking(doctor.getCode(), -1).get("status"))) {
|
|
|
Map<String,Integer> map=new HashMap<>();
|
|
|
//得到医生多少条咨询消息
|
|
|
Integer size=getDoctorMesssageCount(doctor.getCode(),1);
|
|
|
addData(map, size, "1");
|
|
|
Integer zxsize = getDoctorMesssageCount(doctor.getCode(), 1);
|
|
|
//得到医生多少条签约消息
|
|
|
size=getDoctorMesssageCount(doctor.getCode(),2);
|
|
|
addData(map, size, "2");
|
|
|
//得到医生多少条体征消息
|
|
|
size=getDoctorMesssageCount(doctor.getCode(),3);
|
|
|
addData(map, size, "3");
|
|
|
if(map.size()>0){
|
|
|
maps.put(doctor.getCode(),map);
|
|
|
Integer qysize = getDoctorMesssageCount(doctor.getCode(), 2);
|
|
|
//如果既有签约又有咨询
|
|
|
if (zxsize > 0 && qysize > 0) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
noticeContent1.replace("[zxsize]", zxsize + "");
|
|
|
noticeContent1.replace("[qysize]", qysize + "");
|
|
|
jo.put("content", noticeContent1);
|
|
|
jo.put("level", doctor.getLevel());
|
|
|
maps.put(doctor.getCode(), jo);
|
|
|
}
|
|
|
//只有咨询
|
|
|
if (zxsize > 0 && qysize == 0) {
|
|
|
JSONObject jo = new JSONObject();
|
|
|
noticeContent2.replace("[zxsize]", zxsize + "");
|
|
|
jo.put("content", noticeContent2);
|
|
|
jo.put("level", doctor.getLevel());
|
|
|
maps.put(doctor.getCode(), jo);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
//发送通知
|
|
|
for (Map.Entry<String, Map<String, Integer>> entry : maps.entrySet()) {
|
|
|
for (Map.Entry<String, Integer> entry1 : entry.getValue().entrySet()) {
|
|
|
// 异常通知
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("receiver", entry.getKey());
|
|
|
json.put("type", noticeKey[Integer.valueOf(entry1.getKey())]);
|
|
|
json.put("title", noticeTitle[Integer.valueOf(entry1.getKey())]);
|
|
|
json.put("msg", noticeContent[Integer.valueOf(entry1.getKey())].replace("[SIZE]", entry1.getValue() + ""));
|
|
|
json.put("data", "");
|
|
|
jsonArray.add(json);
|
|
|
}
|
|
|
for (Map.Entry<String, JSONObject> entry : maps.entrySet()) {
|
|
|
// 异常通知
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("receiver", entry.getKey());
|
|
|
json.put("type", getType(entry.getValue().getInt("level")));
|
|
|
json.put("title", noticeTitle);
|
|
|
json.put("msg", entry.getValue().getString("content"));
|
|
|
json.put("data", "");
|
|
|
jsonArray.add(json);
|
|
|
}
|
|
|
// 推送消息给医生
|
|
|
PushMsgTask.url=url;
|
|
|
PushMsgTask.url = url + "/api/v1/chats/sm";
|
|
|
// 推送消息给医生
|
|
|
PushMsgTask.getInstance().put(jsonArray);
|
|
|
//保存日志
|
|
|
quartzJobLog.setJobEndTime(new Date());
|
|
@ -108,20 +122,57 @@ public class NoticeJob implements Job {
|
|
|
|
|
|
}
|
|
|
|
|
|
private void addData(Map<String, Integer> map, Integer size, String key) {
|
|
|
if (size > 0) {
|
|
|
map.put(key, size);
|
|
|
private String getType(Integer level) {
|
|
|
switch (level) {
|
|
|
case 1: {
|
|
|
//专科
|
|
|
return noticeKey1;
|
|
|
}
|
|
|
case 2: {
|
|
|
//全科
|
|
|
return noticeKey2;
|
|
|
}
|
|
|
case 3: {
|
|
|
//健康管理师
|
|
|
return noticeKey3;
|
|
|
}
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 得到医生的未读数目
|
|
|
* @param code 医生code
|
|
|
* @param type 1是咨询 2个签约 3是体征
|
|
|
*
|
|
|
* @param doctorCode 医生code
|
|
|
* @param type 1是咨询 2个签约 3是体征
|
|
|
* @return
|
|
|
*/
|
|
|
private Integer getDoctorMesssageCount(String code, int type) {
|
|
|
private Integer getDoctorMesssageCount(String doctorCode, int type) {
|
|
|
switch (type) {
|
|
|
case 1: {
|
|
|
return getImMsgAmount(doctorCode);
|
|
|
}
|
|
|
case 2: {
|
|
|
String sql = "select count(a.id) from wlyy_message a where a.type =1 and a.readonly=1 and a.receiver=?";
|
|
|
return jdbcTemplate.queryForObject(sql, Integer.class, doctorCode);
|
|
|
}
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
private Integer getImMsgAmount(String doctor) {
|
|
|
String urlall = url + "/api/v1/chats/msg/amount?user_id=" + doctor;
|
|
|
String response = HttpClientUtil.get(urlall, "UTF-8");
|
|
|
/**
|
|
|
* {"msg":"获取消息总数成功!","data":{"imMsgCount":"{\"doctor\":0,\"patient\":0}","healthIndex":{"amount":0},"sign":{"amount":0}},"status":200}
|
|
|
*/
|
|
|
JSONObject jo = JSONObject.fromObject(response);
|
|
|
JSONObject jochildren = jo.getJSONObject("data");
|
|
|
Integer countAll = jochildren.getJSONObject("imMsgCount").getInt("doctor") +
|
|
|
jochildren.getJSONObject("imMsgCount").getInt("patient") +
|
|
|
jochildren.getJSONObject("healthIndex").getInt("amount") +
|
|
|
jochildren.getJSONObject("sign").getInt("amount");
|
|
|
return countAll;
|
|
|
}
|
|
|
}
|