martin 3 年之前
父节点
当前提交
aa22906b1e
共有 25 个文件被更改,包括 358 次插入100 次删除
  1. 5 2
      simulation-resource-common/src/main/java/com/css/simulation/resource/common/controller/MinioController.java
  2. 14 0
      simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/MinioUtil.java
  3. 0 2
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/SimulationResourceSchedulerApplication.java
  4. 18 17
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/consumer/ManualProjectConsumer.java
  5. 21 0
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/feign/fallback/CommonServiceFallback.java
  6. 29 0
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/manager/TaskIndexManager.java
  7. 29 0
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/manager/TaskManager.java
  8. 13 6
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/IndexTemplateMapper.java
  9. 2 2
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/SceneMapper.java
  10. 59 0
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/TaskIndexMapper.java
  11. 9 4
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/TaskMapper.java
  12. 0 18
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/dto/VehicleDTO.java
  13. 5 3
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/po/IndexTemplatePO.java
  14. 18 0
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/po/TaskIndexPO.java
  15. 3 0
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/po/TaskPO.java
  16. 2 2
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/DynamicsTO.java
  17. 2 2
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/InfoTO.java
  18. 2 2
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/ModelTO.java
  19. 2 2
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/ScenarioTO.java
  20. 17 0
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/ScoreTO.java
  21. 2 2
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/SensorsTO.java
  22. 5 5
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/TaskTO.java
  23. 18 0
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/VehicleTO.java
  24. 79 29
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/TaskService.java
  25. 4 2
      simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/util/ScoreUtil.java

+ 5 - 2
simulation-resource-common/src/main/java/com/css/simulation/resource/common/controller/MinioController.java

@@ -6,6 +6,7 @@ import api.common.util.FileUtil;
 import com.css.simulation.resource.common.util.MinioUtil;
 import io.minio.MinioClient;
 import io.minio.errors.*;
+import io.minio.http.Method;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.MediaType;
 import org.springframework.validation.annotation.Validated;
@@ -35,7 +36,7 @@ public class MinioController {
         return "hello minio!";
     }
 
-    @PostMapping(value="/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
     public ResponseBodyVO<String> upload(
             @RequestPart("file") MultipartFile file,
             @RequestParam("objectName") String objectName//  "/xx/xxx/x/xx"
@@ -46,7 +47,9 @@ public class MinioController {
                 bucketName,
                 objectName
         );
-        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
+        String previewUrl = MinioUtil.getPreviewUrl(minioClient, Method.GET, bucketName, objectName);
+
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, previewUrl);
     }
 
 //    @PostMapping("/download")

+ 14 - 0
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/MinioUtil.java

@@ -5,6 +5,7 @@ import io.minio.errors.ErrorResponseException;
 import io.minio.errors.InsufficientDataException;
 import io.minio.errors.InvalidResponseException;
 import io.minio.errors.XmlParserException;
+import io.minio.http.Method;
 import jdk.nashorn.internal.runtime.regexp.joni.exception.InternalException;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -32,6 +33,19 @@ public class MinioUtil {
         }
     }
 
+    /**
+     * 获取预览路径
+     *
+     * @return 预览路径
+     */
+    public static String getPreviewUrl(MinioClient minioClient, Method method, String bucket, String object) throws io.minio.errors.ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, io.minio.errors.InternalException {
+        return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
+                .method(method)
+                .bucket(bucket)
+                .object(object)
+                .build());
+    }
+
     /**
      * 通过文件路径上传文件上传文件
      */

+ 0 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/SimulationResourceSchedulerApplication.java

@@ -4,13 +4,11 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.openfeign.EnableFeignClients;
-import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
 
 
 @SpringBootApplication
 @EnableFeignClients
 @EnableDiscoveryClient
