场景

parent 9f10bbc6
......@@ -64,6 +64,9 @@ import java.util.stream.Stream;
@Slf4j
public class MacroPlannerResultController {
@Autowired
private com.aps.macroplanner.scene.MacroSceneMode sceneMode;
@Autowired
private MpPispipResultPersistenceService mpPispipResultPersistenceService;
......@@ -543,7 +546,7 @@ public class MacroPlannerResultController {
try {
// 1. 数据转换: 数据库工艺物料类 → macroplanner 实体
TestDataBuilder data = macroPlannerDataConverter.convert(sid);
TestDataBuilder data = macroPlannerDataConverter.convert(sceneMode.resolve(sid));
result.put("dataSummary", buildDataSummary(data));
// 2. 数据验证
......
package com.aps.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aps.common.util.R;
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
@RequestMapping("/planPeriod")
@RequiredArgsConstructor
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;
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 java.io.Serializable;
import java.math.BigDecimal;
......@@ -8,6 +12,7 @@ import lombok.Data;
@Data
public class PlanPeriod {
@TableId(type = IdType.INPUT)
private String id;
private LocalDateTime creationtime;
private Long creatoruserid;
......@@ -34,5 +39,6 @@ private Long isvisable;
private Long top;
private LocalDateTime basetime;
private Short enabled;
@TableField(value = "MP_SCENE_ID", fill = FieldFill.INSERT)
private String mpSceneId;
}
\ No newline at end of file
}
......@@ -31,7 +31,8 @@ public class MacroSceneDataPermissionHandler implements MultiDataPermissionHandl
"PLAN_RESOURCE",
"EQUIPINFO",
"EQUIP_SHIFT_CAPACITY",
"APS_TIME_CONFIG"
"APS_TIME_CONFIG",
"PLAN_PERIOD"
));
@Override
......
......@@ -6,7 +6,7 @@ import org.springframework.stereotype.Component;
@Component
public class MacroSceneMode {
// 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;
public MacroSceneMode() {
......
......@@ -71,6 +71,7 @@ public class MacroSceneService {
private final EquipinfoMapper equipinfoMapper;
private final EquipShiftCapacityMapper equipShiftCapacityMapper;
private final ApsTimeConfigMapper apsTimeConfigMapper;
private final PlanPeriodMapper planPeriodMapper;
public List<MacroSceneConfig> listScenes() {
if (sceneMode.isDefaultOnly()) return java.util.Collections.singletonList(sceneMode.defaultScene());
......@@ -183,6 +184,7 @@ public class MacroSceneService {
sjzPfWhStockMapper.delete(null);
materialInfoMapper.delete(null);
apsTimeConfigMapper.delete(null);
planPeriodMapper.delete(null);
});
}
......@@ -214,6 +216,8 @@ public class MacroSceneService {
copyStocksAndSupplies(sourceSceneId, targetSceneId, materialIds, routingIds);
copyEquipCapacity(sourceSceneId, targetSceneId, equipIds, resourceIds);
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) {
......@@ -1027,7 +1031,8 @@ public class MacroSceneService {
|| mapper == routingDetailEquipMapper || mapper == stockMapper
|| mapper == materialPurchaseMapper || mapper == erpPurchaseOrderMapper
|| mapper == purchaseReceiptMapper || mapper == sjzPfWhStockMapper
|| mapper == planResourceMapper || mapper == equipinfoMapper) {
|| mapper == planResourceMapper || mapper == equipinfoMapper
|| mapper == planPeriodMapper) {
return "ISDELETED";
}
if (mapper == routingDetailMapper || mapper == equipShiftCapacityMapper) {
......
......@@ -45,4 +45,14 @@ class MacroSceneDataPermissionHandlerTest {
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