|
@@ -1,5 +1,7 @@
|
|
|
package com.ruoyi.ams.agv.ndc.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
|
|
@@ -15,7 +17,7 @@ import com.ruoyi.ams.task.service.IWcsTaskService;
|
|
|
import com.ruoyi.base.constant.Constant;
|
|
|
import com.ruoyi.base.domain.BaseLocationInfo;
|
|
|
import com.ruoyi.base.service.IBaseLocationInfoService;
|
|
|
-import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
|
import com.ruoyi.common.utils.uuid.SnowflakeIdWorker;
|
|
|
import com.ruoyi.hard.modbus.tcp.AutoDoorClient;
|
|
|
import com.ruoyi.system.enums.CnveyorBeltsPlcEnum;
|
|
@@ -25,7 +27,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.time.Duration;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.ruoyi.ams.agv.ndc.service.impl.StatusUpdateServiceImpl.AGV_ACTION.UNLOAD;
|
|
|
|
|
@@ -54,6 +59,11 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
@Autowired
|
|
|
ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StatusUpdateService statusUpdateService;
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
public enum AGV_ACTION {
|
|
|
/***
|
|
|
* 取货
|
|
@@ -99,27 +109,44 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
result.setState(1);
|
|
|
break;
|
|
|
case 90:
|
|
|
-
|
|
|
+ if (wcsTask.getState()==7){
|
|
|
+ log.info("任务已取消!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
result.setState(2);
|
|
|
break;
|
|
|
+ case 204:
|
|
|
+ //切换导航
|
|
|
+ threadPoolTaskExecutor.execute(() -> {
|
|
|
+ try {
|
|
|
+ if ("10016".equals(wcsTask.getAreaTo())) {
|
|
|
+ statusUpdateService.changeNavigation(carNo, amsTask.getIkey(), "0001");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("切换导航失败,Switching navigation failed,msg:{}", e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ result.setState(3);
|
|
|
+ break;
|
|
|
case 91:
|
|
|
result.setState(4);
|
|
|
- threadPoolTaskExecutor.execute(()->{
|
|
|
+ threadPoolTaskExecutor.execute(() -> {
|
|
|
try {
|
|
|
endOfMissionSecurity(wcsTask);
|
|
|
} catch (InterruptedException e) {
|
|
|
- log.error("The security judgment execution is abnormal,msg:{}",e.getMessage());
|
|
|
+ log.error("The security judgment execution is abnormal,msg:{}", e.getMessage());
|
|
|
}
|
|
|
|
|
|
});
|
|
|
break;
|
|
|
case 92:
|
|
|
result.setState(6);
|
|
|
- threadPoolTaskExecutor.execute(()->{
|
|
|
+ threadPoolTaskExecutor.execute(() -> {
|
|
|
try {
|
|
|
endOfMissionSecurity(wcsTask);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("The security judgment execution is abnormal,msg:{}",e.getMessage());
|
|
|
+ log.error("The security judgment execution is abnormal,msg:{}", e.getMessage());
|
|
|
}
|
|
|
|
|
|
});
|
|
@@ -130,12 +157,9 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
case 113:
|
|
|
result.setState(8);
|
|
|
break;
|
|
|
- case 114:
|
|
|
- result.setState(2);
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ log.info("任务回调执行:{}", result);
|
|
|
wcsTaskService.callBack(result.getTaskNo(), result.getState(), result.getCarNo());
|
|
|
|
|
|
amsTask.setSystemStatus(result.getState());
|
|
@@ -145,31 +169,32 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
|
|
|
private void endOfMissionSecurity(WcsTask wcsTask) throws InterruptedException {
|
|
|
S7PLC conveyorBeltsPlc = plcConnectServiceRunner.getPlcServer("conveyorBeltsPlc");
|
|
|
- byte command = 24;
|
|
|
+ byte command = 25;
|
|
|
byte initial = 0;
|
|
|
byte submit = 1;
|
|
|
- if("102102".equals(wcsTask.getLocationTo())){
|
|
|
- conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_1.getMetadata(),command);
|
|
|
- conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_1.getMetadata(),submit);
|
|
|
+ if ("102102".equals(wcsTask.getLocationTo())) {
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_1.getMetadata(), command);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_1.getMetadata(), submit);
|
|
|
Thread.sleep(3000);
|
|
|
- conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_1.getMetadata(),initial);
|
|
|
- conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_1.getMetadata(),initial);
|
|
|
- }else {
|
|
|
- conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_4.getMetadata(),command);
|
|
|
- conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_4.getMetadata(),submit);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_1.getMetadata(), initial);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_1.getMetadata(), initial);
|
|
|
+ } else if ("102103".equals(wcsTask.getLocationTo())) {
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_3.getMetadata(), command);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_3.getMetadata(), submit);
|
|
|
Thread.sleep(3000);
|
|
|
- conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_4.getMetadata(),initial);
|
|
|
- conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_4.getMetadata(),initial);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_3.getMetadata(), initial);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_3.getMetadata(), initial);
|
|
|
}
|
|
|
+ log.info("agv安全退出");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized void confirmAnalysis(String taskNo, Integer aciIndex, String type, Integer carNo) {
|
|
|
+ public synchronized void confirmAnalysis(String taskNo, Integer aciIndex, String type, Integer carNo) throws InterruptedException {
|
|
|
AmsTask amsTask = new AmsTask();
|
|
|
amsTask.setTaskNo(taskNo);
|
|
|
amsTask = amsTaskService.selectAmsTaskByModel(amsTask);
|
|
|
//添加取货卸货前安全握
|
|
|
- if (AGVUnloadOrPickUpSafetyJudgment(taskNo,type)){
|
|
|
+ if (AGVUnloadOrPickUpSafetyJudgment(taskNo, type,amsTask.getAciIndex().toString())) {
|
|
|
return;
|
|
|
}
|
|
|
if (amsTask != null) {
|
|
@@ -222,6 +247,7 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
addTaskForm.setRemark(taskNo);
|
|
|
addTaskForm.setExt2(updateLocation);
|
|
|
addTaskForm.setExt3(updateValue);
|
|
|
+ addTaskForm.setIkey((long) BusinessServiceImpl.geniKey(addTaskForm.getTaskNo()));
|
|
|
//如果ams_task已经有此任务的待接收m消息,则不生成新的m消息
|
|
|
AmsTask amsTaskQuery = new AmsTask();
|
|
|
amsTaskQuery.setAciAccept(0);
|
|
@@ -230,6 +256,7 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
amsTaskQuery.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_m.getValue());
|
|
|
amsTaskQuery.setExt2(addTaskForm.getExt2());
|
|
|
amsTaskQuery.setExt2(addTaskForm.getExt3());
|
|
|
+ amsTaskQuery.setIkey((long) BusinessServiceImpl.geniKey(addTaskForm.getTaskNo()));
|
|
|
List<AmsTask> undoneList = amsTaskService.selectAmsTaskList(amsTaskQuery);
|
|
|
if (undoneList.size() > 0) {
|
|
|
return;
|
|
@@ -240,6 +267,25 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void changeNavigation(Integer carNo, Long ikey, String i) {
|
|
|
+ AmsTask amsTask = new AmsTask();
|
|
|
+ amsTask = amsTaskService.selectAmsTaskByModel(amsTask);
|
|
|
+ if (amsTask != null) {
|
|
|
+ AmsTask addTaskForm = new AmsTask();
|
|
|
+ addTaskForm.setTaskNo(System.currentTimeMillis() + "");
|
|
|
+ addTaskForm.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_50.getValue());
|
|
|
+ addTaskForm.setStFrom(998);
|
|
|
+ addTaskForm.setStTo(999);
|
|
|
+ addTaskForm.setPriority(1);
|
|
|
+ addTaskForm.setExt1(carNo.toString());
|
|
|
+ addTaskForm.setExt2(i);
|
|
|
+ addTaskForm.setExt3(ikey.toString());
|
|
|
+ addTaskForm.setIkey((long) BusinessServiceImpl.geniKey(addTaskForm.getTaskNo()));
|
|
|
+ amsTaskService.insertAmsTask(addTaskForm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void feedbackTS(Integer doorNo) {
|
|
|
AmsTask addTaskForm = new AmsTask();
|
|
@@ -301,40 +347,96 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public boolean AGVUnloadOrPickUpSafetyJudgment(String taskNo,String type) {
|
|
|
+ public boolean AGVUnloadOrPickUpSafetyJudgment(String taskNo, String type, String aciIndex) throws InterruptedException {
|
|
|
+ byte command_21 = 21;
|
|
|
+ byte command_22 = 22;
|
|
|
+ byte initial = 0;
|
|
|
+ byte submit = 1;
|
|
|
+
|
|
|
+ if (ObjectUtil.isNull(redisCache.getCacheObject("Confirm"+taskNo))){
|
|
|
+ log.info("agv进行安全握");
|
|
|
+ redisCache.setCacheObject("Confirm"+taskNo,new Date().getTime(),60,TimeUnit.SECONDS);
|
|
|
+ }else {
|
|
|
+ Long time = Long.parseLong( redisCache.getCacheObject("Confirm" + taskNo).toString());
|
|
|
+ DateTime dateTime = new DateTime(new Date(time));
|
|
|
+ Duration between = LocalDateTimeUtil.between(dateTime.toLocalDateTime(), new DateTime(new Date()).toLocalDateTime());
|
|
|
+ long seconds = between.getSeconds();
|
|
|
+ if (seconds>30){
|
|
|
+ AmsTask addTaskForm = new AmsTask();
|
|
|
+ addTaskForm.setTaskNo(System.currentTimeMillis() + "");
|
|
|
+ addTaskForm.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_m.getValue());
|
|
|
+ addTaskForm.setExt1(aciIndex);
|
|
|
+ addTaskForm.setStFrom(998);
|
|
|
+ addTaskForm.setStTo(999);
|
|
|
+ addTaskForm.setPriority(1);
|
|
|
+ addTaskForm.setRemark(taskNo);
|
|
|
+ // 取货确认
|
|
|
+ if (type.equals(AGV_ACTION.PICKUP.getValue())) {
|
|
|
+ addTaskForm.setExt2("08");
|
|
|
+ addTaskForm.setExt3("0002");
|
|
|
+ // 卸货确认
|
|
|
+ } else if (type.equals(AGV_ACTION.UNLOAD.getValue())) {
|
|
|
+ addTaskForm.setExt2("09");
|
|
|
+ addTaskForm.setExt3("0002");
|
|
|
+ }
|
|
|
+ //如果ams_task已经有此任务的待接收m消息,则不生成新的m消息
|
|
|
+ AmsTask amsTaskQuery = new AmsTask();
|
|
|
+ amsTaskQuery.setAciAccept(0);
|
|
|
+ amsTaskQuery.setIsDelete(0);
|
|
|
+ amsTaskQuery.setRemark(taskNo);
|
|
|
+ amsTaskQuery.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_m.getValue());
|
|
|
+ amsTaskQuery.setExt2(addTaskForm.getExt2());
|
|
|
+ List<AmsTask> undoneList = amsTaskService.selectAmsTaskList(amsTaskQuery);
|
|
|
+ if (undoneList.size() > 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ amsTaskService.insertAmsTask(addTaskForm);
|
|
|
+ }
|
|
|
+ }
|
|
|
WcsTask wcsTask = wcsTaskMapper.selectWcsTaskByTaskNo(taskNo);
|
|
|
- if (ObjectUtil.isNull(wcsTask)){
|
|
|
- throw new ServiceException("The AGV feedback task does not exist,Security judgment cannot be made!!!");
|
|
|
+ if (ObjectUtil.isNull(wcsTask)) {
|
|
|
+ log.error("The AGV feedback task does not exist,Security judgment cannot be made!!!");
|
|
|
+ return true;
|
|
|
}
|
|
|
S7PLC conveyorBeltsPlc = plcConnectServiceRunner.getPlcServer("conveyorBeltsPlc");
|
|
|
- if (type.equals(UNLOAD.getValue())){
|
|
|
- BaseLocationInfo baseLocationInfo = iBaseLocationInfoService.selectBaseLocationInfoById(Long.parseLong( wcsTask.getLocationTo()));
|
|
|
- if (baseLocationInfo.getZoneId().equals(10005L)){
|
|
|
- if("102102".equals(wcsTask.getLocationTo())){
|
|
|
- if (conveyorBeltsPlc.readByte(CnveyorBeltsPlcEnum.MOVE_1.getMetadata()) ==3){
|
|
|
- return true;
|
|
|
- }
|
|
|
- }else {
|
|
|
- if (conveyorBeltsPlc.readByte(CnveyorBeltsPlcEnum.MOVE_4.getMetadata()) ==3){
|
|
|
- return true;
|
|
|
+ BaseLocationInfo to = iBaseLocationInfoService.selectBaseLocationInfoById(Long.parseLong(wcsTask.getLocationTo()));
|
|
|
+ BaseLocationInfo from = iBaseLocationInfoService.selectBaseLocationInfoById(Long.parseLong(wcsTask.getLocationFrom()));
|
|
|
+ if (to.getZoneId().equals(10005L) || from.getZoneId().equals(10005L)) {
|
|
|
+ if ("102102".equals(wcsTask.getLocationTo())) {
|
|
|
+ if (conveyorBeltsPlc.readByte(CnveyorBeltsPlcEnum.RELEASE_SIGNAL_1.getMetadata()) == 1) {
|
|
|
+ log.info("agv结束安全握,一号位");
|
|
|
+ return false;
|
|
|
+ }else{
|
|
|
+ log.info("一号位禁止进入原因:{}",conveyorBeltsPlc.readByte(CnveyorBeltsPlcEnum.REJECT_REASON_1.getMetadata()));
|
|
|
+ if (type.equals(UNLOAD.getValue())){
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_1.getMetadata(),command_21);
|
|
|
+ }else {
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_1.getMetadata(),command_22);
|
|
|
}
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_1.getMetadata(), submit);
|
|
|
+ Thread.sleep(3000L);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_1.getMetadata(),initial);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_1.getMetadata(), initial);
|
|
|
}
|
|
|
- }
|
|
|
- }else {
|
|
|
- BaseLocationInfo baseLocationInfo = iBaseLocationInfoService.selectBaseLocationInfoById(Long.parseLong( wcsTask.getLocationFrom()));
|
|
|
- if (baseLocationInfo.getZoneId().equals(10005L)) {
|
|
|
- if ("102103".equals(wcsTask.getLocationTo())) {
|
|
|
- if (conveyorBeltsPlc.readByte(CnveyorBeltsPlcEnum.MOVE_1.getMetadata()) != 3) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (conveyorBeltsPlc.readByte(CnveyorBeltsPlcEnum.MOVE_4.getMetadata()) != 3) {
|
|
|
- return true;
|
|
|
+ } else {
|
|
|
+ if (conveyorBeltsPlc.readByte(CnveyorBeltsPlcEnum.RELEASE_SIGNAL_3.getMetadata()) == 1) {
|
|
|
+ log.info("agv结束安全握,三号位");
|
|
|
+ return false;
|
|
|
+ }else{
|
|
|
+ log.info("三号位禁止进入原因:{}",conveyorBeltsPlc.readByte(CnveyorBeltsPlcEnum.REJECT_REASON_3.getMetadata()));
|
|
|
+ if (type.equals(UNLOAD.getValue())){
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_3.getMetadata(),command_21);
|
|
|
+ }else {
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_3.getMetadata(),command_22);
|
|
|
}
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_3.getMetadata(), submit);
|
|
|
+ Thread.sleep(3000L);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_3.getMetadata(),initial);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_3.getMetadata(), initial);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return false;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
}
|