-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathUtil.java
More file actions
370 lines (343 loc) · 8.26 KB
/
Copy pathUtil.java
File metadata and controls
370 lines (343 loc) · 8.26 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
package com.java110.util;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletResponse;
import com.java110.common.SpringAppFactory;
import com.java110.service.common.CommonService;
/**
* 工具类(主要实现系统工具方法实现)
*
* @author wuxw
* @date 2016-1-22 version 1.0
*/
public class Util {
/**
* 获取当前日期的 yyyy-MM-dd HH:mm:SS格式
*
* @return
*/
public static String getSimilerDatePath() {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return df.format(new Date());
}
/**
* 获取当前日期的yyyy/MM/dd格式
*
* @return
*/
public static String getSimilerDate() {
DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
return df.format(new Date());
}
/**
* 获取当前日期的yyyy年MM月dd日格式
*
* @return
*/
public static String getDateString() {
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日");
return df.format(new Date());
}
/**
* 获取月份
*
* add by wuxw 2016-2-18
*
* @return
*/
public static int getMonths() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.MONTH) + 1;
}
public static String getFormatDate(String format) throws Exception {
if (Util.isEmpty(format)) {
format = "yyyy-MM-dd HH:mm:ss";
}
SimpleDateFormat dateformat = new SimpleDateFormat(format);
Calendar cal = Calendar.getInstance();
return dateformat.format(cal.getTime());
}
/**
* 获取days
*
* add by wuxw 2016-2-18
*
* @return
*/
public static int getDays() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.DATE);
}
public static byte[] md5(byte[] src) throws NoSuchAlgorithmException {
MessageDigest tool = MessageDigest.getInstance("MD5");
tool.update(src);
byte[] byts = tool.digest();
return byts;
}
/**
* MD5 加密
*
* @param src
* @return
* @throws Exception
*/
public static String md5(String src) throws Exception {
return new String(md5(src.getBytes()));
}
/**
* 创建32位seqid 采用uuid算法
*
* @return
*/
public static String getUUID() {
UUID uuid = UUID.randomUUID();
String str = uuid.toString();
return str.replaceAll("-", "");
}
public static Map<String, String> getRequestMap(Map map) {
Map<String, String> rst = new HashMap<String, String>();
Set keys = map.keySet();
for (Object obj : keys) {
String key = String.valueOf(obj);
String[] value = (String[]) map.get(key);
if (value.length > 0) {
rst.put(key, value[0]);
}
}
return rst;
}
public static void responseAJAXData(HttpServletResponse response,
String writeValue) throws IOException {
response.setContentType("text/html");
response.setContentType("utf-8");
response.getWriter().write(writeValue);
}
/**
* 数值判断
*
* @param str
* @return
*/
public static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("^([1-9]{1})([0-9]*)");
Matcher matcher = pattern.matcher(str);
if (matcher.matches()) {
return true;
}
return false;
}
/**
* String 空值判断(为空)
*
* @param str
* @return
*/
public static boolean isEmpty(String str) {
if (null == str || "".equals(str.trim())) {
return true;
}
return false;
}
/**
* String 空值判断(不为空)
*
* @param str
* @return
*/
public static boolean isNotEmpty(String str) {
str = str.trim();
if (null == str || "".equals(str)) {
return false;
}
return true;
}
/**
* Map 空值判断(为空)
*
* @param str
* @return
*/
public static boolean isEmpty(Map str) {
if (null == str || "".equals(str)) {
return true;
}
return false;
}
/**
* Map 空值判断(不为空)
*
* @param str
* @return
*/
public static boolean isNotEmpty(Map str) {
if (null == str || "".equals(str)) {
return true;
}
return false;
}
/**
* 获取秒杀日期
*
* add by wuxw 2016-3-9
* @param str
* @return
*/
public static Date getSpikeDate(String str) {
Date convertDate = null;
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
format.setLenient(false);
convertDate = format.parse(str);
} catch (Exception e) {
//出现异常就获取当前时间
convertDate= new Date();
}
return convertDate;
}
/**
* 时间比较
*
* add by wuxw 2016-3-9
* @param DATE1
* @param DATE2
* @return
*/
public static int compare_date(String DATE1, String DATE2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
Date dt1 = df.parse(DATE1);
Date dt2 = df.parse(DATE2);
if (dt1.getTime() > dt2.getTime()) {
return 1;
} else if (dt1.getTime() < dt2.getTime()) {
return -1;
} else {
return 0;
}
} catch (Exception exception) {
return 0;
}
}
/**
* 时间比较
*
* add by wuxw 2016-3-9
* @param DATE1
* @param DATE2
* @return
*/
public static int compare_date_2_sysdate(String DATE1) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
Date dt1 = df.parse(DATE1);
Date dt2 = new Date();
if (dt1.getTime() > dt2.getTime()) {
return 1;
} else if (dt1.getTime() < dt2.getTime()) {
return -1;
} else {
return -1;
}
} catch (Exception exception) {
return -1;
}
}
public static void main(String[] args) {
System.out.println(compare_date_2_sysdate("2016-03-23 13:13:13"));
}
/**
* 获取发红包主键
*
* @return
*/
public static String getSendRedPacketId() {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
CommonService cs = (CommonService) SpringAppFactory
.getBean("CommonServiceImpl");
Map info = new HashMap();
info.put("primaryName", "sendRedPacketId");
return "10000000" + df.format(new Date()) + "0000"
+ cs.getPrimaryKey(info).get("val");
}
/**
* 获取用户主键
*
* @return
*/
public static String getUserId() {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
CommonService cs = (CommonService) SpringAppFactory
.getBean("CommonServiceImpl");
Map info = new HashMap();
info.put("primaryName", "userId");
return "70" + df.format(new Date()) + "0000"
+ cs.getPrimaryKey(info).get("val");
}
/**
* 获取账户主键
*
* @return
*/
public static String getAccountId() {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
CommonService cs = (CommonService) SpringAppFactory
.getBean("CommonServiceImpl");
Map info = new HashMap();
info.put("primaryName", "accountId");
return "60" + df.format(new Date()) + "0000"
+ cs.getPrimaryKey(info).get("val");
}
/**
* 抢红包主键
*
* @return
*/
public static String getRedPacketId() {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
CommonService cs = (CommonService) SpringAppFactory
.getBean("CommonServiceImpl");
Map info = new HashMap();
info.put("primaryName", "getRedPacketId");
return "60" + df.format(new Date()) + "0000"
+ cs.getPrimaryKey(info).get("val");
}
/**
* 兑红包主键
*
* @return
*/
public static String getExchangeRedPacketId() {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
CommonService cs = (CommonService) SpringAppFactory
.getBean("CommonServiceImpl");
Map info = new HashMap();
info.put("primaryName", "exchangeRedPacketId");
return "50" + df.format(new Date()) + "0000"
+ cs.getPrimaryKey(info).get("val");
}
/**
* 支付主键
*
* @return
*/
public static String getPayId() {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
CommonService cs = (CommonService) SpringAppFactory
.getBean("CommonServiceImpl");
Map info = new HashMap();
info.put("primaryName", "payId");
return "40" + df.format(new Date()) + "0000"
+ cs.getPrimaryKey(info).get("val");
}
}