Browse Source

随访计划消息发送任务

hzp 8 years ago
parent
commit
9e584f6d66

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

@ -467,4 +467,30 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /******************************** 随访计划消息 ****************************************************/
    @ApiOperation(value = "启动随访计划消息任务")
    @RequestMapping(value = "startFollowupPlantJob", method = RequestMethod.GET)
    public String startFollowupPlantJob() {
        try {
            jobService.startFollowupPlantJob();
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    @ApiOperation(value = "停止随访计划消息任务")
    @RequestMapping(value = "stopFollowupPlantJob", method = RequestMethod.GET)
    public String stopFollowupPlantJob() {
        try {
            jobService.stopFollowupPlantJob();
            return success("停止成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
}

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

@ -0,0 +1,96 @@
package com.yihu.wlyy.statistics.job.message;
import com.yihu.wlyy.statistics.dao.MessageDao;
import com.yihu.wlyy.statistics.model.signfamily.Message;
import com.yihu.wlyy.statistics.task.PushMsgTask;
import com.yihu.wlyy.statistics.util.DateUtil;
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.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import javax.transaction.Transactional;
import java.util.*;
/**
 * Created by hzp on 2017.1.4.
 */
@Component
@Scope("prototype")
public class FollowupPlanJob implements Job {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    private MessageDao messageDao;
    public static String cron="0 5 0 * * ?";
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        System.out.print("follow plan message sending...");
        String date = DateUtil.dateToStrShort(new Date());
        //发送随访计划消息
        sendMessage(date);
        System.out.print("follow plan message send over.");
    }
    /**
     * 每日发送随访计划提醒消息
     */
    @Transactional
    public void sendMessage(String date)
    {
        try{
            String start = date +" 00:00:00";
            String end = date +" 23:59:59";
            String sql = "select doctor_code,count(1) count from wlyy_followup where status not in ('0','1') and followup_plan_date>='"+start+"' and followup_plan_date<='"+end+"' group by doctor_code";
            //获取所有未执行随访计划
            List<Map<String,Object>> followupToday = jdbcTemplate.queryForList(sql);
            if(followupToday!=null)
            {
                List<Message> list = new ArrayList<>();
                for(Map<String,Object> map:followupToday)
                {
                    String doctor = String.valueOf(map.get("doctor_code"));
                    String count = String.valueOf(map.get("count"));
                    // 添加签约消息
                    String title = "随访计划提醒";
                    String content = "您今日有" +count+"个随访计划待处理";
                    Message message = new Message();
                    message.setCode(UUID.randomUUID().toString());
                    message.setCzrq(new Date());
                    message.setContent(content);
                    message.setRead(1);//设置未读
                    message.setReceiver(doctor);//设置接受医生的code
                    message.setSender("system");//设置发送的用户
                    message.setTitle(title);
                    message.setType(4);//随访计划提醒
                    message.setReadonly(1);//是否只读消息
                    list.add(message);
                    // 推送消息给医生
                    PushMsgTask.getInstance().put(doctor,"4",title,content,"");
                }
                messageDao.save(list);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

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

@ -10,6 +10,7 @@ import com.yihu.wlyy.statistics.job.business.QuartzHelper;
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.FollowupPlanJob;
import com.yihu.wlyy.statistics.job.message.HealthMessageJob;
import com.yihu.wlyy.statistics.job.message.NoticeJob;
import com.yihu.wlyy.statistics.model.doctor.DoctorPatientGroupInfo;
@ -475,4 +476,22 @@ public class JobService {
            throw new Exception("已经停止");
        }
    }
    /******************************* 随访计划任务 *******************************************************/
    private String followupJob = "FOLLOWUP_PLAN_JOB";
    public void startFollowupPlantJob() throws Exception {
        if (!quartzHelper.isExistJob(followupJob)) {
            quartzHelper.addJob(FollowupPlanJob.class, FollowupPlanJob.cron, followupJob, new HashMap<>());
        } else {
            throw new Exception("已经启动");
        }
    }
    public void stopFollowupPlantJob() throws Exception {
        if (quartzHelper.isExistJob(followupJob)) {
            quartzHelper.removeJob(followupJob);
        } else {
            throw new Exception("已经停止");
        }
    }
}