公共分页和list查询修改和info修改

parent 8105cd67
......@@ -187,7 +187,7 @@ public class ChromosomeDataController {
* - 文件实体: GET /queryChromosome/order/info?sceneId=xxx
* - 数据库实体: GET /queryChromosome/user/info
*
* @param sceneId 场景ID (文件实体可选,数据库实体不需要)
* @param entityName 实体名称 (如: order, entry, machine, user, department等)
* @return 字段信息列表
*/
......@@ -196,7 +196,7 @@ public class ChromosomeDataController {
public R<List<FieldInfo>> getEntityInfo(
@Parameter(description = "实体名称", required = true)
@PathVariable String entityName) {
System.out.println("getEntityInfo");
List<FieldInfo> fieldInfos = chromosomeDataService.getEntityInfo(entityName);
return R.ok(fieldInfos);
}
......
......@@ -637,7 +637,7 @@ public class ResourceGanttController {
@GetMapping("/productGantt")
@Operation(summary = "获取资源甘特图数据", description = "获取资源甘特图数据")
@Operation(summary = "获取工单甘特图数据", description = "获取工单甘特图数据")
public List<ProductGanttVO> productGantt(@RequestParam String sceneId) {
// 从PlanResultService获取ScheduleChromosome列表
Chromosome schedule = sceneService.loadChromosomeFromFile(sceneId);
......
......@@ -43,7 +43,7 @@ private BigDecimal checkTime;
private String taskType;
private Long taskFlag;
private Long insertFlag;
private Long shopid;
private Integer shopid;
private Long lockFlag;
private Short subWorkHourStatus;
private Short isOutsourcing;
......
package com.aps.entity.Gantt;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* 供给关系响应数据类
*/
@Data
public class SupplyRelationResponse {
private int code;
private String msg;
private List<Object> data;
private String timestamp;
/**
* 构建成功响应
* @param data 响应数据
* @return 响应对象
*/
public static SupplyRelationResponse success(List<Object> data) {
SupplyRelationResponse response = new SupplyRelationResponse();
response.setCode(200);
response.setMsg("success");
response.setData(data);
response.setTimestamp(java.time.LocalDateTime.now().toString());
return response;
}
}
\ No newline at end of file
package com.aps.entity;
import lombok.Data;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
......
......@@ -102,4 +102,7 @@ public class ProdProcessExec {
private String routingCode;
/** 部门ID,来自工艺路线 routing_header.department_id,新增场景时在 createProcessExec 中赋值 */
private Integer departmentId;
}
\ No newline at end of file
......@@ -43,6 +43,8 @@ public class Entry {
private Integer routingId;
private String routingCode;
private String routingName;
/** 部门ID,来自工艺路线 routing_header.department_id,在创建 Entry 时从工艺头带出 */
private Integer departmentId;
private Long routingDetailId;
private Long taskSeq;
private String routingDetailName;
......
......@@ -20,8 +20,10 @@ public class Paged {
private List<String> sortByList=new ArrayList<>(); // 多字段排序列表,格式如["type asc", "id desc"]
private String sortBy=""; //排序字段
private Boolean desc=true; //是否倒序
private String fields=""; // 返回的字段
/** 返回的字段,多个用逗号分隔如 "id,name";有值时只返回这些列,有几列返回几列 */
private String fields="";
private String table=""; // 返回的表
/** 分组字段,多个用逗号分隔如 "id,name"。有值时按这些字段 GROUP BY,返回结果仅含分组列 + count(每组条数) */
private String groupName;
private Boolean and=true; // 条件逻辑关系,true为与关系,false为或关系
private List<ConditionEntity> conditions=new ArrayList<>(); //条件集合
......
......@@ -543,8 +543,9 @@ if(routingIds.size()==0)
ProdLaunchOrder prodOrderMain= convertToLaunchOrder(order,"");
List<RoutingDetailEquip> finalRoutingDetailEquips = routingDetailEquips;
Integer departmentId = headers1.getDepartmentId() != null ? headers1.getDepartmentId() : null;
List<ProdProcessExec> processExecList = RoutingDetails.stream()
.map(detail -> lanuchService.createProcessExec(prodOrderMain, detail, sceneId, finalRoutingDetailEquips))
.map(detail -> lanuchService.createProcessExec(prodOrderMain, detail, sceneId, finalRoutingDetailEquips, departmentId))
.collect(Collectors.toList());
List<Equipinfo> equipinfoList = equipinfoService.lambdaQuery().eq(Equipinfo::getIsdeleted, 0).list();
List<ProdEquipment> ProdEquipmentList= lanuchService.batchInsertEquipMent(routingDetailEquips, sceneId,processExecList,false,equipinfoList);
......
......@@ -217,6 +217,9 @@ public class RoutingDataService {
entry.setRoutingDetailId(op.getRoutingDetailId());
entry.setTaskSeq(op.getTaskSeq());
entry.setRoutingDetailName(op.getRoutingDetailName());
if (op.getDepartmentId() != null) {
entry.setDepartmentId(op.getDepartmentId());
}
entry.setIsInterrupt(op.getCanInterrupt());
Order order = ProdLaunchOrders.stream()
.filter(t -> t.getOrderId().equals(op.getOrderId()))
......
......@@ -46,7 +46,8 @@ public interface LanuchService {
ProdProcessExec createProcessExec(ProdLaunchOrder prodOrderMain,
RoutingDetail detail,
String sceneId,List<RoutingDetailEquip> routingDetailEquip);
String sceneId, List<RoutingDetailEquip> routingDetailEquip,
Integer departmentId);
List<ProdEquipment> batchInsertEquipMent(
List<RoutingDetailEquip> routingDetailEquips,
......
......@@ -30,6 +30,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.math.RoundingMode;
import java.time.LocalDateTime;
......@@ -65,6 +66,12 @@ public class ChromosomeDataService {
@Autowired
private PlanResultService planResultService;
/**
* 字段注释缓存,避免重复读取源文件
*/
private final ConcurrentHashMap<Class<?>, Map<String, String>> fieldCommentCache = new ConcurrentHashMap<>();
/**
* 根据场景ID和实体名称查询Chromosome中的数据
*/
......@@ -326,7 +333,7 @@ public class ChromosomeDataService {
}
// 获取字段描述映射
Map<String, String> fieldDescriptions = getFieldDescriptions(entityName);
Map<String, String> fieldDescriptions = new HashMap<>();
// 遍历字段,生成FieldInfo
for (Field field : fields) {
......@@ -441,7 +448,6 @@ public class ChromosomeDataService {
return fieldInfos;
}
/**
* 获取实体对应的Java类
* @param entityName 实体名称
......@@ -464,6 +470,7 @@ public class ChromosomeDataService {
return entityClassMap.get(entityName.toLowerCase());
}
/**
* 将数据库字段类型转换为Java类型
* @param dbType 数据库字段类型
......@@ -490,6 +497,7 @@ public class ChromosomeDataService {
return typeMap.getOrDefault(dbType.toUpperCase(), dbType);
}
/**
* 获取指定实体的字段描述映射
* @param entityName 实体名称
......@@ -814,7 +822,8 @@ public class ChromosomeDataService {
}
}
return (List<Object>) (List<?>) resultMachineOptions;
List<Object> listResult = (List<Object>) (List<?>) resultMachineOptions;
return applyGroupAndFieldsToList(listResult, paged);
} else {
return new ArrayList<>();
}
......@@ -840,20 +849,38 @@ public class ChromosomeDataService {
// 应用排序
List<Object> sortedData = sortData(resultOrders, paged);
return sortedData;
return applyGroupAndFieldsToList(sortedData, paged);
} else {
return new ArrayList<>();
}
} else {
Object data = queryFileData(sceneId, config);
return applyConditionsToList(data, paged, entityName);
List<Object> listResult = applyConditionsToList(data, paged, entityName);
return applyGroupAndFieldsToList(listResult, paged);
}
} else {
// 数据库查询
// 数据库查询(已支持 groupName、fields)
return databaseQueryService.queryDatabaseDataList(config, paged);
}
}
/**
* List 接口统一应用 groupName、fields:先分组(若有)再投影(若有)。
*/
private List<Object> applyGroupAndFieldsToList(List<?> dataList, Paged paged) {
if (dataList == null) {
return new ArrayList<>();
}
List<?> result = new ArrayList<>(dataList);
if (paged.getGroupName() != null && !paged.getGroupName().trim().isEmpty()) {
result = groupListByFields(result, paged.getGroupName());
}
if (paged.getFields() != null && !paged.getFields().trim().isEmpty()) {
result = projectListToFields(result, paged.getFields());
}
return (List<Object>) result;
}
/**
* 根据ID查询单条数据
*/
......@@ -1144,6 +1171,12 @@ public class ChromosomeDataService {
if (data instanceof List) {
List<?> dataList = (List<?>) data;
if (paged.getGroupName() != null && !paged.getGroupName().trim().isEmpty()) {
dataList = groupListByFields(dataList, paged.getGroupName());
}
if (paged.getFields() != null && !paged.getFields().trim().isEmpty()) {
dataList = projectListToFields(dataList, paged.getFields());
}
int total = dataList.size();
int fromIndex = (page - 1) * size;
......@@ -1321,6 +1354,115 @@ public class ChromosomeDataService {
}
}
/**
* 按 fields 只保留指定字段,返回 List<Map>,每个 Map 仅含 fields 中的列(key 小写)。
* fields 格式如 "id,name";若项已是 Map 则按 key 过滤,否则按实体反射取字段值。
*/
private List<Object> projectListToFields(List<?> dataList, String fields) {
if (CollectionUtils.isEmpty(dataList) || fields == null || fields.trim().isEmpty()) {
return new ArrayList<>(dataList);
}
List<String> fieldNames = Arrays.stream(fields.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
if (fieldNames.isEmpty()) {
return new ArrayList<>(dataList);
}
List<Object> result = new ArrayList<>();
for (Object item : dataList) {
Map<String, Object> row = new LinkedHashMap<>();
if (item instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> m = (Map<String, Object>) item;
for (String fn : fieldNames) {
Object val = null;
for (Map.Entry<String, Object> e : m.entrySet()) {
if (e.getKey() != null && e.getKey().equalsIgnoreCase(fn)) {
val = e.getValue();
break;
}
}
row.put(fn.toLowerCase(), val);
}
} else {
try {
for (String fn : fieldNames) {
Field field = getFieldIgnoreCase(item.getClass(), fn);
if (field != null) {
field.setAccessible(true);
row.put(fn.toLowerCase(), field.get(item));
}
}
} catch (Exception e) {
log.warn("投影字段失败 fields={}", fieldNames, e);
}
}
result.add(row);
}
return result;
}
/**
* 按 groupName 对列表做内存分组,返回分组列 + count(每组条数)。
* groupName 格式如 "id,name",返回 List<Map>,每个 Map 含分组字段(小写 key)+ "count"。
*/
private List<Object> groupListByFields(List<?> dataList, String groupName) {
if (CollectionUtils.isEmpty(dataList) || groupName == null || groupName.trim().isEmpty()) {
return new ArrayList<>(dataList);
}
List<String> fieldNames = Arrays.stream(groupName.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
if (fieldNames.isEmpty()) {
return new ArrayList<>(dataList);
}
Map<String, Long> countByKey = new LinkedHashMap<>();
List<List<Object>> keyOrder = new ArrayList<>();
for (Object item : dataList) {
List<Object> key = new ArrayList<>();
try {
for (String fn : fieldNames) {
Field field = getFieldIgnoreCase(item.getClass(), fn);
if (field != null) {
field.setAccessible(true);
key.add(field.get(item));
} else {
key.add(null);
}
}
} catch (Exception e) {
log.warn("分组取字段失败 fieldNames={}", fieldNames, e);
continue;
}
String keyStr = key.stream()
.map(v -> v == null ? "" : v.toString())
.collect(Collectors.joining("\u0000"));
if (!countByKey.containsKey(keyStr)) {
keyOrder.add(key);
}
countByKey.merge(keyStr, 1L, Long::sum);
}
List<Object> result = new ArrayList<>();
for (List<Object> key : keyOrder) {
String keyStr = key.stream()
.map(v -> v == null ? "" : v.toString())
.collect(Collectors.joining("\u0000"));
Long count = countByKey.get(keyStr);
Map<String, Object> row = new LinkedHashMap<>();
for (int i = 0; i < fieldNames.size(); i++) {
row.put(fieldNames.get(i).toLowerCase(), key.get(i));
}
row.put("count", count != null ? count : 0L);
result.add(row);
}
return result;
}
/**
* 根据条件过滤数据(文件数据使用)- 修复版本
*/
......@@ -2149,6 +2291,9 @@ public class ChromosomeDataService {
// 其他字段根据需要进行映射
prodProcessExec.setCanInterrupt(entry.getIsInterrupt());
prodProcessExec.setRoutingId(entry.getRoutingId());
if (entry.getDepartmentId() != null) {
prodProcessExec.setDepartmentId(entry.getDepartmentId());
}
return prodProcessExec;
}
......
......@@ -233,6 +233,14 @@ public class LanuchServiceImpl implements LanuchService {
throw new RuntimeException("插入mes_order失败");
}
// 构建 orderId -> mes_order.id 映射,供 dispatch 的 PART_TASK_READY_ID 使用
List<String> orderIds = prodLanuchList.stream().map(Order::getOrderId).distinct().collect(Collectors.toList());
List<MesOrder> savedMesOrders = mesOrderService.lambdaQuery()
.in(MesOrder::getMesCode, orderIds)
.list();
Map<String, Long> mesOrderIdByOrderId = savedMesOrders.stream()
.collect(Collectors.toMap(MesOrder::getMesCode, MesOrder::getId, (a, b) -> a));
// List<ProdProcessExec> processExecList = prodProcessExecService.lambdaQuery()
// .eq(ProdProcessExec::getSceneId, sceneId)
// .list();
......@@ -261,7 +269,13 @@ public class LanuchServiceImpl implements LanuchService {
dispatch.setOpe(entry1.getRoutingDetailName());
dispatch.setRoutingDetailId(entry1.getRoutingDetailId());
dispatch.setStatus(12L);
// PART_TASK_READY_ID:取对应 mes_order 的主键 id(按 orderId/mesCode 关联)
Long partTaskReadyId = mesOrderIdByOrderId.get(gaResult.getOrderId());
if (partTaskReadyId != null) {
dispatch.setPartTaskReadyId(partTaskReadyId);
}
dispatch.setShopid(entry1.getDepartmentId());
// 添加到列表中
dispatches.add(dispatch);
}
......@@ -561,8 +575,9 @@ public class LanuchServiceImpl implements LanuchService {
List<RoutingDetail> routingDetails = getRoutingDetails(routingHeader.getId());
List<RoutingDetailEquip> routingDetailEquip = getRoutingDetailEquip(routingHeader.getId(),routingHeader.getCode());
// 批量插入新的工序工单记录
batchInsertProcessExec(prodOrderMain, routingDetails, sceneId,routingDetailEquip);
// 批量插入新的工序工单记录(部门ID从工艺头带出)
Integer departmentId = routingHeader.getDepartmentId() != null ? routingHeader.getDepartmentId() : null;
batchInsertProcessExec(prodOrderMain, routingDetails, sceneId, routingDetailEquip, departmentId);
return true;
}
......@@ -644,9 +659,10 @@ public class LanuchServiceImpl implements LanuchService {
*/
public void batchInsertProcessExec(ProdLaunchOrder prodOrderMain,
List<RoutingDetail> routingDetails,
String sceneId, List<RoutingDetailEquip> routingDetailEquip) {
String sceneId, List<RoutingDetailEquip> routingDetailEquip,
Integer departmentId) {
List<ProdProcessExec> processExecList = routingDetails.stream()
.map(detail -> createProcessExec(prodOrderMain, detail, sceneId,routingDetailEquip))
.map(detail -> createProcessExec(prodOrderMain, detail, sceneId, routingDetailEquip, departmentId))
.collect(Collectors.toList());
List<Equipinfo> list = equipinfoService.lambdaQuery().eq(Equipinfo::getIsdeleted, 0).list();
......@@ -673,7 +689,8 @@ public class LanuchServiceImpl implements LanuchService {
*/
public ProdProcessExec createProcessExec(ProdLaunchOrder prodOrderMain,
RoutingDetail detail,
String sceneId,List<RoutingDetailEquip> routingDetailEquip) {
String sceneId, List<RoutingDetailEquip> routingDetailEquip,
Integer departmentId) {
ProdProcessExec prodProcessExec = new ProdProcessExec();
prodProcessExec.setExecId(UUID.randomUUID().toString().replace("-", ""));
......@@ -726,7 +743,9 @@ public class LanuchServiceImpl implements LanuchService {
prodProcessExec.setRoutingCode(prodOrderMain.getRoutingCode());
prodProcessExec.setConnectPropertyName(detail.getConnectPropertyName());
prodProcessExec.setCanInterrupt(detail.getCanInterrupt());
if (departmentId != null) {
prodProcessExec.setDepartmentId(departmentId);
}
prodProcessExec.setSpeed(
Optional.ofNullable(detail.getRuntime())
......
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