对接第三方枚举的转换(抖音团购)

已优化点:

info、code需要注释

方法调用不得违反得墨忒耳定律

方法应该只有一个退出口

匹配到结果后立即退出循环

public enum DyProductType {

    /**
     * 团购类型
     */
    GROUPON("1","团购"),
    /**
     * 代金券类型
     */
    VOUCHER("2","代金券"),
    /**
     * 次卡类型
     */
    TIMES_CARD("3","次卡"),
    /**
     * 储值卡类型
     */
    STORE_MONEY_CARD("4","储值卡"),
    /**
     * 周期卡类型
     */
    PERIOD_CARD("5","周期卡"),
    /**
     * 预约品类型
     */
    APPOINTMENT("6","预约品"),
    /**
     * 提货券类型
     */
    RETAIL_PICK_UP("7","提货券");

    /**
     * @param  枚举编码
     */
    private  String code;
    /**
     * @param  枚举信息
     */
    private  String info;

    DyProductType(String code, String info) {
        this.code = code;
        this.info = info;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    /**
     * @description: 根据枚举信息获取枚举编码
     * @author: ***
     * @date: 2025/3/10 9:22
     * @param: [info]
     * @return: java.lang.String
     **/
    public static String getCodeByInfo(String info){
        String result = null;
        for (DyProductType type : DyProductType.values()){
            if (info.equals(type.info)){
                result = type.getCode();
                break;
            }
        }
        return result;
    }

    /**
     * @description: 根据枚举编码获取枚举信息
     * @author: ***
     * @date: 2025/3/10 9:22
     * @param: [info]
     * @return: java.lang.String
     **/
    public static String getInfoByCode(String code){
        String result = null;
        for (DyProductType type : DyProductType.values()){
            if (code.equals(type.code)){
                result = type.getInfo();
                break;
            }
        }
        return result;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值