root 2 anni fa
parent
commit
7810349b13

+ 29 - 0
api-common/src/main/java/api/common/util/FileUtil.java

@@ -16,6 +16,35 @@ import java.nio.file.Paths;
 import java.util.*;
 
 public class FileUtil {
+
+    /**
+     * 拷贝文件。
+     */
+    @SneakyThrows
+    public static void cp(String sourceFile, String targetFile) {
+        createParentDirectory(targetFile);
+        FileInputStream fileInputStream = new FileInputStream(sourceFile);
+        FileOutputStream fileOutputStream = new FileOutputStream(targetFile);
+        FileChannel readChannel = fileInputStream.getChannel();
+        FileChannel writeChannel = fileOutputStream.getChannel();
+        //自动生成与文件大小相同但不超过 8096 的缓存,即缓存最大为 8096。
+        writeChannel.transferFrom(readChannel, 0, readChannel.size());
+        writeChannel.close();
+        readChannel.close();
+        fileOutputStream.close();
+        fileInputStream.close();
+    }
+
+    @SneakyThrows
+    public static void cpR(String sourceDirectoryPath, String targetDirectoryPath) {
+        File[] files = new File(sourceDirectoryPath).listFiles();
+        for (File file : files) {
+            String sourceFilePath = file.getAbsolutePath();
+            String targetFilePath = sourceFilePath.replace(sourceDirectoryPath, targetDirectoryPath);
+            cp(sourceFilePath, targetFilePath);
+        }
+    }
+
     /**
      * 获得绝对路径
      *

+ 16 - 7
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/manager/TaskManager.java

@@ -4,10 +4,7 @@ import api.common.pojo.constants.DictConstants;
 import api.common.pojo.dto.ProjectMessageDTO;
 import api.common.util.*;
 import com.css.simulation.resource.scheduler.feign.VideoService;
-import com.css.simulation.resource.scheduler.mapper.AutoSubProjectMapper;
-import com.css.simulation.resource.scheduler.mapper.IndexMapper;
-import com.css.simulation.resource.scheduler.mapper.ManualProjectMapper;
-import com.css.simulation.resource.scheduler.mapper.TaskMapper;
+import com.css.simulation.resource.scheduler.mapper.*;
 import com.css.simulation.resource.scheduler.pojo.po.IndexTemplatePO;
 import com.css.simulation.resource.scheduler.pojo.po.LeafIndexPO;
 import com.css.simulation.resource.scheduler.pojo.po.ProjectPO;
@@ -83,6 +80,8 @@ public class TaskManager {
     @Resource
     IndexMapper indexMapper;
     @Resource
+    ScoringRulesMapper scoringRulesMapper;
+    @Resource
     CloseableHttpClient closeableHttpClient;
     @Resource
     RequestConfig requestConfig;
@@ -172,6 +171,13 @@ public class TaskManager {
         stringRedisTemplate.delete(projectRunningKey);
     }
 
+    /**
+     * @param redisPrefix
+     * @param userId      项目创建用户的 id
+     * @param projectId
+     * @param projectType
+     * @param session
+     */
     @SneakyThrows
     public void score(PrefixTO redisPrefix, String userId, String projectId, String projectType, ClientSession session) {
         // -------------------------------- 打分 --------------------------------
@@ -201,7 +207,7 @@ public class TaskManager {
         for (int i = 0; i < leafIndexTemplateList.size(); i++) {
             AtomicReference<String> scoreExplain = new AtomicReference<>(); // 每个叶子指标下的任务的得分说明一样和叶子指标一致
             IndexTemplatePO leafIndexTemplate = leafIndexTemplateList.get(i);
-            String indexId = leafIndexTemplate.getIndexId();
+            String indexId = leafIndexTemplate.getIndexId(); // 叶子指标id
             String parentId = leafIndexTemplate.getParentId(); // 父 id
             String rootId = leafIndexTemplate.getRootId(); // 包 id
             String weight = leafIndexTemplate.getWeight(); // 权重
@@ -212,12 +218,15 @@ public class TaskManager {
                 maxLevel = packageLevel;
             }
             log.info("TaskService--state 开始执行对第 " + (i + 1) + " 个叶子节点 " + indexId + " 进行打分!");
+            // 根据叶子指标id查询评分规则创建用户id
+            String createUserIdOfRule = scoringRulesMapper.selectCreateUserIdByIndexId(indexId);
             //1 判断有没有用户目录,没有则复制
-            String scoreDirectoryOfUser = linuxTempPath + "score/" + userId + "/";
+            String scoreDirectoryOfUser = linuxTempPath + "score/" + createUserIdOfRule + "/";
             if (!new File(scoreDirectoryOfUser + "main.py").exists()) {
                 // 复制 main.py
                 FileUtil.createDirectory(scoreDirectoryOfUser);
-                LinuxUtil.execute("cp -r " + pyPath + "* " + scoreDirectoryOfUser);
+                FileUtil.cpR(pyPath, scoreDirectoryOfUser);
+//                LinuxUtil.execute("cp -r " + pyPath + "* " + scoreDirectoryOfUser);
             }
             //2 将打分规则保存到script目录
 

+ 23 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/ScoringRulesMapper.java

@@ -0,0 +1,23 @@
+package com.css.simulation.resource.scheduler.mapper;
+
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+/**
+ * 场景查询
+ * scene_natural
+ * scene_standard
+ * scene_accident
+ */
+@Mapper
+public interface ScoringRulesMapper {
+
+    @Select("select create_user_id  \n" +
+            "from scoring_rules sr \n" +
+            "where sr.rules_id = (select package_and_rules from scene_package_sublist sps where sps.sublist_id = #{indexId})")
+    String selectCreateUserIdByIndexId(@Param("indexId") String indexId);
+
+
+}