Преглед на файлове

添加人员的枚举值

konghl преди 4 години
родител
ревизия
b8a06cf6e6
променени са 1 файла, в които са добавени 172 реда и са изтрити 150 реда
  1. 172 150
      ebc-sea-platform/src/main/java/com/ai/ipu/server/enums/UserEnums.java

+ 172 - 150
ebc-sea-platform/src/main/java/com/ai/ipu/server/enums/UserEnums.java

@ -10,155 +10,177 @@ import java.util.Map;
10 10
11 11
import org.springframework.util.ReflectionUtils;
12 12
13
14 13
public enum UserEnums {
15
    oneUser(1, "张三", "1111", "搜救", "经理"),
16
    twoUser(2, "李四", "2222", "搜救", "员工"),
17
    threeUser(3, "王五", "3333", "搜救", "员工"),
18
    fiveUser(4, "赵六", "4444", "搜救", "员工"),
19
    sixUser(5, "田七", "5555", "搜救", "员工");
20
    public int id; //id
21
    public String userName;//姓名
22
    public String employeeNo;//员工编号
23
    public String department;//部门
24
    public String duty;//职务
25
26
    UserEnums() {
27
    }
28
29
    UserEnums(int id, String userName, String employeeNo, String department, String duty) {
30
        this.id = id;
31
        this.userName = userName;
32
        this.employeeNo = employeeNo;
33
        this.department = department;
34
        this.duty = duty;
35
    }
36
37
    public int getId() {
38
        return id;
39
    }
40
41
    public String getUserName() {
42
        return userName;
43
    }
44
45
    public String getEmployeeNo() {
46
        return employeeNo;
47
    }
48
49
    public String getDepartment() {
50
        return department;
51
    }
52
53
    public String getDuty() {
54
        return duty;
55
    }
56
57
    /**
58
     * 根据id返回枚举值
59
     * @param id
60
     * @return
61
     */
62
    public static UserEnums   getEumByid(int id){
63
        for(UserEnums userEnum: UserEnums.values()) {
64
            if(userEnum.getId()==id) {
65
                return userEnum;
66
            }
67
        }
68
        return null;
69
    }
70
71
    /**
72
     * 根据序号获取枚举数组中的值,序号必须从0开始
73
     * @param id
74
     * @return
75
     * @throws IllegalAccessException
76
     * @throws IllegalArgumentException
77
     * @throws InvocationTargetException
78
     * @throws InstantiationException
79
     */
80
    public static <T> List<T> getEumByKey(int id) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
81
        List<String> enumList=getEumValueList();
82
        List<T> enumList1=new ArrayList<T>();
83
        for(UserEnums testEnums: UserEnums.values()) {
84
            if(testEnums.getId()==id) {
85
                Class<?> clazz=testEnums.getClass();
86
                // 获取所有常量
87
                Object object = clazz.getEnumConstants()[id];
88
                Field[]  filedFields=clazz.getFields();
89
                for (Field field : filedFields) {
90
                    field.setAccessible(true);
91
                    Object sssObject=field.get(object);
92
                    if(enumList.contains(field.getName())) {
93
                        continue;
94
                    }else {
95
                        if(sssObject!=null)
96
                            enumList1.add((T) sssObject);
97
                    }
98
                }
99
                return enumList1;
100
            }
101
        }
102
        return null;
103
    }
104
    /**
105
     * 获取枚举值常量列表
106
     * @param
107
     * @return
108
     */
109
    public static List<String>  getEumValueList() {
110
        List<String> list=new ArrayList<String>();
111
        for(Object object:UserEnums.values()) {
112
            list.add(object.toString());
113
        }
114
        return list;
115
    }
116
    /**
117
     * 传入方法名称  values是值 ,field是 字段mingcheng
118
     * @param <T>
119
     * @param enumType
120
     * @param value
121
     * @param field
122
     * @return
123
     * @throws Exception
124
     */
125
    public static <T extends Enum<T>> T getEnumOnValue(Class<T> enumType, String value, String field) throws Exception {
126
127
        for (Object obj : enumType.getEnumConstants()) {
128
            Method m = obj.getClass().getDeclaredMethod("values", null);
129
            Object[] results = (Object[]) m.invoke(obj, null);
130
            for (Object result : results) {
131
                Field codeField = result.getClass().getDeclaredField(field);
132
                ReflectionUtils.makeAccessible(codeField);
133
                String fileValue = String.valueOf(ReflectionUtils.getField(codeField, result));
134
                if (fileValue.equals(value)) {
135
                    return (T) result;
136
                }
137
138
            }
139
        }
140
        return null;
141
    }
142
143
144
    /**
145
     * 获取所有的用户放到list里
146
     *
147
     * @return
148
     * @throws Exception
149
     */
150
151
    public static List<Map<String,Object>> getUserList(){
152
        ArrayList<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
153
        for(UserEnums userEnum : UserEnums .values()){
154
            Map<String,Object> userMap = new HashMap<String,Object>();
155
            userMap.put("id",userEnum.getId());
156
            userMap.put("userName",userEnum.getUserName());
157
            userMap.put("employeeNo",userEnum.getEmployeeNo());
158
            userMap.put("department",userEnum.getDepartment());
159
            userMap.put("duty",userEnum.getDuty());
160
            list.add(userMap);
161
        }
162
        return list;
163
    }
14
	oneUser(1, "张三", "1111", "搜救", "1", "zhangsan", "经理"), 
15
	twoUser(2, "李四", "2222", "搜救", "1", "lisi", "员工"),
16
	threeUser(3, "王五", "3333", "搜救", "1", "wangwu", "员工"), 
