From 945764de58898661a3f3197e58353141b5deaf91 Mon Sep 17 00:00:00 2001
From: pang.jiabao <pang_jiabao@163.com>
Date: 星期三, 22 十月 2025 16:21:15 +0800
Subject: [PATCH] 侧面输送线出入库流程对接
---
src/main/java/com/zy/common/model/Shelves.java | 49 ++++++++++++++++++++++++++++++-------------------
1 files changed, 30 insertions(+), 19 deletions(-)
diff --git a/src/main/java/com/zy/common/model/Shelves.java b/src/main/java/com/zy/common/model/Shelves.java
index 17515ce..26b21ab 100644
--- a/src/main/java/com/zy/common/model/Shelves.java
+++ b/src/main/java/com/zy/common/model/Shelves.java
@@ -1,5 +1,8 @@
package com.zy.common.model;
+import com.alibaba.fastjson.JSON;
+import com.core.exception.CoolException;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -11,13 +14,13 @@
public class Shelves {
// 璐ф灦鎺掓暟閲�
- private final int size;
+ public final int size;
// 璐ф灦缁勬暟閲�
- private final int group;
+ public final int group;
// 鍋忕Щ閲廩default:0]
- private final int offset;
+ public final int offset;
// 璐ф灦瀹炰緥鑺傜偣闆嗗悎
public List<List<Integer>> nodes;
@@ -38,18 +41,29 @@
init();
}
+ public static void main(String[] args) throws InterruptedException {
+ Shelves shelves = new Shelves(8, 2);
+ System.out.println(shelves.nodes.toString());
+ int start = 1;
+ while (true) {
+ System.out.println(start);
+ start = shelves.start(start);
+ Thread.sleep(500L);
+ }
+ }
+
/**
* 鍒濆鍖栨柟娉曘�愮鏈夈��
*/
- private void init(){
- if (group == 0 || size%group != 0) {
+ 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++){
- int unit = size/group;
+ for (int g = 1; g <= this.group; g++) {
+ int unit = size / group;
List<Integer> node = new ArrayList<>();
- for (int i = (g-1)*unit+1+offset ; i <= g*unit+offset; i++){
+ for (int i = (g - 1) * unit + 1 + offset; i <= g * unit + offset; i++) {
node.add(i);
}
nodes.add(node);
@@ -69,9 +83,9 @@
* @param curSeq 褰撳墠璐ф灦鍙�
* @return 瑙勫垯鍛戒腑璐ф灦鍙�
*/
- public int start(int curSeq){
+ public int start(int curSeq) {
Iterator<List<Integer>> iterator = nodes.iterator();
- while (iterator.hasNext()){
+ while (iterator.hasNext()) {
List<Integer> node = iterator.next();
if (node.contains(curSeq)) {
int idx = node.indexOf(curSeq);
@@ -97,16 +111,13 @@
return -1;
}
-
- public static void main(String[] args) throws InterruptedException {
- Shelves shelves = new Shelves(8,2);
- System.out.println(shelves.nodes.toString());
- int start = 1;
- while (true) {
- System.out.println(start);
- start = shelves.start(start);
- Thread.sleep(500L);
+ public Integer get(Integer curRow) {
+ for (List<Integer> node : nodes) {
+ if (node.contains(curRow)) {
+ return nodes.indexOf(node) + 1;
+ }
}
+ throw new CoolException("璐ф帓妫�绱㈢郴缁熸姤閿欙紝 node:" + JSON.toJSONString(nodes) + ", curRow:" + curRow);
}
}
--
Gitblit v1.9.1