自动化立体仓库 - WMS系统
#
zyx
2024-05-08 4d99b3dd7a4e3aba703740152bd1c2d72a36874e
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
package com.zy.asrs.task.handler;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.*;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
import com.zy.asrs.utils.Utils;
import com.zy.common.properties.SlaveProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
import java.util.List;
 
/**
 * Created by vincent on 2020/7/6
 */
@Service
@Slf4j
public class CheckDeepHandler extends AbstractHandler<String> {
 
    @Value("${wcs-slave.doubleDeep}")
    private boolean confirmDeep;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private WorkService workService;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private SlaveProperties slaveProperties;
 
    @Transactional
    public synchronized ReturnT<String> start() {
        try {
            for (int crnNo = 1; crnNo < 3; crnNo++){
                List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                        .eq("crn_no",crnNo)
                        .last(" and wrk_sts in (2,3,4,11,12)")
                );
                if (wrkMasts.size() > 0) continue;
 
                //暂停移库
                BasCrnp crnp = basCrnpService.selectById(crnNo);
                if(!Cools.isEmpty(crnp) && !Cools.isEmpty(crnp.getTankQty()) && crnp.getTankQty()==0){
                    continue;
                }
 
                List<LocMast> locMasts = locMastService.queryShallowLocFMast(crnNo);
                if (null == locMasts) continue;
 
                for (LocMast sourceLoc : locMasts){
                    String deep = Utils.getDeepLoc(slaveProperties, sourceLoc.getLocNo());
                    LocMast destLoc = locMastService.selectById(deep);
 
                    if(!Cools.isEmpty(sourceLoc) && !Cools.isEmpty(destLoc)) {
                        //查找源库位是否有转移任务,如果有,不生成库位移转
                        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
                                .eq("source_loc_no", sourceLoc.getLocNo()));
                        if (Cools.isEmpty(wrkMast) && destLoc.getLocSts().equals("O") &&
                                (sourceLoc.getLocSts().equals("F") || sourceLoc.getLocSts().equals("D"))) {
                            workService.locMove(sourceLoc.getLocNo(), deep, 1L);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return FAIL.setMsg(e.getMessage());
        }
        return SUCCESS;
    }
 
    /**
     * 遍历库存中,浅库位状态F,深库位状态O的数据,生成库位移转工作档将浅库位移转到对应深库位中去
     */
//    private void locMoveToDeep(int crnNo){
//        if (!confirmDeep) return;
//        List<LocMast> locMasts = locMastService.queryShallowLocFMast();
//
//
//        if (null == locMasts) return;
//
//        for (LocMast sourceLoc : locMasts){
//            String deep = Utils.getDeepLoc(slaveProperties, sourceLoc.getLocNo());
//            LocMast destLoc = locMastService.selectById(deep);
//
//            if(!Cools.isEmpty(sourceLoc) && !Cools.isEmpty(destLoc)) {
//                //查找源库位是否有转移任务,如果有,不生成库位移转
//                WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
//                        .eq("source_loc_no", sourceLoc.getLocNo()));
//                if (Cools.isEmpty(wrkMast) && destLoc.getLocSts().equals("O") &&
//                        (sourceLoc.getLocSts().equals("F") || sourceLoc.getLocSts().equals("D"))) {
//                    workService.locMove(sourceLoc.getLocNo(), deep, 1L);
//                }
//            }
//        }
//
//    }
 
//    @Transactional
//    public synchronized ReturnT<String> start1() {
//        try {
//            for (int crnNo = 1; crnNo < 6; crnNo++){
//                List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
//                        .eq("crn_no",crnNo)
//                        .last(" and wrk_sts in (2,3,4,11,12)")
//                );
//                if (wrkMasts.size() > 0) continue;
//
//                //暂停移库
//                BasCrnp crnp = basCrnpService.selectById(crnNo);
//                if(!Cools.isEmpty(crnp) && crnp.getOrigin()!=0){
//                    continue;
//                }
//
//                //遍历库存中,深浅库位状态都为F,物料不相同,或者浅库位入库日期比深库位早的库位,做库位移转移到新的深库位中去
//                boolean flag0 = false;
//                List<LocMast> locMasts = locMastService.queryNeedMoveShallLoc(crnNo);
//                for (LocMast locMast : locMasts) {
//                    //多笔明细的不做移转调整
//                    List<LocDetl> shallowLocDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
//                            .eq("loc_no", locMast.getLocNo()));
//                    String deepLoc = Utils.getDeepLoc(slaveProperties, locMast.getLocNo());
//                    List<LocDetl> deepLocDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
//                            .eq("loc_no", deepLoc));
//
//                    if ((!Cools.isEmpty(shallowLocDetls) && shallowLocDetls.size()>1)
//                        || (!Cools.isEmpty(deepLocDetls) && deepLocDetls.size()>1)) {
//                        continue;
//                    }
//
//                    LocMast targetLoc = locMastService.queryEmptyDeepLoc(crnNo);
//                    if(!Cools.isEmpty(targetLoc)) {
//                        workService.locMove(locMast.getLocNo(), targetLoc.getLocNo(), 1L);
//                        log.info("浅库位移转到深库位:生成库位移转任务成功[浅到深]===>>" + locMast.getLocNo() + "---" + targetLoc.getLocNo());
//                        flag0 = true;
//                    }
//                    break;
//                }
//                if(flag0) continue;
//
////                List<LocMast> ignoreLocs = new ArrayList<>();
//                List<LocMast> allDeeps = locMastService.selectAllDeepLoc(crnNo);
//                for (LocMast sourceDeep : allDeeps) {
//
//                    LocDetl sourceLoc = locDetlService.selectOne(new EntityWrapper<LocDetl>()
//                            .eq("loc_no", sourceDeep.getLocNo()).orderBy("mat_no"));
//                    if(Cools.isEmpty(sourceLoc)){
//                        continue;
//                    }
//
//                    boolean moveFlag = false;//每次执行一笔
////                    //如果这个库位已经被操作过了,直接跳过
////                    Boolean flag = false;
////                    for (LocMast ignoreLoc : ignoreLocs) {
////                        if (ignoreLoc.getLocNo() == sourceDeep.getLocNo()) {
////                            flag = true;
////                            break;
////                        }
////                    }
////                    if (flag) {
////                        continue;
////                    }
//
//                    List<LocMast> allDeepsWithCrnNo = locMastService.selectAllDeepLocWithCrnNo(sourceDeep.getCrnNo(),
//                            sourceLoc.getMatNo(), sourceLoc.getItemBatch(), sourceLoc.getSpecs());
//                    for (LocMast targetDeep : allDeepsWithCrnNo) {
//                        if(targetDeep.getLocNo().equals(sourceDeep.getLocNo())){
//                            continue;
//                        }
////                        LocDetl sourceLoc = locDetlService.selectOne(new EntityWrapper<LocDetl>()
////                                .eq("loc_no", sourceDeep.getLocNo()));
//
//                        LocDetl targetLoc = locDetlService.selectOne(new EntityWrapper<LocDetl>()
//                                .eq("loc_no", targetDeep.getLocNo()));
//                        //多笔明细的不做移转调整
//                        List<LocDetl> sourceLocDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
//                                .eq("loc_no", sourceDeep.getLocNo()));
//                        List<LocDetl> targetLocDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
//                                .eq("loc_no", targetDeep.getLocNo()));
//
//                        if (Cools.isEmpty(targetLoc)
//                                || (!Cools.isEmpty(sourceLocDetls) && sourceLocDetls.size()>1)
//                                || (!Cools.isEmpty(targetLocDetls) && targetLocDetls.size()>1)) {
//                            continue;
//                        }
//
//                        //物料号相同,源库位入库日期早于目标库位对应深库位入库日期,库位状态都为F
//                        if (sourceLoc.getMatNo().equals(targetLoc.getMatNo())
//                                && sourceLoc.getItemBatch().equals(targetLoc.getItemBatch())
//                                && sourceLoc.getSpecs().equals(targetLoc.getSpecs())
//                                && sourceLoc.getAppeTime().getTime() < targetLoc.getAppeTime().getTime()
//                                && sourceDeep.getLocSts().equals("F") && targetDeep.getLocSts().equals("F")) {
//
////                    System.out.println("成功: "+sourceDeep +"-----" +targetDeep);
//                            String shallow = convertShallow(targetDeep.getLocNo());
//                            LocMast shallowLoc = locMastService.selectById(shallow);
//                            if(!Cools.isEmpty(shallowLoc) && shallowLoc.getLocSts().equals("O")) {
//                                workService.locMove(sourceDeep.getLocNo(), shallow, 1L);
//                                log.info("深库位合并定时任务:生成库位移转任务成功[深到浅]===>>" + sourceDeep.getLocNo() + "---" + shallow);
//                                moveFlag=true;
////                                ignoreLocs.add(sourceDeep);
////                                ignoreLocs.add(targetDeep);
//                                break;
//                            }
//                        }
//                    }
//                    if(moveFlag) break;
//                }
//
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//            return FAIL.setMsg(e.getMessage());
//        }
//        return SUCCESS;
//    }
 
    /**
     * 将深库位转为对应浅库位
     * @param deep
     * @return
     */
    private String convertShallow(String deep){
        String shallLoc = "";
        Integer mastInt = Integer.parseInt(deep.substring(0, 2));
        if (mastInt % 2 == 0){
            mastInt -= 1;
        }else if (mastInt % 2 == 1){
            mastInt += 1;
        }
        if (mastInt <10){
            shallLoc = "0" + mastInt+ deep.substring(2,7);
        }else {
            shallLoc = mastInt+ deep.substring(2,7);
        }
        return shallLoc;
    }
 
}