MakeDbzFeesService.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package thyyxxk.webserver.service.makedbzfees;
  2. import com.alibaba.fastjson.JSONObject;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.transaction.annotation.Transactional;
  7. import org.springframework.web.client.RestTemplate;
  8. import thyyxxk.webserver.config.exception.ExceptionEnum;
  9. import thyyxxk.webserver.dao_his.makedbzfees.MakeDbzFeesDao;
  10. import thyyxxk.webserver.pojo.HrgResponse;
  11. import thyyxxk.webserver.pojo.ResultVo;
  12. import thyyxxk.webserver.pojo.makedbzfees.*;
  13. import thyyxxk.webserver.utils.*;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.concurrent.atomic.AtomicInteger;
  18. @Slf4j
  19. @Service
  20. public class MakeDbzFeesService {
  21. private final MakeDbzFeesDao dao;
  22. @Autowired
  23. public MakeDbzFeesService(MakeDbzFeesDao dao) {
  24. this.dao = dao;
  25. }
  26. public ResultVo<List<Map<String, String>>> getReceipts(GetMzFeesParam param) {
  27. String patientId = param.getCardNo();
  28. if (1 == param.getCardType()) {
  29. patientId = dao.getPatientId(param.getCardNo());
  30. }
  31. if (null == patientId || patientId.trim().equals("")) {
  32. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到门诊id!");
  33. }
  34. JSONObject obj = new JSONObject();
  35. obj.put("patCardType", 21);
  36. obj.put("patCardNo", patientId);
  37. obj.put("hisOrdNum", null);
  38. RestTemplate template = new RestTemplate();
  39. HrgResponse hrgRes = template.postForObject(HrgAddr.GET_MZ_CHARGE_DETAIL_FOR_UN_PAID, obj, HrgResponse.class);
  40. if (null == hrgRes || null == hrgRes.getResultCode()) {
  41. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "网络服务错误!");
  42. }
  43. if (hrgRes.getResultCode() != 0) {
  44. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgRes.getResultMessage());
  45. }
  46. List<Map<String, String>> list = FilterUtil.cast(hrgRes.getData());
  47. List<Map<String, String>> data = new ArrayList<>();
  48. for (Map<String, String> item : list) {
  49. String[] str = item.get("hisOrdNum").split("_");
  50. JSONObject p = new JSONObject();
  51. p.put("patientId", str[0]);
  52. p.put("times", str[1]);
  53. p.put("receiptNo", str[2]);
  54. HrgResponse hrgResponse = template.postForObject(HrgAddr.UN_PAID_TO_FULL_CHARGE_DETAIL, p, HrgResponse.class);
  55. if (null == hrgResponse || null == hrgResponse.getResultCode()) {
  56. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "网络服务错误!");
  57. }
  58. if (hrgResponse.getResultCode() != 0) {
  59. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgResponse.getResultMessage());
  60. }
  61. List<Map<String, String>> details = FilterUtil.cast(hrgResponse.getData());
  62. for (Map<String, String> pojo : details) {
  63. if (!"TC".equals(pojo.get("billItemCode")) && "5".equals(pojo.get("payMark"))) {
  64. pojo.replace("priceTime", DateUtil.formatPriceTime(pojo.get("priceTime")));
  65. data.add(pojo);
  66. }
  67. }
  68. }
  69. return ResultVoUtil.success(data);
  70. }
  71. @Transactional(rollbackFor = Exception.class)
  72. public ResultVo<String> saveToZyFees(SaveZyFeesParam param) {
  73. String inpatientNo = param.getCardNo();
  74. if (param.getCardType() == 2) {
  75. inpatientNo = dao.getInpatientNo(param.getCardNo());
  76. }
  77. if (null == inpatientNo || inpatientNo.equals("")) {
  78. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的住院号!请确认患者有住院身份。");
  79. }
  80. InpatientInfoPojo inpatientInfo = dao.getInpatientInfo(inpatientNo);
  81. if (null == inpatientInfo) {
  82. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的在院信息!请确认此患者已经办理住院。");
  83. }
  84. inpatientInfo.setStaffId(TokenUtil.getTokenUserId());
  85. AtomicInteger detailSn = new AtomicInteger(inpatientInfo.getMaxDetailSn());
  86. List<ZyDetailChargePojo> zyFees = new ArrayList<>();
  87. for (MzChargeDetailPojo mzFee : param.getList()) {
  88. if (mzFee.getBillItemCode().equalsIgnoreCase("TC")) {
  89. continue;
  90. }
  91. ZyDetailChargePojo zyFee = new ZyDetailChargePojo();
  92. zyFee.setChargeCodeMx(mzFee.getChargeItemCode());
  93. if (mzFee.getGroupNo().equals("00")) {
  94. zyFee.setChargeCode(mzFee.getChargeItemCode());
  95. } else if (mzFee.getGroupNo().equals("81") || mzFee.getGroupNo().equals("82")) {
  96. zyFee.setChargeCode("BILL01");
  97. } else {
  98. zyFee.setChargeCode("BILL02");
  99. }
  100. zyFee.setDetailSn(detailSn.incrementAndGet());
  101. zyFee.setChargeFee(mzFee.getChargeFee());
  102. zyFee.setChargeAmount(mzFee.getQuantity());
  103. zyFee.setSerial(mzFee.getSerial());
  104. zyFee.setDoctorCode(mzFee.getDoctorCode());
  105. zyFees.add(zyFee);
  106. dao.updateFyPayMark(mzFee.getPatientId(), mzFee.getTimes(), mzFee.getItemNo());
  107. if (null != mzFee.getReqYj() && 1 == mzFee.getReqYj()) {
  108. dao.updateYjPayMark(mzFee.getPatientId(), mzFee.getTimes(), mzFee.getReqNo());
  109. log.info("update yj: {}, {}, {}", mzFee.getPatientId(), mzFee.getTimes(), mzFee.getReqNo());
  110. }
  111. }
  112. if (zyFees.size() <= 20) {
  113. dao.insertInfoZyDetailCharge(inpatientInfo, zyFees);
  114. } else {
  115. List<ZyDetailChargePojo> tempList = new ArrayList<>();
  116. for (ZyDetailChargePojo item : zyFees) {
  117. tempList.add(item);
  118. if (tempList.size() == 20) {
  119. dao.insertInfoZyDetailCharge(inpatientInfo, tempList);
  120. tempList.clear();
  121. }
  122. }
  123. if (tempList.size() > 0) {
  124. dao.insertInfoZyDetailCharge(inpatientInfo, tempList);
  125. }
  126. }
  127. return ResultVoUtil.success();
  128. }
  129. }