Bladeren bron

优化项目录入的查询

DESKTOP-0GD05B0\Administrator 2 jaren geleden
bovenliggende
commit
20fd76fdb4

+ 22 - 260
src/main/java/thyyxxk/webserver/dao/his/inpatient/XiangMuLuRuDao.java

@@ -28,7 +28,6 @@ import java.util.Map;
 @Mapper
 public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
 
-
     @Select("<script>" +
             "select a.admiss_times, a.inpatient_no, a.order_no, a.gen_time, a.ledger_sn, a.detail_sn,  " +
             "                   a.trans_flag_yb,    " +
@@ -40,104 +39,28 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
             "       self_flag=isnull(a.self_flag,0), suppress_flag=a.suppress_flag, group_no='00',  " +
             "       separate_flag=a.separate_flag, ope_flag=a.ope_flag, drugname=c.name, isnull(a.ori_detail_sn,0) ori_detail_sn  " +
             "    FROM  (select top ${pageSize} * from (select ROW_NUMBER() OVER (order by charge_date ${riQiPaiXu} ) as RowNumber,* from zy_detail_charge a " +
-            "where  a.charge_code  " +
-            "like 'BILL%' and a.ledger_sn = #{ledgerSn}  and trans_flag_yb &lt;&gt; 2 and a.order_no &lt;&gt; 6 and inpatient_no = #{inpatientNo}  " +
-            "and admiss_times = #{admissTimes} and a.infant_flag = #{infantFlag} " +
-            "<if test=\"chargeCode != null and chargeCode != '' \">" +
-            "and charge_code_mx = #{chargeCode} " +
-            "</if>" +
-            "<if test=\"startTime != null and startTime!= '' \">" +
-            "and charge_date &gt;= #{startTime} and charge_date &lt;= #{endTime} " +
-            "</if>" +
-            "<if test=\"dept != null and dept != '' \"> " +
-            "and exec_unit=#{dept}   " +
-            "</if>" +
-            "<if test=\"orderNo != 2 and orderNo != 1 \">" +
-            "and order_no = #{orderNo} " +
-            "</if>" +
-            "<if test=\"orderNo !=2 and orderNo == 1\">" +
-            "and len(order_no) &gt;2 " +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 0  \">" +
-            "and ori_detail_sn is null and charge_fee > 0" +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 1  \">" +
-            "and (ori_detail_sn &gt; 0 or charge_fee &lt; 0) " +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 2  \">" +
-            "and (ori_detail_sn = -1 )" +
-            "</if>" +
-            "<if test=\"actOrderNo != null\">" +
-            " and order_no = #{actOrderNo} " +
-            "</if>" +
+            "  ${ew.customSqlSegment} " +
             ") temp where RowNumber > ${pageSize} * (${currentPage} - 1 )) a  " +
             "        left join zd_charge_item b on (a.charge_code = b.code)  " +
             "        left join  yp_zd_dict c on (a.serial = c.serial and c.code= a.charge_code_mx)  " +
             "        left join a_employee_mi d on (d.code = a.op_id_code)  " +
             "</script>")
-    List<ZyDetailCharge> huanZheYaoPinFeiYong(@Param("currentPage") long currentPage,
-                                              @Param("pageSize") long pageSize,
-                                              @Param("inpatientNo") String inpatientNo,
-                                              @Param("admissTimes") Integer admissTimes,
-                                              @Param("ledgerSn") Integer ledgerSn,
-                                              @Param("chargeCode") String chargeCode,
-                                              @Param("infantFlag") int infantFlag,
-                                              @Param("startTime") String startTime,
-                                              @Param("endTime") String endTime,
-                                              @Param("orderNo") BigDecimal orderNo,
-                                              @Param("actOrderNo") BigDecimal actOrderNo,
-                                              @Param("dept") String dept,
-                                              @Param("riQiPaiXu") String riQiPaiXu,
-                                              @Param("tuiFeiFlag") Integer tuiFeiFlag);
+    List<ZyDetailCharge> huanZheYaoPinFeiYongV2(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper,
+                                                @Param("currentPage") long currentPage,
+                                                @Param("pageSize") long pageSize,
+                                                @Param("riQiPaiXu") String riQiPaiXu);
 
