package thyyxxk.webserver.service.markmtfees; import com.alibaba.fastjson.JSONObject; 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.webserver.config.exception.ExceptionEnum; import thyyxxk.webserver.constants.Capacity; import thyyxxk.webserver.constants.ResponceType; import thyyxxk.webserver.dao.his.markmtfees.MarkMtFeesDao; import thyyxxk.webserver.pojo.ResultVo; import thyyxxk.webserver.pojo.markmtfees.*; import thyyxxk.webserver.utils.*; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author dj */ @Slf4j @Service public class MarkMtFeesService { private final MarkMtFeesDao dao; @Autowired public MarkMtFeesService(MarkMtFeesDao dao) { this.dao = dao; } public ResultVo> queryMtPersonInfo(QueryMtInfoParam param) { log.info("查询门特身份:{}", param); String patientId = param.getPatientId(); if (StringUtil.isBlank(patientId)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请输入正确的门诊id号!"); } patientId = patientId.trim(); if (StringUtil.notBlank(param.getPhoneNo())) { dao.updatePhoneNo(patientId, param.getPhoneNo()); } if (StringUtil.notBlank(param.getIdCard())) { dao.updateSocialNo(patientId, param.getIdCard()); } Integer times = dao.selectMaxTimes(patientId); if (null == times || times == 0) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未查询到些患者的就诊信息,请检查!"); } if (StringUtil.isBlank(param.getIdCard())) { param.setIdCard(dao.selectSocialNoByPatientId(patientId)); } if (!IdCardUtil.isValidatedIdCard(param.getIdCard())) { return ResultVoUtil.fail(ExceptionEnum.SLIGHTLY_ERROR, "应医保局要求,门诊特殊病患者的身份证不能为空,请补充。"); } if (StringUtil.isBlank(param.getPhoneNo())) { param.setPhoneNo(dao.selectPhoneNo(patientId)); } if (StringUtil.isBlank(param.getPhoneNo())) { return ResultVoUtil.fail(ExceptionEnum.SLIGHTLY_ERROR, "应医保局要求,门诊特殊病患者的联系电话不能为空,请补充。"); } Map data = new HashMap<>(Capacity.THREE); data.put("patientId", patientId); data.put("times", times); int mtCount; if (ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE.equals(param.getResponceType())) { mtCount = dao.selectCountMtPartInfo(patientId, times); } else { mtCount = dao.selectCountMtPartInfoForSyb(patientId, times, param.getBizType()); } if (mtCount > 0) { return ResultVoUtil.success(data); } param.setStaffId(TokenUtil.getTokenUserId()); RestTemplate template = new RestTemplate(); Object mapRet; if (ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE.equals(param.getResponceType())) { param.setBizType("13"); mapRet = template.postForObject(YbLinksUtil.normalLinks.get("hnsybMtInfo"), param, Object.class); } else { mapRet = template.postForObject(YbLinksUtil.normalLinks.get("cssybReadMzPatient"), param, Object.class); } if (null == mapRet) { return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "服务器内部错误,查询门特身份信息失败。"); } Map map = FilterUtil.cast(mapRet); if (ExceptionEnum.SUCCESS.getCode() != (int) map.get("code")) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, map.get("message").toString()); } if (ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE.equals(param.getResponceType())) { Map hnsybRet = FilterUtil.cast(map.get("data")); List> spinfos = FilterUtil.cast(hnsybRet.get("spinfo")); Map spinfo = spinfos.get(0); String icd = spinfo.get("icd"); String serialApply = spinfo.get("serial_apply"); spinfos = FilterUtil.cast(hnsybRet.get("personinfo")); String balance = spinfos.get(0).get("last_balance"); dao.insertHnsybMtPartInfo(patientId, times, icd, balance, serialApply); return ResultVoUtil.success(data); } data.put("list", map.get("data")); return ResultVoUtil.success(data); } public ResultVo confirmCssybMtApplyInfo(CssybApplyInfo param) { int mtCount = dao.selectCountMtPartInfoForSyb(param.getPatientId(), param.getTimes(), param.getBizType()); if (mtCount > 0) { return ResultVoUtil.success(); } dao.clearMtPartInfo(param.getPatientId(), param.getTimes()); param.setMzSerialNo(SnowFlakeId.instance().nextId()); dao.insertCssybMtPartInfo(param); return ResultVoUtil.success(); } public ResultVo> getMtReceipts(String patientId, Integer times) { Map map = new HashMap<>(Capacity.FOUR); List mzPatients = dao.selectMzPatient(patientId, times); if (null == mzPatients || mzPatients.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patientId + ",就诊次数:" + times + "】未找到此患者的本次就诊信息,请核实。"); } MzVisit mzVisit = dao.selectMzVisit(patientId, times); if (null == mzVisit) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patientId + ",就诊次数:" + times + "】未找到此患者的本次就诊信息,请核实。"); } map.put("mzPatient", mzPatients.get(0)); map.put("mzVisit", mzVisit); List mzReceipts = dao.selectMzReceipts(patientId, times, mzVisit.getReceiptNo()); mzReceipts.removeIf(item -> "TC".equals(item.getBillItemCode()) || item.getPayMark() != 5 || "BILL99".equals(item.getChargeItemCode())); Map> temp = new HashMap<>(Capacity.DEFAULT); mzReceipts.forEach(item -> { item.setChecked(true); if (!temp.containsKey(item.getOrderNo())) { List list = new ArrayList<>(); list.add(item); temp.put(item.getOrderNo(), list); } else { temp.get(item.getOrderNo()).add(item); } }); List orderNos = new ArrayList<>(); for (Map.Entry> entry : temp.entrySet()) { OrderNo orderNo = new OrderNo(); orderNo.setPatientId(patientId); orderNo.setTimes(times); orderNo.setReceiptNo(mzVisit.getReceiptNo()); orderNo.setOrderNo(entry.getKey()); BigDecimal total = new BigDecimal("0.00"); for (MzReceipt item : entry.getValue()) { total = total.add(item.getChargeFee()); } orderNo.setTotalFee(total); int count = dao.selectFeeCount(patientId, times, mzVisit.getReceiptNo(), entry.getKey()); orderNo.setStatus(count > 0); orderNos.add(orderNo); } map.put("orderNos", orderNos); map.put("mzReceipts", temp); return ResultVoUtil.success(map); } public ResultVo insertMtFees(MarkMtFeeParam param) { if (param.getResponceType().equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) { param.setYbType("13"); } MzReceipt receipt = param.getReceipts().get(0); int count = dao.selectFeeCount(receipt.getPatientId(), receipt.getTimes(), receipt.getReceiptNo(), receipt.getOrderNo()); if (count > 0) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该处方已生成过门特费用,请勿重复操作。"); } dao.insertMzChargeYb(receipt.getPatientId(), receipt.getTimes(), receipt.getReceiptNo(), receipt.getOrderNo(), param.getResponceType(), param.getYbType()); param.getReceipts().forEach(item -> { if (item.getChecked()) { dao.insertBatchedMtFeeInfo(item); } }); return ResultVoUtil.success(); } public ResultVo deleteMtFees(OrderNo param) { dao.deleteMtFees(param); return ResultVoUtil.success(); } public ResultVo cssybMtPreCal(String patientId, Integer times) { JSONObject param = new JSONObject(); param.put("patientId", patientId); param.put("times", times); param.put("staffId", TokenUtil.getTokenUserId()); log.info("市门特试算:{}", param); RestTemplate template = new RestTemplate(); Object mapRet = template.postForObject(YbLinksUtil.normalLinks.get("cssybMtPreCal"), param, Object.class); log.info("市门特试算结果:{}", mapRet); if (null == mapRet) { return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "服务器内部错误,门特费用试算失败。"); } Map map = FilterUtil.cast(mapRet); if (ExceptionEnum.SUCCESS.getCode() != (int) map.get("code")) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, map.get("message").toString()); } return ResultVoUtil.success(map.get("data")); } public Map uploadMtFees(UploadMtFeeParam param) { log.info("上传省门特费用:{}", param); Map resultMap = new HashMap<>(Capacity.TWO); String responceType = dao.selectResponceType(param.getPatientId(), param.getTimes()); if (null == responceType) { resultMap.put("code", -1); resultMap.put("msg", "未查询到此人的门特身份记录。"); return resultMap; } String urlHead = YbLinksUtil.normalLinks.get("mtBase"); String urlEnd; if (responceType.equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) { urlEnd = ":2000/shengyb/mt/uploadFees"; } else { urlEnd = ":1000/mzsyb/mzCalculate"; } String url = urlHead + urlEnd; RestTemplate restTemplate = new RestTemplate(); Object templateRet = restTemplate.postForObject(url, param, Object.class); log.info("上传省门特费用结果:{}", templateRet); return FilterUtil.cast(templateRet); } public Map retractMtFees(UploadMtFeeParam param) { log.info("撤销门特费用:{}", param); Map resultMap = new HashMap<>(Capacity.TWO); String responceType = dao.selectResponceType(param.getPatientId(), param.getTimes()); if (null == responceType) { resultMap.put("code", -1); resultMap.put("msg", "未查询到此人的门特身份记录。"); return resultMap; } String urlHead = YbLinksUtil.normalLinks.get("mtBase"); String urlEnd; if (responceType.equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) { urlEnd = ":2000/shengyb/mt/retractFees"; } else { urlEnd = ":1000/mzsyb/mzCancelCalculate"; } String url = urlHead + urlEnd; RestTemplate restTemplate = new RestTemplate(); Object templateRet = restTemplate.postForObject(url, param, Object.class); return FilterUtil.cast(templateRet); } public Map calculateMtFees(UploadMtFeeParam param) { log.info("结算门特费用:{}", param); Map resultMap = new HashMap<>(Capacity.TWO); String responceType = dao.selectResponceType(param.getPatientId(), param.getTimes()); if (null == responceType) { resultMap.put("code", -1); resultMap.put("msg", "未查询到此人的门特身份记录。"); return resultMap; } String urlHead = YbLinksUtil.normalLinks.get("mtBase"); String urlEnd; if (responceType.equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) { urlEnd = ":2000/shengyb/mt/calculateCost"; } else { urlEnd = ":1000/mzsyb/mzCalculate"; } String url = urlHead + urlEnd; RestTemplate restTemplate = new RestTemplate(); Object templateRet = restTemplate.postForObject(url, param, Object.class); log.info("结算门特费用结果:{}", templateRet); return FilterUtil.cast(templateRet); } }