From 09009377b44b914effba2538421dbc09b1218af6 Mon Sep 17 00:00:00 2001
From: skyouc <creaycat@gmail.com>
Date: 星期五, 26 十二月 2025 11:00:41 +0800
Subject: [PATCH] 库位初始化优化

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java |   55 +++++++++++++++++++++++++++++++------------------------
 1 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java
index 0e59c09..1d384e6 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocServiceImpl.java
@@ -60,7 +60,7 @@
 
         String join = loc.getType();
         if (!Objects.isNull(loc.getTypeIds()) && !loc.getTypeIds().isEmpty()) {
-             join = StringUtils.join(loc.getTypeIds(), ",");
+            join = StringUtils.join(loc.getTypeIds(), ",");
         }
         boolean update = this.update(new LambdaUpdateWrapper<Loc>()
                 .in(Loc::getId, locs.getId())
@@ -85,25 +85,29 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public R initLocs(LocMastInitParam param, Long loginUserId) {
-        //娓呯┖琛�
-//        this.baseMapper.deleteAll();
-        //娓呯┖褰撳墠搴撳尯搴撲綅
-        List<Loc> locs = this.list(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, param.getWarehouseId()).eq(Loc::getAreaId, param.getAreaId()));
-        if (!locs.isEmpty()) {
-            if (!this.remove(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, param.getWarehouseId()).eq(Loc::getAreaId, param.getAreaId()))) {
-                throw new CoolException("鍒濆鍖栧け璐ワ細鏁版嵁鍒犻櫎澶辫触锛侊紒");
-            }
-        }
+
         WarehouseAreas warehouseAreas = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>()
-                .eq(WarehouseAreas::getWarehouseId, param.getWarehouseId())
-                .eq(WarehouseAreas::getId, param.getAreaId()));
+                .eq(!Objects.isNull(param.getWarehouseId()), WarehouseAreas::getWarehouseId, param.getWarehouseId())
+                .eq(!Objects.isNull(param.getAreaId()), WarehouseAreas::getId, param.getAreaId()));
         if (Objects.isNull(warehouseAreas)) {
             throw new CoolException("搴撳尯涓嶅瓨鍦紒锛�");
         }
+        // 娓呯┖琛�
+        // this.baseMapper.deleteAll();
+        // 娓呯┖褰撳墠搴撳尯搴撲綅
+        List<Loc> locs = this.list(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, warehouseAreas.getWarehouseId())
+                .eq(Loc::getAreaId, warehouseAreas.getId()));
+        if (!locs.isEmpty()) {
+            if (!this.remove(new LambdaQueryWrapper<Loc>().eq(Loc::getWarehouseId, warehouseAreas.getWarehouseId())
+                    .eq(Loc::getAreaId, warehouseAreas.getId()))) {
+                throw new CoolException("鍒濆鍖栧け璐ワ細鏁版嵁鍒犻櫎澶辫触锛侊紒");
+            }
+        }
+
         String join = StringUtils.join(param.getTypeIds(), ",");
 
         String[] split = warehouseAreas.getCode().split("\\.");
-        if (split.length == 0){
+        if (split.length == 0) {
             throw new CoolException("搴撳尯缂栫爜閿欒锛侊紒");
         }
         StringBuilder locStar = new StringBuilder();
@@ -112,27 +116,28 @@
         }
 
         List<Loc> list = new ArrayList<>();
-        Integer chanl = 0; //榛樿绗竴宸烽亾
+        Integer chanl = 0; // 榛樿绗竴宸烽亾
         for (int r = param.getStartRow(); r <= param.getEndRow(); r++) {
-            try{
-                Shelves shelves = new Shelves(param.getEndRow() - param.getStartRow() + 1, param.getChannel(),param.getStartRow());
-                for (List<Integer> node : shelves.nodes){
+            try {
+                Shelves shelves = new Shelves(param.getEndRow() - param.getStartRow() + 1, param.getChannel(),
+                        param.getStartRow());
+                for (List<Integer> node : shelves.nodes) {
                     if (node.contains(r)) {
-                        if (!Cools.isEmpty(param.getStartChannel()) && param.getStartChannel() > 0){
+                        if (!Cools.isEmpty(param.getStartChannel()) && param.getStartChannel() > 0) {
                             chanl = shelves.nodes.indexOf(node) + param.getStartChannel();
-                        }else {
+                        } else {
                             chanl = shelves.nodes.indexOf(node) + 1;
                         }
                         break;
                     }
                 }
-            }catch (Exception e){
+            } catch (Exception e) {
                 throw new CoolException("瑙f瀽宸烽亾鍙峰け璐�");
             }
             for (int b = param.getStartBay(); b <= param.getEndBay(); b++) {
                 for (int l = param.getStartLev(); l <= param.getEndLev(); l++) {
                     // 鑾峰彇搴撲綅鍙�
-                    String locNo = locStar +  String.format("%d", r) + String.format("-%d", b) + String.format("-%d", l);
+                    String locNo = locStar + String.format("%d", r) + String.format("-%d", b) + String.format("-%d", l);
                     Loc loc = new Loc();
                     loc.setCode(locNo)
                             .setUseStatus("O")
@@ -169,7 +174,7 @@
 
     @Override
     public boolean saveType(Loc loc) {
-        List<LocTypeRela> relas =  new ArrayList<>();
+        List<LocTypeRela> relas = new ArrayList<>();
         loc.getTypeIds().forEach(id -> {
             LocTypeRela typeRela = new LocTypeRela();
             typeRela.setTypeId(id)
@@ -185,7 +190,7 @@
     @Override
     public boolean updateLoc(Loc loc) {
         locTypeRelaMapper.delete(new LambdaQueryWrapper<LocTypeRela>().eq(LocTypeRela::getLocId, loc.getId()));
-        List<LocTypeRela> relas =  new ArrayList<>();
+        List<LocTypeRela> relas = new ArrayList<>();
         loc.getTypeIds().forEach(id -> {
             LocTypeRela typeRela = new LocTypeRela();
             typeRela.setTypeId(id)
@@ -206,7 +211,8 @@
         if (Objects.isNull(locs.getLocAreaId())) {
             throw new CoolException("淇敼搴撲綅淇℃伅涓嶈兘涓虹┖锛侊紒");
         }
-        List<LocArea> locAreas = locAreaService.list(new LambdaQueryWrapper<LocArea>().eq(LocArea::getId, locs.getLocAreaId()));
+        List<LocArea> locAreas = locAreaService
+                .list(new LambdaQueryWrapper<LocArea>().eq(LocArea::getId, locs.getLocAreaId()));
         if (locAreas.isEmpty()) {
             throw new CoolException("搴撲綅鍒嗗尯涓嶅瓨鍦紒锛�");
         }
@@ -226,6 +232,7 @@
 
     /**
      * 鑾峰彇搴撲綅浣跨敤鎯呭喌
+     * 
      * @return
      */
     @Override

--
Gitblit v1.9.1