|
@ -1,14 +1,12 @@
|
|
|
package com.yihu.wlyy.statistics.job.message;
|
|
|
|
|
|
import com.yihu.wlyy.statistics.dao.NoticeDao;
|
|
|
import com.yihu.wlyy.statistics.dao.DoctorDao;
|
|
|
import com.yihu.wlyy.statistics.dao.QuartzJobLogDao;
|
|
|
import com.yihu.wlyy.statistics.etl.storage.DBStorage;
|
|
|
import com.yihu.wlyy.statistics.job.business.QuartzHelper;
|
|
|
import com.yihu.wlyy.statistics.model.doctor.Doctor;
|
|
|
import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
|
|
|
import com.yihu.wlyy.statistics.model.message.Notice;
|
|
|
import com.yihu.wlyy.statistics.service.DoctorWorkTimeService;
|
|
|
import com.yihu.wlyy.statistics.task.PushMsgTask;
|
|
|
import com.yihu.wlyy.statistics.util.JsonUtil;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.quartz.Job;
|
|
@ -19,7 +17,6 @@ import org.springframework.context.annotation.Scope;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@ -33,17 +30,17 @@ import java.util.Map;
|
|
|
@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]条未读的健康指导消息"};
|
|
|
@Autowired
|
|
|
private NoticeDao noticeDao;
|
|
|
private static String[] noticeTitle = {"no", "咨询消息", "签约消息", "体征指标"};
|
|
|
private static String[] noticeContent = {"no", "您有[SIZE]条新的咨询消息", "您有[SIZE]条新的签约消息", "您有[SIZE]条新的体征指标"};
|
|
|
|
|
|
@Autowired
|
|
|
private DoctorWorkTimeService doctorWorkTimeService;
|
|
|
@Autowired
|
|
|
private QuartzHelper quartzHelper;
|
|
|
@Autowired
|
|
|
private QuartzJobLogDao dbStorage;
|
|
|
@Autowired
|
|
|
private DoctorDao doctorDao;
|
|
|
|
|
|
@Transactional
|
|
|
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
@ -53,38 +50,25 @@ public class NoticeJob implements Job {
|
|
|
quartzJobLog.setJobId(jobKey);
|
|
|
quartzJobLog.setJobName(jobKey);
|
|
|
try {
|
|
|
Date nextStartTime = null;
|
|
|
List<Doctor> doctors = doctorDao.findAllDoctors();
|
|
|
//得到所有未发送的医生的通知
|
|
|
List<Notice> noticeList = noticeDao.findAllDoctorNoRead();
|
|
|
Map<String, Map<String, Integer>> maps = new HashMap<>();
|
|
|
//发送通知
|
|
|
for (Notice notice : noticeList) {
|
|
|
for (Doctor doctor : doctors) {
|
|
|
//判断医生是不是在工作时间内
|
|
|
if ("1".equals(doctorWorkTimeService.isDoctorWorking(notice.getToUid(), -1).get("status"))) {
|
|
|
//医生在工作时间内
|
|
|
Map<String, Integer> size = maps.get(notice.getToUid());
|
|
|
if (size == null) {
|
|
|
size = new HashMap<>();
|
|
|
size.put(notice.getType(), 1);
|
|
|
} else {
|
|
|
Integer num = size.get(notice.getType());
|
|
|
if (num == null) {
|
|
|
size.put(notice.getType(), 1);
|
|
|
} else {
|
|
|
size.put(notice.getType(), num++);
|
|
|
}
|
|
|
}
|
|
|
maps.put(notice.getToUid(), size);
|
|
|
notice.setStatus("0");
|
|
|
} else {
|
|
|
//得到这个医生的下次工作时间
|
|
|
Date workTime = doctorWorkTimeService.getDoctorNextWork(notice.getToUid());
|
|
|
if(nextStartTime==null){
|
|
|
nextStartTime=workTime;
|
|
|
}
|
|
|
if (workTime.before(nextStartTime)) {
|
|
|
//如果医生的工作时间在下次工作之前,那就把医生的工作时间作为下次的执行时间
|
|
|
nextStartTime = workTime;
|
|
|
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");
|
|
|
//得到医生多少条签约消息
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -104,46 +88,36 @@ public class NoticeJob implements Job {
|
|
|
}
|
|
|
// 推送消息给医生
|
|
|
PushMsgTask.getInstance().put(jsonArray);
|
|
|
//判断是否任务在执行
|
|
|
if (noticeList.size() != 0) {
|
|
|
//判断下次任务执行时间
|
|
|
if (nextStartTime!=null&&nextStartTime.before(new Date())) {
|
|
|
//如果在现在之前 就立马执行
|
|
|
quartzHelper.startNow(NoticeJob.class, NoticeJob.jobKey+new Date().getTime(), new HashMap<>());
|
|
|
} else {
|
|
|
//如果在现在之前 就立马执行
|
|
|
quartzHelper.startAt(nextStartTime, NoticeJob.class, NoticeJob.jobKey+nextStartTime.getTime(), new HashMap<>());
|
|
|
}
|
|
|
} else {
|
|
|
//如果没有数据延迟半小时
|
|
|
long curren = System.currentTimeMillis();
|
|
|
curren += 30 * 60 * 1000;
|
|
|
Date da = new Date(curren);
|
|
|
quartzHelper.startAt(da, NoticeJob.class, NoticeJob.jobKey+curren, new HashMap<>());
|
|
|
}
|
|
|
//保存日志
|
|
|
quartzJobLog.setJobEndTime(new Date());
|
|
|
quartzJobLog.setJobContent("通知成功");
|
|
|
quartzJobLog.setJobType("1");
|
|
|
dbStorage.save(quartzJobLog);
|
|
|
} catch (Exception e) {
|
|
|
try {
|
|
|
//保存日志
|
|
|
quartzJobLog.setJobEndTime(new Date());
|
|
|
quartzJobLog.setJobContent("通知失败");
|
|
|
quartzJobLog.setJobType("0");
|
|
|
dbStorage.save(quartzJobLog);
|
|
|
//如果失败的话延迟10分钟执行
|
|
|
long curren = System.currentTimeMillis();
|
|
|
curren += 10 * 60 * 1000;
|
|
|
Date da = new Date(curren);
|
|
|
quartzHelper.startAt(da, NoticeJob.class, NoticeJob.jobKey+curren, new HashMap<>());
|
|
|
} catch (Exception e1) {
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
//保存日志
|
|
|
quartzJobLog.setJobEndTime(new Date());
|
|
|
quartzJobLog.setJobContent("通知失败");
|
|
|
quartzJobLog.setJobType("0");
|
|
|
dbStorage.save(quartzJobLog);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void addData(Map<String, Integer> map, Integer size, String key) {
|
|
|
if (size > 0) {
|
|
|
map.put(key, size);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 得到医生的未读数目
|
|
|
* @param code 医生code
|
|
|
* @param type 1是咨询 2个签约 3是体征
|
|
|
* @return
|
|
|
*/
|
|
|
private Integer getDoctorMesssageCount(String code, int type) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
}
|