自动化立体仓库 - WMS系统
#
1
5 小时以前 10c441b49c936ff93a549112b31330042605b857
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.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 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) {
            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){
                        Integer number =  basArmRulesService.getNumber(orderDetl.getWeight(),orderDetl.getVolume(),orderDetl.getManLength(),orderDetl.getWidth(),orderDetl.getHeight());
                        if (number == null) {
                            BasArmRules basArmRules = new BasArmRules();
                            basArmRules.setMaterialHeight(orderDetl.getHeight());
                            basArmRules.setMaterialWeight(orderDetl.getWeight());
                            basArmRules.setMaterialLength(orderDetl.getManLength());
                            basArmRules.setMaterialWidth(orderDetl.getWidth());
                            basArmRulesService.insert(basArmRules);
                            return;
                        } else if (number == 0){
                            Integer status =  basArmRulesService.getStatus(orderDetl.getWeight(),orderDetl.getVolume(),orderDetl.getManLength(),orderDetl.getWidth(),orderDetl.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());
            }
        }
    }
 
}