From e98d4b1133ed058bfe1e6af75be9975aebfc32d8 Mon Sep 17 00:00:00 2001
From: zyh <zyh@123>
Date: 星期六, 28 三月 2026 16:00:35 +0800
Subject: [PATCH] 最后可运行版本
---
src/main/java/com/zy/asrs/service/impl/RcsServiceImpl.java | 839 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 704 insertions(+), 135 deletions(-)
diff --git a/src/main/java/com/zy/asrs/service/impl/RcsServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/RcsServiceImpl.java
index ec9d0e7..ae6c3c0 100644
--- a/src/main/java/com/zy/asrs/service/impl/RcsServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/RcsServiceImpl.java
@@ -1,14 +1,15 @@
package com.zy.asrs.service.impl;
import com.alibaba.excel.util.StringUtils;
+import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.entity.*;
import com.zy.asrs.enums.RcsRetMethodEnum;
+import com.zy.asrs.service.AgvTaskService;
import com.zy.asrs.service.RcsService;
-import com.zy.asrs.service.TaskService;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
@@ -28,22 +29,28 @@
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
import java.util.Date;
-import java.util.List;
import java.util.Objects;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
@Slf4j
@Service
public class RcsServiceImpl implements RcsService {
+
+ @Value("${mes.url}")
+ public String MES_URL;
+
// 娴峰悍RCS鍦板潃
@Value("${hik.url}")
private String HIK_URL;
+ // 浜哄憳鍏ヤ镜绯荤粺妫�鏌�
+ @Value("${hik.renyuan}")
+ private String HIK_RENYUAN;
+ // 涓嶉渶瑕佸彂閫乪nd鐨勭珯鐐�
+ @Value("${hik.station}")
+ private String HIK_STATION;
@Autowired
- private TaskService taskService;
+ private AgvTaskService taskService;
/**
@@ -55,6 +62,7 @@
*/
@Override
public RcsReturn reporterTask(RcsReporterTask rcsReporterTask) {
+ log.info("娴峰悍AGV绔欑偣浠诲姟璇锋眰={}", JSONObject.toJSONString(rcsReporterTask));
RcsReturn rcsReturn = new RcsReturn();
@@ -68,115 +76,65 @@
String carrierType = values.getString("carrierType");
String slotCategory = values.getString("slotCategory");
String slotCode = values.getString("slotCode");
- EntityWrapper<Task> wrapper = new EntityWrapper<>();
- wrapper.eq("task_no", robotTaskCode);
- Task task = taskService.selectOne(wrapper);
- if(!Cools.isEmpty(task)){
+ EntityWrapper<AgvTask> wrapper = new EntityWrapper<>();
+ // 淇敼鍚庣殑閫昏緫锛氭湁"-"鍒欏幓鎺夋渶鍚庝竴涓�"-"鍙婂悗闈㈠唴瀹癸紝娌℃湁鍒欎繚鎸佸師鏍�
+ String taskNo = rcsReporterTask.getRobotTaskCode();
+ if (taskNo.contains("-")) {
+ taskNo = taskNo.substring(0, taskNo.lastIndexOf("-"));
+ }
+ wrapper.eq("task_no", taskNo);
+ AgvTask task = taskService.selectOne(wrapper);
+ if (!Cools.isEmpty(task)) {
try {
- // q3,q8=1
- if ("1".equals(carrierType)) { //AGV
-
- switch (Objects.requireNonNull(RcsRetMethodEnum.getEnum(method))) {
- //鏀捐揣鐢宠
- case APPLY_PUT: {
+ switch (Objects.requireNonNull(RcsRetMethodEnum.getEnum(method))) {
+ //鏀捐揣鐢宠
+ case APPLY_PUT: {
+ if (task.getStaNo().equals("401") || task.getStaNo().equals("402") || task.getStaNo().equals("307")) {
Integer sourceStaNo = Integer.valueOf(task.getStaNo());
SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone();
//wcs鍙嶉rcs缁х画鎵ц
if (staProtocol != null && !staProtocol.isLoading() && !staProtocol.isEmptyOutType()) {
- RcsTaskContinue rcsTaskContinue = new RcsTaskContinue();
- rcsTaskContinue.setRobotTaskCode(task.getTaskNo());
- rcsTaskContinue.setTriggerType("TASK");
- rcsTaskContinue.setTriggerCode(task.getTaskNo());
+ if (task.getTaskType().equals("AGV琛ョ┖鏂欐灦")) {
+ RcsTaskContinue rcsTaskContinue = new RcsTaskContinue();
+ rcsTaskContinue.setRobotTaskCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ rcsTaskContinue.setTriggerType("TASK");
+ rcsTaskContinue.setTriggerCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
- String url =HIK_URL + "api/robot/controller/task/extend/continue";
- String response = sendPost(url, JSONObject.toJSONString(rcsTaskContinue));
- if (!StringUtils.isEmpty(response) && response.contains("code")){
- RcsReturn rcsReturn1 = JSONObject.parseObject(response, RcsReturn.class);
- if("200".equals(rcsReturn1.getCode())) {
- //鍑哄彂PLC绔欑偣鐨勬壂鐮佸櫒鎵爜
- boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(3, staProtocol));
- log.info("AGV鏀捐揣瀹屾垚锛岀粰绔欑偣鍐�9991宸ヤ綔鍙�,涓嬪彂浠诲姟:{},绔欑偣:{},agv浠诲姟鍙�:{}",result,task.getStaNo(),task.getTaskNo());
- if (result) {
- // 杩斿洖RCS
- rcsReturn.setCode("SUCCESS");
- rcsReturn.setMessage("");
- JSONObject data = new JSONObject();
- data.put("robotTaskCode", robotTaskCode);
- rcsReturn.setData(data);
- }else {
- // 杩斿洖RCS
- rcsReturn.setCode("Err_Internal");
- rcsReturn.setMessage("");
- JSONObject data = new JSONObject();
- data.put("robotTaskCode", robotTaskCode);
- rcsReturn.setData(data);
- }
+ String url = HIK_URL + "api/robot/controller/task/extend/continue";
+ String response = sendPost(url, JSONObject.toJSONString(rcsTaskContinue));
+ if (!StringUtils.isEmpty(response) && response.contains("code")) {
+ log.info("鍏佽AGV鏀捐揣鎴愬姛");
}
- }
- }
- }
- break;
-
- //鏀捐揣瀹屾垚 --銆媋gv宸茬粡绂诲紑
- case TASK_END: {
- Integer sourceStaNo = Integer.valueOf(task.getStaNo());
- SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
- StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone();
- //鏀捐揣瀹屾垚 --銆媋gv宸茬粡绂诲紑 --銆嬬粰PLC绔欑偣鍐�9991宸ヤ綔鍙�
- if (staProtocol != null && staProtocol.isLoading() && staProtocol.isEmptyOutType() && staProtocol.getWorkNo() ==0) {
- staProtocol.setWorkNo((short) 9991);
- staProtocol.setStaNo(Short.valueOf(task.getStaNo()));
- boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(2, staProtocol));
- log.info("AGV鏀捐揣瀹屾垚锛岀粰绔欑偣鍐�9991宸ヤ綔鍙�,涓嬪彂浠诲姟:{},绔欑偣:{},agv浠诲姟鍙�:{}",result,task.getStaNo(),task.getTaskNo());
- if(result){
- // 鏇存柊浠诲姟鐘舵�佺瓑鍐呴儴閫昏緫
- task.setWrkSts(304L); // 301 浠诲姟涓嬪彂銆�302 浠诲姟鎵ц銆�303 浠诲姟涓柇銆�304 浠诲姟缁撴潫
- task.setModiTime(new Date());
- taskService.updateById(task);
// 杩斿洖RCS
rcsReturn.setCode("SUCCESS");
rcsReturn.setMessage("");
JSONObject data = new JSONObject();
data.put("robotTaskCode", robotTaskCode);
rcsReturn.setData(data);
- }else {
- // 杩斿洖RCS
- rcsReturn.setCode("Err_Internal");
- rcsReturn.setMessage("");
- JSONObject data = new JSONObject();
- data.put("robotTaskCode", robotTaskCode);
- rcsReturn.setData(data);
- }
- }
- }
- break;
- //rcs璇锋眰wms鍙栬揣鐢宠
- case APPLY_PICK: {
- Integer sourceStaNo = Integer.valueOf(task.getSourceStaNo());
- SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
- StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone();
- //鍒ゆ柇绔欑偣鏄惁鏈夋枡鏋跺拰鎵樼洏
- if (staProtocol != null && staProtocol.isLoading()
- && staProtocol.isEmptyOutType()
- && staProtocol.getWorkNo() >0 && staProtocol.getWorkNo() <9990) {
- RcsTaskContinue rcsTaskContinue = new RcsTaskContinue();
- rcsTaskContinue.setRobotTaskCode(task.getTaskNo());
- rcsTaskContinue.setTriggerType("TASK");
- rcsTaskContinue.setTriggerCode(task.getTaskNo());
-
- String url =HIK_URL + "api/robot/controller/task/extend/continue";
- String response = sendPost(url, JSONObject.toJSONString(rcsTaskContinue));
- if (!StringUtils.isEmpty(response) && response.contains("code")){
- RcsReturn rcsReturn1 = JSONObject.parseObject(response, RcsReturn.class);
- if("200".equals(rcsReturn1.getCode())) {
+ } else {
+ //鍑哄彂PLC绔欑偣鐨勬壂鐮佸櫒鎵爜
+ boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(3, staProtocol));
+ if (result) {
+ log.info("鍏ュ簱绔欑偣={}瑙﹀彂鎵爜鎴愬姛", staProtocol.getSiteId());
// 杩斿洖RCS
rcsReturn.setCode("SUCCESS");
rcsReturn.setMessage("");
JSONObject data = new JSONObject();
data.put("robotTaskCode", robotTaskCode);
rcsReturn.setData(data);
- }else {
+ RcsTaskContinue rcsTaskContinue = new RcsTaskContinue();
+ rcsTaskContinue.setAgvFactory("1");
+ rcsTaskContinue.setRobotTaskCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ rcsTaskContinue.setTriggerType("TASK");
+ rcsTaskContinue.setTriggerCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+
+ String url = HIK_URL + "api/robot/controller/task/extend/continue";
+ String response = sendPost(url, JSONObject.toJSONString(rcsTaskContinue));
+ if (!StringUtils.isEmpty(response) && response.contains("code")) {
+ log.info("鍏佽AGV鏀捐揣鎴愬姛");
+ }
+ } else {
// 杩斿洖RCS
rcsReturn.setCode("Err_Internal");
rcsReturn.setMessage("");
@@ -186,27 +144,117 @@
}
}
}
+ } else {
+ TransParent transParent = new TransParent();
+ transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setStationId(task.getStaNo());
+ transParent.setAgvFactory(1);
+ transParent.setAgvCode("1");//杩炴帴鍣ㄥ簱
+ //08-1鏄┖鎵樼洏杞簭浠诲姟
+ //08-2鏄墿鏂欒浆搴忎换鍔�
+ if (task.getTaskType().equals("ZX-AGV-08-1")) {
+ transParent.setTransType("08-1");
+ } else if (task.getTaskType().equals("ZX-AGV-08-2")) {
+ transParent.setTransType("08-2");
+ } else if (task.getTaskType().equals("PP-AGV")) {
+ transParent.setTransType("10");
+ } else if (task.getTaskType().equals("ZP-AGV")) {
+ transParent.setTransType("11");
+ }
+ int i = applyInStation(transParent);
+
+ if (HIK_RENYUAN.contains(task.getStaNo())){
+ // 寤惰繜澶勭悊锛岀‘淇濆埌绔欏畬鎴愪俊鍙蜂紭鍏堝鐞�
+ try {
+ Thread.sleep(20000); // 鐫$湢20绉�
+ } catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ if (i == 1) {
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
}
- break;
- //rcs鍙栬揣瀹屾垚锛屽凡閫�鍑鸿緭閫佺嚎
- case PICK_COMPLETE: {
- Integer sourceStaNo = Integer.valueOf(task.getSourceStaNo());
+
+ }
+ break;
+
+ //鏀捐揣瀹屾垚 --銆媋gv宸茬粡绂诲紑
+ case TASK_END: {
+ if (task.getIsPda()!=null && task.getIsPda().equals("Y")){
+ // 鏇存柊浠诲姟鐘舵�佺瓑鍐呴儴閫昏緫
+ task.setWrkSts(305L); // 301 浠诲姟涓嬪彂銆�302 浠诲姟鎵ц銆�303 浠诲姟涓柇銆�304 浠诲姟缁撴潫
+ task.setModiTime(new Date());
+ taskService.updateById(task);
+ // 杩斿洖RCS
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ if (task.getStaNo().equals("Q-E2") || task.getStaNo().equals("Q-E3") || HIK_STATION.contains(task.getStaNo())){
+ // 鏇存柊浠诲姟鐘舵�佺瓑鍐呴儴閫昏緫
+ task.setWrkSts(304L); // 301 浠诲姟涓嬪彂銆�302 浠诲姟鎵ц銆�303 浠诲姟涓柇銆�304 浠诲姟缁撴潫
+ task.setModiTime(new Date());
+ taskService.updateById(task);
+ // 杩斿洖RCS
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ else if (task.getStaNo().equals("401") || task.getStaNo().equals("402") || task.getStaNo().equals("307")) {
+ Integer sourceStaNo = Integer.valueOf(task.getStaNo());
SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone();
+ Boolean boo = false;
+ Short wrkNo = 9991;
+ if (task.getStaNo().equals("307")) {
+ wrkNo = 9997;
+ }
+
//鏀捐揣瀹屾垚 --銆媋gv宸茬粡绂诲紑 --銆嬬粰PLC绔欑偣鍐�9991宸ヤ綔鍙�
- if (staProtocol != null && !staProtocol.isLoading() && !staProtocol.isEmptyOutType() && staProtocol.getWorkNo() >0 && staProtocol.getWorkNo() <9990) {
- staProtocol.setWorkNo((short) 0);
- staProtocol.setStaNo((short) 0);
+ //琛ョ┖鏂欐灦 --銆媋gv宸茬粡绔嬪簱 --銆嬬粰PLC绔欑偣鍐�9995宸ヤ綔鍙�
+ if (task.getTaskType().equals("AGV琛ョ┖鏂欐灦") && staProtocol != null && !staProtocol.isLoading() && staProtocol.isEmptyOutType() && staProtocol.getWorkNo() == 0) {
+ boo = true;
+ wrkNo = 9998;
+ } else if (!task.getTaskType().equals("AGV琛ョ┖鏂欐灦") && staProtocol != null && staProtocol.isLoading() && staProtocol.isEmptyOutType()) {
+ boo = true;
+ }
+ if (boo) {
+ staProtocol.setWorkNo(wrkNo);//绌烘枡鏋跺埌浣嶄俊鍙风偣
+ staProtocol.setStaNo(Short.valueOf("0"));
boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(2, staProtocol));
- log.info("AGV鍙栬揣瀹屾垚锛岀粰绔欑偣鍐�0宸ヤ綔鍙�,涓嬪彂浠诲姟:{},绔欑偣:{},agv浠诲姟鍙�:{}",result,task.getStaNo(),task.getTaskNo());
- if(result){
+ log.info("AGV鏀捐揣瀹屾垚锛岀粰绔欑偣鍐�9991宸ヤ綔鍙�,涓嬪彂浠诲姟:{},绔欑偣:{},agv浠诲姟鍙�:{}", result, task.getStaNo(), task.getTaskNo());
+ if (result) {
+ // 鏇存柊浠诲姟鐘舵�佺瓑鍐呴儴閫昏緫
+ task.setWrkSts(304L); // 301 浠诲姟涓嬪彂銆�302 浠诲姟鎵ц銆�303 浠诲姟涓柇銆�304 浠诲姟缁撴潫
+ task.setModiTime(new Date());
+ taskService.updateById(task);
// 杩斿洖RCS
rcsReturn.setCode("SUCCESS");
rcsReturn.setMessage("");
+
JSONObject data = new JSONObject();
data.put("robotTaskCode", robotTaskCode);
rcsReturn.setData(data);
- }else {
+ } else {
// 杩斿洖RCS
rcsReturn.setCode("Err_Internal");
rcsReturn.setMessage("");
@@ -214,16 +262,404 @@
data.put("robotTaskCode", robotTaskCode);
rcsReturn.setData(data);
}
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ } else {
+ TransParent transParent = new TransParent();
+ transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setStationId(task.getStaNo());
+ transParent.setAgvFactory(1);
+ transParent.setAgvCode("1");//杩炴帴鍣ㄥ簱
+ //08-1鏄┖鎵樼洏杞簭浠诲姟
+ //08-2鏄墿鏂欒浆搴忎换鍔�
+ if (task.getTaskType().equals("ZX-AGV-08-1")) {
+ transParent.setTransType("08-1");
+ } else if (task.getTaskType().equals("ZX-AGV-08-2")) {
+ transParent.setTransType("08-2");
+ } else if (task.getTaskType().equals("PP-AGV")) {
+ transParent.setTransType("10");
+ } else if (task.getTaskType().equals("ZP-AGV")) {
+ transParent.setTransType("11");
+ }
+ //鏀捐揣绂诲紑绔欑偣
+ int i = AGVDepartureCompleted(transParent);
+ if (i == 1) {
+ // 鏇存柊浠诲姟鐘舵�佺瓑鍐呴儴閫昏緫
+ task.setWrkSts(304L); // 301 浠诲姟涓嬪彂銆�302 浠诲姟鎵ц銆�303 浠诲姟涓柇銆�304 浠诲姟缁撴潫
+ task.setModiTime(new Date());
+ taskService.updateById(task);
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ }
+ }
+ break;
+ //rcs璇锋眰wms鍙栬揣鐢宠
+ case APPLY_PICK: {
+ if (task.getSourceStaNo().equals("401") || task.getSourceStaNo().equals("402") || task.getSourceStaNo().equals("307")) {
+ Integer sourceStaNo = Integer.valueOf(task.getSourceStaNo());
+ SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
+ StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone();
+ //鍒ゆ柇绔欑偣鏄惁鏈夋枡鏋跺拰鎵樼洏
+ if (staProtocol != null && (staProtocol.isLoading() || task.getTaskType().equals("AGV绌烘枡鏋跺洖缂撳瓨鍖�"))
+ && staProtocol.isEmptyOutType()) {
+ RcsTaskContinue rcsTaskContinue = new RcsTaskContinue();
+ rcsTaskContinue.setRobotTaskCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ rcsTaskContinue.setTriggerType("TASK");
+ rcsTaskContinue.setTriggerCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ String url = HIK_URL + "api/robot/controller/task/extend/continue";
+ String response = sendPost(url, JSONObject.toJSONString(rcsTaskContinue));
+ if (!StringUtils.isEmpty(response) && response.contains("code")) {
+ RcsReturn rcsReturn1 = JSONObject.parseObject(response, RcsReturn.class);
+ if ("SUCCESS".equals(rcsReturn1.getCode())) {
+ // 杩斿洖RCS
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ }
+ }
+ } else {
+ TransParent transParent = new TransParent();
+ transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setStationId(task.getSourceStaNo());
+ transParent.setAgvFactory(1);
+ transParent.setAgvCode("1");//杩炴帴鍣ㄥ簱
+ //08-1鏄┖鎵樼洏杞簭浠诲姟
+ //08-2鏄墿鏂欒浆搴忎换鍔�
+ if (task.getTaskType().equals("ZX-AGV-08-1")) {
+ transParent.setTransType("08-1");
+ } else if (task.getTaskType().equals("ZX-AGV-08-2")) {
+ transParent.setTransType("08-2");
+ } else if (task.getTaskType().equals("PP-AGV")) {
+ transParent.setTransType("10");
+ } else if (task.getTaskType().equals("ZP-AGV")) {
+ transParent.setTransType("11");
+ }
+ int i = applyInStation(transParent);
+
+ if (HIK_RENYUAN.contains(task.getStaNo())){
+ // 寤惰繜澶勭悊锛岀‘淇濆埌绔欏畬鎴愪俊鍙蜂紭鍏堝鐞�
+ try {
+ Thread.sleep(20000); // 鐫$湢20绉�
+ } catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ if (i == 1) {
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ }
+ }
+ break;
+ //rcs鍙栬揣瀹屾垚锛屽凡閫�鍑鸿緭閫佺嚎
+ case PICK_COMPLETE: {
+ if (task.getSourceStaNo().equals("401") || task.getSourceStaNo().equals("402") || task.getSourceStaNo().equals("307")) {
+ Integer sourceStaNo = Integer.valueOf(task.getSourceStaNo());
+ SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
+ StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone();
+ //鏀捐揣瀹屾垚 --銆媋gv宸茬粡绂诲紑 --銆嬬粰PLC绔欑偣鍐�9991宸ヤ綔鍙�
+ if (staProtocol != null && !staProtocol.isLoading() && !staProtocol.isEmptyOutType()) {
+ staProtocol.setWorkNo((short) 0);
+ staProtocol.setStaNo((short) 0);
+ boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(2, staProtocol));
+ log.info("AGV鍙栬揣瀹屾垚锛岀粰绔欑偣鍐�0宸ヤ綔鍙�,涓嬪彂浠诲姟:{},绔欑偣:{},agv浠诲姟鍙�:{}", result, task.getStaNo(), task.getTaskNo());
+ if (result) {
+ // 杩斿洖RCS
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ }
+ } else {
+ TransParent transParent = new TransParent();
+ transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setStationId(task.getSourceStaNo());
+ transParent.setAgvFactory(1);
+ transParent.setAgvCode("1");//杩炴帴鍣ㄥ簱
+ //08-1鏄┖鎵樼洏杞簭浠诲姟
+ //08-2鏄墿鏂欒浆搴忎换鍔�
+ if (task.getTaskType().equals("ZX-AGV-08-1")) {
+ transParent.setTransType("08-1");
+ } else if (task.getTaskType().equals("ZX-AGV-08-2")) {
+ transParent.setTransType("08-2");
+ } else if (task.getTaskType().equals("PP-AGV")) {
+ transParent.setTransType("10");
+ } else if (task.getTaskType().equals("ZP-AGV")) {
+ transParent.setTransType("11");
+ }
+ //鍙栬揣绂诲紑绔欑偣
+ int i = AGVDepartureCompleted(transParent);
+ if (i == 1) {
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ }
+ }
+ break;
+ //AGV鍙栬揣绂荤珯璇锋眰
+ case APPLY_IN_OFF_STATION: {
+ //濡傛灉鏄珛搴撶珯鐐圭洿鎺ュ厑璁哥绔�
+ if (task.getSourceStaNo().equals("401") || task.getSourceStaNo().equals("402") || task.getSourceStaNo().equals("307")) {
+ RcsTaskContinue rcsTaskContinue = new RcsTaskContinue();
+ rcsTaskContinue.setRobotTaskCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ rcsTaskContinue.setTriggerType("TASK");
+ rcsTaskContinue.setTriggerCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+
+ String url = HIK_URL + "api/robot/controller/task/extend/continue";
+ String response = sendPost(url, JSONObject.toJSONString(rcsTaskContinue));
+ if (!StringUtils.isEmpty(response) && response.contains("code")) {
+ RcsReturn rcsReturn1 = JSONObject.parseObject(response, RcsReturn.class);
+ if ("SUCCESS".equals(rcsReturn1.getCode())) {
+ // 杩斿洖RCS
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ }
+ } else {
+
+ // 寤惰繜澶勭悊锛岀‘淇濆埌绔欏畬鎴愪俊鍙蜂紭鍏堝鐞�
+ try {
+ Thread.sleep(5000); // 鐫$湢5绉�
+ } catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+
+ //濡傛灉鏄伐浣嶉渶瑕佸儚mes璇锋眰绂荤珯
+ TransParent transParent = new TransParent();
+ transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setStationId(values.getString("slotName"));
+ transParent.setAgvFactory(1);
+ transParent.setAgvCode("1");//杩炴帴鍣ㄥ簱
+ //08-1鏄┖鎵樼洏杞簭浠诲姟
+ //08-2鏄墿鏂欒浆搴忎换鍔�
+ if (task.getTaskType().equals("ZX-AGV-08-1")) {
+ transParent.setTransType("08-1");
+ } else if (task.getTaskType().equals("ZX-AGV-08-2")) {
+ transParent.setTransType("08-2");
+ } else if (task.getTaskType().equals("PP-AGV")) {
+ transParent.setTransType("10");
+ } else if (task.getTaskType().equals("ZP-AGV")) {
+ transParent.setTransType("11");
+ }
+ int i = applyOutStation(transParent);
+ if (i == 1) {
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
}
}
break;
+ }
+ //AGV鏀捐揣绂荤珯璇锋眰
+ case APPLY_OFF_STATION: {
+ //濡傛灉鏄珛搴撶珯鐐圭洿鎺ュ厑璁哥绔�
+ if (task.getStaNo().equals("401") || task.getStaNo().equals("402") || task.getStaNo().equals("307")) {
+ RcsTaskContinue rcsTaskContinue = new RcsTaskContinue();
+ rcsTaskContinue.setRobotTaskCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ rcsTaskContinue.setTriggerType("TASK");
+ rcsTaskContinue.setTriggerCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
- default: {
+ String url = HIK_URL + "api/robot/controller/task/extend/continue";
+ String response = sendPost(url, JSONObject.toJSONString(rcsTaskContinue));
+ if (!StringUtils.isEmpty(response) && response.contains("code")) {
+ RcsReturn rcsReturn1 = JSONObject.parseObject(response, RcsReturn.class);
+ if ("SUCCESS".equals(rcsReturn1.getCode())) {
+ // 杩斿洖RCS
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ }
+ } else {
+
+ // 寤惰繜澶勭悊锛岀‘淇濆埌绔欏畬鎴愪俊鍙蜂紭鍏堝鐞�
+ try {
+ Thread.sleep(5000); // 鐫$湢5绉�
+ } catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+
+ //濡傛灉鏄伐浣嶉渶瑕佸儚mes璇锋眰绂荤珯
+ TransParent transParent = new TransParent();
+ transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setStationId(values.getString("slotName"));
+ transParent.setAgvFactory(1);
+ transParent.setAgvCode("1");//杩炴帴鍣ㄥ簱
+ //08-1鏄┖鎵樼洏杞簭浠诲姟
+ //08-2鏄墿鏂欒浆搴忎换鍔�
+ if (task.getTaskType().equals("ZX-AGV-08-1")) {
+ transParent.setTransType("08-1");
+ } else if (task.getTaskType().equals("ZX-AGV-08-2")) {
+ transParent.setTransType("08-2");
+ } else if (task.getTaskType().equals("PP-AGV")) {
+ transParent.setTransType("10");
+ } else if (task.getTaskType().equals("ZP-AGV")) {
+ transParent.setTransType("11");
+ }
+ int i = applyOutStation(transParent);
+ if (i == 1) {
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
+ }
+
+ break;
+ }
+ //鍒扮珯瀹屾垚
+ case ARRIVE_ON_STATION: {
+ if ( values.getString("slotName").equals("401") || values.getString("slotName").equals("402") || values.getString("slotName").equals("307")) {
+ // 杩斿洖RCS
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ TransParent transParent = new TransParent();
+ transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
+ transParent.setStationId(values.getString("slotName"));
+ transParent.setAgvFactory(1);
+ transParent.setAgvCode("1");//杩炴帴鍣ㄥ簱
+ //08-1鏄┖鎵樼洏杞簭浠诲姟
+ //08-2鏄墿鏂欒浆搴忎换鍔�
+ if (task.getTaskType().equals("ZX-AGV-08-1")) {
+ transParent.setTransType("08-1");
+ } else if (task.getTaskType().equals("ZX-AGV-08-2")) {
+ transParent.setTransType("08-2");
+ } else if (task.getTaskType().equals("PP-AGV")) {
+ transParent.setTransType("10");
+ } else if (task.getTaskType().equals("ZP-AGV")) {
+ transParent.setTransType("11");
+ }
+ int i = AGVArrivalCompletedFit(transParent);
+ if (i == 1) {
+ rcsReturn.setCode("SUCCESS");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ } else {
+ // 杩斿洖RCS
+ rcsReturn.setCode("Err_Internal");
+ rcsReturn.setMessage("");
+ JSONObject data = new JSONObject();
+ data.put("robotTaskCode", robotTaskCode);
+ rcsReturn.setData(data);
+ }
}
break;
}
+
+ default: {
+ }
+ break;
}
+
} catch (Exception e) {
log.error("RCS鍙嶉浠诲姟杩涘害澶勭悊寮傚父 - {}", rcsReporterTask, e);
@@ -238,9 +674,108 @@
}
/**
+ * 鍒扮珯瀹屾垚锛欰GV鍒拌揪宸ヤ綅閲岄潰--銆媘es鍒颁綅瀹屾垚
+ *
+ * @param apply
+ * @return
+ */
+ public int AGVArrivalCompletedFit(TransParent apply) {
+
+ String url = MES_URL + "AGVArrivalCompletedFit";
+ String response = RcsServiceImpl.sendPost(url, JSONObject.toJSONString(apply));
+ if (!StringUtils.isEmpty(response) && response.contains("Success")) {
+ MesReturn mesReturn = JSONObject.parseObject(response, MesReturn.class);
+ if ("1".equals(mesReturn.getSuccess())) {
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+ /**
+ * 绂荤珯瀹屾垚锛歸ms->mes
+ * AGV绂诲紑鎺ラ┏浣嶅悗鍙戦�佺寮�鐘舵�佺粰MES
+ *
+ * @param apply
+ * @return
+ */
+ public int AGVDepartureCompleted(TransParent apply) {
+
+ String url = MES_URL + "AGVDepartureCompleted";
+ String response = RcsServiceImpl.sendPost(url, JSONObject.toJSONString(apply));
+ if (!StringUtils.isEmpty(response) && response.contains("Success")) {
+ MesReturn mesReturn = JSONObject.parseObject(response, MesReturn.class);
+ if ("1".equals(mesReturn.getSuccess())) {
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+ /**
+ * 鍏ョ珯璇锋眰锛氳浆鍙慉GV->鍏ョ珯璇锋眰->缁橫ES
+ *
+ * @param apply
+ * @return
+ */
+ public int applyInStation(TransParent apply) {
+ String path = "AGVTransportPalletNotice";
+ String url = MES_URL + path;
+ String response = RcsServiceImpl.sendPost(url, JSONObject.toJSONString(apply));
+ if (!StringUtils.isEmpty(response) && response.contains("Success")) {
+ MesReturn mesReturn = JSONObject.parseObject(response, MesReturn.class);
+ if ("1".equals(mesReturn.getSuccess())) {
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+
+ /**
+ * 绂荤珯璇锋眰锛氳浆鍙慉GV->绂荤珯璇锋眰->缁橫ES
+ *
+ * @param apply
+ * @return
+ */
+
+ public int applyOutStation(TransParent apply) {
+
+ String url = MES_URL + "AGVDepartureRequest";
+ String response = RcsServiceImpl.sendPost(url, JSONObject.toJSONString(apply));
+ if (!StringUtils.isEmpty(response) && response.contains("Success")) {
+ MesReturn mesReturn = JSONObject.parseObject(response, MesReturn.class);
+ if ("1".equals(mesReturn.getSuccess())) {
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+ @Override
+ public R bindOrUnbind (BindOrUnbindParam param) {
+ //1.鍏堣繘琛岀粦瀹�
+ String url = HIK_URL + "api/robot/controller/carrier/bind";
+ String response = sendPost(url, JSONObject.toJSONString(param));
+ if (!StringUtils.isEmpty(response) && response.contains("code")) {
+ RcsReturn rcsReturn1 = JSONObject.parseObject(response, RcsReturn.class);
+ if ("SUCCESS".equals(rcsReturn1.getCode())) {
+ //2.缁戝畾鎴愬姛锛屽绔欏畾杩涜瑙g粦
+ String url1 = HIK_URL + "api/robot/controller/carrier/unbind";
+ String response1 = sendPost(url, JSONObject.toJSONString(param));
+ return R.ok();
+ } else {
+ R.error("缁戝畾澶辫触锛岃鍖哄煙婊′簡");
+ }
+ }else {
+ return R.error();
+ }
+ return R.ok();
+ }
+ /**
* 鍚戞寚瀹� URL 鍙戦�丳OST鏂规硶鐨勮姹�
*
- * @param url 鍙戦�佽姹傜殑 URL
+ * @param url 鍙戦�佽姹傜殑 URL
* @param param 璇锋眰鍙傛暟锛岃姹傚弬鏁板簲璇ユ槸 name1=value1&name2=value2 鐨勫舰寮忋��
* @return 鎵�浠h〃杩滅▼璧勬簮鐨勫搷搴旂粨鏋�
*/
@@ -248,8 +783,7 @@
PrintWriter out = null;
BufferedReader in = null;
StringBuilder result = new StringBuilder();
- try
- {
+ try {
log.info("sendPost - {} - {}", url, param);
URL realUrl = new URL(url);
URLConnection conn = realUrl.openConnection();
@@ -272,46 +806,81 @@
out.flush();
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
String line;
- while ((line = in.readLine()) != null)
- {
+ while ((line = in.readLine()) != null) {
result.append(line);
}
log.info("recv - {}", result);
- }
- catch (ConnectException e)
- {
+ } catch (ConnectException e) {
log.error("璋冪敤HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
- }
- catch (SocketTimeoutException e)
- {
+ } catch (SocketTimeoutException e) {
log.error("璋冪敤HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
log.error("璋冪敤HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
log.error("璋冪敤HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
- }
- finally
- {
- try
- {
- if (out != null)
- {
+ } finally {
+ try {
+ if (out != null) {
out.close();
}
- if (in != null)
- {
+ if (in != null) {
in.close();
}
- }
- catch (IOException ex)
- {
+ } catch (IOException ex) {
log.error("璋冪敤in.close Exception, url=" + url + ",param=" + param, ex);
}
}
return result.toString();
}
+
+
+ public void agvPause(StaProtocol staProtocol){
+ if (staProtocol.isHighError()) {
+ JSONObject params = new JSONObject();
+ if (staProtocol.getSiteId()==402) {
+ params.put("zoneCode", "GK402");
+ params.put("mapCode", "BB");
+ params.put("invoke", "FREEZE");
+ System.out.println("402瓒呴珮鎶ヨ");
+ }else if (staProtocol.getSiteId() == 401){
+ params.put("zoneCode", "GK401");
+ params.put("mapCode", "BB");
+ params.put("invoke", "FREEZE");
+ System.out.println("401瓒呴珮鎶ヨ");
+ }
+ String url = HIK_URL + "api/robot/controller/zone/pause";
+ try {
+ String response = RcsServiceImpl.sendPost(url, JSONObject.toJSONString(params));
+ JSONObject jsonObject = JSON.parseObject(response);
+ if (!StringUtils.isEmpty(response) && (jsonObject.getString("code").equals("SUCCESS") || jsonObject.getInteger("code") == 200)) {
+ System.out.println("鏆傚仠鎴愬姛");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (!staProtocol.isHighError()) {
+ JSONObject params = new JSONObject();
+ if (staProtocol.getSiteId()==402) {
+ params.put("zoneCode", "GK402");
+ params.put("mapCode", "BB");
+ params.put("invoke", "RUN");
+ }else if (staProtocol.getSiteId() == 401){
+ params.put("zoneCode", "GK401");
+ params.put("mapCode", "BB");
+ params.put("invoke", "RUN");
+ System.out.println("灏濊瘯鍚姩401鍙GV");
+ }
+ String url = HIK_URL + "api/robot/controller/zone/pause";
+ try {
+ String response = RcsServiceImpl.sendPost(url, JSONObject.toJSONString(params));
+ JSONObject jsonObject = JSON.parseObject(response);
+ if (!StringUtils.isEmpty(response) && (jsonObject.getString("code").equals("SUCCESS") || jsonObject.getInteger("code") == 200)) {
+ System.out.println("AGV鍚姩鎴愬姛");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
}
--
Gitblit v1.9.1