From 39b22a93673a65872b7f63f8d5ff1c2b95ef0bbd Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 11 六月 2020 15:28:45 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java |    2 
 src/main/java/com/zy/common/model/Shelves.java              |   98 ++++++++++++++++++++++++++++++++
 src/main/java/com/zy/common/service/DoubleDeepService.java  |   77 +++++++++++++++++--------
 3 files changed, 152 insertions(+), 25 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
index 624ddb0..6517a0e 100644
--- a/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -44,7 +44,7 @@
             }
         }
         // 搴撲綅妫�绱�
-        String locNo = doubleDeepService.getLocNo();
+        String locNo = doubleDeepService.getLocNo(1);
 
 
 //        if (staNo == null || staNo.get)
diff --git a/src/main/java/com/zy/common/model/Shelves.java b/src/main/java/com/zy/common/model/Shelves.java
new file mode 100644
index 0000000..f8cebc4
--- /dev/null
+++ b/src/main/java/com/zy/common/model/Shelves.java
@@ -0,0 +1,98 @@
+package com.zy.common.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Created by vincent on 2020/6/11
+ */
+public class Shelves {
+
+    // 璐ф灦鎺掓暟閲�
+    private final int size;
+
+    // 璐ф灦缁勬暟閲�
+    private final int group;
+
+    // 鍋忕Щ閲廩default:0]
+    private int offset = 0;
+
+    // 璐ф灦瀹炰緥鑺傜偣
+    private List<List<Integer>> nodes;
+
+    public Shelves(int size, int group) {
+        this(size, group, 0);
+    }
+
+    public Shelves(int size, int group, int offset) {
+        this.size = size;
+        this.group = group;
+        this.offset = offset;
+        init();
+    }
+
+    /**
+     * 鍒濆鍖�
+     */
+    private void init(){
+        if (group == 0 || size%group != 0) {
+            throw new RuntimeException("shelves init fail!");
+        }
+        nodes = new ArrayList<>();
+        for (int g = 1; g <= this.group; g++){ // 1 2
+            int unit = size/group;  // 4
+            List<Integer> node = new ArrayList<>();
+            for (int i = (g-1)*unit+1+offset ; i <= g*unit+offset; i++){
+                node.add(i);
+            }
+            nodes.add(node);
+        }
+    }
+
+    /**
+     *
+     * @param curSeq 褰撳墠璐ф灦鍙�
+     * @return 瑙勫垯鍛戒腑璐ф灦鍙�
+     */
+    public int start(int curSeq){
+        Iterator<List<Integer>> iterator = nodes.iterator();
+        while (iterator.hasNext()){
+            List<Integer> node = iterator.next();
+            if (node.contains(curSeq)) {
+                int idx = node.indexOf(curSeq);
+                // 鏄惁涓烘湯灏捐揣鏋�
+                if (iterator.hasNext()) {
+                    return iterator.next().get(idx);
+                } else {
+                    List<Integer> first = nodes.get(0);
+                    Integer val = first.get(idx);
+                    int res = size /group + 1 + offset - val;
+                    // 鍙嶅悜鍛戒腑璐ф灦鏃朵笉鍐嶆槸瀵圭珛涓嬫爣锛堢浉瀵逛簬宸烽亾锛�
+                    if (res < val) {
+                        // 杞鎵�鏈夎揣鏋跺悗閲嶆柊寮�濮嬪畾浣�
+                        if (val - res - offset == 1) {
+                            return first.get(0);
+                        }
+                        res = res + 1;
+                    }
+                    return res + offset;
+                }
+            }
+        }
+        return 0;
+    }
+
+    public static void main(String[] args) throws InterruptedException {
+        Shelves shelves = new Shelves(4,2);
+        System.out.println(shelves.nodes.toString());
+        int start = 1;
+        while (true) {
+            System.out.println(start);
+            start = shelves.start(start);
+            Thread.sleep(500L);
+        }
+    }
+
+}
+
diff --git a/src/main/java/com/zy/common/service/DoubleDeepService.java b/src/main/java/com/zy/common/service/DoubleDeepService.java
index 04db044..0e0ff7b 100644
--- a/src/main/java/com/zy/common/service/DoubleDeepService.java
+++ b/src/main/java/com/zy/common/service/DoubleDeepService.java
@@ -1,10 +1,14 @@
 package com.zy.common.service;
 
 import com.core.common.Cools;
