|
@@ -1,12 +1,24 @@
|
|
package com.dingtalk.h5app.quickstart.controller;
|
|
package com.dingtalk.h5app.quickstart.controller;
|
|
|
|
|
|
|
|
+
|
|
|
|
+import com.dingtalk.h5app.quickstart.domain.ServiceResult;
|
|
import com.dingtalk.h5app.quickstart.entity.Grade;
|
|
import com.dingtalk.h5app.quickstart.entity.Grade;
|
|
|
|
+import com.dingtalk.h5app.quickstart.mapper.CronMapper;
|
|
import com.dingtalk.h5app.quickstart.service.CiKuService;
|
|
import com.dingtalk.h5app.quickstart.service.CiKuService;
|
|
|
|
+import com.dingtalk.h5app.quickstart.service.QuartzService;
|
|
|
|
+import com.dingtalk.h5app.quickstart.service.TokenService;
|
|
import com.dingtalk.h5app.quickstart.vo.CiKuVO;
|
|
import com.dingtalk.h5app.quickstart.vo.CiKuVO;
|
|
|
|
+import org.junit.Test;
|
|
|
|
+import org.quartz.JobKey;
|
|
|
|
+import org.quartz.Scheduler;
|
|
|
|
+import org.quartz.SchedulerException;
|
|
|
|
+import org.quartz.TriggerKey;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
-
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.sql.SQLException;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@CrossOrigin
|
|
@CrossOrigin
|
|
@@ -15,6 +27,18 @@ public class CiKuController {
|
|
@Resource
|
|
@Resource
|
|
private CiKuService ciKuService;
|
|
private CiKuService ciKuService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private QuartzService quartzService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TokenService tokenService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CronMapper cronMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private Scheduler scheduler;
|
|
|
|
+
|
|
@GetMapping("/findByRandom")
|
|
@GetMapping("/findByRandom")
|
|
public List<CiKuVO> findByRandom() {
|
|
public List<CiKuVO> findByRandom() {
|
|
return ciKuService.findByRandom();
|
|
return ciKuService.findByRandom();
|
|
@@ -30,4 +54,91 @@ public class CiKuController {
|
|
return ciKuService.getGrade(name);
|
|
return ciKuService.getGrade(name);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @PostMapping("/setTimer")
|
|
|
|
+ public ServiceResult serTimer(@RequestParam("pinlv") String pinlv, @RequestParam("time") String time, @RequestParam("userid") String userid){
|
|
|
|
+// System.out.println(pinlv);
|
|
|
|
+// System.out.println(userid);
|
|
|
|
+ String accessToken;
|
|
|
|
+// System.out.println(file);
|
|
|
|
+ // 获取accessToken
|
|
|
|
+ ServiceResult<String> accessTokenSr = tokenService.getAccessToken();
|
|
|
|
+ if (!accessTokenSr.isSuccess()) {
|
|
|
|
+ return ServiceResult.failure(accessTokenSr.getCode(), accessTokenSr.getMessage());
|
|
|
|
+ }
|
|
|
|
+ List<Integer> a = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ accessToken = accessTokenSr.getResult();
|
|
|
|
+ String cron = "";
|
|
|
|
+ if ("day".equals(pinlv)){
|
|
|
|
+ if(time.charAt(0) == '0'&& time.charAt(3) == '0'){
|
|
|
|
+ cron = "0 " + time.charAt(4) + " " + time.charAt(1) + " * * ?";
|
|
|
|
+ }else if (time.charAt(0) == '0'&& time.charAt(3) != '0'){
|
|
|
|
+ cron = "0 " + time.substring(3,5) + " " + time.charAt(1) + " * * ?";
|
|
|
|
+ }else if(time.charAt(0) != '0'&& time.charAt(3) == '0'){
|
|
|
|
+ cron = "0 " + time.charAt(4) + " " + time.substring(0,2) + " * * ?";
|
|
|
|
+ }else if(time.charAt(0) != '0'&& time.charAt(3) != '0'){
|
|
|
|
+ cron = "0 " + time.substring(3,5) + " " + time.substring(0,2) + " * * ?";
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ if ("00".equals(time.substring(3,5))){
|
|
|
|
+ if("0".equals(time.substring(0,1))){
|
|
|
|
+ cron = "0 0 "+ time.charAt(1) +" ? * "+pinlv;
|
|
|
|
+ }else{
|
|
|
|
+ cron = "0 0 "+ time.substring(0,2) +" ? * "+pinlv;
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ if("0".equals(time.substring(0,1))){
|
|
|
|
+ if ("0".equals(time.substring(3,4))){
|
|
|
|
+ cron = "0 "+time.charAt(4)+" "+ time.charAt(1) +" ? * " +pinlv;
|
|
|
|
+ }else {
|
|
|
|
+ cron = "0 "+time.substring(3,5)+" "+ time.charAt(1) +" ? * " +pinlv;
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ if ("0".equals(time.substring(3,4))){
|
|
|
|
+ cron = "0 "+time.charAt(4)+" "+ time.substring(0,2) +" ? * " +pinlv;
|
|
|
|
+ }else {
|
|
|
|
+ cron = "0 "+time.substring(3,5)+" "+ time.substring(0,2) +" ? * " +pinlv;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ if("success".equals(quartzService.insertQuartz(userid, cron, accessToken,pinlv+"|"+time))){
|
|
|
|
+ return ServiceResult.success("成功");
|
|
|
|
+ }else {
|
|
|
|
+ return ServiceResult.failure("失败");
|
|
|
|
+ }
|
|
|
|
+ } catch (SchedulerException | SQLException e) {
|
|
|
|
+ return ServiceResult.failure(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/selectTimer")
|
|
|
|
+ public ServiceResult selectTimer(@RequestParam("userid") String userid){
|
|
|
|
+ return ServiceResult.success(cronMapper.selectCron(userid));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/deleteTimer")
|
|
|
|
+ public ServiceResult deleteTimer(@RequestParam("userid") String userid,@RequestParam("frequency") String frequency) throws SchedulerException {
|
|
|
|
+ String jobID = cronMapper.getJobID(userid, frequency);
|
|
|
|
+// System.out.println(jobID);
|
|
|
|
+ try {
|
|
|
|
+ JobKey jobKey = new JobKey(jobID,userid);
|
|
|
|
+ if (!scheduler.checkExists(jobKey)) {
|
|
|
|
+ System.out.println("job not exists, job name: "+jobKey.getName()+", group name: "+ jobKey.getGroup());
|
|
|
|
+ return ServiceResult.failure("200");
|
|
|
|
+ }
|
|
|
|
+ TriggerKey triggerKey = TriggerKey.triggerKey(jobID,userid);
|
|
|
|
+ scheduler.pauseTrigger(triggerKey);
|
|
|
|
+ scheduler.unscheduleJob(triggerKey);
|
|
|
|
+ boolean b = scheduler.deleteJob(jobKey);
|
|
|
|
+ System.out.println(b);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ System.out.println(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+// System.out.println(b);
|
|
|
|
+ return ServiceResult.success(cronMapper.deleteTimer(userid,frequency));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|