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 java.math.BigDecimal;
019import java.util.Objects;
020
021/**
022 * 协作类型
023 * APPROVAL-无:无其他协作方式
024 * TRANSFER-转办:任务转给其他人办理
025 * DEPUTE-委派:求助其他人审批,然后参照他的意见决定是否审批通过
026 * COUNTERSIGN-会签:和其他人一起审批通过,才算通过
027 * VOTE-票签:和部分人一起审批,达到一定通过率,才算通过
028 * ADD_SIGNATURE-加签:办理中途,希望其他人一起参与办理
029 * REDUCTION_SIGNATURE-减签:办理中途,希望某些人不参与办理
030 *
031 * @author xiarg
032 * @since 2024/5/10 16:04
033 */
034public enum CooperateType {
035
036    APPROVAL(1, "无"),
037    TRANSFER(2, "转办"),
038    DEPUTE(3, "委派"),
039    COUNTERSIGN(4, "会签"),
040    VOTE(5, "票签"),
041    ADD_SIGNATURE(6, "加签"),
042    REDUCTION_SIGNATURE(7, "减签");
043
044    private Integer key;
045    private String value;
046
047    CooperateType(Integer key, String value) {
048        this.key = key;
049        this.value = value;
050    }
051
052    public static Integer getKeyByValue(String value) {
053        for (CooperateType item : CooperateType.values()) {
054            if (item.getValue().equals(value)) {
055                return item.getKey();
056            }
057        }
058        return null;
059    }
060
061    public static String getValueByKey(Integer key) {
062        for (CooperateType item : CooperateType.values()) {
063            if (item.getKey().equals(key)) {
064                return item.getValue();
065            }
066        }
067        return null;
068    }
069
070    public static CooperateType getByKey(Integer key) {
071        for (CooperateType item : CooperateType.values()) {
072            if (item.getKey().equals(key)) {
073                return item;
074            }
075        }
076        return null;
077    }
078
079
080    public Integer getKey() {
081        return key;
082    }
083
084    public String getValue() {
085        return value;
086    }
087
088
089    public final static BigDecimal ONE_HUNDRED = BigDecimal.valueOf(100);
090
091    /**
092     * 判断是否为或签
093     *
094     * @param
095     * @return
096     */
097    public static boolean isOrSign(BigDecimal ratio) {
098        if (Objects.isNull(ratio) || ratio.compareTo(BigDecimal.ZERO) <= 0) {
099            return true;
100        }
101        return false;
102    }
103
104
105    /**
106     * 判断是否是票签
107     *
108     * @param
109     * @return
110     */
111    public static boolean isVoteSign(BigDecimal ratio) {
112        if (Objects.nonNull(ratio) && ratio.compareTo(BigDecimal.ZERO) > 0 && ratio.compareTo(ONE_HUNDRED) < 0) {
113            return true;
114        }
115        return false;
116    }
117
118    /**
119     * 判断是否是会签
120     *
121     * @param
122     * @return
123     */
124    public static boolean isCountersign(BigDecimal ratio) {
125        if (Objects.nonNull(ratio) && ratio.compareTo(ONE_HUNDRED) >= 0) {
126            return true;
127        }
128        return false;
129    }
130
131}