更新权限管理和问卷相关功能
This commit is contained in:
parent
b2dad013ab
commit
e1a5e76be6
|
|
@ -558,6 +558,7 @@ public class PsyQuestionnaireAnswerServiceImpl implements IPsyQuestionnaireAnswe
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算单选题得分
|
* 计算单选题得分
|
||||||
|
* 对于问卷,直接使用选项的分值,不检查是否是正确答案
|
||||||
*/
|
*/
|
||||||
private BigDecimal calculateRadioScore(PsyQuestionnaireAnswerDetail detail, Set<Long> correctOptionIds,
|
private BigDecimal calculateRadioScore(PsyQuestionnaireAnswerDetail detail, Set<Long> correctOptionIds,
|
||||||
BigDecimal itemScore, List<PsyQuestionnaireOption> allOptions)
|
BigDecimal itemScore, List<PsyQuestionnaireOption> allOptions)
|
||||||
|
|
@ -567,19 +568,21 @@ public class PsyQuestionnaireAnswerServiceImpl implements IPsyQuestionnaireAnswe
|
||||||
return BigDecimal.ZERO;
|
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()))
|
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;
|
return itemScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -657,6 +660,7 @@ public class PsyQuestionnaireAnswerServiceImpl implements IPsyQuestionnaireAnswe
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算判断题得分
|
* 计算判断题得分
|
||||||
|
* 对于问卷,直接使用选项的分值,不检查是否是正确答案
|
||||||
*/
|
*/
|
||||||
private BigDecimal calculateBooleanScore(PsyQuestionnaireAnswerDetail detail, Set<Long> correctOptionIds,
|
private BigDecimal calculateBooleanScore(PsyQuestionnaireAnswerDetail detail, Set<Long> correctOptionIds,
|
||||||
BigDecimal itemScore, List<PsyQuestionnaireOption> allOptions)
|
BigDecimal itemScore, List<PsyQuestionnaireOption> allOptions)
|
||||||
|
|
@ -666,19 +670,21 @@ public class PsyQuestionnaireAnswerServiceImpl implements IPsyQuestionnaireAnswe
|
||||||
return BigDecimal.ZERO;
|
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()))
|
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;
|
return itemScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ import com.ddnai.system.service.psychology.IPsyWarningRuleService;
|
||||||
import com.ddnai.system.service.psychology.IPsyWarningService;
|
import com.ddnai.system.service.psychology.IPsyWarningService;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
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
|
@Service
|
||||||
public class PsyWarningServiceImpl implements IPsyWarningService
|
public class PsyWarningServiceImpl implements IPsyWarningService
|
||||||
{
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(PsyWarningServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PsyWarningMapper warningMapper;
|
private PsyWarningMapper warningMapper;
|
||||||
|
|
||||||
|
|
@ -122,8 +126,10 @@ public class PsyWarningServiceImpl implements IPsyWarningService
|
||||||
List<PsyWarningRule> rules = warningRuleService.selectEnabledWarningRuleListByScaleId(assessment.getScaleId());
|
List<PsyWarningRule> rules = warningRuleService.selectEnabledWarningRuleListByScaleId(assessment.getScaleId());
|
||||||
if (rules == null || rules.isEmpty())
|
if (rules == null || rules.isEmpty())
|
||||||
{
|
{
|
||||||
|
log.warn("没有找到启用的预警规则 - 测评ID: {}, 量表ID: {}", assessmentId, assessment.getScaleId());
|
||||||
return 0; // 没有预警规则,不创建预警
|
return 0; // 没有预警规则,不创建预警
|
||||||
}
|
}
|
||||||
|
log.info("找到启用的预警规则 - 测评ID: {}, 量表ID: {}, 规则数量: {}", assessmentId, assessment.getScaleId(), rules.size());
|
||||||
|
|
||||||
// 4. 先检查并自动解除该用户的旧预警(基于新的测评分数)
|
// 4. 先检查并自动解除该用户的旧预警(基于新的测评分数)
|
||||||
checkAndAutoRelieveWarnings(assessment, factorScores, rules);
|
checkAndAutoRelieveWarnings(assessment, factorScores, rules);
|
||||||
|
|
@ -169,27 +175,49 @@ public class PsyWarningServiceImpl implements IPsyWarningService
|
||||||
BigDecimal totalScore = assessment.getTotalScore();
|
BigDecimal totalScore = assessment.getTotalScore();
|
||||||
if (totalScore != null)
|
if (totalScore != null)
|
||||||
{
|
{
|
||||||
|
log.info("检查总分预警 - 测评ID: {}, 总分: {}, 规则数量: {}", assessmentId, totalScore, rules.size());
|
||||||
for (PsyWarningRule rule : rules)
|
for (PsyWarningRule rule : rules)
|
||||||
{
|
{
|
||||||
// 只处理总分配置(factorId为null的规则)
|
// 只处理总分配置(factorId为null的规则)
|
||||||
if (rule.getFactorId() != null)
|
if (rule.getFactorId() != null)
|
||||||
{
|
{
|
||||||
|
log.debug("跳过因子规则 - 规则ID: {}, 因子ID: {}", rule.getRuleId(), rule.getFactorId());
|
||||||
continue; // 跳过因子规则
|
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);
|
PsyWarning warning = createWarning(assessment, rule, totalScore, null);
|
||||||
if (warning != null)
|
if (warning != null)
|
||||||
{
|
{
|
||||||
insertWarning(warning);
|
int insertResult = insertWarning(warning);
|
||||||
warningCount++;
|
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;
|
return warningCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,8 +261,8 @@ public class PsyWarningServiceImpl implements IPsyWarningService
|
||||||
percentileMatch = percentile.compareTo(rule.getPercentileMax()) <= 0;
|
percentileMatch = percentile.compareTo(rule.getPercentileMax()) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果规则设置了百分位,优先使用百分位;否则使用分值
|
// 如果规则设置了百分位且提供了百分位值,优先使用百分位;否则使用分值
|
||||||
if (rule.getPercentileMin() != null || rule.getPercentileMax() != null)
|
if (percentile != null && (rule.getPercentileMin() != null || rule.getPercentileMax() != null))
|
||||||
{
|
{
|
||||||
return percentileMatch;
|
return percentileMatch;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,4 +176,3 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@
|
||||||
<el-option
|
<el-option
|
||||||
v-for="user in userList"
|
v-for="user in userList"
|
||||||
:key="user.userId"
|
:key="user.userId"
|
||||||
:label="user.userName"
|
:label="user.nickName ? `${user.nickName}(${user.userName})` : user.userName"
|
||||||
:value="user.userId">
|
:value="Number(user.userId)">
|
||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -101,8 +101,8 @@
|
||||||
<el-option
|
<el-option
|
||||||
v-for="user in userList"
|
v-for="user in userList"
|
||||||
:key="user.userId"
|
:key="user.userId"
|
||||||
:label="user.userName"
|
:label="user.nickName ? `${user.nickName}(${user.userName})` : user.userName"
|
||||||
:value="user.userId">
|
:value="Number(user.userId)">
|
||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -220,8 +220,11 @@ export default {
|
||||||
},
|
},
|
||||||
/** 加载用户列表 */
|
/** 加载用户列表 */
|
||||||
loadUsers() {
|
loadUsers() {
|
||||||
listUser({ status: '0' }).then(response => {
|
listUser({ status: '0', pageNum: 1, pageSize: 1000 }).then(response => {
|
||||||
this.userList = response.rows || [];
|
this.userList = (response.rows || []).map(user => ({
|
||||||
|
...user,
|
||||||
|
userId: Number(user.userId) // 确保userId是数字类型
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 取消按钮
|
// 取消按钮
|
||||||
|
|
@ -272,7 +275,13 @@ export default {
|
||||||
this.reset();
|
this.reset();
|
||||||
const permissionId = row.permissionId || this.ids[0];
|
const permissionId = row.permissionId || this.ids[0];
|
||||||
getPermission(permissionId).then(response => {
|
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.open = true;
|
||||||
this.title = "修改量表权限";
|
this.title = "修改量表权限";
|
||||||
});
|
});
|
||||||
|
|
@ -281,14 +290,21 @@ export default {
|
||||||
submitForm() {
|
submitForm() {
|
||||||
this.$refs["form"].validate(valid => {
|
this.$refs["form"].validate(valid => {
|
||||||
if (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) {
|
if (this.form.permissionId != undefined) {
|
||||||
updatePermission(this.form).then(response => {
|
updatePermission(submitData).then(response => {
|
||||||
this.$modal.msgSuccess("修改成功");
|
this.$modal.msgSuccess("修改成功");
|
||||||
this.open = false;
|
this.open = false;
|
||||||
this.getList();
|
this.getList();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
addPermission(this.form).then(response => {
|
addPermission(submitData).then(response => {
|
||||||
this.$modal.msgSuccess("新增成功");
|
this.$modal.msgSuccess("新增成功");
|
||||||
this.open = false;
|
this.open = false;
|
||||||
this.getList();
|
this.getList();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user