| | |
| | | import com.zy.core.network.api.ZyStationConnectApi; |
| | | import com.zy.core.network.entity.ZyStationStatusEntity; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | |
| | | status.setOutEnable(true);// 模拟可出 |
| | | status.setEmptyMk(false);// 模拟空板信号 |
| | | status.setFullPlt(false);// 模拟满托盘 |
| | | status.setRunBlock(false);// 运行无堵塞 |
| | | status.setPalletHeight(0);// 模拟托盘高度为0 |
| | | status.setError(0);// 模拟无报警 |
| | | status.setBarcode("");// 模拟无条码 |
| | |
| | | return; |
| | | } |
| | | |
| | | stationMove(navigateNodes, taskNo, stationId, true, generateBarcode); |
| | | stationMove(targetNavigateNodes, taskNo, targetStationId, false, generateBarcode); |
| | | boolean result = stationMove(navigateNodes, taskNo, stationId, true, generateBarcode); |
| | | if(result) { |
| | | stationMove(targetNavigateNodes, taskNo, targetStationId, false, generateBarcode); |
| | | } |
| | | } |
| | | |
| | | private void stationMove(List<NavigateNode> navigateNodes, Integer taskNo, Integer targetStationId, boolean clearData, boolean generateBarcode) { |
| | | private boolean stationMove(List<NavigateNode> navigateNodes, Integer taskNo, Integer targetStationId, boolean clearData, boolean generateBarcode) { |
| | | Integer lastStationId = null; |
| | | |
| | | long executeTime = System.currentTimeMillis(); |
| | | int i = 0; |
| | | while (i < navigateNodes.size()) { |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return false; |
| | | } |
| | | NavigateNode navigateNode = navigateNodes.get(i); |
| | | JSONObject valueObject = JSON.parseObject(navigateNode.getNodeValue()); |
| | | Integer currentStationId = valueObject.getInteger("stationId"); |
| | |
| | | |
| | | } |
| | | |
| | | if (nextStationId != null) { |
| | | if (!checkTaskNoInArea(taskNo)) { |
| | | boolean fakeAllowCheckBlock = true; |
| | | Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key); |
| | | if (systemConfigMapObj != null) { |
| | | HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj; |
| | | if (!systemConfigMap.get("fakeAllowCheckBlock").equals("Y")) { |
| | | fakeAllowCheckBlock = false; |
| | | } |
| | | } |
| | | |
| | | if (fakeAllowCheckBlock && System.currentTimeMillis() - executeTime > 1000 * 10) { |
| | | //认定堵塞 |
| | | boolean result = runBlockStation(taskNo, currentStationId, taskNo, currentStationId); |
| | | if(!result) { |
| | | continue; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | if (i == 0) { |
| | |
| | | continue; |
| | | } |
| | | sleep(1000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | if(nextStationId != null) { |
| | |
| | | } |
| | | |
| | | i++; |
| | | executeTime = System.currentTimeMillis(); |
| | | sleep(1000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | if (generateBarcode) { |
| | | if (lastStationId != null) { |
| | | while (true) { |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | break; |
| | | } |
| | | boolean result = generateStationBarcode(taskNo, targetStationId); |
| | | sleep(1000); |
| | | if (!result) { |
| | |
| | | |
| | | if (clearData) { |
| | | sleep(10000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return true; |
| | | } |
| | | if (lastStationId != null) { |
| | | while (true) { |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | break; |
| | | } |
| | | boolean result = clearStation(taskNo, targetStationId); |
| | | sleep(1000); |
| | | if (!result) { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private void sleep(long ms) { |
| | | try { |
| | | Thread.sleep(ms); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | Thread.currentThread().interrupt(); |
| | | } |
| | | } |
| | | |
| | |
| | | return true; |
| | | } |
| | | |
| | | public synchronized boolean updateStationData(Integer lockTaskNo, Integer stationId, Integer taskNo, Integer targetStaNo, Boolean isLoading, String barcode) { |
| | | public synchronized boolean updateStationData(Integer lockTaskNo, Integer stationId, Integer taskNo, Integer targetStaNo, Boolean isLoading, String barcode, Boolean runBlock) { |
| | | if (LOCK_STATION != lockTaskNo) { |
| | | return false; |
| | | } |
| | |
| | | if (barcode != null) { |
| | | currentStatus.setBarcode(barcode); |
| | | } |
| | | |
| | | if(runBlock != null) { |
| | | currentStatus.setRunBlock(runBlock); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | if(currentStatus.getTaskNo().equals(taskNo)) { |
| | | return true; |
| | | if (currentStatus.getTaskNo() > 0) { |
| | | if (!currentStatus.getTaskNo().equals(taskNo) && currentStatus.isLoading()) { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | if (currentStatus.getTaskNo() > 0 || currentStatus.isLoading()) { |
| | | return false; |
| | | } |
| | | |
| | | boolean result = updateStationData(taskNo, currentStationId, taskNo, targetStationId, isLoading, barcode); |
| | | boolean result = updateStationData(taskNo, currentStationId, taskNo, targetStationId, isLoading, barcode, false); |
| | | if (!result) { |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | boolean result = updateStationData(lockTaskNo, nextStationId, taskNo, targetStaNo, true, null); |
| | | boolean result = updateStationData(lockTaskNo, nextStationId, taskNo, targetStaNo, true, null, false); |
| | | if (!result) { |
| | | return false; |
| | | } |
| | | |
| | | boolean result2 = updateStationData(lockTaskNo, currentStationId, 0, 0, false, null); |
| | | boolean result2 = updateStationData(lockTaskNo, currentStationId, 0, 0, false, "", false); |
| | | if (!result2) { |
| | | return false; |
| | | } |
| | |
| | | String barcodeTime = String.valueOf(System.currentTimeMillis()); |
| | | String barcode = barcodeTime.substring(5); |
| | | |
| | | boolean result = updateStationData(lockTaskNo, currentStationId, null, null, null, barcode); |
| | | boolean result = updateStationData(lockTaskNo, currentStationId, null, null, null, barcode, null); |
| | | if (!result) { |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | boolean result = updateStationData(lockTaskNo, currentStationId, 0, 0, false, ""); |
| | | boolean result = updateStationData(lockTaskNo, currentStationId, 0, 0, false, "", false); |
| | | if (!result) { |
| | | return false; |
| | | } |
| | | return true; |
| | | }); |
| | | |
| | | return executeResult; |
| | | } |
| | | |
| | | public synchronized boolean runBlockStation(Integer lockTaskNo, Integer currentStationId, Integer taskNo, Integer blockStationId) { |
| | | boolean executeResult = lockExecute(lockTaskNo, () -> { |
| | | ZyStationStatusEntity currentStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null); |
| | | |
| | | if (currentStatus == null) { |
| | | return false; |
| | | } |
| | | |
| | | boolean result = updateStationData(lockTaskNo, currentStationId, taskNo, blockStationId, true, "", true); |
| | | if (!result) { |
| | | return false; |
| | | } |