mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-29 16:25:12 +00:00
更新
This commit is contained in:
@@ -20,16 +20,5 @@
|
||||
<groupId>com.egridcloud.udf</groupId>
|
||||
<artifactId>udf-starter-core</artifactId>
|
||||
</dependency>
|
||||
<!-- spring-context-support -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<!-- quartz -->
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
<artifactId>quartz</artifactId>
|
||||
<version>${quartz.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* IExecute.java
|
||||
* Created at 2017-06-11
|
||||
* Created by Administrator
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.scheduler.client;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 描述 : IExecute
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
public interface IExecute {
|
||||
|
||||
/**
|
||||
* 描述 : 执行方法
|
||||
*
|
||||
* @param jobDataMap jobDataMap
|
||||
*/
|
||||
public void execute(Map<String, Object> jobDataMap);
|
||||
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.scheduler;
|
||||
package com.egridcloud.udf.scheduler.client;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
+25
@@ -7,6 +7,7 @@
|
||||
package com.egridcloud.udf.scheduler.client.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -37,6 +38,30 @@ public class GeneralJobParam implements Serializable {
|
||||
@ApiModelProperty(value = "bean名称", required = true, dataType = "string")
|
||||
private String beanName;
|
||||
|
||||
/**
|
||||
* 描述 : 作业参数
|
||||
*/
|
||||
@ApiModelProperty(value = "作业参数", required = true, dataType = "object")
|
||||
private Map<String, Object> jobDataMap; //NOSONAR
|
||||
|
||||
/**
|
||||
* 描述 : 获取jobDataMap
|
||||
*
|
||||
* @return the jobDataMap
|
||||
*/
|
||||
public Map<String, Object> getJobDataMap() {
|
||||
return jobDataMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置jobDataMap
|
||||
*
|
||||
* @param jobDataMap the jobDataMap to set
|
||||
*/
|
||||
public void setJobDataMap(Map<String, Object> jobDataMap) {
|
||||
this.jobDataMap = jobDataMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取fireInstanceId
|
||||
*
|
||||
|
||||
+107
-10
@@ -7,6 +7,7 @@
|
||||
package com.egridcloud.udf.scheduler.client.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -29,24 +30,120 @@ public class GeneralJobResult implements Serializable {
|
||||
* 描述 : 执行ID
|
||||
*/
|
||||
@ApiModelProperty(value = "执行ID", required = true, dataType = "string")
|
||||
private String id;
|
||||
private String fireInstanceId;
|
||||
|
||||
/**
|
||||
* 描述 : 获取id
|
||||
*
|
||||
* @return the id
|
||||
* 描述 : 参数
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
@ApiModelProperty(value = "参数", required = true, dataType = "object")
|
||||
private GeneralJobParam param;
|
||||
|
||||
/**
|
||||
* 描述 : 客户端初始化时间
|
||||
*/
|
||||
@ApiModelProperty(value = "客户端初始化时间", required = true, dataType = "long")
|
||||
private Date clientInitTime;
|
||||
|
||||
/**
|
||||
* 描述 : 客户端开始时间
|
||||
*/
|
||||
@ApiModelProperty(value = "客户端开始时间", required = true, dataType = "long")
|
||||
private Date clientStartExecuteTime;
|
||||
|
||||
/**
|
||||
* 描述 : 客户端结束时间
|
||||
*/
|
||||
@ApiModelProperty(value = "客户端结束时间", required = true, dataType = "long")
|
||||
private Date clientEndExecuteTime;
|
||||
|
||||
/**
|
||||
* 描述 : 获取clientInitTime
|
||||
*
|
||||
* @return the clientInitTime
|
||||
*/
|
||||
public Date getClientInitTime() {
|
||||
return clientInitTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置id
|
||||
* 描述 : 设置clientInitTime
|
||||
*
|
||||
* @param id the id to set
|
||||
* @param clientInitTime the clientInitTime to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
public void setClientInitTime(Date clientInitTime) {
|
||||
this.clientInitTime = clientInitTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取clientStartExecuteTime
|
||||
*
|
||||
* @return the clientStartExecuteTime
|
||||
*/
|
||||
public Date getClientStartExecuteTime() {
|
||||
return clientStartExecuteTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置clientStartExecuteTime
|
||||
*
|
||||
* @param clientStartExecuteTime the clientStartExecuteTime to set
|
||||
*/
|
||||
public void setClientStartExecuteTime(Date clientStartExecuteTime) {
|
||||
this.clientStartExecuteTime = clientStartExecuteTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取clientEndExecuteTime
|
||||
*
|
||||
* @return the clientEndExecuteTime
|
||||
*/
|
||||
public Date getClientEndExecuteTime() {
|
||||
return clientEndExecuteTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置clientEndExecuteTime
|
||||
*
|
||||
* @param clientEndExecuteTime the clientEndExecuteTime to set
|
||||
*/
|
||||
public void setClientEndExecuteTime(Date clientEndExecuteTime) {
|
||||
this.clientEndExecuteTime = clientEndExecuteTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取param
|
||||
*
|
||||
* @return the param
|
||||
*/
|
||||
public GeneralJobParam getParam() {
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置param
|
||||
*
|
||||
* @param param the param to set
|
||||
*/
|
||||
public void setParam(GeneralJobParam param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取fireInstanceId
|
||||
*
|
||||
* @return the fireInstanceId
|
||||
*/
|
||||
public String getFireInstanceId() {
|
||||
return fireInstanceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置fireInstanceId
|
||||
*
|
||||
* @param fireInstanceId the fireInstanceId to set
|
||||
*/
|
||||
public void setFireInstanceId(String fireInstanceId) {
|
||||
this.fireInstanceId = fireInstanceId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* ISchClientController.java
|
||||
* Created at 2017-05-26
|
||||
* Created by Administrator
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.scheduler.client.web;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import com.egridcloud.udf.core.RestResponse;
|
||||
import com.egridcloud.udf.scheduler.client.domain.GeneralJobParam;
|
||||
import com.egridcloud.udf.scheduler.client.domain.GeneralJobResult;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* 描述 : ISchClientController
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
@Api(value = "计划任务客户端", consumes = "application/json", produces = "application/json",
|
||||
protocols = "http")
|
||||
@RequestMapping(value = "/service/scheduler/client")
|
||||
public interface ISchClientController {
|
||||
|
||||
/**
|
||||
* 描述 : 执行计划任务
|
||||
*
|
||||
* @param param param
|
||||
*
|
||||
* @return 执行计划任务
|
||||
*/
|
||||
@ApiOperation(value = "接口编号自定义", notes = "执行计划任务")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称",
|
||||
required = true, dataType = "string"),
|
||||
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true,
|
||||
dataType = "string"),
|
||||
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号",
|
||||
required = true, dataType = "string") })
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public RestResponse<GeneralJobResult> execute(@RequestBody GeneralJobParam param);
|
||||
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* SchClientController.java
|
||||
* Created at 2017-05-26
|
||||
* Created by Administrator
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.scheduler.client.web;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.egridcloud.udf.core.RestResponse;
|
||||
import com.egridcloud.udf.scheduler.client.IExecute;
|
||||
import com.egridcloud.udf.scheduler.client.SchException;
|
||||
import com.egridcloud.udf.scheduler.client.domain.GeneralJobParam;
|
||||
import com.egridcloud.udf.scheduler.client.domain.GeneralJobResult;
|
||||
|
||||
/**
|
||||
* 描述 : SchClientController
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
public class SchClientController implements ISchClientController, ApplicationContextAware {
|
||||
|
||||
/**
|
||||
* 描述 : spring上下文
|
||||
*/
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public RestResponse<GeneralJobResult> execute(@RequestBody GeneralJobParam param) {
|
||||
//客户端初始化时间
|
||||
Date clientInitTime = new Date();
|
||||
//定义返回值
|
||||
GeneralJobResult result = new GeneralJobResult();
|
||||
result.setFireInstanceId(param.getFireInstanceId());
|
||||
result.setParam(param);
|
||||
//获得bean
|
||||
IExecute bean = applicationContext.getBean(IExecute.class, param.getBeanName());
|
||||
if (bean == null) {
|
||||
throw new SchException(param.getBeanName() + " not definition");
|
||||
}
|
||||
//客户端开始时间
|
||||
Date clientStartExecuteTime = new Date();
|
||||
//执行
|
||||
bean.execute(param.getJobDataMap());
|
||||
//客户端结束时间
|
||||
Date clientEndExecuteTime = new Date();
|
||||
//设置返回值
|
||||
result.setClientInitTime(clientInitTime);
|
||||
result.setClientStartExecuteTime(clientStartExecuteTime);
|
||||
result.setClientEndExecuteTime(clientEndExecuteTime);
|
||||
//返回
|
||||
return new RestResponse<>(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext arg0) throws BeansException {
|
||||
applicationContext = arg0;
|
||||
}
|
||||
|
||||
}
|
||||
+10
-15
@@ -17,7 +17,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import com.egridcloud.udf.core.RestResponse;
|
||||
import com.egridcloud.udf.rms.Rms;
|
||||
import com.egridcloud.udf.scheduler.IGeneralJobResult;
|
||||
import com.egridcloud.udf.scheduler.SchException;
|
||||
import com.egridcloud.udf.scheduler.client.SchException;
|
||||
import com.egridcloud.udf.scheduler.client.domain.GeneralJobParam;
|
||||
import com.egridcloud.udf.scheduler.client.domain.GeneralJobResult;
|
||||
|
||||
@@ -50,22 +50,17 @@ public class GeneralJob extends AbstractBaseJob {
|
||||
GeneralJobParam generalJobParam = new GeneralJobParam();
|
||||
generalJobParam.setFireInstanceId(jobExecutionContext.getFireInstanceId());
|
||||
generalJobParam.setBeanName(beanName);
|
||||
generalJobParam.setJobDataMap(jobDataMap.getWrappedMap());
|
||||
//请求
|
||||
try {
|
||||
//拿到结果
|
||||
ResponseEntity<RestResponse<GeneralJobResult>> result = rms.call(serviceCode, generalJobParam,
|
||||
null, new ParameterizedTypeReference<RestResponse<GeneralJobResult>>() {
|
||||
}, null);
|
||||
//判断http状态
|
||||
if (result.getStatusCode() != HttpStatus.OK) {
|
||||
throw new SchException(result.getStatusCode().toString());
|
||||
}
|
||||
//记录结果
|
||||
saveGeneralJobResult(result.getBody().getResult());
|
||||
} catch (Exception e) {
|
||||
//抛出异常
|
||||
throw new JobExecutionException(e);
|
||||
ResponseEntity<RestResponse<GeneralJobResult>> result = rms.call(serviceCode, generalJobParam,
|
||||
null, new ParameterizedTypeReference<RestResponse<GeneralJobResult>>() {
|
||||
}, null);
|
||||
//判断http状态
|
||||
if (result.getStatusCode() != HttpStatus.OK) {
|
||||
throw new SchException(result.getStatusCode().toString());
|
||||
}
|
||||
//记录结果
|
||||
saveGeneralJobResult(result.getBody().getResult());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -26,8 +26,8 @@ import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.egridcloud.udf.core.utils.ClassUtil;
|
||||
import com.egridcloud.udf.scheduler.SchException;
|
||||
import com.egridcloud.udf.scheduler.SchedulerProperties;
|
||||
import com.egridcloud.udf.scheduler.client.SchException;
|
||||
import com.egridcloud.udf.scheduler.job.AbstractBaseJob;
|
||||
import com.egridcloud.udf.scheduler.meta.JobDetailMeta;
|
||||
|
||||
|
||||
+1
-1
@@ -31,8 +31,8 @@ import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.egridcloud.udf.core.utils.DateUtil;
|
||||
import com.egridcloud.udf.scheduler.SchException;
|
||||
import com.egridcloud.udf.scheduler.SchedulerProperties;
|
||||
import com.egridcloud.udf.scheduler.client.SchException;
|
||||
import com.egridcloud.udf.scheduler.meta.CronTriggerMeta;
|
||||
import com.egridcloud.udf.scheduler.meta.JobDetailMeta;
|
||||
import com.egridcloud.udf.scheduler.meta.SimpleTriggerMeta;
|
||||
|
||||
Reference in New Issue
Block a user