123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- package com.yihu.jw.care.web;
- import com.yihu.jw.care.job.QuartzHelper;
- import com.yihu.jw.care.job.consult.FinishConsultJob;
- import com.yihu.jw.care.job.message.DoctorSendUnreadJob;
- import com.yihu.jw.care.job.message.PatientSendUnreadJob;
- import com.yihu.jw.care.service.JobService;
- import com.yihu.jw.care.util.SystemConf;
- import com.yihu.jw.restmodel.web.ObjEnvelop;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.HashMap;
- /**
- * 任务启动
- *
- * @author chenweida
- */
- @RestController
- @RequestMapping(value = "/job", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- @Api(description = "后台-任务控制")
- public class JobController extends BaseController {
- private org.slf4j.Logger logger = LoggerFactory.getLogger(JobController.class);
- private final JobService jobService;
- private final QuartzHelper quartzHelper;
- @Autowired
- public JobController(JobService jobService, QuartzHelper quartzHelper) {
- this.jobService = jobService;
- this.quartzHelper = quartzHelper;
- }
- @RequestMapping(value = "removeJob", method = RequestMethod.GET)
- public String removeJob(String taskId) {
- try {
- if(quartzHelper.isExistJob(taskId)){
- quartzHelper.removeJob(taskId);
- return success("删除成功!");
- }
- return success("删除成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "删除失败:" + e.getMessage());
- }
- }
- @RequestMapping(value = "getCalendar", method = RequestMethod.GET)
- public ObjEnvelop getCalendar() throws Exception{
- return success(quartzHelper.getCalendar());
- }
- @RequestMapping(value = "isExist", method = RequestMethod.GET)
- public String isExist(String taskId) {
- try {
- if(quartzHelper.isExistJob(taskId)){
- return success("job已经存在!");
- }
- return success("job不存在!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "执行失败:" + e.getMessage());
- }
- }
- @RequestMapping(value = "reStartById", method = RequestMethod.GET)
- public String reStartById(String taskId) {
- try {
- if(quartzHelper.isExistJob(taskId)){
- quartzHelper.removeJob(taskId);
- }
- switch(taskId){
- case "finish_consult_job":
- if (!quartzHelper.isExistJob("finish_consult_job")) {
- String trigger = SystemConf.getInstance().getSystemProperties().getProperty("finish_consult_job");
- quartzHelper.addJob(FinishConsultJob.class, trigger, "finish_consult_job", new HashMap<String, Object>());
- logger.info("finish_consult_job success");
- } else {
- logger.info("finish_consult_job exist");
- }
- break;
- case "DOCTOR_SEND_UNREAD_MES_JOB":
- if (!quartzHelper.isExistJob("DOCTOR_SEND_UNREAD_MES_JOB")) {
- String trigger = SystemConf.getInstance().getSystemProperties().getProperty("DOCTOR_SEND_UNREAD_MES_JOB");
- quartzHelper.addJob(DoctorSendUnreadJob.class, trigger, "DOCTOR_SEND_UNREAD_MES_JOB", new HashMap<String, Object>());
- logger.info("DOCTOR_SEND_UNREAD_MES_JOB success");
- } else {
- logger.info("DOCTOR_SEND_UNREAD_MES_JOB exist");
- }
- break;
- case "PATIENT_SEND_UNREAD_MES_JOB":
- if (!quartzHelper.isExistJob("PATIENT_SEND_UNREAD_MES_JOB")) {
- String trigger = SystemConf.getInstance().getSystemProperties().getProperty("PATIENT_SEND_UNREAD_MES_JOB");
- quartzHelper.addJob(PatientSendUnreadJob.class, trigger, "PATIENT_SEND_UNREAD_MES_JOB", new HashMap<String, Object>());
- logger.info("PATIENT_SEND_UNREAD_MES_JOB success");
- } else {
- logger.info("PATIENT_SEND_UNREAD_MES_JOB exist");
- }
- break;
- default :
- }
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 生成过去几天的数据
- *
- * @param day
- * @return
- */
- @RequestMapping(value = "productDataByDay", method = RequestMethod.GET)
- public String productDataByDay(Integer day) {
- try {
- jobService.productDataByDay(day);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 生成过去某一天的全部的数据
- *
- * @param day
- * @return
- */
- @RequestMapping(value = "productDataByOneDay", method = RequestMethod.GET)
- public String productDataByOneDay(String day) {
- try {
- jobService.productDataByOneDay(day);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 生成过去某一天的某一个指标的数据
- *
- * @param day
- * @return
- */
- @RequestMapping(value = "productDataByOneDayWithId", method = RequestMethod.GET)
- public String productDataByOneDayWithId(String day, String id) {
- try {
- jobService.productDataByOneDayWithId(day, id);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 生成过去某几天的某一个指标的数据
- *
- * @param day
- * @return
- */
- @RequestMapping(value = "productDataByDayAndId", method = RequestMethod.GET)
- public String productDataByDayAndId(Integer day, String id) {
- try {
- jobService.productDataByDayAndId(day, id);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 启动任务
- *
- * @param id id
- * @return
- */
- @RequestMapping(value = "startById", method = RequestMethod.GET)
- public String startById(String id) {
- try {
- jobService.startById(id);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 停止任务
- *
- * @param id id
- * @return
- */
- @RequestMapping(value = "stopById", method = RequestMethod.GET)
- public String stopById(String id) {
- try {
- jobService.stopById(id);
- return success("停止成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 停止所有任务
- *
- * @return
- */
- @RequestMapping(value = "stopAll", method = RequestMethod.GET)
- public String stopAll() {
- try {
- jobService.stopAll();
- return success("停止成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 启动所有任务
- *
- * @return
- */
- @RequestMapping(value = "startAll", method = RequestMethod.GET)
- public String startAll() {
- try {
- jobService.startAll();
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- @RequestMapping(value = "/testNow", method = RequestMethod.POST)
- @ApiOperation("立即执行")
- public String executeSignFamilyPayResultJob() {
- try {
- quartzHelper.startNow(FinishConsultJob.class, "finish_consult_job", null);
- quartzHelper.startNow(DoctorSendUnreadJob.class, "DOCTOR_SEND_UNREAD_MES_JOB", null);
- quartzHelper.startNow(PatientSendUnreadJob.class, "PATIENT_SEND_UNREAD_MES_JOB", null);
- return write(200, "启动成功");
- } catch (Exception e) {
- error(e);
- return error(-1, e.getMessage());
- }
- }
- }
|