Переглянути джерело

添加咨询超时关闭任务“

Sand 8 роки тому
батько
коміт
c1a8a2a8b7

+ 1 - 6
pom.xml

@ -13,7 +13,7 @@
        <springside.version>4.2.3-GA</springside.version>
        <springside.version>4.2.3-GA</springside.version>
        <spring.version>4.2.6.RELEASE</spring.version>
        <spring.version>4.2.6.RELEASE</spring.version>
        <hibernate.version>4.3.5.Final</hibernate.version>
        <hibernate.version>4.3.5.Final</hibernate.version>
        <spring-data-jpa.version>1.7.2.RELEASE</spring-data-jpa.version>
        <spring-data-jpa.version>1.6.0.RELEASE</spring-data-jpa.version>
        <tomcat-jdbc.version>7.0.53</tomcat-jdbc.version>
        <tomcat-jdbc.version>7.0.53</tomcat-jdbc.version>
        <sitemesh.version>2.4.2</sitemesh.version>
        <sitemesh.version>2.4.2</sitemesh.version>
        <shiro.version>1.2.3</shiro.version>
        <shiro.version>1.2.3</shiro.version>
@ -82,11 +82,6 @@
            <artifactId>spring-context-support</artifactId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
            <version>${spring.version}</version>
        </dependency>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <artifactId>poi</artifactId>

+ 21 - 49
src/main/java/com/yihu/wlyy/entity/consult/ConsultTeam.java

@ -12,60 +12,33 @@ import com.yihu.wlyy.entity.IdEntity;
/**
/**
 * 三师咨询
 * 三师咨询
 * @author George
 * @author George
 *
 */
 */
