场景

parent 9f10bbc6
...@@ -64,6 +64,9 @@ import java.util.stream.Stream; ...@@ -64,6 +64,9 @@ import java.util.stream.Stream;
@Slf4j @Slf4j
public class MacroPlannerResultController { public class MacroPlannerResultController {
@Autowired
private com.aps.macroplanner.scene.MacroSceneMode sceneMode;
@Autowired @Autowired
private MpPispipResultPersistenceService mpPispipResultPersistenceService; private MpPispipResultPersistenceService mpPispipResultPersistenceService;
...@@ -543,7 +546,7 @@ public class MacroPlannerResultController { ...@@ -543,7 +546,7 @@ public class MacroPlannerResultController {
try { try {
// 1. 数据转换: 数据库工艺物料类 → macroplanner 实体 // 1. 数据转换: 数据库工艺物料类 → macroplanner 实体
TestDataBuilder data = macroPlannerDataConverter.convert(sid); TestDataBuilder data = macroPlannerDataConverter.convert(sceneMode.resolve(sid));
result.put("dataSummary", buildDataSummary(data)); result.put("dataSummary", buildDataSummary(data));
// 2. 数据验证 // 2. 数据验证
......
package com.aps.controller; package com.aps.controller;
import org.springframework.web.bind.annotation.RequestMapping; import com.aps.common.util.R;
import org.springframework.web.bind.annotation.RestController; import com.aps.entity.MacroSceneConfig;
import com.aps.entity.PlanPeriod;
import com.aps.macroplanner.scene.MacroSceneContext;
import com.aps.macroplanner.scene.MacroSceneService;
import com.aps.service.PlanPeriodService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
/**
* <p>
* 前端控制器
* </p>
*
* @author MyBatis-Plus
* @since 2026-09-20
*/
@RestController @RestController
@RequestMapping("/planPeriod") @RequestMapping("/planPeriod")
@RequiredArgsConstructor
public class PlanPeriodController { public class PlanPeriodController {
private final PlanPeriodService planPeriodService;
private final MacroSceneService macroSceneService;
@PostMapping("/create")
@Operation(summary = "新增场景计划周期")
public R<PlanPeriod> create(@RequestParam(required = false) String sceneId,
@RequestBody PlanPeriod period) {
String targetScene = resolveScene(sceneId);
return MacroSceneContext.execute(targetScene, () -> {
period.setId(UUID.randomUUID().toString());
period.setMpSceneId(targetScene);
period.setIsdeleted(0L);
period.setDeletiontime(null);
period.setDeleteruserid(null);
period.setCreationtime(LocalDateTime.now());
if (!planPeriodService.save(period)) {
return R.failed("新增计划周期失败");
}
return R.ok(period);
});
}
@GetMapping("/list")
@Operation(summary = "查询场景计划周期")
public R<List<PlanPeriod>> list(@RequestParam(required = false) String sceneId) {
String targetScene = resolveScene(sceneId);
return MacroSceneContext.execute(targetScene, () ->
R.ok(planPeriodService.list(new LambdaQueryWrapper<PlanPeriod>()
.eq(PlanPeriod::getIsdeleted, 0))));
}
private String resolveScene(String sceneId) {
String targetScene = sceneId == null ? MacroSceneContext.getSceneId() : sceneId.trim();
if (targetScene == null || targetScene.isEmpty()) return null;
MacroSceneConfig scene = macroSceneService.getScene(targetScene);
if (scene == null || !targetScene.equals(scene.getSceneId())
|| !"READY".equals(scene.getSceneStatus())) {
throw new IllegalArgumentException("场景不存在或尚未就绪: " + targetScene);
}
return targetScene;
}
} }
package com.aps.entity; package com.aps.entity;
import lombok.Data; import lombok.Data;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -8,6 +12,7 @@ import lombok.Data; ...@@ -8,6 +12,7 @@ import lombok.Data;
@Data @Data
public class PlanPeriod { public class PlanPeriod {
@TableId(type = IdType.INPUT)
private String id; private String id;
private LocalDateTime creationtime; private LocalDateTime creationtime;
private Long creatoruserid; private Long creatoruserid;
...@@ -34,5 +39,6 @@ private Long isvisable; ...@@ -34,5 +39,6 @@ private Long isvisable;
private Long top; private Long top;
private LocalDateTime basetime; private LocalDateTime basetime;
private Short enabled; private Short enabled;
@TableField(value = "MP_SCENE_ID", fill = FieldFill.INSERT)
private String mpSceneId; private String mpSceneId;
} }
\ No newline at end of file
...@@ -31,7 +31,8 @@ public class MacroSceneDataPermissionHandler implements MultiDataPermissionHandl ...@@ -31,7 +31,8 @@ public class MacroSceneDataPermissionHandler implements MultiDataPermissionHandl
"PLAN_RESOURCE", "PLAN_RESOURCE",
"EQUIPINFO", "EQUIPINFO",
"EQUIP_SHIFT_CAPACITY", "EQUIP_SHIFT_CAPACITY",
"APS_TIME_CONFIG" "APS_TIME_CONFIG",
"PLAN_PERIOD"
)); ));
@Override @Override
......
...@@ -6,7 +6,7 @@ import org.springframework.stereotype.Component; ...@@ -6,7 +6,7 @@ import org.springframework.stereotype.Component;
@Component @Component
public class MacroSceneMode { public class MacroSceneMode {
// Temporary test mode. Set to false and rebuild to restore scene management. // Temporary test mode. Set to false and rebuild to restore scene management.
private static final boolean DEFAULT_ONLY = true; private static final boolean DEFAULT_ONLY = false;
private final boolean defaultOnly; private final boolean defaultOnly;
public MacroSceneMode() { public MacroSceneMode() {
......
...@@ -71,6 +71,7 @@ public class MacroSceneService { ...@@ -71,6 +71,7 @@ public class MacroSceneService {
private final EquipinfoMapper equipinfoMapper; private final EquipinfoMapper equipinfoMapper;
private final EquipShiftCapacityMapper equipShiftCapacityMapper; private final EquipShiftCapacityMapper equipShiftCapacityMapper;
private final ApsTimeConfigMapper apsTimeConfigMapper; private final ApsTimeConfigMapper apsTimeConfigMapper;
private final PlanPeriodMapper planPeriodMapper;
public List<MacroSceneConfig> listScenes() { public List<MacroSceneConfig> listScenes() {
if (sceneMode.isDefaultOnly()) return java.util.Collections.singletonList(sceneMode.defaultScene()); if (sceneMode.isDefaultOnly()) return java.util.Collections.singletonList(sceneMode.defaultScene());
...@@ -183,6 +184,7 @@ public class MacroSceneService { ...@@ -183,6 +184,7 @@ public class MacroSceneService {
sjzPfWhStockMapper.delete(null); sjzPfWhStockMapper.delete(null);
materialInfoMapper.delete(null); materialInfoMapper.delete(null);
apsTimeConfigMapper.delete(null); apsTimeConfigMapper.delete(null);
planPeriodMapper.delete(null);
}); });
} }
...@@ -214,6 +216,8 @@ public class MacroSceneService { ...@@ -214,6 +216,8 @@ public class MacroSceneService {
copyStocksAndSupplies(sourceSceneId, targetSceneId, materialIds, routingIds); copyStocksAndSupplies(sourceSceneId, targetSceneId, materialIds, routingIds);
copyEquipCapacity(sourceSceneId, targetSceneId, equipIds, resourceIds); copyEquipCapacity(sourceSceneId, targetSceneId, equipIds, resourceIds);
copySimpleRows(sourceSceneId, targetSceneId, apsTimeConfigMapper, ApsTimeConfig.class, null); copySimpleRows(sourceSceneId, targetSceneId, apsTimeConfigMapper, ApsTimeConfig.class, null);
copySimpleRows(sourceSceneId, targetSceneId, planPeriodMapper, PlanPeriod.class,
row -> row.setId(UUID.randomUUID().toString()));
} }
private Map<Integer, Integer> copyEquipinfo(String source, String target) { private Map<Integer, Integer> copyEquipinfo(String source, String target) {
...@@ -1027,7 +1031,8 @@ public class MacroSceneService { ...@@ -1027,7 +1031,8 @@ public class MacroSceneService {
|| mapper == routingDetailEquipMapper || mapper == stockMapper || mapper == routingDetailEquipMapper || mapper == stockMapper
|| mapper == materialPurchaseMapper || mapper == erpPurchaseOrderMapper || mapper == materialPurchaseMapper || mapper == erpPurchaseOrderMapper
|| mapper == purchaseReceiptMapper || mapper == sjzPfWhStockMapper || mapper == purchaseReceiptMapper || mapper == sjzPfWhStockMapper
|| mapper == planResourceMapper || mapper == equipinfoMapper) { || mapper == planResourceMapper || mapper == equipinfoMapper
|| mapper == planPeriodMapper) {
return "ISDELETED"; return "ISDELETED";
} }
if (mapper == routingDetailMapper || mapper == equipShiftCapacityMapper) { if (mapper == routingDetailMapper || mapper == equipShiftCapacityMapper) {
......
...@@ -45,4 +45,14 @@ class MacroSceneDataPermissionHandlerTest { ...@@ -45,4 +45,14 @@ class MacroSceneDataPermissionHandlerTest {
assertNull(expression); assertNull(expression);
} }
@Test
void planPeriodsAreScopedToBaselineOrSelectedScene() {
Table table = new Table("PLAN_PERIOD");
assertEquals("PLAN_PERIOD.MP_SCENE_ID IS NULL",
handler.getSqlSegment(table, null, "test.select").toString());
MacroSceneContext.setSceneId("scene-001");
assertEquals("PLAN_PERIOD.MP_SCENE_ID = 'scene-001'",
handler.getSqlSegment(table, null, "test.select").toString());
}
} }
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