From d2aa9473613af8cd99c3a6dea0331765ecb830dc Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期二, 17 十二月 2024 13:57:20 +0800 Subject: [PATCH] # --- zy-acs-fake/src/main/java/com/zy/acs/fake/service/MapService.java | 78 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 77 insertions(+), 1 deletions(-) diff --git a/zy-acs-fake/src/main/java/com/zy/acs/fake/service/MapService.java b/zy-acs-fake/src/main/java/com/zy/acs/fake/service/MapService.java index 1578c7a..6228265 100644 --- a/zy-acs-fake/src/main/java/com/zy/acs/fake/service/MapService.java +++ b/zy-acs-fake/src/main/java/com/zy/acs/fake/service/MapService.java @@ -1,11 +1,21 @@ package com.zy.acs.fake.service; +import com.zy.acs.fake.config.RedisProperties; import com.zy.acs.fake.domain.DynamicNode; import com.zy.acs.framework.common.Cools; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; import org.springframework.stereotype.Component; +import org.springframework.util.StopWatch; +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; @@ -18,9 +28,73 @@ @Autowired private MapDataDispatcher mapDataDispatcher; + @Autowired + private RedisProperties redisProperties; + + public synchronized void unlockPath0(String agvNo, String codeData) { + try { + + Resource resource = new ClassPathResource("unlock.py"); + File tempScript = null; + + InputStream is = resource.getInputStream(); + tempScript = File.createTempFile("unlock", ".py"); + tempScript.deleteOnExit(); + + Files.copy(is, tempScript.toPath(), StandardCopyOption.REPLACE_EXISTING); + tempScript.setExecutable(true); + + ProcessBuilder processBuilder = new ProcessBuilder( + "python" + , tempScript.getAbsolutePath() + , redisProperties.getHost() + , redisProperties.getPassword() + , String.valueOf(redisProperties.getPort()) + , String.valueOf(redisProperties.getIndex()) + , agvNo + , codeData + ); + + processBuilder.redirectErrorStream(true); + + Process process = processBuilder.start(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + StringBuilder builder = new StringBuilder(); + while ((line = reader.readLine()) != null) { + builder.append(line); + } + + int exitCode = process.waitFor(); + if (exitCode != 0) { + log.error("Python script exited with error code: {}", exitCode); + log.error("python error:{}", builder.toString()); + return; + } + reader.close(); + + if (builder.length() <= 0) { + return; + } + + String result = builder.toString(); + + if (!Cools.isEmpty(result)) { + if (!"1".equals(result)) { + log.error("Fail python"); + } + } + + + } catch (Exception e) { + log.error("MapService.unlockPath", e); + } + } public synchronized void unlockPath(String agvNo, String codeData) { try { + long startTime = System.currentTimeMillis(); if (Cools.isEmpty(agvNo, codeData)) { return; @@ -55,8 +129,10 @@ mapDataDispatcher.clearDynamicMatrixByCodeList(lev, resetCodeList); } + log.info("瑙i攣璺緞鍑芥暟鑺辫垂鏃堕棿涓猴細{}姣......", System.currentTimeMillis() - startTime); + } catch (Exception e) { - log.error("TrafficService.unlockPath", e); + log.error("MapService.unlockPath", e); } } -- Gitblit v1.9.1