@Entity
@Entity
@Table(name = "wlyy_consult_team")
@Table(name = "wlyy_consult_team")
public class ConsultTeam extends IdEntity {
public class ConsultTeam extends IdEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7644448339473861513L;
	private static final long serialVersionUID = -7644448339473861513L;
	// 咨询标识
	private String consult;
	// 医生标识
	private String doctor;
	// 三师团队标识
	private String team;
	//1 三师咨询,2家庭医生咨询 6.名医咨询
	private Integer type;
	// 提问者标识
	private String patient;
	// 患者姓名
	private String name;
	// 患者性别
	private Integer sex;
	// 患者生日
	private Date birthday;
	// 患者头像
	private String photo;
	// 发病日期
	private String when;
	// 主要症状
	private String symptoms;
	// 咨询状态(0进行中,1已完成,-1患者取消)
	private Integer status;
	// 咨询图片URL,多图以逗号分隔
	private String images;
	// 咨询语音URL
	private String voice;
	// 用户评价标识
	private String comment;
	// 用户评价内容
	private String commentContent;
	// 用户评价星级
	private Integer commentStar;
	// 医生未读数量
	private Integer doctorRead;
	// 患者未读数量
	private Integer patientRead;
	// 咨询时间
	private Date czrq;
	// 作废标识,1正常,0作废
	private String del;
	private String consult;         // 咨询标识
	private String doctor;          // 医生标识
	private String team;            // 三师团队标识
	private Integer type;           //  1、三师咨询,2、家庭医生咨询,6、名医咨询
	private String patient;         // 提问者标识
	private String name;            // 患者姓名
	private Integer sex;            // 患者性别
	private Date birthday;          // 患者生日
	private String photo;           // 患者头像
	private String when;            // 发病日期
	private String symptoms;        // 主要症状
	private Integer status;         // 咨询状态(0进行中,1已完成,-1患者取消,-2超时未响应自动关闭)
	private String images;          // 咨询图片URL,多图以逗号分隔
	private String voice;           // 咨询语音URL
	private String comment;         // 用户评价标识
	private String commentContent;  // 用户评价内容
	private Integer commentStar;    // 用户评价星级
	private Integer doctorRead;     // 医生未读数量
	private Integer patientRead;    // 患者未读数量
	private Date czrq;              // 咨询时间
	private String del;             // 作废标识,1正常,0作废
	public String getConsult() {
	public String getConsult() {
		return consult;
		return consult;
@ -76,7 +49,6 @@ public class ConsultTeam extends IdEntity {
	}
	}
	public ConsultTeam() {
	public ConsultTeam() {
	}
	}
	public String getDoctor() {
	public String getDoctor() {

+ 35 - 18
src/main/java/com/yihu/wlyy/job/QuartzHelper.java

@ -1,17 +1,14 @@
package com.yihu.wlyy.job;
package com.yihu.wlyy.job;
import java.util.Date;
import java.util.Map;
import javax.annotation.PostConstruct;
import com.yihu.wlyy.repository.*;
import org.quartz.*;
import org.quartz.*;
import org.quartz.impl.triggers.SimpleTriggerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.Map;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
@Component("quartzHelper")
@Component("quartzHelper")
@ -66,25 +63,45 @@ public class QuartzHelper {
    }
    }
    public boolean isExistJob(String jobKey) throws SchedulerException {
    public boolean isExistJob(String jobKey) throws SchedulerException {
        JobKey jk = new JobKey("job-id:" + jobKey,"job-group:" + jobKey);
        if(scheduler.checkExists(jk)){
        JobKey jk = new JobKey("job-id:" + jobKey, "job-group:" + jobKey);
        if (scheduler.checkExists(jk)) {
            return true;
            return true;
        }else{
        } else {
            return false;
            return false;
        }
        }
    }
    }
    public void startNow(Class jobClass,  String id, Map<String, Object> params) throws Exception {
    /**
     * 立即执行任务。
     *
     * @param jobClass
     * @param id
     * @param params
     * @throws Exception
     */
    public void startNow(Class jobClass, String id, Map<String, Object> params) throws Exception {
        startAt(new Date(), jobClass, id, params);
    }
    /**
     * 在指定时间点执行。
     *
     * @param time
     * @param jobClass
     * @param id
     * @param params
     * @throws Exception
     */
    public void startAt(Date time, Class jobClass, String id, Map<String, Object> params) throws Exception {
        JobDetail job = JobBuilder.newJob(jobClass).
        JobDetail job = JobBuilder.newJob(jobClass).
                withIdentity("job-simple-id:" + id, "job-simple-group:" + id)
                withIdentity("job-id:" + id, "job-group:" + id)
                .build();
                .build();
        JobDataMap jobDataMap = job.getJobDataMap();
        JobDataMap jobDataMap = job.getJobDataMap();
        jobDataMap.putAll(params);
        SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder.newTrigger().withIdentity("trigger1-simple-id:" + id, "group1-simple-group:" + id)
                .startAt(new Date()).withSchedule(simpleSchedule()//new Date() 是执行时间
                        .withIntervalInSeconds(10)//如果有重复次数 那么间隔10秒执行一次
                        .withRepeatCount(0) //重复的次数
                )
        if(null != params) jobDataMap.putAll(params);
        SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger-id:" + id, "group-group:" + id)
                .startAt(time)
                .withSchedule(simpleSchedule().withIntervalInSeconds(10).withRepeatCount(0))
                .build();
                .build();
        scheduler.scheduleJob(job, trigger);
        scheduler.scheduleJob(job, trigger);

+ 72 - 0
src/main/java/com/yihu/wlyy/job/consult/ConsultCleaner.java

@ -0,0 +1,72 @@
package com.yihu.wlyy.job.consult;
import com.yihu.wlyy.entity.consult.ConsultTeam;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.repository.consult.ConsultTeamDao;
import com.yihu.wlyy.service.quota.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static com.yihu.wlyy.job.consult.ConsultCleanerJob.ConsultTerminatorJobKey;
/**
 * @author Sand
 * @since 2016/9/26
 */
@Service
public class ConsultCleaner {
    private final ConsultTeamDao consultTeamDao;
    private final JobService jobService;
    private final QuartzHelper quartzHelper;
    @Autowired
    public ConsultCleaner(QuartzHelper quartzHelper, JobService jobService, ConsultTeamDao consultTeamDao) {
        this.quartzHelper = quartzHelper;
        this.jobService = jobService;
        this.consultTeamDao = consultTeamDao;
    }
    @Transactional
    public void doClean() {
        try {
            System.out.println("开始清除未响应咨询......");
            // 先关闭超过24小时未回应的咨询
            consultTeamDao.updateUnresponsedConsultOver24Hours();
            // 计算下一次执行此任务的时间,若无下次计算时间为半个小时后
            Date nextTriggerTime;
            Page<ConsultTeam> consultTeams = consultTeamDao.getUnresponsedConsultIn24Hours(new PageRequest(0, 1));
            if (consultTeams.getContent().size() > 0) {
                ConsultTeam consultTeam = consultTeams.getContent().get(0);
                Calendar calendar =  new GregorianCalendar();
                calendar.setTime(consultTeam.getCzrq());
                calendar.add(Calendar.HOUR, 24);
                nextTriggerTime = calendar.getTime();
            } else {
                Calendar calendar = GregorianCalendar.getInstance();
                calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) + 30);
                nextTriggerTime = calendar.getTime();
            }
            if (quartzHelper.isExistJob(ConsultTerminatorJobKey)) {
                quartzHelper.removeJob(ConsultTerminatorJobKey);
            }
            System.out.println("计算下次任务执行时间,下次执行在" + nextTriggerTime.toString());
            quartzHelper.startAt(nextTriggerTime, ConsultCleanerJob.class, ConsultTerminatorJobKey, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

+ 25 - 0
src/main/java/com/yihu/wlyy/job/consult/ConsultCleanerJob.java

@ -0,0 +1,25 @@
package com.yihu.wlyy.job.consult;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
/**
 * @author Sand
 * @since 2016/9/23
 */
public class ConsultCleanerJob implements Job {
    @Autowired
    ConsultCleaner cleaner;
    public final static String ConsultTerminatorJobKey = "consult-terminator";
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        cleaner.doClean();
    }
}

+ 17 - 47
src/main/java/com/yihu/wlyy/service/quota/JobService.java

@ -1,9 +1,9 @@
package com.yihu.wlyy.service.quota;
package com.yihu.wlyy.service.quota;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo;
import com.yihu.wlyy.entity.job.QuartzJobConfig;
import com.yihu.wlyy.entity.job.QuartzJobConfig;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.statistics.WlyyQuota;
import com.yihu.wlyy.entity.statistics.WlyyQuota;
import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao;
import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao;
import com.yihu.wlyy.repository.job.QuartzJobConfigDao;
import com.yihu.wlyy.repository.job.QuartzJobConfigDao;
@ -21,19 +21,22 @@ import java.text.SimpleDateFormat;
import java.util.*;
import java.util.*;
/**
/**
 * Created by Administrator on 2016/8/16.
 * @author chenweida
 */
 */
@Service
@Service
public class JobService {
public class JobService {
    @Autowired
    @Autowired
    private QuartzHelper quartzHelper;
    private QuartzHelper quartzHelper;
    @Autowired
    @Autowired
    private QuartzJobConfigDao wlyyJobConfigDao;
    private QuartzJobConfigDao wlyyJobConfigDao;
    @Autowired
    @Autowired
    private QuotaDao quotaDao;
    private QuotaDao quotaDao;
    @Autowired
    @Autowired
    private SignFamilyDao signFamilyDao;
    private SignFamilyDao signFamilyDao;
    @Autowired
    @Autowired
    private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao;
    private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao;
@ -120,8 +123,8 @@ public class JobService {
        Map<String, Object> params = new HashMap<String, Object>();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("quota", wlyyQuotaVO);
        params.put("quota", wlyyQuotaVO);
        params.put("jobConfig", wlyyJobConfigVO);
        params.put("jobConfig", wlyyJobConfigVO);
        //往quartz框架添加任务
        //往quartz框架添加任务
        if (!StringUtils.isEmpty(quartzJobConfig.getJobClass())) {
        if (!StringUtils.isEmpty(quartzJobConfig.getJobClass())) {
            quartzHelper.startNow(Class.forName(quartzJobConfig.getJobClass()), quartzJobConfig.getId(), params);
            quartzHelper.startNow(Class.forName(quartzJobConfig.getJobClass()), quartzJobConfig.getId(), params);
        }
        }
@ -196,7 +199,6 @@ public class JobService {
    }
    }
    public void productDataByOneDayWithId(String yesterday, String id) throws Exception {
    public void productDataByOneDayWithId(String yesterday, String id) throws Exception {
        SimpleDateFormat dataSimple = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dataSimple = new SimpleDateFormat("yyyy-MM-dd");
        Date date = dataSimple.parse(yesterday);
        Date date = dataSimple.parse(yesterday);
        if (date == null) {
        if (date == null) {
@ -221,6 +223,7 @@ public class JobService {
        Map<String, Object> params = new HashMap<String, Object>();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("quota", wlyyQuotaVO);
        params.put("quota", wlyyQuotaVO);
        params.put("jobConfig", wlyyJobConfigVO);
        params.put("jobConfig", wlyyJobConfigVO);
        //往quartz框架添加任务
        //往quartz框架添加任务
        params.put("now", now);
        params.put("now", now);
        params.put("yesterday", yesterday);
        params.put("yesterday", yesterday);
@ -228,38 +231,36 @@ public class JobService {
            quartzHelper.startNow(Class.forName(quartzJobConfig.getJobClass()), quartzJobConfig.getId() + UUID.randomUUID(), params);
            quartzHelper.startNow(Class.forName(quartzJobConfig.getJobClass()), quartzJobConfig.getId() + UUID.randomUUID(), params);
            Thread.sleep(15000L);
            Thread.sleep(15000L);
        }
        }
    }
    }
    @Transactional
    @Transactional
    public void startaaaa() {
    public void startaaaa() {
        List<SignFamily> s = signFamilyDao.findByDate("2016-08-05 15:40:00");
        List<SignFamily> s = signFamilyDao.findByDate("2016-08-05 15:40:00");
        for (SignFamily ss : s) {
        for (SignFamily ss : s) {
            List<DoctorPatientGroupInfo> DoctorPatientGroupInfos=doctorPatientGroupInfoDao.findByPatient(ss.getPatient());
            if(DoctorPatientGroupInfos!=null&&DoctorPatientGroupInfos.size()==0){
                DoctorPatientGroupInfo qkDoctorPatientGroupInfo=new DoctorPatientGroupInfo();
            List<DoctorPatientGroupInfo> DoctorPatientGroupInfos = doctorPatientGroupInfoDao.findByPatient(ss.getPatient());
            if (DoctorPatientGroupInfos != null && DoctorPatientGroupInfos.size() == 0) {
                DoctorPatientGroupInfo qkDoctorPatientGroupInfo = new DoctorPatientGroupInfo();
                qkDoctorPatientGroupInfo.setCzrq(new Date());
                qkDoctorPatientGroupInfo.setCzrq(new Date());
                qkDoctorPatientGroupInfo.setQyrq(ss.getApplyDate());
                qkDoctorPatientGroupInfo.setQyrq(ss.getApplyDate());
                qkDoctorPatientGroupInfo.setGroup("2");
                qkDoctorPatientGroupInfo.setGroup("2");
                qkDoctorPatientGroupInfo.setPatient(ss.getPatient());
                qkDoctorPatientGroupInfo.setPatient(ss.getPatient());
                qkDoctorPatientGroupInfo.setPartAmount(0);
                qkDoctorPatientGroupInfo.setPartAmount(0);
                qkDoctorPatientGroupInfo.setStatus(ss.getStatus()>0?1:0);
                if(ss.getStatus()<0){
                qkDoctorPatientGroupInfo.setStatus(ss.getStatus() > 0 ? 1 : 0);
                if (ss.getStatus() < 0) {
                    qkDoctorPatientGroupInfo.setDqrq(ss.getApplyUnsignDate());
                    qkDoctorPatientGroupInfo.setDqrq(ss.getApplyUnsignDate());
                }
                }
                qkDoctorPatientGroupInfo.setSignType("1");
                qkDoctorPatientGroupInfo.setSignType("1");
                qkDoctorPatientGroupInfo.setDoctor(ss.getDoctor());
                qkDoctorPatientGroupInfo.setDoctor(ss.getDoctor());
                doctorPatientGroupInfoDao.save(qkDoctorPatientGroupInfo);
                doctorPatientGroupInfoDao.save(qkDoctorPatientGroupInfo);
                qkDoctorPatientGroupInfo=new DoctorPatientGroupInfo();
                qkDoctorPatientGroupInfo = new DoctorPatientGroupInfo();
                qkDoctorPatientGroupInfo.setCzrq(new Date());
                qkDoctorPatientGroupInfo.setCzrq(new Date());
                qkDoctorPatientGroupInfo.setQyrq(ss.getApplyDate());
                qkDoctorPatientGroupInfo.setQyrq(ss.getApplyDate());
                qkDoctorPatientGroupInfo.setGroup("2");
                qkDoctorPatientGroupInfo.setGroup("2");
                qkDoctorPatientGroupInfo.setPatient(ss.getPatient());
                qkDoctorPatientGroupInfo.setPatient(ss.getPatient());
                qkDoctorPatientGroupInfo.setPartAmount(0);
                qkDoctorPatientGroupInfo.setPartAmount(0);
                qkDoctorPatientGroupInfo.setStatus(ss.getStatus()>0?1:0);
                if(ss.getStatus()<0){
                qkDoctorPatientGroupInfo.setStatus(ss.getStatus() > 0 ? 1 : 0);
                if (ss.getStatus() < 0) {
                    qkDoctorPatientGroupInfo.setDqrq(ss.getApplyUnsignDate());
                    qkDoctorPatientGroupInfo.setDqrq(ss.getApplyUnsignDate());
                }
                }
                qkDoctorPatientGroupInfo.setSignType("1");
                qkDoctorPatientGroupInfo.setSignType("1");
@ -267,38 +268,7 @@ public class JobService {
                doctorPatientGroupInfoDao.save(qkDoctorPatientGroupInfo);
                doctorPatientGroupInfoDao.save(qkDoctorPatientGroupInfo);
            }
            }
        }
        }
        s = signFamilyDao.findByDate("2016-08-16 00:00:00");
        for (SignFamily ss : s) {
            List<DoctorPatientGroupInfo> DoctorPatientGroupInfos=doctorPatientGroupInfoDao.findByPatient(ss.getPatient());
            if(DoctorPatientGroupInfos!=null&&DoctorPatientGroupInfos.size()==0){
                DoctorPatientGroupInfo qkDoctorPatientGroupInfo=new DoctorPatientGroupInfo();
                qkDoctorPatientGroupInfo.setCzrq(new Date());
                qkDoctorPatientGroupInfo.setQyrq(ss.getApplyDate());
                qkDoctorPatientGroupInfo.setGroup("2");
                qkDoctorPatientGroupInfo.setPatient(ss.getPatient());
                qkDoctorPatientGroupInfo.setPartAmount(0);
                qkDoctorPatientGroupInfo.setStatus(ss.getStatus()>0?1:0);
                if(ss.getStatus()<0){
                    qkDoctorPatientGroupInfo.setDqrq(ss.getApplyUnsignDate());
                }
                qkDoctorPatientGroupInfo.setSignType("1");
                qkDoctorPatientGroupInfo.setDoctor(ss.getDoctor());
                doctorPatientGroupInfoDao.save(qkDoctorPatientGroupInfo);
                qkDoctorPatientGroupInfo=new DoctorPatientGroupInfo();
                qkDoctorPatientGroupInfo.setCzrq(new Date());
                qkDoctorPatientGroupInfo.setQyrq(ss.getApplyDate());
                qkDoctorPatientGroupInfo.setGroup("2");
                qkDoctorPatientGroupInfo.setPatient(ss.getPatient());
                qkDoctorPatientGroupInfo.setPartAmount(0);
                qkDoctorPatientGroupInfo.setStatus(ss.getStatus()>0?1:0);
                if(ss.getStatus()<0){
                    qkDoctorPatientGroupInfo.setDqrq(ss.getApplyUnsignDate());
                }
                qkDoctorPatientGroupInfo.setSignType("1");
                qkDoctorPatientGroupInfo.setDoctor(ss.getDoctorHealth());
                doctorPatientGroupInfoDao.save(qkDoctorPatientGroupInfo);
            }
        }
        s = signFamilyDao.findByDate("2016-08-16 00:00:00");
    }
    }
}
}

+ 0 - 140
src/main/java/com/yihu/wlyy/web/common/util/ManagerUtilController.java

@ -1,140 +0,0 @@
package com.yihu.wlyy.web.common.util;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.job.consult.FamousConsultTimesJob;
import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.hash.HashMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
/**
 * Created by lyr on 2016/09/13.
 */
@RestController
@RequestMapping(value = "/manage_util")
@Api(description = "管理工具及后台任务控制")
public class ManagerUtilController extends BaseController {
    @Autowired
    PatientDiseaseService diseaseService;
    @Autowired
    StringRedisTemplate redisTemplate;
    @Autowired
    QuartzHelper quartzHelper;
    @Autowired
    DoctorWorkTimeService workTimeService;
    @Autowired
    StatisticsService statisticsService;
    /*********************************************患者疾病相关******************************************/
    /**
     * 更新到redis
     *
     * @return
     */
    @RequestMapping(value = "/disease/to_redis")
    public String updateToRedid() {
        try {
            diseaseService.updateToRedis();
            return write(200, "更新成功");
        } catch (Exception e) {
            return error(-1, "更新失败");
        }
    }
    /**
     * 更新到疾病表
     *
     * @return
     */
    @RequestMapping(value = "/disease/to_disease")
    public String updateToDisease() {
        try {
            diseaseService.updateToDisease();
            return write(200, "更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "更新失败");
        }
    }
    /**
     * 查询患者redis疾病
     *
     * @param patient
     * @return
     */
    @RequestMapping(value = "/disease/patient")
    public String getDiseaseFromRedis(String patient) {
        try {
            return write(200, "查询成功", "data", redisTemplate.opsForValue().get("disease:" + patient));
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /***********************************************名医咨询相关****************************************/
    /**
     * 开始名医咨询剩余次数统计任务
     *
     * @return
     */
    @RequestMapping(value = "/famous_doctor/start_job")
    public String startConsultTimesJob() {
        try {
            if (!quartzHelper.isExistJob("famous-doctor-times")) {
                quartzHelper.addJob(FamousConsultTimesJob.class, "0 0 0 * * ?", "famous-doctor-times", new HashMap<String, Object>());
                return write(200, "启动成功");
            } else {
                return write(200, "任务已存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "启动失败");
        }
    }
    /**
     * 名医咨询剩余次数手动更新
     *
     * @return
     */
    @RequestMapping(value = "/famous_doctor/times_update")
    public String famousConsultTimeUpdate() {
        try {
            workTimeService.consultTimesRemain(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
            return write(200, "更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "更新失败");
        }
    }
    /*********************************************统计相关*******************************************/
    /**
     * 更新人口数据到redis
     *
     * @return
     */
    @RequestMapping(value = "/people_num_to_redis")
    public String peopleNumToRedis() {
        try {
            statisticsService.peopleNumToRedis();
            return write(200, "更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "更新失败");
        }
    }
}

+ 1 - 33
src/main/java/com/yihu/wlyy/web/doctor/patient/PatientDiseaseController.java

@ -18,7 +18,7 @@ import java.util.List;
/**
/**
 * 患者疾病控制器
 * 患者疾病控制器
 * <p>
 *
 * Created by lyr on 2016/09/09.
 * Created by lyr on 2016/09/09.
 */
 */
@RestController
@RestController
@ -95,36 +95,4 @@ public class PatientDiseaseController extends BaseController {
            return error(-1, "更新失败");
            return error(-1, "更新失败");
        }
        }
    }
    }
    /**
     * 更新到redis
     *
     * @return
     */
    @RequestMapping(value = "/to_redis")
    public String updateToRedid() {
        try {
            patientDiseaseService.updateToRedis();
            return write(200, "更新成功");
        } catch (Exception e) {
            return error(-1, "更新失败");
        }
    }
    /**
     * 更新到疾病表
     *
     * @return
     */
    @RequestMapping(value = "/to_disease")
    public String updateToDisease() {
        try {
            patientDiseaseService.updateToDisease();
            return write(200, "更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "更新失败");
        }
    }
}
}

+ 174 - 36
src/main/java/com/yihu/wlyy/web/quota/JobController.java

@ -1,90 +1,119 @@
package com.yihu.wlyy.web.quota;
package com.yihu.wlyy.web.quota;
import com.yihu.wlyy.job.*;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.job.consult.ConsultCleanerJob;
import com.yihu.wlyy.job.consult.FamousConsultTimesJob;
import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.service.quota.JobService;
import com.yihu.wlyy.service.quota.JobService;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import static com.yihu.wlyy.job.consult.ConsultCleanerJob.ConsultTerminatorJobKey;
/**
/**
 * Created by Administrator on 2016/8/15.
 * 任务启动
 * 任务启动
 *
 * @author chenweida
 */
 */
@Controller
@RestController
@RequestMapping("/job")
@RequestMapping("/job")
@Api(description = "后台-任务控制")
@Api(description = "后台-任务控制", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class JobController extends BaseController {
public class JobController extends BaseController {
    private final JobService jobService;
    private final PatientDiseaseService diseaseService;
    private final StringRedisTemplate redisTemplate;
    private final QuartzHelper quartzHelper;
    private final DoctorWorkTimeService workTimeService;
    private final StatisticsService statisticsService;
    @Autowired
    @Autowired
    private JobService jobService;
    public JobController(StatisticsService statisticsService, JobService jobService, StringRedisTemplate redisTemplate, DoctorWorkTimeService workTimeService, PatientDiseaseService diseaseService, QuartzHelper quartzHelper) {
        this.statisticsService = statisticsService;
        this.jobService = jobService;
        this.redisTemplate = redisTemplate;
        this.workTimeService = workTimeService;
        this.diseaseService = diseaseService;
        this.quartzHelper = quartzHelper;
    }
    /**
    /**
     * 启动任务
     * 启动任务
     *
     *
     * @param id id
     * @param id id
     * @return
     * @return
     */
     */
    @RequestMapping(value = "startNowById")
    @ResponseBody
    @RequestMapping(value = "startNowById", method = RequestMethod.GET)
    public String startNowById(String id) {
    public String startNowById(String id) {
        try {
        try {
            jobService.startNowById(id);
            jobService.startNowById(id);
            return success("启动成功!");
            return success("启动成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 生成过去几天的数据
     * 生成过去几天的数据
     *
     * @param day
     * @param day
     * @return
     * @return
     */
     */
    @RequestMapping(value = "productDataByDay")
    @ResponseBody
    @RequestMapping(value = "productDataByDay", method = RequestMethod.GET)
    public String productDataByDay(Integer day) {
    public String productDataByDay(Integer day) {
        try {
        try {
            jobService.productDataByDay(day);
            jobService.productDataByDay(day);
            return success("启动成功!");
            return success("启动成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 生成过去某一天的全部的数据
     * 生成过去某一天的全部的数据
     *
     * @param day
     * @param day
     * @return
     * @return
     */
     */
    @RequestMapping(value = "productDataByOneDay")
    @ResponseBody
    @RequestMapping(value = "productDataByOneDay", method = RequestMethod.GET)
    public String productDataByOneDay(String day) {
    public String productDataByOneDay(String day) {
        try {
        try {
            jobService.productDataByOneDay(day);
            jobService.productDataByOneDay(day);
            return success("启动成功!");
            return success("启动成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 生成过去某一天的某一个指标的数据
     * 生成过去某一天的某一个指标的数据
     *
     * @param day
     * @param day
     * @return
     * @return
     */
     */
    @RequestMapping(value = "productDataByOneDayWithId")
    @ResponseBody
    public String productDataByOneDayWithId(String day,String id) {
    @RequestMapping(value = "productDataByOneDayWithId", method = RequestMethod.GET)
    public String productDataByOneDayWithId(String day, String id) {
        try {
        try {
            jobService.productDataByOneDayWithId(day,id);
            jobService.productDataByOneDayWithId(day, id);
            return success("启动成功!");
            return success("启动成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
@ -94,8 +123,7 @@ public class JobController extends BaseController {
     * @param id id
     * @param id id
     * @return
     * @return
     */
     */
    @RequestMapping(value = "startById")
    @ResponseBody
    @RequestMapping(value = "startById", method = RequestMethod.GET)
    public String startById(String id) {
    public String startById(String id) {
        try {
        try {
@ -103,24 +131,24 @@ public class JobController extends BaseController {
            return success("启动成功!");
            return success("启动成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    /**
    /**
     * 停止任务
     * 停止任务
     *
     *
     * @param id id
     * @param id id
     * @return
     * @return
     */
     */
    @RequestMapping(value = "stopById")
    @ResponseBody
    @RequestMapping(value = "stopById", method = RequestMethod.GET)
    public String stopById(String id) {
    public String stopById(String id) {
        try {
        try {
            jobService.stopById(id);
            jobService.stopById(id);
            return success("停止成功!");
            return success("停止成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
@ -129,15 +157,14 @@ public class JobController extends BaseController {
     *
     *
     * @return
     * @return
     */
     */
    @RequestMapping(value = "stopAll")
    @ResponseBody
    @RequestMapping(value = "stopAll", method = RequestMethod.GET)
    public String stopAll() {
    public String stopAll() {
        try {
        try {
            jobService.stopAll();
            jobService.stopAll();
            return success("停止成功!");
            return success("停止成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
@ -146,27 +173,138 @@ public class JobController extends BaseController {
     *
     *
     * @return
     * @return
     */
     */
    @RequestMapping(value = "startAll")
    @ResponseBody
    @RequestMapping(value = "startAll", method = RequestMethod.GET)
    public String startAll() {
    public String startAll() {
        try {
        try {
            jobService.startAll();
            jobService.startAll();
            return success("启动成功!");
            return success("启动成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
        }
    }
    }
    @RequestMapping(value = "startaaaa")
    @ResponseBody
    @RequestMapping(value = "startaaaa", method = RequestMethod.GET)
    public String startaaaa() {
    public String startaaaa() {
        try {
        try {
            jobService.startaaaa();
            jobService.startaaaa();
            return success("启动成功!");
            return success("启动成功!");
        } catch (Exception e) {
        } catch (Exception e) {
            error(e);
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 将患者疾病推送到redis
     *
     * @return
     */
    @RequestMapping(value = "/disease/to_redis", method = RequestMethod.GET)
    public String updateToRedid() {
        try {
            diseaseService.updateToRedis();
            return write(200, "更新成功");
        } catch (Exception e) {
            return error(-1, "更新失败");
        }
    }
    /**
     * 将患者疾病到数据库
     *
     * @return
     */
    @RequestMapping(value = "/disease/to_disease", method = RequestMethod.GET)
    public String updateToDisease() {
        try {
            diseaseService.updateToDisease();
            return write(200, "更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "更新失败");
        }
    }
    /**
     * 从Redis查询患者疾病
     *
     * @param patient
     * @return
     */
    @RequestMapping(value = "/disease/patient", method = RequestMethod.GET)
    public String getDiseaseFromRedis(String patient) {
        try {
            return write(200, "查询成功", "data", redisTemplate.opsForValue().get("disease:" + patient));
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     * 开始名医咨询剩余次数统计任务
     *
     * @return
     */
    @RequestMapping(value = "/famous_doctor/start_job", method = RequestMethod.GET)
    public String startConsultTimesJob() {
        try {
            if (!quartzHelper.isExistJob("famous-doctor-times")) {
                quartzHelper.addJob(FamousConsultTimesJob.class, "0 0 0 * * ?", "famous-doctor-times", new HashMap<String, Object>());
                return write(200, "启动成功");
            } else {
                return write(200, "任务已存在");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "启动失败");
        }
    }
    /**
     * 名医咨询剩余次数手动更新
     *
     * @return
     */
    @RequestMapping(value = "/famous_doctor/times_update", method = RequestMethod.GET)
    public String famousConsultTimeUpdate() {
        try {
            workTimeService.consultTimesRemain(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
            return write(200, "更新成功");
        } catch (Exception e) {
            error(e);
            return error(-1, "更新失败");
        }
    }
    /**
     * 更新人口数据到redis
     *
     * @return
     */
    public String peopleNumToRedis() {
        try {
            statisticsService.peopleNumToRedis();
            return write(200, "更新成功");
        } catch (Exception e) {
            error(e);
            return error(-1, "更新失败");
        }
    }
    /**
     * 添加患者咨询超时未响应关闭任务。
     */
    @RequestMapping(value = "/consult_auto_termination", method = RequestMethod.POST)
    @ApiOperation("添加超时咨询自动关闭任务")
    public String addConsultJob() {
        try {
            quartzHelper.startNow(ConsultCleanerJob.class, ConsultTerminatorJobKey, null);
            return write(200, "");
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
        }
    }
    }
}
}

+ 0 - 17
src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -23,23 +23,6 @@ public class StatisticsController extends BaseController {
    @Autowired
    @Autowired
    StatisticsService statisticsService;
    StatisticsService statisticsService;
    /**
     * 缓存人口数据到redis
     *
     * @return
     */
    @RequestMapping(value = "/people_num_to_redis")
    @ResponseBody
    public String peopleNumToRedis(){
        try{
            statisticsService.peopleNumToRedis();
            return write(200,"更新成功");
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"更新失败");
        }
    }
    /**
    /**
     * 指标按间隔统计
     * 指标按间隔统计
     *
     *