root 2 years ago
parent
commit
05b1fd11f4

+ 11 - 12
simulation-resource-server/src/main/java/com/css/simulation/resource/algorithm/controller/AlgorithmController.java

@@ -10,14 +10,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
-import java.io.IOException;
 import java.util.Map;
 
 /**
  * 算法库模块
  */
 @RestController
-@RequestMapping(value = "/algorithm",name = LogConstants.MODULE_ALGORITH)
+@RequestMapping(value = "/algorithm", name = LogConstants.MODULE_ALGORITH)
 public class AlgorithmController {
 
     @Resource
@@ -25,7 +24,7 @@ public class AlgorithmController {
 
     //* -------------------------------- Comm删除算法ent --------------------------------
     @RequestMapping("deleteByid")
-    public ResponseBodyVO<String> deleteById(@RequestBody AlgorithmParameter param){
+    public ResponseBodyVO<String> deleteById(@RequestBody AlgorithmParameter param) {
         return algorithmService.deleteById(param);
     }
     //* -------------------------------- Comment --------------------------------
@@ -35,7 +34,7 @@ public class AlgorithmController {
      * 新增/修改算法
      */
     @RequestMapping("addOrUpdate")
-    public ResponseBodyVO<Void> addOrUpdate(@RequestBody AlgorithmParameter param) throws IOException {
+    public ResponseBodyVO<Void> addOrUpdate(@RequestBody AlgorithmParameter param) {
         return algorithmService.addOrUpdate(param);
     }
 
@@ -44,7 +43,7 @@ public class AlgorithmController {
      * 查询算法列表-私有导入和私有仓库页面
      */
     @RequestMapping("selectAlgorithmList")
-    public ResponseBodyVO selectAlgorithmList(@RequestBody AlgorithmParameter param){
+    public ResponseBodyVO selectAlgorithmList(@RequestBody AlgorithmParameter param) {
         return algorithmService.selectAlgorithmList(param);
     }
 
@@ -52,7 +51,7 @@ public class AlgorithmController {
      * 查询算法列表-算法平台页面
      */
     @RequestMapping("selectAlgoPlatformList")
-    public ResponseBodyVO selectAlgoPlatformList(@RequestBody AlgorithmParameter param){
+    public ResponseBodyVO selectAlgoPlatformList(@RequestBody AlgorithmParameter param) {
         return algorithmService.selectAlgoPlatformList(param);
     }
 
@@ -61,7 +60,7 @@ public class AlgorithmController {
      * 查询算法列表-公有页面
      */
     @RequestMapping("selectSharedAlgorithmList")
-    public ResponseBodyVO selectSharedAlgorithmList(@RequestBody AlgorithmParameter param){
+    public ResponseBodyVO selectSharedAlgorithmList(@RequestBody AlgorithmParameter param) {
         return algorithmService.selectSharedAlgorithmList(param);
     }
 
@@ -70,7 +69,7 @@ public class AlgorithmController {
      * 删除算法前校验
      */
     @RequestMapping("deleteCheck")
-    public ResponseBodyVO<Map<String,String>> deleteCheck(@RequestBody AlgorithmParameter param){
+    public ResponseBodyVO<Map<String, String>> deleteCheck(@RequestBody AlgorithmParameter param) {
         return algorithmService.deleteCheck(param);
     }
 
@@ -79,7 +78,7 @@ public class AlgorithmController {
      * 分享算法
      */
     @RequestMapping("shareAlgorithm")
-    public ResponseBodyVO shareAlgorithm(@RequestBody AlgorithmParameter param){
+    public ResponseBodyVO shareAlgorithm(@RequestBody AlgorithmParameter param) {
         return algorithmService.shareAlgorithm(param);
     }
 
@@ -88,7 +87,7 @@ public class AlgorithmController {
      * 查看算法详情
      */
     @RequestMapping("selectDetailsById")
-    public ResponseBodyVO selectDetailsById(@RequestBody AlgorithmParameter param){
+    public ResponseBodyVO selectDetailsById(@RequestBody AlgorithmParameter param) {
         String algorithmId = param.getId();
         return algorithmService.selectDetailsById(algorithmId);
     }
@@ -97,7 +96,7 @@ public class AlgorithmController {
      * git测试连接
      */
     @RequestMapping("testConnection")
-    public ResponseBodyVO<String> testConnection(@RequestBody AlgorithmParameter param){
+    public ResponseBodyVO<String> testConnection(@RequestBody AlgorithmParameter param) {
         return algorithmService.testConnection(param);
     }
 
@@ -108,7 +107,7 @@ public class AlgorithmController {
     public ResponseBodyVO<String> getGitVersion(@RequestBody AlgorithmParameter param) {
         String id = param.getId();
         String gitVersion = algorithmService.getGitVersion(id);
-        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS,"请求成功。", gitVersion);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, "请求成功。", gitVersion);
     }
 
 }

+ 42 - 30
simulation-resource-server/src/main/java/com/css/simulation/resource/project/impl/SimulationProjectServiceImpl.java

@@ -869,7 +869,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         totalScoreRatio = Double.valueOf(totalSceneScoreNum) / Double.valueOf(totalSceneNum) * 100;
         // 汇总得分率计算方式修改
 //        algorithmScoreVo.setScoreRatio(saveTwoDecimalPlaces(totalScoreRatio));
-        algorithmScoreVo.setScoreRatio(NumberUtil.cut(totalScoreRatio,2));
+        algorithmScoreVo.setScoreRatio(NumberUtil.cut(totalScoreRatio, 2));
         algorithmScoreVoList.add(algorithmScoreVo);
         projectReportVo.setScoreRatio(saveTwoDecimalPlaces(totalScoreRatio));
         projectReportVo.setAlgorithmScore(saveTwoDecimalPlaces(totalScore));
@@ -2850,35 +2850,32 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
             List<AlgorithmScoreVo> algorithmScoreList = vo.getAlgorithmScoreList();
 
-            StringBuffer stringBuffer = new StringBuffer("       " + vo.getAlgorithmName() + "在");
-            int size1 = algorithmScoreList.size();
-            for (int i = 0; i < size1; i++) {
-                AlgorithmScoreVo v = algorithmScoreList.get(i);
+            StringBuilder stringBuilder = new StringBuilder("       " + vo.getAlgorithmName() + "在");
+            for (AlgorithmScoreVo v : algorithmScoreList) {
                 if ("汇总".equals(v.getProjectName())) {
                     continue;
                 }
-                stringBuffer.append(v.getProjectName() + "项目的" + v.getSceneNum() + "个场景中,测试得分为" + v.getScore() +
-                        ",得分率为" + v.getScoreRatio() + "%;");
-
+                stringBuilder.append(v.getProjectName()).append("项目的").append(v.getSceneNum()).append("个场景中,测试得分为").append(v.getScore()).append(",得分率为").append(v.getScoreRatio()).append("%;");
             }
-            String substring = stringBuffer.substring(0, stringBuffer.lastIndexOf(";"));
+            String substring = stringBuilder.substring(0, stringBuilder.lastIndexOf(";"));
 
             addElement(document, substring + ",详见表2-1。", null, bf3, 15, false, 30, false);
             addElement(document, "表2-1 测试得分表", null, bf3, 15, false, 30, true);
 
-            /*
-            测试得分表
-             */
+            //表 2-1 测试得分表
             setBlankLineSpacing(20, font, document);
-            //表头
             PdfPTable pdfPTable = new PdfPTable(5);
-            pdfPTable.setHeaderRows(1);//换页每页显示表头
-            addTitleList(pdfPTable, font, new String[]{"测试项目", "场景数量", "测试权重(%)", "测试得分", "得分率(%)"});
+            pdfPTable.setHeaderRows(1); //换页每页显示表头
+            addTitleList(pdfPTable, font, new String[]{"测试项目", "场景数量", "测试权重(%)", "测试得分", "得分率(%)"}, true);
 
             //数据
             for (AlgorithmScoreVo asv : algorithmScoreList) {
                 String[] data = new String[]{
-                        asv.getProjectName(), String.valueOf(asv.getSceneNum()), asv.getWeight(), String.valueOf(asv.getScore()), String.valueOf(asv.getScoreRatio())
+                        asv.getProjectName(),
+                        String.valueOf(asv.getSceneNum()),
+                        asv.getWeight(),
+                        String.valueOf(asv.getScore()),
+                        String.valueOf(asv.getScoreRatio())
                 };
 
                 addDataList(pdfPTable, font, data);
@@ -2894,21 +2891,20 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             addElement(document, "       算法在本次场景测试包中的表现见表3-1.", null, bf3, 15, false, 30, false);
             addElement(document, "表3-1 算法测试评分细则", null, bf3, 15, false, 30, true);
 
-            /**
-             * 算法评分细则
-             */
+            //* -------------------------------- 算法评分细则 --------------------------------
 
             setBlankLineSpacing(20, font, document);
 
             List<Map> subListScoreLiTitle = vo.getSubListScoreLiTitle();
             int size = subListScoreLiTitle.size();
+            // 表 3-1 算法评分细则
             PdfPTable pdfPTable2 = new PdfPTable(size);
             pdfPTable2.setHeaderRows(1);
             String[] slt = new String[size];
             for (int i = 0; i < size; i++) {
                 slt[i] = subListScoreLiTitle.get(i).get("label").toString();
             }
-            addTitleList(pdfPTable2, font, slt);
+            addTitleList(pdfPTable2, font, slt, true);
 
             List<SubScListVo> subListScoreLi = vo.getSubListScoreLi();
 
@@ -3066,7 +3062,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
                     }
                     int r = score.compareTo(new BigDecimal("100"));
                     //小于100
-                    if (r == -1) {
+                    if (r < 0) {
                         xy100b++;
                         deFenShuoMing.append("在" + m + "指标中的" + sc1.getSceneId() + "中,测试得分为" + sceneScore + ";");
                     }
@@ -3164,7 +3160,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             for (int i = 0; i < size2; i++) {
                 slt2[i] = scoreLiTitle.get(i).get("label").toString();
             }
-            addTitleList(pdfPTable3, font, slt2);
+            addTitleList(pdfPTable3, font, slt2, true);
 
             List<String[]> list2 = new ArrayList<>();
 
@@ -4932,9 +4928,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
     /**
      * 默认字体
-     *
-     * @param font
-     * @return
      */
     private Font defaultFont(BaseFont font) {
         return new Font(font, 14);
@@ -4942,10 +4935,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
     /**
      * 添加表头
-     *
-     * @param pdfPTable
-     * @param font
-     * @param titleList
      */
     private void addTitleList(PdfPTable pdfPTable, BaseFont font, String[] titleList) {
         for (String title : titleList) {
@@ -4953,9 +4942,32 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             pdfPCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
             pdfPCell.setHorizontalAlignment(1);
             pdfPTable.addCell(pdfPCell);
-
         }
+    }
 
+    /**
+     * 水平垂直居中添加表头
+     */
+    private void addTitleList(PdfPTable pdfPTable, BaseFont font, String[] titleList, boolean center) {
+        if (center) {
+            for (String title : titleList) {
+                PdfPCell pdfPCell = new PdfPCell();
+                pdfPCell.setBackgroundColor(BaseColor.LIGHT_GRAY);  // 单元格底色
+                pdfPCell.setHorizontalAlignment(Element.ALIGN_CENTER);  // 水平居中
+                pdfPCell.setUseAscender(true);                          // 垂直居中
+                pdfPCell.setVerticalAlignment(Element.ALIGN_MIDDLE);    // 垂直居中
+                final Paragraph paragraph = new Paragraph(title, defaultFont(font));
+                pdfPCell.setPhrase(paragraph);
+                pdfPTable.addCell(pdfPCell);
+            }
+        } else {
+            for (String title : titleList) {
+                PdfPCell pdfPCell = new PdfPCell(new Paragraph(title, defaultFont(font)));
+                pdfPCell.setBackgroundColor(BaseColor.LIGHT_GRAY);
+                pdfPCell.setHorizontalAlignment(1);
+                pdfPTable.addCell(pdfPCell);
+            }
+        }
     }
 
     /**