自动化立体仓库 - WMS系统
#
lsh
3 天以前 1c99199ceac9596a30cf0cd4e57d684ac7da7a94
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
package com.zy.asrs.utils;
 
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.OrderDetl;
import com.zy.asrs.entity.param.StockOutParam;
import com.zy.asrs.service.*;
import com.zy.common.entity.OutLocBoxExcel;
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 lombok.extern.slf4j.Slf4j;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * Created by vincent on 2019-11-25
 */
@Slf4j
public class OutLocBoxExcelListener extends AnalysisEventListener<OutLocBoxExcel> {
 
    private int total = 0;
    private String errorMsgOrderLoc = "";
    private String orderOneNo = null;
    private String cstmrName = null;
    private Long userId;
    private String remoteAddr;
    private boolean sign = true;
 
    List<String[]> OutLocBoxCs = new ArrayList<>();
 
    public OutLocBoxExcelListener() {
    }
 
    public OutLocBoxExcelListener(Long userId) {
        this.userId = userId;
    }
 
    public OutLocBoxExcelListener(String remoteAddr,Long userId) {
        this.remoteAddr = remoteAddr;
        this.userId = userId;
    }
 
    /**
     * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
     */
    private static final int BATCH_COUNT = 50;
 
    private final List<OutLocBoxExcel> list = new ArrayList<>();
 
    /**
     * 这里会一行行的返回头
     */
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
    }
 
    /**
     * 这个每一条数据解析都会来调用
     */
    @Override
    public void invoke(OutLocBoxExcel excel, AnalysisContext ctx) {
        String batch = excel.getBatch();
        String orderNo = excel.getOrderNo();
//        String cstmrName = excel.getCstmrName();
        String memo = excel.getMemo();
        if (Cools.isEmpty(orderOneNo)){
            if (!Cools.isEmpty(excel.getOrderNo())){
                orderOneNo = excel.getOrderNo();
            } else {
                throw new CoolException("订单号参数为空");
            }
        }
        if (Cools.isEmpty(cstmrName)){
            if (!Cools.isEmpty(excel.getCstmrName())){
                cstmrName = excel.getCstmrName();
            } else {
                throw new CoolException("客户名称参数为空");
            }
        }
        String[] s=new String[4];
        s[0] = batch;
        s[1] = orderOneNo;
        s[2] = cstmrName;
        s[3] = memo;
        OutLocBoxCs.add(s);
        total++;
    }
 
    /**
     * 所有数据解析完成了调用
     * 适合事务
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext ctx) {
        if (!Cools.isEmpty(OutLocBoxCs) && OutLocBoxCs.size() != 0) {
            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]+" 未查询到数据!!!");
                    }
                    LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locDetlSou.getLocNo()));
                    if (Cools.isEmpty(locMast)){
                        sign = false;
                        errorMsgOrderLoc = errorMsgOrderLoc + "[===》" +"箱号:"+outLocBoxC[0]+" 所在库位不满足出库条件!!!未查询到此箱号所在库位"+"《===]";
                        continue;
//                        throw new CoolException("箱号:"+outLocBoxC[0]+" 所在库位不满足出库条件!!!未查询到此箱号所在库位");
                    }
                    if (!locMast.getLocSts().equals("F")){
                        sign = false;
                        errorMsgOrderLoc = errorMsgOrderLoc + "[===》" +"箱号:"+outLocBoxC[0]+" 所在库位不满足出库条件!!!库位状态不为F!!!库位状态:"+locMast.getLocSts$()+"《===]";
                        continue;
//                        throw new CoolException("箱号:"+outLocBoxC[0]+" 所在库位不满足出库条件!!!库位状态不为F!!!库位状态:"+locMast.getLocSts$());
                    }
 
                    // 目标库位 ===>> 浅库位
                    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[4];
                            locDetlNow[0] = locDetl.getBatch();
                            locDetlNow[1] = outLocBoxC[1];
                            locDetlNow[2] = outLocBoxC[2];
                            locDetlNow[3] = outLocBoxC[3];
                            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;
                }
//                LocDto locDto = new LocDto(locDetl.getManu(), locDetl.getMatnr(), locDetl.getMaktx(),locDetl.getModel(),locDetl.getSpecs(),
//                        locDetl.getBatch(),locDetl.getBrand(),locDetl.getBarcode(), outLocBoxC[1],locDetl.getAnfme());
//                locDto.setOrigin(locDetl.getOrigin());
//                locDto.setWeight(locDetl.getWeight());
                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());
 
                locDetls.add(locDetl);
            }
            param.setLocDetls(locDetls);
            param.setOrderNo(orderOneNo);
            param.setCstmrName(cstmrName);
 
            if (sign && total>0){
                workService.startupFullTakeStoreOrder(param,9999L);
            }
 
            try {
                OperateLogService operateLogService = SpringUtils.getBean(OperateLogService.class);
                // 记录操作日志
                OperateLog operateLog = new OperateLog();
                operateLog.setAction("导入订单批量出库");
                operateLog.setIp(remoteAddr);
                operateLog.setUserId(userId);
                operateLog.setRequest("单号:"+orderOneNo+"、客户名:"+cstmrName);
                operateLog.setResponse(errorMsgOrderLoc.equals("")? "正常" : (sign && total>0)? "成功:"+errorMsgOrderLoc : "失败:"+errorMsgOrderLoc);
                operateLogService.insert(operateLog);
            } catch (Exception e){
                log.error("记录操作日志失败!"+e.getMessage());
            }
 
//            if (!sign || total<1){
//                throw new CoolException("失败:"+errorMsgOrderLoc);
//            }
 
        }
 
        log.info("出库{}条箱号!", total);
    }
 
    public int getTotal() {
        return total;
    }
 
    public boolean getSign() {
        return sign;
    }
 
    public String getErrorMsgOrderLoc() {
        return errorMsgOrderLoc;
    }
}