Sfoglia il codice sorgente

优化 医嘱退费匹配

xiaochan 4 anni fa
parent
commit
4290f9d7f3

+ 1 - 1
src/main/java/thyyxxk/webserver/dao/his/yibao/XiangMuLuRuDao.java

@@ -607,7 +607,7 @@ public interface XiangMuLuRuDao {
      */
     @Select("select charge_date,charge_fee,charge_amount,charge_code_mx,detail_sn,ori_detail_sn,ABS(order_no) order_no " +
             "from zy_detail_charge where  inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and  LEN(order_no)  > 2  and " +
-            "ori_detail_sn is null and charge_amount ${ZF} 0 and charge_fee ${ZF} 0")
+            "ori_detail_sn is null and charge_amount ${ZF} 0 and charge_fee ${ZF} 0 and ledger_sn > 0")
     List<ZyDetailCharge> getYiZhuFeiYong(@Param("inpatientNo") String inpatientNo,
                                          @Param("admissTimes") Integer admissTimes,
                                          @Param("ZF") String ZF);

+ 18 - 13
src/main/java/thyyxxk/webserver/service/yibao/XiangMuLuRuService.java

@@ -239,25 +239,26 @@ public class XiangMuLuRuService {
         List<ZyDetailCharge> getYiZhuFeiYongZhenShu = dao.getYiZhuFeiYong(inpatientNo, admissTimes, ">");
         // 获取负的费用
         List<ZyDetailCharge> getYiZhuFeiYongFuShu = dao.getYiZhuFeiYong(inpatientNo, admissTimes, "<");
-        // 需要匹配的一些流水
+        // 需要匹配的一些流水数据
         List<ZyDetailCharge> piPei = new ArrayList<>();
+
+        // 保存正数的 map 用来匹配
+        Map<String, ZyDetailCharge> zhenShuMap = new HashMap<>();
+        for (ZyDetailCharge zhenShu : getYiZhuFeiYongZhenShu) {
+            String key = zhenShu.getOrderNo() + DateUtil.formatDatetime(zhenShu.getChargeDate()) + zhenShu.getChargeCodeMx() + zhenShu.getChargeAmount();
+            zhenShuMap.put(key, zhenShu);
+        }
+        // 用负数拼接的 key 去查找
         for (ZyDetailCharge fuShu : getYiZhuFeiYongFuShu) {
-            for (ZyDetailCharge zhenShu : getYiZhuFeiYongZhenShu) {
-                // 判断退费的数据匹配一条正数 通过医嘱号,收费日期,项目编码,数量
-                if (fuShu.getOrderNo().equals(zhenShu.getOrderNo())
-                        && DateUtil.formatDatetime(fuShu.getChargeDate()).equals(DateUtil.formatDatetime(zhenShu.getChargeDate()))
-                        && fuShu.getChargeCodeMx().equals(zhenShu.getChargeCodeMx())
-                        && fuShu.getChargeAmount().negate().equals(zhenShu.getChargeAmount())) {
-                    // 把匹配到的 流水号 添加进来
-                    fuShu.setOriDetailSn(zhenShu.getDetailSn());
-                    // 在保存到list中
-                    piPei.add(fuShu);
-                }
+            String key = fuShu.getOrderNo() + DateUtil.formatDatetime(fuShu.getChargeDate()) + fuShu.getChargeCodeMx() + fuShu.getChargeAmount().negate();
+            if (zhenShuMap.containsKey(key)) {
+                fuShu.setOriDetailSn(zhenShuMap.get(key).getDetailSn());
+                piPei.add(fuShu);
             }
         }
+        // 开始匹配
         if (piPei.size() > 0) {
             // 100 条的更新
-            log.info("医嘱退费匹配 ==》 操作人:{} :住院号:{},住院次数:{}", TokenUtil.getTokenUserId(), inpatientNo, admissTimes);
             List<ZyDetailCharge> fenDuanPiPei = new ArrayList<>();
             for (ZyDetailCharge zyDetailCharge : piPei) {
                 fenDuanPiPei.add(zyDetailCharge);
@@ -266,6 +267,10 @@ public class XiangMuLuRuService {
                     fenDuanPiPei.clear();
                 }
             }
+            if (fenDuanPiPei.size() > 0) {
+                dao.yiZhuTuiFeiPiPei(inpatientNo, admissTimes, fenDuanPiPei);
+            }
+            log.info("医嘱退费匹配 ==》 操作人:{} :住院号:{},住院次数:{}", TokenUtil.getTokenUserId(), inpatientNo, admissTimes);
             return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, String.format("医嘱退费匹配成功共匹配%d条", piPei.size()));
         } else {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者没有可以匹配的医嘱退费");