自动化立体仓库 - WMS系统
*
lsh
19 小时以前 64781aac1c41bb8c4dda2deb4dc7ae98cace8315
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
package com.zy.asrs.utils;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.param.StockOutParam;
import com.zy.asrs.service.LocDetlService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.WorkService;
import com.zy.common.model.LocDto;
import com.zy.common.properties.SlaveProperties;
import com.zy.system.entity.OperateLog;
import com.zy.system.service.OperateLogService;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import static org.reflections.Reflections.log;
 
public class OrderOutBatchUtil {
    private String errorMsgOrderLoc = "";
    private boolean sign = true;
    private String orderOneNo = null;
    private String cstmrName = null;
    private String ip = "";
    private String action = "";
    private String orderName = "";
    private Long userId = 9999L;
 
 
    public OrderOutBatchUtil() {
        this.sign = true;
        this.errorMsgOrderLoc = "";
    }
 
    public OrderOutBatchUtil(String orderOneNo, String cstmrName) {
        this.errorMsgOrderLoc = "";
        this.sign = true;
        this.orderOneNo = orderOneNo;
        this.cstmrName = cstmrName;
    }
 
    public OrderOutBatchUtil(String orderOneNo, String cstmrName, String ip, String action,String orderName) {
        this.errorMsgOrderLoc = "";
        this.sign = true;
        this.orderOneNo = orderOneNo;
        this.cstmrName = cstmrName;
        this.ip = ip;
        this.action = action;
        this.orderName = orderName;
        this.userId = 9999L;
    }
 
    public R setOrderOutBatch() {
        return R.ok();
    }
 
 
    public R setOrderOutBatch(List<String[]> OutLocBoxCs) {
        int total = OutLocBoxCs.size();
        if (!Cools.isEmpty(OutLocBoxCs) && !OutLocBoxCs.isEmpty()) {
            LocDetlService locDetlService = SpringUtils.getBean(LocDetlService.class);
            LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
            SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class);
            WorkService workService = SpringUtils.getBean(WorkService.class);
            List<LocDto> locDtos = new ArrayList<>();
            List<String[]> outLocBoxCList = new ArrayList<>();
            List<String> outLocBoxCNew = new ArrayList<>();
            for (String[] outLocBoxC : OutLocBoxCs) {
                total--;
                if (!outLocBoxCNew.contains(outLocBoxC[0])) {
                    LocDetl locDetlSou = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("batch", outLocBoxC[0]));
                    if (Cools.isEmpty(locDetlSou)) {
                        sign = false;
                        errorMsgOrderLoc = errorMsgOrderLoc + "[===》" + "箱号:" + outLocBoxC[0] + " 未查询到数据!!!《===]";
                        continue;
//                        throw new CoolException("箱号:"+outLocBoxC[0]+" 未查询到数据!!!");
                    }
//                    if (!locDetlSou.getDanger$().equals(outLocBoxC[4])) {
//                        sign = false;
//                        errorMsgOrderLoc = errorMsgOrderLoc + "[===》" + "箱号:" + outLocBoxC[0] + " ==》出库输入待判状态:" + outLocBoxC[4] + "、库存状态:" + locDetlSou.getDanger$() + "。状态不匹配《===]";
//                        continue;
//                    }
                    LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetlSou.getLocNo()));
                    if (Cools.isEmpty(locMast)) {
                        sign = false;
                        errorMsgOrderLoc = errorMsgOrderLoc + "[===》" + "箱号:" + outLocBoxC[0] + " 所在库位不满足出库条件!!!未查询到此箱号所在库位" + "《===]";
                        continue;
                    }
                    if (!locMast.getLocSts().equals("F")) {
                        sign = false;
                        errorMsgOrderLoc = errorMsgOrderLoc + "[===》" + "箱号:" + outLocBoxC[0] + " 所在库位不满足出库条件!!!库位状态不为F!!!库位状态:" + locMast.getLocSts$() + "《===]";
                        continue;
                    }
 
