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 6e0b8abd
authored
Nov 14, 2023
by
刘鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ID1004088): 博西PEA_V1.0-工作台-工程师:修改工程师上下班时间后,工程师个人容量计算不准确
1 parent
9db35015
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
3 deletions
project-order/src/main/java/com/dituhui/pea/order/scheduler/CalcEngineerCapacityScheduler.java
project-order/src/main/java/com/dituhui/pea/order/scheduler/CalcEngineerCapacityScheduler.java
View file @
6e0b8ab
...
...
@@ -11,6 +11,7 @@ import com.dituhui.pea.order.dao.EngineerBusinessDao;
import
com.dituhui.pea.order.dao.EngineerInfoDao
;
import
com.dituhui.pea.order.dao.EngineerSliceUsedCapacityDao
;
import
com.dituhui.pea.order.dao.OrderInfoDao
;
import
com.dituhui.pea.order.dao.TimeSliceDao
;
import
com.dituhui.pea.order.entity.CapacityEngineerSliceUsedEntity
;
import
com.dituhui.pea.order.entity.CapacityEngineerStatEntity
;
import
com.dituhui.pea.order.entity.EngineerBusinessEntity
;
...
...
@@ -19,6 +20,7 @@ import com.dituhui.pea.order.entity.OrderInfoEntity;
import
com.dituhui.pea.order.entity.TimeSliceEntity
;
import
com.dituhui.pea.order.service.EngineerCalendarService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Scheduled
;
...
...
@@ -30,10 +32,12 @@ import java.time.LocalDateTime;
import
java.time.LocalTime
;
import
java.time.ZoneId
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
@Slf4j
...
...
@@ -57,6 +61,8 @@ public class CalcEngineerCapacityScheduler {
private
EngineerSliceUsedCapacityDao
engineerSliceUsedCapacityDao
;
@Autowired
private
EngineerCalendarService
engineerCalendarService
;
@Autowired
private
TimeSliceDao
timeSliceDao
;
@Scheduled
(
cron
=
"${scheduler.calc-engineer-capacity.cron-expr}"
)
public
void
run
()
{
...
...
@@ -108,8 +114,9 @@ public class CalcEngineerCapacityScheduler {
})
.
collect
(
Collectors
.
toList
());
initOneEngineerTimeSlot
(
date
,
engineerCode
,
configs
,
orders
);
List
<
TimeSliceEntity
>
commonTimeSliceList
=
timeSliceDao
.
findByType
(
"HOURS"
);
initOneEngineerTimeSlot
(
date
,
engineerCode
,
configs
,
orders
,
commonTimeSliceList
);
caculateEngineerOneDay
(
date
,
businessEntity
,
orders
,
configs
,
statEntity
);
capacityEngineerStatDao
.
save
(
statEntity
);
}
...
...
@@ -125,20 +132,51 @@ public class CalcEngineerCapacityScheduler {
List
<
OccupyInfoDetail
>
durationTime
=
CapacityUtils
.
getMaxRemainBlock
(
startTime
,
endTime
,
occupyInfo
);
long
maxRemainBlock
=
durationTime
.
stream
().
mapToLong
(
OccupyInfoDetail:
:
getDuration
).
max
().
orElse
(
0L
);
//总时长
long
total
=
Duration
.
between
(
startTime
,
endTime
).
abs
().
toMinutes
();
statEntity
.
setCapTotal
((
int
)
total
);
statEntity
.
setOrderCount
(
orders
.
size
());
statEntity
.
setCapUsed
((
int
)
totalUseTime
);
statEntity
.
setCapLeft
(
statEntity
.
getCapTotal
()
-
(
int
)
totalUseTime
);
statEntity
.
setCapLeft
(
(
int
)
total
-
(
int
)
totalUseTime
);
statEntity
.
setMaxDuration
((
int
)
maxRemainBlock
);
statEntity
.
setUpdateTime
(
LocalDateTime
.
now
());
}
//添加工程师日历参数
private
void
initOneEngineerTimeSlot
(
String
date
,
String
engineerCode
,
List
<
OccupyInfoDetail
>
configs
,
List
<
OrderInfoEntity
>
orders
)
{
List
<
OrderInfoEntity
>
orders
,
List
<
TimeSliceEntity
>
commonTimeSliceList
)
{
final
LocalDate
localDate
=
LocalDate
.
parse
(
date
,
DateTimeUtil
.
DATE_FORMAT
);
//查询时间片容量
List
<
CapacityEngineerSliceUsedEntity
>
engineerTimeSlice
=
engineerSliceUsedCapacityDao
.
findByWorkdayAndEngineerCode
(
date
,
engineerCode
);
//查询哪些时间片需要新增, 哪些时间片需要删除
List
<
TimeSliceEntity
>
timeCorridor
=
engineerTimeSlice
(
engineerCode
,
date
,
commonTimeSliceList
);
//需要删除的时间片记录
List
<
CapacityEngineerSliceUsedEntity
>
needDeleteTimeSlice
=
engineerTimeSlice
.
stream
()
.
filter
(
t
->
timeCorridor
.
stream
().
noneMatch
(
ti
->
Objects
.
equals
(
ti
,
t
.
getTimmeSlice
())))
.
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isNotEmpty
(
needDeleteTimeSlice
))
{
engineerTimeSlice
.
removeAll
(
needDeleteTimeSlice
);
engineerSliceUsedCapacityDao
.
deleteAll
(
needDeleteTimeSlice
);
engineerSliceUsedCapacityDao
.
flush
();
}
//需要增加的时间切片
List
<
CapacityEngineerSliceUsedEntity
>
needAdd
=
timeCorridor
.
stream
()
.
filter
(
slice
->
engineerTimeSlice
.
stream
()
.
map
(
CapacityEngineerSliceUsedEntity:
:
getTimmeSlice
).
noneMatch
(
ti
->
Objects
.
equals
(
ti
,
slice
))
).
map
(
timeSlice
->
{
CapacityEngineerSliceUsedEntity
r
=
new
CapacityEngineerSliceUsedEntity
();
r
.
setTimmeSlice
(
timeSlice
);
r
.
setEngineerCode
(
engineerCode
);
r
.
setWorkday
(
date
);
LocalTime
sliceStartLocalTime
=
LocalTime
.
parse
(
timeSlice
.
getStart
(),
DateUtil
.
TIME_FORMATTER
);
LocalTime
sliceEndLocalTime
=
LocalTime
.
parse
(
timeSlice
.
getEnd
(),
DateUtil
.
TIME_FORMATTER
);
r
.
setCapTotal
(
DateTimeUtil
.
betweenTwoTime
(
sliceStartLocalTime
,
sliceEndLocalTime
,
TimeUnit
.
MINUTES
));
r
.
setCreateTime
(
LocalDateTime
.
now
());
return
r
;
}).
collect
(
Collectors
.
toList
());
engineerTimeSlice
.
addAll
(
needAdd
);
for
(
CapacityEngineerSliceUsedEntity
sliceCap
:
engineerTimeSlice
)
{
final
TimeSliceEntity
timeSlice
=
sliceCap
.
getTimmeSlice
();
LocalTime
sliceStartLocalTime
=
LocalTime
.
parse
(
timeSlice
.
getStart
(),
DateUtil
.
TIME_FORMATTER
);
...
...
@@ -164,4 +202,35 @@ public class CalcEngineerCapacityScheduler {
engineerSliceUsedCapacityDao
.
saveAll
(
engineerTimeSlice
);
}
private
List
<
TimeSliceEntity
>
engineerTimeSlice
(
String
engineerCode
,
String
date
,
List
<
TimeSliceEntity
>
commonTimeSliceList
)
{
EngineerBusinessEntity
businessEntity
=
engineerBusinessDao
.
getByEngineerCode
(
engineerCode
);
LocalDateTime
workStartTime
=
DateUtils
.
localDateTimeFromStr
(
String
.
format
(
"%s %s:00"
,
date
,
businessEntity
.
getWorkOn
()));
LocalDateTime
workEndTime
=
DateUtils
.
localDateTimeFromStr
(
String
.
format
(
"%s %s:00"
,
date
,
businessEntity
.
getWorkOff
()));
return
getTimeSliceEntities
(
workStartTime
,
workEndTime
,
commonTimeSliceList
);
}
private
List
<
TimeSliceEntity
>
getTimeSliceEntities
(
LocalDateTime
workStartTime
,
LocalDateTime
workEndTime
,
List
<
TimeSliceEntity
>
commonTimeSliceList
)
{
//切片开始时间
LocalTime
sliceStartHour
=
LocalTime
.
of
(
workStartTime
.
getHour
(),
0
);
//切片结束时间
LocalTime
sliceEndHour
;
int
minuteOfHour
=
workEndTime
.
getMinute
();
if
(
minuteOfHour
>
0
)
{
sliceEndHour
=
LocalTime
.
of
(
workEndTime
.
getHour
(),
0
).
plusHours
(
1
);
}
else
{
sliceEndHour
=
LocalTime
.
of
(
workEndTime
.
getHour
(),
0
);
}
List
<
TimeSliceEntity
>
timeCorridor
=
commonTimeSliceList
.
stream
()
.
filter
(
slice
->
{
LocalTime
startLocalTime
=
LocalTime
.
parse
(
slice
.
getStart
(),
DateUtil
.
TIME_FORMATTER
);
LocalTime
endLocalTime
=
LocalTime
.
parse
(
slice
.
getEnd
(),
DateUtil
.
TIME_FORMATTER
);
return
(
startLocalTime
.
isAfter
(
sliceStartHour
)
&&
endLocalTime
.
isBefore
(
sliceEndHour
))
||
(
startLocalTime
.
equals
(
sliceStartHour
)
||
endLocalTime
.
equals
(
sliceEndHour
));
}).
sorted
(
Comparator
.
comparing
(
TimeSliceEntity:
:
getId
)).
collect
(
Collectors
.
toList
());
return
timeCorridor
;
}
}
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