Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
HYH.APSJ
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
佟礼
HYH.APSJ
Commits
ebfcf137
Commit
ebfcf137
authored
Jan 09, 2026
by
DESKTOP-VKRD9QF\Administration
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kpi计算
parent
a3632e76
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
238 additions
and
128 deletions
+238
-128
GAScheduleResult.java
src/main/java/com/aps/entity/Algorithm/GAScheduleResult.java
+3
-0
TaskVO.java
src/main/java/com/aps/entity/Gantt/TaskVO.java
+6
-0
ProdLaunchOrder.java
src/main/java/com/aps/entity/ProdLaunchOrder.java
+1
-0
ProdProcessExec.java
src/main/java/com/aps/entity/ProdProcessExec.java
+1
-0
Entry.java
src/main/java/com/aps/entity/basic/Entry.java
+4
-0
Order.java
src/main/java/com/aps/entity/basic/Order.java
+1
-0
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+3
-0
KpiCalculator.java
src/main/java/com/aps/service/Algorithm/KpiCalculator.java
+7
-7
MaterialRequirementService.java
...com/aps/service/Algorithm/MaterialRequirementService.java
+2
-0
RoutingDataService.java
...in/java/com/aps/service/Algorithm/RoutingDataService.java
+3
-0
ScheduleOperationService.java
...a/com/aps/service/Algorithm/ScheduleOperationService.java
+1
-0
ChromosomeDataService.java
...in/java/com/aps/service/common/ChromosomeDataService.java
+1
-0
DiscreteParameterMatrixServiceImpl.java
.../aps/service/impl/DiscreteParameterMatrixServiceImpl.java
+190
-104
LanuchServiceImpl.java
src/main/java/com/aps/service/impl/LanuchServiceImpl.java
+3
-1
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+12
-16
No files found.
src/main/java/com/aps/entity/Algorithm/GAScheduleResult.java
View file @
ebfcf137
...
...
@@ -19,7 +19,10 @@ public class GAScheduleResult {
*/
public
String
ExecId
;
public
String
OrderId
;
public
String
OrderCode
;
private
String
productId
;
private
String
productName
;
private
String
productCode
;
private
long
MachineId
;
private
int
StartTime
;
// 相对开始时间(秒)
private
int
EndTime
;
// 相对结束时间(秒)
...
...
src/main/java/com/aps/entity/Gantt/TaskVO.java
View file @
ebfcf137
...
...
@@ -23,6 +23,9 @@ public class TaskVO {
@Schema
(
description
=
"计划ID"
)
private
String
planId
;
@Schema
(
description
=
"计划编号"
)
private
String
planCode
;
@Schema
(
description
=
"产品类型"
)
private
Integer
productType
;
...
...
@@ -32,6 +35,9 @@ public class TaskVO {
@Schema
(
description
=
"产品ID"
)
private
String
productId
;
@Schema
(
description
=
"产品编码"
)
private
String
productCode
;
@Schema
(
description
=
"数量"
)
private
double
quantity
;
...
...
src/main/java/com/aps/entity/ProdLaunchOrder.java
View file @
ebfcf137
...
...
@@ -19,6 +19,7 @@ public class ProdLaunchOrder {
private
String
createUser
;
private
String
productType
;
private
String
materialCode
;
private
String
materialName
;
private
String
materialVer
;
private
LocalDateTime
startDate
;
private
LocalDateTime
endDate
;
...
...
src/main/java/com/aps/entity/ProdProcessExec.java
View file @
ebfcf137
...
...
@@ -14,6 +14,7 @@ public class ProdProcessExec {
private
String
execId
;
private
String
sceneId
;
private
String
orderId
;
private
String
orderCode
;
private
Long
routingDetailId
;
private
Long
taskSeq
;
private
String
routingDetailName
;
...
...
src/main/java/com/aps/entity/basic/Entry.java
View file @
ebfcf137
...
...
@@ -32,6 +32,8 @@ public class Entry {
public
String
OrderId
;
public
String
OrderCode
;
/**
* 原订单ID
*/
...
...
@@ -45,6 +47,8 @@ public class Entry {
private
String
productId
;
private
String
productCode
;
private
String
productName
;
/**
* 工单ID
*/
...
...
src/main/java/com/aps/entity/basic/Order.java
View file @
ebfcf137
...
...
@@ -17,6 +17,7 @@ public class Order {
private
int
productId
;
private
String
materialId
;
private
String
materialCode
;
private
String
materialName
;
private
String
serie
;
private
Integer
routingId
;
private
String
routingCode
;
...
...
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
ebfcf137
...
...
@@ -488,7 +488,10 @@ if(finishedOrder==null||finishedOrder.size()==0)
result
.
setOperationId
(
operation
.
getId
());
result
.
setExecId
(
operation
.
getExecId
());
result
.
setOrderId
(
operation
.
getOrderId
());
result
.
setOrderCode
(
operation
.
getOrderCode
());
result
.
setProductId
(
operation
.
getProductId
());
result
.
setProductName
(
operation
.
getProductName
());
result
.
setProductCode
(
operation
.
getProductCode
());
result
.
setMachineId
(
machine
.
getId
());
...
...
src/main/java/com/aps/service/Algorithm/KpiCalculator.java
View file @
ebfcf137
...
...
@@ -41,7 +41,7 @@ public class KpiCalculator {
.
mapToDouble
(
Machine:
:
getRate
)
.
min
()
.
orElse
(
0
);
addKpi
(
kpiMetrics
,
"最小设备利用率"
,
machineMinRate
,
"实际工作时间/计划工作时间 最小"
,
0
,
1
);
addKpi
(
kpiMetrics
,
"最小设备利用率"
,
Math
.
round
(
machineMinRate
*
100.0
)
/
100.0
,
"实际工作时间/计划工作时间 最小"
,
0
,
1
);
double
machineActualWorkTime
=
chromosome
.
getMachines
().
stream
()
.
mapToDouble
(
Machine:
:
getActualWorkTime
)
...
...
@@ -53,8 +53,8 @@ public class KpiCalculator {
double
orderNoDelayCount
=
chromosome
.
getOrders
().
stream
()
.
filter
(
t
->
t
.
getDelayHours
()
<=
0
)
.
count
();
//
double
orderOnTime
=
Math
.
round
(
orderNoDelayCount
/
chromosome
.
getOrders
().
size
()
*
10000
)
/
10000
*
10
0
;
double
orderOnTime
=
Math
.
round
(
orderNoDelayCount
*
10000.0
/
chromosome
.
getOrders
().
size
())
/
100.
0
;
addKpi
(
kpiMetrics
,
"订单按时完成率"
,
orderOnTime
,
"规定时间内交付的订单数量/所有订单数量"
,
0
,
1
);
//最大延迟
double
OrderMaxDelay
=
chromosome
.
getOrders
().
stream
()
...
...
@@ -73,7 +73,7 @@ public class KpiCalculator {
.
mapToDouble
(
Order:
:
getDelayHours
)
.
sum
();
//平均延迟
double
OrderDelay
=
Math
.
round
(
OrderSumDelay
/
chromosome
.
getOrders
().
size
()
*
100
)
/
10
0
;
double
OrderDelay
=
Math
.
round
(
OrderSumDelay
/
chromosome
.
getOrders
().
size
()
*
100
.0
)
/
100.
0
;
addKpi
(
kpiMetrics
,
"平均延迟"
,
OrderDelay
,
"所有订单的延迟时间平均值"
,
2
,
1
);
//最长生产周期
double
OrderMaxProductTime
=
chromosome
.
getOrders
().
stream
()
...
...
@@ -92,7 +92,7 @@ public class KpiCalculator {
.
mapToDouble
(
Order:
:
getOrderProductTime
)
.
sum
();
//平均生产周期
double
OrderProductTime
=
Math
.
round
(
OrderSumProductTime
/
chromosome
.
getOrders
().
size
()
*
100
)
/
10
0
;
double
OrderProductTime
=
Math
.
round
(
OrderSumProductTime
/
chromosome
.
getOrders
().
size
()
*
100
.0
)
/
100.
0
;
addKpi
(
kpiMetrics
,
"平均生产周期"
,
OrderProductTime
,
"订单在计划中的实际存续时长"
,
2
,
1
);
//最大流量
...
...
@@ -114,7 +114,7 @@ public class KpiCalculator {
.
mapToDouble
(
Order:
:
getOrderFlow
)
.
sum
();
//平均流量
double
OrderFlow
=
Math
.
round
(
OrderSumFlow
/
chromosome
.
getOrders
().
size
()
*
100
)
/
10
0
;
double
OrderFlow
=
Math
.
round
(
OrderSumFlow
/
chromosome
.
getOrders
().
size
()
*
100
.0
)
/
100.
0
;
addKpi
(
kpiMetrics
,
"平均流量"
,
OrderFlow
,
"订单的最短理论耗时与其在计划中的实际耗时的比值"
,
0
,
1
);
chromosome
.
setKpiMetrics
(
kpiMetrics
);
...
...
@@ -234,7 +234,7 @@ public class KpiCalculator {
Duration
Orderduration
=
Duration
.
between
(
actualStartTime
,
actualCompletionTime
);
double
orderProductTime
=
Orderduration
.
getSeconds
();
order
.
setOrderProductTime
(
orderProductTime
);
double
flow
=
Math
.
round
(
orderProcessingTime
/
orderProductTime
*
10000
)/
10000
*
10
0
;
double
flow
=
Math
.
round
(
orderProcessingTime
/
orderProductTime
*
10000
.0
)/
10000.0
*
100.
0
;
order
.
setOrderFlow
(
flow
);
// 计算延迟时间(若提前完成则延迟为0)
...
...
src/main/java/com/aps/service/Algorithm/MaterialRequirementService.java
View file @
ebfcf137
...
...
@@ -411,6 +411,7 @@ if(routingIds.size()==0)
launchOrder
.
setSerie
(
order
.
getSerie
());
launchOrder
.
setCreateUser
(
"GA"
);
launchOrder
.
setMaterialCode
(
order
.
getMaterialCode
());
launchOrder
.
setMaterialName
(
order
.
getMaterialName
());
// launchOrder.setStartDate(order.get);
launchOrder
.
setEndDate
(
order
.
getDueDate
());
// launchOrder.setOrderPriority(order.getPrioritry());
...
...
@@ -603,6 +604,7 @@ if(routingIds.size()==0)
childorder
.
setOrderId
(
OrderId
);
childorder
.
setMaterialId
(
material
.
getId
());
childorder
.
setMaterialCode
(
material
.
getCode
());
childorder
.
setMaterialName
(
material
.
getName
());
childorder
.
setOrderCode
(
material
.
getCode
());
childorder
.
setQuantity
((
int
)
orderMaterial
.
getQjQty
());
childorder
.
setFinishOrderId
(
new
ArrayList
<>());
...
...
src/main/java/com/aps/service/Algorithm/RoutingDataService.java
View file @
ebfcf137
...
...
@@ -214,6 +214,7 @@ public class RoutingDataService {
entry
.
setRuntime
(
op
.
getRuntime
());
entry
.
setSingleOut
(
op
.
getSingleOut
());
entry
.
setOrderId
(
op
.
getOrderId
());
entry
.
setOrderCode
(
op
.
getOrderCode
());
entry
.
setQuantity
(
op
.
getPlanQty
());
entry
.
setRoutingId
(
op
.
getRoutingId
());
entry
.
setRoutingDetailId
(
op
.
getRoutingDetailId
());
...
...
@@ -225,6 +226,8 @@ public class RoutingDataService {
.
findFirst
().
orElse
(
null
);
if
(
order
!=
null
)
{
entry
.
setProductId
(
order
.
getMaterialId
());
entry
.
setProductCode
(
order
.
getMaterialCode
());
entry
.
setProductName
(
order
.
getMaterialName
());
entry
.
setPriority
(
order
.
getActualPriority
());
order
.
setId
(
entry
.
getGroupId
());
}
...
...
src/main/java/com/aps/service/Algorithm/ScheduleOperationService.java
View file @
ebfcf137
...
...
@@ -515,6 +515,7 @@ Integer newMachineId1=newMachineId.intValue();
Entry
newOp
=
ProductionDeepCopyUtil
.
deepCopy
(
entry
,
Entry
.
class
);
newOp
.
setExecId
(
newId
);
newOp
.
setOrderId
(
neworder
.
getOrderId
());
newOp
.
setOrderCode
(
neworder
.
getOrderCode
());
newOp
.
setGroupId
(
maxorderId
);
newOp
.
setQuantity
(
splitCounts
[
i
]);
newOp
.
setNewCreate
(
true
);
...
...
src/main/java/com/aps/service/common/ChromosomeDataService.java
View file @
ebfcf137
...
...
@@ -1104,6 +1104,7 @@ public class ChromosomeDataService {
prodProcessExec
.
setExecId
(
entry
.
ExecId
);
prodProcessExec
.
setSceneId
(
entry
.
SceneId
);
prodProcessExec
.
setOrderId
(
entry
.
OrderId
);
prodProcessExec
.
setRoutingDetailId
(
entry
.
getRoutingDetailId
());
prodProcessExec
.
setTaskSeq
(
entry
.
getTaskSeq
());
prodProcessExec
.
setRoutingDetailName
(
entry
.
getRoutingDetailName
());
...
...
src/main/java/com/aps/service/impl/DiscreteParameterMatrixServiceImpl.java
View file @
ebfcf137
...
...
@@ -10,90 +10,183 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.stream.Collectors
;
/**
* <p>
* 服务实现类
* </p>
*
* @author MyBatis-Plus
* @since 2025-12-03
*/
@Service
public
class
DiscreteParameterMatrixServiceImpl
extends
ServiceImpl
<
DiscreteParameterMatrixMapper
,
DiscreteParameterMatrix
>
implements
DiscreteParameterMatrixService
{
@Autowired
private
RoutingDiscreteParamService
_routingDiscreteParamService
;
@Override
public
double
getDiscreteParameterMatrixValue
(
Entry
entry
,
Entry
lastEntry
)
{
// 缓存配置
private
static
final
int
MAX_RESULT_CACHE_SIZE
=
1000
;
// 结果缓存最大容量
private
static
final
int
MAX_MATRIX_CACHE_SIZE
=
500
;
// 矩阵数据缓存最大容量
private
static
final
int
CLEANUP_INTERVAL
=
100
;
// 每100次调用清理一次
// 双缓存:计算结果缓存 + 矩阵数据缓存
private
final
ConcurrentHashMap
<
String
,
Double
>
resultCache
=
new
ConcurrentHashMap
<>();
private
final
ConcurrentHashMap
<
String
,
List
<
DiscreteParameterMatrix
>>
matrixDataCache
=
new
ConcurrentHashMap
<>();
// 调用计数器
private
int
callCount
=
0
;
// 1. 参数验证
@Override
public
double
getDiscreteParameterMatrixValue
(
Entry
entry
,
Entry
lastEntry
)
{
// 参数校验
if
(
entry
==
null
||
lastEntry
==
null
)
{
return
0.0
;
}
// 2. 获取基础数据
List
<
RoutingDiscreteParam
>
firstParams
=
lastEntry
.
getDiscreteParameter
();
List
<
RoutingDiscreteParam
>
secondParams
=
entry
.
getDiscreteParameter
();
// 检查参数列表是否为null
if
(
firstParams
==
null
||
secondParams
==
null
)
{
if
(
firstParams
==
null
||
secondParams
==
null
||
firstParams
.
isEmpty
()
||
secondParams
.
isEmpty
())
{
return
0.0
;
}
if
(
firstParams
.
isEmpty
()
||
secondParams
.
isEmpty
())
{
return
0.0
;
// 生成缓存键
String
cacheKey
=
generateCacheKey
(
entry
,
lastEntry
,
firstParams
,
secondParams
);
// 使用computeIfAbsent:线程安全,有则返回,无则计算
double
result
=
resultCache
.
computeIfAbsent
(
cacheKey
,
key
->
{
// 查找匹配参数
List
<
RoutingDiscreteParam
>
matchingParams
=
findMatchingParams
(
firstParams
,
secondParams
);
if
(
matchingParams
.
isEmpty
())
{
return
0.0
;
}
// 获取设备/设备类型ID
long
firstEquipId
=
lastEntry
.
getSelectMachineID
()
!=
null
?
lastEntry
.
getSelectMachineID
()
:
0L
;
long
secondEquipId
=
entry
.
getSelectMachineID
()
!=
null
?
entry
.
getSelectMachineID
()
:
0L
;
long
firstEquipTypeId
=
lastEntry
.
getEquipTypeID
()
!=
null
?
lastEntry
.
getEquipTypeID
()
:
0L
;
long
secondEquipTypeId
=
entry
.
getEquipTypeID
()
!=
null
?
entry
.
getEquipTypeID
()
:
0L
;
if
(
firstEquipId
==
0
||
secondEquipId
==
0
||
firstEquipTypeId
==
0
||
secondEquipTypeId
==
0
)
{
System
.
out
.
println
(
firstEquipId
+
"-- "
+
secondEquipId
+
"-- "
+
firstEquipTypeId
+
"-- "
+
secondEquipTypeId
);
return
0.0
;
}
// 查找最大换型时间
return
findMaxChangeOverTime
(
matchingParams
,
secondParams
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
);
});
// 定期清理缓存
synchronized
(
this
)
{
callCount
++;
if
(
callCount
>=
CLEANUP_INTERVAL
)
{
cleanCachesIfNeeded
();
callCount
=
0
;
}
}
// 3. 查找匹配的参数
List
<
RoutingDiscreteParam
>
matchingParams
=
findMatchingParams
(
firstParams
,
secondParams
);
if
(
matchingParams
.
isEmpty
())
{
return
0.0
;
}
long
firstEquipId
=
lastEntry
.
getSelectMachineID
()
!=
null
?
lastEntry
.
getSelectMachineID
()
:
0L
;
long
secondEquipId
=
entry
.
getSelectMachineID
()
!=
null
?
entry
.
getSelectMachineID
()
:
0L
;
long
firstEquipTypeId
=
lastEntry
.
getEquipTypeID
()
!=
null
?
lastEntry
.
getEquipTypeID
()
:
0L
;
long
secondEquipTypeId
=
entry
.
getSelectMachineID
()
!=
null
?
entry
.
getSelectMachineID
()
:
0L
;
return
result
;
}
if
(
firstEquipId
==
0
||
secondEquipId
==
0
||
firstEquipTypeId
==
0
||
secondEquipTypeId
==
0
)
{
System
.
out
.
println
(
firstEquipId
+
"-- "
+
secondEquipId
+
"-- "
+
firstEquipTypeId
+
"-- "
+
secondEquipTypeId
);
/**
* 获取矩阵数据(带缓存)
*/
private
List
<
DiscreteParameterMatrix
>
getMatrixDataWithCache
(
Set
<
String
>
groupIds
)
{
if
(
groupIds
==
null
||
groupIds
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
return
0.0
;
// 生成缓存键
String
cacheKey
=
groupIds
.
stream
()
.
filter
(
Objects:
:
nonNull
)
.
sorted
()
.
collect
(
Collectors
.
joining
(
","
));
if
(
cacheKey
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
// 使用computeIfAbsent缓存矩阵数据
return
matrixDataCache
.
computeIfAbsent
(
cacheKey
,
key
->
this
.
lambdaQuery
()
.
in
(
DiscreteParameterMatrix:
:
getGroupid
,
groupIds
)
.
eq
(
DiscreteParameterMatrix:
:
getIsdeleted
,
0
)
.
list
()
);
}
/**
* 清理缓存(如果需要)
*/
private
void
cleanCachesIfNeeded
()
{
// 清理结果缓存
if
(
resultCache
.
size
()
>
MAX_RESULT_CACHE_SIZE
)
{
cleanCache
(
resultCache
,
MAX_RESULT_CACHE_SIZE
);
}
// 4. 获取矩阵数据并计算最大时长
return
findMaxChangeOverTime
(
matchingParams
,
secondParams
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
);
// 清理矩阵缓存
if
(
matrixDataCache
.
size
()
>
MAX_MATRIX_CACHE_SIZE
)
{
cleanCache
(
matrixDataCache
,
MAX_MATRIX_CACHE_SIZE
);
}
}
/**
* 通用的缓存清理方法
*/
private
<
K
,
V
>
void
cleanCache
(
ConcurrentHashMap
<
K
,
V
>
cache
,
int
maxSize
)
{
if
(
cache
.
size
()
<=
maxSize
)
{
return
;
}
int
targetSize
=
maxSize
*
3
/
4
;
// 清理到75%
Iterator
<
K
>
iterator
=
cache
.
keySet
().
iterator
();
int
removed
=
0
;
while
(
cache
.
size
()
>
targetSize
&&
iterator
.
hasNext
())
{
iterator
.
next
();
iterator
.
remove
();
removed
++;
}
}
/**
*
获取路由参数列表
*
生成结果缓存键
*/
private
List
<
RoutingDiscreteParam
>
getRoutingParams
(
Long
detailId
)
{
return
_routingDiscreteParamService
.
lambdaQuery
()
.
eq
(
RoutingDiscreteParam:
:
getRoutingDetailId
,
detailId
)
.
eq
(
RoutingDiscreteParam:
:
getIsDeleted
,
0
)
.
list
();
private
String
generateCacheKey
(
Entry
entry
,
Entry
lastEntry
,
List
<
RoutingDiscreteParam
>
firstParams
,
List
<
RoutingDiscreteParam
>
secondParams
)
{
StringBuilder
key
=
new
StringBuilder
();
key
.
append
(
"E"
).
append
(
entry
.
getId
())
.
append
(
"_LE"
).
append
(
lastEntry
.
getId
())
.
append
(
"_EID"
).
append
(
entry
.
getSelectMachineID
())
.
append
(
"_LEID"
).
append
(
lastEntry
.
getSelectMachineID
())
.
append
(
"_ET"
).
append
(
entry
.
getEquipTypeID
())
.
append
(
"_LET"
).
append
(
lastEntry
.
getEquipTypeID
());
// 参数哈希(避免顺序影响)
if
(
firstParams
!=
null
&&
secondParams
!=
null
)
{
key
.
append
(
"_PH"
).
append
(
getParamsHash
(
firstParams
)).
append
(
"_"
).
append
(
getParamsHash
(
secondParams
));
}
return
key
.
toString
();
}
/**
*
查找匹配的参数(first中groupId在second中也存在的参数)
*
计算参数哈希值
*/
private
List
<
RoutingDiscreteParam
>
findMatchingParams
(
List
<
RoutingDiscreteParam
>
firstParams
,
List
<
RoutingDiscreteParam
>
secondParams
)
{
private
int
getParamsHash
(
List
<
RoutingDiscreteParam
>
params
)
{
if
(
params
==
null
||
params
.
isEmpty
())
{
return
0
;
}
String
paramStr
=
params
.
stream
()
.
filter
(
Objects:
:
nonNull
)
.
map
(
p
->
(
p
.
getGroupId
()
!=
null
?
p
.
getGroupId
()
:
""
)
+
":"
+
(
p
.
getParameterId
()
!=
null
?
p
.
getParameterId
()
:
""
))
.
sorted
()
.
collect
(
Collectors
.
joining
(
"#"
));
return
paramStr
.
hashCode
();
}
/**
* 查找匹配的参数(first中groupId在second中存在的参数)
*/
private
List
<
RoutingDiscreteParam
>
findMatchingParams
(
List
<
RoutingDiscreteParam
>
firstParams
,
List
<
RoutingDiscreteParam
>
secondParams
)
{
Set
<
String
>
secondGroupIds
=
secondParams
.
stream
()
.
map
(
RoutingDiscreteParam:
:
getGroupId
)
.
filter
(
Objects:
:
nonNull
)
...
...
@@ -108,7 +201,9 @@ public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscretePara
* 查找最大换型时间
*/
private
double
findMaxChangeOverTime
(
List
<
RoutingDiscreteParam
>
matchingParams
,
List
<
RoutingDiscreteParam
>
secondParams
,
long
firstEquipId
,
long
secondEquipId
,
long
firstEquipTypeId
,
long
secondEquipTypeId
)
{
List
<
RoutingDiscreteParam
>
secondParams
,
long
firstEquipId
,
long
secondEquipId
,
long
firstEquipTypeId
,
long
secondEquipTypeId
)
{
Set
<
String
>
groupIds
=
matchingParams
.
stream
()
.
map
(
RoutingDiscreteParam:
:
getGroupId
)
...
...
@@ -119,67 +214,67 @@ public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscretePara
return
0.0
;
}
// 获取矩阵数据
List
<
DiscreteParameterMatrix
>
matrixData
=
getMatrixData
(
groupIds
);
// 获取矩阵数据
(走缓存)
List
<
DiscreteParameterMatrix
>
matrixData
=
getMatrixData
WithCache
(
groupIds
);
// 按优先级
查找匹配的
矩阵记录
// 按优先级
匹配
矩阵记录
List
<
DiscreteParameterMatrix
>
matchedMatrix
=
findMatchedMatrixByPriority
(
matchingParams
,
secondParams
,
matrixData
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
);
matchingParams
,
secondParams
,
matrixData
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
);
// 获取最大时长
return
getMaxDuration
(
matchedMatrix
);
}
/**
* 获取矩阵数据
*/
private
List
<
DiscreteParameterMatrix
>
getMatrixData
(
Set
<
String
>
groupIds
)
{
// 直接使用this调用,避免循环依赖
return
this
.
lambdaQuery
()
.
in
(
DiscreteParameterMatrix:
:
getGroupid
,
groupIds
)
.
eq
(
DiscreteParameterMatrix:
:
getIsdeleted
,
0
)
.
list
();
}
/**
* 按优先级查找匹配的矩阵记录
* 按优先级匹配矩阵记录(设备级→设备类型级→全局级)
*/
private
List
<
DiscreteParameterMatrix
>
findMatchedMatrixByPriority
(
List
<
RoutingDiscreteParam
>
matchingParams
,
List
<
RoutingDiscreteParam
>
secondParams
,
List
<
DiscreteParameterMatrix
>
matrixData
,
long
firstEquipId
,
long
secondEquipId
,
long
firstEquipTypeId
,
long
secondEquipTypeId
)
{
List
<
DiscreteParameterMatrix
>
matrixData
,
long
firstEquipId
,
long
secondEquipId
,
long
firstEquipTypeId
,
long
secondEquipTypeId
)
{
// 优先级1
: 设备级别匹配 (isEquip=1, isEquipType=0, isGlobal=0)
// 优先级1
:设备级别
List
<
DiscreteParameterMatrix
>
result
=
findMatrixMatches
(
matchingParams
,
secondParams
,
matrixData
,
1
,
0
,
0
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
);
matchingParams
,
secondParams
,
matrixData
,
1
,
0
,
0
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
);
if
(!
result
.
isEmpty
())
{
return
result
;
}
// 优先级2: 设备类型级别匹配 (isEquip=0, isEquipType=1, isGlobal=0)
result
=
findMatrixMatches
(
matchingParams
,
secondParams
,
matrixData
,
0
,
1
,
0
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
);
// 优先级2:设备类型级别
result
=
findMatrixMatches
(
matchingParams
,
secondParams
,
matrixData
,
0
,
1
,
0
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
);
if
(!
result
.
isEmpty
())
{
return
result
;
}
// 优先级3: 全局级别匹配 (isEquip=0, isEquipType=0, isGlobal=1)
return
findMatrixMatches
(
matchingParams
,
secondParams
,
matrixData
,
0
,
0
,
1
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
);
// 优先级3:全局级别
return
findMatrixMatches
(
matchingParams
,
secondParams
,
matrixData
,
0
,
0
,
1
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
);
}
/**
*
查找矩阵匹配
记录
*
匹配矩阵
记录
*/
private
List
<
DiscreteParameterMatrix
>
findMatrixMatches
(
List
<
RoutingDiscreteParam
>
matchingParams
,
List
<
RoutingDiscreteParam
>
secondParams
,
List
<
DiscreteParameterMatrix
>
matrixData
,
int
isEquip
,
int
isEquipType
,
int
isGlobal
,
long
firstEquipId
,
long
secondEquipId
,
long
firstEquipTypeId
,
long
secondEquipTypeId
)
{
int
isEquip
,
int
isEquipType
,
int
isGlobal
,
long
firstEquipId
,
long
secondEquipId
,
long
firstEquipTypeId
,
long
secondEquipTypeId
)
{
return
matchingParams
.
stream
()
.
flatMap
(
firstParam
->
secondParams
.
stream
()
.
flatMap
(
secondParam
->
matrixData
.
stream
()
.
filter
(
matrix
->
isMatrixMatch
(
matrix
,
firstParam
,
secondParam
,
isEquip
,
isEquipType
,
isGlobal
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
))
.
filter
(
matrix
->
isMatrixMatch
(
matrix
,
firstParam
,
secondParam
,
isEquip
,
isEquipType
,
isGlobal
,
firstEquipId
,
secondEquipId
,
firstEquipTypeId
,
secondEquipTypeId
))
)
)
.
collect
(
Collectors
.
toList
());
...
...
@@ -188,68 +283,59 @@ public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscretePara
/**
* 检查矩阵是否匹配
*/
/**
* 检查矩阵是否匹配(最简修正)
*/
private
boolean
isMatrixMatch
(
DiscreteParameterMatrix
matrix
,
RoutingDiscreteParam
firstParam
,
RoutingDiscreteParam
secondParam
,
int
requiredEquip
,
int
requiredEquipType
,
int
requiredGlobal
,
long
firstEquipId
,
long
secondEquipId
,
long
firstEquipTypeId
,
long
secondEquipTypeId
)
{
int
requiredEquip
,
int
requiredEquipType
,
int
requiredGlobal
,
long
firstEquipId
,
long
secondEquipId
,
long
firstEquipTypeId
,
long
secondEquipTypeId
)
{
//
1. 先检查参数ID匹配
//
参数ID匹配校验
if
(!
Objects
.
equals
(
matrix
.
getFirstparameterid
(),
firstParam
.
getParameterId
())
||
!
Objects
.
equals
(
matrix
.
getSecondparameterid
(),
secondParam
.
getParameterId
()))
{
return
false
;
}
//
2. 按优先级检查:处理null值,null视为0
//
设备级别匹配
if
(
requiredEquip
==
1
)
{
return
(
(
matrix
.
getIsequip
()
!=
null
?
matrix
.
getIsequip
()
:
0
)
==
1
)
&&
return
(
matrix
.
getIsequip
()
!=
null
?
matrix
.
getIsequip
()
:
0
)
==
1
&&
Objects
.
equals
(
matrix
.
getEquipid
(),
firstEquipId
)
&&
Objects
.
equals
(
matrix
.
getEquipid
(),
secondEquipId
)
&&
firstEquipId
==
secondEquipId
;
// 确保前后工序使用同一设备
firstEquipId
==
secondEquipId
;
}
// 设备类型级别匹配
if
(
requiredEquipType
==
1
)
{
return
(
(
matrix
.
getIsequiptype
()
!=
null
?
matrix
.
getIsequiptype
()
:
0
)
==
1
)
&&
return
(
matrix
.
getIsequiptype
()
!=
null
?
matrix
.
getIsequiptype
()
:
0
)
==
1
&&
Objects
.
equals
(
matrix
.
getEquiptypeid
(),
firstEquipTypeId
)
&&
Objects
.
equals
(
matrix
.
getEquiptypeid
(),
secondEquipTypeId
)
&&
firstEquipTypeId
==
secondEquipTypeId
;
// 确保前后工序使用同类型设备
firstEquipTypeId
==
secondEquipTypeId
;
}
// 全局级别匹配
if
(
requiredGlobal
==
1
)
{
return
(
matrix
.
getIsglobal
()
!=
null
?
matrix
.
getIsglobal
()
:
0
)
==
1
;
}
return
false
;
}
/**
* 获取最大时长
* 获取最大
换型
时长
*/
private
double
getMaxDuration
(
List
<
DiscreteParameterMatrix
>
matrixList
)
{
return
matrixList
.
stream
()
.
filter
(
matrix
->
matrix
.
getDurationsecond
()
>
0
)
.
map
(
DiscreteParameterMatrix:
:
getDurationsecond
)
// 保持Double类型
.
max
(
Double:
:
compareTo
)
// 使用Double的比较器
.
filter
(
matrix
->
matrix
.
getDurationsecond
()
>
0
)
.
map
(
DiscreteParameterMatrix:
:
getDurationsecond
)
.
max
(
Double:
:
compareTo
)
.
orElse
(
0.0
);
}
/**
* 清理所有缓存
*/
public
void
clearCache
()
{
resultCache
.
clear
();
matrixDataCache
.
clear
();
}
}
\ No newline at end of file
src/main/java/com/aps/service/impl/LanuchServiceImpl.java
View file @
ebfcf137
...
...
@@ -360,9 +360,10 @@ public class LanuchServiceImpl implements LanuchService {
launchOrder
.
setSerie
(
order
.
getSeries
());
launchOrder
.
setCreateUser
(
String
.
valueOf
(
order
.
getCreatoruserid
()));
launchOrder
.
setMaterialCode
(
order
.
getMmcode
());
launchOrder
.
setMaterialName
(
order
.
getMmname
());
launchOrder
.
setEndDate
(
order
.
getDeliverytime
());
launchOrder
.
setStartDate
(
order
.
getBegintime
());
launchOrder
.
setOrderCode
(
order
.
getCode
());
try
{
launchOrder
.
setOrderPriority
(
Integer
.
valueOf
(
order
.
getPrioritry
()));
}
catch
(
NumberFormatException
e
)
{
...
...
@@ -687,6 +688,7 @@ public class LanuchServiceImpl implements LanuchService {
ProdProcessExec
prodProcessExec
=
new
ProdProcessExec
();
prodProcessExec
.
setExecId
(
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
));
prodProcessExec
.
setOrderId
(
prodOrderMain
.
getOrderId
());
prodProcessExec
.
setOrderCode
(
prodOrderMain
.
getOrderCode
());
prodProcessExec
.
setRoutingDetailId
(
detail
.
getId
());
prodProcessExec
.
setTaskSeq
(
detail
.
getTaskSeq
());
prodProcessExec
.
setRoutingDetailName
(
detail
.
getName
());
...
...
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
ebfcf137
...
...
@@ -7,6 +7,7 @@ import com.aps.entity.*;
import
com.aps.entity.Algorithm.*
;
import
com.aps.entity.Algorithm.IDAndChildID.GroupResult
;
import
com.aps.entity.Algorithm.IDAndChildID.NodeInfo
;
import
com.aps.entity.Gantt.TaskVO
;
import
com.aps.entity.Schedule.SceneChromsome
;
import
com.aps.entity.basic.ScheduleChromosome
;
import
com.aps.entity.Schedule.GenVO
;
...
...
@@ -936,6 +937,7 @@ private GlobalParam InitGlobalParam()
for
(
ProdLaunchOrder
lo
:
ProdLaunchOrders
)
{
Order
order
=
new
Order
();
order
.
setMaterialCode
(
lo
.
getMaterialCode
());
order
.
setMaterialName
(
lo
.
getMaterialName
());
order
.
setSerie
(
lo
.
getSerie
()==
null
?
""
:
lo
.
getSerie
());
order
.
setOrderCode
(
lo
.
getOrderCode
());
order
.
setOrderId
(
lo
.
getOrderId
());
...
...
@@ -1539,12 +1541,14 @@ private GlobalParam InitGlobalParam()
.
filter
(
t
->
t
.
getId
()
==
gene
.
getOperationId
()).
findFirst
().
orElse
(
null
);
com
.
aps
.
entity
.
Gantt
.
TaskVO
taskVO
=
new
com
.
aps
.
entity
.
Gantt
.
TaskVO
();
TaskVO
taskVO
=
new
TaskVO
();
taskVO
.
setId
(
String
.
valueOf
(
gene
.
getOperationId
()));
taskVO
.
setPlanId
(
gene
.
getOrderId
());
// 默认值
taskVO
.
setPlanCode
(
gene
.
getOrderCode
());
// 默认值
// taskVO.setProductType(0); // 默认值
// taskVO.setProductName("产品"+gene.getProductId
());
taskVO
.
setProductName
(
gene
.
getProductName
());
taskVO
.
setProductId
(
gene
.
getProductId
());
// 默认值
taskVO
.
setProductCode
(
gene
.
getProductCode
());
// 默认值
taskVO
.
setQuantity
(
gene
.
getQuantity
());
taskVO
.
setStart
(
scheduleChromosome
.
getBaseTime
().
plusSeconds
(
gene
.
getStartTime
()));
taskVO
.
setEnd
(
scheduleChromosome
.
getBaseTime
().
plusSeconds
(
gene
.
getEndTime
()));
...
...
@@ -1569,22 +1573,14 @@ private GlobalParam InitGlobalParam()
taskVO
.
setShopId
(
machine
.
getId
());
taskVO
.
setShopName
(
resourceGanttVO
.
getShopName
());
taskVO
.
setStatus
(
0
);
// 默认值
taskVO
.
setDetailId
(
(
long
)
gene
.
getStartTime
());
// 将productId和operationID组合为detailId
taskVO
.
setHeaderId
(
gene
.
getEndTime
());
// 默认值
// taskVO.setHeaderName("工艺"+gene.getProductId
()); // 默认值
// taskVO.setSeq(gene.getSequenceId(
)); // 使用工序ID
// taskVO.setSeqName( "工序名称"+gene.getSequenceId
());
taskVO
.
setDetailId
(
entry
.
getRoutingDetailId
());
// 将productId和operationID组合为detailId
taskVO
.
setHeaderId
(
entry
.
getRoutingId
());
// 默认值
taskVO
.
setHeaderName
(
entry
.
getRoutingName
());
// 默认值
taskVO
.
setSeq
(
Math
.
toIntExact
(
entry
.
getTaskSeq
()
));
// 使用工序ID
taskVO
.
setSeqName
(
entry
.
getRoutingDetailName
());
taskVO
.
setProcessingTime
(
gene
.
getProcessingTime
());
// taskVO.setAbsoluteStart(scheduleChromosome.getBaseTime().plusMinutes(gene.getStartTime()));
// taskVO.setAbsoluteEnd(scheduleChromosome.getBaseTime().plusMinutes(gene.getEndTime()));
taskVOList
.
add
(
taskVO
);
// 调试:检查machine中的shifts状态
// if (machine.getShifts() != null) {
// for (Shift shift : machine.getShifts()) {
// System.out.println("Before setting shifts - Shift status: " + shift.getStatus());
// }
// }
taskVOList
.
add
(
taskVO
);
taskVO
.
setAbsolutePreparationTime
(
gene
.
getTeardownTime
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment