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
1173674e
Commit
1173674e
authored
Dec 01, 2025
by
DESKTOP-VKRD9QF\Administration
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
场景文件保存读取
parent
05e4217f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
421 additions
and
21 deletions
+421
-21
LanuchController.java
src/main/java/com/aps/controller/LanuchController.java
+16
-0
ResourceGanttController.java
...ava/com/aps/controller/gantt/ResourceGanttController.java
+146
-16
Chromosome.java
src/main/java/com/aps/entity/Algorithm/Chromosome.java
+5
-0
TaskVO.java
src/main/java/com/aps/entity/Gantt/TaskVO.java
+4
-4
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+65
-1
SceneService.java
src/main/java/com/aps/service/plan/SceneService.java
+185
-0
No files found.
src/main/java/com/aps/controller/LanuchController.java
View file @
1173674e
package
com
.
aps
.
controller
;
import
com.aps.common.util.R
;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.service.LanuchService
;
import
com.aps.service.plan.PlanResultService
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -16,6 +19,8 @@ public class LanuchController {
@Autowired
private
LanuchService
lanuchService
;
@Autowired
private
PlanResultService
planResultService
;
/**
* 启动工单
*
...
...
@@ -33,4 +38,15 @@ public class LanuchController {
return
lanuchService
.
lanuch
(
sceneName
,
username
);
}
@GetMapping
(
"/schedule"
)
public
Chromosome
schedule
(
@RequestParam
String
sceneID
)
{
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome
scheduleChromosomes
=
planResultService
.
schedule
(
sceneID
);
// 提取所有场景ID
return
scheduleChromosomes
;
}
}
\ No newline at end of file
src/main/java/com/aps/controller/gantt/ResourceGanttController.java
View file @
1173674e
...
...
@@ -2,6 +2,7 @@ package com.aps.controller.gantt;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.entity.Algorithm.GAScheduleResult
;
import
com.aps.entity.basic.ScheduleChromosome
;
import
com.aps.entity.Gantt.ProductGanttVO
;
import
com.aps.entity.Gantt.ResourceGanttVO
;
...
...
@@ -9,6 +10,7 @@ import com.aps.entity.Gantt.TaskVO;
import
com.aps.entity.basic.*
;
import
com.aps.service.plan.PlanResultService
;
import
com.aps.service.plan.PlanSchedulerService
;
import
com.aps.service.plan.SceneService
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
io.swagger.v3.oas.annotations.Operation
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -36,9 +38,11 @@ public class ResourceGanttController {
@Autowired
private
PlanResultService
planResultService
;
@GetMapping
(
"/resourceGantt"
)
@Autowired
private
SceneService
sceneService
;
@GetMapping
(
"/resourceGantt1"
)
@Operation
(
summary
=
"获取资源甘特图数据"
,
description
=
"获取资源甘特图数据"
)
public
List
<
ResourceGanttVO
>
getResourceGantt
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
sceneId
)
{
public
List
<
ResourceGanttVO
>
getResourceGantt
1
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
sceneId
)
{
// 从PlanResultService获取ScheduleChromosome列表
List
<
ScheduleChromosome
>
scheduleChromosomes
=
planResultService
.
execute
();
...
...
@@ -66,7 +70,7 @@ public class ResourceGanttController {
@GetMapping
(
"/productGantt"
)
@Operation
(
summary
=
"获取产品甘特图数据"
,
description
=
"获取产品甘特图数据"
)
public
List
<
ProductGanttVO
>
getProductGantt
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
sceneId
)
{
public
List
<
ProductGanttVO
>
getProductGantt
1
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
sceneId
)
{
// 从PlanResultService获取ScheduleChromosome列表
List
<
ScheduleChromosome
>
scheduleChromosomes
=
planResultService
.
execute
();
...
...
@@ -94,14 +98,21 @@ public class ResourceGanttController {
@GetMapping
(
"/sceneIds"
)
@Operation
(
summary
=
"获取所有场景ID"
,
description
=
"获取所有场景ID"
)
public
List
<
Long
>
getSceneIds
()
{
// 调用 PlanResultService 获取 ScheduleChromosome 列表
List
<
ScheduleChromosome
>
scheduleChromosomes
=
planResultService
.
execute
();
public
List
<
String
>
getSceneIds
()
{
// // 调用 PlanResultService 获取 ScheduleChromosome 列表
// List<ScheduleChromosome> scheduleChromosomes = planResultService.execute();
//
//
//
// // 提取所有场景ID
// return scheduleChromosomes.stream()
// .map(ScheduleChromosome::getSceneId)
// .collect(Collectors.toList());
ArrayList
<
String
>
strings
=
new
ArrayList
<>();
strings
.
add
(
"B571EF6682DB463AB2977B1055A74112"
);
return
strings
;
// 提取所有场景ID
return
scheduleChromosomes
.
stream
()
.
map
(
ScheduleChromosome:
:
getSceneId
)
.
collect
(
Collectors
.
toList
());
}
@GetMapping
(
"/getScene"
)
...
...
@@ -163,10 +174,10 @@ public class ResourceGanttController {
for
(
Gene
gene
:
machineGenes
)
{
TaskVO
taskVO
=
new
TaskVO
();
taskVO
.
setId
(
gene
.
getId
());
// 临时处理
taskVO
.
setPlanId
(
gene
.
getOrderId
(
));
// 默认值
taskVO
.
setPlanId
(
String
.
valueOf
(
gene
.
getOrderId
()
));
// 默认值
taskVO
.
setProductType
(
0
);
// 默认值
taskVO
.
setProductName
(
"产品"
+
gene
.
getProductId
());
taskVO
.
setProductId
(
gene
.
getProductId
(
));
// 默认值
taskVO
.
setProductId
(
String
.
valueOf
(
gene
.
getProductId
()
));
// 默认值
taskVO
.
setQuantity
(
gene
.
getBatchSize
());
taskVO
.
setStart
(
scheduleChromosome
.
getBaseTime
().
plusMinutes
(
gene
.
getAbsoluteStartTime
()));
taskVO
.
setEnd
(
scheduleChromosome
.
getBaseTime
().
plusMinutes
(
gene
.
getAbsoluteEndTime
()));
...
...
@@ -270,10 +281,10 @@ public class ResourceGanttController {
Gene
gene
=
genes
.
get
(
i
);
TaskVO
taskVO
=
new
TaskVO
();
taskVO
.
setId
(
gene
.
getId
());
// 生成唯一ID
taskVO
.
setPlanId
(
orderId
);
taskVO
.
setPlanId
(
String
.
valueOf
(
orderId
)
);
taskVO
.
setProductType
(
0
);
taskVO
.
setProductName
(
"产品"
+
gene
.
getProductId
());
taskVO
.
setProductId
(
gene
.
getProductId
(
));
taskVO
.
setProductId
(
String
.
valueOf
(
gene
.
getProductId
()
));
taskVO
.
setQuantity
(
gene
.
getBatchSize
());
taskVO
.
setStart
(
scheduleChromosome
.
getBaseTime
().
plusMinutes
(
gene
.
getAbsoluteStartTime
()));
taskVO
.
setEnd
(
scheduleChromosome
.
getBaseTime
().
plusMinutes
(
gene
.
getAbsoluteEndTime
()));
...
...
@@ -333,4 +344,123 @@ public class ResourceGanttController {
// 注意:tasks 字段需要在其他地方设置,因为 Machine 类中没有任务信息
return
shiftVO
;
}
@GetMapping
(
"/resourceGantt"
)
@Operation
(
summary
=
"获取资源甘特图数据"
,
description
=
"获取资源甘特图数据"
)
public
List
<
ResourceGanttVO
>
getResourceGantt
(
@RequestParam
String
sceneId
)
{
// 从PlanResultService获取ScheduleChromosome列表
Chromosome
schedule
=
sceneService
.
loadChromosomeFromFile
(
sceneId
);
// 转换为 ResourceGanttVO 格式
List
<
ResourceGanttVO
>
resourceGanttVOList
=
new
ArrayList
<>();
List
<
ResourceGanttVO
>
resourceGanttVOs
=
convertToResourceGanttVO1
(
schedule
);
resourceGanttVOList
.
addAll
(
resourceGanttVOs
);
return
resourceGanttVOList
;
}
private
List
<
ResourceGanttVO
>
convertToResourceGanttVO1
(
Chromosome
scheduleChromosome
)
{
List
<
ResourceGanttVO
>
resourceGanttVOList
=
new
ArrayList
<>();
// 遍历所有机器资源
if
(
scheduleChromosome
.
getMachines
()
!=
null
)
{
for
(
int
i
=
0
;
i
<
scheduleChromosome
.
getMachines
().
size
();
i
++)
{
Machine
machine
=
scheduleChromosome
.
getMachines
().
get
(
i
);
ResourceGanttVO
resourceGanttVO
=
new
ResourceGanttVO
();
resourceGanttVO
.
setId
(
machine
.
getId
());
resourceGanttVO
.
setName
(
machine
.
getId
()+
"号设备"
);
resourceGanttVO
.
setShift
(
convertToVO
(
machine
));
// 转换任务列表
List
<
TaskVO
>
taskVOList
=
new
ArrayList
<>();
if
(
scheduleChromosome
.
getResult
()
!=
null
)
{
// 筛选出属于当前设备的任务
List
<
GAScheduleResult
>
machineGenes
=
scheduleChromosome
.
getResult
().
stream
()
.
filter
(
gene
->
gene
.
getMachineId
()==(
machine
.
getId
()))
.
collect
(
Collectors
.
toList
());
// 按开始时间排序
machineGenes
.
sort
((
g1
,
g2
)
->
Integer
.
compare
(
g1
.
getStartTime
(),
g2
.
getStartTime
()));
for
(
GAScheduleResult
gene
:
machineGenes
)
{
TaskVO
taskVO
=
new
TaskVO
();
// taskVO.setId(gene.getId()); // 临时处理
taskVO
.
setPlanId
(
gene
.
getOrderId
());
// 默认值
// taskVO.setProductType(0); // 默认值
// taskVO.setProductName("产品"+gene.getProductId());
taskVO
.
setProductId
(
gene
.
getProductId
());
// 默认值
taskVO
.
setQuantity
(
gene
.
getQuantity
());
taskVO
.
setStart
(
scheduleChromosome
.
getBaseTime
().
plusSeconds
(
gene
.
getStartTime
()));
taskVO
.
setEnd
(
scheduleChromosome
.
getBaseTime
().
plusSeconds
(
gene
.
getEndTime
()));
taskVO
.
setSetup
(
0
);
// 默认值
taskVO
.
setTeardown
(
gene
.
getTeardownTime
());
// 默认值
taskVO
.
setEquipChange
(
gene
.
getChangeoverTime
());
// 默认值
taskVO
.
setEquipCooling
(
0
);
// 默认值
taskVO
.
setEquipType
(
resourceGanttVO
.
getType
());
taskVO
.
setEquipName
(
resourceGanttVO
.
getName
());
// taskVO.setDuration(calculateDuration(
// scheduleChromosome.getBaseTime().plusMinutes(gene.getStartTime()),
// scheduleChromosome.getBaseTime().plusMinutes(gene.getEndTime()))); // 计算持续时间
taskVO
.
setDuration
(
0
);
//
taskVO
.
setEquipId
(
machine
.
getId
());
taskVO
.
setShopId
(
machine
.
getId
());
taskVO
.
setShopName
(
resourceGanttVO
.
getShopName
());
taskVO
.
setStatus
(
0
);
// 默认值
taskVO
.
setDetailId
((
long
)
gene
.
getStartTime
());
// 将productId和operationID组合为detailId
taskVO
.
setHeaderId
(
gene
.
getEndTime
());
// 默认值
// taskVO.setHeaderName("工艺"+gene.getProductId()); // 默认值
// taskVO.setSeq(gene.getSequenceId()); // 使用工序ID
// taskVO.setSeqName( "工序名称"+gene.getSequenceId());
taskVO
.
setProcessingTime
(
gene
.
getProcessingTime
());
// taskVO.setAbsoluteStart(scheduleChromosome.getBaseTime().plusMinutes(gene.getStartTime()));
// taskVO.setAbsoluteEnd(scheduleChromosome.getBaseTime().plusMinutes(gene.getEndTime()));
taskVOList
.
add
(
taskVO
);
// 调试:检查machine中的shifts状态
// if (machine.getShifts() != null) {
// for (Shift shift : machine.getShifts()) {
// System.out.println("Before setting shifts - Shift status: " + shift.getStatus());
// }
// }
taskVO
.
setAbsolutePreparationTime
(
gene
.
getTeardownTime
());
}
}
resourceGanttVO
.
setList
(
taskVOList
);
resourceGanttVOList
.
add
(
resourceGanttVO
);
}
}
return
resourceGanttVOList
;
}
}
\ No newline at end of file
src/main/java/com/aps/entity/Algorithm/Chromosome.java
View file @
1173674e
...
...
@@ -5,6 +5,7 @@ import com.aps.entity.basic.Machine;
import
com.aps.entity.basic.Order
;
import
lombok.Data
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
...
...
@@ -97,4 +98,8 @@ public class Chromosome {
private
double
DelayTime
;
private
String
ScenarioID
;
private
String
ScenarioName
;
private
LocalDateTime
BaseTime
;
// 当前基准时间
}
src/main/java/com/aps/entity/Gantt/TaskVO.java
View file @
1173674e
...
...
@@ -20,7 +20,7 @@ public class TaskVO {
private
Integer
id
;
@Schema
(
description
=
"计划ID"
)
private
Integer
planId
;
private
String
planId
;
@Schema
(
description
=
"产品类型"
)
private
Integer
productType
;
...
...
@@ -29,10 +29,10 @@ public class TaskVO {
private
String
productName
;
@Schema
(
description
=
"产品ID"
)
private
Integer
productId
;
private
String
productId
;
@Schema
(
description
=
"数量"
)
private
Integer
quantity
;
private
double
quantity
;
@Schema
(
description
=
"开始时间"
)
@JsonFormat
(
timezone
=
"GMT+8"
,
pattern
=
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
)
...
...
@@ -101,7 +101,7 @@ public class TaskVO {
@Schema
(
description
=
"工序名称"
)
private
String
seqName
;
private
int
processingTime
;
// 绝对处理时间(分钟)
private
double
processingTime
;
// 绝对处理时间(分钟)
private
int
absolutePreparationTime
;
// 新增:绝对准备时间
...
...
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
1173674e
...
...
@@ -59,7 +59,8 @@ public class PlanResultService {
@Autowired
private
PlanResourceService
_PlanResourceService
;
@Autowired
private
SceneService
_sceneService
;
@Autowired
private
ProdOrderProcessService
_prodOrderProcessService
;
...
...
@@ -294,6 +295,69 @@ public class PlanResultService {
}
public
Chromosome
schedule
(
String
SceneId
)
{
try
{
ScheduleParams
param
=
new
ScheduleParams
();
param
.
setBaseTime
(
LocalDateTime
.
of
(
2025
,
11
,
1
,
0
,
0
,
0
));
param
.
setPopulationSize
(
50
);
param
.
setMaxIterations
(
100
);
// 1. 读取数据
// List<Machine> machines = loadData("machines.json", Machine.class);
// List<Product> products = loadData("products.json", Product.class);
// List<Order> orders = loadData("orders.json", Order.class);
List
<
ProdEquipment
>
ProdEquipments
=
_prodEquipmentService
.
lambdaQuery
()
.
eq
(
ProdEquipment:
:
getSceneId
,
SceneId
)
.
list
();
List
<
ProdLaunchOrder
>
ProdLaunchOrders
=
_prodLaunchOrderService
.
lambdaQuery
()
.
eq
(
ProdLaunchOrder:
:
getSceneId
,
SceneId
)
.
list
();
// 3. 创建调度服务
MachineSchedulerService
machineScheduler
=
new
MachineSchedulerService
(
param
.
getBaseTime
());
List
<
Machine
>
machines
=
InitCalendarToAllMachines
(
SceneId
,
ProdEquipments
,
machineScheduler
);
// 3. 构建订单-工序数据
List
<
Order
>
orders
=
new
ArrayList
<>();
for
(
ProdLaunchOrder
lo
:
ProdLaunchOrders
)
{
Order
order
=
new
Order
();
order
.
setOrderId
(
lo
.
getOrderId
());
order
.
setMaterialId
(
lo
.
getMaterialId
());
order
.
setDueDate
(
lo
.
getEndDate
());
order
.
setQuantity
(
lo
.
getQuantity
());
orders
.
add
(
order
);
}
List
<
Entry
>
entrys
=
InitEntrys
(
SceneId
,
ProdEquipments
,
ProdLaunchOrders
);
GlobalParam
globalParam
=
new
GlobalParam
();
// 5. 执行调度算法
GeneticAlgorithm
scheduler
=
new
GeneticAlgorithm
(
globalParam
,
machines
,
orders
,
null
,
machineScheduler
);
//new GeneticAlgorithm(products, machines, orders, machineScheduler);
Chromosome
chromosomes
=
scheduler
.
Run
(
param
,
entrys
);
chromosomes
.
setScenarioID
(
SceneId
);
chromosomes
.
setBaseTime
(
param
.
getBaseTime
());
// 保存chromosomes到文件
_sceneService
.
saveChromosomeToFile
(
chromosomes
,
SceneId
);
// Chromosomes.forEach(this::WriteScheduleSummary);
return
chromosomes
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"调度执行失败"
,
e
);
}
}
public
void
WriteScheduleSummary
(
Chromosome
schedule
)
{
// 写入日志
FileHelper
.
writeLogFile
(
String
.
format
(
"\n=== Schedule Summary === %f"
,
schedule
.
getFitness
()));
...
...
src/main/java/com/aps/service/plan/SceneService.java
0 → 100644
View file @
1173674e
package
com
.
aps
.
service
.
plan
;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
org.springframework.stereotype.Service
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
/**
* SceneService.java
*
* @author jdt
* @description 场景保存修改
* @since 2025-12-01
*/
@Service
public
class
SceneService
{
private
static
final
org
.
slf4j
.
Logger
logger
=
org
.
slf4j
.
LoggerFactory
.
getLogger
(
SceneService
.
class
);
// 统一配置 ObjectMapper
private
ObjectMapper
createObjectMapper
()
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
registerModule
(
new
JavaTimeModule
());
objectMapper
.
disable
(
SerializationFeature
.
WRITE_DATES_AS_TIMESTAMPS
);
objectMapper
.
enable
(
SerializationFeature
.
INDENT_OUTPUT
);
// 忽略未知属性,防止反序列化时出错
objectMapper
.
configure
(
com
.
fasterxml
.
jackson
.
databind
.
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
return
objectMapper
;
}
/**
* 获取文件存储目录
*/
private
File
getResultDirectory
()
{
File
resultDir
=
new
File
(
"result"
);
if
(!
resultDir
.
exists
())
{
boolean
created
=
resultDir
.
mkdirs
();
if
(!
created
)
{
logger
.
warn
(
"无法创建结果目录: {}"
,
resultDir
.
getAbsolutePath
());
throw
new
RuntimeException
(
"无法创建结果目录: "
+
resultDir
.
getAbsolutePath
());
}
}
return
resultDir
;
}
/**
* 获取文件路径
*/
private
File
getChromosomeFile
(
String
sceneId
)
{
File
resultDir
=
getResultDirectory
();
String
fileName
=
"chromosome_result_"
+
sceneId
+
".json"
;
return
new
File
(
resultDir
,
fileName
);
}
/**
* 从文件中读取Chromosome对象
*/
public
Chromosome
loadChromosomeFromFile
(
String
sceneId
)
{
if
(
sceneId
==
null
||
sceneId
.
trim
().
isEmpty
())
{
logger
.
warn
(
"场景ID不能为空"
);
return
null
;
}
try
{
ObjectMapper
objectMapper
=
createObjectMapper
();
File
file
=
getChromosomeFile
(
sceneId
);
if
(!
file
.
exists
())
{
logger
.
warn
(
"染色体文件不存在: {}"
,
file
.
getAbsolutePath
());
return
null
;
}
if
(
file
.
length
()
==
0
)
{
logger
.
warn
(
"染色体文件为空: {}"
,
file
.
getAbsolutePath
());
return
null
;
}
logger
.
info
(
"正在从文件加载染色体: {}"
,
file
.
getAbsolutePath
());
Chromosome
chromosome
=
objectMapper
.
readValue
(
file
,
Chromosome
.
class
);
logger
.
info
(
"染色体加载成功,场景ID: {}"
,
sceneId
);
return
chromosome
;
}
catch
(
Exception
e
)
{
// 正确的错误日志写法
logger
.
error
(
"加载染色体文件失败,场景ID: "
+
sceneId
,
e
);
throw
new
RuntimeException
(
"加载染色体文件失败: "
+
e
.
getMessage
(),
e
);
}
}
/**
* 将染色体结果保存到JSON文件
*/
public
boolean
saveChromosomeToFile
(
Chromosome
chromosome
,
String
sceneId
)
{
if
(
chromosome
==
null
)
{
logger
.
warn
(
"染色体对象不能为空"
);
return
false
;
}
if
(
sceneId
==
null
||
sceneId
.
trim
().
isEmpty
())
{
logger
.
warn
(
"场景ID不能为空"
);
return
false
;
}
try
{
ObjectMapper
objectMapper
=
createObjectMapper
();
File
file
=
getChromosomeFile
(
sceneId
);
File
tempFile
=
new
File
(
file
.
getParentFile
(),
file
.
getName
()
+
".tmp"
);
objectMapper
.
writeValue
(
tempFile
,
chromosome
);
if
(
tempFile
.
length
()
==
0
)
{
logger
.
error
(
"写入的临时文件为空: {}"
,
tempFile
.
getAbsolutePath
());
Files
.
deleteIfExists
(
tempFile
.
toPath
());
return
false
;
}
// 验证文件内容
try
{
Chromosome
verifyChromosome
=
objectMapper
.
readValue
(
tempFile
,
Chromosome
.
class
);
if
(
verifyChromosome
==
null
)
{
throw
new
IOException
(
"验证读取失败"
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"验证染色体文件内容失败,文件: {}"
,
tempFile
.
getAbsolutePath
(),
e
);
Files
.
deleteIfExists
(
tempFile
.
toPath
());
return
false
;
}
// 替换原文件
if
(
file
.
exists
())
{
Files
.
deleteIfExists
(
file
.
toPath
());
}
Files
.
move
(
tempFile
.
toPath
(),
file
.
toPath
());
logger
.
info
(
"染色体保存成功,场景ID: {}, 文件: {}"
,
sceneId
,
file
.
getAbsolutePath
());
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"保存染色体文件失败,场景ID: "
+
sceneId
,
e
);
return
false
;
}
}
/**
* 检查染色体文件是否存在
*/
public
boolean
chromosomeFileExists
(
String
sceneId
)
{
if
(
sceneId
==
null
||
sceneId
.
trim
().
isEmpty
())
{
return
false
;
}
File
file
=
getChromosomeFile
(
sceneId
);
return
file
.
exists
()
&&
file
.
length
()
>
0
;
}
/**
* 删除染色体文件
*/
public
boolean
deleteChromosomeFile
(
String
sceneId
)
{
try
{
File
file
=
getChromosomeFile
(
sceneId
);
if
(
file
.
exists
())
{
boolean
deleted
=
Files
.
deleteIfExists
(
file
.
toPath
());
if
(
deleted
)
{
logger
.
info
(
"删除染色体文件成功: {}"
,
file
.
getAbsolutePath
());
}
return
deleted
;
}
return
true
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"删除染色体文件失败,场景ID: "
+
sceneId
,
e
);
return
false
;
}
}
}
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