|  |  |  | 
|---|
|  |  |  | package com.zy.common.utils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.zy.common.model.NavigateNode; | 
|---|
|  |  |  | import com.zy.core.model.command.NyShuttleHttpCommand; | 
|---|
|  |  |  | import com.zy.core.model.protocol.NyShuttleProtocol; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Random; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 牛眼四向穿梭车HTTP请求工具类 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public class NyHttpUtils { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final String requestUrl = "localhost:9090/skwcs"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取HTTP请求标准结构体 | 
|---|
|  |  |  | public static NyShuttleHttpCommand getHttpStandard(Integer shuttleNo) { | 
|---|
|  |  |  | 
|---|
|  |  |  | HashMap<String, Object> body = new HashMap<>(); | 
|---|
|  |  |  | body.put("requestType", "move");//移动命令 | 
|---|
|  |  |  | body.put("taskId", wrkNo);//任务号 | 
|---|
|  |  |  | body.put("start", start);//起点 | 
|---|
|  |  |  | body.put("target", target);//终点 | 
|---|
|  |  |  | body.put("start", navigateNodeToNyPointNode(start));//起点 | 
|---|
|  |  |  | body.put("target", navigateNodeToNyPointNode(target));//终点 | 
|---|
|  |  |  | request.setBody(body); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | httpStandard.setRequest(request); | 
|---|
|  |  |  | 
|---|
|  |  |  | HashMap<String, Object> body = new HashMap<>(); | 
|---|
|  |  |  | body.put("requestType", in ? "intoLift" : "outLift");//进出提升机 | 
|---|
|  |  |  | body.put("taskId", wrkNo);//任务号 | 
|---|
|  |  |  | body.put("start", start);//起点 | 
|---|
|  |  |  | body.put("target", target);//终点 | 
|---|
|  |  |  | body.put("start", navigateNodeToNyPointNode(start));//起点 | 
|---|
|  |  |  | body.put("target", navigateNodeToNyPointNode(target));//终点 | 
|---|
|  |  |  | request.setBody(body); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | httpStandard.setRequest(request); | 
|---|
|  |  |  | 
|---|
|  |  |  | //获取请求编号 | 
|---|
|  |  |  | public static Integer getRequestId() { | 
|---|
|  |  |  | Random random = new Random(); | 
|---|
|  |  |  | return random.nextInt(); | 
|---|
|  |  |  | return random.nextInt(9999999); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //发出请求 | 
|---|
|  |  |  | public static JSONObject requestCommand(NyShuttleHttpCommand httpCommand) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(requestUrl) | 
|---|
|  |  |  | .setPath("/static/readStatus.json") | 
|---|
|  |  |  | .setJson(JSON.toJSONString(httpCommand)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doGet(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | JSONObject response2 = jsonObject.getJSONObject("response"); | 
|---|
|  |  |  | JSONObject body = response2.getJSONObject("body"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (body.get("responseType").equals("state")) {//读取状态,不需要判断success | 
|---|
|  |  |  | return body; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (body.get("result").equals("success")) { | 
|---|
|  |  |  | return body; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | //            e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //地图节点转换牛眼节点 | 
|---|
|  |  |  | public static NyShuttleProtocol.NyShuttlePointClass navigateNodeToNyPointNode(NavigateNode node) { | 
|---|
|  |  |  | int[] NyPosition = NavigatePositionConvert.WCSXyzToNyXyz(node.getX(), node.getY(), node.getZ());//WCS系统坐标转牛眼坐标 | 
|---|
|  |  |  | NyShuttleProtocol.NyShuttlePointClass point = new NyShuttleProtocol.NyShuttlePointClass(); | 
|---|
|  |  |  | point.setX(NyPosition[0]); | 
|---|
|  |  |  | point.setY(NyPosition[1]); | 
|---|
|  |  |  | point.setZ(NyPosition[2]); | 
|---|
|  |  |  | return point; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|