自动化立体仓库 - WCS系统
#
Junjie
2023-09-08 448340025aefd8edbb72a23f2f1677fc3c74d486
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
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("/api/wcs/is_system_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, Map<String, Object> skuInfo, String from, String to) {
        Environment environment = SpringUtils.getBean(Environment.class);
        String robotUrl = environment.getProperty("robot.url");
 
        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("api/wcs/single_class_depal_task")
                    .setJson(JSON.toJSONString(map))
                    .build()
                    .doPost();
 
            JSONObject data = JSON.parseObject(response);
            int error = Integer.parseInt(data.get("error").toString());
            if (error == 0) {
                return true;//成功
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;//异常
    }
 
}