001/*
002 *    Copyright 2024-2025, Warm-Flow (290631660@qq.com).
003 *
004 *    Licensed under the Apache License, Version 2.0 (the "License");
005 *    you may not use this file except in compliance with the License.
006 *    You may obtain a copy of the License at
007 *
008 *       https://www.apache.org/licenses/LICENSE-2.0
009 *
010 *    Unless required by applicable law or agreed to in writing, software
011 *    distributed under the License is distributed on an "AS IS" BASIS,
012 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *    See the License for the specific language governing permissions and
014 *    limitations under the License.
015 */
016package org.dromara.warm.flow.core.enums;
017
018import org.dromara.warm.flow.core.utils.ObjectUtil;
019
020/**
021 * 流程状态
022 *
023 * @author warm
024 * @since 2023/3/31 12:16
025 */
026public enum FlowStatus {
027    TOBESUBMIT("0", "待提交"),
028
029    APPROVAL("1", "审批中"),
030
031    PASS("2", "审批通过"),
032
033    AUTO_PASS("3", "自动完成"),
034
035    TERMINATE("4", "终止"),
036
037    NULLIFY("5", "作废"),
038
039    CANCEL("6", "撤销"),
040
041    RETRIEVE("7", "取回"),
042
043    FINISHED("8", "已完成"),
044
045    REJECT("9", "已退回"),
046
047    INVALID("10", "失效");
048
049    private String key;
050    private String value;
051
052    FlowStatus(String key, String value) {
053        this.key = key;
054        this.value = value;
055    }
056
057    public static String getKeyByValue(String value) {
058        for (FlowStatus item : FlowStatus.values()) {
059            if (item.getValue().equals(value)) {
060                return item.getKey();
061            }
062        }
063        return null;
064    }
065
066    public static String getValueByKey(String key) {
067        for (FlowStatus item : FlowStatus.values()) {
068            if (item.getKey().equals(key)) {
069                return item.getValue();
070            }
071        }
072        return null;
073    }
074
075    public static FlowStatus getByKey(String key) {
076        for (FlowStatus item : FlowStatus.values()) {
077            if (item.getKey().equals(key)) {
078                return item;
079            }
080        }
081        return null;
082    }
083
084    /**
085     * 判断是否结束节点
086     *
087     * @param Key
088     * @return
089     */
090    public static Boolean isFinished(String Key) {
091        return ObjectUtil.isNotNull(Key) && (FlowStatus.FINISHED.getKey().equals(Key));
092    }
093
094    public String getKey() {
095        return key;
096    }
097
098    public String getValue() {
099        return value;
100    }
101}