Bladeren bron

上传评估

chenying2100 2 maanden geleden
bovenliggende
commit
8cb1406c54

+ 5 - 1
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/enums/biz/QuestionsList.java

@@ -26,7 +26,11 @@ public enum QuestionsList {
     MULTIPLE_CHOICE("multipleChoice", "多选"),
     FILL_BLANKS("fillBlanks", "填空"),
     SCALE_QUESTIONS("scaleQuestions", "量表"),
-    MATRIX_SCALE("matrixScale", "矩阵");
+    MATRIX_SCALE("matrixScale", "矩阵"),
+    INPUT_BOX("inputBox", "输入框"),
+    INPUT_NUMBER("inputNumber", "输入数值"),
+    INPUT_TEXT("inputText", "输入文本"),
+    CALCULATED("calculated", "公式计算");
 
     private String code;
     private String remark;

+ 5 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysScreeningAssessmentQuestion.java

@@ -29,6 +29,11 @@ public class SysScreeningAssessmentQuestion extends TenantEntity {
     @TableId(value = "question_id")
     private Long questionId;
 
+    /**
+     * 导入数据使用
+     */
+    private String qId;
+
     /**
      * 主键ID
      */

+ 5 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysScreeningAssessmentQuestionVo.java

@@ -37,6 +37,11 @@ public class SysScreeningAssessmentQuestionVo implements Serializable {
     @ExcelProperty(value = "主键ID")
     private Long questionId;
 
+    /**
+     * 导入数据使用
+     */
+    private String qId;
+
     /**
      * 主键ID
      */

+ 16 - 1
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/NutritionEvaluationServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONValidator;
 import com.alibaba.fastjson.TypeReference;
 import org.dromara.common.core.constant.BizConst;
 import org.dromara.common.core.enums.biz.PaymentStatus;
@@ -31,6 +32,9 @@ import org.dromara.system.domain.NutritionEvaluation;
 import org.dromara.system.mapper.NutritionEvaluationMapper;
 import org.dromara.system.service.INutritionEvaluationService;
 
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -123,7 +127,7 @@ public class NutritionEvaluationServiceImpl implements INutritionEvaluationServi
     private LambdaQueryWrapper<NutritionEvaluation> buildQueryWrapper(NutritionEvaluationBo bo) {
         Map<String, Object> params = bo.getParams();
         LambdaQueryWrapper<NutritionEvaluation> lqw = Wrappers.lambdaQuery();
-        lqw.orderByAsc(NutritionEvaluation::getId);
+        lqw.orderByDesc(NutritionEvaluation::getId);
         lqw.eq(bo.getPatientId() != null, NutritionEvaluation::getPatientId, bo.getPatientId());
         lqw.eq(bo.getConfigId() != null, NutritionEvaluation::getConfigId, bo.getConfigId());
         lqw.eq(bo.getScreeningTime() != null, NutritionEvaluation::getScreeningTime, bo.getScreeningTime());
@@ -148,6 +152,17 @@ public class NutritionEvaluationServiceImpl implements INutritionEvaluationServi
         if (StrUtil.isBlank(bo.getContent())) {
             throw new ServiceException("提交的“营养评估”不能为空!");
         }
+
+        try {
+            JSONValidator validator = JSONValidator.from(bo.getContent());
+            if (ObjUtil.isNull(validator.getType()) || JSONValidator.Type.Value.equals(validator.getType())) {
+                String content =new String(Base64.getDecoder().decode(bo.getContent()), StandardCharsets.UTF_8) ;
+                bo.setContent(URLDecoder.decode(content, StandardCharsets.UTF_8.displayName()));
+            }
+        } catch (Exception e) {
+            throw new ServiceException(e.getMessage());
+        }
+
         SysScreeningAssessmentConfigBo configBo = JSON.parseObject(bo.getContent(), new TypeReference<SysScreeningAssessmentConfigBo>() {
         });
         if (CollUtil.isEmpty(configBo.getOtherInfo()) && ObjUtil.isEmpty(configBo.getBaseInfo())) {

+ 15 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/NutritionScreeningServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONValidator;
 import com.alibaba.fastjson.TypeReference;
 import org.dromara.common.core.constant.BizConst;
 import org.dromara.common.core.enums.biz.PaymentStatus;
@@ -35,6 +36,9 @@ import org.dromara.system.mapper.NutritionScreeningMapper;
 import org.dromara.system.service.INutritionScreeningService;
 
 import java.math.BigDecimal;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -156,6 +160,17 @@ public class NutritionScreeningServiceImpl implements INutritionScreeningService
         if (StrUtil.isBlank(bo.getContent())) {
             throw new ServiceException("提交的“营养筛查”不能为空!");
         }
+
+        try {
+            JSONValidator validator = JSONValidator.from(bo.getContent());
+            if (ObjUtil.isNull(validator.getType()) || JSONValidator.Type.Value.equals(validator.getType())) {
+                String content =new String(Base64.getDecoder().decode(bo.getContent()), StandardCharsets.UTF_8) ;
+                bo.setContent(URLDecoder.decode(content, StandardCharsets.UTF_8.displayName()));
+            }
+        } catch (Exception e) {
+            throw new ServiceException(e.getMessage());
+        }
+
         SysScreeningAssessmentConfigBo configBo = JSON.parseObject(bo.getContent(), new TypeReference<SysScreeningAssessmentConfigBo>() {
         });
         if (CollUtil.isEmpty(configBo.getOtherInfo()) && ObjUtil.isEmpty(configBo.getBaseInfo())) {

+ 141 - 7
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysScreeningAssessmentConfigServiceImpl.java

@@ -9,6 +9,7 @@ import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.JSONValidator;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import org.aspectj.weaver.ast.Or;
@@ -299,9 +300,10 @@ public class SysScreeningAssessmentConfigServiceImpl implements ISysScreeningAss
         JSONObject jsonObject = JSON.parseObject(content);
 
         SysScreeningAssessmentConfigBo config = new SysScreeningAssessmentConfigBo();
-        config.setName(jsonObject.getString("title"));
-        config.setPurpose(jsonObject.getString("purpose"));
+        config.setName(jsonObject.getString("purpose"));
+        config.setPurpose("import");
         config.setSource(jsonObject.getString("source"));
+        config.setRemark(jsonObject.getString("title"));
         config.setType(configType);
 
         if (jsonObject.containsKey("scoring")) {
@@ -323,7 +325,10 @@ public class SysScreeningAssessmentConfigServiceImpl implements ISysScreeningAss
                 SysScreeningAssessmentQuestionBo questionBo = new SysScreeningAssessmentQuestionBo();
                 otherInfo.add(questionBo);
 
-                questionBo.setTitle(question.getString("text"));
+                if (question.containsKey("text")) {
+                    questionBo.setTitle(question.getString("text"));
+                }
+
                 setQId(questionBo, question);
                 questionBo.setArrangement("2");
                 if ("单选".equals(type)) {
@@ -340,7 +345,11 @@ public class SysScreeningAssessmentConfigServiceImpl implements ISysScreeningAss
                 for (int j = 0, len2 = options.size(); j < len2; j++) {
                     SysScreeningAssessmentQuestionBo.QuestionAttrBo questionAttrBo = new SysScreeningAssessmentQuestionBo.QuestionAttrBo();
                     JSONObject op = options.getJSONObject(j);
-                    questionAttrBo.setLabel(StrUtil.emptyToDefault(op.getString("text"), op.getString("input_tex")));
+                    if (op.containsKey("text")) {
+                        questionAttrBo.setLabel(op.getString("text"));
+                    } else if (op.containsKey("input_text")) {
+                        questionAttrBo.setLabel(op.getString("input_text"));
+                    }
                     questionAttrBo.setScore(op.getString("score"));
                     if ("单选".equals(type)) {
                         questionAttrBo.setNameEn("single" + j);
@@ -356,20 +365,27 @@ public class SysScreeningAssessmentConfigServiceImpl implements ISysScreeningAss
                 SysScreeningAssessmentQuestionBo questionBo = new SysScreeningAssessmentQuestionBo();
                 otherInfo.add(questionBo);
 
-                questionBo.setTitle(question.getString("text"));
+                if (question.containsKey("text")) {
+                    questionBo.setTitle(question.getString("text"));
+                }
+
                 questionBo.setArrangement("2");
                 setQId(questionBo, question);
                 questionBo.setQuestionType(QuestionsList.QUESTION_TYPE_SELECTION.getCode());
                 questionBo.setQuestionChildType(QuestionsList.SINGLE_CHOICE.getCode());
-                questionBo.setRequired(Boolean.TRUE);
                 JSONArray options = question.getJSONArray("options");
+                questionBo.setRequired(CollUtil.isNotEmpty(options));
                 List<SysScreeningAssessmentQuestionBo.QuestionAttrBo> contentList = CollUtil.newArrayList();
 
                 if (CollUtil.isNotEmpty(options)) {
                     for (int j = 0, len2 = options.size(); j < len2; j++) {
                         SysScreeningAssessmentQuestionBo.QuestionAttrBo questionAttrBo = new SysScreeningAssessmentQuestionBo.QuestionAttrBo();
                         JSONObject op = options.getJSONObject(j);
-                        questionAttrBo.setLabel(StrUtil.emptyToDefault(op.getString("text"), op.getString("input_tex")));
+                        if (op.containsKey("text")) {
+                            questionAttrBo.setLabel(op.getString("text"));
+                        } else if (op.containsKey("input_text")) {
+                            questionAttrBo.setLabel(op.getString("input_text"));
+                        }
                         questionAttrBo.setScore(op.getString("score"));
                         questionAttrBo.setNameEn("single" + j);
                         questionAttrBo.setAllowFillBlank(Boolean.FALSE);
@@ -391,6 +407,124 @@ public class SysScreeningAssessmentConfigServiceImpl implements ISysScreeningAss
                 }
                 questionBo.setContentList(contentList);
                 questionBo.setContent(JSON.toJSONString(contentList));
+            } else if ("multiple_choice".equalsIgnoreCase(type) || "single_choice".equalsIgnoreCase(type)) {
+                SysScreeningAssessmentQuestionBo questionBo = new SysScreeningAssessmentQuestionBo();
+                otherInfo.add(questionBo);
+
+                if (question.containsKey("text")) {
+                    questionBo.setTitle(question.getString("text"));
+                } else if (question.containsKey("title")) {
+                    questionBo.setTitle(question.getString("title"));
+                }
+
+                setQId(questionBo, question);
+                questionBo.setArrangement("2");
+
+                if ("single_choice".equalsIgnoreCase(type)) {
+                    questionBo.setQuestionType(QuestionsList.QUESTION_TYPE_SELECTION.getCode());
+                    questionBo.setQuestionChildType(QuestionsList.SINGLE_CHOICE.getCode());
+                } else if ("multiple_choice".equalsIgnoreCase(type)) {
+                    questionBo.setQuestionType(QuestionsList.QUESTION_TYPE_SELECTION.getCode());
+                    questionBo.setQuestionChildType(QuestionsList.MULTIPLE_CHOICE.getCode());
+                }
+
+                JSONArray options = question.getJSONArray("options");
+                List<SysScreeningAssessmentQuestionBo.QuestionAttrBo> contentList = CollUtil.newArrayList();
+                for (int j = 0, len2 = options.size(); j < len2; j++) {
+                    SysScreeningAssessmentQuestionBo.QuestionAttrBo questionAttrBo = new SysScreeningAssessmentQuestionBo.QuestionAttrBo();
+                    Object op = options.get(j);
+                    String opStr = JSON.toJSONString(op);
+                    if (JSONValidator.Type.Value.equals(JSONValidator.from(opStr).getType())) {
+                        questionAttrBo.setLabel(String.valueOf(op));
+                        questionAttrBo.setScore("0");
+                        questionAttrBo.setAllowFillBlank(Boolean.FALSE);
+                        questionBo.setRequired(Boolean.FALSE);
+                    } else {
+                        questionBo.setRequired(Boolean.TRUE);
+                        JSONObject opObj = (JSONObject) op;
+                        if (opObj.containsKey("label")) {
+                            questionAttrBo.setLabel(opObj.getString("label"));
+                        } else if (opObj.containsKey("text")) {
+                            questionAttrBo.setLabel(opObj.getString("text"));
+                        } else if (opObj.containsKey("value")) {
+                            questionAttrBo.setLabel(opObj.getString("value"));
+                        }
+
+                        if (opObj.containsKey("score")) {
+                            questionAttrBo.setScore(opObj.getString("score"));
+                        } else if (opObj.containsKey("value")) {
+                            questionAttrBo.setScore(opObj.getString("value"));
+                        }
+
+                        String val = opObj.getString("input_text");
+                        questionAttrBo.setAllowFillBlank(String.valueOf(Boolean.TRUE).equalsIgnoreCase(val));
+                    }
+
+                    if ("single_choice".equalsIgnoreCase(type)) {
+                        questionAttrBo.setNameEn("single" + j);
+                    } else if ("multiple_choice".equalsIgnoreCase(type)) {
+                        questionAttrBo.setNameEn("multiple" + j);
+                    }
+
+                    contentList.add(questionAttrBo);
+                }
+                questionBo.setContentList(contentList);
+                questionBo.setContent(JSON.toJSONString(contentList));
+            } else if ("input_number".equalsIgnoreCase(type) || "input_text".equalsIgnoreCase(type) || "calculated".equalsIgnoreCase(type)) {
+                SysScreeningAssessmentQuestionBo questionBo = new SysScreeningAssessmentQuestionBo();
+                otherInfo.add(questionBo);
+
+                questionBo.setQId("Q" + i);
+                setQId(questionBo, question);
+
+                if ("input_number".equalsIgnoreCase(type)) {
+                    questionBo.setQuestionType(QuestionsList.INPUT_BOX.getCode());
+                    questionBo.setQuestionChildType(QuestionsList.INPUT_NUMBER.getCode());
+                } else if ("input_text".equalsIgnoreCase(type)) {
+                    questionBo.setQuestionType(QuestionsList.INPUT_BOX.getCode());
+                    questionBo.setQuestionChildType(QuestionsList.INPUT_TEXT.getCode());
+                } else if ("calculated".equalsIgnoreCase(type)) {
+                    questionBo.setQuestionType(QuestionsList.INPUT_BOX.getCode());
+                    questionBo.setQuestionChildType(QuestionsList.CALCULATED.getCode());
+                }
+
+                if (question.containsKey("text")) {
+                    questionBo.setTitle(question.getString("text"));
+                } else if (question.containsKey("title")) {
+                    questionBo.setTitle(question.getString("title"));
+                }
+
+                questionBo.setRequired(Boolean.FALSE);
+
+            } else if (StrUtil.isBlank(type) && question.containsKey("question_text")) {
+                SysScreeningAssessmentQuestionBo questionBo = new SysScreeningAssessmentQuestionBo();
+                otherInfo.add(questionBo);
+
+                if (question.containsKey("question_text")) {
+                    questionBo.setTitle(question.getString("question_text"));
+                }
+
+                questionBo.setQId("Q" + i);
+                setQId(questionBo, question);
+                questionBo.setArrangement("2");
+                questionBo.setQuestionType(QuestionsList.QUESTION_TYPE_SELECTION.getCode());
+                questionBo.setQuestionChildType(QuestionsList.SINGLE_CHOICE.getCode());
+                questionBo.setRequired(Boolean.TRUE);
+
+                JSONArray options = question.getJSONArray("options");
+                List<SysScreeningAssessmentQuestionBo.QuestionAttrBo> contentList = CollUtil.newArrayList();
+                for (int j = 0, len2 = options.size(); j < len2; j++) {
+                    SysScreeningAssessmentQuestionBo.QuestionAttrBo questionAttrBo = new SysScreeningAssessmentQuestionBo.QuestionAttrBo();
+                    JSONObject op = options.getJSONObject(j);
+                    questionAttrBo.setLabel(op.getString("input_text"));
+                    questionAttrBo.setScore(op.getString("score"));
+                    questionAttrBo.setNameEn("single" + j);
+                    String inputType = op.getString("input_type");
+                    questionAttrBo.setAllowFillBlank(StrUtil.isNotBlank(inputType) && "input_text".equalsIgnoreCase(inputType));
+                    contentList.add(questionAttrBo);
+                }
+                questionBo.setContentList(contentList);
+                questionBo.setContent(JSON.toJSONString(contentList));
             }
         }
 

+ 1 - 0
script/sql/biz/create.sql

@@ -225,6 +225,7 @@ CREATE TABLE sys_screening_assessment_question(
     score_method CHAR(1)  COMMENT '累计选项得分、按最高分、按最低分',
     required tinyint  COMMENT '是否必填',
     content   text COMMENT '内容',
+    q_id varchar(30) COMMENT '导入json格式数据问题的的id,用来公式计算',
 
     -- 系统字段
     create_dept  bigint null comment '创建部门',