|
@@ -0,0 +1,270 @@
|
|
1
|
+package com.unis.equipmentOnlineRateAssessment.modular.monitorNvr.utils;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+import java.io.BufferedInputStream;
|
|
5
|
+import java.io.InputStream;
|
|
6
|
+import java.text.ParseException;
|
|
7
|
+import java.text.SimpleDateFormat;
|
|
8
|
+import java.util.*;
|
|
9
|
+
|
|
10
|
+public class ParameterUtil {
|
|
11
|
+
|
|
12
|
+ public static String getSysDateTime(){
|
|
13
|
+ String temp_str="";
|
|
14
|
+ Date dt = new Date();
|
|
15
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
16
|
+ temp_str=sdf.format(dt);
|
|
17
|
+ System.out.println("获取当前时间"+temp_str);
|
|
18
|
+ return temp_str;
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ public static String getDateYMDHMS(Date date) {
|
|
22
|
+ String str = "";
|
|
23
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
24
|
+ str=sdf.format(date);
|
|
25
|
+ System.out.println("获取当前时间"+str);
|
|
26
|
+ return str;
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ public static String getSysDate(){
|
|
30
|
+ String temp_str="";
|
|
31
|
+ Date dt = new Date();
|
|
32
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
33
|
+ temp_str=sdf.format(dt);
|
|
34
|
+ return temp_str;
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ public static Date string2datetime(String dateTime){
|
|
38
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
39
|
+ Date date = null;
|
|
40
|
+ try {
|
|
41
|
+ date = dateFormat.parse(dateTime);
|
|
42
|
+ } catch (ParseException e) {
|
|
43
|
+ e.printStackTrace();
|
|
44
|
+ }
|
|
45
|
+ return date;
|
|
46
|
+ }
|
|
47
|
+ public static Date string2date(String dateTime){
|
|
48
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
49
|
+ Date date = null;
|
|
50
|
+ try {
|
|
51
|
+ date = dateFormat.parse(dateTime);
|
|
52
|
+ } catch (ParseException e) {
|
|
53
|
+ e.printStackTrace();
|
|
54
|
+ }
|
|
55
|
+ return date;
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ public static String date2string(Date date){
|
|
59
|
+ SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
|
|
60
|
+ String str=sdf.format(date);
|
|
61
|
+ return str;
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ /**
|
|
65
|
+ * 获取指定时间的时间戳
|
|
66
|
+ * @param datatime
|
|
67
|
+ * @return
|
|
68
|
+ */
|
|
69
|
+ public static String getTimeStamp(String datatime){
|
|
70
|
+ long timeStamp = 0;
|
|
71
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
72
|
+ try {
|
|
73
|
+ Date date = format.parse(datatime);
|
|
74
|
+ timeStamp = date.getTime();
|
|
75
|
+ } catch (ParseException e) {
|
|
76
|
+ e.printStackTrace();
|
|
77
|
+ }
|
|
78
|
+ return String.valueOf(timeStamp);
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ /*
|
|
82
|
+ * 将时间戳转换为时间
|
|
83
|
+ */
|
|
84
|
+ public static String stampToDate(String s){
|
|
85
|
+ String res;
|
|
86
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
87
|
+ long lt = new Long(s);
|
|
88
|
+ Date date = new Date(lt);
|
|
89
|
+ res = simpleDateFormat.format(date);
|
|
90
|
+ return res;
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ public static void main(String[] args) {
|
|
94
|
+ System.out.println(stampToDate("1504689208643"));
|
|
95
|
+ System.out.println(getTimeStamp(getSysDateTime()));
|
|
96
|
+ }
|
|
97
|
+ public static String getBHS(String BHS){
|
|
98
|
+ String[] str = BHS.split(",");
|
|
99
|
+ StringBuffer sb = new StringBuffer();
|
|
100
|
+ for(int i=0;i<str.length;i++){
|
|
101
|
+ sb.append("'").append(str[i]).append("'").append(",");
|
|
102
|
+ }
|
|
103
|
+ String s=sb.toString();
|
|
104
|
+ String t=s.substring(0,s.length()-1);
|
|
105
|
+ return t;
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ //判断字段值是为空 不为空返回ture
|
|
109
|
+ public static boolean isnotnull(Object name){
|
|
110
|
+ return (null!=name&&!"".equals(name) && !"null".equals(name) && "null" != name);
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ //判断字段值是为空,为空返回ture
|
|
114
|
+ public static boolean isnull(Object name){
|
|
115
|
+ return (null==name || "".equals(name) || "null".equals(name) || "null" == name);
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+ //判断字段值是相等 相等返回ture
|
|
119
|
+ public static boolean isequal(Object name,Object value){
|
|
120
|
+ if(name==value||name.equals(value)){
|
|
121
|
+ return true;
|
|
122
|
+ }
|
|
123
|
+ return false;
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ /**
|
|
127
|
+ * 判断list和str数组是否全等
|
|
128
|
+ * @param list
|
|
129
|
+ * @param str
|
|
130
|
+ * @return
|
|
131
|
+ */
|
|
132
|
+ public static boolean isAllequal(List<String> list,String[] str){
|
|
133
|
+ boolean isbz = true;
|
|
134
|
+ for(int z=0;z<str.length;z++){
|
|
135
|
+ if(!isequal(list.get(z),str[z])){
|
|
136
|
+ isbz = false;
|
|
137
|
+ break;
|
|
138
|
+ }
|
|
139
|
+ }
|
|
140
|
+ return !isbz || !(str.length == list.size());
|
|
141
|
+ }
|
|
142
|
+
|
|
143
|
+ //判断字段值是否在某个集合里 在返回ture
|
|
144
|
+ public static boolean isallequal(Object name,String[] value){
|
|
145
|
+ for(int i=0;i<value.length;i++){
|
|
146
|
+ if(name==value[i]||name.equals(value[i])){
|
|
147
|
+ return true;
|
|
148
|
+ }
|
|
149
|
+ }
|
|
150
|
+ return false;
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ /**
|
|
154
|
+ * 从properties得到路径
|
|
155
|
+ * @param filePath
|
|
156
|
+ * @return
|
|
157
|
+ */
|
|
158
|
+ public static Properties readProperties(String filePath) {
|
|
159
|
+ Properties props = new Properties();
|
|
160
|
+ try {
|
|
161
|
+ InputStream in = new BufferedInputStream(ParameterUtil.class.getResourceAsStream(filePath));
|
|
162
|
+ props.load(in);
|
|
163
|
+ } catch (Exception e) {
|
|
164
|
+ e.printStackTrace();
|
|
165
|
+ }
|
|
166
|
+ return props;
|
|
167
|
+ }
|
|
168
|
+
|
|
169
|
+ /**
|
|
170
|
+ * 获取6位随机码
|
|
171
|
+ * @param num 随机数位数
|
|
172
|
+ * @return String 返回随机数
|
|
173
|
+ */
|
|
174
|
+ public static String randomCode(int num) {
|
|
175
|
+ StringBuilder str = new StringBuilder();
|
|
176
|
+ Random random = new Random();
|
|
177
|
+ for (int i = 0; i < num; i++) {
|
|
178
|
+ str.append(random.nextInt(10));
|
|
179
|
+ }
|
|
180
|
+ return str.toString();
|
|
181
|
+ }
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+ //修改一个list
|
|
185
|
+ public static List<Map<String, Object>> slashCapitals(List<Map<String, Object>> list){
|
|
186
|
+ List<Map<String, Object>> listData = new ArrayList<Map<String,Object>>();
|
|
187
|
+ if(isnull(list)){
|
|
188
|
+ return listData;
|
|
189
|
+ }
|
|
190
|
+ Map<String,Object> data = new HashMap<String, Object>();
|
|
191
|
+ //循环list修改map
|
|
192
|
+ for (Map<String,Object> hcData : list) {
|
|
193
|
+ //循环修改一条数据
|
|
194
|
+ data = slashCapitals(hcData);
|
|
195
|
+ listData.add(data);
|
|
196
|
+ }
|
|
197
|
+ return listData;
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ //修改一条map数据
|
|
201
|
+ public static Map<String, Object> slashCapitals(Map<String, Object> map){
|
|
202
|
+ Map<String,Object> data = new HashMap<String, Object>();
|
|
203
|
+ if(isnull(map)){
|
|
204
|
+ return data;
|
|
205
|
+ }
|
|
206
|
+ //循环修改一条数据
|
|
207
|
+ for (Map.Entry<String,Object> entry: map.entrySet()) {
|
|
208
|
+ //字符串缓冲区
|
|
209
|
+ StringBuffer sbf = new StringBuffer();
|
|
210
|
+ //获取map的key值
|
|
211
|
+ String strs = slashCapital(entry.getKey());
|
|
212
|
+ // 转换成字符数组
|
|
213
|
+ char[] ch = strs.toCharArray();
|
|
214
|
+ // 首字母换小写
|
|
215
|
+ ch[0] = (char) (ch[0] + 32);
|
|
216
|
+ sbf.append(ch);
|
|
217
|
+ //添加key和value进入新的返回map
|
|
218
|
+ data.put(sbf.toString(),entry.getValue());
|
|
219
|
+ }
|
|
220
|
+ return data;
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ /** 方法说明 :带 _ 后第一个字母 转换成大写
|
|
224
|
+ * @return :String
|
|
225
|
+ * @author :HFanss
|
|
226
|
+ **/
|
|
227
|
+ public static String slashCapital(String str){
|
|
228
|
+ //字符串缓冲区
|
|
229
|
+ StringBuffer sbf = new StringBuffer();
|
|
230
|
+ //如果字符串包含下划线
|
|
231
|
+ if (str.contains("_")){
|
|
232
|
+ //按下划线来切割字符串为数组
|
|
233
|
+ String[] split = str.split("_");
|
|
234
|
+ //循环数组操作其中的字符串
|
|
235
|
+ for (int i = 0, index = split.length; i<index; i++) {
|
|
236
|
+ //递归调用方法
|
|
237
|
+ String upperTable = slashCapital(split[i]);
|
|
238
|
+ //添加到字符串缓冲区
|
|
239
|
+ sbf.append(upperTable);
|
|
240
|
+ }
|
|
241
|
+ }else{// 字符串不包含下划线
|
|
242
|
+ // 转换成字符数组
|
|
243
|
+ char[] ch = str.toCharArray();
|
|
244
|
+ // 判断首字母是否是字母
|
|
245
|
+ if (ch[0] >= 'a' && ch[0] <= 'z'){
|
|
246
|
+ // 利用ASCII码实现大写
|
|
247
|
+ ch[0] = (char) (ch[0] - 32);
|
|
248
|
+ }
|
|
249
|
+ // 添加进字符串缓存区
|
|
250
|
+ sbf.append(ch);
|
|
251
|
+ }
|
|
252
|
+ // 返回
|
|
253
|
+ return sbf.toString();
|
|
254
|
+ }
|
|
255
|
+
|
|
256
|
+ public static String dellOneDay(String time) {
|
|
257
|
+ String add = null;
|
|
258
|
+ try {
|
|
259
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
260
|
+ java.util.Date timeNow = df.parse(time);
|
|
261
|
+ Calendar begin=Calendar.getInstance();
|
|
262
|
+ begin.setTime(timeNow);
|
|
263
|
+ begin.add(Calendar.DAY_OF_MONTH,-1);
|
|
264
|
+ add = df.format(begin.getTime());
|
|
265
|
+ } catch (Exception e) {
|
|
266
|
+ e.printStackTrace();
|
|
267
|
+ }
|
|
268
|
+ return add;
|
|
269
|
+ }
|
|
270
|
+}
|