From 00a44859a673b388e1dca5f54c4ecaffc5fee30e Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期四, 19 三月 2026 10:21:08 +0800
Subject: [PATCH] lsh#0:新增、更新、解禁(只要调用了更新,就代表非禁用了)  1:禁用

---
 rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java |  126 ++++++++++++++++++++++++++++++++++--------
 1 files changed, 102 insertions(+), 24 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java
index 68ce40f..2f739e4 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java
@@ -207,7 +207,6 @@
     @Override
     @Transactional(timeout = 60, rollbackFor = Exception.class)
     public void syncMatnrs(List<BaseMatParms> matnrs) {
-        List<Matnr> syncMatnrs = new ArrayList<>();
         if (!matnrs.isEmpty()) {
             matnrs.forEach(matnr -> {
                 Matnr mat = new Matnr();
@@ -222,12 +221,23 @@
                         mat.setGroupCode(matnrGroup.getCode()).setGroupId(matnrGroup.getId());
                     }
                 }
-                syncMatnrs.add(mat);
-            });
+                Matnr exist = matnrService.getOne(new LambdaQueryWrapper<Matnr>()
+                        .eq(Matnr::getCode, matnr.getMatnr())
+                        .last("limit 1"));
 
-            if (!matnrService.saveOrUpdateBatch(syncMatnrs)) {
-                throw new CoolException("鐗╂枡淇℃伅淇濆瓨鎴愬姛锛侊紒");
-            }
+                mat.setStatus(Objects.isNull(matnr.getOperateType()) ? 1 : (matnr.getOperateType() == 1 ? 0 : 1));
+                if (!Objects.isNull(exist)) {
+                    mat.setId(exist.getId());
+                    if (!matnrService.saveOrUpdate(mat)) {
+                        throw new CoolException("鐗╂枡淇℃伅鏇存柊澶辫触锛侊紒");
+                    }
+                } else {
+                    mat.setId(null);
+                    if (!matnrService.save(mat)) {
+                        throw new CoolException("鐗╂枡淇℃伅淇濆瓨澶辫触锛侊紒");
+                    }
+                }
+            });
         }
     }
 
@@ -307,7 +317,8 @@
     @Override
     @Transactional(timeout = 60, rollbackFor = Exception.class)
     public R syncMatGroups(List<SyncMatGroupsParams> matGroupsParams) {
-        List<MatnrGroup> syncMatGroups = new ArrayList<>();
+        final int[] insertCount = {0};
+        final int[] updateCount = {0};
         matGroupsParams.forEach(matGroupsParam -> {
             MatnrGroup matnrGroup = new MatnrGroup();
             BeanUtils.copyProperties(matGroupsParam, matnrGroup);
@@ -320,12 +331,36 @@
             if (Objects.isNull(matGroupsParam.getParCode())) {
                 throw new CoolException("涓婄骇鐗╂枡鍒嗙粍缂栫爜涓嶈兘涓虹┖锛侊紒");
             }
-            syncMatGroups.add(matnrGroup);
+
+            // 骞傜瓑鍚屾锛氫紭鍏堟寜缂栫爜鍖归厤锛屾壘涓嶅埌鍐嶆寜鍚嶇О鍖归厤
+            MatnrGroup one = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>()
+                    .eq(MatnrGroup::getCode, matGroupsParam.getCode())
+                    .last("limit 1"));
+            if (Objects.isNull(one)) {
+                one = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>()
+                        .eq(MatnrGroup::getName, matGroupsParam.getName())
+                        .last("limit 1"));
+            }
+
+            if (!Objects.isNull(one)) {
+                matnrGroup.setId(one.getId());
+                if (!matnrGroupService.saveOrUpdate(matnrGroup)) {
+                    throw new CoolException("鐗╂枡鍒嗙粍鏇存柊澶辫触锛侊紒");
+                }
+                updateCount[0]++;
+            } else {
+                matnrGroup.setId(null);
+                if (!matnrGroupService.save(matnrGroup)) {
+                    throw new CoolException("鐗╂枡鍒嗙粍淇濆瓨澶辫触锛侊紒");
+                }
+                insertCount[0]++;
+            }
         });
