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
5330e8fc
Commit
5330e8fc
authored
Jan 26, 2026
by
DESKTOP-VKRD9QF\Administration
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公共分页和list查询修改,设备字段修改
parent
c0f28f4f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
433 additions
and
173 deletions
+433
-173
ScheduleResultController1.java
...in/java/com/aps/controller/ScheduleResultController1.java
+0
-166
RoutingDataService.java
...in/java/com/aps/service/Algorithm/RoutingDataService.java
+26
-3
ChromosomeDataService.java
...in/java/com/aps/service/common/ChromosomeDataService.java
+407
-4
No files found.
src/main/java/com/aps/controller/ScheduleResultController1.java
deleted
100644 → 0
View file @
c0f28f4f
package
com
.
aps
.
controller
;
import
com.aps.common.util.R
;
import
com.aps.entity.Gantt.PlanResourceTaskGanttVO1
;
import
com.aps.entity.Gantt.SimpleEquipinfo1
;
import
com.aps.entity.Mpsplannedorder
;
import
com.aps.entity.RoutingDetail
;
import
com.aps.entity.RoutingDetailEquip
;
import
com.aps.entity.RoutingHeader
;
import
com.aps.entity.ScheduledTask
;
import
com.aps.entity.Equipinfo
;
import
com.aps.service.ScheduleService
;
import
com.aps.service.MpsplannedorderService
;
import
com.aps.service.RoutingHeaderService
;
import
com.aps.service.RoutingDetailService
;
import
com.aps.service.RoutingDetailEquipService
;
import
com.aps.service.EquipinfoService
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.responses.ApiResponse
;
import
io.swagger.v3.oas.annotations.responses.ApiResponses
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
@RestController
@RequestMapping
(
"/ganttest"
)
@Tag
(
name
=
"甘特图"
,
description
=
"甘特图相关API"
)
public
class
ScheduleResultController1
{
@Autowired
private
ScheduleService
schedulerService
;
@Autowired
private
MpsplannedorderService
orderService
;
@Autowired
private
RoutingHeaderService
processService
;
@Autowired
private
RoutingDetailService
operationService
;
@Autowired
private
RoutingDetailEquipService
operationEquipService
;
@Autowired
private
EquipinfoService
equipmentService
;
@GetMapping
(
"/resourcetest"
)
@Operation
(
summary
=
"资源甘特图"
,
description
=
"获取资源甘特图数据"
)
@ApiResponses
({
@ApiResponse
(
responseCode
=
"200"
,
description
=
"成功返回甘特图数据"
),
@ApiResponse
(
responseCode
=
"500"
,
description
=
"内部服务器错误"
)
})
public
R
<
PlanResourceTaskGanttVO1
>
runScheduling
()
{
try
{
// 获取routingid为'SY1102507-0056202车间-21号线'和'SY1102507-0060202车间-21号线'的待调度工单
List
<
Mpsplannedorder
>
orders
=
orderService
.
lambdaQuery
()
.
in
(
Mpsplannedorder:
:
getRoutingid
,
"SY1102507-0056202车间-21号线"
,
"SY1102507-0060202车间-21号线"
)
.
list
();
if
(
orders
.
isEmpty
())
{
// 当没有订单时,返回空的甘特图VO
PlanResourceTaskGanttVO1
ganttVO
=
new
PlanResourceTaskGanttVO1
()
.
setResources
(
new
ArrayList
<>())
.
setEarliestTaskStartTime
(
LocalDateTime
.
of
(
2025
,
6
,
1
,
0
,
0
,
0
))
.
setLastTaskAssignmentTime
(
LocalDateTime
.
of
(
2025
,
12
,
1
,
0
,
0
,
0
));
return
R
.
ok
(
ganttVO
);
}
// 提取所需的工艺ID列表
Set
<
String
>
routingIds
=
orders
.
stream
()
.
map
(
Mpsplannedorder:
:
getRoutingid
)
.
collect
(
Collectors
.
toSet
());
// 根据工单获取相关工艺
List
<
RoutingHeader
>
processes
=
processService
.
lambdaQuery
()
.
in
(
RoutingHeader:
:
getCode
,
routingIds
)
.
list
();
if
(
processes
.
isEmpty
())
{
return
R
.
failed
(
"未找到相关工艺信息"
);
}
// 提取工艺ID用于后续查询
Set
<
Integer
>
processIds
=
processes
.
stream
()
.
map
(
RoutingHeader:
:
getId
)
.
collect
(
Collectors
.
toSet
());
// 根据工艺获取相关工序
List
<
RoutingDetail
>
operations
=
operationService
.
lambdaQuery
()
.
in
(
RoutingDetail:
:
getRoutingHeaderId
,
processIds
)
.
orderByAsc
(
RoutingDetail:
:
getTaskSeq
)
.
list
();
if
(
operations
.
isEmpty
())
{
return
R
.
failed
(
"未找到相关工序信息"
);
}
// 提取工序ID用于后续查询
Set
<
Long
>
operationIds
=
operations
.
stream
()
.
map
(
RoutingDetail:
:
getId
)
.
collect
(
Collectors
.
toSet
());
// 获取相关工序设备关系
List
<
RoutingDetailEquip
>
operationEquipments
=
operationEquipService
.
lambdaQuery
()
.
in
(
RoutingDetailEquip:
:
getRoutingDetailId
,
operationIds
)
.
list
();
if
(
operationEquipments
.
isEmpty
())
{
return
R
.
failed
(
"未找到工序设备关系信息"
);
}
// 提取设备ID用于后续查询
Set
<
Long
>
equipmentIds
=
operationEquipments
.
stream
()
.
map
(
RoutingDetailEquip:
:
getEquipId
)
.
collect
(
Collectors
.
toSet
());
// 获取相关设备
List
<
Equipinfo
>
equipments
=
equipmentService
.
lambdaQuery
()
.
in
(
Equipinfo:
:
getId
,
equipmentIds
)
.
list
();
// 添加空值检查
if
(
orders
==
null
||
processes
==
null
||
operations
==
null
||
operationEquipments
==
null
||
equipments
==
null
)
{
return
R
.
failed
(
"获取调度数据失败,存在空数据"
);
}
List
<
ScheduledTask
>
result
=
schedulerService
.
scheduleOrders
(
orders
,
processes
,
operations
,
operationEquipments
,
equipments
);
// 转换设备信息为简要信息,并关联相关任务
List
<
SimpleEquipinfo1
>
simpleEquipinfos
=
equipments
.
stream
()
.
map
(
equip
->
{
// 查找与该设备关联的任务
List
<
ScheduledTask
>
equipTasks
=
result
.
stream
()
.
filter
(
task
->
task
.
getEquipId
()
!=
null
&&
task
.
getEquipId
().
equals
(
equip
.
getId
()))
.
collect
(
Collectors
.
toList
());
return
new
SimpleEquipinfo1
()
.
setId
(
equip
.
getId
())
.
setEquipId
(
equip
.
getEquipId
())
.
setEquipName
(
equip
.
getEquipName
())
.
setTasks
(
equipTasks
);
})
.
collect
(
Collectors
.
toList
());
// 设置甘特图VO的最早时间为2025年6月1日,最晚时间为2025年12月1日
PlanResourceTaskGanttVO1
ganttVO
=
new
PlanResourceTaskGanttVO1
()
.
setResources
(
simpleEquipinfos
)
.
setEarliestTaskStartTime
(
LocalDateTime
.
of
(
2025
,
6
,
1
,
0
,
0
,
0
))
.
setLastTaskAssignmentTime
(
LocalDateTime
.
of
(
2025
,
12
,
1
,
0
,
0
,
0
));
return
R
.
ok
(
ganttVO
);
}
catch
(
Exception
e
)
{
return
R
.
failed
(
"调度执行失败: "
+
e
.
getMessage
());
}
}
}
\ No newline at end of file
src/main/java/com/aps/service/Algorithm/RoutingDataService.java
View file @
5330e8fc
...
...
@@ -304,7 +304,6 @@ public class RoutingDataService {
machine
.
setCode
(
""
);
machine
.
setName
(
""
);
machines
.
add
(
machine
);
}
...
...
@@ -360,7 +359,7 @@ public class RoutingDataService {
Equipinfo
equipinfo
=
equipinfoList
.
stream
()
.
filter
(
t
->
t
.
getId
().
equals
(
PlanResource
.
getReferenceId
()))
.
findFirst
().
orElse
(
null
);
machine
.
setDepartment
(
PlanResource
.
getDepartTitle
());
if
(
equipinfo
!=
null
)
{
machine
.
setCode
(
equipinfo
.
getEquipId
());
...
...
@@ -408,6 +407,30 @@ public class RoutingDataService {
}
}
else
{
for
(
Machine
machine
:
machines
)
{
PlanResource
PlanResource
=
PlanResources
.
stream
()
.
filter
(
t
->
t
.
getId
()
==
machine
.
getId
())
.
findFirst
().
orElse
(
null
);
if
(
PlanResource
!=
null
)
{
Equipinfo
equipinfo
=
equipinfoList
.
stream
()
.
filter
(
t
->
t
.
getId
().
equals
(
PlanResource
.
getReferenceId
()))
.
findFirst
().
orElse
(
null
);
machine
.
setDepartment
(
PlanResource
.
getDepartTitle
());
if
(
equipinfo
!=
null
)
{
machine
.
setCode
(
equipinfo
.
getEquipId
());
machine
.
setName
(
equipinfo
.
getEquipName
());
}
else
{
machine
.
setCode
(
PlanResource
.
getReferenceCode
());
machine
.
setName
(
PlanResource
.
getTitle
());
}
}
List
<
Shift
>
shifts1
=
new
ArrayList
<>();
Shift
shift
=
new
Shift
();
shift
.
setMachineId
(
machine
.
getId
());
...
...
@@ -488,7 +511,7 @@ public class RoutingDataService {
Equipinfo
equipinfo
=
equipinfoList
.
stream
()
.
filter
(
t
->
t
.
getId
().
equals
(
resource
.
getReferenceId
()))
.
findFirst
().
orElse
(
null
);
machine
.
setDepartment
(
resource
.
getDepartTitle
());
if
(
equipinfo
!=
null
)
{
machine
.
setCode
(
equipinfo
.
getEquipId
());
...
...
src/main/java/com/aps/service/common/ChromosomeDataService.java
View file @
5330e8fc
...
...
@@ -3,6 +3,7 @@ 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.Algorithm.GAScheduleResult
;
import
com.aps.entity.ProdProcessExec
;
import
com.aps.entity.Algorithm.GlobalOperationInfo
;
import
com.aps.entity.Algorithm.IDAndChildID.GroupResult
;
...
...
@@ -28,13 +29,17 @@ import org.springframework.util.CollectionUtils;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.math.BigDecimal
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.math.RoundingMode
;
import
java.time.LocalDateTime
;
import
java.time.OffsetDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeParseException
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
com.aps.service.MaterialInfoService
;
import
com.aps.entity.MaterialInfo
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
@Service
@Slf4j
...
...
@@ -46,6 +51,9 @@ public class ChromosomeDataService {
@Autowired
private
DatabaseQueryService
databaseQueryService
;
@Autowired
private
MaterialInfoService
materialInfoService
;
@Autowired
private
NamedParameterJdbcTemplate
namedParameterJdbcTemplate
;
...
...
@@ -108,6 +116,196 @@ public class ChromosomeDataService {
return
result
.
toString
();
}
/**
* 查询当前场景排产的成品/半成品物料信息
*/
public
Map
<
String
,
Object
>
queryScheduledMaterials
(
String
sceneId
,
Paged
paged
)
{
try
{
// 1. 从文件中加载Chromosome对象
Chromosome
chromosome
=
sceneService
.
loadChromosomeFromFile
(
sceneId
);
if
(
chromosome
==
null
||
chromosome
.
getResult
()
==
null
)
{
return
createEmptyPageResult
();
}
// 2. 从排产结果中提取产品ID列表
Set
<
String
>
productIds
=
chromosome
.
getResult
().
stream
()
.
map
(
GAScheduleResult:
:
getProductId
)
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toSet
());
if
(
productIds
.
isEmpty
())
{
return
createEmptyPageResult
();
}
// 3. 查询MaterialInfo表获取物料详细信息
List
<
MaterialInfo
>
materialInfos
=
queryMaterialInfoByProductIds
(
productIds
,
paged
);
// 4. 构建分页结果
return
buildPageResult
(
materialInfos
,
paged
);
}
catch
(
Exception
e
)
{
log
.
error
(
"查询排产物料失败,场景ID: "
+
sceneId
,
e
);
return
createEmptyPageResult
();
}
}
/**
* 根据产品ID列表查询MaterialInfo
*/
private
List
<
MaterialInfo
>
queryMaterialInfoByProductIds
(
Set
<
String
>
productIds
,
Paged
paged
)
{
// 使用MyBatis-Plus查询
LambdaQueryWrapper
<
MaterialInfo
>
wrapper
=
new
LambdaQueryWrapper
<>();
wrapper
.
in
(
MaterialInfo:
:
getId
,
productIds
)
.
eq
(
MaterialInfo:
:
getIsdeleted
,
0
);
// 添加额外的查询条件
if
(
paged
.
getConditions
()
!=
null
&&
!
paged
.
getConditions
().
isEmpty
())
{
for
(
ConditionEntity
condition
:
paged
.
getConditions
())
{
if
(!
"sceneId"
.
equals
(
condition
.
getFieldName
()))
{
addConditionToWrapper
(
wrapper
,
condition
);
}
}
}
// 添加排序
if
(
paged
.
getSortByList
()
!=
null
&&
!
paged
.
getSortByList
().
isEmpty
())
{
for
(
String
sortBy
:
paged
.
getSortByList
())
{
String
[]
parts
=
sortBy
.
split
(
" "
);
String
fieldName
=
parts
[
0
];
boolean
isAsc
=
parts
.
length
<=
1
||
!
"desc"
.
equalsIgnoreCase
(
parts
[
1
]);
// 根据字段名添加排序
switch
(
fieldName
.
toLowerCase
())
{
case
"id"
:
wrapper
.
orderBy
(
true
,
isAsc
,
MaterialInfo:
:
getId
);
break
;
case
"name"
:
wrapper
.
orderBy
(
true
,
isAsc
,
MaterialInfo:
:
getName
);
break
;
case
"code"
:
wrapper
.
orderBy
(
true
,
isAsc
,
MaterialInfo:
:
getCode
);
break
;
case
"creationtime"
:
wrapper
.
orderBy
(
true
,
isAsc
,
MaterialInfo:
:
getCreationtime
);
break
;
// 可以继续添加其他字段的排序
}
}
}
// 查询数据
List
<
MaterialInfo
>
materialInfos
;
long
total
=
0
;
if
(
paged
.
getPageSize
()
>
0
)
{
// Oracle分页查询 - 使用MyBatis-Plus的Page对象
Page
<
MaterialInfo
>
page
=
new
Page
<>(
paged
.
getPageIndex
(),
paged
.
getPageSize
());
Page
<
MaterialInfo
>
result
=
materialInfoService
.
page
(
page
,
wrapper
);
materialInfos
=
result
.
getRecords
();
total
=
result
.
getTotal
();
}
else
{
materialInfos
=
materialInfoService
.
list
(
wrapper
);
total
=
materialInfos
.
size
();
}
// 将总数存储到paged对象中,供buildPageResult使用
paged
.
setTotal
((
int
)
total
);
return
materialInfos
;
}
/**
* 为查询条件包装器添加条件
*/
private
void
addConditionToWrapper
(
LambdaQueryWrapper
<
MaterialInfo
>
wrapper
,
ConditionEntity
condition
)
{
String
fieldName
=
condition
.
getFieldName
();
String
conditionType
=
condition
.
getConditionalType
();
String
fieldValue
=
condition
.
getFieldValue
();
switch
(
fieldName
.
toLowerCase
())
{
case
"name"
:
if
(
"LIKE"
.
equalsIgnoreCase
(
conditionType
))
{
wrapper
.
like
(
MaterialInfo:
:
getName
,
fieldValue
);
}
else
if
(
"EQUAL"
.
equalsIgnoreCase
(
conditionType
))
{
wrapper
.
eq
(
MaterialInfo:
:
getName
,
fieldValue
);
}
break
;
case
"code"
:
if
(
"LIKE"
.
equalsIgnoreCase
(
conditionType
))
{
wrapper
.
like
(
MaterialInfo:
:
getCode
,
fieldValue
);
}
else
if
(
"EQUAL"
.
equalsIgnoreCase
(
conditionType
))
{
wrapper
.
eq
(
MaterialInfo:
:
getCode
,
fieldValue
);
}
break
;
case
"categoryname"
:
if
(
"LIKE"
.
equalsIgnoreCase
(
conditionType
))
{
wrapper
.
like
(
MaterialInfo:
:
getCategoryName
,
fieldValue
);
}
else
if
(
"EQUAL"
.
equalsIgnoreCase
(
conditionType
))
{
wrapper
.
eq
(
MaterialInfo:
:
getCategoryName
,
fieldValue
);
}
break
;
// 可以继续添加其他字段的条件处理
}
}
/**
* 构建分页结果
*/
private
Map
<
String
,
Object
>
buildPageResult
(
List
<
MaterialInfo
>
data
,
Paged
paged
)
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
"data"
,
data
);
result
.
put
(
"pageIndex"
,
paged
.
getPageIndex
());
result
.
put
(
"pageSize"
,
paged
.
getPageSize
());
result
.
put
(
"total"
,
paged
.
getTotal
()
!=
null
?
paged
.
getTotal
()
:
data
.
size
());
return
result
;
}
/**
* 根据ID查询单个排产物料
*/
private
Object
queryScheduledMaterialById
(
String
sceneId
,
String
id
)
{
try
{
// 1. 从文件中加载Chromosome对象
Chromosome
chromosome
=
sceneService
.
loadChromosomeFromFile
(
sceneId
);
if
(
chromosome
==
null
||
chromosome
.
getResult
()
==
null
)
{
return
null
;
}
// 2. 检查该ID是否在排产结果中
boolean
isScheduled
=
chromosome
.
getResult
().
stream
()
.
anyMatch
(
result
->
id
.
equals
(
result
.
getProductId
()));
if
(!
isScheduled
)
{
return
null
;
}
// 3. 使用MyBatis-Plus查询MaterialInfo
LambdaQueryWrapper
<
MaterialInfo
>
wrapper
=
new
LambdaQueryWrapper
<>();
wrapper
.
eq
(
MaterialInfo:
:
getId
,
id
)
.
eq
(
MaterialInfo:
:
getIsdeleted
,
0
);
MaterialInfo
materialInfo
=
materialInfoService
.
getOne
(
wrapper
);
return
materialInfo
;
}
catch
(
Exception
e
)
{
log
.
error
(
"查询排产物料失败,场景ID: "
+
sceneId
+
", 物料ID: "
+
id
,
e
);
return
null
;
}
}
/**
* 创建空的分页结果
*/
private
Map
<
String
,
Object
>
createEmptyPageResult
()
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
"data"
,
Collections
.
emptyList
());
result
.
put
(
"pageIndex"
,
1
);
result
.
put
(
"pageSize"
,
0
);
result
.
put
(
"total"
,
0
);
return
result
;
}
/**
* 获取实体的字段信息
* @param entityName 实体名称
...
...
@@ -266,10 +464,96 @@ public class ChromosomeDataService {
return
fieldDescriptions
;
}
/**
* 创建空的分页结果
*/
private
Map
<
String
,
Object
>
createEmptyResult
(
Paged
paged
)
{
Map
<
String
,
Object
>
emptyResult
=
new
HashMap
<>();
emptyResult
.
put
(
"records"
,
Collections
.
emptyList
());
emptyResult
.
put
(
"totalCount"
,
0
);
emptyResult
.
put
(
"pageIndex"
,
paged
.
getPageIndex
()
!=
null
?
paged
.
getPageIndex
()
:
1
);
emptyResult
.
put
(
"size"
,
paged
.
getPageSize
()
!=
null
?
paged
.
getPageSize
()
:
10
);
return
emptyResult
;
}
/**
* 过滤Machine对象,移除不需要的字段
*/
private
List
<
Object
>
filterMachineData
(
List
<?>
machineList
)
{
List
<
Object
>
filteredMachines
=
new
ArrayList
<>();
for
(
Object
obj
:
machineList
)
{
if
(
obj
instanceof
Machine
)
{
Machine
originalMachine
=
(
Machine
)
obj
;
Machine
filteredMachine
=
new
Machine
();
// 只复制需要的字段
filteredMachine
.
setId
(
originalMachine
.
getId
());
filteredMachine
.
setName
(
originalMachine
.
getName
());
filteredMachine
.
setEarliestTime
(
originalMachine
.
getEarliestTime
());
filteredMachine
.
setTotalTaskTime
(
originalMachine
.
getTotalTaskTime
());
filteredMachine
.
setCode
(
originalMachine
.
getCode
());
filteredMachine
.
setActualWorkTime
(
originalMachine
.
getActualWorkTime
());
filteredMachine
.
setRate
(
originalMachine
.
getRate
());
filteredMachine
.
setDepartment
(
originalMachine
.
getDepartment
());
// 不设置不需要的字段:shifts, maintenanceWindows, availability, holidays, shiftsChanged, maintenanceWindowsChanged
filteredMachines
.
add
(
filteredMachine
);
}
else
{
filteredMachines
.
add
(
obj
);
}
}
return
filteredMachines
;
}
/**
* 根据场景ID和实体名称查询Chromosome中的分页数据,带条件过滤
*/
public
Map
<
String
,
Object
>
queryChromosomeDataWithConditions
(
String
sceneId
,
String
entityName
,
Paged
paged
)
{
// 对于materialInfo且有sceneId时,在conditions中添加排产物料ID过滤
System
.
out
.
println
(
entityName
);
if
(
"materialinfo"
.
equalsIgnoreCase
(
entityName
)
&&
sceneId
!=
null
&&
!
sceneId
.
isEmpty
())
{
boolean
hasProductIds
=
false
;
try
{
// 从文件中加载Chromosome对象
Chromosome
chromosome
=
sceneService
.
loadChromosomeFromFile
(
sceneId
);
if
(
chromosome
!=
null
&&
chromosome
.
getResult
()
!=
null
)
{
// 从排产结果中提取产品ID列表
Set
<
String
>
productIds
=
chromosome
.
getResult
().
stream
()
.
map
(
GAScheduleResult:
:
getProductId
)
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toSet
());
if
(!
productIds
.
isEmpty
())
{
// 创建物料ID的IN条件
ConditionEntity
idCondition
=
new
ConditionEntity
();
idCondition
.
setFieldName
(
"id"
);
idCondition
.
setConditionalType
(
"IN"
);
idCondition
.
setFieldValue
(
String
.
join
(
","
,
productIds
));
// 添加到conditions中
if
(
paged
.
getConditions
()
==
null
)
{
paged
.
setConditions
(
new
ArrayList
<>());
}
paged
.
getConditions
().
add
(
idCondition
);
hasProductIds
=
true
;
}
}
// 如果没有找到productIds,返回空结果
if
(!
hasProductIds
)
{
return
createEmptyResult
(
paged
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"提取排产物料ID失败,场景ID: "
+
sceneId
,
e
);
return
createEmptyResult
(
paged
);
}
finally
{
// 无论是否发生异常,都移除原始的sceneId条件
if
(
paged
.
getConditions
()
!=
null
)
{
paged
.
getConditions
().
removeIf
(
condition
->
"sceneId"
.
equalsIgnoreCase
(
condition
.
getFieldName
()));
}
}
}
EntityConfig
config
=
getEntityConfig
(
entityName
);
if
(
config
.
getDataSource
()
==
DataSourceType
.
FILE
)
{
...
...
@@ -284,6 +568,49 @@ public class ChromosomeDataService {
* 查询文件数据列表(支持条件过滤)
*/
public
List
<
Object
>
queryChromosomeDataList
(
String
sceneId
,
String
entityName
,
Paged
paged
)
{
// 对于materialInfo且有sceneId时,在conditions中添加排产物料ID过滤
if
(
"materialinfo"
.
equalsIgnoreCase
(
entityName
)
&&
sceneId
!=
null
&&
!
sceneId
.
isEmpty
())
{
boolean
hasProductIds
=
false
;
try
{
// 从文件中加载Chromosome对象
Chromosome
chromosome
=
sceneService
.
loadChromosomeFromFile
(
sceneId
);
if
(
chromosome
!=
null
&&
chromosome
.
getResult
()
!=
null
)
{
// 从排产结果中提取产品ID列表
Set
<
String
>
productIds
=
chromosome
.
getResult
().
stream
()
.
map
(
GAScheduleResult:
:
getProductId
)
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toSet
());
if
(!
productIds
.
isEmpty
())
{
// 创建物料ID的IN条件
ConditionEntity
idCondition
=
new
ConditionEntity
();
idCondition
.
setFieldName
(
"id"
);
idCondition
.
setConditionalType
(
"IN"
);
idCondition
.
setFieldValue
(
String
.
join
(
","
,
productIds
));
// 添加到conditions中
if
(
paged
.
getConditions
()
==
null
)
{
paged
.
setConditions
(
new
ArrayList
<>());
}
paged
.
getConditions
().
add
(
idCondition
);
hasProductIds
=
true
;
}
}
// 如果没有找到productIds,返回空结果
if
(!
hasProductIds
)
{
return
Collections
.
emptyList
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
"提取排产物料ID失败,场景ID: "
+
sceneId
,
e
);
return
Collections
.
emptyList
();
}
finally
{
// 无论是否发生异常,都移除原始的sceneId条件
if
(
paged
.
getConditions
()
!=
null
)
{
paged
.
getConditions
().
removeIf
(
condition
->
"sceneId"
.
equalsIgnoreCase
(
condition
.
getFieldName
()));
}
}
}
EntityConfig
config
=
getEntityConfig
(
entityName
);
if
(
config
.
getDataSource
()
==
DataSourceType
.
FILE
)
{
...
...
@@ -360,7 +687,7 @@ public class ChromosomeDataService {
}
}
else
{
Object
data
=
queryFileData
(
sceneId
,
config
);
return
applyConditionsToList
(
data
,
paged
);
return
applyConditionsToList
(
data
,
paged
,
entityName
);
}
}
else
{
// 数据库查询
...
...
@@ -372,6 +699,28 @@ public class ChromosomeDataService {
* 根据ID查询单条数据
*/
public
Object
queryChromosomeDataById
(
String
sceneId
,
String
entityName
,
String
id
)
{
// 对于materialInfo且有sceneId时,从排产结果中检查
if
(
"materialinfo"
.
equalsIgnoreCase
(
entityName
)
&&
sceneId
!=
null
&&
!
sceneId
.
isEmpty
())
{
try
{
// 1. 从文件中加载Chromosome对象
Chromosome
chromosome
=
sceneService
.
loadChromosomeFromFile
(
sceneId
);
if
(
chromosome
==
null
||
chromosome
.
getResult
()
==
null
)
{
return
null
;
}
// 2. 检查该ID是否在排产结果中
boolean
isScheduled
=
chromosome
.
getResult
().
stream
()
.
anyMatch
(
result
->
id
.
equals
(
result
.
getProductId
()));
if
(!
isScheduled
)
{
return
null
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"检查排产物料失败,场景ID: "
+
sceneId
+
", 物料ID: "
+
id
,
e
);
return
null
;
}
}
EntityConfig
config
=
getEntityConfig
(
entityName
);
if
(
config
.
getDataSource
()
==
DataSourceType
.
FILE
)
{
...
...
@@ -414,6 +763,13 @@ public class ChromosomeDataService {
config
.
setEntityName
(
entityName
);
config
.
setDataSource
(
DataSourceType
.
FILE
);
config
.
setFieldName
(
"kpiMetrics"
);
}
// 特殊处理:当实体是Machine时,映射到Machines字段
else
if
(
"machine"
.
equalsIgnoreCase
(
key
))
{
config
=
new
EntityConfig
();
config
.
setEntityName
(
entityName
);
config
.
setDataSource
(
DataSourceType
.
FILE
);
config
.
setFieldName
(
"Machines"
);
}
else
{
// 自动创建数据库配置(默认行为)
config
=
createDefaultDbConfig
(
entityName
);
...
...
@@ -613,6 +969,12 @@ public class ChromosomeDataService {
// 应用排序
List
<
Object
>
sortedData
=
sortData
(
dataList
,
paged
);
// 特殊处理:当实体是Machine时,过滤不需要的字段
if
(
"machine"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
sortedData
=
filterMachineData
(
sortedData
);
}
data
=
sortedData
;
}
}
...
...
@@ -645,6 +1007,28 @@ public class ChromosomeDataService {
return
result
;
}
/**
* 过滤单个Machine对象,移除不需要的字段
*/
private
Object
filterSingleMachineData
(
Object
machineObj
)
{
if
(
machineObj
instanceof
Machine
)
{
Machine
originalMachine
=
(
Machine
)
machineObj
;
Machine
filteredMachine
=
new
Machine
();
// 只复制需要的字段
filteredMachine
.
setId
(
originalMachine
.
getId
());
filteredMachine
.
setName
(
originalMachine
.
getName
());
filteredMachine
.
setEarliestTime
(
originalMachine
.
getEarliestTime
());
filteredMachine
.
setTotalTaskTime
(
originalMachine
.
getTotalTaskTime
());
filteredMachine
.
setCode
(
originalMachine
.
getCode
());
filteredMachine
.
setActualWorkTime
(
originalMachine
.
getActualWorkTime
());
filteredMachine
.
setRate
(
originalMachine
.
getRate
());
filteredMachine
.
setDepartment
(
originalMachine
.
getDepartment
());
// 不设置不需要的字段:shifts, maintenanceWindows, availability, holidays, shiftsChanged, maintenanceWindowsChanged
return
filteredMachine
;
}
return
machineObj
;
}
/**
* 根据ID查询文件数据
*/
...
...
@@ -704,12 +1088,20 @@ public class ChromosomeDataService {
.
orElse
(
null
);
if
(
item
!=
null
)
{
// 特殊处理:当实体是Machine时,过滤不需要的字段
if
(
"machine"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
return
filterSingleMachineData
(
item
);
}
return
item
;
}
else
{
return
null
;
// 找不到数据时返回null而不是抛出异常
}
}
else
{
// 如果不是列表,直接返回结果
// 特殊处理:当实体是Machine时,过滤不需要的字段
if
(
"machine"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
return
filterSingleMachineData
(
result
);
}
return
result
;
}
}
...
...
@@ -734,7 +1126,7 @@ public class ChromosomeDataService {
/**
* 将数据应用条件过滤并返回列表
*/
private
List
<
Object
>
applyConditionsToList
(
Object
data
,
Paged
paged
)
{
private
List
<
Object
>
applyConditionsToList
(
Object
data
,
Paged
paged
,
String
entityName
)
{
// 检查是否是直接传入的EntityConfig(这种情况可能需要获取场景ID和实体类型)
// 实际上这个方法是在queryChromosomeDataList中调用的,此时数据已经从文件中获取
...
...
@@ -749,10 +1141,21 @@ public class ChromosomeDataService {
// 应用排序
dataList
=
sortData
(
dataList
,
paged
);
// 特殊处理:当实体是Machine时,过滤不需要的字段
if
(
"machine"
.
equalsIgnoreCase
(
entityName
))
{
dataList
=
filterMachineData
(
dataList
);
}
return
dataList
;
}
else
{
List
<
Object
>
resultList
=
new
ArrayList
<>();
resultList
.
add
(
data
);
// 特殊处理:当实体是Machine时,过滤不需要的字段
if
(
"machine"
.
equalsIgnoreCase
(
entityName
)
&&
data
instanceof
Machine
)
{
resultList
=
filterMachineData
(
resultList
);
}
return
resultList
;
}
}
...
...
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