|
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ccsens.carbasics.bean.dto.PatientDto; |
|
|
|
import com.ccsens.carbasics.bean.po.*; |
|
|
|
import com.ccsens.carbasics.bean.vo.PatientVo; |
|
|
@ -13,9 +14,12 @@ import com.ccsens.carbasics.persist.mapper.FirstAidRecordLogMapper; |
|
|
|
import com.ccsens.carbasics.util.Constant; |
|
|
|
import com.ccsens.carbasics.util.DefaultCodeError; |
|
|
|
import com.ccsens.util.CodeEnum; |
|
|
|
import com.ccsens.util.JacksonUtil; |
|
|
|
import com.ccsens.util.StringUtil; |
|
|
|
import com.ccsens.util.config.RabbitMQConfig; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.amqp.core.AmqpTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -45,6 +49,10 @@ public class FirstAidRecordService implements IFirstAidRecordService { |
|
|
|
private CodeParentDao codeParentDao; |
|
|
|
@Resource |
|
|
|
private FirstAidDao firstAidDao; |
|
|
|
@Resource |
|
|
|
private OrganizationProjectDao organizationProjectDao; |
|
|
|
@Resource |
|
|
|
private AmqpTemplate rabbitTemplate; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@ -101,29 +109,70 @@ public class FirstAidRecordService implements IFirstAidRecordService { |
|
|
|
checkTime(param, firstAid); |
|
|
|
// 保存
|
|
|
|
param.getCodeAndAnswerList().forEach(codeAndAnswer -> { |
|
|
|
if(StrUtil.isNotEmpty(codeAndAnswer.getQuestionCode())) { |
|
|
|
//添加记录表,需要查找之前的记录,删除后重新添加
|
|
|
|
FirstAidRecordExample recordExample = new FirstAidRecordExample(); |
|
|
|
recordExample.createCriteria().andFirstAidIdEqualTo(firstAid.getId()).andQuestionCodeEqualTo(codeAndAnswer.getQuestionCode()); |
|
|
|
List<FirstAidRecord> firstAidRecords = firstAidRecordDao.selectByExample(recordExample); |
|
|
|
if (CollectionUtil.isNotEmpty(firstAidRecords)) { |
|
|
|
firstAidRecords.forEach(firstAidRecord -> { |
|
|
|
firstAidRecord.setRecStatus((byte) 2); |
|
|
|
firstAidRecordDao.updateByPrimaryKeySelective(firstAidRecord); |
|
|
|
}); |
|
|
|
} |
|
|
|
//判断答案是否为空
|
|
|
|
if(CollectionUtil.isNotEmpty(codeAndAnswer.getAnswer())){ |
|
|
|
//循环答案
|
|
|
|
codeAndAnswer.getAnswer().forEach(answer -> saveRecord(param.getUserType(), userId, firstAid.getId(), codeAndAnswer.getQuestionCode(), StrUtil.isBlank(answer) ? "" : answer,param.getProjectId())); |
|
|
|
}else { |
|
|
|
saveRecord(param.getUserType(), userId, firstAid.getId(), codeAndAnswer.getQuestionCode(), "",param.getProjectId()); |
|
|
|
} |
|
|
|
if(StrUtil.isEmpty(codeAndAnswer.getQuestionCode())) { |
|
|
|
// code为空,终止本次循环
|
|
|
|
return; |
|
|
|
} |
|
|
|
//添加记录表,需要查找之前的记录,删除后重新添加
|
|
|
|
FirstAidRecordExample recordExample = new FirstAidRecordExample(); |
|
|
|
recordExample.createCriteria().andFirstAidIdEqualTo(firstAid.getId()).andQuestionCodeEqualTo(codeAndAnswer.getQuestionCode()); |
|
|
|
List<FirstAidRecord> firstAidRecords = firstAidRecordDao.selectByExample(recordExample); |
|
|
|
if (CollectionUtil.isNotEmpty(firstAidRecords)) { |
|
|
|
firstAidRecords.forEach(firstAidRecord -> { |
|
|
|
firstAidRecord.setRecStatus((byte) 2); |
|
|
|
firstAidRecordDao.updateByPrimaryKeySelective(firstAidRecord); |
|
|
|
}); |
|
|
|
} |
|
|
|
//判断答案是否为空
|
|
|
|
if(CollectionUtil.isNotEmpty(codeAndAnswer.getAnswer())){ |
|
|
|
//循环答案
|
|
|
|
codeAndAnswer.getAnswer().forEach(answer -> saveRecord(param.getUserType(), userId, firstAid.getId(), codeAndAnswer.getQuestionCode(), StrUtil.isBlank(answer) ? "" : answer,param.getProjectId())); |
|
|
|
}else { |
|
|
|
saveRecord(param.getUserType(), userId, firstAid.getId(), codeAndAnswer.getQuestionCode(), "",param.getProjectId()); |
|
|
|
} |
|
|
|
|
|
|
|
if (Constant.QuestionCode.QZSJ.equals(codeAndAnswer.getQuestionCode()) |
|
|
|
|| Constant.QuestionCode.THSJ.equals(codeAndAnswer.getQuestionCode())) { |
|
|
|
sendQcp(firstAid.getHospitalId(), codeAndAnswer, userId); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 给 qcp 消息 |
|
|
|
* @param hospitalId 医院ID |
|
|
|
* @param codeAndAnswer code答案 |
|
|
|
* @param userId |
|
|
|
*/ |
|
|
|
private void sendQcp(Long hospitalId, PatientDto.CodeAndAnswerN codeAndAnswer, Long userId) { |
|
|
|
String stepCode = Constant.QuestionCode.getStepCode(codeAndAnswer.getQuestionCode()); |
|
|
|
String value = codeAndAnswer.getAnswer().get(0); |
|
|
|
if (!StringUtil.checkNum(value, false)) { |
|
|
|
// 空或不为数字
|
|
|
|
return; |
|
|
|
} |
|
|
|
Long time = Long.parseLong(value); |
|
|
|
// 查找医院项目ID
|
|
|
|
OrganizationProject project = organizationProjectDao.queryByOrganizationId(hospitalId); |
|
|
|
log.info("医院{}对应的项目ID:{}", hospitalId, project); |
|
|
|
if (project == null) { |
|
|
|
// 没有项目,不处理
|
|
|
|
return; |
|
|
|
} |
|
|
|
Long projectId = project.getProjectId(); |
|
|
|
PatientDto.Qcp qcp = new PatientDto.Qcp(projectId, stepCode, time, userId); |
|
|
|
//通过MQ发送消息给QCP
|
|
|
|
rabbitTemplate.convertAndSend(Constant.MQ.QCP_NOTIFY_STEP, JSONObject.toJSONString(qcp)); |
|
|
|
log.info("向QCP发送消息:{}", qcp); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 时间检查 |
|
|
|
* @param param 存储答案 |
|
|
|
* @param firstAid 急救 |
|
|
|
*/ |
|
|
|
private void checkTime(PatientDto.SaveAidRecordN param, FirstAid firstAid) { |
|
|
|
for (PatientDto.CodeAndAnswerN answer: param.getCodeAndAnswerList()) { |
|
|
|
// 需要校验的时间
|
|
|
|