From d7001b28850f98c06a077d59d637103b2100dba5 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 17 三月 2026 11:13:40 +0800
Subject: [PATCH] fix: 调整定时任务时间、移除反射获取同步日期、物料类型同步数据存在类型不对应问题、新增更新修改为批次保存
---
src/main/java/com/ruoyi/production/task/ProductMaterialTask.java | 2 +-
src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java | 32 +++++++++++++++++++++-----------
src/main/java/com/ruoyi/productionPlan/task/ProductionPlanTask.java | 2 +-
src/main/java/com/ruoyi/framework/util/AliDingUtils.java | 19 ++++++-------------
4 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/src/main/java/com/ruoyi/framework/util/AliDingUtils.java b/src/main/java/com/ruoyi/framework/util/AliDingUtils.java
index bd1eea7..cfa260e 100644
--- a/src/main/java/com/ruoyi/framework/util/AliDingUtils.java
+++ b/src/main/java/com/ruoyi/framework/util/AliDingUtils.java
@@ -152,22 +152,15 @@
LambdaQueryWrapper<T> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(timeField).last("LIMIT 1");
T lastRecord = service.getOne(queryWrapper);
+
if (lastRecord == null) {
return null;
}
- try {
- Method writeReplace = timeField.getClass().getDeclaredMethod("writeReplace");
- writeReplace.setAccessible(true);
- SerializedLambda lambda = (SerializedLambda) writeReplace.invoke(timeField);
- // 鑾峰彇鏂规硶鍚�
- String methodName = lambda.getImplMethodName();
- // 杞瓧娈靛悕
- String fieldName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
- Field field = lastRecord.getClass().getDeclaredField(fieldName);
- field.setAccessible(true);
- return (LocalDateTime) field.get(lastRecord);
- } catch (Exception e) {
- throw new RuntimeException("鑾峰彇鏈�鍚庡悓姝ユ椂闂村け璐�", e);
+ Object value = timeField.apply(lastRecord);
+
+ if (value instanceof LocalDateTime) {
+ return (LocalDateTime) value;
}
+ return null;
}
}
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
index 6fc0783..1336736 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
@@ -82,8 +82,6 @@
}
try {
-
-
JSONArray searchConditions = new JSONArray();
JSONObject statusCondition = new JSONObject();
statusCondition.put("key", "processInstanceStatus");
@@ -148,6 +146,9 @@
material.setRemark(formData.getString("textareaField_l92f36f9"));
String materialType = formData.getString("selectField_l92f36fb");
+ if ("鏉挎潗".equals(materialType) || "鐮屽潡".equals(materialType) || "鏍囩爾".equals(materialType)) {
+ materialType = "鎴愬搧";
+ }
String inventoryCat = formData.getString("selectField_la154noy");
material.setMaterialTypeId(getOrCreateConfigId(materialType, MaterialConfigTypeEnum.MATERIAL_TYPE.name()));
material.setInventoryCategoryId(getOrCreateConfigId(inventoryCat, MaterialConfigTypeEnum.INVENTORY_CAT.name()));
@@ -224,10 +225,11 @@
if (list == null || list.isEmpty()) {
return 0;
}
- int affected = 0;
+
+ List<ProductMaterialSku> toSave = new ArrayList<>();
+ List<ProductMaterialSku> toUpdate = new ArrayList<>();
for (ProductMaterialSku sku : list) {
-
LambdaQueryWrapper<ProductMaterialSku> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ProductMaterialSku::getProductId, sku.getProductId())
.eq(ProductMaterialSku::getModel, sku.getModel());
@@ -240,20 +242,28 @@
ProductMaterialSku exist = productMaterialSkuService.getOne(wrapper);
if (exist == null) {
- productMaterialSkuService.save(sku);
- affected++;
- log.info("鏂板鐗╂枡瑙勬牸 {}", sku.getModel());
+ toSave.add(sku);
} else {
if (exist.getFormModifiedTime() == null || !exist.getFormModifiedTime().equals(sku.getFormModifiedTime())) {
sku.setId(exist.getId());
sku.setCreateTime(exist.getCreateTime());
- productMaterialSkuService.updateById(sku);
-
- affected++;
- log.info("鏇存柊鐗╂枡瑙勬牸 {}", sku.getModel());
+ toUpdate.add(sku);
}
}
}
+
+ int affected = 0;
+ if (!toSave.isEmpty()) {
+ productMaterialSkuService.saveBatch(toSave);
+ affected += toSave.size();
+ log.info("鎵归噺鏂板鐗╂枡瑙勬牸 {} 鏉�", toSave.size());
+ }
+ if (!toUpdate.isEmpty()) {
+ productMaterialSkuService.updateBatchById(toUpdate);
+ affected += toUpdate.size();
+ log.info("鎵归噺鏇存柊鐗╂枡瑙勬牸 {} 鏉�", toUpdate.size());
+ }
+
return affected;
}
diff --git a/src/main/java/com/ruoyi/production/task/ProductMaterialTask.java b/src/main/java/com/ruoyi/production/task/ProductMaterialTask.java
index aa65f38..4e6b523 100644
--- a/src/main/java/com/ruoyi/production/task/ProductMaterialTask.java
+++ b/src/main/java/com/ruoyi/production/task/ProductMaterialTask.java
@@ -20,7 +20,7 @@
@Autowired
private ProductMaterialService productMaterialService;
- @Scheduled(cron = "0 0 * * * ?")
+ @Scheduled(cron = "0 0 0 * * ?")
public void syncProdDataJob() {
productMaterialService.syncProductMaterialJob();
}
diff --git a/src/main/java/com/ruoyi/productionPlan/task/ProductionPlanTask.java b/src/main/java/com/ruoyi/productionPlan/task/ProductionPlanTask.java
index 4e91c43..4d01b3f 100644
--- a/src/main/java/com/ruoyi/productionPlan/task/ProductionPlanTask.java
+++ b/src/main/java/com/ruoyi/productionPlan/task/ProductionPlanTask.java
@@ -23,7 +23,7 @@
@Autowired
private ProductionPlanService productionPlanService;
- @Scheduled(cron = "0 0 * * * ?")
+ @Scheduled(cron = "0 0 0 * * ?")
public void syncProdDataJob() {
productionPlanService.syncProdDataJob();
}
--
Gitblit v1.9.3