package com.dy.pmsGlobal.util; public enum DeviceResult { PASS(1, "通过"), TEST_PASS(2, "测试通过"), INSPECTION_PASS(3, "品检通过"), REPAIR_PASS(4, "维修通过"), TEST_FAIL(5, "测试不通过"), INSPECTION_FAIL(6, "品检不通过"), WASTE(7, "报废"); private final int code; private final String description; DeviceResult(int code, String description) { this.code = code; this.description = description; } public int getCode() { return code; } public String getDescription() { return description; } // 根据code值获取对应的枚举值 public static DeviceResult fromCode(int code) { for (DeviceResult result : values()) { if (result.code == code) { return result; } } throw new IllegalArgumentException("未知的枚举code: " + code); } }