| | |
| | | import lombok.Getter; |
| | | |
| | | import java.math.BigDecimal; |
| | | //商品星级 |
| | | @Getter |
| | | public enum StarRatingEnum { |
| | | /** |
| | | * 定级规则 |
| | | * 大于最小值,小于等于最大值 |
| | | */ |
| | | NORMAL("普通",0,30), |
| | | ONE_STAR("一星",30,50), |
| | | TWO_STAR("二星",50,100), |
| | | THREE_STAR("三星",100,200); |
| | | NORMAL("普通",0,30,1), |
| | | ONE_STAR("一星",30,50,2), |
| | | TWO_STAR("二星",50,100,3), |
| | | THREE_STAR("三星",100,200,4); |
| | | |
| | | private String name; |
| | | |
| | |
| | | |
| | | private Integer maxValue; |
| | | |
| | | StarRatingEnum(String name,Integer minValue, Integer maxValue) { |
| | | private Integer code; |
| | | |
| | | StarRatingEnum(String name,Integer minValue, Integer maxValue,Integer code) { |
| | | this.name = name; |
| | | this.minValue = minValue; |
| | | this.maxValue = maxValue; |
| | | this.code = code; |
| | | } |
| | | |
| | | /** |
| | |
| | | return name; |
| | | } |
| | | |
| | | /** |
| | | * 根据输入的商品星级获取对应的Code |
| | | * @param name |
| | | * @return |
| | | */ |
| | | public Integer getGoodsStarCode(String name){ |
| | | Integer code = 0; |
| | | for(StarRatingEnum starRatingEnum : StarRatingEnum.values()){ |
| | | if(starRatingEnum.name.equals(name)){ |
| | | code = starRatingEnum.code; |
| | | } |
| | | } |
| | | return code; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String s = StarRatingEnum.NORMAL.belongStarRating(String.valueOf(100)); |
| | | System.out.println(s); |