package thyyxxk.webserver.service.medicalinsurance; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import thyyxxk.webserver.config.exception.ExceptionEnum; import thyyxxk.webserver.constants.sidicts.SiFunction; import thyyxxk.webserver.constants.YesOrNo; import thyyxxk.webserver.constants.sidicts.*; import thyyxxk.webserver.dao.his.medicalinsurance.SiQueryDao; import thyyxxk.webserver.dao.his.medicalinsurance.SiSetlinfoDao; import thyyxxk.webserver.entity.ResultVo; import thyyxxk.webserver.entity.dictionary.PureCodeName; import thyyxxk.webserver.entity.medicalinsurance.inpatient.InHspPsnInfo; import thyyxxk.webserver.entity.medicalinsurance.outpatient.SpcChrDiseAcct; import thyyxxk.webserver.entity.medicalinsurance.query.*; import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetldetail; import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo; import thyyxxk.webserver.entity.medicalinsurance.setlinfo.TimesList; import thyyxxk.webserver.entity.medicalinsurance.setllist.*; import thyyxxk.webserver.entity.yibao.ZyActpatient; import thyyxxk.webserver.service.redislike.RedisLikeService; import thyyxxk.webserver.service.wxapi.SendWxInfoService; import thyyxxk.webserver.utils.*; import java.math.BigDecimal; import java.time.LocalDate; import java.util.*; /** * @description: 医保查询服务 * @author: DingJie * @create: 2021-06-23 16:35:23 **/ @Slf4j @Service public class SiQueryService { private final ExecService exec; private final SiQueryDao dao; private final SendWxInfoService wxsrvc; private final SiSetlinfoDao setlinfoDao; private final RedisLikeService redis; private static final String RESULT_CODE = "infcode"; private static final String ERROR_MESSAGE = "err_msg"; private static final String OUTPUT = "output"; @Autowired public SiQueryService(ExecService exec, SiQueryDao dao, SendWxInfoService wxsrvc, SiSetlinfoDao setlinfoDao, RedisLikeService redis) { this.exec = exec; this.dao = dao; this.wxsrvc = wxsrvc; this.setlinfoDao = setlinfoDao; this.redis = redis; } public ResultVo getSiPatInfo(QryPsnBsInfo qryPsnBsInfo) { SiPatInfo siPatInfo = dao.selectSiPatInfoForZy(qryPsnBsInfo.getPatNo(), qryPsnBsInfo.getTimes(), qryPsnBsInfo.getLedgerSn()); if (null == siPatInfo) { siPatInfo = new SiPatInfo(); } return ResultVoUtil.success(siPatInfo); } public ResultVo fetchPsnNo(String socialNo, String admdvs) { if (StringUtil.isBlank(socialNo)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的身份证不能为空,请补充!"); } if (StringUtil.isBlank(admdvs)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的参保地区不能为空,请补充!"); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OBTAIN_BASIC_PERSON_INFO, admdvs); JSONObject data = new JSONObject(); data.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode()); data.put("psn_cert_type", "01"); data.put("mdtrt_cert_no", socialNo); data.put("certno", socialNo); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_BASIC_PERSON_INFO); log.info("【操作员:{}】,人员基本信息获取:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONObject baseinfo = output.getJSONObject("baseinfo"); String psnNo = baseinfo.getString("psn_no"); if (StringUtil.notBlank(psnNo)) { return ResultVoUtil.success(psnNo); } } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "无法查询到患者的医保个人编码。"); } public ResultVo obtainBasicPersonInfo(QryPsnBsInfo qryPsnBsInfo) { if (null == qryPsnBsInfo.getOnlyQry() && StringUtil.isBlank(qryPsnBsInfo.getMedType())) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "请选择患者的医疗类别!"); } if (StringUtil.isBlank(qryPsnBsInfo.getSocialNo()) && StringUtil.notBlank(qryPsnBsInfo.getPatNo()) && qryPsnBsInfo.getPatNo().length() >= 15) { qryPsnBsInfo.setSocialNo(qryPsnBsInfo.getPatNo()); } if (StringUtil.isBlank(qryPsnBsInfo.getSocialNo())) { QryPsnBsInfo qpbi = dao.selectMzSocialAndName(qryPsnBsInfo.getPatNo()); if (StringUtil.isBlank(qpbi.getSocialNo())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的身份证不能为空,请补充!"); } if (null == qryPsnBsInfo.getTimes()) { qryPsnBsInfo.setTimes(qpbi.getTimes()); } qryPsnBsInfo.setName(qpbi.getName()); qryPsnBsInfo.setSocialNo(qpbi.getSocialNo()); qryPsnBsInfo.setLedgerSn(0); } if (null != qryPsnBsInfo.getLedgerSn() && qryPsnBsInfo.getLedgerSn() != 0) { qryPsnBsInfo.setLedgerSn(dao.selectMaxLedgerSn(qryPsnBsInfo.getPatNo(), qryPsnBsInfo.getTimes())); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OBTAIN_BASIC_PERSON_INFO, qryPsnBsInfo.getAdmdvs()); JSONObject data = new JSONObject(); if (qryPsnBsInfo.getSocialNo().length() < 15) { data.put("mdtrt_cert_type", MdtrtCertType.OTHER.getCode()); data.put("psn_cert_type", PsnCertType.RESIDENCE_PERMIT_FOR_HMT.getCode()); } else { data.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode()); data.put("psn_cert_type", "01"); } data.put("mdtrt_cert_no", qryPsnBsInfo.getSocialNo()); data.put("certno", qryPsnBsInfo.getSocialNo()); if (StringUtil.notBlank(qryPsnBsInfo.getName())) { data.put("psn_name", qryPsnBsInfo.getName()); } input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_BASIC_PERSON_INFO); log.info("【操作员:{}】,人员基本信息获取:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONObject baseinfo = output.getJSONObject("baseinfo"); PsnBaseInfo psnBaseinfo = JSONObject.parseObject(baseinfo.toJSONString(), PsnBaseInfo.class); psnBaseinfo.setPatNo(qryPsnBsInfo.getPatNo()); psnBaseinfo.setTimes(qryPsnBsInfo.getTimes()); psnBaseinfo.setLedgerSn(qryPsnBsInfo.getLedgerSn()); psnBaseinfo.setMedType(qryPsnBsInfo.getMedType()); psnBaseinfo.setGendName(Gend.get(psnBaseinfo.getGend()).getName()); psnBaseinfo.setPsnCertTypeName(PsnCertType.get(psnBaseinfo.getPsnCertType()).getName()); Naty naty = Naty.get(psnBaseinfo.getNaty()); if (null != naty) { psnBaseinfo.setNatyName(naty.getName()); } List idetInfos = new ArrayList<>(); JSONArray idet = output.getJSONArray("idetinfo"); for (int i = 0; i < idet.size(); i++) { JSONObject item = idet.getJSONObject(i); IdetInfo info = JSONObject.parseObject(item.toJSONString(), IdetInfo.class); PsnIdetType psnIdetType = PsnIdetType.get(info.getPsnIdetType()); if (null != psnIdetType) { psnBaseinfo.setPsnIdetType(psnIdetType.getCode()); info.setPsnIdetTypeName(psnIdetType.getName()); } idetInfos.add(info); } if (StringUtil.notBlank(psnBaseinfo.getPsnIdetType())) { dao.updatePsnIdetType(psnBaseinfo.getPsnIdetType(), psnBaseinfo.getPsnNo()); } psnBaseinfo.setIdetinfo(idetInfos); if (new Integer(1).equals(qryPsnBsInfo.getNeedSaving())) { dao.updateZyActpatient(psnBaseinfo); int saved = dao.selectSiZyInfoCount(qryPsnBsInfo.getPatNo(), qryPsnBsInfo.getTimes(), qryPsnBsInfo.getLedgerSn()); if (saved == 0) { dao.insertSiZyInfoPsnNo(psnBaseinfo); } else { dao.updateSiZyInfoPsnNo(psnBaseinfo); } log.info("患者基本信息已更新:{}", psnBaseinfo); output.put("times", qryPsnBsInfo.getTimes()); } List list = new ArrayList<>(); JSONArray insuinfo = output.getJSONArray("insuinfo"); for (int i = 0; i < insuinfo.size(); i++) { JSONObject item = insuinfo.getJSONObject(i); InsuInfo info = JSONObject.parseObject(item.toJSONString(), InsuInfo.class); Insutype insutype = Insutype.get(info.getInsutype()); if (null != insutype) { info.setInsutypeName(insutype.getName()); } PsnType psnType = PsnType.get(info.getPsnType()); if (null != psnType) { info.setPsnTypeName(psnType.getName()); } if (null != info.getPsnInsuStas()) { if (info.getPsnInsuStas().equals(YesOrNo.YES.getCodeStr())) { info.setPsnInsuStasName("正常参保"); } else { info.setPsnInsuStasName("暂停参保"); } } if (null != info.getCvlservFlag()) { if (info.getCvlservFlag().equals(YesOrNo.YES.getCodeStr())) { info.setCvlservFlagName("是"); } else { info.setCvlservFlagName("否"); } } info.setInsuplcAdmdvsName(redis.getRegionName(info.getInsuplcAdmdvs())); list.add(info); } psnBaseinfo.setInsuinfo(list); return ResultVoUtil.success(psnBaseinfo); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> obtainMedicalInstitutionInfo(String type, String fuzzyName) { JSONObject input = exec.makeTradeHeader(SiFunction.OBTAIN_MEDICAL_INSTITUTION_INFO); JSONObject medinsinfo = new JSONObject(); medinsinfo.put("fixmedins_type", type); medinsinfo.put("fixmedins_name", fuzzyName); input.getJSONObject("input").put("medinsinfo", medinsinfo); JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_MEDICAL_INSTITUTION_INFO); log.info("【操作员:{}】,获取定点医药机构信息:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONArray output = result.getJSONObject(OUTPUT).getJSONArray("medinsinfo"); List list = new ArrayList<>(); for (int i = 0; i < output.size(); i++) { JSONObject item = output.getJSONObject(i); MedInsInfo info = JSONObject.parseObject(item.toJSONString(), MedInsInfo.class); info.setFixmedinsAdmdvs(info.getFixmedinsCode().substring(1, 7)); info.setFixmedinsAdmdvsName(dao.selectRegionName(info.getFixmedinsAdmdvs())); FixmedinsType fixmedinsType = FixmedinsType.get(info.getFixmedinsType()); if (null != fixmedinsType) { info.setFixmedinsTypeName(fixmedinsType.getName()); } HospLv hospLv = HospLv.get(info.getHospLv()); if (null != hospLv) { info.setHospLvName(hospLv.getName()); } list.add(info); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryVisitInfo(BscQryPrm q) { PureCodeName codeName = dao.selectPsnNoByPatNoAndMedType(q.getPatNo(), q.getMedType()); if (null == codeName) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有找到患者该医疗类别的我院就诊记录。"); } q.setPsnNo(codeName.getName()); JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_VISIT_INFO, codeName.getCode()); String ref = JSONObject.toJSONStringWithDateFormat(q, "yyyy-MM-dd HH:mm:ss"); input.getJSONObject("input").put("data", JSONObject.parseObject(ref)); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_VISIT_INFO); log.info("【操作员:{}】,查询就诊信息:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray mdts = output.getJSONArray("mdtrtinfo"); List list = new ArrayList<>(); for (int i = 0; i < mdts.size(); i++) { JSONObject item = mdts.getJSONObject(i); MdtrtInfo mdtrtInfo = JSONObject.parseObject(item.toJSONString(), MdtrtInfo.class); if (null != mdtrtInfo.getInsuOptins()) { mdtrtInfo.setInsuOptinsName(dao.selectRegionName(mdtrtInfo.getInsuOptins())); } SiEnumReflectUtil.mdtrtInfoReflect(mdtrtInfo); list.add(mdtrtInfo); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryDiagnosisInfo(BscQryPrm q) { String admdvs = dao.selectAdmdvsByPsnNo(q.getPsnNo()); JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_DIAGNOSIS_INFO, admdvs); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("mdtrt_id", q.getMdtrtId()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_DIAGNOSIS_INFO); log.info("【操作员:{}】,查询诊断信息:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); List list = new ArrayList<>(); JSONArray diseInfos = output.getJSONArray("diseinfo"); for (int i = 0; i < diseInfos.size(); i++) { JSONObject item = diseInfos.getJSONObject(i); DiseInfo diseInfo = JSONObject.parseObject(item.toJSONString(), DiseInfo.class); SiEnumReflectUtil.diseInfoReflect(diseInfo); list.add(diseInfo); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo querySettlementInfo(BscQryPrm q) { SiPatInfo siPatInfo; if (null == q.getMdtrtId()) { if (null == q.getLedgerSn()) { q.setLedgerSn(0); } siPatInfo = dao.selectSiPatInfoForZy(q.getPatNo(), q.getTimes(), q.getLedgerSn()); } else { siPatInfo = dao.selectSiPatInfoByMdtrtId(q.getMdtrtId()); } if (null == siPatInfo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该次就诊尚未结算,无法查询结算信息。"); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SETTLEMENT_INFO, siPatInfo.getInsuplcAdmdvs()); JSONObject data = new JSONObject(); data.put("psn_no", siPatInfo.getPsnNo()); data.put("setl_id", siPatInfo.getSetlId()); data.put("mdtrt_id", siPatInfo.getMdtrtId()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_SETTLEMENT_INFO); log.info("【操作员:{}】,查询结算信息:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONObject obj = output.getJSONObject("setlinfo"); if (null == obj) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到该次就诊的结算明细。"); } SetlInfo setlInfo = JSONObject.parseObject(obj.toJSONString(), SetlInfo.class); ClrType clrType = ClrType.get(setlInfo.getClrType()); if (null != clrType) { setlInfo.setClrTypeName(clrType.getName()); } MedType medType = MedType.get(setlInfo.getMedType()); if (null != medType) { setlInfo.setMedTypeName(medType.getName()); } Insutype insutype = Insutype.get(setlInfo.getInsutype()); if (null != insutype) { setlInfo.setInsutypeName(insutype.getName()); } PsnType psnType = PsnType.get(setlInfo.getPsnType()); if (null != psnType) { setlInfo.setPsnTypeName(psnType.getName()); } JSONArray setldetail = output.getJSONArray("setldetail"); if (null != setldetail && setldetail.size() > 0) { List list = new ArrayList<>(); for (int i = 0; i < setldetail.size(); i++) { SiSetldetail setldtel = JSONObject.parseObject(setldetail.getJSONObject(i).toJSONString(), SiSetldetail.class); FundPayType fundPayType = FundPayType.get(setldtel.getFundPayType()); if (null != fundPayType) { setldtel.setFundPayTypeName(fundPayType.getName()); } list.add(setldtel); } setlInfo.setSetldetail(list); } return ResultVoUtil.success(setlInfo); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryFeeDetails(QryFeeDetl q) { SiPatInfo psninfo = dao.selectSiPatInfoByMdtrtId(q.getMdtrtId()); if (null == psninfo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的医保登记信息。"); } Map map = new HashMap<>(); map.put("psninfo", psninfo); if (!q.getType().equals("settled")) { List list = dao.selectTempCharge(psninfo.getPatNo(), psninfo.getTimes(), psninfo.getLedgerSn()); if (null == list || list.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有已经上传的医保费用。"); } map.put("feedtle", list); map.put("analyse", analyseFeedtle(list)); return ResultVoUtil.success(map); } List list = dao.selectFeeDetlList(psninfo.getMdtrtId(), psninfo.getPatNo(), psninfo.getTimes(), psninfo.getLedgerSn()); if (list.size() > 0) { map.put("feedtle", list); map.put("analyse", analyseFeedtle(list)); return ResultVoUtil.success(map); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_FEE_DETAILS, psninfo.getInsuplcAdmdvs()); JSONObject data = new JSONObject(); data.put("psn_no", psninfo.getPsnNo()); data.put("setl_id", psninfo.getSetlId()); data.put("mdtrt_id", psninfo.getMdtrtId()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_FEE_DETAILS); log.info("【操作员:{}】,【就诊信息查询】查询费用明细:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONArray output = result.getJSONArray(OUTPUT); if (null == output || output.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到费用明细。"); } for (int i = 0; i < output.size(); i++) { list.add(JSONObject.parseObject(output.getJSONObject(i).toJSONString(), SiSetlFeeDetl.class)); if (list.size() == 30) { dao.insertSetlFeeDetlBatch(list); list.clear(); } } if (list.size() > 0) { dao.insertSetlFeeDetlBatch(list); } list = dao.selectFeeDetlList(psninfo.getMdtrtId(), psninfo.getPatNo(), psninfo.getTimes(), psninfo.getLedgerSn()); map.put("feedtle", list); map.put("analyse", analyseFeedtle(list)); return ResultVoUtil.success(map); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } private Map analyseFeedtle(List fees) { Map map = new HashMap<>(); map.put("zhj", new String[]{"合计", "0.00", "0.00", "0.00"}); fees.forEach(itm -> { if (StringUtil.isBlank(itm.getChrgitmLvName())) { ChrgitmLv chrgitmLv = ChrgitmLv.get(itm.getChrgitmLv()); if (null == chrgitmLv) { chrgitmLv = ChrgitmLv.SELF_PAY; } itm.setChrgitmLvName(chrgitmLv.getName()); } String[] all = map.get("zhj"); all[1] = DecimalUtil.add(all[1], itm.getDetItemFeeSumamt()); all[2] = DecimalUtil.add(all[2], itm.getInscpScpAmt()); all[3] = DecimalUtil.add(all[3], DecimalUtil.minus(itm.getDetItemFeeSumamt(), itm.getInscpScpAmt())); if (map.containsKey(itm.getMedChrgitmType())) { String[] dtle = map.get(itm.getMedChrgitmType()); dtle[1] = DecimalUtil.add(dtle[1], itm.getDetItemFeeSumamt()); dtle[2] = DecimalUtil.add(dtle[2], itm.getInscpScpAmt()); dtle[3] = DecimalUtil.add(dtle[3], DecimalUtil.minus(itm.getDetItemFeeSumamt(), itm.getInscpScpAmt())); } else { String[] dtle = new String[4]; MedChrgitmType type = MedChrgitmType.get(itm.getMedChrgitmType()); if (type == null) { type = MedChrgitmType.OTH; itm.setMedChrgitmType(type.getCode()); } dtle[0] = type.getName(); dtle[1] = itm.getDetItemFeeSumamt(); dtle[2] = itm.getInscpScpAmt(); dtle[3] = DecimalUtil.minus(itm.getDetItemFeeSumamt(), itm.getInscpScpAmt()); map.put(type.getCode(), dtle); } }); String total = map.get("zhj")[1]; for (Map.Entry entry : map.entrySet()) { if (!entry.getKey().equals("zhj")) { String percentage = DecimalUtil.percentage(entry.getValue()[1], total); entry.getValue()[0] = entry.getValue()[0] + "(" + percentage + ")"; } } return map; } public ResultVo> checkPersonTreatment(BscQryPrm q) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.CHECK_PERSON_TREATMENT, dao.selectAdmdvs(q.getPatNo(), q.getTimes())); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("insutype", q.getInsutype()); data.put("fixmedins_code", SiUtil.INSTITUTION_ID); data.put("med_type", q.getMedType()); data.put("begntime", DateUtil.formatDatetime(q.getBegntime())); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.CHECK_PERSON_TREATMENT); log.info("【操作员:{}】,人员待遇享受检查:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { List list = new ArrayList<>(); JSONObject output = result.getJSONObject(OUTPUT); JSONArray trtinfo = output.getJSONArray("trtinfo"); for (int i = 0; i < trtinfo.size(); i++) { JSONObject obj = trtinfo.getJSONObject(i); TrtInfo item = JSONObject.parseObject(obj.toJSONString(), TrtInfo.class); TrtChkType trtChkType = TrtChkType.get(item.getTrtChkType()); if (null != trtChkType) { item.setTrtChkTypeName(trtChkType.getName()); } FundPayType fundPayType = FundPayType.get(item.getFundPayType()); if (null != fundPayType) { item.setFundPayTypeName(fundPayType.getName()); } if (null != item.getTrtEnjymntFlag()) { if (item.getTrtEnjymntFlag().equals(YesOrNo.YES.getCodeStr())) { item.setTrtEnjymntFlagName("是"); } else { item.setTrtEnjymntFlagName("否"); } } list.add(item); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryInHospitalPatientsInfo(BscQryPrm q) { if (StringUtil.notBlank(q.getPatNo())) { String psnNo = dao.selectPsnNo(q.getPatNo()); if (null == psnNo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【住院号/门诊号:" + q.getPatNo() + "】没有找到此患者在我院的医保在院信息,请核实。"); } q.setPsnNo(psnNo); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_IN_HOSPITAL_PATIENTS_INFO, dao.selectAdmdvsByPatNoAndPsnNo(q.getPatNo(), q.getPsnNo())); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("begntime", DateUtil.formatDatetime(q.getBegntime())); data.put("endtime", null == q.getEndtime() ? DateUtil.now() : DateUtil.formatDatetime(q.getEndtime())); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_IN_HOSPITAL_PATIENTS_INFO); log.info("【操作员:{}】,在院信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray pts = output.getJSONArray("data"); if (pts.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到医保在院的患者信息。"); } List list = new ArrayList<>(); for (int i = 0; i < pts.size(); i++) { JSONObject item = pts.getJSONObject(i); InHspPsnInfo inHspPsnInfo = JSONObject.parseObject(item.toJSONString(), InHspPsnInfo.class); SiEnumReflectUtil.inHspPsnInfoReflect(inHspPsnInfo); list.add(inHspPsnInfo); } if (list.size() == 1 && null != q.getTimes()) { InHspPsnInfo info = list.get(0); dao.updateInhospInfo(q.getPatNo(), q.getTimes(), q.getLedgerSn(), info.getMdtrtId(), info.getInsutype()); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryPersonnelTransferHospitalInfo(BscQryPrm q) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_TRANSFER_HOSPITAL_INFO, dao.selectAdmdvsByPatNoAndPsnNo(q.getPatNo(), q.getPsnNo())); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("begntime", DateUtil.formatDatetime(q.getBegntime())); data.put("endtime", DateUtil.formatDatetime(q.getEndtime())); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_TRANSFER_HOSPITAL_INFO); log.info("【操作员:{}】,转院信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray array = output.getJSONArray("refmedin"); if (null == array || array.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到符合条件的转院信息。"); } List list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject obj = array.getJSONObject(i); RefMedin item = JSONObject.parseObject(obj.toJSONString(), RefMedin.class); Insutype insutype = Insutype.get(item.getInsutype()); if (null != insutype) { item.setInsutypeName(insutype.getName()); } DclaSouc dclaSouc = DclaSouc.get(item.getDclaSouc()); if (null != dclaSouc) { item.setDclaSoucName(dclaSouc.getName()); } PsnCertType psnCertType = PsnCertType.get(item.getPsnCertType()); if (null != psnCertType) { item.setPsnCertTypeName(psnCertType.getName()); } item.setGendName(Gend.get(item.getGend()).getName()); if (null != item.getInsuOptins()) { item.setInsuOptinsName(dao.selectRegionName(item.getInsuOptins())); } if (null != item.getOutFlag()) { if (item.getOutFlag().equals(YesOrNo.YES.getCodeStr())) { item.setOutFlagName("是"); } else { item.setOutFlagName("否"); } } if (null != item.getHospAgreReflFlag()) { if (item.getHospAgreReflFlag().equals(YesOrNo.YES.getCodeStr())) { item.setHospAgreReflFlagName("是"); } else { item.setHospAgreReflFlagName("否"); } } list.add(item); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> querySpecialChronicDiseasesMedicalRecord(BscQryPrm q) { if (null == q.getPsnNo()) { String psnNo = dao.selectPsnNo(q.getPatNo()); if (null == psnNo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【住院号/门诊号:" + q.getPatNo() + "】未找到此患者的医保参保信息,请核实。"); } q.setPsnNo(psnNo); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_MEDICAL_RECORD, dao.selectAdmdvsByPsnNo(q.getPsnNo())); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("begntime", DateUtil.formatDatetime(q.getBegntime())); data.put("endtime", DateUtil.formatDatetime(q.getEndtime())); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_MEDICAL_RECORD); log.info("【操作员:{}】,人员慢特病用药记录查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray array = output.getJSONArray("feedetail"); if (null == array || array.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到此人的慢特病用药记录。"); } List list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject obj = array.getJSONObject(i); MedUseRcd item = JSONObject.parseObject(obj.toJSONString(), MedUseRcd.class); list.add(item); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryPersonnelCumulativeInfo(BscQryPrm q) { String admdvs = q.getAdmdvs(); if (StringUtil.isBlank(admdvs)) { admdvs = dao.selectAdmdvsByPsnNo(q.getPsnNo()); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO, admdvs); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("cum_ym", q.getCumYm()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO); log.info("【操作员:{}】,人员累计信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray array = output.getJSONArray("cuminfo"); List list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject obj = array.getJSONObject(i); CumInfo item = JSONObject.parseObject(obj.toJSONString(), CumInfo.class); Insutype insutype = Insutype.get(item.getInsutype()); if (null != insutype) { item.setInsutypeName(insutype.getName()); } list.add(item); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> querySpecialChronicDiseasesAccreditation(BscQryPrm q) { if (null == q.getPsnNo()) { String psnNo = dao.selectPsnNo(q.getPatNo()); if (null == psnNo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【住院号/门诊号:" + q.getPatNo() + "】未找到此患者的医保参保信息,请核实。"); } q.setPsnNo(psnNo); } if (StringUtil.isBlank(q.getAdmdvs())) { String admdvs = StringUtil.isBlank(q.getPatNo()) ? dao.selectAdmdvsByPsnNo(q.getPsnNo()) : dao.selectAdmdvsByPatNo(q.getPatNo()); q.setAdmdvs(admdvs); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_ACCREDITATION, q.getAdmdvs()); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_ACCREDITATION); log.info("【操作员:{}】,人员慢特病备案查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray details = output.getJSONArray("feedetail"); if (null == details || details.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到此患者的慢特病备案信息。"); } List list = new ArrayList<>(); Date now = new Date(); for (int i = 0; i < details.size(); i++) { JSONObject detail = details.getJSONObject(i); SpcChrDiseAcct spcChrDiseAcct = JSONObject.parseObject(detail.toJSONString(), SpcChrDiseAcct.class); if (null != q.getNeedAllRcd() && 1 == q.getNeedAllRcd()) { list.add(spcChrDiseAcct); } else { if (now.before(spcChrDiseAcct.getEnddate())) { spcChrDiseAcct.setPatNo(q.getPatNo()); spcChrDiseAcct.setTimes(q.getTimes()); list.add(spcChrDiseAcct); } } } if (list.size() > 0) { return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的慢特病备案,或慢特病备案已过期!"); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryPersonnelAssignmentInfo(BscQryPrm q) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_ASSIGNMENT_INFO, q.getAdmdvs()); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("biz_appy_type", q.getBizAppyType()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_ASSIGNMENT_INFO); log.info("【操作员:{}】,人员定点信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray array = output.getJSONArray("psnfixmedin"); if (null == array || array.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到对应的点定信息。"); } List list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject obj = array.getJSONObject(i); PsnFixMedin item = JSONObject.parseObject(obj.toJSONString(), PsnFixMedin.class); Insutype insutype = Insutype.get(item.getInsutype()); if (null != insutype) { item.setInsutypeName(insutype.getName()); } list.add(item); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> fetchSiTimesList(String patNo, Integer type) { List list = dao.fetchSiTimesList(patNo, type); if (null == list || list.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "此患者没有有效的结算信息。"); } return ResultVoUtil.success(list); } public ResultVo queryInsuplcAdmdvsByMdtrtId(String mdtrtId) { return ResultVoUtil.success(dao.selectInsuplcAdmdvsByMdtrtId(mdtrtId)); } public ResultVo querySiSetlList(SetlIndex index) { if (null == index.getTimes() && StringUtil.isBlank(index.getLabel())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算条目不能为空!"); } if (StringUtil.notBlank(index.getLabel())) { String[] arr = index.getLabel().split("_"); index.setSetlId(arr[0]); index.setTimes(Integer.parseInt(arr[1])); if (index.getType() == SetlType.INPATIENT.getCode()) { index.setLedgerSn(Integer.parseInt(arr[2])); } else { index.setLedgerSn(0); } } else { index.setLedgerSn(0); index.setSetlId(dao.selectSetlId(index.getPatNo(), index.getTimes(), index.getLedgerSn())); } SiPatInfo siPatInfo = dao.selectSiPatInfo(index.getPatNo(), index.getTimes(), index.getLedgerSn()); if (null == siPatInfo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!"); } CuminfoInYear cuminfo = getYearCuminfo(siPatInfo.getPsnNo(), siPatInfo.getInsuplcAdmdvs()); if (cuminfo.getCode() != ExceptionEnum.SUCCESS.getCode()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, cuminfo.getMessage()); } if (index.getType() == SetlType.INPATIENT.getCode()) { InptntSetlmtLst lst = dao.selectZySetlinfo(index.getSetlId(), "zy_inactpatient"); if (null == lst) { lst = dao.selectZySetlinfo(index.getSetlId(), "zy_actpatient"); if (null == lst) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!"); } } lst.setInHospdays(DateUtil.daysBetween(lst.getBegntime(), lst.getEndtime()) + 1); PsnIdetType psnIdetType = PsnIdetType.get(lst.getPsnIdetType()); if (null != psnIdetType) { lst.setPsnIdetTypeName(psnIdetType.getName()); } Admdvs admdvs = Admdvs.get(lst.getInsuplcAdmdvs()); if (null == admdvs) { lst.setInsuplcAdmdvsName(dao.selectRegionName(lst.getInsuplcAdmdvs())); } else { lst.setInsuplcAdmdvsName(admdvs.getName()); } lst.setFixmedinsName(SiUtil.INSTITUTION_NAME); lst.setGendName(Gend.get(lst.getGend()).getName()); SiEnumReflectUtil.inptntSetlmtLstReflect(lst); ResultVo> chrgrsvo = getChrgitems(lst.getPsnNo(), lst.getSetlId(), lst.getMdtrtId(), lst.getInsuplcAdmdvs()); if (!chrgrsvo.getCode().equals(ExceptionEnum.SUCCESS.getCode())) { return chrgrsvo; } analyzeZyChrgitm(lst, chrgrsvo.getData()); lst.setYrAdmtimes(cuminfo.getYearAdmtimesZy()); lst.setYrAcmltvExpsClted(cuminfo.getYearPeriodfeeSumamtZy()); lst.setYrMedfeeSumamt(cuminfo.getYearMedfeesumZy()); lst.setYrPayedBegnLine(cuminfo.getYearPayedBegnlineZy()); lst.setYrFundPaySumamt(cuminfo.getYearBaseFundPayAmtZy()); lst.setYrBigAmtFundPay(cuminfo.getYearBigAmtpaysZy()); lst.setYrBigDssInsPay(cuminfo.getYearBigdssFundPayAmtZy()); lst.setYrMafPay(cuminfo.getYearMafPayAmtZy()); lst.setYrPolicySelfPay(cuminfo.getYearPolicySelfPayZy()); lst.setYrPreSelfPay(cuminfo.getYearPreSelfPayZy()); lst.setYrBigDssFee(cuminfo.getYearBigDssLegalFee()); return listPolItemCodePayInfo(lst); } else { index.setLedgerSn(0); OtptntSetlmtLst lst = dao.selectMzSetlifo(index.getPatNo(), index.getTimes()); if (null == lst) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!"); } Admdvs admdvs = Admdvs.get(lst.getInsuplcAdmdvs()); if (null == admdvs) { lst.setInsuplcAdmdvsName(dao.selectRegionName(lst.getInsuplcAdmdvs())); } else { lst.setInsuplcAdmdvsName(admdvs.getName()); } SiEnumReflectUtil.outptntSetlmtLstReflect(lst); List chrgitms = dao.selectMzBrfChrgitms(index.getPatNo(), index.getTimes()); analyzeMzChrgitm(lst, chrgitms); lst.setYrAdmtimes(cuminfo.getYearAdmtimesMz()); lst.setYrMedfeeSumamt(cuminfo.getYearMedfeesumMz()); lst.setYrFundPaySumamt(cuminfo.getYearBaseFundPayAmtMz()); lst.setYrBigAmtFundPay(cuminfo.getYearBigAmtpaysMz()); lst.setYrBigDssFundPay(cuminfo.getYearBigdssFundPayAmtMz()); lst.setYrAcctPay(cuminfo.getYearAcctPayMz()); lst.setYrMafPay(cuminfo.getYearMafPayAmtMz()); lst.setFixmedinsName(SiUtil.INSTITUTION_NAME); return ResultVoUtil.success(lst); } } private ResultVo listPolItemCodePayInfo(InptntSetlmtLst lst) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.LIST_POL_ITEM_CODE_PAY_INFO, lst.getInsuplcAdmdvs()); JSONObject data = new JSONObject(); data.put("psn_no", lst.getPsnNo()); data.put("mdtrt_id", lst.getMdtrtId()); data.put("setl_id", lst.getSetlId()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.LIST_POL_ITEM_CODE_PAY_INFO); log.info("【操作员:{}】,政策信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger("code")) { String message = result.getString("message"); if (null == message) { message = result.getString(ERROR_MESSAGE); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + message); } if (result.getIntValue("code") != 0) { String message = result.getString("message"); if (null == message) { message = result.getString(ERROR_MESSAGE); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心出错:" + message); } JSONArray array = result.getJSONArray("data"); BigDecimal selfPaySum = new BigDecimal(0); BigDecimal fundPaySum = new BigDecimal(0); for (int i = 0; i < array.size(); i++) { JSONObject itm = array.getJSONObject(i); BigDecimal selfPayAmt = BigDecimal.valueOf(itm.getDouble("selfPayAmt")); String selfPayProp = itm.getString("selfPayProp"); BigDecimal fundPayAmt = BigDecimal.valueOf(itm.getDouble("fundPayAmt")); String fundPayProp = itm.getString("fundPayProp"); BigDecimal polItemPaySum = BigDecimal.valueOf(itm.getDouble("polItemPaySum")); selfPaySum = selfPaySum.add(selfPayAmt); fundPaySum = fundPaySum.add(fundPayAmt); PolItemCode polItemCode = PolItemCode.get(itm.getString("polItemCode")); if (null == polItemCode) { String message = String.format("找到了字典缺失的政策项:%s", itm); log.info(message); wxsrvc.sendCorpWxMsg("2801", message); continue; } switch (polItemCode) { case QZF: lst.setSelfPayPsnAmt(selfPayAmt); lst.setSelfPayPsnProp(selfPayProp); lst.setSelfPayFundAmt(fundPayAmt); lst.setSelfPayFundProp(fundPayProp); lst.setSelfPaySum(polItemPaySum); break; case YLXZF: lst.setScndPrePayPsnAmt(selfPayAmt); lst.setScndPrePayPsnProp(selfPayProp); lst.setScndPrePayFundAmt(fundPayAmt); lst.setScndPrePayFundProp(fundPayProp); lst.setScndPrePaySum(polItemPaySum); break; case CXEZF: lst.setOvrlmtSelfPayPsnAmt(selfPayAmt); lst.setOvrlmtSelfPayPsnProp(selfPayProp); lst.setOvrlmtSelfPayFundAmt(fundPayAmt); lst.setOvrlmtSelfPayFundProp(fundPayProp); lst.setOvrlmtSelfPaySum(polItemPaySum); break; case BCYFQFBZ: lst.setBegnlinePsnAmt(selfPayAmt); lst.setBegnlinePsnProp(selfPayProp); lst.setBegnlineFundAmt(fundPayAmt); lst.setBegnlineFundProp(fundPayProp); lst.setBegnlineSum(polItemPaySum); break; case TCYD: lst.setFundFrstLvPsnAmt(selfPayAmt); lst.setFundFrstLvPsnProp(selfPayProp); lst.setFundFrstLvFundAmt(fundPayAmt); lst.setFundFrstLvFundProp(fundPayProp); lst.setFundFrstLvSum(polItemPaySum); break; case TCED: lst.setFundScndLvPsnAmt(selfPayAmt); lst.setFundScndLvPsnProp(selfPayProp); lst.setFundScndLvFundAmt(fundPayAmt); lst.setFundScndLvFundProp(fundPayProp); lst.setFundScndLvSum(polItemPaySum); break; case DEYD: lst.setBigAmtFrstLvPsnAmt(selfPayAmt); lst.setBigAmtFrstLvPsnProp(selfPayProp); lst.setBigAmtFrstLvFundAmt(fundPayAmt); lst.setBigAmtFrstLvFundProp(fundPayProp); lst.setBigAmtFrstLvSum(polItemPaySum); break; } } lst.setAllPsnAmt(selfPaySum); lst.setAllFundAmt(fundPaySum); lst.setAllSum(fundPaySum.add(selfPaySum)); return ResultVoUtil.success(lst); } private CuminfoInYear getYearCuminfo(String psnNo, String admdvs) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO, admdvs); JSONObject data = new JSONObject(); data.put("psn_no", psnNo); data.put("cum_ym", ""); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO); CuminfoInYear cuminfo = new CuminfoInYear(); if (null == result) { cuminfo.setCode(ExceptionEnum.NETWORK_ERROR.getCode()); cuminfo.setMessage(ExceptionEnum.NETWORK_ERROR.getMessage()); return cuminfo; } if (null == result.getInteger(RESULT_CODE)) { cuminfo.setCode(ExceptionEnum.LOGICAL_ERROR.getCode()); cuminfo.setMessage("医保中心报错:" + result.getString("message")); return cuminfo; } if (result.getIntValue(RESULT_CODE) != 0) { cuminfo.setCode(ExceptionEnum.NETWORK_ERROR.getCode()); cuminfo.setMessage("医保中心出错:" + result.getString("message")); return cuminfo; } cuminfo.setCode(ExceptionEnum.SUCCESS.getCode()); String year = String.valueOf(LocalDate.now().getYear()); JSONArray cuminfos = result.getJSONObject(OUTPUT).getJSONArray("cuminfo"); log.info("累计信息:{}", cuminfos); for (int i = 0; i < cuminfos.size(); i++) { JSONObject itm = cuminfos.getJSONObject(i); if (itm.getString("year").equals(year)) { switch (itm.getString("cum_type_code")) { // 本年住院次数 case "C0000_BIZ2101": case "C0000_BIZ2102": case "C0000_BIZ2106": case "C0000_BIZ2107": case "C0000_BIZ22": case "C0000_BIZ52": cuminfo.addYearAdmtimesZy(itm.getDoubleValue("cum")); break; // 本年门诊次数 case "C0000_BIZ11": case "C0000_BIZ13": case "C0000_BIZ14": case "C0000_BIZ51": case "C0000_BIZ9901": case "C0000_BIZ9903": case "C0000_BIZ9904": cuminfo.addYearAdmtimesMz(itm.getDoubleValue("cum")); break; // 本年度住院分段计算费用累计 case "S0000_BIZ2101": case "S0000_BIZ2102": case "S0000_BIZ2106": case "S0000_BIZ2107": case "S0000_BIZ22": case "S0000_BIZ52": cuminfo.addYearPeriodFeeSumZy(itm.getDoubleValue("cum")); break; // 住院医疗费合计 case "F0000_BIZ2101": case "F0000_BIZ2102": case "F0000_BIZ2106": case "F0000_BIZ2107": case "F0000_BIZ22": case "F0000_BIZ52": cuminfo.addYearFeesumZy(itm.getDoubleValue("cum")); break; // 门诊医疗费合计 case "F0000_BIZ11": case "F0000_BIZ13": case "F0000_BIZ14": case "F0000_BIZ51": case "F0000_BIZ9901": case "F0000_BIZ9903": case "F0000_BIZ9904": cuminfo.addYearFeesumMz(itm.getDoubleValue("cum")); break; // 住院已付起付线 case "Q0000_BIZ2101": case "Q0000_BIZ2102": case "Q0000_BIZ2106": case "Q0000_BIZ2107": case "Q0000_BIZ22": case "Q0000_BIZ52": cuminfo.addYearPayedbegnlineZy(itm.getDoubleValue("cum")); break; // 住院统筹支付 case "D310101_BIZ2101": case "D310101_BIZ2102": case "D310101_BIZ2106": case "D310101_BIZ2107": case "D310101_BIZ22": case "D310101_BIZ52": case "D390101_BIZ2101": case "D390101_BIZ2102": case "D390101_BIZ2106": case "D390101_BIZ2107": case "D390101_BIZ22": case "D390101_BIZ52": cuminfo.addYearFundpaysZy(itm.getDoubleValue("cum")); break; // 门诊统筹支付 case "D310101_BIZ11": case "D310101_BIZ13": case "D310101_BIZ14": case "D310101_BIZ51": case "D310101_BIZ9901": case "D310101_BIZ9903": case "D310101_BIZ9904": case "D390101_BIZ11": case "D390101_BIZ13": case "D390101_BIZ14": case "D390101_BIZ51": case "D390101_BIZ9901": case "D390101_BIZ9903": case "D390101_BIZ9904": cuminfo.addYearFundpaysMz(itm.getDoubleValue("cum")); break; // 政策自费 case "Z0000_BIZ2101_LAB101": case "Z0000_BIZ2102_LAB101": case "Z0000_BIZ22_LAB101": case "Z0000_BIZ2106_LAB101": case "Z0000_BIZ2107_LAB101": case "Z0000_BIZ52_LAB101": case "Z0000_BIZ2101_LAB103": case "Z0000_BIZ2102_LAB103": case "Z0000_BIZ22_LAB103": case "Z0000_BIZ2106_LAB103": case "Z0000_BIZ2107_LAB103": case "Z0000_BIZ52_LAB103": cuminfo.addYearPolicySelfpayZy(itm.getDoubleValue("cum")); break; // 政策自付 case "Z0000_BIZ2101_LAB102": case "Z0000_BIZ2102_LAB102": case "Z0000_BIZ22_LAB102": case "Z0000_BIZ2106_LAB102": case "Z0000_BIZ2107_LAB102": case "Z0000_BIZ52_LAB102": cuminfo.addYearPreSelfpayZy(itm.getDoubleValue("cum")); break; // 住院大额基金支付 case "D330101_BIZ2101": case "D330101_BIZ2102": case "D330101_BIZ2106": case "D330101_BIZ2107": case "D330101_BIZ22": case "D330101_BIZ52": cuminfo.addYearBigAmtpaysZy(itm.getDoubleValue("cum")); break; // 门诊大额基金支付 case "D330101_BIZ11": case "D330101_BIZ13": case "D330101_BIZ14": case "D330101_BIZ51": case "D330101_BIZ9901": case "D330101_BIZ9903": case "D330101_BIZ9904": cuminfo.addYearBigAmtpaysMz(itm.getDoubleValue("cum")); break; // 住院大病保险支付 case "D390201_BIZ2101": case "D390201_BIZ2102": case "D390201_BIZ2106": case "D390201_BIZ2107": case "D390201_BIZ22": case "D390201_BIZ52": cuminfo.addYearBigdssInspaysZy(itm.getDoubleValue("cum")); break; // 门诊大病保险支付 case "D390201_BIZ11": case "D390201_BIZ13": case "D390201_BIZ14": case "D390201_BIZ51": case "D390201_BIZ9901": case "D390201_BIZ9903": case "D390201_BIZ9904": cuminfo.addYearBigdssInspaysMz(itm.getDoubleValue("cum")); break; // 住院医疗救助支付 case "D610101_BIZ2101": case "D610101_BIZ2102": case "D610101_BIZ2106": case "D610101_BIZ2107": case "D610101_BIZ22": case "D610101_BIZ52": cuminfo.addYearMafpaysZy(itm.getDoubleValue("cum")); break; // 门诊医疗救助支付 case "D610101_BIZ11": case "D610101_BIZ13": case "D610101_BIZ14": case "D610101_BIZ51": case "D610101_BIZ9901": case "D610101_BIZ9903": case "D610101_BIZ9904": cuminfo.addYearMafpaysMz(itm.getDoubleValue("cum")); break; // 门诊个人账户支付 case "D310201_BIZ11": case "D310201_BIZ13": case "D310201_BIZ14": case "D310201_BIZ51": case "D310201_BIZ9901": case "D310201_BIZ9903": case "D310201_BIZ9904": cuminfo.addYearAcctPayMz(itm.getDoubleValue("cum")); break; // 大病保险合规费用 case "TS390201": cuminfo.addYearBigdssLegalFee(itm.getDoubleValue("cum")); break; } } } return cuminfo; } private ResultVo> getChrgitems(String psnNo, String setlId, String mdtrtId, String admdvs) { List list = dao.selectAllSetlFeeDtle(mdtrtId); if (list.size() > 0) { return ResultVoUtil.success(list); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_FEE_DETAILS, admdvs); JSONObject data = new JSONObject(); data.put("psn_no", psnNo); data.put("setl_id", setlId); data.put("mdtrt_id", mdtrtId); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_FEE_DETAILS); log.info("【操作员:{}】,【结算单查询】查询费用明细:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger(RESULT_CODE)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message")); } if (0 == result.getInteger(RESULT_CODE)) { JSONArray output = result.getJSONArray(OUTPUT); if (null == output || output.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到费用明细。"); } for (int i = 0; i < output.size(); i++) { SiSetlFeeDetl fee = JSONObject.parseObject(output.getJSONObject(i).toJSONString(), SiSetlFeeDetl.class); if (StringUtil.isBlank(fee.getSetlId())) { fee.setSetlId(setlId); } list.add(fee); if (list.size() == 30) { dao.insertSetlFeeDetlBatch(list); list.clear(); } } if (list.size() > 0) { dao.insertSetlFeeDetlBatch(list); } return ResultVoUtil.success(dao.selectAllSetlFeeDtle(mdtrtId)); } return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, result.getString(ERROR_MESSAGE)); } private void analyzeZyChrgitm(InptntSetlmtLst lst, List chrgitms) { Map map = new HashMap<>(); map.put("allfeeSum", new BigDecimal(0)); map.put("totalFrst", new BigDecimal(0)); map.put("totalScnd", new BigDecimal(0)); chrgitms.forEach(itm -> { BigDecimal itmfeeSum = new BigDecimal(itm.getDetItemFeeSumamt()); map.replace("allfeeSum", map.get("allfeeSum").add(itmfeeSum)); if (itm.getChrgitmLv().equals(ChrgitmLv.FIRST_CLASS.getCode())) { map.replace("totalFrst", map.get("totalFrst").add(itmfeeSum)); } else if (itm.getChrgitmLv().equals(ChrgitmLv.SECOND_CLASS.getCode())) { map.replace("totalScnd", map.get("totalScnd").add(itmfeeSum)); } String typeKey = itm.getMedChrgitmType(); String lvKey = typeKey + "-" + itm.getChrgitmLv(); if (map.containsKey(typeKey)) { map.replace(typeKey, map.get(typeKey).add(itmfeeSum)); } else { map.put(typeKey, itmfeeSum); } if (map.containsKey(lvKey)) { map.replace(lvKey, map.get(lvKey).add(itmfeeSum)); } else { map.put(lvKey, itmfeeSum); } }); lst.setAllfeeSum(map.get("allfeeSum")); lst.setAllfeeFrst(map.get("totalFrst")); lst.setAllfeeScnd(map.get("totalScnd")); lst.setWestMedFeeSum(map.get("09")); lst.setWestMedFeeFrst(map.get("09-01")); lst.setWestMedFeeScnd(map.get("09-02")); lst.setHerbalSum(map.get("10")); lst.setHerbalFrst(map.get("10-01")); lst.setHerbalScnd(map.get("10-02")); lst.setChnsPtntSum(map.get("11")); lst.setChnsPtntFrst(map.get("11-01")); lst.setChnsPtntScnd(map.get("11-02")); lst.setClinicSum(map.get("02")); lst.setClinicFrst(map.get("02-01")); lst.setClinicScnd(map.get("02-02")); lst.setTreatSum(map.get("05")); lst.setTreatFrst(map.get("05-01")); lst.setTreatScnd(map.get("05-02")); lst.setSurgerySum(map.get("06")); lst.setSurgeryFrst(map.get("06-01")); lst.setSurgeryScnd(map.get("06-02")); lst.setNursingSum(map.get("07")); lst.setNursingFrst(map.get("07-01")); lst.setNursingScnd(map.get("07-02")); lst.setSntryMtrlsSum(map.get("08")); lst.setSntryMtrlsFrst(map.get("08-01")); lst.setSntryMtrlsScnd(map.get("08-02")); lst.setExamSum(map.get("04")); lst.setExamFrst(map.get("04-01")); lst.setExamScnd(map.get("04-02")); lst.setNrmlTrtmtSum(map.get("12")); lst.setNrmlTrtmtFrst(map.get("12-01")); lst.setNrmlTrtmtScnd(map.get("12-02")); lst.setInspectSum(map.get("03")); lst.setInspectFrst(map.get("03-01")); lst.setInspectScnd(map.get("03-02")); lst.setRegisterSum(map.get("13")); lst.setRegisterFrst(map.get("13-01")); lst.setRegisterScnd(map.get("13-02")); lst.setBedfeeSum(map.get("01")); lst.setBedfeeFrst(map.get("01-01")); lst.setBedfeeScnd(map.get("01-02")); lst.setOthfeeSum(map.get("14")); lst.setOthfeeFrst(map.get("14-01")); lst.setOthfeeScnd(map.get("14-02")); } private void analyzeMzChrgitm(OtptntSetlmtLst lst, List chrgitms) { Map map = new HashMap<>(); map.put("allfeeSum", BigDecimal.valueOf(0)); map.put("totalThrd", BigDecimal.valueOf(0)); map.put("totalScnd", BigDecimal.valueOf(0)); map.put("othSum", BigDecimal.valueOf(0)); map.put("othThrd", BigDecimal.valueOf(0)); map.put("othScnd", BigDecimal.valueOf(0)); chrgitms.forEach(itm -> { map.replace("allfeeSum", map.get("allfeeSum").add(BigDecimal.valueOf(itm.getChargeFee()))); if (itm.getChrgitmLv().equals(ChrgitmLv.SELF_PAY.getCode())) { map.replace("totalThrd", map.get("totalThrd").add(BigDecimal.valueOf(itm.getChargeFee()))); } else if (itm.getChrgitmLv().equals(ChrgitmLv.SECOND_CLASS.getCode())) { map.replace("totalScnd", map.get("totalScnd").add(BigDecimal.valueOf(itm.getChargeFee()))); } String typeKey = itm.getMedChrgitmType(); if (!typeKey.equals("09") && !typeKey.equals("11")) { map.replace("othSum", map.get("othSum").add(BigDecimal.valueOf(itm.getChargeFee()))); if (itm.getChrgitmLv().equals(ChrgitmLv.SELF_PAY.getCode())) { map.replace("othThrd", map.get("othThrd").add(BigDecimal.valueOf(itm.getChargeFee()))); } else if (itm.getChrgitmLv().equals(ChrgitmLv.SECOND_CLASS.getCode())) { map.replace("othScnd", map.get("othScnd").add(BigDecimal.valueOf(itm.getChargeFee()))); } } else { String lvKey = typeKey + "-" + itm.getChrgitmLv(); if (map.containsKey(typeKey)) { map.replace(typeKey, map.get(typeKey).add(BigDecimal.valueOf(itm.getChargeFee()))); } else { map.put(typeKey, BigDecimal.valueOf(itm.getChargeFee())); } if (map.containsKey(lvKey)) { map.replace(lvKey, map.get(lvKey).add(BigDecimal.valueOf(itm.getChargeFee()))); } else { map.put(lvKey, BigDecimal.valueOf(itm.getChargeFee())); } } }); lst.setAllfeeSum(map.get("allfeeSum")); lst.setAllfeeThrd(map.get("totalThrd")); lst.setAllfeeScnd(map.get("totalScnd")); lst.setWestMedFeeSum(map.get("09")); lst.setWestMedFeeThrd(map.get("09-03")); lst.setWestMedFeeScnd(map.get("09-02")); lst.setChnsPtntSum(map.get("11")); lst.setChnsPtntThrd(map.get("11-03")); lst.setChnsPtntScnd(map.get("11-02")); lst.setMedsrvcSum(map.get("othSum")); lst.setMedsrvcThrd(map.get("othThrd")); lst.setMedsrvcScnd(map.get("othScnd")); } public ResultVo> queryMzMatnDises() { return ResultVoUtil.success(dao.selectAllMzMatnDises()); } public ResultVo> selectSetlinfoStatistics(SetlCondition condition) { String begntime = condition.getMonth() + "-01 00:00:00.000"; String endtime = DateUtil.getMonthEndtime(condition.getMonth()); String insutype = condition.getInsutype(); if (StringUtil.isBlank(insutype)) { insutype = "%%"; } List baseStatistics; switch (condition.getAdmdvsType()) { case 1: baseStatistics = dao.selectBaseSetlStatisticsInProvinceLevel(begntime, endtime, insutype, condition.getSetlType()); break; case 2: baseStatistics = dao.selectBaseSetlStatisticsInChangshaCity(begntime, endtime, insutype, condition.getSetlType()); break; case 3: baseStatistics = dao.selectBaseSetlStatisticsInProvinceOtherCities(begntime, endtime, insutype, condition.getSetlType()); break; case 4: baseStatistics = dao.selectBaseSetlStatisticsOutProvince(begntime, endtime, insutype, condition.getSetlType()); break; case 5: baseStatistics = dao.selectBaseSetlStatisticsInChangshaCounty(begntime, endtime, insutype, condition.getSetlType()); break; case 6: baseStatistics = dao.selectBaseSetlStatisticsInLiuYangCity(begntime, endtime, insutype, condition.getSetlType()); break; default: baseStatistics = dao.selectBaseSetlStatisticsInAllPlaces(begntime, endtime, insutype, condition.getSetlType()); break; } if (null == baseStatistics || baseStatistics.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST); } Map regionMap = new HashMap<>(); Map> admdvsSetldataMap = new HashMap<>(); List shangChuanJieSuanDan = new ArrayList<>(); baseStatistics.forEach(itm -> { itm.setInsutypeName(Insutype.getName(itm.getInsutype())); if (null != itm.getHospPay()) { itm.setFundPaySumamt(DecimalUtil.minus(itm.getFundPaySumamt(), itm.getHospPay())); } String key; if (condition.getAdmdvsType() == 5 || condition.getAdmdvsType() == 6) { key = itm.getInsuplcAdmdvs(); } else { key = itm.getInsuplcAdmdvs().substring(0, 4) + "00"; } String admdvsName = regionMap.get(key); if (null == admdvsName) { PureCodeName region = dao.selectAdmdvsNameAndParentName(key); if (null == region) { region = dao.selectAdmdvsName(key); } admdvsName = region.getCode() + region.getName(); regionMap.put(key, admdvsName); } if (admdvsSetldataMap.containsKey(admdvsName)) { admdvsSetldataMap.get(admdvsName).add(itm); } else { List tempList = new ArrayList<>(); tempList.add(itm); admdvsSetldataMap.put(admdvsName, tempList); } shangChuanJieSuanDan.add(itm); }); List resultList = new ArrayList<>(); for (Map.Entry> entry : admdvsSetldataMap.entrySet()) { List admdvsSetldataList = entry.getValue(); SetlStatisticResult resultItem = new SetlStatisticResult(); resultItem.setAdmdvsName(entry.getKey()); resultItem.setInsuplcAdmdvs(entry.getValue().get(0).getInsuplcAdmdvs().substring(0, 4) + "00"); resultItem.setPsnSumamt(admdvsSetldataList.size()); if (StringUtil.notBlank(condition.getInsutype())) { resultItem.setInsutype(condition.getInsutype()); resultItem.setInsutypeName(Insutype.getName(condition.getInsutype())); resultItem.setChildKey(entry.getKey() + "-" + resultItem.getInsutypeName()); } else { resultItem.setInsutypeName("-"); resultItem.setChildKey(entry.getKey()); } fillSetlStatisticResult(resultList, admdvsSetldataList, resultItem); } if (StringUtil.isBlank(condition.getInsutype())) { for (SetlStatisticResult resultItem : resultList) { Map> insutypeSetldataMap = new HashMap<>(); String admdvsName = resultItem.getAdmdvsName(); List admdvsSetldataList = admdvsSetldataMap.get(admdvsName); for (BaseSetlStatistics baseSetlStatistics : admdvsSetldataList) { if (insutypeSetldataMap.containsKey(baseSetlStatistics.getInsutypeName())) { insutypeSetldataMap.get(baseSetlStatistics.getInsutypeName()).add(baseSetlStatistics); } else { List tmpList = new ArrayList<>(); tmpList.add(baseSetlStatistics); insutypeSetldataMap.put(baseSetlStatistics.getInsutypeName(), tmpList); } } if (insutypeSetldataMap.size() == 1) { resultItem.setInsutype(admdvsSetldataList.get(0).getInsutype()); resultItem.setInsutypeName(admdvsSetldataList.get(0).getInsutypeName()); continue; } List children = new ArrayList<>(); for (Map.Entry> entry : insutypeSetldataMap.entrySet()) { List insutypeSetldataList = entry.getValue(); SetlStatisticResult result = new SetlStatisticResult(); result.setAdmdvsName(resultItem.getAdmdvsName()); result.setInsuplcAdmdvs(resultItem.getInsuplcAdmdvs()); result.setPsnSumamt(insutypeSetldataList.size()); result.setInsutype(entry.getValue().get(0).getInsutype()); result.setInsutypeName(entry.getValue().get(0).getInsutypeName()); result.setChildKey(resultItem.getAdmdvsName() + "-" + result.getInsutypeName()); result.setIsChildren(true); fillSetlStatisticResult(children, insutypeSetldataList, result); } resultItem.setChildren(children); } } resultList.get(0).setShangChuanJieSuanDan(shangChuanJieSuanDan); return ResultVoUtil.success(resultList); } private void fillSetlStatisticResult(List resultList, List admdvsSetldataList, SetlStatisticResult resultItem) { String medfeeSumamt = "0"; String baseMedFundpaySumamt = "0"; String bigDssFundpaySumamt = "0"; String clvFundpaySumamt = "0"; String othFundpaySumamt = "0"; String fundpaySumamt = "0"; for (BaseSetlStatistics itm : admdvsSetldataList) { medfeeSumamt = DecimalUtil.add(medfeeSumamt, itm.getMedfeeSumamt()); baseMedFundpaySumamt = DecimalUtil.add(baseMedFundpaySumamt, itm.getHifpPay()); bigDssFundpaySumamt = DecimalUtil.add(bigDssFundpaySumamt, itm.getHifmiPay()); clvFundpaySumamt = DecimalUtil.add(clvFundpaySumamt, itm.getCvlservPay()); fundpaySumamt = DecimalUtil.add(fundpaySumamt, itm.getFundPaySumamt()); String othpay = DecimalUtil.minusLink(itm.getFundPaySumamt(), itm.getHifpPay(), itm.getHifmiPay(), itm.getCvlservPay()); othFundpaySumamt = DecimalUtil.add(othFundpaySumamt, othpay); } resultItem.setMedfeeSumamt(medfeeSumamt); resultItem.setBaseMedFundpaySumamt(baseMedFundpaySumamt); resultItem.setBigDssFundpaySumamt(bigDssFundpaySumamt); resultItem.setClvFundpaySumamt(clvFundpaySumamt); resultItem.setOthFundpaySumamt(othFundpaySumamt); resultItem.setFundpaySumamt(fundpaySumamt); resultList.add(resultItem); } public ResultVo> selectSetldetailStatistics(SetlCondition condition) { String begntime = condition.getMonth() + "-01 00:00:00.000"; String endtime = DateUtil.getMonthEndtime(condition.getMonth()); String insuplcAdmdvs; if (condition.getAdmdvsType() == 5) { insuplcAdmdvs = "430121"; } else if (condition.getAdmdvsType() == 6) { insuplcAdmdvs = "430181"; } else { insuplcAdmdvs = condition.getInsuplcAdmdvs().substring(0, 4) + "%"; } String insutype = condition.getInsutype(); if (StringUtil.isBlank(insutype)) { insutype = "%%"; } QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("setl_type", condition.getSetlType()); wrapper.eq("revoked", YesOrNo.NO.getCode()); wrapper.like("insutype", insutype); wrapper.like("insuplc_admdvs", insuplcAdmdvs); wrapper.apply("setl_time>='" + begntime + "'"); wrapper.apply("setl_time<='" + endtime + "'"); List list = setlinfoDao.selectList(wrapper); list.forEach(item -> { item.setInsuplcAdmdvsName(redis.getRegionName(item.getInsuplcAdmdvs())); FilterUtil.filterCodeToName(item); }); return ResultVoUtil.success(list); } public ResultVo> weiJieSuanZaiYuanHuanZhe(String patNo, String startTime, String endTime, String name, String certno) { List actpatients = dao.zaiYuanHuanZheXinXi(patNo, startTime, endTime, StringUtil.isContainChinese(name), certno); Map insuplcAdmdvs = new HashMap<>(); for (ZyActpatient actpatient : actpatients) { if (StringUtil.isBlank(actpatient.getInsuplcAdmdvsName())) { String key = actpatient.getInsuplcAdmdvs().substring(0, 4) + "00"; if (insuplcAdmdvs.containsKey(key)) { actpatient.setInsuplcAdmdvsName(insuplcAdmdvs.get(key)); } else { String insuplcAdmdvsName = dao.selectRegionName(key); insuplcAdmdvs.put(key, insuplcAdmdvsName); actpatient.setInsuplcAdmdvsName(insuplcAdmdvsName); } } } return ResultVoUtil.success(actpatients); } public ResultVo checkRegisterDate(String patNo, Integer times) { Date ledgerAccountDate = dao.selectMaxLedgerAccountDate(patNo, times); if (null == ledgerAccountDate) { return ResultVoUtil.success(); } Date registerDate = dao.selectRegisterDate(patNo); if (null == registerDate) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保登记日期不能为空。"); } Calendar ledgerCalendar = Calendar.getInstance(); ledgerCalendar.setTime(ledgerAccountDate); Calendar registerCalendar = Calendar.getInstance(); registerCalendar.setTime(registerDate); if (registerCalendar.after(ledgerCalendar)) { return ResultVoUtil.success(); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("医保登记日期【%s】不能小于断账日期【%s】,请修改。", DateUtil.formatDatetime(registerDate), DateUtil.formatDatetime(ledgerAccountDate))); } }