You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
6.3 KiB
Java
182 lines
6.3 KiB
Java
package com.supervision.manage.dto;
|
|
|
|
import cn.hutool.core.annotation.Alias;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.supervision.model.AskTemplateQuestionLibrary;
|
|
import com.supervision.model.CommonDic;
|
|
import lombok.Data;
|
|
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Data
|
|
public class UploadQuestionLibraryDTO {
|
|
|
|
/**
|
|
* 问诊类目1
|
|
*/
|
|
@Alias(value = "问诊类目Ⅰ")
|
|
private String questionTypeOne;
|
|
|
|
/**
|
|
* 问诊类目2 对应于 vp_ask_template_question_library 表中的 dict_id对应的 name_zh
|
|
*/
|
|
@Alias(value = "问诊类目Ⅱ")
|
|
private String questionTypeTwo;
|
|
|
|
/**
|
|
* 问题
|
|
*/
|
|
@Alias(value = "* 知识")
|
|
private String question;
|
|
|
|
/**
|
|
* 回答
|
|
*/
|
|
@Alias(value = "* 回答")
|
|
private String answer;
|
|
|
|
|
|
@Alias(value = "错误信息")
|
|
private static String errorReason;
|
|
|
|
private List<UploadQuestionLibraryDTO.ErrorCodeEnum> errorCodeEnums = new ArrayList<>();
|
|
|
|
private String dictId;
|
|
|
|
|
|
public static final List<String> READ_ANSWER_VIDEO_TITLE = CollUtil.newArrayList("问诊类目Ⅰ", "问诊类目Ⅱ", "* 知识", "* 回答");
|
|
|
|
public static final List<String> WRITE_ANSWER_VIDEO_TITLE = CollUtil.newArrayList("问诊类目Ⅰ", "问诊类目Ⅱ", "* 知识", "* 回答","错误原因");
|
|
|
|
public static final Map<String,String> READ_HEADER_ALIAS = getReadAlias();
|
|
|
|
public static final Map<String,String> WRITE_HEADER_ALIAS = getWriteAlias();
|
|
|
|
|
|
public void doAction(List<AskTemplateQuestionLibrary> questionLibraryList, List<CommonDic> questionTypeDicList){
|
|
this.absentCheck();
|
|
this.matchQuestion(questionLibraryList);
|
|
this.matchQuestionDicId(questionTypeDicList);
|
|
}
|
|
|
|
|
|
|
|
public Map<String,Object> toExcelMap(){
|
|
Map<String,Object> map = new HashMap<>();
|
|
map.put("questionTypeOne",this.questionTypeOne);
|
|
map.put("questionTypeTwo",this.questionTypeTwo);
|
|
map.put("question",this.question);
|
|
map.put("answer",this.answer);
|
|
if (CollUtil.isNotEmpty(errorCodeEnums)){
|
|
String errorMessage = errorCodeEnums.stream().map(i -> i.desc).collect(Collectors.joining(";"));
|
|
map.put("errorReason",errorMessage);
|
|
}
|
|
return map;
|
|
}
|
|
public void absentCheck(){
|
|
/*if (StrUtil.isEmpty(questionTypeOne)){
|
|
errorCodeEnums.add(UploadQuestionLibraryDTO.ErrorCodeEnum.QUESTION_TYPE_ONE_EMPTY);
|
|
}
|
|
if (StrUtil.isEmpty(questionTypeTwo)){
|
|
errorCodeEnums.add(UploadQuestionLibraryDTO.ErrorCodeEnum.QUESTION_TYPE_TWO_EMPTY);
|
|
}*/
|
|
if (StrUtil.isEmpty(question)){
|
|
errorCodeEnums.add(UploadQuestionLibraryDTO.ErrorCodeEnum.QUESTION_EMPTY);
|
|
}
|
|
if (StrUtil.isEmpty(answer)){
|
|
errorCodeEnums.add(UploadQuestionLibraryDTO.ErrorCodeEnum.ANSWER_EMPTY);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 匹配问题库
|
|
* @param questionLibraryList 问题库
|
|
*/
|
|
public void matchQuestion(List<AskTemplateQuestionLibrary> questionLibraryList){
|
|
if (StrUtil.isEmpty(this.question)){
|
|
return;
|
|
}
|
|
for (AskTemplateQuestionLibrary questionLibrary : questionLibraryList) {
|
|
String description = questionLibrary.getDescription();
|
|
List<String> questionList = questionLibrary.getQuestion();
|
|
if (this.question.equals(description)){
|
|
errorCodeEnums.add(UploadQuestionLibraryDTO.ErrorCodeEnum.QUESTION_REPEAT);
|
|
return;
|
|
}
|
|
if (CollUtil.isNotEmpty(questionList) && questionList.contains(this.question)){
|
|
errorCodeEnums.add(UploadQuestionLibraryDTO.ErrorCodeEnum.QUESTION_REPEAT);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
public void matchQuestionDicId(List<CommonDic> questionTypeDicList){
|
|
if (StrUtil.isEmpty(this.questionTypeTwo)){
|
|
return;
|
|
}
|
|
|
|
for (CommonDic questionTypeDic : questionTypeDicList) {
|
|
if (this.questionTypeTwo.equals(questionTypeDic.getNameZh())){
|
|
this.dictId = String.valueOf(questionTypeDic.getId());
|
|
return;
|
|
}
|
|
}
|
|
for (CommonDic questionTypeDic : questionTypeDicList) {
|
|
if (this.questionTypeTwo.equals(questionTypeDic.getNameZh())) {
|
|
String nameZhPath = questionTypeDic.getNameZhPath();
|
|
if (StrUtil.isEmpty(nameZhPath)) {
|
|
continue;
|
|
}
|
|
// 一共两个级别
|
|
List<String> split = StrUtil.split(nameZhPath, "/");
|
|
if (!this.questionTypeOne.equals(CollUtil.getFirst(split))) {
|
|
// 如果类目一匹配不正确,也不进行处理
|
|
continue;
|
|
}
|
|
this.dictId = String.valueOf(questionTypeDic.getId());
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private static Map<String,String> getReadAlias(){
|
|
Map<String, String> map = new LinkedHashMap<>();
|
|
map.put("问诊类目Ⅰ","questionTypeOne");
|
|
map.put("问诊类目Ⅱ", "questionTypeTwo");
|
|
map.put("* 知识", "question");
|
|
map.put("* 回答", "answer");
|
|
return map;
|
|
}
|
|
|
|
private static Map<String,String> getWriteAlias(){
|
|
Map<String, String> map = new LinkedHashMap<>();
|
|
map.put("questionTypeOne","问诊类目Ⅰ");
|
|
map.put("questionTypeTwo", "问诊类目Ⅱ");
|
|
map.put("question", "* 知识");
|
|
map.put("answer", "* 回答");
|
|
map.put("errorReason", "错误原因");
|
|
return map;
|
|
}
|
|
public enum ErrorCodeEnum{
|
|
QUESTION_TYPE_ONE_EMPTY("0001","问诊类目1不能为空"),
|
|
QUESTION_TYPE_TWO_EMPTY("0002","问诊类目2不能为空"),
|
|
QUESTION_EMPTY("0003","知识不能为空"),
|
|
ANSWER_EMPTY("0004","回答不能为空"),
|
|
ANSWER_VIDEO_NAME_EMPTY("0005","视频名称不能为空"),
|
|
QUESTION_NOT_FIND("40001","知识未找到"),
|
|
ANSWER_VIDEO_NAME_NOT_FIND("40002","视频不存在"),
|
|
DICE_NOT_FIND("40003","类目字典码值未找到"),
|
|
|
|
QUESTION_REPEAT("50001","知识数据重复");
|
|
private String code;
|
|
private String desc;
|
|
|
|
ErrorCodeEnum(String code, String desc) {
|
|
this.code = code;
|
|
this.desc = desc;
|
|
}
|
|
}
|
|
}
|