Ver Fonte

违规费用分析

xiaochan há 3 anos atrás
pai
commit
84217c5dde

+ 21 - 2
src/main/java/thyyxxk/webserver/controller/yibao/XiangMuLuRuController.java

@@ -116,7 +116,26 @@ public class XiangMuLuRuController {
     @PassToken
     @GetMapping("/weiGuiFeiYongFenXi")
     public ResultVo<WeiGuiFeiYongFenXi> weiGuiFeiYongFenXi(@RequestParam("inpatientNo") String inpatientNo,
-                                                           @RequestParam("admissTimes") Integer admissTimes) {
-        return service.weiGuiFeiYongFenXi(inpatientNo, admissTimes);
+                                                           @RequestParam("admissTimes") Integer admissTimes,
+                                                           @RequestParam("execUnit") String execUnit) {
+        return service.weiGuiFeiYongFenXi(inpatientNo, admissTimes, execUnit);
+    }
+
+
+    @GetMapping("/huoQuZhenShuKePiPei")
+    public ResultVo<List<ZyDetailCharge>> huoQuZhenShuKePiPei(@RequestParam("inpatientNo") String inpatientNo,
+                                                              @RequestParam("admissTimes") Integer admissTimes,
+                                                              @RequestParam("ledgerSn") Integer ledgerSn,
+                                                              @RequestParam("chargeCodeMx") String chargeCodeMx,
+                                                              @RequestParam("execUnit") String execUnit,
+                                                              @RequestParam("startTime") String startTime,
+                                                              @RequestParam("endTime") String endTime,
+                                                              @RequestParam("riQiPaiXu") String riQiPaiXu) {
+        return service.huoQuZhenShuKePiPei(inpatientNo, admissTimes, ledgerSn, chargeCodeMx, execUnit, startTime, endTime, riQiPaiXu);
+    }
+
+    @PostMapping("/caiFenPiPei")
+    public ResultVo<String> caiFenPiPei(@RequestBody ZyDetailCharge zyDetailCharge) {
+        return service.caiFenPiPei(zyDetailCharge);
     }
 }

+ 18 - 10
src/main/java/thyyxxk/webserver/dao/his/PublicDao.java

@@ -110,16 +110,24 @@ public interface PublicDao {
                                       @Param("admissTimes") Integer admissTimes);
 
 
