Helius
2021-06-29 5252d1396e21a16774be699a5ba1c8d39c14a22e
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
package com.xzx.gc.util;
 
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import com.xzx.gc.util.enums.EvaluationLabelType;
import org.springframework.stereotype.Service;
 
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
 
@Service
public  class DateUtil {
 
 
 
    public static List<Map<String,String>> query12WeekStartTimeAndEndTime(){
        List<Map<String, Date>> list = new ArrayList<>();
        for(int i = 0, h = 7; i <= 12; i++){
            list.add(getLastWeek(h * i));
        }
 
        List<Map<String, String>> result = new ArrayList<>();
        for(Map<String, Date> map : list){
            Map<String,String> resultMap = new HashMap<>();
            String startTime = cn.hutool.core.date.DateUtil.formatDate(map.get("monday"))+" 00:00:00";
            String endTime = cn.hutool.core.date.DateUtil.formatDate(map.get("sunday"))+" 23:59:59";
            resultMap.put("startTime",startTime);
            resultMap.put("endTime",endTime);
            result.add(resultMap);
        }
        return result;
    }
    public static Map<String, Date> getLastWeek(int days) {
        Map<String, Date> map = new HashMap<String, Date>();
        Calendar cal = Calendar.getInstance();
        int n = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (n == 0) {
            n = 7;
        }
        // 上周一的日期
        cal.add(Calendar.DATE, -(days + (n - 1)));
        Date monday = cal.getTime();
        map.put("monday", monday);
 
        cal.add(Calendar.DATE, 1);
        Date tuesday = cal.getTime();
        map.put("tuesday", tuesday);
 
        cal.add(Calendar.DATE, 1);
        Date wednesday = cal.getTime();
        map.put("wednesday", wednesday);
 
        cal.add(Calendar.DATE, 1);
        Date thursday = cal.getTime();
        map.put("thursday", thursday);
 
        cal.add(Calendar.DATE, 1);
        Date friday = cal.getTime();
        map.put("friday", friday);
 
        cal.add(Calendar.DATE, 1);
        Date saturday = cal.getTime();
        map.put("saturday", saturday);
 
        cal.add(Calendar.DATE, 1);
        Date sunday = cal.getTime();
        map.put("sunday", sunday);
        return map;
    }
 
 
    public static List<Map<String,String>> query12MonthStartTimeAndEndTime() {
        List<Map<String,String>> list = new ArrayList<>();
        String[] latest12Month = getLatest12Month();
        for(String s : latest12Month){
            Map<String, String> m = new HashMap<>();
            m.put("startTime", s + "-01 00:00:00");
            m.put("endTime", s + "-31 23:59:59");
            list.add(m);
        }
 
 
        for(int i=0;i<list.size();i++){
            for(int j=0;j<list.size()-i-1;j++){
                if(list.get(j).get("startTime").compareTo(list.get(j+1).get("startTime"))<0){
                    Map<String,String> r=list.get(j);
                    list.set(j, list.get(j+1));
                    list.set(j+1, r);
                }
            }
        }
        return list;
    }
 
    public static String fillZero(int i){
        String month = "";
        if(i<10){
            month = "0" + i;
        }else{
            month = String.valueOf(i);
        }
        return month;
    }
 
    public static String[] getLatest12Month(){
        String[] latest12Months = new String[12];
        Calendar cal = Calendar.getInstance();
        //要先+1,才能把本月的算进去
        cal.set(Calendar.MONTH, cal.get(Calendar.MONTH)+1);
        for(int i=0; i<12; i++){
            //逐次往前推1个月
            cal.set(Calendar.MONTH, cal.get(Calendar.MONTH)-1);
            latest12Months[11-i] = cal.get(Calendar.YEAR)+ "-" +fillZero(cal.get(Calendar.MONTH)+1);
        }
        return latest12Months;
    }
 
 
 
 
    /**
     *字符串的日期格式的计算
     */
    public static int daysBetween(String smdate,String bdate) throws ParseException{
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(sdf.parse(smdate));
        long time1 = cal.getTimeInMillis();
        cal.setTime(sdf.parse(bdate));
        long time2 = cal.getTimeInMillis();
        long between_days=(time2-time1)/(1000*3600*24);
 
        return Integer.parseInt(String.valueOf(between_days));
    }
 
