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
66d8a496
Commit
66d8a496
authored
Dec 12, 2025
by
DESKTOP-VKRD9QF\Administration
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
场景接口返回统一修改
parent
2c8b8b29
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
13388 additions
and
1165 deletions
+13388
-1165
chromosome_result_09D1B21432744D84982DE2674ADC7442.json
...t/chromosome_result_09D1B21432744D84982DE2674ADC7442.json
+6696
-0
chromosome_result_7E99857F64A44780AF06C326CAEE9682.json
...t/chromosome_result_7E99857F64A44780AF06C326CAEE9682.json
+5286
-0
chromosome_result_B571EF6682DB463AB2977B1055A74112.json
...t/chromosome_result_B571EF6682DB463AB2977B1055A74112.json
+873
-873
R.java
src/main/java/com/aps/common/util/R.java
+12
-12
SwaggerMapParamConfig.java
src/main/java/com/aps/config/SwaggerMapParamConfig.java
+167
-0
LanuchController.java
src/main/java/com/aps/controller/LanuchController.java
+88
-39
ResourceGanttController.java
...ava/com/aps/controller/gantt/ResourceGanttController.java
+186
-193
ProdSceneConfig.java
src/main/java/com/aps/entity/ProdSceneConfig.java
+2
-0
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+3
-17
Initialization.java
src/main/java/com/aps/service/Algorithm/Initialization.java
+18
-19
LanuchServiceImpl.java
src/main/java/com/aps/service/impl/LanuchServiceImpl.java
+7
-7
AlgorithmScheduler8.java
src/main/java/com/aps/service/plan/AlgorithmScheduler8.java
+0
-2
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+2
-0
ProdEquipmentMapper.xml
src/main/resources/mapper/ProdEquipmentMapper.xml
+7
-2
ProdSceneConfigMapper.xml
src/main/resources/mapper/ProdSceneConfigMapper.xml
+6
-1
PlanResultServiceTest.java
src/test/java/com/aps/demo/PlanResultServiceTest.java
+35
-0
No files found.
result/chromosome_result_09D1B21432744D84982DE2674ADC7442.json
0 → 100644
View file @
66d8a496
This diff is collapsed.
Click to expand it.
result/chromosome_result_7E99857F64A44780AF06C326CAEE9682.json
0 → 100644
View file @
66d8a496
This diff is collapsed.
Click to expand it.
result/chromosome_result_B571EF6682DB463AB2977B1055A74112.json
View file @
66d8a496
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/common/util/R.java
View file @
66d8a496
...
...
@@ -17,14 +17,14 @@ import java.time.LocalDateTime;
public
class
R
<
T
>
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Schema
(
description
=
"code码,通常为0为正常,500为异常,其它code码见异常对照表,为规范code码报错异常操作。所有异常报错码以数据表映射相关"
)
@Schema
(
description
=
"code码,通常为
20
0为正常,500为异常,其它code码见异常对照表,为规范code码报错异常操作。所有异常报错码以数据表映射相关"
)
@Getter
@Setter
private
int
code
=
0
;
private
int
code
=
20
0
;
@Getter
@Setter
@Schema
(
description
=
"返回code码为0 时, 默认为success,其它的情况为具体的消息"
)
@Schema
(
description
=
"返回code码为
20
0 时, 默认为success,其它的情况为具体的消息"
)
private
String
msg
=
"success"
;
@Getter
...
...
@@ -39,31 +39,31 @@ public class R<T> implements Serializable {
private
LocalDateTime
timestamp
=
LocalDateTime
.
now
();
public
static
<
T
>
R
<
T
>
ok
()
{
return
restResult
(
null
,
0
,
"success"
);
return
restResult
(
null
,
20
0
,
"success"
);
}
public
static
<
T
>
R
<
T
>
ok
(
T
data
)
{
return
restResult
(
data
,
0
,
"success"
);
return
restResult
(
data
,
20
0
,
"success"
);
}
public
static
<
T
>
R
<
T
>
ok
(
T
data
,
String
msg
)
{
return
restResult
(
data
,
0
,
msg
);
return
restResult
(
data
,
20
0
,
msg
);
}
public
static
<
T
>
R
<
T
>
failed
()
{
return
restResult
(
null
,
1
,
"error"
);
return
restResult
(
null
,
500
,
"error"
);
}
public
static
<
T
>
R
<
T
>
failed
(
String
msg
)
{
return
restResult
(
null
,
1
,
msg
);
return
restResult
(
null
,
500
,
msg
);
}
public
static
<
T
>
R
<
T
>
failed
(
T
data
)
{
return
restResult
(
data
,
1
,
"error"
);
return
restResult
(
data
,
500
,
"error"
);
}
public
static
<
T
>
R
<
T
>
failed
(
T
data
,
String
msg
)
{
return
restResult
(
data
,
1
,
msg
);
return
restResult
(
data
,
500
,
msg
);
}
public
static
<
T
>
R
<
T
>
failed
(
int
code
,
String
msg
)
{
...
...
@@ -96,7 +96,7 @@ public class R<T> implements Serializable {
public
R
(
Throwable
e
)
{
super
();
this
.
msg
=
e
.
getMessage
();
this
.
code
=
1
;
this
.
code
=
500
;
}
private
static
<
T
>
R
<
T
>
restResult
(
T
data
,
int
code
,
String
msg
)
{
...
...
@@ -113,6 +113,6 @@ public class R<T> implements Serializable {
* @return
*/
public
boolean
is
()
{
return
this
.
code
==
0
;
return
this
.
code
==
20
0
;
}
}
\ No newline at end of file
src/main/java/com/aps/config/SwaggerMapParamConfig.java
0 → 100644
View file @
66d8a496
package
com
.
aps
.
config
;
import
io.swagger.v3.oas.models.media.MapSchema
;
import
io.swagger.v3.oas.models.media.Schema
;
import
io.swagger.v3.oas.models.media.StringSchema
;
import
io.swagger.v3.oas.models.examples.Example
;
// 添加这个导入
import
org.springdoc.core.customizers.OperationCustomizer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.method.HandlerMethod
;
import
java.util.HashMap
;
import
java.util.Map
;
@Configuration
public
class
SwaggerMapParamConfig
{
@Bean
public
OperationCustomizer
customizeOperation
()
{
return
(
operation
,
handlerMethod
)
->
{
if
(
operation
.
getRequestBody
()
!=
null
&&
operation
.
getRequestBody
().
getContent
()
!=
null
&&
operation
.
getRequestBody
().
getContent
().
get
(
"application/json"
)
!=
null
)
{
Schema
<?>
schema
=
operation
.
getRequestBody
().
getContent
().
get
(
"application/json"
).
getSchema
();
if
(
schema
instanceof
MapSchema
)
{
addParamExamples
(
operation
,
handlerMethod
);
}
}
return
operation
;
};
}
private
void
addParamExamples
(
io
.
swagger
.
v3
.
oas
.
models
.
Operation
operation
,
HandlerMethod
handlerMethod
)
{
String
methodName
=
handlerMethod
.
getMethod
().
getName
();
Map
<
String
,
Schema
>
properties
=
new
HashMap
<>();
Map
<
String
,
Example
>
examples
=
new
HashMap
<>();
// 修改这里:Object -> Example
switch
(
methodName
)
{
case
"lanuch"
:
properties
.
put
(
"sceneName"
,
new
StringSchema
().
description
(
"场景名称"
).
example
(
"scene_001"
));
properties
.
put
(
"userId"
,
new
StringSchema
().
description
(
"用户ID"
).
example
(
"111"
));
examples
.
put
(
"启动工单示例"
,
createExample
(
"启动指定场景的工单处理"
,
"{\n"
+
" \"sceneName\": \"scene_001\",\n"
+
" \"userId\": \"111\"\n"
+
"}"
));
break
;
case
"schedule"
:
properties
.
put
(
"sceneId"
,
new
StringSchema
().
description
(
"场景ID"
).
example
(
"487282ECAF57435F9373BAAAFBE90616"
));
examples
.
put
(
"排程计算示例"
,
createExample
(
"执行场景的排程算法计算"
,
"{\n"
+
" \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\"\n"
+
"}"
));
break
;
case
"copyScene"
:
properties
.
put
(
"oldSceneId"
,
new
StringSchema
().
description
(
"原场景ID"
).
example
(
"B571EF6682DB463AB2977B1055A74112"
));
properties
.
put
(
"newSceneId"
,
new
StringSchema
().
description
(
"新场景名称"
).
example
(
"scene_002"
));
properties
.
put
(
"userId"
,
new
StringSchema
().
description
(
"用户ID"
).
example
(
"111"
));
examples
.
put
(
"完整复制示例"
,
createExample
(
"复制场景包含所有数据和配置"
,
"{\n"
+
" \"oldSceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n"
+
" \"newSceneName\": \"scene_002\",\n"
+
" \"userId\": \"111\"\n"
+
"}"
));
examples
.
put
(
"最小复制示例"
,
createExample
(
"仅提供必需参数的场景复制"
,
"{\n"
+
" \"oldSceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n"
+
" \"newSceneName\": \"scene_002\",\n"
+
" \"userId\": \"111\"\n"
+
"}"
));
break
;
case
"exportPlan"
:
properties
.
put
(
"sceneId"
,
new
StringSchema
().
description
(
"场景ID"
).
example
(
"487282ECAF57435F9373BAAAFBE90616"
));
examples
.
put
(
"导出计划示例"
,
createExample
(
"导出指定场景的排程结果为生产计划"
,
"{\n"
+
" \"sceneId\": \"487282ECAF57435F9373BAAAFBE90616\"\n"
+
"}"
));
break
;
case
"deleteScene"
:
properties
.
put
(
"sceneId"
,
new
StringSchema
().
description
(
"场景ID"
).
example
(
"487282ECAF57435F9373BAAAFBE90616"
));
examples
.
put
(
"删除场景示例"
,
createExample
(
"删除指定的场景"
,
"{\n"
+
" \"sceneId\": \"487282ECAF57435F9373BAAAFBE90616\"\n"
+
"}"
));
examples
.
put
(
"批量删除示例"
,
createExample
(
"删除多个场景(如果支持批量删除)"
,
"{\n"
+
" \"sceneId\": \"487282ECAF57435F9373BAAAFBE90616\"\n"
+
"}"
));
break
;
case
"getAllScene"
:
properties
.
put
(
"userId"
,
new
StringSchema
().
description
(
"用户ID"
).
example
(
"111"
));
examples
.
put
(
"获取场景示例"
,
createExample
(
"获取指定用户的所有场景"
,
"{\n"
+
" \"userId\": \"111\"\n"
+
"}"
));
examples
.
put
(
"管理员查询示例"
,
createExample
(
"管理员查询系统所有场景(如果支持)"
,
"{\n"
+
" \"userId\": \"111\"\n"
+
"}"
));
break
;
}
if
(!
properties
.
isEmpty
())
{
MapSchema
mapSchema
=
new
MapSchema
();
mapSchema
.
setProperties
(
properties
);
mapSchema
.
setDescription
(
getMethodDescription
(
methodName
));
if
(!
examples
.
isEmpty
())
{
mapSchema
.
setExample
(
examples
.
values
().
iterator
().
next
());
operation
.
getRequestBody
().
getContent
().
get
(
"application/json"
).
setExamples
(
examples
);
// 这行现在类型匹配了
}
operation
.
getRequestBody
().
getContent
().
get
(
"application/json"
).
setSchema
(
mapSchema
);
}
}
// 修改这里:返回类型从 Map<String, Object> 改为 Example
private
Example
createExample
(
String
summary
,
String
value
)
{
Example
example
=
new
Example
();
example
.
setSummary
(
summary
);
example
.
setValue
(
value
);
return
example
;
}
private
String
getMethodDescription
(
String
methodName
)
{
switch
(
methodName
)
{
case
"lanuch"
:
return
"启动工单请求参数"
;
case
"schedule"
:
return
"排程计算请求参数"
;
case
"copyScene"
:
return
"复制场景请求参数"
;
case
"exportPlan"
:
return
"导出计划请求参数"
;
case
"deleteScene"
:
return
"删除场景请求参数"
;
case
"getAllScene"
:
return
"获取场景列表请求参数"
;
default
:
return
"请求参数"
;
}
}
}
src/main/java/com/aps/controller/LanuchController.java
View file @
66d8a496
...
...
@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/lanuch"
)
...
...
@@ -26,64 +27,112 @@ public class LanuchController {
@Autowired
private
ProdSceneConfigService
prodSceneConfigService
;
/**
* 启动工单
*
* @param sceneId 场景名称
* @param userId 用户名
* @return 处理结果
*/
@PostMapping
(
"/execute"
)
public
R
<
String
>
lanuch
(
@RequestParam
String
sceneId
,
@RequestHeader
(
required
=
false
)
String
userId
)
{
@Operation
(
summary
=
"启动工单"
)
public
R
<
String
>
lanuch
(
@RequestBody
Map
<
String
,
String
>
params
)
{
String
sceneName
=
params
.
get
(
"sceneName"
);
String
userId
=
params
.
get
(
"userId"
);
if
(
sceneName
==
null
||
sceneName
.
trim
().
isEmpty
())
{
return
R
.
failed
(
"场景名称不能为空"
);
}
return
lanuchService
.
lanuch
(
scene
Id
,
userId
);
return
lanuchService
.
lanuch
(
scene
Name
,
userId
);
}
@GetMapping
(
"/schedule"
)
public
Chromosome
schedule
(
@RequestParam
String
sceneId
)
{
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome
scheduleChromosomes
=
planResultService
.
schedule
(
sceneId
);
/**
* 执行排程
*/
@PostMapping
(
"/schedule"
)
@Operation
(
summary
=
"运算"
)
public
R
<
Chromosome
>
schedule
(
@RequestBody
Map
<
String
,
String
>
params
)
{
String
sceneId
=
params
.
get
(
"sceneId"
);
// 提取所有场景ID
return
scheduleChromosomes
;
if
(
sceneId
==
null
||
sceneId
.
trim
().
isEmpty
())
{
return
R
.
failed
(
"场景ID不能为空"
)
;
}
try
{
Chromosome
scheduleChromosomes
=
planResultService
.
schedule
(
sceneId
);
return
R
.
ok
(
scheduleChromosomes
);
}
catch
(
Exception
e
)
{
return
R
.
failed
(
"排程执行失败: "
+
e
.
getMessage
());
}
}
/**
* 复制场景
*/
@PostMapping
(
"/copyScene"
)
public
R
<
String
>
copyScene
(
@RequestParam
String
newSceneId
,
@RequestParam
String
oldSceneId
,
@RequestHeader
(
required
=
false
)
String
userId
)
{
@Operation
(
summary
=
"复制场景"
)
public
R
<
String
>
copyScene
(
@RequestBody
Map
<
String
,
String
>
params
)
{
String
oldSceneId
=
params
.
get
(
"oldSceneId"
);
String
newSceneName
=
params
.
get
(
"newSceneName"
);
String
userId
=
params
.
get
(
"userId"
);
if
(
oldSceneId
==
null
||
oldSceneId
.
trim
().
isEmpty
())
{
return
R
.
failed
(
"原场景ID不能为空"
);
}
if
(
newSceneName
==
null
||
newSceneName
.
trim
().
isEmpty
())
{
return
R
.
failed
(
"新场景名称不能为空"
);
}
if
(
userId
==
null
||
userId
.
trim
().
isEmpty
())
{
return
R
.
failed
(
"用户名不能为空"
);
}
return
lanuchService
.
copyScene
(
oldSceneId
,
userId
,
newSceneName
);
}
/**
* 导出计划
*/
@PostMapping
(
"/exportPlan"
)
@Operation
(
summary
=
"导出计划"
)
public
R
<
String
>
exportPlan
(
@RequestBody
Map
<
String
,
String
>
params
)
{
String
sceneId
=
params
.
get
(
"sceneId"
);
return
lanuchService
.
copyScene
(
oldSceneId
,
userId
,
newSceneId
);
if
(
sceneId
==
null
||
sceneId
.
trim
().
isEmpty
())
{
return
R
.
failed
(
"场景ID不能为空"
);
}
@GetMapping
(
"/exportPlan"
)
public
R
<
String
>
exportPlan
(
@RequestParam
String
sceneId
)
{
// 调用 PlanResultService 获取 ScheduleChromosome 列表
return
lanuchService
.
exportPlan
(
sceneId
);
}
/**
* 删除场景
*/
@PostMapping
(
"/deleteScene"
)
@Operation
(
summary
=
"删除场景"
)
public
R
<
Boolean
>
deleteScene
(
@RequestBody
Map
<
String
,
String
>
params
)
{
String
sceneId
=
params
.
get
(
"sceneId"
);
@GetMapping
(
"/deleteScene"
)
public
R
<
Boolean
>
deleteScene
(
@RequestParam
String
sceneId
)
{
// 调用 PlanResultService 获取 ScheduleChromosome 列表
return
R
.
ok
(
prodSceneConfigService
.
deleteSceneById
(
sceneId
));
if
(
sceneId
==
null
||
sceneId
.
trim
().
isEmpty
())
{
return
R
.
failed
(
"场景ID不能为空"
);
}
boolean
result
=
prodSceneConfigService
.
deleteSceneById
(
sceneId
);
return
result
?
R
.
ok
(
true
)
:
R
.
failed
(
"删除场景失败"
);
}
@GetMapping
(
"/getAllScene"
)
public
R
<
List
<
ProdSceneConfig
>>
getAllScene
(
@RequestParam
String
userId
)
{
// 调用 PlanResultService 获取 ScheduleChromosome 列表
return
R
.
ok
(
prodSceneConfigService
.
lambdaQuery
()
.
eq
(
ProdSceneConfig:
:
getCreateUser
,
userId
)
.
list
());
/**
* 获取用户所有场景
*/
@PostMapping
(
"/getAllScene"
)
@Operation
(
summary
=
"获取用户场景"
)
public
R
<
List
<
ProdSceneConfig
>>
getAllScene
(
@RequestBody
Map
<
String
,
String
>
params
)
{
String
userId
=
params
.
get
(
"userId"
);
if
(
userId
==
null
||
userId
.
trim
().
isEmpty
())
{
return
R
.
failed
(
"用户ID不能为空"
);
}
List
<
ProdSceneConfig
>
scenes
=
prodSceneConfigService
.
lambdaQuery
()
.
eq
(
ProdSceneConfig:
:
getCreateUser
,
userId
)
.
list
();
return
R
.
ok
(
scenes
);
}
}
\ No newline at end of file
src/main/java/com/aps/controller/gantt/ResourceGanttController.java
View file @
66d8a496
...
...
@@ -488,7 +488,7 @@ public class ResourceGanttController {
// 转换为 ResourceGanttVO 格式
List
<
ResourceGanttVO
>
resourceGanttVOList
=
new
ArrayList
<>();
List
<
ResourceGanttVO
>
resourceGanttVOs
=
convertToResourceGanttVO1
(
schedule
,
sceneId
);
List
<
ResourceGanttVO
>
resourceGanttVOs
=
convertToResourceGanttVO1
(
schedule
);
resourceGanttVOList
.
addAll
(
resourceGanttVOs
);
return
resourceGanttVOList
;
...
...
@@ -497,13 +497,10 @@ public class ResourceGanttController {
private
List
<
ResourceGanttVO
>
convertToResourceGanttVO1
(
Chromosome
scheduleChromosome
,
String
sceneId
)
{
private
List
<
ResourceGanttVO
>
convertToResourceGanttVO1
(
Chromosome
scheduleChromosome
)
{
List
<
ResourceGanttVO
>
resourceGanttVOList
=
new
ArrayList
<>();
List
<
Machine
>
machineList
=
planResultService
.
InitCalendarToAllMachines1
(
sceneId
);
List
<
Machine
>
machineList
=
planResultService
.
InitCalendarToAllMachines1
(
scheduleChromosome
.
getScenarioID
());
// 遍历所有机器资源
if
(
machineList
!=
null
)
{
for
(
int
i
=
0
;
i
<
machineList
.
size
();
i
++)
{
...
...
@@ -511,16 +508,14 @@ public class ResourceGanttController {
ResourceGanttVO
resourceGanttVO
=
new
ResourceGanttVO
();
resourceGanttVO
.
setId
(
machine
.
getId
());
resourceGanttVO
.
setName
(
machine
.
getId
()
+
"号设备"
);
resourceGanttVO
.
setName
(
machine
.
getId
()
+
"号设备"
);
resourceGanttVO
.
setShift
(
convertToVO
(
machine
));
// 转换任务列表
List
<
TaskVO
>
taskVOList
=
new
ArrayList
<>();
if
(
scheduleChromosome
!=
null
){
if
(
scheduleChromosome
.
getResult
()
!=
null
)
{
if
(
scheduleChromosome
.
getResult
()
!=
null
)
{
// 筛选出属于当前设备的任务
List
<
GAScheduleResult
>
machineGenes
=
scheduleChromosome
.
getResult
().
stream
()
.
filter
(
gene
->
gene
.
getMachineId
()
==
(
machine
.
getId
()))
.
filter
(
gene
->
gene
.
getMachineId
()==
(
machine
.
getId
()))
.
collect
(
Collectors
.
toList
());
// 按开始时间排序
...
...
@@ -572,9 +567,10 @@ public class ResourceGanttController {
taskVO
.
setAbsolutePreparationTime
(
gene
.
getTeardownTime
());
}
}
}
resourceGanttVO
.
setList
(
taskVOList
);
resourceGanttVOList
.
add
(
resourceGanttVO
);
}
...
...
@@ -596,9 +592,6 @@ public class ResourceGanttController {
List
<
ProductGanttVO
>
productGanttVOList
=
new
ArrayList
<>();
// 按产品ID和工单ID分组基因
if
(
scheduleChromosome
!=
null
)
{
if
(
scheduleChromosome
.
getResult
()
!=
null
)
{
// 按工单ID分组
scheduleChromosome
.
getResult
().
stream
()
...
...
@@ -608,17 +601,17 @@ public class ResourceGanttController {
ProductGanttVO
productGanttVO
=
new
ProductGanttVO
();
GAScheduleResult
firstGene
=
genes
.
get
(
0
);
productGanttVO
.
setId
(
firstGene
.
getOrderId
());
productGanttVO
.
setProductName
(
"产品"
+
firstGene
.
getProductId
());
// 默认值,实际应从订单数据获取
productGanttVO
.
setProductName
(
"产品"
+
firstGene
.
getProductId
());
// 默认值,实际应从订单数据获取
productGanttVO
.
setProductType
(
0
);
productGanttVO
.
setProductId
(
firstGene
.
getProductId
());
// 计算总数量(假设同一批次)
productGanttVO
.
setQuantity
(
firstGene
.
getQuantity
());
productGanttVO
.
setCode
(
"编号"
+
firstGene
.
getProductId
());
// 默认值
productGanttVO
.
setCode
(
"编号"
+
firstGene
.
getProductId
());
// 默认值
productGanttVO
.
setShopId
(
firstGene
.
getMachineId
());
// 默认值
productGanttVO
.
setShopName
(
firstGene
.
getMachineId
()
+
"号线"
);
// 默认值
productGanttVO
.
setShopName
(
firstGene
.
getMachineId
()+
"号线"
);
// 默认值
productGanttVO
.
setStatus
(
"已发布"
);
// productGanttVO.setHeaderId(firstGene.getProductId());
productGanttVO
.
setHeaderName
(
"工艺"
+
firstGene
.
getProductId
());
// 默认值
productGanttVO
.
setHeaderName
(
"工艺"
+
firstGene
.
getProductId
());
// 默认值
// 计算开始和结束时间
int
minStartTime
=
genes
.
stream
()
...
...
@@ -644,7 +637,7 @@ public class ResourceGanttController {
taskVO
.
setId
(
gene
.
getOrderId
());
// 生成唯一ID
taskVO
.
setPlanId
(
String
.
valueOf
(
orderId
));
taskVO
.
setProductType
(
0
);
taskVO
.
setProductName
(
"产品"
+
gene
.
getProductId
());
taskVO
.
setProductName
(
"产品"
+
gene
.
getProductId
());
taskVO
.
setProductId
(
String
.
valueOf
(
gene
.
getProductId
()));
taskVO
.
setQuantity
(
gene
.
getQuantity
());
taskVO
.
setStart
(
scheduleChromosome
.
getBaseTime
().
plusSeconds
(
gene
.
getStartTime
()));
...
...
@@ -660,11 +653,11 @@ public class ResourceGanttController {
scheduleChromosome
.
getBaseTime
().
plusMinutes
(
gene
.
getEndTime
())));
taskVO
.
setEquipId
(
gene
.
getMachineId
());
// 生成设备ID
taskVO
.
setShopId
(
gene
.
getMachineId
());
taskVO
.
setShopName
(
gene
.
getMachineId
()
+
"车间"
);
taskVO
.
setShopName
(
gene
.
getMachineId
()+
"车间"
);
taskVO
.
setStatus
(
0
);
// taskVO.setDetailId((long) gene.getProductId() * 1000 + gene.getOperationId());
// taskVO.setHeaderId(gene.getProductId());
taskVO
.
setHeaderName
(
"工艺"
+
gene
.
getProductId
());
taskVO
.
setHeaderName
(
"工艺"
+
gene
.
getProductId
());
// taskVO.setSeq(gene.getSequenceId());
// taskVO.setSeqName("工序名称"+gene.getSequenceId());
// taskVO.setAbsoluteStart(scheduleChromosome.getBaseTime().plusMinutes(gene.getStartTime()));
...
...
@@ -678,7 +671,7 @@ public class ResourceGanttController {
}
});
}
}
return
productGanttVOList
;
}
...
...
src/main/java/com/aps/entity/ProdSceneConfig.java
View file @
66d8a496
...
...
@@ -7,6 +7,8 @@ import java.time.LocalDateTime;
@Data
public
class
ProdSceneConfig
{
private
String
sceneId
;
private
String
sceneName
;
private
String
sceneDesc
;
...
...
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
66d8a496
...
...
@@ -254,8 +254,7 @@ public class GeneticDecoder {
int
preTime
=
machineOption
.
getPreTime
();
int
setupTime
=
calculateSetupTime
(
chromosome
.
getResult
(),
operation
,
machine
,
machineOption
);
System
.
out
.
println
(
" 处理时间: "
+
processingTime
+
", 后处理: "
+
teardownTime
+
", 前处理: "
+
preTime
+
", 换型: "
+
setupTime
);
// 确定任务的最早开始时间(基于前一道工序的完整结束时间,包含后处理)
...
...
@@ -284,32 +283,25 @@ public class GeneticDecoder {
machineAvailableTime
+=
setupTime
;
// 平滑模式:换型在非工作时间进行,不额外占用设备时间
System
.
out
.
println
(
" 平滑模式换型:在非工作时间进行,设备可用时间不变"
);
}
else
{
// 标准模式:换型需要额外占用设备时间
machineAvailableTime
+=
setupTime
;
System
.
out
.
println
(
" 标准模式换型:需要额外占用设备 "
+
setupTime
+
" 分钟"
);
}
}
earliestStartTime
=
Math
.
max
(
earliestStartTime
,
machineAvailableTime
);
}
System
.
out
.
println
(
" 最终最早开始时间: "
+
earliestStartTime
+
" (前序工序结束含后处理: "
+
prevOperationEndTime
+
", 设备可用: "
+
(
lastGeneOnMachine
!=
null
?
lastGeneOnMachine
.
getEndTime
()
:
0
)
+
", 换型: "
+
setupTime
+
")"
);
// 根据换型模式调整处理时间
// int processingTimeForScheduling;
if
(
_globalParam
.
is_smoothSetup
())
{
// 平滑模式:只需要安排主处理时间
// processingTimeForScheduling = processingTimeTotal;
System
.
out
.
println
(
" 平滑模式:安排主处理时间 "
+
processingTime
+
" 分钟"
);
}
else
{
// 标准模式:需要安排主处理时间+换型时间
processingTimeTotal
=
processingTimeTotal
+
setupTime
;
System
.
out
.
println
(
" 标准模式:安排主处理+"
+
setupTime
+
"分钟换型="
+
processingTimeTotal
+
"分钟"
);
}
GAScheduleResult
existingResult
=
chromosome
.
getResultOld
().
stream
().
filter
(
r
->
r
.
getOperationId
()
==
operation
.
Id
).
findFirst
().
orElse
(
null
);
...
...
@@ -346,7 +338,6 @@ public class GeneticDecoder {
.
orElse
(
null
);
if
(
conflictingGene
!=
null
)
{
System
.
out
.
println
(
" ⚠️ 检测到时间冲突,重新调度"
);
int
conflictSetupStartTime
=
conflictingGene
.
getEndTime
();
int
conflictSetupTime
=
calculateSetupTimeForConflict
(
chromosome
.
getResult
(),
operation
,
machine
,
machineOption
,
conflictingGene
);
int
conflictEarliestStartTime
=
conflictSetupStartTime
+
conflictSetupTime
;
...
...
@@ -365,7 +356,6 @@ public class GeneticDecoder {
.
mapToInt
(
ScheduleResultDetail:
:
getEndTime
)
.
max
()
.
orElse
(
0
);
System
.
out
.
println
(
" 重新安排时间: "
+
ConvertTime
(
startTime
)
+
" - "
+
ConvertTime
(
endTime
));
}
}
...
...
@@ -655,7 +645,6 @@ public class GeneticDecoder {
.
orElse
(
null
);
if
(
lastGeneOnMachine
==
null
)
{
System
.
out
.
println
(
"设备 "
+
machine
.
getId
()
+
" 上无历史任务,换型时间为0"
);
return
0
;
}
Entry
prev
=
_allOperations
.
stream
().
...
...
@@ -673,7 +662,6 @@ public class GeneticDecoder {
if
(
setupTime
>
0
)
{
System
.
out
.
println
(
"设备 "
+
machine
.
getId
()
+
" 需要换型,因为产品从 "
+
prev
.
getProductId
()
+
" 变更为 "
+
operation
.
getProductId
());
}
}
...
...
@@ -694,9 +682,7 @@ public class GeneticDecoder {
setupTime
=
0
;
}
if
(
setupTime
>
0
)
{
System
.
out
.
println
(
"设备 "
+
machine
.
getId
()
+
" 需要换型,因为产品从 "
+
conflictingGene
.
getProductId
()
+
" 变更为 "
+
operation
.
getProductId
());
}
return
setupTime
;
}
...
...
src/main/java/com/aps/service/Algorithm/Initialization.java
View file @
66d8a496
...
...
@@ -44,36 +44,32 @@ public class Initialization {
* 生成初始种群
*/
public
List
<
Chromosome
>
generateInitialPopulation
(
ScheduleParams
param
,
List
<
GlobalOperationInfo
>
globalOpList
)
{
List
<
Chromosome
>
population
=
new
ArrayList
<>();
// 按比例生成不同类型个体(GS:40%, LS:40%, RS:20%)
int
gsCount
=
(
int
)
(
param
.
getPopulationSize
()
*
param
.
getGsRatio
());
int
lsCount
=
gsCount
+
(
int
)
(
param
.
getPopulationSize
()
*
param
.
getLsRatio
());
int
lsCount
=
gsCount
+
(
int
)
(
param
.
getPopulationSize
()
*
param
.
getLsRatio
());
int
rsCount
=
param
.
getPopulationSize
()
-
gsCount
-
lsCount
;
int
populationSize
=
param
.
getPopulationSize
();
// 并行循环:对应 Parallel.For(0, PopulationSize, i => { ... })
IntStream
.
range
(
0
,
populationSize
)
.
parallel
()
// 开启并行
.
forEach
(
i
->
{
Chromosome
chromo
=
new
Chromosome
();
// 初始化染色体
int
populationSize
=
param
.
getPopulationSize
();
// 使用并行流生成所有染色体,然后收集到列表中,避免并发修改ArrayList的问题
List
<
Chromosome
>
population
=
IntStream
.
range
(
0
,
populationSize
)
.
parallel
()
.
mapToObj
(
i
->
{
Chromosome
chromo
=
new
Chromosome
();
// 全局选择(GS):按GlobalOpId顺序生成MachineSelection
if
(
i
<
gsCount
)
{
generateGSChromosome
(
chromo
,
globalOpList
);
// 对应 C# GenerateGSChromosome
generateGSChromosome
(
chromo
,
globalOpList
);
}
else
if
(
i
<
lsCount
)
{
// 局部选择(LS):按GlobalOpId顺序生成MachineSelection(仅负载计算范围不同)
generateLSChromosome
(
chromo
,
globalOpList
);
generateLSChromosome
(
chromo
,
globalOpList
);
}
else
{
// 随机选择(RS):按GlobalOpId顺序生成MachineSelection(仅机器选择随机)
generateRSChromosome
(
chromo
,
globalOpList
);
generateRSChromosome
(
chromo
,
globalOpList
);
}
population
.
add
(
chromo
);
// 赋值到数组,线程安全(数组索引唯一)
});
return
chromo
;
})
.
collect
(
Collectors
.
toList
());
return
population
;
}
...
...
@@ -113,7 +109,6 @@ int populationSize=param.getPopulationSize();
.
min
(
Comparator
.
comparingDouble
(
m
->
machineLoad
.
getOrDefault
(
m
.
getMachineId
(),
(
double
)
0
)
+
m
.
getProcessingTime
()))
.
orElseThrow
(()
->
new
NoSuchElementException
(
"MachineOption not found for machine: "
));
OptionalInt
index
=
IntStream
.
range
(
0
,
optionalMachines
.
size
())
.
filter
(
i
->
minLoadMachine
.
getMachineId
()==
optionalMachines
.
get
(
i
).
getMachineId
())
.
findFirst
();
...
...
@@ -177,6 +172,10 @@ int populationSize=param.getPopulationSize();
// 选择“当前订单内设备负载+加工时间”最小的机器
List
<
MachineOption
>
optionalMachines
=
op
.
getMachineOptions
();
if
(
optionalMachines
==
null
||
optionalMachines
.
isEmpty
())
{
throw
new
IllegalStateException
(
"工序 "
+
op
.
getId
()
+
" 没有可用的机器选项"
);
}
MachineOption
minLoadMachine
=
optionalMachines
.
stream
()
...
...
src/main/java/com/aps/service/impl/LanuchServiceImpl.java
View file @
66d8a496
...
...
@@ -142,16 +142,16 @@ public class LanuchServiceImpl implements LanuchService {
/**
*复制数据
* @param oldScene
Name
* @param oldScene
Id
* @param newSceneName
* @return R<String> Result
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
R
<
String
>
copyScene
(
String
oldScene
Name
,
String
username
,
String
newSceneName
)
{
public
R
<
String
>
copyScene
(
String
oldScene
Id
,
String
username
,
String
newSceneName
)
{
try
{
// Validate input parameters
if
(
oldScene
Name
==
null
||
oldSceneName
.
trim
().
isEmpty
())
{
if
(
oldScene
Id
==
null
||
oldSceneId
.
trim
().
isEmpty
())
{
return
R
.
failed
(
"场景ID不能为空"
);
}
...
...
@@ -163,7 +163,7 @@ public class LanuchServiceImpl implements LanuchService {
// 检查场景是否存在
ProdSceneConfig
oldScene
=
prodSceneConfigService
.
lambdaQuery
()
.
eq
(
ProdSceneConfig:
:
getScene
Name
,
oldSceneName
)
.
eq
(
ProdSceneConfig:
:
getScene
Id
,
oldSceneId
)
.
one
();
if
(
oldScene
==
null
)
{
...
...
@@ -185,7 +185,6 @@ public class LanuchServiceImpl implements LanuchService {
// 复制染色体文件(排产结果)
copyChromosomeFile
(
oldScene
.
getSceneId
(),
newSceneId
);
log
.
info
(
"场景数据复制完成,从 {} 到 {}"
,
oldSceneName
,
newSceneName
);
return
R
.
ok
(
"场景数据复制成功"
);
}
catch
(
Exception
e
)
{
...
...
@@ -864,8 +863,9 @@ public class LanuchServiceImpl implements LanuchService {
private
List
<
ProdOrderProcess
>
createProcessRelations
(
ProdLaunchOrder
prodOrderMain
,
String
sceneId
,
Map
<
Long
,
String
>
routingDetailIdToExecIdMap
)
{
LambdaQueryWrapper
<
RoutingDetailConnect
>
wrapper
=
new
LambdaQueryWrapper
<>();
wrapper
.
eq
(
RoutingDetailConnect:
:
getRoutingHeaderId
,
prodOrderMain
.
getRoutingId
())
.
eq
(
RoutingDetailConnect:
:
getIsdeleted
,
0
);
// 添加 isdeleted=0 过滤条件
.
eq
(
RoutingDetailConnect:
:
getIsdeleted
,
0
)
.
isNotNull
(
RoutingDetailConnect:
:
getSourceoperationid
)
// 添加 sourceoperationid 不为 null 的过滤条件
.
isNotNull
(
RoutingDetailConnect:
:
getSourceoperation
);
List
<
RoutingDetailConnect
>
connections
=
routingDetailConnectService
.
list
(
wrapper
);
return
connections
.
stream
()
...
...
src/main/java/com/aps/service/plan/AlgorithmScheduler8.java
View file @
66d8a496
...
...
@@ -553,7 +553,6 @@ public class AlgorithmScheduler8 {
.
orElse
(
null
);
if
(
lastGeneOnMachine
==
null
)
{
System
.
out
.
println
(
"设备 "
+
machine
.
getId
()
+
" 上无历史任务,换型时间为0"
);
return
0
;
}
...
...
@@ -562,7 +561,6 @@ public class AlgorithmScheduler8 {
:
0
;
if
(
setupTime
>
0
)
{
System
.
out
.
println
(
"设备 "
+
machine
.
getId
()
+
" 需要换型,因为产品从 "
+
lastGeneOnMachine
.
getProductId
()
+
" 变更为 "
+
currentOrder
.
getProductId
());
}
return
setupTime
;
...
...
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
66d8a496
...
...
@@ -552,6 +552,8 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
return
chromosomes
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"调度执行失败"
,
e
);
}
}
...
...
src/main/resources/mapper/ProdEquipmentMapper.xml
View file @
66d8a496
...
...
@@ -9,11 +9,16 @@
<id
column=
"RESOURCE_ID"
property=
"resourceId"
/>
<result
column=
"EQUIP_CODE"
property=
"equipCode"
/>
<result
column=
"EQUIP_NAME"
property=
"equipName"
/>
<result
column=
"EXEC_ID"
property=
"execId"
/>
<result
column=
"SPEED"
property=
"speed"
/>
<result
column=
"ID"
property=
"id"
/>
<result
column=
"EFFICIENCY_VALUE"
property=
"efficiencyValue"
/>
<result
column=
"SETUP_TIME"
property=
"setupTime"
/>
</resultMap>
<!-- 通用查询结果列 -->
<sql
id=
"Base_Column_List"
>
SCENE_ID, EQUIP_ID, EQUIP_CODE, EQUIP_NAME, RESOURCE_ID
SCENE_ID, EQUIP_ID, EQUIP_CODE, EQUIP_NAME, RESOURCE_ID
, EXEC_ID, SPEED, ID, EFFICIENCY_VALUE, SETUP_TIME
</sql>
</mapper>
\ No newline at end of file
src/main/resources/mapper/ProdSceneConfigMapper.xml
View file @
66d8a496
...
...
@@ -24,4 +24,9 @@
SCENE_ID, SCENE_NAME, SCENE_DESC, CREATE_TIME, SCENE_OWNER, SCENE_STATUS, RELATE_PLAN_ID, CREATE_USER, UPDATE_TIME, UPDATE_USER, EXTEND1, EXTEND2, EXTEND3
</sql>
<!-- 根据ID删除场景配置 -->
<delete
id=
"deleteById"
parameterType=
"string"
>
DELETE FROM prod_scene_config WHERE SCENE_ID = #{sceneId}
</delete>
</mapper>
\ No newline at end of file
src/test/java/com/aps/demo/PlanResultServiceTest.java
0 → 100644
View file @
66d8a496
package
com
.
aps
.
demo
;
import
com.aps.ApsApplication
;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.service.plan.PlanResultService
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
(
classes
=
ApsApplication
.
class
)
public
class
PlanResultServiceTest
{
@Autowired
private
PlanResultService
planResultService
;
@Test
public
void
testExecute2
()
{
// 这里需要一个有效的SceneId来测试
// 在实际测试中,您需要提供一个数据库中存在的SceneId
String
sceneId
=
"7E99857F64A44780AF06C326CAEE9682"
;
try
{
Chromosome
result
=
planResultService
.
execute2
(
sceneId
);
System
.
out
.
println
(
"执行成功,结果:"
+
(
result
!=
null
?
"获得染色体对象"
:
"空结果"
));
if
(
result
!=
null
)
{
System
.
out
.
println
(
"适应度: "
+
result
.
getFitness
());
System
.
out
.
println
(
"工序字符串: "
+
result
.
getOperationStr
());
}
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
"执行过程中发生异常: "
+
e
.
getMessage
());
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
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