package thyyxxk.wxservice_server.service; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import thyyxxk.wxservice_server.config.exception.ExceptionEnum; import thyyxxk.wxservice_server.config.properties.ApiAddr; import thyyxxk.wxservice_server.constant.Constants; import thyyxxk.wxservice_server.dao.InpatientDao; import thyyxxk.wxservice_server.entity.ResultVo; import thyyxxk.wxservice_server.entity.inpatient.DoorFace; import thyyxxk.wxservice_server.entity.inpatient.GetZyFeeParam; import thyyxxk.wxservice_server.entity.inpatient.InpatientInfo; import thyyxxk.wxservice_server.entity.inpatient.ZyFee; import thyyxxk.wxservice_server.utils.DecimalTool; import thyyxxk.wxservice_server.utils.ResultVoUtil; import thyyxxk.wxservice_server.utils.StringUtil; import java.util.*; /** * @author dj */ @Slf4j @Service public class InpatientService { private final InpatientDao dao; private final String addFaceApi; @Autowired public InpatientService(InpatientDao dao, ApiAddr apiAddr) { this.dao = dao; this.addFaceApi = apiAddr.getAddFaceApi(); } public ResultVo getInpatientInfo(String patientId) { List inpatientNos = getInpatientNoByPatientId(patientId); if (inpatientNos.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有找到此卡号对应的住院号。"); } InpatientInfo info; for (String inpatientNo : inpatientNos) { info = dao.getInpatientInfo(inpatientNo); if (null != info) { info.setPatientId(patientId); return ResultVoUtil.success(info); } } return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有找到此卡号的在院信息。"); } public ResultVo getInpatientBaseInfo(String inpatientNo) { InpatientInfo info = dao.getInpatientInfo(inpatientNo); if (null == info) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有找到此住院号的在院信息。"); } String socialNo = dao.selectSocialNoByInpatientNo(inpatientNo); if (StringUtil.notBlank(socialNo)) { info.setSocialNo(socialNo); String patientId = dao.selectPatientIdBySocialNo(socialNo); if (StringUtil.notBlank(patientId)) { info.setPatientId(patientId); } } return ResultVoUtil.success(info); } public ResultVo> getZyFees(GetZyFeeParam param) { dao.receiveProjectFees(param.getInpatientNo(), param.getAdmissTimes()); dao.receiveMedicineFees(param.getInpatientNo(), param.getAdmissTimes()); Map map = new HashMap<>(Constants.Capacity.TWO); List fees = dao.selectZyFees(param); String total = "0.00"; for (ZyFee fee : fees) { total = DecimalTool.add(total, fee.getJe()); } map.put("fees", fees); map.put("totalCost", total); return ResultVoUtil.success(map); } public ResultVo> getPrepaidHistory(String patientId) { ResultVo infoResultVo = getInpatientInfo(patientId); if (infoResultVo.getCode() != ExceptionEnum.SUCCESS.getCode()) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, infoResultVo.getMessage()); } InpatientInfo info = infoResultVo.getData(); Map map = new HashMap<>(Constants.Capacity.TWO); map.put("baseInfo", info); map.put("prepaid", dao.selectPrepaidHistory(info.getInpatientNo(), info.getAdmissTimes())); return ResultVoUtil.success(map); } public List getInpatientNoByPatientId(String patientId) { List inpatientNos = dao.selectInpatientNoByPatientId(patientId); if (inpatientNos.isEmpty()) { inpatientNos = dao.selectInpatientNoBySocialNo(patientId); } log.info("getInpatientNoByPatientId:{}, {}", patientId, inpatientNos); return inpatientNos; } public ResultVo updateDoorFace(DoorFace request) { log.info("修改人脸信息:{}", request.getFaceData()); request.setFaceData(request.getFaceData().split("base64,")[1]); return new RestTemplate().postForObject(addFaceApi, request, ResultVo.class); } }