chenweida 8 лет назад
Родитель
Сommit
3892fe2e5d

+ 6 - 6
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/config/war/ServletInitializer.java

@ -7,9 +7,9 @@ import org.springframework.boot.context.web.SpringBootServletInitializer;
/**
 * Created by Administrator on 2016.10.14.
 */
public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}
//public class ServletInitializer extends SpringBootServletInitializer {
//    @Override
//    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
//        return application.sources(Application.class);
//    }
//}

+ 16 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/controller/JobController.java

@ -435,4 +435,20 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 启动通知任务
     *
     * @return
     */
    @ApiOperation(value = "启动通知任务")
    @RequestMapping(value = "startNoticeJob", method = RequestMethod.GET)
    public String startNoticeJob() {
        try {
            jobService.startNoticeJob();
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
}

+ 23 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/dao/DoctorWorkTimeDao.java

@ -0,0 +1,23 @@
package com.yihu.wlyy.statistics.dao;
import com.yihu.wlyy.statistics.model.doctor.WlyyDoctorWorkTime;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by lyr on 2016/08/19.
 */
public interface DoctorWorkTimeDao extends PagingAndSortingRepository<WlyyDoctorWorkTime, Long>, JpaSpecificationExecutor<WlyyDoctorWorkTime> {
    /**
     * 查询医生工作时间
     *
     * @param doctor
     * @return
     */
    @Query("select a from WlyyDoctorWorkTime a where a.doctor = ?1")
    WlyyDoctorWorkTime findDoctorWorkTime(String doctor);
}

+ 40 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/dao/DoctorWorkWeekDao.java

@ -0,0 +1,40 @@
package com.yihu.wlyy.statistics.dao;
import com.yihu.wlyy.statistics.model.doctor.WlyyDoctorWorkWeek;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by lyr on 2016/08/19.
 */
public interface DoctorWorkWeekDao extends PagingAndSortingRepository<WlyyDoctorWorkWeek, Long>, JpaSpecificationExecutor<WlyyDoctorWorkWeek> {
    /**
     * 查询医生排班列表
     *
     * @param doctor
     * @return
     */
    @Query("select a from WlyyDoctorWorkWeek a where a.doctor = ?1")
    List<WlyyDoctorWorkWeek> findDoctorWorkWeeks(String doctor);
    /**
     * 查询医生某天排班信息
     *
     * @param doctor
     * @param week
     * @return
     */
    @Query("select a from WlyyDoctorWorkWeek a where a.doctor = ?1 and a.week = ?2")
    WlyyDoctorWorkWeek findDoctorWorkWeek(String doctor, String week);
    /**
     * 删除医生的排班信息
     *
     * @param doctor
     */
    void deleteByDoctor(String doctor);
}

+ 17 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/dao/NoticeDao.java

@ -0,0 +1,17 @@
package com.yihu.wlyy.statistics.dao;
import com.yihu.wlyy.statistics.model.message.Notice;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Administrator on 2016/11/7.
 */
public interface NoticeDao extends PagingAndSortingRepository<Notice, Long>, JpaSpecificationExecutor<Notice> {
    @Query("select p from Notice p where p.toType=1 and p.status=1")
    List<Notice> findAllDoctorNoRead();
}

+ 149 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/message/NoticeJob.java

@ -0,0 +1,149 @@
package com.yihu.wlyy.statistics.job.message;
import com.yihu.wlyy.statistics.dao.NoticeDao;
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.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;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
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;
import java.util.Map;
/**
 * Created by Administrator on 2016/11/7.
 */
@Component
@Scope("prototype")
public class NoticeJob implements Job {
    public static String jobKey = "Notice_JOB";
    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;
    @Autowired
    private DoctorWorkTimeService doctorWorkTimeService;
    @Autowired
    private QuartzHelper quartzHelper;
    @Autowired
    private QuartzJobLogDao dbStorage;
    @Transactional
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //新建任务日志对象
        QuartzJobLog quartzJobLog = new QuartzJobLog();
        quartzJobLog.setJobStartTime(new Date());
        quartzJobLog.setJobId(jobKey);
        quartzJobLog.setJobName(jobKey);
        try {
            Date nextStartTime = null;
            //得到所有未发送的医生的通知
            List<Notice> noticeList = noticeDao.findAllDoctorNoRead();
            Map<String, Map<String, Integer>> maps = new HashMap<>();
            //发送通知
            for (Notice notice : noticeList) {
                //判断医生是不是在工作时间内
                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;
                    }
                }
            }
            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);
                }
            }
            // 推送消息给医生
            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();
            }
            e.printStackTrace();
        }
    }
}

