更新acs

This commit is contained in:
USER-20220102CG\noblelift
2022-11-04 15:00:44 +08:00
parent c41273bdad
commit c72a6426d9
6 changed files with 218 additions and 116 deletions

View File

@@ -1,6 +1,7 @@
package org.nl.acs.agv.server;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.nl.acs.agv.server.dto.AgvDto;
import org.nl.acs.instruction.service.dto.Instruction;
@@ -45,7 +46,7 @@ public interface XianGongAgvService {
*/
public HttpResponse queryXZAgvDeviceStatus();
public HttpResponse queryXZAgvInstStatus(String instCode);
public HttpResponse queryXZAgvInstStatus();
/**
* 删除先知任务
@@ -67,6 +68,7 @@ public interface XianGongAgvService {
public HttpResponse addOrderSequences(Instruction inst) throws Exception;
public JSONArray createBlocksData(Instruction inst);
/**
* 组织json数据
*

View File

@@ -1,5 +1,6 @@
package org.nl.acs.agv.server.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
@@ -168,19 +169,17 @@ public class XianGongAgvServiceImpl implements XianGongAgvService {
@LokiLog(type = LokiLogType.AGV)
@Override
public HttpResponse queryXZAgvInstStatus(String instCode) {
public HttpResponse queryXZAgvInstStatus() {
if (StrUtil.equals(paramService.findByCode(AcsConfig.FORKAGV).getValue(), "1")) {
String agvurl = paramService.findByCode(AcsConfig.AGVURL).getValue();
String agvport = paramService.findByCode(AcsConfig.AGVPORT).getValue();
agvurl = agvurl + ":" + agvport + "/api/route/transportOrders/" + instCode;
agvurl = agvurl + ":" + agvport + "/orders?page=1&size=9999";
HttpResponse result = HttpRequest.get(agvurl)
.timeout(20000)//超时,毫秒
.execute();
System.out.println("查询agv指令数据:" + result.body());
log.info("queryXZAgvInstStatus----查询agv指令数据:{}" + result.body());
return result;
} else {
@@ -211,31 +210,16 @@ public class XianGongAgvServiceImpl implements XianGongAgvService {
@Override
public HttpResponse sendOrderSequencesToXZ(Instruction inst) throws Exception {
JSONObject jo = new JSONObject();
jo.put("intendedVehicle", "");
jo.put("category", "");
jo.put("failureFatal", false);
jo.put("complete", false);
JSONArray transports = new JSONArray();
JSONObject orderjo = new JSONObject();
orderjo.put("name", inst.getInstruction_code());
orderjo.put("order", createOrederData(inst, "1"));
transports.add(orderjo);
jo.put("transports", transports);
JSONArray ja1 = new JSONArray();
JSONObject jo1 = new JSONObject();
jo1.put("key", "");
jo1.put("value", "");
ja1.add(jo1);
jo.put("properties", ja1);
jo.put("id", inst.getInstruction_code());
jo.put("complete", true);
jo.put("blocks", createBlocksData(inst));
jo.put("priority", inst.getPriority());
log.info("任务号:{},指令号{},下发agv订单序列参数:{}", inst.getTask_code(), inst.getInstruction_code(), jo.toString());
if (StrUtil.equals(paramService.findByCode(AcsConfig.FORKAGV).getValue(), "1")) {
String agvurl = paramService.findByCode(AcsConfig.AGVURL).getValue();
String agvport = paramService.findByCode(AcsConfig.AGVPORT).getValue();
agvurl = agvurl + ":" + agvport + "/api/route/orderSequences/" + inst.getTask_code();
agvurl = agvurl + ":" + agvport + "/setOrder";
HttpResponse result = HttpRequest.post(agvurl)
.body(String.valueOf(jo))//表单内容
@@ -243,13 +227,28 @@ public class XianGongAgvServiceImpl implements XianGongAgvService {
.execute();
log.info(agvurl);
log.info("任务号:{},指令号{},状态{},下发agv订单序列反馈:{}", inst.getTask_code(), inst.getInstruction_code(), result.getStatus(), result.body());
return result;
} else {
return null;
}
}
@Override
public JSONArray createBlocksData(Instruction inst) {
JSONArray ja = new JSONArray();
JSONObject jo = new JSONObject();
jo.put("blockId", IdUtil.simpleUUID());
jo.put("location",inst.getStart_point_code());
jo.put("operation","JackLoad");
ja.add(jo);
JSONObject jo1 = new JSONObject();
jo1.put("blockId",IdUtil.simpleUUID());
jo1.put("location",inst.getNext_point_code());
jo1.put("operation","JackUnload");
ja.add(jo1);
return ja;
}
@LokiLog(type = LokiLogType.AGV)
@Override
public HttpResponse addOrderSequences(Instruction inst) throws Exception {

View File

@@ -266,4 +266,13 @@ public interface InstructionService {
boolean removeByCodeFromCache(String code);
/**
* 根据指令号缓存查询
*
* @param inst_code inst_code
* @return Instruction
*/
Instruction findByInstCodeFromCache(String inst_code);
}

