浏览代码

报告结果添加总分百分比

zsf 1 年之前
父节点
当前提交
ef6128b8ad

+ 0 - 2
src/main/java/com/rf/psychological/miniapp/praise/controller/PraiseController.java

@@ -2,7 +2,6 @@ package com.rf.psychological.miniapp.praise.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.rf.psychological.base.rest.BaseController;
-import com.rf.psychological.miniapp.browse.model.BrowseEntity;
 import com.rf.psychological.miniapp.praise.model.PraiseEntity;
 import com.rf.psychological.miniapp.praise.service.PraiseService;
 import com.rf.psychological.security.AesEncryptUtils;
@@ -17,7 +16,6 @@ import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 

+ 41 - 0
src/main/java/com/rf/psychological/scale/resultBusiness/scaleResult/NEWCOMMONScale.java

@@ -1,5 +1,6 @@
 package com.rf.psychological.scale.resultBusiness.scaleResult;
 
+import cn.hutool.core.util.NumberUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.rf.psychological.dao.dto.scale.NewResultDto;
@@ -13,6 +14,7 @@ import org.springframework.lang.Nullable;
 
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
+import java.text.NumberFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -151,8 +153,17 @@ public class NEWCOMMONScale extends BaseScale {
                         resultJson.put("总分说明", tempTotalScore.getImprovementSuggestions());
                         resultJson.put("总分解读", tempTotalScore.getNameExplain());
                         resultJson.put("总分建议", tempTotalScore.getSuggestion());
+                        break;
                     }
+                    //计算总分占比
+                    //获取维度最大值
+                    int max = getMaxValue(totalScores);
+                    System.out.println("------------------------"+max);
+                    String value = percnet(score,max);
+                    resultMap0.put("总分百分比", value);
+                    resultJson.put("总分百分比", value);
                 }
+
             }
         } else {
             for (ScaleMarksEntity tempTotalScore : totalScore) {
@@ -169,8 +180,16 @@ public class NEWCOMMONScale extends BaseScale {
                     resultJson.put("总分说明", tempTotalScore.getImprovementSuggestions());
                     resultJson.put("总分解读", tempTotalScore.getNameExplain());
                     resultJson.put("总分建议", tempTotalScore.getSuggestion());
+                    break;
                 }
             }
+            //计算总分占比
+            //获取维度最大值
+            int max = getMaxValue(totalScore);
+            System.out.println("------------------------"+max);
+            String value = percnet(score,max);
+            resultMap0.put("总分百分比", value);
+            resultJson.put("总分百分比", value);
         }
 
 
@@ -207,6 +226,28 @@ public class NEWCOMMONScale extends BaseScale {
         return returnJson;
     }
 
+    private int  getMaxValue(List<ScaleMarksEntity> list){
+        int value = -1;
+        for (ScaleMarksEntity entity :list){
+            int endScore = Integer.parseInt(entity.getScoreEnd());
+            if (value < 0){
+                value = endScore;
+            }
+            if (value <=endScore){
+                value = endScore;
+            }
+        }
+        return value;
+    }
+
+    public static String percnet(double d,double e){
+        double p = d/e;
+        DecimalFormat nf = (DecimalFormat) NumberFormat.getPercentInstance();
+        nf.applyPattern("00%"); //00表示小数点2位
+        nf.setMaximumFractionDigits(2); //2表示精确到小数点后2位
+        return nf.format(p);
+    }
+
     /**
      * 通用计算量表所有维度分数,以及其维度所在分数段症状等
      *