package thyyxxk.webserver.service.makedbzfees; 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.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; import thyyxxk.webserver.config.exception.ExceptionEnum; import thyyxxk.webserver.dao_his.makedbzfees.MakeDbzFeesDao; import thyyxxk.webserver.pojo.HrgResponse; import thyyxxk.webserver.pojo.ResultVo; import thyyxxk.webserver.pojo.makedbzfees.*; import thyyxxk.webserver.utils.*; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @Slf4j @Service public class MakeDbzFeesService { private final MakeDbzFeesDao dao; @Autowired public MakeDbzFeesService(MakeDbzFeesDao dao) { this.dao = dao; } public ResultVo>> getReceipts(GetMzFeesParam param) { String patientId = param.getCardNo(); if (1 == param.getCardType()) { patientId = dao.getPatientId(param.getCardNo()); } if (null == patientId || patientId.trim().equals("")) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到门诊id!"); } JSONObject obj = new JSONObject(); obj.put("patCardType", 21); obj.put("patCardNo", patientId); obj.put("hisOrdNum", null); RestTemplate template = new RestTemplate(); HrgResponse hrgRes = template.postForObject(HrgAddr.GET_MZ_CHARGE_DETAIL_FOR_UN_PAID, obj, HrgResponse.class); if (null == hrgRes || null == hrgRes.getResultCode()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "网络服务错误!"); } if (hrgRes.getResultCode() != 0) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgRes.getResultMessage()); } List> list = FilterUtil.cast(hrgRes.getData()); List> data = new ArrayList<>(); for (Map item : list) { String[] str = item.get("hisOrdNum").split("_"); JSONObject p = new JSONObject(); p.put("patientId", str[0]); p.put("times", str[1]); p.put("receiptNo", str[2]); HrgResponse hrgResponse = template.postForObject(HrgAddr.UN_PAID_TO_FULL_CHARGE_DETAIL, p, HrgResponse.class); if (null == hrgResponse || null == hrgResponse.getResultCode()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "网络服务错误!"); } if (hrgResponse.getResultCode() != 0) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgResponse.getResultMessage()); } List> details = FilterUtil.cast(hrgResponse.getData()); for (Map pojo : details) { if (!"TC".equals(pojo.get("billItemCode")) && "5".equals(pojo.get("payMark"))) { pojo.replace("priceTime", DateUtil.formatPriceTime(pojo.get("priceTime"))); data.add(pojo); } } } return ResultVoUtil.success(data); } @Transactional(rollbackFor = Exception.class) public ResultVo saveToZyFees(SaveZyFeesParam param) { String inpatientNo = param.getCardNo(); if (param.getCardType() == 2) { inpatientNo = dao.getInpatientNo(param.getCardNo()); } if (null == inpatientNo || inpatientNo.equals("")) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的住院号!请确认患者有住院身份。"); } InpatientInfoPojo inpatientInfo = dao.getInpatientInfo(inpatientNo); if (null == inpatientInfo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的在院信息!请确认此患者已经办理住院。"); } inpatientInfo.setStaffId(TokenUtil.getTokenUserId()); AtomicInteger detailSn = new AtomicInteger(inpatientInfo.getMaxDetailSn()); List zyFees = new ArrayList<>(); for (MzChargeDetailPojo mzFee : param.getList()) { if (mzFee.getBillItemCode().equalsIgnoreCase("TC")) { continue; } ZyDetailChargePojo zyFee = new ZyDetailChargePojo(); zyFee.setChargeCodeMx(mzFee.getChargeItemCode()); if (mzFee.getGroupNo().equals("00")) { zyFee.setChargeCode(mzFee.getChargeItemCode()); } else if (mzFee.getGroupNo().equals("81") || mzFee.getGroupNo().equals("82")) { zyFee.setChargeCode("BILL01"); } else { zyFee.setChargeCode("BILL02"); } zyFee.setDetailSn(detailSn.incrementAndGet()); zyFee.setChargeFee(mzFee.getChargeFee()); zyFee.setChargeAmount(mzFee.getQuantity()); zyFee.setSerial(mzFee.getSerial()); zyFee.setDoctorCode(mzFee.getDoctorCode()); zyFees.add(zyFee); dao.updateFyPayMark(mzFee.getPatientId(), mzFee.getTimes(), mzFee.getItemNo()); if (null != mzFee.getReqYj() && 1 == mzFee.getReqYj()) { dao.updateYjPayMark(mzFee.getPatientId(), mzFee.getTimes(), mzFee.getReqNo()); log.info("update yj: {}, {}, {}", mzFee.getPatientId(), mzFee.getTimes(), mzFee.getReqNo()); } } if (zyFees.size() <= 20) { dao.insertInfoZyDetailCharge(inpatientInfo, zyFees); } else { List tempList = new ArrayList<>(); for (ZyDetailChargePojo item : zyFees) { tempList.add(item); if (tempList.size() == 20) { dao.insertInfoZyDetailCharge(inpatientInfo, tempList); tempList.clear(); } } if (tempList.size() > 0) { dao.insertInfoZyDetailCharge(inpatientInfo, tempList); } } return ResultVoUtil.success(); } }