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
20d04adf
Commit
20d04adf
authored
Jan 16, 2026
by
DESKTOP-VKRD9QF\Administration
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改工单订单设备
parent
bc3adbc4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
493 additions
and
239 deletions
+493
-239
ChromosomeDataController.java
...a/com/aps/controller/common/ChromosomeDataController.java
+190
-118
KpiCalculator.java
src/main/java/com/aps/service/Algorithm/KpiCalculator.java
+1
-1
ChromosomeDataService.java
...in/java/com/aps/service/common/ChromosomeDataService.java
+301
-119
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+1
-1
No files found.
src/main/java/com/aps/controller/common/ChromosomeDataController.java
View file @
20d04adf
...
...
@@ -8,6 +8,7 @@ import com.aps.entity.common.Paged;
import
com.aps.service.common.ChromosomeDataService
;
import
com.aps.service.plan.PlanResultService
;
import
com.aps.service.plan.SceneService
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Parameter
;
...
...
@@ -15,7 +16,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -163,40 +165,27 @@ public class ChromosomeDataController {
// 文件实体必须要有sceneId
if
(
isFileEntity
(
entityName
)
&&
(
sceneId
==
null
||
sceneId
.
isEmpty
()))
{
return
R
.
failed
(
"文件实体更新时sceneId不能为空"
);
throw
new
RuntimeException
(
"文件实体更新时sceneId不能为空"
);
}
if
(
entityName
.
equalsIgnoreCase
(
"machine
Option
"
)){
if
(
entityName
.
equalsIgnoreCase
(
"machine"
)){
return
updateMachineOption
(
sceneId
,
taskId
,
data
);
}
try
{
boolean
success
=
chromosomeDataService
.
updateChromosomeData
(
sceneId
,
entityName
,
data
);
if
(
success
)
{
return
R
.
ok
(
"更新成功"
);
}
else
{
return
R
.
failed
(
"更新失败"
);
}
}
catch
(
Exception
e
)
{
return
R
.
failed
(
"更新失败: "
+
e
.
getMessage
());
}
}
private
R
<
String
>
updateMachineOption
(
String
sceneId
,
String
taskId
,
Map
<
String
,
Object
>
data
)
{
// 验证taskId不能为空
if
(
taskId
==
null
||
taskId
.
isEmpty
())
{
return
R
.
failed
(
"更新machineOption时taskId不能为空"
);
}
try
{
private
R
<
String
>
updateMachineOption
(
String
sceneId
,
String
taskId
,
Map
<
String
,
Object
>
data
)
{
// 1. 加载Chromosome对象
Chromosome
chromosome
=
sceneService
.
loadChromosomeFromFile
(
sceneId
);
if
(
chromosome
==
null
)
{
return
R
.
failed
(
"未找到场景ID为 "
+
sceneId
+
" 的Chromosome数据"
);
}
// 2. 根据taskId找到对应的entry
Entry
targetEntry
=
null
;
...
...
@@ -207,107 +196,206 @@ public class ChromosomeDataController {
}
}
if
(
targetEntry
==
null
)
{
return
R
.
failed
(
"未找到taskId为 "
+
taskId
+
" 的entry数据"
);
Long
machineId
=
null
;
Object
machineIdObj
=
data
.
get
(
"machineId"
);
if
(
machineIdObj
instanceof
Long
)
{
machineId
=
(
Long
)
machineIdObj
;
}
else
if
(
machineIdObj
instanceof
Integer
)
{
machineId
=
((
Integer
)
machineIdObj
).
longValue
();
}
else
if
(
machineIdObj
instanceof
String
)
{
machineId
=
Long
.
parseLong
((
String
)
machineIdObj
);
}
// 3. 获取machineOption的id
String
machineOptionId
=
String
.
valueOf
(
data
.
get
(
"machineId"
));
// 4. 在entry的machineOptions列表中找到对应的machineOption
MachineOption
targetMachineOption
=
null
;
for
(
MachineOption
machineOption
:
targetEntry
.
getMachineOptions
())
{
if
(
String
.
valueOf
(
machineOption
.
getMachineId
()).
equals
(
machineOption
Id
))
{
if
(
machineOption
.
getMachineId
().
equals
(
machine
Id
))
{
targetMachineOption
=
machineOption
;
break
;
}
}
if
(
targetMachineOption
==
null
)
{
return
R
.
failed
(
"未找到id为 "
+
machineOptionId
+
" 的machineOption数据"
);
}
// 5. 更新machineOption的字段
ObjectMapper
objectMapper
=
new
ObjectMapper
();
MachineOption
updatedMachineOption
=
objectMapper
.
convertValue
(
data
,
MachineOption
.
class
);
// 6. 替换原来的machineOption
int
index
=
targetEntry
.
getMachineOptions
().
indexOf
(
targetMachineOption
);
targetEntry
.
getMachineOptions
().
set
(
index
,
updatedMachineOption
);
planResultService
.
editMachine
(
chromosome
,
sceneId
,
targetEntry
);
// 5. 只更新传入的字段,保留原有字段值
updateMachineOptionFields
(
targetMachineOption
,
data
);
// 6. 调用editMachine方法
planResultService
.
editMachine
(
chromosome
,
sceneId
,
targetEntry
);
// 7. 保存更新后的Chromosome
boolean
saved
=
sceneService
.
saveChromosomeToFile
(
chromosome
,
sceneId
);
if
(
saved
)
{
return
R
.
ok
(
"更新成功"
);
}
else
{
return
R
.
failed
(
"更新失败"
);
}
}
catch
(
Exception
e
)
{
return
R
.
failed
(
"更新machineOption失败: "
+
e
.
getMessage
());
}
}
/**
*
同一entry下的多个machineOption更新
*
只更新MachineOption的传入字段,保留原有字段值
*/
private
R
<
String
>
updateMultipleMachineOptionsInEntry
(
String
sceneId
,
String
taskId
,
Map
<
String
,
Object
>
data
)
{
try
{
// 1. 加载Chromosome对象
Chromosome
chromosome
=
sceneService
.
loadChromosomeFromFile
(
sceneId
);
if
(
chromosome
==
null
)
{
return
R
.
failed
(
"未找到场景ID为 "
+
sceneId
+
" 的Chromosome数据"
);
}
// 2. 根据taskId找到对应的entry
Entry
targetEntry
=
null
;
for
(
Entry
entry
:
chromosome
.
getAllOperations
())
{
if
(
String
.
valueOf
(
entry
.
getId
()).
equals
(
taskId
))
{
targetEntry
=
entry
;
break
;
}
}
if
(
targetEntry
==
null
)
{
return
R
.
failed
(
"未找到taskId为 "
+
taskId
+
" 的entry数据"
);
}
// 3. 获取machineOptions列表
Object
machineOptionsObj
=
data
.
get
(
"machineOptions"
);
if
(!(
machineOptionsObj
instanceof
List
))
{
return
R
.
failed
(
"machineOptions必须是数组格式"
);
}
List
<?>
machineOptionsList
=
(
List
<?>)
machineOptionsObj
;
if
(
machineOptionsList
.
isEmpty
())
{
return
R
.
failed
(
"machineOptions数组不能为空"
);
}
// 4. 更新当前entry下的所有machineOption
ObjectMapper
objectMapper
=
new
ObjectMapper
();
private
void
updateMachineOptionFields
(
MachineOption
machineOption
,
Map
<
String
,
Object
>
data
)
{
// 处理runtime字段
if
(
data
.
containsKey
(
"runtime"
))
{
Object
runtimeObj
=
data
.
get
(
"runtime"
);
if
(
runtimeObj
instanceof
Integer
)
{
machineOption
.
setRuntime
(
new
BigDecimal
((
Integer
)
runtimeObj
));
}
else
if
(
runtimeObj
instanceof
Long
)
{
machineOption
.
setRuntime
(
new
BigDecimal
((
Long
)
runtimeObj
));
}
else
if
(
runtimeObj
instanceof
Double
)
{
machineOption
.
setRuntime
(
new
BigDecimal
((
Double
)
runtimeObj
));
}
else
if
(
runtimeObj
instanceof
String
)
{
machineOption
.
setRuntime
(
new
BigDecimal
((
String
)
runtimeObj
));
}
}
// 处理singleOut字段
if
(
data
.
containsKey
(
"singleOut"
))
{
Object
singleOutObj
=
data
.
get
(
"singleOut"
);
if
(
singleOutObj
instanceof
Integer
)
{
machineOption
.
setSingleOut
(
new
BigDecimal
((
Integer
)
singleOutObj
));
}
else
if
(
singleOutObj
instanceof
Long
)
{
machineOption
.
setSingleOut
(
new
BigDecimal
((
Long
)
singleOutObj
));
}
else
if
(
singleOutObj
instanceof
Double
)
{
machineOption
.
setSingleOut
(
new
BigDecimal
((
Double
)
singleOutObj
));
}
else
if
(
singleOutObj
instanceof
String
)
{
machineOption
.
setSingleOut
(
new
BigDecimal
((
String
)
singleOutObj
));
}
}
// 处理preTime字段
if
(
data
.
containsKey
(
"preTime"
))
{
Object
preTimeObj
=
data
.
get
(
"preTime"
);
if
(
preTimeObj
instanceof
Integer
)
{
machineOption
.
setPreTime
((
Integer
)
preTimeObj
);
}
else
if
(
preTimeObj
instanceof
Long
)
{
machineOption
.
setPreTime
(((
Long
)
preTimeObj
).
intValue
());
}
else
if
(
preTimeObj
instanceof
String
)
{
machineOption
.
setPreTime
(
Integer
.
parseInt
((
String
)
preTimeObj
));
}
}
// 处理processingTime字段 - 修改为:时间(runtime) ÷ 数量(singleOut)
if
(
data
.
containsKey
(
"processingTime"
)
||
data
.
containsKey
(
"singleOut"
)
||
data
.
containsKey
(
"runtime"
))
{
// 1. 获取singleOut值
BigDecimal
singleOut
=
machineOption
.
getSingleOut
();
if
(
data
.
containsKey
(
"singleOut"
))
{
Object
singleOutObj
=
data
.
get
(
"singleOut"
);
if
(
singleOutObj
instanceof
Integer
)
{
singleOut
=
new
BigDecimal
((
Integer
)
singleOutObj
);
}
else
if
(
singleOutObj
instanceof
Long
)
{
singleOut
=
new
BigDecimal
((
Long
)
singleOutObj
);
}
else
if
(
singleOutObj
instanceof
Double
)
{
singleOut
=
new
BigDecimal
((
Double
)
singleOutObj
);
}
else
if
(
singleOutObj
instanceof
String
)
{
singleOut
=
new
BigDecimal
((
String
)
singleOutObj
);
}
else
if
(
singleOutObj
instanceof
BigDecimal
)
{
singleOut
=
(
BigDecimal
)
singleOutObj
;
}
}
// 2. 获取runtime值
BigDecimal
runtime
=
machineOption
.
getRuntime
();
if
(
data
.
containsKey
(
"runtime"
))
{
Object
runtimeObj
=
data
.
get
(
"runtime"
);
if
(
runtimeObj
instanceof
Integer
)
{
runtime
=
new
BigDecimal
((
Integer
)
runtimeObj
);
}
else
if
(
runtimeObj
instanceof
Long
)
{
runtime
=
new
BigDecimal
((
Long
)
runtimeObj
);
}
else
if
(
runtimeObj
instanceof
Double
)
{
runtime
=
new
BigDecimal
((
Double
)
runtimeObj
);
}
else
if
(
runtimeObj
instanceof
String
)
{
runtime
=
new
BigDecimal
((
String
)
runtimeObj
);
}
else
if
(
runtimeObj
instanceof
BigDecimal
)
{
runtime
=
(
BigDecimal
)
runtimeObj
;
}
}
// 3. 计算processingTime = runtime ÷ singleOut(时间 ÷ 数量)
double
processingTime
=
0.0
;
if
(
singleOut
!=
null
&&
runtime
!=
null
&&
runtime
.
compareTo
(
BigDecimal
.
ZERO
)
!=
0
)
{
// 考虑runtime单位转换:如果runtime是毫秒,转换为秒
BigDecimal
runtimeSeconds
=
runtime
.
divide
(
new
BigDecimal
(
1000
),
6
,
RoundingMode
.
HALF_UP
);
// 关键修改:时间(秒) ÷ 数量,保留2位小数
processingTime
=
runtimeSeconds
.
divide
(
singleOut
,
2
,
RoundingMode
.
HALF_UP
).
doubleValue
();
}
// 4. 设置计算后的processingTime
machineOption
.
setProcessingTime
(
processingTime
);
}
//
// // 处理setupTime字段
// if (data.containsKey("setupTime")) {
// Object setupTimeObj = data.get("setupTime");
// if (setupTimeObj instanceof Integer) {
// machineOption.setSetupTime((Integer) setupTimeObj);
// } else if (setupTimeObj instanceof Long) {
// machineOption.setSetupTime(((Long) setupTimeObj).intValue());
// } else if (setupTimeObj instanceof String) {
// machineOption.setSetupTime(Integer.parseInt((String) setupTimeObj));
// }
// }
//
// // 处理teardownTime字段
// if (data.containsKey("teardownTime")) {
// Object teardownTimeObj = data.get("teardownTime");
// if (teardownTimeObj instanceof Integer) {
// machineOption.setTeardownTime((Integer) teardownTimeObj);
// } else if (teardownTimeObj instanceof Long) {
// machineOption.setTeardownTime(((Long) teardownTimeObj).intValue());
// } else if (teardownTimeObj instanceof String) {
// machineOption.setTeardownTime(Integer.parseInt((String) teardownTimeObj));
// }
// }
//
// // 处理contantTime字段
// if (data.containsKey("contantTime")) {
// Object contantTimeObj = data.get("contantTime");
// if (contantTimeObj instanceof Integer) {
// machineOption.setContantTime((Integer) contantTimeObj);
// } else if (contantTimeObj instanceof Long) {
// machineOption.setContantTime(((Long) contantTimeObj).intValue());
// } else if (contantTimeObj instanceof String) {
// machineOption.setContantTime(Integer.parseInt((String) contantTimeObj));
// }
// }
// // 处理equipCode字段
// if (data.containsKey("equipCode")) {
// machineOption.setEquipCode(String.valueOf(data.get("equipCode")));
// }
//
// // 处理resourceCode字段
// if (data.containsKey("resourceCode")) {
// machineOption.setResourceCode(String.valueOf(data.get("resourceCode")));
// }
// 忽略id等未知字段
}
private
boolean
updateMachineOptionsForEntry
(
Entry
targetEntry
,
List
<?>
machineOptions
,
ObjectMapper
objectMapper
)
{
boolean
allSuccess
=
true
;
List
<
String
>
errorMessages
=
new
ArrayList
<>();
for
(
Object
optionObj
:
machineOptionsList
)
{
for
(
Object
optionObj
:
machineOptions
)
{
if
(!(
optionObj
instanceof
Map
))
{
allSuccess
=
false
;
errorMessages
.
add
(
"machineOptions中的元素必须是对象格式"
);
continue
;
}
Map
<
String
,
Object
>
optionMap
=
(
Map
<
String
,
Object
>)
optionObj
;
Map
<?,
?>
optionMap
=
(
Map
<?,
?
>)
optionObj
;
// 获取machineOption的
machineId
String
machineOptionId
=
String
.
valueOf
(
optionMap
.
get
(
"machineId"
)
);
if
(
machineOptionId
==
null
)
{
// 获取
machineId
Object
machineIdObj
=
optionMap
.
get
(
"machineId"
);
if
(
machineIdObj
==
null
)
{
allSuccess
=
false
;
errorMessages
.
add
(
"machineOption必须包含machineId字段"
);
continue
;
}
String
machineOptionId
=
String
.
valueOf
(
machineIdObj
);
// 在entry的machineOptions列表中找到对应的machineOption
MachineOption
targetMachineOption
=
null
;
for
(
MachineOption
machineOption
:
targetEntry
.
getMachineOptions
())
{
...
...
@@ -319,7 +407,6 @@ public class ChromosomeDataController {
if
(
targetMachineOption
==
null
)
{
allSuccess
=
false
;
errorMessages
.
add
(
"未找到machineId为 "
+
machineOptionId
+
" 的machineOption数据"
);
continue
;
}
...
...
@@ -331,26 +418,11 @@ public class ChromosomeDataController {
targetEntry
.
getMachineOptions
().
set
(
index
,
updatedMachineOption
);
}
if
(!
allSuccess
)
{
return
R
.
failed
(
"部分更新失败: "
+
String
.
join
(
"; "
,
errorMessages
));
return
allSuccess
;
}
// 5. 调用editMachine方法处理entry更新
planResultService
.
editMachine
(
chromosome
,
sceneId
,
targetEntry
);
// 6. 保存更新后的Chromosome
boolean
saved
=
sceneService
.
saveChromosomeToFile
(
chromosome
,
sceneId
);
if
(
saved
)
{
return
R
.
ok
(
"批量更新成功"
);
}
else
{
return
R
.
failed
(
"批量更新失败: 保存Chromosome数据失败"
);
}
}
catch
(
Exception
e
)
{
return
R
.
failed
(
"批量更新machineOption失败: "
+
e
.
getMessage
());
}
}
/**
* 判断是否为文件实体
*/
...
...
src/main/java/com/aps/service/Algorithm/KpiCalculator.java
View file @
20d04adf
...
...
@@ -129,7 +129,7 @@ public class KpiCalculator {
.
mapToLong
(
GAScheduleResult:
:
getChangeOverTime
)
.
filter
(
changeOverTime
->
changeOverTime
>
0
)
.
count
();
addKpi
(
kpiMetrics
,
"换型次数"
,
changeOverTimeCount
,
"总的换型次数"
,
2
,
1
);
addKpi
(
kpiMetrics
,
"换型次数"
,
changeOverTimeCount
,
"总的换型次数"
,
1
,
1
);
}
...
...
src/main/java/com/aps/service/common/ChromosomeDataService.java
View file @
20d04adf
package
com
.
aps
.
service
.
common
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.aps.common.util.R
;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.entity.ProdProcessExec
;
import
com.aps.entity.basic.Entry
;
...
...
@@ -20,6 +21,8 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.CollectionUtils
;
import
java.lang.reflect.Field
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -47,18 +50,18 @@ public class ChromosomeDataService {
ObjectMapper
objectMapper
=
new
ObjectMapper
()
.
registerModule
(
new
JavaTimeModule
())
.
configure
(
SerializationFeature
.
WRITE_DATES_AS_TIMESTAMPS
,
false
);
public
Object
queryChromosomeData
(
String
sceneId
,
String
entityName
)
{
EntityConfig
config
=
getEntityConfig
(
entityName
);
if
(
config
.
getDataSource
()
==
DataSourceType
.
FILE
)
{
return
queryFileData
(
sceneId
,
config
);
}
else
{
// 数据库实体不需要sceneId,创建空的Paged对象
Paged
paged
=
new
Paged
();
List
<
Object
>
result
=
databaseQueryService
.
queryDatabaseDataList
(
config
,
paged
);
return
result
;
}
}
//
public Object queryChromosomeData(String sceneId, String entityName) {
//
EntityConfig config = getEntityConfig(entityName);
//
//
if (config.getDataSource() == DataSourceType.FILE) {
//
return queryFileData(sceneId, config);
//
} else {
//
// 数据库实体不需要sceneId,创建空的Paged对象
//
Paged paged = new Paged();
//
List<Object> result = databaseQueryService.queryDatabaseDataList(config, paged);
//
return result;
//
}
//
}
/**
* 驼峰命名转下划线大写:prodProduct -> PROD_PRODUCT
*/
...
...
@@ -306,38 +309,6 @@ public class ChromosomeDataService {
return
camelCaseToUnderScoreUpperCase
(
processedName
);
}
/**
* 驼峰命名转下划线大写:ProdProduct -> PROD_PRODUCT
*/
// private String camelCaseToUnderScoreUpperCase(String camelCase) {
// if (camelCase == null || camelCase.isEmpty()) {
// return camelCase;
// }
//
// StringBuilder result = new StringBuilder();
// for (int i = 0; i < camelCase.length(); i++) {
// char c = camelCase.charAt(i);
// if (Character.isUpperCase(c) && i > 0) {
// result.append('_');
// }
// result.append(Character.toUpperCase(c));
// }
// return result.toString();
// }
/**
* 查询文件数据
*/
...
...
@@ -350,11 +321,11 @@ public class ChromosomeDataService {
try
{
String
fieldName
=
config
.
getFieldName
();
// 特殊处理:当实体是ProdProcessExec时,使用allOperations字段
if
(
"prodprocessexec"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
fieldName
=
"allOperations"
;
}
//
// 特殊处理:当实体是ProdProcessExec时,使用allOperations字段
//
if ("prodprocessexec".equalsIgnoreCase(config.getEntityName())) {
//
fieldName = "allOperations";
//
}
//
// 特殊处理:当实体是MachineOption时,使用allOperations字段
if
(
"machineoption"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
fieldName
=
"allOperations"
;
...
...
@@ -364,10 +335,10 @@ public class ChromosomeDataService {
field
.
setAccessible
(
true
);
Object
result
=
field
.
get
(
chromosome
);
// 如果实体是ProdProcessExec,但数据源是Entry,则进行转换
if
(
"prodprocessexec"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
return
convertEntryToProdProcessExec
(
result
);
}
//
// 如果实体是ProdProcessExec,但数据源是Entry,则进行转换
//
if ("prodprocessexec".equalsIgnoreCase(config.getEntityName())) {
//
return convertEntryToProdProcessExec(result);
//
}
// 如果实体是MachineOption,提取Entry中的MachineOption列表
if
(
"machineoption"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
...
...
@@ -556,27 +527,6 @@ public class ChromosomeDataService {
return
null
;
// 找不到数据时返回null而不是抛出异常
}
// // 特殊处理:当实体是Order时,使用orderId字段进行查询
// if ("order".equalsIgnoreCase(config.getEntityName())) {
// Object result = queryFileData(sceneId, config);
//
// if (result instanceof List) {
// List<?> orderList = (List<?>) result;
// // 查找orderId匹配的Order
// for (Object obj : orderList) {
// if (obj instanceof Order) {
// Order order = (Order) obj;
// // 检查Order的orderId是否匹配
// if (order.getOrderId() != null && order.getOrderId().equals(id)) {
// // 如果orderId匹配,返回该Order
// return order;
// }
// }
// }
// }
// return null; // 找不到数据时返回null而不是抛出异常
// }
Object
result
=
queryFileData
(
sceneId
,
config
);
// 如果结果是List类型,则根据ID查找特定项
...
...
@@ -888,13 +838,28 @@ public class ChromosomeDataService {
}
if
(
entityName
.
equals
(
"order"
))
{
chromosome
=
planResultService
.
editOrder
(
chromosome
,
sceneId
,
BeanUtil
.
toBean
(
data
,
Order
.
class
));
System
.
out
.
println
(
"test1123"
);
Order
bean
=
BeanUtil
.
toBean
(
data
,
Order
.
class
);
Order
order
=
chromosome
.
getOrders
().
stream
().
filter
(
o
->
o
.
getId
()
==
(
bean
.
getId
())).
findFirst
().
orElse
(
null
);
chromosome
=
planResultService
.
editOrder
(
chromosome
,
sceneId
,
order
);
}
else
if
(
entityName
.
equals
(
"entry"
))
{
System
.
out
.
println
(
"5757"
);
Entry
entry
=
objectMapper
.
convertValue
(
data
,
Entry
.
class
);
// 获取原有entry对象
List
<
Object
>
dataList
=
(
List
<
Object
>)
originalData
;
String
id
=
data
.
get
(
"id"
).
toString
();
Entry
originalEntry
=
null
;
for
(
Object
item
:
dataList
)
{
if
(
item
instanceof
Entry
)
{
Entry
entry
=
(
Entry
)
item
;
if
(
String
.
valueOf
(
entry
.
getId
()).
equals
(
id
))
{
originalEntry
=
entry
;
break
;
}
}
}
// 2. 手动转换machineOptions字段
// 如果找到了原有entry对象,直接使用它
if
(
originalEntry
!=
null
)
{
// 如果传入了machineOptions字段,需要特殊处理
if
(
data
.
containsKey
(
"machineOptions"
))
{
List
<?>
machineOptionsList
=
(
List
<?>)
data
.
get
(
"machineOptions"
);
List
<
MachineOption
>
convertedOptions
=
new
ArrayList
<>();
...
...
@@ -904,14 +869,18 @@ public class ChromosomeDataService {
convertedOptions
.
add
(
option
);
}
// 设置转换后的machineOptions
entry
.
setMachineOptions
(
convertedOptions
);
originalEntry
.
setMachineOptions
(
convertedOptions
);
// 从data中移除machineOptions,避免updateObjectFields再次处理
data
.
remove
(
"machineOptions"
);
}
chromosome
=
planResultService
.
editOperation
(
chromosome
,
sceneId
,
entry
);
}
else
if
(
entityName
.
equals
(
"machineOption"
))
{
// chromosome =planResultService.editMachine(chromosome, sceneId, BeanUtil.toBean(data, MachineOption.class));
// 更新其他传入的字段
updateObjectFields
(
originalEntry
,
data
);
// 调用editOperation方法
chromosome
=
planResultService
.
editOperation
(
chromosome
,
sceneId
,
originalEntry
);
}
// 其他字段通过updateObjectFields更新
}
...
...
@@ -1150,7 +1119,21 @@ public class ChromosomeDataService {
Object
fieldValue
=
entry
.
getValue
();
try
{
Field
field
=
clazz
.
getDeclaredField
(
fieldName
);
// 尝试直接查找字段(区分大小写)
Field
field
=
null
;
try
{
field
=
clazz
.
getDeclaredField
(
fieldName
);
}
catch
(
NoSuchFieldException
e
)
{
// 如果找不到,尝试忽略大小写查找
for
(
Field
declaredField
:
clazz
.
getDeclaredFields
())
{
if
(
declaredField
.
getName
().
equalsIgnoreCase
(
fieldName
))
{
field
=
declaredField
;
break
;
}
}
}
if
(
field
!=
null
)
{
field
.
setAccessible
(
true
);
// 简单的类型转换处理
...
...
@@ -1182,6 +1165,7 @@ public class ChromosomeDataService {
}
else
{
field
.
set
(
obj
,
null
);
}
}
}
catch
(
Exception
e
)
{
// 忽略无法设置的字段
}
...
...
@@ -1300,4 +1284,202 @@ public class ChromosomeDataService {
}
}
public
R
<
String
>
updateMachineOption
(
String
sceneId
,
String
taskId
,
Map
<
String
,
Object
>
data
)
{
// 1. 加载Chromosome对象
Chromosome
chromosome
=
sceneService
.
loadChromosomeFromFile
(
sceneId
);
// 2. 根据taskId找到对应的entry
Entry
targetEntry
=
null
;
for
(
Entry
entry
:
chromosome
.
getAllOperations
())
{
if
(
String
.
valueOf
(
entry
.
getId
()).
equals
(
taskId
))
{
targetEntry
=
entry
;
break
;
}
}
Long
machineId
=
null
;
Object
machineIdObj
=
data
.
get
(
"machineId"
);
if
(
machineIdObj
instanceof
Long
)
{
machineId
=
(
Long
)
machineIdObj
;
}
else
if
(
machineIdObj
instanceof
Integer
)
{
machineId
=
((
Integer
)
machineIdObj
).
longValue
();
}
else
if
(
machineIdObj
instanceof
String
)
{
machineId
=
Long
.
parseLong
((
String
)
machineIdObj
);
}
// 4. 在entry的machineOptions列表中找到对应的machineOption
MachineOption
targetMachineOption
=
null
;
for
(
MachineOption
machineOption
:
targetEntry
.
getMachineOptions
())
{
if
(
machineOption
.
getMachineId
().
equals
(
machineId
))
{
targetMachineOption
=
machineOption
;
break
;
}
}
// 5. 只更新传入的字段,保留原有字段值
updateMachineOptionFields
(
targetMachineOption
,
data
);
// 6. 调用editMachine方法
planResultService
.
editMachine
(
chromosome
,
sceneId
,
targetEntry
);
// 7. 保存更新后的Chromosome
boolean
saved
=
sceneService
.
saveChromosomeToFile
(
chromosome
,
sceneId
);
return
R
.
ok
(
"更新成功"
);
}
/**
* 只更新MachineOption的传入字段,保留原有字段值
*/
private
void
updateMachineOptionFields
(
MachineOption
machineOption
,
Map
<
String
,
Object
>
data
)
{
// 处理runtime字段
if
(
data
.
containsKey
(
"runtime"
))
{
Object
runtimeObj
=
data
.
get
(
"runtime"
);
if
(
runtimeObj
instanceof
Integer
)
{
machineOption
.
setRuntime
(
new
BigDecimal
((
Integer
)
runtimeObj
));
}
else
if
(
runtimeObj
instanceof
Long
)
{
machineOption
.
setRuntime
(
new
BigDecimal
((
Long
)
runtimeObj
));
}
else
if
(
runtimeObj
instanceof
Double
)
{
machineOption
.
setRuntime
(
new
BigDecimal
((
Double
)
runtimeObj
));
}
else
if
(
runtimeObj
instanceof
String
)
{
machineOption
.
setRuntime
(
new
BigDecimal
((
String
)
runtimeObj
));
}
}
// 处理singleOut字段
if
(
data
.
containsKey
(
"singleOut"
))
{
Object
singleOutObj
=
data
.
get
(
"singleOut"
);
if
(
singleOutObj
instanceof
Integer
)
{
machineOption
.
setSingleOut
(
new
BigDecimal
((
Integer
)
singleOutObj
));
}
else
if
(
singleOutObj
instanceof
Long
)
{
machineOption
.
setSingleOut
(
new
BigDecimal
((
Long
)
singleOutObj
));
}
else
if
(
singleOutObj
instanceof
Double
)
{
machineOption
.
setSingleOut
(
new
BigDecimal
((
Double
)
singleOutObj
));
}
else
if
(
singleOutObj
instanceof
String
)
{
machineOption
.
setSingleOut
(
new
BigDecimal
((
String
)
singleOutObj
));
}
}
// 处理preTime字段
if
(
data
.
containsKey
(
"preTime"
))
{
Object
preTimeObj
=
data
.
get
(
"preTime"
);
if
(
preTimeObj
instanceof
Integer
)
{
machineOption
.
setPreTime
((
Integer
)
preTimeObj
);
}
else
if
(
preTimeObj
instanceof
Long
)
{
machineOption
.
setPreTime
(((
Long
)
preTimeObj
).
intValue
());
}
else
if
(
preTimeObj
instanceof
String
)
{
machineOption
.
setPreTime
(
Integer
.
parseInt
((
String
)
preTimeObj
));
}
}
// 处理processingTime字段 - 修改为:时间(runtime) ÷ 数量(singleOut)
if
(
data
.
containsKey
(
"processingTime"
)
||
data
.
containsKey
(
"singleOut"
)
||
data
.
containsKey
(
"runtime"
))
{
// 1. 获取singleOut值
BigDecimal
singleOut
=
machineOption
.
getSingleOut
();
if
(
data
.
containsKey
(
"singleOut"
))
{
Object
singleOutObj
=
data
.
get
(
"singleOut"
);
if
(
singleOutObj
instanceof
Integer
)
{
singleOut
=
new
BigDecimal
((
Integer
)
singleOutObj
);
}
else
if
(
singleOutObj
instanceof
Long
)
{
singleOut
=
new
BigDecimal
((
Long
)
singleOutObj
);
}
else
if
(
singleOutObj
instanceof
Double
)
{
singleOut
=
new
BigDecimal
((
Double
)
singleOutObj
);
}
else
if
(
singleOutObj
instanceof
String
)
{
singleOut
=
new
BigDecimal
((
String
)
singleOutObj
);
}
else
if
(
singleOutObj
instanceof
BigDecimal
)
{
singleOut
=
(
BigDecimal
)
singleOutObj
;
}
}
// 2. 获取runtime值
BigDecimal
runtime
=
machineOption
.
getRuntime
();
if
(
data
.
containsKey
(
"runtime"
))
{
Object
runtimeObj
=
data
.
get
(
"runtime"
);
if
(
runtimeObj
instanceof
Integer
)
{
runtime
=
new
BigDecimal
((
Integer
)
runtimeObj
);
}
else
if
(
runtimeObj
instanceof
Long
)
{
runtime
=
new
BigDecimal
((
Long
)
runtimeObj
);
}
else
if
(
runtimeObj
instanceof
Double
)
{
runtime
=
new
BigDecimal
((
Double
)
runtimeObj
);
}
else
if
(
runtimeObj
instanceof
String
)
{
runtime
=
new
BigDecimal
((
String
)
runtimeObj
);
}
else
if
(
runtimeObj
instanceof
BigDecimal
)
{
runtime
=
(
BigDecimal
)
runtimeObj
;
}
}
// 3. 计算processingTime = runtime ÷ singleOut(时间 ÷ 数量)
double
processingTime
=
0.0
;
if
(
singleOut
!=
null
&&
runtime
!=
null
&&
runtime
.
compareTo
(
BigDecimal
.
ZERO
)
!=
0
)
{
// 考虑runtime单位转换:如果runtime是毫秒,转换为秒
BigDecimal
runtimeSeconds
=
runtime
.
divide
(
new
BigDecimal
(
1000
),
6
,
RoundingMode
.
HALF_UP
);
// 关键修改:时间(秒) ÷ 数量,保留2位小数
processingTime
=
runtimeSeconds
.
divide
(
singleOut
,
2
,
RoundingMode
.
HALF_UP
).
doubleValue
();
}
// 4. 设置计算后的processingTime
machineOption
.
setProcessingTime
(
processingTime
);
}
//
// // 处理setupTime字段
// if (data.containsKey("setupTime")) {
// Object setupTimeObj = data.get("setupTime");
// if (setupTimeObj instanceof Integer) {
// machineOption.setSetupTime((Integer) setupTimeObj);
// } else if (setupTimeObj instanceof Long) {
// machineOption.setSetupTime(((Long) setupTimeObj).intValue());
// } else if (setupTimeObj instanceof String) {
// machineOption.setSetupTime(Integer.parseInt((String) setupTimeObj));
// }
// }
//
// // 处理teardownTime字段
// if (data.containsKey("teardownTime")) {
// Object teardownTimeObj = data.get("teardownTime");
// if (teardownTimeObj instanceof Integer) {
// machineOption.setTeardownTime((Integer) teardownTimeObj);
// } else if (teardownTimeObj instanceof Long) {
// machineOption.setTeardownTime(((Long) teardownTimeObj).intValue());
// } else if (teardownTimeObj instanceof String) {
// machineOption.setTeardownTime(Integer.parseInt((String) teardownTimeObj));
// }
// }
//
// // 处理contantTime字段
// if (data.containsKey("contantTime")) {
// Object contantTimeObj = data.get("contantTime");
// if (contantTimeObj instanceof Integer) {
// machineOption.setContantTime((Integer) contantTimeObj);
// } else if (contantTimeObj instanceof Long) {
// machineOption.setContantTime(((Long) contantTimeObj).intValue());
// } else if (contantTimeObj instanceof String) {
// machineOption.setContantTime(Integer.parseInt((String) contantTimeObj));
// }
// }
// // 处理equipCode字段
// if (data.containsKey("equipCode")) {
// machineOption.setEquipCode(String.valueOf(data.get("equipCode")));
// }
//
// // 处理resourceCode字段
// if (data.containsKey("resourceCode")) {
// machineOption.setResourceCode(String.valueOf(data.get("resourceCode")));
// }
// 忽略id等未知字段
}
}
\ No newline at end of file
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
20d04adf
...
...
@@ -444,7 +444,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
}
GlobalParam
globalParam
=
new
GlobalParam
();
ScheduleOperationService
ScheduleOperation
=
new
ScheduleOperationService
();
System
.
out
.
println
(
operation
.
getSelectMachineID
());
ScheduleOperation
.
editMachineOption
(
chromosome
,
operation
,
operation
.
getSelectMachineID
(),
globalParam
);
return
redecodeChromosome
(
chromosome
,
SceneId
);
...
...
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