# AreaEnum.java

    package cloud.wconnect.workperformance.cons.monthlyreport;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import lombok.AllArgsConstructor;
    import lombok.Getter;

    import java.text.MessageFormat;
    import java.util.Arrays;
    import java.util.Optional;

    /**
     * 区域枚举类
     *
     * @author lichen
     * @date 2023/9/1
     */
    @Getter
    @AllArgsConstructor
    public enum AreaEnum {

        /**
         * 收入区域
         */
        ROOM_REVENUE(1, 1, "Room Revenue", "roomRevenueServiceImpl", "roomRevenueServiceImpl", "roomRevenueServiceImpl"),
        /**
         * 利润区域
         */
        PROFIT(2, 2, "Profit", "profitServiceImpl", "profitServiceImpl", "profitServiceImpl"),
        /**
         * 市场营销组合区域
         */
        MARKET_MIX(3, 3, "Market Mix", "marketSegmentServiceImpl", null, null),
        /**
         * 预测区域
         */
        FORECAST(4, 4, "Forecast", "forecastServiceImpl", "forecastServiceImpl", "forecastServiceImpl"),
        /**
         * STR报告区域
         */
        STR_REPORT(5, 5, "STR Report", null, null, null),
        /**
         * Support Team报告区域
         */
        SUPPORT_TEAM_REPORT(6, 7, "Support Team Report", null, null, null),
        /**
         * 客户满意度区域
         */
        CUSTOMER_SATISFACTION(7, 8, "Customer Satisfaction", "customerSatisfactionServiceImpl,customerScoreServiceImpl", null, null),
        /**
         * 报销费用区域
         */
        EXPENSES(8, 9, "EXPENSES", "expenseServiceImpl,expenseCategoryServiceImpl,expenseCategoryItemServiceImpl", "expenseCategoryServiceImpl", "expenseCategoryServiceImpl,expenseCategoryItemServiceImpl"),
        /**
         * 售罄管理区域
         */
        SOLD_OUT_MANAGEMENT(9, 10, "Sold Out Management", "soldOutManagementServiceImpl", null, null),
        /**
         * 行动计划区域
         */
        ACTION_PLANS(10, 11, "Action Plans", "actionPlanServiceImpl", "actionPlanServiceImpl", "actionPlanServiceImpl"),
        /**
         * 经理评分区域
         */
        MANAGERS_SCORECARD(11, 12, "Managers’ Scorecard", null, null, null),
        /**
         * Weekly Sales Plan
         */
        WEEKLY_SALES_PLAN(12, 6, "Weekly Sales Plan", "monthlyReportWeeklySalesPlanServiceImpl", "monthlyReportWeeklySalesPlanServiceImpl", null);

        /**
         * 区域id
         */
        private int areaId;

        /**
         * 详情页面显示顺序
         */
        private int sort;

        /**
         * 描述
         */
        private String desc;

        /**
         * 删除区域数据的业务层集合，多个用,分隔
         * 当资产关闭某一区域时,加载这些业务层执行删除区域数据
         */
        private String delServiceImpls;

        /**
         * 新增区域时，需要初始化区域数据的业务层，多个用,分隔
         */
        private String initAreaServiceImpl;

        /**
         * 需要处理分类数据的业务层，多个用,分隔
         * 当前删除分类，修改分类时，加载这些业务层做对应的逻辑处理
         */
        private String handleCategoryServiceImpls;

        /**
         * 获取区域描述
         *
         * @param areaId 区域id
         * @return java.lang.String
         * @author lichen
         * @date 2023/9/2
         */
        public static String getDesc(int areaId) {
            Optional<AreaEnum> optional = Arrays.stream(AreaEnum.values()).filter(areaEnum -> areaEnum.getAreaId() == areaId).findFirst();
            return optional.isPresent() ? optional.get().getDesc() : "";
        }

        /**
         * 获取区域 处理分类业务实现类
         *
         * @param areaId 区域id
         * @return java.lang.String
         * @author lichen
         * @date 2023/9/6
         */
        public static String getHandleCategoryServiceImpls(int areaId) {
            Optional<AreaEnum> optional = Arrays.stream(AreaEnum.values()).filter(areaEnum -> areaEnum.getAreaId() == areaId).findFirst();
            return optional.isPresent() ? optional.get().getHandleCategoryServiceImpls() : "";
        }

        /**
         * 校验区域id是否合法
         *
         * @param areaId 区域id
         * @return void
         * @author lichen
         * @date 2023/9/6
         */
        public static void verifyValidity(int areaId) {
            Optional<AreaEnum> optional = Arrays.stream(AreaEnum.values()).filter(areaEnum -> areaEnum.getAreaId() == areaId).findFirst();
            if (optional.isEmpty()) {
                throw new BadRequestException(BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getI18nCode(), BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        MessageFormat.format("The area id is invalid, areaId:{0}", areaId));
            }
        }

        /**
         * 根据区域id获取排序sort
         *
         * @param areaId 区域id
         * @return int
         * @author lichen
         * @date 2024/12/9
         */
        public static int getSort(int areaId) {
            Optional<AreaEnum> optional = Arrays.stream(AreaEnum.values()).filter(areaEnum -> areaEnum.getAreaId() == areaId).findFirst();
            if (optional.isEmpty()) {
                throw new BadRequestException(BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getI18nCode(), BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        MessageFormat.format("The area id is invalid, areaId:{0}", areaId));
            }
            return optional.get().getSort();
        }
    }