+import com.core.exception.CoolException;
+import com.zy.asrs.entity.RowLastno;
 import com.zy.asrs.entity.WrkLastno;
 import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.service.RowLastnoService;
 import com.zy.asrs.service.WrkLastnoService;
 import com.zy.asrs.service.WrkMastService;
+import com.zy.common.model.Shelves;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -19,6 +23,8 @@
     private WrkMastService wrkMastService;
     @Autowired
     private WrkLastnoService wrkLastnoService;
+    @Autowired
+    private RowLastnoService rowLastnoService;
 
     /**
      * 鐢熸垚宸ヤ綔鍙�
@@ -27,43 +33,66 @@
      */
     public int getWorkNo(Integer wrkMk) {
         WrkLastno wrkLastno = wrkLastnoService.selectById(wrkMk);
+        if (Cools.isEmpty(wrkLastno)) {
+            throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�");
+        }
         int workNo = 0;
         // 鍏ュ嚭搴撶被鍨�
         if (wrkLastno.getWrkMk() == 0) {
-            if (!Cools.isEmpty(wrkLastno)){
-                workNo = wrkLastno.getWrkNo();
-                int sNo = wrkLastno.getSNo();
-                int eNo = wrkLastno.getENo();
+            workNo = wrkLastno.getWrkNo();
+            int sNo = wrkLastno.getSNo();
+            int eNo = wrkLastno.getENo();
 
-                workNo = workNo>=eNo ? sNo : workNo+1;
+            workNo = workNo>=eNo ? sNo : workNo+1;
 
-                while (true) {
-                    WrkMast wrkMast = wrkMastService.selectById(workNo);
-                    if (null != wrkMast) {
-                        workNo = workNo>=eNo ? sNo : workNo+1;
-                    } else {
-                        break;
-                    }
-                }
-
-                if (workNo > 0){
-                    // todo
-                    wrkLastno.setWrkNo(workNo);
-                    wrkLastnoService.updateById(wrkLastno);
+            while (true) {
+                WrkMast wrkMast = wrkMastService.selectById(workNo);
+                if (null != wrkMast) {
+                    workNo = workNo>=eNo ? sNo : workNo+1;
+                } else {
+                    break;
                 }
             }
-
+            if (workNo > 0){
+                // todo
+                wrkLastno.setWrkNo(workNo);
+                wrkLastnoService.updateById(wrkLastno);
+            }
         }
         return workNo;
     }
 
     /**
      * 妫�绱㈠簱浣嶅彿
-     * @param
-     * @return
+     * @param whsType 绫诲瀷 1:鍙屾繁寮忚揣鏋�
+     * @return locNo 妫�绱㈠埌鐨勫簱浣嶅彿
      */
-    public String getLocNo() {
-        return null;
+    public String getLocNo(Integer whsType) {
+        RowLastno rowLastno = rowLastnoService.selectById(whsType);
+        if (Cools.isEmpty(rowLastno)) {
+            throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�");
+        }
+        String locNo = null;
+        if (rowLastno.getWhsType() == 1){
+            int curRow = rowLastno.getCurrentRow();
+            int sRow = rowLastno.getsRow();
+            int eRow = rowLastno.geteRow();
+            int crn_qty = rowLastno.getCrnQty();
+
+            Shelves shelves = new Shelves(8, crn_qty);
+            curRow = shelves.start(curRow);
+
+            if (curRow != 0) {
+
+
+                rowLastno.setCurrentRow(curRow);
+                rowLastnoService.updateById(rowLastno);
+            }
+
+        }
+
+        return locNo;
     }
 
-}
+
+}
\ No newline at end of file

--
Gitblit v1.9.1