pipeline code

pull/2/head
3y 3 years ago
parent eb7ed0d148
commit 7c1feb607d

@ -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","业务处理器配置为空" ),
;
/**

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}

@ -1,4 +1,4 @@
package com.java3y.austin.pojo.vo;
package com.java3y.austin.vo;
import com.java3y.austin.constant.RespStatusEnum;
import lombok.AllArgsConstructor;

@ -17,5 +17,10 @@
<artifactId>austin-service-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.java3y.austin</groupId>
<artifactId>austin-support</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

@ -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) {
}
}

@ -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();
}
}

@ -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<MessageParam> messageParamList;
/**
*
*/
private TaskInfo taskInfo;
}

@ -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;
}

@ -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());
}
}

@ -11,5 +11,12 @@
<artifactId>austin-service-api</artifactId>
<dependencies>
<dependency>
<groupId>com.java3y.austin</groupId>
<artifactId>austin-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

@ -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<MessageParam> messageParamList;
}

@ -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<String, String> variables;
/**
* @Description:
*/
private Map<String,String> extra;
}

@ -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;

@ -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;
}

@ -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;
}

@ -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);
}

@ -6,5 +6,10 @@ package com.java3y.austin.pipeline;
* @author 3y
*/
public interface BusinessProcess {
/**
*
* @param context
*/
void process(ProcessContext context);
}

@ -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();
}

@ -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<String, ProcessTemplate> 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<BusinessProcess> 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<String, ProcessTemplate> getTemplateConfig() {
return templateConfig;
}
public void setTemplateConfig(Map<String, ProcessTemplate> templateConfig) {
this.templateConfig = templateConfig;
}
}

@ -1,10 +1,12 @@
package com.java3y.austin.pipeline;
import com.java3y.austin.vo.BasicResultVO;
/**
*
* @author 3y
*/
public class ProcessModel {
public interface ProcessModel {
}

@ -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;
}

@ -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;

Loading…
Cancel
Save