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