|  | @@ -172,179 +172,6 @@ public class XiangMuLuRuService {
 | 
	
		
			
				|  |  |          return ResultVoUtil.success(dao.getChargeCode(StringUtil.isContainChinese(pyCode)));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * @param param 需要生成退费 的数据
 | 
	
		
			
				|  |  | -     * @return 返回
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public ResultVo<String> xiangMuTuiFei(ZyDetailCharge param) {
 | 
	
		
			
				|  |  | -        UserInfo userInfo = redisLikeService.getUserInfoByToken();
 | 
	
		
			
				|  |  | -        List<Integer> yongHuJueSe = userInfo.getRoles();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        // 判断是否为婴儿
 | 
	
		
			
				|  |  | -        int infantFlag = PublicServer.getInfantFlag(param.getInpatientNo());
 | 
	
		
			
				|  |  | -        if (infantFlag == 1) {
 | 
	
		
			
				|  |  | -            param.setInpatientNo(param.getInpatientNo().split("\\$")[0]);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        if (!yongHuJueSe.contains(36) && !yongHuJueSe.contains(1)) {
 | 
	
		
			
				|  |  | -            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限退费。");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (param.getList() == null || param.getList().isEmpty()) {
 | 
	
		
			
				|  |  | -            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请先选择需要退费的数据,一次性退费不得超过100条");
 | 
	
		
			
				|  |  | -        } else if (param.getList().size() > 100) {
 | 
	
		
			
				|  |  | -            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "项目退费一次性大于100条数据");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (StringUtil.isBlank(param.getInpatientNo()) || param.getAdmissTimes() == null || param.getList().size() == 0) {
 | 
	
		
			
				|  |  | -            return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "患者信息不全");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (dao.getHuanZheSFZaiYuan(param.getInpatientNo(), param.getAdmissTimes()) == 0) {
 | 
	
		
			
				|  |  | -            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者已出院");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        Integer settlementFlag = dao.getHuanZheSFJieSuan(param.getInpatientNo(), param.getAdmissTimes());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        if (settlementFlag == null || settlementFlag != 0) {
 | 
	
		
			
				|  |  | -            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者已经结算了");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        // 获取 患者的账页号
 | 
	
		
			
				|  |  | -        Integer ledgerSn = publicServer.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes());
 | 
	
		
			
				|  |  | -        // 获取原来的数据
 | 
	
		
			
				|  |  | -        List<ZyDetailCharge> yuanTuiFeiList = dao.huoQuJuTiFeiYong(param.getInpatientNo(), param.getAdmissTimes(), ledgerSn, param.getList());
 | 
	
		
			
				|  |  | -        // 获取患者自己的科室和下面的子科室
 | 
	
		
			
				|  |  | -        Set<String> deptList;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        UserInfo us = redisLikeService.getUserInfoByToken();
 | 
	
		
			
				|  |  | -        if (us.getDeptCode().startsWith("8")) {
 | 
	
		
			
				|  |  | -            deptList = dao.chaXunZhiZXinKeShi(param.getDeptCode());
 | 
	
		
			
				|  |  | -            deptList.add(userInfo.getDeptCode());
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            deptList = publicServer.getChildDeptByUserCode();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        List<ZyDetailCharge> project = new ArrayList<>();
 | 
	
		
			
				|  |  | -        List<ZyDetailCharge> drug = new ArrayList<>();
 | 
	
		
			
				|  |  | -        List<ZyDetailCharge> tuiFeiList = new ArrayList<>();
 | 
	
		
			
				|  |  | -        List<ZyDetailCharge> medicalTechnologyDrugReturnForm = new ArrayList<>();
 | 
	
		
			
				|  |  | -        // 保存被退费的流水号,把这些流水号修改为 -1 代表已经退费了
 | 
	
		
			
				|  |  | -        List<Integer> updateRefundFlag = new ArrayList<>();
 | 
	
		
			
				|  |  | -        // 把 药品 改成 -1 代表已经退了 -2 代表申请 -3 代表拒绝
 | 
	
		
			
				|  |  | -        List<Integer> updateDrugLabel = new ArrayList<>();
 | 
	
		
			
				|  |  | -        // 患者最大的 detail_sn
 | 
	
		
			
				|  |  | -        int maxDetailSn = publicServer.getMaxDetailSn(param.getInpatientNo(), param.getAdmissTimes());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        for (ZyDetailCharge item : yuanTuiFeiList) {
 | 
	
		
			
				|  |  | -            // -3 退药申请,拒绝退药申请是可以重新申请的
 | 
	
		
			
				|  |  | -            if (item.getOriDetailSn() != null && item.getOriDetailSn().equals(-3)) {
 | 
	
		
			
				|  |  | -                item.setOriDetailSn(null);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if (item.getOriDetailSn() != null && item.getOriDetailSn().equals(-2)) {
 | 
	
		
			
				|  |  | -                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,该药品在申请退药。", item.getDetailSn()));
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if (item.getOriDetailSn() != null) {
 | 
	
		
			
				|  |  | -                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,该数据为退费数据。", item.getDetailSn()));
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if (BigUtils.bigXiaoYu(item.getChargeFee(), 0) || BigUtils.bigXiaoYu(item.getChargeAmount(), 0)) {
 | 
	
		
			
				|  |  | -                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,该数据为负数。", item.getDetailSn()));
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if (StringUtil.isBlank(item.getExecDept())) {
 | 
	
		
			
				|  |  | -                item.setExecDept(userInfo.getDeptCode());
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if (!yongHuJueSe.contains(1)) {
 | 
	
		
			
				|  |  | -                if ("00".equals(item.getSerial()) && !deptList.contains(item.getExecUnit())) {
 | 
	
		
			
				|  |  | -                    return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,请对应的执行科室进行退费。", item.getDetailSn()));
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if ("BILL02".equals(item.getChargeCode())) {
 | 
	
		
			
				|  |  | -                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,中药无法退费。", item.getDetailSn()));
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            item.setNewOrderNo(item.getOrderNo());
 | 
	
		
			
				|  |  | -            // 00 是项目
 | 
	
		
			
				|  |  | -            if ("00".equals(item.getSerial())) {
 | 
	
		
			
				|  |  | -                maxDetailSn = setRefund(project, tuiFeiList, updateRefundFlag, maxDetailSn, item);
 | 
	
		
			
				|  |  | -            } else {
 | 
	
		
			
				|  |  | -                if ("3".equals(item.getOrderNo().stripTrailingZeros().toPlainString())) {
 | 
	
		
			
				|  |  | -                    if (!deptList.contains(item.getExecUnit())) {
 | 
	
		
			
				|  |  | -                        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,此药品为医技科室录入,请对应的医技科室退费。", item.getDetailSn()));
 | 
	
		
			
				|  |  | -                    } else {
 | 
	
		
			
				|  |  | -                        maxDetailSn = setRefund(project, tuiFeiList, updateRefundFlag, maxDetailSn, item);
 | 
	
		
			
				|  |  | -                        medicalTechnologyDrugReturnForm.add(item);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                } else {
 | 
	
		
			
				|  |  | -                    // 仅退费不退药品
 | 
	
		
			
				|  |  | -                    if ("refundOnly".equals(param.getRefundFlag())) {
 | 
	
		
			
				|  |  | -                        maxDetailSn = setRefund(project, tuiFeiList, updateRefundFlag, maxDetailSn, item);
 | 
	
		
			
				|  |  | -                    } else {
 | 
	
		
			
				|  |  | -                        // 数量设置为负数
 | 
	
		
			
				|  |  | -                        item.setChargeAmount(item.getChargeAmount().negate());
 | 
	
		
			
				|  |  | -                        drug.add(item);
 | 
	
		
			
				|  |  | -                        updateDrugLabel.add(item.getDetailSn());
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        // 护士退药单
 | 
	
		
			
				|  |  | -        if (ListUtil.notBlank(drug)) {
 | 
	
		
			
				|  |  | -            for (ZyDetailCharge item : drug) {
 | 
	
		
			
				|  |  | -                ZyDetailCharge a = dao.selectDrugClassByOrderNo(item.getOrderNo());
 | 
	
		
			
				|  |  | -                if ("refundOnly".equals(param.getRefundFlag())) {
 | 
	
		
			
				|  |  | -                    if (dao.getDrugKing(item.getChargeCodeMx(), item.getSerial()) > 0) {
 | 
	
		
			
				|  |  | -                        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,药品无法退费,毒麻药药品无法仅退费不退药品,编码为:【%s】。", item.getDetailSn(), item.getChargeCodeMx()));
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                if (a == null) {
 | 
	
		
			
				|  |  | -                    return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,药品无法退费,原因没有查询到原药品对应的医嘱,编码为:【%s】。", item.getDetailSn(), item.getChargeCodeMx()));
 | 
	
		
			
				|  |  | -                } else {
 | 
	
		
			
				|  |  | -                    // 口服药无法退费 包装规格是 09,盒,15,瓶 的可以退费
 | 
	
		
			
				|  |  | -                    if ("1".equals(a.getClassCode())) {
 | 
	
		
			
				|  |  | -                        if (!(a.getMiniUnit().equals("09") || a.getMiniUnit().equals("15"))) {
 | 
	
		
			
				|  |  | -                            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,药品无法退费,原因原医嘱的给药方式为口服药,口服无法退费。", item.getDetailSn()));
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    if ("d".equals(a.getDrugClass())) {
 | 
	
		
			
				|  |  | -                        a.setDrugClass("j");
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    // 医嘱表中会有 z 所以把所有 z 的换成 j
 | 
	
		
			
				|  |  | -                    item.setDrugClass("z".equals(a.getDrugClass()) ? "j" : a.getDrugClass());
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            ZyActpatient patientInfo = publicServer.huoQuHuanZheXinXi(param.getInpatientNo());
 | 
	
		
			
				|  |  | -            // 退药明细
 | 
	
		
			
				|  |  | -            dao.detailsOfDrugReturnForm(drug, patientInfo.getInpatientNo(), patientInfo.getAdmissTimes(),
 | 
	
		
			
				|  |  | -                    patientInfo.getName(), patientInfo.getBedNo(), userInfo.getDeptCode(), infantFlag,
 | 
	
		
			
				|  |  | -                    param.getGroupNo(), TokenUtil.getTokenUserId(), -1, ledgerSn);
 | 
	
		
			
				|  |  | -            // 药品的退药 标准 为 -2 申请退药
 | 
	
		
			
				|  |  | -            ListUtil.partitionAndFunc(updateRefundFlag, 20, item -> {
 | 
	
		
			
				|  |  | -                dao.genXinZhenShuTuiFeiLiuShui(
 | 
	
		
			
				|  |  | -                        param.getInpatientNo(),
 | 
	
		
			
				|  |  | -                        param.getAdmissTimes(),
 | 
	
		
			
				|  |  | -                        ledgerSn,
 | 
	
		
			
				|  |  | -                        item,
 | 
	
		
			
				|  |  | -                        -2);
 | 
	
		
			
				|  |  | -            });
 | 
	
		
			
				|  |  | -            log.info("项目录入==》药品退费,操作人:{},数据:{}", TokenUtil.getTokenUserId(), JSON.toJSONStringWithDateFormat(drug, DateUtil.DEFAULT_PATTERN));
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        // 医技科室药品单
 | 
	
		
			
				|  |  | -        if (ListUtil.notBlank(medicalTechnologyDrugReturnForm)) {
 | 
	
		
			
				|  |  | -            dao.shenQingYaoPing(param, medicalTechnologyDrugReturnForm, infantFlag, ledgerSn, TokenUtil.getTokenUserId());
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        // 项目退费
 | 
	
		
			
				|  |  | -        if (ListUtil.notBlank(project)) {
 | 
	
		
			
				|  |  | -            ListUtil.partitionAndFunc(project, 2, dao::xiangMuTuiFei);
 | 
	
		
			
				|  |  | -            ListUtil.partitionAndFunc(updateRefundFlag, 20, item -> {
 | 
	
		
			
				|  |  | -                dao.genXinZhenShuTuiFeiLiuShui(
 | 
	
		
			
				|  |  | -                        param.getInpatientNo(),
 | 
	
		
			
				|  |  | -                        param.getAdmissTimes(),
 | 
	
		
			
				|  |  | -                        ledgerSn,
 | 
	
		
			
				|  |  | -                        item,
 | 
	
		
			
				|  |  | -                        -1);
 | 
	
		
			
				|  |  | -            });
 | 
	
		
			
				|  |  | -            log.info("项目录入==》项目退费,操作人:{},数据:{}", TokenUtil.getTokenUserId(), JSON.toJSONStringWithDateFormat(project, DateUtil.DEFAULT_PATTERN));
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "退费成功。");
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 退费
 |