新增webcad生产单导入:1、封边条非必须对应修复;2、es回滚批次数据增加异步两次等待删除;3、多次拆单已有板材对应处理;

This commit is contained in:
gaoqr
2025-03-20 11:07:33 +08:00
parent 2f1478688c
commit 0bf1ebd5f1
2 changed files with 100 additions and 58 deletions
@@ -92,14 +92,32 @@ public class OrderInputProcessor {
public void deleteByOrderIdBatch(Long orderId, Long batchId, String index) { public void deleteByOrderIdBatch(Long orderId, Long batchId, String index) {
DeleteByQueryRequest.Builder builder = new DeleteByQueryRequest.Builder(); DeleteByQueryRequest.Builder builder = new DeleteByQueryRequest.Builder();
builder.index(index); builder.index(index);
builder.query(q -> q.term(t -> t.field(FIELD_ORDER_ID).value(orderId))); builder.query(q -> q.bool(b -> b
builder.query(q -> q.term(t -> t.field(FIELD_BATCH_ID).value(batchId))); .must(must -> must.term(t -> t.field(FIELD_ORDER_ID).value(orderId)))
.must(must -> must.term(t -> t.field(FIELD_BATCH_ID).value(batchId)))
));
try { try {
DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(builder.build()); DeleteByQueryRequest deleteBuild = builder.build();
log.info("Deleted {} documents with planId {}", response.deleted(), orderId); // es刚插入有可能无法马上查询删除(默认1s的可见时间),线程每1s删除一次,再删除两次
DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(deleteBuild);
if (response.deleted() == 0) {
for (int i = 0; i < 2; i++) {
response = elasticsearchClient.deleteByQuery(deleteBuild);
// 删除成功,不再继续
if (response.deleted() > 0) {
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.error("====================【线程中断异常】====================");
}
}
}
log.info("Deleted {} documents with orderId {}", response.deleted(), orderId);
} catch (IOException | ElasticsearchException e) { } catch (IOException | ElasticsearchException e) {
log.error("Error deleting documents with planId {}: {}", orderId, e.getMessage()); log.error("Error deleting documents with orderId {}: {}", orderId, e.getMessage());
throw new ServiceException(INTERNAL_SERVER_ERROR); throw new ServiceException(INTERNAL_SERVER_ERROR);
} }
} }
@@ -60,6 +60,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@@ -127,6 +128,9 @@ public class WebCadOrderImportFactory {
// 是否入库的第一块板件 // 是否入库的第一块板件
private boolean isFirstPlate; private boolean isFirstPlate;
// 是否有插入es数据
private boolean esInsert;
private CustomPlateNoGenerateConfigVO plateNoGenerateConfigVO; private CustomPlateNoGenerateConfigVO plateNoGenerateConfigVO;
// 操作人 // 操作人
@@ -221,8 +225,12 @@ public class WebCadOrderImportFactory {
saveData(); saveData();
} catch (Exception e) { } catch (Exception e) {
if (esInsert) {
CompletableFuture.runAsync(() -> {
// 数据库数据回滚,此时删除 ES 里的数据 // 数据库数据回滚,此时删除 ES 里的数据
orderInputProcessor.deleteByOrderIdBatch(orderId, batchId, ORDER_PLATE_MODEL); orderInputProcessor.deleteByOrderIdBatch(orderId, batchId, ORDER_PLATE_MODEL);
});
}
throw e; throw e;
} finally { } finally {
// 清理数据 // 清理数据
@@ -269,9 +277,19 @@ public class WebCadOrderImportFactory {
String plateGoodsId = materialReqVO.getId(); String plateGoodsId = materialReqVO.getId();
String plateGoodsGoodsId = materialReqVO.getGoodsId(); String plateGoodsGoodsId = materialReqVO.getGoodsId();
PlateGoodDO plateGoodDO = plateGoodMapper.selectById(plateGoodsId); PlateGoodDO plateGoodDO = plateGoodMapper.selectById(plateGoodsId);
// 检查板材库
if (ObjectUtil.isNull(plateGoodDO)) { if (ObjectUtil.isNull(plateGoodDO)) {
throw ServiceExceptionUtil.exception(WEBCAD_ORDER_IMPORT_PLATE_NOT_EXIST_ERROR, plateGoodsId); throw ServiceExceptionUtil.exception(WEBCAD_ORDER_IMPORT_PLATE_NOT_EXIST_ERROR, plateGoodsId);
} }
// 检查生产单下是否已经有板材下的order_goods,有不再创建
List<GoodsDO> existOrderGoods = goodsMapper.selectList(new LambdaUpdateWrapper<GoodsDO>()
.eq(GoodsDO::getGoodsId, plateGoodsGoodsId)
.eq(GoodsDO::getOrderId, orderId)
.eq(GoodsDO::getOrganId, organId));
Long orderGoodsId;
if (CollUtil.isNotEmpty(existOrderGoods)) {
orderGoodsId = existOrderGoods.get(0).getId();
} else {
// 创建设计端商品 // 创建设计端商品
Long rawGoodsId = (Long) snowFlakeGenerator.nextId(null); Long rawGoodsId = (Long) snowFlakeGenerator.nextId(null);
RawGoodsDO rawGoodsDO = RawGoodsDO.builder() RawGoodsDO rawGoodsDO = RawGoodsDO.builder()
@@ -290,7 +308,7 @@ public class WebCadOrderImportFactory {
.deleted(false) .deleted(false)
.organId(organId) .organId(organId)
.build(); .build();
Long orderGoodsId = (Long) snowFlakeGenerator.nextId(null); orderGoodsId = (Long) snowFlakeGenerator.nextId(null);
// 创建生产单商品 // 创建生产单商品
GoodsDO goodsDO = GoodsDO.builder() GoodsDO goodsDO = GoodsDO.builder()
@@ -317,6 +335,7 @@ public class WebCadOrderImportFactory {
goodsDOS.add(goodsDO); goodsDOS.add(goodsDO);
rawGoodsDOS.add(rawGoodsDO); rawGoodsDOS.add(rawGoodsDO);
}
for (Integer blockIndex : materialReqVO.getOrginIds()) { for (Integer blockIndex : materialReqVO.getOrginIds()) {
// blockIndex序号获取对应板件a // blockIndex序号获取对应板件a
WebCadDataBlockReqVO webCadDataBlockReqVO = blockReqVOS.get(blockIndex - 1); WebCadDataBlockReqVO webCadDataBlockReqVO = blockReqVOS.get(blockIndex - 1);
@@ -631,6 +650,9 @@ public class WebCadOrderImportFactory {
orderModelDO.setCreator(operatorName); orderModelDO.setCreator(operatorName);
orderModelDO.setUpdater(operatorName); orderModelDO.setUpdater(operatorName);
orderModelDOS.add(orderModelDO); orderModelDOS.add(orderModelDO);
if (!esInsert) {
esInsert = true;
}
// 批量插入造型数据 // 批量插入造型数据
orderModelsBatchInsertWithinThreshold(false); orderModelsBatchInsertWithinThreshold(false);
@@ -999,6 +1021,7 @@ public class WebCadOrderImportFactory {
if (PART_CATEGORY_ONE.equals(partType)) { if (PART_CATEGORY_ONE.equals(partType)) {
// 封边对应查询配件库中的封边条配件,使用配件库的model、spec、brand、factory // 封边对应查询配件库中的封边条配件,使用配件库的model、spec、brand、factory
String sealPartId = part.getPartId(); String sealPartId = part.getPartId();
if (ObjectUtil.isNotNull(sealPartId)) {
PartsDO partsDO = partsMapper.selectById(sealPartId); PartsDO partsDO = partsMapper.selectById(sealPartId);
if (ObjectUtil.isNotNull(partsDO)) { if (ObjectUtil.isNotNull(partsDO)) {
model = partsDO.getModel(); model = partsDO.getModel();
@@ -1009,6 +1032,7 @@ public class WebCadOrderImportFactory {
throw ServiceExceptionUtil.exception(WEBCAD_ORDER_IMPORT_SEAL_NOT_EXIST_ERROR, sealPartId); throw ServiceExceptionUtil.exception(WEBCAD_ORDER_IMPORT_SEAL_NOT_EXIST_ERROR, sealPartId);
} }
} }
}
String type = changePartType(partType, part.getIsComposite()); String type = changePartType(partType, part.getIsComposite());
String goodsId = part.getGoodsId(); String goodsId = part.getGoodsId();