From 7c1feb607df16024c57e7d24cb4cc1626d7d890b Mon Sep 17 00:00:00 2001 From: 3y Date: Mon, 22 Nov 2021 22:15:14 +0800 Subject: [PATCH] pipeline code --- .../austin/constant/RespStatusEnum.java | 11 +++ .../com/java3y/austin/enums/ChannelType.java | 29 ++----- .../java/com/java3y/austin/enums/IdType.java | 25 ++---- .../com/java3y/austin/enums/MessageType.java | 31 ++----- .../com/java3y/austin/enums/SmsStatus.java | 26 ++---- .../com/java3y/austin/enums/TemplateType.java | 27 ++----- .../java/com/java3y/austin/pojo/TaskInfo.java | 8 +- .../austin/{pojo => }/vo/BasicResultVO.java | 2 +- austin-service-api-impl/pom.xml | 5 ++ .../java3y/austin/action/AssembleAction.java | 17 ++++ .../com/java3y/austin/action/ParamAction.java | 17 ++++ .../java3y/austin/domain/SendTaskModel.java | 47 +++++++++++ .../com/java3y/austin/enums/RequestType.java | 31 +++++++ .../austin/service/SendServiceImpl.java | 47 ++++++++++- austin-service-api/pom.xml | 7 ++ .../austin/domain/BatchSendRequest.java | 37 +++++++++ .../java3y/austin/domain/MessageParam.java | 31 +++++++ .../com/java3y/austin/domain/SendRequest.java | 18 ++++- .../java3y/austin/domain/SendResponse.java | 22 +++++ .../com/java3y/austin/enums/BusinessCode.java | 28 +++++++ .../java3y/austin/service/SendService.java | 14 +++- .../austin/pipeline/BusinessProcess.java | 5 ++ .../austin/pipeline/ProcessContext.java | 15 ++++ .../austin/pipeline/ProcessController.java | 80 +++++++++++++++++++ .../java3y/austin/pipeline/ProcessModel.java | 4 +- .../austin/pipeline/ProcessResponse.java | 19 +++++ .../austin/pipeline/ProcessTemplate.java | 0 .../austin/controller/SendController.java | 3 +- 28 files changed, 490 insertions(+), 116 deletions(-) rename austin-common/src/main/java/com/java3y/austin/{pojo => }/vo/BasicResultVO.java (98%) create mode 100644 austin-service-api-impl/src/main/java/com/java3y/austin/action/AssembleAction.java create mode 100644 austin-service-api-impl/src/main/java/com/java3y/austin/action/ParamAction.java create mode 100644 austin-service-api-impl/src/main/java/com/java3y/austin/domain/SendTaskModel.java create mode 100644 austin-service-api-impl/src/main/java/com/java3y/austin/enums/RequestType.java create mode 100644 austin-service-api/src/main/java/com/java3y/austin/domain/BatchSendRequest.java create mode 100644 austin-service-api/src/main/java/com/java3y/austin/domain/MessageParam.java create mode 100644 austin-service-api/src/main/java/com/java3y/austin/enums/BusinessCode.java rename {austin-service-api-impl => austin-support}/src/main/java/com/java3y/austin/pipeline/BusinessProcess.java (71%) rename {austin-service-api-impl => austin-support}/src/main/java/com/java3y/austin/pipeline/ProcessContext.java (55%) create mode 100644 austin-support/src/main/java/com/java3y/austin/pipeline/ProcessController.java rename {austin-service-api-impl => austin-support}/src/main/java/com/java3y/austin/pipeline/ProcessModel.java (56%) create mode 100644 austin-support/src/main/java/com/java3y/austin/pipeline/ProcessResponse.java rename {austin-service-api-impl => austin-support}/src/main/java/com/java3y/austin/pipeline/ProcessTemplate.java (100%) diff --git a/austin-common/src/main/java/com/java3y/austin/constant/RespStatusEnum.java b/austin-common/src/main/java/com/java3y/austin/constant/RespStatusEnum.java index c25eb7f..d0057a0 100644 --- a/austin-common/src/main/java/com/java3y/austin/constant/RespStatusEnum.java +++ b/austin-common/src/main/java/com/java3y/austin/constant/RespStatusEnum.java @@ -20,6 +20,7 @@ public enum RespStatusEnum { SUCCESS("00000", "操作成功"), FAIL("00001", "操作失败"), + /** * 客户端 */ @@ -30,6 +31,16 @@ public enum RespStatusEnum { */ SERVICE_ERROR("B0001", "服务执行异常"), RESOURCE_NOT_FOUND("B0404", "资源不存在"), + + + /** + * pipeline + */ + CONTEXT_IS_NULL("P0001","流程上下文为空"), + BUSINESS_CODE_IS_NULL("P0002","业务代码为空"), + PROCESS_TEMPLATE_IS_NULL("P0003","流程模板配置为空"), + PROCESS_LIST_IS_NULL("P0004","业务处理器配置为空" ), + ; /** diff --git a/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java b/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java index d6b0664..71d9296 100644 --- a/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java +++ b/austin-common/src/main/java/com/java3y/austin/enums/ChannelType.java @@ -1,9 +1,16 @@ package com.java3y.austin.enums; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.ToString; + /** * 发送渠道类型枚举 */ +@Getter +@ToString +@AllArgsConstructor public enum ChannelType { IM(10, "IM(站内信)"), PUSH(20, "push(通知栏)"), @@ -13,30 +20,8 @@ public enum ChannelType { MINI_PROGRAM(60, "miniProgram(小程序)") ; - private Integer code; private String description; - ChannelType(Integer code, String description) { - this.code = code; - this.description = description; - } - - public Integer getCode() { - return code; - } - - public void setCode(Integer code) { - this.code = code; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - } diff --git a/austin-common/src/main/java/com/java3y/austin/enums/IdType.java b/austin-common/src/main/java/com/java3y/austin/enums/IdType.java index 113a17d..7805366 100644 --- a/austin-common/src/main/java/com/java3y/austin/enums/IdType.java +++ b/austin-common/src/main/java/com/java3y/austin/enums/IdType.java @@ -1,9 +1,16 @@ package com.java3y.austin.enums; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.ToString; + /** * 发送ID类型枚举 */ +@Getter +@ToString +@AllArgsConstructor public enum IdType { USER_ID(10, "userid"), DID(20, "did"), @@ -11,27 +18,9 @@ public enum IdType { OPEN_ID(40, "openId"), EMAIL(50, "email"); - IdType(Integer code, String description) { - this.code = code; - this.description = description; - } private Integer code; private String description; - public Integer getCode() { - return code; - } - - public void setCode(Integer code) { - this.code = code; - } - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } } diff --git a/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java b/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java index 8642174..acc1ab5 100644 --- a/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java +++ b/austin-common/src/main/java/com/java3y/austin/enums/MessageType.java @@ -1,40 +1,23 @@ package com.java3y.austin.enums; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.ToString; + /** * 发送的消息类型 */ +@Getter +@ToString +@AllArgsConstructor public enum MessageType { NOTICE(10,"通知类消息"), MARKETING(20,"营销类消息"), AUTH_CODE(30,"验证码消息") ; - /** - * `msg_type` tinyint(4) - * NOT NULL DEFAULT '0' COMMENT '10.通知类消息 20.营销类消息 30.验证码类消息', - */ - private Integer code; private String description; - MessageType(Integer code, String description) { - this.code = code; - this.description = description; - } - - public Integer getCode() { - return code; - } - - public void setCode(Integer code) { - this.code = code; - } - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } } diff --git a/austin-common/src/main/java/com/java3y/austin/enums/SmsStatus.java b/austin-common/src/main/java/com/java3y/austin/enums/SmsStatus.java index 1ee5b69..026e640 100644 --- a/austin-common/src/main/java/com/java3y/austin/enums/SmsStatus.java +++ b/austin-common/src/main/java/com/java3y/austin/enums/SmsStatus.java @@ -1,5 +1,12 @@ package com.java3y.austin.enums; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +@AllArgsConstructor public enum SmsStatus { SEND_SUCCESS(10,"调用渠道接口发送成功"), @@ -9,24 +16,5 @@ public enum SmsStatus { private Integer code; private String description; - SmsStatus(Integer code, String description) { - this.code = code; - this.description = description; - } - - public Integer getCode() { - return code; - } - - public void setCode(Integer code) { - this.code = code; - } - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } } diff --git a/austin-common/src/main/java/com/java3y/austin/enums/TemplateType.java b/austin-common/src/main/java/com/java3y/austin/enums/TemplateType.java index a113e4a..f155fe0 100644 --- a/austin-common/src/main/java/com/java3y/austin/enums/TemplateType.java +++ b/austin-common/src/main/java/com/java3y/austin/enums/TemplateType.java @@ -1,5 +1,12 @@ package com.java3y.austin.enums; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +@AllArgsConstructor public enum TemplateType { OPERATION(10, "运营类的模板"), @@ -9,24 +16,4 @@ public enum TemplateType { private Integer code; private String description; - TemplateType(Integer code, String description) { - this.code = code; - this.description = description; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Integer getCode() { - return code; - } - - public void setCode(Integer code) { - this.code = code; - } } diff --git a/austin-common/src/main/java/com/java3y/austin/pojo/TaskInfo.java b/austin-common/src/main/java/com/java3y/austin/pojo/TaskInfo.java index b108882..2ad9c40 100644 --- a/austin-common/src/main/java/com/java3y/austin/pojo/TaskInfo.java +++ b/austin-common/src/main/java/com/java3y/austin/pojo/TaskInfo.java @@ -1,15 +1,20 @@ package com.java3y.austin.pojo; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import java.util.Set; /** * 发送任务信息 + * @author 3y */ @Data @Builder +@AllArgsConstructor +@NoArgsConstructor public class TaskInfo { /** @@ -18,7 +23,7 @@ public class TaskInfo { private Long messageTemplateId; /** - * 业务Id + * 业务Id(数据追踪使用) */ private Long businessId; @@ -69,5 +74,4 @@ public class TaskInfo { */ private Integer isNightShield; - } diff --git a/austin-common/src/main/java/com/java3y/austin/pojo/vo/BasicResultVO.java b/austin-common/src/main/java/com/java3y/austin/vo/BasicResultVO.java similarity index 98% rename from austin-common/src/main/java/com/java3y/austin/pojo/vo/BasicResultVO.java rename to austin-common/src/main/java/com/java3y/austin/vo/BasicResultVO.java index 052bbff..e803ffc 100644 --- a/austin-common/src/main/java/com/java3y/austin/pojo/vo/BasicResultVO.java +++ b/austin-common/src/main/java/com/java3y/austin/vo/BasicResultVO.java @@ -1,4 +1,4 @@ -package com.java3y.austin.pojo.vo; +package com.java3y.austin.vo; import com.java3y.austin.constant.RespStatusEnum; import lombok.AllArgsConstructor; diff --git a/austin-service-api-impl/pom.xml b/austin-service-api-impl/pom.xml index cf380ff..fd4b192 100644 --- a/austin-service-api-impl/pom.xml +++ b/austin-service-api-impl/pom.xml @@ -17,5 +17,10 @@ austin-service-api 0.0.1-SNAPSHOT + + com.java3y.austin + austin-support + 0.0.1-SNAPSHOT + \ No newline at end of file diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/action/AssembleAction.java b/austin-service-api-impl/src/main/java/com/java3y/austin/action/AssembleAction.java new file mode 100644 index 0000000..e3705e7 --- /dev/null +++ b/austin-service-api-impl/src/main/java/com/java3y/austin/action/AssembleAction.java @@ -0,0 +1,17 @@ +package com.java3y.austin.action; + +import com.java3y.austin.pipeline.BusinessProcess; +import com.java3y.austin.pipeline.ProcessContext; + +/** + * @author 3y + * @date 2021/11/22 + * @description 拼装参数 + */ +public class AssembleAction implements BusinessProcess { + + @Override + public void process(ProcessContext context) { + + } +} diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/action/ParamAction.java b/austin-service-api-impl/src/main/java/com/java3y/austin/action/ParamAction.java new file mode 100644 index 0000000..842a553 --- /dev/null +++ b/austin-service-api-impl/src/main/java/com/java3y/austin/action/ParamAction.java @@ -0,0 +1,17 @@ +package com.java3y.austin.action; + +import com.java3y.austin.domain.SendTaskModel; +import com.java3y.austin.pipeline.BusinessProcess; +import com.java3y.austin.pipeline.ProcessContext; + +/** + * @author 3y + * @date 2021/11/22 + * @description 参数校验 + */ +public class ParamAction implements BusinessProcess { + @Override + public void process(ProcessContext context) { + SendTaskModel sendTaskModel = (SendTaskModel) context.getProcessModel(); + } +} diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/domain/SendTaskModel.java b/austin-service-api-impl/src/main/java/com/java3y/austin/domain/SendTaskModel.java new file mode 100644 index 0000000..960a7d3 --- /dev/null +++ b/austin-service-api-impl/src/main/java/com/java3y/austin/domain/SendTaskModel.java @@ -0,0 +1,47 @@ +package com.java3y.austin.domain; + +import com.java3y.austin.pipeline.ProcessModel; +import com.java3y.austin.pojo.TaskInfo; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.util.List; + +/** + * @author 3y + * @date 2021/11/22 + * @description 发送消息任务模型 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class SendTaskModel implements ProcessModel { + + + /** + * 请求类型 10:single 20:batch + */ + private int requestType; + + /** + * 请求参数 single 接口 + */ + private MessageParam messageParam; + + /** + * 请求参数 batch 接口 + */ + private List messageParamList; + + + /** + * 发送任务信息 + */ + private TaskInfo taskInfo; + + +} diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/enums/RequestType.java b/austin-service-api-impl/src/main/java/com/java3y/austin/enums/RequestType.java new file mode 100644 index 0000000..ac11a77 --- /dev/null +++ b/austin-service-api-impl/src/main/java/com/java3y/austin/enums/RequestType.java @@ -0,0 +1,31 @@ +package com.java3y.austin.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.ToString; + +/** + * @author 3y + * @date 2021/11/22 + * 请求类型 + */ +@Getter +@ToString +@AllArgsConstructor +public enum RequestType { + + + SINGLE(10, "请求接口为 single 类型"), + + BATCH(20, "请求接口为 batch 类型"); + + /** + * code + */ + private Integer code; + + /** + * 类型说明 + */ + private String description; +} diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/service/SendServiceImpl.java b/austin-service-api-impl/src/main/java/com/java3y/austin/service/SendServiceImpl.java index 3b1a4c3..0602fbd 100644 --- a/austin-service-api-impl/src/main/java/com/java3y/austin/service/SendServiceImpl.java +++ b/austin-service-api-impl/src/main/java/com/java3y/austin/service/SendServiceImpl.java @@ -1,20 +1,61 @@ package com.java3y.austin.service; +import com.java3y.austin.domain.BatchSendRequest; import com.java3y.austin.domain.SendRequest; import com.java3y.austin.domain.SendResponse; +import com.java3y.austin.domain.SendTaskModel; +import com.java3y.austin.enums.RequestType; +import com.java3y.austin.pipeline.ProcessContext; +import com.java3y.austin.pipeline.ProcessController; +import com.java3y.austin.pojo.TaskInfo; +import com.java3y.austin.vo.BasicResultVO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; /** * 发送接口 * @author 3y */ +@Service public class SendServiceImpl implements SendService { + + @Autowired + private ProcessController processController; + @Override public SendResponse send(SendRequest sendRequest) { - return null; + + SendTaskModel sendTaskModel = SendTaskModel.builder() + .requestType(RequestType.SINGLE.getCode()) + .messageParam(sendRequest.getMessageParam()) + .taskInfo(TaskInfo.builder().messageTemplateId(sendRequest.getMessageTemplateId()).build()) + .build(); + + ProcessContext context = ProcessContext.builder() + .code(sendRequest.getCode()) + .processModel(sendTaskModel).build(); + + ProcessContext process = processController.process(context); + + return new SendResponse(process.getResponse().getCode(), process.getResponse().getMsg()); } @Override - public SendResponse batchSend(SendRequest sendRequest) { - return null; + public SendResponse batchSend(BatchSendRequest batchSendRequest) { + SendTaskModel sendTaskModel = SendTaskModel.builder() + .requestType(RequestType.BATCH.getCode()) + .messageParamList(batchSendRequest.getMessageParamList()) + .taskInfo(TaskInfo.builder().messageTemplateId(batchSendRequest.getMessageTemplateId()).build()) + .build(); + + ProcessContext context = ProcessContext.builder() + .code(batchSendRequest.getCode()) + .processModel(sendTaskModel).build(); + + ProcessContext process = processController.process(context); + + return new SendResponse(process.getResponse().getCode(), process.getResponse().getMsg()); } + + } diff --git a/austin-service-api/pom.xml b/austin-service-api/pom.xml index d874b76..c0df95d 100644 --- a/austin-service-api/pom.xml +++ b/austin-service-api/pom.xml @@ -11,5 +11,12 @@ austin-service-api + + + com.java3y.austin + austin-common + 0.0.1-SNAPSHOT + + \ No newline at end of file diff --git a/austin-service-api/src/main/java/com/java3y/austin/domain/BatchSendRequest.java b/austin-service-api/src/main/java/com/java3y/austin/domain/BatchSendRequest.java new file mode 100644 index 0000000..aba66e0 --- /dev/null +++ b/austin-service-api/src/main/java/com/java3y/austin/domain/BatchSendRequest.java @@ -0,0 +1,37 @@ +package com.java3y.austin.domain; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.List; + +/** + * 发送接口的参数 + * batch + * + * @author 3y + */ +@Data +@Accessors(chain = true) +public class BatchSendRequest { + + + /** + * 执行业务类型 + */ + private String code; + + + /** + * 消息模板Id + */ + private Long messageTemplateId; + + + /** + * 消息相关的参数 + */ + private List messageParamList; + + +} diff --git a/austin-service-api/src/main/java/com/java3y/austin/domain/MessageParam.java b/austin-service-api/src/main/java/com/java3y/austin/domain/MessageParam.java new file mode 100644 index 0000000..8c25373 --- /dev/null +++ b/austin-service-api/src/main/java/com/java3y/austin/domain/MessageParam.java @@ -0,0 +1,31 @@ +package com.java3y.austin.domain; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Map; + +/** + * 消息参数 + * single + */ +@Data +@Accessors(chain = true) +public class MessageParam { + + /** + * @Description: 接收者 + * 多个用,逗号号分隔开 + */ + private String receiver; + + /** + * @Description: 消息内容中的可变部分 + */ + private Map variables; + + /** + * @Description: 扩展参数 + */ + private Map extra; +} diff --git a/austin-service-api/src/main/java/com/java3y/austin/domain/SendRequest.java b/austin-service-api/src/main/java/com/java3y/austin/domain/SendRequest.java index 58d9fbc..6d87e0c 100644 --- a/austin-service-api/src/main/java/com/java3y/austin/domain/SendRequest.java +++ b/austin-service-api/src/main/java/com/java3y/austin/domain/SendRequest.java @@ -1,22 +1,32 @@ package com.java3y.austin.domain; +import lombok.Data; +import lombok.experimental.Accessors; + /** * 发送接口的参数 - * + * @author 3y */ +@Data +@Accessors(chain = true) public class SendRequest { + /** + * 执行业务类型 + */ + private String code; + /** * 消息模板Id */ private Long messageTemplateId; + /** - * 接收者 - * 多个用 + * 消息相关的参数 */ - private String receiver; + private MessageParam messageParam; diff --git a/austin-service-api/src/main/java/com/java3y/austin/domain/SendResponse.java b/austin-service-api/src/main/java/com/java3y/austin/domain/SendResponse.java index 031d119..bc1f386 100644 --- a/austin-service-api/src/main/java/com/java3y/austin/domain/SendResponse.java +++ b/austin-service-api/src/main/java/com/java3y/austin/domain/SendResponse.java @@ -1,4 +1,26 @@ package com.java3y.austin.domain; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.experimental.Accessors; + + +/** + * 发送接口返回值 + * @author 3y + */ +@Data +@Accessors(chain = true) +@AllArgsConstructor public class SendResponse { + /** + * 响应状态 + */ + private String code; + + /** + * 响应编码 + */ + private String msg; + } diff --git a/austin-service-api/src/main/java/com/java3y/austin/enums/BusinessCode.java b/austin-service-api/src/main/java/com/java3y/austin/enums/BusinessCode.java new file mode 100644 index 0000000..a335521 --- /dev/null +++ b/austin-service-api/src/main/java/com/java3y/austin/enums/BusinessCode.java @@ -0,0 +1,28 @@ +package com.java3y.austin.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.ToString; + +/** + * @author 3y + * @date 2021/11/22 + */ +@Getter +@ToString +@AllArgsConstructor +public enum BusinessCode { + + COMMON_SEND("send", "普通发送"), + + RECALL_SEND("recall", "撤回消息"); + + + /** code 关联着责任链的模板 */ + private String code; + + /** 类型说明 */ + private String description; + + +} diff --git a/austin-service-api/src/main/java/com/java3y/austin/service/SendService.java b/austin-service-api/src/main/java/com/java3y/austin/service/SendService.java index 9d2f912..0b8918f 100644 --- a/austin-service-api/src/main/java/com/java3y/austin/service/SendService.java +++ b/austin-service-api/src/main/java/com/java3y/austin/service/SendService.java @@ -1,5 +1,6 @@ package com.java3y.austin.service; +import com.java3y.austin.domain.BatchSendRequest; import com.java3y.austin.domain.SendRequest; import com.java3y.austin.domain.SendResponse; @@ -11,8 +12,19 @@ import com.java3y.austin.domain.SendResponse; public interface SendService { + /** + * 单文案发送接口 + * @param sendRequest + * @return + */ SendResponse send(SendRequest sendRequest); - SendResponse batchSend(SendRequest sendRequest); + /** + * 多文案发送接口 + * @param batchSendRequest + * @return + */ + SendResponse batchSend(BatchSendRequest batchSendRequest); + } diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/BusinessProcess.java b/austin-support/src/main/java/com/java3y/austin/pipeline/BusinessProcess.java similarity index 71% rename from austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/BusinessProcess.java rename to austin-support/src/main/java/com/java3y/austin/pipeline/BusinessProcess.java index c99e99a..b8502eb 100644 --- a/austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/BusinessProcess.java +++ b/austin-support/src/main/java/com/java3y/austin/pipeline/BusinessProcess.java @@ -6,5 +6,10 @@ package com.java3y.austin.pipeline; * @author 3y */ public interface BusinessProcess { + + /** + * 真正处理逻辑 + * @param context + */ void process(ProcessContext context); } diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/ProcessContext.java b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessContext.java similarity index 55% rename from austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/ProcessContext.java rename to austin-support/src/main/java/com/java3y/austin/pipeline/ProcessContext.java index 43d1fcc..e7cf17a 100644 --- a/austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/ProcessContext.java +++ b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessContext.java @@ -1,9 +1,19 @@ package com.java3y.austin.pipeline; +import com.java3y.austin.vo.BasicResultVO; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + /** * 责任链上下文 * @author 3y */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder public class ProcessContext { /** @@ -21,4 +31,9 @@ public class ProcessContext { */ private Boolean needBreak = false; + /** + * 流程处理的结果 + */ + BasicResultVO response = BasicResultVO.success(); + } diff --git a/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessController.java b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessController.java new file mode 100644 index 0000000..97f3858 --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessController.java @@ -0,0 +1,80 @@ +package com.java3y.austin.pipeline; + + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.java3y.austin.constant.RespStatusEnum; +import com.java3y.austin.vo.BasicResultVO; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; +import java.util.Map; + +/** + * 流程控制器 + * + * @author 3y + */ +@Slf4j +public class ProcessController { + + /** + * 模板映射 + */ + private Map templateConfig = null; + + + /** + * 执行责任链 + * + * @param context + * @return 返回上下文内容 + */ + public ProcessContext process(ProcessContext context) { + + // 上下文 + if (context == null) { + context.setResponse(BasicResultVO.fail(RespStatusEnum.CONTEXT_IS_NULL)); + return context; + } + + //业务代码 + String businessCode = context.getCode(); + if (StrUtil.isBlank(businessCode)) { + context.setResponse(BasicResultVO.fail(RespStatusEnum.BUSINESS_CODE_IS_NULL)); + return context; + } + + // 执行模板 + ProcessTemplate processTemplate = templateConfig.get(businessCode); + if (processTemplate == null) { + context.setResponse(BasicResultVO.fail(RespStatusEnum.PROCESS_TEMPLATE_IS_NULL)); + return context; + } + + // 执行模板列表 + List processList = processTemplate.getProcessList(); + if (CollUtil.isEmpty(processList)) { + context.setResponse(BasicResultVO.fail(RespStatusEnum.PROCESS_LIST_IS_NULL)); + return context; + } + + //遍历某个流程节点,出现异常往外抛 + for (BusinessProcess businessProcess : processList) { + businessProcess.process(context); + if (context.getNeedBreak()) { + break; + } + } + return context; + } + + public Map getTemplateConfig() { + return templateConfig; + } + + public void setTemplateConfig(Map templateConfig) { + this.templateConfig = templateConfig; + } + +} diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/ProcessModel.java b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessModel.java similarity index 56% rename from austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/ProcessModel.java rename to austin-support/src/main/java/com/java3y/austin/pipeline/ProcessModel.java index d955a4e..9a2e2d0 100644 --- a/austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/ProcessModel.java +++ b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessModel.java @@ -1,10 +1,12 @@ package com.java3y.austin.pipeline; +import com.java3y.austin.vo.BasicResultVO; + /** * 真正存储着责任链的数据 * @author 3y */ -public class ProcessModel { +public interface ProcessModel { } diff --git a/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessResponse.java b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessResponse.java new file mode 100644 index 0000000..d8f169d --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessResponse.java @@ -0,0 +1,19 @@ +package com.java3y.austin.pipeline; + +import lombok.Builder; + +/** + * @author 3y + * @date 2021/11/22 + * @cription 流程处理的结果 + */ +@Builder +public class ProcessResponse { + + /** 返回值编码 */ + private final String code; + + /** 返回值描述 */ + private final String description; + +} diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/ProcessTemplate.java b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessTemplate.java similarity index 100% rename from austin-service-api-impl/src/main/java/com/java3y/austin/pipeline/ProcessTemplate.java rename to austin-support/src/main/java/com/java3y/austin/pipeline/ProcessTemplate.java diff --git a/austin-web/src/main/java/com/java3y/austin/controller/SendController.java b/austin-web/src/main/java/com/java3y/austin/controller/SendController.java index 6d22b3d..855529f 100644 --- a/austin-web/src/main/java/com/java3y/austin/controller/SendController.java +++ b/austin-web/src/main/java/com/java3y/austin/controller/SendController.java @@ -2,9 +2,10 @@ package com.java3y.austin.controller; import com.java3y.austin.handler.SmsHandler; import com.java3y.austin.pojo.TaskInfo; -import com.java3y.austin.pojo.vo.BasicResultVO; import java.util.Collections; import java.util.HashSet; + +import com.java3y.austin.vo.BasicResultVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;