ソースを参照

Merge remote-tracking branch 'origin/master'

martin 3 年 前
コミット
465ebbeb70
20 ファイル変更420 行追加699 行削除
  1. 0 15
      api-common/src/main/java/api/common/pojo/vo/project/PageInfoVo.java
  2. 0 18
      api-common/src/main/java/api/common/pojo/vo/project/ScenePackageBaseVo.java
  3. 0 27
      api-common/src/main/java/api/common/pojo/vo/project/SceneScoreInfoVo.java
  4. 0 35
      api-common/src/main/java/api/common/pojo/vo/project/VehicleSensorVo.java
  5. 0 88
      simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressBar.java
  6. 0 62
      simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressState.java
  7. 0 103
      simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressStream.java
  8. 0 88
      simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressThread.java
  9. 12 0
      simulation-resource-server/pom.xml
  10. 2 3
      simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/ctrl/AlgorithmCtrl.java
  11. 1 3
      simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/serviceImpl/AlgorithmServiceImpl.java
  12. 5 19
      simulation-resource-server/src/main/java/com/css/simulation/resource/model/service/GpsService.java
  13. 23 3
      simulation-resource-server/src/main/java/com/css/simulation/resource/open/ctrl/ReportCtrl.java
  14. 8 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/project/constants/ProjectConstants.java
  15. 13 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/project/ctrl/SimulationProjectCtrl.java
  16. 332 201
      simulation-resource-server/src/main/java/com/css/simulation/resource/project/impl/SimulationProjectServiceImpl.java
  17. 2 2
      simulation-resource-server/src/main/java/com/css/simulation/resource/project/mapper/SimulationProjectMapper.java
  18. 11 0
      simulation-resource-server/src/main/java/com/css/simulation/resource/project/service/SimulationProjectService.java
  19. 10 31
      simulation-resource-server/src/main/resources/mapper/project/SimulationProjectMapper.xml
  20. 1 1
      simulation-resource-server/src/main/resources/mapper/scene/ScenePackageMapper.xml

+ 0 - 15
api-common/src/main/java/api/common/pojo/vo/project/PageInfoVo.java

@@ -1,15 +0,0 @@
-package api.common.pojo.vo.project;
-
-import lombok.Getter;
-import lombok.Setter;
-
-import java.util.List;
-
-@Getter
-@Setter
-public class PageInfoVo<T> {
-
-    private List<T> info;
-
-    private Long total;
-}

+ 0 - 18
api-common/src/main/java/api/common/pojo/vo/project/ScenePackageBaseVo.java

@@ -1,18 +0,0 @@
-package api.common.pojo.vo.project;
-
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * 场景包基本信息
- */
-@Getter
-@Setter
-public class ScenePackageBaseVo {
-
-    private String packageId;
-
-    private String packageName;
-
-    private String sceneNum;
-}

+ 0 - 27
api-common/src/main/java/api/common/pojo/vo/project/SceneScoreInfoVo.java

@@ -1,27 +0,0 @@
-package api.common.pojo.vo.project;
-
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * 场景得分信息
- */
-@Getter
-@Setter
-public class SceneScoreInfoVo {
-
-    //场景名称
-    private String sceneName;
-
-    //场景id
-    private String sceneId;
-
-    //场景类型
-    private String sceneType;
-
-    //得分
-    private String score;
-
-    //指标
-    private String target;
-}

+ 0 - 35
api-common/src/main/java/api/common/pojo/vo/project/VehicleSensorVo.java

@@ -1,35 +0,0 @@
-package api.common.pojo.vo.project;
-
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * 车辆传感器关联信息
- */
-@Getter
-@Setter
-public class VehicleSensorVo {
-
-    //传感器id
-    private String sensorId;
-
-    //传感器类型
-    private String sensorType;
-
-    private String configId;
-
-    private Double sensorX;
-
-    private Double sensorY;
-
-    private Double sensorZ;
-
-    private Double sensorH;
-
-    private Double sensorP;
-
-    private Double sensorR;
-
-    private Integer sensorPort;
-
-}

+ 0 - 88
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressBar.java

@@ -1,88 +0,0 @@
-//
-// Source code recreated from a .class file by IntelliJ IDEA
-// (powered by Fernflower decompiler)
-//
-
-package com.css.simulation.resource.common.util.processbar;
-
-import com.css.simulation.resource.common.controller.RedisController;
-
-import java.io.PrintStream;
-import java.time.LocalDateTime;
-
-public class ProgressBar {
-    private ProgressState progress;
-    private ProgressThread target;
-    private Thread thread;
-
-    public ProgressBar(RedisController redisController, String task, long initialMax) {
-        this(redisController, task, initialMax, 1000, System.err);
-    }
-
-
-    public ProgressBar(RedisController redisController, String task, long initialMax, int updateIntervalMillis, PrintStream os) {
-        this.progress = new ProgressState(task, initialMax);
-        this.target = new ProgressThread(this.progress, (long)updateIntervalMillis, os, redisController);
-        this.thread = new Thread(this.target);
-    }
-
-    public ProgressBar start() {
-        this.progress.startTime = LocalDateTime.now();
-        this.thread.start();
-        return this;
-    }
-
-    public ProgressBar stepBy(long n) {
-        this.progress.stepBy(n);
-        return this;
-    }
-
-    public ProgressBar stepTo(long n) {
-        this.progress.stepTo(n);
-        return this;
-    }
-
-    public ProgressBar step() {
-        this.progress.stepBy(1L);
-        return this;
-    }
-
-    public ProgressBar maxHint(long n) {
-        this.progress.maxHint(n);
-        return this;
-    }
-
-    public ProgressBar stop() {
-        this.target.kill();
-
-        try {
-            this.thread.join();
-            this.target.consoleStream.print("\n");
-            this.target.consoleStream.flush();
-        } catch (InterruptedException var2) {
-        }
-
-        return this;
-    }
-
-    public ProgressBar setExtraMessage(String msg) {
-        this.progress.setExtraMessage(msg);
-        return this;
-    }
-
-    public long getCurrent() {
-        return this.progress.getCurrent();
-    }
-
-    public long getMax() {
-        return this.progress.getMax();
-    }
-
-    public String getTask() {
-        return this.progress.getTask();
-    }
-
-    public String getExtraMessage() {
-        return this.progress.getExtraMessage();
-    }
-}

+ 0 - 62
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressState.java