-    @Select("<script>" +
-            "select count(*) total,sum(charge_fee) charge_fee" +
+    @Select("select count(*) total,sum(charge_fee) charge_fee" +
             "    FROM zy_detail_charge a  " +
-            "where   a.charge_code  " +
-            "like 'BILL%' and a.ledger_sn = #{ledgerSn}  and trans_flag_yb &lt;&gt; 2 and a.order_no &lt;&gt; 6 and inpatient_no = #{inpatientNo}  " +
-            "and admiss_times = #{admissTimes} and a.infant_flag = #{infantFlag} " +
-            "<if test=\"chargeCode != null and chargeCode != '' \">" +
-            "and charge_code_mx = #{chargeCode} " +
-            "</if>" +
-            "<if test=\"startTime != null and startTime!= '' \">" +
-            "and charge_date &gt;= #{startTime} and charge_date &lt;= #{endTime} " +
-            "</if>" +
-            "<if test=\"dept != null and dept != '' \"> " +
-            "and exec_unit=#{dept}   " +
-            "</if>" +
-            "<if test=\"orderNo != 2 and orderNo != 1 \">" +
-            "and order_no = #{orderNo} " +
-            "</if>" +
-            "<if test=\"orderNo !=2 and orderNo == 1\">" +
-            "and len(order_no) &gt;2 " +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 0  \">" +
-            "and ori_detail_sn is null and charge_fee > 0" +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 1  \">" +
-            "and (ori_detail_sn &gt; 0 or charge_fee &lt; 0) " +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 2  \">" +
-            "and (ori_detail_sn = -1 )" +
-            "</if>" +
-            "<if test=\"actOrderNo != null\">" +
-            " and order_no = #{actOrderNo} " +
-            "</if>" +
-            "</script>")
-    long huanZheYaoPinFeiYongTotal(@Param("inpatientNo") String inpatientNo,
-                                   @Param("admissTimes") Integer admissTimes,
-                                   @Param("ledgerSn") Integer ledgerSn,
-                                   @Param("chargeCode") String chargeCode,
-                                   @Param("infantFlag") int infantFlag,
-                                   @Param("startTime") String startTime,
-                                   @Param("endTime") String endTime,
-                                   @Param("orderNo") BigDecimal orderNo,
-                                   @Param("actOrderNo") BigDecimal actOrderNo,
-                                   @Param("dept") String dept,
-                                   @Param("tuiFeiFlag") Integer tuiFeiFlag);
+            " ${ew.customSqlSegment} ")
+    long huanZheYaoPinFeiYongTotalV2(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);
 
