diff --git a/ry-xinli-system/src/main/java/com/ddnai/system/service/impl/psychology/PsyQuestionnaireAnswerServiceImpl.java b/ry-xinli-system/src/main/java/com/ddnai/system/service/impl/psychology/PsyQuestionnaireAnswerServiceImpl.java index aa6f552e..cb859e9e 100644 --- a/ry-xinli-system/src/main/java/com/ddnai/system/service/impl/psychology/PsyQuestionnaireAnswerServiceImpl.java +++ b/ry-xinli-system/src/main/java/com/ddnai/system/service/impl/psychology/PsyQuestionnaireAnswerServiceImpl.java @@ -558,6 +558,7 @@ public class PsyQuestionnaireAnswerServiceImpl implements IPsyQuestionnaireAnswe /** * 计算单选题得分 + * 对于问卷,直接使用选项的分值,不检查是否是正确答案 */ private BigDecimal calculateRadioScore(PsyQuestionnaireAnswerDetail detail, Set correctOptionIds, BigDecimal itemScore, List allOptions) @@ -567,19 +568,21 @@ public class PsyQuestionnaireAnswerServiceImpl implements IPsyQuestionnaireAnswe return BigDecimal.ZERO; } - // 如果选中的是正确答案,得满分 + // 查找选中选项的分值 + PsyQuestionnaireOption selectedOption = allOptions.stream() + .filter(opt -> opt.getOptionId().equals(detail.getOptionId())) + .findFirst() + .orElse(null); + + if (selectedOption != null && selectedOption.getOptionScore() != null) + { + // 直接返回选项的分值 + return selectedOption.getOptionScore(); + } + + // 如果选项没有设置分值,检查是否是正确答案 if (correctOptionIds.contains(detail.getOptionId())) { - // 查找选中选项的分值 - PsyQuestionnaireOption selectedOption = allOptions.stream() - .filter(opt -> opt.getOptionId().equals(detail.getOptionId())) - .findFirst() - .orElse(null); - - if (selectedOption != null && selectedOption.getOptionScore() != null) - { - return selectedOption.getOptionScore(); - } return itemScore; } @@ -657,6 +660,7 @@ public class PsyQuestionnaireAnswerServiceImpl implements IPsyQuestionnaireAnswe /** * 计算判断题得分 + * 对于问卷,直接使用选项的分值,不检查是否是正确答案 */ private BigDecimal calculateBooleanScore(PsyQuestionnaireAnswerDetail detail, Set correctOptionIds, BigDecimal itemScore, List allOptions) @@ -666,19 +670,21 @@ public class PsyQuestionnaireAnswerServiceImpl implements IPsyQuestionnaireAnswe return BigDecimal.ZERO; } - // 如果选中的是正确答案,得满分 + // 查找选中选项的分值 + PsyQuestionnaireOption selectedOption = allOptions.stream() + .filter(opt -> opt.getOptionId().equals(detail.getOptionId())) + .findFirst() + .orElse(null); + + if (selectedOption != null && selectedOption.getOptionScore() != null) + { + // 直接返回选项的分值 + return selectedOption.getOptionScore(); + } + + // 如果选项没有设置分值,检查是否是正确答案 if (correctOptionIds.contains(detail.getOptionId())) { - // 查找选中选项的分值 - PsyQuestionnaireOption selectedOption = allOptions.stream() - .filter(opt -> opt.getOptionId().equals(detail.getOptionId())) - .findFirst() - .orElse(null); - - if (selectedOption != null && selectedOption.getOptionScore() != null) - { - return selectedOption.getOptionScore(); - } return itemScore; } diff --git a/ry-xinli-system/src/main/java/com/ddnai/system/service/impl/psychology/PsyWarningServiceImpl.java b/ry-xinli-system/src/main/java/com/ddnai/system/service/impl/psychology/PsyWarningServiceImpl.java index 74755b7f..a15b6686 100644 --- a/ry-xinli-system/src/main/java/com/ddnai/system/service/impl/psychology/PsyWarningServiceImpl.java +++ b/ry-xinli-system/src/main/java/com/ddnai/system/service/impl/psychology/PsyWarningServiceImpl.java @@ -19,6 +19,8 @@ import com.ddnai.system.service.psychology.IPsyWarningRuleService; import com.ddnai.system.service.psychology.IPsyWarningService; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * 危机预警 服务层实现 @@ -28,6 +30,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Service public class PsyWarningServiceImpl implements IPsyWarningService { + private static final Logger log = LoggerFactory.getLogger(PsyWarningServiceImpl.class); + @Autowired private PsyWarningMapper warningMapper; @@ -122,8 +126,10 @@ public class PsyWarningServiceImpl implements IPsyWarningService List rules = warningRuleService.selectEnabledWarningRuleListByScaleId(assessment.getScaleId()); if (rules == null || rules.isEmpty()) { + log.warn("没有找到启用的预警规则 - 测评ID: {}, 量表ID: {}", assessmentId, assessment.getScaleId()); return 0; // 没有预警规则,不创建预警 } + log.info("找到启用的预警规则 - 测评ID: {}, 量表ID: {}, 规则数量: {}", assessmentId, assessment.getScaleId(), rules.size()); // 4. 先检查并自动解除该用户的旧预警(基于新的测评分数) checkAndAutoRelieveWarnings(assessment, factorScores, rules); @@ -169,27 +175,49 @@ public class PsyWarningServiceImpl implements IPsyWarningService BigDecimal totalScore = assessment.getTotalScore(); if (totalScore != null) { + log.info("检查总分预警 - 测评ID: {}, 总分: {}, 规则数量: {}", assessmentId, totalScore, rules.size()); for (PsyWarningRule rule : rules) { // 只处理总分配置(factorId为null的规则) if (rule.getFactorId() != null) { + log.debug("跳过因子规则 - 规则ID: {}, 因子ID: {}", rule.getRuleId(), rule.getFactorId()); continue; // 跳过因子规则 } + log.info("检查总分规则 - 规则ID: {}, 规则名称: {}, 分值范围: {} - {}", + rule.getRuleId(), rule.getRuleName(), rule.getScoreMin(), rule.getScoreMax()); + // 检查分值范围 - if (matchScoreRule(totalScore, null, rule)) + boolean matched = matchScoreRule(totalScore, null, rule); + log.info("分值匹配结果 - 规则ID: {}, 总分: {}, 匹配: {}", rule.getRuleId(), totalScore, matched); + + if (matched) { PsyWarning warning = createWarning(assessment, rule, totalScore, null); if (warning != null) { - insertWarning(warning); - warningCount++; + int insertResult = insertWarning(warning); + if (insertResult > 0) + { + warningCount++; + log.info("创建预警成功 - 预警ID: {}, 规则ID: {}, 总分: {}", + warning.getWarningId(), rule.getRuleId(), totalScore); + } + else + { + log.error("创建预警失败 - 规则ID: {}, 总分: {}", rule.getRuleId(), totalScore); + } } } } } + else + { + log.warn("测评总分为空,无法检查总分预警 - 测评ID: {}", assessmentId); + } + log.info("预警检查完成 - 测评ID: {}, 创建预警数量: {}", assessmentId, warningCount); return warningCount; } @@ -233,8 +261,8 @@ public class PsyWarningServiceImpl implements IPsyWarningService percentileMatch = percentile.compareTo(rule.getPercentileMax()) <= 0; } - // 如果规则设置了百分位,优先使用百分位;否则使用分值 - if (rule.getPercentileMin() != null || rule.getPercentileMax() != null) + // 如果规则设置了百分位且提供了百分位值,优先使用百分位;否则使用分值 + if (percentile != null && (rule.getPercentileMin() != null || rule.getPercentileMax() != null)) { return percentileMatch; } diff --git a/ry-xinli-system/src/main/resources/mapper/system/psychology/PsyScalePermissionMapper.xml b/ry-xinli-system/src/main/resources/mapper/system/psychology/PsyScalePermissionMapper.xml index 6efaca34..8da382f5 100644 --- a/ry-xinli-system/src/main/resources/mapper/system/psychology/PsyScalePermissionMapper.xml +++ b/ry-xinli-system/src/main/resources/mapper/system/psychology/PsyScalePermissionMapper.xml @@ -176,4 +176,3 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - diff --git a/xinli-ui/src/views/psychology/permission/index.vue b/xinli-ui/src/views/psychology/permission/index.vue index 294ea473..d96c3e67 100644 --- a/xinli-ui/src/views/psychology/permission/index.vue +++ b/xinli-ui/src/views/psychology/permission/index.vue @@ -16,8 +16,8 @@ + :label="user.nickName ? `${user.nickName}(${user.userName})` : user.userName" + :value="Number(user.userId)"> @@ -101,8 +101,8 @@ + :label="user.nickName ? `${user.nickName}(${user.userName})` : user.userName" + :value="Number(user.userId)"> @@ -220,8 +220,11 @@ export default { }, /** 加载用户列表 */ loadUsers() { - listUser({ status: '0' }).then(response => { - this.userList = response.rows || []; + listUser({ status: '0', pageNum: 1, pageSize: 1000 }).then(response => { + this.userList = (response.rows || []).map(user => ({ + ...user, + userId: Number(user.userId) // 确保userId是数字类型 + })); }); }, // 取消按钮 @@ -272,7 +275,13 @@ export default { this.reset(); const permissionId = row.permissionId || this.ids[0]; getPermission(permissionId).then(response => { - this.form = response.data; + const data = response.data || {}; + // 确保userId类型正确(转换为数字或undefined) + this.form = { + ...data, + userId: data.userId ? Number(data.userId) : undefined, + scaleId: data.scaleId ? Number(data.scaleId) : undefined + }; this.open = true; this.title = "修改量表权限"; }); @@ -281,14 +290,21 @@ export default { submitForm() { this.$refs["form"].validate(valid => { if (valid) { + // 准备提交数据,确保类型正确 + const submitData = { + ...this.form, + userId: this.form.userId ? Number(this.form.userId) : null, + scaleId: this.form.scaleId ? Number(this.form.scaleId) : undefined + }; + if (this.form.permissionId != undefined) { - updatePermission(this.form).then(response => { + updatePermission(submitData).then(response => { this.$modal.msgSuccess("修改成功"); this.open = false; this.getList(); }); } else { - addPermission(this.form).then(response => { + addPermission(submitData).then(response => { this.$modal.msgSuccess("新增成功"); this.open = false; this.getList();