123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package thyyxxk.webserver.service.mzpayqrcode;
- import com.alibaba.fastjson.JSONArray;
- 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.ExternalAddr;
- import thyyxxk.webserver.dao.his.mzpayqrcode.MzPayQrcodeDao;
- import thyyxxk.webserver.entity.HrgResponse;
- import thyyxxk.webserver.entity.ResultVo;
- import thyyxxk.webserver.entity.mzpayqrcode.PatInfo;
- import thyyxxk.webserver.entity.mzpayqrcode.RoughIndex;
- import thyyxxk.webserver.utils.*;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * @author dj
- */
- @Slf4j
- @Service
- public class MzPayQrcodeService {
- private final MzPayQrcodeDao dao;
- private static final int MIN_PATIENT_ID_LENGTH = 7;
- @Autowired
- public MzPayQrcodeService(MzPayQrcodeDao dao) {
- this.dao = dao;
- }
- private PatInfo getPatientInfo(String patientId) {
- String socialNo = dao.selectSocialNoByPatientId(patientId);
- JSONObject obj = new JSONObject();
- obj.put("patIdType", 11);
- obj.put("patIdNo", socialNo);
- RestTemplate template = new RestTemplate();
- return template.postForObject(ExternalAddr.QUERY_PATIENT_INFO, obj, PatInfo.class);
- }
- public ResultVo<List<Map<String, String>>> getRoughList(String patientId) {
- if (null == patientId || patientId.length() < MIN_PATIENT_ID_LENGTH) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请输入正确的门诊ID号。");
- }
- patientId = patientId.trim();
- JSONObject obj = new JSONObject();
- obj.put("patCardType", 21);
- obj.put("patCardNo", patientId);
- obj.put("hisOrdNum", "");
- RestTemplate template = new RestTemplate();
- HrgResponse hrgRes = template.postForObject(ExternalAddr.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<Map<String, String>> list = FilterUtil.cast(hrgRes.getData());
- for (Map<String, String> item : list) {
- item.put("fixedAmt", DecimalUtil.divide(String.valueOf(item.get("totalAmt")), "100"));
- }
- return ResultVoUtil.success(list);
- }
- @SuppressWarnings("unchecked")
- public ResultVo<JSONObject> getDetailFees(RoughIndex param) {
- PatInfo patInfo = getPatientInfo(param.getPatientId());
- if (null == patInfo || null == patInfo.getResultCode() || 0 != patInfo.getResultCode()) {
- return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "无法获取到患者个人信息!");
- }
- JSONObject pObj = new JSONObject();
- pObj.put("patCardType", 21);
- pObj.put("patCardNo", param.getPatientId());
- pObj.put("hisOrdNum", param.getHisOrdNum());
- RestTemplate template = new RestTemplate();
- HrgResponse hrgRes = template.postForObject(ExternalAddr.GET_CHARGE_DETAIL_BY_HIS_ORD_NUM, pObj, 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<Map<String, String>> list = FilterUtil.cast(hrgRes.getData());
- JSONObject retObj = new JSONObject();
- retObj.put("list", makeSimpleData(list));
- RestTemplate restTemplate = new RestTemplate();
- ResultVo<String> qrResult = restTemplate.postForObject(ExternalAddr.CREATE_ORDER_FOR_MZ_GUIDE_BILL, param, ResultVo.class);
- if (null == qrResult || qrResult.getCode() != ExceptionEnum.SUCCESS.getCode()) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请求微信支付二维码失败,请联系管理员。");
- }
- retObj.put("wxQrcode", qrResult.getData());
- return ResultVoUtil.success(retObj);
- }
- private JSONArray makeSimpleData(List<Map<String, String>> arr) {
- JSONArray array = new JSONArray();
- Map<String, String> map = new HashMap<>(Capacity.DEFAULT);
- for (Map<String, String> item : arr) {
- final String itemType = "".equals(item.get("itemType")) ?
- " - " : item.get("itemType");
- String execDeptName = "".equals(item.get("execDeptName")) ?
- " - " : item.get("execDeptName");
- String execDeptAddress = "".equals(item.get("execDeptAddress")) ?
- " - " : item.get("execDeptAddress");
- if ("静脉采血".equals(item.get("itemName"))) {
- execDeptName = "急诊抽血室";
- execDeptAddress = "门诊大楼一楼";
- }
- String key = itemType + "^" + execDeptName + "^" + execDeptAddress;
- if (!map.containsKey(key)) {
- map.put(key, String.valueOf(item.get("itemTotalFee")));
- } else {
- String fee = DecimalUtil.add(String.valueOf(map.get(key)), String.valueOf(item.get("itemTotalFee")));
- map.replace(key, fee);
- }
- }
- for (Map.Entry<String, String> entry : map.entrySet()) {
- String[] keys = entry.getKey().split("\\^");
- JSONObject obj = new JSONObject();
- obj.put("itemType", keys[0]);
- obj.put("execDeptName", keys[1]);
- obj.put("execDeptAddress", keys[2]);
- obj.put("itemTotalFee", entry.getValue());
- obj.put("fixedAmt", DecimalUtil.divide(entry.getValue(), "100"));
- array.add(obj);
- }
- return array;
- }
- }
|