自动化立体仓库 - WCS系统
999
zhangc
8 天以前 3c3ec87a6ac907d375f2fb78f0882ab9f30a1533
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
package com.zy.common.utils;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.core.common.SpringUtils;
import org.springframework.core.env.Environment;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 机械手(Robot)工具类
 */
public class RobotUtils {
 
    //获取Robot系统状态
    public static boolean getSystemStatus() {
        Environment environment = SpringUtils.getBean(Environment.class);
        String robotUrl = environment.getProperty("robot.url");
 
        HashMap<String, Object> map = new HashMap<>();
        try {
            String response = new HttpHandler.Builder()
                    .setUri(robotUrl)
                    .setPath("/adaptor/api/wcs/is_vp_ready")
                    .setJson(JSON.toJSONString(map))
                    .build()
                    .doPost();
 
            JSONObject data = JSON.parseObject(response);
            int status = Integer.parseInt(data.get("status").toString());
            if (status == 0) {
                return true;//系统正常
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;//系统异常,没有准备好
    }
 
    //WCS向机械臂下发单拆任务
    public static boolean sendTask(String taskId, Integer skuNum, String from) {
        Environment environment = SpringUtils.getBean(Environment.class);
        String robotUrl = environment.getProperty("robot.url");
 
        Map<String, Object> skuInfo = new HashMap<>();
        skuInfo.put("sku_id", "1");
        skuInfo.put("length", 500);
        skuInfo.put("width", 350);
        skuInfo.put("height", 280);
        skuInfo.put("weight", 1);
        skuInfo.put("sku_num", skuNum);
 
        String to = "307";
        if (from.equals("317")) {
            to = "310";
        }
 
        HashMap<String, Object> map = new HashMap<>();
        map.put("task_id", taskId);
        map.put("sku_info", skuInfo);
        map.put("from", from);
        map.put("to", to);
        try {
            String response = new HttpHandler.Builder()
                    .setUri(robotUrl)
                    .setPath("/adaptor/api/wcs/task/single_depal")
                    .setJson(JSON.toJSONString(map))
                    .build()
                    .doPost();
 
            JSONObject data = JSON.parseObject(response);
            int code = Integer.parseInt(data.get("code").toString());
            String msg = data.get("msg").toString();
            if (code == 0 && msg.equals("success")) {
                return true;//成功
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;//异常
    }
 
}