MzPayQrcodeService.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package thyyxxk.webserver.service.mzpayqrcode;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import org.springframework.web.client.RestTemplate;
  8. import thyyxxk.webserver.config.exception.ExceptionEnum;
  9. import thyyxxk.webserver.constants.Capacity;
  10. import thyyxxk.webserver.constants.ExternalAddr;
  11. import thyyxxk.webserver.dao.his.mzpayqrcode.MzPayQrcodeDao;
  12. import thyyxxk.webserver.entity.HrgResponse;
  13. import thyyxxk.webserver.entity.ResultVo;
  14. import thyyxxk.webserver.entity.mzpayqrcode.PatInfo;
  15. import thyyxxk.webserver.entity.mzpayqrcode.RoughIndex;
  16. import thyyxxk.webserver.utils.*;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * @author dj
  22. */
  23. @Slf4j
  24. @Service
  25. public class MzPayQrcodeService {
  26. private final MzPayQrcodeDao dao;
  27. private static final int MIN_PATIENT_ID_LENGTH = 7;
  28. @Autowired
  29. public MzPayQrcodeService(MzPayQrcodeDao dao) {
  30. this.dao = dao;
  31. }
  32. private PatInfo getPatientInfo(String patientId) {
  33. String socialNo = dao.selectSocialNoByPatientId(patientId);
  34. JSONObject obj = new JSONObject();
  35. obj.put("patIdType", 11);
  36. obj.put("patIdNo", socialNo);
  37. RestTemplate template = new RestTemplate();
  38. return template.postForObject(ExternalAddr.QUERY_PATIENT_INFO, obj, PatInfo.class);
  39. }
  40. public ResultVo<List<Map<String, String>>> getRoughList(String patientId) {
  41. if (null == patientId || patientId.length() < MIN_PATIENT_ID_LENGTH) {
  42. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请输入正确的门诊ID号。");
  43. }
  44. patientId = patientId.trim();
  45. JSONObject obj = new JSONObject();
  46. obj.put("patCardType", 21);
  47. obj.put("patCardNo", patientId);
  48. obj.put("hisOrdNum", "");
  49. RestTemplate template = new RestTemplate();
  50. HrgResponse hrgRes = template.postForObject(ExternalAddr.GET_MZ_CHARGE_DETAIL_FOR_UN_PAID, obj, HrgResponse.class);
  51. if (null == hrgRes || null == hrgRes.getResultCode()) {
  52. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "网络服务错误!");
  53. }
  54. if (hrgRes.getResultCode() != 0 ) {
  55. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgRes.getResultMessage());
  56. }
  57. List<Map<String, String>> list = FilterUtil.cast(hrgRes.getData());
  58. for (Map<String, String> item : list) {
  59. item.put("fixedAmt", DecimalUtil.divide(String.valueOf(item.get("totalAmt")), "100"));
  60. }
  61. return ResultVoUtil.success(list);
  62. }
  63. @SuppressWarnings("unchecked")
  64. public ResultVo<JSONObject> getDetailFees(RoughIndex param) {
  65. PatInfo patInfo = getPatientInfo(param.getPatientId());
  66. if (null == patInfo || null == patInfo.getResultCode() || 0 != patInfo.getResultCode()) {
  67. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "无法获取到患者个人信息!");
  68. }
  69. JSONObject pObj = new JSONObject();
  70. pObj.put("patCardType", 21);
  71. pObj.put("patCardNo", param.getPatientId());
  72. pObj.put("hisOrdNum", param.getHisOrdNum());
  73. RestTemplate template = new RestTemplate();
  74. HrgResponse hrgRes = template.postForObject(ExternalAddr.GET_CHARGE_DETAIL_BY_HIS_ORD_NUM, pObj, HrgResponse.class);
  75. if (null == hrgRes || null == hrgRes.getResultCode()) {
  76. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "网络服务错误!");
  77. }
  78. if (hrgRes.getResultCode() != 0 ) {
  79. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgRes.getResultMessage());
  80. }
  81. List<Map<String, String>> list = FilterUtil.cast(hrgRes.getData());
  82. JSONObject retObj = new JSONObject();
  83. retObj.put("list", makeSimpleData(list));
  84. RestTemplate restTemplate = new RestTemplate();
  85. ResultVo<String> qrResult = restTemplate.postForObject(ExternalAddr.CREATE_ORDER_FOR_MZ_GUIDE_BILL, param, ResultVo.class);
  86. if (null == qrResult || qrResult.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  87. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请求微信支付二维码失败,请联系管理员。");
  88. }
  89. retObj.put("wxQrcode", qrResult.getData());
  90. return ResultVoUtil.success(retObj);
  91. }
  92. private JSONArray makeSimpleData(List<Map<String, String>> arr) {
  93. JSONArray array = new JSONArray();
  94. Map<String, String> map = new HashMap<>(Capacity.DEFAULT);
  95. for (Map<String, String> item : arr) {
  96. final String itemType = "".equals(item.get("itemType")) ?
  97. " - " : item.get("itemType");
  98. String execDeptName = "".equals(item.get("execDeptName")) ?
  99. " - " : item.get("execDeptName");
  100. String execDeptAddress = "".equals(item.get("execDeptAddress")) ?
  101. " - " : item.get("execDeptAddress");
  102. if ("静脉采血".equals(item.get("itemName"))) {
  103. execDeptName = "急诊抽血室";
  104. execDeptAddress = "门诊大楼一楼";
  105. }
  106. String key = itemType + "^" + execDeptName + "^" + execDeptAddress;
  107. if (!map.containsKey(key)) {
  108. map.put(key, String.valueOf(item.get("itemTotalFee")));
  109. } else {
  110. String fee = DecimalUtil.add(String.valueOf(map.get(key)), String.valueOf(item.get("itemTotalFee")));
  111. map.replace(key, fee);
  112. }
  113. }
  114. for (Map.Entry<String, String> entry : map.entrySet()) {
  115. String[] keys = entry.getKey().split("\\^");
  116. JSONObject obj = new JSONObject();
  117. obj.put("itemType", keys[0]);
  118. obj.put("execDeptName", keys[1]);
  119. obj.put("execDeptAddress", keys[2]);
  120. obj.put("itemTotalFee", entry.getValue());
  121. obj.put("fixedAmt", DecimalUtil.divide(entry.getValue(), "100"));
  122. array.add(obj);
  123. }
  124. return array;
  125. }
  126. }