BasicMethod.java
6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.neotel.webbox.capacitynew.method;
import com.neotel.webbox.capacitynew.bean.*;
import com.neotel.webbox.capacitynew.box.Box;
import com.neotel.webbox.capacitynew.box.Column;
import com.neotel.webbox.capacitynew.box.SlotUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BasicMethod {
protected static SlotUnit getValidSlotUnit(int requestReelCount, ReelData reelData, int validHeight) {
if (requestReelCount <= 0) {
return null;
}
//剩余空间可放多少层料格
int slotCount = validHeight / reelData.getReelSlotHeight();
if (slotCount < reelData.getMinUnit()) {
//可放料格层数不到一个模组
return null;
}
int validReelCount = slotCount;
if (reelData.is7Reel()) {
validReelCount = validReelCount * 2;
}
if (validReelCount >= requestReelCount) {
//可以全部放下
return new SlotUnit(reelData, requestReelCount);
}
//只可以放下部分
return new SlotUnit(reelData, validReelCount);
}
protected static int fillToColumn(Column column, int remainCount, ReelData reelData) {
if (remainCount > 0 || remainCount == -1) {
//剩余空间可放多少层料格
int slotCount = column.getRemainHeight() / reelData.getReelSlotHeight();
if (remainCount != -1 && slotCount > remainCount) {
slotCount = remainCount;
}
SlotUnit existSlotUnit = column.getSlotUnit(reelData);
int existCount = 0;
if (existSlotUnit == null) {
//不存在同尺寸料格,需要判断最小模组
if (slotCount < reelData.getMinUnit()) {
//可放料格层数不到一个模组,尝试扩展已存在的料盘
return 0;
}
} else {
existCount = existSlotUnit.getReelCount();
}
int reelCount = slotCount;
if (reelData.is7Reel()) {
reelCount = reelCount * 2;
}
SlotUnit newSlotUnit = new SlotUnit(reelData, reelCount);
SlotUnit mergeSlotUnit = column.mergeSlotUnit(newSlotUnit);
if (mergeSlotUnit != null) {
int addCount = mergeSlotUnit.getReelCount() - existCount;
return addCount;
}
}
return 0;
}
protected static Column getPureColumn(int validHeight, BoxData boxData, ReelData reelData, int pureCapacity) {
Column column = new Column(validHeight);
column.setRemainHeight(0);
List<SlotUnit> slotUnitList = new ArrayList<>();
SlotUnit unit = new SlotUnit(reelData, pureCapacity);
slotUnitList.add(unit);
column.setSlotUnitList(slotUnitList);
return column;
}
protected static BoxResult getBoxResult(List<RequestItem> requestList, BoxData boxData, List<Box> mixBoxList) {
List<Box> boxes = new ArrayList<>();
for (RequestItem requestItem : requestList) {
ReelData reelData = requestItem.getReelData();
int pressHeight = reelData.getPressHeight();
for (int i = 0; i < requestItem.getPureBoxCount(); i++) {
Box box = new Box();
box.setColumnCount(boxData.getColumnCount());
int standColumnValidHeight = boxData.getColumnValidHeight(pressHeight); //标准列可用高度
int pureColumnCapacity = boxData.getColumnPureSizeCapacity(standColumnValidHeight,reelData.getReelSize(),reelData.getReelSlotHeight()); //可放入数量
Column standColumn = getPureColumn(standColumnValidHeight, boxData, reelData, pureColumnCapacity);
box.setColumn(standColumn);
//获取特殊列与特殊列上部的值
Map<String, Column> specialColumnMap = new HashMap<>();
Map<String, Column> specialColumnUpMap = new HashMap<>();
Map<String, List<BoxSpecialColumnContent>> boxSpecialColumnMap = boxData.getBoxSpecialColumnMap();
if (boxSpecialColumnMap != null && boxSpecialColumnMap.size() > 0) {
boxSpecialColumnMap = boxData.boxFillSpecialColumnHeight(boxSpecialColumnMap, reelData);
for (Map.Entry<String, List<BoxSpecialColumnContent>> entry : boxSpecialColumnMap.entrySet()) {
String boxSpecialColumnTitle = entry.getKey();
//特殊列
List<BoxSpecialColumnContent> boxSpecialColumnContentList = entry.getValue();
int boxSpecialColumnValidHeight = boxData.getBoxSingleSpecialColumnHeight(boxSpecialColumnContentList);
int boxSingleSpecialColumnCapacity = boxData.getColumnPureSizeCapacity(boxSpecialColumnValidHeight, reelData.getReelSize(),reelData.getReelSlotHeight());
Column specialColumn = getPureColumn(boxSpecialColumnValidHeight, boxData, reelData, boxSingleSpecialColumnCapacity);
specialColumnMap.put(boxSpecialColumnTitle, specialColumn);
//特殊列上部
int boxSingleSpecialColumnUpValidHeight = boxData.getBoxSingleSpecialColumnUpValidHeight(boxSpecialColumnContentList, reelData.getPressHeight());
int boxSingleSpecialColumnUpCapacity = boxData.getColumnPureSizeCapacity(boxSingleSpecialColumnUpValidHeight, reelData.getReelSize(), reelData.getReelSlotHeight());
Column specialColumnUp = getPureColumn(boxSingleSpecialColumnUpValidHeight, boxData, reelData, boxSingleSpecialColumnUpCapacity);
specialColumnUpMap.put(boxSpecialColumnTitle, specialColumnUp);
}
}
box.setSpecialColumnMap(specialColumnMap);
box.setSpecialColumnUpMap(specialColumnUpMap);
boxes.add(box);
}
}
for (Box box : mixBoxList) {
boxes.add(box);
}
BoxResult boxResult = new BoxResult();
boxResult.setBoxList(boxes);
boxResult.setRequestList(requestList);
return boxResult;
}
}