agv常用请求接口实体和和设备参数获取
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
package com.ruoyi.schedule.scheduleTask;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.common.Constant;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.device.agv.domain.genAgvSchedulingTask.GenAgvSchedulingTaskRequest;
|
||||
import com.ruoyi.device.agv.domain.genAgvSchedulingTask.GenAgvSchedulingTaskResponse;
|
||||
import com.ruoyi.schedule.job.mydojob.domain.MydoJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 向AGV/CTU下发指令
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class Execution {
|
||||
|
||||
|
||||
/**
|
||||
* 查询是否有wcs任务
|
||||
*/
|
||||
// @PostConstruct
|
||||
public List<MydoJob> getmydoJob(){
|
||||
|
||||
String url = Constant.BASEURL + "/job/inmydoJob/listAll";
|
||||
|
||||
HttpResponse response = HttpRequest.get(url).execute();
|
||||
|
||||
List<MydoJob> mydoJobs = JSON.parseArray(response.body(), MydoJob.class);
|
||||
|
||||
return mydoJobs;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 向AGV/CTU请求下发指令
|
||||
* @param request 请求对象
|
||||
* @return
|
||||
*/
|
||||
public boolean sendCommand(GenAgvSchedulingTaskRequest request) {
|
||||
|
||||
//下发校验
|
||||
if (checkForSendCommand(request)) return false;
|
||||
|
||||
String jsonString = JSON.toJSONString(request);
|
||||
|
||||
//请求源数据输出日志
|
||||
log.info("【下发设备指令】" + jsonString);
|
||||
|
||||
//请求接口
|
||||
HttpResponse response = HttpRequest.post(Constant.BASEURL_REST + "genAgvSchedulingTask")
|
||||
.body(jsonString)
|
||||
.header("Content-Type", "application/json")
|
||||
.execute();
|
||||
|
||||
//获取响应对象
|
||||
GenAgvSchedulingTaskResponse genAgvSchedulingTaskResponse = JSON.parseObject(response.body(), GenAgvSchedulingTaskResponse.class);
|
||||
|
||||
//返回请求编号校验
|
||||
if (genAgvSchedulingTaskResponse.getReqCode() != request.getReqCode()) {
|
||||
log.error("【下发设备任务】下发任务失败,请求编号错误不一致!");
|
||||
return false;
|
||||
}
|
||||
|
||||
//返回码
|
||||
if (genAgvSchedulingTaskResponse.getCode() == 0 ) {
|
||||
return true;
|
||||
}else {
|
||||
log.error("【下发设备任务】下发任务失败," + genAgvSchedulingTaskResponse.getMessage() + "!");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 下发指令校验
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public boolean checkForSendCommand(GenAgvSchedulingTaskRequest request){
|
||||
//todo:请求信息校验
|
||||
//1.reqCode空
|
||||
if (StringUtils.isBlank(request.getReqCode())){
|
||||
log.warn("【生成AGV任务请求接口】---请求异常,reqCode为空!---");
|
||||
return false;
|
||||
}
|
||||
|
||||
//2.wbCode和positionCodePath至少填写其中一项,以确定任务中的位置信息。若任务中需要指定多个位置信息,如起点和终点信息等,请使用positionCodePath
|
||||
if (StringUtils.isBlank(request.getWbCode()) && request.getPositionCodePath().size() < 1){
|
||||
log.warn("【生成AGV任务请求接口】---请求异常,wbCode和positionCodePath至少填写其中一项!---");
|
||||
return false;
|
||||
}
|
||||
|
||||
//3.当前区域AGV/CTU是否已存在任务
|
||||
//todo 请求获取设备状态
|
||||
if (true){
|
||||
log.warn("【生成AGV任务请求接口】---当前设备已存在执行中的任务!---");
|
||||
return false;
|
||||
}
|
||||
|
||||
//4.请求编号一致时避免重复下发
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.ruoyi.schedule.scheduleTask;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.common.Constant;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.device.agv.domain.genAgvSchedulingTask.GenAgvSchedulingTaskRequest;
|
||||
import com.ruoyi.device.agv.domain.genAgvSchedulingTask.PositionCodeData;
|
||||
import com.ruoyi.schedule.data.ConvConnection;
|
||||
import com.ruoyi.schedule.plc.domain.ConvPTLInRead;
|
||||
import com.ruoyi.schedule.plc.domain.ConvPTLOutRead;
|
||||
import com.ruoyi.schedule.task.domain.WcsTask;
|
||||
import com.ruoyi.schedule.task.service.IWcsTaskService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 获取任务生成AGV指令
|
||||
*/
|
||||
@Component
|
||||
public class Generation {
|
||||
|
||||
@Autowired
|
||||
ConvConnection conv;
|
||||
|
||||
@Autowired
|
||||
Execution execution;
|
||||
|
||||
IWcsTaskService iWcsTaskService;
|
||||
|
||||
//获取PTL拣选工位入口状态
|
||||
public List<ConvPTLInRead> getConvPTLInRead() {
|
||||
|
||||
List<ConvPTLInRead> convPTLInReads=conv.getConvPTLIn();
|
||||
|
||||
for (int i = 0; i < convPTLInReads.size(); i++) {
|
||||
|
||||
//设备空闲 && 输送机任务号空
|
||||
if (convPTLInReads.get(i).getFree() == 1 && StringUtils.isBlank(convPTLInReads.get(i).getTaskId())){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return convPTLInReads;
|
||||
}
|
||||
|
||||
|
||||
//=========================获取PTL拣选工位出口状态---【CTU入库】=========================
|
||||
// @Scheduled(cron = "*/2 * * * * *")
|
||||
public List<ConvPTLOutRead> getConvPTLOutRead() {
|
||||
|
||||
List<ConvPTLOutRead> convPTLOutReads = conv.getConvPTLOut();
|
||||
|
||||
//轮询输送机状态
|
||||
for (int i = 0; i < convPTLOutReads.size(); i++) {
|
||||
|
||||
//条码不为空 && 存在任务号 && 设备占用(非空闲)
|
||||
if (StringUtils.isBlank(convPTLOutReads.get(i).getPalletId()) && StringUtils.isBlank(convPTLOutReads.get(i).getTaskId()) && convPTLOutReads.get(i).getFree() == 0) {
|
||||
|
||||
//查找mydoJob是否存在该条码的任务
|
||||
//todo 有无其他任务字段校验
|
||||
HttpResponse response = HttpRequest.get(Constant.BASEURL + "/job/inmydoJob/getTaskCount").execute();
|
||||
Integer count = JSON.parseObject(response.body(), Integer.class);
|
||||
|
||||
WcsTask task = new WcsTask();
|
||||
|
||||
iWcsTaskService.insertWcsTask(task);
|
||||
|
||||
//存在当前托盘条码的任务
|
||||
if (count > 0){
|
||||
//生成请求数据
|
||||
GenAgvSchedulingTaskRequest request = new GenAgvSchedulingTaskRequest();
|
||||
|
||||
request.setTaskTyp("F12");
|
||||
|
||||
//添加路径测试
|
||||
List<PositionCodeData> path = new ArrayList<PositionCodeData>(2);
|
||||
path.add(new PositionCodeData("G1001","05"));
|
||||
path.add(new PositionCodeData("010101","05"));
|
||||
|
||||
request.setPositionCodePath(path);
|
||||
|
||||
execution.sendCommand(request);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return convPTLOutReads;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user