自动化立体仓库 - WMS系统
#
luxiaotao1123
2021-03-22 0a58dc2ed7c8349efc4e7dd0b45d8c6ab7e6f9df
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
package com.zy.asrs.controller;
 
import com.core.common.Cools;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.MatCode;
import com.zy.asrs.entity.param.OpenApiStockOutParam;
import com.zy.asrs.entity.result.StoPreTab;
import com.zy.asrs.service.LocDetlService;
import com.zy.asrs.service.MatCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
 
/**
 * Created by vincent on 2021/3/19
 */
@RestController
@RequestMapping("/open/api")
public class OpenController {
 
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private MatCodeService matCodeService;
 
    @PostMapping("/stockOut/prew")
    @Transactional
    public R stockOutPrew(@RequestBody List<OpenApiStockOutParam> params){
        List<StoPreTab> result = new ArrayList<>();
        StringBuilder errorMsg = new StringBuilder();
        boolean error = false;
        for (OpenApiStockOutParam param : params) {
            Double sumAnfme = Optional.ofNullable(locDetlService.getSumAnfme(param.getMatnr())).orElse(0.0D);
            if (sumAnfme < param.getAnfme()) {
                if (!error) {
                    error = true;
                }
                MatCode mat = matCodeService.selectById(param.getMatnr());
                errorMsg.append(mat == null ? param.getMatnr() : mat.getMatName()).append("库存不足,缺货数量:").append(param.getAnfme() - sumAnfme).append("</br>");
                continue;
            }
            List<LocDetl> locDetls = locDetlService.selectPakoutByRule(param.getMatnr());
            double issued = Optional.ofNullable(param.getAnfme()).orElse(0.0D) ;
            double anfme = issued;
            for (LocDetl locDetl : locDetls) {
                if (issued > 0) {
                    // 视图对象
                    StoPreTab tab = new StoPreTab();
                    tab.setTitle(locDetl.getMatnr() + "(" + locDetl.getMaktx() + ")");
                    tab.setMatnr(locDetl.getMatnr());
                    tab.setMaktx(locDetl.getMaktx());
                    tab.setAnfme(param.getTotal());
 
                    tab.setLocNo(locDetl.getLocNo());
//                    tab.setNodeId(locDetl.getNodeId());
                    tab.setTotal(locDetl.getAnfme());
                    tab.setReduce(issued>=locDetl.getAnfme()?locDetl.getAnfme():issued);
                    tab.setRemQty(tab.getTotal() - tab.getReduce());
                    tab.setPrior(false);
                    tab.setPrior$("×");
                    tab.setType(2);
                    result.add(tab);
                    // 剩余待出数量递减
                    issued = issued - locDetl.getAnfme();
                }
            }
 
        }
        if (error) {
            return R.error().add(errorMsg.toString());
        }
        return R.ok().add(result);
    }
 
    @PostMapping("/stockOut")
    @Transactional
    public R stockOut(@RequestBody List<OpenApiStockOutParam> params){
        if (!Cools.isEmpty(params)) {
            for (OpenApiStockOutParam param : params) {
                Double sumAnfme = Optional.ofNullable(locDetlService.getSumAnfme(param.getMatnr())).orElse(0.0D);
                if (sumAnfme < param.getAnfme()) {
                    throw new CoolException(param.getMatnr() + "物料数量不足,缺货数量:" + (param.getAnfme() - sumAnfme));
                }
 
 
 
            }
        }
 
 
        return R.ok();
    }
 
 
}