|
@@ -1,7 +1,6 @@
|
|
|
package thyyxxk.webserver.service.yibao;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.ListUtils;
|
|
@@ -58,6 +57,9 @@ public class XiangMuLuRuService {
|
|
|
if (StringUtil.isBlank(param.getInpatientNo()) || param.getAdmissTimes() == null) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "住院号或住院次数为空 <br/>๑乛◡乛๑");
|
|
|
}
|
|
|
+ if (dao.chaKanHuanZheSFZaiYuan(param.getInpatientNo()) == 0) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者已出院");
|
|
|
+ }
|
|
|
log.info("查询患者费用==》住院号{},住院次数:{},项目名称:{},费用类型:{},科室:{},当前页:{},页大小:{}", param.getInpatientNo(), param.getAdmissTimes(),
|
|
|
param.getChargeCode(), param.getOrderNo(), param.getDept(), param.getCurrentPage(), param.getPageSize());
|
|
|
int infantFlag = 0;
|
|
@@ -66,6 +68,7 @@ public class XiangMuLuRuService {
|
|
|
param.setInpatientNo(param.getInpatientNo().split("\\$")[0]);
|
|
|
infantFlag = 1;
|
|
|
}
|
|
|
+
|
|
|
Page<ZyDetailCharge> page = new Page<>(param.getCurrentPage(), param.getPageSize(), false);
|
|
|
if (param.getFeiYongLeiXingCode() == 0) {
|
|
|
page.setTotal(dao.huanZheFeiYongCount(param.getInpatientNo(), param.getAdmissTimes(), param.getChargeCode(), infantFlag,
|
|
@@ -124,7 +127,10 @@ public class XiangMuLuRuService {
|
|
|
if (StringUtil.isBlank(param.getInpatientNo()) || param.getAdmissTimes() == null || param.getList().size() == 0) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "患者信息不全");
|
|
|
}
|
|
|
- // 判断数据是否为 退费数据
|
|
|
+ if (dao.chaKanHuanZheSFZaiYuan(param.getInpatientNo()) == 0) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者已出院");
|
|
|
+ }
|
|
|
+ // 判断数据是否为 退费数据
|
|
|
List<ZyDetailCharge> chaKanSFtuiFei = dao.chaKanSFYiJingTuiFeiLe(param.getInpatientNo(), param.getAdmissTimes(), param.getList());
|
|
|
|
|
|
for (ZyDetailCharge charge : chaKanSFtuiFei) {
|
|
@@ -395,24 +401,38 @@ public class XiangMuLuRuService {
|
|
|
List<ZyDetailCharge> getYiZhuFeiYongZhenShu = dao.getYiZhuFeiYong(inpatientNo, admissTimes, ">", infantFlag);
|
|
|
// 获取负的医嘱费用
|
|
|
List<ZyDetailCharge> getYiZhuFeiYongFuShu = dao.getYiZhuFeiYong(inpatientNo, admissTimes, "<", infantFlag);
|
|
|
+ // 获取负数的退费数据 主要是用来判断 这一条正的是否退费了。
|
|
|
+ List<ZyDetailCharge> tuiFeiList = dao.tuiFeiList(inpatientNo, admissTimes, infantFlag);
|
|
|
+ if (!tuiFeiList.isEmpty()) {
|
|
|
+ Map<Integer, Integer> map = new HashMap<>();
|
|
|
+ for (ZyDetailCharge zyDetailCharge : tuiFeiList) {
|
|
|
+ map.put(zyDetailCharge.getOriDetailSn(), zyDetailCharge.getDetailSn());
|
|
|
+ }
|
|
|
+ getYiZhuFeiYongZhenShu.forEach(item -> {
|
|
|
+ if (map.containsKey(item.getDetailSn())) {
|
|
|
+ item.setTuiFeiFlag(1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
// 需要保存需要匹配的一些流水数据
|
|
|
List<ZyDetailCharge> piPei = new ArrayList<>();
|
|
|
-
|
|
|
+ // 此处是需要二次匹配的 list
|
|
|
List<ZyDetailCharge> erCiPiPei = new ArrayList<>();
|
|
|
// 用map 来保存正数的信息,但是有可能匹配的条件中map 的 key会一致 所以在这里使用 java8 的新特性 stream 流来进行分组 这样就不会因为key 一样导致数据被覆盖了
|
|
|
+ // 第一次 匹配 根据 医嘱号 收费时间 项目编码 数量 账页号
|
|
|
Map<String, List<ZyDetailCharge>> zhenShuMap = getYiZhuFeiYongZhenShu.stream().collect(
|
|
|
Collectors.groupingBy(item -> item.getOrderNo() + DateUtil.formatDatetime(item.getChargeDate()) + item.getChargeCodeMx() + item.getChargeAmount() + item.getLedgerSn())
|
|
|
);
|
|
|
-
|
|
|
// 用负数拼接的 key 去查找
|
|
|
for (ZyDetailCharge fuShu : getYiZhuFeiYongFuShu) {
|
|
|
String key = fuShu.getOrderNo() + DateUtil.formatDatetime(fuShu.getChargeDate()) + fuShu.getChargeCodeMx() + fuShu.getChargeAmount().negate() + fuShu.getLedgerSn();
|
|
|
if (zhenShuMap.containsKey(key)) {
|
|
|
for (ZyDetailCharge zyDetailCharge : zhenShuMap.get(key)) {
|
|
|
- if (zyDetailCharge.getTuiFeiFlag() == null) {
|
|
|
+ if (zyDetailCharge.getTuiFeiFlag() == null && zyDetailCharge.getOriDetailSn() == null) {
|
|
|
fuShu.setOriDetailSn(zyDetailCharge.getDetailSn());
|
|
|
- piPei.add(fuShu);
|
|
|
zyDetailCharge.setTuiFeiFlag(1);
|
|
|
+ piPei.add(fuShu);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -420,50 +440,10 @@ public class XiangMuLuRuService {
|
|
|
erCiPiPei.add(fuShu);
|
|
|
}
|
|
|
}
|
|
|
- if (piPei.size() > 0) {
|
|
|
- // 100 条的更新 ListUtils.partition 用来拆分 list size 是拆分的条数
|
|
|
- // 在这里更新 不然会导致下面重复匹配同一条
|
|
|
- List<List<ZyDetailCharge>> fenDuan = ListUtils.partition(piPei, 100);
|
|
|
- for (List<ZyDetailCharge> list : fenDuan) {
|
|
|
- dao.yiZhuTuiFeiPiPei(inpatientNo, admissTimes, list, infantFlag);
|
|
|
- }
|
|
|
- }
|
|
|
// 下面是二次匹配
|
|
|
if (erCiPiPei.size() > 0) {
|
|
|
- // 这里清空一次 再次二次匹配 不然会导致 重复匹配到同一条
|
|
|
- piPei.clear();
|
|
|
- List<String> chargeCodeMxList = new ArrayList<>();
|
|
|
- // 去掉重复的项目编码
|
|
|
- erCiPiPei.forEach(item -> {
|
|
|
- if (!chargeCodeMxList.contains(item.getChargeCodeMx())) {
|
|
|
- chargeCodeMxList.add(item.getChargeCodeMx());
|
|
|
- }
|
|
|
- });
|
|
|
- // 获取负数的退费数据 主要是用来判断 这一条正的是否退费了。
|
|
|
- List<ZyDetailCharge> tuiFeiList = dao.tuiFeiList(inpatientNo, admissTimes, infantFlag);
|
|
|
- // 在这里获取 正数
|
|
|
- QueryWrapper<ZyDetailCharge> qw = new QueryWrapper<>();
|
|
|
- qw.select("exec_unit,ledger_sn,charge_code_mx,detail_sn,charge_fee,charge_amount");
|
|
|
- qw.eq("inpatient_no", inpatientNo);
|
|
|
- qw.eq("admiss_times", admissTimes);
|
|
|
- qw.isNull("ori_detail_sn");
|
|
|
- qw.gt("charge_fee", 0);
|
|
|
- qw.gt("ledger_sn", 0);
|
|
|
- qw.in("charge_code_mx", chargeCodeMxList);
|
|
|
- qw.eq("infant_flag", infantFlag);
|
|
|
- List<ZyDetailCharge> zhengShuList = dao.selectList(qw);
|
|
|
- if (!tuiFeiList.isEmpty()) {
|
|
|
- Map<Integer, Integer> map = new HashMap<>();
|
|
|
- for (ZyDetailCharge zyDetailCharge : tuiFeiList) {
|
|
|
- map.put(zyDetailCharge.getOriDetailSn(), zyDetailCharge.getDetailSn());
|
|
|
- }
|
|
|
- zhengShuList.forEach(item -> {
|
|
|
- if (map.containsKey(item.getDetailSn())) {
|
|
|
- item.setTuiFeiFlag(1);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- Map<String, List<ZyDetailCharge>> erCiPiPeiZhenShu = zhengShuList.stream().collect(
|
|
|
+ // 二次匹配 条件为 执行科室 项目编码 数量 账页号
|
|
|
+ Map<String, List<ZyDetailCharge>> erCiPiPeiZhenShu = getYiZhuFeiYongZhenShu.stream().collect(
|
|
|
Collectors.groupingBy(item -> item.getExecUnit() + item.getChargeCodeMx() + item.getChargeAmount() + item.getLedgerSn())
|
|
|
);
|
|
|
// 开始二次匹配
|
|
@@ -471,7 +451,7 @@ public class XiangMuLuRuService {
|
|
|
String key = zyDetailCharge.getExecUnit() + zyDetailCharge.getChargeCodeMx() + zyDetailCharge.getChargeAmount().negate() + zyDetailCharge.getLedgerSn();
|
|
|
if (erCiPiPeiZhenShu.containsKey(key)) {
|
|
|
for (ZyDetailCharge detailCharge : erCiPiPeiZhenShu.get(key)) {
|
|
|
- if (detailCharge.getTuiFeiFlag() == null) {
|
|
|
+ if (detailCharge.getTuiFeiFlag() == null && detailCharge.getOriDetailSn() == null) {
|
|
|
zyDetailCharge.setOriDetailSn(detailCharge.getDetailSn());
|
|
|
piPei.add(zyDetailCharge);
|
|
|
detailCharge.setTuiFeiFlag(1);
|
|
@@ -489,7 +469,8 @@ public class XiangMuLuRuService {
|
|
|
dao.yiZhuTuiFeiPiPei(inpatientNo, admissTimes, list, infantFlag);
|
|
|
}
|
|
|
log.info("医嘱退费匹配 ==》 操作人:{},住院号:{},住院次数:{}", TokenUtil.getTokenUserId(), inpatientNo, admissTimes);
|
|
|
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "匹配成功");
|
|
|
+ return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION,
|
|
|
+ String.format("匹配成功共:{%d}条,匹配成功:{%s}条", getYiZhuFeiYongFuShu.size(), piPei.size()));
|
|
|
}
|
|
|
return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "该患者没有可以匹配的医嘱退费 |д・)っ");
|
|
|
}
|