CZT
2023-11-10 24da09489db83167c91f5920a92ea19f29d96829
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
package com.fzzy.api.utils;
 
import com.fzzy.api.Constant;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
 
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;
 
/**
 *
 */
public class ContextUtil {
 
 
    public static String getUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
 
    public static String getCurTimeMillis() {
        return System.currentTimeMillis() + "";
    }
 
 
    /**
     * 根据当前时间获取只有 yyyy-MM-dd的时间
     *
     * @param date
     * @return
     */
    public static Date getCurZero(Date date) {
        //TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
        date = DateUtils.setHours(date, 0);
        date = DateUtils.setMinutes(date, 0);
        date = DateUtils.setSeconds(date, 0);
        date = DateUtils.setMilliseconds(date, 0);
        return date;
    }
 
    /**
     * 获取当前时间下一天的零点零分零秒
     *
     * @param date
     * @return
     */
    public static Date getNextZero(Date date) {
        //TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
        date = DateUtils.addDays(date, 1);
        date = DateUtils.setHours(date, 0);
        date = DateUtils.setMinutes(date, 0);
        date = DateUtils.setSeconds(date, 0);
        date = DateUtils.setMilliseconds(date, 0);
        return date;
    }
 
    /**
     * 根据时间获取当前时间星期
     * <p>
     * 周日=1,周一=2
     *
     * @param date
     * @return
     */
    public static int getDayOfWeek(Date date) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        return now.get(Calendar.DAY_OF_WEEK);
    }
 
    /**
     * 获取当前时间在一天中的时间 24小时制
     *
     * @param date
     * @return
     */
    public static int getHourOfDay(Date date) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
 
        return now.get(Calendar.HOUR_OF_DAY);
    }
 
 
 
    /**
     * 获取时间在当前小时中的分钟
     *
     * @param date
     * @return
     */
    public static int getMinuteOfHour(Date date) {
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        return now.get(Calendar.MINUTE);
    }
 
 
    public static void main(String[] args) {
//        Date date = new Date();
//        int i = ContextUtil.getMinuteOfHour(date);
//
//        System.out.println(i);
        String str = null;
        String [] s= str.split("-");
        System.out.println( Integer.valueOf(s[0]));
    }
 
 
    /**
     * 最高的编码为:组织编码,然后逐级往下,如:5013,5013_001,5013_002,5013_001_001
     *
     * @param companyId 必须
     * @param parentId  可空
     * @param endId     可空
     * @param format    必须 三位传1000,四位传10000
     * @return
     */
    public static String getNextId(String companyId, String parentId,
                                   String endId, int format) {
        if (parentId == null || Constant.DEFAULT_PARENT_CODE.equals(parentId)) {
            return companyId;
        }
        try {
            int endNum = 0;
            if (StringUtils.isNotEmpty(endId)) {
                endNum = Integer.valueOf(endId.substring(endId.length() - 3));
            }
            String endStr = ("" + (endNum + format + 1)).substring(1);
 
            if (parentId.equals(companyId)) {
                return companyId + "_" + endStr;
            }
            parentId = parentId.substring(parentId.lastIndexOf("_") + 1);
            return companyId + "_" + parentId + "_" + endStr;
 
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}