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 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 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 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;//异常 } }