Browse Source

MBTI量表开发

zsf 10 tháng trước cách đây
mục cha
commit
8a0c292ef3

+ 39 - 4
src/main/java/com/rf/psychological/rest/DeviceController.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.rf.psychological.base.rest.BaseController;
 import com.rf.psychological.dao.model.AnswerEntity;
 import com.rf.psychological.dao.model.DimensionEntity;
+import com.rf.psychological.scale.dao.model.MBTIResultDetail;
 import com.rf.psychological.scale.dao.model.ScaleEntity;
 import com.rf.psychological.scale.dao.model.ScaleMarksEntity;
 import com.rf.psychological.scale.dao.model.SubjectEntity;
@@ -47,6 +48,9 @@ public class DeviceController extends BaseController {
     @Autowired
     private DimensionService dimensionService;
 
+    @Autowired
+    private MBTIResultDetailService detailService;
+
     /**
      * APP查找服务器使用
      * @return
@@ -78,8 +82,10 @@ public class DeviceController extends BaseController {
                     }
                 }
                 scaleEntity.setCheckItems(item);
-                //scaleService.saveScale(scaleEntity);
-                log.info("------" + scaleEntity.getCheckItems());
+                if (item != null){
+                    scaleService.saveScale(scaleEntity);
+                }
+                log.info("------" + scaleEntity.toString());
             }
         }catch (Exception e){
             e.printStackTrace();
@@ -166,9 +172,9 @@ public class DeviceController extends BaseController {
             List<List<List<Object>>> datas = ExcelUtil.getBankListByExcelSheet(new FileInputStream(file.getAbsolutePath()), file.getName());
             List<ScaleMarksEntity> scaleMarksEntities = scaleMarksService.getScaleMarksByFlag(flag);
             List<List<Object>> markObj = datas.get(2);
-            for (int i =0;i<1;i++){
+            for (int i =0;i<scaleMarksEntities.size();i++){
                 ScaleMarksEntity entity = scaleMarksEntities.get(i);
-                //entity.setSymptom(markObj.get(i).get(0).toString());
+                entity.setSymptom(markObj.get(i).get(0).toString());
                 entity.setImprovementSuggestions(markObj.get(i).get(3).toString());
                 log.info(entity.toString());
                 //scaleMarksService.saveScaleMarks(entity);
@@ -179,4 +185,33 @@ public class DeviceController extends BaseController {
         }
     }
 
+    @GetMapping("updateMBTI")
+    public void updateMBTI(String fileName){
+        File file = new File("C:\\Users\\Administrator\\Desktop\\"+fileName+".xlsx");
+        try {
+            List<List<List<Object>>> datas = ExcelUtil.getBankListByExcelSheet(new FileInputStream(file.getAbsolutePath()), file.getName());
+            List<List<Object>> markObj = datas.get(1);
+            for (int i =0;i<markObj.size();i++){
+                List<Object> objects = markObj.get(i);
+                MBTIResultDetail detail = new MBTIResultDetail();
+                detail.setFlag(objects.get(0).toString());
+                detail.setConclusion(objects.get(1).toString());
+                detail.setCharacteristic(objects.get(2).toString());
+                detail.setEvaluate(objects.get(3).toString());
+                detail.setRepresentative(objects.get(4).toString());
+                detail.setPursuit(objects.get(5).toString());
+                detail.setAdvantage(objects.get(6).toString());
+                detail.setDisadvantages(objects.get(7).toString());
+                detail.setRecommendation(objects.get(8).toString());
+                detail.setSuggest(objects.get(9).toString());
+                detail.setRevered(objects.get(10).toString());
+                log.info(detail.toString());
+                detailService.save(detail);
+            }
+
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
 }

+ 58 - 0
src/main/java/com/rf/psychological/scale/dao/model/MBTIResultDetail.java

@@ -0,0 +1,58 @@
+package com.rf.psychological.scale.dao.model;
+
+import com.rf.psychological.base.model.BaseEntity;
+import lombok.*;
+import org.hibernate.annotations.DynamicUpdate;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+/**
+ * @Description:MBTI结果详情
+ * @Author: mimang
+ * @Date: 2024/6/3
+ */
+@Entity
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode(callSuper=false)
+@Table(name = "t_mbti_result_detail")
+@org.hibernate.annotations.Table(appliesTo = "t_mbti_result_detail", comment = "MBTI结果详情")
+@DynamicUpdate(value = true)
+public class MBTIResultDetail extends BaseEntity {
+
+    @Column(name = "flag",columnDefinition = "varchar(20)  comment '标识'")
+    private String flag;
+
+    @Column(name = "conclusion",columnDefinition = "varchar(20)  comment '测评结论-性格结论'")
+    private String conclusion;
+
+    @Column(name = "characteristic",columnDefinition = "varchar(100)  comment '测评结论-测试特点'")
+    private String characteristic;
+
+    @Column(name = "evaluate",columnDefinition = "varchar(255)  comment '人格特点-总体评价'")
+    private String evaluate;
+
+    @Column(name = "representative",columnDefinition = "varchar(100)  comment '人格特点-名人名家代表'")
+    private String representative;
+
+    @Column(name = "pursuit",columnDefinition = "varchar(255)  comment '人格特点-终极追求'")
+    private String pursuit;
+
+    @Column(name = "advantage",columnDefinition = "varchar(255)  comment '职场建议-优势'")
+    private String advantage;
+
+    @Column(name = "disadvantages",columnDefinition = "varchar(255)  comment '职场建议-劣势'")
+    private String disadvantages;
+
+    @Column(name = "recommendation",columnDefinition = "varchar(200)  comment '职场建议-职业推荐'")
+    private String recommendation;
+
+    @Column(name = "suggest",columnDefinition = "varchar(200)  comment '成长建议'")
+    private String suggest;
+
+    @Column(name = "revered",columnDefinition = "varchar(200)  comment '恋爱宝典'")
+    private String revered;
+}

+ 19 - 0
src/main/java/com/rf/psychological/scale/dao/repository/MBTIResultDetailRepository.java

@@ -0,0 +1,19 @@
+package com.rf.psychological.scale.dao.repository;
+
+import com.rf.psychological.base.repository.BaseRepository;
+import com.rf.psychological.scale.dao.model.MBTIResultDetail;
+
+/**
+ * @Description:MBTI详情接口
+ * @Author: mimang
+ * @Date: 2024/6/3
+ */
+public interface MBTIResultDetailRepository extends BaseRepository<MBTIResultDetail,String> {
+
+    /**
+     * 根据Flag获取到详情
+     * @param flag 标识
+     * @return
+     */
+    MBTIResultDetail findByFlag(String flag);
+}

+ 13 - 4
src/main/java/com/rf/psychological/scale/rest/WebScaleResultController.java

@@ -99,6 +99,9 @@ public class WebScaleResultController extends BaseController {
     @Autowired
     private InstitutionService institutionService;
 
+    @Autowired
+    private MBTIResultDetailService mbtiResultDetailService;
+
 
 
     @SafetyProcess
@@ -300,10 +303,16 @@ public class WebScaleResultController extends BaseController {
         Class<?> cls; // 取得Class对象
         try {
             cls = Class.forName(className);
-            Constructor<?> cons = cls.getConstructor(JSONArray.class, JSONObject.class);
-//            Object obj = cons.newInstance(); // 为构造方法传递参数
-            Object obj = cons.newInstance(jsonArray, resultJson);
-            //cls.getDeclaredMethods();
+            Constructor<?> cons;
+            Object obj;
+
+            if (className.contains("MBTIScale")){
+                cons = cls.getConstructor(JSONArray.class, JSONObject.class,MBTIResultDetailService.class);
+                obj = cons.newInstance(jsonArray, resultJson,mbtiResultDetailService);
+            }else {
+                cons = cls.getConstructor(JSONArray.class, JSONObject.class);
+                obj = cons.newInstance(jsonArray, resultJson);
+            }
             Method method = null;
             //通过配置文件获取量表计分规则使用的版本
             ObjectMapper objectMapper = new ObjectMapper();

+ 118 - 329
src/main/java/com/rf/psychological/scale/resultBusiness/scaleResult/MBTIScale.java

@@ -5,10 +5,21 @@ import com.alibaba.fastjson.JSONObject;
 import com.rf.psychological.dao.dto.scale.NewResultDto;
 import com.rf.psychological.dao.model.AnswerEntity;
 import com.rf.psychological.dao.model.DimensionEntity;
+import com.rf.psychological.scale.dao.model.MBTIResultDetail;
 import com.rf.psychological.scale.dao.model.ScaleEntity;
 import com.rf.psychological.scale.dao.model.ScaleMarksEntity;
+import com.rf.psychological.scale.dao.repository.MBTIResultDetailRepository;
 import com.rf.psychological.scale.scaleresult.ScaleConstant;
-
+import com.rf.psychological.scale.service.MBTIResultDetailService;
+import com.rf.psychological.scale.service.impl.MBTIResultDetailServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
 import java.util.*;
@@ -19,359 +30,137 @@ import java.util.stream.Collectors;
  * @description:职业性格测试
  * @date 2021/7/20 15:55
  */
-public class MBTIScale extends BaseScale {
+@Slf4j
+public class MBTIScale  {
+
+    private JSONArray jsonArray;
+    private JSONObject resultJson;
+    private MBTIResultDetailService detailService;
 
-    public MBTIScale(JSONArray jsonArray, JSONObject resultJson) {
-        super(jsonArray, resultJson);
+    public MBTIScale(JSONArray jsonArray, JSONObject resultJson,MBTIResultDetailService detailService) {
+        this.jsonArray = jsonArray;
+        this.resultJson = resultJson;
+        this.detailService = detailService;
     }
 
     public JSONObject scaleCalculate() throws Exception {
-
-        //总分
-        double score = 0;
-        Map<String, String> resultMap0 = new LinkedHashMap<>();
-        List<Map<String, String>> resultMapList = new ArrayList<>();
-
+        return null;
+    }
+    public JSONObject scaleCalculateV2() throws Exception {
         //获取答案列表
         List<AnswerEntity> answerEntities = (List<AnswerEntity>) resultJson.get("answerEntities");
-        //获取题目和答案列表
-        List<ScaleEntity> scaleEntities = (List<ScaleEntity>) resultJson.get("scaleEntities");
-        //获取评分规则列表
-        List<ScaleMarksEntity> scaleMarksEntities = (List<ScaleMarksEntity>) resultJson.get("scaleMarksEntities");
         //获取维度信息列表
         List<DimensionEntity> dimensionEntities = (List<DimensionEntity>) resultJson.get("dimensionEntities");
-        Map<String,Double> dimensionScoreMap = new HashMap<>();
-        if (dimensionEntities.size() > 0) {
-            //计算每个维度得分
-            double[] dimensionScore = new double[dimensionEntities.size()];
-            for (int i = 0; i < jsonArray.size(); i++) {
-                JSONObject jsonObject1 = jsonArray.getJSONObject(i);
-                for (int y = 0; y < dimensionEntities.size(); y++) {
-                    //for (DimensionEntity dimensionEntity:dimensionEntities){
-                    DimensionEntity dimensionEntity = dimensionEntities.get(y);
-                    String questionNos = dimensionEntity.getQuestionNo();
-                    String[] questionNo = questionNos.split(";");
-                    for (String question : questionNo) {
-                        if (question.equals(jsonObject1.getString("questionNo"))) {
-                            for (AnswerEntity answerEntity : answerEntities) {
-                                if (answerEntity.getQuestionNo().equals(question) && answerEntity.getName().equals(jsonObject1.getString("checkItems"))) {
-                                    String checkItems = scaleEntities.get(Integer.parseInt(answerEntity.getQuestionNo()) - 1).getCheckItems();
-                                    String[] CheckIteml = checkItems.split(";");
-                                    if ((y & 1) == 1) {
-                                        if (CheckIteml[0].equals(jsonObject1.getString("checkItems"))) {
-                                            dimensionScore[y] += Double.parseDouble(answerEntity.getScore());
-                                        } else {
-                                            dimensionScore[y - 1] += Double.parseDouble(answerEntity.getScore());
-                                        }
-                                    } else {
-                                        if (CheckIteml[0].equals(jsonObject1.getString("checkItems"))) {
-                                            dimensionScore[y] += Double.parseDouble(answerEntity.getScore());
-                                        } else {
-                                            dimensionScore[y + 1] += Double.parseDouble(answerEntity.getScore());
-                                        }
-                                    }
-                                }
-                            }
-                            break;
-                        }
-                    }
-                }
-            }
-
-            /*score = dimensionScore[0]+dimensionScore[1]+dimensionScore[2]+dimensionScore[3]+dimensionScore[5]-dimensionScore[4]-dimensionScore[6]+100;
-            resultMap0.put("TMD(情绪纷乱的总分)", String.valueOf(score));
-            resultJson.put("TMD(情绪纷乱的总分)", String.valueOf(score));*/
-            for (int y = 0; y < dimensionEntities.size(); y += 2) {
-                DimensionEntity dimensionEntity = dimensionEntities.get(y);
-                DecimalFormat df = new DecimalFormat("######0.00");
-                resultMap0.put(dimensionEntity.getName() + "得分", String.valueOf(Double.parseDouble(df.format(dimensionScore[y]))));
-                resultJson.put(dimensionEntity.getName() + "得分", String.valueOf(Double.parseDouble(df.format(dimensionScore[y]))));
-                resultMap0.put(dimensionEntities.get(y + 1).getName() + "得分", String.valueOf(Double.parseDouble(df.format(dimensionScore[y + 1]))));
-                resultJson.put(dimensionEntities.get(y + 1).getName() + "得分", String.valueOf(Double.parseDouble(df.format(dimensionScore[y + 1]))));
-            }
-            resultMapList.add(resultMap0);
+        String scoreResult = getAnswerScore(answerEntities,dimensionEntities);
+        resultJson.put("scoreResult",scoreResult);
+        if (scoreResult != null){
+            MBTIResultDetail detail = detailService.findByFlag(scoreResult);
+            resultJson.put("scoreDetail",detail);
         }
-
         JSONObject returnJson = new JSONObject(true);
-        returnJson.put("resultMapList", resultMapList);
-        //returnJson.put("scaleName",resultJson.getString("scaleName"));
         returnJson.put("resultJson", resultJson);
-
         return returnJson;
     }
 
-    public JSONObject scaleCalculateV2() throws Exception {
-
-        //总分
-        double score = 0;
-        //外倾(E)得分
-        int scoreE = 0;
-        //内倾(I)得分
-        int scoreI = 0;
-        //直觉(N)得分
-        int scoreN = 0;
-        //感觉(S)得分
-        int scoreS = 0;
-        //情感(F)得分
-        int scoreF = 0;
-        //思维(T)得分
-        int scoreT = 0;
-        //判断(J)得分
-        int scoreJ = 0;
-        //知觉(P)得分
-        int scoreP = 0;
-        Map<String, String> resultMap0 = new LinkedHashMap<>();
-        List<Map<String, String>> resultMapList = new ArrayList<>();
-
-        //获取答案列表
-        List<AnswerEntity> answerEntities = (List<AnswerEntity>) resultJson.get("answerEntities");
-        //获取题目和答案列表
-        List<ScaleEntity> scaleEntities = (List<ScaleEntity>) resultJson.get("scaleEntities");
-        //获取评分规则列表
-        List<ScaleMarksEntity> scaleMarksEntities = (List<ScaleMarksEntity>) resultJson.get("scaleMarksEntities");
-        //获取维度信息列表
-        List<DimensionEntity> dimensionEntities = (List<DimensionEntity>) resultJson.get("dimensionEntities");
-        //新版本数据格式
-        Map<String, Object> newResult = null;
-        if (dimensionEntities.size() > 0) {
-            //计算每个维度得分
-            double[] dimensionScore = new double[dimensionEntities.size()];
-            for (int i = 0; i < jsonArray.size(); i++) {
-                JSONObject jsonObject1 = jsonArray.getJSONObject(i);
-                for (int y = 0; y < dimensionEntities.size(); y++) {
-                    //for (DimensionEntity dimensionEntity:dimensionEntities){
-                    DimensionEntity dimensionEntity = dimensionEntities.get(y);
-                    String questionNos = dimensionEntity.getQuestionNo();
-                    String[] questionNo = questionNos.split(";");
-                    for (String question : questionNo) {
-                        if (question.equals(jsonObject1.getString("questionNo"))) {
-                            for (AnswerEntity answerEntity : answerEntities) {
-                                if (answerEntity.getQuestionNo().equals(question) && answerEntity.getName().equals(jsonObject1.getString("checkItems"))) {
-                                    if (dimensionEntity.getName().equals("外倾-内倾")){
-                                        if (answerEntity.getOptions().equals("A")){
-                                            scoreE += Double.parseDouble(answerEntity.getScore());
-                                        }else {
-                                            scoreI += Double.parseDouble(answerEntity.getScore());
-                                        }
-                                    }else if (dimensionEntity.getName().equals("感觉-直觉")){
-                                        if (answerEntity.getOptions().equals("A")){
-                                            scoreS += Double.parseDouble(answerEntity.getScore());
-                                        }else {
-                                            scoreN += Double.parseDouble(answerEntity.getScore());
-                                        }
-                                    }else if (dimensionEntity.getName().equals("思维-情感")){
-                                        if (answerEntity.getOptions().equals("A")){
-                                            scoreT += Double.parseDouble(answerEntity.getScore());
-                                        }else {
-                                            scoreF += Double.parseDouble(answerEntity.getScore());
-                                        }
+    private String getAnswerScore(List<AnswerEntity> answerEntities, List<DimensionEntity> dimensionEntities) {
+        //外倾(E)得分,内倾(I)得分
+        int scoreE = 0,scoreI = 0;
+        //直觉(N)得分,感觉(S)得分
+        int scoreN = 0,scoreS = 0;
+        //情感(F)得分,思维(T)得分
+        int scoreF = 0,scoreT = 0;
+        //判断(J)得分,知觉(P)得分
+        int scoreJ = 0,scoreP = 0;
+
+        if (CollectionUtils.isEmpty(dimensionEntities)){
+            log.error("维度参数为空");
+            return null;
+        }
+        //获取各维度选项得分
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
+            for (int y = 0; y < dimensionEntities.size(); y++) {
+                DimensionEntity dimensionEntity = dimensionEntities.get(y);
+                String questionNos = dimensionEntity.getQuestionNo();
+                String[] questionNo = questionNos.split(";");
+                for (String question : questionNo) {
+                    if (question.equals(jsonObject1.getString("questionNo"))) {
+                        for (AnswerEntity answerEntity : answerEntities) {
+                            if (answerEntity.getQuestionNo().equals(question) && answerEntity.getName().equals(jsonObject1.getString("checkItems"))) {
+                                if (dimensionEntity.getName().equals("外倾-内倾")){
+                                    if (answerEntity.getOptions().equals("A")){
+                                        scoreE += Double.parseDouble(answerEntity.getScore());
                                     }else {
-                                        if (answerEntity.getOptions().equals("A")){
-                                            scoreJ += Double.parseDouble(answerEntity.getScore());
-                                        }else {
-                                            scoreP += Double.parseDouble(answerEntity.getScore());
-                                        }
+                                        scoreI += Double.parseDouble(answerEntity.getScore());
                                     }
-                                    String checkItems = scaleEntities.get(Integer.parseInt(answerEntity.getQuestionNo()) - 1).getCheckItems();
-                                    String[] CheckIteml = checkItems.split(";");
-                                    if ((y & 1) == 1) {
-                                        if (CheckIteml[0].equals(jsonObject1.getString("checkItems"))) {
-                                            dimensionScore[y] += Double.parseDouble(answerEntity.getScore());
-                                        } else {
-                                            dimensionScore[y - 1] += Double.parseDouble(answerEntity.getScore());
-                                        }
-                                    } else {
-                                        if (CheckIteml[0].equals(jsonObject1.getString("checkItems"))) {
-                                            dimensionScore[y] += Double.parseDouble(answerEntity.getScore());
-                                        } else {
-                                            dimensionScore[y + 1] += Double.parseDouble(answerEntity.getScore());
-                                        }
+                                }else if (dimensionEntity.getName().equals("感觉-直觉")){
+                                    if (answerEntity.getOptions().equals("A")){
+                                        scoreS += Double.parseDouble(answerEntity.getScore());
+                                    }else {
+                                        scoreN += Double.parseDouble(answerEntity.getScore());
+                                    }
+                                }else if (dimensionEntity.getName().equals("思维-情感")){
+                                    if (answerEntity.getOptions().equals("A")){
+                                        scoreT += Double.parseDouble(answerEntity.getScore());
+                                    }else {
+                                        scoreF += Double.parseDouble(answerEntity.getScore());
+                                    }
+                                }else {
+                                    if (answerEntity.getOptions().equals("A")){
+                                        scoreJ += Double.parseDouble(answerEntity.getScore());
+                                    }else {
+                                        scoreP += Double.parseDouble(answerEntity.getScore());
                                     }
                                 }
                             }
-                            break;
                         }
+                        break;
                     }
                 }
             }
-            dimensionScore[0] = scoreE - scoreI;
-            dimensionScore[1] = scoreS - scoreN;
-            dimensionScore[2] = scoreT - scoreF;
-            dimensionScore[3] = scoreJ - scoreP;
-
-
-            //将量表总维度根据维度名称进行分组
-            Map<String, List<ScaleMarksEntity>> scaleMarksMap = scaleMarksEntities.stream().collect(Collectors.groupingBy(ScaleMarksEntity::getName));
-            newResult = new LinkedHashMap<>();
-            //返回值以及存数据库格式
-            List<NewResultDto> newResultDtos = new ArrayList<>();
-            JSONObject iconInfo = new JSONObject();
-            //雷达图需要的维度以及最大值
-            List<Map<String, Object>> indicator = new LinkedList<>();
-            //雷达图所需要的常模参考值
-            LinkedList<String> reference = new LinkedList<>();
-            //雷达图需要的分数
-            LinkedList<String> scoreList = new LinkedList<>();
-            Map<String,Double> dimensionScoreMap = new HashMap<>();
-            NEWCOMMONScale.commonComputeDimensionScore(null, resultMap0, resultJson, "外倾-内倾", dimensionScore[0], true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
-            NEWCOMMONScale.commonComputeDimensionScore(null, resultMap0, resultJson, "感觉-直觉", dimensionScore[1], true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
-            NEWCOMMONScale.commonComputeDimensionScore(null, resultMap0, resultJson, "思维-情感", dimensionScore[2], true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
-            NEWCOMMONScale.commonComputeDimensionScore(null, resultMap0, resultJson, "判断-知觉", dimensionScore[3], true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
-//            NEWCOMMONScale.commonComputeDimensionScore(null, resultMap0, resultJson, "感觉(S)", dimensionScore[4], true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
-//            NEWCOMMONScale.commonComputeDimensionScore(null, resultMap0, resultJson, "直觉(N)", dimensionScore[5], true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
-//            NEWCOMMONScale.commonComputeDimensionScore(null, resultMap0, resultJson, "外倾(E)", dimensionScore[6], true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
-//            NEWCOMMONScale.commonComputeDimensionScore(null, resultMap0, resultJson, "内倾(I)", dimensionScore[7], true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
-            dimensionScoreMap.put("8af1788589de8b880189de8bb1eb0008",dimensionScore[0]);
-            dimensionScoreMap.put("8af1788589de8b880189de8bb2230009",dimensionScore[1]);
-            dimensionScoreMap.put("8af1788589de8b880189de8bb25a000a",dimensionScore[2]);
-            dimensionScoreMap.put("8af1788589de8b880189de8bb28f000b",dimensionScore[3]);
-//            dimensionScoreMap.put("2c91f37d7bec0878017c9bc8586f57dc",dimensionScore[4]);
-//            dimensionScoreMap.put("2c91f37d7bec0878017c9bc858a757dd",dimensionScore[5]);
-//            dimensionScoreMap.put("2c91f37d7bec0878017c9bc858df57de",dimensionScore[6]);
-//            dimensionScoreMap.put("2c91f37d7bec0878017c9bc8591857df",dimensionScore[7]);
-            resultJson.put("dimensionScoreMap",dimensionScoreMap);
-
-
-
-            // “外倾/内倾”=(内倾-外倾)/21*10 (正分为内倾I, 负分为外倾E)
-            /*double score0 = ((dimensionScore[6] - dimensionScore[7]) / 21) * 10;
-            String score0FLag = null;
-            // “感觉/直觉”=(感觉-直觉)/26*10(正分为感觉S,负分为直觉N)
-            double score1 = ((dimensionScore[4] - dimensionScore[5]) / 26) * 10;
-            String score1FLag = null;
-            //“思考/情感”=(思考-情感)/24*10(正分为思考T,负分为情感F)
-            double score2 = ((dimensionScore[2] - dimensionScore[3]) / 24) * 10;
-            String score2FLag = null;
-            //“知觉/判断”=(知觉-判断)/22*10(正分为感性P,负分为判断J)
-            double score3 = ((dimensionScore[1] - dimensionScore[0]) / 22) * 10;
-            String score3FLag = null;
-            DecimalFormat df = new DecimalFormat("######0.00");
-            if (new BigDecimal(df.format(score0)).compareTo(new BigDecimal("-20")) >= 0 && new BigDecimal(df.format(score0)).compareTo(new BigDecimal("0")) < 0) {
-                newResultDtos.add(new NewResultDto("外倾—内倾", df.format(score0), "外倾型", "外倾态度(E):在外倾的态度中,心理能量和注意是向外流动的,是指向外在环境中的客体的。个体着重外在世界,因注意外在事情而获得动力。",
-                        "无", "无", "(内倾-外倾)/21*10", "无", "否"));
-                score0FLag = "E";
-            } else if (new BigDecimal(df.format(score0)).compareTo(new BigDecimal("0")) >= 0 && new BigDecimal(df.format(score0)).compareTo(new BigDecimal("20")) <= 0) {
-                newResultDtos.add(new NewResultDto("外倾—内倾", df.format(score0), "内倾型", "内倾态度(I):在内倾的态度中,心理能量是从外部环境向内流动的,指向个体的内在经验与反应。个体着重内在世界,因内省、感觉而获得动力。",
-                        "无", "无", "(内倾-外倾)/21*10", "无", "否"));
-                score0FLag = "I";
-            }
-            if (new BigDecimal(df.format(score1)).compareTo(new BigDecimal("-25")) >= 0 && new BigDecimal(df.format(score1)).compareTo(new BigDecimal("0")) < 0) {
-                newResultDtos.add(new NewResultDto("感觉—直觉", df.format(score1), "直觉型", "直觉功能(N):偏好直觉的个体倾向于感知的可能性、事物之间的关系,注重事物的未来发展。",
-                        "无", "无", "(感觉-直觉)/26*10", "无", "否"));
-                score1FLag = "N";
-            } else if (new BigDecimal(df.format(score1)).compareTo(new BigDecimal("0")) >= 0 && new BigDecimal(df.format(score1)).compareTo(new BigDecimal("25")) <= 0) {
-                newResultDtos.add(new NewResultDto("感觉—直觉", df.format(score1), "感觉型", "感觉功能(S):偏好感觉的个体倾向于通过视觉、听觉、触觉、味觉和嗅觉这5种方式来获得信息,个体表现为注重现在的事实与具体观点。",
-                        "无", "无", "(感觉-直觉)/26*10", "无", "否"));
-                score1FLag = "S";
-            }
-            if (new BigDecimal(df.format(score2)).compareTo(new BigDecimal("-23")) >= 0 && new BigDecimal(df.format(score2)).compareTo(new BigDecimal("0")) < 0) {
-                newResultDtos.add(new NewResultDto("感觉—直觉", df.format(score2), "情感型", "情感功能(F):在作出判断时,倾向于从个人感觉出发,注重事物对自身的价值与喜好。",
-                        "无", "无", "(思考-情感)/24*10", "无", "否"));
-                score2FLag = "F";
-            } else if (new BigDecimal(df.format(score2)).compareTo(new BigDecimal("0")) >= 0 && new BigDecimal(df.format(score2)).compareTo(new BigDecimal("23")) <= 0) {
-                newResultDtos.add(new NewResultDto("感觉—直觉", df.format(score2), "思考型", "思维功能(T):根据对客观事实的分析,来作出决定,注重公平原则。",
-                        "无", "无", "(思考-情感)/24*10", "无", "否"));
-                score2FLag = "T";
-            }
-            if (new BigDecimal(df.format(score3)).compareTo(new BigDecimal("-21")) >= 0 && new BigDecimal(df.format(score3)).compareTo(new BigDecimal("0")) < 0) {
-                newResultDtos.add(new NewResultDto("判断—知觉", df.format(score3), "判断型", "判断态度(J):喜欢有条理的生活,实践计划时,以目标为本。通过思考或情感(T或F)来对外界作出反应。",
-                        "无", "无", "(知觉-判断)/22*10", "无", "否"));
-                score3FLag = "J";
-            } else if (new BigDecimal(df.format(score3)).compareTo(new BigDecimal("0")) >= 0 && new BigDecimal(df.format(score3)).compareTo(new BigDecimal("21")) <= 0) {
-                newResultDtos.add(new NewResultDto("判断—知觉", df.format(score3), "感性型", "感知态度(P):不介意突发事情,喜欢弹性生活,注重过程而非目标。通过感觉或直觉(N或S)来对外界作出反应。",
-                        "无", "无", "(知觉-判断)/22*10", "无", "否"));
-                score3FLag = "P";
-            }
-            String totalFlag = score0FLag + score1FLag + score2FLag + score3FLag;
-            if ("ISTJ".equals(totalFlag)) {
-                resultMap0.put("结论", "沉静,认真,有责任感,讲求实际,注重事实,目标清晰且不易动摇,工作生活都打理得井井有条,心思缜密,重视传统和忠诚。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ISTJ组合型", "沉静,认真,有责任感,讲求实际,注重事实,目标清晰且不易动摇,工作生活都打理得井井有条,心思缜密,重视传统和忠诚。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ISFJ".equals(totalFlag)) {
-                resultMap0.put("结论", "沉静,友善,谨慎,有责任感,重视细节,勤奋,做事有始有终,忠诚,细心,关心他人感受、尊重他人、替他人着想,努力创造一个有秩序、和谐的工作和家居环境。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ISFJ组合型", "沉静,友善,谨慎,有责任感,重视细节,勤奋,做事有始有终,忠诚,细心,关心他人感受、尊重他人、替他人着想,努力创造一个有秩序、和谐的工作和家居环境。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("INFJ".equals(totalFlag)) {
-                resultMap0.put("结论", "喜欢探索世界意义、体察万物关系,对人有很强的洞察力,坚持并践履自己的价值观念,懂得关心他人,友好而和善,有一个清晰的理念以谋取大众的最佳利益,能够有计划地、果断地去实践自己的理念。");
-                newResultDtos.add(new NewResultDto("总分", "无", "INFJ组合型", "喜欢探索世界意义、体察万物关系,对人有很强的洞察力,坚持并践履自己的价值观念,懂得关心他人,友好而和善,有一个清晰的理念以谋取大众的最佳利益,能够有计划地、果断地去实践自己的理念。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("INTJ".equals(totalFlag)) {
-                resultMap0.put("结论", "具有创意头脑、有很大的冲劲去实践自己的理念,较为聪慧,能够很快地掌握事情发展的规律,想出长远的发展方向。对复杂的理论充满激情,会有条理地开展工作,并致力于目标的达成,是天生的组织者,有怀疑精神,能看到更多的机会,独立自主,有高水准的工作表现。");
-                newResultDtos.add(new NewResultDto("总分", "无", "INTJ组合型", "具有创意头脑、有很大的冲劲去实践自己的理念,较为聪慧,能够很快地掌握事情发展的规律,想出长远的发展方向。对复杂的理论充满激情,会有条理地开展工作,并致力于目标的达成,是天生的组织者,有怀疑精神,能看到更多的机会,独立自主,有高水准的工作表现。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ISTP".equals(totalFlag)) {
-                resultMap0.put("结论", "是冷静的观察者,具有超强的忍耐力和弹性,很重视事件的前因后果,遇到问题会马上行动并找到应对措施,可以从大量信息中找到症结,能够以理性的原则把事实组织起来,重视效率,善于实践,动手能力强。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ISTP组合型", "是冷静的观察者,具有超强的忍耐力和弹性,很重视事件的前因后果,遇到问题会马上行动并找到应对措施,可以从大量信息中找到症结,能够以理性的原则把事实组织起来,重视效率,善于实践,动手能力强。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ISFP".equals(totalFlag)) {
-                resultMap0.put("结论", "沉静、友善、敏感和仁慈,心思细腻,不喜欢与人产生冲突,不会强迫别人接受自己的意见或价值观,喜欢有独自的空间,可以按照自己的时间规划进行工作安排,渴望沟通分享,热爱大自然,喜欢探索未知的事物。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ISFP组合型", "沉静、友善、敏感和仁慈,心思细腻,不喜欢与人产生冲突,不会强迫别人接受自己的意见或价值观,喜欢有独自的空间,可以按照自己的时间规划进行工作安排,渴望沟通分享,热爱大自然,喜欢探索未知的事物。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("INFP".equals(totalFlag)) {
-                resultMap0.put("结论", "理想主义者,忠于自己的价值观及自己所重视的人,只要双方的价值观没有抵触,往往能包容他人,有弹性,善于接受新事物,有好奇心,能快速预判事情的发展趋向,适应力强,能快速发现他人的优势,并助其发挥潜能。");
-                newResultDtos.add(new NewResultDto("总分", "无", "INFP组合型", "理想主义者,忠于自己的价值观及自己所重视的人,只要双方的价值观没有抵触,往往能包容他人,有弹性,善于接受新事物,有好奇心,能快速预判事情的发展趋向,适应力强,能快速发现他人的优势,并助其发挥潜能。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("INTP".equals(totalFlag)) {
-                resultMap0.put("结论", "沉静、满足、有弹性、适应力强,有怀疑精神,有时喜欢批评,擅于分析,对任何感兴趣的事物,都要探索一个合理的解释,喜欢理论性和抽象性的概念,热衷于思考,有深度的钻研精神,思维严谨有条理。");
-                newResultDtos.add(new NewResultDto("总分", "无", "INTP组合型", "沉静、满足、有弹性、适应力强,有怀疑精神,有时喜欢批评,擅于分析,对任何感兴趣的事物,都要探索一个合理的解释,喜欢理论性和抽象性的概念,热衷于思考,有深度的钻研精神,思维严谨有条理。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ESTP".equals(totalFlag)) {
-                resultMap0.put("结论", "自然不做作,喜欢主动与别人交往,专注于“此时此地”,讲求实际,注重结果,希望以积极的行动去解决问题,喜欢学习新的事物,较为理性,擅长数学及专业理论,追求利益最大化,但过度严谨。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ESTP组合型", "自然不做作,喜欢主动与别人交往,专注于“此时此地”,讲求实际,注重结果,希望以积极的行动去解决问题,喜欢学习新的事物,较为理性,擅长数学及专业理论,追求利益最大化,但过度严谨。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ESFP".equals(totalFlag)) {
-                resultMap0.put("结论", "外向、友善、包容,热爱生命,喜欢物质享受,接受力强,讲究实用性,易接受新朋友和适应新环境,富有灵活性,善于识人,喜欢和他人一起工作,周到得体,但处理原则问题时会摇摆不定。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ESFP组合型", "外向、友善、包容,热爱生命,喜欢物质享受,接受力强,讲究实用性,易接受新朋友和适应新环境,富有灵活性,善于识人,喜欢和他人一起工作,周到得体,但处理原则问题时会摇摆不定。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ENFP".equals(totalFlag)) {
-                resultMap0.put("结论", "热情且富有想象力,认为生活充满很多可能性,有灵性,可以快速将事物的有关信息联系起来,有信心按照自己的判断去解决问题,有很强的即兴发挥能力,容易冲动,很需要别人的肯定,也乐于欣赏和支持别人。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ENFP组合型", "热情且富有想象力,认为生活充满很多可能性,有灵性,可以快速将事物的有关信息联系起来,有信心按照自己的判断去解决问题,有很强的即兴发挥能力,容易冲动,很需要别人的肯定,也乐于欣赏和支持别人。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ENTP".equals(totalFlag)) {
-                resultMap0.put("结论", "思维敏捷,反应快,勇于发言,善于洞察别人,能激励他人,警觉性强,喜欢用战略的眼光分析问题,不喜欢例行公事,能随机应变地去应付新的和富于挑战性的问题。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ENTP组合型", "思维敏捷,反应快,勇于发言,善于洞察别人,能激励他人,警觉性强,喜欢用战略的眼光分析问题,不喜欢例行公事,能随机应变地去应付新的和富于挑战性的问题。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ESTJ".equals(totalFlag)) {
-                resultMap0.put("结论", "讲求实际,注重现实,能果断而快速地作出实际可行的决定,并安排计划和组织人员去完成工作,注重细节,有一套清晰的逻辑标准,能遵从规章制度并坚决执行,善于处理程式化事物,一丝不苟,习惯以经验解决问题。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ESTJ组合型", "讲求实际,注重现实,能果断而快速地作出实际可行的决定,并安排计划和组织人员去完成工作,注重细节,有一套清晰的逻辑标准,能遵从规章制度并坚决执行,善于处理程式化事物,一丝不苟,习惯以经验解决问题。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ESFJ".equals(totalFlag)) {
-                resultMap0.put("结论", "能言善辩,有爱心、尽责,善于合作,喜欢与别人共事,能够注意到别人生活中的需要,渴望和谐的环境并致力于营造这样的环境,希望自己的努力可以得到认可,有极强的同理心,希望通过自己的力量帮助他人。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ESFJ组合型", "能言善辩,有爱心、尽责,善于合作,喜欢与别人共事,能够注意到别人生活中的需要,渴望和谐的环境并致力于营造这样的环境,希望自己的努力可以得到认可,有极强的同理心,希望通过自己的力量帮助他人。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ENFJ".equals(totalFlag)) {
-                resultMap0.put("结论", "温情,有同情心,反应敏捷,有责任感,能为他人着想,善于发现他人的潜能,表达能力强,社交活跃,能积极地协助他人和组织的成长,有启发人的领导才能,忠诚,对赞美和批评都能作出快速回应,喜欢直接表明自己的观点。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ENFJ组合型", "温情,有同情心,反应敏捷,有责任感,能为他人着想,善于发现他人的潜能,表达能力强,社交活跃,能积极地协助他人和组织的成长,有启发人的领导才能,忠诚,对赞美和批评都能作出快速回应,喜欢直接表明自己的观点。",
-                        "无", "无", "无", "无", "是"));
-            } else if ("ENTJ".equals(totalFlag)) {
-                resultMap0.put("结论", "坦率、果断、乐于作为领导者,能够发现组织规章制度的不合理性并着力加以改善,喜欢制定长远计划,善于设定目标,努力求知,又能把知识传给别人,富有远见,见解深刻。");
-                newResultDtos.add(new NewResultDto("总分", "无", "ENTJ组合型", "坦率、果断、乐于作为领导者,能够发现组织规章制度的不合理性并着力加以改善,喜欢制定长远计划,善于设定目标,努力求知,又能把知识传给别人,富有远见,见解深刻。",
-                        "无", "无", "无", "无", "是"));
-            }*/
-            //需要图表展示的
-            iconInfo.put("indicator", indicator);
-            //判断是否有常模参考值,即reference的内容如果全为0,则不进行返回
-            if (!reference.stream().allMatch("0"::equals)) {
-                iconInfo.put("reference", reference);
-            }
-            iconInfo.put("scoreList", scoreList);
-            if (indicator.size() == 0 && reference.size() == 0) {
-                newResult.put("iconInfo", "");
-            } else {
-                newResult.put("iconInfo", iconInfo);
-            }
-            newResult.put("result", newResultDtos);
-            resultMapList.add(resultMap0);
         }
+        return getPersonalityType(scoreE,scoreI,scoreN,scoreS,scoreF,scoreT,scoreJ,scoreP);
+    }
 
-        JSONObject returnJson = new JSONObject(true);
-        returnJson.put("resultMapList", resultMapList);
-
-        returnJson.put("resultJson", resultJson);
-        returnJson.put(ScaleConstant.ResultEnum.RESULT_NEW_FIELD.getKeyword(), newResult);
-
-
-        return returnJson;
+    /**
+     * 根据各个指标得分计算维度
+     * @param scoreE 外倾(E)得分
+     * @param scoreI 内倾(I)得分
+     * @param scoreN 直觉(N)得分
+     * @param scoreS 感觉(S)得分
+     * @param scoreF 情感(F)得分
+     * @param scoreT 思维(T)得分
+     * @param scoreJ 判断(J)得分
+     * @param scoreP 知觉(P)得分
+     * @return
+     */
+    private String getPersonalityType(int scoreE, int scoreI, int scoreN, int scoreS, int scoreF, int scoreT, int scoreJ, int scoreP) {
+        StringBuffer scaleResult = new StringBuffer();
+        //“外倾/内倾”=(内倾-外倾)/21*10 (正分为内倾I, 负分为外倾E)
+        if (((scoreI-scoreE)/21*10)>0){
+            scaleResult.append("I");
+        }else {
+            scaleResult.append("E");
+        }
+        //“感觉/直觉”=(感觉-直觉)/26*10(正分为感觉S,负分为直觉N)
+        if (((scoreS-scoreN)/26*10)>0){
+            scaleResult.append("S");
+        }else {
+            scaleResult.append("N");
+        }
+        //“思考/情感”=(思考-情感)/24*10(正分为思考T,负分为情感F)
+        if (((scoreT-scoreF)/24*10)>0){
+            scaleResult.append("T");
+        }else {
+            scaleResult.append("F");
+        }
+        //“知觉/判断”=(知觉-判断)/22*10(正分为感性P,负分为判断J)
+        if (((scoreP-scoreJ)/22*10)>0){
+            scaleResult.append("P");
+        }else {
+            scaleResult.append("J");
+        }
+        return scaleResult.toString();
     }
 
 

+ 15 - 0
src/main/java/com/rf/psychological/scale/service/MBTIResultDetailService.java

@@ -0,0 +1,15 @@
+package com.rf.psychological.scale.service;
+
+import com.rf.psychological.scale.dao.model.MBTIResultDetail;
+
+/**
+ * @Description:
+ * @Author: mimang
+ * @Date: 2024/6/3
+ */
+public interface MBTIResultDetailService {
+
+    public MBTIResultDetail findByFlag(String flag);
+
+    void save(MBTIResultDetail detail);
+}

+ 77 - 0
src/main/java/com/rf/psychological/scale/service/impl/MBTIResultDetailServiceImpl.java

@@ -0,0 +1,77 @@
+package com.rf.psychological.scale.service.impl;
+
+import cn.hutool.core.util.RandomUtil;
+import com.rf.psychological.scale.dao.model.MBTIResultDetail;
+import com.rf.psychological.scale.dao.repository.MBTIResultDetailRepository;
+import com.rf.psychological.scale.service.MBTIResultDetailService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @Description:MBTI结论详情
+ * @Author: mimang
+ * @Date: 2024/6/3
+ */
+@Service
+public class MBTIResultDetailServiceImpl implements MBTIResultDetailService {
+
+    @Autowired
+    private MBTIResultDetailRepository detailRepository;
+
+    @Override
+    public MBTIResultDetail findByFlag(String flag) {
+        MBTIResultDetail detail = detailRepository.findByFlag(flag);
+        if (detail != null){
+            detail.setConclusion(this.getRandomResult(detail.getConclusion()));
+            detail.setCharacteristic(this.getRandomResultByNum(detail.getCharacteristic(),3));
+            detail.setEvaluate(this.getRandomResult(detail.getEvaluate()));
+            detail.setPursuit(this.getRandomResult(detail.getPursuit()));
+            detail.setAdvantage(this.getRandomResult(detail.getAdvantage()));
+            detail.setDisadvantages(this.getRandomResult(detail.getDisadvantages()));
+            detail.setRecommendation(this.getRandomResult(detail.getRecommendation()));
+            detail.setSuggest(this.getRandomResult(detail.getSuggest()));
+            detail.setRevered(this.getRandomResult(detail.getRevered()));
+            detail.setRepresentative(this.getRandomResultByNum(detail.getRepresentative(),4));
+        }
+        return detailRepository.findByFlag(flag);
+    }
+
+    private String getRandomResult(String str) {
+        List<String> list = Arrays.asList(str.split("#;"));
+        if (list.size()>1){
+            int size = list.size();
+            int num = RandomUtil.randomInt(0,size-1);
+            String text = list.get(num);
+            return text.contains("#")?text.replace("#",""):text;
+        }else {
+            return str;
+        }
+    }
+
+    private String getRandomResultByNum(String str,int num) {
+        List<String> list = Arrays.asList(str.split("、"));
+        if (list.size()>1){
+            String result = null;
+            for (int i =0;i<num;i++){
+                int random =  RandomUtil.randomInt(0,list.size()-1);
+                String text = list.get(random);
+                if (result == null){
+                    result = text;
+                }else {
+                    result = result+"、"+text;
+                }
+            }
+            return result;
+        }else {
+            return str;
+        }
+    }
+
+    @Override
+    public void save(MBTIResultDetail detail) {
+        detailRepository.save(detail);
+    }
+}