                    // 目标库位 ===>> 浅库位
                    if (Utils.isShallowLoc(slaveProperties, locMast.getLocNo())) {
                        String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast.getLocNo());
                        LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", shallowLoc));
                        if (!Cools.isEmpty(locMast2)) {
                            if (locMast2.getLocSts().equals("P") || locMast2.getLocSts().equals("R")) {
                                errorMsgOrderLoc = errorMsgOrderLoc + "[===》" + "箱号:" + outLocBoxC[0] + " 所在库位满足出库条件!!!但是深库位在出库中!!!因此会夹杂在前边订单执行!!!" + "《===]";
                            }
                        }
                    }
 
                    if (sign) {
                        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
                                .eq("loc_no", locDetlSou.getLocNo()).eq("origin", locDetlSou.getOrigin()));
                        for (LocDetl locDetl : locDetls) {
                            total++;
                            String[] locDetlNow = new String[5];
                            locDetlNow[0] = locDetl.getBatch();
                            locDetlNow[1] = outLocBoxC[1];
                            locDetlNow[2] = outLocBoxC[2];
                            locDetlNow[3] = outLocBoxC[3];
                            locDetlNow[4] = outLocBoxC[4];
                            outLocBoxCList.add(locDetlNow);
                            outLocBoxCNew.add(outLocBoxC[0]);
                        }
                    }
                }
            }
            for (String[] outLocBoxC : outLocBoxCList) {
                LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("batch", outLocBoxC[0]));
                if (Cools.isEmpty(locDetl)) {
                    total--;
                    continue;
                }
 
                if (!Cools.isEmpty(outLocBoxC[3])) {
                    String memo = Cools.isEmpty(locDetl.getMemo()) ? "" : locDetl.getMemo() + ",";
                    locDetl.setMemo(memo + DateUtils.convert(new Date(), DateUtils.yyyyMMdd_C) + "备注:" + outLocBoxC[3]);
                } else if (Cools.isEmpty(locDetl.getMemo())) {
                    locDetl.setMemo(outLocBoxC[3]);
                }
                LocDto locDto = new LocDto(locDetl);
                locDtos.add(locDto);
            }
 
            StockOutParam param = new StockOutParam();
            ArrayList<StockOutParam.LocDetl> locDetls = new ArrayList<>();
            List<LocDto> locDtosList = new ArrayList<>();
            List<String> batchList = new ArrayList<>();
            for (LocDto locDto : locDtos) {
                if (!batchList.contains(locDto.getBatch())) {
                    batchList.add(locDto.getBatch());
                    locDtosList.add(locDto);
                }
            }
            for (LocDto locDto : locDtosList) {
                StockOutParam.LocDetl locDetl = new StockOutParam.LocDetl();
                locDetl.setBrand(locDto.getBrand());
                locDetl.setLocNo(locDto.getLocNo());
                locDetl.setAnfme(locDto.getAnfme());
                locDetl.setMatnr(locDto.getMatnr());
                locDetl.setBatch(locDto.getBatch());
                locDetl.setModel(locDto.getModel());
                locDetl.setSpecs(locDto.getSpecs());
                locDetl.setZpallet(locDto.getZpallet());
                locDetl.setOrigin(locDto.getOrigin());
                locDetl.setWeight(locDto.getWeight());
                locDetl.setMemo(locDto.getMemo());
                locDetl.setDanger(locDto.getDanger());
 
                locDetls.add(locDetl);
            }
            param.setLocDetls(locDetls);
            param.setOrderNo(orderOneNo);
            param.setCstmrName(cstmrName);
            param.setOrderName(orderName);
 
            if (sign && total > 0) {
                workService.startupFullTakeStoreOrder(param, 9999L);
            }
 
            try {
                OperateLogService operateLogService = SpringUtils.getBean(OperateLogService.class);
                // 记录操作日志
                OperateLog operateLog = new OperateLog();
                operateLog.setAction(action);
                operateLog.setIp(ip);
                operateLog.setUserId(9999L);
                operateLog.setRequest("单号:" + orderOneNo + "、客户名:" + cstmrName);
                operateLog.setResponse(errorMsgOrderLoc.equals("") ? "正常" : (sign && total > 0) ? "成功:" + errorMsgOrderLoc : "失败:" + errorMsgOrderLoc);
                operateLogService.insert(operateLog);
            } catch (Exception e) {
                log.error("记录操作日志失败!" + e.getMessage());
            }
 
        }
 
        log.info("出库{}条箱号!", total);
 
        String requert = errorMsgOrderLoc.equals("") ? "正常" : (sign && total > 0) ? "成功:" + errorMsgOrderLoc : "失败:" + errorMsgOrderLoc;
        if (sign && total > 0) {
            return R.ok(requert.equals("正常")? "成功":requert);
        }
        return R.error(requert);
    }
}