-@EnableResourceServer
 public class SimulationResourceSchedulerApplication {
 
     public static void main(String[] args) {

+ 18 - 17
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/consumer/ManualProjectConsumer.java

@@ -6,12 +6,13 @@ import api.common.pojo.dto.ProjectMessageDTO;
 import api.common.pojo.param.KafkaParameter;
 import api.common.pojo.param.MinioParameter;
 import api.common.pojo.param.RedisParameter;
-import api.common.util.*;
+import api.common.util.JsonUtil;
+import api.common.util.StringUtil;
+import api.common.util.TimeUtil;
 import com.css.simulation.resource.scheduler.feign.CommonService;
 import com.css.simulation.resource.scheduler.mapper.*;
-import com.css.simulation.resource.scheduler.pojo.dto.*;
+import com.css.simulation.resource.scheduler.pojo.to.*;
 import com.css.simulation.resource.scheduler.pojo.po.*;
-import com.github.dockerjava.api.DockerClient;
 import feign.Response;
 import io.kubernetes.client.openapi.ApiClient;
 import io.kubernetes.client.openapi.ApiException;
@@ -41,7 +42,7 @@ public class ManualProjectConsumer {
     @Autowired
     TaskMapper taskMapper;
     @Autowired
-    IndexMapper indexMapper;
+    IndexTemplateMapper indexTemplateMapper;
     @Autowired
     SceneMapper sceneMapper;
     @Autowired
@@ -81,14 +82,14 @@ public class ManualProjectConsumer {
         // -------------------------------- 1 场景 --------------------------------
         // 根据 packageId,拿到场景 id,然后获取每个场景的文件地址。
         String packageId = projectMessageDTO.getScenePackageId();
-        List<IndexPO> leafIndexList = indexMapper.selectLeafIndexByPackageId(packageId);
+        List<IndexTemplatePO> leafIndexList = indexTemplateMapper.selectLeafIndexByPackageId(packageId);
         List<String> naturalIdList = new ArrayList<>();
         List<String> standardIdList = new ArrayList<>();
         List<String> accidentIdList = new ArrayList<>();
-        for (IndexPO indexPO : leafIndexList) {
-            String naturalIds = indexPO.getSceneNaturalIds();
-            String standardIds = indexPO.getSceneStatueIds();
-            String accidentIds = indexPO.getSceneTrafficIds();
+        for (IndexTemplatePO indexTemplatePO : leafIndexList) {
+            String naturalIds = indexTemplatePO.getSceneNaturalIds();
+            String standardIds = indexTemplatePO.getSceneStatueIds();
+            String accidentIds = indexTemplatePO.getSceneTrafficIds();
             if (StringUtil.isNotEmpty(naturalIds)) {
                 String[] naturalIdArray = naturalIds.split(",");
                 naturalIdList.addAll(Arrays.asList(naturalIdArray));
@@ -141,23 +142,23 @@ public class ManualProjectConsumer {
             // 心跳信息存在緩存中
             commonService.set(new RedisParameter(manualProjectTopic + ":" + projectId + ":" + taskId, TimeUtil.getNow() + "", 0));
             // 组装 task 消息
-            TaskDTO taskDTO = TaskDTO.builder()
-                    .info(InfoDTO.builder()
+            TaskTO taskTO = TaskTO.builder()
+                    .info(InfoTO.builder()
                             .project_id(projectId)
                             .task_id(taskId)
                             .task_path(resultPath)
                             .default_time(maxSimulationTime)
                             .build())
-                    .scenario(ScenarioDTO.builder()
+                    .scenario(ScenarioTO.builder()
                             .scenario_osc(scenePO.getScenarioOsc())
                             .scenario_odr(scenePO.getScenarioOdr())
                             .scenario_osgb(scenePO.getScenarioOsgb())
                             .build())
-                    .vehicle(VehicleDTO.builder()
-                            .model(ModelDTO.builder()
+                    .vehicle(VehicleTO.builder()
+                            .model(ModelTO.builder()
                                     .model_label(vehiclePO.getModelLabel())
                                     .build())
-                            .dynamics(DynamicsDTO.builder()
+                            .dynamics(DynamicsTO.builder()
                                     .dynamics_maxspeed(vehiclePO.getMaxSpeed())
                                     .dynamics_enginepower(vehiclePO.getEnginePower())
                                     .dynamics_maxdecel(vehiclePO.getMaxDeceleration())
@@ -176,14 +177,14 @@ public class ManualProjectConsumer {
                                     .dynamics_distheight(vehiclePO.getHeightDistance())
                                     .dynamics_wheelbase(vehiclePO.getWheelbase())
                                     .build())
-                            .sensors(SensorsDTO.builder()   // 根据 vehicleId 查询绑定的传感器列表
+                            .sensors(SensorsTO.builder()   // 根据 vehicleId 查询绑定的传感器列表
                                     .camera(cameraPOList)
                                     .OGT(ogtPOList)
                                     .build())
                             .build())
                     .build();
             //4-4 将对象转成 json
-            String taskJson = JsonUtil.beanToJson(taskDTO);
+            String taskJson = JsonUtil.beanToJson(taskTO);
             //4-5 将 projectId 作为 topic 名称,发送 task 信息到 kafka
             commonService.send(new KafkaParameter(projectId, taskJson));
         }

+ 21 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/feign/fallback/CommonServiceFallback.java

@@ -3,6 +3,7 @@ package com.css.simulation.resource.scheduler.feign.fallback;
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.param.KafkaParameter;
 import api.common.pojo.param.MinioParameter;
+import api.common.pojo.param.RedisParameter;
 import com.css.simulation.resource.scheduler.feign.CommonService;
 import feign.Response;
 import lombok.extern.slf4j.Slf4j;
@@ -34,4 +35,24 @@ public class CommonServiceFallback implements CommonService {
     public ResponseBodyVO<String> send(KafkaParameter kafkaParameter) {
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE);
     }
+
+    @Override
+    public ResponseBodyVO<String> get(RedisParameter redisParameter) {
+        return null;
+    }
+
+    @Override
+    public ResponseBodyVO<String> set(RedisParameter redisParameter) {
+        return null;
+    }
+
+    @Override
+    public ResponseBodyVO<Long> getExpire(RedisParameter redisParameter) {
+        return null;
+    }
+
+    @Override
+    public ResponseBodyVO<String> delete(RedisParameter redisParameter) {
+        return null;
+    }
 }

+ 29 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/manager/TaskIndexManager.java

@@ -0,0 +1,29 @@
+package com.css.simulation.resource.scheduler.manager;
+
+import com.css.simulation.resource.scheduler.mapper.TaskIndexMapper;
+import com.css.simulation.resource.scheduler.pojo.po.TaskIndexPO;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class TaskIndexManager {
+
+    @Autowired
+    private SqlSessionFactory sqlSessionFactory;
+
+    public void batchInsertLeafIndex(List<TaskIndexPO> leafTaskIndexList) {
+
+        try(SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false)){
+            TaskIndexMapper taskIndexMapper = sqlSession.getMapper(TaskIndexMapper.class);
+            for (TaskIndexPO taskIndexPO : leafTaskIndexList) {
+                taskIndexMapper.insertLeafIndex(taskIndexPO);
+            }
+            sqlSession.commit();
+        }
+    }
+}

+ 29 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/manager/TaskManager.java

@@ -0,0 +1,29 @@
+package com.css.simulation.resource.scheduler.manager;
+
+import com.css.simulation.resource.scheduler.mapper.TaskMapper;
+import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class TaskManager {
+
+    @Autowired
+    private SqlSessionFactory sqlSessionFactory;
+
+    public void batchUpdateByScoreResult(List<TaskPO> taskList) {
+
+        try(SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false)){
+            TaskMapper taskMapper = sqlSession.getMapper(TaskMapper.class);
+            for (TaskPO taskPO : taskList) {
+                taskMapper.updateByScoreResult(taskPO);
+            }
+            sqlSession.commit();
+        }
+    }
+}

+ 13 - 6
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/IndexMapper.java → simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/IndexTemplateMapper.java

@@ -1,18 +1,19 @@
 package com.css.simulation.resource.scheduler.mapper;
 
 
-import com.css.simulation.resource.scheduler.pojo.po.IndexPO;
+import com.css.simulation.resource.scheduler.pojo.po.IndexTemplatePO;
+import com.css.simulation.resource.scheduler.pojo.po.TaskIndexPO;
 import org.apache.ibatis.annotations.*;
 import org.apache.ibatis.type.JdbcType;
 
 import java.util.List;
 
 /**
- * 指标查询
+ * 指标模板
  * simulation_package_sublist
  */
 @Mapper
-public interface IndexMapper {
+public interface IndexTemplateMapper {
 
 
     @Results(id = "index", value = {
@@ -31,7 +32,7 @@ public interface IndexMapper {
             "where is_deleted = '0'\n" +
             "  and root_id = #{packageId}\n" +
             "  and package_and_rules is not null and package_and_rules != ''")
-    List<IndexPO> selectLeafIndexByPackageId(@Param("packageId") String packageId);
+    List<IndexTemplatePO> selectLeafIndexByPackageId(@Param("packageId") String packageId);
 
     @ResultMap("index")
     @Select("select sps.scene_natural_ids,\n" +
@@ -45,7 +46,7 @@ public interface IndexMapper {
             "where root_id = '#{packageId}'\n" +
             "  and package_and_rules is not null\n" +
             "  and package_and_rules != ''")
-    List<IndexPO> selectLeafIndexWithRuleDetailsByPackageId(@Param("packageId") String packageId);
+    List<IndexTemplatePO> selectLeafIndexWithRuleDetailsByPackageId(@Param("packageId") String packageId);
 
 
     @ResultMap("index")
@@ -64,6 +65,12 @@ public interface IndexMapper {
             "       </foreach>\n" +
             "</if>\n" +
             "")
-    List<IndexPO> selectByIdList(@Param("idList") List<String> idList);
+    List<IndexTemplatePO> selectByIdList(@Param("idList") List<String> idList);
 
+
+    @Insert("insert into ")
+    void insertLeafIndex(IndexTemplatePO indexTemplatePO);
+
+    
+    void insertTotalScore(TaskIndexPO totalTaskIndex);
 }

+ 2 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/SceneMapper.java

@@ -1,7 +1,7 @@
 package com.css.simulation.resource.scheduler.mapper;
 
 
-import com.css.simulation.resource.scheduler.pojo.po.IndexPO;
+import com.css.simulation.resource.scheduler.pojo.po.IndexTemplatePO;
 import com.css.simulation.resource.scheduler.pojo.po.ScenePO;
 import org.apache.ibatis.annotations.*;
 import org.apache.ibatis.type.JdbcType;
@@ -32,7 +32,7 @@ public interface SceneMapper {
             "  and ((scene_natural_ids is not null and scene_natural_ids != '')\n" +
             "    or (scene_traffic_ids is not null and scene_traffic_ids != '')\n" +
             "    or (scene_statue_ids is not null and scene_statue_ids != ''))")
-    List<IndexPO> selectLeafIndexByPackageId(@Param("packageId") String packageId);
+    List<IndexTemplatePO> selectLeafIndexByPackageId(@Param("packageId") String packageId);
 
 
     @Results(id = "scene", value = {

+ 59 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/TaskIndexMapper.java

@@ -0,0 +1,59 @@
+package com.css.simulation.resource.scheduler.mapper;
+
+
+import com.css.simulation.resource.scheduler.pojo.po.TaskIndexPO;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * 任务指标
+ * simulation_mpt_first_target_score
+ * simulation_mpt_last_target_score
+ */
+@Mapper
+public interface TaskIndexMapper {
+
+
+    @Insert("insert into simulation_mpt_last_target_score(id,\n" +
+            "                                             p_id,\n" +
+            "                                             target,\n" +
+            "                                             not_standard_scene_num,\n" +
+            "                                             score,\n" +
+            "                                             create_time,\n" +
+            "                                             create_user_id,\n" +
+            "                                             modify_time,\n" +
+            "                                             modify_user_id,\n" +
+            "                                             is_deleted)\n" +
+            "values (#{leaf.id},\n" +
+            "        #{leaf.pId},\n" +
+            "        #{leaf.target},\n" +
+            "        #{leaf.notStandardSceneNum},\n" +
+            "        #{leaf.score},\n" +
+            "        #{leaf.createTime},\n" +
+            "        #{leaf.createUserId},\n" +
+            "        #{leaf.modifyTime},\n" +
+            "        #{leaf.modifyUserId},\n" +
+            "        #{leaf.isDeleted})")
+    void insertLeafIndex(@Param("leaf") TaskIndexPO taskIndexPO);
+
+    @Insert("insert into simulation_mpt_first_target_score(id,\n" +
+            "                                             p_id,\n" +
+            "                                             target,\n" +
+            "                                             score,\n" +
+            "                                             create_time,\n" +
+            "                                             create_user_id,\n" +
+            "                                             modify_time,\n" +
+            "                                             modify_user_id,\n" +
+            "                                             is_deleted)\n" +
+            "values (#{total.id},\n" +
+            "        #{total.pId},\n" +
+            "        #{total.target},\n" +
+            "        #{total.score},\n" +
+            "        #{total.createTime},\n" +
+            "        #{total.createUserId},\n" +
+            "        #{total.modifyTime},\n" +
+            "        #{total.modifyUserId},\n" +
+            "        #{total.isDeleted})")
+    void insertTotalIndex(@Param("total")TaskIndexPO totalTaskIndex);
+}

+ 9 - 4
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/mapper/TaskMapper.java

@@ -35,10 +35,6 @@ public interface TaskMapper {
             "where p_id = #{projectId}")
     List<TaskPO> selectTaskListByProjectId(@Param("projectId") String projectId);
 
-    @Update("update monitor_task\n" +
-            "set tick_time = #{tickTime}\n" +
-            "where task_id = #{id}")
-    void updateTickTime(@Param("id") String id, @Param("tickTime") Timestamp tickTime);
 
     @Update("update simulation_manual_project_task smpt,monitor_task mt\n" +
             "set smpt.run_state = #{tickTime},\n" +
@@ -59,4 +55,13 @@ public interface TaskMapper {
             "from simulation_manual_project_task\n" +
             "where id = #{id}")
     String selectStateById(@Param("id") String id);
+
+    @Update("update simulation_manual_project_task\n" +
+            "set return_scene_id = #{task.returnSceneId},\n" +
+            "    score           = #{task.score},\n" +
+            "    target_evaluate = #{task.targetEvaluate},\n" +
+            "    score_explain   = #{task.scoreExplain},\n" +
+            "    modify_user_id  = #{task.modifyUserId},\n" +
+            "    modify_time     = #{task.modifyTime}")
+    void updateByScoreResult(@Param("task") TaskPO task);
 }

+ 0 - 18
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/dto/VehicleDTO.java

@@ -1,18 +0,0 @@
-package com.css.simulation.resource.scheduler.pojo.dto;
-
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class VehicleDTO {
-
-    private ModelDTO model;
-    private DynamicsDTO dynamics;
-    private SensorsDTO sensors;
-
-}

+ 5 - 3
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/po/IndexPO.java → simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/po/IndexTemplatePO.java

@@ -9,14 +9,16 @@ import lombok.NoArgsConstructor;
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class IndexPO {
+public class IndexTemplatePO {
 
     private String indexId;
     private String sceneNaturalIds;
     private String sceneTrafficIds;
     private String sceneStatueIds;
     private String weight;  // 权重
-    private String parentId;  // 权重
+    private String parentId;  // 父 id
     private String ruleDetails; // 打分规则代码
-    private Double score; // 打分规则代码
+    private Double tempScore; // 打分规则代码
+
+
 }

+ 18 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/po/TaskIndexPO.java

@@ -0,0 +1,18 @@
+package com.css.simulation.resource.scheduler.pojo.po;
+
+import api.common.pojo.common.CommonPO;
+import lombok.*;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class TaskIndexPO extends CommonPO {
+
+    private String id;
+    private String pId; // 项目 id
+    private String target;
+    private Integer notStandardSceneNum;
+    private Double score; // 得分
+}

+ 3 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/po/TaskPO.java

@@ -16,5 +16,8 @@ public class TaskPO extends CommonPO {
     private String sceneType;
     private String runState;
     private String runResult;
+    private String returnSceneId;
     private Double score;
+    private String targetEvaluate;
+    private String scoreExplain;
 }

+ 2 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/dto/DynamicsDTO.java → simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/DynamicsTO.java

@@ -1,4 +1,4 @@
-package com.css.simulation.resource.scheduler.pojo.dto;
+package com.css.simulation.resource.scheduler.pojo.to;
 
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -11,7 +11,7 @@ import java.math.BigDecimal;
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class DynamicsDTO {
+public class DynamicsTO {
 
     /**
      * 		"dynamics": {

+ 2 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/dto/InfoDTO.java → simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/InfoTO.java

@@ -1,4 +1,4 @@
-package com.css.simulation.resource.scheduler.pojo.dto;
+package com.css.simulation.resource.scheduler.pojo.to;
 
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -9,7 +9,7 @@ import lombok.NoArgsConstructor;
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class InfoDTO {
+public class InfoTO {
 
     private String project_id;
     private String task_id;

+ 2 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/dto/ModelDTO.java → simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/ModelTO.java

@@ -1,4 +1,4 @@
-package com.css.simulation.resource.scheduler.pojo.dto;
+package com.css.simulation.resource.scheduler.pojo.to;
 
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -9,6 +9,6 @@ import lombok.NoArgsConstructor;
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class ModelDTO {
+public class ModelTO {
     private String model_label;
 }

+ 2 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/dto/ScenarioDTO.java → simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/ScenarioTO.java

@@ -1,4 +1,4 @@
-package com.css.simulation.resource.scheduler.pojo.dto;
+package com.css.simulation.resource.scheduler.pojo.to;
 
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -9,7 +9,7 @@ import lombok.NoArgsConstructor;
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class ScenarioDTO {
+public class ScenarioTO {
     private String scenario_osc;
     private String scenario_odr;
     private String scenario_osgb;

+ 17 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/ScoreTO.java

@@ -0,0 +1,17 @@
+package com.css.simulation.resource.scheduler.pojo.to;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class ScoreTO {
+    private String unitSceneID;
+    private Double unitSceneScore;
+    private String evaluateItem;
+    private String scoreDescription;
+}

+ 2 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/dto/SensorsDTO.java → simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/SensorsTO.java

@@ -1,4 +1,4 @@
-package com.css.simulation.resource.scheduler.pojo.dto;
+package com.css.simulation.resource.scheduler.pojo.to;
 
 import com.css.simulation.resource.scheduler.pojo.po.CameraPO;
 import com.css.simulation.resource.scheduler.pojo.po.OgtPO;
@@ -13,7 +13,7 @@ import java.util.List;
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class SensorsDTO {
+public class SensorsTO {
     private List<CameraPO> camera;
     private List<OgtPO> OGT;
 }

+ 5 - 5
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/dto/TaskDTO.java → simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/TaskTO.java

@@ -1,4 +1,4 @@
-package com.css.simulation.resource.scheduler.pojo.dto;
+package com.css.simulation.resource.scheduler.pojo.to;
 
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -117,10 +117,10 @@ import lombok.NoArgsConstructor;
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class TaskDTO {
+public class TaskTO {
 
-    private InfoDTO info;
-    private ScenarioDTO scenario;
-    private VehicleDTO vehicle;
+    private InfoTO info;
+    private ScenarioTO scenario;
+    private VehicleTO vehicle;
 
 }

+ 18 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/pojo/to/VehicleTO.java

@@ -0,0 +1,18 @@
+package com.css.simulation.resource.scheduler.pojo.to;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class VehicleTO {
+
+    private ModelTO model;
+    private DynamicsTO dynamics;
+    private SensorsTO sensors;
+
+}

+ 79 - 29
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/TaskService.java

@@ -6,16 +6,22 @@ import api.common.util.CollectionUtil;
 import api.common.util.StringUtil;
 import api.common.util.TimeUtil;
 import com.css.simulation.resource.scheduler.feign.CommonService;
-import com.css.simulation.resource.scheduler.mapper.IndexMapper;
+import com.css.simulation.resource.scheduler.manager.TaskIndexManager;
+import com.css.simulation.resource.scheduler.manager.TaskManager;
+import com.css.simulation.resource.scheduler.mapper.IndexTemplateMapper;
 import com.css.simulation.resource.scheduler.mapper.ProjectMapper;
+import com.css.simulation.resource.scheduler.mapper.TaskIndexMapper;
 import com.css.simulation.resource.scheduler.mapper.TaskMapper;
-import com.css.simulation.resource.scheduler.pojo.po.IndexPO;
+import com.css.simulation.resource.scheduler.pojo.po.IndexTemplatePO;
 import com.css.simulation.resource.scheduler.pojo.po.ProjectPO;
+import com.css.simulation.resource.scheduler.pojo.po.TaskIndexPO;
 import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
+import com.css.simulation.resource.scheduler.pojo.to.ScoreTO;
 import com.css.simulation.resource.scheduler.util.ScoreUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -23,15 +29,22 @@ import java.util.stream.Collectors;
 @Service
 public class TaskService {
 
+    private final String USER_ID = "simulation-resource-scheduler";
 
     @Autowired
     private CommonService commonService;
     @Autowired
     private ProjectMapper projectMapper;
     @Autowired
+    private TaskManager taskManager;
+    @Autowired
     private TaskMapper taskMapper;
     @Autowired
-    private IndexMapper indexMapper;
+    private TaskIndexManager taskIndexManager;
+    @Autowired
+    private TaskIndexMapper taskIndexMapper;
+    @Autowired
+    private IndexTemplateMapper indexTemplateMapper;
     @Value("${spring.kafka.consumer.topic.manual-project}")
     private String manualProjectTopic;
 
@@ -39,36 +52,36 @@ public class TaskService {
         // 刷新 redis 心跳时间
         ProjectPO projectPO = projectMapper.selectById(taskId);
         String projectId = projectPO.getId();
-        taskMapper.updateTickTime(taskId, TimeUtil.getNowForMysql());
         commonService.set(RedisParameter.builder()
                 .key(manualProjectTopic + ":" + projectId + ":" + taskId)
                 .value(TimeUtil.getNow() + "")
                 .build());
     }
 
-
+    @Transactional
     public void taskState(String taskId, String state) {
         //1 根据 taskId 修改任务状态 taskState。
         taskMapper.updateState(taskId, state);
         //2 如果 taskState 为完成状态,校验一下项目的已完成数量。
         ProjectPO projectPO = projectMapper.selectById(taskId);
         String projectId = projectPO.getId();
-        String scenePackageId = projectPO.getScenePackageId();
+        String scenePackageId = projectPO.getScenePackageId();  // 场景测试包 id,指标根 id
         int taskNum = projectMapper.selectTaskNumById(projectId);
         int completedTaskNum = projectMapper.selectTaskNumByProjectIdAndState(projectId, DictConstants.TASK_COMPLETED);
         if (taskNum != completedTaskNum) {
             return;
         }  //3 如果已完成任务数等于所有任务数量,调用打分程序,对项目中每个指标进行打分,
         List<TaskPO> taskList = taskMapper.selectTaskListByProjectId(projectId);  // 所有任务信息
-        List<IndexPO> leafIndexList = indexMapper.selectLeafIndexWithRuleDetailsByPackageId(scenePackageId);
+        List<IndexTemplatePO> leafIndexTemplateList = indexTemplateMapper.selectLeafIndexWithRuleDetailsByPackageId(scenePackageId);
+        List<TaskIndexPO> leafTaskIndexList = new ArrayList<>();
 
         // 计算所有叶子节点指标的得分
-        for (IndexPO indexPO : leafIndexList) {
-            String ruleDetails = indexPO.getRuleDetails();
+        for (IndexTemplatePO indexTemplatePO : leafIndexTemplateList) {
+            String ruleDetails = indexTemplatePO.getRuleDetails();
             Set<String> sceneIdSet = new HashSet<>();
-            String naturalIds = indexPO.getSceneNaturalIds();
-            String standardIds = indexPO.getSceneStatueIds();
-            String accidentIds = indexPO.getSceneTrafficIds();
+            String naturalIds = indexTemplatePO.getSceneNaturalIds();
+            String standardIds = indexTemplatePO.getSceneStatueIds();
+            String accidentIds = indexTemplatePO.getSceneTrafficIds();
             if (StringUtil.isNotEmpty(naturalIds)) {
                 String[] naturalIdArray = naturalIds.split(",");
                 sceneIdSet.addAll(Arrays.asList(naturalIdArray));
@@ -86,18 +99,55 @@ public class TaskService {
                     .filter(task1 -> sceneIdSet.contains(task1.getSceneId()))
                     .mapToDouble(task2 -> {
                         // 计算每个任务的得分
-                        double score = ScoreUtil.score(task2.getRunResult(), ruleDetails);
-                        task2.setScore(score);
-                        return score;
+                        ScoreTO score = ScoreUtil.score(task2.getRunResult(), ruleDetails);
+                        task2.setReturnSceneId(score.getUnitSceneID());
+                        task2.setScore(score.getUnitSceneScore());
+                        task2.setTargetEvaluate(score.getEvaluateItem());
+                        task2.setScoreExplain(score.getScoreDescription());
+                        task2.setModifyUserId(USER_ID);
+                        task2.setModifyTime(TimeUtil.getNowForMysql());
+                        return score.getUnitSceneScore();
                     }).sum();
-            double indexScore = sum / resultNumberOfCurrentIndex;
-            indexPO.setScore(indexScore);
+            long notStandardSceneNum = taskList.stream()    // 计算不合格的任务数(不到100分就是不合格)
+                    .filter(task1 -> sceneIdSet.contains(task1.getSceneId()) && task1.getScore() < 100)
+                    .count();
+            double leafIndexScore = sum / resultNumberOfCurrentIndex;   // 叶子指标的得分
+            indexTemplatePO.setTempScore(leafIndexScore);
+            TaskIndexPO leafTaskIndex = TaskIndexPO.builder()
+                    .id(StringUtil.getRandomUUID())
+                    .pId(projectId)
+                    .target(indexTemplatePO.getIndexId())
+                    .notStandardSceneNum((int) notStandardSceneNum)
+                    .score(leafIndexScore)
+                    .build();
+            leafTaskIndex.setCreateUserId(USER_ID);
+            leafTaskIndex.setCreateTime(TimeUtil.getNowForMysql());
+            leafTaskIndex.setModifyUserId(USER_ID);
+            leafTaskIndex.setModifyTime(TimeUtil.getNowForMysql());
+            leafTaskIndex.setIsDeleted("0");
+            leafTaskIndexList.add(leafTaskIndex);
         }
-        // 计算不合格的任务总数(不到100分就是不合格)
-        int unqualified = (int) taskList.stream().filter(taskPO -> taskPO.getScore() < 100).count();
+
         //4 根据每个指标的得分和权重算出 project 的总得分。
-        double totalScore = compute(leafIndexList);
-        //5 保存指标的分数和总分数
+        double totalScore = compute(leafIndexTemplateList);
+        //5 保存分数
+        //5-1 保存任务分数
+        taskManager.batchUpdateByScoreResult(taskList);
+        //5-2 保存指标分数
+        taskIndexManager.batchInsertLeafIndex(leafTaskIndexList);
+        //5-3 保存总分数
+        TaskIndexPO totalTaskIndex = TaskIndexPO.builder()
+                .id(StringUtil.getRandomUUID())
+                .pId(projectId)
+                .target(scenePackageId)
+                .score(totalScore)
+                .build();
+        totalTaskIndex.setCreateUserId(USER_ID);
+        totalTaskIndex.setCreateTime(TimeUtil.getNowForMysql());
+        totalTaskIndex.setModifyUserId(USER_ID);
+        totalTaskIndex.setModifyTime(TimeUtil.getNowForMysql());
+        totalTaskIndex.setIsDeleted("0");
+        taskIndexMapper.insertTotalIndex(totalTaskIndex);
     }
 
 
@@ -107,17 +157,17 @@ public class TaskService {
         return DictConstants.TASK_PENDING.equals(state);
     }
 
-    public double compute(List<IndexPO> leaf) {
+    public double compute(List<IndexTemplatePO> leaf) {
         double result = 0.0;
-        Map<String, List<IndexPO>> groups = leaf.stream().collect(Collectors.groupingBy(IndexPO::getParentId));
+        Map<String, List<IndexTemplatePO>> groups = leaf.stream().collect(Collectors.groupingBy(IndexTemplatePO::getParentId));
         Set<String> idSet = groups.keySet();
-        List<IndexPO> indexPOList = indexMapper.selectByIdList(CollectionUtil.setToList(idSet));
-        indexPOList.forEach(index1 -> {
-            double sum = groups.get(index1.getIndexId()).stream().mapToDouble(index2 -> index2.getScore() * Double.parseDouble(index2.getWeight())).sum();
-            index1.setScore(sum);
+        List<IndexTemplatePO> indexTemplatePOList = indexTemplateMapper.selectByIdList(CollectionUtil.setToList(idSet));
+        indexTemplatePOList.forEach(index1 -> {
+            double sum = groups.get(index1.getIndexId()).stream().mapToDouble(index2 -> index2.getTempScore() * Double.parseDouble(index2.getWeight())).sum();
+            index1.setTempScore(sum);
         });
-        if (indexPOList.size() > 1) {
-            result = result + compute(indexPOList);
+        if (indexTemplatePOList.size() > 1) {
+            result = result + compute(indexTemplatePOList);
         }
         return result;
     }

+ 4 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/util/ScoreUtil.java

@@ -1,12 +1,14 @@
 package com.css.simulation.resource.scheduler.util;
 
+import com.css.simulation.resource.scheduler.pojo.to.ScoreTO;
+
 /**
  * 任务结果打分
  */
 public class ScoreUtil {
 
-    public static double score(Object taskResult, String scoreRule) {
-        return Math.random();
+    public static ScoreTO score(Object taskResult, String scoreRule) {
+        return new ScoreTO();
     }