wangwei %!s(int64=7) %!d(string=hai) anos
pai
achega
97e2ef5037

+ 85 - 85
examcloud-task-api-provider/src/main/java/cn/com/qmth/examcloud/task/api/controller/JobController.java

@@ -1,85 +1,85 @@
-package cn.com.qmth.examcloud.task.api.controller;
-
-import javax.transaction.Transactional;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import cn.com.qmth.examcloud.commons.base.exception.StatusException;
-import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
-import cn.com.qmth.examcloud.task.base.QuartzManager;
-import cn.com.qmth.examcloud.task.base.ScheduleJob;
-import cn.com.qmth.examcloud.task.dao.ScheduleJobRepo;
-import cn.com.qmth.examcloud.task.dao.entity.ScheduleJobEntity;
-import io.swagger.annotations.ApiOperation;
-
-@Transactional
-@RestController
-@RequestMapping("${$rmp.ctr.task}" + "job")
-public class JobController extends ControllerSupport {
-
-	@Autowired
-	private ScheduleJobRepo scheduleJobEntityRepo;
-
-	@Autowired
-	private QuartzManager quartzManager;
-
-	@ApiOperation(value = "启动job")
-	@PostMapping("/executeJob/{jobName}")
-	public void executeJob(@PathVariable String jobName) {
-		ScheduleJob scheduleJob = getEnableScheduleJob(jobName);
-		quartzManager.addJob(scheduleJob);
-	}
-
-	@ApiOperation(value = "暂停job")
-	@PostMapping("/pauseJob/{jobName}")
-	public void pauseJob(@PathVariable String jobName) {
-		ScheduleJob scheduleJob = getEnableScheduleJob(jobName);
-		quartzManager.pauseJob(scheduleJob);
-	}
-
-	@ApiOperation(value = "从暂停中恢复job")
-	@PostMapping("/resumeJob/{jobName}")
-	public void resumeJob(@PathVariable String jobName) {
-		ScheduleJob scheduleJob = getEnableScheduleJob(jobName);
-		quartzManager.resumeJob(scheduleJob);
-	}
-
-	@ApiOperation(value = "删除job")
-	@PostMapping("/deleteJob/{jobName}")
-	public void deleteJob(@PathVariable String jobName) {
-		ScheduleJob scheduleJob = getEnableScheduleJob(jobName);
-		quartzManager.deleteJob(scheduleJob);
-	}
-
-	/**
-	 * 获取可用job
-	 *
-	 * @author WANGWEI
-	 * @param jobName
-	 * @return
-	 */
-	private ScheduleJob getEnableScheduleJob(String jobName) {
-		ScheduleJobEntity jobEntity = scheduleJobEntityRepo.findByJobName(jobName);
-		if (null == jobEntity) {
-			throw new StatusException("T-100001", "任务不存在");
-		}
-
-		if (!jobEntity.getEnable()) {
-			throw new StatusException("T-100001", "任务被禁用");
-		}
-
-		ScheduleJob scheduleJob = new ScheduleJob();
-		scheduleJob.setJobName(jobEntity.getJobName());
-		scheduleJob.setJobGroup(jobEntity.getJobGroup());
-		scheduleJob.setSpringBean(jobEntity.getSpringBean());
-		scheduleJob.setCronExpression(jobEntity.getCronExpression());
-		scheduleJob.setStateful(jobEntity.getStateful());
-
-		return scheduleJob;
-	}
-
-}
+package cn.com.qmth.examcloud.task.api.controller;
+
+import javax.transaction.Transactional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.task.base.QuartzManager;
+import cn.com.qmth.examcloud.task.base.ScheduleJob;
+import cn.com.qmth.examcloud.task.dao.ScheduleJobRepo;
+import cn.com.qmth.examcloud.task.dao.entity.ScheduleJobEntity;
+import io.swagger.annotations.ApiOperation;
+
+@Transactional
+@RestController
+@RequestMapping("${$rmp.ctr.task}" + "job")
+public class JobController extends ControllerSupport {
+
+	@Autowired
+	private ScheduleJobRepo scheduleJobEntityRepo;
+
+	@Autowired
+	private QuartzManager quartzManager;
+
+	@ApiOperation(value = "启动job")
+	@PostMapping("/executeJob/{jobName}")
+	public void executeJob(@PathVariable String jobName) {
+		ScheduleJob scheduleJob = getEnableScheduleJob(jobName);
+		quartzManager.addJob(scheduleJob);
+	}
+
+	@ApiOperation(value = "暂停job")
+	@PostMapping("/pauseJob/{jobName}")
+	public void pauseJob(@PathVariable String jobName) {
+		ScheduleJob scheduleJob = getEnableScheduleJob(jobName);
+		quartzManager.pauseJob(scheduleJob);
+	}
+
+	@ApiOperation(value = "从暂停中恢复job")
+	@PostMapping("/resumeJob/{jobName}")
+	public void resumeJob(@PathVariable String jobName) {
+		ScheduleJob scheduleJob = getEnableScheduleJob(jobName);
+		quartzManager.resumeJob(scheduleJob);
+	}
+
+	@ApiOperation(value = "删除job")
+	@PostMapping("/deleteJob/{jobName}")
+	public void deleteJob(@PathVariable String jobName) {
+		ScheduleJob scheduleJob = getEnableScheduleJob(jobName);
+		quartzManager.deleteJob(scheduleJob);
+	}
+
+	/**
+	 * 获取可用job
+	 *
+	 * @author WANGWEI
+	 * @param jobName
+	 * @return
+	 */
+	private ScheduleJob getEnableScheduleJob(String jobName) {
+		ScheduleJobEntity jobEntity = scheduleJobEntityRepo.findByJobName(jobName);
+		if (null == jobEntity) {
+			throw new StatusException("T-100001", "任务不存在");
+		}
+
+		if (!jobEntity.getEnable()) {
+			throw new StatusException("T-100002", "任务被禁用");
+		}
+
+		ScheduleJob scheduleJob = new ScheduleJob();
+		scheduleJob.setJobName(jobEntity.getJobName());
+		scheduleJob.setJobGroup(jobEntity.getJobGroup());
+		scheduleJob.setSpringBean(jobEntity.getSpringBean());
+		scheduleJob.setCronExpression(jobEntity.getCronExpression());
+		scheduleJob.setStateful(jobEntity.getStateful());
+
+		return scheduleJob;
+	}
+
+}