自动化立体仓库 - WMS系统
lsh
14 小时以前 ef012984e2a1d92e4a35844c6dce92ebb66c7c87
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
package com.zy.asrs.task;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.OrderToLine;
import com.zy.asrs.service.*;
import com.zy.asrs.task.core.ReturnT;
import com.zy.asrs.task.handler.OrderToLineHandler;
import com.zy.asrs.utils.ToSortLineUtils;
import com.zy.asrs.utils.param.ItemUtilParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.List;
 
@Slf4j
@Component
//订单下发至分拣线
public class OrderToSortLineScheduler {
    @Autowired
    private OrderPakinService orderPakinService;
    @Autowired
    private OrderDetlPakinService orderDetlPakinService;
    @Autowired
    private BasArmRulesService basArmRulesService;
    @Autowired
    private OrderToLineHandler orderToLineHandler;
    @Autowired
    private MatService matService;
    @Autowired
    private BasArmMastSignService basArmMastSignService;
 
//    @Scheduled(cron = "0/3 * * * * ? ")
    private void orderToSortLine() {
        //获取未下发单据
        List<String> orderNos = orderPakinService.AllStatusSatisfyOrder(0);
        if(orderNos == null || orderNos.isEmpty()) {
//            log.info("未有新订单");
            return;
        }
 
        //遍历单据
        for (String orderNo : orderNos) {
            OrderPakin orderPakin = orderPakinService.selectOne(new EntityWrapper<OrderPakin>().eq("order_no",orderNo));
            if(orderPakin.getDocType() == 16){
                orderPakin.setMoveStatus(1);
                orderPakinService.updateById(orderPakin);
                continue;
            }
 
            try{
                List<OrderDetlPakin> orderDetlPakinListAll = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>().eq("order_no",orderNo).eq("inspect",0));
                if (orderDetlPakinListAll.size()<1){
                    orderPakinService.updateOrderStatus(orderNo);   //更新订单状态 0 -> 1
                    continue;
                }
                List<String> boxType3List = new ArrayList<>();
                for (OrderDetlPakin orderDetl:orderDetlPakinListAll){
                    if (!boxType3List.contains(orderDetl.getBoxType3())){
                        boxType3List.add(orderDetl.getBoxType3());
                    }
                }
                for (String boxType3 : boxType3List){
                    List<OrderDetlPakin> orderDetlPakinList = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>().eq("order_no",orderNo).eq("box_type3",boxType3).eq("inspect",0));
                    if (orderDetlPakinList.size()<1){
                        continue;
                    }
                    List<ItemUtilParam.Item> items = new ArrayList<>();
                    for (OrderDetlPakin orderDetl:orderDetlPakinList){
                        Mat mat = matService.selectByMatnr(orderDetl.getMatnr());
                        Integer number =  basArmRulesService.getNumber(mat.getWeight(),mat.getVolume(),mat.getManLength(),mat.getWidth(),mat.getHeight());
                        if (number == null) {
                            BasArmRules basArmRules = new BasArmRules();
                            basArmRules.setMaterialHeight(mat.getHeight());
                            basArmRules.setMaterialWeight(mat.getWeight());
                            basArmRules.setMaterialLength(mat.getManLength());
                            basArmRules.setMaterialWidth(mat.getWidth());
                            basArmRulesService.insert(basArmRules);
                            return;
                        } else if (number == 0){
 
                            Integer status =  basArmRulesService.getStatus(mat.getWeight(),mat.getVolume(),mat.getManLength(),mat.getWidth(),mat.getHeight());
                            if (!Cools.isEmpty(status) && status == 2){
                                continue;
                            } else {
                                return;
                            }
                        }
                        String name = ToSortLineUtils.MergerParameter(orderDetl.getMatnr(),orderDetl.getStandby3(),orderDetl.getStandby1(),orderDetl.getStandby2());
                        int maxCapacity = number;
                        int stock = orderDetl.getAnfme().intValue();
                        items.add(new ItemUtilParam.Item(name, maxCapacity, stock));
                    }
 
                    OrderToLine orderToLine = new OrderToLine();
                    orderToLine.setOrderNo(boxType3);  //单据编号
                    orderToLine.setCreateTime(System.currentTimeMillis());  //创建时间
                    OrderToLine orderToLineR = ToSortLineUtils.GetOrderToLine(items, orderToLine,"Opt3");
 
                    try{
                        ReturnT<String> returnT = orderToLineHandler.start(orderToLineR);
                        if (!returnT.isSuccess()) {
//                        log.error("下发单据失败===>"+ JSON.toJSON(orderToLineR));
                        } else {
                            try{
                                for (OrderToLine.MatList matList:orderToLineR.getMatList()){
                                    BasArmMastSign basArmMastSign = new BasArmMastSign();
                                    basArmMastSign.setMatnr(matList.getItem());
                                    basArmMastSign.setOrderNo(boxType3);//b3
                                    basArmMastSign.setSku(matList.getSku());//s3
                                    basArmMastSign.setPo(matList.getPo());//s1
                                    basArmMastSign.setUpc(matList.getUpc());//s2
//                                    basArmMastSign.setSupplier(matList.getSupplier());
                                    basArmMastSign.setStatus(0);
                                    basArmMastSign.setAnfme(matList.getCtns());
                                    basArmMastSign.setCreateTime(matList.getBindingTags());
                                    basArmMastSignService.insert(basArmMastSign);
                                }
                                for (OrderDetlPakin orderDetl:orderDetlPakinList){
                                    orderDetl.setInspect(1);
                                    orderDetlPakinService.updateById(orderDetl);
                                }
                            }catch (Exception e){}
                        }
                    } catch (Exception e){
                        log.error("下发单据异常===>"+e.getMessage());
                    }
                }
 
            } catch (Exception e){
                log.error("下发单据异常,跳转下一个订单===>"+e.getMessage());
            }
        }
    }
 
    @Scheduled(cron = "0/3 * * * * ? ")
    private void orderToSortLine2() {
        //获取未下发单据
        List<String> orderNos = orderPakinService.AllStatusSatisfyOrder(1);
        if(orderNos == null || orderNos.isEmpty()) {
//            log.info("未有新订单");
            return;
        }
 
        //遍历单据
        for (String orderNo : orderNos) {
            OrderPakin orderPakin = orderPakinService.selectOne(new EntityWrapper<OrderPakin>().eq("order_no",orderNo));
            if(orderPakin.getDocType() == 16){
                orderPakin.setMoveStatus(0);
                orderPakinService.updateById(orderPakin);
                continue;
            }
 
            try{
                List<OrderDetlPakin> orderDetlPakinListAll = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>().eq("order_no",orderNo).eq("inspect",1));
                if (orderDetlPakinListAll.size()<1){
                    orderPakinService.updateOrderStatus0(orderNo);   //更新订单状态 1 -> 0
                    continue;
                }
                List<String> boxType3List = new ArrayList<>();
                for (OrderDetlPakin orderDetl:orderDetlPakinListAll){
                    if (!boxType3List.contains(orderDetl.getBoxType3())){
                        boxType3List.add(orderDetl.getBoxType3());
                    }
                }
                for (String boxType3 : boxType3List){
                    List<OrderDetlPakin> orderDetlPakinList = orderDetlPakinService.selectList(new EntityWrapper<OrderDetlPakin>().eq("order_no",orderNo).eq("box_type3",boxType3).eq("inspect",1));
                    if (orderDetlPakinList.size()<1){
                        continue;
                    }
                    List<ItemUtilParam.Item> items = new ArrayList<>();
                    for (OrderDetlPakin orderDetl:orderDetlPakinList){
                        Mat mat = matService.selectByMatnr(orderDetl.getMatnr());
                        Integer number =  basArmRulesService.getNumber(mat.getWeight(),mat.getVolume(),mat.getManLength(),mat.getWidth(),mat.getHeight());
                        if (number == null) {
                            BasArmRules basArmRules = new BasArmRules();
                            basArmRules.setMaterialHeight(mat.getHeight());
                            basArmRules.setMaterialWeight(mat.getWeight());
                            basArmRules.setMaterialLength(mat.getManLength());
                            basArmRules.setMaterialWidth(mat.getWidth());
                            basArmRulesService.insert(basArmRules);
                            return;
                        } else if (number == 0){
 
                            Integer status =  basArmRulesService.getStatus(mat.getWeight(),mat.getVolume(),mat.getManLength(),mat.getWidth(),mat.getHeight());
                            if (!Cools.isEmpty(status) && status == 2){
                                continue;
                            } else {
                                return;
                            }
                        }
                        String name = ToSortLineUtils.MergerParameter(orderDetl.getMatnr(),orderDetl.getStandby3(),orderDetl.getStandby1(),orderDetl.getStandby2());
                        int maxCapacity = number;
                        if (orderDetl.getSortingAnfme()<1){
                            continue;
                        }
                        int stock = orderDetl.getSortingAnfme().intValue();
                        items.add(new ItemUtilParam.Item(name, maxCapacity, stock));
                    }
 
                    OrderToLine orderToLine = new OrderToLine();
                    orderToLine.setOrderNo(boxType3);  //单据编号
                    orderToLine.setCreateTime(System.currentTimeMillis());  //创建时间
                    OrderToLine orderToLineR = ToSortLineUtils.GetOrderToLine(items, orderToLine,"Opt3");
 
                    try{
                        ReturnT<String> returnT = orderToLineHandler.start(orderToLineR);
                        if (!returnT.isSuccess()) {
//                        log.error("下发单据失败===>"+ JSON.toJSON(orderToLineR));
                        } else {
                            try{
                                for (OrderToLine.MatList matList:orderToLineR.getMatList()){
                                    BasArmMastSign basArmMastSign = new BasArmMastSign();
                                    basArmMastSign.setMatnr(matList.getItem());
                                    basArmMastSign.setOrderNo(boxType3);//b3
                                    basArmMastSign.setSku(matList.getSku());//s3
                                    basArmMastSign.setPo(matList.getPo());//s1
                                    basArmMastSign.setUpc(matList.getUpc());//s2
//                                    basArmMastSign.setSupplier(matList.getSupplier());
                                    basArmMastSign.setStatus(0);
                                    basArmMastSign.setAnfme(matList.getCtns());
                                    basArmMastSign.setCreateTime(matList.getBindingTags());
                                    basArmMastSignService.insert(basArmMastSign);
                                }
                                for (OrderDetlPakin orderDetl:orderDetlPakinList){
                                    orderDetl.setSortingAnfme(0.0);
                                    orderDetl.setInspect(0);
                                    orderDetlPakinService.updateById(orderDetl);
                                }
                            }catch (Exception e){}
                        }
                    } catch (Exception e){
                        log.error("下发单据异常===>"+e.getMessage());
                    }
                }
 
            } catch (Exception e){
                log.error("下发单据异常,跳转下一个订单===>"+e.getMessage());
            }
        }
    }
 
}