gaoluyang
昨天 90b3ad820eea45d021835197eac5bc3ad55b12ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cn.iocoder.yudao.module.finance.enums;
 
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
 
import java.math.BigDecimal;
import java.util.Arrays;
 
/**
 * 会计科目余额方向枚举
 *
 * @author 超级管理员
 */
@RequiredArgsConstructor
@Getter
public enum FinBalanceDirectionEnum implements ArrayValuable<Integer> {
 
    DEBIT(1, "借"),
    CREDIT(2, "贷");
 
    public static final Integer[] ARRAYS = Arrays.stream(values()).map(FinBalanceDirectionEnum::getDirection).toArray(Integer[]::new);
 
    /**
     * 方向
     */
    private final Integer direction;
    /**
     * 方向名
     */
    private final String name;
 
    @Override
    public Integer[] array() {
        return ARRAYS;
    }
 
    /**
     * 根据余额(借方为正、贷方为负)判断余额方向
     *
     * @param balance 余额,允许为空(按 0 处理)
     * @return 余额方向
     */
    public static Integer getByBalance(BigDecimal balance) {
        return balance != null && balance.compareTo(BigDecimal.ZERO) < 0
                ? CREDIT.getDirection() : DEBIT.getDirection();
    }
 
}