工序操作修改

parent 7c8ef9a1
......@@ -137,14 +137,14 @@ public class SwaggerMapParamConfig {
case "operationMove":
properties.put("SceneId", new StringSchema().description("场景ID").example("B571EF6682DB463AB2977B1055A74112"));
properties.put("opid", new StringSchema().description("操作ID").example(1));
properties.put("id", new StringSchema().description("操作ID").example(1));
properties.put("newStartTime", new StringSchema().description("新的开始时间").example("2025-11-03T07:36:00.000Z"));
properties.put("newMachineId", new StringSchema().description("新机器ID").example(3402));
examples.put("移动操作示例", createExample(
"将指定操作移动到新的时间和机器上",
"{\n" +
" \"SceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"opid\": 1,\n" +
" \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"id\": 1,\n" +
" \"newStartTime\": \"2025-11-03T07:36:00.000Z\",\n" +
" \"newMachineId\": 3402\n" +
"}"
......@@ -157,33 +157,33 @@ public class SwaggerMapParamConfig {
examples.put("编辑操作示例", createExample(
"编辑指定的操作",
"{\n" +
" \"SceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"operation\": {}\n" +
"}"
));
break;
case "changebasetime":
properties.put("SceneId", new StringSchema().description("场景ID").example("B571EF6682DB463AB2977B1055A74112"));
properties.put("BaseTime", new StringSchema().description("基础时间").example("2025-11-03T07:36:00.000Z"));
properties.put("sceneId", new StringSchema().description("场景ID").example("B571EF6682DB463AB2977B1055A74112"));
properties.put("baseTime", new StringSchema().description("基础时间").example("2025-11-03T07:36:00.000Z"));
examples.put("更改基准时间示例", createExample(
"更改场景的基准时间",
"{\n" +
" \"SceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"BaseTime\": \"2025-11-03T07:36:00.000Z\"\n" +
" \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"baseTime\": \"2025-11-03T07:36:00.000Z\"\n" +
"}"
));
break;
case "spiltOperation":
properties.put("sceneId", new StringSchema().description("场景ID").example("B571EF6682DB463AB2977B1055A74112"));
properties.put("opid", new StringSchema().description("操作ID").example(1));
properties.put("id", new StringSchema().description("操作ID").example(1));
properties.put("splitCounts", new StringSchema().description("拆分数量数组").example("[20000.0, 30000.0]"));
examples.put("拆分操作示例", createExample(
"按指定数量拆分操作",
"{\n" +
" \"SceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"opid\": 2,\n" +
" \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"id\": 2,\n" +
" \"splitCounts\": [20000, 30000]\n" +
"}"
));
......@@ -191,26 +191,26 @@ public class SwaggerMapParamConfig {
case "delOperation":
properties.put("sceneId", new StringSchema().description("场景ID").example("B571EF6682DB463AB2977B1055A74112"));
properties.put("opid", new StringSchema().description("操作ID").example(1));
properties.put("id", new StringSchema().description("操作ID").example(1));
examples.put("删除操作示例", createExample(
"删除指定操作",
"{\n" +
" \"SceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"opid\": 1\n" +
" \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"id\": 1\n" +
"}"
));
break;
case "lockedOperation":
properties.put("sceneId", new StringSchema().description("场景ID").example("B571EF6682DB463AB2977B1055A74112"));
properties.put("opid", new StringSchema().description("操作ID").example(1));
properties.put("isLocked", new StringSchema().description("是否锁定").example(true));
properties.put("id", new StringSchema().description("操作ID").example(1));
properties.put("locked", new StringSchema().description("是否锁定").example(true));
examples.put("锁定操作示例", createExample(
"锁定或解锁指定操作",
"{\n" +
" \"SceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"opid\": 1,\n" +
" \"isLocked\": true\n" +
" \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"id\": 1,\n" +
" \"locked\": true\n" +
"}"
));
break;
......@@ -222,7 +222,7 @@ public class SwaggerMapParamConfig {
examples.put("拆分订单示例", createExample(
"按指定数量拆分订单",
"{\n" +
" \"SceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"sceneId\": \"B571EF6682DB463AB2977B1055A74112\",\n" +
" \"orderid\": \"fcc0892a-0483-4da7-8414-9ce98be36e53\",\n" +
" \"splitCounts\": [20000, 20000, 10000]\n" +
"}"
......
......@@ -139,11 +139,12 @@ public class ResourceGanttController {
}
@PostMapping("/operationMove")
@Operation(summary = "操作移动", description = "操作移动")
public R<Chromosome> operationMove(@RequestBody Map<String, Object> params) {
// 1. 提取参数
String sceneId = ParamValidator.getString(params, "sceneId", "场景ID");
Integer opid = ParamValidator.getInteger(params, "operationid", "操作ID");
Integer opid = ParamValidator.getInteger(params, "id", "操作ID");
LocalDateTime newStartTime = ParamValidator.getDateTime(params, "newStartTime", "新的开始时间");
Long newMachineId = ParamValidator.getLong(params, "newMachineId", "新机器ID");
......@@ -157,6 +158,7 @@ public class ResourceGanttController {
}
@PostMapping("/operationedit")
@Operation(summary = "修改工单", description = "修改工单")
public R<Chromosome> operationedit(@RequestBody Map<String, Object> params) {
log.info("operationedit 请求参数: {}", params);
......@@ -172,6 +174,7 @@ public class ResourceGanttController {
}
@PostMapping("/changebasetime")
@Operation(summary = "修改基础时间", description = "修改基础时间")
public R<Chromosome> changeBaseTime(@RequestBody Map<String, Object> params) {
log.info("changeBaseTime 请求参数: {}", params);
......@@ -184,11 +187,12 @@ public class ResourceGanttController {
}
@PostMapping("/operationspilt")
@Operation(summary = "工单拆分", description = "工单拆分")
public R<Chromosome> spiltOperation(@RequestBody Map<String, Object> params) {
log.info("spiltOperation 请求参数: {}", params);
String sceneId = ParamValidator.getString(params, "sceneId", "场景ID");
Integer opid = ParamValidator.getInteger(params, "opid", "操作ID");
Integer opid = ParamValidator.getInteger(params, "id", "操作ID");
List<?> splitCounts = ParamValidator.getList(params, "splitCounts", "拆分数量");
// 类型转换
......@@ -200,11 +204,12 @@ public class ResourceGanttController {
}
@PostMapping("/operationdel")
@Operation(summary = "删除工单", description = "删除工单")
public R<Chromosome> delOperation(@RequestBody Map<String, Object> params) {
log.info("delOperation 请求参数: {}", params);
String sceneId = ParamValidator.getString(params, "sceneId", "场景ID");
Integer opid = ParamValidator.getInteger(params, "opid", "操作ID");
Integer opid = ParamValidator.getInteger(params, "id", "操作ID");
ParamValidator.validateSceneExists(sceneService, sceneId);
Chromosome result = planResultService.DelOperation(sceneId, opid);
......@@ -212,12 +217,13 @@ public class ResourceGanttController {
}
@PostMapping("/operationlocked")
@Operation(summary = "工单锁定", description = "订工单锁定")
public R<Chromosome> lockedOperation(@RequestBody Map<String, Object> params) {
log.info("lockedOperation 请求参数: {}", params);
String sceneId = ParamValidator.getString(params, "sceneId", "场景ID");
Integer opid = ParamValidator.getInteger(params, "opid", "操作ID");
Boolean isLocked = ParamValidator.getBoolean(params, "isLocked", "锁定状态");
Integer opid = ParamValidator.getInteger(params, "id", "操作ID");
Boolean isLocked = ParamValidator.getBoolean(params, "locked", "锁定状态");
ParamValidator.validateSceneExists(sceneService, sceneId);
Chromosome result = planResultService.LockOperation(sceneId, opid, isLocked);
......@@ -225,6 +231,7 @@ public class ResourceGanttController {
}
@PostMapping("/orderspilt")
@Operation(summary = "订单拆分", description = "订单拆分")
public R<Chromosome> spiltOrder(@RequestBody Map<String, Object> params) {
log.info("spiltOrder 请求参数: {}", params);
......@@ -240,6 +247,7 @@ public class ResourceGanttController {
}
@PostMapping("/ordermerge")
@Operation(summary = "订单合并", description = "订单合并")
public R<Chromosome> orderMerge(@RequestBody Map<String, Object> params) {
log.info("orderMerge 请求参数: {}", params);
......@@ -711,7 +719,7 @@ public class ResourceGanttController {
return new ArrayList<>();
}
List<Machine> machineList = planResultService.InitCalendarToAllMachines1(schedule.getScenarioID());
List<Machine> machineList = planResultService.InitCalendarToAllMachines1(sceneId);
// 转换为 ResourceGanttVO 格式
List<ResourceGanttVO> resourceGanttVOList = new ArrayList<>();
......@@ -747,6 +755,7 @@ public class ResourceGanttController {
List<ResourceGanttVO> resourceGanttVOs = planResultService.convertToResourceGanttVO1(schedule, machineList);
resourceGanttVOList.addAll(resourceGanttVOs);
System.out.println("完成甘特图请求");
return R.ok(resourceGanttVOList);
}
......
......@@ -49,4 +49,6 @@ public class ResourceGanttVO {
private ShiftVO shift;
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
......@@ -105,7 +106,8 @@ public class TaskVO {
private int absolutePreparationTime; // 新增:绝对准备时间
@Schema(description = "锁定状态")
private boolean locked; // 改为小写开头
}
\ No newline at end of file
......@@ -58,4 +58,7 @@ public class RoutingDetail {
private String singleOutUnitName;
private Long connectUnitId;
private String connectUnitName;
private BigDecimal incrementQty;
}
\ No newline at end of file
......@@ -78,4 +78,9 @@ public class MachineTimeline {
public int hashCode() {
return Objects.hash(machineId);
}
// 处理维护窗口
}
\ No newline at end of file
......@@ -218,7 +218,7 @@ public class MaterialRequirementService {
LanuchServiceImpl lanuchService=new LanuchServiceImpl();
List<RoutingDetail> RoutingDetails= lanuchService.getRoutingDetails(routingIds);
List<RoutingDetailEquip> routingDetailEquips = lanuchService.getRoutingDetailEquip(routingIds);
List<RoutingDetailEquip> routingDetailEquips = lanuchService.getRoutingDetailEquip(routingIds,headers1.getCode());
ProdLaunchOrder prodOrderMain= convertToLaunchOrder(order,"");
......
......@@ -286,6 +286,17 @@ public class ScheduleOperationService {
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Order not found: " + orderId));
double sum = Arrays.stream(splitCounts)
.filter(Objects::nonNull)
.mapToDouble(Double::doubleValue)
.sum();
if(sum!=order.getQuantity()){
throw new RuntimeException("订单数量拆分不正确");
}
int maxorderId =OperatRels.size() ;
int maxgroupId =maxorderId ;
......
......@@ -86,7 +86,7 @@ public class LanuchServiceImpl implements LanuchService {
*/
@Override
@Transactional(rollbackFor = Exception.class)
public R<String> lanuch( String sceneName, String username) {
public R<String> lanuch(String sceneName, String username) {
// 参数校验
if (sceneName == null || sceneName.trim().isEmpty()) {
throw new IllegalArgumentException("场景名称不能为空");
......@@ -96,8 +96,10 @@ public class LanuchServiceImpl implements LanuchService {
throw new IllegalArgumentException("用户ID不能为空");
}
String sceneId = null;
try {
// 1. 创建场景
String sceneId = createScene(sceneName, username);
sceneId = createScene(sceneName, username);
if (sceneId == null) {
throw new RuntimeException("场景名称已存在");
}
......@@ -107,13 +109,13 @@ public class LanuchServiceImpl implements LanuchService {
List<ApsOrder> apsOrders = apsOrderService.lambdaQuery()
.eq(ApsOrder::getIsdeleted, 0)
.eq(ApsOrder::getSchedulestatus, 1)
.eq(ApsOrder::getCreatoruserid,username)
.eq(ApsOrder::getCreatoruserid, username)
.list();
if (CollectionUtils.isEmpty(apsOrders)) {
prodSceneConfigService.deleteSceneById(sceneId);
throw new SceneGenerationException("工单列表不能为空");
}
// 4. 处理订单数据转换
// 4. 处理工单数据转换
List<ProdLaunchOrder> prodLaunchOrders = processOrderData(sceneId, apsOrders);
// 5. 转换工单于工序执行表
......@@ -124,7 +126,14 @@ public class LanuchServiceImpl implements LanuchService {
log.info("场景数据生成完成,场景ID:{}", sceneId);
return R.ok("场景数据生成成功");
} catch (Exception e) {
// 发生任何异常都应回滚事务
// 如果sceneId已经创建但在事务完成前发生异常,则事务回滚会自动清理数据
log.error("场景生成过程中发生异常,事务将回滚", e);
throw e; // 重新抛出异常以触发事务回滚
}
}
/**
*复制数据
......@@ -516,7 +525,7 @@ public class LanuchServiceImpl implements LanuchService {
// 查询该工艺下的所有工序
List<RoutingDetail> routingDetails = getRoutingDetails(routingHeader.getId());
List<RoutingDetailEquip> routingDetailEquip = getRoutingDetailEquip(routingHeader.getId());
List<RoutingDetailEquip> routingDetailEquip = getRoutingDetailEquip(routingHeader.getId(),routingHeader.getCode());
// 批量插入新的工序工单记录
batchInsertProcessExec(prodOrderMain, routingDetails, sceneId,routingDetailEquip);
......@@ -908,7 +917,7 @@ public class LanuchServiceImpl implements LanuchService {
◦ @return 工序列表
*/
public List<RoutingDetailEquip> getRoutingDetailEquip(Integer routingHeaderId) {
public List<RoutingDetailEquip> getRoutingDetailEquip(Integer routingHeaderId,String routingCode) {
List<RoutingDetailEquip> detailEquips = routingDetailEquipService.lambdaQuery()
.eq(RoutingDetailEquip::getRoutingHeaderId, routingHeaderId)
.eq(RoutingDetailEquip::getIsdeleted, 0)
......@@ -916,7 +925,7 @@ public class LanuchServiceImpl implements LanuchService {
if (CollectionUtils.isEmpty(detailEquips)) {
log.error("工艺下无设备信息: {}", routingHeaderId);
throw new RuntimeException("工艺下无设备信息: " + routingHeaderId);
throw new RuntimeException("工艺下无设备信息: " + routingCode);
}
return detailEquips;
......
......@@ -290,7 +290,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
ScheduleParams param = new ScheduleParams();
param.setBaseTime(LocalDateTime.of(2025, 11, 1, 0, 0, 0));
System.out.println("开始调度");
// 1. 读取数据
// List<Machine> machines = loadData("machines.json", Machine.class);
......@@ -419,6 +419,21 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
List<GAScheduleResult> result = chromosome.getResult();
GAScheduleResult gaScheduleResult = result.stream()
.filter(r -> r.getOperationId() == opId).findFirst().orElse(null);
double sum = Arrays.stream(splitCounts)
.filter(Objects::nonNull)
.mapToDouble(Double::doubleValue)
.sum();
if (gaScheduleResult.getQuantity() != sum) {
throw new RuntimeException("拆分数量不正确");
}
ScheduleOperation.SpiltOperation(chromosome,opId,splitCounts, globalParam);
WriteScheduleSummary(chromosome);
......@@ -1129,6 +1144,27 @@ private GlobalParam InitGlobalParam()
}
}
// List<PlanResource> PlanResources1 = PlanResources.stream()
// .filter(t -> t.getReferenceId() == machine.getId())
// .collect(Collectors.toList());
// if(PlanResources1!=null&&PlanResources1.size()>0)
// {
// for (PlanResource PlanResource : PlanResources1) {
//
// List<MesShiftWorkSched> ShiftWorkScheds = MesShiftWorkScheds.stream()
// .filter(t -> (long) t.getWeekWorkSchedId() == PlanResource.getWorkSchedId())
// .collect(Collectors.toList());
// List<Shift> Shifts = mergeShiftData(ShiftWorkScheds);
// for (Shift shift : Shifts) {
//
// shift.setMachineId(machine.getId());
// shift.setStartDate(LocalDateTime.of(2000, 1, 1, 0, 0, 0));
// shift.setEndDate(LocalDateTime.of(2000, 1, 1, 0, 0, 0));
// shifts1.add(shift);
// }
// }
//
// }
......@@ -1241,7 +1277,7 @@ private GlobalParam InitGlobalParam()
taskVO.setEquipCooling(0); // 默认值
taskVO.setEquipType(resourceGanttVO.getType());
taskVO.setEquipName(resourceGanttVO.getName());
taskVO.setLocked(gene.isIsLocked()); // 默认值
if (entry != null) {
taskVO.setSeq(Math.toIntExact(entry.getTaskSeq())); // 使用工序ID
taskVO.setSeqName(entry.getRoutingDetailName());
......
......@@ -40,6 +40,7 @@
<result column="CONNECT_TYPE_NAME" property="connectTypeName" />
<result column="CONNECT_PROPERTY_NAME" property="connectPropertyName" />
<result column="CONST_TIME" property="constTime" />
<result column="INCREMENT_QTY" property="incrementQty" />
<result column="BATCH_QTY" property="batchQty" />
<result column="MIN_PRODUCTION_QTY" property="minProductionQty" />
<result column="MAX_PRODUCTION_QTY" property="maxProductionQty" />
......@@ -58,7 +59,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
ID, CREATION_TIME, CREATOR_USER_ID, LAST_MODIFICATION_TIME, LAST_MODIFIER_USER_ID, IS_DELETED, DELETER_USER_ID, DELETION_TIME, ROUTING_HEADER_ID, NAME, TASK_SEQ, RUNTIME, SETUP_TIME, EFFICIENCY_VALUE, SINGLE_OUT, IS_OUTSIDE, STATUS, REMARK, EXTEND, OUTSIDE_TIME, PERFORMANCE_HOURS, SCHEDULING_WORKING_HOURS, REAL_WORKING_HOURS, REAL_RUNTIME, PERFORMANCE_WORKING_HOURS, EQUIP_TYPE, EQUIP_TYPE_ID, CAN_INTERRUPT, PREVIOUS_START_TIME_BEGIN, CHANGE_LINE_TIME, PRE_DETAIL_ID, CONNECT_TYPE, CONNECT_PROPERTY, CONNECT_TYPE_NAME, CONNECT_PROPERTY_NAME, CONST_TIME, BATCH_QTY, MIN_PRODUCTION_QTY, MAX_PRODUCTION_QTY, PRODUCTION_TAKT, PREPROCESSING_TIME, POSTPROCESSING_TIME, SPLIT_MIN_QTY, SPLIT_MAX_QTY, EQUIPMENT_CONNECTIVITY, SINGLE_OUT_UNIT_ID, SINGLE_OUT_UNIT_NAME, CONNECT_UNIT_ID, CONNECT_UNIT_NAME
ID, CREATION_TIME, CREATOR_USER_ID, LAST_MODIFICATION_TIME, LAST_MODIFIER_USER_ID, IS_DELETED, DELETER_USER_ID, DELETION_TIME, ROUTING_HEADER_ID, NAME, TASK_SEQ, RUNTIME, SETUP_TIME, EFFICIENCY_VALUE, SINGLE_OUT, IS_OUTSIDE, STATUS, REMARK, EXTEND, OUTSIDE_TIME, PERFORMANCE_HOURS, SCHEDULING_WORKING_HOURS, REAL_WORKING_HOURS, REAL_RUNTIME, PERFORMANCE_WORKING_HOURS, EQUIP_TYPE, EQUIP_TYPE_ID, CAN_INTERRUPT, PREVIOUS_START_TIME_BEGIN, CHANGE_LINE_TIME, PRE_DETAIL_ID, CONNECT_TYPE, CONNECT_PROPERTY, CONNECT_TYPE_NAME, CONNECT_PROPERTY_NAME, CONST_TIME,INCREMENT_QTY, BATCH_QTY, MIN_PRODUCTION_QTY, MAX_PRODUCTION_QTY, PRODUCTION_TAKT, PREPROCESSING_TIME, POSTPROCESSING_TIME, SPLIT_MIN_QTY, SPLIT_MAX_QTY, EQUIPMENT_CONNECTIVITY, SINGLE_OUT_UNIT_ID, SINGLE_OUT_UNIT_NAME, CONNECT_UNIT_ID, CONNECT_UNIT_NAME
</sql>
</mapper>
......@@ -2,8 +2,10 @@ package com.aps.demo;
import com.aps.ApsApplication;
import com.aps.entity.Algorithm.Chromosome;
import com.aps.entity.Gantt.ProductGanttVO;
import com.aps.entity.basic.Machine;
import com.aps.service.plan.PlanResultService;
import com.aps.service.plan.SceneService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -17,11 +19,14 @@ public class PlanResultServiceTest {
@Autowired
private PlanResultService planResultService;
@Autowired
private SceneService sceneService;
@Test
public void testExecute2() {
// 这里需要一个有效的SceneId来测试
// 在实际测试中,您需要提供一个数据库中存在的SceneId
String sceneId = "21DA0A695F2A4AA1B860ED43723F118A";
String sceneId = "2BAB2BF160BE447EA6673DABACEF05D2";
try {
// Chromosome result = planResultService.execute2(sceneId);
......@@ -31,12 +36,25 @@ public class PlanResultServiceTest {
// System.out.println("适应度: " + result.getFitness());
// System.out.println("工序字符串: " + result.getOperationStr());
// }
List<Double> splitCounts = new ArrayList<>();
splitCounts.add(20000.0);
splitCounts.add(30000.0);
// List<Double> splitCounts = new ArrayList<>();
// splitCounts.add(10000.0);
// splitCounts.add(10000.0);
// splitCounts.add(10000.0);
// splitCounts.add(10000.0);
// splitCounts.add(10000.0);
////
//// planResultService.SpiltOperation(sceneId,1,splitCounts.toArray(new Double[0]));
//
//planResultService.SpiltOrder(sceneId,"2f24e563-1337-422b-a0ba-92da7e8c6584",splitCounts.toArray(new Double[0]));
Chromosome schedule = sceneService.loadChromosomeFromFile(sceneId);
planResultService.SpiltOperation(sceneId,1,splitCounts.toArray(new Double[0]));
// 转换为 ProductGanttVO 格式
List<ProductGanttVO> productGanttVOList= new ArrayList<>();
List<ProductGanttVO> resourceGanttVOs = planResultService.convertToProductGanttVO1(schedule);
productGanttVOList.addAll(resourceGanttVOs);
System.out.println("执行成功,结果:" + (productGanttVOList != null ? "获得染色体对象" : "空结果"));
......
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