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