#
luxiaotao1123
2024-12-17 d2aa9473613af8cd99c3a6dea0331765ecb830dc
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("解锁路径函数花费时间为:{}毫秒......", System.currentTimeMillis() - startTime);
        } catch (Exception e) {
            log.error("TrafficService.unlockPath", e);
            log.error("MapService.unlockPath", e);
        }
    }