自动化立体仓库 - WMS系统
whycq
2024-07-08 8366535c15151e7def2ba8398be4dba3e3121727
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.CombParam;
import com.zy.asrs.service.*;
import com.zy.common.model.MobileLocDetlVo;
import com.zy.common.web.BaseController;
import com.zy.ints.entity.WaitMatchk;
import com.zy.ints.entity.WaitMatin;
import com.zy.ints.service.WaitMatchkService;
import com.zy.ints.service.WaitMatinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 移动端接口控制器
 * Created by vincent on 2020/6/10
 */
@RestController
@RequestMapping("mobile")
public class MobileController extends BaseController  {
 
    @Autowired
    private MobileService mobileService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private WrkDetlService wrkDetlService;
    @Autowired
    private WaitMatinService waitMatinService;
    @Autowired
    private WaitMatchkService waitMatchkService;
    @Autowired
    private MatCodeService matCodeService;
    @Autowired
    private WrkMastService wrkMastService;
 
    /**
     * 组托
     */
    @RequestMapping("/comb/auth")
    @ManagerAuth(memo = "组托")
    public R comb(@RequestBody CombParam combParam){
        System.out.println("combParam = " + combParam);
        mobileService.comb(combParam, getUserId());
        return R.ok();
    }
 
    /**
     * 组托
     */
    @RequestMapping("/comb/form")
    @ManagerAuth(memo = "组托")
    public R combForm(@RequestParam CombParam combParam){
        mobileService.comb(combParam, getUserId());
        return R.ok();
    }
 
