| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.core.enums.CrnStatusType; |
| | | import com.zy.core.enums.CrnTaskModeType; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.command.CrnCommand; |
| | | import com.zy.core.network.api.ZyCrnConnectApi; |
| | | import com.zy.core.network.entity.ZyCrnStatusEntity; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | |
| | | public class ZyCrnFakeConnect implements ZyCrnConnectApi { |
| | | |
| | | private ZyCrnStatusEntity crnStatus; |
| | | private DeviceConfig deviceConfig; |
| | | private final ExecutorService executor = Executors.newSingleThreadExecutor(); |
| | | |
| | | public ZyCrnFakeConnect(DeviceConfig deviceConfig) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | @Override |
| | | public CommandResponse sendCommand(CrnCommand command) { |
| | | CommandResponse response = new CommandResponse(false); |
| | | if (command.getTaskMode().intValue() == CrnTaskModeType.LOC_MOVE.id) { |
| | | //取放货 |
| | | executor.submit(() -> commandTake(command)); |
| | | } else if (command.getTaskMode().intValue() == CrnTaskModeType.CRN_MOVE.id) { |
| | | //移动 |
| | | executor.submit(() -> commandMove(command)); |
| | | } else if (command.getTaskMode().intValue() == CrnTaskModeType.NONE.id) { |
| | | //复位 |
| | | executor.submit(() -> commandTaskComplete(command)); |
| | | } |
| | | response.setResult(true); |
| | | return response; |
| | | } |
| | | |
| | | private void commandTaskComplete(CrnCommand command) { |
| | | this.crnStatus.setTaskNo(0); |
| | | this.crnStatus.setStatus(CrnStatusType.IDLE.id); |
| | | } |
| | | |
| | | private void commandMove(CrnCommand command) { |
| | | int destinationPosX = command.getDestinationPosX().intValue(); |
| | | int destinationPosY = command.getDestinationPosY().intValue(); |
| | | int destinationPosZ = command.getDestinationPosZ().intValue(); |
| | | int taskMode = command.getTaskMode().intValue(); |
| | | int taskNo = command.getTaskNo().intValue(); |
| | | |
| | | this.crnStatus.setTaskNo(taskNo); |
| | | this.crnStatus.setStatus(CrnStatusType.MOVING.id); |
| | | moveY(this.crnStatus.getBay(), destinationPosY); |
| | | moveZ(this.crnStatus.getLevel(), destinationPosZ); |
| | | this.crnStatus.setStatus(CrnStatusType.WAITING.id); |
| | | } |
| | | |
| | | private void commandTake(CrnCommand command) { |
| | | int sourcePosX = command.getSourcePosX().intValue(); |
| | | int sourcePosY = command.getSourcePosY().intValue(); |
| | | int sourcePosZ = command.getSourcePosZ().intValue(); |
| | | int destinationPosX = command.getDestinationPosX().intValue(); |
| | | int destinationPosY = command.getDestinationPosY().intValue(); |
| | | int destinationPosZ = command.getDestinationPosZ().intValue(); |
| | | int taskMode = command.getTaskMode().intValue(); |
| | | int taskNo = command.getTaskNo().intValue(); |
| | | |
| | | this.crnStatus.setTaskNo(taskNo); |
| | | this.crnStatus.setStatus(CrnStatusType.FETCH_MOVING.id); |
| | | moveY(this.crnStatus.getBay(), sourcePosY); |
| | | moveZ(this.crnStatus.getLevel(), sourcePosZ); |
| | | this.crnStatus.setStatus(CrnStatusType.FETCHING.id); |
| | | try { |
| | | Thread.sleep(2000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | this.crnStatus.setLoaded(1); |
| | | this.crnStatus.setStatus(CrnStatusType.PUT_MOVING.id); |
| | | moveY(this.crnStatus.getBay(), destinationPosY); |
| | | moveZ(this.crnStatus.getLevel(), destinationPosZ); |
| | | this.crnStatus.setStatus(CrnStatusType.PUTTING.id); |
| | | try { |
| | | Thread.sleep(2000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | this.crnStatus.setLoaded(0); |
| | | this.crnStatus.setStatus(CrnStatusType.WAITING.id); |
| | | } |
| | | |
| | | private void moveZ(int sourcePosZ, int destinationPosZ) { |
| | | if(destinationPosZ - sourcePosZ > 0) { |
| | | int moveLength = destinationPosZ - sourcePosZ; |
| | | int initSourcePosZ = sourcePosZ; |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosZ++; |
| | | this.crnStatus.setLevel(initSourcePosZ); |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }else { |
| | | int moveLength = sourcePosZ - destinationPosZ; |
| | | int initSourcePosZ = sourcePosZ; |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosZ--; |
| | | this.crnStatus.setLevel(initSourcePosZ); |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void moveY(int sourcePosY, int destinationPosY) { |
| | | if(destinationPosY - sourcePosY > 0) { |
| | | int moveLength = destinationPosY - sourcePosY; |
| | | int initSourcePosY = sourcePosY; |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosY++; |
| | | this.crnStatus.setBay(initSourcePosY); |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }else { |
| | | int moveLength = sourcePosY - destinationPosY; |
| | | int initSourcePosY = sourcePosY; |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosY--; |
| | | this.crnStatus.setBay(initSourcePosY); |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |