|
|
@@ -4,39 +4,36 @@ import java.io.BufferedInputStream;
|
|
4
|
4
|
import java.io.InputStream;
|
|
5
|
5
|
import java.text.ParseException;
|
|
6
|
6
|
import java.text.SimpleDateFormat;
|
|
7
|
|
-import java.util.Calendar;
|
|
8
|
|
-import java.util.Date;
|
|
9
|
|
-import java.util.List;
|
|
10
|
|
-import java.util.Properties;
|
|
|
7
|
+import java.util.*;
|
|
11
|
8
|
|
|
12
|
9
|
public class ParameterUtil {
|
|
13
|
10
|
|
|
14
|
|
- public static String getSysDateTime(){
|
|
15
|
|
- String temp_str="";
|
|
|
11
|
+ public static String getSysDateTime() {
|
|
|
12
|
+ String temp_str = "";
|
|
16
|
13
|
Date dt = new Date();
|
|
17
|
14
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
18
|
|
- temp_str=sdf.format(dt);
|
|
19
|
|
- System.out.println("获取当前时间"+temp_str);
|
|
|
15
|
+ temp_str = sdf.format(dt);
|
|
|
16
|
+ System.out.println("获取当前时间" + temp_str);
|
|
20
|
17
|
return temp_str;
|
|
21
|
18
|
}
|
|
22
|
|
-
|
|
|
19
|
+
|
|
23
|
20
|
public static String getDateYMDHMS(Date date) {
|
|
24
|
|
- String str = "";
|
|
|
21
|
+ String str = "";
|
|
25
|
22
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
26
|
|
- str=sdf.format(date);
|
|
27
|
|
- System.out.println("获取当前时间"+str);
|
|
|
23
|
+ str = sdf.format(date);
|
|
|
24
|
+ System.out.println("获取当前时间" + str);
|
|
28
|
25
|
return str;
|
|
29
|
26
|
}
|
|
30
|
|
-
|
|
31
|
|
- public static String getSysDate(){
|
|
32
|
|
- String temp_str="";
|
|
|
27
|
+
|
|
|
28
|
+ public static String getSysDate() {
|
|
|
29
|
+ String temp_str = "";
|
|
33
|
30
|
Date dt = new Date();
|
|
34
|
31
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
35
|
|
- temp_str=sdf.format(dt);
|
|
|
32
|
+ temp_str = sdf.format(dt);
|
|
36
|
33
|
return temp_str;
|
|
37
|
34
|
}
|
|
38
|
35
|
|
|
39
|
|
- public static Date string2datetime(String dateTime){
|
|
|
36
|
+ public static Date string2datetime(String dateTime) {
|
|
40
|
37
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
41
|
38
|
Date date = null;
|
|
42
|
39
|
try {
|
|
|
@@ -46,7 +43,8 @@ public class ParameterUtil {
|
|
46
|
43
|
}
|
|
47
|
44
|
return date;
|
|
48
|
45
|
}
|
|
49
|
|
- public static Date string2date(String dateTime){
|
|
|
46
|
+
|
|
|
47
|
+ public static Date string2date(String dateTime) {
|
|
50
|
48
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
51
|
49
|
Date date = null;
|
|
52
|
50
|
try {
|
|
|
@@ -57,20 +55,21 @@ public class ParameterUtil {
|
|
57
|
55
|
return date;
|
|
58
|
56
|
}
|
|
59
|
57
|
|
|
60
|
|
- public static String date2string(Date date){
|
|
61
|
|
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
|
|
62
|
|
- String str=sdf.format(date);
|
|
|
58
|
+ public static String date2string(Date date) {
|
|
|
59
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
60
|
+ String str = sdf.format(date);
|
|
63
|
61
|
return str;
|
|
64
|
62
|
}
|
|
65
|
63
|
|
|
66
|
64
|
/**
|
|
67
|
65
|
* 获取指定时间的时间戳
|
|
|
66
|
+ *
|
|
68
|
67
|
* @param datatime
|
|
69
|
68
|
* @return
|
|
70
|
69
|
*/
|
|
71
|
|
- public static String getTimeStamp(String datatime){
|
|
|
70
|
+ public static String getTimeStamp(String datatime) {
|
|
72
|
71
|
long timeStamp = 0;
|
|
73
|
|
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
72
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
74
|
73
|
try {
|
|
75
|
74
|
Date date = format.parse(datatime);
|
|
76
|
75
|
timeStamp = date.getTime();
|
|
|
@@ -83,7 +82,7 @@ public class ParameterUtil {
|
|
83
|
82
|
/*
|
|
84
|
83
|
* 将时间戳转换为时间
|
|
85
|
84
|
*/
|
|
86
|
|
- public static String stampToDate(String s){
|
|
|
85
|
+ public static String stampToDate(String s) {
|
|
87
|
86
|
String res;
|
|
88
|
87
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
89
|
88
|
long lt = new Long(s);
|
|
|
@@ -92,34 +91,34 @@ public class ParameterUtil {
|
|
92
|
91
|
return res;
|
|
93
|
92
|
}
|
|
94
|
93
|
|
|
95
|
|
-// public static void main(String[] args) {
|
|
|
94
|
+ // public static void main(String[] args) {
|
|
96
|
95
|
// System.out.println(stampToDate("1504689208643"));
|
|
97
|
96
|
// System.out.println(getTimeStamp(getSysDateTime()));
|
|
98
|
97
|
// }
|
|
99
|
|
- public static String getBHS(String BHS){
|
|
|
98
|
+ public static String getBHS(String BHS) {
|
|
100
|
99
|
String[] str = BHS.split(",");
|
|
101
|
100
|
StringBuffer sb = new StringBuffer();
|
|
102
|
|
- for(int i=0;i<str.length;i++){
|
|
|
101
|
+ for (int i = 0; i < str.length; i++) {
|
|
103
|
102
|
sb.append("'").append(str[i]).append("'").append(",");
|
|
104
|
103
|
}
|
|
105
|
|
- String s=sb.toString();
|
|
106
|
|
- String t=s.substring(0,s.length()-1);
|
|
|
104
|
+ String s = sb.toString();
|
|
|
105
|
+ String t = s.substring(0, s.length() - 1);
|
|
107
|
106
|
return t;
|
|
108
|
107
|
}
|
|
109
|
108
|
|
|
110
|
109
|
//判断字段值是为空 不为空返回ture
|
|
111
|
|
- public static boolean isnotnull(Object name){
|
|
112
|
|
- return (null!=name&&!"".equals(name) && !"null".equals(name) && "null" != name);
|
|
|
110
|
+ public static boolean isnotnull(Object name) {
|
|
|
111
|
+ return (null != name && !"".equals(name) && !"null".equals(name) && "null" != name);
|
|
113
|
112
|
}
|
|
114
|
|
-
|
|
|
113
|
+
|
|
115
|
114
|
//判断字段值是为空,为空返回ture
|
|
116
|
|
- public static boolean isnull(Object name){
|
|
117
|
|
- return (null==name || "".equals(name) || "null".equals(name) || "null" == name);
|
|
|
115
|
+ public static boolean isnull(Object name) {
|
|
|
116
|
+ return (null == name || "".equals(name) || "null".equals(name) || "null" == name);
|
|
118
|
117
|
}
|
|
119
|
118
|
|
|
120
|
119
|
//判断字段值是相等 相等返回ture
|
|
121
|
|
- public static boolean isequal(Object name,Object value){
|
|
122
|
|
- if(name==value||name.equals(value)){
|
|
|
120
|
+ public static boolean isequal(Object name, Object value) {
|
|
|
121
|
+ if (name == value || name.equals(value)) {
|
|
123
|
122
|
return true;
|
|
124
|
123
|
}
|
|
125
|
124
|
return false;
|
|
|
@@ -127,14 +126,15 @@ public class ParameterUtil {
|
|
127
|
126
|
|
|
128
|
127
|
/**
|
|
129
|
128
|
* 判断list和str数组是否全等
|
|
|
129
|
+ *
|
|
130
|
130
|
* @param list
|
|
131
|
131
|
* @param str
|
|
132
|
132
|
* @return
|
|
133
|
133
|
*/
|
|
134
|
|
- public static boolean isAllequal(List<String> list,String[] str){
|
|
|
134
|
+ public static boolean isAllequal(List<String> list, String[] str) {
|
|
135
|
135
|
boolean isbz = true;
|
|
136
|
|
- for(int z=0;z<str.length;z++){
|
|
137
|
|
- if(!isequal(list.get(z),str[z])){
|
|
|
136
|
+ for (int z = 0; z < str.length; z++) {
|
|
|
137
|
+ if (!isequal(list.get(z), str[z])) {
|
|
138
|
138
|
isbz = false;
|
|
139
|
139
|
break;
|
|
140
|
140
|
}
|
|
|
@@ -143,9 +143,9 @@ public class ParameterUtil {
|
|
143
|
143
|
}
|
|
144
|
144
|
|
|
145
|
145
|
//判断字段值是否在某个集合里 在返回ture
|
|
146
|
|
- public static boolean isallequal(Object name,String[] value){
|
|
147
|
|
- for(int i=0;i<value.length;i++){
|
|
148
|
|
- if(name==value[i]||name.equals(value[i])){
|
|
|
146
|
+ public static boolean isallequal(Object name, String[] value) {
|
|
|
147
|
+ for (int i = 0; i < value.length; i++) {
|
|
|
148
|
+ if (name == value[i] || name.equals(value[i])) {
|
|
149
|
149
|
return true;
|
|
150
|
150
|
}
|
|
151
|
151
|
}
|
|
|
@@ -154,6 +154,7 @@ public class ParameterUtil {
|
|
154
|
154
|
|
|
155
|
155
|
/**
|
|
156
|
156
|
* 从properties得到路径
|
|
|
157
|
+ *
|
|
157
|
158
|
* @param filePath
|
|
158
|
159
|
* @return
|
|
159
|
160
|
*/
|
|
|
@@ -168,15 +169,14 @@ public class ParameterUtil {
|
|
168
|
169
|
return props;
|
|
169
|
170
|
}
|
|
170
|
171
|
|
|
171
|
|
- public static String dellOneDay(String time)
|
|
172
|
|
- {
|
|
|
172
|
+ public static String dellOneDay(String time) {
|
|
173
|
173
|
String add = null;
|
|
174
|
174
|
try {
|
|
175
|
175
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
176
|
176
|
java.util.Date timeNow = df.parse(time);
|
|
177
|
|
- Calendar begin=Calendar.getInstance();
|
|
|
177
|
+ Calendar begin = Calendar.getInstance();
|
|
178
|
178
|
begin.setTime(timeNow);
|
|
179
|
|
- begin.add(Calendar.DAY_OF_MONTH,-1);
|
|
|
179
|
+ begin.add(Calendar.DAY_OF_MONTH, -1);
|
|
180
|
180
|
add = df.format(begin.getTime());
|
|
181
|
181
|
} catch (Exception e) {
|
|
182
|
182
|
e.printStackTrace();
|
|
|
@@ -184,4 +184,158 @@ public class ParameterUtil {
|
|
184
|
184
|
return add;
|
|
185
|
185
|
}
|
|
186
|
186
|
|
|
|
187
|
+ //判断两个时间是否是同一周
|
|
|
188
|
+ public static boolean isSameDate(Date d1, Date d2) {
|
|
|
189
|
+ Calendar cal1 = Calendar.getInstance();
|
|
|
190
|
+ Calendar cal2 = Calendar.getInstance();
|
|
|
191
|
+ cal1.setTime(d1);
|
|
|
192
|
+ cal2.setTime(d2);
|
|
|
193
|
+ int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
|
|
|
194
|
+ //subYear==0,说明是同一年
|
|
|
195
|
+ if (subYear == 0) {
|
|
|
196
|
+ if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
|
|
|
197
|
+ return true;
|
|
|
198
|
+ }
|
|
|
199
|
+ //例子:cal1是"2005-1-1",cal2是"2004-12-25"
|
|
|
200
|
+ //java对"2004-12-25"处理成第52周
|
|
|
201
|
+ // "2004-12-26"它处理成了第1周,和"2005-1-1"相同了
|
|
|
202
|
+ //大家可以查一下自己的日历
|
|
|
203
|
+ //处理的比较好
|
|
|
204
|
+ //说明:java的一月用"0"标识,那么12月用"11"
|
|
|
205
|
+ else if (subYear == 1 && cal2.get(Calendar.MONTH) == 11) {
|
|
|
206
|
+ if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
|
|
|
207
|
+ return true;
|
|
|
208
|
+ }
|
|
|
209
|
+ //例子:cal1是"2004-12-31",cal2是"2005-1-1"
|
|
|
210
|
+ else if (subYear == -1 && cal1.get(Calendar.MONTH) == 11) {
|
|
|
211
|
+ if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
|
|
|
212
|
+ return true;
|
|
|
213
|
+ }
|
|
|
214
|
+ return false;
|
|
|
215
|
+ }
|
|
|
216
|
+
|
|
|
217
|
+ /**
|
|
|
218
|
+ * List转换String
|
|
|
219
|
+ *
|
|
|
220
|
+ * @param list :需要转换的List
|
|
|
221
|
+ * @return String转换后的字符串
|
|
|
222
|
+ */
|
|
|
223
|
+ public static String ListToString(List<?> list) {
|
|
|
224
|
+ StringBuffer sb = new StringBuffer();
|
|
|
225
|
+ if (list != null && list.size() > 0) {
|
|
|
226
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
227
|
+ if (list.get(i) == null || list.get(i) == "") {
|
|
|
228
|
+ continue;
|
|
|
229
|
+ }
|
|
|
230
|
+ // 如果值是list类型则调用自己
|
|
|
231
|
+ if (list.get(i) instanceof List) {
|
|
|
232
|
+ sb.append(ListToString((List<?>) list.get(i)));
|
|
|
233
|
+ sb.append(",");
|
|
|
234
|
+ } else if (list.get(i) instanceof Map) {
|
|
|
235
|
+ sb.append(MapToString((Map<?, ?>) list.get(i)));
|
|
|
236
|
+ sb.append(",");
|
|
|
237
|
+ } else {
|
|
|
238
|
+ sb.append(list.get(i));
|
|
|
239
|
+ sb.append(",");
|
|
|
240
|
+ }
|
|
|
241
|
+ }
|
|
|
242
|
+ }
|
|
|
243
|
+ return "L" + sb.toString();
|
|
|
244
|
+ }
|
|
|
245
|
+
|
|
|
246
|
+ /**
|
|
|
247
|
+ * Map转换String
|
|
|
248
|
+ *
|
|
|
249
|
+ * @param map :需要转换的Map
|
|
|
250
|
+ * @return String转换后的字符串
|
|
|
251
|
+ */
|
|
|
252
|
+ public static String MapToString(Map<?, ?> map) {
|
|
|
253
|
+ StringBuffer sb = new StringBuffer();
|
|
|
254
|
+ // 遍历map
|
|
|
255
|
+ for (Object obj : map.keySet()) {
|
|
|
256
|
+ if (obj == null) {
|
|
|
257
|
+ continue;
|
|
|
258
|
+ }
|
|
|
259
|
+ Object key = obj;
|
|
|
260
|
+ Object value = map.get(key);
|
|
|
261
|
+ if (value instanceof List<?>) {
|
|
|
262
|
+ sb.append(key.toString() + "," + ListToString((List<?>) value));
|
|
|
263
|
+ sb.append("|");
|
|
|
264
|
+ } else if (value instanceof Map<?, ?>) {
|
|
|
265
|
+ sb.append(key.toString() + "," + MapToString((Map<?, ?>) value));
|
|
|
266
|
+ sb.append("|");
|
|
|
267
|
+ } else {
|
|
|
268
|
+ sb.append(key.toString() + "=" + value.toString());
|
|
|
269
|
+ sb.append("|");
|
|
|
270
|
+ }
|
|
|
271
|
+ }
|
|
|
272
|
+ return "M" + sb.toString();
|
|
|
273
|
+ }
|
|
|
274
|
+
|
|
|
275
|
+ /**
|
|
|
276
|
+ * String转换List
|
|
|
277
|
+ *
|
|
|
278
|
+ * @param listText
|
|
|
279
|
+ * :需要转换的文本
|
|
|
280
|
+ * @return List<?>
|
|
|
281
|
+ */
|
|
|
282
|
+ public static List<Map<String,Object>> StringToList(String listText) {
|
|
|
283
|
+ if (listText == null || listText.equals("")) {
|
|
|
284
|
+ return null;
|
|
|
285
|
+ }
|
|
|
286
|
+ listText = listText.substring(1);
|
|
|
287
|
+
|
|
|
288
|
+ List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
|
|
|
289
|
+ String[] text = listText.split("\\" + ",");
|
|
|
290
|
+ String listStr = "";
|
|
|
291
|
+ boolean flag = false;
|
|
|
292
|
+ for (String str : text) {
|
|
|
293
|
+ if (!str.equals("")) {
|
|
|
294
|
+ if (str.charAt(0) == 'M') {
|
|
|
295
|
+ Map<String,Object> map = StringToMap(str);
|
|
|
296
|
+ list.add(map);
|
|
|
297
|
+ } else if (str.charAt(0) == 'L' || flag) {
|
|
|
298
|
+ flag = true;
|
|
|
299
|
+ listStr += str + ",";
|
|
|
300
|
+ }
|
|
|
301
|
+ }
|
|
|
302
|
+ }
|
|
|
303
|
+ return list;
|
|
|
304
|
+ }
|
|
|
305
|
+
|
|
|
306
|
+ /**
|
|
|
307
|
+ * String转换Map
|
|
|
308
|
+ *
|
|
|
309
|
+ * @param mapText
|
|
|
310
|
+ * :需要转换的字符串
|
|
|
311
|
+ * @return Map<?,?>
|
|
|
312
|
+ */
|
|
|
313
|
+ public static Map<String, Object> StringToMap(String mapText) {
|
|
|
314
|
+
|
|
|
315
|
+ if (mapText == null || mapText.equals("")) {
|
|
|
316
|
+ return null;
|
|
|
317
|
+ }
|
|
|
318
|
+ mapText = mapText.substring(1);
|
|
|
319
|
+
|
|
|
320
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
321
|
+ String[] text = mapText.split("\\" + "|"); // 转换为数组
|
|
|
322
|
+ for (String str : text) {
|
|
|
323
|
+ String[] keyText = str.split("="); // 转换key与value的数组
|
|
|
324
|
+ if (keyText.length < 1) {
|
|
|
325
|
+ continue;
|
|
|
326
|
+ }
|
|
|
327
|
+ String key = keyText[0]; // key
|
|
|
328
|
+ String value = keyText[1]; // value
|
|
|
329
|
+ if (value.charAt(0) == 'M') {
|
|
|
330
|
+ Map<?, ?> map1 = StringToMap(value);
|
|
|
331
|
+ map.put(key, map1);
|
|
|
332
|
+ } else if (value.charAt(0) == 'L') {
|
|
|
333
|
+ List<?> list = StringToList(value);
|
|
|
334
|
+ map.put(key, list);
|
|
|
335
|
+ } else {
|
|
|
336
|
+ map.put(key, value);
|
|
|
337
|
+ }
|
|
|
338
|
+ }
|
|
|
339
|
+ return map;
|
|
|
340
|
+ }
|
|
187
|
341
|
}
|