初始化

This commit is contained in:
2022-06-21 20:47:46 +08:00
parent b666a24a98
commit 59da3376c1
1246 changed files with 129600 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
package com.njcn.job.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.job.api.fallback.JobFeignClientFallbackFactory;
import com.njcn.job.model.XxlJobInfo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
/**
* @author hongawen
* @version 1.0.0
* @date 2022年04月18日 14:41
*/
@FeignClient(value = ServerInfo.JOB_ADMIN,path = "/job-admin/jobinfo",fallbackFactory = JobFeignClientFallbackFactory.class)
public interface JobFeignClient {
/**
* 新增定时任务
* @param jobInfo 任务细节
* @return 新增结果
*/
@PostMapping("/addJob")
@ResponseBody
HttpResult<String> addJob(@RequestBody XxlJobInfo jobInfo);
/**
* 修改定时任务
* @param jobInfo 任务细节
* @return 修改结果
*/
@PostMapping("/updateJob")
@ResponseBody
HttpResult<String> updateJob(@RequestBody XxlJobInfo jobInfo);
/**
* 删除定时任务
* @param id
* @return 新增结果
*/
@GetMapping("/removeJob")
@ResponseBody
HttpResult<String> removeJob(@RequestParam("id")int id);
/**
* 停止定时任务
* @param id
* @return 新增结果
*/
@GetMapping("/stopJob")
@ResponseBody
HttpResult<String> stopJob(@RequestParam("id")int id);
/**
* 启动任务
* @param id 任务ID
* @return 新增结果
*/
@RequestMapping("/startTask")
@ResponseBody
HttpResult<String> startTask(@RequestParam("id")int id);
}

View File

@@ -0,0 +1,66 @@
package com.njcn.job.api.fallback;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.job.api.JobFeignClient;
import com.njcn.job.model.XxlJobInfo;
import com.xxl.job.core.biz.model.ReturnT;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author hongawen
* @version 1.0.0
* @date 2022年04月18日 14:44
*/
@Slf4j
@Component
public class JobFeignClientFallbackFactory implements FallbackFactory<JobFeignClient> {
/**
* 输出远程请求接口异常日志
*
* @param cause RPC请求异常
*/
@Override
public JobFeignClient create(Throwable cause) {
return new JobFeignClient() {
@Override
public HttpResult<String> addJob(XxlJobInfo jobInfo) {
log.error("{}异常,降级处理,异常为:{}", "新增定时任务", cause.toString());
return new HttpResult(ReturnT.FAIL_CODE, "新增定时任务降级失败");
}
@Override
public HttpResult<String> updateJob(XxlJobInfo jobInfo) {
log.error("{}异常,降级处理,异常为:{}", "修改定时任务", cause.toString());
return new HttpResult(ReturnT.FAIL_CODE, "修改定时任务降级失败");
}
@Override
public HttpResult<String> removeJob(int id) {
log.error("{}异常,降级处理,异常为:{}", "删除定时任务", cause.toString());
return new HttpResult(ReturnT.FAIL_CODE, "删除定时任务降级失败");
}
@Override
public HttpResult<String> stopJob(int id) {
log.error("{}异常,降级处理,异常为:{}", "停止定时任务", cause.toString());
return new HttpResult(ReturnT.FAIL_CODE, "停止定时任务降级失败");
}
@Override
public HttpResult<String> startTask(int id) {
log.error("{}异常,降级处理,异常为:{}", "启动任务", cause.toString());
return new HttpResult(ReturnT.FAIL_CODE, "启动任务降级失败");
}
};
}
}