+ 116 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/model/doctor/WlyyDoctorWorkTime.java

@ -0,0 +1,116 @@
package com.yihu.wlyy.statistics.model.doctor;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.statistics.model.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by lyr on 2016/08/19.
 */
@Entity
@Table(name = "wlyy_doctor_work_time")
public class WlyyDoctorWorkTime extends IdEntity {
    // 医生标识
    private String doctor;
    // 医生姓名
    private String doctorName;
    // 接收咨询 0不接受 1接受
    private String receiveConsult;
    // 名医咨询次数
    private Integer famousConsultTimes;
    // 上午开始时间
    private String morningBegin;
    // 上午结束时间
    private String morningEnd;
    // 下午开始时间
    private String afternoonBegin;
    // 下午结束时间
    private String afternoonEnd;
    // 晚上开始时间
    private String nightBegin;
    // 晚上结束时间
    private String nightEnd;
    // 更新时间
    private Date czrq;
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    public String getDoctorName() {
        return doctorName;
    }
    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }
    public String getReceiveConsult() {
        return receiveConsult;
    }
    public void setReceiveConsult(String receiveConsult) {
        this.receiveConsult = receiveConsult;
    }
    public Integer getFamousConsultTimes() {
        return famousConsultTimes;
    }
    public void setFamousConsultTimes(Integer famousConsultTimes) {
        this.famousConsultTimes = famousConsultTimes;
    }
    public String getMorningBegin() {
        return morningBegin;
    }
    public void setMorningBegin(String morningBegin) {
        this.morningBegin = morningBegin;
    }
    public String getMorningEnd() {
        return morningEnd;
    }
    public void setMorningEnd(String morningEnd) {
        this.morningEnd = morningEnd;
    }
    public String getAfternoonBegin() {
        return afternoonBegin;
    }
    public void setAfternoonBegin(String afternoonBegin) {
        this.afternoonBegin = afternoonBegin;
    }
    public String getAfternoonEnd() {
        return afternoonEnd;
    }
    public void setAfternoonEnd(String afternoonEnd) {
        this.afternoonEnd = afternoonEnd;
    }
    public String getNightBegin() {
        return nightBegin;
    }
    public void setNightBegin(String nightBegin) {
        this.nightBegin = nightBegin;
    }
    public String getNightEnd() {
        return nightEnd;
    }
    public void setNightEnd(String nightEnd) {
        this.nightEnd = nightEnd;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 70 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/model/doctor/WlyyDoctorWorkWeek.java

@ -0,0 +1,70 @@
package com.yihu.wlyy.statistics.model.doctor;
import com.yihu.wlyy.statistics.model.IdEntity;
import javax.persistence.Entity;
import java.util.Date;
/**
 * Created by lyr on 2016/08/19.
 */
@Entity
public class WlyyDoctorWorkWeek extends IdEntity {
    private String doctor;
    private String doctorName;
    private String week;
    private String morning;
    private String afternoon;
    private String night;
    private Date czrq;
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    public String getDoctorName() {
        return doctorName;
    }
    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }
    public String getWeek() {
        return week;
    }
    public void setWeek(String week) {
        this.week = week;
    }
    public String getMorning() {
        return morning;
    }
    public void setMorning(String morning) {
        this.morning = morning;
    }
    public String getAfternoon() {
        return afternoon;
    }
    public void setAfternoon(String afternoon) {
        this.afternoon = afternoon;
    }
    public String getNight() {
        return night;
    }
    public void setNight(String night) {
        this.night = night;
    }
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 90 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/model/message/Notice.java

@ -0,0 +1,90 @@
package com.yihu.wlyy.statistics.model.message;
import com.yihu.wlyy.statistics.model.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Administrator on 2016/11/7.
 * 系通通知
 */
@Entity
@Table(name = "wlyy_notice")
public class Notice extends IdEntity {
    private String toUid;//接受人code
    private String content;//通知内容
    private String title;//消息标题
    private String data;//消息数据
    private String type;//通知类型 1咨询 2签约 3健康指导
    private Date createTime;//创建时间
    private String status;//是否发送 1 否 0是
    private String toType;//接受人类型 1:医生 2患者
    public String getToUid() {
        return toUid;
    }
    public void setToUid(String toUid) {
        this.toUid = toUid;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    public String getToType() {
        return toType;
    }
    public void setToType(String toType) {
        this.toType = toType;
    }
}

+ 306 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/service/DoctorWorkTimeService.java

@ -0,0 +1,306 @@
package com.yihu.wlyy.statistics.service;
import com.yihu.wlyy.statistics.dao.DoctorDao;
import com.yihu.wlyy.statistics.dao.DoctorWorkTimeDao;
import com.yihu.wlyy.statistics.dao.DoctorWorkWeekDao;
import com.yihu.wlyy.statistics.model.doctor.Doctor;
import com.yihu.wlyy.statistics.model.doctor.WlyyDoctorWorkTime;
import com.yihu.wlyy.statistics.model.doctor.WlyyDoctorWorkWeek;
import com.yihu.wlyy.statistics.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * 医生工作排班
 * <p>
 * Created by lyr on 2016/08/19.
 */
@Service
@Transactional
public class DoctorWorkTimeService {
    static Object obj = new Object();
    @Autowired
    private DoctorWorkTimeDao doctorWorkTimeDao;
    @Autowired
    private DoctorWorkWeekDao doctorWorkWeekDao;
    @Autowired
    private DoctorDao doctorDao;
    /**
     * 查询医生某天工作时间
     *
     * @param doctor 医生标识
     * @param week   某天
     * @return
     */
    public JSONObject findDoctorWeekWorkTime(String doctor, String week) throws Exception {
        JSONObject result = new JSONObject();
        WlyyDoctorWorkTime workTime = doctorWorkTimeDao.findDoctorWorkTime(doctor);
        WlyyDoctorWorkWeek workWeek = doctorWorkWeekDao.findDoctorWorkWeek(doctor, week);
        result.put("workTime", workTime != null ? new JSONObject(workTime) : "");
        result.put("workWeek", workWeek != null ? new JSONObject(workWeek) : "");
        return result;
    }
    /**
     * 查询医生某天工作时间
     *
     * @param doctor 医生标识
     * @param week   某天
     * @return
     */
    public Map<String, Object> findDoctorWeekWork(String doctor, String week) throws Exception {
        Map<String, Object> map = new HashMap<>();
        Doctor doc = doctorDao.findByCode(doctor);
        if (doc == null) {
            throw new Exception("doctor-worktime-error:doctor not exist");
        }
        WlyyDoctorWorkTime workTime = doctorWorkTimeDao.findDoctorWorkTime(doctor);
        WlyyDoctorWorkWeek workWeek = doctorWorkWeekDao.findDoctorWorkWeek(doctor, week);
        map.put("workTime", workTime);
        map.put("workWeek", workWeek);
        return map;
    }
    /**
     * 医生是否在工作
     *
     * @param doctor 医生
     * @return
     */
    public JSONObject isDoctorWorking(String doctor, Integer week) throws Exception {
        JSONObject json = new JSONObject();
        Calendar calendar = Calendar.getInstance();
        if (week < 0) {
            week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
            if (week == 0) {
                week = 7;
            }
        }
        // 医生工作时间设置
        Map<String, Object> result = findDoctorWeekWork(doctor, String.valueOf(week));
        if (result.get("workTime") == null) {
            // 医生未设置时,默认7*24小时工作
            json.put("status", "1");
            json.put("msg", "医生当前接受咨询");
        } else {
            WlyyDoctorWorkTime doctorWorkTime = (WlyyDoctorWorkTime) result.get("workTime");
            if (doctorWorkTime.getReceiveConsult().equals("0")) {
                // 医生设置不接受咨询
                json.put("status", "0");
                json.put("msg", "医生不接受咨询");
            } else {
                if (StringUtils.isEmpty(doctorWorkTime.getMorningBegin()) && StringUtils.isEmpty(doctorWorkTime.getMorningEnd())
                        && StringUtils.isEmpty(doctorWorkTime.getAfternoonBegin()) && StringUtils.isEmpty(doctorWorkTime.getAfternoonEnd())
                        && StringUtils.isEmpty(doctorWorkTime.getNightBegin()) && StringUtils.isEmpty(doctorWorkTime.getNightEnd())) {
                    // 医生未设置工作时间,默认7*24小时工作
                    json.put("status", "1");
                    json.put("msg", "医生当前接受咨询");
                } else {
                    if (result.get("workWeek") != null) {
                        // 当前工作日已设置工作时间
                        int flag = 0;
                        WlyyDoctorWorkTime workTime = (WlyyDoctorWorkTime) result.get("workTime");
                        WlyyDoctorWorkWeek workWeek = (WlyyDoctorWorkWeek) result.get("workWeek");
                        int hour = calendar.get(Calendar.HOUR_OF_DAY);
                        int minute = calendar.get(Calendar.MINUTE);
                        String current = (hour < 10 ? ("0" + hour) : hour) + ":" + (hour < 10 ? ("0" + minute) : minute);
                        // 早上
                        if (workWeek.getMorning().equals("1")) {
                            String currentStart = workTime.getMorningBegin();
                            String currentEnd = workTime.getMorningEnd();
                            if (currentStart.length() == 4) {
                                currentStart = "0" + currentStart;
                            }
                            if (currentEnd.length() == 4) {
                                currentEnd = "0" + currentEnd;
                            }
                            if (current.compareTo(currentStart) >= 0 &&
                                    current.compareTo(currentEnd) < 0) {
                                flag = 1;
                            }
                        }
                        // 下午
                        if (workWeek.getAfternoon().equals("1")) {
                            String currentStart = workTime.getAfternoonBegin();
                            String currentEnd = workTime.getAfternoonEnd();
                            if (currentStart.length() == 4) {
                                currentStart = "0" + currentStart;
                            }
                            if (currentEnd.length() == 4) {
                                currentEnd = "0" + currentEnd;
                            }
                            if (current.compareTo(currentStart) >= 0 &&
                                    current.compareTo(currentEnd) < 0) {
                                flag = 1;
                            }
                        }
                        // 晚上
                        if (workWeek.getNight().equals("1")) {
                            String currentStart = workTime.getNightBegin();
                            String currentEnd = workTime.getNightEnd();
                            if (currentStart.length() == 4) {
                                currentStart = "0" + currentStart;
                            }
                            if (currentEnd.length() == 4) {
                                currentEnd = "0" + currentEnd;
                            }
                            if (current.compareTo(currentStart) >= 0 &&
                                    current.compareTo(currentEnd) < 0) {
                                flag = 1;
                            }
                        }
                        if (flag == 1) {
                            json.put("status", "1");
                            json.put("msg", "医生当前接受咨询");
                        } else {
                            json.put("status", "2");
                            json.put("msg", "医生当前不在工作时间");
                        }
                    } else {
                        json.put("status", "2");
                        json.put("msg", "医生当前不在工作时间");
                    }
                }
            }
        }
        return json;
    }
    public Date getDoctorWeek(String doctor, Integer week) throws Exception {
        Date json = new Date();
        Calendar calendar = Calendar.getInstance();
        // 医生工作时间设置
        Map<String, Object> result = findDoctorWeekWork(doctor, String.valueOf(week));
        if (result.get("workTime") == null) {
            // 医生未设置时,默认7*24小时工作
            return json;
        } else {
            WlyyDoctorWorkTime doctorWorkTime = (WlyyDoctorWorkTime) result.get("workTime");
            if (doctorWorkTime.getReceiveConsult().equals("0")) {
                return null;
            } else {
                if (StringUtils.isEmpty(doctorWorkTime.getMorningBegin()) && StringUtils.isEmpty(doctorWorkTime.getMorningEnd())
                        && StringUtils.isEmpty(doctorWorkTime.getAfternoonBegin()) && StringUtils.isEmpty(doctorWorkTime.getAfternoonEnd())
                        && StringUtils.isEmpty(doctorWorkTime.getNightBegin()) && StringUtils.isEmpty(doctorWorkTime.getNightEnd())) {
                    // 医生未设置工作时间,默认7*24小时工作
                    return json;
                } else {
                    if (result.get("workWeek") != null) {
                        // 当前工作日已设置工作时间
                        int flag = 0;
                        WlyyDoctorWorkTime workTime = (WlyyDoctorWorkTime) result.get("workTime");
                        WlyyDoctorWorkWeek workWeek = (WlyyDoctorWorkWeek) result.get("workWeek");
                        int hour = calendar.get(Calendar.HOUR_OF_DAY);
                        int minute = calendar.get(Calendar.MINUTE);
                        String current = (hour < 10 ? ("0" + hour) : hour) + ":" + (hour < 10 ? ("0" + minute) : minute);
                        // 早上
                        if (workWeek.getMorning().equals("1")) {
                            String currentStart = workTime.getMorningBegin();
                            String currentEnd = workTime.getMorningEnd();
                            if (currentStart.length() == 4) {
                                currentStart = "0" + currentStart;
                            }
                            if (currentEnd.length() == 4) {
                                currentEnd = "0" + currentEnd;
                            }
                            if (current.compareTo(currentStart) >= 0 &&
                                    current.compareTo(currentEnd) < 0) {
                               String preDate= DateUtil.dateToStr(json,"yyyy-MM-dd");
                               preDate=preDate+" "+currentStart;
                                return DateUtil.strToDate(preDate,"yyyy-MM-dd HH:mm");
                            }
                        }
                        // 下午
                        if (workWeek.getAfternoon().equals("1")) {
                            String currentStart = workTime.getAfternoonBegin();
                            String currentEnd = workTime.getAfternoonEnd();
                            if (currentStart.length() == 4) {
                                currentStart = "0" + currentStart;
                            }
                            if (currentEnd.length() == 4) {
                                currentEnd = "0" + currentEnd;
                            }
                            if (current.compareTo(currentStart) >= 0 &&
                                    current.compareTo(currentEnd) < 0) {
                                String preDate= DateUtil.dateToStr(json,"yyyy-MM-dd");
                                preDate=preDate+" "+currentStart;
                                return DateUtil.strToDate(preDate,"yyyy-MM-dd HH:mm");
                            }
                        }
                        // 晚上
                        if (workWeek.getNight().equals("1")) {
                            String currentStart = workTime.getNightBegin();
                            String currentEnd = workTime.getNightEnd();
                            if (currentStart.length() == 4) {
                                currentStart = "0" + currentStart;
                            }
                            if (currentEnd.length() == 4) {
                                currentEnd = "0" + currentEnd;
                            }
                            if (current.compareTo(currentStart) >= 0 &&
                                    current.compareTo(currentEnd) < 0) {
                                String preDate= DateUtil.dateToStr(json,"yyyy-MM-dd");
                                preDate=preDate+" "+currentStart;
                                return DateUtil.strToDate(preDate,"yyyy-MM-dd HH:mm");
                            }
                        }
                    } else {
                        return null;
                    }
                }
            }
        }
        return null;
    }
    /**
     * 得到医生的下次工作时间
     *
     * @param doctor
     * @return
     * @throws Exception
     */
    public Date getDoctorNextWork(String doctor) throws Exception {
        Calendar calendar = Calendar.getInstance();
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (week == 0) {
            week = 7;
        }
        //得到今天的是否有工作
        Date date=getDoctorWeek(doctor,week);
        if(date==null){
            //如果工作时间遍历得到最新的一天的时间
            for(int i=1;i<8;i++){
                int weekTemp=(i+week)%7;
                if(weekTemp==0){
                    weekTemp=7;
                }
                date=getDoctorWeek(doctor,weekTemp);
            }
        }
        return date;
    }
}

+ 17 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/service/JobService.java

@ -11,6 +11,7 @@ import com.yihu.wlyy.statistics.job.cache.CacheCleanJob;
import com.yihu.wlyy.statistics.job.check.CheckSignJob;
import com.yihu.wlyy.statistics.job.check.ReportAllLogJob;
import com.yihu.wlyy.statistics.job.message.HealthMessageJob;
import com.yihu.wlyy.statistics.job.message.NoticeJob;
import com.yihu.wlyy.statistics.model.doctor.DoctorPatientGroupInfo;
import com.yihu.wlyy.statistics.model.job.QuartzJobConfig;
import com.yihu.wlyy.statistics.model.job.WlyyQuota;
@ -455,4 +456,20 @@ public class JobService {
            throw new Exception("已经停止");
        }
    }
    public void startNoticeJob() throws Exception {
        if(!quartzHelper.isExistJob(NoticeJob.jobKey)){
            quartzHelper.startNow(NoticeJob.class,NoticeJob.jobKey,new HashMap<>());
        }else{
            throw new Exception("已经启动");
        }
    }
    public void stopNoticeJob()throws Exception  {
        if(quartzHelper.isExistJob(NoticeJob.jobKey)){
            quartzHelper.removeJob(NoticeJob.jobKey);
        }else{
            throw new Exception("已经停止");
        }
    }
}