-    @Select("select count(1) from zy_detail_charge where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn}  " +
-            "and ori_detail_sn > 0 ")
-    Integer tuiFeiYiPiPei(@Param("inpatientNo") String inpatientNo,
-                          @Param("admissTimes") Integer admissTimes,
-                          @Param("ledgerSn") Integer ledgerSn);
-
-    @Select("select count(1) from zy_detail_charge where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} and ori_detail_sn < 0")
-    Integer beiPiPeiZhenShu(@Param("inpatientNo") String inpatientNo,
-                            @Param("admissTimes") Integer admissTimes,
-                            @Param("ledgerSn") Integer ledgerSn);
+    @Select("select ori_detail_sn from zy_detail_charge " +
+            "where  inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn =  #{ledgerSn} " +
+            "  and charge_fee < 0 " +
+            "group by ori_detail_sn having count(1) >  1")
+    List<Integer> chongFuTuiFei(@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} " +
+            "and (detail_sn = #{item} or ori_detail_sn = #{item}) " +
+            "</foreach>" +
+            "</script>")
+    void chongFuTuiFeiChongZhi(@Param("inpatientNo") String inpatientNo,
+                               @Param("admissTimes") Integer admissTimes,
+                               @Param("ledgerSn") Integer ledgerSn,
+                               @Param("list") List<Integer> oriDetailSn);
 
     @Update("update zy_detail_charge set ori_detail_sn = null where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn =  #{ledgerSn}  " +
             "and charge_fee > 0 and charge_amount > 0 and ori_detail_sn = -1  " +

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

@@ -623,18 +623,23 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
             "charge_fee , self_flag , separate_flag , supress_flag , ward_code , dept_code , ope_flag , exec_unit , retprice , amount , zy_serial_no , " +
             "serial , group_no , occ_cate ) values " +
             "<foreach collection='list' item='item' separator=','>" +
-            "<if test=\"item.serial !=null and item.serial !='' and item.serial == '01' \">" +
-            "( #{zyDetailCharge.inpatientNo} , #{zyDetailCharge.admissTimes} , #{ledgerSn} , #{item.detailSn} , getdate() , #{zyDetailCharge.opIdCode} , " +
-            "#{item.chargeCodeMx} ,  #{infantFlag} , cast(#{item.chargeAmount,jdbcType=DECIMAL} as decimal(14,5)) , '0' , '0' , null , #{zyDetailCharge.ward} , #{zyDetailCharge.dept} , '0' , #{item.deptCode}" +
-            " , cast(#{item.chargeAmount,jdbcType=DECIMAL} as decimal(14,5)) , cast(#{item.amount,jdbcType=DECIMAL} as decimal(14,5)) " +
+            "( #{zyDetailCharge.inpatientNo} , #{zyDetailCharge.admissTimes} , #{ledgerSn} , #{item.detailSn} , getdate() , #{opIdCode} , " +
+            "#{item.chargeCodeMx} ,  #{infantFlag} , " +
+            // 金额
+            "cast(#{item.chargeFee,jdbcType=DECIMAL} as decimal(14,5))," +
+            " '0' , '0' , null , #{zyDetailCharge.ward} , #{zyDetailCharge.dept} , '0' , #{item.deptCode} ," +
+            // 单价
+            "  cast(#{item.chargeFee,jdbcType=DECIMAL} / #{item.chargeAmount,jdbcType=DECIMAL} as decimal(14,5)) , " +
+            // 数量
+            "cast(#{item.chargeAmount,jdbcType=DECIMAL} as decimal(14,5)) " +
             ", #{zyDetailCharge.zySerialNo} , #{item.serial} , #{item.groupNo} ,'1' )" +
-            "</if>" +
             "</foreach>" +
             "</script>")
     void shenQingYaoPing(@Param("zyDetailCharge") ZyDetailCharge zyDetailCharge,
                          @Param("list") List<ZyDetailCharge> list,
                          @Param("infantFlag") int infantFlag,
-                         @Param("ledgerSn") Integer ledgerSn);
+                         @Param("ledgerSn") Integer ledgerSn,
+                         @Param("opIdCode") String opIdCode);
 
     /**
      * 需要更新患者的总费用
@@ -872,7 +877,7 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
 
 
     @Select("select detail_sn,ori_detail_sn,trans_flag_yb from zy_detail_charge where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledger} " +
-            "and detail_sn = #{detailSn} and order_no <> 6 and trans_flag_yb <> 2")
+            "and detail_sn = #{detailSn} and order_no <> 6 and trans_flag_yb <> 2 ")
     ZyDetailCharge beiTuiFeiYongXinXi(@Param("inpatientNo") String inpatientNo,
                                       @Param("admissTimes") Integer admissTimes,
                                       @Param("ledger") Integer ledger,
@@ -894,31 +899,24 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
                                      @Param("detailSn") Integer detailSn);
 
 
-    // 违规费用 分析
-
-
-    @Select("select ori_detail_sn from zy_detail_charge " +
-            "where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledger} " +
-            "and infant_flag = #{infantFlag} " +
-            "  and charge_fee < 0 " +
-            "  and ori_detail_sn is not null " +
-            "group by ori_detail_sn having count(1)  > 1")
-    List<Integer> chongFuTuiFei(@Param("inpatientNo") String inpatientNo,
-                                @Param("admissTimes") Integer admissTimes,
-                                @Param("ledger") Integer ledger,
-                                @Param("infantFlag") Integer infantFlag);
+    @Select("select b.code from zy_detail_charge a, yp_zd_dict b " +
+            "where order_no <> 6 and trans_flag_yb not in (1,2)  and charge_code like 'BILL%' " +
+            "  and  isnull(b.national_code,'') = '' and inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledger} " +
+            "and a.infant_flag = #{infantFlag} " +
+            "  and a.charge_code_mx = b.code " +
+            "group by  b.code ")
+    List<Integer> weiGuiYaoPinInt(@Param("inpatientNo") String inpatientNo,
+                                  @Param("admissTimes") Integer admissTimes,
+                                  @Param("ledger") Integer ledger,
+                                  @Param("infantFlag") Integer infantFlag);
 
     @Update("<script>" +
-            "update zy_detail_charge set ori_detail_sn = null where inpatient_no = '0402330' and admiss_times = 1 and ledger_sn = 1 and infant_flag = 0 and ori_detail_sn in " +
-            "<foreach collection='list' item='item' index='index' open='(' close=')' separator=','>" +
-            "#{item}" +
+            "<foreach collection='list' item='item' separator=';'>" +
+            "update yp_zd_dict set national_code = (select national_code from yp_zd_dict where  code = #{item} and national_code is not null ) " +
+            "where code = #{item} and national_code is null" +
             "</foreach>" +
             "</script>")
-    void chongZhiWeiGuiYuanLiuShui(@Param("inpatientNo") String inpatientNo,
-                                   @Param("admissTimes") Integer admissTimes,
-                                   @Param("ledger") Integer ledger,
-                                   @Param("infantFlag") Integer infantFlag,
-                                   @Param("list") List<Integer> oriDetailSn);
+    void genXinYaoPingPiPeiXinXi(@Param("list") List<Integer> list);
 
     /**
      * 违规药品 信息 没有匹配的
@@ -939,6 +937,7 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
                                           @Param("ledger") Integer ledger,
                                           @Param("infantFlag") Integer infantFlag);
 
+
     @Select("select charge_code_mx,b.name,national_code from zy_detail_charge a, zd_charge_item b  " +
             "where order_no <> 6 and trans_flag_yb not in (1,2)  and charge_code not like 'BILL%'  " +
             "  and  isnull(b.national_code,'') = '' and inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledger}  " +
@@ -951,15 +950,91 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
                                            @Param("infantFlag") Integer infantFlag);
 
 
-    @Select("select rtrim(inpatient_no) inpatient_no,admiss_times,ledger_sn,charge_code_mx,detail_sn,ori_detail_sn,charge_fee,charge_amount, " +
-            "       exec_unit_name = (select rtrim(name) name from zd_unit_code where exec_unit = code),charge_date,trans_flag_yb, " +
-            "       op_id_code = (select rtrim(name) name from a_employee_mi where code  = op_id_code) from zy_detail_charge " +
+    @Select("<script>" +
+            "select rtrim(inpatient_no) inpatient_no,admiss_times,ledger_sn,charge_code_mx,detail_sn,ori_detail_sn,charge_fee,charge_amount, " +
+            "       exec_unit_name = (select rtrim(name) name from zd_unit_code where exec_unit = code),charge_date,trans_flag_yb, exec_unit, " +
+            "       op_id_code = (select rtrim(name) name from a_employee_mi where code  = op_id_code)," +
+            "       charge_code_name = (select rtrim(name) name from zd_charge_item where code = charge_code_mx),charge_code = 'xm' from zy_detail_charge " +
             "where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledger} " +
-            "  and charge_fee < 0 " +
+            "  and charge_fee &lt; 0 and charge_code not like 'BILL%' " +
             "  and  trans_flag_yb not in (1,2) " +
-            "  and ori_detail_sn is null")
-    List<ZyDetailCharge> weiXieDaiYuanLiuShui(@Param("inpatientNo") String inpatientNo,
-                                              @Param("admissTimes") Integer admissTimes,
-                                              @Param("ledger") Integer ledger,
-                                              @Param("infantFlag") Integer infantFlag);
+            "  and ori_detail_sn is null" +
+            "<if test=\"execUnit != null and execUnit != '' \">" +
+            " and exec_unit = #{execUnit} " +
+            "</if>" +
+            "</script>")
+    List<ZyDetailCharge> weiXieDaiYuanLiuShuiXiangMu(@Param("inpatientNo") String inpatientNo,
+                                                     @Param("admissTimes") Integer admissTimes,
+                                                     @Param("ledger") Integer ledger,
+                                                     @Param("infantFlag") Integer infantFlag,
+                                                     @Param("execUnit") String execUnit);
+
+    @Select("<script>" +
+            "select rtrim(inpatient_no) inpatient_no,admiss_times,ledger_sn,charge_code_mx,detail_sn,ori_detail_sn,charge_fee,charge_amount, " +
+            "       exec_unit_name = (select rtrim(name) name from zd_unit_code where exec_unit = code),charge_date,trans_flag_yb,exec_unit, " +
+            "       op_id_code = (select rtrim(name) name from a_employee_mi where code  = op_id_code)," +
+            "       charge_code_name = (select top(1) rtrim(name) name from yp_zd_dict where code = charge_code_mx),charge_code = 'yp' from zy_detail_charge " +
+            "where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledger} " +
+            "  and charge_fee &lt; 0 and charge_code  like 'BILL%' " +
+            "  and  trans_flag_yb not in (1,2) " +
+            "  and ori_detail_sn is null" +
+            "<if test=\"execUnit != null and execUnit != '' \">" +
+            " and exec_unit = #{execUnit} " +
+            "</if>" +
+            "</script>")
+    List<ZyDetailCharge> weiXieDaiYuanLiuShuiYaoPing(@Param("inpatientNo") String inpatientNo,
+                                                     @Param("admissTimes") Integer admissTimes,
+                                                     @Param("ledger") Integer ledger,
+                                                     @Param("infantFlag") Integer infantFlag,
+                                                     @Param("execUnit") String execUnit);
+
+    @Select("<script>" +
+            "select inpatient_no,admiss_times,ledger_sn,detail_sn,charge_amount,charge_fee,charge_code_mx,charge_date " +
+            "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 " +
+            "<if test=\"startTime != null and startTime != '' \">" +
+            "and charge_date &gt;= #{startTime} and charge_date &lt;= #{endTime} " +
+            "</if>" +
+            " order by charge_date ${riQiPaiXu}" +
+            "</script>")
+    List<ZyDetailCharge> weiGuiZhenShuPiPei(@Param("inpatientNo") String inpatientNo,
+                                            @Param("admissTimes") Integer admissTimes,
+                                            @Param("ledgerSn") Integer ledgerSn,
+                                            @Param("chargeCodeMx") String chargeCodeMx,
+                                            @Param("execUnit") String execUnit,
+                                            @Param("startTime") String startTime,
+                                            @Param("endTime") String endTime,
+                                            @Param("riQiPaiXu") String riQiPaiXu);
+
+    @Select("<script>" +
+            "select * from zy_detail_charge\n" +
+            "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 " +
+            "</script>")
+    List<ZyDetailCharge> piPeiXinXi(@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\n" +
+            "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 ")
+    ZyDetailCharge piPeiXinXiFuShu(@Param("inpatientNo") String inpatientNo,
+                                   @Param("admissTimes") Integer admissTimes,
+                                   @Param("ledgerSn") Integer ledgerSn,
+                                   @Param("infantFlag") Integer infantFlag,
+                                   @Param("detailSn") Integer detailSn);
+
+    @Update("update zy_detail_charge set ori_detail_sn = #{oriDetailSn} where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} " +
+            "and detail_sn = #{detailSn} ")
+    void zhiYouYiGeJiuGenXingFuShuLiuShui(@Param("inpatientNo") String inpatientNo,
+                                          @Param("admissTimes") Integer admissTimes,
+                                          @Param("ledgerSn") Integer ledgerSn,
+                                          @Param("detailSn") Integer detailSn,
+                                          @Param("oriDetailSn") Integer oriDetailSn);
 }

+ 6 - 6
src/main/java/thyyxxk/webserver/service/PublicServer.java

@@ -135,6 +135,7 @@ public class PublicServer {
      * @return 返回项目信息
      */
     public ResultVo<List<GetDropdownBox>> getChargeCode(String pyCode) {
+        log.info("获取编码:{}", pyCode);
         return ResultVoUtil.success(dao.getChargeCode(StringUtil.isContainChinese(pyCode)));
     }
 
