Browse Source

调度接口

master
周俊杰 2 years ago
parent
commit
d51b3d27d5
  1. 245
      hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java
  2. 3
      hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java
  3. 100
      hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryAgvTaskStatus.java
  4. 6
      hd/nladmin-system/src/main/resources/config/application-dev.yml
  5. 2
      hd/nladmin-system/src/main/resources/config/application.yml
  6. 6
      package-lock.json

245
hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java

@ -22,6 +22,7 @@ import org.nl.acs.device_driver.special_ordinary_site.SpecialOrdinarySiteDeviceD
import org.nl.acs.device_driver.standard_autodoor.StandardAutodoorDeviceDriver; import org.nl.acs.device_driver.standard_autodoor.StandardAutodoorDeviceDriver;
import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceDriver; import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceDriver;
import org.nl.acs.device_driver.standard_manipulator_inspect_site.StandardManipulatorInspectSiteDeviceDriver; import org.nl.acs.device_driver.standard_manipulator_inspect_site.StandardManipulatorInspectSiteDeviceDriver;
import org.nl.acs.device_driver.standard_manipulator_stacking_site.StandardManipulatorStackingSiteDeviceDriver;
import org.nl.acs.device_driver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver;
import org.nl.acs.device_driver.standard_storage.StandardStorageDeviceDriver; import org.nl.acs.device_driver.standard_storage.StandardStorageDeviceDriver;
import org.nl.acs.device_driver.weighing_site.WeighingSiteDeviceDriver; import org.nl.acs.device_driver.weighing_site.WeighingSiteDeviceDriver;
@ -36,6 +37,7 @@ import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.opc.DeviceAppServiceImpl; import org.nl.acs.opc.DeviceAppServiceImpl;
import org.nl.acs.opc.DeviceType; import org.nl.acs.opc.DeviceType;
import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.TaskService;
import org.nl.acs.task.service.dto.TaskDto;
import org.nl.exception.BadRequestException; import org.nl.exception.BadRequestException;
import org.nl.logger.BusinessLogger; import org.nl.logger.BusinessLogger;
import org.nl.start.auto.run.NDCSocketConnectionAutoRun; import org.nl.start.auto.run.NDCSocketConnectionAutoRun;
@ -769,193 +771,118 @@ public class AgvServiceImpl implements AgvService {
//1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 //1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
@Override @Override
public synchronized String process(String jobno, String type, String address, String action, String processingVehicle) { public synchronized String process(String jobno, String type, String address, String action, String processingVehicle)
log.info("查询到AGV请求参数,jobno:{},address:{}", jobno + ",address:" + address + ",type:" + type + ",action:" + action); {
boolean is_feedback = false; {
String str = ""; log.info("查询到AGV请求参数,jobno:{},address:{}", jobno + ",address:" + address + ",type:" + type + ",action:" + action);
String backaddress = address; //释放AGV资源,继续后续动作
if (address.indexOf(".") > 0) { boolean is_feedback = false;
str = address.substring(address.indexOf("."), address.length()); String str = "";
address = address.substring(0, address.indexOf(".")); String backaddress = address;
} else if (address.indexOf("-") > 0) { if (address.indexOf(".") > 0) {
address = address.substring(0, address.indexOf("-")); str = address.substring(address.indexOf(".") + 1, address.length());
} address = address.substring(0, address.indexOf("."));
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); } else if (address.indexOf("-") > 0) {
Instruction inst = instructionService.findByCodeFromCache(jobno); address = address.substring(0, address.indexOf("-"));
}
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
TaskService taskService = SpringContextHolder.getBean("taskServiceImpl");
AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl");
Instruction inst = instructionService.findByCodeFromCache(jobno);
TaskDto task = taskService.findByCode(inst.getTask_code());
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
Device addressdevice = appService.findDeviceByCode(address); Device addressdevice = appService.findDeviceByCode(address);
StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver;
StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; StandardManipulatorStackingSiteDeviceDriver standardManipulatorStackingSiteDeviceDriver;
SpecialOrdinarySiteDeviceDriver specialOrdinarySiteDeviceDriver; //取货的进入前等待和离开等待
//请求进入 if (action.equals("taking")) {
if ("onEntry".equals(type)) { if ("EntryRequired".equals(type)) {
//
if (addressdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { if (addressdevice.getDeviceDriver() instanceof StandardManipulatorStackingSiteDeviceDriver) {
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) addressdevice.getDeviceDriver(); standardManipulatorStackingSiteDeviceDriver = (StandardManipulatorStackingSiteDeviceDriver) addressdevice.getDeviceDriver();
//请求取货 if(standardManipulatorStackingSiteDeviceDriver.getMove()==1){
if ("Load".equals(action)) { is_feedback = true;
if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() > 0) { } else {
inst.setExecute_status("1"); log.info("设备{} 请求取货,光电信号:{}",addressdevice,standardManipulatorStackingSiteDeviceDriver.getMove());
is_feedback = true; }
} }
//请求放货 if (addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
} else if ("Unload".equals(action)) {
if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() == 0) {
inst.setExecute_status("3");
is_feedback = true; is_feedback = true;
} }
} }
} if ("PauseOnStation".equals(type)) {
if (addressdevice.getDeviceDriver() instanceof SpecialOrdinarySiteDeviceDriver) { if (addressdevice.getDeviceDriver() instanceof StandardManipulatorStackingSiteDeviceDriver) {
specialOrdinarySiteDeviceDriver = (SpecialOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); standardManipulatorStackingSiteDeviceDriver = (StandardManipulatorStackingSiteDeviceDriver) addressdevice.getDeviceDriver();
//请求取货 if(standardManipulatorStackingSiteDeviceDriver.getMove()==0){
if ("Load".equals(action)) { is_feedback = true;
if (addressdevice.getHas_goods() > 0) { } else {
inst.setExecute_status("1"); log.info("设备{} 请求离开,光电信号:{}",addressdevice,standardManipulatorStackingSiteDeviceDriver.getMove());
is_feedback = true; }
} }
//请求放货 if (addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
} else if ("Unload".equals(action)) {
if (addressdevice.getHas_goods() == 0) {
inst.setExecute_status("3");
is_feedback = true; is_feedback = true;
} }
} }
} }
if (addressdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); //放货的进入前等待和离开等待
//请求取货 if (action.equals("puting")) {
if ("Load".equals(action)) { if ("EntryRequired".equals(type)) {
if (addressdevice.getHas_goods() > 0) { if (addressdevice.getDeviceDriver() instanceof StandardManipulatorStackingSiteDeviceDriver) {
inst.setExecute_status("1"); standardManipulatorStackingSiteDeviceDriver = (StandardManipulatorStackingSiteDeviceDriver) addressdevice.getDeviceDriver();
is_feedback = true; if(standardManipulatorStackingSiteDeviceDriver.getMove()==0){
is_feedback = true;
} else {
log.info("设备{} 请求放货,光电信号:{}",addressdevice,standardManipulatorStackingSiteDeviceDriver.getMove());
}
} }
//请求放货 if (addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
} else if ("Unload".equals(action)) {
if (addressdevice.getHas_goods() == 0) {
inst.setExecute_status("3");
is_feedback = true; is_feedback = true;
} }
} }
} if ("PauseOnStation".equals(type)) {
if (addressdevice.getDeviceDriver() instanceof StandardManipulatorStackingSiteDeviceDriver) {
if (addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) { standardManipulatorStackingSiteDeviceDriver = (StandardManipulatorStackingSiteDeviceDriver) addressdevice.getDeviceDriver();
//请求取货 if(standardManipulatorStackingSiteDeviceDriver.getMove()==1){
if ("Load".equals(action)) { is_feedback = true;
inst.setExecute_status("1"); } else {
is_feedback = true; log.info("设备{} 请求离开,光电信号:{}",addressdevice,standardManipulatorStackingSiteDeviceDriver.getMove());
//请求放货 }
} else if ("Unload".equals(action)) {
inst.setExecute_status("3");
is_feedback = true;
}
}
//取放货完成
} else if ("onStation".equals(type)) {
System.out.println("取放货完成");
if (addressdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) addressdevice.getDeviceDriver();
//取货完成
if ("Load".equals(action)) {
if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() == 0) {
inst.setExecute_device_code(processingVehicle);
inst.setExecute_status("2");
is_feedback = true;
} }
//放货完成 if (addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
} else if ("Unload".equals(action)) {
if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() > 0) {
inst.setExecute_device_code(address);
inst.setExecute_status("4");
is_feedback = true; is_feedback = true;
} }
} }
} }
if (addressdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { com.alibaba.fastjson.JSONObject requestjo = new com.alibaba.fastjson.JSONObject();
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); if (is_feedback) {
//取货完成 requestjo.put("task_code", jobno);
if ("Load".equals(action)) { requestjo.put("operation", action);
inst.setExecute_device_code(processingVehicle); if (type.equals("entryRequired") || type.equals("EntryRequired")) {
inst.setExecute_status("2"); requestjo.put("entryRequired", "true");
is_feedback = true; } else {
//放货完成 requestjo.put("pauseOnStation", "true");
} else if ("Unload".equals(action)) {
inst.setExecute_device_code(address);
inst.setExecute_status("4");
is_feedback = true;
} }
log.info("反馈AGV请求数据:{}", requestjo);
System.out.println("back agv:" + requestjo);
}
if (addressdevice.getDeviceDriver() instanceof SpecialOrdinarySiteDeviceDriver) {
specialOrdinarySiteDeviceDriver = (SpecialOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver();
//取货完成
if ("Load".equals(action)) {
inst.setExecute_device_code(processingVehicle);
inst.setExecute_status("2");
is_feedback = true;
//放货完成
} else if ("Unload".equals(action)) {
inst.setExecute_device_code(processingVehicle);
inst.setExecute_status("4");
is_feedback = true;
}
}
if (addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) {
//取货完成
if ("Load".equals(action)) {
inst.setExecute_device_code(processingVehicle);
inst.setExecute_status("2");
is_feedback = true;
//放货完成
} else if ("Unload".equals(action)) {
inst.setExecute_device_code(processingVehicle);
inst.setExecute_status("4");
is_feedback = true;
}
}
}
JSONObject requestjo = new JSONObject(); String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL);
JSONArray ja = new JSONArray(); String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT);
if (is_feedback) {
String param = "";
JSONObject jo = new JSONObject();
if (str.length() > 0) {
backaddress = backaddress + str;
}
if ("onEntry".equals(type)) {
param = "EntryPermitted-" + backaddress + action;
} else if ("onStation".equals(type)) {
param = "ContinueOnStation-" + backaddress + action;
}
jo.put("key", param); agvurl = agvurl + ":" + agvport + "/api/route/transportOrders/" + jobno + "/interact";
jo.put("value", "False");
ja.add(jo);
requestjo.put("properties", ja);
log.info("反馈AGV请求数据:{}", requestjo);
System.out.println("back agv:" + requestjo);
String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL);
String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT);
agvurl = agvurl + ":" + agvport + "/v1/transportOrders/" + jobno + "/interact"; HttpResponse result = HttpRequest.post(agvurl)
.body(String.valueOf(requestjo))
.timeout(20000)//超时,毫秒
.execute();
}
return requestjo.toString();
HttpResponse result = HttpRequest.post(agvurl)
.body(String.valueOf(requestjo))
.timeout(20000)//超时,毫秒
.execute();
} }
is_feedback = false;
return requestjo.toString();
} }
@Override @Override

