commit | author | age
|
a18bfa
|
1 |
package cn.autoform.util.thread; |
Z |
2 |
|
|
3 |
import cn.autoform.factory.product.ProductMethod.IOType; |
|
4 |
import lombok.EqualsAndHashCode; |
|
5 |
import lombok.Getter; |
|
6 |
import lombok.ToString; |
|
7 |
|
|
8 |
import java.util.Properties; |
|
9 |
|
|
10 |
/** |
|
11 |
* 线程存储区的key |
|
12 |
* @author WangYX |
|
13 |
* |
|
14 |
*/ |
|
15 |
@EqualsAndHashCode |
|
16 |
@Getter |
|
17 |
@ToString |
|
18 |
public class Keys<T> { |
|
19 |
|
|
20 |
private String key; |
|
21 |
|
|
22 |
private Class<T> clazz; |
|
23 |
|
|
24 |
private T defaultValue; |
|
25 |
|
|
26 |
private Format<T> format; |
|
27 |
|
|
28 |
public Keys(String key, Class<T> clazz) { |
|
29 |
super(); |
|
30 |
this.key = key; |
|
31 |
this.clazz = clazz; |
|
32 |
} |
|
33 |
|
|
34 |
public Keys(String key, Class<T> clazz, T defaultValue) { |
|
35 |
super(); |
|
36 |
this.key = key; |
|
37 |
this.clazz = clazz; |
|
38 |
this.defaultValue = defaultValue; |
|
39 |
} |
|
40 |
|
|
41 |
public Keys(String key, Class<T> clazz, T defaultValue, Format<T> format) { |
|
42 |
super(); |
|
43 |
this.key = key; |
|
44 |
this.clazz = clazz; |
|
45 |
this.defaultValue = defaultValue; |
|
46 |
this.format = format; |
|
47 |
} |
|
48 |
|
|
49 |
public T format(Object obj){ |
|
50 |
if(format != null) |
|
51 |
return format.format(obj); |
|
52 |
if(clazz.equals(String.class)) |
|
53 |
return (T) obj.toString(); |
|
54 |
if(clazz.equals(Integer.class)) |
|
55 |
return (T) new Integer(Integer.parseInt(obj.toString())); |
|
56 |
return defaultValue; |
|
57 |
} |
|
58 |
|
|
59 |
public static <T> Keys<T> getKeys(String key, Class<T> clazz){ |
|
60 |
return new Keys<>(key, clazz); |
|
61 |
} |
|
62 |
|
|
63 |
public static <T> Keys<T> getKeys(String key, Class<T> clazz, T defaultValue){ |
|
64 |
return new Keys<>(key, clazz, defaultValue); |
|
65 |
} |
|
66 |
|
|
67 |
public static <T> Keys<T> getKeys(String key, Class<T> clazz, T defaultValue, Format<T> format){ |
|
68 |
return new Keys<>(key, clazz, defaultValue, format); |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* 格式数据 |
|
73 |
* @author WangYX |
|
74 |
* |
|
75 |
* @param <T> |
|
76 |
*/ |
|
77 |
public static interface Format<T>{ |
|
78 |
|
|
79 |
T format(Object obj); |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* token令牌 |
|
84 |
*/ |
|
85 |
public static final Keys<String> TOKEN = getKeys("token" , String.class , ""); |
|
86 |
|
|
87 |
/** |
|
88 |
* 业务系统id |
|
89 |
*/ |
|
90 |
public static final Keys<String> APP_KEY = getKeys("APP_KEY" , String.class , ""); |
|
91 |
|
|
92 |
/** |
|
93 |
* 租户id |
|
94 |
*/ |
|
95 |
public static final Keys<String> TENANT_ID = getKeys("tenantID" , String.class , ""); |
|
96 |
|
|
97 |
/** |
|
98 |
* 用户id |
|
99 |
*/ |
|
100 |
public static final Keys<String> USER_ID = getKeys("USER_ID" , String.class); |
|
101 |
|
|
102 |
/** |
|
103 |
* 用户名称 |
|
104 |
*/ |
|
105 |
public static final Keys<String> USER_NAME = getKeys("USER_NAME" , String.class); |
|
106 |
|
|
107 |
/** |
|
108 |
* 用户语言 |
|
109 |
*/ |
|
110 |
public static final Keys<String> USER_LANGUAGE = getKeys("USER_LANGUAGE" , String.class , "zh-CN"); |
|
111 |
|
|
112 |
/** |
|
113 |
* 用户语言属性文件 |
|
114 |
*/ |
|
115 |
public static final Keys<Properties> LANGUAGE_PROP = getKeys("LANGUAGE_PROP" , Properties.class); |
|
116 |
|
|
117 |
/** |
|
118 |
* 页码 |
|
119 |
*/ |
|
120 |
public static final Keys<Integer> PAGE_NUM = getKeys("pageNum" , Integer.class , 1); |
|
121 |
|
|
122 |
/** |
|
123 |
* 每页条数 |
|
124 |
*/ |
|
125 |
public static final Keys<Integer> PAGE_SIZE = getKeys("pageSize" , Integer.class , 10); |
|
126 |
|
|
127 |
/** |
|
128 |
* 表单id |
|
129 |
*/ |
|
130 |
public static final Keys<String> FORM_ID = getKeys("formID" , String.class , ""); |
|
131 |
|
|
132 |
/** |
|
133 |
* 表单数据存储位置 |
|
134 |
*/ |
|
135 |
public static final Keys<IOType> IO_FLAG = getKeys("flag" , IOType.class , IOType.cloud, obj->IOType.valueOf(obj.toString())); |
|
136 |
|
|
137 |
/** |
|
138 |
* openId |
|
139 |
*/ |
|
140 |
public static final Keys<String> OPEN_ID = getKeys("openId" , String.class , ""); |
|
141 |
|
|
142 |
/** |
|
143 |
* serviceId |
|
144 |
*/ |
|
145 |
public static final Keys<String> SERVICE_ID = getKeys("serviceId" , String.class , ""); |
|
146 |
|
|
147 |
/** |
|
148 |
* comanyId |
|
149 |
*/ |
|
150 |
public static final Keys<String> COMPANY_ID = getKeys("companyId" , String.class , ""); |
|
151 |
|
|
152 |
/** |
|
153 |
* URL |
|
154 |
*/ |
|
155 |
public static final Keys<String> URL = getKeys("url" , String.class , ""); |
|
156 |
|
|
157 |
/** |
|
158 |
* URL |
|
159 |
*/ |
|
160 |
public static final Keys<String> DATA_SOURCE_ID = getKeys("dataSourceId" , String.class , ""); |
|
161 |
|
|
162 |
|
|
163 |
} |