    public static boolean isSorted(List<String> listOfStrings, int index) {
        if (index < 2) {
            return true;
        } else if (listOfStrings.get(index - 2).compareTo(listOfStrings.get(index - 1)) > 0) {
            System.out.println(listOfStrings.get(index - 2)+"============"+listOfStrings.get(index - 1));
            return false;
        } else {
            return isSorted(listOfStrings, index - 1);
        }
    }
 
    public static int getCaseByType(String type){
        if(EvaluationLabelType.ONE_TYPE.equals(type)){
            return 1;
        }else if(EvaluationLabelType.TWO_TYPE.equals(type)){
            return 2;
        }else if(EvaluationLabelType.THREE_TYPE.equals(type)){
            return 3;
        }else if(EvaluationLabelType.FOUR_TYPE.equals(type)){
            return 4;
        }else if(EvaluationLabelType.FIVE_TYPE.equals(type)){
            return 5;
        }else if(EvaluationLabelType.SIX_TYPE.equals(type)){
            return 6;
        }else if(EvaluationLabelType.SENVEN_TYPE.equals(type)){
            return 7;
        }else if(EvaluationLabelType.EIGHT_TYPE.equals(type)){
            return 8;
        }else if(EvaluationLabelType.NINE_TYPE.equals(type)){
            return 9;
        }else if(EvaluationLabelType.TEN_TYPE.equals(type)){
            return 10;
        }else if(EvaluationLabelType.ELE_TYPE.equals(type)){
            return 11;
        }else if(EvaluationLabelType.TELF_TYPE.equals(type)){
            return 12;
        }else if(EvaluationLabelType.THR_TYPE.equals(type)){
            return 13;
        }else if(EvaluationLabelType.FOR_TYPE.equals(type)){
            return 14;
        }else if(EvaluationLabelType.FIV_TYPE.equals(type)){
            return 15;
        }else if(EvaluationLabelType.SI_TYPE.equals(type)){
            return 16;
        }else if(EvaluationLabelType.SEV_TYPE.equals(type)){
            return 17;
        }else if(EvaluationLabelType.EIG_TYPE.equals(type)){
            return 18;
        }else if(EvaluationLabelType.NIG_TYPE.equals(type)){
            return 19;
        }
        return 0;
    }
 
    public static boolean isBase64(String str) {
        if (str == null || str.trim().length() == 0) {
            return false;
        } else {
            if (str.length() % 4 != 0) {
                return false;
            }
 
            char[] strChars = str.toCharArray();
            for (char c:strChars) {
                if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
                        || c == '+' || c == '/' || c == '=') {
                    continue;
                } else {
                    return false;
                }
            }
            return true;
        }
    }
 
    public  static String generate(String prefix,long datacenterId){
        Snowflake snowflake = IdUtil.createSnowflake(Convert.toLong(0), datacenterId);
        return prefix+snowflake.nextIdStr();
    }
 
   /* public static void main(String[] args) {
        String now = sdf1.format(new Date());
        System.out.println(now);
        int b = checkBig(now,"2019-12-31 14:00:00");
        System.out.println(b);
    }*/
    /**
     *
     * @param s1  时间字符串  注意时间格式要一样哦,不一样你比个毛线
     * @param s2 时间字符串
     * @return 1是s1大    2是s2大   0是俩个一样大   -1是出错了吧
     */
    public static int checkBig(String s1,String s2){
        try {
            if(s1.compareTo(s2) >0){
                return 1;
            }else if(s1.compareTo(s2) <0){
                return 2;
            }else{
                return 0;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }
 
 
    public static String dayForWeek(String pTime) throws Throwable {
 
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
 
        Date tmpDate = format.parse(pTime);
 
        Calendar cal = Calendar.getInstance();
 
        String[] weekDays = { "7", "1", "2", "3", "4", "5", "6" };
 
        try {
 
            cal.setTime(tmpDate);
 
        } catch (Exception e) {
 
            e.printStackTrace();
 
        }
 
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
 
        if (w < 0){
            w = 0;
        }
        return weekDays[w];
 
    }
 
 
    public static boolean isInteger(String s) {
        if (s != null && !"".equals(s.trim())){
            return s.matches("^[0-9]*$");
        }
        else{
            return false;
        }
    }
 
    public static int getDayHour() {
        Calendar cal=Calendar.getInstance(TimeZone.getTimeZone("GMT+8"));
        int hour=cal.get(Calendar.HOUR_OF_DAY);
        return hour;
    }
 
}