wujianwei
2026-03-27 279366f14d6e1361b6caf7c05b74f0cea4227a36
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.ruoyi.cwgl.enums;
 
/**
 * 核算项目枚举
 * 使用位运算表示多个核算项目的组合
 * 
 * @author ruoyi
 * @date 2026-01-19
 */
public enum AccountingItemEnum {
    
    /** 现金流量项目 */
    CASH_FLOW(1, "现金流量项目"),
    
    /** 物料基本分类 */
    MATERIAL_CATEGORY(2, "物料基本分类"),
    
    /** 机构 */
    ORGANIZATION(4, "机构"),
    
    /** 操作员 */
    OPERATOR(8, "操作员"),
    
    /** 客商 */
    CUSTOMER_SUPPLIER(16, "客商"),
    
    /** 银行账户 */
    BANK_ACCOUNT(32, "银行账户"),
    
    /** 收支项目 */
    INCOME_EXPENSE(64, "收支项目"),
    
    /** 项目 */
    PROJECT(128, "项目"),
    
    /** 部门 */
    DEPARTMENT(256, "部门"),
    
    /** 业务明细 */
    BUSINESS_DETAIL(512, "业务明细"),
    
    /** 金融工具辅助 */
    FINANCIAL_TOOL(1024, "金融工具辅助"),
    
    /** 业务类别 */
    BUSINESS_CATEGORY(2048, "业务类别"),
    
    /** 集团内外部 */
    GROUP_INTERNAL_EXTERNAL(4096, "集团内外部"),
    
    /** 银行类别 */
    BANK_CATEGORY(8192, "银行类别"),
    
    /** 现金账户 */
    CASH_ACCOUNT(16384, "现金账户"),
    
    /** 职工类型 */
    EMPLOYEE_TYPE(32768, "职工类型");
 
    private final int value;
    private final String description;
 
    AccountingItemEnum(int value, String description) {
        this.value = value;
        this.description = description;
    }
 
    public int getValue() {
        return value;
    }
 
    public String getDescription() {
        return description;
    }
 
    /**
     * 根据值获取枚举
     */
    public static AccountingItemEnum getByValue(int value) {
        for (AccountingItemEnum item : AccountingItemEnum.values()) {
            if (item.getValue() == value) {
                return item;
            }
        }
        return null;
    }
 
    /**
     * 检查是否包含某个项目
     */
    public static boolean contains(int totalValue, AccountingItemEnum item) {
        return (totalValue & item.getValue()) != 0;
    }
 
    /**
     * 添加项目到总和中
     */
    public static int addItem(int totalValue, AccountingItemEnum item) {
        return totalValue | item.getValue();
    }
 
    /**
     * 从总和中移除项目
     */
    public static int removeItem(int totalValue, AccountingItemEnum item) {
        return totalValue & ~item.getValue();
    }
 
    /**
     * 获取所有项目的描述字符串
     */
    public static String getDescriptions(int totalValue) {
        StringBuilder sb = new StringBuilder();
        for (AccountingItemEnum item : AccountingItemEnum.values()) {
            if (contains(totalValue, item)) {
                if (sb.length() > 0) {
                    sb.append(",");
                }
                sb.append(item.getDescription());
            }
        }
        return sb.toString();
    }
 
    /**
     * 根据描述字符串获取值
     */
    public static int getValueByDescriptions(String descriptions) {
        if (descriptions == null || descriptions.trim().isEmpty()) {
            return 0;
        }
        
        int totalValue = 0;
        String[] descArray = descriptions.split(",");
        for (String desc : descArray) {
            String trimmedDesc = desc.trim();
            for (AccountingItemEnum item : AccountingItemEnum.values()) {
                if (item.getDescription().equals(trimmedDesc)) {
                    totalValue = addItem(totalValue, item);
                    break;
                }
            }
        }
        return totalValue;
    }
}