Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 087edfee
authored
Nov 02, 2023
by
刘鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(时间片容量): 时间片交集运算 以及并集运算修改
1 parent
fa12213f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
5 deletions
project-order/src/main/java/com/dituhui/pea/order/common/CapacityUtils.java
project-order/src/main/java/com/dituhui/pea/order/common/OccupyInfoDetail.java
project-order/src/test/java/com/dituhui/pea/order/common/CapacityUtilsTest.java
project-order/src/main/java/com/dituhui/pea/order/common/CapacityUtils.java
View file @
087edfe
...
@@ -231,8 +231,13 @@ public class CapacityUtils {
...
@@ -231,8 +231,13 @@ public class CapacityUtils {
//计算最大空闲时间
//计算最大空闲时间
List
<
Long
>
engineerMaxDurationList
=
new
ArrayList
<>();
List
<
Long
>
engineerMaxDurationList
=
new
ArrayList
<>();
engineerSliceMap
.
forEach
((
engineerCode
,
t
)
->
{
engineerSliceMap
.
forEach
((
engineerCode
,
t
)
->
{
long
engineerMaxDuration
=
t
.
stream
().
map
(
CapacityEngineerSliceUsedEntity:
:
getDurationTime
)
.
flatMap
(
Collection:
:
stream
)
List
<
OccupyInfoDetail
>
timeSlots
=
t
.
stream
().
map
(
CapacityEngineerSliceUsedEntity:
:
getDurationTime
)
.
flatMap
(
Collection:
:
stream
).
collect
(
Collectors
.
toList
());
timeSlots
=
calculateUnion
(
timeSlots
);
long
engineerMaxDuration
=
Optional
.
ofNullable
(
timeSlots
).
orElse
(
Collections
.
emptyList
())
.
stream
()
.
mapToLong
(
OccupyInfoDetail:
:
getDuration
)
.
mapToLong
(
OccupyInfoDetail:
:
getDuration
)
.
sum
();
.
sum
();
engineerMaxDurationList
.
add
(
engineerMaxDuration
);
engineerMaxDurationList
.
add
(
engineerMaxDuration
);
...
...
project-order/src/main/java/com/dituhui/pea/order/common/OccupyInfoDetail.java
View file @
087edfe
...
@@ -6,8 +6,6 @@ import lombok.NoArgsConstructor;
...
@@ -6,8 +6,6 @@ import lombok.NoArgsConstructor;
import
lombok.experimental.Accessors
;
import
lombok.experimental.Accessors
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.List
;
@EqualsAndHashCode
(
callSuper
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@Data
...
@@ -31,8 +29,11 @@ public class OccupyInfoDetail extends OccupyInfo implements Comparable<OccupyInf
...
@@ -31,8 +29,11 @@ public class OccupyInfoDetail extends OccupyInfo implements Comparable<OccupyInf
// 判断两个时间片是否有交集
// 判断两个时间片是否有交集
public
boolean
overlaps
(
OccupyInfoDetail
other
)
{
public
boolean
overlaps
(
OccupyInfoDetail
other
)
{
// 如果一个时间片的开始时间在另一个时间片的结束时间之后,或者一个时间片的结束时间在另一个时间片的开始时间之前,那么他们没有交集
// 如果一个时间片的开始时间在另一个时间片的结束时间之后,或者一个时间片的结束时间在另一个时间片的开始时间之前,那么他们没有交集
return
!(
this
.
beginTime
.
isAfter
(
other
.
endTime
)
||
this
.
endTime
.
isBefore
(
other
.
beginTime
));
LocalDateTime
maxStart
=
this
.
beginTime
.
isAfter
(
other
.
beginTime
)
?
this
.
beginTime
:
other
.
beginTime
;
LocalDateTime
minEnd
=
this
.
endTime
.
isAfter
(
other
.
endTime
)
?
other
.
endTime
:
this
.
endTime
;
return
maxStart
.
isBefore
(
minEnd
);
}
}
// 计算两个时间片的交集
// 计算两个时间片的交集
public
OccupyInfoDetail
intersection
(
OccupyInfoDetail
other
)
{
public
OccupyInfoDetail
intersection
(
OccupyInfoDetail
other
)
{
// 如果两个时间片没有交集,返回null
// 如果两个时间片没有交集,返回null
...
...
project-order/src/test/java/com/dituhui/pea/order/common/CapacityUtilsTest.java
View file @
087edfe
...
@@ -81,5 +81,29 @@ public class CapacityUtilsTest {
...
@@ -81,5 +81,29 @@ public class CapacityUtilsTest {
Assertions
.
assertEquals
(
2
,
occupyInfoDetails1
.
size
());
Assertions
.
assertEquals
(
2
,
occupyInfoDetails1
.
size
());
}
}
@Test
public
void
testOverlaps
()
{
OccupyInfoDetail
fixedTime
=
new
OccupyInfoDetail
(
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
of
(
9
,
0
)
),
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
of
(
11
,
0
)));
OccupyInfoDetail
dynaTime
=
new
OccupyInfoDetail
(
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
of
(
9
,
0
)
),
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
of
(
11
,
0
)));
Assertions
.
assertTrue
(
fixedTime
.
overlaps
(
dynaTime
));
dynaTime
=
new
OccupyInfoDetail
(
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
of
(
10
,
0
)
),
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
of
(
11
,
0
)));
Assertions
.
assertTrue
(
fixedTime
.
overlaps
(
dynaTime
));
dynaTime
=
new
OccupyInfoDetail
(
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
of
(
11
,
0
)
),
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
of
(
12
,
0
)));
Assertions
.
assertFalse
(
fixedTime
.
overlaps
(
dynaTime
));
dynaTime
=
new
OccupyInfoDetail
(
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
of
(
8
,
0
)
),
LocalDateTime
.
of
(
LocalDate
.
now
(),
LocalTime
.
of
(
9
,
0
)));
Assertions
.
assertFalse
(
fixedTime
.
overlaps
(
dynaTime
));
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment