|
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.ccsens.tcm.bean.dto.CodeVo; |
|
|
|
import com.ccsens.tcm.bean.dto.QuestionDto; |
|
|
|
import com.ccsens.tcm.bean.po.*; |
|
|
|
import com.ccsens.tcm.bean.vo.QuestionVo; |
|
|
|
import com.ccsens.tcm.persist.dao.QuestionDao; |
|
|
@ -15,6 +16,7 @@ import com.ccsens.tcm.persist.mapper.QuestionRecordTimeMapper; |
|
|
|
import com.ccsens.tcm.uitl.Constant; |
|
|
|
import com.ccsens.util.*; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import lombok.Data; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
@ -58,27 +60,31 @@ public class ImportService implements IImportService { |
|
|
|
List<Object[]> reports = PoiUtil.readExce(excelFile, 0, null,1, false); |
|
|
|
log.info("读取数据完成"); |
|
|
|
List<ReportCode> reportList = new ArrayList<>(); |
|
|
|
List<QuestionRecordTime> recordTimes = new ArrayList<>(); |
|
|
|
for (Object[] objs: reports) { |
|
|
|
if (!(objs != null && objs.length >= 2 && !StringUtils.isEmpty(objs[0]) && !StringUtils.isEmpty(objs[1]))) { |
|
|
|
log.info("测评报告单数据不足,跳转下一行"); |
|
|
|
continue; |
|
|
|
} |
|
|
|
ReportCode report = initReport(objs); |
|
|
|
ReportCode report = initReport(objs, recordTimes); |
|
|
|
reportList.add(report); |
|
|
|
} |
|
|
|
if (!reportList.isEmpty()) { |
|
|
|
reportCodeDao.insertBatch(reportList); |
|
|
|
} |
|
|
|
if (CollectionUtil.isNotEmpty(recordTimes)) { |
|
|
|
reportCodeDao.insertTimesBatch(recordTimes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void importBsxg(File excelFile, String codeBsxg) throws Exception { |
|
|
|
log.info("导入试题参数:{}, {}", excelFile, codeBsxg); |
|
|
|
public void importQuestion(File excelFile, String code) throws Exception { |
|
|
|
log.info("导入试题参数:{}, {}", excelFile, code); |
|
|
|
List<String> types = new ArrayList<>(); |
|
|
|
if (Constant.Question.ALL.equalsIgnoreCase(codeBsxg)) { |
|
|
|
if (Constant.Question.ALL.equalsIgnoreCase(code)) { |
|
|
|
types.addAll(Constant.Question.QUESTION_TYPE); |
|
|
|
} else { |
|
|
|
types.add(codeBsxg); |
|
|
|
types.add(code); |
|
|
|
} |
|
|
|
log.info("导入试题类型:{}", types); |
|
|
|
for (String sheetName: types) { |
|
|
@ -106,10 +112,9 @@ public class ImportService implements IImportService { |
|
|
|
} |
|
|
|
// 医院
|
|
|
|
Map<String, Long> hospitalMap = new HashMap<>(); |
|
|
|
hospitals.forEach(hospital -> { |
|
|
|
hospitalMap.put(hospital.getCode(), hospital.getId()); |
|
|
|
}); |
|
|
|
|
|
|
|
hospitals.forEach(hospital -> hospitalMap.put(hospital.getCode(), hospital.getId())); |
|
|
|
List<QuestionHospital> questionHospitals = new ArrayList<>(); |
|
|
|
List<QuestionDto.QuestionHospitalDel> questionHospitalDelList = new ArrayList<>(); |
|
|
|
|
|
|
|
for(Object[] objs : questions) { |
|
|
|
if (objs == null || objs.length < 4 || StringUtils.isEmpty(objs[2])) { |
|
|
@ -121,7 +126,7 @@ public class ImportService implements IImportService { |
|
|
|
String type = String.valueOf(objs[0]); |
|
|
|
switch (type) { |
|
|
|
case "题目" : |
|
|
|
Question question = initQuestion(objs, code, sort,null, hospitalMap); |
|
|
|
Question question = initQuestion(objs, code, sort,null, hospitalMap, questionHospitals, questionHospitalDelList); |
|
|
|
questionId = question.getId(); |
|
|
|
questionList.add(question); |
|
|
|
break; |
|
|
@ -137,7 +142,7 @@ public class ImportService implements IImportService { |
|
|
|
if (optionList.isEmpty()) { |
|
|
|
break; |
|
|
|
} |
|
|
|
Question relevanceQuestion = initQuestion(objs, code, sort, optionId, hospitalMap); |
|
|
|
Question relevanceQuestion = initQuestion(objs, code, sort, optionId, hospitalMap, questionHospitals, questionHospitalDelList); |
|
|
|
questionList.add(relevanceQuestion); |
|
|
|
optionQuestionId = relevanceQuestion.getId(); |
|
|
|
break; |
|
|
@ -159,6 +164,14 @@ public class ImportService implements IImportService { |
|
|
|
if (!optionList.isEmpty()) { |
|
|
|
questionOptionDao.insertBatch(optionList); |
|
|
|
} |
|
|
|
if (CollectionUtil.isNotEmpty(questionHospitalDelList)) { |
|
|
|
questionHospitalDao.deleteBatch(questionHospitalDelList); |
|
|
|
log.info("删除试题和医院的旧关联"); |
|
|
|
} |
|
|
|
if (CollectionUtil.isNotEmpty(questionHospitals)) { |
|
|
|
questionHospitalDao.insertBatch(questionHospitals); |
|
|
|
log.info("批量添加试题和医院的关联"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -195,9 +208,10 @@ public class ImportService implements IImportService { |
|
|
|
/** |
|
|
|
* 初始化报告单对象,若该对象已存在,则返回null |
|
|
|
* @param objs 表格内读取的数据 |
|
|
|
* @param recordTimes |
|
|
|
* @return 返回测试类型 |
|
|
|
*/ |
|
|
|
private ReportCode initReport(Object[] objs) { |
|
|
|
private ReportCode initReport(Object[] objs, List<QuestionRecordTime> recordTimes) { |
|
|
|
ReportCodeExample example = new ReportCodeExample(); |
|
|
|
example.createCriteria().andCodeEqualTo((String) objs[0]); |
|
|
|
List<ReportCode> list = reportCodeDao.selectByExample(example); |
|
|
@ -216,9 +230,9 @@ public class ImportService implements IImportService { |
|
|
|
report.setCode((String) objs[0]); |
|
|
|
report.setName((String) objs[1]); |
|
|
|
report.setParentCode(objs.length > 2 && !StringUtils.isEmpty(objs[2]) ? (String) objs[2] : Constant.STRING_DEFAULT); |
|
|
|
if (objs.length > 3 && objs[3] != null && ((String)objs[3]).length() > 0) { |
|
|
|
// report.setReportType(objs.length > 3 && StringUtil.checkNum(String.valueOf(objs[3]),false)? Byte.parseByte((String) objs[3]) : Constant.NUMBER_DEFAULT);
|
|
|
|
String types = (String)objs[3]; |
|
|
|
int typeIndex = 3; |
|
|
|
if (objs.length > typeIndex && objs[typeIndex] != null && ((String)objs[typeIndex]).length() > 0) { |
|
|
|
String types = (String)objs[typeIndex]; |
|
|
|
String[] split = types.split("[,,]"); |
|
|
|
|
|
|
|
for (String type: split) { |
|
|
@ -228,7 +242,7 @@ public class ImportService implements IImportService { |
|
|
|
time.setId(snowflake.nextId()); |
|
|
|
time.setCode(report.getCode()); |
|
|
|
time.setRecodeTime(Integer.parseInt(type)); |
|
|
|
questionRecordTimeMapper.insertSelective(time); |
|
|
|
recordTimes.add(time); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -242,25 +256,42 @@ public class ImportService implements IImportService { |
|
|
|
return report; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化试题 |
|
|
|
* @param objs 表格内读取的数据 |
|
|
|
* @param evaluationCode 试题类型 |
|
|
|
* @param code 试题类型 |
|
|
|
* @param sort 排序 |
|
|
|
* @param hospitalMap |
|
|
|
* @param hospitalMap 医院code和ID |
|
|
|
* @param questionHospitals 试题医院关联 |
|
|
|
* @param QuestionHospitalDelList 要删除的条件 |
|
|
|
* @return 返回试题 |
|
|
|
*/ |
|
|
|
private Question initQuestion(Object[] objs, String evaluationCode, int sort, Long optionId, Map<String, Long> hospitalMap) { |
|
|
|
private Question initQuestion(Object[] objs, String code, int sort, Long optionId, Map<String, Long> hospitalMap, List<QuestionHospital> questionHospitals, List<QuestionDto.QuestionHospitalDel> QuestionHospitalDelList) { |
|
|
|
// 查询关联医院
|
|
|
|
List<Long> hospitalIds = new ArrayList<>(); |
|
|
|
int hospitalIndex = 10; |
|
|
|
if (objs.length > hospitalIndex && !StringUtils.isEmpty(objs[hospitalIndex])) { |
|
|
|
String[] hospitalCodes = ((String) objs[hospitalIndex]).split("[,,]"); |
|
|
|
for (String hospitalCode:hospitalCodes) { |
|
|
|
hospitalIds.add(hospitalMap.get(hospitalCode)); |
|
|
|
} |
|
|
|
} else { |
|
|
|
hospitalMap.forEach((key, value)->hospitalIds.add(value)); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询试题是否已经存在
|
|
|
|
QuestionExample example = new QuestionExample(); |
|
|
|
example.createCriteria().andCodeEqualTo(evaluationCode).andSortEqualTo(sort); |
|
|
|
List<Question> questions = questionDao.selectByExample(example); |
|
|
|
Question question; |
|
|
|
if (CollectionUtils.isEmpty(questions)) { |
|
|
|
example.createCriteria().andCodeEqualTo(code).andSortEqualTo(sort); |
|
|
|
Question question = questionDao.getByCodeAndHospitals(code, sort, hospitalIds); |
|
|
|
if (question == null) { |
|
|
|
question = new Question(); |
|
|
|
question.setId(snowflake.nextId()); |
|
|
|
} else { |
|
|
|
question = questions.get(0); |
|
|
|
// 题存在 -->删除原有关联关系
|
|
|
|
QuestionHospitalDelList.add(new QuestionDto.QuestionHospitalDel(question.getId(), hospitalIds)); |
|
|
|
} |
|
|
|
|
|
|
|
question.setCode(StringUtils.isEmpty(objs[1]) ? Constant.STRING_DEFAULT : String.valueOf(objs[1])); |
|
|
|
question.setQuestion(StringUtils.isEmpty(objs[2]) ? Constant.STRING_DEFAULT : String.valueOf(objs[2])); |
|
|
|
question.setSort(sort); |
|
|
@ -282,28 +313,20 @@ public class ImportService implements IImportService { |
|
|
|
} |
|
|
|
} |
|
|
|
question.setRelevanceOptionId(optionId == null ? 0 : optionId); |
|
|
|
// 设置是否必填
|
|
|
|
int fillStatusIndex = 11; |
|
|
|
boolean hasFillStatus = objs.length > fillStatusIndex && objs[fillStatusIndex] != null |
|
|
|
&& StringUtil.isMatch((String)objs[fillStatusIndex], StringUtil.NUMBER_DOUBLE); |
|
|
|
byte fillType = hasFillStatus ? Byte.parseByte((String)objs[fillStatusIndex]) : 1; |
|
|
|
// 设置关联那个医院
|
|
|
|
List<Long> hospitalIds = new ArrayList<>(); |
|
|
|
int hospitalIndex = 10; |
|
|
|
if (objs.length > hospitalIndex && !StringUtils.isEmpty(objs[hospitalIndex])) { |
|
|
|
String[] codes = ((String) objs[hospitalIndex]).split("[,,]"); |
|
|
|
for (String code:codes) { |
|
|
|
hospitalIds.add(hospitalMap.get(code)); |
|
|
|
} |
|
|
|
} else { |
|
|
|
hospitalMap.forEach((key, value)->{ |
|
|
|
hospitalIds.add(value); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
hospitalIds.forEach(id->{ |
|
|
|
for (Long id: hospitalIds) { |
|
|
|
QuestionHospital questionHospital = new QuestionHospital(); |
|
|
|
questionHospital.setId(snowflake.nextId()); |
|
|
|
questionHospital.setQuestionId(question.getId()); |
|
|
|
questionHospital.setHospitalId(id); |
|
|
|
questionHospitalDao.insertSelective(questionHospital); |
|
|
|
}); |
|
|
|
|
|
|
|
questionHospital.setFillType(fillType); |
|
|
|
questionHospitals.add(questionHospital); |
|
|
|
} |
|
|
|
log.info("导入试题:{}", question); |
|
|
|
return question; |
|
|
|
} |
|
|
@ -341,6 +364,10 @@ public class ImportService implements IImportService { |
|
|
|
*/ |
|
|
|
private List<QuestionVo.CodeQuestionVo> getQuestionByCode(String code) { |
|
|
|
List<QuestionVo.CodeQuestionVo> subCodeQuestionVos = questionDao.queryQuestionByCode(code); |
|
|
|
return getCodeQuestionVos(subCodeQuestionVos); |
|
|
|
} |
|
|
|
|
|
|
|
private List<QuestionVo.CodeQuestionVo> getCodeQuestionVos(List<QuestionVo.CodeQuestionVo> subCodeQuestionVos) { |
|
|
|
if(CollectionUtil.isNotEmpty(subCodeQuestionVos)){ |
|
|
|
subCodeQuestionVos.forEach(question -> { |
|
|
|
if(CollectionUtil.isNotEmpty(question.getOptionVos())){ |
|
|
@ -360,24 +387,13 @@ public class ImportService implements IImportService { |
|
|
|
*/ |
|
|
|
private List<QuestionVo.CodeQuestionVo> queryOptionQuestion(Long optionId){ |
|
|
|
List<QuestionVo.CodeQuestionVo> questionVos = questionDao.queryQuestionByOption(optionId); |
|
|
|
if(CollectionUtil.isNotEmpty(questionVos)){ |
|
|
|
questionVos.forEach(question -> { |
|
|
|
if(CollectionUtil.isNotEmpty(question.getOptionVos())){ |
|
|
|
question.getOptionVos().forEach(option -> { |
|
|
|
if(option.getAfterOperation() == Constant.AFTER_OPERATION){ |
|
|
|
option.setQuestionVos(queryOptionQuestion(option.getId())); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
return questionVos; |
|
|
|
return getCodeQuestionVos(questionVos); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 查看类型下的试题信息 |
|
|
|
* @param param |
|
|
|
* @param param 试题类型 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<QuestionVo.ReportCodeVo> getQuestion(CodeVo.QuestionCode param) { |
|
|
|