-    @Select("<script>" +
-            "            SELECT " +
+    @Select(" select count(*) total,sum(charge_fee) charge_fee" +
+            " from zy_detail_charge ${ew.customSqlSegment} ")
+    long huanZheFeiYongToatalV2(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);
+
+
+    @Select("            SELECT " +
             "                   a.admiss_times, " +
             "                   a.inpatient_no, " +
             "                   a.order_no,    " +
@@ -169,98 +92,16 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
             "                   specification,    " +
             "                   drugname=b.name,    " +
             "                   isnull(a.ori_detail_sn,0) ori_detail_sn    " +
-            "                   FROM  (select top ${pageSize} * from (select ROW_NUMBER() OVER (order by charge_date ${riQiPaiXu} ) as RowNumber,*  from zy_detail_charge where inpatient_no= #{inpatientNo} and " +
-            "admiss_times= #{admissTimes}  and ledger_sn = #{ledgerSn} and infant_flag = #{infantFlag} and  " +
-            "  isnull(trans_flag_yb,0) &lt;&gt; 2 AND charge_code not like 'BILL%' and  order_no &lt;&gt; 6" +
-            "<if test=\"chargeCode != null and chargeCode != '' \">" +
-            "and charge_code_mx = #{chargeCode} " +
-            "</if>" +
-            "<if test=\"startTime != null and startTime!= '' \">" +
-            "and charge_date &gt;= #{startTime} and charge_date &lt;= #{endTime} " +
-            "</if>" +
-            "<if test=\"dept != null and dept != '' \"> " +
-            "and exec_unit = #{dept}   " +
-            "</if>" +
-            "<if test=\"orderNo != 2 and orderNo != 1 \">" +
-            "and order_no = #{orderNo} " +
-            "</if>" +
-            "<if test=\"orderNo !=2 and orderNo == 1\">" +
-            "and len(order_no) &gt;2 " +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 0  \">" +
-            "and ori_detail_sn is null and charge_fee > 0" +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 1  \">" +
-            "and (ori_detail_sn &gt; 0 or charge_fee &lt; 0) " +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 2  \">" +
-            "and (ori_detail_sn = -1 )" +
-            "</if>" +
-            "<if test=\"actOrderNo != null\">" +
-            " and order_no = #{actOrderNo} " +
-            "</if>" +
+            "                   FROM  (select top ${pageSize} * from (select ROW_NUMBER() OVER (order by charge_date ${riQiPaiXu} ) as RowNumber,*  " +
+            "from zy_detail_charge " +
+            "${ew.customSqlSegment}" +
             ") temp where RowNumber > ${pageSize} * (${currentPage}-1) )  a " +
             "  left join  zd_charge_item b on (a.charge_code=b.code) " +
-            "  left join a_employee_mi c on (c.code = a.op_id_code)" +
-            "</script>")
-    List<ZyDetailCharge> huanZheXiangMuFeiYong(@Param("currentPage") long currentPage,
-                                               @Param("pageSize") long pageSize,
-                                               @Param("inpatientNo") String inpatientNo,
-                                               @Param("admissTimes") Integer admissTimes,
-                                               @Param("ledgerSn") Integer ledgerSn,
-                                               @Param("chargeCode") String chargeCode,
-                                               @Param("infantFlag") int infantFlag,
-                                               @Param("startTime") String startTime,
-                                               @Param("endTime") String endTime,
-                                               @Param("orderNo") BigDecimal orderNo,
-                                               @Param("actOrderNo") BigDecimal actOrderNo,
-                                               @Param("dept") String dept,
-                                               @Param("riQiPaiXu") String riQiPaiXu,
-                                               @Param("tuiFeiFlag") Integer tuiFeiFlag);
-
-
-    @Select("<script>" +
-            " select count(*) total,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 trans_flag_yb &lt;&gt; 2 AND charge_code not like 'BILL%' and  order_no &lt;&gt; 6" +
-            "<if test=\"chargeCode != null and chargeCode != '' \">" +
-            "and charge_code_mx = #{chargeCode} " +
-            "</if>" +
-            "<if test=\"startTime != null and startTime!= '' \">" +
-            "and charge_date &gt;= #{startTime} and charge_date &lt;= #{endTime} " +
-            "</if>" +
-            "<if test=\"dept != null and dept != '' \"> " +
-            "and exec_unit = #{dept}   " +
-            "</if>" +
-            "<if test=\"orderNo != 2 and orderNo != 1 \">" +
-            "and order_no = #{orderNo} " +
-            "</if>" +
-            "<if test=\"orderNo !=2 and orderNo == 1\">" +
-            "and len(order_no) &gt;2 " +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 0  \">" +
-            "and ori_detail_sn is null and charge_fee > 0" +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 1  \">" +
-            "and (ori_detail_sn &gt; 0 or charge_fee &lt; 0) " +
-            "</if>" +
-            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 2  \">" +
-            "and (ori_detail_sn = -1 )" +
-            "</if>" +
-            "<if test=\"actOrderNo != null\">" +
-            " and order_no = #{actOrderNo} " +
-            "</if>" +
-            "</script>")
-    long huanZheFeiYongToatal(@Param("inpatientNo") String inpatientNo,
-                              @Param("admissTimes") Integer admissTimes,
-                              @Param("ledgerSn") Integer ledgerSn,
-                              @Param("chargeCode") String chargeCode,
-                              @Param("infantFlag") int infantFlag,
-                              @Param("startTime") String startTime,
-                              @Param("endTime") String endTime,
-                              @Param("orderNo") BigDecimal orderNo,
-                              @Param("actOrderNo") BigDecimal actOrderNo,
-                              @Param("dept") String dept,
-                              @Param("tuiFeiFlag") Integer tuiFeiFlag);
+            "  left join a_employee_mi c on (c.code = a.op_id_code)")
+    List<ZyDetailCharge> huanZheXiangMuFeiYongV2(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper,
+                                                 @Param("currentPage") long currentPage,
+                                                 @Param("pageSize") long pageSize,
+                                                 @Param("riQiPaiXu") String riQiPaiXu);
 
 
     @Select("select detail_sn,ori_detail_sn from zy_detail_charge where inpatient_no=#{inpatientNo} and admiss_times = #{admissTimes} " +
@@ -341,63 +182,6 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
                                           @Param("ledgerSn") Integer ledgerSn,
                                           @Param("list") List<ZyDetailCharge> list);
 