    /**
     * 库存查询(根据物料编码和库位查询库存数量和捡料数量)
     * @param locNo
     * @param matNo
     * @return
     */
    @RequestMapping("/locDetl/stockQuery")
    @ManagerAuth
    public R stockQuery(@RequestParam(required = false)String locNo,
                        @RequestParam(required = false)String matNo){
        if (!Cools.isEmpty(locNo)) {
            LocMast locMast = locMastService.selectById(locNo);
            if (null == locMast || !"F".equals(locMast.getLocSts())) {
                return R.parse(BaseRes.EMPTY);
            }
            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
                    .eq("loc_no", locNo).orderBy("appe_time", false));
            List<MobileLocDetlVo> res = new ArrayList<>();
            locDetls.forEach(locDetl -> {
                MobileLocDetlVo vo = new MobileLocDetlVo();
                List<WrkDetl> wrkDetlsList = wrkDetlService.queryWrkDetl(locDetl.getMatNo(), locDetl.getLocNo());
                final Double[] pickNum = {0.0};
                wrkDetlsList.forEach(item -> {
                    pickNum[0] = pickNum[0] + item.getQty();
                });
                vo.setPickNum(pickNum[0]);
                vo.setLocNo(locDetl.getLocNo());
                vo.setMatNo(locDetl.getMatNo());
                vo.setMatName(locDetl.getMatName());
                vo.setCount(locDetl.getQty());
                res.add(vo);
            });
            return R.ok().add(res);
        }
        if (!Cools.isEmpty(matNo)) {
            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
                    .eq("mat_no", matNo).orderBy("appe_time", false));
            List<MobileLocDetlVo> res = new ArrayList<>();
            locDetls.forEach(locDetl -> {
                MobileLocDetlVo vo = new MobileLocDetlVo();
                List<WrkDetl> wrkDetlsList = wrkDetlService.queryWrkDetl(locDetl.getMatNo(), locDetl.getLocNo());
                final Double[] pickNum = {0.0};
                wrkDetlsList.forEach(item -> {
                    pickNum[0] = pickNum[0] + item.getQty();
                });
                vo.setPickNum(pickNum[0]);
                vo.setLocNo(locDetl.getLocNo());
                vo.setMatNo(locDetl.getMatNo());
                vo.setMatName(locDetl.getMatName());
                vo.setCount(locDetl.getQty());
                res.add(vo);
            });
            return R.ok().add(res);
        }
        return R.parse(BaseRes.PARAM);
    }
 
    // 拣料检索托盘信息
    @RequestMapping("/piking/auth")
    @ManagerAuth
    public R pikingAuth(String barcode) {
        WrkMast wrkMast = wrkMastService.selectByBarcode(barcode);
        if (Cools.isEmpty(wrkMast)) {
            throw new CoolException(barcode + "暂无工作档");
        }
        if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 107){
            throw new CoolException(barcode + "不为拣料/盘点出库");
        }
        List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
        return R.ok().add(wrkDetls);
    }
    /**
     *  根据库位号查找库存明细
     */
    @RequestMapping("/locDetl")
    @ManagerAuth
    public R getLocDetl(@RequestParam(required = false)String locNo,
                        @RequestParam(required = false)String matNo){
        if (!Cools.isEmpty(locNo)) {
            LocMast locMast = locMastService.selectById(locNo);
            if (null == locMast || !"F".equals(locMast.getLocSts())) {
                return R.parse(BaseRes.EMPTY);
            }
            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
                    .eq("loc_no", locNo).orderBy("appe_time", false));
            List<MobileLocDetlVo> res = new ArrayList<>();
            locDetls.forEach(locDetl -> {
                MobileLocDetlVo vo = new MobileLocDetlVo();
                vo.setLocNo(locDetl.getLocNo());
                vo.setMatNo(locDetl.getMatNo());
                vo.setMatName(locDetl.getMatName());
                vo.setCount(locDetl.getQty());
                res.add(vo);
            });
            return R.ok().add(res);
        }
        if (!Cools.isEmpty(matNo)) {
            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
                    .eq("mat_no", matNo).orderBy("appe_time", false));
            List<MobileLocDetlVo> res = new ArrayList<>();
            locDetls.forEach(locDetl -> {
                MobileLocDetlVo vo = new MobileLocDetlVo();
                vo.setLocNo(locDetl.getLocNo());
                vo.setMatNo(locDetl.getMatNo());
                vo.setMatName(locDetl.getMatName());
                vo.setCount(locDetl.getQty());
                res.add(vo);
            });
            return R.ok().add(res);
        }
        return R.parse(BaseRes.PARAM);
    }
 
    /**
     * 根据通知单查询明细
     */
    @RequestMapping("/bill/query/auth")
    @ManagerAuth(memo = "根据通知单查询明细")
    public R billQuery(@RequestParam String billNo){
        List<WaitMatin> waitMatins = waitMatinService.selectList(new EntityWrapper<WaitMatin>().eq("bill_no", billNo).last("and qty > in_qty"));
        List<CombBillQueryVo> vos = new ArrayList<>();
        if (!Cools.isEmpty(waitMatins)) {
            for (WaitMatin waitMatin : waitMatins) {
                CombBillQueryVo vo = new CombBillQueryVo();
                vo.setMatNo(waitMatin.getMatNo());
                vo.setMatName(waitMatin.getMatName());
                vo.setCount(waitMatin.getQty()-waitMatin.getInQty());
                vo.setBillNo(waitMatin.getBillNo());
                vo.setSeqNo(waitMatin.getSeqNo());
                vo.setUnit(waitMatin.getUnit());
                vo.setSpecs(waitMatin.getSpecs());
                vo.setSize(waitMatin.getSize());
                vo.setColor(waitMatin.getColor());
                vos.add(vo);
            }
        }
        return R.ok().add(vos);
    }
 
    /**
     * PDA盘点根据出库口查询对应物料信息
     */
    @RequestMapping("/check/queryMatFromDevNo")
    public R queryMatFromDevNo(Integer devNo) {
        List<WrkDetl> list = wrkDetlService.queryMatFromDevNo(devNo);
        return R.ok().add(list);
    }
 
    /**
     * 根据PDA盘点数量,更新盘点通知档
     * @param param
     * @return
     */
    @RequestMapping("/stock/check")
    @Transactional
    @ManagerAuth
    public R erpStockCheck(@RequestBody String param) {
        Boolean flag = false;
        JSONObject jsonObject = JSONObject.parseObject(param);
        String checkListStr = jsonObject.getString("checkList");
        List<WaitMatchk> checkList = JSONArray.parseArray(checkListStr, WaitMatchk.class);
        Long userId = 9527L; //getUserId();//9527L;
        int seq = 0;
        Date now = new Date();
        for (Integer i = 0; i < checkList.size(); i++) {
            String locNo = checkList.get(i).getLocNo();
            String matNo = checkList.get(i).getMatNo();
            Double checkQty = checkList.get(i).getCheckQty();
 
            Wrapper<WaitMatchk> wrapper = new EntityWrapper<WaitMatchk>().eq("loc_no",locNo).eq("mat_no",matNo);
            WaitMatchk waitMatchk0 = waitMatchkService.selectOne(wrapper);
            if(null != waitMatchk0){
                waitMatchk0.setCheckQty(checkQty);
                flag = waitMatchkService.update(waitMatchk0,wrapper);
                if(!flag){
                    throw new CoolException("更新盘点通知档失败");
                }
            } else {
                MatCode matCode = matCodeService.selectOne(new EntityWrapper<MatCode>().eq("mat_no",matNo));
                WaitMatchk waitMatchk1 = waitMatchkService.selectOne(new EntityWrapper<WaitMatchk>().eq("loc_no",locNo).orderBy("seq_no",false));
                if(null != matCode) {
                    WaitMatchk waitMatchk = new WaitMatchk();
                    waitMatchk.setLocNo(locNo);
                    waitMatchk.setMatNo(matNo);
                    if(null != waitMatchk1){
                        waitMatchk.setBillNo(waitMatchk1.getBillNo());
                        waitMatchk.setSeqNo(waitMatchk1.getSeqNo()+1);
                        waitMatchk.setZpallet(waitMatchk1.getZpallet());
                        waitMatchk.setLinkErp(waitMatchk1.getLinkErp());
                        waitMatchk.setIoStatus(waitMatchk1.getIoStatus());
                    } else {
                        waitMatchk.setBillNo("0");
                        waitMatchk.setSeqNo(seq++);
                        waitMatchk.setLinkErp(0);
                        waitMatchk.setIoStatus(1);
                    }
                    waitMatchk.setBillType(1);//抽盘
                    waitMatchk.setMatName(matCode.getMatName());
                    waitMatchk.setStockQty(0D);
                    waitMatchk.setCheckQty(checkQty);
                    waitMatchk.setModiTime(now);
                    waitMatchk.setModiUser(getUserId());
                    waitMatchk.setAppeTime(now);
                    waitMatchk.setAppeUser(getUserId());
                    flag = waitMatchkService.insert(waitMatchk);
                    if(!flag){
                        throw new CoolException("新增盘点通知档数据失败");
                    }
                }
 
            }
        }
        return R.ok().add(flag);
    }
 
    // 拣料转全板
    // sBarcode 原托盘码  tBarcode 转换托盘码
    @RequestMapping("/piking/to/full")
    @ManagerAuth
    @Transactional
    public R pikingToFull(String sBarcode,String tBarcode) {
        //  检查转换托盘码是否在库
        List<LocDetl> locDetls = locDetlService.selectByZpallet(tBarcode);
        if (!Cools.isEmpty(locDetls)) {
            throw new CoolException("需要转换的托盘已被使用,请更换托盘!");
        }
        WrkMast twrkMast = wrkMastService.selectByBarcode(tBarcode);
        if (!Cools.isEmpty(twrkMast)) {
            throw new CoolException("需要转换的托盘已被使用,请更换托盘!");
        }
        LocMast tlocMast = locMastService.selectByBarcode(tBarcode);
        if (!Cools.isEmpty(tlocMast)) {
            throw new CoolException("需要转换的托盘已被使用,请更换托盘!");
        }
        WrkDetl twrkDetl = wrkDetlService.selectByZpallet0(tBarcode);
        if (!Cools.isEmpty(twrkDetl)) {
            throw new CoolException("需要转换的托盘已被使用,请更换托盘!");
        }
//        修改工作档托盘码
        WrkMast wrkMast = wrkMastService.selectByBarcode(sBarcode);
        if (wrkMast.getWrkSts() != 14) {
            throw new CoolException("出库未完成!");
        }
        List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo());
        for (WrkDetl wrkDetl : wrkDetls) {
            //++++
            wrkDetlService.updateBarcode(sBarcode,tBarcode,wrkDetl.getSupplier());
        }
 
        if (Cools.isEmpty(wrkMast)) {
            throw new CoolException("请确认托盘码!");
        }
//                修改库存明细档托盘码
        List<LocDetl> locDetls1 = locDetlService.selectByZpallet(sBarcode);
        for (LocDetl locDetl : locDetls1) {
            //++++
            locDetlService.updateZpallet(sBarcode,tBarcode,locDetl.getSupplier());
        }
//        修改工作主档条码
        wrkMast.setBarcode(tBarcode);
        wrkMastService.updateById(wrkMast);
        LocMast locMast = locMastService.selectByBarcode(sBarcode);
        locMast.setBarcode(tBarcode);
        locMastService.updateById(locMast);
        return R.ok("转换成功");
    }
}