@@ -1,62 +0,0 @@
-//
-// Source code recreated from a .class file by IntelliJ IDEA
-// (powered by Fernflower decompiler)
-//
-
-package com.css.simulation.resource.common.util.processbar;
-
-import java.time.LocalDateTime;
-
-class ProgressState {
-    String task;
-    long current = 0L;
-    long max = 0L;
-    LocalDateTime startTime = null;
-    String extraMessage = "";
-
-    ProgressState(String task, long initialMax) {
-        this.task = task;
-        this.max = initialMax;
-    }
-
-    synchronized void maxHint(long n) {
-        this.max = n;
-    }
-
-    synchronized void stepBy(long n) {
-        this.current += n;
-        if (this.current > this.max) {
-            this.max = this.current;
-        }
-
-    }
-
-    synchronized void stepTo(long n) {
-        this.current = n;
-        if (this.current > this.max) {
-            this.max = this.current;
-        }
-
-    }
-
-    synchronized void setExtraMessage(String msg) {
-        this.extraMessage = msg;
-    }
-
-    String getTask() {
-        return this.task;
-    }
-
-    synchronized String getExtraMessage() {
-        return this.extraMessage;
-    }
-
-    synchronized long getCurrent() {
-        return this.current;
-    }
-
-    synchronized long getMax() {
-        return this.max;
-    }
-}
-

+ 0 - 103
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressStream.java

@@ -1,103 +0,0 @@
-package com.css.simulation.resource.common.util.processbar;/*
- * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import com.css.simulation.resource.common.controller.RedisController;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public class ProgressStream extends InputStream {
-    private InputStream in;
-    private ProgressBar pb;
-
-    /**
-     * ProgressStream implements an extends InputStream while also writing out the read progress on
-     * console. ProgressStream can be used as a direct replacement for any InputStream compatible
-     * input.
-     *
-     * @param msg Custom message string.
-     * @param stream InputStream to be wrapped.
-     * @throws IOException For any exception generated by the InputStream.
-     */
-    public ProgressStream(RedisController redisController, String msg, InputStream stream) throws IOException {
-        this(redisController, msg, (long) stream.available(), stream);
-    }
-
-    /**
-     * ProgressStream implements an extends InputStream while also writing out the read progress on
-     * console. ProgressStream can be used as a direct replacement for any InputStream compatible
-     * input.
-     *
-     * @param msg Custom message string.
-     * @param size Size of the progress bar.
-     * @param stream InputStream to be wrapped.
-     * @throws IOException For any exception generated by the InputStream.
-     */
-    public ProgressStream(RedisController redisController, String msg, long size, InputStream stream)
-            throws IOException {
-        super();
-
-        // Allocate the reader.
-        this.in = stream;
-
-        // Initialize progress bar.
-        this.pb = new ProgressBar(redisController, msg, size);
-        this.pb.start();
-    }
-
-    @Override
-    public int available() throws IOException {
-        return this.in.available();
-    }
-
-    @Override
-    public void close() throws IOException {
-        this.pb.stop();
-        this.in.close();
-        return;
-    }
-
-    @Override
-    public int read() throws IOException {
-        this.pb.step();
-        return this.in.read();
-    }
-
-    @Override
-    public int read(byte[] toStore) throws IOException {
-        int readBytes = this.in.read(toStore);
-        this.pb.stepBy(readBytes); // Update progress bar.
-        return readBytes;
-    }
-
-    @Override
-    public int read(byte[] toStore, int off, int len) throws IOException {
-        int readBytes = this.in.read(toStore, off, len);
-        this.pb.stepBy(readBytes);
-        return readBytes;
-    }
-
-    @Override
-    public long skip(long n) throws IOException {
-        this.pb.stepTo(n);
-        return this.in.skip(n);
-    }
-
-    @Override
-    public boolean markSupported() {
-        return false;
-    }
-}

+ 0 - 88
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/processbar/ProgressThread.java

@@ -1,88 +0,0 @@
-//
-// Source code recreated from a .class file by IntelliJ IDEA
-// (powered by Fernflower decompiler)
-//
-
-package com.css.simulation.resource.common.util.processbar;
-
-import api.common.pojo.param.RedisParameter;
-import com.css.simulation.resource.common.controller.RedisController;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.core.StringRedisTemplate;
-import org.springframework.stereotype.Component;
-
-import java.io.PrintStream;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.time.Duration;
-
-
-public class ProgressThread implements Runnable {
-    private final RedisController redisController;
-    volatile boolean running;
-    ProgressState progress;
-    long updateInterval;
-    PrintStream consoleStream;
-
-//    @Autowired
-//    RedisController redisController;
-
-//    @Autowired
-//    StringRedisTemplate redisTemplate;
-
-
-    ProgressThread(ProgressState progress, long updateInterval, PrintStream consoleStream,RedisController redisController) {
-        this.progress = progress;
-        this.updateInterval = updateInterval;
-        this.consoleStream = consoleStream;
-        this.redisController = redisController;
-    }
-
-    double progress() {
-        return this.progress.max == 0L ? 0.0D : (double)this.progress.current / (double)this.progress.max;
-    }
-
-
-    /**
-     * 保存文件进度
-     */
-    void refresh() {
-
-        //保存进度
-        Long progressMax = this.progress.max;
-        Long progressCurrent = this.progress.current;
-        String task = this.progress.task;
-//        System.out.println("上传进度:"+task);
-        Double radio = new BigDecimal(Double.valueOf(progressCurrent)/Double.valueOf(progressMax)).setScale(2, RoundingMode.UP).doubleValue();
-//        System.out.println("上传进度:"+radio);
-        RedisParameter redisParameter = new RedisParameter();
-        redisParameter.setKey(task);
-        redisParameter.setValue(radio.toString());
-        redisParameter.setMinutes(1440);//24小时清除
-
-        this.redisController.set(redisParameter);
-//        redisTemplate.opsForValue().set(redisParameter.getKey(), redisParameter.getValue(), Duration.ofMinutes(redisParameter.getMinutes()));
-
-
-    }
-
-    void kill() {
-        this.running = false;
-    }
-
-    public void run() {
-        this.running = true;
-
-        try {
-            while(this.running) {
-                this.refresh();
-                Thread.sleep(this.updateInterval);
-            }
-
-            this.refresh();
-        } catch (InterruptedException var2) {
-        }
-
-    }
-}

+ 12 - 0
simulation-resource-server/pom.xml

@@ -87,6 +87,18 @@
             <artifactId>spring-boot-starter-validation</artifactId>
         </dependency>
 
+        <!--itext生成pdf-->
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>itextpdf</artifactId>
+            <version>5.5.6</version>
+        </dependency>
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>itext-asian</artifactId>
+            <version>5.2.0</version>
+        </dependency>
+
     </dependencies>
     <build>
         <plugins>

+ 2 - 3
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/ctrl/AlgorithmCtrl.java