-    /**
-     * 查询出 有哪些数据已经退过了 费用
-     *
-     * @param inpatientNo 住院号
-     * @param admissTimes 住院次数
-     * @param list        流水号
-     * @return 返回 已经退过费用的数据
-     */
-    @Select("<script>" +
-            "select " +
-            "inpatient_no, " +
-            "       admiss_times, " +
-            "       ledger_sn, " +
-            "       detail_sn, " +
-            "       charge_date, " +
-            "       op_id_code, " +
-            "       charge_code, " +
-            "       bill_item_code = (select  bill_item_zy from zd_charge_item where code = charge_code), " +
-            "       infant_flag, " +
-            "       charge_status, " +
-            "       retprice, " +
-            "       charge_amount, " +
-            "       charge_fee, " +
-            "       self_flag, " +
-            "       separate_flag, " +
-            "       suppress_flag, " +
-            "       ward_code, " +
-            "       dept_code, " +
-            "       order_no, " +
-            "       ope_flag, " +
-            "       exec_unit, " +
-            "       gen_time, " +
-            "       pay_percent, " +
-            "       zj_flag, " +
-            "       zfl, " +
-            "       charge_code_mx, " +
-            "       serial, " +
-            "       zy_serial_no, " +
-            "       doctor_code, " +
-            "       yb_self_flag, " +
-            "       orig_charge_fee, " +
-            "       confirm_id, " +
-            "       trans_flag_yb, " +
-            "       ss_code, " +
-            "       gs_flag, " +
-            "       refer_physician, " +
-            "       consult_physician, " +
-            "       ori_detail_sn" +
-            " from zy_detail_charge where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn}  and detail_sn in " +
-            "<foreach collection='list' item='item' index='index' open='(' close=')' separator=','>" +
-            "#{item.detailSn}" +
-            "</foreach>" +
-            "</script>")
-    List<ZyDetailCharge> chaKanSFYiJingTuiFeiLe(@Param("inpatientNo") String inpatientNo,
-                                                @Param("admissTimes") Integer admissTimes,
-                                                @Param("ledgerSn") Integer ledgerSn,
-                                                @Param("list") List<ZyDetailCharge> list);
 
     /**
      * 插入数据
@@ -653,20 +437,6 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
                       @Param("infantFlag") int infantFlag,
                       @Param("ledgerSn") Integer ledgerSn);
 
-    @Select("<script>" +
-            "select code                                                                              as charge_code_mx, " +
-            "       CASE infusion_flag " +
-            "           when '1' then 'i' " +
-            "           else (case when code &gt;= '30000' and code &lt; '50000' then 'd' else 'j' end) end as drug_class " +
-            "from yp_zd_dict " +
-            "where rtrim(code) + rtrim(serial) in " +
-            "<foreach collection='list' item='item' index='index' open='(' close=')' separator=','>" +
-            " '${item.chargeCodeMx}${item.serial}' " +
-            "</foreach>" +
-            "</script>")
-    List<ZyDetailCharge> getDrugClass(List<ZyDetailCharge> yaoPingCode);
-
-
     @Select("select b.class as class_code," +
             "       a.drug_flag as drug_class " +
             "from yz_act_order a, " +
@@ -829,14 +599,6 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
     Integer getHuanZheSFJieSuan(@Param("inpatientNo") String inpatientNo,
                                 @Param("admissTimes") Integer admissTimes);
 
-
-    @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 ")
-    ZyDetailCharge beiTuiFeiYongXinXi(@Param("inpatientNo") String inpatientNo,
-                                      @Param("admissTimes") Integer admissTimes,
-                                      @Param("ledger") Integer ledger,
-                                      @Param("detailSn") Integer detailSn);
-
     @Select("<script>" +
             "select code from yp_zd_dict where code in " +
             "<foreach collection='list' item='item' index='index' open='(' close=')' separator=','>" +

+ 65 - 16
src/main/java/thyyxxk/webserver/service/inpatient/XiangMuLuRuService.java

@@ -77,27 +77,34 @@ public class XiangMuLuRuService {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_HTML_ERROR, "住院号或住院次数为空 <br/>๑乛◡乛๑");
         }
         Integer ledgerSn = publicServer.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes());
-        int infantFlag = 0;
+        param.setLedgerSn(ledgerSn);
+        param.setInfantFlag("0");
         // 如果是婴儿的话那么就需要截取 字符串了 在通过婴儿标识来判断
         if (param.getInpatientNo().contains("$")) {
             param.setInpatientNo(param.getInpatientNo().split("\\$")[0]);
-            infantFlag = 1;
+            param.setInfantFlag("1");
         }
         if (param.getTuiFeiFlag() == null) {
             param.setTuiFeiFlag(2);
         }
         Page<ZyDetailCharge> page = new Page<>();
+        QueryWrapper<?> qw = setQueryWrapperItem(param);
 
         if (param.getFeiYongLeiXingCode() == 0) {
+            // 查询项目
+            qw.eq("serial", "00");
             if (param.getTotal() == 0) {
-                page.setTotal(dao.huanZheFeiYongToatal(param.getInpatientNo(), param.getAdmissTimes(), ledgerSn, param.getChargeCode(), infantFlag, param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getActOrderNo(), param.getDept(), param.getTuiFeiFlag()));
+                page.setTotal(dao.huanZheFeiYongToatalV2(qw));
             }
-            page.setRecords(dao.huanZheXiangMuFeiYong(param.getCurrentPage(), param.getPageSize(), param.getInpatientNo(), param.getAdmissTimes(), ledgerSn, param.getChargeCode(), infantFlag, param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getActOrderNo(), param.getDept(), param.getRiQiPaiXu(), param.getTuiFeiFlag()));
+            page.setRecords(dao.huanZheXiangMuFeiYongV2(qw, param.getCurrentPage(), param.getPageSize(), param.getRiQiPaiXu()));
         } else {
+
+            // 查询药品
+            qw.ne("serial", "00");
             if (param.getTotal() == 0) {
-                page.setTotal(dao.huanZheYaoPinFeiYongTotal(param.getInpatientNo(), param.getAdmissTimes(), ledgerSn, param.getChargeCode(), infantFlag, param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getActOrderNo(), param.getDept(), param.getTuiFeiFlag()));
+                page.setTotal(dao.huanZheYaoPinFeiYongTotalV2(qw));
             }
-            page.setRecords(dao.huanZheYaoPinFeiYong(param.getCurrentPage(), param.getPageSize(), param.getInpatientNo(), param.getAdmissTimes(), ledgerSn, param.getChargeCode(), infantFlag, param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getActOrderNo(), param.getDept(), param.getRiQiPaiXu(), param.getTuiFeiFlag()));
+            page.setRecords(dao.huanZheYaoPinFeiYongV2(qw, param.getCurrentPage(), param.getPageSize(), param.getRiQiPaiXu()));
         }
         if (ListUtil.isBlank(page.getRecords())) {
             return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到符合费用。");
@@ -105,6 +112,54 @@ public class XiangMuLuRuService {
         return ResultVoUtil.success(page);
     }
 
+    private QueryWrapper<?> setQueryWrapperItem(ZyDetailCharge v) {
+        QueryWrapper<?> qw = new QueryWrapper<>();
+        qw.eq("inpatient_no", v.getInpatientNo())
+                .eq("admiss_times", v.getAdmissTimes())
+                .eq("ledger_sn", v.getLedgerSn())
+                .eq("infant_flag", v.getInfantFlag())
+                .ne("isnull(trans_flag_yb, 0)", 2)
+                .ne("order_no", new BigDecimal(6));
+        if (StringUtil.notBlank(v.getChargeCode())) {
+            qw.eq("charge_code_mx", v.getChargeCode());
+        }
+        if (StringUtil.notBlank(v.getStartTime())) {
+            qw.ge("charge_date", v.getStartTime())
+                    .le("charge_date", v.getEndTime());
+        }
+        // 因为这里是护士也要看的所以护士可以看患者所以科室的费用
+        if (StringUtil.notBlank(v.getDept())) {
+            Set<String> deptList = publicServer.getChildDeptByUserCode();
+            qw.in("exec_unit", deptList);
+        }
+        int order = Integer.parseInt(v.getOrderNo().stripTrailingZeros().toPlainString());
+        if (order != 2 && order != 1) {
+            qw.eq("order_no", order);
+        }
+        if (order == 1) {
+            qw.gt("len(order_no)", new BigDecimal(2));
+        }
+        if (v.getTuiFeiFlag() == 0) {
+            qw.isNull("ori_detail_sn")
+                    .ge("charge_fee", 0);
+        }
+        if (v.getTuiFeiFlag() == 1) {
+            qw.and(q -> {
+                q.gt("ori_detail_sn", 0)
+                        .or()
+                        .lt("charge_fee", 0);
+            });
+        }
+        if (v.getTuiFeiFlag() == 2) {
+            qw.eq("ori_detail_sn", -1);
+        }
+        if (v.getActOrderNo() != null) {
+            qw.eq("order_no", v.getActOrderNo());
+        }
+        return qw;
+    }
+
+
     /**
      * 搜索项目信息
      *
@@ -153,12 +208,8 @@ public class XiangMuLuRuService {
         Integer ledgerSn = publicServer.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes());
         // 获取原来的数据
         List<ZyDetailCharge> yuanTuiFeiList = dao.huoQuJuTiFeiYong(param.getInpatientNo(), param.getAdmissTimes(), ledgerSn, param.getList());
-        // 获取当前用户 下面的科室
-        List<String> zhiXinKeShi = dao.chaXunZhiZXinKeShi(param.getDeptCode());
-        // 放入 自己的科室
-        if (!zhiXinKeShi.contains(userInfo.getDeptCode())) {
-            zhiXinKeShi.add(userInfo.getDeptCode());
-        }
+        // 获取患者自己的科室和下面的子科室
+        Set<String> deptList = publicServer.getChildDeptByUserCode();
 
         List<ZyDetailCharge> project = new ArrayList<>();
         List<ZyDetailCharge> drug = new ArrayList<>();
@@ -185,8 +236,7 @@ public class XiangMuLuRuService {
             if (BigUtils.bigXiaoYu(item.getChargeFee(), 0) || BigUtils.bigXiaoYu(item.getChargeAmount(), 0)) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,该数据为负数。", item.getDetailSn()));
             }
-
-            if ("00".equals(item.getSerial()) && !zhiXinKeShi.contains(item.getExecUnit())) {
+            if ("00".equals(item.getSerial()) && !deptList.contains(item.getExecUnit())) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,请对应的执行科室进行退费。", item.getDetailSn()));
             }
 
@@ -202,7 +252,7 @@ public class XiangMuLuRuService {
                 maxDetailSn = setRefund(project, tuiFeiList, updateRefundFlag, maxDetailSn, item);
             } else {
                 if ("3".equals(item.getOrderNo().stripTrailingZeros().toPlainString())) {
-                    if (!zhiXinKeShi.contains(item.getExecUnit())) {
+                    if (!deptList.contains(item.getExecUnit())) {
                         return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("流水号:【%s】,此药品为医技科室录入,请对应的医技科室退费。", item.getDetailSn()));
                     } else {
                         maxDetailSn = setRefund(project, tuiFeiList, updateRefundFlag, maxDetailSn, item);
@@ -221,7 +271,6 @@ public class XiangMuLuRuService {
                 }
             }
         }
-
         // 护士退药单
         if (ListUtil.notBlank(drug)) {
             for (ZyDetailCharge item : drug) {