diff --git a/tcm/src/main/java/com/ccsens/tcm/service/PatientService.java b/tcm/src/main/java/com/ccsens/tcm/service/PatientService.java index 45ce209f..a998098b 100644 --- a/tcm/src/main/java/com/ccsens/tcm/service/PatientService.java +++ b/tcm/src/main/java/com/ccsens/tcm/service/PatientService.java @@ -114,26 +114,43 @@ public class PatientService implements IPatientService { PatientInformation patientInformation = patientInformationMapper.selectByPrimaryKey(param.getPatientId()); //处理过的答案信息集合 List patientRecordList1=new ArrayList(); - //处理过的提交的试题id集合 + //处理过的提交的答案试题id,答案类型为0,1 集合 Set longSet=new HashSet(); + //处理过的提交的答案试题id,答案类型为2 集合 + Set longSet1=new HashSet(); + //用来装试题答案id和其数量 + Map shitiwei2de=new HashMap(); //下面是对试题进行处理 if(param.getList().size()>0) { //在这个地方修改其中得集合 List saveCaseMesSigList= param.getList(); Set stringSet=new HashSet(); + //类型为2的数组 + Set stringSet1=new HashSet(); saveCaseMesSigList.forEach(saveCaseMesSig -> { if(saveCaseMesSig.getContentsType()==(byte)1){ stringSet.add(saveCaseMesSig.getTestQuestionsId()+"-"+saveCaseMesSig.getContents().substring(0,saveCaseMesSig.getContents().indexOf(":"))); } }); for (int i = param.getList().size() - 1; i >= 0; i--) { + //先统计一下数量 + if(shitiwei2de.containsKey(param.getList().get(i))){ + shitiwei2de.put( param.getList().get(i).getTestQuestionsId(),shitiwei2de.get(param.getList().get(i).getTestQuestionsId())+1); + }else { + shitiwei2de.put( param.getList().get(i).getTestQuestionsId(),1); + } if(param.getList().get(i).getContentsType()==(byte) 0){ if(stringSet.contains(param.getList().get(i).getTestQuestionsId()+"-"+param.getList().get(i).getContents())){ param.getList().remove(i); } } } - + for (int i = 0; i < param.getList().size(); i++) { + //拿出答案类型为2的并且数量为1的 + if((param.getList().get(i).getContentsType()==(byte) 2 )&&(shitiwei2de.get(param.getList().get(i).getTestQuestionsId())==1)){ + longSet1.add(param.getList().get(i).getTestQuestionsId()); + } + } for (int i = 0; i < param.getList().size(); i++) { PatientRecord patientRecord=new PatientRecord(); BeanUtils.copyProperties(param.getList().get(i),patientRecord); @@ -145,17 +162,29 @@ public class PatientService implements IPatientService { patientRecord.setId(param.getList().get(i).getPatientRecordId()); } patientRecord.setUserId(userId); - longSet.add(patientRecord.getTestQuestionsId()); + if(!longSet1.contains(param.getList().get(i).getTestQuestionsId())){ + longSet.add(patientRecord.getTestQuestionsId()); + } //因为得删除之前得内容,所以把试题集合都抽出来,另外再写循环进行插入 patientRecordList1.add(patientRecord); } } - //对答案进行更新删除 - PatientRecordExample patientRecordExample=new PatientRecordExample(); - patientRecordExample.createCriteria().andTestQuestionsIdIn(new ArrayList(longSet)).andRecStatusEqualTo((byte) 0).andPatientIdEqualTo(param.getPatientId()).andCollectTimeEqualTo(param.getNums()); - PatientRecord patientRecord=new PatientRecord(); - patientRecord.setRecStatus((byte)2); - patientRecordMapper.updateByExampleSelective(patientRecord,patientRecordExample); + if(longSet.size()>0) { + //对答案 0 和 1 进行更新删除 + PatientRecordExample patientRecordExample = new PatientRecordExample(); + patientRecordExample.createCriteria().andTestQuestionsIdIn(new ArrayList(longSet)).andRecStatusEqualTo((byte) 0).andPatientIdEqualTo(param.getPatientId()).andCollectTimeEqualTo(param.getNums()); + PatientRecord patientRecord = new PatientRecord(); + patientRecord.setRecStatus((byte) 2); + patientRecordMapper.updateByExampleSelective(patientRecord, patientRecordExample); + } + //对答案是2的进行删除 + if(longSet1.size()>0) { + PatientRecordExample patientRecordExample1 = new PatientRecordExample(); + patientRecordExample1.createCriteria().andTestQuestionsIdIn(new ArrayList(longSet1)).andRecStatusEqualTo((byte) 0).andPatientIdEqualTo(param.getPatientId()).andCollectTimeEqualTo(param.getNums()).andContentsTypeEqualTo((byte) 2); + PatientRecord patientRecord2 = new PatientRecord(); + patientRecord2.setRecStatus((byte) 2); + patientRecordMapper.updateByExampleSelective(patientRecord2, patientRecordExample1); + } //插入答案 patientRecordList1.forEach(patientRecord1 -> { patientRecord1.setId(snowflake.nextId()); diff --git a/tcm/src/main/java/com/ccsens/tcm/service/QuestionService.java b/tcm/src/main/java/com/ccsens/tcm/service/QuestionService.java index f76bbedd..b4c9c858 100644 --- a/tcm/src/main/java/com/ccsens/tcm/service/QuestionService.java +++ b/tcm/src/main/java/com/ccsens/tcm/service/QuestionService.java @@ -53,7 +53,7 @@ public class QuestionService implements IQuestionService{ if(CollectionUtil.isNotEmpty(patientCode.getSubReportCodes())){ patientCode.getSubReportCodes().forEach(subReportCode -> { //查询二级code下的试题和答案 - List subpatientQuestionNumList = questionDao.getQuestionByCodeAndPatientId(patientCode.getCode(),param.getId(),param.getNums()); + List subpatientQuestionNumList = questionDao.getQuestionByCodeAndPatientId(subReportCode.getCode(),param.getId(),param.getNums()); //查询选项关联的试题及答案 if(CollectionUtil.isNotEmpty(subpatientQuestionNumList)){ subpatientQuestionNumList.forEach(question -> { diff --git a/tcm/src/main/resources/mapper_dao/QuestionDao.xml b/tcm/src/main/resources/mapper_dao/QuestionDao.xml index 3693509f..bf0d3736 100644 --- a/tcm/src/main/resources/mapper_dao/QuestionDao.xml +++ b/tcm/src/main/resources/mapper_dao/QuestionDao.xml @@ -163,14 +163,19 @@ and q.rec_status = 0 and q.`code` = #{code} - ) qq, + ) qq left join ( + SELECT + test_questions_id, + contents + FROM t_patient_record tpr - where - tpr.test_questions_id = qq.qid - AND tpr.contents_type = 2 - AND tpr.patient_id = #{patientId} - AND tpr.collect_time = #{nums} - AND tpr.rec_status = 0 + WHERE + tpr.contents_type = 2 + AND tpr.patient_id = #{patientId} + AND tpr.collect_time = #{nums} + AND tpr.rec_status = 0 + ) tpr on tpr.test_questions_id = qq.qid + ORDER BY qq.qsort,qq.osort,qq.choose DESC,-qq.otherInformation DESC