@@ -168,11 +169,12 @@ public class PublicServer {
     public void genXingYuanLiuShuiBiaoZhi(String inpatientNo, Integer admissTimes, Integer ledger) {
         // 如果这两个不一样的话 就需要重新匹配
         log.info("更新正数的流水号 ==> 流水号:{},住院次数:{},账页号:{}", inpatientNo, admissTimes, ledger);
-        if (!dao.tuiFeiYiPiPei(inpatientNo, admissTimes, ledger).equals(dao.beiPiPeiZhenShu(inpatientNo, admissTimes, ledger))) {
-            log.info("更新正数的流水号 ==> 流水号:{},住院次数:{},账页号:{}", inpatientNo, admissTimes, ledger);
-            dao.jiuZhengZhenShuLiuShui(inpatientNo, admissTimes, ledger);
-            dao.genXinYuanTuiFeiLiuShui(inpatientNo, admissTimes, ledger);
+        List<Integer> chongFuTuiFei = dao.chongFuTuiFei(inpatientNo, admissTimes, ledger);
+        if (ListUtil.notBlank(chongFuTuiFei)) {
+            dao.chongFuTuiFeiChongZhi(inpatientNo, admissTimes, ledger, chongFuTuiFei);
         }
+        dao.jiuZhengZhenShuLiuShui(inpatientNo, admissTimes, ledger);
+        dao.genXinYuanTuiFeiLiuShui(inpatientNo, admissTimes, ledger);
     }
 
     public UserInfo huoQuYuanGongXinXi(String code) {
@@ -180,9 +182,7 @@ public class PublicServer {
             return new UserInfo();
         }
         return dao.huoQuYuanGongXinXi(code);
-
     }
 
-
 }
 

+ 204 - 126
src/main/java/thyyxxk/webserver/service/yibao/XiangMuLuRuService.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.ListUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -19,10 +20,7 @@ import thyyxxk.webserver.utils.*;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -98,6 +96,7 @@ public class XiangMuLuRuService {
      * @return 返回项目信息
      */
     public ResultVo<List<GetDropdownBox>> getChargeCode(String pyCode) {
+        log.info("获取编码:{}", pyCode);
         return ResultVoUtil.success(dao.getChargeCode(StringUtil.isContainChinese(pyCode)));
     }
 
@@ -125,19 +124,15 @@ public class XiangMuLuRuService {
         for (ZyDetailCharge charge : chaKanSFtuiFei) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号为:【%s】已退费,请勿重复退费 <br/>···(。•́︿•̀。) ", charge.getOriDetailSn()));
         }
+        int infantFlag = 0;
         // 判断是否为婴儿
         if (param.getInpatientNo().contains("$")) {
             param.setInpatientNo(param.getInpatientNo().split("\\$")[0]);
+            infantFlag = 1;
         }
         if (dao.getHuanZheSFJieSuan(param.getInpatientNo(), param.getAdmissTimes()) == null || dao.getHuanZheSFJieSuan(param.getInpatientNo(), param.getAdmissTimes()) != 0) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者已经结算了");
         }
-        // 获取到用户角色
-        List<Integer> yongHuJueSe = dao.huoQuJueSe(TokenUtil.getTokenUserId());
-
-        //获取到这个人是否属于这个科室
-        List<String> zhiXinKeShi = dao.chaXunZhiZXinKeShi(param.getDeptCode());
-
         // 获取原来的数据
         List<ZyDetailCharge> yuanTuiFeiList = dao.huoQuJuTiFeiYong(param.getInpatientNo(), param.getAdmissTimes(), param.getList());
         // 获取患者的总费用
@@ -146,6 +141,8 @@ public class XiangMuLuRuService {
         // 获取最大值
         Integer maxDetailSn = publicServer.getMaxDetailSn(param.getInpatientNo(), param.getAdmissTimes());
 
+        List<ZyDetailCharge> yaoPingDan = new ArrayList<>();
+
         List<Integer> genXingZhenShuTuiFeiLiuShui = new ArrayList<>();
         List<ZyDetailCharge> tuiFeiList = new ArrayList<>();
         for (ZyDetailCharge pojo : yuanTuiFeiList) {
@@ -153,21 +150,12 @@ public class XiangMuLuRuService {
             if (pojo.getChargeFee().signum() == -1 || pojo.getChargeAmount().signum() == -1) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("患者费用存在负数,流水号:【%s】,该数据为退费数据。<br/>( ´Д`)y━・~~", pojo.getDetailSn()));
             }
-            // 管理员角色可以无视
-            if (!yongHuJueSe.contains(1)) {
-                // 科室开头 是 8 就不是医技科室 只有医技科室可以退药品
-                if (param.getDeptCode().startsWith("8")) {
-                    if (!zhiXinKeShi.contains(pojo.getExecUnit())) {
-                        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号为【%s】,请对应的执行科室进行退费。<br/>( ´Д`)y━・~~", pojo.getDetailSn()));
-                    }
-                    // 护士是不可以退药品的
-                    if (pojo.getChargeCode().startsWith("BILL")) {
-                        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号为【%s】,包含药品费用,无法退费。<br/>( ´Д`)y━・~~", pojo.getDetailSn()));
-                    }
-                } else if (!param.getDeptCode().equals(pojo.getExecUnit())) {
-                    return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号为【%s】,请对应的执行科室进行退费。<br/>( ´Д`)y━・~~", pojo.getDetailSn()));
-                }
+            if (pojo.getChargeCode().startsWith("BILL")) {
+                yaoPingDan.add(pojo);
             }
+            // 在这里判断执行科室
+            ResultVo<String> LOGICAL_ERROR = getStringResultVo(param, pojo);
+            if (LOGICAL_ERROR != null) return LOGICAL_ERROR;
             // 数据库有个 触发器 如果带了医嘱号且有篆刻那么这里就需要改成 0
             if (BigUtils.bigDaYu(pojo.getOrderNo(), 10)) {
                 pojo.setOrderNo(new BigDecimal(0));
@@ -191,18 +179,43 @@ public class XiangMuLuRuService {
         if (tuiFeiList.isEmpty()) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询不到患者原数据,请联系管理员。( ´Д`)y━・~~");
         } else {
+            log.info("操作项目退费 ==》 操作人:{},数据:{}", TokenUtil.getTokenUserId(), JSON.toJSONString(tuiFeiList));
             List<List<ZyDetailCharge>> fenGe = ListUtils.partition(tuiFeiList, 20);
+            if (ListUtil.notBlank(yaoPingDan)) {
+                dao.shenQingYaoPing(param, yaoPingDan, infantFlag, publicServer.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes()), TokenUtil.getTokenUserId());
+            }
             fenGe.forEach(dao::xiangMuTuiFei);
             dao.genXinZhenShuTuiFeiLiuShui(param.getInpatientNo(), param.getAdmissTimes(),
                     publicServer.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes()), genXingZhenShuTuiFeiLiuShui);
             dao.huanZheZongFeiYong(fy, param.getInpatientNo(), param.getAdmissTimes(), "zy_ledger_file");
             dao.huanZheZongFeiYong(fy, param.getInpatientNo(), param.getAdmissTimes(), "zy_actpatient");
-            log.info("更新正数水流:{}", JSON.toJSONString(genXingZhenShuTuiFeiLiuShui));
-            log.info("操作项目退费 ==》 操作人:{},数据:{}", TokenUtil.getTokenUserId(), JSON.toJSONString(tuiFeiList));
+
             return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "项目退费操作成功。乁( ˙ ω˙乁)");
         }
     }
 
