Storage.java
8.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
package com.myproject.bean.update;
import com.myproject.bean.BaseMongoBean;
import com.myproject.bean.json.PlateSizeBean;
import com.myproject.bean.json.UsageItem;
import com.myproject.util.PLATE_SIZE;
import com.myproject.util.StorageConstants;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.data.annotation.Transient;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by kangmor on 2015/12/3.
*/
public class Storage extends BaseMongoBean {
@NotEmpty(message = "{storage.name.empty}")
private String name;
/**
* 程序路径
*/
private String sourcePath;
private String cid;
private int totalSlots;
private int emptySlots;
/**
* 兼容类型:完全匹配,完全兼容,同尺寸兼容
*/
private StorageConstants.COMPATIBLE_TYPE compatibleType = StorageConstants.COMPATIBLE_TYPE.EXACT_MATCH;
/**
* 料仓类型:单台自动料仓,手动料仓流水线料仓
*/
private String type = StorageConstants.TYPE.AUTO.name();
//包含料仓 Box数量
private Integer boxCount=1;
public Integer getBoxCount() {
if (boxCount == null){
boxCount = 1;
}
return boxCount;
}
/**
* 使用情况
*/
private Map<String, UsageItem> usageMap = new ConcurrentHashMap<>();
/**
* 禁止出入库的 box
*/
private List<Integer> disableBoxes;
public List<Integer> getDisableBoxes() {
return disableBoxes;
}
/**
* 判断 box 是否可用
*/
public boolean isBoxEnable(Integer boxId){
if(disableBoxes != null){
return disableBoxes.contains(boxId);
}
return true;
}
public void setDisableBoxes(List<Integer> disableBoxes) {
this.disableBoxes = disableBoxes;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public void setBoxCount(Integer boxCount) {
this.boxCount = boxCount;
}
private boolean available = true;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public int getTotalSlots() {
return totalSlots;
}
public void setTotalSlots(int totalSlots) {
this.totalSlots = totalSlots;
}
public int getEmptySlots() {
return emptySlots;
}
public void setEmptySlots(int emptySlots) {
this.emptySlots = emptySlots;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
/**
* 是否是上下层的在线料仓
* @return
*/
public boolean isOnlineStorage(){
return StorageConstants.TYPE.ONLINE.name().equals(type);
}
/**
* 是否是指上下料的料仓
* @return
*/
public boolean isBatchStorage(){
return StorageConstants.TYPE.BATCH.name().equals(type);
}
/**
* 是否是单台自动仓
*/
public boolean isAuto(){
return StorageConstants.TYPE.AUTO.name().equals(type);
}
/**
* 是否是虚拟仓
*/
public boolean isVirtual(){
return StorageConstants.TYPE.VIRTUAL.name().equals(type);
}
/**
* 是否是流水线料仓
*/
public boolean isLine() {
return StorageConstants.TYPE.LINE.name().equals(type);
}
/**
* 是否是智能料架
*/
public boolean isShelf() {
return StorageConstants.TYPE.SHELF.name().equals(type);
}
/**
* 是否是ACC智能料架
*/
public boolean isAccShelf() {
return StorageConstants.TYPE.ACCSHELF.name().equals(type);
}
/**
* 是否是扫码料架
*/
public boolean isCodeShelf() {
return StorageConstants.TYPE.CODESHELF.name().equals(type);
}
/**
* 是否是锡膏料仓
*/
public boolean isSolderPaste(){
return StorageConstants.TYPE.SOLDERPASTE.name().equals(type);
}
/**
* 是否是料柜
*/
public boolean isCabinet() {
return StorageConstants.TYPE.CABINET.name().equals(type);
}
public boolean canPutInPos(int w, int h, int PosW, int posH){
if(compatibleType == StorageConstants.COMPATIBLE_TYPE.EXACT_MATCH){//完全匹配
if(w == PosW && h == posH){
return true;
}
}else if(compatibleType == StorageConstants.COMPATIBLE_TYPE.FULLY_COMPATIBLE){//完全兼容
if(w <= PosW && h <= posH){
return true;
}
}else if(compatibleType == StorageConstants.COMPATIBLE_TYPE.SIZE_COMPATIBLE){//同尺寸兼容
if(w == PosW && h <= posH){
return true;
}
}
return false;
}
/**
* 判断料盘是否能够放入该仓库: 0=完全匹配,1=完全兼容,2=同尺寸兼容
*/
public boolean canPutIn(int w, int h){
if(usageMap != null){
for (UsageItem usageItem : usageMap.values()) {
if(canPutInPos(w,h, usageItem.getW(), usageItem.getH())){
return true;
}
}
}
return false;
}
public String getSourcePath() {
return sourcePath;
}
public void setSourcePath(String sourcePath) {
this.sourcePath = sourcePath;
}
public StorageConstants.COMPATIBLE_TYPE getCompatibleType() {
return compatibleType;
}
public void setCompatibleType(StorageConstants.COMPATIBLE_TYPE compatibleType) {
this.compatibleType = compatibleType;
}
public Map<String, UsageItem> getUsageMap() {
return usageMap;
}
public void setUsageMap(Map<String, UsageItem> usageMap) {
this.usageMap = usageMap;
}
/**
* 使用一个仓位,更新使用情况
*/
public void useOnePos(StoragePos pos){
if(usageMap != null){
String sizeStr = pos.getSizeStr();
UsageItem usageItem = usageMap.get(sizeStr);
if(usageItem != null){
this.emptySlots = this.emptySlots - 1;
int usedCount = usageItem.getUsedCount();
usageItem.setUsedCount(usedCount + 1);
usageMap.put(sizeStr, usageItem);
}
}
}
public void emptyOnePos(StoragePos pos){
if(usageMap != null){
String sizeStr = pos.getSizeStr();
UsageItem usageItem = usageMap.get(sizeStr);
if(usageItem != null){
this.emptySlots = this.emptySlots + 1;
int usedCount = usageItem.getUsedCount();
usageItem.setUsedCount(usedCount - 1);
usageMap.put(sizeStr, usageItem);
}
}
}
public void initUsage(List<PlateSizeBean> plateSizeBeanList){
usageMap = new ConcurrentHashMap<>();
int totalPosCount = 0;
int emptyPosCount = 0;
for (PlateSizeBean plateSizeBean : plateSizeBeanList) {
String sizeStr = plateSizeBean.getSizeStr();
UsageItem usageItem = usageMap.get(sizeStr);
if(usageItem == null){
usageItem = new UsageItem();
usageItem.setW(plateSizeBean.getPlateSize().getW());
usageItem.setH(plateSizeBean.getPlateSize().getH());
}
if(plateSizeBean.getPlateSize().isUsed()){
int usedCount = plateSizeBean.getCount();
usageItem.setUsedCount(usedCount);
usageItem.setTotalCount(usedCount + usageItem.getTotalCount());
}else{
//未使用的数量
int idleCount = plateSizeBean.getCount();
usageItem.setTotalCount(idleCount + usageItem.getTotalCount());
emptyPosCount = emptyPosCount + idleCount;
}
totalPosCount = totalPosCount + plateSizeBean.getCount();
usageMap.put(sizeStr, usageItem);
}
this.setEmptySlots(emptyPosCount);
this.setTotalSlots(totalPosCount);
}
}