Browse Source

fix 请求取放货

master
张江玮 1 year ago
parent
commit
3d7c5a7c0f
  1. 26
      hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java
  2. 40
      hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java
  3. 18
      hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java
  4. 93
      hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java
  5. 2
      hd/nladmin-system/src/main/resources/config/application-prod.yml

26
hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java

@ -23,9 +23,6 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
@Slf4j
public class AgvWaitUtil {
private final DeviceAppService deviceAppService;
private final AcsToWmsZDServiceImpl acsToWmsZDService;
private final InstructionService instructionService;
private final AcsToWmsService acsToWmsService;
@Autowired
LogServer logServer;
@ -107,23 +104,10 @@ public class AgvWaitUtil {
public JSONObject waitOutPut(String endDeviceCode, Instruction inst) {
log.info("仙工AGV放货完成后请求离开,设备号 - {}", endDeviceCode);
JSONObject responseBody = acsToWmsService.gccQueryStationState(inst);
if (ObjectUtil.isNotEmpty(responseBody) && 200 == responseBody.optInt("status")) {
JSONArray data = responseBody.optJSONArray("data");
for (int i = 0; i < data.size(); i++) {
JSONObject datum = data.getJSONObject(i);
if (endDeviceCode.equals(datum.optString("Station_Code"))
&& datum.optBoolean("IsHasGoods")) {
JSONObject map = new JSONObject();
map.put("status", 200);
map.put("message", "允许离开!");
log.info("允许仙工AGV放货完成后请求离开,设备号 - {}", endDeviceCode);
return map;
}
}
}
throw new BadRequestException("请求失败!");
JSONObject map = new JSONObject();
map.put("status", 200);
map.put("message", "允许离开!");
log.info("允许仙工AGV放货完成后请求离开,设备号 - {}", endDeviceCode);
return map;
}
}

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

@ -2181,26 +2181,26 @@ public class AgvServiceImpl implements AgvService {
jo4.put("operation", "JackUnload");
ja.add(jo4);
// if ("true".equals(nextDevice.getExtraValue().get("ignore_release_check"))) {
// //放货完成等待
// com.alibaba.fastjson.JSONObject jo5 = new com.alibaba.fastjson.JSONObject();
// jo5.put("blockId", IdUtil.simpleUUID());
// jo5.put("location", inst.getNext_point_code() + "OUTPUT");
// jo5.put("operation", "script");
// jo5.put("id", inst.getNext_point_code() + "OUTPUT");
// jo5.put("script_name", "userpy/interact.py");
// com.alibaba.fastjson.JSONObject script_args5 = new com.alibaba.fastjson.JSONObject();
// script_args5.put("addr", addr);
// com.alibaba.fastjson.JSONObject data5 = new com.alibaba.fastjson.JSONObject();
// com.alibaba.fastjson.JSONObject reach5 = new com.alibaba.fastjson.JSONObject();
// reach5.put("task_code", inst.getInstruction_code());
// reach5.put("address", inst.getNext_point_code() + "OUTPUT");
// data5.put("reach", reach5);
// script_args5.put("data", data5);
// script_args5.put("protocol", "HTTP");
// jo5.put("script_args", script_args5);
// ja.add(jo5);
// }
if ("true".equals(nextDevice.getExtraValue().get("ignore_release_check"))) {
//放货完成等待
com.alibaba.fastjson.JSONObject jo5 = new com.alibaba.fastjson.JSONObject();
jo5.put("blockId", IdUtil.simpleUUID());
jo5.put("location", inst.getNext_point_code() + "OUTPUT");
jo5.put("operation", "script");
jo5.put("id", inst.getNext_point_code() + "OUTPUT");
jo5.put("script_name", "userpy/interact.py");
com.alibaba.fastjson.JSONObject script_args5 = new com.alibaba.fastjson.JSONObject();
script_args5.put("addr", addr);
com.alibaba.fastjson.JSONObject data5 = new com.alibaba.fastjson.JSONObject();
com.alibaba.fastjson.JSONObject reach5 = new com.alibaba.fastjson.JSONObject();
reach5.put("task_code", inst.getInstruction_code());
reach5.put("address", inst.getNext_point_code() + "OUTPUT");
data5.put("reach", reach5);
script_args5.put("data", data5);
script_args5.put("protocol", "HTTP");
jo5.put("script_args", script_args5);
ja.add(jo5);
}
return ja;
}

18
hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java

@ -53,6 +53,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* @author ldjun
@ -64,7 +65,7 @@ import java.util.regex.Pattern;
@Slf4j
public class InstructionServiceImpl implements InstructionService, ApplicationAutoInitial {
List<Instruction> instructions = new ArrayList();
List<Instruction> instructions = new ArrayList<>();
@Autowired
DeviceAppService deviceAppService;
@ -1212,12 +1213,15 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
@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;
}
if (StrUtil.isBlank(inst_code)) {
return null;
}
List<Instruction> list = this.instructions.stream().filter(i -> inst_code.equals(i.getInstruction_code())).collect(Collectors.toList());
if (list.isEmpty()) {
return null;
} else {
return list.get(0);
}
return null;
}
}

93
hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java

@ -1,6 +1,5 @@
package org.nl.modules.quartz.task;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
@ -15,8 +14,6 @@ import org.nl.acs.task.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 查询AGV任务状态
*/
@ -36,33 +33,39 @@ public class QueryXZAgvTaskStatus {
@Autowired
TaskService taskService;
public void run() throws Exception {
private boolean lock = false;
HttpResponse response = agvService.queryXZAgvInstStatus();
com.alibaba.fastjson.JSONObject jo = JSONArray.parseObject(response.body());
public void run() throws Exception {
JSONArray ja = JSONArray.parseArray(jo.getString("list"));
for (int i = 0; i < ja.size(); i++) {
com.alibaba.fastjson.JSONObject one = (com.alibaba.fastjson.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++){
com.alibaba.fastjson.JSONObject blocksjo = (JSONObject) blocks.get(j);
String blockId = blocksjo.getString("blockId");
String device_code = blocksjo.getString("location");
String state = blocksjo.getString("state");
if (!this.lock) {
try {
this.lock = true;
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 = ja.getJSONObject(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++){
// com.alibaba.fastjson.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);
}
String state = one.getString("state");
if (!StrUtil.isEmpty(one.getString("vehicle"))) {
String carno = one.getString("vehicle");
inst.setCarno(carno);
}
// 已创建=CREATED,
// 待分配=TOBEDISPATCHED,
@ -73,23 +76,23 @@ public class QueryXZAgvTaskStatus {
// 无法执行=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);
}
}
//执行中
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());
@ -98,6 +101,10 @@ public class QueryXZAgvTaskStatus {
// taskService.cancel(taskDto.getTask_id());
// }
// }
}
} finally {
this.lock = false;
}
}
}

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

@ -137,4 +137,4 @@ file:
avatarMaxSize: 5
agvToAcs:
addr: http://192.168.2.96:8010
addr: http://10.118.33.115:8010

Loading…
Cancel
Save