Browse Source

切换分支

sd
zhizhi wu 4 years ago
parent
commit
48410cdf03
  1. 23
      ht/src/main/java/com/ccsens/ht/api/ImportController.java
  2. 18
      ht/src/main/java/com/ccsens/ht/api/PatientReportController.java
  3. 59
      ht/src/main/java/com/ccsens/ht/api/PatientReportExportController.java
  4. 12
      ht/src/main/java/com/ccsens/ht/bean/dto/PatientReportDto.java
  5. 16
      ht/src/main/java/com/ccsens/ht/bean/vo/QuestionVo.java
  6. 9
      ht/src/main/java/com/ccsens/ht/persist/dao/HtQuestionDao.java
  7. 10
      ht/src/main/java/com/ccsens/ht/persist/dao/HtReportDao.java
  8. 13
      ht/src/main/java/com/ccsens/ht/service/IImportService.java
  9. 155
      ht/src/main/java/com/ccsens/ht/service/ImportService.java
  10. 42
      ht/src/main/java/com/ccsens/ht/service/QuestionService.java
  11. 97
      ht/src/main/resources/mapper_dao/HtQuestionDao.xml
  12. 15
      ht/src/main/resources/mapper_dao/HtQuestionOptionDao.xml
  13. 61
      ht/src/main/resources/mapper_dao/HtReportDao.xml

23
ht/src/main/java/com/ccsens/ht/api/ImportController.java

