schedule4util.jsp
10.9 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
<%@ page import="com.engine.kq.biz.KQTimesArrayComInfo" %>
<%@ page import="com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean" %>
<%@ page import="com.engine.kq.util.KQDurationCalculatorUtil" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.time.LocalDateTime" %>
<%@ page import="java.time.ZoneOffset" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="java.util.List" %>
<%@ page import="weaver.general.Util" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
try {
String userids = Util.null2String(request.getParameter("userids"));
String fromdatetime = Util.null2String(request.getParameter("fromdatetime"));
String mimilliseconds = Util.null2String(request.getParameter("mimilliseconds"));
if(userids.length() == 0){
out.println("param userids is null:<br/>");
return ;
}
if(fromdatetime.length() == 0){
out.println("param fromdatetime is null:<br/>");
return ;
}
if(mimilliseconds.length() == 0){
out.println("param mimilliseconds is null:<br/>");
return ;
}
int userid = Util.getIntValue(userids);
long mimillisecond = Long.parseLong(mimilliseconds);
//最大循环次数是7次
int max_day = 14;
KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo();
DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter timeMinFormatter = DateTimeFormatter.ofPattern("HH:mm");
DateTimeFormatter ssFormatter = DateTimeFormatter.ofPattern("ss");
LocalDateTime localDateTime = LocalDateTime.parse(fromdatetime, fullFormatter);
String timeMin = localDateTime.toLocalTime().format(timeMinFormatter);
//秒
String timeSS = localDateTime.toLocalTime().format(ssFormatter);
int firstDayTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(timeMin);
LocalDate curLocalDate =localDateTime.toLocalDate();
long totalCnt = 0L;
long tmp_totalCnt = 0L;
String needDateTime = "";
//负数表示往前推
if(mimillisecond < 0){
mimillisecond = Math.abs(mimillisecond);
for(int i = 0 ; i < max_day ; i++){
String curdate = curLocalDate.format(dateFormatter);
if(needDateTime.length() > 0){
break;
}
ShiftInfoBean shiftInfoBean = KQDurationCalculatorUtil
.getWorkTime(""+userid, curdate,true,false);
if(shiftInfoBean != null){
int restStartIndex = -1;
int restEndIndex = -1;
List<int[]> restIndex = shiftInfoBean.getRestIndex();
for(int r = 0 ; r < restIndex.size();r++){
int[] rests = restIndex.get(r);
if(rests != null && rests.length == 2){
restStartIndex = rests[0];
restEndIndex = rests[1];
}
}
List<int[]> workIndex = shiftInfoBean.getWorkIndex();
//如果有休息时间的话,只能是一次打卡,把工作时段需要拆分长两段
if(restStartIndex > -1 && restEndIndex > -1){
List<int[]> tmpWorkIndex = new ArrayList<>();
int[] tmpWroks = workIndex.get(0);
int[] combined0 = new int[2];
combined0[0] = tmpWroks[0];
combined0[1] = restStartIndex;
int[] combined1 = new int[2];
combined1[0] = restEndIndex;
combined1[1] = tmpWroks[1];
tmpWorkIndex.add(combined0);
tmpWorkIndex.add(combined1);
workIndex = tmpWorkIndex;
}
for(int j = workIndex.size()-1 ; j >= 0;j--){
int[] initArrays = kqTimesArrayComInfo.getInitArr();
int[] works = workIndex.get(j);
if(works != null && works.length == 2){
Arrays.fill(initArrays, works[0], works[1], 0);
int arrayCnt = 0;
if(i == 0){
arrayCnt = kqTimesArrayComInfo.getCnt(initArrays, 0,firstDayTimeIndex,0);
arrayCnt = arrayCnt*60*1000;
}else{
arrayCnt = kqTimesArrayComInfo.getCnt(initArrays, 0,1440,0);
arrayCnt = arrayCnt*60*1000;
}
totalCnt += arrayCnt;
if(totalCnt >= mimillisecond){
long betweenArray = mimillisecond-tmp_totalCnt;
int betweenMins = (int) (betweenArray/(1000*60));
if(i == 0){
if(firstDayTimeIndex >= works[0] && firstDayTimeIndex <= works[1]){
int needMin = firstDayTimeIndex-betweenMins;
needDateTime = shiftInfoBean.getSplitDate()+" "+kqTimesArrayComInfo.getTimesByArrayindex(needMin);
}else{
int needMin = works[1]-betweenMins;
needDateTime = shiftInfoBean.getSplitDate()+" "+kqTimesArrayComInfo.getTimesByArrayindex(needMin);
}
}else{
int needMin = works[1]-betweenMins;
needDateTime = shiftInfoBean.getSplitDate()+" "+kqTimesArrayComInfo.getTimesByArrayindex(needMin);
}
break;
}
tmp_totalCnt = totalCnt;
}
}
}
curLocalDate =curLocalDate.minusDays(1);
}
}else{
for(int i = 0 ; i < max_day ; i++){
String curdate = curLocalDate.format(dateFormatter);
if(needDateTime.length() > 0){
break;
}
ShiftInfoBean shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(""+userid, curdate,true,false);
if(shiftInfoBean != null){
int restStartIndex = -1;
int restEndIndex = -1;
List<int[]> restIndex = shiftInfoBean.getRestIndex();
for(int r = 0 ; r < restIndex.size();r++){
int[] rests = restIndex.get(r);
if(rests != null && rests.length == 2){
restStartIndex = rests[0];
restEndIndex = rests[1];
}
}
List<int[]> workIndex = shiftInfoBean.getWorkIndex();
//如果有休息时间的话,只能是一次打卡,把工作时段需要拆分长两段
if(restStartIndex > -1 && restEndIndex > -1){
List<int[]> tmpWorkIndex = new ArrayList<>();
int[] tmpWroks = workIndex.get(0);
int[] combined0 = new int[2];
combined0[0] = tmpWroks[0];
combined0[1] = restStartIndex;
int[] combined1 = new int[2];
combined1[0] = restEndIndex;
combined1[1] = tmpWroks[1];
tmpWorkIndex.add(combined0);
tmpWorkIndex.add(combined1);
workIndex = tmpWorkIndex;
}
for(int j = 0 ; j < workIndex.size();j++){
int[] initArrays = kqTimesArrayComInfo.getInitArr();
int[] works = workIndex.get(j);
if(works != null && works.length == 2){
Arrays.fill(initArrays, works[0], works[1], 0);
int arrayCnt = 0;
if(i == 0){
arrayCnt = kqTimesArrayComInfo.getCnt(initArrays, firstDayTimeIndex,1440,0);
arrayCnt = arrayCnt*60*1000;
}else{
arrayCnt = kqTimesArrayComInfo.getCnt(initArrays, 0,1440,0);
arrayCnt = arrayCnt*60*1000;
}
totalCnt += arrayCnt;
out.print(curdate+":arrayCnt:"+ arrayCnt+":totalCnt:"+ totalCnt+":mimillisecond:"+mimillisecond+"::"+(totalCnt >= mimillisecond) +"<br/>");
if(totalCnt >= mimillisecond){
long betweenArray = mimillisecond-tmp_totalCnt;
int betweenMins = (int) (betweenArray/(1000*60));
if(i == 0){
if(firstDayTimeIndex >= works[0] && firstDayTimeIndex <= works[1]){
int needMin = firstDayTimeIndex+betweenMins;
needDateTime = shiftInfoBean.getSplitDate()+" "+kqTimesArrayComInfo.getTimesByArrayindex(needMin);
}else{
int needMin = works[0]+betweenMins;
needDateTime = shiftInfoBean.getSplitDate()+" "+kqTimesArrayComInfo.getTimesByArrayindex(needMin);
}
}else{
int needMin = works[0]+betweenMins;
needDateTime = shiftInfoBean.getSplitDate()+" "+kqTimesArrayComInfo.getTimesByArrayindex(needMin);
}
break;
}
tmp_totalCnt = totalCnt;
}
}
}
curLocalDate =curLocalDate.plusDays(1);
}
}
if(needDateTime.length() > 0){
needDateTime += ":"+timeSS;
out.print("结果:"+LocalDateTime.parse(needDateTime, fullFormatter).toInstant(ZoneOffset.of("+8")).toEpochMilli()+"<br/>");
}else{
out.print("结果:"+0L+"<br/>");
}
} catch (Exception e) {
e.printStackTrace();
out.print(e.getMessage());
}
%>