自动化立体仓库 - WMS系统
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
package com.zy.asrs.task;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.asrs.task.handler.AutoReplenishmentHandler;
import com.zy.common.entity.Parameter;
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.List;
import java.util.Set;
 
@Slf4j
@Component
public class AutoReplenishmentScheduler {
 
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private DocTypeService docTypeService;
    @Autowired
    private AutoReplenishmentHandler autoReplenishmentHandler;
    @Autowired
    private MatService matService;
    @Autowired
    private AgvLocDetlService agvLocDetlService;
    @Autowired
    private AgvLocMastService agvLocMastService;
    @Autowired
    private LocDetlService locDetlService;
 
    /*
    定时遍历库存,生成自动补货单据
     */
    @Scheduled(cron = "0 */1 * * * ? ")
    public void createOrder(){
 
        if(!"Y".equals(Parameter.get().getAutoReplenishment())){
            return;
        }
 
        //检测是否有未完成的补货单据
        DocType docType = docTypeService.selectOne(new EntityWrapper<DocType>().eq("doc_name", "自动补货单"));
        int count = orderService.selectCount(new EntityWrapper<Order>()
                .eq("doc_type", docType.getDocId())
                .andNew().eq("settle",2)
                .or().eq("settle",1));
        if(count > 2){
            return;
        }
        
        //判断CTU库是否有足够的空库位,空库位数需要大于100
        int i = agvLocMastService.selectCount(new EntityWrapper<AgvLocMast>().eq("loc_sts", "O"));
        if(i < 100){
            return;
        }
 
        //查询所有需要补货的物料
        List<Mat> matList = matService.selectList(new EntityWrapper<Mat>().gt( "store_min", 0));
        if(!Cools.isEmpty(matList)){
            for (Mat mat : matList){
                //检测是否有未完成的补货单据
                DocType docType1 = docTypeService.selectOne(new EntityWrapper<DocType>().eq("doc_name", "自动补货单"));
                int count1 = orderService.selectCount(new EntityWrapper<Order>()
                        .eq("doc_type", docType1.getDocId())
                        .andNew().eq("settle",2)
                        .or().eq("settle",1));
                if(count1 > 2){
                    break;
                }
 
                //判断CTU库是否有足够的空库位,空库位数需要大于100
                int j = agvLocMastService.selectCount(new EntityWrapper<AgvLocMast>().eq("loc_sts", "O"));
                if(j < 100){
                    return;
                }
 
                //收集当前物料自动补货单明细数量
                Double orderDetlCount = 0.0;
                List<Order> orders = orderService.selectList(new EntityWrapper<Order>()
                        .eq("doc_type", docType1.getDocId())
                        .andNew().eq("settle", 2)
                        .or().eq("settle", 1));
                if(!Cools.isEmpty(orders)){
                    for (Order order : orders){
                        List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>()
                                .eq("matnr", mat.getMatnr())
                                .eq("order_no", order.getOrderNo()));
                        if(Cools.isEmpty(orderDetls)){
                            continue;
                        }
                        for (OrderDetl orderDetl : orderDetls){
                            orderDetlCount=orderDetlCount+orderDetl.getQty();
                        }
                    }
                }
                //查询当前物料是否在agv库小于库存上限
                Double anfmeSum = agvLocDetlService.selectSumAnfmeByMatnr(mat.getMatnr());
                if(Cools.isEmpty(anfmeSum)){
                    anfmeSum = 0.0;
                }
                //当前物料不需要补货
                if(anfmeSum+orderDetlCount > mat.getStoreMin()){
                    continue;
                }
                //查询当前物料四项库是否存在,并且托盘不含有非料箱物料
                if(Cools.isEmpty(locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("matnr", mat.getMatnr())))){
                    continue;
                }
 
                Set<String> locNosSearch = locDetlService.selectLocNos(mat.getMatnr());
                //是否含有可补货出库的库位
                boolean flag = false;
                for (String locNo : locNosSearch){
                    //log.info("需要拣料的货位:" + locNo +",需要补货的物料:" + mat.getMatnr());
                    if(Cools.isEmpty(locDetlService.selectByLocWithoutContainer(locNo))){
                        flag = true;
                        continue;
                    }
                }
 
                if(flag){
                    autoReplenishmentHandler.create(mat,mat.getStoreMax() - anfmeSum);
                    break;
                }
            }
        }
    }
 
    /*
    定时处理自动补货单据
     */
    @Scheduled(cron = "0/10 * * * * ? ")
    public void excuteOrder(){
        DocType docType = docTypeService.selectOne(new EntityWrapper<DocType>().eq("doc_name", "自动补货单"));
        List<Order> orderList = orderService.selectList(new EntityWrapper<Order>()
                .eq("doc_type", docType.getDocId())
                .eq("settle",1));
        if(!Cools.isEmpty(orderList)){
            orderList.forEach(order -> {
                autoReplenishmentHandler.start(order);
            });
        }
    }
}