@ -19,7 +19,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.Part; import javax.servlet.http.Part;
import java.io.File; import java.io.File;
import java.util.Collections;
import java.util.List; import java.util.List;
@ -69,7 +68,8 @@ public class ImportController {
List<String> codes = importService.importReport(excelFile, 2); List<String> codes = importService.importReport(excelFile, 2);
long time5 = System.currentTimeMillis(); long time5 = System.currentTimeMillis();
log.info("导入报告单耗时:{}", (time5 - time4)); log.info("导入报告单耗时:{}", (time5 - time4));
importService.importReportRecord(excelFile, 3);
log.info("导入报告单其他记录耗时:{}", System.currentTimeMillis() - time5);
if (CollectionUtil.isNotEmpty(codes)) { if (CollectionUtil.isNotEmpty(codes)) {
for (String code: codes) { for (String code: codes) {
importService.importQuestion(excelFile, code); importService.importQuestion(excelFile, code);
@ -99,11 +99,22 @@ public class ImportController {
String dir = WebConstant.UPLOAD_PROJECT_WBS + File.separator; String dir = WebConstant.UPLOAD_PROJECT_WBS + File.separator;
String path = UploadFileUtil_Servlet3.uploadFile(file, allowedExts, dir); String path = UploadFileUtil_Servlet3.uploadFile(file, allowedExts, dir);
File excelFile = new File(dir+path); File excelFile = new File(dir+path);
long time2 = System.currentTimeMillis();
long time4 = System.currentTimeMillis();
importService.importReport(excelFile, 2); importService.importReport(excelFile, 2);
long time5 = System.currentTimeMillis(); return JsonResponse.newInstance().ok();
log.info("导入报告单耗时:{}", (time5 - time4)); }
@ApiOperation(value = "单独导入报告单类型",notes = "文件大小不能超过20M,支持后缀:.xls|.xlsx")
@ApiImplicitParams({
@ApiImplicitParam(name = "file", value = "医疗项目表", required = true, paramType = "form",dataType = "__file")
})
@RequestMapping(value = "/importReportTypeRecord", method = RequestMethod.POST)
public JsonResponse importReportTypeRecord(@RequestParam(required = true) Part file) throws Exception{
//1.上传文件
String allowedExts = "xls,xlsx";
String dir = WebConstant.UPLOAD_PROJECT_WBS + File.separator;
String path = UploadFileUtil_Servlet3.uploadFile(file, allowedExts, dir);
File excelFile = new File(dir+path);
importService.importReportRecord(excelFile, 3);
return JsonResponse.newInstance().ok(); return JsonResponse.newInstance().ok();
} }

18
ht/src/main/java/com/ccsens/ht/api/PatientReportController.java

@ -143,20 +143,10 @@ public class PatientReportController {
return JsonResponse.newInstance().ok(authority); return JsonResponse.newInstance().ok(authority);
} }
@ApiOperation(value = "导出报告单",notes = "导出报告单")
@ApiImplicitParams({
@ApiImplicitParam(name = "json", value = "导出报告单", required = true)
})
@RequestMapping(value="/exportReport", method = RequestMethod.POST)
public JsonResponse<PatientReportVo.Export> exportReport(@RequestBody @ApiParam @Valid QueryDto<PatientReportDto.QueryDetail> param){
//查询报告单信息
log.info("查询报告单详情:{}", param);
String path = patientReportService.exportReport(param.getParam(), param.getUserId());
log.info("文件路径:{}", path);
PatientReportVo.Export export = new PatientReportVo.Export();
export.setPath(path);
return JsonResponse.newInstance().ok(export);
}
@ApiOperation(value = "分享报告单",notes = "分享报告单") @ApiOperation(value = "分享报告单",notes = "分享报告单")
@ApiImplicitParams({ @ApiImplicitParams({

59
ht/src/main/java/com/ccsens/ht/api/PatientReportExportController.java

@ -0,0 +1,59 @@
package com.ccsens.ht.api;
import com.ccsens.ht.bean.dto.PatientReportDto;
import com.ccsens.ht.bean.vo.PatientReportVo;
import com.ccsens.ht.service.IPatientReportService;
import com.ccsens.util.JsonResponse;
import com.ccsens.util.bean.dto.QueryDto;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
/**
* @description:
* @author: whj
* @time: 2021/4/21 19:01
*/
@Slf4j
@Api(tags = "报告单导出",value = "报告单导出")
@RestController
public class PatientReportExportController {
@Resource
private IPatientReportService patientReportService;
@ApiOperation(value = "导出报告单",notes = "导出报告单")
@ApiImplicitParams({
@ApiImplicitParam(name = "json", value = "导出报告单", required = true)
})
@RequestMapping(value="/exportReport", method = RequestMethod.POST)
public JsonResponse<PatientReportVo.Export> exportReport(@RequestBody @ApiParam @Valid QueryDto<PatientReportDto.QueryDetail> param){
//查询报告单信息
log.info("查询报告单详情:{}", param);
String path = patientReportService.exportReport(param.getParam(), param.getUserId());
log.info("文件路径:{}", path);
PatientReportVo.Export export = new PatientReportVo.Export();
export.setPath(path);
return JsonResponse.newInstance().ok(export);
}
@ApiOperation(value = "导出指定报告单",notes = "导出报告单")
@ApiImplicitParams({
@ApiImplicitParam(name = "json", value = "导出报告单", required = true)
})
@RequestMapping(value="/export", method = RequestMethod.POST)
public JsonResponse<PatientReportVo.Export> export(@RequestBody @ApiParam @Valid QueryDto<PatientReportDto.ExportCode> param){
//查询报告单信息
log.info("导出指定报告单:{}", param);
String path = patientReportService.export(param.getParam(), param.getUserId());
log.info("文件路径:{}", path);
PatientReportVo.Export export = new PatientReportVo.Export();
export.setPath(path);
return JsonResponse.newInstance().ok(export);
}
}

12
ht/src/main/java/com/ccsens/ht/bean/dto/PatientReportDto.java

@ -86,7 +86,17 @@ public class PatientReportDto {
@ApiModelProperty("报告单类型") @ApiModelProperty("报告单类型")
private String report = "REPORT1.0"; private String report = "REPORT1.0";
} }
@ApiModel("导出指定某一种报告单")
@Data
public static class ExportCode{
@ApiModelProperty("病人报告单ID")
@NotNull(message = "病人报告单ID不能为空")
private Long id;
@ApiModelProperty("报告单类型")
private String code;
}
/**医生对报告单权限*/ /**医生对报告单权限*/
@ApiModel("PatientReportDtoAuthority") @ApiModel("PatientReportDtoAuthority")

16
ht/src/main/java/com/ccsens/ht/bean/vo/QuestionVo.java

@ -117,6 +117,8 @@ public class QuestionVo {
public static class Question{ public static class Question{
@ApiModelProperty("试题ID") @ApiModelProperty("试题ID")
private Long id; private Long id;
@ApiModelProperty("一级评测类型")
private String evaluationCode;
@ApiModelProperty("评测类型") @ApiModelProperty("评测类型")
private String parentCode; private String parentCode;
@ApiModelProperty("排序") @ApiModelProperty("排序")
@ -141,8 +143,8 @@ public class QuestionVo {
private Integer clearTimes; private Integer clearTimes;
@ApiModelProperty("定时器时长") @ApiModelProperty("定时器时长")
private Integer timingLength; private Integer timingLength;
@ApiModelProperty("答案路径") // @ApiModelProperty("答案路径")
private String path; // private String path;
@ApiModelProperty("共享答案的试题Id") @ApiModelProperty("共享答案的试题Id")
private List<Long> shareAnswerIds; private List<Long> shareAnswerIds;
@ApiModelProperty("是否展示关联的试题的答案 0否 1是") @ApiModelProperty("是否展示关联的试题的答案 0否 1是")
@ -186,9 +188,6 @@ public class QuestionVo {
public static final class QuestionRecord{ public static final class QuestionRecord{
@ApiModelProperty("id") @ApiModelProperty("id")
private Long id; private Long id;
private Byte recordType;
private Long questionId;
private Integer sort;
@ApiModelProperty("0:点击过程 1:自动计算 2:手动计算") @ApiModelProperty("0:点击过程 1:自动计算 2:手动计算")
private Byte calcType; private Byte calcType;
@ApiModelProperty("显示内容") @ApiModelProperty("显示内容")
@ -201,6 +200,8 @@ public class QuestionVo {
private Byte type; private Byte type;
@ApiModelProperty("备注") @ApiModelProperty("备注")
private String remark; private String remark;
@ApiModelProperty("答案")
private List<String> answers;
} }
@Data @Data
@ -251,8 +252,13 @@ public class QuestionVo {
private String answer; private String answer;
@ApiModelProperty("是否选中") @ApiModelProperty("是否选中")
private Byte choose; private Byte choose;
@ApiModelProperty("选项补充")
private List<OptionDesc> optionDescList;
} }
@Data @Data
@ApiModel("QuestionVoIntroduce") @ApiModel("QuestionVoIntroduce")
public static class Introduce { public static class Introduce {

9
ht/src/main/java/com/ccsens/ht/persist/dao/HtQuestionDao.java

@ -28,4 +28,13 @@ public interface HtQuestionDao extends HtQuestionMapper {
* 查询可以共享答案的试题id * 查询可以共享答案的试题id
*/ */
List<QuestionVo.ShareAnswer> queryShareAnswer(@Param("questionId")Long questionId, @Param("patientReportId") Long patientReportId); List<QuestionVo.ShareAnswer> queryShareAnswer(@Param("questionId")Long questionId, @Param("patientReportId") Long patientReportId);
/**
* 查询试题和其他记录以及其他记录的答案
* @param code evaluation_code
* @param num sort
* @param patientReportId 报告单ID
* @return 试题
*/
QuestionVo.Question queryQuestionAndRecord(@Param("code") String code, @Param("num") int num, @Param("patientReportId") Long patientReportId);
} }

10
ht/src/main/java/com/ccsens/ht/persist/dao/HtReportDao.java

@ -2,10 +2,10 @@ package com.ccsens.ht.persist.dao;
import com.ccsens.ht.bean.po.HtReport; import com.ccsens.ht.bean.po.HtReport;
import com.ccsens.ht.bean.vo.PatientReportSearchVo; import com.ccsens.ht.bean.vo.PatientReportSearchVo;
import com.ccsens.ht.bean.vo.QuestionVo;
import com.ccsens.ht.persist.mapper.HtReportMapper; import com.ccsens.ht.persist.mapper.HtReportMapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -45,4 +45,12 @@ public interface HtReportDao extends HtReportMapper {
* @return code * @return code
*/ */
List<String> queryCode(@Param("type") byte type); List<String> queryCode(@Param("type") byte type);
/**
* 查询报告单和记录
* @param code code
* @param patientReportId patientReportId
* @return report+record
*/
QuestionVo.Report queryReportAndRecord(@Param("code") String code, @Param("patientReportId") Long patientReportId);
} }

13
ht/src/main/java/com/ccsens/ht/service/IImportService.java

@ -31,14 +31,14 @@ public interface IImportService {
String importTitle(File file, int sheetIndex) throws Exception; String importTitle(File file, int sheetIndex) throws Exception;
/** /**
*@Description:导入测评报告单分类 *@Description:导入测评报告单分类
*@param file 文件
*@param sheetIndex 第几个sheet
*@return: void *@return: void
*@Author: wuhuijuan *@Author: wuhuijuan
*@date: 2019/10/21 15:08 *@date: 2019/10/21 15:08
* @return 报告单类型 * @return 报告单类型
* @param file 文件
* @param index report是第几个sheet
*/ */
List<String> importReport(File file, int sheetIndex) throws Exception; List<String> importReport(File file, int index) throws Exception;
/** /**
*@Description:导入测评报告单分类 *@Description:导入测评报告单分类
@ -49,4 +49,11 @@ public interface IImportService {
*@date: 2019/10/21 15:08 *@date: 2019/10/21 15:08
*/ */
void importQuestion(File file, String type) throws Exception; void importQuestion(File file, String type) throws Exception;
/**
* 导入报告单其他记录
* @param excelFile excel
* @param sheetIndex 第几个
*/
void importReportRecord(File excelFile, int sheetIndex) throws Exception;
} }

155
ht/src/main/java/com/ccsens/ht/service/ImportService.java

@ -9,9 +9,11 @@ import com.alibaba.fastjson.JSONObject;
import com.ccsens.ht.bean.po.*; import com.ccsens.ht.bean.po.*;
import com.ccsens.ht.persist.dao.*; import com.ccsens.ht.persist.dao.*;
import com.ccsens.ht.uitl.Constant; import com.ccsens.ht.uitl.Constant;
import com.ccsens.util.CodeEnum;
import com.ccsens.util.PoiUtil; import com.ccsens.util.PoiUtil;
import com.ccsens.util.PropUtil; import com.ccsens.util.PropUtil;
import com.ccsens.util.StringUtil; import com.ccsens.util.StringUtil;
import com.ccsens.util.exception.BaseException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -237,6 +239,40 @@ public class ImportService implements IImportService {
} }
} }
@Override
public void importReportRecord(File excelFile, int sheetIndex) throws Exception {
List<Object[]> reports = PoiUtil.readExce(excelFile, sheetIndex, null,1, false);
log.info("导入报告单其他记录,读取数据完成");
List<HtReport> htReports = htReportDao.selectByExample(new HtReportExample());
Map<String, Long> reportMap = new HashMap<>();
htReports.forEach(htReport -> reportMap.put(htReport.getCode(), htReport.getId()));
log.info("报告单类型查询完成");
List<HtQuestionRecord> reportRecordList = new ArrayList<>();
List<HtQuestionRecordOption> optionList = new ArrayList<>();
for (Object[] objs: reports) {
if (!pageData(objs)) {
log.info("测评报告单数据不足,跳转下一行");
continue;
}
Long id = reportMap.get(String.valueOf(objs[0]));
if (id == null) {
log.info("报告单类型不存在:{}", objs[0]);
throw new BaseException(CodeEnum.PARAM_ERROR);
}
HtQuestionRecord record = initRecord(objs, id , optionList, Constant.Ht.QuestionRecord.RECORD_TYPE_CODE, 1);
reportRecordList.add(record);
}
if (!reportRecordList.isEmpty()) {
htQuestionRecordDao.insertBatch(reportRecordList);
}
if (!optionList.isEmpty()) {
htQuestionRecordOptionDao.insertBatch(optionList);
}
}
/** /**
* 保存试题 * 保存试题
* */ * */
@ -259,60 +295,7 @@ public class ImportService implements IImportService {
int sort = objs.length > 3 && StringUtil.checkNum(String.valueOf(objs[3]), false) ? Integer.parseInt(String.valueOf(objs[3])) : 1; int sort = objs.length > 3 && StringUtil.checkNum(String.valueOf(objs[3]), false) ? Integer.parseInt(String.valueOf(objs[3])) : 1;
String type = String.valueOf(objs[0]); String type = String.valueOf(objs[0]);
switch (type) { initData(evaluationCode, questionList, optionList, introduceList, ruleList, questionRecordList, questionRecordOptionList, optionDescList, optionDescDelList, parentCode, objs, sort, type);
case Constant.Import.EVALUATION_QUESTION :
HtQuestion question = initQuestion(objs, evaluationCode, sort);
question.setEvaluationCode(parentCode.getOrDefault(question.getParentCode(), question.getEvaluationCode()));
questionList.add(question);
break;
case Constant.Import.EVALUATION_RELATION:
HtQuestion relationQuestion = initQuestion(objs, evaluationCode, sort);
relationQuestion.setEvaluationCode(parentCode.getOrDefault(relationQuestion.getParentCode(), relationQuestion.getEvaluationCode()));
if (CollectionUtil.isNotEmpty(questionList)) {
HtQuestion prev = questionList.get(questionList.size() - 1);
if (prev.getRelationId() != null && prev.getRelationId() >0) {
prev.setRelationId(prev.getRelationId());
} else {
prev.setRelationId(prev.getId());
}
}
questionList.add(relationQuestion);
break;
case Constant.Import.EVALUATION_OPTION :
if (questionList.isEmpty()) {
break;
}
HtQuestionOption option = initOption(objs, questionList.get(questionList.size()-1).getId(), sort, optionDescList, optionDescDelList);
optionList.add(option);
break;
case Constant.Import.EVALUATION_PARSE :
if (questionList.isEmpty()) {
break;
}
HtQuestionIntroducer introduce = initIntroduce(objs, questionList.get(questionList.size()-1).getId(), sort);
introduceList.add(introduce);
break;
case Constant.Import.EVALUATION_RULE :
if (questionList.isEmpty()) {
break;
}
HtQuestionScoringRule rule = initRule(objs, questionList.get(questionList.size() - 1).getId());
ruleList.add(rule);
break;
case Constant.Import.EVALUATION_RECORD:
if (questionList.isEmpty()) {
break;
}
HtQuestionRecord record = initRecord(objs, questionList.get(questionList.size() - 1).getId(), questionRecordOptionList);
questionRecordList.add(record);
break;
default:
log.info("{}类型未知,不解析", type);
break;
}
} }
if (!questionList.isEmpty()) { if (!questionList.isEmpty()) {
@ -341,6 +324,63 @@ public class ImportService implements IImportService {
} }
} }
/**
* 试题导入将obj[] 转换成 对应的data
*/
private void initData(String evaluationCode, List<HtQuestion> questionList, List<HtQuestionOption> optionList, List<HtQuestionIntroducer> introduceList, List<HtQuestionScoringRule> ruleList, List<HtQuestionRecord> questionRecordList, List<HtQuestionRecordOption> questionRecordOptionList, List<HtQuestionOptionDesc> optionDescList, List<Long> optionDescDelList, Map<String, String> parentCode, Object[] objs, int sort, String type) {
switch (type) {
case Constant.Import.EVALUATION_QUESTION :
HtQuestion question = initQuestion(objs, evaluationCode, sort);
question.setEvaluationCode(parentCode.getOrDefault(question.getParentCode(), question.getEvaluationCode()));
questionList.add(question);
break;
case Constant.Import.EVALUATION_RELATION:
HtQuestion relationQuestion = initQuestion(objs, evaluationCode, sort);
relationQuestion.setEvaluationCode(parentCode.getOrDefault(relationQuestion.getParentCode(), relationQuestion.getEvaluationCode()));
if (CollectionUtil.isNotEmpty(questionList)) {
HtQuestion prev = questionList.get(questionList.size() - 1);
if (prev.getRelationId() != null && prev.getRelationId() >0) {
prev.setRelationId(prev.getRelationId());
} else {
prev.setRelationId(prev.getId());
}
}
questionList.add(relationQuestion);
break;
case Constant.Import.EVALUATION_OPTION :
if (questionList.isEmpty()) {
break;
}
HtQuestionOption option = initOption(objs, questionList.get(questionList.size()-1).getId(), sort, optionDescList, optionDescDelList);
optionList.add(option);
break;
case Constant.Import.EVALUATION_PARSE :
if (questionList.isEmpty()) {
break;
}
HtQuestionIntroducer introduce = initIntroduce(objs, questionList.get(questionList.size()-1).getId(), sort);
introduceList.add(introduce);
break;
case Constant.Import.EVALUATION_RULE :
if (questionList.isEmpty()) {
break;
}
HtQuestionScoringRule rule = initRule(objs, questionList.get(questionList.size() - 1).getId());
ruleList.add(rule);
break;
case Constant.Import.EVALUATION_RECORD:
if (questionList.isEmpty()) {
break;
}
HtQuestionRecord record = initRecord(objs, questionList.get(questionList.size() - 1).getId(), questionRecordOptionList, Constant.Ht.QuestionRecord.RECORD_TYPE_QUESTION, (byte)3);
questionRecordList.add(record);
break;
default:
log.info("{}类型未知,不解析", type);
break;
}
}
/** /**
* 封装record option * 封装record option
* @param objs 一列 * @param objs 一列
@ -348,16 +388,16 @@ public class ImportService implements IImportService {
* @param questionRecordOptions record选项 * @param questionRecordOptions record选项
* @return record * @return record
*/ */
private HtQuestionRecord initRecord(Object[] objs, Long id, List<HtQuestionRecordOption> questionRecordOptions) { private HtQuestionRecord initRecord(Object[] objs, Long id, List<HtQuestionRecordOption> questionRecordOptions, byte recordType, int sortIndex ) {
HtQuestionRecord record = new HtQuestionRecord(); HtQuestionRecord record = new HtQuestionRecord();
String content = (String)objs[2]; String content = (String)objs[2];
JSONObject json = JSONObject.parseObject(content); JSONObject json = JSONObject.parseObject(content);
BeanUtils.copyProperties(json, record); BeanUtils.copyProperties(json, record);
record.setRecordType(Constant.Ht.QuestionRecord.RECORD_TYPE_QUESTION); record.setRecordType(recordType);
// 判断是否存在,设置id // 判断是否存在,设置id
int sortIndex = 3;
int sort = StringUtil.checkNum(String.valueOf(objs[sortIndex]), false) ? int sort = StringUtil.checkNum(String.valueOf(objs[sortIndex]), false) ?
Integer.parseInt(String.valueOf(objs[sortIndex])) : Constant.Ht.Question.RULE_TYPE_DEFAULT; Integer.parseInt(String.valueOf(objs[sortIndex])) : Constant.Ht.Question.RULE_TYPE_DEFAULT;
record.setSort(sort);
HtQuestionRecordExample recordExample = new HtQuestionRecordExample(); HtQuestionRecordExample recordExample = new HtQuestionRecordExample();
recordExample.createCriteria().andQuestionIdEqualTo(id).andSortEqualTo(sort); recordExample.createCriteria().andQuestionIdEqualTo(id).andSortEqualTo(sort);
List<HtQuestionRecord> questionRecords = htQuestionRecordDao.selectByExample(recordExample); List<HtQuestionRecord> questionRecords = htQuestionRecordDao.selectByExample(recordExample);
@ -368,6 +408,7 @@ public class ImportService implements IImportService {
record.setId(questionRecords.get(0).getId()); record.setId(questionRecords.get(0).getId());
} }
log.info("添加record:{}", record); log.info("添加record:{}", record);
if (!json.containsKey(Constant.Import.RELATION_OPTION)) { if (!json.containsKey(Constant.Import.RELATION_OPTION)) {
return record; return record;

42
ht/src/main/java/com/ccsens/ht/service/QuestionService.java

@ -75,25 +75,19 @@ public class QuestionService implements IQuestionService {
@Override @Override
public QuestionVo.Query queryQuestion(QuestionDto.Query query, Long userId) { public QuestionVo.Query queryQuestion(QuestionDto.Query query, Long userId) {
log.info("请求参数:{},{}", query, userId); log.info("请求参数:{},{}", query, userId);
//TODO 1.根据类型和题号,查询试题 和 补充内容(含code的补充内容) //1.根据类型和题号,查询试题 和 补充内容
HtQuestionExample questionExample = new HtQuestionExample(); QuestionVo.Question questionVo = htQuestionDao.queryQuestionAndRecord(query.getCode(), query.getNum(), query.getPatientReportId());
questionExample.createCriteria().andEvaluationCodeEqualTo(query.getCode()).andSortEqualTo(query.getNum()); if (questionVo == null) {
List<HtQuestion> questionList = htQuestionDao.selectByExample(questionExample);
log.info("测评试题:{}", questionList);
if (CollectionUtils.isEmpty(questionList)) {
throw new BaseException(CodeEnum.QUESTION_NOT_FOUND); throw new BaseException(CodeEnum.QUESTION_NOT_FOUND);
} }
HtQuestion question = questionList.get(0); //获取code信息及补充信息
QuestionVo.Question questionVo = QuestionVo.Question.toQuestionVo(question); QuestionVo.Report reportVo = htReportDao.queryReportAndRecord(questionVo.getParentCode(), query.getPatientReportId());
// TODO 查询code的补充内容,做缓存
//检查当前试题是否有答案,共享答案的试题是否有答案 //检查当前试题是否有答案,共享答案的试题是否有答案
boolean f = false; boolean f = false;
if(ObjectUtil.isNotNull(query.getPatientReportId())){ if(ObjectUtil.isNotNull(query.getPatientReportId())){
HtPatientScoreExample scoreExample = new HtPatientScoreExample(); HtPatientScoreExample scoreExample = new HtPatientScoreExample();
scoreExample.createCriteria().andPatientReportIdEqualTo(query.getPatientReportId()).andQuestionIdEqualTo(question.getId()) scoreExample.createCriteria().andPatientReportIdEqualTo(query.getPatientReportId()).andQuestionIdEqualTo(questionVo.getId())
.andTypeBetween((byte)0,(byte)1); .andTypeBetween((byte)0,(byte)1);
if(htPatientScoreDao.countByExample(scoreExample) > 0){ if(htPatientScoreDao.countByExample(scoreExample) > 0){
f = true; f = true;
@ -103,7 +97,7 @@ public class QuestionService implements IQuestionService {
//查询可以共享答案的试题的id //查询可以共享答案的试题的id
List<Long> shareAnswerIds = new ArrayList<>(); List<Long> shareAnswerIds = new ArrayList<>();
List<QuestionVo.ShareAnswer> shareAnswers = htQuestionDao.queryShareAnswer(question.getId(),query.getPatientReportId()); List<QuestionVo.ShareAnswer> shareAnswers = htQuestionDao.queryShareAnswer(questionVo.getId(),query.getPatientReportId());
log.info("答案关联的试题id:{}", shareAnswers); log.info("答案关联的试题id:{}", shareAnswers);
if(CollectionUtil.isNotEmpty(shareAnswers)){ if(CollectionUtil.isNotEmpty(shareAnswers)){
for(QuestionVo.ShareAnswer shareAnswer : shareAnswers){ for(QuestionVo.ShareAnswer shareAnswer : shareAnswers){
@ -122,22 +116,10 @@ public class QuestionService implements IQuestionService {
//TODO 获取评测信息及补充信息
HtReportExample reportExample = new HtReportExample();
reportExample.createCriteria().andCodeEqualTo(question.getEvaluationCode());
List<HtReport> htReports = htReportDao.selectByExample(reportExample);
QuestionVo.Report reportVo = new QuestionVo.Report();
if (CollectionUtil.isNotEmpty(htReports)) {
HtReport htReport = htReports.get(0);
reportVo.setCode(htReport.getCode());
reportVo.setName(htReport.getName());
}
Integer maxSort = htQuestionDao.selectMaxSort(query.getCode()); Integer maxSort = htQuestionDao.selectMaxSort(query.getCode());
//查询关联题目 //查询关联题目
HtQuestionExample example = new HtQuestionExample(); HtQuestionExample example = new HtQuestionExample();
example.createCriteria().andRelationIdEqualTo(question.getId()); example.createCriteria().andRelationIdEqualTo(questionVo.getId());
example.setOrderByClause("id"); example.setOrderByClause("id");
List<HtQuestion> relationQuestions = htQuestionDao.selectByExample(example); List<HtQuestion> relationQuestions = htQuestionDao.selectByExample(example);
List<QuestionVo.QuestionOption> vos = new ArrayList<>(); List<QuestionVo.QuestionOption> vos = new ArrayList<>();
@ -154,18 +136,18 @@ public class QuestionService implements IQuestionService {
//试题引导语 //试题引导语
HtQuestionIntroducerExample introduceExample = new HtQuestionIntroducerExample(); HtQuestionIntroducerExample introduceExample = new HtQuestionIntroducerExample();
introduceExample.createCriteria().andQuestionIdEqualTo(question.getId()); introduceExample.createCriteria().andQuestionIdEqualTo(questionVo.getId());
introduceExample.setOrderByClause("sort"); introduceExample.setOrderByClause("sort");
List<HtQuestionIntroducer> introduces = htQuestionIntroducerDao.selectByExample(introduceExample); List<HtQuestionIntroducer> introduces = htQuestionIntroducerDao.selectByExample(introduceExample);
List<QuestionVo.Introduce> introduceVos = QuestionVo.Introduce.toIntroduces(introduces); List<QuestionVo.Introduce> introduceVos = QuestionVo.Introduce.toIntroduces(introduces);
//TODO 试题选项 及补充
List<QuestionVo.Option> optionList = htQuestionOptionDao.queryOption(question.getId(), query.getPatientReportId()); List<QuestionVo.Option> optionList = htQuestionOptionDao.queryOption(questionVo.getId(), query.getPatientReportId());
//答题记录 //答题记录
List<QuestionVo.Record> recordVos; List<QuestionVo.Record> recordVos;
if (query.getPatientReportId() != null && query.getPatientReportId() != 0) { if (query.getPatientReportId() != null && query.getPatientReportId() != 0) {
HtPatientQuestionRecordExample recordExample = new HtPatientQuestionRecordExample(); HtPatientQuestionRecordExample recordExample = new HtPatientQuestionRecordExample();
recordExample.createCriteria().andPatientReportIdEqualTo(query.getPatientReportId()).andQuestionIdEqualTo(question.getId()); recordExample.createCriteria().andPatientReportIdEqualTo(query.getPatientReportId()).andQuestionIdEqualTo(questionVo.getId());
recordExample.setOrderByClause("record_time"); recordExample.setOrderByClause("record_time");
List<HtPatientQuestionRecord> records = htPatientQuestionRecordMapper.selectByExample(recordExample); List<HtPatientQuestionRecord> records = htPatientQuestionRecordMapper.selectByExample(recordExample);
recordVos = QuestionVo.Record.toRecords(records); recordVos = QuestionVo.Record.toRecords(records);

97
ht/src/main/resources/mapper_dao/HtQuestionDao.xml

@ -1,29 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.ht.persist.dao.HtQuestionDao"> <mapper namespace="com.ccsens.ht.persist.dao.HtQuestionDao">
<resultMap id="BaseResultMap" type="com.ccsens.ht.bean.po.HtQuestion"> <resultMap id="BaseResultMap" type="com.ccsens.ht.bean.vo.QuestionVo$Question">
<id column="id" jdbcType="BIGINT" property="id" /> <id column="id" jdbcType="BIGINT" property="id" />
<result column="evaluation_code" jdbcType="VARCHAR" property="evaluationCode" /> <result column="evaluationCode" jdbcType="VARCHAR" property="evaluationCode" />
<result column="parent_code" jdbcType="VARCHAR" property="parentCode" /> <result column="parentCode" jdbcType="VARCHAR" property="parentCode" />
<result column="sort" jdbcType="INTEGER" property="sort" /> <result column="sort" jdbcType="INTEGER" property="sort" />
<result column="question" jdbcType="VARCHAR" property="question" /> <result column="question" jdbcType="VARCHAR" property="question" />
<result column="type" jdbcType="TINYINT" property="type" /> <result column="type" jdbcType="TINYINT" property="type" />
<result column="record_type" jdbcType="VARCHAR" property="recordType" /> <result column="recordType" jdbcType="VARCHAR" property="recordType" />
<result column="record_content" jdbcType="VARCHAR" property="recordContent" /> <result column="recordContent" jdbcType="VARCHAR" property="recordContent" />
<result column="relation_code" jdbcType="VARCHAR" property="relationCode" /> <result column="operateType" jdbcType="TINYINT" property="operateType" />
<result column="operate_type" jdbcType="TINYINT" property="operateType" /> <result column="recodeStarttime" jdbcType="TINYINT" property="recodeStarttime" />
<result column="recode_starttime" jdbcType="TINYINT" property="recodeStarttime" /> <result column="timeWabei" jdbcType="TINYINT" property="timeWabei" />
<result column="time_wabei" jdbcType="TINYINT" property="timeWabei" /> <result column="allowClear" jdbcType="TINYINT" property="allowClear" />
<result column="allow_clear" jdbcType="TINYINT" property="allowClear" /> <result column="clearTimes" jdbcType="INTEGER" property="clearTimes" />
<result column="clear_times" jdbcType="INTEGER" property="clearTimes" /> <result column="timingLength" jdbcType="INTEGER" property="timingLength" />
<result column="timing_length" jdbcType="INTEGER" property="timingLength" /> <collection property="questionRecords" ofType="com.ccsens.ht.bean.vo.QuestionVo$QuestionRecord">
<result column="remark" jdbcType="VARCHAR" property="remark" /> <id column="rid" property="id"></id>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="rCalcType" property="calcType"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="rShowTitle" property="showTitle"/>
<result column="is_del" jdbcType="TINYINT" property="isDel" /> <result column="rShowForm" property="showForm"/>
<result column="rDefaultValue" property="defaultValue"/>
<result column="rType" property="type"/>
<result column="rRemark" property="remark"/>
<collection property="answers" ofType="String">
<id column="answer"/>
</collection>
</collection>
</resultMap> </resultMap>
<insert id="insertBatch" parameterType="List"> <insert id="insertBatch" parameterType="java.util.List">
replace into t_ht_question (id, evaluation_code, parent_code, replace into t_ht_question (id, evaluation_code, parent_code,
sort, question, type, sort, question, type,
record_type, record_content, relation_code, record_type, record_content, relation_code,
@ -60,4 +67,60 @@
r.question_id = #{questionId} r.question_id = #{questionId}
GROUP BY r.relevance_id GROUP BY r.relevance_id
</select> </select>
<select id="queryQuestionAndRecord" resultMap="BaseResultMap">
SELECT
*
FROM
(
SELECT
q.id,
q.evaluation_code AS evaluationCode,
q.parent_code AS parentCode,
q.sort,
q.question,
q.type,
q.record_type AS recordType,
q.record_content AS recordContent,
q.operate_type AS operateType,
q.recode_starttime AS recodeStarttime,
q.time_wabei AS timeWabei,
q.allow_clear AS allowClear,
q.clear_times AS clearTimes,
q.timing_length AS timingLength
FROM
t_ht_question q
WHERE
q.evaluation_code = #{code}
AND q.sort = #{num}
AND q.is_del = 0
LIMIT 1
) q
LEFT JOIN (
SELECT
r.id AS rId,
r.question_id,
r.calc_type AS rCalcType,
r.show_title AS rShowTitle,
r.show_form AS rShowForm,
r.default_value AS rDefaultValue,
r.type AS rType,
r.remark AS rRemark,
qr.answer
FROM
( SELECT * FROM t_ht_question_record WHERE record_type = 1 AND is_del = 0 ) r
LEFT JOIN ( SELECT * FROM t_ht_patient_report_record_desc WHERE
<choose>
<when test="patientReportId != null and patientReportId != 0">
patient_report_id = #{patientReportId} AND is_del = 0
</when>
<otherwise>
1=2
</otherwise>
</choose>
) qr ON r.id = qr.record_id
ORDER BY
r.question_id,
r.sort
) r ON q.id = r.question_id
</select>
</mapper> </mapper>

15
ht/src/main/resources/mapper_dao/HtQuestionOptionDao.xml

@ -23,9 +23,14 @@
<result column="display" jdbcType="VARCHAR" property="display" /> <result column="display" jdbcType="VARCHAR" property="display" />
<result column="choose" jdbcType="TINYINT" property="choose" /> <result column="choose" jdbcType="TINYINT" property="choose" />
<result column="answer" jdbcType="VARCHAR" property="answer" /> <result column="answer" jdbcType="VARCHAR" property="answer" />
<collection property="optionDescList" ofType="com.ccsens.ht.bean.vo.QuestionVo$OptionDesc">
<id column="descId" property="id"/>
<result column="type" property="type"/>
<result column="content" property="content"/>
</collection>
</resultMap> </resultMap>
<insert id="insertBatch" parameterType="List"> <insert id="insertBatch" parameterType="java.util.List">
replace into t_ht_question_option (id, question_id, sort, replace into t_ht_question_option (id, question_id, sort,
type, name, score, type, name, score,
display, remark, create_time, display, remark, create_time,
@ -41,11 +46,15 @@
<select id="queryOption" resultMap="OptionMap"> <select id="queryOption" resultMap="OptionMap">
select t1.id, t1.type, t1.question_id, t1.name, t1.score, t1.display, case when t1.type = 'hidden' then 0 when t2.id is null then 0 else 1 end as choose , if(t2.type = 3, null, t2.answer) as answer select t1.id, t1.type, t1.question_id, t1.name, t1.score, t1.display,
case when t1.type = 'hidden' then 0 when t2.id is null then 0 else 1 end as choose ,
if(t2.type = 3, null, t2.answer) as answer,
t3.id as descId, t3.type, t3.content
from t_ht_question_option t1 left join t_ht_patient_score t2 on t1.id = t2.option_id and (t2.id is null or (t2.patient_report_id = #{patientReportId,jdbcType=BIGINT} and t2.is_del = 0)) from t_ht_question_option t1 left join t_ht_patient_score t2 on t1.id = t2.option_id and (t2.id is null or (t2.patient_report_id = #{patientReportId,jdbcType=BIGINT} and t2.is_del = 0))
left join (select * from t_ht_question_option_desc where is_del = 0) t3 on t1.id = t3.option_id
where t1.question_id = #{questionId,jdbcType=BIGINT} where t1.question_id = #{questionId,jdbcType=BIGINT}
and t1.is_del = 0 and t1.is_del = 0
group by t1.id group by t1.id
order by t1.sort order by t1.sort, t3.sort
</select> </select>
</mapper> </mapper>

61
ht/src/main/resources/mapper_dao/HtReportDao.xml

@ -1,23 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.ht.persist.dao.HtReportDao"> <mapper namespace="com.ccsens.ht.persist.dao.HtReportDao">
<resultMap id="BaseResultMap" type="com.ccsens.ht.bean.po.HtReport"> <resultMap id="BaseResultMap" type="com.ccsens.ht.bean.vo.QuestionVo$Report">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="code" jdbcType="VARCHAR" property="code" /> <result column="code" jdbcType="VARCHAR" property="code" />
<result column="name" jdbcType="VARCHAR" property="name" /> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="parent_code" jdbcType="VARCHAR" property="parentCode" /> <collection property="codeRecords" ofType="com.ccsens.ht.bean.vo.QuestionVo$QuestionRecord">
<result column="description" jdbcType="VARCHAR" property="description" /> <id column="rid" property="id"></id>
<result column="total_score" jdbcType="INTEGER" property="totalScore" /> <result column="rCalcType" property="calcType"/>
<result column="type" jdbcType="TINYINT" property="type" /> <result column="rShowTitle" property="showTitle"/>
<result column="is_show" jdbcType="TINYINT" property="isShow" /> <result column="rShowForm" property="showForm"/>
<result column="sort" jdbcType="INTEGER" property="sort" /> <result column="rDefaultValue" property="defaultValue"/>
<result column="remark" jdbcType="VARCHAR" property="remark" /> <result column="rType" property="type"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="rRemark" property="remark"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <collection property="answers" ofType="String">
<result column="is_del" jdbcType="TINYINT" property="isDel" /> <id column="answer"/>
</collection>
</collection>
</resultMap> </resultMap>
<insert id="insertBatch" parameterType="List"> <insert id="insertBatch" parameterType="java.util.List">
replace into t_ht_report (id, code, name, replace into t_ht_report (id, code, name,
parent_code, description, total_score, parent_code, description, total_score,
type, is_show, sort, type, is_show, sort,
@ -32,7 +33,7 @@
</foreach> </foreach>
</insert> </insert>
<select id="queryReportShow" resultMap="BaseResultMap"> <select id="queryReportShow" resultMap="com.ccsens.ht.persist.mapper.HtReportMapper.BaseResultMap">
select * from t_ht_report where is_show = 1 and is_del = 0 order by type,sort select * from t_ht_report where is_show = 1 and is_del = 0 order by type,sort
</select> </select>
<select id="queryParam" resultType="com.ccsens.ht.bean.vo.PatientReportSearchVo$SearchParam"> <select id="queryParam" resultType="com.ccsens.ht.bean.vo.PatientReportSearchVo$SearchParam">
@ -69,5 +70,37 @@
<select id="queryCode" resultType="java.lang.String"> <select id="queryCode" resultType="java.lang.String">
select code from t_ht_report where type = #{type} and is_del = 0 select code from t_ht_report where type = #{type} and is_del = 0
</select> </select>
<select id="queryReportAndRecord" resultMap="BaseResultMap">
select * from
(select id, code, name from t_ht_report where code = #{code} and is_del = 0 ) report
left join
(
SELECT
r.id AS rId,
r.question_id,
r.calc_type AS rCalcType,
r.show_title AS rShowTitle,
r.show_form AS rShowForm,
r.default_value AS rDefaultValue,
r.type AS rType,
r.remark AS rRemark,
qr.answer
FROM
( SELECT * FROM t_ht_question_record WHERE record_type = 0 AND is_del = 0 ) r
LEFT JOIN ( SELECT * FROM t_ht_patient_report_record_desc WHERE
<choose>
<when test="patientReportId != null and patientReportId != 0">
patient_report_id = #{patientReportId} AND is_del = 0
</when>
<otherwise>
1=2
</otherwise>
</choose>
) qr ON r.id = qr.record_id
ORDER BY
r.question_id,
r.sort
) record on report.id = record.question_id
</select>
</mapper> </mapper>
Loading…
Cancel
Save