取消固定日期

parent d209cd62
......@@ -170,7 +170,7 @@ public class ChromosomeDataController {
if (entityName.equalsIgnoreCase("machine")){
return updateMachineOption(sceneId, taskId, data);
return chromosomeDataService.updateMachineOption(sceneId, taskId, data);
}
......@@ -181,148 +181,6 @@ public class ChromosomeDataController {
}
private R<String> updateMachineOption(String sceneId, String taskId, Map<String, Object> data) {
// 1. 加载Chromosome对象
Chromosome chromosome = sceneService.loadChromosomeFromFile(sceneId);
// 2. 根据taskId找到对应的entry
Entry targetEntry = null;
for (Entry entry : chromosome.getAllOperations()) {
if (String.valueOf(entry.getId()).equals(taskId)) {
targetEntry = entry;
break;
}
}
Long machineId = null;
Object machineIdObj = data.get("machineId");
if (machineIdObj instanceof Long) {
machineId = (Long) machineIdObj;
} else if (machineIdObj instanceof Integer) {
machineId = ((Integer) machineIdObj).longValue();
} else if (machineIdObj instanceof String) {
machineId = Long.parseLong((String) machineIdObj);
}
// 4. 在entry的machineOptions列表中找到对应的machineOption
MachineOption targetMachineOption = null;
for (MachineOption machineOption : targetEntry.getMachineOptions()) {
if (machineOption.getMachineId().equals(machineId)) {
targetMachineOption = machineOption;
break;
}
}
// 5. 只更新传入的字段,保留原有字段值
updateMachineOptionFields(targetMachineOption, data);
// 6. 调用editMachine方法
planResultService.editMachine(chromosome, sceneId, targetEntry);
// 7. 保存更新后的Chromosome
boolean saved = sceneService.saveChromosomeToFile(chromosome, sceneId);
return R.ok("更新成功");
}
/**
* 只更新MachineOption的传入字段,保留原有字段值
*/
private void updateMachineOptionFields(MachineOption machineOption, Map<String, Object> data) {
// 处理runtime字段
if (data.containsKey("runtime")) {
Object runtimeObj = data.get("runtime");
if (runtimeObj instanceof Integer) {
machineOption.setRuntime(new BigDecimal((Integer) runtimeObj));
} else if (runtimeObj instanceof Long) {
machineOption.setRuntime(new BigDecimal((Long) runtimeObj));
} else if (runtimeObj instanceof Double) {
machineOption.setRuntime(new BigDecimal((Double) runtimeObj));
} else if (runtimeObj instanceof String) {
machineOption.setRuntime(new BigDecimal((String) runtimeObj));
}
}
// 处理singleOut字段
if (data.containsKey("singleOut")) {
Object singleOutObj = data.get("singleOut");
if (singleOutObj instanceof Integer) {
machineOption.setSingleOut(new BigDecimal((Integer) singleOutObj));
} else if (singleOutObj instanceof Long) {
machineOption.setSingleOut(new BigDecimal((Long) singleOutObj));
} else if (singleOutObj instanceof Double) {
machineOption.setSingleOut(new BigDecimal((Double) singleOutObj));
} else if (singleOutObj instanceof String) {
machineOption.setSingleOut(new BigDecimal((String) singleOutObj));
}
}
// 处理preTime字段
if (data.containsKey("preTime")) {
Object preTimeObj = data.get("preTime");
if (preTimeObj instanceof Integer) {
machineOption.setPreTime((Integer) preTimeObj);
} else if (preTimeObj instanceof Long) {
machineOption.setPreTime(((Long) preTimeObj).intValue());
} else if (preTimeObj instanceof String) {
machineOption.setPreTime(Integer.parseInt((String) preTimeObj));
}
}
// 处理processingTime字段 - 修改为:时间(runtime) ÷ 数量(singleOut)
if (data.containsKey("processingTime") || data.containsKey("singleOut") || data.containsKey("runtime")) {
// 1. 获取singleOut值
BigDecimal singleOut = machineOption.getSingleOut();
if (data.containsKey("singleOut")) {
Object singleOutObj = data.get("singleOut");
if (singleOutObj instanceof Integer) {
singleOut = new BigDecimal((Integer) singleOutObj);
} else if (singleOutObj instanceof Long) {
singleOut = new BigDecimal((Long) singleOutObj);
} else if (singleOutObj instanceof Double) {
singleOut = new BigDecimal((Double) singleOutObj);
} else if (singleOutObj instanceof String) {
singleOut = new BigDecimal((String) singleOutObj);
} else if (singleOutObj instanceof BigDecimal) {
singleOut = (BigDecimal) singleOutObj;
}
}
// 2. 获取runtime值
BigDecimal runtime = machineOption.getRuntime();
if (data.containsKey("runtime")) {
Object runtimeObj = data.get("runtime");
if (runtimeObj instanceof Integer) {
runtime = new BigDecimal((Integer) runtimeObj);
} else if (runtimeObj instanceof Long) {
runtime = new BigDecimal((Long) runtimeObj);
} else if (runtimeObj instanceof Double) {
runtime = new BigDecimal((Double) runtimeObj);
} else if (runtimeObj instanceof String) {
runtime = new BigDecimal((String) runtimeObj);
} else if (runtimeObj instanceof BigDecimal) {
runtime = (BigDecimal) runtimeObj;
}
}
// 3. 计算processingTime = runtime ÷ singleOut(时间 ÷ 数量)
double processingTime = 0.0;
if (singleOut != null && runtime != null && runtime.compareTo(BigDecimal.ZERO) != 0) {
// 考虑runtime单位转换:如果runtime是毫秒,转换为秒
BigDecimal runtimeSeconds = runtime.divide(new BigDecimal(1000), 6, RoundingMode.HALF_UP);
// 关键修改:时间(秒) ÷ 数量,保留2位小数
processingTime = runtimeSeconds.divide(singleOut, 2, RoundingMode.HALF_UP).doubleValue();
}
// 4. 设置计算后的processingTime
machineOption.setProcessingTime(processingTime);
}
//
......@@ -373,7 +231,7 @@ public class ChromosomeDataController {
// }
// 忽略id等未知字段
}
private boolean updateMachineOptionsForEntry(Entry targetEntry, List<?> machineOptions, ObjectMapper objectMapper) {
......
......@@ -2,11 +2,9 @@ package com.aps.controller.gantt;
import cn.hutool.core.bean.BeanUtil;
import com.aps.common.util.NumberUtils;
import com.aps.common.util.ParamValidator;
import com.aps.common.util.R;
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;
......@@ -23,8 +21,7 @@ import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -44,6 +41,9 @@ public class ResourceGanttController {
@Autowired
private SceneService sceneService;
@GetMapping("/resourceGantt1")
@Operation(summary = "获取资源甘特图数据", description = "获取资源甘特图数据")
public List<ResourceGanttVO> getResourceGantt1(@RequestParam(required = false, defaultValue = "1") Long sceneId) {
......@@ -578,7 +578,7 @@ public class ResourceGanttController {
taskVO.setStart(scheduleChromosome.getBaseTime().plusMinutes(gene.getAbsoluteStartTime()));
taskVO.setEnd(scheduleChromosome.getBaseTime().plusMinutes(gene.getAbsoluteEndTime()));
taskVO.setSetup(gene.getAbsolutePreparationTime()*60); // 默认值
taskVO.setTeardown(gene.getAbsoluteTeardownTime()*60); // 默认
taskVO.setTeardown(gene.getAbsoluteTeardownTime()*60); // 默认
taskVO.setEquipChange(gene.getSetupTime()*60); // 默认값
taskVO.setEquipCooling(0); // 默认值
// taskVO.setEquipType("PTT-" + (i+1) + "-" + gene.getOperationName().toUpperCase().substring(0, Math.min(3, gene.getOperationName().length())));
......@@ -638,194 +638,6 @@ public class ResourceGanttController {
private List<ResourceGanttVO> convertToResourceGanttVO1(Chromosome scheduleChromosome) {
List<ResourceGanttVO> resourceGanttVOList = new ArrayList<>();
List<Machine> machineList = planResultService.InitCalendarToAllMachines1(scheduleChromosome.getScenarioID());
// 遍历所有机器资源
if (machineList != null) {
for (int i = 0; i < machineList.size(); i++) {
Machine machine = machineList.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.setEquipCode(machine.getCode());
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;
}
/**
* 将 ScheduleChromosome 转换为 ProductGanttVO 列表
* @param scheduleChromosome 调度结果
* @return 转换后的数据
*/
private List<ProductGanttVO> convertToProductGanttVO1(Chromosome scheduleChromosome) {
List<ProductGanttVO> productGanttVOList = new ArrayList<>();
// 按产品ID和工单ID分组基因
if (scheduleChromosome.getResult() != null) {
// 按工单ID分组
scheduleChromosome.getResult().stream()
.collect(Collectors.groupingBy(GAScheduleResult::getOrderId))
.forEach((orderId, genes) -> {
if (!genes.isEmpty()) {
ProductGanttVO productGanttVO = new ProductGanttVO();
GAScheduleResult firstGene = genes.get(0);
productGanttVO.setId(firstGene.getOrderId());
productGanttVO.setProductName("产品"+firstGene.getProductId()); // 默认值,实际应从订单数据获取
productGanttVO.setProductType(0);
productGanttVO.setProductId(firstGene.getProductId());
// 计算总数量(假设同一批次)
productGanttVO.setQuantity(firstGene.getQuantity());
productGanttVO.setCode("编号"+firstGene.getProductId()); // 默认值
productGanttVO.setShopId(firstGene.getMachineId()); // 默认值
productGanttVO.setShopName(firstGene.getMachineId()+"号线"); // 默认值
productGanttVO.setStatus("已发布");
// productGanttVO.setHeaderId(firstGene.getProductId());
productGanttVO.setHeaderName("工艺"+firstGene.getProductId()); // 默认值
// 计算开始和结束时间
int minStartTime = genes.stream()
.mapToInt(GAScheduleResult::getStartTime)
.min()
.orElse(0);
int maxEndTime = genes.stream()
.mapToInt(GAScheduleResult::getEndTime)
.max()
.orElse(0);
productGanttVO.setStartDate(scheduleChromosome.getBaseTime().plusMinutes(minStartTime));
productGanttVO.setEndDate(scheduleChromosome.getBaseTime().plusMinutes(maxEndTime));
// 转换任务列表
List<TaskVO> taskVOList = new ArrayList<>();
// // 按工序顺序排序
// genes.sort((g1, g2) -> Integer.compare(g1.getSequenceId(), g2.getSequenceId()));
for (int i = 0; i < genes.size(); i++) {
GAScheduleResult gene = genes.get(i);
TaskVO taskVO = new TaskVO();
taskVO.setId(gene.getOrderId()); // 生成唯一ID
taskVO.setPlanId(String.valueOf(orderId));
taskVO.setProductType(0);
taskVO.setProductName("产品"+gene.getProductId());
taskVO.setProductId(String.valueOf(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("PTT-" + (i+1) + "-" + gene.getOperationName().toUpperCase().substring(0, Math.min(3, gene.getOperationName().length())));
// taskVO.setEquipName(gene.getOperationName());
taskVO.setDuration(calculateDuration(
scheduleChromosome.getBaseTime().plusMinutes(gene.getStartTime()),
scheduleChromosome.getBaseTime().plusMinutes(gene.getEndTime())));
taskVO.setEquipId(gene.getMachineId()); // 生成设备ID
taskVO.setShopId(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.setSeq(gene.getSequenceId());
// taskVO.setSeqName("工序名称"+gene.getSequenceId());
// taskVO.setAbsoluteStart(scheduleChromosome.getBaseTime().plusMinutes(gene.getStartTime()));
// taskVO.setAbsoluteEnd(scheduleChromosome.getBaseTime().plusMinutes(gene.getEndTime()));
taskVOList.add(taskVO);
}
productGanttVO.setList(taskVOList);
productGanttVOList.add(productGanttVO);
}
});
}
return productGanttVOList;
}
@GetMapping("/productGantt")
@Operation(summary = "获取资源甘特图数据", description = "获取资源甘特图数据")
public List<ProductGanttVO> productGantt(@RequestParam String sceneId) {
......@@ -952,4 +764,35 @@ public class ResourceGanttController {
return R.ok(numbers);
}
@PostMapping("/unFixStartDate")
@Operation(summary = "取消固定开始日期", description = "取消固定开始日期",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "取消固定开始日期参数",
content = @io.swagger.v3.oas.annotations.media.Content(
mediaType = "application/json",
examples = @io.swagger.v3.oas.annotations.media.ExampleObject(
name = "取消固定开始日期示例",
value = "{\n \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n \"id\": 123\n}"
)
)
)
)
public R<String> unFixStartDate(@RequestBody Map<String, Object> params) {
// 1. 提取参数
String sceneId = ParamValidator.getString(params, "sceneId", "场景ID");
Integer opid = ParamValidator.getInteger(params, "id", "操作ID");
// 2. 验证场景
ParamValidator.validateSceneExists(sceneService, sceneId);
planResultService.UnlockStartTime(sceneId, opid);
return R.ok("取消固定开始日期成功");
}
}
\ No newline at end of file
......@@ -473,7 +473,11 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
public void UnlockStartTime(String sceneId, int opId) {
Chromosome chromosome = _sceneService.loadChromosomeFromFile(sceneId);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperation.UnlockStartTime(chromosome, opId);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment