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
fa5b9c03
Commit
fa5b9c03
authored
Jan 23, 2026
by
DESKTOP-VKRD9QF\Administration
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
离散参数修改,公共分页和list查询修改
parent
d98a5bf6
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
977 additions
and
411 deletions
+977
-411
ChromosomeDataController.java
...a/com/aps/controller/common/ChromosomeDataController.java
+21
-0
Entry.java
src/main/java/com/aps/entity/basic/Entry.java
+2
-2
Order.java
src/main/java/com/aps/entity/basic/Order.java
+134
-12
Paged.java
src/main/java/com/aps/entity/common/Paged.java
+22
-5
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+6
-3
DiscreteParameterDurationService.java
...ava/com/aps/service/DiscreteParameterDurationService.java
+3
-3
ChromosomeDataService.java
...in/java/com/aps/service/common/ChromosomeDataService.java
+496
-197
DatabaseQueryService.java
...ain/java/com/aps/service/common/DatabaseQueryService.java
+62
-5
DiscreteParameterDurationServiceImpl.java
...ps/service/impl/DiscreteParameterDurationServiceImpl.java
+17
-26
DiscreteParameterMatrixServiceImpl.java
.../aps/service/impl/DiscreteParameterMatrixServiceImpl.java
+2
-0
LanuchServiceImpl.java
src/main/java/com/aps/service/impl/LanuchServiceImpl.java
+211
-157
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 @
fa5b9c03
...
...
@@ -4,6 +4,7 @@ import com.aps.common.util.R;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.entity.basic.Entry
;
import
com.aps.entity.basic.MachineOption
;
import
com.aps.entity.common.FieldInfo
;
import
com.aps.entity.common.Paged
;
import
com.aps.service.common.ChromosomeDataService
;
import
com.aps.service.plan.PlanResultService
;
...
...
@@ -179,6 +180,26 @@ public class ChromosomeDataController {
}
/**
* 获取实体的字段信息
* 示例:
* - 文件实体: GET /queryChromosome/order/info?sceneId=xxx
* - 数据库实体: GET /queryChromosome/user/info
*
* @param sceneId 场景ID (文件实体可选,数据库实体不需要)
* @param entityName 实体名称 (如: order, entry, machine, user, department等)
* @return 字段信息列表
*/
@GetMapping
(
"/{entityName}/info"
)
@Operation
(
summary
=
"获取实体字段信息"
,
description
=
"根据实体名称获取字段名称、类型等信息,支持文件实体和数据库实体"
)
public
R
<
List
<
FieldInfo
>>
getEntityInfo
(
@Parameter
(
description
=
"实体名称"
,
required
=
true
)
@PathVariable
String
entityName
)
{
List
<
FieldInfo
>
fieldInfos
=
chromosomeDataService
.
getEntityInfo
(
entityName
);
return
R
.
ok
(
fieldInfos
);
}
...
...
src/main/java/com/aps/entity/basic/Entry.java
View file @
fa5b9c03
...
...
@@ -143,8 +143,8 @@ public class Entry {
private
BigDecimal
singleOut
;
//单件产出
private
double
changeLineTime
;
//换模时间
private
BigDecimal
setupTime
;
//准备时间
private
int
teardownTime
;
//
收尾时间
(后处理时间)
private
int
preTime
;
//
收尾时间(后
处理时间)
private
int
teardownTime
;
// (后处理时间)
private
int
preTime
;
//
(前
处理时间)
//常数时间
private
int
constTime
;
private
String
equipCode
;
//设备编码
...
...
src/main/java/com/aps/entity/basic/Order.java
View file @
fa5b9c03
...
...
@@ -12,46 +12,168 @@ import java.util.List;
*/
@Data
public
class
Order
{
/**
* 自增主键
*/
private
int
id
;
/**
* 订单ID
*/
private
String
orderId
;
/**
* 订单编码
*/
private
String
orderCode
;
/**
* 产品ID
*/
private
int
productId
;
/**
* 物料ID
*/
private
String
materialId
;
/**
* 物料编码
*/
private
String
materialCode
;
/**
* 物料名称
*/
private
String
materialName
;
/**
* 系列
*/
private
String
serie
;
/**
* 工艺路线ID
*/
private
Integer
routingId
;
/**
* 工艺路线编码
*/
private
String
routingCode
;
private
double
quantity
=
100
;
// 100个
/**
* 订单数量,默认值:100
*/
private
double
quantity
=
100
;
/**
* 生产数量
*/
private
double
sYQuantity
;
/**
* 开始日期
*/
private
LocalDateTime
startDate
;
/**
* 到期日期
*/
private
LocalDateTime
dueDate
;
/**
* 组开始日期
*/
private
LocalDateTime
groupStartDate
;
/**
* 组到期日期
*/
private
LocalDateTime
groupDueDate
;
/**
* 订单完成时间
*/
private
LocalDateTime
orderCompletion
;
/**
* 订单开始时间
*/
private
LocalDateTime
orderStart
;
/**
* 机器加工时间
*/
private
double
machineProcessingTime
;
/**
* 订单流程
*/
private
double
orderFlow
;
/**
* 订单生产时间
*/
private
double
orderProductTime
;
/**
* 延误时间
*/
private
double
tardiness
;
/**
* 优先级
*/
private
int
priority
;
/**
* 是否可拆分,默认值:false
*/
private
boolean
canSplit
=
false
;
/**
* 是否可中断,默认值:false
*/
private
boolean
canInterrupt
=
false
;
/**
* 实际优先级
*/
private
double
actualPriority
;
/**
* 主ID
*/
private
String
mainId
;
/*使用这个半成品的成品工单*/
private
List
<
Integer
>
FinishOrderId
;
/**
* 使用这个半成品的成品工单
*/
private
List
<
Integer
>
FinishOrderId
;
/**
* 是否新创建,默认值:false
*/
private
boolean
newCreate
=
false
;
/**
* 是否创建BOM,默认值:false
*/
private
boolean
createBom
=
false
;
/
// <summary>
///
关联的成品工序ID(核心:明确该半成品服务于哪个成品工序)
/// </summary>
/
**
*
关联的成品工序ID(核心:明确该半成品服务于哪个成品工序)
*/
private
List
<
Integer
>
TargetFinishedOperationId
;
private
double
delayHours
;
//延迟时间
//物料需求
/**
* 延迟时间
*/
private
double
delayHours
;
/**
* 物料需求
*/
private
List
<
OrderMaterialRequirement
>
materialRequirementList
;
}
\ No newline at end of file
src/main/java/com/aps/entity/common/Paged.java
View file @
fa5b9c03
...
...
@@ -7,22 +7,23 @@ import java.util.List;
import
java.util.Optional
;
/**
*
*
* @Title: PagedGridResult.java
* @Package com.lei.utils
* @Description: 用来返回分页Grid的数据格式
*/
public
class
Paged
{
private
Integer
pageIndex
=
1
;
//当前页
private
Integer
pageSize
=
1000
;
//每页多少条
private
Integer
total
=
0
;
// 特殊设置,总记录数,如果前台带有此值,则分页查询时不查询总数。
private
List
<
String
>
sortByList
=
new
ArrayList
<>();
// 多字段排序列表,格式如["type asc", "id desc"]
private
String
sortBy
=
""
;
//排序字段
private
Boolean
desc
=
true
;
//是否倒序
private
String
fields
=
""
;
// 返回的字段
private
String
table
;
// 返回的表
//分组字段名称
private
String
fields
=
""
;
// 返回的字段
private
String
table
=
""
;
// 返回的表
private
String
groupName
;
private
Boolean
and
=
true
;
// 条件逻辑关系,true为与关系,false为或关系
private
List
<
ConditionEntity
>
conditions
=
new
ArrayList
<>();
//条件集合
...
...
@@ -125,4 +126,20 @@ public class Paged {
public
void
setTotal
(
Integer
total
)
{
this
.
total
=
total
;
}
public
List
<
String
>
getSortByList
()
{
return
sortByList
;
}
public
void
setSortByList
(
List
<
String
>
sortByList
)
{
this
.
sortByList
=
sortByList
;
}
public
Boolean
getAnd
()
{
return
and
;
}
public
void
setAnd
(
Boolean
and
)
{
this
.
and
=
and
;
}
}
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
fa5b9c03
...
...
@@ -914,11 +914,14 @@ if(finishedOrder==null||finishedOrder.size()==0)
// setupTime = (prev.getProductId() != operation.getProductId())
// ? (int) discreteParameterMatrixService.getDiscreteParameterMatrixValue(prev, operation)
// : 0;
DiscreteParameterMatrixService
service
=
SpringContextUtil
.
getBean
(
DiscreteParameterMatrixService
.
class
);
DiscreteParameterMatrixService
discreteParameterMatrixService
=
SpringContextUtil
.
getBean
(
DiscreteParameterMatrixService
.
class
);
DiscreteParameterDurationService
discreteParameterDurationService
=
SpringContextUtil
.
getBean
(
DiscreteParameterDurationService
.
class
);
double
discreteParameterMatrixValue
=
service
.
getDiscreteParameterMatrixValue
(
operation
,
prev
);
setupTime
=
(
int
)
discreteParameterMatrixValue
;
double
discreteParameterDurationValue
=
discreteParameterDurationService
.
calculateChangeoverTime
(
prev
,
operation
,
machine
,
_allOperations
,
earliestStartTime
,
machineTasks
);
double
discreteParameterMatrixValue
=
discreteParameterMatrixService
.
getDiscreteParameterMatrixValue
(
operation
,
prev
);
setupTime
=
(
int
)
Math
.
max
(
discreteParameterDurationValue
,
discreteParameterMatrixValue
);
// setupTime = (int) discreteParameterMatrixValue;
...
...
src/main/java/com/aps/service/DiscreteParameterDurationService.java
View file @
fa5b9c03
...
...
@@ -19,8 +19,8 @@ import java.util.List;
public
interface
DiscreteParameterDurationService
extends
IService
<
DiscreteParameterDuration
>
{
double
calculateChangeoverTime
(
List
<
GAScheduleResult
>
existingGenes
,
Entry
operation
,
double
calculateChangeoverTime
(
Entry
lastEntry
,
Entry
entry
,
Machine
machine
,
List
<
Entry
>
allOperations
,
int
startTime
);
List
<
Entry
>
allOperations
,
int
startTime
,
List
<
GAScheduleResult
>
machineTasks
);
}
src/main/java/com/aps/service/common/ChromosomeDataService.java
View file @
fa5b9c03
...
...
@@ -4,7 +4,10 @@ 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.Algorithm.GlobalOperationInfo
;
import
com.aps.entity.Algorithm.IDAndChildID.GroupResult
;
import
com.aps.entity.basic.Entry
;
import
com.aps.entity.basic.Machine
;
import
com.aps.entity.basic.MachineOption
;
import
com.aps.entity.basic.Order
;
import
com.aps.entity.common.*
;
...
...
@@ -15,12 +18,15 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.namedparam.MapSqlParameterSource
;
import
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.time.LocalDateTime
;
...
...
@@ -31,6 +37,7 @@ import java.util.*;
import
java.util.stream.Collectors
;
@Service
@Slf4j
public
class
ChromosomeDataService
{
@Autowired
...
...
@@ -41,6 +48,9 @@ public class ChromosomeDataService {
@Autowired
private
NamedParameterJdbcTemplate
namedParameterJdbcTemplate
;
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Autowired
private
Map
<
String
,
EntityConfig
>
entityConfigMap
;
...
...
@@ -51,7 +61,7 @@ public class ChromosomeDataService {
* 根据场景ID和实体名称查询Chromosome中的数据
*/
ObjectMapper
objectMapper
=
new
ObjectMapper
()
ObjectMapper
objectMapper
=
new
ObjectMapper
()
.
registerModule
(
new
JavaTimeModule
())
.
configure
(
SerializationFeature
.
WRITE_DATES_AS_TIMESTAMPS
,
false
);
// public Object queryChromosomeData(String sceneId, String entityName) {
...
...
@@ -67,7 +77,7 @@ public class ChromosomeDataService {
// }
// }
/**
* 驼峰命名转下划线大写:prodProduct -> PROD_PRODUCT
* 驼峰命名转下划线大写:prodProduct -> PROD_PRODUCT
, apsOder -> APS_ORDER
*/
private
String
camelCaseToUnderScoreUpperCase
(
String
camelCase
)
{
if
(
camelCase
==
null
||
camelCase
.
isEmpty
())
{
...
...
@@ -90,8 +100,172 @@ public class ChromosomeDataService {
result
.
append
(
Character
.
toUpperCase
(
c
));
}
// 特殊处理:apsOder -> APS_ORDER
if
(
result
.
toString
().
equals
(
"APS_ODER"
))
{
return
"APS_ORDER"
;
}
return
result
.
toString
();
}
/**
* 获取实体的字段信息
* @param entityName 实体名称
* @return 字段信息列表
*/
public
List
<
FieldInfo
>
getEntityInfo
(
String
entityName
)
{
List
<
FieldInfo
>
fieldInfos
=
new
ArrayList
<>();
// 获取实体配置
EntityConfig
config
=
getEntityConfig
(
entityName
);
// 处理文件实体
if
(
config
.
getDataSource
()
==
DataSourceType
.
FILE
)
{
// 实体类映射
Map
<
String
,
Class
<?>>
fileEntityClassMap
=
new
HashMap
<>();
fileEntityClassMap
.
put
(
"order"
,
Order
.
class
);
fileEntityClassMap
.
put
(
"entry"
,
Entry
.
class
);
fileEntityClassMap
.
put
(
"machine"
,
Machine
.
class
);
fileEntityClassMap
.
put
(
"machineoption"
,
MachineOption
.
class
);
fileEntityClassMap
.
put
(
"prodprocessexec"
,
ProdProcessExec
.
class
);
fileEntityClassMap
.
put
(
"globaloperationinfo"
,
GlobalOperationInfo
.
class
);
fileEntityClassMap
.
put
(
"groupresult"
,
GroupResult
.
class
);
// 获取实体类
Class
<?>
entityClass
=
fileEntityClassMap
.
get
(
entityName
.
toLowerCase
());
// 如果没有找到实体类,返回空列表
if
(
entityClass
==
null
)
{
return
fieldInfos
;
}
// 通过反射获取所有字段(包括父类字段)
List
<
Field
>
fields
=
new
ArrayList
<>();
Class
<?>
currentClass
=
entityClass
;
while
(
currentClass
!=
null
&&
currentClass
!=
Object
.
class
)
{
fields
.
addAll
(
Arrays
.
asList
(
currentClass
.
getDeclaredFields
()));
currentClass
=
currentClass
.
getSuperclass
();
}
// 获取字段描述映射
Map
<
String
,
String
>
fieldDescriptions
=
getFieldDescriptions
(
entityName
);
// 遍历字段,生成FieldInfo
for
(
Field
field
:
fields
)
{
// 跳过静态字段
if
(
Modifier
.
isStatic
(
field
.
getModifiers
()))
{
continue
;
}
FieldInfo
fieldInfo
=
new
FieldInfo
();
fieldInfo
.
setFieldName
(
field
.
getName
());
fieldInfo
.
setFieldType
(
field
.
getType
().
getSimpleName
());
// 设置字段描述
fieldInfo
.
setDescription
(
fieldDescriptions
.
getOrDefault
(
field
.
getName
(),
""
));
fieldInfo
.
setDataSource
(
config
.
getDataSource
().
name
());
fieldInfo
.
setEntityName
(
entityName
);
fieldInfos
.
add
(
fieldInfo
);
}
}
// 处理数据库实体
else
{
try
{
// 获取数据库连接
java
.
sql
.
Connection
connection
=
jdbcTemplate
.
getDataSource
().
getConnection
();
// 获取数据库元数据
java
.
sql
.
DatabaseMetaData
metaData
=
connection
.
getMetaData
();
// 获取表名
String
tableName
=
config
.
getTableName
();
// 获取表的列信息
java
.
sql
.
ResultSet
columns
=
metaData
.
getColumns
(
null
,
null
,
tableName
,
null
);
// 遍历列信息,生成FieldInfo
while
(
columns
.
next
())
{
FieldInfo
fieldInfo
=
new
FieldInfo
();
fieldInfo
.
setFieldName
(
columns
.
getString
(
"COLUMN_NAME"
));
fieldInfo
.
setFieldType
(
columns
.
getString
(
"TYPE_NAME"
));
fieldInfo
.
setDescription
(
columns
.
getString
(
"REMARKS"
));
fieldInfo
.
setDataSource
(
config
.
getDataSource
().
name
());
fieldInfo
.
setEntityName
(
entityName
);
fieldInfos
.
add
(
fieldInfo
);
}
// 关闭资源
columns
.
close
();
connection
.
close
();
}
catch
(
Exception
e
)
{
log
.
error
(
"获取数据库表字段信息失败: {}"
,
e
.
getMessage
(),
e
);
}
}
return
fieldInfos
;
}
/**
* 获取指定实体的字段描述映射
* @param entityName 实体名称
* @return 字段描述映射
*/
private
Map
<
String
,
String
>
getFieldDescriptions
(
String
entityName
)
{
Map
<
String
,
String
>
fieldDescriptions
=
new
HashMap
<>();
// 根据实体名称返回对应的字段描述
switch
(
entityName
.
toLowerCase
())
{
case
"order"
:
// Order实体字段描述
fieldDescriptions
.
put
(
"id"
,
"自增主键"
);
fieldDescriptions
.
put
(
"orderId"
,
"订单ID"
);
fieldDescriptions
.
put
(
"orderCode"
,
"订单编码"
);
fieldDescriptions
.
put
(
"productId"
,
"产品ID"
);
fieldDescriptions
.
put
(
"materialId"
,
"物料ID"
);
fieldDescriptions
.
put
(
"materialCode"
,
"物料编码"
);
fieldDescriptions
.
put
(
"materialName"
,
"物料名称"
);
fieldDescriptions
.
put
(
"serie"
,
"系列"
);
fieldDescriptions
.
put
(
"routingId"
,
"工艺路线ID"
);
fieldDescriptions
.
put
(
"routingCode"
,
"工艺路线编码"
);
fieldDescriptions
.
put
(
"quantity"
,
"订单数量,默认值:100"
);
fieldDescriptions
.
put
(
"sYQuantity"
,
"生产数量"
);
fieldDescriptions
.
put
(
"startDate"
,
"开始日期"
);
fieldDescriptions
.
put
(
"dueDate"
,
"到期日期"
);
fieldDescriptions
.
put
(
"groupStartDate"
,
"组开始日期"
);
fieldDescriptions
.
put
(
"groupDueDate"
,
"组到期日期"
);
fieldDescriptions
.
put
(
"orderCompletion"
,
"订单完成时间"
);
fieldDescriptions
.
put
(
"orderStart"
,
"订单开始时间"
);
fieldDescriptions
.
put
(
"machineProcessingTime"
,
"机器加工时间"
);
fieldDescriptions
.
put
(
"orderFlow"
,
"订单流程"
);
fieldDescriptions
.
put
(
"orderProductTime"
,
"订单生产时间"
);
fieldDescriptions
.
put
(
"tardiness"
,
"延误时间"
);
fieldDescriptions
.
put
(
"priority"
,
"优先级"
);
fieldDescriptions
.
put
(
"canSplit"
,
"是否可拆分,默认值:false"
);
fieldDescriptions
.
put
(
"canInterrupt"
,
"是否可中断,默认值:false"
);
fieldDescriptions
.
put
(
"actualPriority"
,
"实际优先级"
);
fieldDescriptions
.
put
(
"mainId"
,
"主ID"
);
fieldDescriptions
.
put
(
"FinishOrderId"
,
"使用这个半成品的成品工单"
);
fieldDescriptions
.
put
(
"newCreate"
,
"是否新创建,默认值:false"
);
fieldDescriptions
.
put
(
"createBom"
,
"是否创建BOM,默认值:false"
);
fieldDescriptions
.
put
(
"TargetFinishedOperationId"
,
"关联的成品工序ID(核心:明确该半成品服务于哪个成品工序)"
);
fieldDescriptions
.
put
(
"delayHours"
,
"延迟时间"
);
fieldDescriptions
.
put
(
"materialRequirementList"
,
"物料需求"
);
break
;
// 可以继续添加其他实体的字段描述
case
"entry"
:
// Entry实体字段描述
// 后续可以补充
break
;
case
"machine"
:
// Machine实体字段描述
// 后续可以补充
break
;
}
return
fieldDescriptions
;
}
/**
* 根据场景ID和实体名称查询Chromosome中的分页数据,带条件过滤
*/
...
...
@@ -120,43 +294,40 @@ public class ChromosomeDataService {
entryConfig
.
setEntityName
(
"entry"
);
entryConfig
.
setDataSource
(
DataSourceType
.
FILE
);
entryConfig
.
setFieldName
(
"allOperations"
);
Object
entryData
=
queryFileData
(
sceneId
,
entryConfig
);
if
(
entryData
instanceof
List
)
{
List
<?>
entryList
=
(
List
<?>)
entryData
;
List
<
MachineOption
>
resultMachineOption
s
=
new
ArrayList
<>();
List
<
Object
>
resultEntrie
s
=
new
ArrayList
<>();
//
过滤Entry列表,只保留与场景ID匹配的Entry
//
先将Entry对象转换为Object对象,方便后续处理
for
(
Object
obj
:
entryList
)
{
if
(
obj
instanceof
Entry
)
{
Entry
entry
=
(
Entry
)
obj
;
// 检查Entry的SceneId是否匹配
if
(
entry
.
getSceneId
()
!=
null
&&
!
entry
.
getSceneId
().
equals
(
sceneId
))
{
continue
;
// 跳过不属于当前场景的Entry
}
// 检查Entry是否满足其他条件
boolean
matchesOtherConditions
=
true
;
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getConditions
()))
{
for
(
ConditionEntity
condition
:
paged
.
getConditions
())
{
if
(
condition
!=
null
&&
!
"sceneId"
.
equalsIgnoreCase
(
condition
.
getFieldName
()))
{
if
(!
matchesCondition
(
entry
,
condition
.
getFieldName
(),
condition
.
getFieldValue
(),
ConditionEnum
.
getByName
(
condition
.
getConditionalType
())))
{
matchesOtherConditions
=
false
;
break
;
}
}
}
if
(
entry
.
getSceneId
()
==
null
||
entry
.
getSceneId
().
equals
(
sceneId
))
{
resultEntries
.
add
(
obj
);
}
if
(
matchesOtherConditions
&&
entry
.
getMachineOptions
()
!=
null
)
{
// 如果Entry满足所有条件,添加其MachineOptions
}
}
// 应用条件过滤,支持AND/OR关系
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getConditions
()))
{
resultEntries
=
filterDataByConditions
(
resultEntries
,
paged
.
getConditions
(),
paged
.
getAnd
());
}
// 提取符合条件的Entry的MachineOptions
List
<
MachineOption
>
resultMachineOptions
=
new
ArrayList
<>();
for
(
Object
obj
:
resultEntries
)
{
if
(
obj
instanceof
Entry
)
{
Entry
entry
=
(
Entry
)
obj
;
if
(
entry
.
getMachineOptions
()
!=
null
)
{
resultMachineOptions
.
addAll
(
entry
.
getMachineOptions
());
}
}
}
return
(
List
<
Object
>)
(
List
<?>)
resultMachineOptions
;
}
else
{
return
new
ArrayList
<>();
...
...
@@ -164,36 +335,26 @@ public class ChromosomeDataService {
}
else
if
(
"order"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
// 特殊处理:当实体是Order时,使用orderId字段进行查询
Object
data
=
queryFileData
(
sceneId
,
config
);
if
(
data
instanceof
List
)
{
List
<?>
orderList
=
(
List
<?>)
data
;
List
<
O
rder
>
resultOrders
=
new
ArrayList
<>();
List
<
O
bject
>
resultOrders
=
new
ArrayList
<>();
//
过滤Order列表,只保留与场景ID匹配的Order(如果Order中有SceneId的话)
//
先将Order对象转换为Object对象,方便后续处理
for
(
Object
obj
:
orderList
)
{
if
(
obj
instanceof
Order
)
{
Order
order
=
(
Order
)
obj
;
// 检查Order是否满足条件
boolean
matchesOtherConditions
=
true
;
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getConditions
()))
{
for
(
ConditionEntity
condition
:
paged
.
getConditions
())
{
if
(
condition
!=
null
&&
!
"sceneId"
.
equalsIgnoreCase
(
condition
.
getFieldName
()))
{
if
(!
matchesCondition
(
order
,
condition
.
getFieldName
(),
condition
.
getFieldValue
(),
ConditionEnum
.
getByName
(
condition
.
getConditionalType
())))
{
matchesOtherConditions
=
false
;
break
;
}
}
}
}
if
(
matchesOtherConditions
)
{
resultOrders
.
add
(
order
);
}
resultOrders
.
add
(
obj
);
}
}
return
(
List
<
Object
>)
(
List
<?>)
resultOrders
;
// 应用条件过滤,支持AND/OR关系
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getConditions
()))
{
resultOrders
=
filterDataByConditions
(
resultOrders
,
paged
.
getConditions
(),
paged
.
getAnd
());
}
// 应用排序
List
<
Object
>
sortedData
=
sortData
(
resultOrders
,
paged
);
return
sortedData
;
}
else
{
return
new
ArrayList
<>();
}
...
...
@@ -324,7 +485,7 @@ public class ChromosomeDataService {
try
{
String
fieldName
=
config
.
getFieldName
();
// // 特殊处理:当实体是ProdProcessExec时,使用allOperations字段
// if ("prodprocessexec".equalsIgnoreCase(config.getEntityName())) {
// fieldName = "allOperations";
...
...
@@ -334,26 +495,26 @@ public class ChromosomeDataService {
if
(
"machineoption"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
fieldName
=
"allOperations"
;
}
Field
field
=
Chromosome
.
class
.
getDeclaredField
(
fieldName
);
field
.
setAccessible
(
true
);
Object
result
=
field
.
get
(
chromosome
);
// // 如果实体是ProdProcessExec,但数据源是Entry,则进行转换
// if ("prodprocessexec".equalsIgnoreCase(config.getEntityName())) {
// return convertEntryToProdProcessExec(result);
// }
// 如果实体是MachineOption,提取Entry中的MachineOption列表
if
(
"machineoption"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
return
extractMachineOptionsFromEntries
(
result
);
}
// 如果实体是KpiMetrics,直接返回结果
if
(
"kpimetrics"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
return
result
;
}
return
result
;
}
catch
(
NoSuchFieldException
e
)
{
throw
new
RuntimeException
(
"Chromosome类中未找到字段: "
+
config
.
getFieldName
(),
e
);
...
...
@@ -367,7 +528,7 @@ public class ChromosomeDataService {
*/
private
Map
<
String
,
Object
>
queryFileDataWithConditions
(
String
sceneId
,
EntityConfig
config
,
Paged
paged
)
{
Object
data
;
// 特殊处理:当实体是MachineOption时,需要先获取Entry列表,再提取符合条件的Entry的MachineOption
if
(
"machineoption"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
// 先获取Entry列表(而不是MachineOption列表)
...
...
@@ -375,43 +536,40 @@ public class ChromosomeDataService {
entryConfig
.
setEntityName
(
"entry"
);
entryConfig
.
setDataSource
(
DataSourceType
.
FILE
);
entryConfig
.
setFieldName
(
"allOperations"
);
Object
entryData
=
queryFileData
(
sceneId
,
entryConfig
);
if
(
entryData
instanceof
List
)
{
List
<?>
entryList
=
(
List
<?>)
entryData
;
List
<
MachineOption
>
resultMachineOption
s
=
new
ArrayList
<>();
List
<
Object
>
resultEntrie
s
=
new
ArrayList
<>();
//
过滤Entry列表,只保留与场景ID匹配的Entry
//
先将Entry对象转换为Object对象,方便后续处理
for
(
Object
obj
:
entryList
)
{
if
(
obj
instanceof
Entry
)
{
Entry
entry
=
(
Entry
)
obj
;
// 检查Entry的SceneId是否匹配
if
(
entry
.
getSceneId
()
!=
null
&&
!
entry
.
getSceneId
().
equals
(
sceneId
))
{
continue
;
// 跳过不属于当前场景的Entry
}
// 检查Entry是否满足其他条件
boolean
matchesOtherConditions
=
true
;
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getConditions
()))
{
for
(
ConditionEntity
condition
:
paged
.
getConditions
())
{
if
(
condition
!=
null
&&
!
"sceneId"
.
equalsIgnoreCase
(
condition
.
getFieldName
()))
{
if
(!
matchesCondition
(
entry
,
condition
.
getFieldName
(),
condition
.
getFieldValue
(),
ConditionEnum
.
getByName
(
condition
.
getConditionalType
())))
{
matchesOtherConditions
=
false
;
break
;
}
}
}
if
(
entry
.
getSceneId
()
==
null
||
entry
.
getSceneId
().
equals
(
sceneId
))
{
resultEntries
.
add
(
obj
);
}
if
(
matchesOtherConditions
&&
entry
.
getMachineOptions
()
!=
null
)
{
// 如果Entry满足所有条件,添加其MachineOptions
}
}
// 应用条件过滤,支持AND/OR关系
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getConditions
()))
{
resultEntries
=
filterDataByConditions
(
resultEntries
,
paged
.
getConditions
(),
paged
.
getAnd
());
}
// 提取符合条件的Entry的MachineOptions
List
<
MachineOption
>
resultMachineOptions
=
new
ArrayList
<>();
for
(
Object
obj
:
resultEntries
)
{
if
(
obj
instanceof
Entry
)
{
Entry
entry
=
(
Entry
)
obj
;
if
(
entry
.
getMachineOptions
()
!=
null
)
{
resultMachineOptions
.
addAll
(
entry
.
getMachineOptions
());
}
}
}
data
=
resultMachineOptions
;
}
else
{
data
=
new
ArrayList
<
MachineOption
>();
...
...
@@ -419,52 +577,43 @@ public class ChromosomeDataService {
}
else
if
(
"order"
.
equalsIgnoreCase
(
config
.
getEntityName
()))
{
// 特殊处理:当实体是Order时,使用orderId字段进行查询
Object
orderData
=
queryFileData
(
sceneId
,
config
);
if
(
orderData
instanceof
List
)
{
List
<?>
orderList
=
(
List
<?>)
orderData
;
List
<
O
rder
>
resultOrders
=
new
ArrayList
<>();
List
<
O
bject
>
resultOrders
=
new
ArrayList
<>();
//
过滤Order列表,只保留满足条件的Order
//
先将Order对象转换为Object对象,方便后续处理
for
(
Object
obj
:
orderList
)
{
if
(
obj
instanceof
Order
)
{
Order
order
=
(
Order
)
obj
;
// 检查Order是否满足条件
boolean
matchesOtherConditions
=
true
;
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getConditions
()))
{
for
(
ConditionEntity
condition
:
paged
.
getConditions
())
{
if
(
condition
!=
null
&&
!
"sceneId"
.
equalsIgnoreCase
(
condition
.
getFieldName
()))
{
if
(!
matchesCondition
(
order
,
condition
.
getFieldName
(),
condition
.
getFieldValue
(),
ConditionEnum
.
getByName
(
condition
.
getConditionalType
())))
{
matchesOtherConditions
=
false
;
break
;
}
}
}
}
if
(
matchesOtherConditions
)
{
resultOrders
.
add
(
order
);
}
resultOrders
.
add
(
obj
);
}
}
data
=
resultOrders
;
// 应用条件过滤,支持AND/OR关系
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getConditions
()))
{
resultOrders
=
filterDataByConditions
(
resultOrders
,
paged
.
getConditions
(),
paged
.
getAnd
());
}
// 应用排序
List
<
Object
>
sortedData
=
sortData
(
resultOrders
,
paged
);
data
=
sortedData
;
}
else
{
data
=
new
ArrayList
<
Order
>();
}
}
else
{
data
=
queryFileData
(
sceneId
,
config
);
if
(
data
instanceof
List
)
{
List
<?>
dataList
=
(
List
<?>)
data
;
// 应用条件过滤
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getConditions
()))
{
dataList
=
filterDataByConditions
(
dataList
,
paged
.
getConditions
());
dataList
=
filterDataByConditions
(
dataList
,
paged
.
getConditions
()
,
paged
.
getAnd
()
);
}
data
=
dataList
;
// 应用排序
List
<
Object
>
sortedData
=
sortData
(
dataList
,
paged
);
data
=
sortedData
;
}
}
...
...
@@ -507,9 +656,9 @@ public class ChromosomeDataService {
entryConfig
.
setEntityName
(
"entry"
);
entryConfig
.
setDataSource
(
DataSourceType
.
FILE
);
entryConfig
.
setFieldName
(
"allOperations"
);
Object
result
=
queryFileData
(
sceneId
,
entryConfig
);
if
(
result
instanceof
List
)
{
List
<?>
entryList
=
(
List
<?>)
result
;
// 查找ID匹配的Entry
...
...
@@ -569,21 +718,17 @@ public class ChromosomeDataService {
* 忽略大小写获取字段
*/
private
Field
getFieldIgnoreCase
(
Class
<?>
clazz
,
String
fieldName
)
{
try
{
return
clazz
.
getDeclaredField
(
fieldName
);
}
catch
(
NoSuchFieldException
e
)
{
// 尝试大写
try
{
return
clazz
.
getDeclaredField
(
fieldName
.
toUpperCase
());
}
catch
(
NoSuchFieldException
e1
)
{
// 尝试小写
try
{
return
clazz
.
getDeclaredField
(
fieldName
.
toLowerCase
());
}
catch
(
NoSuchFieldException
e2
)
{
return
null
;
}
// 遍历所有声明的字段,查找忽略大小写匹配的字段
for
(
Field
field
:
clazz
.
getDeclaredFields
())
{
if
(
field
.
getName
().
equalsIgnoreCase
(
fieldName
))
{
return
field
;
}
}
// 如果当前类没有找到,递归查找父类
if
(
clazz
.
getSuperclass
()
!=
null
&&
clazz
.
getSuperclass
()
!=
Object
.
class
)
{
return
getFieldIgnoreCase
(
clazz
.
getSuperclass
(),
fieldName
);
}
return
null
;
}
/**
...
...
@@ -592,15 +737,18 @@ public class ChromosomeDataService {
private
List
<
Object
>
applyConditionsToList
(
Object
data
,
Paged
paged
)
{
// 检查是否是直接传入的EntityConfig(这种情况可能需要获取场景ID和实体类型)
// 实际上这个方法是在queryChromosomeDataList中调用的,此时数据已经从文件中获取
if
(
data
instanceof
List
)
{
List
<
Object
>
dataList
=
(
List
<
Object
>)
data
;
// 应用条件过滤
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getConditions
()))
{
dataList
=
filterDataByConditions
(
dataList
,
paged
.
getConditions
());
dataList
=
filterDataByConditions
(
dataList
,
paged
.
getConditions
()
,
paged
.
getAnd
()
);
}
// 应用排序
dataList
=
sortData
(
dataList
,
paged
);
return
dataList
;
}
else
{
List
<
Object
>
resultList
=
new
ArrayList
<>();
...
...
@@ -612,44 +760,201 @@ public class ChromosomeDataService {
/**
* 根据条件过滤数据(文件数据使用)- 修复版本
*/
private
List
<
Object
>
filterDataByConditions
(
List
<?>
dataList
,
List
<
ConditionEntity
>
conditions
)
{
private
List
<
Object
>
filterDataByConditions
(
List
<?>
dataList
,
List
<
ConditionEntity
>
conditions
,
Boolean
and
)
{
if
(
CollectionUtils
.
isEmpty
(
conditions
))
{
return
new
ArrayList
<>(
dataList
);
}
List
<
Object
>
filteredList
=
new
ArrayList
<>(
dataList
);
// 分离sceneId条件和其他条件
List
<
ConditionEntity
>
sceneIdConditions
=
new
ArrayList
<>();
List
<
ConditionEntity
>
otherConditions
=
new
ArrayList
<>();
for
(
ConditionEntity
condition
:
conditions
)
{
if
(
condition
==
null
||
condition
.
getFieldName
()
==
null
||
condition
.
getFieldValue
()
==
null
)
{
continue
;
if
(
condition
!=
null
&&
condition
.
getFieldName
()
!=
null
&&
condition
.
getFieldValue
()
!=
null
)
{
if
(
"sceneId"
.
equalsIgnoreCase
(
condition
.
getFieldName
()))
{
sceneIdConditions
.
add
(
condition
);
}
else
{
otherConditions
.
add
(
condition
);
}
}
}
final
String
fieldName
=
condition
.
getFieldName
();
final
String
fieldValue
=
condition
.
getFieldValue
();
ConditionEnum
conditionType
=
ConditionEnum
.
getByName
(
condition
.
getConditionalType
());
if
(
conditionType
==
null
)
{
conditionType
=
ConditionEnum
.
Equal
;
}
final
ConditionEnum
finalConditionType
=
conditionType
;
// 如果只有sceneId条件,返回所有数据(因为sceneId已经在查询层面处理了)
if
(
otherConditions
.
isEmpty
())
{
return
new
ArrayList
<>(
dataList
);
}
// 特殊处理:sceneId条件应该在查询层面处理,这里跳过
if
(
"sceneId"
.
equalsIgnoreCase
(
fieldName
))
{
continue
;
}
List
<
Object
>
filteredList
=
new
ArrayList
<>(
dataList
);
boolean
isAnd
=
and
!=
null
&&
and
;
if
(
isAnd
)
{
// 与关系:逐个应用条件,只有满足所有条件的记录才会保留
for
(
ConditionEntity
condition
:
otherConditions
)
{
final
String
fieldName
=
condition
.
getFieldName
();
final
String
fieldValue
=
condition
.
getFieldValue
();
ConditionEnum
conditionType
=
ConditionEnum
.
getByName
(
condition
.
getConditionalType
());
if
(
conditionType
==
null
)
{
conditionType
=
ConditionEnum
.
Equal
;
}
final
ConditionEnum
finalConditionType
=
conditionType
;
// 使用增强的for循环替代stream,避免lambda变量问题
List
<
Object
>
tempList
=
new
ArrayList
<>();
List
<
Object
>
tempList
=
new
ArrayList
<>();
for
(
Object
item
:
filteredList
)
{
if
(
matchesCondition
(
item
,
fieldName
,
fieldValue
,
finalConditionType
))
{
tempList
.
add
(
item
);
}
}
filteredList
=
tempList
;
}
}
else
{
// 或关系:只要满足一个条件的记录就会保留
List
<
Object
>
resultList
=
new
ArrayList
<>();
for
(
Object
item
:
filteredList
)
{
if
(
matchesCondition
(
item
,
fieldName
,
fieldValue
,
finalConditionType
))
{
tempList
.
add
(
item
);
boolean
matches
=
false
;
for
(
ConditionEntity
condition
:
otherConditions
)
{
final
String
fieldName
=
condition
.
getFieldName
();
final
String
fieldValue
=
condition
.
getFieldValue
();
ConditionEnum
conditionType
=
ConditionEnum
.
getByName
(
condition
.
getConditionalType
());
if
(
conditionType
==
null
)
{
conditionType
=
ConditionEnum
.
Equal
;
}
if
(
matchesCondition
(
item
,
fieldName
,
fieldValue
,
conditionType
))
{
matches
=
true
;
break
;
}
}
if
(
matches
)
{
resultList
.
add
(
item
);
}
}
filteredList
=
temp
List
;
filteredList
=
result
List
;
}
return
filteredList
;
}
/**
* 根据排序规则对数据进行排序
*/
private
List
<
Object
>
sortData
(
List
<?>
dataList
,
Paged
paged
)
{
if
(
CollectionUtils
.
isEmpty
(
dataList
))
{
return
new
ArrayList
<>(
dataList
);
}
List
<
Object
>
sortedList
=
new
ArrayList
<>(
dataList
);
// 优先使用sortByList进行多字段排序
if
(!
CollectionUtils
.
isEmpty
(
paged
.
getSortByList
()))
{
// 构建Comparator链
Comparator
<
Object
>
comparator
=
null
;
for
(
String
sortBy
:
paged
.
getSortByList
())
{
String
[]
parts
=
sortBy
.
trim
().
split
(
"\\s+"
);
if
(
parts
.
length
<
2
)
{
continue
;
// 跳过格式不正确的排序规则
}
String
fieldName
=
parts
[
0
];
boolean
isAsc
=
!
"desc"
.
equalsIgnoreCase
(
parts
[
1
]);
// 创建字段比较器
Comparator
<
Object
>
fieldComparator
=
(
o1
,
o2
)
->
{
try
{
Field
field1
=
getFieldIgnoreCase
(
o1
.
getClass
(),
fieldName
);
Field
field2
=
getFieldIgnoreCase
(
o2
.
getClass
(),
fieldName
);
if
(
field1
==
null
||
field2
==
null
)
{
return
0
;
}
field1
.
setAccessible
(
true
);
field2
.
setAccessible
(
true
);
Object
value1
=
field1
.
get
(
o1
);
Object
value2
=
field2
.
get
(
o2
);
// 处理null值
if
(
value1
==
null
&&
value2
==
null
)
{
return
0
;
}
if
(
value1
==
null
)
{
return
isAsc
?
-
1
:
1
;
}
if
(
value2
==
null
)
{
return
isAsc
?
1
:
-
1
;
}
// 比较值
if
(
value1
instanceof
Comparable
&&
value2
instanceof
Comparable
)
{
@SuppressWarnings
(
"unchecked"
)
int
compareResult
=
((
Comparable
<
Object
>)
value1
).
compareTo
(
value2
);
return
isAsc
?
compareResult
:
-
compareResult
;
}
return
0
;
}
catch
(
Exception
e
)
{
log
.
error
(
"排序字段获取失败: "
+
fieldName
,
e
);
return
0
;
}
};
// 链式比较
comparator
=
comparator
==
null
?
fieldComparator
:
comparator
.
thenComparing
(
fieldComparator
);
}
if
(
comparator
!=
null
)
{
sortedList
.
sort
(
comparator
);
}
}
// 使用原有sortBy和desc字段进行单字段排序
else
if
(
paged
.
getSortBy
()
!=
null
&&
!
paged
.
getSortBy
().
isEmpty
())
{
String
sortBy
=
paged
.
getSortBy
();
boolean
isDesc
=
paged
.
getDesc
()
!=
null
&&
paged
.
getDesc
();
sortedList
.
sort
((
o1
,
o2
)
->
{
try
{
Field
field1
=
getFieldIgnoreCase
(
o1
.
getClass
(),
sortBy
);
Field
field2
=
getFieldIgnoreCase
(
o2
.
getClass
(),
sortBy
);
if
(
field1
==
null
||
field2
==
null
)
{
return
0
;
}
field1
.
setAccessible
(
true
);
field2
.
setAccessible
(
true
);
Object
value1
=
field1
.
get
(
o1
);
Object
value2
=
field2
.
get
(
o2
);
// 处理null值
if
(
value1
==
null
&&
value2
==
null
)
{
return
0
;
}
if
(
value1
==
null
)
{
return
isDesc
?
1
:
-
1
;
}
if
(
value2
==
null
)
{
return
isDesc
?
-
1
:
1
;
}
// 比较值
if
(
value1
instanceof
Comparable
&&
value2
instanceof
Comparable
)
{
@SuppressWarnings
(
"unchecked"
)
int
compareResult
=
((
Comparable
<
Object
>)
value1
).
compareTo
(
value2
);
return
isDesc
?
-
compareResult
:
compareResult
;
}
return
0
;
}
catch
(
Exception
e
)
{
log
.
error
(
"排序字段获取失败: "
+
sortBy
,
e
);
return
0
;
}
});
}
return
sortedList
;
}
/**
* 判断单个对象是否匹配条件
*/
...
...
@@ -665,9 +970,11 @@ public class ChromosomeDataService {
switch
(
conditionType
)
{
case
Equal:
return
actualValueStr
.
equals
(
fieldValue
);
// 使用compareValues方法比较,支持数字和字符串
return
compareValues
(
actualValueStr
,
fieldValue
)
==
0
;
case
NoEqual:
return
!
actualValueStr
.
equals
(
fieldValue
);
// 使用compareValues方法比较,支持数字和字符串
return
compareValues
(
actualValueStr
,
fieldValue
)
!=
0
;
case
Like:
return
actualValueStr
.
contains
(
fieldValue
);
case
GreaterThan:
...
...
@@ -687,7 +994,7 @@ public class ChromosomeDataService {
case
NotEmpty:
return
!
actualValueStr
.
isEmpty
();
default
:
return
actualValueStr
.
equals
(
fieldValue
)
;
return
compareValues
(
actualValueStr
,
fieldValue
)
==
0
;
}
}
catch
(
Exception
e
)
{
// 如果匹配过程中出错,保守起见返回true(不过滤掉数据)
...
...
@@ -699,26 +1006,18 @@ public class ChromosomeDataService {
* 安全获取字段值(支持多种字段名格式)
*/
private
Object
getFieldValue
(
Object
item
,
String
fieldName
)
{
// 尝试多种可能的字段名
String
[]
possibleNames
=
{
fieldName
,
fieldName
.
toLowerCase
(),
fieldName
.
toUpperCase
(),
toCamelCase
(
fieldName
),
toUnderScoreCase
(
fieldName
)
};
for
(
String
name
:
possibleNames
)
{
try
{
Field
field
=
item
.
getClass
().
getDeclaredField
(
name
);
try
{
// 使用getFieldIgnoreCase方法获取字段,支持忽略大小写和父类字段
Field
field
=
getFieldIgnoreCase
(
item
.
getClass
(),
fieldName
);
if
(
field
!=
null
)
{
field
.
setAccessible
(
true
);
Object
value
=
field
.
get
(
item
);
if
(
value
!=
null
)
{
return
value
;
}
}
catch
(
Exception
e
)
{
// 继续尝试下一个名称
// 对于基本数据类型,field.get(item)会返回对应的包装类型,不会返回null
// 所以不需要检查value是否为null
return
field
.
get
(
item
);
}
}
catch
(
Exception
e
)
{
// 如果获取字段值时出错,返回null
log
.
error
(
"获取字段值失败: {}"
,
fieldName
,
e
);
}
return
null
;
...
...
@@ -779,7 +1078,7 @@ public class ChromosomeDataService {
return
updateDatabaseEntity
(
entityName
,
data
);
}
}
/**
* 更新文件实体数据
*/
...
...
@@ -880,7 +1179,7 @@ public class ChromosomeDataService {
// 更新其他传入的字段
updateObjectFields
(
originalEntry
,
data
);
// 调用editOperation方法
chromosome
=
planResultService
.
editOperation
(
chromosome
,
sceneId
,
originalEntry
);
if
(
originalEntry
.
getDesignatedStartTime
()==
null
){
...
...
@@ -894,7 +1193,7 @@ public class ChromosomeDataService {
}
}
// 其他字段通过updateObjectFields更新
// 其他字段通过updateObjectFields更新
}
...
...
@@ -906,32 +1205,32 @@ public class ChromosomeDataService {
throw
new
RuntimeException
(
"访问Chromosome字段失败: "
+
e
.
getMessage
(),
e
);
}
}
/**
* 更新数据库实体数据
*/
private
boolean
updateDatabaseEntity
(
String
entityName
,
Map
<
String
,
Object
>
data
)
{
EntityConfig
config
=
getEntityConfig
(
entityName
);
String
tableName
=
config
.
getTableName
();
if
(
data
==
null
||
!
data
.
containsKey
(
"id"
))
{
throw
new
RuntimeException
(
"更新数据库实体时必须提供id字段"
);
}
String
id
=
data
.
get
(
"id"
).
toString
();
// 构建更新SQL
StringBuilder
sql
=
new
StringBuilder
();
sql
.
append
(
"UPDATE "
).
append
(
tableName
).
append
(
" SET "
);
List
<
String
>
setParts
=
new
ArrayList
<>();
MapSqlParameterSource
params
=
new
MapSqlParameterSource
();
// 遍历要更新的字段,排除id字段
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
data
.
entrySet
())
{
String
fieldName
=
entry
.
getKey
();
Object
fieldValue
=
entry
.
getValue
();
if
(!
"id"
.
equalsIgnoreCase
(
fieldName
))
{
// 将驼峰命名转换为下划线大写格式
String
dbFieldName
=
camelCaseToUnderScoreUpperCase
(
fieldName
).
toUpperCase
();
...
...
@@ -939,17 +1238,17 @@ public class ChromosomeDataService {
params
.
addValue
(
fieldName
,
fieldValue
);
}
}
if
(
setParts
.
isEmpty
())
{
throw
new
RuntimeException
(
"没有有效的字段用于更新"
);
}
sql
.
append
(
String
.
join
(
", "
,
setParts
));
// 添加WHERE条件
sql
.
append
(
" WHERE ID = :idParam"
);
params
.
addValue
(
"idParam"
,
id
);
try
{
int
rowsAffected
=
namedParameterJdbcTemplate
.
update
(
sql
.
toString
(),
params
);
return
rowsAffected
>
0
;
...
...
@@ -1146,7 +1445,7 @@ public class ChromosomeDataService {
}
}
}
if
(
field
!=
null
)
{
field
.
setAccessible
(
true
);
...
...
@@ -1231,7 +1530,7 @@ public class ChromosomeDataService {
}
}
}
/**
* 将Entry列表转换为ProdProcessExec列表
*/
...
...
@@ -1239,7 +1538,7 @@ public class ChromosomeDataService {
if
(
data
instanceof
List
)
{
List
<?>
entryList
=
(
List
<?>)
data
;
List
<
ProdProcessExec
>
result
=
new
ArrayList
<>();
for
(
Object
obj
:
entryList
)
{
if
(
obj
instanceof
Entry
)
{
Entry
entry
=
(
Entry
)
obj
;
...
...
@@ -1247,22 +1546,22 @@ public class ChromosomeDataService {
result
.
add
(
prodProcessExec
);
}
}
return
result
;
}
else
if
(
data
instanceof
Entry
)
{
Entry
entry
=
(
Entry
)
data
;
return
convertEntryToProdProcessExecSingle
(
entry
);
}
return
data
;
// 如果不是Entry类型,直接返回原数据
}
/**
* 将单个Entry转换为ProdProcessExec
*/
private
ProdProcessExec
convertEntryToProdProcessExecSingle
(
Entry
entry
)
{
ProdProcessExec
prodProcessExec
=
new
ProdProcessExec
();
// 基本字段映射
prodProcessExec
.
setExecId
(
entry
.
ExecId
);
prodProcessExec
.
setSceneId
(
entry
.
SceneId
);
...
...
@@ -1279,17 +1578,17 @@ public class ChromosomeDataService {
prodProcessExec
.
setSingleOut
(
entry
.
getSingleOut
());
prodProcessExec
.
setPlanQty
(
entry
.
getQuantity
());
prodProcessExec
.
setLogicalOrder
((
long
)
entry
.
getSequence
());
// 设置ID字段
prodProcessExec
.
setId
(
String
.
valueOf
(
entry
.
getId
()));
// 其他字段根据需要进行映射
prodProcessExec
.
setCanInterrupt
(
entry
.
getIsInterrupt
());
prodProcessExec
.
setRoutingId
(
entry
.
getRoutingId
());
return
prodProcessExec
;
}
/**
* 从Entry列表中提取MachineOption列表
*/
...
...
@@ -1297,8 +1596,8 @@ public class ChromosomeDataService {
if
(
data
instanceof
List
)
{
List
<?>
entryList
=
(
List
<?>)
data
;
List
<
MachineOption
>
result
=
new
ArrayList
<>();
for
(
Object
obj
:
entryList
)
{
if
(
obj
instanceof
Entry
)
{
Entry
entry
=
(
Entry
)
obj
;
...
...
@@ -1309,13 +1608,13 @@ public class ChromosomeDataService {
}
}
}
return
result
;
}
else
if
(
data
instanceof
Entry
)
{
Entry
entry
=
(
Entry
)
data
;
return
entry
.
getMachineOptions
()
!=
null
?
entry
.
getMachineOptions
()
:
new
ArrayList
<>();
}
return
new
ArrayList
<>();
// 如果不是Entry类型,返回空列表
}
...
...
src/main/java/com/aps/service/common/DatabaseQueryService.java
View file @
fa5b9c03
...
...
@@ -35,13 +35,23 @@ public class DatabaseQueryService {
// 处理条件
int
paramIndex
=
1
;
if
(
paged
.
getConditions
()
!=
null
&&
!
paged
.
getConditions
().
isEmpty
())
{
boolean
isAnd
=
paged
.
getAnd
()
!=
null
&&
paged
.
getAnd
();
String
logicalOperator
=
isAnd
?
" AND "
:
" OR "
;
// 构建条件列表
List
<
String
>
conditionSqlList
=
new
ArrayList
<>();
for
(
ConditionEntity
condition
:
paged
.
getConditions
())
{
String
conditionSql
=
buildConditionSql
(
condition
,
params
,
paramIndex
);
if
(
conditionSql
!=
null
)
{
whereClause
.
append
(
" AND "
).
appen
d
(
conditionSql
);
conditionSqlList
.
ad
d
(
conditionSql
);
paramIndex
++;
}
}
// 如果有条件,使用指定的逻辑运算符连接
if
(!
conditionSqlList
.
isEmpty
())
{
whereClause
.
append
(
" AND ("
).
append
(
String
.
join
(
logicalOperator
,
conditionSqlList
)).
append
(
")"
);
}
}
// 构建排序
...
...
@@ -110,13 +120,23 @@ public class DatabaseQueryService {
// 处理条件
int
paramIndex
=
1
;
if
(
paged
.
getConditions
()
!=
null
&&
!
paged
.
getConditions
().
isEmpty
())
{
boolean
isAnd
=
paged
.
getAnd
()
!=
null
&&
paged
.
getAnd
();
String
logicalOperator
=
isAnd
?
" AND "
:
" OR "
;
// 构建条件列表
List
<
String
>
conditionSqlList
=
new
ArrayList
<>();
for
(
ConditionEntity
condition
:
paged
.
getConditions
())
{
String
conditionSql
=
buildConditionSql
(
condition
,
params
,
paramIndex
);
if
(
conditionSql
!=
null
)
{
whereClause
.
append
(
" AND "
).
appen
d
(
conditionSql
);
conditionSqlList
.
ad
d
(
conditionSql
);
paramIndex
++;
}
}
// 如果有条件,使用指定的逻辑运算符连接
if
(!
conditionSqlList
.
isEmpty
())
{
whereClause
.
append
(
" AND ("
).
append
(
String
.
join
(
logicalOperator
,
conditionSqlList
)).
append
(
")"
);
}
}
// 构建排序
...
...
@@ -188,11 +208,48 @@ public class DatabaseQueryService {
* 构建排序子句
*/
private
String
buildOrderBy
(
Paged
paged
)
{
// 优先使用sortByList进行多字段排序
if
(
paged
.
getSortByList
()
!=
null
&&
!
paged
.
getSortByList
().
isEmpty
())
{
StringBuilder
orderBy
=
new
StringBuilder
(
" ORDER BY "
);
boolean
first
=
true
;
for
(
String
sortBy
:
paged
.
getSortByList
())
{
if
(!
first
)
{
orderBy
.
append
(
", "
);
}
first
=
false
;
// 解析排序规则,格式如"field asc"或"field desc"
String
[]
parts
=
sortBy
.
trim
().
split
(
"\\s+"
);
if
(
parts
.
length
<
2
)
{
continue
;
// 跳过格式不正确的排序规则
}
String
fieldName
=
parts
[
0
];
String
direction
=
"DESC"
.
equalsIgnoreCase
(
parts
[
1
])
?
"DESC"
:
"ASC"
;
// 处理字段名大小写问题:将驼峰命名转换为下划线大写(数据库字段格式)
fieldName
=
camelCaseToUnderScoreUpperCase
(
fieldName
).
toUpperCase
();
orderBy
.
append
(
fieldName
).
append
(
" "
).
append
(
direction
);
}
// 如果有有效的排序规则,返回构建的ORDER BY子句
if
(!
first
)
{
return
orderBy
.
toString
();
}
}
// 使用原有sortBy和desc字段进行单字段排序
if
(
paged
.
getSortBy
()
!=
null
&&
!
paged
.
getSortBy
().
isEmpty
())
{
String
direction
=
Boolean
.
TRUE
.
equals
(
paged
.
getDesc
())
?
"DESC"
:
"ASC"
;
return
" ORDER BY "
+
paged
.
getSortBy
()
+
" "
+
direction
;
// 处理字段名大小写问题:将驼峰命名转换为下划线大写(数据库字段格式)
String
fieldName
=
camelCaseToUnderScoreUpperCase
(
paged
.
getSortBy
()).
toUpperCase
();
return
" ORDER BY "
+
fieldName
+
" "
+
direction
;
}
return
" ORDER BY ID DESC"
;
// 默认按ID降序
// 默认按ID降序
return
" ORDER BY ID DESC"
;
}
/**
...
...
@@ -262,7 +319,7 @@ public class DatabaseQueryService {
return
fieldName
+
" = :"
+
paramName
;
}
}
/**
* 驼峰命名转下划线大写:prodProduct -> PROD_PRODUCT
*/
...
...
src/main/java/com/aps/service/impl/DiscreteParameterDurationServiceImpl.java
View file @
fa5b9c03
package
com
.
aps
.
service
.
impl
;
import
com.aps.entity.Algorithm.GAScheduleResult
;
import
com.aps.entity.DiscreteParameterConfigType
;
import
com.aps.entity.DiscreteParameterDuration
;
import
com.aps.entity.basic.Entry
;
import
com.aps.entity.basic.Machine
;
...
...
@@ -22,24 +23,23 @@ public class DiscreteParameterDurationServiceImpl extends ServiceImpl<DiscretePa
* 计算当前工序需要的换型时间
*/
@Override
public
double
calculateChangeoverTime
(
List
<
GAScheduleResult
>
existingGenes
,
Entry
operation
,
public
double
calculateChangeoverTime
(
Entry
lastEntry
,
Entry
entry
,
Machine
machine
,
List
<
Entry
>
allOperations
,
int
startTime
)
{
List
<
Entry
>
allOperations
,
int
startTime
,
List
<
GAScheduleResult
>
machineTasks
)
{
if
(
existingGene
s
.
isEmpty
())
{
if
(
machineTask
s
.
isEmpty
())
{
return
0.0
;
}
// 获取当前工序的所有参数
List
<
ParameterPair
>
currentParams
=
getOperationParameters
(
operation
);
List
<
ParameterPair
>
currentParams
=
getOperationParameters
(
entry
);
if
(
currentParams
.
isEmpty
())
{
return
0.0
;
}
// 获取设备上最后一个任务
GAScheduleResult
lastGene
=
existingGene
s
.
stream
()
GAScheduleResult
lastGene
=
machineTask
s
.
stream
()
.
filter
(
g
->
g
.
getMachineId
()
==
machine
.
getId
())
.
max
(
Comparator
.
comparingInt
(
GAScheduleResult:
:
getEndTime
))
.
orElse
(
null
);
...
...
@@ -48,27 +48,18 @@ public class DiscreteParameterDurationServiceImpl extends ServiceImpl<DiscretePa
return
0.0
;
}
if
(
operation
.
getOrderId
()==
"a0e61488-0647-4f8e-a27c-cfed9cbbba52"
){
System
.
out
.
println
(
"lastGene"
+
lastGene
.
getExecId
());
}
// 找到最后一个任务对应的Entry
Entry
prev
=
allOperations
.
stream
()
.
filter
(
t
->
t
.
getExecId
().
equals
(
lastGene
.
getExecId
()))
.
findFirst
().
orElse
(
null
);
if
(
prev
==
null
)
{
if
(
lastEntry
==
null
)
{
return
0.0
;
}
List
<
ParameterPair
>
lastParams
=
getOperationParameters
(
prev
);
List
<
ParameterPair
>
lastParams
=
getOperationParameters
(
lastEntry
);
List
<
DiscreteParameterDuration
>
parameterDurations
=
this
.
lambdaQuery
().
list
();
// 获取该设备上的所有任务(按开始时间排序)
List
<
GAScheduleResult
>
machineGenes
=
existingGene
s
.
stream
()
List
<
GAScheduleResult
>
machineGenes
=
machineTask
s
.
stream
()
.
filter
(
g
->
g
.
getMachineId
()
==
machine
.
getId
())
.
sorted
(
Comparator
.
comparingInt
(
GAScheduleResult:
:
getStartTime
))
.
collect
(
Collectors
.
toList
());
...
...
@@ -122,7 +113,7 @@ public class DiscreteParameterDurationServiceImpl extends ServiceImpl<DiscretePa
List
<
DiscreteParameterDuration
>
parameterDurations
,
List
<
Entry
>
allOperations
)
{
DiscreteParameterDuration
config
=
findParameterConfig
(
currentParam
,
"WorkingDuration"
,
parameterDurations
);
DiscreteParameterDuration
config
=
findParameterConfig
(
currentParam
,
DiscreteParameterConfigType
.
WORKING_DURATION
,
parameterDurations
);
if
(
config
==
null
)
{
return
0.0
;
}
...
...
@@ -161,7 +152,7 @@ public class DiscreteParameterDurationServiceImpl extends ServiceImpl<DiscretePa
List
<
DiscreteParameterDuration
>
parameterDurations
,
int
startTime
,
List
<
Entry
>
allOperations
)
{
DiscreteParameterDuration
config
=
findParameterConfig
(
currentParam
,
"AbsoluteDuration"
,
parameterDurations
);
DiscreteParameterDuration
config
=
findParameterConfig
(
currentParam
,
DiscreteParameterConfigType
.
ABSOLUTE_DURATION
,
parameterDurations
);
if
(
config
==
null
)
{
return
0.0
;
}
...
...
@@ -197,7 +188,7 @@ public class DiscreteParameterDurationServiceImpl extends ServiceImpl<DiscretePa
List
<
DiscreteParameterDuration
>
parameterDurations
,
int
startTime
,
List
<
Entry
>
allOperations
)
{
DiscreteParameterDuration
config
=
findParameterConfig
(
currentParam
,
"MaxInterval"
,
parameterDurations
);
DiscreteParameterDuration
config
=
findParameterConfig
(
currentParam
,
DiscreteParameterConfigType
.
MAX_INTERVAL
,
parameterDurations
);
if
(
config
==
null
)
{
return
0.0
;
}
...
...
@@ -231,7 +222,7 @@ public class DiscreteParameterDurationServiceImpl extends ServiceImpl<DiscretePa
List
<
DiscreteParameterDuration
>
parameterDurations
,
List
<
Entry
>
allOperations
)
{
DiscreteParameterDuration
config
=
findParameterConfig
(
currentParam
,
"OrderCount"
,
parameterDurations
);
DiscreteParameterDuration
config
=
findParameterConfig
(
currentParam
,
DiscreteParameterConfigType
.
ORDER_COUNT
,
parameterDurations
);
if
(
config
==
null
)
{
return
0.0
;
}
...
...
@@ -409,12 +400,12 @@ public class DiscreteParameterDurationServiceImpl extends ServiceImpl<DiscretePa
.
collect
(
Collectors
.
toList
());
}
private
DiscreteParameterDuration
findParameterConfig
(
ParameterPair
param
,
String
configType
,
private
DiscreteParameterDuration
findParameterConfig
(
ParameterPair
param
,
DiscreteParameterConfigType
configType
,
List
<
DiscreteParameterDuration
>
parameterDurations
)
{
return
parameterDurations
.
stream
()
.
filter
(
pd
->
param
.
getGroupId
().
equals
(
pd
.
getGroupid
())
&&
param
.
getParameterId
().
equals
(
pd
.
getParameterid
())
&&
configType
.
equals
(
pd
.
getExp1
()
))
configType
.
getValue
()==
pd
.
getMeasureparameterid
(
))
.
findFirst
()
.
orElse
(
null
);
}
...
...
@@ -443,7 +434,7 @@ public class DiscreteParameterDurationServiceImpl extends ServiceImpl<DiscretePa
List
<
DiscreteParameterDuration
>
parameterDurations
,
List
<
Entry
>
allOperations
)
{
DiscreteParameterDuration
config
=
findParameterConfig
(
currentParam
,
"AccumulatedQuantity"
,
parameterDurations
);
DiscreteParameterDuration
config
=
findParameterConfig
(
currentParam
,
DiscreteParameterConfigType
.
WORKING_QUANTITY
,
parameterDurations
);
if
(
config
==
null
)
{
return
0.0
;
}
...
...
src/main/java/com/aps/service/impl/DiscreteParameterMatrixServiceImpl.java
View file @
fa5b9c03
...
...
@@ -35,6 +35,8 @@ public class DiscreteParameterMatrixServiceImpl extends ServiceImpl<DiscretePara
@Override
public
double
getDiscreteParameterMatrixValue
(
Entry
entry
,
Entry
lastEntry
)
{
// 参数校验
cleanCache
(
resultCache
,
MAX_RESULT_CACHE_SIZE
);
if
(
entry
==
null
||
lastEntry
==
null
)
{
return
0.0
;
...
...
src/main/java/com/aps/service/impl/LanuchServiceImpl.java
View file @
fa5b9c03
...
...
@@ -27,6 +27,7 @@ import java.time.LocalDate;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
static
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
;
...
...
@@ -42,55 +43,25 @@ import static org.springframework.beans.BeanUtils.copyProperties;
@RequiredArgsConstructor
public
class
LanuchServiceImpl
implements
LanuchService
{
@Autowired
private
ProdEquipSpecialCalService
prodEquipSpecialCalService
;
@Autowired
private
ApsOrderService
apsOrderService
;
@Autowired
private
RoutingHeaderService
routingHeaderService
;
@Autowired
private
ProdLaunchOrderService
prodLaunchOrderService
;
@Autowired
private
RoutingDetailMapper
routingDetailMapper
;
@Autowired
private
ProdProcessExecService
prodProcessExecService
;
@Autowired
private
RoutingDetailConnectService
routingDetailConnectService
;
@Autowired
private
ProdOrderProcessService
prodOrderProcessService
;
@Autowired
private
RoutingHeaderMapper
routingHeaderMapper
;
@Autowired
private
ProdSceneConfigService
prodSceneConfigService
;
@Autowired
private
ProdEquipmentService
prodEquipmentService
;
@Autowired
private
RoutingDetailEquipService
routingDetailEquipService
;
@Autowired
private
SceneService
sceneService
;
@Autowired
private
MesOrderService
mesOrderService
;
@Autowired
private
DispatchService
dispatchService
;
@Autowired
private
RoutingDiscreteParamService
routingDiscreteParamService
;
@Autowired
private
MesScheduleService
mesScheduleService
;
@Autowired
private
Equiptype1Service
equiptype1Service
;
@Autowired
private
PlanResourceService
planResourceService
;
@Autowired
private
OrderMaterialRequirementService
orderMaterialRequirementService
;
@Autowired
private
EquipinfoService
equipinfoService
;
private
final
ProdEquipSpecialCalService
prodEquipSpecialCalService
;
private
final
ApsOrderService
apsOrderService
;
private
final
ProdLaunchOrderService
prodLaunchOrderService
;
private
final
RoutingDetailMapper
routingDetailMapper
;
private
final
ProdProcessExecService
prodProcessExecService
;
private
final
RoutingDetailConnectService
routingDetailConnectService
;
private
final
ProdOrderProcessService
prodOrderProcessService
;
private
final
RoutingHeaderMapper
routingHeaderMapper
;
private
final
ProdSceneConfigService
prodSceneConfigService
;
private
final
ProdEquipmentService
prodEquipmentService
;
private
final
RoutingDetailEquipService
routingDetailEquipService
;
private
final
SceneService
sceneService
;
private
final
MesOrderService
mesOrderService
;
private
final
DispatchService
dispatchService
;
private
final
MesScheduleService
mesScheduleService
;
private
final
Equiptype1Service
equiptype1Service
;
private
final
PlanResourceService
planResourceService
;
private
final
OrderMaterialRequirementService
orderMaterialRequirementService
;
private
final
EquipinfoService
equipinfoService
;
/**
* 生成场景数据
*
...
...
@@ -113,14 +84,14 @@ public class LanuchServiceImpl implements LanuchService {
String
sceneId
=
null
;
// 1. 创建场景
ProdSceneConfig
sceneConfig
=
createScene
(
sceneName
,
username
);
if
(
sceneConfig
==
null
)
{
throw
new
RuntimeException
(
"场景名称已存在"
);
}
sceneId
=
sceneConfig
.
getSceneId
();
// 1. 创建场景
ProdSceneConfig
sceneConfig
=
createScene
(
sceneName
,
username
);
if
(
sceneConfig
==
null
)
{
throw
new
RuntimeException
(
"场景名称已存在"
);
}
sceneId
=
sceneConfig
.
getSceneId
();
prodEquipSpecialCalService
.
copyFromEquipCapacityDef
(
sceneId
);
prodEquipSpecialCalService
.
copyFromEquipCapacityDef
(
sceneId
);
List
<
MesSchedule
>
mesSchedules
=
mesScheduleService
.
lambdaQuery
()
...
...
@@ -130,38 +101,38 @@ public class LanuchServiceImpl implements LanuchService {
// 2. 获取工单列表
List
<
String
>
apsOrderIds
=
mesSchedules
.
stream
()
List
<
String
>
apsOrderIds
=
mesSchedules
.
stream
()
.
map
(
MesSchedule:
:
getApsOrderId
)
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toList
());
List
<
ApsOrder
>
apsOrders
;
if
(
apsOrderIds
.
isEmpty
())
{
apsOrders
=
new
ArrayList
<>();
}
else
{
apsOrders
=
apsOrderService
.
lambdaQuery
()
.
eq
(
ApsOrder:
:
getIsdeleted
,
0
)
.
eq
(
ApsOrder:
:
getStatus
,
4
)
List
<
ApsOrder
>
apsOrders
;
if
(
apsOrderIds
.
isEmpty
())
{
apsOrders
=
new
ArrayList
<>();
}
else
{
apsOrders
=
apsOrderService
.
lambdaQuery
()
.
eq
(
ApsOrder:
:
getIsdeleted
,
0
)
.
eq
(
ApsOrder:
:
getStatus
,
4
)
// .eq(ApsOrder::getCreatoruserid, username)
.
in
(
ApsOrder:
:
getId
,
apsOrderIds
)
.
list
();
}
if
(
CollectionUtils
.
isEmpty
(
apsOrders
))
{
throw
new
SceneGenerationException
(
"工单列表不能为空"
);
}
.
in
(
ApsOrder:
:
getId
,
apsOrderIds
)
.
list
();
}
if
(
CollectionUtils
.
isEmpty
(
apsOrders
))
{
throw
new
SceneGenerationException
(
"工单列表不能为空"
);
}
// 4. 处理工单数据转换
List
<
ProdLaunchOrder
>
prodLaunchOrders
=
processOrderData
(
sceneId
,
apsOrders
);
// 4. 处理工单数据转换
List
<
ProdLaunchOrder
>
prodLaunchOrders
=
processOrderData
(
sceneId
,
apsOrders
);
// 5. 转换工单于工序执行表
convertToProcessExecBatch
(
prodLaunchOrders
,
sceneId
);
// 5. 转换工单于工序执行表
convertToProcessExecBatch
(
prodLaunchOrders
,
sceneId
);
// 6. 生成工序关联关系
generateProcessRelationsBatch
(
prodLaunchOrders
,
sceneId
);
// 6. 生成工序关联关系
generateProcessRelationsBatch
(
prodLaunchOrders
,
sceneId
);
log
.
info
(
"场景数据生成完成,场景ID:{}"
,
sceneId
);
return
R
.
ok
(
sceneConfig
);
log
.
info
(
"场景数据生成完成,场景ID:{}"
,
sceneId
);
return
R
.
ok
(
sceneConfig
);
}
...
...
@@ -304,7 +275,7 @@ public class LanuchServiceImpl implements LanuchService {
// 先删除表中所有数据
orderMaterialRequirementService
.
remove
(
new
LambdaQueryWrapper
<>());
// 再批量插入新数据
orderMaterialRequirementService
.
saveBatch
(
orderMaterials
);
...
...
@@ -735,11 +706,11 @@ public class LanuchServiceImpl implements LanuchService {
{
Equiptype1
equipType
=
equiptype1Service
.
lambdaQuery
().
eq
(
Equiptype1:
:
getId
,
detail
.
getEquipTypeId
()).
one
();
if
(
equipType
!=
null
)
{
prodProcessExec
.
setEquipTypeName
(
equipType
.
getEquipTypeName
());
prodProcessExec
.
setEquipTypeCode
(
equipType
.
getEquipTypeId
());
if
(
equipType
!=
null
)
{
prodProcessExec
.
setEquipTypeName
(
equipType
.
getEquipTypeName
());
prodProcessExec
.
setEquipTypeCode
(
equipType
.
getEquipTypeId
());
}
}
}
prodProcessExec
.
setPlanQty
(
prodOrderMain
.
getQuantity
());
prodProcessExec
.
setTargetStartDate
(
prodOrderMain
.
getStartDate
());
prodProcessExec
.
setTargetEndDate
(
prodOrderMain
.
getEndDate
());
...
...
@@ -904,29 +875,29 @@ public class LanuchServiceImpl implements LanuchService {
String
execId
=
routingDetailIdToExecIdMap
.
get
(
connection
.
getSourceoperationid
()
+
"_"
+
prodOrderMain
.
getOrderId
());
String
targetExecId
=
routingDetailIdToExecIdMap
.
get
(
connection
.
getDestoperationid
()
+
"_"
+
prodOrderMain
.
getOrderId
());
if
(
connection
.
getDestoperationid
()
!=
null
&&
connection
.
getSourceoperationid
()
!=
null
&&
execId
!=
null
&&
targetExecId
!=
null
)
{
if
(
connection
.
getDestoperationid
()
!=
null
&&
connection
.
getSourceoperationid
()
!=
null
&&
execId
!=
null
&&
targetExecId
!=
null
)
{
prodOrderProcess
.
setTaskSeq
(
getTaskSeqFromRoutingDetail
(
connection
.
getSourceoperationid
(),
connection
.
getSourceoperation
()));
prodOrderProcess
.
setTaskSeq
(
getTaskSeqFromRoutingDetail
(
connection
.
getSourceoperationid
(),
connection
.
getSourceoperation
()));
prodOrderProcess
.
setTargetTaskSeq
(
getTaskSeqFromRoutingDetail
(
connection
.
getDestoperationid
(),
connection
.
getDestoperation
()));
prodOrderProcess
.
setTargetTaskSeq
(
getTaskSeqFromRoutingDetail
(
connection
.
getDestoperationid
(),
connection
.
getDestoperation
()));
prodOrderProcess
.
setSceneId
(
sceneId
);
prodOrderProcess
.
setOrderId
(
prodOrderMain
.
getOrderId
());
prodOrderProcess
.
setSceneId
(
sceneId
);
prodOrderProcess
.
setOrderId
(
prodOrderMain
.
getOrderId
());
// prodOrderProcess.setTaskSeq(connection.getSourceoperation());
prodOrderProcess
.
setTargetOrderId
(
prodOrderMain
.
getOrderId
());
prodOrderProcess
.
setTargetOrderId
(
prodOrderMain
.
getOrderId
());
// prodOrderProcess.setTargetTaskSeq(connection.getDestoperation());
prodOrderProcess
.
setId
(
String
.
valueOf
(
SnowFlackIdWorker
.
getId
()));
prodOrderProcess
.
setId
(
String
.
valueOf
(
SnowFlackIdWorker
.
getId
()));
if
(
execId
!=
null
)
{
prodOrderProcess
.
setExecId
(
execId
);
}
if
(
execId
!=
null
)
{
prodOrderProcess
.
setExecId
(
execId
);
}
if
(
targetExecId
!=
null
)
{
prodOrderProcess
.
setTargetExecId
(
targetExecId
);
}
}
if
(
targetExecId
!=
null
)
{
prodOrderProcess
.
setTargetExecId
(
targetExecId
);
}
}
return
prodOrderProcess
;
}
...
...
@@ -993,86 +964,169 @@ if (connection.getDestoperationid() !=null && connection.getSourceoperationid()
// log.warn("工艺设备列表为空,跳过设备对照表生成");
// return null;
// }
// 预加载数据并转换为Map以提高查询效率
List
<
Equiptype1
>
equipTypes
=
equiptype1Service
.
lambdaQuery
().
eq
(
Equiptype1:
:
getIsdeleted
,
0
).
list
();
Map
<
Long
,
Equiptype1
>
equipTypeMap
=
equipTypes
.
stream
()
.
collect
(
Collectors
.
toMap
(
Equiptype1:
:
getId
,
Function
.
identity
()));
List
<
PlanResource
>
list
=
planResourceService
.
lambdaQuery
()
.
eq
(
PlanResource:
:
getIsdeleted
,
0
)
.
list
();
Map
<
Integer
,
PlanResource
>
planResourceMap
=
list
.
stream
()
.
collect
(
Collectors
.
toMap
(
PlanResource:
:
getId
,
Function
.
identity
()));
Map
<
Integer
,
PlanResource
>
planResourceByReferenceIdMap
=
list
.
stream
()
.
filter
(
pr
->
pr
.
getReferenceId
()
!=
null
)
.
collect
(
Collectors
.
toMap
(
PlanResource:
:
getReferenceId
,
Function
.
identity
()));
// 转换equipinfo为Map
Map
<
Integer
,
Equipinfo
>
equipinfoMap
=
equipinfo
.
stream
()
.
collect
(
Collectors
.
toMap
(
Equipinfo:
:
getId
,
Function
.
identity
()));
Map
<
Integer
,
List
<
Equipinfo
>>
equipinfoByEquipTypeMap
=
equipinfo
.
stream
()
.
filter
(
e
->
e
.
getEquipType
()
!=
null
)
.
collect
(
Collectors
.
groupingBy
(
Equipinfo:
:
getEquipType
));
// 创建ProdEquipment列表
List
<
ProdEquipment
>
prodEquipments
=
new
java
.
util
.
ArrayList
<>();
List
<
ProdEquipment
>
prodEquipments
=
new
ArrayList
<>();
if
(
routingDetailEquips
!=
null
&&
routingDetailEquips
.
size
()
>
0
)
{
if
(
routingDetailEquips
!=
null
&&
!
routingDetailEquips
.
isEmpty
())
{
// 遍历RoutingDetailEquip列表,转换为ProdEquipment对象
for
(
RoutingDetailEquip
routingDetailEquip
:
routingDetailEquips
)
{
ProdEquipment
prodEquipment
=
new
ProdEquipment
();
prodEquipment
.
setSceneId
(
sceneId
);
prodEquipment
.
setEquipId
(
routingDetailEquip
.
getEquipId
().
longValue
());
Integer
i
=
list
.
stream
().
filter
(
equip
->
equip
.
getId
().
equals
(
routingDetailEquip
.
getEquipId
().
intValue
())).
findFirst
().
map
(
PlanResource:
:
getReferenceId
).
orElse
(
null
);
Equipinfo
equipinfo1
=
equipinfo
.
stream
().
filter
(
equip
->
equip
.
getId
().
equals
(
i
)).
findFirst
().
orElse
(
null
);
try
{
ProdEquipment
prodEquipment
=
new
ProdEquipment
();
prodEquipment
.
setSceneId
(
sceneId
);
prodEquipment
.
setEquipId
(
routingDetailEquip
.
getEquipId
().
longValue
());
// 使用Map快速查询,替代多次stream操作
PlanResource
planResource
=
planResourceMap
.
get
(
routingDetailEquip
.
getEquipId
().
intValue
());
if
(
planResource
!=
null
&&
planResource
.
getReferenceId
()
!=
null
)
{
Equipinfo
equipinfo1
=
equipinfoMap
.
get
(
planResource
.
getReferenceId
());
if
(
equipinfo1
!=
null
)
{
prodEquipment
.
setEquipCode
(
equipinfo1
.
getEquipId
());
prodEquipment
.
setEquipName
(
equipinfo1
.
getEquipName
());
}
else
{
log
.
warn
(
"未找到referenceId={}对应的设备信息"
,
planResource
.
getReferenceId
());
continue
;
}
}
else
{
log
.
warn
(
"未找到equipId={}对应的PlanResource信息"
,
routingDetailEquip
.
getEquipId
());
continue
;
}
prodEquipment
.
setEquipCode
(
equipinfo1
.
getEquipId
());
prodEquipment
.
setEquipName
(
equipinfo1
.
getEquipName
());
// 使用Map快速查询
Long
resourceId
=
routingDetailEquip
.
getType1
();
prodEquipment
.
setResourceId
(
resourceId
);
Equiptype1
equiptype1
=
equipTypeMap
.
get
(
resourceId
);
if
(
equiptype1
!=
null
)
{
prodEquipment
.
setResourceCode
(
equiptype1
.
getEquipTypeId
());
}
prodEquipment
.
setResourceId
(
routingDetailEquip
.
getType1
());
prodEquipment
.
setEfficiencyValue
(
routingDetailEquip
.
getEfficiencyValue
());
prodEquipment
.
setSetupTime
(
routingDetailEquip
.
getSetupTime
());
prodEquipment
.
setId
(
String
.
valueOf
(
SnowFlackIdWorker
.
getId
()));
prodEquipment
.
setRuntime
(
routingDetailEquip
.
getDuration
());
prodEquipment
.
setSingleOut
(
routingDetailEquip
.
getOutputQuantity
());
// 计算speed
prodEquipment
.
setSpeed
(
Optional
.
ofNullable
(
routingDetailEquip
.
getDuration
())
.
filter
(
out
->
routingDetailEquip
.
getOutputQuantity
()
!=
null
)
.
filter
(
out
->
routingDetailEquip
.
getOutputQuantity
().
compareTo
(
BigDecimal
.
ZERO
)
!=
0
)
.
map
(
out
->
out
.
divide
(
routingDetailEquip
.
getOutputQuantity
(),
6
,
RoundingMode
.
HALF_UP
))
.
map
(
BigDecimal:
:
doubleValue
)
.
orElse
(
0.0
)
);
// 查找execId
Long
routingDetailId
=
routingDetailEquip
.
getRoutingDetailId
();
String
execId
=
null
;
if
(
routingDetailId
!=
null
)
{
execId
=
processExecList
.
stream
()
.
filter
(
exec
->
routingDetailId
.
equals
(
exec
.
getRoutingDetailId
()))
.
findFirst
()
.
map
(
ProdProcessExec:
:
getExecId
)
.
orElse
(
null
);
}
if
(
execId
!=
null
)
{
prodEquipment
.
setExecId
(
execId
);
}
else
{
log
.
warn
(
"未找到routingDetailId={}对应的execId"
,
routingDetailEquip
.
getRoutingDetailId
());
}
Equiptype1
equiptype1
=
equipTypes
.
stream
().
filter
(
equip
->
equip
.
getId
().
equals
(
routingDetailEquip
.
getType1
()))
.
findFirst
()
.
orElse
(
null
);
prodEquipments
.
add
(
prodEquipment
);
}
catch
(
Exception
e
)
{
log
.
error
(
"处理设备信息失败,routingDetailEquipId={}"
,
routingDetailEquip
.
getId
(),
e
);
}
}
}
else
{
// 当routingDetailEquips为null时,遍历processExecList,根据machineId去equipinfo里面找设备然后创建prodEquipMent
if
(
processExecList
!=
null
&&
!
processExecList
.
isEmpty
())
{
for
(
ProdProcessExec
exec
:
processExecList
)
{
try
{
// 获取machineId
Long
machineId
=
exec
.
getMachineId
();
if
(
machineId
==
null
)
{
continue
;
}
// 使用Map快速查询设备列表
List
<
Equipinfo
>
matchedEquipments
=
equipinfoByEquipTypeMap
.
get
(
machineId
.
intValue
());
if
(
matchedEquipments
==
null
||
matchedEquipments
.
isEmpty
())
{
log
.
warn
(
"未找到machineId={}对应的设备信息"
,
machineId
);
continue
;
}
// 遍历所有匹配的设备,创建ProdEquipment对象
for
(
Equipinfo
equipinfo1
:
matchedEquipments
)
{
ProdEquipment
prodEquipment
=
new
ProdEquipment
();
prodEquipment
.
setSceneId
(
sceneId
);
// 使用Map快速查询,替代stream操作
PlanResource
planResource
=
planResourceByReferenceIdMap
.
get
(
equipinfo1
.
getId
());
if
(
planResource
!=
null
)
{
prodEquipment
.
setEquipId
(
planResource
.
getId
().
longValue
());
}
else
{
log
.
warn
(
"未找到equipinfoId={}对应的planResource信息"
,
equipinfo1
.
getId
());
continue
;
}
prodEquipment
.
setEquipCode
(
equipinfo1
.
getEquipId
());
prodEquipment
.
setEquipName
(
equipinfo1
.
getEquipName
());
if
(
equiptype1
!=
null
)
{
prodEquipment
.
setResourceCode
(
equiptype1
.
getEquipTypeId
());
}
prodEquipment
.
setEfficiencyValue
(
routingDetailEquip
.
getEfficiencyValue
());
prodEquipment
.
setSetupTime
(
routingDetailEquip
.
getSetupTime
());
prodEquipment
.
setId
(
String
.
valueOf
(
SnowFlackIdWorker
.
getId
()));
prodEquipment
.
setRuntime
(
routingDetailEquip
.
getDuration
());
prodEquipment
.
setSingleOut
(
routingDetailEquip
.
getOutputQuantity
());
prodEquipment
.
setSpeed
(
Optional
.
ofNullable
(
routingDetailEquip
.
getDuration
())
.
filter
(
out
->
routingDetailEquip
.
getOutputQuantity
()
!=
null
)
.
filter
(
out
->
routingDetailEquip
.
getOutputQuantity
().
compareTo
(
BigDecimal
.
ZERO
)
!=
0
)
.
map
(
out
->
out
.
divide
(
routingDetailEquip
.
getOutputQuantity
(),
6
,
RoundingMode
.
HALF_UP
))
.
map
(
BigDecimal:
:
doubleValue
)
// 关键转换
.
orElse
(
0.0
)
);
String
execId
=
processExecList
.
stream
()
.
filter
(
exec
->
{
Long
execRoutingDetailId
=
exec
.
getRoutingDetailId
();
Long
equipRoutingDetailId
=
routingDetailEquip
.
getRoutingDetailId
();
// 处理null值
if
(
execRoutingDetailId
==
null
||
equipRoutingDetailId
==
null
)
{
return
false
;
// 使用Map快速查询
prodEquipment
.
setResourceId
(
machineId
);
Equiptype1
equiptype1
=
equipTypeMap
.
get
(
machineId
);
if
(
equiptype1
!=
null
)
{
prodEquipment
.
setResourceCode
(
equiptype1
.
getEquipTypeId
());
}
// 使用equals比较
return
execRoutingDetailId
.
equals
(
equipRoutingDetailId
);
})
.
findFirst
()
.
map
(
ProdProcessExec:
:
getExecId
)
.
orElse
(
null
);
if
(
execId
!=
null
)
{
prodEquipment
.
setExecId
(
execId
);
}
else
{
log
.
warn
(
"未找到routingDetailId={}对应的execId"
,
routingDetailEquip
.
getRoutingDetailId
());
// 设置其他属性
prodEquipment
.
setEfficiencyValue
(
1.0
);
// 默认效率值
prodEquipment
.
setSetupTime
(
0
);
// 默认准备时间
prodEquipment
.
setId
(
String
.
valueOf
(
SnowFlackIdWorker
.
getId
()));
prodEquipment
.
setRuntime
(
exec
.
getRuntime
());
prodEquipment
.
setSingleOut
(
exec
.
getSingleOut
());
// 计算speed
prodEquipment
.
setSpeed
(
Optional
.
ofNullable
(
exec
.
getRuntime
())
.
filter
(
out
->
exec
.
getSingleOut
()
!=
null
)
.
filter
(
out
->
exec
.
getSingleOut
().
compareTo
(
BigDecimal
.
ZERO
)
!=
0
)
.
map
(
out
->
out
.
divide
(
exec
.
getSingleOut
(),
6
,
RoundingMode
.
HALF_UP
))
.
map
(
BigDecimal:
:
doubleValue
)
.
orElse
(
0.0
)
);
// 设置execId
prodEquipment
.
setExecId
(
exec
.
getExecId
());
prodEquipments
.
add
(
prodEquipment
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"处理工序执行设备信息失败,execId={}"
,
exec
.
getExecId
(),
e
);
}
}
prodEquipments
.
add
(
prodEquipment
);
}
}
else
{
}
// 批量保存
if
(!
prodEquipments
.
isEmpty
()&&
isSave
)
{
...
...
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
fa5b9c03
...
...
@@ -1095,7 +1095,7 @@ private GlobalParam InitGlobalParam()
{
globalParam
.
setIsUseCalendar
(
c
.
isValue
());
}
else
if
(
c
.
getTitle
().
contain
s
(
"设置时间"
))
else
if
(
c
.
getTitle
().
equal
s
(
"设置时间"
))
{
//是否考虑换型时间
globalParam
.
set_smoothChangeOver
(
c
.
isValue
());
...
...
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