17
	fourUser(4, "赵六", "4444", "搜救", "1", "zhaoliu", "员工"),
18
	fiveUser(5, "田七", "5555", "搜救", "1", "tianqi", "员工"), 
19
	sixUser(6, "周八", "6666", "搜救", "1", "zhouba", "员工"),
20
	sevenUser(7, "吴九", "7777", "搜救", "1", "wujiu", "员工"), 
21
	eightUser(8, "郑十", "8888", "搜救", "1", "zhengshi", "员工"),
22
	nineUser(9, "刘一", "9999", "搜救", "1", "liuyi", "员工");
23
24
	public int id; // id
25
	public String userName;// 姓名
26
	public String employeeNo;// 员工编号
27
	public String department;// 部门
28
	public String employeeType;// 人员类型(1:内部员工; 2:外部人员)
29
	public String employeeCode;// 人员业务编码(员工:统一用户中心存储的员工唯一编码;外来人员:存储PARTY_ID)
30
	public String duty;// 职务
31
32
	UserEnums() {
33
34
	}
35
36
	private UserEnums(int id, String userName, String employeeNo, String department, String employeeType,
37
			String employeeCode, String duty) {
38
		this.id = id;
39
		this.userName = userName;
40
		this.employeeNo = employeeNo;
41
		this.department = department;
42
		this.employeeType = employeeType;
43
		this.employeeCode = employeeCode;
44
		this.duty = duty;
45
	}
46
47
	public int getId() {
48
		return id;
49
	}
50
51
	public String getUserName() {
52
		return userName;
53
	}
54
55
	public String getEmployeeNo() {
56
		return employeeNo;
57
	}
58
59
	public String getDepartment() {
60
		return department;
61
	}
62
63
	public String getEmployeeType() {
64
		return employeeType;
65
	}
66
67
	public String getEmployeeCode() {
68
		return employeeCode;
69
	}
70
71
	public String getDuty() {
72
		return duty;
73
	}
74
75
	/**
76
	 * 根据id返回枚举值
77
	 * @param id
78
	 * @return
79
	 */
80
	public static UserEnums getEumByid(int id) {
81
		for (UserEnums userEnum : UserEnums.values()) {
82
			if (userEnum.getId() == id) {
83
				return userEnum;
84
			}
85
		}
86
		return null;
87
	}
88
89
	/**
90
	 * 根据序号获取枚举数组中的值,序号必须从0开始
91
	 * @param id
92
	 * @return
93
	 * @throws IllegalAccessException
94
	 * @throws IllegalArgumentException
95
	 * @throws InvocationTargetException
96
	 * @throws InstantiationException
97
	 */
98
	public static <T> List<T> getEumByKey(int id)
99
			throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
100
		List<String> enumList = getEumValueList();
101
		List<T> enumList1 = new ArrayList<T>();
102
		for (UserEnums testEnums : UserEnums.values()) {
103
			if (testEnums.getId() == id) {
104
				Class<?> clazz = testEnums.getClass();
105
				// 获取所有常量
106
				Object object = clazz.getEnumConstants()[id];
107
				Field[] filedFields = clazz.getFields();
108
				for (Field field : filedFields) {
109
					field.setAccessible(true);
110
					Object sssObject = field.get(object);
111
					if (enumList.contains(field.getName())) {
112
						continue;
113
					} else {
114
						if (sssObject != null)
115
							enumList1.add((T) sssObject);
116
					}
117
				}
118
				return enumList1;
119
			}
120
		}
121
		return null;
122
	}
123
124
	/**
125
	 * 获取枚举值常量列表
126
	 * @param
127
	 * @return
128
	 */
129
	public static List<String> getEumValueList() {
130
		List<String> list = new ArrayList<String>();
131
		for (Object object : UserEnums.values()) {
132
			list.add(object.toString());
133
		}
134
		return list;
135
	}
136
137
	/**
138
	 * 传入方法名称  values是值 ,field是 字段mingcheng
139
	 * @param <T>
140
	 * @param enumType
141
	 * @param value
142
	 * @param field
143
	 * @return
144
	 * @throws Exception
145
	 */
146
	public static <T extends Enum<T>> T getEnumOnValue(Class<T> enumType, String value, String field) throws Exception {
147
148
		for (Object obj : enumType.getEnumConstants()) {
149
			Method m = obj.getClass().getDeclaredMethod("values", null);
150
			Object[] results = (Object[]) m.invoke(obj, null);
151
			for (Object result : results) {
152
				Field codeField = result.getClass().getDeclaredField(field);
153
				ReflectionUtils.makeAccessible(codeField);
154
				String fileValue = String.valueOf(ReflectionUtils.getField(codeField, result));
155
				if (fileValue.equals(value)) {
156
					return (T) result;
157
				}
158
159
			}
160
		}
161
		return null;
162
	}
163
164
	/**
165
	 * 获取所有的用户放到list里
166
	 *
167
	 * @return
168
	 * @throws Exception
169
	 */
170
171
	public static List<Map<String, Object>> getUserList() {
172
		ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
173
		for (UserEnums userEnum : UserEnums.values()) {
174
			Map<String, Object> userMap = new HashMap<String, Object>();
175
			userMap.put("id", userEnum.getId());
176
			userMap.put("userName", userEnum.getUserName());
177
			userMap.put("employeeNo", userEnum.getEmployeeNo());
178
			userMap.put("department", userEnum.getDepartment());
179
			userMap.put("employeeType", userEnum.getEmployeeType());
180
			userMap.put("employeeCode", userEnum.getEmployeeCode());
181
			userMap.put("duty", userEnum.getDuty());
182
			list.add(userMap);
183
		}
184
		return list;
185
	}
164 186
}