模版编制的相关实现
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package com.zt.plat.module.tmpltp.enums;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public enum DeleteStatusEnum {
|
||||
|
||||
STATUS_DRF(TmplStsEnum.DRAFT.getCode(), new HashSet<>() {{add(TmplStsEnum.STOPPED.getCode());}}),
|
||||
STATUS_PUB(TmplStsEnum.PUBLISHED.getCode(), new HashSet<>()),
|
||||
STATUS_STOP(TmplStsEnum.STOPPED.getCode(), new HashSet<>());
|
||||
|
||||
|
||||
private final String code;
|
||||
private final Set<String> allowedTransitions;
|
||||
|
||||
DeleteStatusEnum(String code, Set<String> allowedTransitions) {
|
||||
this.code = code;
|
||||
this.allowedTransitions = allowedTransitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态码获取对应的枚举实例
|
||||
*/
|
||||
public static DeleteStatusEnum fromCode(String code) {
|
||||
for (DeleteStatusEnum status : values()) {
|
||||
if (status.code.equals(code)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验状态转换是否合法
|
||||
*/
|
||||
public boolean isTransitionAllowed(String targetStatus) {
|
||||
return allowedTransitions.contains(targetStatus);
|
||||
}
|
||||
}
|
||||
@@ -14,14 +14,15 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode TMPL_TP_DEl_ERROR = new ErrorCode(1_027_000_507, "模版分类删除失败");
|
||||
ErrorCode TEMPLATE_INSTANCE_DATA_NOT_EXISTS = new ErrorCode(1_027_000_508, "实例字段值不存在");
|
||||
ErrorCode TEMPLATE_INSTANCE_ITEM_NOT_EXISTS = new ErrorCode(1_027_000_509, "实例条款值不存在");
|
||||
ErrorCode TEMPLATE_INSTANCE_CREATE_FAIL = new ErrorCode(1_027_000_510, "实例创建失败");
|
||||
ErrorCode PARAMS_IS_NULL_OR_ERR = new ErrorCode(1_027_000_510, "参数为空或参数错误");
|
||||
ErrorCode DEPARTMENT_INSTANCE_RELATIVITY_NOT_EXISTS = new ErrorCode(1_027_000_511, "部门与实例关联不存在");
|
||||
ErrorCode ILLEGAL_OPERATION_TYPE = new ErrorCode(1_027_000_511, "非法操作类型");
|
||||
ErrorCode OPERATION_FAIL= new ErrorCode(1_027_000_512, "操作失败");
|
||||
ErrorCode STATUS_OPERATION_FAIL= new ErrorCode(1_027_000_513, "当前状态不支持此操作");
|
||||
ErrorCode NOT_FOUND_CLASS= new ErrorCode(1_027_000_514, "找不到对应的类");
|
||||
ErrorCode UTIL_NOT_INIT= new ErrorCode(1_027_000_515, "工具类为未初始化");
|
||||
ErrorCode TMPL_INS_FLD_CODE_EXISTS = new ErrorCode(1_027_000_516, "字段已存在");
|
||||
ErrorCode DEPARTMENT_INSTANCE_RELATIVITY_NOT_EXISTS = new ErrorCode(1_027_000_512, "部门与实例关联不存在");
|
||||
ErrorCode ILLEGAL_OPERATION_TYPE = new ErrorCode(1_027_000_513, "非法操作类型");
|
||||
ErrorCode OPERATION_FAIL= new ErrorCode(1_027_000_514, "操作失败");
|
||||
ErrorCode STATUS_OPERATION_FAIL= new ErrorCode(1_027_000_515, "当前状态不支持此操作");
|
||||
ErrorCode NOT_FOUND_CLASS= new ErrorCode(1_027_000_516, "找不到对应的类");
|
||||
ErrorCode UTIL_NOT_INIT= new ErrorCode(1_027_000_517, "工具类为未初始化");
|
||||
ErrorCode TMPL_INS_FLD_CODE_EXISTS = new ErrorCode(1_027_000_518, "字段已存在");
|
||||
//Illegal operation type
|
||||
}
|
||||
|
||||
|
||||
@@ -6,25 +6,23 @@ import java.util.Set;
|
||||
/**
|
||||
* 状态枚举类,定义所有可能的状态及合法的状态转换
|
||||
*/
|
||||
public enum StatusEnum {
|
||||
// 定义所有状态及对应的合法转换目标状态
|
||||
STATUS_1("1", new HashSet<String>() {{
|
||||
add("2");
|
||||
add("4");
|
||||
public enum PublishStatusEnum {
|
||||
|
||||
STATUS_DRF(TmplStsEnum.DRAFT.getCode(), new HashSet<>() {{
|
||||
add(TmplStsEnum.DRAFT.getCode());
|
||||
add(TmplStsEnum.STOPPED.getCode());
|
||||
}}),
|
||||
STATUS_2("2", new HashSet<String>() {{
|
||||
add("3");
|
||||
}}),
|
||||
STATUS_3("3", new HashSet<String>() {{
|
||||
add("4");
|
||||
add("2");
|
||||
}}),
|
||||
STATUS_4("4", new HashSet<>()); // 没有合法的转换目标
|
||||
STATUS_PUB(TmplStsEnum.PUBLISHED.getCode(), new HashSet<>()),
|
||||
STATUS_STOP(TmplStsEnum.STOPPED.getCode(), new HashSet<>() {{
|
||||
add(TmplStsEnum.DRAFT.getCode());
|
||||
add(TmplStsEnum.STOPPED.getCode());
|
||||
}});
|
||||
|
||||
|
||||
private final String code;
|
||||
private final Set<String> allowedTransitions;
|
||||
|
||||
StatusEnum(String code, Set<String> allowedTransitions) {
|
||||
PublishStatusEnum(String code, Set<String> allowedTransitions) {
|
||||
this.code = code;
|
||||
this.allowedTransitions = allowedTransitions;
|
||||
}
|
||||
@@ -32,8 +30,8 @@ public enum StatusEnum {
|
||||
/**
|
||||
* 根据状态码获取对应的枚举实例
|
||||
*/
|
||||
public static StatusEnum fromCode(String code) {
|
||||
for (StatusEnum status : values()) {
|
||||
public static PublishStatusEnum fromCode(String code) {
|
||||
for (PublishStatusEnum status : values()) {
|
||||
if (status.code.equals(code)) {
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.zt.plat.module.tmpltp.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum TmplStsEnum {
|
||||
// 草稿状态
|
||||
DRAFT("DRF", "草稿"),
|
||||
// 已发布状态
|
||||
PUBLISHED("PUB", "已发布"),
|
||||
// 已停用状态
|
||||
STOPPED("STOP", "已停用");
|
||||
|
||||
// 获取状态编码
|
||||
private final String code;
|
||||
// 获取状态描述
|
||||
private final String description;
|
||||
|
||||
// 构造方法
|
||||
TmplStsEnum(String code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
// 根据编码获取枚举实例
|
||||
public static TmplStsEnum getByCode(String code) {
|
||||
for (TmplStsEnum status : TmplStsEnum.values()) {
|
||||
if (status.getCode().equals(code)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.zt.plat.module.tmpltp.enums;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public enum UpdateStatusEnum {
|
||||
|
||||
STATUS_DRF(TmplStsEnum.DRAFT.getCode(), new HashSet<>() {{add(TmplStsEnum.DRAFT.getCode());}}),
|
||||
STATUS_PUB(TmplStsEnum.PUBLISHED.getCode(), new HashSet<>()),
|
||||
STATUS_STOP(TmplStsEnum.STOPPED.getCode(), new HashSet<>());
|
||||
|
||||
|
||||
private final String code;
|
||||
private final Set<String> allowedTransitions;
|
||||
|
||||
UpdateStatusEnum(String code, Set<String> allowedTransitions) {
|
||||
this.code = code;
|
||||
this.allowedTransitions = allowedTransitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态码获取对应的枚举实例
|
||||
*/
|
||||
public static UpdateStatusEnum fromCode(String code) {
|
||||
for (UpdateStatusEnum status : values()) {
|
||||
if (status.code.equals(code)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验状态转换是否合法
|
||||
*/
|
||||
public boolean isTransitionAllowed(String targetStatus) {
|
||||
return allowedTransitions.contains(targetStatus);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user