1、EsUtil支持堆栈输出;2、新增cad拆单到es数据sortId;3、cad各项阈值配置支持动态刷新;

This commit is contained in:
gaoqr
2025-06-04 17:05:47 +08:00
parent 8370b873cf
commit 9418535151
9 changed files with 189 additions and 52 deletions
@@ -116,4 +116,6 @@ public class OrderModelDO extends ESDocument {
private String remarkJson; // 普通备注(板材数据中)
@Schema(description = "特殊备注(板材数据中)")
private String specialRemark; // 特殊备注(板材数据中)
private Long sortId;
}
@@ -3,8 +3,10 @@ package com.cf.imes.module.executor.service.optimizeplan;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.PageUtil;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
import co.elastic.clients.elasticsearch._types.FieldValue;
import co.elastic.clients.elasticsearch._types.SortOrder;
import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
import co.elastic.clients.elasticsearch.core.SearchRequest;
@@ -14,6 +16,7 @@ import co.elastic.clients.elasticsearch.core.search.Hit;
import co.elastic.clients.elasticsearch.sql.TranslateRequest;
import co.elastic.clients.elasticsearch.sql.TranslateResponse;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.JsonpMappingException;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -785,7 +788,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
for (PlateDetailRespVO plateDetailsRespVO : plateDetailRespVOS) {
StringBuilder name = new StringBuilder();
if(!plateDetailsRespVO.getProcessGroupLists().isEmpty()) {
if (CollUtil.isNotEmpty(plateDetailsRespVO.getProcessGroupLists())) {
for (ProcessGroupList groupNameList : plateDetailsRespVO.getProcessGroupLists()) {
// 去除最后的逗号
name.append(groupNameList.getGroupName()).append(",");
@@ -799,7 +802,7 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
// todo 数据结构改后,可以增加排单ID作为筛选,只查为 0 的
List<OrderModelDO> orderModelDOS = esUtils.getEsDocumentByScroll(FIELD_ORDER_ID, orderIds, 1000, ORDER_PLATE_MODEL.getIndex(), OrderModelDO.class);
List<OrderModelDO> orderModelDOS = getOrderModels(orderIds);
AssertUtils.notEmpty(plateDetailRespVOS,ORDER_PLATE_MODEL_DATE_ERROR);
@@ -812,6 +815,78 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
}
/**
* 分页获取生产单ids下的es.orderModels数据
*
* @param orderIds
* @return
*/
private List<OrderModelDO> getOrderModels(List<Long> orderIds) {
List<OrderModelDO> results = new ArrayList<>();
try {
// 查询总数
SearchRequest totalRequest = new SearchRequest.Builder()
.index(ORDER_PLATE_MODEL.getIndex())
.size(0) // 不返回文档,仅统计总数
.query(q -> q.bool(b -> b
.filter(f -> f.terms(t -> t
.field("orderId")
.terms(e -> e.value(orderIds.stream().map(FieldValue::of).toList()))
))
))
.build();
SearchResponse<Void> totalResponse = elasticsearchClient.search(totalRequest, Void.class);
long total = totalResponse.hits().total().value();
// 分页查询
int pageNum = PageUtil.totalPage(total, 5000);
FieldValue searchAfterSortId = FieldValue.of(1);
for (int page = 1; page <= pageNum; page++) {
SearchRequest.Builder searchBuilder = new SearchRequest.Builder()
.index(ORDER_PLATE_MODEL.getIndex())
.size(5000)
.sort(s -> s.field(f -> f.field("sortId").order(SortOrder.Asc)))
.query(q -> q.bool(b -> b
.filter(f -> f.terms(t -> t.field("orderId").terms(e -> e.value(orderIds.stream().map(FieldValue::of).toList()))))
));
searchBuilder.searchAfter(searchAfterSortId);
SearchResponse<OrderModelDO> response = elasticsearchClient.search(searchBuilder.build(), OrderModelDO.class);
List<Hit<OrderModelDO>> hits = response.hits().hits();
for (Hit<OrderModelDO> hit : hits) {
results.add(hit.source());
}
// 取最后一个命中文档的 sortId 作为下一页的 search_after 值
if (!hits.isEmpty()) {
OrderModelDO lastDoc = hits.get(hits.size() - 1).source();
if (lastDoc != null) {
searchAfterSortId = FieldValue.of(lastDoc.getSortId());
} else {
// 没有更多数据了
break;
}
} else {
// 已经到最后一页
break;
}
}
return results;
} catch (JsonpMappingException e) {
log.error(e.getMessage(), e);
throw new ServiceException(ORDER_DATA_ERROR);
} catch (IOException | ElasticsearchException e) {
log.error(e.getMessage(), e);
throw new ServiceException(DATA_DATA_ERROR);
}
}
@@ -76,10 +76,10 @@ public class EsUtils {
}
return new ArrayList<>();
}catch (JsonpMappingException e){
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(ORDER_DATA_ERROR);
}catch (IOException | ElasticsearchException e) {
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(DATA_DATA_ERROR);
}
}
@@ -101,10 +101,10 @@ public class EsUtils {
}
return new ArrayList<>();
}catch (JsonpMappingException e){
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(ORDER_DATA_ERROR);
} catch (IOException | ElasticsearchException e) {
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(DATA_DATA_ERROR);
}
}
@@ -131,10 +131,10 @@ public class EsUtils {
}
return new ArrayList<>();
}catch (JsonpMappingException e){
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(ORDER_DATA_ERROR);
}catch (IOException | ElasticsearchException e) {
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(DATA_DATA_ERROR);
}
}
@@ -157,10 +157,10 @@ public class EsUtils {
}
return new ArrayList<>();
}catch (JsonpMappingException e){
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(ORDER_DATA_ERROR);
}catch (IOException | ElasticsearchException e) {
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(DATA_DATA_ERROR);
}
}
@@ -187,10 +187,10 @@ public class EsUtils {
}
return new ArrayList<>();
}catch (JsonpMappingException e){
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(ORDER_DATA_ERROR);
}catch (IOException | ElasticsearchException e) {
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(DATA_DATA_ERROR);
}
}
@@ -217,10 +217,10 @@ public class EsUtils {
}
return new ArrayList<>();
}catch (JsonpMappingException e){
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(ORDER_DATA_ERROR);
}catch (IOException | ElasticsearchException e) {
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(DATA_DATA_ERROR);
}
}
@@ -247,10 +247,10 @@ public class EsUtils {
}
return new ArrayList<>();
}catch (JsonpMappingException e){
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(ORDER_DATA_ERROR);
}catch (IOException | ElasticsearchException e) {
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(DATA_DATA_ERROR);
}
}
@@ -282,10 +282,10 @@ public class EsUtils {
}
return new ArrayList<>();
}catch (JsonpMappingException e){
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(ORDER_DATA_ERROR);
}catch (IOException | ElasticsearchException e) {
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(DATA_DATA_ERROR);
}
@@ -318,10 +318,10 @@ public class EsUtils {
}
return new ArrayList<>();
}catch (JsonpMappingException e){
log.error(e.getMessage());
log.error(e.getMessage(), e);
throw new ServiceException(ORDER_DATA_ERROR);
}catch (IOException | ElasticsearchException e) {
log.error(e.getMessage());
} catch (IOException | ElasticsearchException e) {
log.error(e.getMessage(), e);
throw new ServiceException(DATA_DATA_ERROR);
}
}