3
hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java

@ -67,7 +67,7 @@ public class InstructionDto implements Serializable {
/** /**
* 完成类型 * 完成类型
*/ */
private String finish_type ="0"; private String finish_type = "0";
/** /**
* 优先级 * 优先级
@ -246,3 +246,4 @@ public class InstructionDto implements Serializable {
*/ */
private String next_parent_code; private String next_parent_code;
} }

100
hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryAgvTaskStatus.java

@ -0,0 +1,100 @@
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.AgvService;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 查询AGV任务状态
*/
@Slf4j
@Component
public class QueryAgvTaskStatus {
@Autowired
InstructionService instructionService;
@Autowired
AgvService agvService;
public void run() throws Exception {
try {
HttpResponse response = agvService.queryAgvInstStatus("1");
//查询AGV指令列表
JSONArray inst_rows = JSONArray.parseArray(response.body());
for (int i = 0; i < inst_rows.size(); i++) {
JSONObject inst_jo = inst_rows.getJSONObject(i);
String inst_code = inst_jo.getString("task_code");
Instruction inst = instructionService.findByCodeFromCache(inst_code);
if (ObjectUtil.isEmpty(inst)) {
continue;
}
//反馈结果状态
log.info("instcode:" + inst_code + "," + inst_jo.toString());
String state = inst_jo.getString("state");
String vehicle = "";
//正在执行指令agv车号
if (!StrUtil.isEmpty(inst_jo.getString("vehicle"))) {
vehicle = inst_jo.getString("vehicle");
inst.setCarno(vehicle);
}
// RAW:初始状态
// ACTIVE:业务订单已激活
// DISPATCHABLE:业务订单已通过系统验证,等待被调度执行
// BEING_PROCESSED:业务订单正在被执行
// WITHDRAWN:业务订单已被撤销
// FINISHED:业务订单已完成
// FAILED:业务订单已失败
// UNROUTABLE:无法规划该业务订单的执行路线
//执行中
if ("BEING_PROCESSED".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 ("WITHDRAWN".equals(state) || "FAILED".equals(state)) {
if (inst != null) {
inst.setInstruction_status("3");
instructionService.update(inst);
instructionService.removeByCodeFromCache(inst_jo.getString("task_code"));
}
}
JSONArray ja = inst_jo.getJSONArray("destinations");
for (int j = 0; j < ja.size(); j++) {
JSONObject jo = ja.getJSONObject(j);
JSONArray pro_rows = jo.getJSONArray("properties");
//Load 取货动作 Unload放货动作 Wait等待
String operation = jo.getString("operation");
String device = jo.getString("locationName");
for (int k = 0; k < pro_rows.size(); k++) {
JSONObject item = pro_rows.getJSONObject(k);
if ("true".equals(item.get("value"))) {
String param = item.get("key").toString();
//EntryRequired是否进入前等待 PauseOnStation是否离开等待 Wait在该点进行等待
agvService.process(inst_code, param, device, operation, vehicle);
}
}
}
}
} catch (Exception e) {
}
}
}

6
hd/nladmin-system/src/main/resources/config/application-dev.yml

@ -7,11 +7,11 @@ spring:
db-type: com.alibaba.druid.pool.DruidDataSource db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
#url: jdbc:log4jdbc:mysql://${DB_HOST:47.111.78.178}:${DB_PORT:3306}/${DB_NAME:lx_rs_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true #url: jdbc:log4jdbc:mysql://${DB_HOST:47.111.78.178}:${DB_PORT:3306}/${DB_NAME:lx_rs_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:zdtn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:zdtn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
username: ${DB_USER:root} username: ${DB_USER:root}
#password: ${DB_PWD:P@ssw0rd} #password: ${DB_PWD:P@ssw0rd}
#password: ${DB_PWD:Root.123456} password: ${DB_PWD:Root.123456}
password: ${DB_PWD:password} #password: ${DB_PWD:password}
# 初始连接数 # 初始连接数
initial-size: 5 initial-size: 5

2
hd/nladmin-system/src/main/resources/config/application.yml

@ -2,7 +2,7 @@ spring:
freemarker: freemarker:
check-template-location: false check-template-location: false
profiles: profiles:
active: prod active: dev
jackson: jackson:
time-zone: GMT+8 time-zone: GMT+8
data: data:

6
package-lock.json

@ -0,0 +1,6 @@
{
"name": "zhongDingTianNeng",
"lockfileVersion": 2,
"requires": true,
"packages": {}
}
Loading…
Cancel
Save