Browse Source

违规退费可以重复匹配 流水了,只要不超过费用。

xiaochan 3 years ago
parent
commit
3e075d48cc

+ 21 - 0
src/main/java/thyyxxk/webserver/dao/his/PublicDao.java

@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
+import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
 import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.entity.yibao.ZyActpatient;
 
@@ -121,6 +122,26 @@ public interface PublicDao {
                                 @Param("admissTimes") Integer admissTimes,
                                 @Param("ledgerSn") Integer ledgerSn);
 
+    @Select("select inpatient_no,admiss_times,ledger_sn,detail_sn,charge_code_mx,sum(charge_fee) yi_tui_fei from (       " +
+            "    select inpatient_no,admiss_times,ledger_sn,detail_sn,charge_code_mx,charge_fee       " +
+            "    from zy_detail_charge where   " +
+            "            inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn =  #{ledgerSn}   " +
+            "     and trans_flag_yb <> 2 and order_no <> 6 and   " +
+            "        detail_sn in(select ori_detail_sn from zy_detail_charge where  inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn =  #{ledgerSn}   " +
+            "     and charge_fee <0 and ori_detail_sn is not null)       " +
+            "    union all       " +
+            "    select inpatient_no,admiss_times,ledger_sn,ori_detail_sn,charge_code_mx,charge_fee       " +
+            "    from zy_detail_charge where   " +
+            "           inpatient_no =  #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn =  #{ledgerSn}   " +
+            "                            and trans_flag_yb <> 2 and order_no <> 6 and   " +
+            "    ori_detail_sn in(select ori_detail_sn from zy_detail_charge where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn =  #{ledgerSn}   " +
+            "and charge_fee <0 and ori_detail_sn is not null)   " +
+            "    ) temp       " +
+            "    group by inpatient_no, admiss_times, ledger_sn, detail_sn, charge_code_mx")
+    List<ZyDetailCharge> tuiFeiYuEr(@Param("inpatientNo") String inpatientNo,
+                                    @Param("admissTimes") Integer admissTimes,
+                                    @Param("ledgerSn") Integer ledgerSn);
+
     @Update("<script>" +
             "<foreach collection='list' item='item' separator=';'>" +
             "update zy_detail_charge set ori_detail_sn = null  where  inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn =  #{ledgerSn} " +

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

@@ -1058,10 +1058,9 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
                                                      @Param("list") List<String> execUnit);
 
     @Select("<script>" +
-            "select inpatient_no,admiss_times,ledger_sn,detail_sn,charge_amount,charge_fee,charge_code_mx,charge_date " +
+            "select inpatient_no,admiss_times,ledger_sn,detail_sn,charge_amount,charge_fee,charge_code_mx,charge_date,ori_detail_sn " +
             "from zy_detail_charge where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and charge_code_mx = #{chargeCodeMx} " +
-            "and  ori_detail_sn is null " +
-            "and exec_unit = #{execUnit} and trans_flag_yb &lt;&gt; 2 and order_no &lt;&gt; 6 and charge_fee &gt; 0 and  charge_amount &gt; 0 " +
+            "and exec_unit = #{execUnit} and trans_flag_yb &lt;&gt; 2 and order_no &lt;&gt; 6 and charge_fee &gt; 0 and  charge_amount &gt; 0 and infant_flag = #{infantFlag}" +
             "<if test=\"startTime != null and startTime != '' \">" +
             "and charge_date &gt;= #{startTime} and charge_date &lt;= #{endTime} " +
             "</if>" +
@@ -1070,19 +1069,43 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
     List<ZyDetailCharge> weiGuiZhenShuPiPei(@Param("inpatientNo") String inpatientNo,
                                             @Param("admissTimes") Integer admissTimes,
                                             @Param("ledgerSn") Integer ledgerSn,
+                                            @Param("infantFlag") Integer infantFlag,
                                             @Param("chargeCodeMx") String chargeCodeMx,
                                             @Param("execUnit") String execUnit,
                                             @Param("startTime") String startTime,
                                             @Param("endTime") String endTime,
                                             @Param("riQiPaiXu") String riQiPaiXu);
 
+
+    @Select("select inpatient_no,admiss_times,ledger_sn,detail_sn,charge_code_mx,sum(charge_fee) yi_tui_fei from (  " +
+            "select inpatient_no,admiss_times,ledger_sn,detail_sn,charge_code_mx,charge_fee  " +
+            "from zy_detail_charge where " +
+            "inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and charge_code_mx = #{chargeCodeMx} " +
+            "and exec_unit = #{execUnit} and trans_flag_yb <> 2 and order_no <> 6 and" +
+            "    detail_sn in(select ori_detail_sn from zy_detail_charge where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and charge_code_mx = #{chargeCodeMx}" +
+            " and charge_fee <0 and ori_detail_sn is not null)  " +
+            "union all  " +
+            "select inpatient_no,admiss_times,ledger_sn,ori_detail_sn,charge_code_mx,charge_fee  " +
+            "from zy_detail_charge where " +
+            "inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and charge_code_mx = #{chargeCodeMx} " +
+            "and exec_unit = #{execUnit} and trans_flag_yb <> 2 and order_no <> 6 and " +
+            "ori_detail_sn in(select ori_detail_sn from zy_detail_charge where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and charge_code_mx = #{chargeCodeMx} and charge_fee <0 and ori_detail_sn is not null)  " +
+            ") temp  " +
+            "group by inpatient_no, admiss_times, ledger_sn, detail_sn, charge_code_mx")
+    List<ZyDetailCharge> tuiFeiYuEr1(@Param("inpatientNo") String inpatientNo,
+                                     @Param("admissTimes") Integer admissTimes,
+                                     @Param("ledgerSn") Integer ledgerSn,
+                                     @Param("infantFlag") Integer infantFlag,
+                                     @Param("chargeCodeMx") String chargeCodeMx,
+                                     @Param("execUnit") String execUnit);
+
     @Select("<script>" +
             "select * from zy_detail_charge " +
             "where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and infant_flag = #{infantFlag} and detail_sn in " +
             "<foreach collection='list' item='item' index='index' open='(' close=')' separator=','>" +
             "#{item}" +
             "</foreach>" +
-            " and charge_fee > 0 and charge_amount > 0 " +
+            " and charge_fee &gt; 0 and charge_amount &gt; 0 " +
             "</script>")
     List<ZyDetailCharge> piPeiXinXi(@Param("inpatientNo") String inpatientNo,
                                     @Param("admissTimes") Integer admissTimes,
@@ -1091,6 +1114,22 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
                                     @Param("list") int[] detailSnList);
 
 
+    @Select("<script>" +
+            "select inpatient_no,admiss_times,ledger_sn,ori_detail_sn,sum(charge_fee) charge_fee from zy_detail_charge  " +
+            "              where  inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and infant_flag = #{infantFlag} and ori_detail_sn in  " +
+            "<foreach collection='list' item='item' index='index' open='(' close=')' separator=','>" +
+            "#{item} " +
+            "</foreach>" +
+            "and charge_fee &lt; 0 and charge_amount &lt; 0  " +
+            "group by inpatient_no, admiss_times, ledger_sn, ori_detail_sn  " +
+            "</script>")
+    List<ZyDetailCharge> tuiFeiYuEr2(@Param("inpatientNo") String inpatientNo,
+                                     @Param("admissTimes") Integer admissTimes,
+                                     @Param("ledgerSn") Integer ledgerSn,
+                                     @Param("infantFlag") Integer infantFlag,
+                                     @Param("list") int[] detailSnList);
+
+
     @Select("select inpatient_no,admiss_times,ledger_sn,detail_sn,charge_fee,charge_amount,ori_detail_sn,trans_flag_yb,exec_unit from zy_detail_charge " +
             "where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and detail_sn = #{detailSn} " +
             "and infant_flag = #{infantFlag} and charge_fee < 0 and charge_amount < 0 ")

+ 3 - 1
src/main/java/thyyxxk/webserver/entity/datamodify/ZyDetailCharge.java

@@ -40,6 +40,8 @@ public class ZyDetailCharge implements Serializable {
 
     private String chargeCodeName;
 
+    private BigDecimal origChargeFee;
+
     private Integer ledgerSn;
 
     private Integer detailSn;
@@ -106,7 +108,7 @@ public class ZyDetailCharge implements Serializable {
 
     private String ybSelfFlag;
 
-    private BigDecimal origChargeFee;
+    private BigDecimal yiTuiFei;
 
     private String confirmId;
 

+ 16 - 8
src/main/java/thyyxxk/webserver/service/PublicServer.java

@@ -9,12 +9,10 @@ import thyyxxk.webserver.dao.his.PublicDao;
 import thyyxxk.webserver.dao.his.yibao.TransferInOfExpensesDao;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
+import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
 import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.entity.yibao.ZyActpatient;
-import thyyxxk.webserver.utils.ListUtil;
-import thyyxxk.webserver.utils.ResultVoUtil;
-import thyyxxk.webserver.utils.StringUtil;
-import thyyxxk.webserver.utils.TokenUtil;
+import thyyxxk.webserver.utils.*;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -34,6 +32,7 @@ public class PublicServer {
 
     private final TransferInOfExpensesDao transferInOfExpensesDao;
 
+
     public PublicServer(PublicDao dao, TransferInOfExpensesDao transferInOfExpensesDao) {
         this.dao = dao;
         this.transferInOfExpensesDao = transferInOfExpensesDao;
@@ -178,10 +177,19 @@ public class PublicServer {
      */
     public void genXingYuanLiuShuiBiaoZhi(String inpatientNo, Integer admissTimes, Integer ledger) {
         // 如果这两个不一样的话 就需要重新匹配
-        List<Integer> chongFuTuiFei = dao.chongFuTuiFei(inpatientNo, admissTimes, ledger);
-        if (ListUtil.notBlank(chongFuTuiFei)) {
-            log.info("重复流水号:{}", JSON.toJSONString(chongFuTuiFei));
-            //dao.chongFuTuiFeiChongZhi(inpatientNo, admissTimes, ledger, chongFuTuiFei);
+        List<ZyDetailCharge> chongFu = dao.tuiFeiYuEr(inpatientNo, admissTimes, ledger);
+        List<Integer> chongFuLiuShui = new ArrayList<>();
+
+        if (ListUtil.notBlank(chongFu)) {
+            for (ZyDetailCharge zyDetailCharge : chongFu) {
+                if (BigUtils.bigXiaoYu(zyDetailCharge.getYiTuiFei(), 0)) {
+                    chongFuLiuShui.add(zyDetailCharge.getDetailSn());
+                }
+            }
+            if (ListUtil.notBlank(chongFuLiuShui)) {
+                dao.chongFuTuiFeiChongZhi(inpatientNo, admissTimes, ledger, chongFuLiuShui);
+                log.info("重复流水号:{}", JSON.toJSONString(chongFuLiuShui));
+            }
         }
         dao.jiuZhengZhenShuLiuShui(inpatientNo, admissTimes, ledger);
         dao.genXinYuanTuiFeiLiuShui(inpatientNo, admissTimes, ledger);

+ 47 - 9
src/main/java/thyyxxk/webserver/service/yibao/XiangMuLuRuService.java

@@ -110,7 +110,8 @@ public class XiangMuLuRuService {
     @Transactional(rollbackFor = Exception.class)
     public ResultVo<String> xiangMuTuiFei(ZyDetailCharge param) {
         List<Integer> yongHuJueSe = dao.huoQuJueSe(TokenUtil.getTokenUserId());
-        if (!yongHuJueSe.contains(36)) {
+        log.info("角色:{}", JSON.toJSONString(yongHuJueSe));
+        if (!yongHuJueSe.contains(36) && !yongHuJueSe.contains(1)) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有权限退费。");
         }
         if (param.getList() == null || param.getList().isEmpty()) {
@@ -454,6 +455,9 @@ public class XiangMuLuRuService {
      */
     @Transactional(rollbackFor = Exception.class)
     public ResultVo<String> yiZhuTuiFeiPiPei(String inpatientNo, Integer admissTimes, String deptCode) {
+        if (StringUtil.isBlank(inpatientNo) || admissTimes == null || StringUtil.isBlank(deptCode)) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者信息不全。");
+        }
         int infantFlag = publicServer.getInfantFlag(inpatientNo);
         inpatientNo = publicServer.getInpatientNo(inpatientNo);
         Integer ledgerSn = publicServer.getLedgerSn(inpatientNo, admissTimes);
@@ -638,7 +642,31 @@ public class XiangMuLuRuService {
 
     public ResultVo<List<ZyDetailCharge>> huoQuZhenShuKePiPei(String inpatientNo, Integer admissTimes, Integer ledgerSn, String chargeCodeMx, String execUnit, String startTime, String endTime, String riQiPaiXu) {
         log.info("获取可以匹配的费用==》 住院号:{},次数:{},账页号:{},项目编码:{},执行科室:{}", inpatientNo, admissTimes, ledgerSn, chargeCodeMx, execUnit);
-        return ResultVoUtil.success(dao.weiGuiZhenShuPiPei(publicServer.getInpatientNo(inpatientNo), admissTimes, ledgerSn, chargeCodeMx, execUnit, startTime, endTime, riQiPaiXu));
+        List<ZyDetailCharge> zhenShuFeiYong = dao.weiGuiZhenShuPiPei(publicServer.getInpatientNo(inpatientNo), admissTimes, ledgerSn, publicServer.getInfantFlag(inpatientNo),
+                chargeCodeMx, execUnit, startTime, endTime, riQiPaiXu);
+        List<ZyDetailCharge> yuEr = dao.tuiFeiYuEr1(publicServer.getInpatientNo(inpatientNo), admissTimes, ledgerSn, publicServer.getInfantFlag(inpatientNo),
+                chargeCodeMx, execUnit);
+        Map<String, ZyDetailCharge> yuErPiPei = new HashMap<>();
+        for (ZyDetailCharge item : yuEr) {
+            String key = item.getInpatientNo() + item.getAdmissTimes() + item.getDetailSn() + item.getChargeCodeMx();
+            yuErPiPei.put(key, item);
+        }
+        for (int i = 0, len = zhenShuFeiYong.size(); i < len; i++) {
+            ZyDetailCharge zy = zhenShuFeiYong.get(i);
+            String key = zy.getInpatientNo() + zy.getAdmissTimes() + zy.getDetailSn() + zy.getChargeCodeMx();
+            if (yuErPiPei.containsKey(key)) {
+                if (BigUtils.dengYu(yuErPiPei.get(key).getYiTuiFei(), 0)) {
+                    zhenShuFeiYong.remove(i);
+                    len--;
+                    i--;
+                } else {
+                    zy.setYiTuiFei(zy.getChargeFee().subtract(yuErPiPei.get(key).getYiTuiFei()));
+                    log.info("原来:{},已退:{},余额:{}", zy.getChargeFee(), yuErPiPei.get(key).getYiTuiFei(), zy.getYiTuiFei());
+                }
+            }
+        }
+        log.info("可匹配的费用:{}", JSON.toJSONString(zhenShuFeiYong));
+        return ResultVoUtil.success(zhenShuFeiYong);
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -658,24 +686,34 @@ public class XiangMuLuRuService {
         } else if (zy.getTransFlagYb().equals("2") || zy.getOriDetailSn() != null) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该负数费用已被正负相抵。");
         }
-        List<ZyDetailCharge> shuJuXinXi = dao.piPeiXinXi(inpatientNo, zyDetailCharge.getAdmissTimes(), zyDetailCharge.getLedgerSn(), infantFlag, detailSnList);
+        List<ZyDetailCharge> zhenShuShuJu = dao.piPeiXinXi(inpatientNo, zyDetailCharge.getAdmissTimes(), zyDetailCharge.getLedgerSn(), infantFlag, detailSnList);
+
+        Map<Integer, ZyDetailCharge> tuiFeiYuErPiPei = dao.tuiFeiYuEr2(inpatientNo, zyDetailCharge.getAdmissTimes(), zyDetailCharge.getLedgerSn(), infantFlag, detailSnList).stream().collect(
+                Collectors.toMap(ZyDetailCharge::getOriDetailSn, a -> a, (k1, k2) -> k1));
+
+
         BigDecimal chargeFeeSum = new BigDecimal(0);
         BigDecimal chargeAmountSum = new BigDecimal(0);
+
         List<Integer> yongHuJueSe = dao.huoQuJueSe(TokenUtil.getTokenUserId());
         List<String> zhiXinKeShi = dao.chaXunZhiZXinKeShi(zyDetailCharge.getDeptCode());
-        for (ZyDetailCharge detailCharge : shuJuXinXi) {
+
+        for (ZyDetailCharge detailCharge : zhenShuShuJu) {
             zyDetailCharge.setYaoPing(false);
             ResultVo<String> LOGICAL_ERROR = getStringResultVo(yongHuJueSe, zhiXinKeShi, zyDetailCharge, detailCharge);
             if (LOGICAL_ERROR != null) return LOGICAL_ERROR;
-            if (detailCharge.getOriDetailSn() != null || detailCharge.getTransFlagYb().equals("2")) {
-                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号为:{%d},已被退费请重新选择。", detailCharge.getDetailSn()));
+            if (detailCharge.getTransFlagYb().equals("2")) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号为:{%d},已被正负抵消。", detailCharge.getDetailSn()));
+            }
+            if (tuiFeiYuErPiPei.containsKey(detailCharge.getDetailSn())) {
+                detailCharge.setChargeFee(detailCharge.getChargeFee().add(tuiFeiYuErPiPei.get(detailCharge.getDetailSn()).getChargeFee()));
             }
             chargeFeeSum = chargeFeeSum.add(detailCharge.getChargeFee());
             chargeAmountSum = chargeAmountSum.add(detailCharge.getChargeAmount());
         }
-        if (BigUtils.dengYu(chargeFeeSum, zy.getChargeFee().negate()) && BigUtils.dengYu(chargeAmountSum, zy.getChargeAmount().negate())) {
-            if (shuJuXinXi.size() == 1) {
-                dao.zhiYouYiGeJiuGenXingFuShuLiuShui(zyDetailCharge.getInpatientNo(), zyDetailCharge.getAdmissTimes(), zyDetailCharge.getLedgerSn(), zyDetailCharge.getDetailSn(), shuJuXinXi.get(0).getDetailSn());
+        if (BigUtils.bigDaYu(chargeFeeSum, zy.getChargeFee().negate()) || BigUtils.dengYu(chargeFeeSum, zy.getChargeFee().negate())) {
+            if (zhenShuShuJu.size() == 1) {
+                dao.zhiYouYiGeJiuGenXingFuShuLiuShui(zyDetailCharge.getInpatientNo(), zyDetailCharge.getAdmissTimes(), zyDetailCharge.getLedgerSn(), zyDetailCharge.getDetailSn(), zhenShuShuJu.get(0).getDetailSn());
                 publicServer.genXingYuanLiuShuiBiaoZhi(inpatientNo, zyDetailCharge.getAdmissTimes(), zyDetailCharge.getLedgerSn());
                 return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "费用匹配成功。");
             } else {