View File

@@ -301,59 +301,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
CargoLiftConveyorDeviceDriver cargoLiftConveyorDeviceDriver;
HaoKaiAutoConveyorDeviceDriver haoKaiAutoConveyorDeviceDriver;
StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver;
//输送线相关需要给任务字段进行赋值,通过任务来判断输送线当前执行到哪一步
if (startdevice.getDeviceDriver() instanceof CargoLiftConveyorDeviceDriver) {
cargoLiftConveyorDeviceDriver = (CargoLiftConveyorDeviceDriver) startdevice.getDeviceDriver();
cargoLiftConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code()));
if (nextdevice.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver){
standardCoveyorControlWithScannerDeviceDriver = (StandardCoveyorControlWithScannerDeviceDriver) nextdevice.getDeviceDriver();
standardCoveyorControlWithScannerDeviceDriver.writing(1,1);
String address = standardCoveyorControlWithScannerDeviceDriver.getExtraValue().get("address").toString();
if (StrUtil.isEmpty(address)){
throw new BadRequestException("设备:"+nextdevice.getDevice_code()+"未设置电气调度号!");
}
String door = standardCoveyorControlWithScannerDeviceDriver.getExtraValue().get("door").toString();
if (StrUtil.isEmpty(door)){
throw new BadRequestException("设备:"+nextdevice.getDevice_code()+"未设置门!");
}
String floor = standardCoveyorControlWithScannerDeviceDriver.getExtraValue().get("floor").toString();
if (StrUtil.isEmpty(floor)){
throw new BadRequestException("设备:"+nextdevice.getDevice_code()+"未设置楼层!");
}
standardCoveyorControlWithScannerDeviceDriver.writing(2, Integer.parseInt(address));
standardCoveyorControlWithScannerDeviceDriver.writing(3, Integer.parseInt(task_code));
standardCoveyorControlWithScannerDeviceDriver.writing(4, Integer.parseInt(door));
standardCoveyorControlWithScannerDeviceDriver.writing(5, Integer.parseInt(floor));
}
}
if (startdevice.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver) {
standardCoveyorControlWithScannerDeviceDriver = (StandardCoveyorControlWithScannerDeviceDriver) startdevice.getDeviceDriver();
standardCoveyorControlWithScannerDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code()));
if (nextdevice.getDeviceDriver() instanceof CargoLiftConveyorDeviceDriver){
cargoLiftConveyorDeviceDriver = (CargoLiftConveyorDeviceDriver) nextdevice.getDeviceDriver();
cargoLiftConveyorDeviceDriver.writing(1,1);
String address = cargoLiftConveyorDeviceDriver.getExtraValue().get("address").toString();
if (StrUtil.isEmpty(address)){
throw new BadRequestException("设备:"+nextdevice.getDevice_code()+"未设置电气调度号!");
}
String door = cargoLiftConveyorDeviceDriver.getExtraValue().get("door").toString();
if (StrUtil.isEmpty(door)){
throw new BadRequestException("设备:"+nextdevice.getDevice_code()+"未设置门!");
}
String floor = cargoLiftConveyorDeviceDriver.getExtraValue().get("floor").toString();
if (StrUtil.isEmpty(floor)){
throw new BadRequestException("设备:"+nextdevice.getDevice_code()+"未设置楼层!");
}
cargoLiftConveyorDeviceDriver.writing(2, Integer.parseInt(address));
cargoLiftConveyorDeviceDriver.writing(3, Integer.parseInt(task_code));
cargoLiftConveyorDeviceDriver.writing(4, Integer.parseInt(door));
cargoLiftConveyorDeviceDriver.writing(5, Integer.parseInt(floor));
}
}
if (startdevice.getDeviceDriver() instanceof HaoKaiAutoConveyorDeviceDriver) {
haoKaiAutoConveyorDeviceDriver = (HaoKaiAutoConveyorDeviceDriver) startdevice.getDeviceDriver();
haoKaiAutoConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code()));
}
try {
String start_device_code = task.getStart_device_code();
@@ -374,13 +321,26 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
throw new BadRequestException("未查询到相关路由!");
}
if (StrUtil.equals(route.getType(), "1")) {
ZheDaAgvService zheDaAgvService = SpringContextHolder.getBean(ZheDaAgvService.class);
HttpResponse result = zheDaAgvService.sendAgvInstToAgv(dto);
if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) {
dto.setSend_status("2");
XianGongAgvService xgAgvService = SpringContextHolder.getBean(XianGongAgvService.class);
if (StrUtil.equals(task.getRequest_again_success(), "1")) {
//追加订单
HttpResponse result = xgAgvService.sendOrderSequencesToXZ(dto);
if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) {
dto.setSend_status("2");
} else {
dto.setSend_status("1");
}
} else {
dto.setSend_status("1");
//创建订单序列
HttpResponse result = xgAgvService.sendOrderSequencesToXZ(dto);
if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) {
dto.setSend_status("2");
} else {
dto.setSend_status("1");
}
}
}
} catch (Exception e) {
@@ -1231,6 +1191,20 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
return false;
}
@Override
public Instruction findByInstCodeFromCache(String inst_code) {
for (int i = 0; i < this.instructions.size(); i++) {
Instruction inst = instructions.get(i);
if (StrUtil.equals(inst_code, inst.getInstruction_code())) {
return inst;
}
}
return null;
}
public Instruction findByContainer(String container_code) {
Iterator var3 = instructions.iterator();

View File

@@ -0,0 +1,101 @@
package org.nl.modules.quartz.task;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.agv.server.XianGongAgvService;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.task.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 查询AGV任务状态
*/
@Slf4j
@Component
public class QueryXZAgvTaskStatus {
@Autowired
InstructionService instructionService;
@Autowired
XianGongAgvService agvService;
@Autowired
AcsToWmsService acsToWmsService;
@Autowired
TaskService taskService;
public void run() throws Exception {
HttpResponse response = agvService.queryXZAgvInstStatus();
JSONObject jo = JSONArray.parseObject(response.body());
JSONArray ja = JSONArray.parseArray(jo.getString("list"));
for (int i = 0; i < ja.size(); i++) {
JSONObject one = (JSONObject) ja.get(i);
String inst_code = one.getString("id");
Instruction inst = instructionService.findByInstCodeFromCache(inst_code);
if (ObjectUtil.isEmpty(inst))
continue;
//子任务状态 待以后处理
JSONArray blocks = JSONArray.parseArray(one.getString("blocks"));
for(int j=0;j<blocks.size();j++){
JSONObject blocksjo = (JSONObject) blocks.get(j);
String blockId = blocksjo.getString("blockId");
String device_code = blocksjo.getString("location");
String state = blocksjo.getString("state");
}
String state = one.getString("state");
if (!StrUtil.isEmpty(one.getString("vehicle"))) {
String carno = one.getString("vehicle");
inst.setCarno(carno);
}
// 已创建=CREATED
// 待分配=TOBEDISPATCHED
// 正在执行=RUNNING
// 完成=FINISHED
// 失败=FAILED(主动失败)
// 终止=STOPPED(被人为终止)
// 无法执行=Error(参数错误)
// 等待=WAITING
//执行中
if ("RUNNING".equals(state) || "CREATED".equals(state) || "TOBEDISPATCHED".equals(state) || "WAITING".equals(state)) {
if (inst != null) {
inst.setInstruction_status("1");
instructionService.update(inst);
}
} else if ("FINISHED".equals(state)) {
if (inst != null) {
inst.setInstruction_status("2");
instructionService.finish(inst);
}
} else if ("STOPPED".equals(state) || "FAILED".equals(state) || "Error".equals(state)) {
if (inst != null) {
inst.setInstruction_status("1");
instructionService.update(inst);
}
}
// else if ("STOPPED".equals(state)){
// if (inst != null) {
// instructionService.cancel(inst.getInstruction_id());
//
// TaskDto taskDto = taskService.findByCode(inst.getTask_code());
// taskService.cancel(taskDto.getTask_id());
// }
// }
}
}
}