自动化立体仓库 - WCS系统
#
Junjie
5 天以前 4c88c0606bb333ac1ad4c1ad536a848f7d27fdb7
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
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.core.annotations.ManagerAuth;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.service.LocMastService;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
 
@RestController
 
public class MapController extends BaseController {
 
    @Autowired
    private LocMastService locMastService;
 
    private static final List<String> DISABLE_LOC_NO = new ArrayList<String>() {{
    }};
 
    @GetMapping("/map/getData/{lev}/auth")
    @ManagerAuth
    public String getMapData(@PathVariable("lev") Integer lev) {
        try {
            String mapFilename = "map_" + lev + ".json";
            String fileName = this.getClass().getClassLoader().getResource(mapFilename).getPath();//获取文件路径
            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);
                ArrayList<HashMap<String, Integer>> lineRows = new ArrayList<>();
                int dataRow = 0;
                int dataRowCount = 0;
                for (int i = 1; i < arrayLists.size(); i++) {
                    boolean flag = true;
                    ArrayList rows = arrayLists.get(i);
                    for (int j = 1; j < rows.size() - 1; j++) {
                        Object o = rows.get(j);
                        JSONObject jsonObject = JSON.parseObject(o.toString());
                        int value = Integer.parseInt(jsonObject.get("value").toString());
                        if (value >= 0 && value != 3) {
                            //只有该行中的任一一列有数据,则不需要创建空白行
                            flag = false;
                        }
                    }
 
                    if (flag) {
                        //空白行需要跳过
                        HashMap<String, Integer> map = new HashMap<>();
                        map.put("start", dataRow);
                        int end = i - 1 - dataRowCount;
                        map.put("end", end);
                        map.put("count", dataRowCount);
                        dataRow = end;
                        dataRowCount++;
                        lineRows.add(map);
                    }
                }
 
                //获取当前楼层库位数据
                List<LocMast> locMasts = locMastService.selectLocByLev(lev);
 
                for (LocMast locMast : locMasts) {
                    Integer row = locMast.getRow1();
                    Integer bay = locMast.getBay1();
                    for (HashMap<String, Integer> lineRow : lineRows) {
                        if (row > lineRow.get("start") && row <= lineRow.get("end")) {
                            row += lineRow.get("count");
                            break;
                        }
                    }
                    ArrayList rowData = arrayLists.get(row);
                    Object o = rowData.get(bay);
                    JSONObject jsonObject = JSON.parseObject(o.toString());
                    if (DISABLE_LOC_NO.contains(locMast.getLocNo())) {
                        //禁止库位
                        jsonObject.put("value", 10);//将禁用库位进行设置
                    }
                    jsonObject.put("locNo", locMast.getLocNo());//设置库位号
                    jsonObject.put("locSts", locMast.getLocSts());//库位状态
                    jsonObject.put("barcode", Optional.ofNullable(locMast.getBarcode()).orElse("无"));//托盘号
 
                    //更新list
                    rowData.set(bay, jsonObject);
                    arrayLists.set(row, rowData);
                }
 
                return JSONObject.toJSONString(arrayLists);
            } else {
                System.out.println("文件不存在!");
            }
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
        return null;
    }
 
}