Java 枚举类型的用法

public static enum VST_CATEGORY {
        CATEGORY_HOTEL("0", "1", "酒店", 7),
        CATEGORY_FINANCE("0", "33", "金融", 7),//合规权益产品
        CATEGORY_CRUISE("0", "2", "邮轮", 7),
        CATEGORY_INSURANCE("0", "3", "保险", 0),
        CATEGORY_VISA("0", "4", "签证", 7),
        CATEGORY_TICKET("0", "5", "景点门票 ", 7),
        CATEGORY_COMB("0", "6", "组合产品", 7),
        CATEGORY_ADDITION("0", "7", "附加项目", 7),
        //邮轮组合产品作为邮轮的子类,这里与vst不同
        CATEGORY_COMB_CRUISE("2", "8", "邮轮组合产品", 7),
        CATEGORY_SIGHTSEEING("7", "9", "岸上观光", 7),
        CATEGORY_CRUISE_ADDITION("7", "10", "邮轮附加项", 7),
        CATEGORY_SINGLE_TICKET("5", "11", "景区门票", 7),
        CATEGORY_OTHER_TICKET("5", "12", "其它票", 7),
        CATEGORY_COMB_TICKET("5", "13", "组合套餐票", 7),
        CATEGORY_ROUTE("0", "14", "线路", 7),
        CATEGORY_ROUTE_NEW_HOTELCOMB("14", "32", "酒套餐", 7),
        CATEGORY_ROUTE_GROUP("14", "15", "跟团游", 7),
        CATEGORY_ROUTE_LOCAL("14", "16", "当地游", 7),
        CATEGORY_ROUTE_HOTELCOMB("14", "17", "酒店套餐", 7),
        CATEGORY_ROUTE_FREEDOM("14", "18", "自由行", 7),
        CATEGORY_ROUTE_AERO_HOTEL("14", "29", "交通+X", 7),
        CATEGORY_ROUTE_CUSTOMIZED("14", "42", "定制游", 15),

        CATEGORY_OTHER("0", "90", "其它", 7),
        CATEGORY_TRAFFIC_AEROPLANE("19", "20", "机票", 7),
        CATEGORY_TRAFFIC_AERO_OTHER("19", "21", "其它机票", 7),
        CATEGORY_TRAFFIC_TRAIN("19", "22", "火车票", 7),
        CATEGORY_TRAFFIC_TRAIN_OTHER("19", "23", "其它火车票", 7),
        CATEGORY_TRAFFIC_BUS("19", "24", "巴士", 7),
        CATEGORY_TRAFFIC_BUS_OTHER("19", "25", "其它巴士", 7),
        CATEGORY_TRAFFIC_SHIP("19", "26", "船票", 7),
        CATEGORY_TRAFFIC_SHIP_OTHER("19", "27", "其它船票", 7),

        CATEGORY_WIFI("0", "28", "WIFI/电话卡", 7),
        CATEGORY_LOCAL_PLAY("0", "30", "当地玩乐", 7),
        CATEGORY_SHOW_TICKET("30", "31", "演出票", 7),
        CATEGORY_CONNECTS("30", "41", "交通接驳", 7),
        CATEGORY_FOOD("30", "43", "美食", 7),
        CATEGORY_SPORT("30", "44", "娱乐", 7),
        CATEGORY_SHOP("30", "45", "购物", 7),
        CATEGORY_PRESALE("0", "99", "预售", 7);

        private String fathercategoryId;
        private String categoryId;
        private String cnName;
        private int clearDay;  //产品支付后距离清分天数

        VST_CATEGORY(String fathercategoryId, String categoryId, String cnName, int clearDay) {
            this.fathercategoryId = fathercategoryId;
            this.categoryId = categoryId;
            this.cnName = cnName;
            this.clearDay = clearDay;
        }

        public String getCode() {
            return this.name();
        }

        public String getFathercategoryId() {
            return this.fathercategoryId;
        }

        public String getCategoryId() {
            return this.categoryId;
        }

        public String getCnName() {
            return this.cnName;
        }

        public int getClearDay() {
            return clearDay;
        }

        public void setClearDay(int clearDay) {
            this.clearDay = clearDay;
        }

        public static String getCnNameByCode(String code) {
            for (VST_CATEGORY item : VST_CATEGORY.values()) {
                if (item.getCode().equals(code)) {
                    return item.getCnName();
                }
            }
            return code;
        }

        public static String getCategoryIdByCode(String code) {
            for (VST_CATEGORY item : VST_CATEGORY.values()) {
                if (item.getCode().equals(code)) {
                    return item.categoryId;
                }
            }
            return null;
        }

        public static String getCnNameByStatus(String categoryId) {
            for (VST_CATEGORY item : VST_CATEGORY.values()) {
                if (item.categoryId.equals(categoryId)) {
                    return item.getCnName();
                }
            }
            return categoryId;
        }

        public static String getCodeByCategoryId(String categoryId) {
            for (VST_CATEGORY item : VST_CATEGORY.values()) {
                if (item.categoryId.equals(categoryId)) {
                    return item.name();
                }
            }
            return null;
        }

        public static String getfatherCategoryCode(String code) {
            for (VST_CATEGORY item : VST_CATEGORY.values()) {
                if (item.getCode().equals(code)) {
                    if (item.fathercategoryId.equals("0")) {
                        return item.getCode();
                    }
                    for (VST_CATEGORY itemf : VST_CATEGORY.values()) {
                        if (itemf.categoryId.equals(item.fathercategoryId)) {
                            return itemf.getCode();
                        }
                    }
                }
            }
            return code;
        }

        public static String getCodeListByCategoryId(String categoryId) {
            StringBuffer sb = new StringBuffer();
            for (VST_CATEGORY item : VST_CATEGORY.values()) {
                if (item.fathercategoryId.equals(categoryId)) {
                    sb.append(item.getCode()).append(",");
                }
            }

            return sb.toString();
        }

        public static String getCodeByCNname(String cnName) {
            for (VST_CATEGORY item : VST_CATEGORY.values()) {
                if (item.cnName.equals(cnName)) {
                    return item.getCode();
                }
            }
            return null;
        }

        @Override
        public String toString() {
            return this.name();
        }

        public static int getClearDayCategoryId(String categoryId) {
            for (VST_CATEGORY item : VST_CATEGORY.values()) {
                if (item.categoryId.equals(categoryId)) {
                    return item.getClearDay();
                }
            }
            return 7;
        }

        public static String getfatherCategoryId(String categoryId){
            for (VST_CATEGORY item : VST_CATEGORY.values()) {
                if (item.categoryId.equals(categoryId)) {
                    return item.fathercategoryId;
                }
            }
            return categoryId;
        }
    }

  

posted on 2018-08-22 17:12  成功没有捷径  阅读(244)  评论(0编辑  收藏  举报