+    private ResultVo<String> getStringResultVo(ZyDetailCharge xuYaoTuiDeShuJu, ZyDetailCharge piPeiDeShuJu) {
+        // 获取到用户角色   管理员角色可以无视
+        List<Integer> yongHuJueSe = dao.huoQuJueSe(TokenUtil.getTokenUserId());
+        if (!yongHuJueSe.contains(1)) {
+            // 科室开头 是 8 就不是医技科室 只有医技科室可以退药品
+            if (xuYaoTuiDeShuJu.getDeptCode().startsWith("8")) {
+                //获取到这个人是否属于这个科室
+                List<String> zhiXinKeShi = dao.chaXunZhiZXinKeShi(xuYaoTuiDeShuJu.getDeptCode());
+                if (!zhiXinKeShi.contains(piPeiDeShuJu.getExecUnit())) {
+                    return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号为【%s】,请对应的执行科室进行退费。<br/>( ´Д`)y━・~~", piPeiDeShuJu.getDetailSn()));
+                }
+                // 护士是不可以退药品的
+                if (piPeiDeShuJu.getChargeCode().startsWith("BILL")) {
+                    return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号为【%s】,包含药品费用,无法退费。<br/>( ´Д`)y━・~~", piPeiDeShuJu.getDetailSn()));
+                }
+            } else if (!xuYaoTuiDeShuJu.getDeptCode().equals(piPeiDeShuJu.getExecUnit())) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号为【%s】,请对应的执行科室进行退费。<br/>( ´Д`)y━・~~", piPeiDeShuJu.getDetailSn()));
+            }
+        }
+        return null;
+    }
+
     /**
      * 获取模板
      *
@@ -264,32 +277,33 @@ public class XiangMuLuRuService {
      */
     @Transactional(rollbackFor = Exception.class)
     public ResultVo<String> xiangMuFeiYongShangChuan(ZyDetailCharge param) {
+
+        log.info("param:{}", JSON.toJSONStringWithDateFormat(param, DateUtil.DEFAULT_PATTERN));
         if (param.getList().size() > 50) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "一次性项目录入大于50条,๑乛◡乛๑");
         }
         StringBuilder errorStr = new StringBuilder();
         if (StringUtil.isBlank(param.getInpatientNo()) || param.getAdmissTimes() == null) {
-            errorStr.append("1、住院号和住院次数为空<br />");
+            errorStr.append("住院号和住院次数为空<br />");
         }
         if (param.getList().size() == 0) {
-            errorStr.append("2、没有要录入的项目 <br />");
+            errorStr.append("没有要录入的项目 <br />");
         }
         if (StringUtil.isBlank(param.getWard())) {
-            errorStr.append("3、病区为空 <br />");
+            errorStr.append("病区为空 <br />");
         }
         if (StringUtil.isBlank(param.getDept())) {
-            errorStr.append("4、申请科室为空 <br />");
+            errorStr.append("申请科室为空 <br />");
         }
         if (StringUtil.isBlank(param.getZySerialNo())) {
-            errorStr.append("5、住院流水号为空 <br />");
+            errorStr.append("住院流水号为空 <br />");
         }
         if (dao.getHuanZheSFZaiYuan(param.getInpatientNo(), param.getAdmissTimes()) == 0) {
-            errorStr.append("6、没有患者的在院信息 <br />");
+            errorStr.append("没有患者的在院信息 <br />");
         }
         if (errorStr.length() > 3) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, errorStr.toString());
         }
-
         // 婴儿 要特殊处理
         // 如果带有这个 $ 说明是婴儿
         int infantFlag = publicServer.getInfantFlag(param.getInpatientNo());
@@ -300,7 +314,7 @@ public class XiangMuLuRuService {
         BigDecimal sum = new BigDecimal(0);
         // 录入人的id
         param.setOpIdCode(TokenUtil.getTokenUserId());
-        int shiFuoCunZaiYaoPing = 0;
+        List<ZyDetailCharge> yaoPingShenQingDan = new ArrayList<>();
         // 药品
         for (ZyDetailCharge zyDetailCharge : param.getList()) {
             switch (zyDetailCharge.getBillItemCode()) {
@@ -356,7 +370,11 @@ public class XiangMuLuRuService {
             zyDetailCharge.setChargeAmount(zyDetailCharge.getChargeAmount().multiply(zyDetailCharge.getAmount()));
             zyDetailCharge.setDetailSn(maxDetailSn += 1);
             if (zyDetailCharge.getSerial().equals("01")) {
-                shiFuoCunZaiYaoPing += 1;
+                ZyDetailCharge shenQing = new ZyDetailCharge();
+                BeanUtils.copyProperties(zyDetailCharge, shenQing);
+                shenQing.setChargeFee(zyDetailCharge.getChargeAmount());
+                shenQing.setChargeAmount((zyDetailCharge.getAmount()));
+                yaoPingShenQingDan.add(shenQing);
             }
         }
         FeiYongLeiXin fy = JiSuanFeiYong.jiSuan(param.getList(), true);
@@ -367,8 +385,9 @@ public class XiangMuLuRuService {
         dao.chaRuFeiYong(param, param.getList(), infantFlag, ledgerSn);
         dao.huanZheZongFeiYong(fy, param.getInpatientNo(), param.getAdmissTimes(), "zy_ledger_file");
         dao.huanZheZongFeiYong(fy, param.getInpatientNo(), param.getAdmissTimes(), "zy_actpatient");
-        if (shiFuoCunZaiYaoPing > 0) {
-            dao.shenQingYaoPing(param, param.getList(), infantFlag, ledgerSn);
+        if (ListUtil.notBlank(yaoPingShenQingDan)) {
+            log.info("shenqingdan:{}", JSON.toJSONStringWithDateFormat(yaoPingShenQingDan, DateUtil.DEFAULT_PATTERN));
+            dao.shenQingYaoPing(param, yaoPingShenQingDan, infantFlag, ledgerSn, TokenUtil.getTokenUserId());
         }
         log.info("项目录入费用上传 ==》 操作人:{},数据:{}", param.getOpIdCode(), JSON.toJSONString(param));
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "费用上传成功。<( ̄︶ ̄)>");
@@ -416,93 +435,95 @@ public class XiangMuLuRuService {
      * @param admissTimes 住院次数
      * @return 返回是否匹配成功
      */
+    @Transactional(rollbackFor = Exception.class)
     public ResultVo<String> yiZhuTuiFeiPiPei(String inpatientNo, Integer admissTimes) {
-        inpatientNo = publicServer.getInpatientNo(inpatientNo);
         int infantFlag = publicServer.getInfantFlag(inpatientNo);
+        inpatientNo = publicServer.getInpatientNo(inpatientNo);
         Integer ledgerSn = publicServer.getLedgerSn(inpatientNo, admissTimes);
 
-        // 获取正的医嘱费用
-        List<ZyDetailCharge> getYiZhuFeiYongZhenShu = dao.getYiZhuFeiYong(inpatientNo, admissTimes, ledgerSn, ">", infantFlag);
-        // 获取负的医嘱费用
-        List<ZyDetailCharge> getYiZhuFeiYongFuShu = dao.getYiZhuFeiYong(inpatientNo, admissTimes, ledgerSn, "<", 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.getChargeFee() + item.getLedgerSn())
-        );
-        // 用负数拼接的 key 去查找
-        for (ZyDetailCharge fuShu : getYiZhuFeiYongFuShu) {
-            String key = fuShu.getOrderNo() + DateUtil.formatDatetime(fuShu.getChargeDate()) + fuShu.getChargeCodeMx() + fuShu.getChargeAmount().negate()
-                    + fuShu.getChargeFee().negate() + fuShu.getLedgerSn();
-            if (zhenShuMap.containsKey(key)) {
-                for (ZyDetailCharge zyDetailCharge : zhenShuMap.get(key)) {
-                    if (zyDetailCharge.getTuiFeiFlag() == null && zyDetailCharge.getOriDetailSn() == null) {
-                        fuShu.setOriDetailSn(zyDetailCharge.getDetailSn());
-                        zyDetailCharge.setTuiFeiFlag(1);
-                        piPei.add(fuShu);
-                        log.info("第一次匹配==》流水:{},匹配流水:{},", fuShu.getDetailSn(), fuShu.getOriDetailSn());
-                        break;
-                    }
-                }
-            } else {
-                // 这个是需要进行二次匹配的
-                erCiPiPei.add(fuShu);
-            }
-        }
-        // 下面是二次匹配
-        if (erCiPiPei.size() > 0) {
-            // 二次匹配 条件为 执行科室 项目编码 数量 账页号
-            Map<String, List<ZyDetailCharge>> erCiPiPeiZhenShu = getYiZhuFeiYongZhenShu.stream().collect(
-                    Collectors.groupingBy(item -> item.getExecUnit() + item.getChargeCodeMx() + item.getChargeAmount() + item.getChargeFee() + item.getLedgerSn())
-            );
-            // 开始二次匹配
-            for (ZyDetailCharge zyDetailCharge : erCiPiPei) {
-                String key = zyDetailCharge.getExecUnit() + zyDetailCharge.getChargeCodeMx() + zyDetailCharge.getChargeAmount().negate()
-                        + zyDetailCharge.getChargeFee().negate() + zyDetailCharge.getLedgerSn();
-                if (erCiPiPeiZhenShu.containsKey(key)) {
-                    for (ZyDetailCharge detailCharge : erCiPiPeiZhenShu.get(key)) {
-                        if (detailCharge.getTuiFeiFlag() == null && detailCharge.getOriDetailSn() == null) {
-                            zyDetailCharge.setOriDetailSn(detailCharge.getDetailSn());
-                            detailCharge.setTuiFeiFlag(1);
-                            piPei.add(zyDetailCharge);
-                            log.info("第二次匹配==》流水:{},匹配流水:{}", zyDetailCharge.getDetailSn(), zyDetailCharge.getOriDetailSn());
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-        // 开始匹配
-        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);
-            }
-            publicServer.genXingYuanLiuShuiBiaoZhi(inpatientNo, admissTimes, ledgerSn);
-            log.info("医嘱退费匹配 ==》 操作人:{},住院号:{},住院次数:{}", TokenUtil.getTokenUserId(), inpatientNo, admissTimes);
-            return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION,
-                    String.format("匹配成功共:{%d}条,匹配成功:{%s}条", getYiZhuFeiYongFuShu.size(), piPei.size()));
-        }
+//        // 获取正的医嘱费用
+//        List<ZyDetailCharge> getYiZhuFeiYongZhenShu = dao.getYiZhuFeiYong(inpatientNo, admissTimes, ledgerSn, ">", infantFlag);
+//        // 获取负的医嘱费用
+//        List<ZyDetailCharge> getYiZhuFeiYongFuShu = dao.getYiZhuFeiYong(inpatientNo, admissTimes, ledgerSn, "<", 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.getChargeFee() + item.getLedgerSn())
+//        );
+//        // 用负数拼接的 key 去查找
+//        for (ZyDetailCharge fuShu : getYiZhuFeiYongFuShu) {
+//            String key = fuShu.getOrderNo() + DateUtil.formatDatetime(fuShu.getChargeDate()) + fuShu.getChargeCodeMx() + fuShu.getChargeAmount().negate()
+//                    + fuShu.getChargeFee().negate() + fuShu.getLedgerSn();
+//            if (zhenShuMap.containsKey(key)) {
+//                for (ZyDetailCharge zyDetailCharge : zhenShuMap.get(key)) {
+//                    if (zyDetailCharge.getTuiFeiFlag() == null && zyDetailCharge.getOriDetailSn() == null) {
+//                        fuShu.setOriDetailSn(zyDetailCharge.getDetailSn());
+//                        zyDetailCharge.setTuiFeiFlag(1);
+//                        piPei.add(fuShu);
+//                        log.info("第一次匹配==》流水:{},匹配流水:{},", fuShu.getDetailSn(), fuShu.getOriDetailSn());
+//                        break;
+//                    }
+//                }
+//            } else {
+//                // 这个是需要进行二次匹配的
+//                erCiPiPei.add(fuShu);
+//            }
+//        }
+//        // 下面是二次匹配
+//        if (erCiPiPei.size() > 0) {
+//            // 二次匹配 条件为 执行科室 项目编码 数量 账页号
+//            Map<String, List<ZyDetailCharge>> erCiPiPeiZhenShu = getYiZhuFeiYongZhenShu.stream().collect(
+//                    Collectors.groupingBy(item -> item.getExecUnit() + item.getChargeCodeMx() + item.getChargeAmount() + item.getChargeFee() + item.getLedgerSn())
+//            );
+//            // 开始二次匹配
+//            for (ZyDetailCharge zyDetailCharge : erCiPiPei) {
+//                String key = zyDetailCharge.getExecUnit() + zyDetailCharge.getChargeCodeMx() + zyDetailCharge.getChargeAmount().negate()
+//                        + zyDetailCharge.getChargeFee().negate() + zyDetailCharge.getLedgerSn();
+//                if (erCiPiPeiZhenShu.containsKey(key)) {
+//                    for (ZyDetailCharge detailCharge : erCiPiPeiZhenShu.get(key)) {
+//                        if (detailCharge.getTuiFeiFlag() == null && detailCharge.getOriDetailSn() == null) {
+//                            zyDetailCharge.setOriDetailSn(detailCharge.getDetailSn());
+//                            detailCharge.setTuiFeiFlag(1);
+//                            piPei.add(zyDetailCharge);
+//                            log.info("第二次匹配==》流水:{},匹配流水:{}", zyDetailCharge.getDetailSn(), zyDetailCharge.getOriDetailSn());
+//                            break;
+//                        }
+//                    }
+//                }
+//            }
+//        }
+//        // 开始匹配
+//        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);
+//            }
+//            publicServer.genXingYuanLiuShuiBiaoZhi(inpatientNo, admissTimes, ledgerSn);
+//            log.info("医嘱退费匹配 ==》 操作人:{},住院号:{},住院次数:{}", TokenUtil.getTokenUserId(), inpatientNo, admissTimes);
+//            return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION,
+//                    String.format("匹配成功共:{%d}条,匹配成功:{%s}条", getYiZhuFeiYongFuShu.size(), piPei.size()));
+//        }
         publicServer.genXingYuanLiuShuiBiaoZhi(inpatientNo, admissTimes, ledgerSn);
-        return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, String.format("该患者有【%d】条,未能匹配 |д・)っ", getYiZhuFeiYongFuShu.size()));
+        return ResultVoUtil.success();
+        //return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, String.format("该患者有【%d】条,未能匹配 |д・)っ", getYiZhuFeiYongFuShu.size()));
     }
 
     /**
@@ -541,10 +562,12 @@ public class XiangMuLuRuService {
         return ResultVoUtil.success(dao.getBingQuDuiYingKeShi(ward));
     }
 
+    @Transactional(rollbackFor = Exception.class)
     public ResultVo<String> cheXiaoTuiFei(String inpatientNo, Integer admissTimes, Integer ledger, Integer detailSn) {
         if (StringUtil.isBlank(inpatientNo) || admissTimes == null || ledger == null || detailSn == null) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者信息不全。");
         }
+        inpatientNo = publicServer.getInpatientNo(inpatientNo);
         ZyDetailCharge zyDetailCharge = dao.beiTuiFeiYongXinXi(inpatientNo, admissTimes, ledger, detailSn);
         if (zyDetailCharge == null) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未查询到对应信息,可能该费用可能已经被撤销了或被正负相抵了。");
@@ -561,24 +584,79 @@ public class XiangMuLuRuService {
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "撤销成功,请刷新数据。");
     }
 
-
-    public ResultVo<WeiGuiFeiYongFenXi> weiGuiFeiYongFenXi(String inpatientNo, Integer admissTimes) {
+    @Transactional(rollbackFor = Exception.class)
+    public ResultVo<WeiGuiFeiYongFenXi> weiGuiFeiYongFenXi(String inpatientNo, Integer admissTimes, String execUnit) {
         inpatientNo = publicServer.getInpatientNo(inpatientNo);
         int infantFlag = publicServer.getInfantFlag(inpatientNo);
         Integer ledger = publicServer.getLedgerSn(inpatientNo, admissTimes);
 
-        List<Integer> chongFuTuiFei = dao.chongFuTuiFei(inpatientNo, admissTimes, ledger, infantFlag);
-
-        if (ListUtil.notBlank(chongFuTuiFei)) {
-            dao.chongZhiWeiGuiYuanLiuShui(inpatientNo, admissTimes, ledger, infantFlag, chongFuTuiFei);
-        }
         WeiGuiFeiYongFenXi weiGuiFeiYongFenXi = new WeiGuiFeiYongFenXi();
         weiGuiFeiYongFenXi.setWeiPiPei(new ArrayList<>());
         weiGuiFeiYongFenXi.setWeiXieDaiYuanLiuShui(new ArrayList<>());
+
+        List<Integer> yaoPingBianMaTongBu = dao.weiGuiYaoPinInt(inpatientNo, admissTimes, ledger, infantFlag);
+
+        if (yaoPingBianMaTongBu.size() > 0) {
+            dao.genXinYaoPingPiPeiXinXi(yaoPingBianMaTongBu);
+        }
         weiGuiFeiYongFenXi.getWeiPiPei().addAll(dao.weiGuiYaoPin(inpatientNo, admissTimes, ledger, infantFlag));
         weiGuiFeiYongFenXi.getWeiPiPei().addAll(dao.weiGuiXiangMu(inpatientNo, admissTimes, ledger, infantFlag));
-        weiGuiFeiYongFenXi.getWeiXieDaiYuanLiuShui().addAll(dao.weiXieDaiYuanLiuShui(inpatientNo, admissTimes, ledger, infantFlag));
+        weiGuiFeiYongFenXi.getWeiXieDaiYuanLiuShui().addAll(dao.weiXieDaiYuanLiuShuiXiangMu(inpatientNo, admissTimes, ledger, infantFlag, execUnit));
+        weiGuiFeiYongFenXi.getWeiXieDaiYuanLiuShui().addAll(dao.weiXieDaiYuanLiuShuiYaoPing(inpatientNo, admissTimes, ledger, infantFlag, execUnit));
         return ResultVoUtil.success(weiGuiFeiYongFenXi);
     }
+
+
+    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));
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public ResultVo<String> caiFenPiPei(ZyDetailCharge zyDetailCharge) {
+        String inpatientNo = publicServer.getInpatientNo(zyDetailCharge.getInpatientNo());
+        Integer infantFlag = publicServer.getInfantFlag(zyDetailCharge.getInpatientNo());
+        if (ListUtil.isBlank(zyDetailCharge.getList())) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请选择数据。");
+        }
+        int[] detailSnList = new int[zyDetailCharge.getList().size()];
+        for (int i = 0; i < zyDetailCharge.getList().size(); i++) {
+            detailSnList[i] = zyDetailCharge.getList().get(i).getDetailSn();
+        }
+        ZyDetailCharge zy = dao.piPeiXinXiFuShu(inpatientNo, zyDetailCharge.getAdmissTimes(), zyDetailCharge.getLedgerSn(), infantFlag, zyDetailCharge.getDetailSn());
+        if (zy == null) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未找到负数费用信息,可能已经被删除了,请刷新页面重试。");
+        } 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);
+        BigDecimal chargeFeeSum = new BigDecimal(0);
+        BigDecimal chargeAmountSum = new BigDecimal(0);
+        for (ZyDetailCharge detailCharge : shuJuXinXi) {
+            ResultVo<String> LOGICAL_ERROR = getStringResultVo(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()));
+            }
+            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());
+                publicServer.genXingYuanLiuShuiBiaoZhi(inpatientNo, zyDetailCharge.getAdmissTimes(), zyDetailCharge.getLedgerSn());
+            } else {
+                ResultVo<String> tuiFei = xiangMuTuiFei(zyDetailCharge);
+                if (tuiFei.getCode() != 201) {
+                    return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, tuiFei.getMessage());
+                }
+                dao.cheXiaoFeiYong(inpatientNo, zyDetailCharge.getAdmissTimes(), zyDetailCharge.getLedgerSn(), zyDetailCharge.getDetailSn());
+            }
+        } else {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR,
+                    String.format("负数费用:{%.2f},匹配费用:{%.2f} <br> 负数数量:{%.2f},匹配数量:{%.2f}", zy.getChargeFee().negate(), chargeFeeSum, zy.getChargeAmount().negate(), chargeAmountSum));
+        }
+        return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "费用拆分成功。");
+    }
 }