@@ -40,7 +40,7 @@ public class AlgorithmCtrl {
      */
     @RequestMapping("selectAlgorithmList")
     @ResponseBody
-    public ResponseBodyVO selectAlgorithmList(@RequestBody AlgorithmParameter param) throws IOException {
+    public ResponseBodyVO selectAlgorithmList(@RequestBody AlgorithmParameter param){
         return service.selectAlgorithmList(param);
     }
 
@@ -51,12 +51,11 @@ public class AlgorithmCtrl {
      */
     @RequestMapping("selectAlgoPlatformList")
     @ResponseBody
-    public ResponseBodyVO selectAlgoPlatformList(@RequestBody AlgorithmParameter param) throws IOException {
+    public ResponseBodyVO selectAlgoPlatformList(@RequestBody AlgorithmParameter param){
         return service.selectAlgoPlatformList(param);
     }
 
 
-
     /**
      * 查询算法列表-公有页面
      * @param param

+ 1 - 3
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/serviceImpl/AlgorithmServiceImpl.java

@@ -14,14 +14,11 @@ import com.css.simulation.resource.algorithm.service.AlgorithmService;
 import com.css.simulation.resource.feign.AlgoPlatformService;
 import com.css.simulation.resource.system.service.DictService;
 import com.github.pagehelper.PageInfo;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.impl.client.CloseableHttpClient;
 import org.eclipse.jgit.lib.Ref;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -161,6 +158,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
             }else {
                 po.setShare("1");
                 po.setId(StringUtil.getRandomUUID());
+                po.setAlgorithmCode(StringUtil.getRandomCode());
                 int add = algorithmMapper.add(po);
                 if(add > 0){
                     return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"分享成功");

+ 5 - 19
simulation-resource-server/src/main/java/com/css/simulation/resource/model/service/GpsService.java

@@ -6,8 +6,8 @@ import api.common.pojo.po.model.GpsPO;
 import api.common.pojo.vo.model.GpsVO;
 import api.common.util.ObjectUtil;
 import api.common.util.StringUtil;
-import api.common.util.TimeUtil;
 import com.css.simulation.resource.common.utils.AuthUtil;
+import com.css.simulation.resource.common.utils.PoUtil;
 import com.css.simulation.resource.model.mapper.GpsMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -41,13 +41,7 @@ public class GpsService {
 
     public GpsPO saveGps(GpsPO gpsPO) {
         //常规字段赋值
-        String currentUserId = AuthUtil.getCurrentUserId();
-        Timestamp currentTime = TimeUtil.getNowForMysql();
-        gpsPO.setCreateUserId(currentUserId);
-        gpsPO.setCreateTime(currentTime);
-        gpsPO.setModifyUserId(currentUserId);
-        gpsPO.setModifyTime(currentTime);
-        gpsPO.setIsDeleted(DictConstants.NO);
+        PoUtil.initAddPo(gpsPO);
         gpsPO.setShare(DictConstants.NO);//私有
         //名称校验
         List<GpsVO> list = gpsMapper.checkGpsName(gpsPO);
@@ -58,7 +52,7 @@ public class GpsService {
         String id = gpsPO.getId();
         if(ObjectUtil.isNull(id)){//新增
             gpsPO.setId(StringUtil.getRandomUUID());
-            gpsPO.setSensorCode(StringUtil.getRandomUUID());
+            gpsPO.setSensorCode(StringUtil.getRandomCode());
             gpsMapper.insert(gpsPO);
         }else{//修改
             gpsMapper.update(gpsPO);
@@ -78,13 +72,7 @@ public class GpsService {
             return gpsPO;
         }
         //常规字段赋值
-        String currentUserId = AuthUtil.getCurrentUserId();
-        Timestamp currentTime = TimeUtil.getNowForMysql();
-        gpsPO.setCreateUserId(currentUserId);
-        gpsPO.setCreateTime(currentTime);
-        gpsPO.setModifyUserId(currentUserId);
-        gpsPO.setModifyTime(currentTime);
-        gpsPO.setIsDeleted(DictConstants.NO);
+        PoUtil.initAddPo(gpsPO);
         gpsPO.setId(StringUtil.getRandomUUID());
         gpsPO.setSensorCode(StringUtil.getRandomCode());
         gpsMapper.insert(gpsPO);
@@ -92,9 +80,7 @@ public class GpsService {
     }
 
     public int delGpsById(GpsPO gpsPO) {
-        gpsPO.setIsDeleted(DictConstants.YES);
-        gpsPO.setModifyUserId(AuthUtil.getCurrentUserId());
-        gpsPO.setModifyTime(TimeUtil.getNowForMysql());
+        PoUtil.initDelPo(gpsPO);
         int i = gpsMapper.delGpsById(gpsPO);
         return i;
     }

+ 23 - 3
simulation-resource-server/src/main/java/com/css/simulation/resource/open/ctrl/ReportCtrl.java

@@ -1,9 +1,12 @@
 package com.css.simulation.resource.open.ctrl;
 
 import api.common.pojo.common.ResponseBodyVO;
+import api.common.pojo.param.project.SimulationManualProjectParam;
 import api.common.pojo.vo.project.ProjectReportVo;
 import api.common.util.ObjectUtil;
+import api.common.util.StringUtil;
 import com.css.simulation.resource.open.service.ReportService;
+import com.css.simulation.resource.project.service.SimulationProjectService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -19,6 +22,11 @@ public class ReportCtrl {
     @Autowired
     ReportService reportService;
 
+    @Autowired
+    SimulationProjectService simulationProjectService;
+
+
+
     /**
      * 获取测试报告详情
      * @param paramMap
@@ -30,9 +38,21 @@ public class ReportCtrl {
         if(ObjectUtil.isNull(paramMap) || ObjectUtil.isNull(paramMap.get("algorithmId"))){
             return new ResponseBodyVO(false, 500, "参数必传!",null);
         }
-        ProjectReportVo reportVo = reportService.getSimulationReportById(paramMap);
-        ResponseBodyVO<ProjectReportVo> response = new ResponseBodyVO<ProjectReportVo>(ResponseBodyVO.Response.SUCCESS);
-        response.setInfo(reportVo);
+
+        //获取最新的报告id
+        String projectId = simulationProjectService.selectProjectReportIdByAlgorithmId(paramMap.get("algorithmId"));
+        if(StringUtil.isEmpty(projectId)){
+            return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"报告不存在");
+        }
+
+        //获取报告详情
+        SimulationManualProjectParam projectParam = new SimulationManualProjectParam();
+        projectParam.setId(projectId);
+        ResponseBodyVO vo = simulationProjectService.selectProjectReportById(projectParam);
+
+        //ProjectReportVo reportVo = reportService.getSimulationReportById(paramMap);
+        ResponseBodyVO<ProjectReportVo> response = new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
+        response.setInfo((ProjectReportVo) vo.getInfo());
         return response;
     }
 }

+ 8 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/project/constants/ProjectConstants.java

@@ -11,4 +11,12 @@ public class ProjectConstants {
     //第三方算法类型(索为)
     public static final String SY_ALGORITHM_TYPE="3";
 
+    //任务运行状态字典
+    public static final String TASK_RUN_STATE = "taskRunState";
+
+    //任务运行结果状态
+    public static final String TASK_RESULT_STATE = "taskResultState";
+
+
+
 }

+ 13 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/project/ctrl/SimulationProjectCtrl.java

@@ -5,10 +5,12 @@ import api.common.pojo.param.project.DictParam;
 import api.common.pojo.param.project.SimulationManualProjectParam;
 import com.css.simulation.resource.project.service.SimulationProjectService;
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.itextpdf.text.DocumentException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -168,6 +170,17 @@ public class SimulationProjectCtrl {
     }
 
 
+    /**
+     * 导出测试报告
+     * @return
+     */
+    @RequestMapping("exportProjectReportById")
+    @ResponseBody
+    public void exportProjectReportById(@RequestBody SimulationManualProjectParam param) throws Exception {
+        service.exportProjectReport(param);
+    }
+
+
 
 
 }

+ 332 - 201
simulation-resource-server/src/main/java/com/css/simulation/resource/project/impl/SimulationProjectServiceImpl.java

@@ -15,15 +15,16 @@ import api.common.pojo.po.model.ConfigSensorPO;
 import api.common.pojo.po.model.VehiclePO;
 import api.common.pojo.po.project.*;
 import api.common.pojo.po.scene.ScenePackagePO;
-import api.common.pojo.po.scene.ScenePackageSublistPO;
+import api.common.pojo.vo.algorithm.AlgorithmVO;
 import api.common.pojo.vo.project.*;
 import api.common.pojo.vo.scene.RunProjectVO;
 import api.common.util.JsonUtil;
 import api.common.util.ObjectUtil;
+import api.common.util.StringUtil;
 import api.common.util.TimeUtil;
-import com.alibaba.druid.support.spring.stat.SpringStatUtils;
 import com.css.simulation.resource.common.utils.AuthUtil;
 import com.css.simulation.resource.common.utils.PageUtil;
+import com.css.simulation.resource.feign.AlgoPlatformService;
 import com.css.simulation.resource.project.constants.ProjectConstants;
 import com.css.simulation.resource.project.enums.ProjectRunStateEnum;
 import com.css.simulation.resource.project.enums.SceneTypeEnum;
@@ -36,19 +37,31 @@ import com.css.simulation.resource.project.service.SimulationProjectService;
 import com.css.simulation.resource.system.service.DictService;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.github.pagehelper.PageInfo;
+import com.itextpdf.text.*;
+import com.itextpdf.text.pdf.BaseFont;
+import com.itextpdf.text.pdf.PdfPCell;
+import com.itextpdf.text.pdf.PdfPTable;
+import com.itextpdf.text.pdf.PdfWriter;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.server.ServletServerHttpRequest;
 import org.springframework.stereotype.Service;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.net.URLEncoder;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.List;
 
 @Service
 @Slf4j
@@ -72,6 +85,9 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
     @Autowired
     DictService dictService;
 
+    @Resource
+    AlgoPlatformService algoPlatformService;
+
     private String[] dateFmtArr= new String[]{"yyyyMMdd", "yyyy-MM-dd HH:mm:ss","yyyy-MM-dd"};
 
     @Override
@@ -239,12 +255,9 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             //设置开始时间
             param.setStartTime(new Date());
 
-            //创建项目最后一级指标信息和场景信息(生成得分时创建数据)
-//            createProjectSceneAndTarget(param.getId());
-            ///TODO Kafka推送消息
+            //Kafka推送消息
             projectRunToKafka(po);
 
-
         }else if("30".equals(param.getNowRunState())){
             //设置完成时间
             param.setFinishTime(new Date());
@@ -283,8 +296,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         }
         ProjectDetailsVo projectDetailsVo = new ProjectDetailsVo();
 
-
-
         //项目基本信息
         SimulationManualProjectPo po = simulationProjectMapper.selectProjectById(param);
         if(po == null){
@@ -352,44 +363,20 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         //任务信息
         ProjectTaskParam projectTaskParam = new ProjectTaskParam();
         projectTaskParam.setPId(po.getId());
-//        List<ManualProjectTaskPo> manualProjectTaskPos = simulationProjectMapper.selectprojectTaskByQuery(projectTaskParam);
-//        List<ManualProjectTaskVo> ManualProjectTaskVoList = new ArrayList<>();
-        List<ProjectRunStateNumVo> projectRunStateNumVoList = new ArrayList<>();
-        List<ProjectRunResultRatioNumVo> projectRunResultRatioNumVoList = new ArrayList<>();
-//        if(manualProjectTaskPos != null){
-//            for(ManualProjectTaskPo task : manualProjectTaskPos){
-//                ManualProjectTaskVo manualProjectTaskVo = convertManualProjectTaskPoToVo(task);
-//                setUpSceneInfo(manualProjectTaskVo);
-//                ManualProjectTaskVoList.add(manualProjectTaskVo);
-//            }
-
-            //任务运行状态统计
-            Integer size = simulationProjectTaskMapper.selectProjectTaskNumByProjectId(projectTaskParam);
-//            List<ProjectRunStateNumVo> projectRunStateNumVos = simulationProjectMapper.selectRunStateCount(po.getId());
-            projectRunStateNumVoList = simulationProjectTaskMapper.selectRunStateCount(po.getId());
-
-            /*状态统计统计数字,不统计比率
-            for(ProjectRunStateNumVo pv : projectRunStateNumVos){
-                Integer num = pv.getNum();
-                Double d = (double)num/size;
-                d = saveTwoDecimalPlaces(d);
-                pv.setRatio(d);
-                projectRunStateNumVoList.add(pv);
-            }*/
+        List<ProjectRunResultRatioNumVo> projectRunResultRatioNumVos = null;
 
-            //结果状态统计
-            List<ProjectRunResultRatioNumVo> projectRunResultRatioNumVos = simulationProjectTaskMapper.selectRunResultCount(po.getId());
-            for(ProjectRunResultRatioNumVo rv : projectRunResultRatioNumVos){
-                Integer num = rv.getNum();
-                Double d = (double)num/size;
-                d = saveTwoDecimalPlaces(d);
-                rv.setRatio(d);
-                projectRunResultRatioNumVoList.add(rv);
-            }
+        //任务运行状态统计
+        List<ProjectRunStateNumVo> projectRunStateNumVos = null;
+        Integer size = simulationProjectTaskMapper.selectProjectTaskNumByProjectId(projectTaskParam);
+        if(size > 0){
+            projectRunStateNumVos = simulationProjectTaskMapper.selectRunStateCount(po.getId());
+            taskRunState(projectRunStateNumVos, size);
 
-//        }
 
+            projectRunResultRatioNumVos = simulationProjectTaskMapper.selectRunResultCount(po.getId());
+            taskResultState(projectRunResultRatioNumVos, size);
 
+        }
 
         projectDetailsVo.setProjectId(po.getProjectId());
         projectDetailsVo.setProjectName(po.getProjectName());
@@ -415,13 +402,68 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         projectDetailsVo.setSensorLidarList(sensorLidarList);
         projectDetailsVo.setSensorRadarList(sensorRadarList);
         projectDetailsVo.setSensorGpsList(sensorGpsList);
-//        projectDetailsVo.setTaskList(ManualProjectTaskVoList);
-        projectDetailsVo.setStateList(projectRunStateNumVoList);
-        projectDetailsVo.setResultList(projectRunResultRatioNumVoList);
+        projectDetailsVo.setStateList(projectRunStateNumVos);
+        projectDetailsVo.setResultList(projectRunResultRatioNumVos);
 
         return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, projectDetailsVo);
     }
 
+    //运行状态统计
+    private void taskRunState(List<ProjectRunStateNumVo> vos, Integer size){
+        for(ProjectRunStateNumVo pv : vos){
+            Integer num = pv.getNum();
+            Double d = (double)num/size;
+            d = saveTwoDecimalPlaces(d);
+            pv.setRatio(d);
+        }
+        //补全没有的
+        Map<String, String> dict = getDictByType(ProjectConstants.TASK_RUN_STATE);
+        for(String key : dict.keySet()){
+            boolean b = false;
+            for(ProjectRunStateNumVo pv : vos){
+                if(pv.getStateName().equals(dict.get(key))){
+                    b = true;
+                }
+            }
+            if(!b){
+                ProjectRunStateNumVo vo = new ProjectRunStateNumVo();
+                vo.setStateName(dict.get(key));
+                vo.setNum(0);
+                vo.setRatio(0D);
+                vos.add(vo);
+            }
+
+        }
+    }
+
+    //运行结果统计
+    private void taskResultState(List<ProjectRunResultRatioNumVo> vos,Integer size){
+        //结果状态统计
+        for(ProjectRunResultRatioNumVo rv : vos){
+            Integer num = rv.getNum();
+            Double d = (double)num/size;
+            d = saveTwoDecimalPlaces(d);
+            rv.setRatio(d);
+        }
+        //补全没有的
+        Map<String, String> dict = getDictByType(ProjectConstants.TASK_RESULT_STATE);
+        for(String key : dict.keySet()){
+            boolean b = false;
+            for(ProjectRunResultRatioNumVo pv : vos){
+                if(pv.getResultName().equals(dict.get(key))){
+                    b = true;
+                }
+            }
+            if(!b){
+                ProjectRunResultRatioNumVo vo = new ProjectRunResultRatioNumVo();
+                vo.setResultName(dict.get(key));
+                vo.setNum(0);
+                vo.setRatio(0D);
+                vos.add(vo);
+            }
+        }
+    }
+
     private void setVehicleConfig(SensorBaseInfoVo vo, ConfigSensorPO vs){
         vo.setConfigId(vs.getConfigId());
         vo.setSensorId(vs.getSensorId());
@@ -568,11 +610,11 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         List<DropDownTypeVo> result = new ArrayList<>();
         if(isEmpty(param.getDropDownType())){
             //获取全部(算法,车辆,场景)
-            setAlgorithmDropDown(result);
+            setAlgorithmDropDown(result,param.getAlgorithmType());
             setVehicleDropDown(result);
             setScenePackageDropDown(result);
         }else if("1".equals(param.getDropDownType())){
-            setAlgorithmDropDown(result);
+            setAlgorithmDropDown(result,param.getAlgorithmType());
         }else if("2".equals(param.getDropDownType())){
             setVehicleDropDown(result);
         }else if("3".equals(param.getDropDownType())){
@@ -646,14 +688,23 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
     @Override
     public String getDictName(String type, String code) {
+        Map<String, String> stringStringMap = getDictByType(type);
+        if(stringStringMap != null && stringStringMap.size() > 0){
+            return stringStringMap.get(code);
+        }
+        return "";
+    }
+
+    private Map<String, String> getDictByType(String type){
         DictParam dictParam = new DictParam();
         dictParam.setDictTypes(type);
         Map<String, Map<String, String>> dictMapsByTypes = dictService.getDictMapsByTypes(dictParam);
         Map<String, String> stringStringMap = dictMapsByTypes.get(type);
         if(stringStringMap != null && stringStringMap.size() > 0){
-            return stringStringMap.get(code);
+            return stringStringMap;
         }
-        return "";
+        return null;
+
     }
 
     @Override
@@ -735,19 +786,50 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
     }
 
-    private void setAlgorithmDropDown(List<DropDownTypeVo> result){
-        List<AlgorithmPO> algorithmBaseInfoVo = simulationProjectMapper.selectAlgorithmBaseInfoById(null);
+    private void setAlgorithmDropDown(List<DropDownTypeVo> result, String algorithmType){
+
         List<DropDownVo> algorithmList = new ArrayList<>();
-        for(AlgorithmPO v : algorithmBaseInfoVo){
-            DropDownVo dropDownVo = new DropDownVo();
-            dropDownVo.setId(v.getId());
-            dropDownVo.setName(v.getAlgorithmName());
-            algorithmList.add(dropDownVo);
+
+        if(algorithmType.equals(ProjectConstants.SY_ALGORITHM_TYPE)){
+            //第三方算法平台获取(索为)
+            String sort = "algorithmId-desc";
+            Integer page = 1;
+            Integer size = 999;//全部
+
+            String urlParam = "&page=" + page+ "&size=" + size+ "&sort=" + sort;
+            ResponseBodyVO algorithmBody = algoPlatformService.getAlgorithmList(urlParam);
+
+            //解析数据
+            Map jsonMap = JsonUtil.jsonToMap((String) algorithmBody.getInfo());
+            Map<String, Object> dataMap = (Map<String, Object>) jsonMap.get("data");
+            List<Map<String, String>> contentList = (List<Map<String, String>>) dataMap.get("content");
+            Integer totalElements = (Integer) dataMap.get("totalElements");
+            if(totalElements > 0){
+                for (Map<String, String> content: contentList) {
+                    DropDownVo dropDownVo = new DropDownVo();
+                    dropDownVo.setId(content.get("algorithmId"));
+                    dropDownVo.setName(content.get("algorithmName"));
+                    algorithmList.add(dropDownVo);
+                }
+            }
+
+
+        }else{
+            List<AlgorithmPO> algorithmBaseInfoVo = simulationProjectMapper.selectAlgorithmBaseInfoById(null);
+
+            for(AlgorithmPO v : algorithmBaseInfoVo){
+                DropDownVo dropDownVo = new DropDownVo();
+                dropDownVo.setId(v.getId());
+                dropDownVo.setName(v.getAlgorithmName());
+                algorithmList.add(dropDownVo);
+            }
+
         }
         DropDownTypeVo algorithmDropDown = new DropDownTypeVo();
         algorithmDropDown.setDropDownList(algorithmList);
         algorithmDropDown.setType("1");
         result.add(algorithmDropDown);
+
     }
     private void setVehicleDropDown(List<DropDownTypeVo> result){
         List<ConfigPO> vehicleBaseInfoVo = simulationProjectMapper.selectConfigVehicle(null);
@@ -953,72 +1035,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         return manualProjectTaskVo;
     }
 
-    /**
-     * 生成项目场景信息和最后一级指标信息 TODO 暂不使用
-     */
-    private void createProjectSceneAndTarget(String id){
-        //1.查询场景包下最后一级指标和指标下所有场景
-        List<ScenePackageSubListVO> scenePackageSubListVOS = simulationProjectMapper.selectSubListByPid(id);
-
-        //2.保存最后一级指标
-        for(ScenePackageSubListVO v : scenePackageSubListVOS){
-            SimulationMptLastTargetScorePo simulationMptTargetScorePo = new SimulationMptLastTargetScorePo();
-            simulationMptTargetScorePo.setPId(id);
-            simulationMptTargetScorePo.setTarget(v.getSublistId());
-            simulationMptTargetScorePo.createPo(AuthUtil.getCurrentUserId());
-            simulationProjectMapper.insertSimulationMptLastTargetScorePo(simulationMptTargetScorePo);
-
-            //3.保存场景
-            String sceneNaturalIds = v.getSceneNaturalIds();
-            String sceneTrafficIds = v.getSceneTrafficIds();
-            String sceneStatueIds = v.getSceneStatueIds();
-            if(!isEmpty(sceneNaturalIds)){
-                String[] split = sceneNaturalIds.split(",");
-                for(String s : split){
-                    SceneBaseInfoVo sceneBaseInfoVo = simulationProjectMapper.selectSceneNatural(s);
-                    SimulationMptSceneScorePo simulationMptSceneScorePo = new SimulationMptSceneScorePo();
-                    simulationMptSceneScorePo.setPId(id);
-                    simulationMptSceneScorePo.setSceneId(s);
-                    simulationMptSceneScorePo.setSceneType(DictConstants.SCENE_NATURAL);
-                    simulationMptSceneScorePo.createPo(AuthUtil.getCurrentUserId());
-                    simulationProjectMapper.insertSimulationMptSceneScorePo(simulationMptSceneScorePo);
-                }
-
-            }
-            if(!isEmpty(sceneTrafficIds)){
-                String[] split = sceneTrafficIds.split(",");
-                for(String s : split){
-                    SceneBaseInfoVo sceneBaseInfoVo = simulationProjectMapper.selectSceneAccidentById(s);
-                    SimulationMptSceneScorePo simulationMptSceneScorePo = new SimulationMptSceneScorePo();
-                    simulationMptSceneScorePo.setPId(id);
-                    simulationMptSceneScorePo.setSceneId(s);
-                    simulationMptSceneScorePo.setSceneType(DictConstants.SCENE_ACCIDENT);
-                    simulationMptSceneScorePo.createPo(AuthUtil.getCurrentUserId());
-                    simulationProjectMapper.insertSimulationMptSceneScorePo(simulationMptSceneScorePo);
-                }
-            }
-            if(!isEmpty(sceneStatueIds)){
-                String[] split = sceneStatueIds.split(",");
-                for(String s : split){
-                    SceneBaseInfoVo sceneBaseInfoVo = simulationProjectMapper.selectSceneStandardsRegulations(s);
-                    SimulationMptSceneScorePo simulationMptSceneScorePo = new SimulationMptSceneScorePo();
-                    simulationMptSceneScorePo.setPId(id);
-                    simulationMptSceneScorePo.setSceneId(s);
-                    simulationMptSceneScorePo.setSceneType(DictConstants.SCENE_STANDARD);
-                    simulationMptSceneScorePo.createPo(AuthUtil.getCurrentUserId());
-                    simulationProjectMapper.insertSimulationMptSceneScorePo(simulationMptSceneScorePo);
-                }
-            }
-
-            ///TODO 泛化场景暂不支持
-        }
-
-        //4.查询第一级指标
-
-        //5.保存第一级指标
-
-    }
-
 
     /**
      * 级联获取场景指标得分数据
@@ -1140,11 +1156,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         List<SceneScListVo> objects = new ArrayList<>();
         //结果补全
         for(List<String> list : result){
-            int offset = size - list.size();
             int start = list.size() - 5;
-//            for(int i=0;i<offset;i++){
-//                list.add(start+i,"");
-//            }
             SceneScListVo sceneScListVo = new SceneScListVo();
             for(int i=0;i<start;i++){
                 if(0 == i){
@@ -1175,37 +1187,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         List<Map<String, String>> cloums = new ArrayList<>();
         for(int i=0; i<size-5;i++){
             setCloums(i,cloums);
-            /*if(0 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","一级指标");
-                map.put("prop","sublistName1");
-                cloums.add(map);
-            }else if(1 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","二级指标");
-                map.put("prop","sublistName2");
-                cloums.add(map);
-            }else if(2 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","三级指标");
-                map.put("prop","sublistName3");
-                cloums.add(map);
-            }else if(3 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","四级指标");
-                map.put("prop","sublistName4");
-                cloums.add(map);
-            }else if(4 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","五级指标");
-                map.put("prop","sublistName5");
-                cloums.add(map);
-            }else if(5 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","六级指标");
-                map.put("prop","sublistName6");
-                cloums.add(map);
-            }*/
         }
 
         Map<String, String> map1 = new HashMap<>();
@@ -1248,13 +1229,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
      * @param pos 所有指标
      */
     private void setParentSub(SublistScoreVo po, SublistScoreVo parentPo, List<SublistScoreVo> pos) {
-        /*for(SublistScoreVo p : pos){
-            if(po.getParentId().equals(p.getId())){
-                po.setSublistName(p.getSublistName()+","+po.getSublistName());
-                setParentSub(p, pos);
-            }
-
-        }*/
         if(parentPo == null){
             for(SublistScoreVo p : pos){
                 setSc(po,p,po,pos);
@@ -1332,11 +1306,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         List<SubScListVo> objects = new ArrayList<>();
         //结果补全
         for(List<String> list : result){
-            int offset = size - list.size();
             int start = list.size() - 4;
-            /*for(int i=0;i<offset;i++){
-                list.add(start+i,"");
-            }*/
             SubScListVo subScListVo = new SubScListVo();
             for(int i=0;i<start;i++){
                 if(0 == i){
@@ -1367,37 +1337,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         List<Map<String, String>> cloums = new ArrayList<>();
         for(int i=0; i<size-4;i++){
             setCloums(i,cloums);
-            /*if(0 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","一级指标");
-                map.put("prop","sublistName1");
-                cloums.add(map);
-            }else if(1 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","二级指标");
-                map.put("prop","sublistName2");
-                cloums.add(map);
-            }else if(2 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","三级指标");
-                map.put("prop","sublistName3");
-                cloums.add(map);
-            }else if(3 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","四级指标");
-                map.put("prop","sublistName4");
-                cloums.add(map);
-            }else if(4 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","五级指标");
-                map.put("prop","sublistName5");
-                cloums.add(map);
-            }else if(5 == i){
-                Map<String, String> map = new HashMap<>();
-                map.put("label","六级指标");
-                map.put("prop","sublistName6");
-                cloums.add(map);
-            }*/
         }
         Map<String, String> map1 = new HashMap<>();
         map1.put("label","场景数量");
@@ -1756,10 +1695,8 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
     }
 
     private void setScoreNum(String sublistId, String pId, SceneScoreVo resultVo){
-//        ScenePackageSubListVO scenePackageSubListVO = simulationProjectMapper.selectsublistBySublistId(sublistId);
         SimulationMptSceneScorePo po = new SimulationMptSceneScorePo();
         po.setPId(pId);
-//        po.setLastTargerId(scenePackageSubListVO.getSublistId());
         po.setLastTargerId(sublistId);
         SceneScoreVo sceneScoreVo = simulationProjectTaskMapper.selectSceneScoreNumQuery(po);
         resultVo.setNum(resultVo.getNum()+sceneScoreVo.getNum());
@@ -1899,6 +1836,200 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, simulationProjectMapper.selectEvaluationLevel(params));
     }
 
+    @Override
+    public void exportProjectReport(SimulationManualProjectParam param) throws Exception {
+        Document document = new Document(PageSize.A4);
+        OutputStream os = null;
+        try {
+            HttpServletResponse response = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();
+
+            //获取要生成的数据
+            ResponseBodyVO bodyVO = selectProjectReportById(param);
+            ProjectReportVo vo = (ProjectReportVo)bodyVO.getInfo();
+
+
+            //下载
+            String fileName="评价报告";
+            response.setContentType("application/x-download");
+            response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".pdf");
+            os = new BufferedOutputStream(response.getOutputStream());
+
+            PdfWriter.getInstance(document, os);
+
+            // 以下生成PDF
+            BaseFont font = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
+
+            //标题
+            document.open();
+            Font titleFont = new Font(font, 20); //字体
+            Paragraph titleElements = new Paragraph("评价报告",titleFont);
+            titleElements.setAlignment(Element.ALIGN_CENTER); //居中
+            document.add(titleElements);
+
+
+            //算法名称、算法得分、测试等级
+            Paragraph algorithmNanmeElements = new Paragraph(
+                    50,
+                    "          算法名称:"+vo.getAlgorithmName()
+                            +"         算法得分:"+vo.getAlgorithmScore()
+                            +"         测试等级:"+vo.getEvaluationLevel(),
+                    defaultFont(font));
+            algorithmNanmeElements.setAlignment(Element.ALIGN_LEFT); //靠左
+            document.add(algorithmNanmeElements);
+
+
+            //算法描述
+            Paragraph algorithmDescribeFontElements = new Paragraph(
+                    30,
+                    "          算法描述:"+vo.getAlgorithmDescribe(),
+                    defaultFont(font));
+            algorithmDescribeFontElements.setAlignment(Element.ALIGN_LEFT); //居中
+            document.add(algorithmDescribeFontElements);
+
+            //算法简评
+            Font algorithmEvaluateFont = new Font(font, 14); //字体
+            Paragraph algorithmEvaluateElements = new Paragraph(
+                    30,
+                    "          算法简评:"+vo.getAlgorithmEvaluation(),
+                    algorithmEvaluateFont);
+            algorithmEvaluateElements.setAlignment(Element.ALIGN_LEFT); //居中
+            document.add(algorithmEvaluateElements);
+
+            /*
+            测试得分表
+             */
+            Paragraph scoreTableElements = new Paragraph(
+                    50,
+                    "测试得分表",
+                    defaultFont(font));
+            scoreTableElements.setAlignment(Element.ALIGN_CENTER); //居中
+            document.add(scoreTableElements);
+
+            setBlankLineSpacing(20,font,document);
+
+            //表头
+            PdfPTable pdfPTable = new PdfPTable(5);
+            pdfPTable.setHeaderRows(1);//换页每页显示表头
+            addTitleList(pdfPTable, font, new String[]{"测试项目","场景数量","测试权重","测试得分","得分率"});
+
+            //数据
+            List<AlgorithmScoreVo> algorithmScoreList = vo.getAlgorithmScoreList();
+            for(AlgorithmScoreVo asv : algorithmScoreList){
+                String[] data = new String[]{
+                        asv.getProjectName(), String.valueOf(asv.getSceneNum()), asv.getWeight(), String.valueOf(asv.getScore()), String.valueOf(asv.getScoreRatio())
+                };
+
+                addDataList(pdfPTable, font, data);
+            }
+            document.add(pdfPTable);
+
+            /*
+            评价等级
+             */
+            Paragraph levelTableElements = new Paragraph(
+                    50,
+                    "评价等级",
+                    defaultFont(font));
+            levelTableElements.setAlignment(Element.ALIGN_CENTER); //居中
+            document.add(levelTableElements);
+
+            setBlankLineSpacing(20,font,document);
+
+            PdfPTable pdfPTable1 = new PdfPTable(5);
+            addTitleList(pdfPTable1, font, new String[]{"测试项目","90<总分<100","80<总分<90","70<总分<80","0<总分<70"});
+            addDataList(pdfPTable1, font, new String[]{"评价等级","优秀(G)","良好(A)","一般(M)","较差(P)",
+                    "评价等级","++++++","+++++","++++","+++",});
+            document.add(pdfPTable1);
+
+
+            //新的一页
+            document.newPage();
+            document.setPageSize(PageSize.A4.rotate());
+            PdfPTable pdfPTable2 = new PdfPTable(5);
+            addTitleList(pdfPTable2, font, new String[]{"测试项目","90<总分<100","80<总分<90","70<总分<80","0<总分<70"});
+            addDataList(pdfPTable2, font, new String[]{"评价等级","优秀(G)","良好(A)","一般(M)","较差(P)",
+                    "评价等级","++++++","+++++","++++","+++",});
+            document.add(pdfPTable2);
+
+
+
+
+
+        } finally {
+            document.close();
+            os.close();
+        }
+
+    }
+
+    @Override
+    public String selectProjectReportIdByAlgorithmId(String algorithmId) {
+        SimulationManualProjectPo po = simulationProjectMapper.selectProjectReportIdByAlgorithmId(algorithmId);
+        if(StringUtil.isNotEmpty(po)){
+            return po.getId();
+        }
+        return null;
+    }
+
+    /**
+     * 换行
+     * @param lineNum 换行数量
+     * @param document
+     */
+    private void lineFeed(int lineNum, Document document) throws DocumentException {
+        for(int i=0;i<lineNum;i++){
+            document.add(Chunk.NEWLINE);
+        }
+    }
+
+    private void setBlankLineSpacing(int lineSpacingIndex, BaseFont font, Document document) throws DocumentException {
+        Paragraph elements2 = new Paragraph(
+                lineSpacingIndex,
+                " ",
+                defaultFont(font));
+        document.add(elements2);
+    }
+
+    /**
+     * 默认字体
+     * @param font
+     * @return
+     */
+    private Font defaultFont(BaseFont font){
+        return new Font(font, 14);
+    }
+
+    /**
+     * 添加表头
+     * @param pdfPTable
+     * @param font
+     * @param titleList
+     */
+    private void addTitleList(PdfPTable pdfPTable, BaseFont font, String[] titleList){
+        for(String title : titleList){
+            PdfPCell pdfPCell = new PdfPCell(new Paragraph(title,defaultFont(font)));
+            pdfPCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
+            pdfPTable.addCell(pdfPCell);
+
+        }
+
+    }
+
+    /**
+     * 添加数据
+     * @param pdfPTable
+     * @param font
+     * @param dataList
+     */
+    private void addDataList(PdfPTable pdfPTable, BaseFont font, String[] dataList){
+        for(String title : dataList){
+            PdfPCell pdfPCell = new PdfPCell(new Paragraph(title,defaultFont(font)));
+            pdfPTable.addCell(pdfPCell);
+
+        }
+
+    }
+
 
     private void insertOtherAlgorithm(SimulationManualProjectParam param){
         if(ProjectConstants.SY_ALGORITHM_TYPE.equals(param.getAlgorithmType())){

+ 2 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/project/mapper/SimulationProjectMapper.java

@@ -73,8 +73,6 @@ public interface SimulationProjectMapper {
 
     int insertSimulationMptLastTargetScorePo(SimulationMptLastTargetScorePo po);
 
-    int insertSimulationMptSceneScorePo(SimulationMptSceneScorePo po);
-
     int insertSimulationMptFirstTargetScorePo(SimulationMptFirstTargetScorePo po);
 
     List<SimulationMptSceneScorePo> selectSceneScore(SimulationMptSceneScorePo po);
@@ -101,5 +99,7 @@ public interface SimulationProjectMapper {
 
     AlgorithmPO selectalgorithmByQuery(AlgorithmPO po);
 
+    SimulationManualProjectPo selectProjectReportIdByAlgorithmId(String algorithmId);
+
 
 }

+ 11 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/project/service/SimulationProjectService.java

@@ -2,7 +2,9 @@ package com.css.simulation.resource.project.service;
 
 import api.common.pojo.common.ResponseBodyVO;
 import api.common.pojo.param.project.SimulationManualProjectParam;
+import com.itextpdf.text.DocumentException;
 
+import java.io.IOException;
 import java.util.Map;
 
 
@@ -35,8 +37,17 @@ public interface SimulationProjectService {
     ResponseBodyVO selectProjectTaskList(SimulationManualProjectParam param);
 
     ResponseBodyVO selectRunProjectBySy();
+
     ResponseBodyVO selectRunTaskBySy();
+
     ResponseBodyVO selectRunTaskByState();
+
     ResponseBodyVO selectRunProjectByState();
+
     ResponseBodyVO selectEvaluationLevel();
+
+    void exportProjectReport(SimulationManualProjectParam param) throws Exception;
+
+    //根据算法id获取最新的一条报告id
+    String selectProjectReportIdByAlgorithmId(String algorithmId);
 }

+ 10 - 31
simulation-resource-server/src/main/resources/mapper/project/SimulationProjectMapper.xml

@@ -404,7 +404,7 @@
 
     <!--保存第一级指标信息-->
     <insert id="insertSimulationMptFirstTargetScorePo" parameterType="api.common.pojo.po.project.SimulationMptFirstTargetScorePo">
-        insert into simulation_mpt_last_target_score
+        insert into simulation_mpt_first_target_score
         (
         id,
         p_id,
@@ -428,36 +428,6 @@
         )
     </insert>
 
-    <!--保存项目场景信息-->
-    <insert id="insertSimulationMptSceneScorePo" parameterType="api.common.pojo.po.project.SimulationMptSceneScorePo">
-        insert into simulation_mpt_scene_score
-        (
-        id,
-        p_id,
-        scene_id,
-        scene_type,
-        score,
-        create_time,
-        create_user_id,
-        modify_time,
-        modify_user_id,
-        is_deleted
-        )
-        values
-        (
-        #{id,jdbcType=VARCHAR},
-        #{p_id,jdbcType=VARCHAR},
-        #{scene_id,jdbcType=VARCHAR},
-        #{scene_type,jdbcType=VARCHAR},
-        #{score,jdbcType=DOUBLE},
-        #{createTime,jdbcType=TIMESTAMP},
-        #{createUserId,jdbcType=VARCHAR},
-        #{modifyTime,jdbcType=TIMESTAMP},
-        #{modifyUserId,jdbcType=VARCHAR},
-        #{isDeleted,jdbcType=VARCHAR}
-        )
-    </insert>
-
     <!--查询场景得分-->
     <select id="selectSceneScore" parameterType="api.common.pojo.po.project.SimulationMptSceneScorePo" resultType="api.common.pojo.po.project.SimulationMptSceneScorePo">
         select score, target_evaluate
@@ -558,4 +528,13 @@
         where id=#{id,jdbcType=VARCHAR}
         and is_deleted = '0'
     </select>
+
+    <!--根据算法id获取最新的一条报告id-->
+    <select id="selectProjectReportIdByAlgorithmId" parameterType="string" resultType="api.common.pojo.po.project.SimulationManualProjectPo">
+        select id
+        from simulation_manual_project
+        where algorithm = #{algorithmId,jdbcType=VARCHAR} and is_deleted = '0' and now_run_state='30'
+        order by finish_time desc
+        limit 1
+    </select>
 </mapper>

+ 1 - 1
simulation-resource-server/src/main/resources/mapper/scene/ScenePackageMapper.xml

@@ -30,7 +30,7 @@
                 and a.package_id = #{packageId,jdbcType=VARCHAR}
             </if>
             <if test="packageCode != null and packageCode != ''">
-                and a.package_code = #{packageCode,jdbcType=VARCHAR}
+                and a.package_code like CONCAT('%',#{packageCode,jdbcType=VARCHAR},'%')
             </if>
             <if test="share != null and share != ''">
                 and a.share = #{share,jdbcType=VARCHAR}