|
|
|
package org.jeecg.modules.erp.robot.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.jeecg.common.util.RedisUtil;
|
|
|
|
import org.jeecg.modules.erp.depot.service.impl.RestTempService;
|
|
|
|
import org.jeecg.modules.erp.robot.entity.ApiConfigYJ;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.security.InvalidKeyException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.time.ZoneId;
|
|
|
|
import java.time.ZonedDateTime;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Slf4j
|
|
|
|
public class YjRobotService {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private ApiConfigYJ apiConfigYJ;
|
|
|
|
private final RestTempService restTempService;
|
|
|
|
|
|
|
|
public YjRobotService(RestTempService restTempService) {
|
|
|
|
this.restTempService = restTempService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取点位
|
|
|
|
* @param storeId
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Map<String, Object> getPoints(@RequestParam String storeId) {
|
|
|
|
log.info("开始获取点位");
|
|
|
|
HashMap<String, Object> r = new HashMap<>();
|
|
|
|
String tk = getaccessToken();
|
|
|
|
if(StrUtil.isBlank(tk)){
|
|
|
|
r.put("code", 501);
|
|
|
|
r.put("message", "获取token失败");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
log.info("token: " + tk);
|
|
|
|
|
|
|
|
String tempUrl1 = "https://open-api.yunjiai.cn/v3/stores/";
|
|
|
|
String tempUrl2 = "/points";
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
String url = stringBuilder.append(tempUrl1).append(storeId).append(tempUrl2).toString();
|
|
|
|
String p1 = "accessToken";
|
|
|
|
String v1 = tk;
|
|
|
|
|
|
|
|
// 使用UriComponentsBuilder构建完整的URL
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
|
|
|
|
.queryParam(p1, v1);
|
|
|
|
|
|
|
|
// 构建完整的URI
|
|
|
|
URI uri = builder.build().toUri();
|
|
|
|
log.info("url:" + uri);
|
|
|
|
|
|
|
|
String response = restTempService.getWithHeaderAuth(uri);
|
|
|
|
log.info("response:" + response);
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(response);
|
|
|
|
int code = jsonObject.getIntValue("code");
|
|
|
|
r.put("code", code);
|
|
|
|
if (code == 0) {
|
|
|
|
} else {
|
|
|
|
log.info("设备列表获取异常");
|
|
|
|
r.put("message", "设备列表获取异常");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
// 取出data数组并遍历
|
|
|
|
JSONArray dataArray = jsonObject.getJSONArray("data");
|
|
|
|
if (code == 0) {
|
|
|
|
r.put("message", "SUCCESS");
|
|
|
|
} else {
|
|
|
|
r.put("message", "FAILED");
|
|
|
|
}
|
|
|
|
r.put("data", dataArray);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
|
|
public Map<String, Object> movetoTarget(@RequestParam String templateId,
|
|
|
|
@RequestParam String deviceId,
|
|
|
|
@RequestParam String pointId,
|
|
|
|
@RequestParam int overtime) {
|
|
|
|
log.info("机器人任务流:{}",templateId);
|
|
|
|
// 创建一个ObjectMapper实例(如果尚未创建)
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
log.info("店铺-->{}", apiConfigYJ.getStoreId());
|
|
|
|
log.info("上舱-->{}", deviceId);
|
|
|
|
log.info("目标位置-->{}", pointId);
|
|
|
|
|
|
|
|
// 您的JSON对象
|
|
|
|
Map<String, Object> taskMap = new HashMap<>();
|
|
|
|
String outTaskId = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
|
|
|
|
log.info("outTaskId-->" + outTaskId);
|
|
|
|
taskMap.put("outTaskId", outTaskId);
|
|
|
|
taskMap.put("templateId", templateId);
|
|
|
|
taskMap.put("storeId", apiConfigYJ.getStoreId());
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
params.put("dockCabinId", deviceId);
|
|
|
|
params.put("target", pointId);
|
|
|
|
if("dock_cabin_and_move_target_with_wait_action".equals(templateId)){
|
|
|
|
params.put("overtime", overtime);
|
|
|
|
params.put("overtimeEvent", "back");
|
|
|
|
}
|
|
|
|
taskMap.put("params", params);
|
|
|
|
|
|
|
|
//taskMap转String
|
|
|
|
String taskRequest = getTaskRequest(taskMap);
|
|
|
|
//组装header
|
|
|
|
HttpHeaders headers = getHttpHeaders();
|
|
|
|
|
|
|
|
String url = "https://open-api.yunjiai.cn/v3/rcs/task/flow/execute";
|
|
|
|
|
|
|
|
HttpEntity<Object> entity = new HttpEntity<>(taskRequest, headers);
|
|
|
|
|
|
|
|
String response = restTempService.postWithHeaderAuth3(url, entity);
|
|
|
|
log.info("url:" + url);
|
|
|
|
log.info("response:" + response);
|
|
|
|
|
|
|
|
Map<String, Object> map = JSONUtil.toBean(response, Map.class);
|
|
|
|
int code = Integer.parseInt(map.get("code").toString());
|
|
|
|
if(code == 0){
|
|
|
|
String data = map.get("data").toString();
|
|
|
|
Map<String, Object> map1 = JSONUtil.toBean(data, Map.class);
|
|
|
|
String taskId = map1.get("taskId").toString();
|
|
|
|
redisUtil.set(apiConfigYJ.getDeviceId(),taskId,3600);
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 取消移动
|
|
|
|
* @param option
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// @PutMapping("/canceltask")
|
|
|
|
public Map<String,Object> canceltask(@RequestParam String option) {
|
|
|
|
|
|
|
|
// 创建一个ObjectMapper实例(如果尚未创建)
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
Object object = redisUtil.get(apiConfigYJ.getDeviceId());
|
|
|
|
if(null == object){
|
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
|
returnMap.put("code", 501);
|
|
|
|
return returnMap;
|
|
|
|
}
|
|
|
|
String taskId = object.toString();
|
|
|
|
log.info("取消任务的taskId: {}", taskId);
|
|
|
|
// 您的JSON对象
|
|
|
|
Map<String, Object> taskMap = new HashMap<>();
|
|
|
|
taskMap.put("newStatus", "cancelled");
|
|
|
|
taskMap.put("robotId", apiConfigYJ.getDeviceId());
|
|
|
|
taskMap.put("option", option);
|
|
|
|
|
|
|
|
// 将Map转换为JSON字符串
|
|
|
|
String taskRequest = null;
|
|
|
|
try {
|
|
|
|
taskRequest = objectMapper.writeValueAsString(taskMap);
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
// 处理异常或返回错误消息
|
|
|
|
}
|
|
|
|
|
|
|
|
String url = "https://open-api.yunjiai.cn/v3/stores/" + apiConfigYJ.getStoreId() + "/tasks/" + taskId+"/status";
|
|
|
|
|
|
|
|
HttpHeaders headers = getHttpHeaders();
|
|
|
|
|
|
|
|
HttpEntity<Object> entity = new HttpEntity<>(taskRequest, headers);
|
|
|
|
|
|
|
|
String response = restTempService.putWithHeaderAuth(url, entity);
|
|
|
|
|
|
|
|
log.info("url: {}",url);
|
|
|
|
log.info("response: {}",response);
|
|
|
|
Map<String, Object> map = JSONUtil.toBean(response, Map.class);
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> callAndDelivery(@RequestParam String target,
|
|
|
|
@RequestParam String via) {
|
|
|
|
// 创建一个ObjectMapper实例(如果尚未创建)
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
log.info("店铺-->{}", apiConfigYJ.getStoreId());
|
|
|
|
|
|
|
|
// 您的JSON对象
|
|
|
|
Map<String, Object> taskMap = new HashMap<>();
|
|
|
|
String outTaskId = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
|
|
|
|
log.info("outTaskId-->" + outTaskId);
|
|
|
|
taskMap.put("storeId", apiConfigYJ.getStoreId());
|
|
|
|
taskMap.put("outTaskId", outTaskId);
|
|
|
|
taskMap.put("target", target);
|
|
|
|
taskMap.put("via", via);
|
|
|
|
|
|
|
|
Map<String, Object> goodMap = new HashMap<>();
|
|
|
|
goodMap.put("goodsId","take-out-goods-"+ DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN));
|
|
|
|
goodMap.put("goodsName","外卖商品");
|
|
|
|
goodMap.put("quantity",2);
|
|
|
|
List<Map> maps = new ArrayList<>();
|
|
|
|
maps.add(goodMap);
|
|
|
|
taskMap.put("goods", maps);
|
|
|
|
|
|
|
|
//taskMap转String
|
|
|
|
String taskRequest = getTaskRequest(taskMap);
|
|
|
|
//组装header
|
|
|
|
HttpHeaders headers = getHttpHeaders();
|
|
|
|
|
|
|
|
String url = "https://open-api.yunjiai.cn/v3/rcs/task/create/merchant-call";
|
|
|
|
|
|
|
|
HttpEntity<Object> entity = new HttpEntity<>(taskRequest, headers);
|
|
|
|
|
|
|
|
String response = restTempService.postWithHeaderAuth3(url, entity);
|
|
|
|
log.info("url:" + url);
|
|
|
|
log.info("response:" + response);
|
|
|
|
|
|
|
|
Map<String, Object> map = JSONUtil.toBean(response, Map.class);
|
|
|
|
// int code = Integer.parseInt(map.get("code").toString());
|
|
|
|
// if(code == 0){
|
|
|
|
// String data = map.get("data").toString();
|
|
|
|
// Map<String, Object> map1 = JSONUtil.toBean(data, Map.class);
|
|
|
|
// String taskId = map1.get("taskId").toString();
|
|
|
|
// redisUtil.set(apiConfigYJ.getDeviceId(),taskId,3600);
|
|
|
|
// }
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dock_cabin_to_move_and_lift_down
|
|
|
|
* 调度底盘(具体调哪个底盘云迹自己调度系统分配)去某个上仓举起并移动到另外点位放下
|
|
|
|
*
|
|
|
|
* @param deviceId
|
|
|
|
* @param pointId
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// @PostMapping("/dockCabinToMoveAndLiftDown")
|
|
|
|
public Map<String,Object> dockCabinToMoveAndLiftDown( String deviceId,
|
|
|
|
String pointId) {
|
|
|
|
|
|
|
|
Map<String, Object> r = new HashMap<>();
|
|
|
|
log.info("=============dock_cabin_to_move_and_lift_down==============");
|
|
|
|
String tk = getaccessToken();
|
|
|
|
if("".equals(tk)) {
|
|
|
|
r.put("code", 501);
|
|
|
|
r.put("message", "获取token失败");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info("店铺-->" + apiConfigYJ.getStoreId());
|
|
|
|
log.info("上舱-->" + deviceId);
|
|
|
|
log.info("目标位置-->" + pointId);
|
|
|
|
|
|
|
|
Map<String, Object> taskMap = new HashMap<>();
|
|
|
|
String outTaskId = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
|
|
|
|
log.info("outTaskId-->" + outTaskId);
|
|
|
|
taskMap.put("outTaskId", outTaskId);
|
|
|
|
taskMap.put("templateId", "dock_cabin_to_move_and_lift_down");
|
|
|
|
taskMap.put("storeId", apiConfigYJ.getStoreId());
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
|
|
|
//执行任务中需要对接的上舱设备 ID
|
|
|
|
params.put("dockCabinId", deviceId);
|
|
|
|
params.put("target", pointId);
|
|
|
|
taskMap.put("params", params);
|
|
|
|
|
|
|
|
//taskMap转String
|
|
|
|
String taskRequest = getTaskRequest(taskMap);
|
|
|
|
//组装header
|
|
|
|
HttpHeaders headers = getHttpHeaders();
|
|
|
|
|
|
|
|
String url = "https://open-api.yunjiai.cn/v3/rcs/task/flow/execute";
|
|
|
|
|
|
|
|
HttpEntity<Object> entity = new HttpEntity<>(taskRequest, headers);
|
|
|
|
log.info("url:" + url);
|
|
|
|
|
|
|
|
String response = restTempService.postWithHeaderAuth3(url, entity);
|
|
|
|
log.info("response:" + response);
|
|
|
|
Map<String, Object> map = JSONUtil.toBean(response, Map.class);
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* docking_cabin_and_docking_down
|
|
|
|
* 调度底盘(具体调哪个底盘云迹自己调度系统分配,以直线距离最近的空闲底盘优先)移动上舱举起并移动到另外一个舱位放下
|
|
|
|
* @param deviceId
|
|
|
|
* @param pointId
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// @PostMapping("/dockingCabinAndDockingDown")
|
|
|
|
public Map<String, Object> dockingCabinAndDockingDown(
|
|
|
|
@RequestParam String deviceId,
|
|
|
|
@RequestParam String pointId) {
|
|
|
|
Map<String, Object> r = new HashMap<>();
|
|
|
|
log.info("=============docking_cabin_and_docking_down==============");
|
|
|
|
// 创建一个ObjectMapper实例(如果尚未创建)
|
|
|
|
log.info("店铺: {}", apiConfigYJ.getStoreId());
|
|
|
|
log.info("上舱: {}", deviceId);
|
|
|
|
log.info("目标位置: {}", pointId);
|
|
|
|
|
|
|
|
// 您的JSON对象
|
|
|
|
Map<String, Object> taskMap = new HashMap<>();
|
|
|
|
String outTaskId = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
|
|
|
|
log.info("outTaskId: {}", outTaskId);
|
|
|
|
taskMap.put("outTaskId", outTaskId);
|
|
|
|
taskMap.put("templateId", "docking_cabin_and_docking_down");
|
|
|
|
taskMap.put("storeId", apiConfigYJ.getStoreId());
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
params.put("dockCabinId", deviceId);
|
|
|
|
params.put("target", pointId);
|
|
|
|
taskMap.put("params", params);
|
|
|
|
|
|
|
|
//taskMap转String
|
|
|
|
String taskRequest = getTaskRequest(taskMap);
|
|
|
|
//组装header
|
|
|
|
HttpHeaders headers = getHttpHeaders();
|
|
|
|
|
|
|
|
String url = "https://open-api.yunjiai.cn/v3/rcs/task/flow/execute";
|
|
|
|
|
|
|
|
HttpEntity<Object> entity = new HttpEntity<>(taskRequest, headers);
|
|
|
|
|
|
|
|
String response = restTempService.postWithHeaderAuth3(url, entity);
|
|
|
|
log.info("url:{}", url);
|
|
|
|
log.info("response:{}", response);
|
|
|
|
|
|
|
|
Map<String, Object> map = JSONUtil.toBean(response, Map.class);
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* docking_cabin_and_move_target
|
|
|
|
* 调度底盘(具体调哪个底盘云迹自己调度系统分配,以直线距离最近的空闲底盘优先)移动上舱举起并移动到目标点
|
|
|
|
* @param httpServletRequest
|
|
|
|
* @param storeId
|
|
|
|
* @param deviceId
|
|
|
|
* @param pointId
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// @PostMapping("/dockingCabinAndMoveTarget")
|
|
|
|
public Map<String, Object> dockingCabinAndMoveTarget(HttpServletRequest httpServletRequest,
|
|
|
|
@RequestParam String storeId, @RequestParam String deviceId,
|
|
|
|
@RequestParam String pointId) {
|
|
|
|
log.info("=============docking_cabin_and_move_target==============");
|
|
|
|
|
|
|
|
Map<String, Object> r = new HashMap<>();
|
|
|
|
// 创建一个ObjectMapper实例(如果尚未创建)
|
|
|
|
|
|
|
|
log.info("店铺-->" + storeId);
|
|
|
|
log.info("上舱-->" + deviceId);
|
|
|
|
log.info("目标位置-->" + pointId);
|
|
|
|
|
|
|
|
// 您的JSON对象
|
|
|
|
Map<String, Object> taskMap = new HashMap<>();
|
|
|
|
String outTaskId = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
|
|
|
|
log.info("outTaskId-->" + outTaskId);
|
|
|
|
taskMap.put("outTaskId", outTaskId);
|
|
|
|
taskMap.put("templateId", "docking_cabin_and_move_target");
|
|
|
|
taskMap.put("storeId", storeId);
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
params.put("dockCabinId", deviceId);
|
|
|
|
params.put("target", pointId);
|
|
|
|
taskMap.put("params", params);
|
|
|
|
|
|
|
|
//taskMap转String
|
|
|
|
String taskRequest = getTaskRequest(taskMap);
|
|
|
|
//组装header
|
|
|
|
HttpHeaders headers = getHttpHeaders();
|
|
|
|
String url = "https://open-api.yunjiai.cn/v3/rcs/task/flow/execute";
|
|
|
|
|
|
|
|
HttpEntity<Object> entity = new HttpEntity<>(taskRequest, headers);
|
|
|
|
|
|
|
|
log.info("taskRequest-->" + taskRequest);
|
|
|
|
log.info("url:" + url);
|
|
|
|
String response = restTempService.postWithHeaderAuth3(url, entity);
|
|
|
|
log.info("response:" + response);
|
|
|
|
|
|
|
|
JSONObject jsonObject2 = JSON.parseObject(response);
|
|
|
|
|
|
|
|
r.put("data", jsonObject2);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* move_target_and_lift_down
|
|
|
|
* 托举上舱移动到目的地并且放下上舱
|
|
|
|
* @param httpServletRequest
|
|
|
|
* @param storeId
|
|
|
|
* @param deviceId
|
|
|
|
* @param pointId
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// @PostMapping("/moveTargetAndLiftDown")
|
|
|
|
public Map<String, Object> moveTargetAndLiftDown(HttpServletRequest httpServletRequest,
|
|
|
|
@RequestParam String storeId, @RequestParam String deviceId,
|
|
|
|
@RequestParam String pointId) {
|
|
|
|
|
|
|
|
log.info("=============move_target_and_lift_down==============");
|
|
|
|
Map<String, Object> r = new HashMap<>();
|
|
|
|
|
|
|
|
// 创建一个ObjectMapper实例(如果尚未创建)
|
|
|
|
log.info("店铺-->" + storeId);
|
|
|
|
log.info("上舱-->" + deviceId);
|
|
|
|
log.info("目标位置-->" + pointId);
|
|
|
|
|
|
|
|
// 您的JSON对象
|
|
|
|
Map<String, Object> taskMap = new HashMap<>();
|
|
|
|
String outTaskId = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
|
|
|
|
log.info("outTaskId-->" + outTaskId);
|
|
|
|
taskMap.put("outTaskId", outTaskId);
|
|
|
|
taskMap.put("templateId", "move_target_and_lift_down");
|
|
|
|
taskMap.put("storeId", storeId);
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
params.put("dockCabinId", deviceId);
|
|
|
|
params.put("target", pointId);
|
|
|
|
taskMap.put("params", params);
|
|
|
|
|
|
|
|
//taskMap转String
|
|
|
|
String taskRequest = getTaskRequest(taskMap);
|
|
|
|
//组装header
|
|
|
|
HttpHeaders headers = getHttpHeaders();
|
|
|
|
|
|
|
|
String url = "https://open-api.yunjiai.cn/v3/rcs/task/flow/execute";
|
|
|
|
|
|
|
|
HttpEntity<Object> entity = new HttpEntity<>(taskRequest, headers);
|
|
|
|
|
|
|
|
log.info("=============url==============" + url);
|
|
|
|
String response1 = restTempService.postWithHeaderAuth3(url, entity);
|
|
|
|
|
|
|
|
log.info("=============response==============" + response1);
|
|
|
|
|
|
|
|
System.out.println("url----------- -----\n" + url);
|
|
|
|
System.out.println("response1-----------restemp-----\n" + response1);
|
|
|
|
|
|
|
|
JSONObject jsonObject2 = JSON.parseObject(response1);
|
|
|
|
|
|
|
|
r.put("data", jsonObject2);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 让某舱到某目的地
|
|
|
|
* dock_cabin_and_move_target_with_wait_action
|
|
|
|
* @param httpServletRequest
|
|
|
|
* @param storeId
|
|
|
|
* @param deviceId
|
|
|
|
* @param pointId
|
|
|
|
* @param overtime
|
|
|
|
* @param overtimeEvent
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// @PostMapping("/dockCabinAndMoveTargetWithWaitAction")
|
|
|
|
public Map<String, Object> dockCabinAndMoveTargetWithWaitAction(HttpServletRequest httpServletRequest,
|
|
|
|
@RequestParam String storeId, @RequestParam String deviceId,
|
|
|
|
@RequestParam String pointId, @RequestParam String overtime, @RequestParam String overtimeEvent) {
|
|
|
|
|
|
|
|
log.info("=============dock_cabin_and_move_target_with_wait_action==============");
|
|
|
|
Map<String, Object> r = new HashMap<>();
|
|
|
|
|
|
|
|
// 创建一个ObjectMapper实例(如果尚未创建)
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
log.info("店铺: " + storeId);
|
|
|
|
log.info("上舱: " + deviceId);
|
|
|
|
log.info("目标位置: " + pointId);
|
|
|
|
|
|
|
|
// 您的JSON对象
|
|
|
|
Map<String, Object> taskMap = new HashMap<>();
|
|
|
|
String outTaskId = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
|
|
|
|
log.info( "outTaskId: " + outTaskId);
|
|
|
|
taskMap.put("outTaskId", outTaskId);
|
|
|
|
taskMap.put("templateId", "dock_cabin_and_move_target_with_wait_action");
|
|
|
|
taskMap.put("storeId", storeId);
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
params.put("dockCabinId", deviceId);
|
|
|
|
params.put("target", pointId);
|
|
|
|
params.put("overtime", overtime);
|
|
|
|
params.put("overtimeEvent", overtimeEvent);
|
|
|
|
taskMap.put("params", params);
|
|
|
|
|
|
|
|
//taskMap转String
|
|
|
|
String taskRequest = getTaskRequest(taskMap);
|
|
|
|
//组装header
|
|
|
|
HttpHeaders headers = getHttpHeaders();
|
|
|
|
|
|
|
|
String url = "https://open-api.yunjibot.com/v3/rcs/task/flow/execute";
|
|
|
|
|
|
|
|
HttpEntity<Object> entity = new HttpEntity<>(taskRequest, headers);
|
|
|
|
|
|
|
|
log.info("taskRequest-->" + taskRequest);
|
|
|
|
log.info("=============url==============" + url);
|
|
|
|
String response1 = restTempService.postWithHeaderAuth3(url, entity);
|
|
|
|
|
|
|
|
log.info("=============response==============" + response1);
|
|
|
|
System.out.println("url----------- -----\n" + url);
|
|
|
|
System.out.println("response1-----------restemp-----\n" + response1);
|
|
|
|
|
|
|
|
JSONObject jsonObject2 = JSON.parseObject(response1);
|
|
|
|
|
|
|
|
|
|
|
|
r.put("data", jsonObject2);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 返回充电
|
|
|
|
* @param deviceId
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// @PostMapping("/gocharge")
|
|
|
|
public Map<String,Object> gocharge(@RequestParam String deviceId) {
|
|
|
|
|
|
|
|
|
|
|
|
String baseUrl = "https://open-api.yunjiai.cn/v3/robot/" + deviceId + "/goto-charge";
|
|
|
|
String p1 = "accessToken";
|
|
|
|
String v1 = getaccessToken();
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl)
|
|
|
|
.queryParam(p1, v1); // 添加查询参数
|
|
|
|
|
|
|
|
// 构建完整的URI
|
|
|
|
URI uri = builder.build().toUri();
|
|
|
|
|
|
|
|
Map<String, Object> taskMap = new HashMap<>();
|
|
|
|
taskMap.put("chargeId", "");
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
//taskMap转String
|
|
|
|
String taskRequest = getTaskRequest(taskMap);
|
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
|
|
|
|
HttpEntity<Object> entity = new HttpEntity<>(taskRequest, headers);
|
|
|
|
|
|
|
|
String response = restTempService.postWithHeaderAuth3(uri.toString(), entity);
|
|
|
|
log.info("response: {}", response);
|
|
|
|
Map<String, Object> map = JSONUtil.toBean(response, Map.class);
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
private String getaccessToken() {
|
|
|
|
String url = "https://open-api.yunjiai.cn/v3/auth/accessToken";//中国
|
|
|
|
|
|
|
|
String accessKeyId = apiConfigYJ.getAccessKeyId();
|
|
|
|
String key = apiConfigYJ.getAccessKeySecret();
|
|
|
|
|
|
|
|
List<String> paraAllList = new java.util.ArrayList<>();
|
|
|
|
|
|
|
|
// 获取当前的中国时间(东八区)
|
|
|
|
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
|
|
|
|
|
|
|
|
// 定义ISO 8601格式,包含时区信息
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter
|
|
|
|
.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
|
|
|
|
|
|
// 格式化时间
|
|
|
|
String timestamp = now.format(formatter);
|
|
|
|
|
|
|
|
UUID uuid = UUID.randomUUID();
|
|
|
|
paraAllList.add("signatureNonce=" + uuid);
|
|
|
|
paraAllList.add("accessKeyId=" + accessKeyId);
|
|
|
|
paraAllList.add("timestamp=" + timestamp);
|
|
|
|
|
|
|
|
// 排序
|
|
|
|
Object[] params = paraAllList.toArray();
|
|
|
|
java.util.Arrays.sort(params);
|
|
|
|
|
|
|
|
// 签名
|
|
|
|
StringBuffer paramBuffer = new StringBuffer();
|
|
|
|
for (Object param : params) {
|
|
|
|
if (paramBuffer.length() > 0) {
|
|
|
|
paramBuffer.append("&");
|
|
|
|
}
|
|
|
|
paramBuffer.append(String.valueOf(param));
|
|
|
|
}
|
|
|
|
|
|
|
|
String MAC_NAME = "HmacSHA1";
|
|
|
|
String ENCODING = "UTF-8";
|
|
|
|
byte[] data = null;
|
|
|
|
byte[] text = null;
|
|
|
|
String signatureStr = "";
|
|
|
|
|
|
|
|
try {
|
|
|
|
data = (key + "&").getBytes(ENCODING);
|
|
|
|
javax.crypto.SecretKey secretKey = new javax.crypto.spec.SecretKeySpec(
|
|
|
|
data, MAC_NAME);
|
|
|
|
javax.crypto.Mac mac = null;
|
|
|
|
|
|
|
|
mac = javax.crypto.Mac.getInstance(MAC_NAME);
|
|
|
|
mac.init(secretKey);
|
|
|
|
text = paramBuffer.toString().getBytes(ENCODING);
|
|
|
|
|
|
|
|
byte[] bytes = mac.doFinal(text);
|
|
|
|
signatureStr = java.util.Base64.getEncoder().encodeToString(bytes);
|
|
|
|
|
|
|
|
log.info("签名值: {}", signatureStr);
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
|
|
|
|
log.error("异常: " + e.getMessage());
|
|
|
|
return "NG";
|
|
|
|
|
|
|
|
} catch (InvalidKeyException e) {
|
|
|
|
|
|
|
|
log.error("异常: " + e.getMessage());
|
|
|
|
return "NG";
|
|
|
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
|
log.error("异常: " + e.getMessage());
|
|
|
|
return "NG";
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, Object> requestBody = new HashMap<>();
|
|
|
|
requestBody.put("signature", signatureStr);
|
|
|
|
requestBody.put("accessKeyId", accessKeyId);
|
|
|
|
requestBody.put("signatureNonce", uuid);
|
|
|
|
requestBody.put("timestamp", timestamp);
|
|
|
|
|
|
|
|
// 你可以通过键来获取值
|
|
|
|
Integer code = null;
|
|
|
|
String message = null;
|
|
|
|
String accessToken = null;
|
|
|
|
try {
|
|
|
|
String response1 = restTempService.postWithHeaderAuth2(url,
|
|
|
|
requestBody);
|
|
|
|
log.info("response: " + response1);
|
|
|
|
|
|
|
|
// 使用fastjson2的JSON类来解析JSON字符串为Map
|
|
|
|
Map<String, Object> map = JSON.parseObject(response1, Map.class);
|
|
|
|
|
|
|
|
code = (Integer) map.get("code");
|
|
|
|
message = (String) map.get("message");
|
|
|
|
if(code==0){
|
|
|
|
// 如果JSON字符串中还嵌套了其他JSON对象,你也可以相应地处理它们
|
|
|
|
Map<String, Object> dataMap = (Map<String, Object>) map.get("data");
|
|
|
|
accessToken = (String) dataMap.get("accessToken");
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("异常: " + e.getMessage());
|
|
|
|
return "NG";
|
|
|
|
}
|
|
|
|
// // 输出结果
|
|
|
|
log.info("Code: {}", code);
|
|
|
|
log.info("Message: {}", message);
|
|
|
|
log.info("Access Token: {}", accessToken);
|
|
|
|
|
|
|
|
return accessToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
private HttpHeaders getHttpHeaders() {
|
|
|
|
UUID uuid = UUID.randomUUID();
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
//获取token
|
|
|
|
String tk = getaccessToken();
|
|
|
|
// 获取当前的中国时间(东八区)
|
|
|
|
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
|
|
|
|
|
|
|
|
// 定义ISO 8601格式,包含时区信息
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter
|
|
|
|
.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
|
|
|
|
|
|
|
|
// 格式化时间
|
|
|
|
String timestamp = now.format(formatter);
|
|
|
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
headers.set("token", tk);
|
|
|
|
headers.set("signatureNonce", uuid.toString());
|
|
|
|
headers.set("timestamp", timestamp);
|
|
|
|
headers.set("accessKeyId",apiConfigYJ.getAccessKeyId());
|
|
|
|
return headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getTaskRequest(Map<String, Object> taskMap) {
|
|
|
|
// 创建一个ObjectMapper实例
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
String taskRequest = null;
|
|
|
|
try {
|
|
|
|
taskRequest = objectMapper.writeValueAsString(taskMap);
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
// 处理异常或返回错误消息
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info("taskRequest-->" + taskRequest);
|
|
|
|
return taskRequest;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|