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 cf1de4fb
authored
Nov 02, 2023
by
刘鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(容量): 单小时时间片容量计算
增加时间片空闲时间片存储, 移除时间片订单数据统计
1 parent
91f4a25b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
21 deletions
project-order/src/main/java/com/dituhui/pea/order/common/CapacityUtils.java
project-order/src/main/java/com/dituhui/pea/order/common/OccupyInfo.java
project-order/src/main/java/com/dituhui/pea/order/common/OccupyInfoDetail.java
project-order/src/main/java/com/dituhui/pea/order/entity/CapacityEngineerSliceUsedEntity.java
project-order/src/main/java/com/dituhui/pea/order/scheduler/CalcEngineerCapacityScheduler.java
project-order/src/main/java/com/dituhui/pea/order/common/CapacityUtils.java
View file @
cf1de4f
...
...
@@ -101,23 +101,29 @@ public class CapacityUtils {
}
public
static
Long
getMaxRemainBlock
(
LocalDateTime
startTime
,
LocalDateTime
endTime
,
List
<
OccupyInfo
>
occupyInfos
)
{
if
(
org
.
springframework
.
util
.
CollectionUtils
.
isEmpty
(
occupyInfos
))
{
return
Duration
.
between
(
startTime
,
endTime
).
toMinutes
();
public
static
List
<
OccupyInfoDetail
>
getMaxRemainBlock
(
LocalDateTime
startTime
,
LocalDateTime
endTime
,
List
<
OccupyInfo
>
occupyInfos
)
{
//存储空闲时间段
List
<
OccupyInfoDetail
>
leisureTime
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isEmpty
(
occupyInfos
))
{
long
minutes
=
Duration
.
between
(
startTime
,
endTime
).
abs
().
toMinutes
();
OccupyInfoDetail
occupyInfo
=
new
OccupyInfoDetail
(
startTime
,
endTime
,
minutes
);
leisureTime
.
add
(
occupyInfo
);
return
leisureTime
;
}
//空闲时间
List
<
Long
>
idlePeriods
=
new
ArrayList
<>();
LocalDateTime
preLast
=
startTime
;
for
(
OccupyInfo
o
:
occupyInfos
)
{
if
(
o
.
getBeginTime
().
isAfter
(
preLast
))
{
idlePeriods
.
add
(
Duration
.
between
(
startTime
,
o
.
getBeginTime
()).
abs
().
toMinutes
());
long
duraionMiu
=
Duration
.
between
(
startTime
,
o
.
getBeginTime
()).
abs
().
toMinutes
();
leisureTime
.
add
(
new
OccupyInfoDetail
(
startTime
,
o
.
getBeginTime
(),
duraionMiu
));
}
preLast
=
o
.
getEndTime
();
}
if
(
preLast
.
isBefore
(
endTime
))
{
idlePeriods
.
add
(
Duration
.
between
(
preLast
,
endTime
).
abs
().
toMinutes
());
long
duraionMiu
=
Duration
.
between
(
preLast
,
endTime
).
abs
().
toMinutes
();
leisureTime
.
add
(
new
OccupyInfoDetail
(
preLast
,
endTime
,
duraionMiu
));
}
return
org
.
springframework
.
util
.
CollectionUtils
.
isEmpty
(
idlePeriods
)
?
Duration
.
between
(
startTime
,
endTime
).
abs
().
toMinutes
()
:
Collections
.
max
(
idlePeriods
)
;
return
leisureTime
;
}
...
...
project-order/src/main/java/com/dituhui/pea/order/common/OccupyInfo.java
View file @
cf1de4f
...
...
@@ -12,6 +12,6 @@ import java.time.LocalDateTime;
@AllArgsConstructor
@NoArgsConstructor
public
class
OccupyInfo
{
pr
ivate
LocalDateTime
beginTime
;
pr
ivate
LocalDateTime
endTime
;
pr
otected
LocalDateTime
beginTime
;
pr
otected
LocalDateTime
endTime
;
}
project-order/src/main/java/com/dituhui/pea/order/common/OccupyInfoDetail.java
0 → 100644
View file @
cf1de4f
package
com
.
dituhui
.
pea
.
order
.
common
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.NoArgsConstructor
;
import
lombok.experimental.Accessors
;
import
java.time.LocalDateTime
;
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@Accessors
(
chain
=
true
)
@NoArgsConstructor
public
class
OccupyInfoDetail
extends
OccupyInfo
{
/**
* 时间片时长(分钟)
*/
private
long
duration
;
public
OccupyInfoDetail
(
LocalDateTime
beginTime
,
LocalDateTime
endTime
,
long
duration
)
{
super
(
beginTime
,
endTime
);
this
.
duration
=
duration
;
}
}
project-order/src/main/java/com/dituhui/pea/order/entity/CapacityEngineerSliceUsedEntity.java
View file @
cf1de4f
package
com
.
dituhui
.
pea
.
order
.
entity
;
import
com.dituhui.pea.order.common.OccupyInfoDetail
;
import
com.vladmihalcea.hibernate.type.json.JsonStringType
;
import
lombok.Getter
;
import
org.hibernate.annotations.GenericGenerator
;
import
org.hibernate.annotations.Type
;
import
org.hibernate.annotations.TypeDef
;
import
javax.persistence.Basic
;
import
javax.persistence.CascadeType
;
...
...
@@ -9,17 +13,18 @@ import javax.persistence.Column;
import
javax.persistence.Entity
;
import
javax.persistence.FetchType
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.OneToOne
;
import
javax.persistence.Table
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.Objects
;
@Getter
@Entity
@Table
(
name
=
"capacity_engineer_slice_used"
)
@TypeDef
(
name
=
"json"
,
typeClass
=
JsonStringType
.
class
)
public
class
CapacityEngineerSliceUsedEntity
{
@Id
@Column
(
name
=
"id"
)
...
...
@@ -51,11 +56,13 @@ public class CapacityEngineerSliceUsedEntity {
@Column
(
name
=
"cap_left"
)
private
Long
capLeft
;
@Basic
@Column
(
name
=
"order_count"
)
private
Long
orderCount
;
@Basic
@Column
(
name
=
"max_duration"
)
private
Long
maxDuration
;
@Type
(
type
=
"json"
)
@Column
(
name
=
"duration_time"
,
columnDefinition
=
"json"
)
private
List
<
OccupyInfoDetail
>
durationTime
;
@Basic
@Column
(
name
=
"max_duration_type"
)
private
String
maxDurationType
;
...
...
@@ -101,14 +108,15 @@ public class CapacityEngineerSliceUsedEntity {
this
.
capLeft
=
capLeft
;
}
public
void
setOrderCount
(
Long
orderCount
)
{
this
.
orderCount
=
orderCount
;
}
public
void
setMaxDuration
(
Long
maxDuration
)
{
this
.
maxDuration
=
maxDuration
;
}
public
void
setDurationTime
(
List
<
OccupyInfoDetail
>
durationTime
)
{
this
.
durationTime
=
durationTime
;
}
public
void
setMaxDurationType
(
String
maxDurationType
)
{
this
.
maxDurationType
=
maxDurationType
;
}
...
...
@@ -130,11 +138,11 @@ public class CapacityEngineerSliceUsedEntity {
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
CapacityEngineerSliceUsedEntity
that
=
(
CapacityEngineerSliceUsedEntity
)
o
;
return
id
==
that
.
id
&&
timmeSlice
==
that
.
timmeSlice
&&
Objects
.
equals
(
workday
,
that
.
workday
)
&&
Objects
.
equals
(
engineerCode
,
that
.
engineerCode
)
&&
Objects
.
equals
(
capTotal
,
that
.
capTotal
)
&&
Objects
.
equals
(
capUsed
,
that
.
capUsed
)
&&
Objects
.
equals
(
capUsedTravel
,
that
.
capUsedTravel
)
&&
Objects
.
equals
(
capLeft
,
that
.
capLeft
)
&&
Objects
.
equals
(
orderCount
,
that
.
orderCount
)
&&
Objects
.
equals
(
maxDuration
,
that
.
maxDuration
)
&&
Objects
.
equals
(
maxDurationType
,
that
.
maxDurationType
)
&&
Objects
.
equals
(
memo
,
that
.
memo
)
&&
Objects
.
equals
(
createTime
,
that
.
createTime
)
&&
Objects
.
equals
(
updateTime
,
that
.
updateTime
);
return
Objects
.
equals
(
id
,
that
.
id
)
&&
Objects
.
equals
(
timmeSlice
,
that
.
timmeSlice
)
&&
Objects
.
equals
(
workday
,
that
.
workday
)
&&
Objects
.
equals
(
engineerCode
,
that
.
engineerCode
)
&&
Objects
.
equals
(
capTotal
,
that
.
capTotal
)
&&
Objects
.
equals
(
capUsed
,
that
.
capUsed
)
&&
Objects
.
equals
(
capUsedTravel
,
that
.
capUsedTravel
)
&&
Objects
.
equals
(
capLeft
,
that
.
capLeft
)
&&
Objects
.
equals
(
maxDuration
,
that
.
maxDuration
)
&&
Objects
.
equals
(
durationTime
,
that
.
durationTime
)
&&
Objects
.
equals
(
maxDurationType
,
that
.
maxDurationType
)
&&
Objects
.
equals
(
memo
,
that
.
memo
)
&&
Objects
.
equals
(
createTime
,
that
.
createTime
)
&&
Objects
.
equals
(
updateTime
,
that
.
updateTime
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
id
,
timmeSlice
,
workday
,
engineerCode
,
capTotal
,
capUsed
,
capUsedTravel
,
capLeft
,
orderCount
,
maxDuration
,
maxDurationType
,
memo
,
createTime
,
updateTime
);
return
Objects
.
hash
(
id
,
timmeSlice
,
workday
,
engineerCode
,
capTotal
,
capUsed
,
capUsedTravel
,
capLeft
,
maxDuration
,
durationTime
,
maxDurationType
,
memo
,
createTime
,
updateTime
);
}
}
project-order/src/main/java/com/dituhui/pea/order/scheduler/CalcEngineerCapacityScheduler.java
View file @
cf1de4f
...
...
@@ -3,6 +3,7 @@ package com.dituhui.pea.order.scheduler;
import
com.dituhui.pea.order.common.CapacityUtils
;
import
com.dituhui.pea.order.common.DateUtils
;
import
com.dituhui.pea.order.common.OccupyInfo
;
import
com.dituhui.pea.order.common.OccupyInfoDetail
;
import
com.dituhui.pea.order.common.jackson.DateTimeUtil
;
import
com.dituhui.pea.order.common.jackson.DateUtil
;
import
com.dituhui.pea.order.dao.CapacityEngineerCalendarDao
;
...
...
@@ -140,11 +141,14 @@ public class CalcEngineerCapacityScheduler {
//已用容量
long
totalUseTime
=
occupyInfo
.
stream
().
mapToLong
(
t
->
Duration
.
between
(
t
.
getEndTime
(),
t
.
getBeginTime
()).
abs
().
toMinutes
()).
sum
();
//最大连续时长
Long
maxRemainBlock
=
CapacityUtils
.
getMaxRemainBlock
(
startTime
,
endTime
,
occupyInfo
);
List
<
OccupyInfoDetail
>
durationTime
=
CapacityUtils
.
getMaxRemainBlock
(
startTime
,
endTime
,
occupyInfo
);
long
maxRemainBlock
=
durationTime
.
stream
().
mapToLong
(
OccupyInfoDetail:
:
getDuration
).
max
().
orElse
(
Duration
.
between
(
startTime
,
endTime
).
abs
().
toMinutes
());
//剩余连续时间段
sliceCap
.
setDurationTime
(
durationTime
);
sliceCap
.
setCapLeft
(
sliceCap
.
getCapTotal
()
-
totalUseTime
);
sliceCap
.
setCapUsed
(
totalUseTime
);
sliceCap
.
setOrderCount
((
long
)
orders
.
size
());
//计算时 存储时间差级(剩余时间段)
sliceCap
.
setMaxDuration
(
maxRemainBlock
);
sliceCap
.
setUpdateTime
(
LocalDateTime
.
now
(
ZoneId
.
of
(
"+8"
)));
}
...
...
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