|
@@ -1,22 +1,34 @@
|
|
|
package com.ruoyi.ams.agv.ndc.service.impl;
|
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
|
|
|
import com.ruoyi.ams.agv.ndc.domain.AmsTask;
|
|
|
import com.ruoyi.ams.agv.ndc.entity.CallbackResult;
|
|
|
import com.ruoyi.ams.agv.ndc.service.IAmsTaskService;
|
|
|
import com.ruoyi.ams.agv.ndc.service.StatusUpdateService;
|
|
|
import com.ruoyi.ams.business.BusinessServiceImpl;
|
|
|
import com.ruoyi.ams.business.IBusinessService;
|
|
|
+import com.ruoyi.ams.task.domain.WcsTask;
|
|
|
+import com.ruoyi.ams.task.mapper.WcsTaskMapper;
|
|
|
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.utils.uuid.SnowflakeIdWorker;
|
|
|
import com.ruoyi.hard.modbus.tcp.AutoDoorClient;
|
|
|
+import com.ruoyi.system.enums.CnveyorBeltsPlcEnum;
|
|
|
+import com.ruoyi.system.init.PlcConnectServiceRunner;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
+import static com.ruoyi.ams.agv.ndc.service.impl.StatusUpdateServiceImpl.AGV_ACTION.UNLOAD;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
@@ -30,6 +42,18 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
@Autowired
|
|
|
private AutoDoorClient autoDoorClient;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WcsTaskMapper wcsTaskMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PlcConnectServiceRunner plcConnectServiceRunner;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IBaseLocationInfoService iBaseLocationInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
+
|
|
|
public enum AGV_ACTION {
|
|
|
/***
|
|
|
* 取货
|
|
@@ -52,7 +76,7 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void updateStatus(Long id, Integer carNo) {
|
|
|
+ public void updateStatus(Long id, Integer carNo) throws InterruptedException {
|
|
|
AmsTask amsTask = amsTaskService.selectAmsTaskById(id);
|
|
|
if (amsTask != null) {
|
|
|
log.info("任务回调-------------------------》" + amsTask.getTaskNo());
|
|
@@ -69,18 +93,36 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
// } else if (null != amsTask.getSystemStatus() && amsTask.getSystemStatus() == 4) {
|
|
|
// result.setState(7);
|
|
|
} else {
|
|
|
+ WcsTask wcsTask = wcsTaskMapper.selectWcsTaskByTaskNo(amsTask.getTaskNo());
|
|
|
switch (amsTask.getEvent().intValue()) {
|
|
|
case 86:
|
|
|
result.setState(1);
|
|
|
break;
|
|
|
case 90:
|
|
|
+
|
|
|
result.setState(2);
|
|
|
break;
|
|
|
case 91:
|
|
|
result.setState(4);
|
|
|
+ threadPoolTaskExecutor.execute(()->{
|
|
|
+ try {
|
|
|
+ endOfMissionSecurity(wcsTask);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("The security judgment execution is abnormal,msg:{}",e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
break;
|
|
|
case 92:
|
|
|
result.setState(6);
|
|
|
+ threadPoolTaskExecutor.execute(()->{
|
|
|
+ try {
|
|
|
+ endOfMissionSecurity(wcsTask);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("The security judgment execution is abnormal,msg:{}",e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
break;
|
|
|
case 85:
|
|
|
result.setState(7);
|
|
@@ -101,11 +143,35 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void endOfMissionSecurity(WcsTask wcsTask) throws InterruptedException {
|
|
|
+ S7PLC conveyorBeltsPlc = plcConnectServiceRunner.getPlcServer("conveyorBeltsPlc");
|
|
|
+ byte command = 24;
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ Thread.sleep(3000);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.TO_COMMAND_4.getMetadata(),initial);
|
|
|
+ conveyorBeltsPlc.writeByte(CnveyorBeltsPlcEnum.ACK_4.getMetadata(),initial);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public synchronized void confirmAnalysis(String taskNo, Integer aciIndex, String type, Integer carNo) {
|
|
|
AmsTask amsTask = new AmsTask();
|
|
|
amsTask.setTaskNo(taskNo);
|
|
|
amsTask = amsTaskService.selectAmsTaskByModel(amsTask);
|
|
|
+ //添加取货卸货前安全握
|
|
|
+ if (AGVUnloadOrPickUpSafetyJudgment(taskNo,type)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (amsTask != null) {
|
|
|
AmsTask addTaskForm = new AmsTask();
|
|
|
addTaskForm.setTaskNo(System.currentTimeMillis() + "");
|
|
@@ -234,4 +300,41 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
|
|
|
feedbackTS(doorNo);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public boolean AGVUnloadOrPickUpSafetyJudgment(String taskNo,String type) {
|
|
|
+ WcsTask wcsTask = wcsTaskMapper.selectWcsTaskByTaskNo(taskNo);
|
|
|
+ if (ObjectUtil.isNull(wcsTask)){
|
|
|
+ throw new ServiceException("The AGV feedback task does not exist,Security judgment cannot be made!!!");
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
}
|