Key2ValueService.java
5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.skua.redis.component;
import com.skua.tool.javassist.JavassistFactory;
import com.skua.tool.query.WrapperFactory;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author sonin
* @date 2021/12/24 18:14
*/
@Component
public class Key2ValueService {
private Class sysDictClazz;
private Class sysDictItemClazz;
private Class sysUserClazz;
private Class sysDepartClazz;
private Class sysStructDictClazz;
private Class sysUserDepartClazz;
private Class equipmentSparepartTypeClazz;
private Class suppliesWarehouseClazz;
public Key2ValueService() {
try {
sysDictClazz = JavassistFactory.create()
.className("SysDict")
.field("id", String.class)
.field("dictCode", String.class)
.buildClass();
sysDictItemClazz = JavassistFactory.create()
.className("SysDictItem")
.field("dictId", String.class)
.field("itemText", String.class)
.field("itemValue", String.class)
.buildClass();
sysUserClazz = JavassistFactory.create()
.field("id", String.class)
.field("realname", String.class)
.className("SysUser")
.buildClass();
sysDepartClazz = JavassistFactory.create()
.className("SysDepart")
.field("id", String.class)
.field("departType", String.class)
.buildClass();
sysStructDictClazz = JavassistFactory.create()
.className("sysStructDict")
.buildClass();
sysUserDepartClazz = JavassistFactory.create().
field("id", String.class)
.field("depId", String.class)
.field("userId", String.class)
.className("SysUserDepart")
.buildClass();
equipmentSparepartTypeClazz = JavassistFactory.create().
field("id", String.class)
.field("itemText", String.class)
.field("itemValue", String.class)
.className("EquipmentSparepartType")
.buildClass();
suppliesWarehouseClazz = JavassistFactory.create()
.className("SuppliesWarehouse")
.field("id", String.class)
.field("warehouseName", String.class)
.buildClass();
} catch (Exception e) {
e.printStackTrace();
}
}
public Map<String, String> dictKey2Val(String dictCode, boolean isKey2Val) {
Map<String, String> result = new LinkedHashMap<>();
List<Map<String, Object>> mapList = null;
try {
if ("sysUser".equals(dictCode)) {
mapList = WrapperFactory
.joinWrapper()
.select("realname as itemText", "id as itemValue")
.from(sysUserClazz)
.where()
.queryWrapperForList();
} else if ("sysDepart".equals(dictCode)) {
mapList = WrapperFactory
.joinWrapper()
.select("depart_name as itemText", "id as itemValue")
.from(sysDepartClazz)
.where()
.queryWrapperForList();
} else if ("sysStructDict".equals(dictCode)) {
mapList = WrapperFactory
.joinWrapper()
.select("struct_name as itemText", "id as itemValue")
.from(sysStructDictClazz)
.where()
.queryWrapperForList();
} else if ("equipmentSparepartType".equals(dictCode)) {
mapList = WrapperFactory
.joinWrapper()
.select("item_text as itemText", "id as itemValue")
.from(equipmentSparepartTypeClazz)
.where()
.queryWrapperForList();
} else if ("suppliesWarehouse".equals(dictCode)) {
mapList = WrapperFactory
.joinWrapper()
.select("warehouse_name as itemText", "id as itemValue")
.from(suppliesWarehouseClazz)
.where()
.queryWrapperForList();
} else {
mapList = WrapperFactory
.joinWrapper()
.select("item_text as itemText", "item_value as itemValue")
.from(sysDictClazz)
.innerJoin(sysDictItemClazz, sysDictItemClazz.getDeclaredField("dictId"), sysDictClazz.getDeclaredField("id"))
.where()
.eq(true, "dict_code", dictCode)
.queryWrapperForList();
}
} catch (
Exception e) {
e.printStackTrace();
}
if (mapList != null) {
if (isKey2Val) {
for (Map<String, Object> map : mapList) {
result.put("" + map.get("itemText"), "" + map.get("itemValue"));
}
} else {
for (Map<String, Object> map : mapList) {
result.put("" + map.get("itemValue"), "" + map.get("itemText"));
}
}
}
return result;
}
}