自动化立体仓库 - WMS系统
luxiaotao1123
2020-07-06 49488551cd97e90b0318d433a7c74a1bc0e0f351
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
package com.zy.asrs.task.handler;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.asrs.task.AbstractHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.List;
 
/**
 * Created by vincent on 2020/7/4
 */
@Service
@Transactional
public class WorkMastHandler extends AbstractHandler {
 
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private WrkDetlService wrkDetlService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private WaitPakinService waitPakinService;
 
    public void start() {
        List<WrkMast> wrkMasts = wrkMastService.selectToBeCompleteData();
        if (wrkMasts.isEmpty()) {
            return;
        }
        for (WrkMast wrkMast : wrkMasts) {
            // 4.入库完成
            if (wrkMast.getWrkSts() == 4) {
                doIn(wrkMast);
            // 14.出库完成
            } else  if (wrkMast.getWrkSts() == 14) {
                doOut(wrkMast);
            }
        }
    }
 
    private void doIn(WrkMast wrkMast){
        Date now = new Date();
        LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
        if (null == locMast) {
            exceptionHandle(""); // todo
            return;
        }
        switch (wrkMast.getIoType()) {
            // 空板入库
            case 10:
                // 修改库位状态=D
                if (locMast.getLocType().equals("S") || locMast.getLocType().equals("Q")) {
                    locMast.setLocType("D");
                    locMast.setIoTime(now);
                    locMast.setModiTime(now);
                    if (!locMastService.updateById(locMast)) {
                        exceptionHandle(""); // todo
                    }
                }
                break;
            // 全板入库
            case 1:
                // 清除所属库位之前的库存明细
                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getLocNo()));
                if (!locDetls.isEmpty()) {
                    locDetlService.delete(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getLocNo()));
                }
                // 根据工作号,查询工作明细档
                List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
                if (wrkDetls.isEmpty()) {
                    exceptionHandle(""); // todo
                }
                // 遍历工作明细,更新库存明细和入库通知档
                for (WrkDetl wrkDetl : wrkDetls) {
                    LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getLocNo()).eq("matnr", wrkDetl.getMatnr()));
                    if (null != locDetl) {
                        boolean res = locDetlService.updateAnfme(wrkDetl.getAnfme(), wrkMast.getLocNo(), wrkDetl.getMatnr());
                        if (!res) {
                            exceptionHandle(""); // todo
                        }
                    } else {
                        locDetl = new LocDetl(
                                wrkMast.getLocNo(), // 库位号
                                wrkDetl.getMatnr(), // 物料号
                                null,    // 仓库号
                                null,    // 转储请求编号
                                null,    // 行项目
                                null,    // 物料标签ID
                                wrkDetl.getMaktx(),    // 物料描述
                                null,    // 工厂
                                wrkDetl.getAnfme(),    // 数量
                                wrkDetl.getAltme(),    // 单位
                                wrkDetl.getZpallet(),    // 托盘条码
                                null,    // 用户ID
                                null,    // 备注
                                null,    // 修改人员
                                now,    // 修改时间
                                null,    // 创建者
                                now    // 添加时间
                        );
                        if (!locDetlService.insert(locDetl)) {
                            exceptionHandle(""); // todo
                        }
                    }
                    // 更新入库通知档 status ===>> Y
                    WaitPakin setParam = new WaitPakin();
                    setParam.setStatus("Y");
                    boolean updateRes = waitPakinService.update(setParam
                            , new EntityWrapper<WaitPakin>().eq("barcode", wrkDetl.getZpallet())
                                    .eq("matnr", wrkDetl.getMatnr())
                                    .eq("anfme", wrkDetl.getAnfme()));
                    if (!updateRes) {
                        exceptionHandle(""); // todo
                    }
                }
                // 修改库位状态 S ====>> F
                if (locMast.getLocType().equals("S")) {
                    locMast.setLocType("F");
                    locMast.setBarcode(wrkMast.getBarcode());
                    locMast.setIoTime(now);
                    locMast.setModiTime(now);
                    if (!locMastService.updateById(locMast)) {
                        exceptionHandle(""); // todo
                    }
                }
                break;
            // 拣料入库
            case 53:
                // 根据工作号,查询工作明细档
                List<WrkDetl> wrkDetls53 = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
                if (wrkDetls53.isEmpty()) {
                    exceptionHandle(""); // todo
                }
                for (WrkDetl wrkDetl:wrkDetls53) {
                    // 修改库存明细数量,如果工作明细数量为0时,删除库存明细
                    LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo()).eq("matnr", wrkDetl.getMatnr()));
                    if (null != locDetl) {
                        if (!locDetlService.updateAnfme(wrkDetl.getAnfme(), locMast.getLocNo(), wrkDetl.getMatnr())) {
                            exceptionHandle(""); // todo
                        }
                        // todo:luxiaotao 3)修改出库通知档 status ==> Y
                    }
                }
                // 修改库位状态 Q ====>> F
                if (locMast.getLocType().equals("Q")) {
                    locMast.setLocType("F");
                    locMast.setBarcode(wrkMast.getBarcode());
                    locMast.setIoTime(now);
                    locMast.setModiTime(now);
                    if (!locMastService.updateById(locMast)) {
                        exceptionHandle(""); // todo
                    }
                }
                break;
            // 并板入库
            case 54:
                // 根据工作号,查询工作明细档
                List<WrkDetl> wrkDetls54 = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
                if (wrkDetls54.isEmpty()) {
                    exceptionHandle(""); // todo
                }
                // 修改库存明细数量,如无库存,曾新增
                for (WrkDetl wrkDetl:wrkDetls54) {
                    LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo()).eq("matnr", wrkDetl.getMatnr()));
                    if (null != locDetl) {
                        if (!locDetlService.updateAnfme(wrkDetl.getAnfme(), locMast.getLocNo(), wrkDetl.getMatnr())) {
                            exceptionHandle(""); // todo
                        }
                    } else {
                        locDetl = new LocDetl(
                                wrkMast.getLocNo(), // 库位号
                                wrkDetl.getMatnr(), // 物料号
                                null,    // 仓库号
                                null,    // 转储请求编号
                                null,    // 行项目
                                null,    // 物料标签ID
                                wrkDetl.getMaktx(),    // 物料描述
                                null,    // 工厂
                                wrkDetl.getAnfme(),    // 数量
                                wrkDetl.getAltme(),    // 单位
                                wrkDetl.getZpallet(),    // 托盘条码
                                null,    // 用户ID
                                null,    // 备注
                                null,    // 修改人员
                                now,    // 修改时间
                                null,    // 创建者
                                now    // 添加时间
                        );
                        if (!locDetlService.insert(locDetl)) {
                            exceptionHandle(""); // todo
                        }
                    }
                    // todo:luxiaotao 3)修改出库通知档 status ==> Y
                }
                // 修改库位状态 Q ====>> F
                if (locMast.getLocType().equals("Q")) {
                    locMast.setLocType("F");
                    locMast.setBarcode(wrkMast.getBarcode());
                    locMast.setIoTime(now);
                    locMast.setModiTime(now);
                    if (!locMastService.updateById(locMast)) {
                        exceptionHandle(""); // todo
                    }
                }
                break;
            // 盘点入库
            case 57:
                // 根据工作号,查询工作明细档
                List<WrkDetl> wrkDetls57 = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
                if (wrkDetls57.isEmpty()) {
                    exceptionHandle(""); // todo
                }
                // todo:luxiaotao 3)修改盘点通知档 status ==> Y
                // 修改库位状态 Q ====>> F
                if (locMast.getLocType().equals("Q")) {
                    locMast.setLocType("F");
                    locMast.setBarcode(wrkMast.getBarcode());
                    locMast.setIoTime(now);
                    locMast.setModiTime(now);
                    if (!locMastService.updateById(locMast)) {
                        exceptionHandle(""); // todo
                    }
                }
                break;
            // 库位移转
            case 11:
 
                break;
            default:
                break;
        }
    }
 
    private void doOut(WrkMast wrkMast){
 
    }
 
 
 
 
    public static void main(String[] args) {
        for (int i = 0;i<10;i++) {
 
            try {
 
                System.out.println("====" + i);
                if (i == 5){
                    throw new Exception("dsa");
                }
                System.out.println("----" + i);
 
            } catch (Exception e) {
                e.printStackTrace();
            }
 
 
 
        }
    }
 
}