-        if (!matnrGroupService.saveBatch(syncMatGroups)) {
-            throw new CoolException("鐗╂枡鍒嗙粍淇濆瓨澶辫触锛侊紒");
-        }
-        return R.ok();
+        Map<String, Object> result = new HashMap<>();
+        result.put("total", matGroupsParams.size());
+        result.put("insertCount", insertCount[0]);
+        result.put("updateCount", updateCount[0]);
+        return R.ok(result);
     }
 
     /**
@@ -337,23 +372,45 @@
     @Override
     @Transactional(timeout = 60, rollbackFor = Exception.class)
     public R syncWarehouseAreas(List<LocAreasParams> areasParams) {
+        final int[] insertCount = {0};
+        final int[] updateCount = {0};
         areasParams.forEach(param -> {
             WarehouseAreas locArea = new WarehouseAreas();
             BeanUtils.copyProperties(param, locArea);
-            WarehouseAreas warehouseAreas = warehouseAreasService
-                    .getOne(new LambdaQueryWrapper<WarehouseAreas>()
-                            .eq(WarehouseAreas::getName, param.getName()));
+            // 骞傜瓑鍚屾锛氫紭鍏堟寜缂栫爜鍖归厤锛屾壘涓嶅埌鍐嶆寜鍚嶇О鍖归厤
+            WarehouseAreas warehouseAreas = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>()
+                    .eq(WarehouseAreas::getCode, param.getCode())
+                    .last("limit 1"));
+            if (Objects.isNull(warehouseAreas)) {
+                warehouseAreas = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>()
+                        .eq(WarehouseAreas::getName, param.getName())
+                        .last("limit 1"));
+            }
             if (!Objects.isNull(warehouseAreas)) {
                 locArea.setWarehouseId(warehouseAreas.getId());
             }
             locArea.setName(param.getName())
-                    .setCode(param.getCode())
-                    .setId(null);
-            if (!warehouseAreasService.save(locArea)) {
-                throw new CoolException("搴撳尯淇濆瓨澶辫触锛侊紒");
+                    .setCode(param.getCode());
+
+            if (!Objects.isNull(warehouseAreas)) {
+                locArea.setId(warehouseAreas.getId());
+                if (!warehouseAreasService.saveOrUpdate(locArea)) {
+                    throw new CoolException("搴撳尯鏇存柊澶辫触锛侊紒");
+                }
+                updateCount[0]++;
+            } else {
+                locArea.setId(null);
+                if (!warehouseAreasService.save(locArea)) {
+                    throw new CoolException("搴撳尯淇濆瓨澶辫触锛侊紒");
+                }
+                insertCount[0]++;
             }
         });
-        return R.ok();
+        Map<String, Object> result = new HashMap<>();
+        result.put("total", areasParams.size());
+        result.put("insertCount", insertCount[0]);
+        result.put("updateCount", updateCount[0]);
+        return R.ok(result);
     }
 
     /**
@@ -365,15 +422,35 @@
     @Override
     @Transactional(timeout = 60, rollbackFor = Exception.class)
     public R syncWarehouse(List<WarehouseParams> warehouses) {
+        final int[] insertCount = {0};
+        final int[] updateCount = {0};
         warehouses.forEach(warehouse -> {
             Warehouse ware = new Warehouse();
             BeanUtils.copyProperties(warehouse, ware);
-            ware.setId(null);
-            if (!warehouseService.save(ware)) {
-                throw new CoolException("浠撳簱鍚屾淇濆瓨澶辫触锛侊紒");
+            // 骞傜瓑鍚屾锛氭寜浠撳簱鍚嶇О鍖归厤
+            Warehouse one = warehouseService.getOne(new LambdaQueryWrapper<Warehouse>()
+                    .eq(Warehouse::getName, warehouse.getName())
+                    .last("limit 1"));
+            ware.setStatus(Objects.isNull(warehouse.getOperateType()) ? 1 : (warehouse.getOperateType() == 1 ? 0 : 1));
+            if (!Objects.isNull(one)) {
+                ware.setId(one.getId());
+                if (!warehouseService.saveOrUpdate(ware)) {
+                    throw new CoolException("浠撳簱鍚屾鏇存柊澶辫触锛侊紒");
+                }
+                updateCount[0]++;
+            } else {
+                ware.setId(null);
+                if (!warehouseService.save(ware)) {
+                    throw new CoolException("浠撳簱鍚屾淇濆瓨澶辫触锛侊紒");
+                }
+                insertCount[0]++;
             }
         });
-        return R.ok();
+        Map<String, Object> result = new HashMap<>();
+        result.put("total", warehouses.size());
+        result.put("insertCount", insertCount[0]);
+        result.put("updateCount", updateCount[0]);
+        return R.ok(result);
     }
 
     /**
@@ -406,6 +483,7 @@
             }
 
             companys.setType(CompanysType.getCustomVal(param.getType()));
+            companys.setStatus(Objects.isNull(param.getOperateType()) ? 1 : (param.getOperateType() == 1 ? 0 : 1));
             if (!Objects.isNull(one)) {
                 companys.setId(one.getId());
                 // 宸插瓨鍦ㄥ垯鏇存柊锛屼笉閲嶅鎶ラ敊

--
Gitblit v1.9.1