自动化立体仓库 - WMS系统
zjj
2023-06-18 28239b573a4be5e7678de8c65279153a7b17b760
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
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.service.LocDetlService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.*;
 
import java.io.*;
import java.util.ArrayList;
import java.util.List;
 
@RestController
 
public class MapController extends BaseController {
 
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private LocDetlService locDetlService;
 
    private static final List<String> DISABLE_LOC_NO = new ArrayList<String>() {{
 
    }};
 
    @GetMapping("/map/getData/auth")
    @ManagerAuth
    public String getMapData(@RequestParam Integer lev,@RequestParam Integer area) {
        try {
            String mapFilename = "map.json";
//            String fileName ="file:" + new ClassPathResource(mapFilename).getPath();
            //获取当前楼层库位数据
            List<LocMast> locMasts = locMastService.selectLocByLev(lev);
            switch (area){
                case 1:
                    break;
                case 2:
                case 3:
                    mapFilename = "DTBnode.json";
                    locMasts = locMastService.selectNodeBLocByLev(lev);
                    break;
                case 4:
                    mapFilename = "DTCnode.json";
                    locMasts = locMastService.selectNodeCLocByLev(lev);
                    break;
                case 5:
                    mapFilename = "DTDnode.json";
                    locMasts = locMastService.selectNodeDLocByLev(lev);
                    break;
                case 6:
                    mapFilename = "DTEnode.json";
                    locMasts = locMastService.selectNodeELocByLev(lev);
                    break;
 
 
            }
            String fileName = this.getClass().getClassLoader().getResource(mapFilename).getPath();//获取文件路径
//            File file = new File("D:\\workspace\\zy-asrs\\src\\main\\resources\\map.json");
            File file = new File(fileName);
            StringBuffer stringBuffer = new StringBuffer();
            if (file.isFile() && file.exists()) {
                InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
                BufferedReader br = new BufferedReader(isr);
                String lineTxt = null;
                while ((lineTxt = br.readLine()) != null) {
                    stringBuffer.append(lineTxt);
                }
                br.close();
 
                //解析json地图数据
                List<ArrayList> arrayLists = JSON.parseArray(stringBuffer.toString(), ArrayList.class);
                for (String locNo : DISABLE_LOC_NO) {//禁用设置库位
                    int row = Utils.getRow(locNo);
                    int bay = Utils.getBay(locNo);
                    if (row >= 2 && row <= 12) {
                        row++;
                    }else if (row == 13) {
                        row += 2;
                    }
                    ArrayList rowData = arrayLists.get(row);
                    Object o = rowData.get(bay);
                    JSONObject jsonObject = JSON.parseObject(o.toString());
                    jsonObject.put("value", 10);//将禁用库位进行设置
                    //更新list
                    rowData.set(bay, jsonObject);
                    arrayLists.set(row, rowData);
                }
 
 
 
                for (LocMast locMast : locMasts) {
 
                    Integer row = locMast.getRow1();
                    Integer bay = locMast.getBay1();
 
                    switch (area){
                        case 1:
                            if (row % 4 == 0 || (row+1) % 4 == 0) {
                                row=row+locMast.getCrnNo();
                            }else{
                                row=row+locMast.getCrnNo()-1;
                            }
                            bay=32-bay;
                            break;
                        case 2:
                        case 3:
//                            if (row<=3 || row>=5){
//                                if (row%1==0){
//                                    row=row+(row/1)-1;
//                                }else {
//                                    row=row+((row+1)/1)-1;
//                                }
//                            }else {
//                                if (row%2==0){
//                                    row=row+(row/2);
//                                }else {
//                                    row=row+((row-1)/2);
//                                }
//                            }
//                            if (row == 9){
//                                row= row -1;
//                            }
 
                            if (row ==7) {
                                row=row+2;
                            }else{
                                if (row>7){
                                    row=row+locMast.getCrnNo()+1;
                                }else {
                                    row=row+locMast.getCrnNo()-1;
                                }
                            }
                            break;
                        case 4:
//                            if (row<=11){
////                                if (row%2==0){
////                                    row=row+(row/2)-1;
////                                }else {
////                                    row=row+((row+1)/2)-1;
////                                }
////                            }else {
////                                if (row%2==0){
////                                    row=row+(row/2);
////                                }else {
////                                    row=row+((row-1)/2);
////                                }
////                            }
 
                            if (row % 10 == 0) {
                                row=row+2;
                            }else{
                                if (row>10){
                                    row=row+locMast.getCrnNo()+1;
                                }else {
                                    row=row+locMast.getCrnNo()-1;
                                }
                            }
                            break;
                        case 5:
//                            if (row<=11){
//                                if (row%2==0){
//                                    row=row+(row/2)-1;
//                                }else {
//                                    row=row+((row+1)/2)-1;
//                                }
//                            }else {
//                                if (row%2==0){
//                                    row=row+(row/2);
//                                }else {
//                                    row=row+((row-1)/2);
//                                }
//                            }
 
                            if (row % 7 == 0) {
                                row=row+2;
                            }else{
                                if (row>7){
                                    row=row+locMast.getCrnNo()+1;
                                }else {
                                    row=row+locMast.getCrnNo()-1;
                                }
                            }
                            break;
 
 
 
                    }
 
                    ArrayList rowData = arrayLists.get(row);
                    Object o = rowData.get(bay);
                    JSONObject jsonObject = JSON.parseObject(o.toString());
                    jsonObject.put("locNo", locMast.getLocNo());//设置库位号
                    jsonObject.put("locSts", locMast.getLocSts());//库位状态
                    //jsonObject.put("locSts$", locMast.getLocSts$());//库位状态
                    //更新list
                    rowData.set(bay, jsonObject);
                    arrayLists.set(row, rowData);
 
 
 
//                    if (area == 1 || area == 6){
//                        ArrayList rowData = arrayLists.get(row);
//                        Object o = rowData.get(bay);
//                        JSONObject jsonObject = JSON.parseObject(o.toString());
//                        jsonObject.put("locNo", locMast.getLocNo());//设置库位号
//                        jsonObject.put("locSts", locMast.getLocSts());//库位状态
//                        //jsonObject.put("locSts$", locMast.getLocSts$());//库位状态
//                        //更新list
//                        rowData.set(bay, jsonObject);
//                        arrayLists.set(row, rowData);
//                    }else {
//                        ArrayList rowData = arrayLists.get(bay);
//                        Object o = rowData.get(row);
//                        JSONObject jsonObject = JSON.parseObject(o.toString());
//                        jsonObject.put("locNo", locMast.getLocNo());//设置库位号
//                        jsonObject.put("locSts", locMast.getLocSts());//库位状态
//                        //jsonObject.put("locSts$", locMast.getLocSts$());//库位状态
//                        //更新list
//                        rowData.set(row, jsonObject);
//                        arrayLists.set(bay, rowData);
//                    }
 
 
 
                }
 
                return JSONObject.toJSONString(arrayLists);
            } else {
                System.out.println("文件不存在!");
            }
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
        return null;
    }
 
    @RequestMapping("/map/searchData/auth")
    @ManagerAuth
    public R searchLoc(@RequestParam("lev") Integer lev,
                       @RequestParam("locNo") String locNo,
                       @RequestParam("orderNo") String orderNo,
                       @RequestParam("specs") String specs,
                       @RequestParam("matnr") String matnr,
                       @RequestParam("maktx") String maktx
    ) {
        List<LocDetl> locDetls = locDetlService.searchByLike(orderNo, matnr, maktx, specs, "");
        ArrayList<LocDetl> lists = new ArrayList<>();
        for (LocDetl locDetl : locDetls) {//过滤掉不是当前楼层的数据
            int lev1 = Utils.getLev(locDetl.getLocNo());
            if (lev1 == lev) {
                lists.add(locDetl);
            }
        }
 
        //搜索指定库位号,即使库位为空,也可以返回数据
        LocMast locMast = locMastService.selectById(locNo);
        if (locMast != null) {
            LocDetl locDetl = new LocDetl();
            locDetl.setLocNo(locMast.getLocNo());
            lists.add(locDetl);
        }
        return R.ok().add(lists);
    }
 
}