公共分页和list查询修改,设备字段修改

parent c0f28f4f
package com.aps.controller;
import com.aps.common.util.R;
import com.aps.entity.Gantt.PlanResourceTaskGanttVO1;
import com.aps.entity.Gantt.SimpleEquipinfo1;
import com.aps.entity.Mpsplannedorder;
import com.aps.entity.RoutingDetail;
import com.aps.entity.RoutingDetailEquip;
import com.aps.entity.RoutingHeader;
import com.aps.entity.ScheduledTask;
import com.aps.entity.Equipinfo;
import com.aps.service.ScheduleService;
import com.aps.service.MpsplannedorderService;
import com.aps.service.RoutingHeaderService;
import com.aps.service.RoutingDetailService;
import com.aps.service.RoutingDetailEquipService;
import com.aps.service.EquipinfoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/ganttest")
@Tag(name = "甘特图", description = "甘特图相关API")
public class ScheduleResultController1 {
@Autowired
private ScheduleService schedulerService;
@Autowired
private MpsplannedorderService orderService;
@Autowired
private RoutingHeaderService processService;
@Autowired
private RoutingDetailService operationService;
@Autowired
private RoutingDetailEquipService operationEquipService;
@Autowired
private EquipinfoService equipmentService;
@GetMapping("/resourcetest")
@Operation(summary = "资源甘特图", description = "获取资源甘特图数据")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "成功返回甘特图数据"),
@ApiResponse(responseCode = "500", description = "内部服务器错误")
})
public R<PlanResourceTaskGanttVO1> runScheduling() {
try {
// 获取routingid为'SY1102507-0056202车间-21号线'和'SY1102507-0060202车间-21号线'的待调度工单
List<Mpsplannedorder> orders = orderService.lambdaQuery()
.in(Mpsplannedorder::getRoutingid, "SY1102507-0056202车间-21号线", "SY1102507-0060202车间-21号线")
.list();
if (orders.isEmpty()) {
// 当没有订单时,返回空的甘特图VO
PlanResourceTaskGanttVO1 ganttVO = new PlanResourceTaskGanttVO1()
.setResources(new ArrayList<>())
.setEarliestTaskStartTime(LocalDateTime.of(2025, 6, 1, 0, 0, 0))
.setLastTaskAssignmentTime(LocalDateTime.of(2025, 12, 1, 0, 0, 0));
return R.ok(ganttVO);
}
// 提取所需的工艺ID列表
Set<String> routingIds = orders.stream()
.map(Mpsplannedorder::getRoutingid)
.collect(Collectors.toSet());
// 根据工单获取相关工艺
List<RoutingHeader> processes = processService.lambdaQuery()
.in(RoutingHeader::getCode, routingIds)
.list();
if (processes.isEmpty()) {
return R.failed("未找到相关工艺信息");
}
// 提取工艺ID用于后续查询
Set<Integer> processIds = processes.stream()
.map(RoutingHeader::getId)
.collect(Collectors.toSet());
// 根据工艺获取相关工序
List<RoutingDetail> operations = operationService.lambdaQuery()
.in(RoutingDetail::getRoutingHeaderId, processIds)
.orderByAsc(RoutingDetail::getTaskSeq)
.list();
if (operations.isEmpty()) {
return R.failed("未找到相关工序信息");
}
// 提取工序ID用于后续查询
Set<Long> operationIds = operations.stream()
.map(RoutingDetail::getId)
.collect(Collectors.toSet());
// 获取相关工序设备关系
List<RoutingDetailEquip> operationEquipments = operationEquipService.lambdaQuery()
.in(RoutingDetailEquip::getRoutingDetailId, operationIds)
.list();
if (operationEquipments.isEmpty()) {
return R.failed("未找到工序设备关系信息");
}
// 提取设备ID用于后续查询
Set<Long> equipmentIds = operationEquipments.stream()
.map(RoutingDetailEquip::getEquipId)
.collect(Collectors.toSet());
// 获取相关设备
List<Equipinfo> equipments = equipmentService.lambdaQuery()
.in(Equipinfo::getId, equipmentIds)
.list();
// 添加空值检查
if (orders == null || processes == null || operations == null || operationEquipments == null || equipments == null) {
return R.failed("获取调度数据失败,存在空数据");
}
List<ScheduledTask> result = schedulerService.scheduleOrders(
orders, processes, operations, operationEquipments, equipments);
// 转换设备信息为简要信息,并关联相关任务
List<SimpleEquipinfo1> simpleEquipinfos = equipments.stream()
.map(equip -> {
// 查找与该设备关联的任务
List<ScheduledTask> equipTasks = result.stream()
.filter(task -> task.getEquipId() != null && task.getEquipId().equals(equip.getId()))
.collect(Collectors.toList());
return new SimpleEquipinfo1()
.setId(equip.getId())
.setEquipId(equip.getEquipId())
.setEquipName(equip.getEquipName())
.setTasks(equipTasks);
})
.collect(Collectors.toList());
// 设置甘特图VO的最早时间为2025年6月1日,最晚时间为2025年12月1日
PlanResourceTaskGanttVO1 ganttVO = new PlanResourceTaskGanttVO1()
.setResources(simpleEquipinfos)
.setEarliestTaskStartTime(LocalDateTime.of(2025, 6, 1, 0, 0, 0))
.setLastTaskAssignmentTime(LocalDateTime.of(2025, 12, 1, 0, 0, 0));
return R.ok(ganttVO);
} catch (Exception e) {
return R.failed("调度执行失败: " + e.getMessage());
}
}
}
\ No newline at end of file
...@@ -304,7 +304,6 @@ public class RoutingDataService { ...@@ -304,7 +304,6 @@ public class RoutingDataService {
machine.setCode(""); machine.setCode("");
machine.setName(""); machine.setName("");
machines.add(machine); machines.add(machine);
} }
...@@ -360,7 +359,7 @@ public class RoutingDataService { ...@@ -360,7 +359,7 @@ public class RoutingDataService {
Equipinfo equipinfo= equipinfoList.stream() Equipinfo equipinfo= equipinfoList.stream()
.filter(t->t.getId().equals(PlanResource.getReferenceId())) .filter(t->t.getId().equals(PlanResource.getReferenceId()))
.findFirst().orElse(null); .findFirst().orElse(null);
machine.setDepartment(PlanResource.getDepartTitle());
if(equipinfo!=null) if(equipinfo!=null)
{ {
machine.setCode(equipinfo.getEquipId()); machine.setCode(equipinfo.getEquipId());
...@@ -408,6 +407,30 @@ public class RoutingDataService { ...@@ -408,6 +407,30 @@ public class RoutingDataService {
} }
} else { } else {
for (Machine machine : machines) { for (Machine machine : machines) {
PlanResource PlanResource = PlanResources.stream()
.filter(t -> t.getId() == machine.getId())
.findFirst().orElse(null);
if (PlanResource != null) {
Equipinfo equipinfo= equipinfoList.stream()
.filter(t->t.getId().equals(PlanResource.getReferenceId()))
.findFirst().orElse(null);
machine.setDepartment(PlanResource.getDepartTitle());
if(equipinfo!=null)
{
machine.setCode(equipinfo.getEquipId());
machine.setName(equipinfo.getEquipName());
}else {
machine.setCode(PlanResource.getReferenceCode());
machine.setName(PlanResource.getTitle());
}
}
List<Shift> shifts1 = new ArrayList<>(); List<Shift> shifts1 = new ArrayList<>();
Shift shift=new Shift(); Shift shift=new Shift();
shift.setMachineId(machine.getId()); shift.setMachineId(machine.getId());
...@@ -488,7 +511,7 @@ public class RoutingDataService { ...@@ -488,7 +511,7 @@ public class RoutingDataService {
Equipinfo equipinfo= equipinfoList.stream() Equipinfo equipinfo= equipinfoList.stream()
.filter(t->t.getId().equals(resource.getReferenceId())) .filter(t->t.getId().equals(resource.getReferenceId()))
.findFirst().orElse(null); .findFirst().orElse(null);
machine.setDepartment(resource.getDepartTitle());
if(equipinfo!=null) if(equipinfo!=null)
{ {
machine.setCode(equipinfo.getEquipId()); machine.setCode(equipinfo.getEquipId());
......
...@@ -3,6 +3,7 @@ package com.aps.service.common; ...@@ -3,6 +3,7 @@ package com.aps.service.common;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.aps.common.util.R; import com.aps.common.util.R;
import com.aps.entity.Algorithm.Chromosome; import com.aps.entity.Algorithm.Chromosome;
import com.aps.entity.Algorithm.GAScheduleResult;
import com.aps.entity.ProdProcessExec; import com.aps.entity.ProdProcessExec;
import com.aps.entity.Algorithm.GlobalOperationInfo; import com.aps.entity.Algorithm.GlobalOperationInfo;
import com.aps.entity.Algorithm.IDAndChildID.GroupResult; import com.aps.entity.Algorithm.IDAndChildID.GroupResult;
...@@ -28,13 +29,17 @@ import org.springframework.util.CollectionUtils; ...@@ -28,13 +29,17 @@ import org.springframework.util.CollectionUtils;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException; import java.time.format.DateTimeParseException;
import java.util.*; import com.aps.service.MaterialInfoService;
import java.util.stream.Collectors; import com.aps.entity.MaterialInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@Service @Service
@Slf4j @Slf4j
...@@ -46,6 +51,9 @@ public class ChromosomeDataService { ...@@ -46,6 +51,9 @@ public class ChromosomeDataService {
@Autowired @Autowired
private DatabaseQueryService databaseQueryService; private DatabaseQueryService databaseQueryService;
@Autowired
private MaterialInfoService materialInfoService;
@Autowired @Autowired
private NamedParameterJdbcTemplate namedParameterJdbcTemplate; private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
...@@ -108,6 +116,196 @@ public class ChromosomeDataService { ...@@ -108,6 +116,196 @@ public class ChromosomeDataService {
return result.toString(); return result.toString();
} }
/**
* 查询当前场景排产的成品/半成品物料信息
*/
public Map<String, Object> queryScheduledMaterials(String sceneId, Paged paged) {
try {
// 1. 从文件中加载Chromosome对象
Chromosome chromosome = sceneService.loadChromosomeFromFile(sceneId);
if (chromosome == null || chromosome.getResult() == null) {
return createEmptyPageResult();
}
// 2. 从排产结果中提取产品ID列表
Set<String> productIds = chromosome.getResult().stream()
.map(GAScheduleResult::getProductId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (productIds.isEmpty()) {
return createEmptyPageResult();
}
// 3. 查询MaterialInfo表获取物料详细信息
List<MaterialInfo> materialInfos = queryMaterialInfoByProductIds(productIds, paged);
// 4. 构建分页结果
return buildPageResult(materialInfos, paged);
} catch (Exception e) {
log.error("查询排产物料失败,场景ID: " + sceneId, e);
return createEmptyPageResult();
}
}
/**
* 根据产品ID列表查询MaterialInfo
*/
private List<MaterialInfo> queryMaterialInfoByProductIds(Set<String> productIds, Paged paged) {
// 使用MyBatis-Plus查询
LambdaQueryWrapper<MaterialInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.in(MaterialInfo::getId, productIds)
.eq(MaterialInfo::getIsdeleted, 0);
// 添加额外的查询条件
if (paged.getConditions() != null && !paged.getConditions().isEmpty()) {
for (ConditionEntity condition : paged.getConditions()) {
if (!"sceneId".equals(condition.getFieldName())) {
addConditionToWrapper(wrapper, condition);
}
}
}
// 添加排序
if (paged.getSortByList() != null && !paged.getSortByList().isEmpty()) {
for (String sortBy : paged.getSortByList()) {
String[] parts = sortBy.split(" ");
String fieldName = parts[0];
boolean isAsc = parts.length <= 1 || !"desc".equalsIgnoreCase(parts[1]);
// 根据字段名添加排序
switch (fieldName.toLowerCase()) {
case "id":
wrapper.orderBy(true, isAsc, MaterialInfo::getId);
break;
case "name":
wrapper.orderBy(true, isAsc, MaterialInfo::getName);
break;
case "code":
wrapper.orderBy(true, isAsc, MaterialInfo::getCode);
break;
case "creationtime":
wrapper.orderBy(true, isAsc, MaterialInfo::getCreationtime);
break;
// 可以继续添加其他字段的排序
}
}
}
// 查询数据
List<MaterialInfo> materialInfos;
long total = 0;
if (paged.getPageSize() > 0) {
// Oracle分页查询 - 使用MyBatis-Plus的Page对象
Page<MaterialInfo> page = new Page<>(paged.getPageIndex(), paged.getPageSize());
Page<MaterialInfo> result = materialInfoService.page(page, wrapper);
materialInfos = result.getRecords();
total = result.getTotal();
} else {
materialInfos = materialInfoService.list(wrapper);
total = materialInfos.size();
}
// 将总数存储到paged对象中,供buildPageResult使用
paged.setTotal((int) total);
return materialInfos;
}
/**
* 为查询条件包装器添加条件
*/
private void addConditionToWrapper(LambdaQueryWrapper<MaterialInfo> wrapper, ConditionEntity condition) {
String fieldName = condition.getFieldName();
String conditionType = condition.getConditionalType();
String fieldValue = condition.getFieldValue();
switch (fieldName.toLowerCase()) {
case "name":
if ("LIKE".equalsIgnoreCase(conditionType)) {
wrapper.like(MaterialInfo::getName, fieldValue);
} else if ("EQUAL".equalsIgnoreCase(conditionType)) {
wrapper.eq(MaterialInfo::getName, fieldValue);
}
break;
case "code":
if ("LIKE".equalsIgnoreCase(conditionType)) {
wrapper.like(MaterialInfo::getCode, fieldValue);
} else if ("EQUAL".equalsIgnoreCase(conditionType)) {
wrapper.eq(MaterialInfo::getCode, fieldValue);
}
break;
case "categoryname":
if ("LIKE".equalsIgnoreCase(conditionType)) {
wrapper.like(MaterialInfo::getCategoryName, fieldValue);
} else if ("EQUAL".equalsIgnoreCase(conditionType)) {
wrapper.eq(MaterialInfo::getCategoryName, fieldValue);
}
break;
// 可以继续添加其他字段的条件处理
}
}
/**
* 构建分页结果
*/
private Map<String, Object> buildPageResult(List<MaterialInfo> data, Paged paged) {
Map<String, Object> result = new HashMap<>();
result.put("data", data);
result.put("pageIndex", paged.getPageIndex());
result.put("pageSize", paged.getPageSize());
result.put("total", paged.getTotal() != null ? paged.getTotal() : data.size());
return result;
}
/**
* 根据ID查询单个排产物料
*/
private Object queryScheduledMaterialById(String sceneId, String id) {
try {
// 1. 从文件中加载Chromosome对象
Chromosome chromosome = sceneService.loadChromosomeFromFile(sceneId);
if (chromosome == null || chromosome.getResult() == null) {
return null;
}
// 2. 检查该ID是否在排产结果中
boolean isScheduled = chromosome.getResult().stream()
.anyMatch(result -> id.equals(result.getProductId()));
if (!isScheduled) {
return null;
}
// 3. 使用MyBatis-Plus查询MaterialInfo
LambdaQueryWrapper<MaterialInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MaterialInfo::getId, id)
.eq(MaterialInfo::getIsdeleted, 0);
MaterialInfo materialInfo = materialInfoService.getOne(wrapper);
return materialInfo;
} catch (Exception e) {
log.error("查询排产物料失败,场景ID: " + sceneId + ", 物料ID: " + id, e);
return null;
}
}
/**
* 创建空的分页结果
*/
private Map<String, Object> createEmptyPageResult() {
Map<String, Object> result = new HashMap<>();
result.put("data", Collections.emptyList());
result.put("pageIndex", 1);
result.put("pageSize", 0);
result.put("total", 0);
return result;
}
/** /**
* 获取实体的字段信息 * 获取实体的字段信息
* @param entityName 实体名称 * @param entityName 实体名称
...@@ -266,10 +464,96 @@ public class ChromosomeDataService { ...@@ -266,10 +464,96 @@ public class ChromosomeDataService {
return fieldDescriptions; return fieldDescriptions;
} }
/**
* 创建空的分页结果
*/
private Map<String, Object> createEmptyResult(Paged paged) {
Map<String, Object> emptyResult = new HashMap<>();
emptyResult.put("records", Collections.emptyList());
emptyResult.put("totalCount", 0);
emptyResult.put("pageIndex", paged.getPageIndex() != null ? paged.getPageIndex() : 1);
emptyResult.put("size", paged.getPageSize() != null ? paged.getPageSize() : 10);
return emptyResult;
}
/**
* 过滤Machine对象,移除不需要的字段
*/
private List<Object> filterMachineData(List<?> machineList) {
List<Object> filteredMachines = new ArrayList<>();
for (Object obj : machineList) {
if (obj instanceof Machine) {
Machine originalMachine = (Machine) obj;
Machine filteredMachine = new Machine();
// 只复制需要的字段
filteredMachine.setId(originalMachine.getId());
filteredMachine.setName(originalMachine.getName());
filteredMachine.setEarliestTime(originalMachine.getEarliestTime());
filteredMachine.setTotalTaskTime(originalMachine.getTotalTaskTime());
filteredMachine.setCode(originalMachine.getCode());
filteredMachine.setActualWorkTime(originalMachine.getActualWorkTime());
filteredMachine.setRate(originalMachine.getRate());
filteredMachine.setDepartment(originalMachine.getDepartment());
// 不设置不需要的字段:shifts, maintenanceWindows, availability, holidays, shiftsChanged, maintenanceWindowsChanged
filteredMachines.add(filteredMachine);
} else {
filteredMachines.add(obj);
}
}
return filteredMachines;
}
/** /**
* 根据场景ID和实体名称查询Chromosome中的分页数据,带条件过滤 * 根据场景ID和实体名称查询Chromosome中的分页数据,带条件过滤
*/ */
public Map<String, Object> queryChromosomeDataWithConditions(String sceneId, String entityName, Paged paged) { public Map<String, Object> queryChromosomeDataWithConditions(String sceneId, String entityName, Paged paged) {
// 对于materialInfo且有sceneId时,在conditions中添加排产物料ID过滤
System.out.println(entityName);
if ("materialinfo".equalsIgnoreCase(entityName) && sceneId != null && !sceneId.isEmpty()) {
boolean hasProductIds = false;
try {
// 从文件中加载Chromosome对象
Chromosome chromosome = sceneService.loadChromosomeFromFile(sceneId);
if (chromosome != null && chromosome.getResult() != null) {
// 从排产结果中提取产品ID列表
Set<String> productIds = chromosome.getResult().stream()
.map(GAScheduleResult::getProductId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (!productIds.isEmpty()) {
// 创建物料ID的IN条件
ConditionEntity idCondition = new ConditionEntity();
idCondition.setFieldName("id");
idCondition.setConditionalType("IN");
idCondition.setFieldValue(String.join(",", productIds));
// 添加到conditions中
if (paged.getConditions() == null) {
paged.setConditions(new ArrayList<>());
}
paged.getConditions().add(idCondition);
hasProductIds = true;
}
}
// 如果没有找到productIds,返回空结果
if (!hasProductIds) {
return createEmptyResult(paged);
}
} catch (Exception e) {
log.error("提取排产物料ID失败,场景ID: " + sceneId, e);
return createEmptyResult(paged);
} finally {
// 无论是否发生异常,都移除原始的sceneId条件
if (paged.getConditions() != null) {
paged.getConditions().removeIf(condition -> "sceneId".equalsIgnoreCase(condition.getFieldName()));
}
}
}
EntityConfig config = getEntityConfig(entityName); EntityConfig config = getEntityConfig(entityName);
if (config.getDataSource() == DataSourceType.FILE) { if (config.getDataSource() == DataSourceType.FILE) {
...@@ -284,6 +568,49 @@ public class ChromosomeDataService { ...@@ -284,6 +568,49 @@ public class ChromosomeDataService {
* 查询文件数据列表(支持条件过滤) * 查询文件数据列表(支持条件过滤)
*/ */
public List<Object> queryChromosomeDataList(String sceneId, String entityName, Paged paged) { public List<Object> queryChromosomeDataList(String sceneId, String entityName, Paged paged) {
// 对于materialInfo且有sceneId时,在conditions中添加排产物料ID过滤
if ("materialinfo".equalsIgnoreCase(entityName) && sceneId != null && !sceneId.isEmpty()) {
boolean hasProductIds = false;
try {
// 从文件中加载Chromosome对象
Chromosome chromosome = sceneService.loadChromosomeFromFile(sceneId);
if (chromosome != null && chromosome.getResult() != null) {
// 从排产结果中提取产品ID列表
Set<String> productIds = chromosome.getResult().stream()
.map(GAScheduleResult::getProductId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (!productIds.isEmpty()) {
// 创建物料ID的IN条件
ConditionEntity idCondition = new ConditionEntity();
idCondition.setFieldName("id");
idCondition.setConditionalType("IN");
idCondition.setFieldValue(String.join(",", productIds));
// 添加到conditions中
if (paged.getConditions() == null) {
paged.setConditions(new ArrayList<>());
}
paged.getConditions().add(idCondition);
hasProductIds = true;
}
}
// 如果没有找到productIds,返回空结果
if (!hasProductIds) {
return Collections.emptyList();
}
} catch (Exception e) {
log.error("提取排产物料ID失败,场景ID: " + sceneId, e);
return Collections.emptyList();
} finally {
// 无论是否发生异常,都移除原始的sceneId条件
if (paged.getConditions() != null) {
paged.getConditions().removeIf(condition -> "sceneId".equalsIgnoreCase(condition.getFieldName()));
}
}
}
EntityConfig config = getEntityConfig(entityName); EntityConfig config = getEntityConfig(entityName);
if (config.getDataSource() == DataSourceType.FILE) { if (config.getDataSource() == DataSourceType.FILE) {
...@@ -360,7 +687,7 @@ public class ChromosomeDataService { ...@@ -360,7 +687,7 @@ public class ChromosomeDataService {
} }
} else { } else {
Object data = queryFileData(sceneId, config); Object data = queryFileData(sceneId, config);
return applyConditionsToList(data, paged); return applyConditionsToList(data, paged, entityName);
} }
} else { } else {
// 数据库查询 // 数据库查询
...@@ -372,6 +699,28 @@ public class ChromosomeDataService { ...@@ -372,6 +699,28 @@ public class ChromosomeDataService {
* 根据ID查询单条数据 * 根据ID查询单条数据
*/ */
public Object queryChromosomeDataById(String sceneId, String entityName, String id) { public Object queryChromosomeDataById(String sceneId, String entityName, String id) {
// 对于materialInfo且有sceneId时,从排产结果中检查
if ("materialinfo".equalsIgnoreCase(entityName) && sceneId != null && !sceneId.isEmpty()) {
try {
// 1. 从文件中加载Chromosome对象
Chromosome chromosome = sceneService.loadChromosomeFromFile(sceneId);
if (chromosome == null || chromosome.getResult() == null) {
return null;
}
// 2. 检查该ID是否在排产结果中
boolean isScheduled = chromosome.getResult().stream()
.anyMatch(result -> id.equals(result.getProductId()));
if (!isScheduled) {
return null;
}
} catch (Exception e) {
log.error("检查排产物料失败,场景ID: " + sceneId + ", 物料ID: " + id, e);
return null;
}
}
EntityConfig config = getEntityConfig(entityName); EntityConfig config = getEntityConfig(entityName);
if (config.getDataSource() == DataSourceType.FILE) { if (config.getDataSource() == DataSourceType.FILE) {
...@@ -414,6 +763,13 @@ public class ChromosomeDataService { ...@@ -414,6 +763,13 @@ public class ChromosomeDataService {
config.setEntityName(entityName); config.setEntityName(entityName);
config.setDataSource(DataSourceType.FILE); config.setDataSource(DataSourceType.FILE);
config.setFieldName("kpiMetrics"); config.setFieldName("kpiMetrics");
}
// 特殊处理:当实体是Machine时,映射到Machines字段
else if ("machine".equalsIgnoreCase(key)) {
config = new EntityConfig();
config.setEntityName(entityName);
config.setDataSource(DataSourceType.FILE);
config.setFieldName("Machines");
} else { } else {
// 自动创建数据库配置(默认行为) // 自动创建数据库配置(默认行为)
config = createDefaultDbConfig(entityName); config = createDefaultDbConfig(entityName);
...@@ -613,6 +969,12 @@ public class ChromosomeDataService { ...@@ -613,6 +969,12 @@ public class ChromosomeDataService {
// 应用排序 // 应用排序
List<Object> sortedData = sortData(dataList, paged); List<Object> sortedData = sortData(dataList, paged);
// 特殊处理:当实体是Machine时,过滤不需要的字段
if ("machine".equalsIgnoreCase(config.getEntityName())) {
sortedData = filterMachineData(sortedData);
}
data = sortedData; data = sortedData;
} }
} }
...@@ -645,6 +1007,28 @@ public class ChromosomeDataService { ...@@ -645,6 +1007,28 @@ public class ChromosomeDataService {
return result; return result;
} }
/**
* 过滤单个Machine对象,移除不需要的字段
*/
private Object filterSingleMachineData(Object machineObj) {
if (machineObj instanceof Machine) {
Machine originalMachine = (Machine) machineObj;
Machine filteredMachine = new Machine();
// 只复制需要的字段
filteredMachine.setId(originalMachine.getId());
filteredMachine.setName(originalMachine.getName());
filteredMachine.setEarliestTime(originalMachine.getEarliestTime());
filteredMachine.setTotalTaskTime(originalMachine.getTotalTaskTime());
filteredMachine.setCode(originalMachine.getCode());
filteredMachine.setActualWorkTime(originalMachine.getActualWorkTime());
filteredMachine.setRate(originalMachine.getRate());
filteredMachine.setDepartment(originalMachine.getDepartment());
// 不设置不需要的字段:shifts, maintenanceWindows, availability, holidays, shiftsChanged, maintenanceWindowsChanged
return filteredMachine;
}
return machineObj;
}
/** /**
* 根据ID查询文件数据 * 根据ID查询文件数据
*/ */
...@@ -704,12 +1088,20 @@ public class ChromosomeDataService { ...@@ -704,12 +1088,20 @@ public class ChromosomeDataService {
.orElse(null); .orElse(null);
if (item != null) { if (item != null) {
// 特殊处理:当实体是Machine时,过滤不需要的字段
if ("machine".equalsIgnoreCase(config.getEntityName())) {
return filterSingleMachineData(item);
}
return item; return item;
} else { } else {
return null; // 找不到数据时返回null而不是抛出异常 return null; // 找不到数据时返回null而不是抛出异常
} }
} else { } else {
// 如果不是列表,直接返回结果 // 如果不是列表,直接返回结果
// 特殊处理:当实体是Machine时,过滤不需要的字段
if ("machine".equalsIgnoreCase(config.getEntityName())) {
return filterSingleMachineData(result);
}
return result; return result;
} }
} }
...@@ -734,7 +1126,7 @@ public class ChromosomeDataService { ...@@ -734,7 +1126,7 @@ public class ChromosomeDataService {
/** /**
* 将数据应用条件过滤并返回列表 * 将数据应用条件过滤并返回列表
*/ */
private List<Object> applyConditionsToList(Object data, Paged paged) { private List<Object> applyConditionsToList(Object data, Paged paged, String entityName) {
// 检查是否是直接传入的EntityConfig(这种情况可能需要获取场景ID和实体类型) // 检查是否是直接传入的EntityConfig(这种情况可能需要获取场景ID和实体类型)
// 实际上这个方法是在queryChromosomeDataList中调用的,此时数据已经从文件中获取 // 实际上这个方法是在queryChromosomeDataList中调用的,此时数据已经从文件中获取
...@@ -749,10 +1141,21 @@ public class ChromosomeDataService { ...@@ -749,10 +1141,21 @@ public class ChromosomeDataService {
// 应用排序 // 应用排序
dataList = sortData(dataList, paged); dataList = sortData(dataList, paged);
// 特殊处理:当实体是Machine时,过滤不需要的字段
if ("machine".equalsIgnoreCase(entityName)) {
dataList = filterMachineData(dataList);
}
return dataList; return dataList;
} else { } else {
List<Object> resultList = new ArrayList<>(); List<Object> resultList = new ArrayList<>();
resultList.add(data); resultList.add(data);
// 特殊处理:当实体是Machine时,过滤不需要的字段
if ("machine".equalsIgnoreCase(entityName) && data instanceof Machine) {
resultList = filterMachineData(resultList);
}
return resultList; return resultList;
} }
} }
......
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