更新
This commit is contained in:
@@ -461,7 +461,9 @@ public class MagicAgvServiceImpl implements MagicAgvService {
|
||||
//请求放货
|
||||
} else if ("Unload".equals(action)) {
|
||||
inst.setExecute_status("3");
|
||||
is_feedback = true;
|
||||
if (!instructionService.hasInstInOneRow(inst)) {
|
||||
is_feedback = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -606,7 +608,6 @@ public class MagicAgvServiceImpl implements MagicAgvService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (addressdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
|
||||
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver();
|
||||
flag = true;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.nl.acs.device_driver.driver;
|
||||
|
||||
/**
|
||||
* @author ldjun
|
||||
* @version 1.0
|
||||
* @date 2023年02月01日 11:21
|
||||
* @desc desc
|
||||
*/
|
||||
public class ItemValue {
|
||||
private String item_code;
|
||||
private Object item_value;
|
||||
|
||||
public ItemValue() {
|
||||
}
|
||||
|
||||
public ItemValue(String item_code, Object item_value) {
|
||||
this.item_code = item_code;
|
||||
this.item_value = item_value;
|
||||
}
|
||||
|
||||
public String getItem_code() {
|
||||
return this.item_code;
|
||||
}
|
||||
|
||||
public void setItem_code(String item_code) {
|
||||
this.item_code = item_code;
|
||||
}
|
||||
|
||||
public Object getItem_value() {
|
||||
return this.item_value;
|
||||
}
|
||||
|
||||
public void setItem_value(Object item_value) {
|
||||
this.item_value = item_value;
|
||||
}
|
||||
}
|
||||
@@ -244,4 +244,6 @@ public interface InstructionService {
|
||||
|
||||
boolean removeByCodeFromCache(String code);
|
||||
|
||||
boolean hasInstInOneRow(Instruction inst);
|
||||
|
||||
}
|
||||
|
||||
@@ -50,6 +50,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
|
||||
@@ -217,7 +218,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
@Override
|
||||
public Instruction findByTaskcodeToWms(String code) {
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_instruction");
|
||||
JSONObject json = wo.query("task_code ='" + code + "'","create_time desc").uniqueResult(0);
|
||||
JSONObject json = wo.query("task_code ='" + code + "'", "create_time desc").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(json))
|
||||
return json.toJavaObject(Instruction.class);
|
||||
return null;
|
||||
@@ -1078,4 +1079,19 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
|
||||
return pattern.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断库位同一排里是否有库位在他之前的指令
|
||||
*
|
||||
* @param inst 指令实体对象
|
||||
* @return 有 true 没有 false
|
||||
*/
|
||||
@Override
|
||||
public boolean hasInstInOneRow(Instruction inst) {
|
||||
return instructions
|
||||
.stream()
|
||||
.anyMatch(i -> !i.getInstruction_id().equals(inst.getInstruction_id())
|
||||
&& i.getTo_x().equals(inst.getTo_x())
|
||||
&& Integer.parseInt(i.getTo_y()) < Integer.parseInt(inst.getTo_y()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,28 @@ import cn.hutool.core.util.NumberUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.jinterop.dcom.core.*;
|
||||
import org.nl.acs.device_driver.driver.ItemValue;
|
||||
import org.nl.exception.BadRequestException;
|
||||
import org.nl.exception.WDKException;
|
||||
import org.openscada.opc.lib.common.ConnectionInformation;
|
||||
import org.openscada.opc.lib.da.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@Slf4j
|
||||
public class OpcUtl {
|
||||
private static int timeout = 180000;
|
||||
private static int timeout = 1*60*1000;
|
||||
private static String key = "rpc.socketTimeout";
|
||||
public static int successNum=0;
|
||||
public static int errNum=0;
|
||||
|
||||
static {
|
||||
checkTimeout();
|
||||
}
|
||||
|
||||
public static void checkTimeout() {
|
||||
if (Integer.getInteger(key, 0).intValue() != timeout) {
|
||||
@@ -26,9 +35,20 @@ public class OpcUtl {
|
||||
}
|
||||
|
||||
|
||||
public static void writeValue(Group group, WriteRequest... requests) {
|
||||
public static void writeValue(Group group, WriteRequest... requests) throws WDKException {
|
||||
try {
|
||||
Map e = group.write(requests);
|
||||
Map<Item, Integer> e=null;
|
||||
try{
|
||||
e=group.write(requests);
|
||||
group.write(requests);
|
||||
}catch (Exception e1){
|
||||
try{
|
||||
e= group.write(requests);
|
||||
}catch (Exception e2){
|
||||
e= group.write(requests);
|
||||
}
|
||||
}
|
||||
|
||||
boolean is_success = true;
|
||||
StringBuilder message = new StringBuilder();
|
||||
Iterator arg4 = e.keySet().iterator();
|
||||
@@ -50,9 +70,60 @@ public class OpcUtl {
|
||||
|
||||
if (!is_success) {
|
||||
// throw new BusinessException(message.toString());
|
||||
System.out.println("下发信号失败:"+message.toString());
|
||||
System.out.println("下发信号失败原因:"+message.toString());
|
||||
log.info("下发信号失败:"+message.toString());
|
||||
throw new WDKException(message.toString());
|
||||
}
|
||||
} catch (JIException arg7) {
|
||||
// throw new BusinessException(arg7);
|
||||
log.info("下发信号失败:"+arg7.getMessage());
|
||||
System.out.println("下发信号失败原因:"+arg7.getMessage());
|
||||
throw new WDKException(arg7);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeValue(Group group, ItemValue... values) throws WDKException {
|
||||
try {
|
||||
if (values != null && values.length > 0) {
|
||||
List<WriteRequest> ws = new ArrayList();
|
||||
ItemValue[] var3 = values;
|
||||
int var4 = values.length;
|
||||
|
||||
for(int var5 = 0; var5 < var4; ++var5) {
|
||||
ItemValue value = var3[var5];
|
||||
Item item = group.addItem(value.getItem_code());
|
||||
ws.add(new WriteRequest(item, getVariant(value.getItem_value())));
|
||||
}
|
||||
|
||||
writeValue(group, (WriteRequest[])ws.toArray(new WriteRequest[0]));
|
||||
}
|
||||
|
||||
} catch (AddFailedException | JIException var8) {
|
||||
throw new WDKException(var8);
|
||||
}
|
||||
}
|
||||
|
||||
public static JIVariant getVariant(Object object) {
|
||||
if (object instanceof Integer) {
|
||||
return getIntegerVariant((Integer)object);
|
||||
} else if (object instanceof String) {
|
||||
return getStringVariant((String)object);
|
||||
} else if (object instanceof byte[]) {
|
||||
return getByteArrayVariant((byte[])((byte[])object));
|
||||
} else if (object instanceof Byte[]) {
|
||||
return getByteArrayVariant((Byte[])((Byte[])object));
|
||||
} else if (object instanceof Boolean) {
|
||||
return new JIVariant((Boolean)object);
|
||||
} else if (object instanceof int[]) {
|
||||
return getByteArrayVariantxx((int[])((int[])object));
|
||||
} else if (object instanceof Integer[]) {
|
||||
JIArray array = new JIArray((Integer)object, false);
|
||||
JIVariant value = new JIVariant(array);
|
||||
return value;
|
||||
} else if (object instanceof JIVariant) {
|
||||
return (JIVariant)object;
|
||||
} else {
|
||||
throw new WDKException("未实现目前支持是int,string,byte[]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +131,7 @@ public class OpcUtl {
|
||||
if (NumberUtil.compare(itemState.getQuality(), Short.valueOf(QualityTypeValue.OPC_QUALITY_GOOD)) != 0) {
|
||||
if (item != null) {
|
||||
log.debug("value is not good {} : {}", item.getId(), itemState.getQuality());
|
||||
// throw new WDKException("值不健康进行重连!");
|
||||
} else {
|
||||
log.debug("value is not good {}", itemState.getQuality());
|
||||
}
|
||||
@@ -150,12 +222,28 @@ public class OpcUtl {
|
||||
server = new Server(getConnection(host, clsid, user, password, domain),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
server.connect();
|
||||
successNum++;
|
||||
return server;
|
||||
} catch (Exception e) {
|
||||
throw new WDKException(e);
|
||||
errNum++;
|
||||
// e.printStackTrace();
|
||||
System.out.println("server error:"+e.getMessage());
|
||||
throw new WDKException(e.getMessage());
|
||||
}finally{
|
||||
System.out.println("successNum:"+successNum);
|
||||
System.out.println("errNum:"+errNum);
|
||||
}
|
||||
}
|
||||
|
||||
public static Server getAutoServer(String host, String clsid, String user, String password, String domain) throws WDKException {
|
||||
checkTimeout();
|
||||
Server server = null;
|
||||
server = new Server(getConnection(host, clsid, user, password, domain), Executors.newSingleThreadScheduledExecutor());
|
||||
AutoReconnectController autoReconnectController = new AutoReconnectController(server);
|
||||
autoReconnectController.connect();
|
||||
return server;
|
||||
}
|
||||
|
||||
public static ConnectionInformation getConnection(String host, String clsid, String user, String password,
|
||||
String domain) {
|
||||
ConnectionInformation connection = new ConnectionInformation();
|
||||
@@ -167,6 +255,44 @@ public class OpcUtl {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public static JIVariant getByteArrayVariantxx(int[] bytes) {
|
||||
Integer[] byte_Data = new Integer[bytes.length];
|
||||
|
||||
for(int i = 0; i < bytes.length; ++i) {
|
||||
byte_Data[i] = bytes[i];
|
||||
}
|
||||
|
||||
JIArray array = new JIArray(byte_Data, false);
|
||||
JIVariant value = new JIVariant(array);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static JIVariant getIntegerVariant(Integer integer) {
|
||||
return new JIVariant(integer);
|
||||
}
|
||||
|
||||
public static JIVariant getStringVariant(String string) {
|
||||
return new JIVariant(string);
|
||||
}
|
||||
|
||||
public static JIVariant getByteArrayVariant(byte[] bytes) {
|
||||
Byte[] byte_Data = new Byte[bytes.length];
|
||||
|
||||
for(int i = 0; i < bytes.length; ++i) {
|
||||
byte_Data[i] = bytes[i];
|
||||
}
|
||||
|
||||
JIArray array = new JIArray(byte_Data, false);
|
||||
JIVariant value = new JIVariant(array);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static JIVariant getByteArrayVariant(Byte[] bytes) {
|
||||
JIArray array = new JIArray(bytes, false);
|
||||
JIVariant value = new JIVariant(array);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static String read(String item) throws Exception {
|
||||
System.out.println(item);
|
||||
Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", "");
|
||||
@@ -193,5 +319,7 @@ public class OpcUtl {
|
||||
System.out.println(itemState.getQuality());
|
||||
System.out.println(getValue(byteItem, itemState));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.agv.server.AgvService;
|
||||
import org.nl.acs.agv.server.MagicAgvService;
|
||||
import org.nl.acs.agv.server.NDCAgvService;
|
||||
import org.nl.acs.config.AcsConfig;
|
||||
import org.nl.acs.config.server.AcsConfigService;
|
||||
@@ -82,7 +83,7 @@ public class PadServiceImpl implements PadService {
|
||||
throw new BadRequestException("未找到该指令!");
|
||||
}
|
||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class);
|
||||
NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class);
|
||||
MagicAgvService agvService = SpringContextHolder.getBean(MagicAgvService.class);
|
||||
AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigServiceImpl.class);
|
||||
|
||||
String task_id = instwo.getString("task_id");
|
||||
@@ -91,9 +92,8 @@ public class PadServiceImpl implements PadService {
|
||||
3 强制完成*/
|
||||
if (type.equals("1")) {
|
||||
//调用agv删除任务的接口
|
||||
agvService = SpringContextHolder.getBean("agvServiceImpl");
|
||||
try {
|
||||
agvService.deleteAgvInstToNDC(instwo.toJavaObject(Instruction.class));
|
||||
agvService.deleteAgvInst(instwo.getString("instruction_code"));
|
||||
instructionService.cancel(inst_uuid);
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -105,14 +105,13 @@ public class PadServiceImpl implements PadService {
|
||||
}
|
||||
if (type.equals("2")) {
|
||||
Instruction instdto = (Instruction) JSONObject.toJavaObject(instwo, Instruction.class);
|
||||
AgvService agvserver = SpringContextHolder.getBean("agvServiceImpl");
|
||||
try {
|
||||
if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) {
|
||||
|
||||
if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "1")) {
|
||||
agvService.sendAgvInstToNDC(instdto);
|
||||
agvService.sendAgvInstToMagic(instdto);
|
||||
} else if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "2")) {
|
||||
agvService.sendAgvInstToNDC(instdto);
|
||||
agvService.sendAgvInstToMagic(instdto);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -145,7 +144,7 @@ public class PadServiceImpl implements PadService {
|
||||
@Override
|
||||
public Map<String, Object> Taskoperation(Map<String, String> jsonObject) {
|
||||
JSONObject jo = new JSONObject();
|
||||
String task_uuid = jsonObject.get("inst_uuid");
|
||||
String task_uuid = jsonObject.get("task_uuid");
|
||||
String type = jsonObject.get("type");
|
||||
JSONObject taskjo = WQLObject.getWQLObject("acs_task").query("task_id='" + task_uuid + "'").uniqueResult(0);
|
||||
if (StrUtil.isEmpty(task_uuid)) {
|
||||
|
||||
@@ -10,6 +10,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.agv.server.MagicAgvService;
|
||||
import org.nl.acs.instruction.service.InstructionService;
|
||||
import org.nl.acs.instruction.service.dto.Instruction;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
@@ -18,91 +20,104 @@ import java.util.List;
|
||||
* 查询AGV任务状态
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Component("queryMagicAgvTaskStatus")
|
||||
@RequiredArgsConstructor
|
||||
public class QueryMagicAgvTaskStatus {
|
||||
private final InstructionService instructionService;
|
||||
private final InstructionService instructionService;
|
||||
|
||||
@Autowired
|
||||
MagicAgvService magicAgvService;
|
||||
|
||||
private String log_file_type = "log_file_type";
|
||||
private String log_type = "agv接口日志";
|
||||
|
||||
public void run() throws Exception {
|
||||
|
||||
List<Instruction> instList = instructionService.findAllInstFromCache();
|
||||
if (instList.size() > 0) {
|
||||
for (int i = 0; i < instList.size(); i++) {
|
||||
Instruction inst = instList.get(i);
|
||||
String instcode = inst.getInstruction_code();
|
||||
HttpResponse response = magicAgvService.queryAgvInstStatus(instcode);
|
||||
JSONObject jo = JSONObject.parseObject(response.body());
|
||||
if (MapUtil.isEmpty(jo)) continue;
|
||||
//反馈结果状态
|
||||
log.info("instcode:" + instcode + "," + jo.toString());
|
||||
//指令执行状态
|
||||
String state = jo.getString("state");
|
||||
String processingVehicle = "";
|
||||
//正在执行指令agv车号
|
||||
if (!StrUtil.isEmpty(jo.getString("processingVehicle"))) {
|
||||
processingVehicle = jo.getString("processingVehicle");
|
||||
inst.setCarno(processingVehicle);
|
||||
}
|
||||
// RAW:初始状态
|
||||
// ACTIVE:业务订单已激活
|
||||
// DISPATCHABLE:业务订单已通过系统验证,等待被调度执行
|
||||
// BEING_PROCESSED:业务订单正在被执行
|
||||
// WITHDRAWN:业务订单已被撤销
|
||||
// FINISHED:业务订单已完成
|
||||
// FAILED:业务订单已失败
|
||||
// UNROUTABLE:无法规划该业务订单的执行路线
|
||||
MDC.put(log_file_type, log_type);
|
||||
try {
|
||||
if (instList.size() > 0) {
|
||||
for (int i = 0; i < instList.size(); i++) {
|
||||
Instruction inst = instList.get(i);
|
||||
String instcode = inst.getInstruction_code();
|
||||
HttpResponse response = magicAgvService.queryAgvInstStatus(instcode);
|
||||
if (response.getStatus() != 200) {
|
||||
continue;
|
||||
}
|
||||
JSONObject jo = JSONObject.parseObject(response.body());
|
||||
if (MapUtil.isEmpty(jo)) continue;
|
||||
//反馈结果状态
|
||||
log.info("instcode:" + instcode + "," + jo.toString());
|
||||
//指令执行状态
|
||||
String state = jo.getString("state");
|
||||
String processingVehicle = "";
|
||||
//正在执行指令agv车号
|
||||
if (!StrUtil.isEmpty(jo.getString("processingVehicle"))) {
|
||||
processingVehicle = jo.getString("processingVehicle");
|
||||
inst.setCarno(processingVehicle);
|
||||
}
|
||||
// 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(instcode);
|
||||
}
|
||||
} else {
|
||||
//执行中
|
||||
if ("BEING_PROCESSED".equals(state)) {
|
||||
if (inst != null) {
|
||||
inst.setInstruction_status("1");
|
||||
instructionService.update(inst);
|
||||
}
|
||||
} else if ("FINISHED".equals(state)) {
|
||||
log.info("agv指令状态:{}",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(instcode);
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
JSONArray ja = jo.getJSONArray("properties");
|
||||
for (int j = 0; j < ja.size(); j++) {
|
||||
JSONObject item = ja.getJSONObject(j);
|
||||
if ("True".equals(item.get("value"))) {
|
||||
String param = item.get("key").toString();
|
||||
String[] strs = param.split("-");
|
||||
//onEntry请求进入 onStation请求离开
|
||||
//onStation-库位名-动作名"
|
||||
String type = null;
|
||||
String device = null;
|
||||
String action = null;
|
||||
// =5表示为货位
|
||||
if (strs.length == 5) {
|
||||
type = strs[0];
|
||||
device = strs[1] + "-" + strs[2] + "-" + strs[3];
|
||||
action = strs[4];
|
||||
} else {
|
||||
type = strs[0];
|
||||
device = strs[1];
|
||||
action = strs[2];
|
||||
}
|
||||
JSONArray ja = jo.getJSONArray("properties");
|
||||
for (int j = 0; j < ja.size(); j++) {
|
||||
JSONObject item = ja.getJSONObject(j);
|
||||
if ("True".equals(item.get("value"))) {
|
||||
String param = item.get("key").toString();
|
||||
String[] strs = param.split("-");
|
||||
//onEntry请求进入 onStation请求离开
|
||||
//onStation-库位名-动作名"
|
||||
String type = null;
|
||||
String device = null;
|
||||
String action = null;
|
||||
// =5表示为货位
|
||||
if (strs.length == 5) {
|
||||
type = strs[0];
|
||||
device = strs[1] + "-" + strs[2] + "-" + strs[3];
|
||||
action = strs[4];
|
||||
} else {
|
||||
type = strs[0];
|
||||
device = strs[1];
|
||||
action = strs[2];
|
||||
}
|
||||
|
||||
String mes = "";
|
||||
|
||||
magicAgvService.process(instcode, type, device, action, processingVehicle);
|
||||
}
|
||||
|
||||
String mes = "";
|
||||
|
||||
magicAgvService.process(instcode, type, device, action, processingVehicle);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
MDC.remove(log_file_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user