|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|