MBTI量表适配优化;个人报告分值判断优化
This commit is contained in:
parent
8931496113
commit
580075b0ce
|
@ -65,10 +65,11 @@ public interface CacheNames {
|
||||||
*/
|
*/
|
||||||
String ONLINE_TOKEN = "online_tokens";
|
String ONLINE_TOKEN = "online_tokens";
|
||||||
String SYS_QUESTION_ANSWER = "scale:question_answer";
|
String SYS_QUESTION_ANSWER = "scale:question_answer";
|
||||||
|
String SYS_ANSWER = "scale:answer#30d";
|
||||||
|
String SYS_SCALE_FACTOR = "scale:factor";
|
||||||
|
|
||||||
String SYS_SCALE_FACTOR = "scale:factor";
|
String MAP_SCALE_QUESTION = "scale:map:question";
|
||||||
|
String MAP_SCALE_ANSWER = "scale:map:answer";
|
||||||
|
|
||||||
String MAP_SCALE_QUESTION = "scale:map:question";
|
|
||||||
String MAP_SCALE_ANSWER = "scale:map:answer";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package org.dromara.scale.constant;
|
||||||
|
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
|
|
||||||
|
public enum MBTICharEnum {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
E( "E"),
|
||||||
|
I( "I"),
|
||||||
|
S( "S"),
|
||||||
|
N( "N"),
|
||||||
|
T( "T"),
|
||||||
|
F( "F"),
|
||||||
|
J( "J"),
|
||||||
|
P( "P");
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
MBTICharEnum( String name) {
|
||||||
|
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
public static MBTICharEnum getByName(String name) {
|
||||||
|
if (StringUtils.isEmpty(name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MBTICharEnum[] flagEnum = MBTICharEnum.values();
|
||||||
|
for (int i = 0; i < flagEnum.length; i++){
|
||||||
|
if(flagEnum[i].getName().equals(name)){
|
||||||
|
return flagEnum[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -46,6 +46,11 @@ public class SysScaleAnswer {
|
||||||
*/
|
*/
|
||||||
private BigDecimal score;
|
private BigDecimal score;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得分类型
|
||||||
|
*/
|
||||||
|
private String scoreType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 展示类型
|
* 展示类型
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -50,6 +50,12 @@ public class SysScaleAnswerBo {
|
||||||
@NotNull(message = "得分不能为空", groups = {AddGroup.class, EditGroup.class})
|
@NotNull(message = "得分不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||||
private BigDecimal score;
|
private BigDecimal score;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得分类型
|
||||||
|
*/
|
||||||
|
private String scoreType;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 展示类型
|
* 展示类型
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -50,6 +50,11 @@ public class SysScaleAnswerVo implements Serializable {
|
||||||
@ExcelProperty(value = "得分")
|
@ExcelProperty(value = "得分")
|
||||||
private BigDecimal score;
|
private BigDecimal score;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得分类型
|
||||||
|
*/
|
||||||
|
private String scoreType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 展示选择
|
* 展示选择
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,4 +18,6 @@ public interface ISysScaleAnswerService {
|
||||||
|
|
||||||
Map<String, List<SysScaleAnswerVo>> getScaleAnswerMap(Long scaleId);
|
Map<String, List<SysScaleAnswerVo>> getScaleAnswerMap(Long scaleId);
|
||||||
|
|
||||||
|
SysScaleAnswerVo queryQuestionAnswerById(Long answerId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,9 +174,11 @@ public class SysEvaluationRecordServiceImpl implements ISysEvaluationRecordServi
|
||||||
answerScore = answerScore + "↑";
|
answerScore = answerScore + "↑";
|
||||||
range.append(minValue.doubleValue());
|
range.append(minValue.doubleValue());
|
||||||
}
|
}
|
||||||
} else {
|
} else if (maxFlag) {
|
||||||
range.append(maxValue.doubleValue());
|
range.append(maxValue.doubleValue());
|
||||||
answerScore = answerScore + "↓";
|
answerScore = answerScore + "↓";
|
||||||
|
} else {
|
||||||
|
range.append("无");
|
||||||
}
|
}
|
||||||
//处理因子得分表格
|
//处理因子得分表格
|
||||||
RowRenderData one = Rows.of(factorName, answerVo.getQuestionNum().toString(),
|
RowRenderData one = Rows.of(factorName, answerVo.getQuestionNum().toString(),
|
||||||
|
|
|
@ -63,11 +63,18 @@ public class SysScaleAnswerServiceImpl implements ISysScaleAnswerService {
|
||||||
}
|
}
|
||||||
return questionAnswerVos;
|
return questionAnswerVos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable(cacheNames = CacheNames.MAP_SCALE_ANSWER, key = "#scaleId")
|
@Cacheable(cacheNames = CacheNames.MAP_SCALE_ANSWER, key = "#scaleId")
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<SysScaleAnswerVo>> getScaleAnswerMap(Long scaleId) {
|
public Map<String, List<SysScaleAnswerVo>> getScaleAnswerMap(Long scaleId) {
|
||||||
List<SysScaleAnswerVo> scaleAnswerVos = baseMapper.selectVoList(
|
List<SysScaleAnswerVo> scaleAnswerVos = baseMapper.selectVoList(
|
||||||
new LambdaQueryWrapper<SysScaleAnswer>().eq(SysScaleAnswer::getScaleId, scaleId));
|
new LambdaQueryWrapper<SysScaleAnswer>().eq(SysScaleAnswer::getScaleId, scaleId));
|
||||||
return scaleAnswerVos.stream().collect(Collectors.groupingBy(e -> e.getQuestionId().toString()));
|
return scaleAnswerVos.stream().collect(Collectors.groupingBy(e -> e.getQuestionId().toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Cacheable(cacheNames = CacheNames.SYS_ANSWER, key = "#answerId")
|
||||||
|
@Override
|
||||||
|
public SysScaleAnswerVo queryQuestionAnswerById(Long answerId) {
|
||||||
|
return baseMapper.selectVoById(answerId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,7 @@ import org.dromara.common.core.enums.UserType;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.MapstructUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.scale.constant.ScaleDimensionEnum;
|
import org.dromara.scale.constant.*;
|
||||||
import org.dromara.scale.constant.ScoreRuleTypeEnum;
|
|
||||||
import org.dromara.scale.constant.SituationEnum;
|
|
||||||
import org.dromara.scale.constant.StatusEnum;
|
|
||||||
import org.dromara.scale.domain.*;
|
import org.dromara.scale.domain.*;
|
||||||
import org.dromara.scale.domain.bo.SubmitAnswerBo;
|
import org.dromara.scale.domain.bo.SubmitAnswerBo;
|
||||||
import org.dromara.scale.domain.bo.SysEvaluationAnswerBo;
|
import org.dromara.scale.domain.bo.SysEvaluationAnswerBo;
|
||||||
|
@ -30,6 +27,7 @@ import java.math.BigDecimal;
|
||||||
import java.math.MathContext;
|
import java.math.MathContext;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -142,6 +140,7 @@ public class WebServiceImpl implements IWebService {
|
||||||
}
|
}
|
||||||
boolean allowQueryResult = true;
|
boolean allowQueryResult = true;
|
||||||
Long scaleId = bo.getScaleId();
|
Long scaleId = bo.getScaleId();
|
||||||
|
SysScale sysScale = scaleMapper.selectById(scaleId);
|
||||||
Map<String, List<SysScaleAnswerVo>> answerMapByQuestion = scaleAnswerService.getScaleAnswerMap(scaleId);
|
Map<String, List<SysScaleAnswerVo>> answerMapByQuestion = scaleAnswerService.getScaleAnswerMap(scaleId);
|
||||||
int keySize = answerMapByQuestion.keySet().size();
|
int keySize = answerMapByQuestion.keySet().size();
|
||||||
if (ObjectUtil.isEmpty(answerList)) {
|
if (ObjectUtil.isEmpty(answerList)) {
|
||||||
|
@ -159,8 +158,15 @@ public class WebServiceImpl implements IWebService {
|
||||||
}
|
}
|
||||||
List<SysEvaluationAnswer> answerAdd = MapstructUtils.convert(answerList, SysEvaluationAnswer.class);
|
List<SysEvaluationAnswer> answerAdd = MapstructUtils.convert(answerList, SysEvaluationAnswer.class);
|
||||||
evaluationAnswerMapper.insertBatch(answerAdd);
|
evaluationAnswerMapper.insertBatch(answerAdd);
|
||||||
//计算
|
//
|
||||||
List<SysEvaluationConclusionVo> list = calculateEvaluationResult(scaleId, answerList);
|
List<SysEvaluationConclusionVo> list;
|
||||||
|
if (sysScale.getScaleName().contains("MBTI")) {
|
||||||
|
//MBTI 另外处理
|
||||||
|
list = calculateMBTIResult(scaleId, answerList);
|
||||||
|
} else {
|
||||||
|
//计算
|
||||||
|
list = calculateEvaluationResult(scaleId, answerList);
|
||||||
|
}
|
||||||
List<SysEvaluationConclusion> conclusionAdd = MapstructUtils.convert(list, SysEvaluationConclusion.class);
|
List<SysEvaluationConclusion> conclusionAdd = MapstructUtils.convert(list, SysEvaluationConclusion.class);
|
||||||
evaluationConclusionMapper.insertBatch(conclusionAdd);
|
evaluationConclusionMapper.insertBatch(conclusionAdd);
|
||||||
//更新记录表完成
|
//更新记录表完成
|
||||||
|
@ -210,7 +216,9 @@ public class WebServiceImpl implements IWebService {
|
||||||
private List<SysEvaluationConclusionVo> calculateEvaluationResult(Long scaleId, List<SysEvaluationAnswerBo> answerList) {
|
private List<SysEvaluationConclusionVo> calculateEvaluationResult(Long scaleId, List<SysEvaluationAnswerBo> answerList) {
|
||||||
Long recordId = answerList.get(0).getRecordId();
|
Long recordId = answerList.get(0).getRecordId();
|
||||||
//暂时使用string解决redis转换问题
|
//暂时使用string解决redis转换问题
|
||||||
|
//key为factorId
|
||||||
Map<String, List<String>> questionMapByFactor = scaleFactorService.getQuestionMapByFactor(scaleId);
|
Map<String, List<String>> questionMapByFactor = scaleFactorService.getQuestionMapByFactor(scaleId);
|
||||||
|
//key为questionID
|
||||||
Map<String, List<SysScaleAnswerVo>> answerMapByQuestion = scaleAnswerService.getScaleAnswerMap(scaleId);
|
Map<String, List<SysScaleAnswerVo>> answerMapByQuestion = scaleAnswerService.getScaleAnswerMap(scaleId);
|
||||||
|
|
||||||
List<SysScaleFactorVo> scaleFactorList = scaleFactorService.getScaleEvalItemList(scaleId);
|
List<SysScaleFactorVo> scaleFactorList = scaleFactorService.getScaleEvalItemList(scaleId);
|
||||||
|
@ -303,7 +311,7 @@ public class WebServiceImpl implements IWebService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//假如未对应上说明这个量表配置有问题联系管理员
|
//假如未对应上说明这个量表配置有问题联系管理员
|
||||||
if(Objects.isNull(evalConclusion.getFactorRangeId())){
|
if (Objects.isNull(evalConclusion.getFactorRangeId())) {
|
||||||
throw new ServiceException("量表配置项有问题,请联系管理员检查!");
|
throw new ServiceException("量表配置项有问题,请联系管理员检查!");
|
||||||
}
|
}
|
||||||
if (used.contains(evalConclusion.getSituation())) {
|
if (used.contains(evalConclusion.getSituation())) {
|
||||||
|
@ -375,4 +383,69 @@ public class WebServiceImpl implements IWebService {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<SysEvaluationConclusionVo> calculateMBTIResult(Long scaleId, List<SysEvaluationAnswerBo> answerList) {
|
||||||
|
Long recordId = answerList.get(0).getRecordId();
|
||||||
|
//key为questionID
|
||||||
|
ConcurrentHashMap<String, Integer> charNumMap = new ConcurrentHashMap<>(8);
|
||||||
|
for (MBTICharEnum one : MBTICharEnum.values()) {
|
||||||
|
charNumMap.put(one.getName(), 0);
|
||||||
|
}
|
||||||
|
for (SysEvaluationAnswerBo evaluationAnswer : answerList) {
|
||||||
|
SysScaleAnswerVo answer = scaleAnswerService.queryQuestionAnswerById(evaluationAnswer.getAnswerId());
|
||||||
|
String scoreType = answer.getScoreType();
|
||||||
|
MBTICharEnum charByNum = MBTICharEnum.getByName(scoreType);
|
||||||
|
if (ObjectUtil.isEmpty(charByNum)) {
|
||||||
|
throw new ServiceException("量表配置项有问题,请联系管理员检查!");
|
||||||
|
}
|
||||||
|
Integer num = charNumMap.get(scoreType);
|
||||||
|
charNumMap.put(scoreType, num + 1);
|
||||||
|
}
|
||||||
|
List<String> resultList = new ArrayList<>(4);
|
||||||
|
Integer eNum = charNumMap.get(MBTICharEnum.E.getName());
|
||||||
|
Integer iNum = charNumMap.get(MBTICharEnum.I.getName());
|
||||||
|
boolean a = eNum > iNum ? resultList.add(MBTICharEnum.E.getName()) : resultList.add(MBTICharEnum.I.getName());
|
||||||
|
Integer sNum = charNumMap.get(MBTICharEnum.S.getName());
|
||||||
|
Integer nNum = charNumMap.get(MBTICharEnum.N.getName());
|
||||||
|
boolean b = sNum > nNum ? resultList.add(MBTICharEnum.S.getName()) : resultList.add(MBTICharEnum.N.getName());
|
||||||
|
Integer tNum = charNumMap.get(MBTICharEnum.T.getName());
|
||||||
|
Integer fNum = charNumMap.get(MBTICharEnum.F.getName());
|
||||||
|
boolean c = tNum > fNum ? resultList.add(MBTICharEnum.T.getName()) : resultList.add(MBTICharEnum.F.getName());
|
||||||
|
Integer jNum = charNumMap.get(MBTICharEnum.J.getName());
|
||||||
|
Integer pNum = charNumMap.get(MBTICharEnum.P.getName());
|
||||||
|
boolean d = jNum > pNum ? resultList.add(MBTICharEnum.J.getName()) : resultList.add(MBTICharEnum.P.getName());
|
||||||
|
|
||||||
|
String collect = resultList.stream().sorted().collect(Collectors.joining());
|
||||||
|
List<SysScaleFactorVo> scaleFactorList = scaleFactorService.getScaleEvalItemList(scaleId);
|
||||||
|
List<SysEvaluationConclusionVo> list = new ArrayList<>(1);
|
||||||
|
for (SysScaleFactorVo scaleFactor : scaleFactorList) {
|
||||||
|
|
||||||
|
String factorName = scaleFactor.getFactorName().trim();
|
||||||
|
String split = Arrays.stream(factorName.split("")).sorted().collect(Collectors.joining());
|
||||||
|
if (Objects.equals(collect, split)) {
|
||||||
|
SysEvaluationConclusionVo evalConclusion = new SysEvaluationConclusionVo();
|
||||||
|
evalConclusion.setFactorName(scaleFactor.getFactorName());
|
||||||
|
evalConclusion.setFactorId(scaleFactor.getFactorId());
|
||||||
|
evalConclusion.setRecordId(recordId);
|
||||||
|
evalConclusion.setStatus(StatusEnum.IN_USE.getValue());
|
||||||
|
evalConclusion.setScore(BigDecimal.ZERO);
|
||||||
|
evalConclusion.setScoreRate(BigDecimal.ZERO);
|
||||||
|
evalConclusion.setWarnStatus(StatusEnum.DISABLED.getValue());
|
||||||
|
List<SysScaleFactorRangeVo> factorRangeList = scaleFactor.getFactorRangeList();
|
||||||
|
if (factorRangeList.size() == 1) {
|
||||||
|
evalConclusion.setEvalDesc(factorRangeList.get(0).getEvalDesc());
|
||||||
|
evalConclusion.setEvalPropose(factorRangeList.get(0).getEvalPropose());
|
||||||
|
evalConclusion.setFactorRangeId(factorRangeList.get(0).getRangeId());
|
||||||
|
evalConclusion.setSituation(factorRangeList.get(0).getSituation());
|
||||||
|
evalConclusion.setSituationName(SituationEnum.getNameByCode(factorRangeList.get(0).getSituation()));
|
||||||
|
} else {
|
||||||
|
throw new ServiceException("量表配置项有问题,请联系管理员检查!");
|
||||||
|
}
|
||||||
|
list.add(evalConclusion);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue