Quellcode durchsuchen

康复管理代码提交

liuwenbin vor 7 Jahren
Ursprung
Commit
75a71f6413

+ 65 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/specialist/SpecialistService.java

@ -0,0 +1,65 @@
package com.yihu.wlyy.service.specialist;
import com.yihu.wlyy.event.ApplicationEvent;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.job.specialist.EightSpecialistJob;
import com.yihu.wlyy.job.specialist.SixteenSpecialistJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
/**
 * Created by 刘文彬 on 2018/9/13.
 */
@Service
public class SpecialistService {
    private Logger logger = LoggerFactory.getLogger(SpecialistService.class);
    @Autowired
    QuartzHelper quartzHelper;
    public void starJob(Integer type) throws Exception{
        if(type==1){
            //康复计划每天8点发送服务执行进展
            if (!quartzHelper.isExistJob(EightSpecialistJob.jobKey)) {
                quartzHelper.addJob(EightSpecialistJob.class, EightSpecialistJob.jobCron, EightSpecialistJob.jobKey, new HashMap<String, Object>());
                logger.info("NoticeJob  job success");
            } else {
                logger.info("NoticeJob  job exist");
            }
        }else if(type==2){
            //康复计划每天16点发送服务执行进展
            if (!quartzHelper.isExistJob(SixteenSpecialistJob.jobKey)) {
                quartzHelper.addJob(SixteenSpecialistJob.class, SixteenSpecialistJob.jobCron, SixteenSpecialistJob.jobKey, new HashMap<String, Object>());
                logger.info("NoticeJob  job success");
            } else {
                logger.info("NoticeJob  job exist");
            }
        }
    }
    /**
     *
     * @param type 1、8点推送,2、16点推送
     * @throws Exception
     */
    public void stopJob(Integer type) throws Exception{
        switch (type){
            case 1:{
                if(quartzHelper.isExistJob(EightSpecialistJob.jobKey)){
                    quartzHelper.removeJob(EightSpecialistJob.jobKey);
                }break;}
            case 2:{
                if(quartzHelper.isExistJob(SixteenSpecialistJob.jobKey)){
                    quartzHelper.removeJob(EightSpecialistJob.jobKey);
                }
                break;}
        }
    }
}

+ 50 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/web/SpecialistController.java

@ -0,0 +1,50 @@
package com.yihu.wlyy.web;
import com.yihu.wlyy.service.specialist.SpecialistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by 刘文彬 on 2018/9/13.
 */
@RestController
@RequestMapping(value = "/job/specialist", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "后台-任务控制每天8点、16点推送康复计划进展")
public class SpecialistController extends BaseController{
    @Autowired
    private SpecialistService specialistService;
    @RequestMapping(value = "starJob", method = RequestMethod.GET)
    @ApiOperation(value = "启动每天8点、16点推送康复计划进展")
    public String starJob(@ApiParam(name = "type", value = "(1、8点推送,2、16点推送)",required = true)
                          @RequestParam(value = "type", required = true)Integer type){
        try{
            specialistService.starJob(type);
            return success("启动成功!");
        }catch (Exception e){
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    @RequestMapping(value = "stopJob", method = RequestMethod.GET)
    @ApiOperation(value = "关闭每天8点、16点推送康复计划进展")
    public String stopJob(@ApiParam(name = "type", value = "(1、8点推送,2、16点推送)",required = true)
                          @RequestParam(value = "type", required = true)Integer type){
        try{
            specialistService.stopJob(type);
            return success("关闭成功!");
        }catch (Exception e){
            error(e);
            return invalidUserException(e, -1, "关闭失败:" + e.getMessage());
        }
    }
}