Browse Source

优化查询患者费用信息,以及添加可以查询已退费和未退费的了。

xiaochan 3 years ago
parent
commit
6e4b19fb9d

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>web-server</artifactId>
-    <version>10.2.0</version>
+    <version>10.2.1</version>
     <name>web-server</name>
     <description>server for yibao-web</description>
     <properties>

+ 41 - 8
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.yibao.ZyActpatient;
 
 import java.util.List;
 
@@ -87,12 +88,44 @@ public interface PublicDao {
     @Select("select rtrim(code) code,rtrim(name) name from zd_unit_code where isnull(del_flag,0) = 0")
     List<GetDropdownBox> getDept();
 
-    // yp_zd_dict zd_charge_item
-    @Select("<script>" +
-            "select rtrim(code) code,rtrim(name) name from yp_zd_dict where code in" +
-            "<foreach collection='list' item='item' index='index' open='(' close=')' separator=','>" +
-            "#{item}" +
-            "</foreach>" +
-            "</script>")
-    List<GetDropdownBox> getYaoPinXingMing(@Param("list") List<String> list);
+
+    @Select("select isnull(max(ledger_sn),1)  from zy_ledger_file where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes}")
+    Integer getLedgerSn(@Param("inpatientNo") String inpatient,
+                        @Param("admissTimes") Integer admissTimes);
+
+
+    @Select("select rtrim(inpatient_no) inpatient_no,admiss_times,admiss_date,dis_date, " +
+            "responce_name = (select rtrim(name) name from zy_zd_responce_type where code = responce_type), " +
+            "ward,ward_name = (select rtrim(name) name from zd_unit_code where code = ward), " +
+            "ledger_sn = (select ledger_sn from zy_ledger_file where a.inpatient_no = zy_ledger_file.inpatient_no and a.admiss_times = zy_ledger_file.admiss_times), " +
+            "chu_yuan_yi_zhu = (case when (select count(1) from yz_act_order where inpatient_no= a.inpatient_no and admiss_times= a.admiss_times " +
+            "and status_flag > '2' and isnull(group_no,'00' )='00' and order_code in ('06026','06053','05973')) > 0 " +
+            "then 1 " +
+            "when (select count(1) from yz_inact_order where inpatient_no= a.inpatient_no and admiss_times= a.admiss_times " +
+            "and status_flag > '2' and isnull(group_no,'00' )='00' and order_code in ('06026','06053','05973')) > 0 " +
+            "then 1 else 0 end  ), " +
+            "bed_no,total_charge,balance from zy_patient a where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes}")
+    ZyActpatient getHuanZheJiBenXinXi(@Param("inpatientNo") String inpatientNo,
+                                      @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 is not " +
+            "null and ori_detail_sn <> -1 and charge_fee < 0 and charge_amount < 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 = -1")
+    Integer beiPiPeiZhenShu(@Param("inpatientNo") String inpatientNo,
+                            @Param("admissTimes") Integer admissTimes,
+                            @Param("ledgerSn") Integer ledgerSn);
+
+    @Update("update zy_detail_charge  set ori_detail_sn = -1 where inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and ledger_sn = #{ledgerSn} 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 ori_detail_sn is not null and ori_detail_sn <> -1 and charge_fee < 0 and charge_amount < 0   " +
+            "    ) and charge_amount > 0 and charge_fee > 0")
+    void genXinYuanTuiFeiLiuShui(@Param("inpatientNo") String inpatientNo,
+                                 @Param("admissTimes") Integer admissTimes,
+                                 @Param("ledgerSn") Integer ledgerSn);
+
+
 }

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

@@ -1,7 +1,6 @@
 package thyyxxk.webserver.dao.his.yibao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.ibatis.annotations.*;
 import thyyxxk.webserver.entity.datamodify.FeiYongLeiXin;
 import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
@@ -23,163 +22,204 @@ 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.charge_date,  " +
-            "            a.op_id_code,  " +
-            "            d.name op_name,  " +
-            "            a.charge_code,  " +
-            "            a.charge_fee,  " +
-            "            a.charge_status  ,  " +
-            "            bill_item_code= b.bill_item_zy,  " +
-            "            bill_item_name=(select name from zy_bill_item where code = b.bill_item_zy),  " +
-            "            charge_name=b.name,  " +
-            "            spec=b.charge_unit,  " +
-            "            a.charge_code_mx,  " +
-            "            a.serial,  " +
-            "            price=0.0000,  " +
-            "            charge_amount=a.charge_amount,  " +
-            "            exec_dept=(select name from zd_unit_code where code = a.exec_unit),  " +
-            "            dept_code = (select name from zd_unit_code where code = a.ward_code) ,  " +
-            "            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,  " +
-            "            a.ori_detail_sn  " +
-            "FROM zy_detail_charge a  ,zd_charge_item b,yp_zd_dict c , a_employee_mi d  " +
-            "where a.charge_code=b.code and  a.serial=c.serial and a.charge_code like 'BILL%' and  c.code= a.charge_code_mx  and a.ledger_sn &gt; 0  " +
-            "and d.code = a.op_id_code and trans_flag_yb !=2 and a.order_no != 6 and inpatient_no = #{inpatientNo} and admiss_times = #{admissTimes} and a.infant_flag = #{infantFlag} " +
+            "select a.admiss_times, a.inpatient_no, a.order_no, a.gen_time, a.ledger_sn, a.detail_sn,  " +
+            "       a.charge_date, a.op_id_code, d.name op_name, a.charge_code, a.charge_fee, a.charge_status ,  " +
+            "       bill_item_code= b.bill_item_zy, bill_item_name=(select name from zy_bill_item where code = b.bill_item_zy),  " +
+            "       charge_name=b.name, spec=b.charge_unit, a.charge_code_mx, a.serial, price=0.0000, charge_amount=a.charge_amount,  " +
+            "       exec_dept=(select name from zd_unit_code where code = a.exec_unit),  " +
+            "       dept_code = (select name from zd_unit_code where code = a.ward_code) ,  " +
+            "       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 ) 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 a.charge_date &gt;= #{startTime} and a.charge_date &lt;= #{endTime} " +
+            "and charge_date &gt;= #{startTime} and charge_date &lt;= #{endTime} " +
             "</if>" +
             "<if test=\"dept != null and dept != '' \"> " +
-            "and a.exec_unit=#{dept}   " +
+            "and exec_unit=#{dept}   " +
             "</if>" +
             "<if test=\"orderNo != 2 and orderNo != 1 \">" +
-            "and a.order_no = #{orderNo} " +
+            "and order_no = #{orderNo} " +
             "</if>" +
             "<if test=\"orderNo !=2 and orderNo == 1\">" +
-            "and len(a.order_no) &gt;2 " +
+            "and len(order_no) &gt;2 " +
             "</if>" +
-            "order by a.charge_date ${riQiPaiXu}" +
+            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 0  \">" +
+            "and ori_detail_sn is null " +
+            "</if>" +
+            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 1  \">" +
+            "and (ori_detail_sn is not null or charge_fee &lt; 0 ) " +
+            "</if>" +
+            ") temp where RowNumber > ${pageSize} * (${currentPage} - 1 ) order by charge_date ${riQiPaiXu} ) 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>")
-    Page<ZyDetailCharge> huanZheYaoPinFeiYong(Page<ZyDetailCharge> page,
+    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("dept") String dept,
-                                              @Param("riQiPaiXu") String riQiPaiXu);
+                                              @Param("riQiPaiXu") String riQiPaiXu,
+                                              @Param("tuiFeiFlag") Integer tuiFeiFlag);
 
+    @Select("<script>" +
+            "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 " +
+            "</if>" +
+            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 1  \">" +
+            "and (ori_detail_sn is not null or charge_fee &lt; 0 ) " +
+            "</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("dept") String dept,
+                                   @Param("tuiFeiFlag") Integer tuiFeiFlag);
 
     @Select("<script>" +
-            "SELECT a.admiss_times,      " +
-            "       a.inpatient_no," +
-            "       a.order_no,   " +
-            "       a.gen_time,     " +
-            "       a.ledger_sn,   " +
-            "       a.detail_sn,   " +
-            "       a.charge_date,   " +
-            "       a.op_id_code,   " +
-            "       c.name op_name,   " +
-            "       a.charge_code,   " +
-            "       a.charge_fee,   " +
-            "       a.charge_status  ,   " +
-            "       bill_item_code = b.bill_item_zy,   " +
-            "       bill_item_name=(select name from zy_bill_item where code = b.bill_item_zy),   " +
-            "       charge_name=b.name,   " +
-            "       spec=b.charge_unit,   " +
-            "       a.charge_code_mx,   " +
-            "       a.serial,   " +
-            "       price=0.0000,   " +
-            "       charge_amount=a.charge_amount,   " +
-            "       exec_dept=(select name from zd_unit_code where code = a.exec_unit),   " +
-            "       dept_code = (select name from zd_unit_code  where code = a.ward_code) ,   " +
-            "       self_flag=a.self_flag,   " +
-            "       suppress_flag=a.suppress_flag,   " +
-            "       group_no='00',   " +
-            "       separate_flag=a.separate_flag,   " +
-            "       ope_flag=a.ope_flag,   " +
-            "       drugname=b.name,   " +
-            "       a.ori_detail_sn   " +
-            "       FROM zy_detail_charge a  ,zd_charge_item b , a_employee_mi c   " +
-            "       where    a.inpatient_no= #{inpatientNo} and   " +
-            "       a.admiss_times= #{admissTimes} and   " +
-            "       a.infant_flag = #{infantFlag} and c.code = a.op_id_code and trans_flag_yb !=2   " +
-            "       AND a.charge_code not like 'BILL%' and  a.order_no != 6 and a.ledger_sn &gt; 0  and a.charge_code=b.code " +
+            "            SELECT a.admiss_times, " +
+            "                   a.inpatient_no, " +
+            "                   a.order_no,    " +
+            "                   a.gen_time,      " +
+            "                   a.ledger_sn,    " +
+            "                   a.detail_sn,    " +
+            "                   a.charge_date,    " +
+            "                   a.op_id_code,    " +
+            "                   c.name op_name,    " +
+            "                   a.charge_code,    " +
+            "                   a.charge_fee,    " +
+            "                   a.charge_status  ,    " +
+            "                   bill_item_code = b.bill_item_zy,    " +
+            "                   bill_item_name=(select name from zy_bill_item where code = b.bill_item_zy),    " +
+            "                   charge_name=b.name,    " +
+            "                   spec=b.charge_unit,    " +
+            "                   a.charge_code_mx,    " +
+            "                   a.serial,    " +
+            "                   price=0.0000,    " +
+            "                   charge_amount=a.charge_amount,    " +
+            "                   exec_dept=(select name from zd_unit_code where code = a.exec_unit),    " +
+            "                   dept_code = (select name from zd_unit_code  where code = a.ward_code) ,    " +
+            "                   self_flag=a.self_flag,    " +
+            "                   suppress_flag=a.suppress_flag,    " +
+            "                   group_no='00',    " +
+            "                   separate_flag=a.separate_flag,    " +
+            "                   ope_flag=a.ope_flag,    " +
+            "                   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 ) as RowNumber,*  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 a.charge_date &gt;= #{startTime} and a.charge_date &lt;= #{endTime} " +
+            "and charge_date &gt;= #{startTime} and charge_date &lt;= #{endTime} " +
             "</if>" +
             "<if test=\"dept != null and dept != '' \"> " +
-            "and a.exec_unit = #{dept}   " +
+            "and exec_unit = #{dept}   " +
             "</if>" +
             "<if test=\"orderNo != 2 and orderNo != 1 \">" +
-            "and a.order_no = #{orderNo} " +
+            "and order_no = #{orderNo} " +
             "</if>" +
             "<if test=\"orderNo !=2 and orderNo == 1\">" +
-            "and len(a.order_no) &gt;2 " +
+            "and len(order_no) &gt;2 " +
+            "</if>" +
+            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 0  \">" +
+            "and ori_detail_sn is null " +
+            "</if>" +
+            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 1  \">" +
+            "and (ori_detail_sn is not null or charge_fee &lt; 0 )" +
             "</if>" +
-            "order by a.charge_date ${riQiPaiXu}" +
+            ") temp where RowNumber > ${pageSize} * (${currentPage}-1) order by charge_date ${riQiPaiXu})  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>")
-    Page<ZyDetailCharge> huanZheXiangMuFeiYong(Page<ZyDetailCharge> page,
+    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("dept") String dept,
-                                               @Param("riQiPaiXu") String riQiPaiXu);
+                                               @Param("riQiPaiXu") String riQiPaiXu,
+                                               @Param("tuiFeiFlag") Integer tuiFeiFlag);
 
 
     @Select("<script>" +
-            "SELECT count(*) " +
-            "       FROM zy_detail_charge a " +
-            "       where    a.inpatient_no= #{inpatientNo} and   " +
-            "       a.admiss_times= #{admissTimes} and   " +
-            "       a.infant_flag = #{infantFlag}  and trans_flag_yb !=2   " +
-            "       AND a.charge_code ${isLike} 'BILL%' and a.order_no != 6 and a.ledger_sn &gt;0  " +
+            " 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 a.charge_date &gt;= #{startTime} and a.charge_date &lt;= #{endTime} " +
+            "and charge_date &gt;= #{startTime} and charge_date &lt;= #{endTime} " +
             "</if>" +
             "<if test=\"dept != null and dept != '' \"> " +
-            "and a.exec_unit = #{dept}   " +
+            "and exec_unit = #{dept}   " +
             "</if>" +
             "<if test=\"orderNo != 2 and orderNo != 1 \">" +
-            "and a.order_no = #{orderNo} " +
+            "and order_no = #{orderNo} " +
             "</if>" +
             "<if test=\"orderNo !=2 and orderNo == 1\">" +
-            "and len(a.order_no) &gt;2 " +
+            "and len(order_no) &gt;2 " +
+            "</if>" +
+            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 0  \">" +
+            "and ori_detail_sn is null " +
+            "</if>" +
+            "<if test=\"tuiFeiFlag != null and tuiFeiFlag == 1  \">" +
+            "and (ori_detail_sn is not null or charge_fee &lt; 0 )" +
             "</if>" +
             "</script>")
     long huanZheFeiYongCount(@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("dept") String dept,
-                             @Param("isLike") String isLike);
+                             @Param("tuiFeiFlag") Integer tuiFeiFlag);
 
 
     @Select("select detail_sn,ori_detail_sn from zy_detail_charge where inpatient_no=#{inpatientNo} and admiss_times = #{admissTimes} " +
@@ -521,7 +561,7 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
             "  , zy_serial_no, charge_code_mx, serial,ss_code,yb_self_flag,refer_physician)  " +
             "VALUES " +
             "<foreach collection='list' item='item' separator=','>" +
-            "(#{zyDetailCharge.inpatientNo}, #{zyDetailCharge.admissTimes}, 1, #{item.detailSn}, getdate()  " +
+            "(#{zyDetailCharge.inpatientNo}, #{zyDetailCharge.admissTimes}, #{ledgerSn}, #{item.detailSn}, getdate()  " +
             "  , #{zyDetailCharge.opIdCode}, #{item.chargeCode}, #{infantFlag}, '2', cast(#{item.chargeAmount,jdbcType=DECIMAL} as decimal(14,5))  " +
             "  , '0', '0', NULL, #{zyDetailCharge.ward}, #{zyDetailCharge.dept}  " +
             "  , #{item.orderNo}, '0', #{item.deptCode}, cast(#{item.amount,jdbcType=DECIMAL} as decimal(14,5)), getdate()  " +
@@ -538,7 +578,8 @@ public interface XiangMuLuRuDao extends BaseMapper<ZyDetailCharge> {
             "</script>")
     void chaRuFeiYong(@Param("zyDetailCharge") ZyDetailCharge zyDetailCharge,
                       @Param("list") List<ZyDetailCharge> list,
-                      @Param("infantFlag") int infantFlag);
+                      @Param("infantFlag") int infantFlag,
+                      @Param("ledgerSn") Integer ledgerSn);
 
     /**
      * 需要更新患者的总费用

+ 2 - 1
src/main/java/thyyxxk/webserver/dao/his/zhuyuanyiji/QueRenYiZhuShouFeiDao.java

@@ -27,7 +27,8 @@ public interface QueRenYiZhuShouFeiDao {
     @Select("<script>" +
             "select  " +
             "rtrim(a.inpatient_no) inpatient_no, a.admiss_times, bed_no =b.bed_no," +
-            "case when b.name IS NULL  then (select top(1) rtrim(name) name from zy_inactpatient where zy_inactpatient.inpatient_no = a.inpatient_no) else  rtrim(b.name) end name, a.ward_code ,b.sex,b.admiss_date,  " +
+            "case when b.name IS NULL  then (select top(1) rtrim(name) name from zy_inactpatient where zy_inactpatient.inpatient_no = a.inpatient_no) else  rtrim(b.name) end name, " +
+            "a.ward_code ,b.sex,b.admiss_date,  " +
             "ledger_sn = (select max(ledger_sn) from zy_ledger_file where zy_ledger_file.inpatient_no = b.inpatient_no  " +
             "and zy_ledger_file.admiss_times = b.admiss_times),b.total_charge,  " +
             "responce_type_name = (select rtrim(name) from zy_zd_responce_type where zy_zd_responce_type.code = b.responce_type),  " +

+ 4 - 9
src/main/java/thyyxxk/webserver/entity/datamodify/ZyDetailCharge.java

@@ -36,7 +36,7 @@ public class ZyDetailCharge implements Serializable {
 
     private String startTime;
     private String endTime;
-    private String riQiPaiXu;
+    private String riQiPaiXu = "DESC";
 
     private String chargeCodeName;
 
@@ -125,6 +125,8 @@ public class ZyDetailCharge implements Serializable {
     @TableField(exist = false)
     private long currentPage;
 
+    private long total;
+
     @TableField(exist = false)
     private Integer feiYongLeiXingCode;
 
@@ -275,16 +277,9 @@ public class ZyDetailCharge implements Serializable {
      */
     private Integer tuiFeiFlag;
 
-    public String getRiQiPaiXu() {
-        if (riQiPaiXu == null) {
-            return "DESC";
-        } else {
-            return riQiPaiXu;
-        }
-    }
 
     public BigDecimal getOrderNo() {
-        if (this.orderNo == null) {
+        if (orderNo == null) {
             return new BigDecimal(0);
         } else {
             return orderNo;

+ 15 - 2
src/main/java/thyyxxk/webserver/service/PublicServer.java

@@ -143,10 +143,23 @@ public class PublicServer {
         return ResultVoUtil.success(dao.getDept());
     }
 
-
-    public void pingJieXinXi() {
+    /**
+     * 获取这个人的账页号
+     *
+     * @param inpatientNo 住院号 这个住院号需要不带 $ 符号
+     * @param admissTimes 住院次数
+     * @return 返回有用的账页号
+     */
+    public Integer getLedgerSn(String inpatientNo, Integer admissTimes) {
+        return dao.getLedgerSn(inpatientNo, admissTimes);
+    }
 
 
+    public void genXingYuanLiuShuiBiaoZhi(String inpatientNo, Integer admissTimes, Integer ledger) {
+        if (!dao.tuiFeiYiPiPei(inpatientNo, admissTimes, ledger).equals(dao.beiPiPeiZhenShu(inpatientNo, admissTimes, ledger))) {
+            log.info("更新正数的流水号 ==> 流水号:{},住院次数:{},账页号:{}", inpatientNo, admissTimes, ledger);
+            dao.genXinYuanTuiFeiLiuShui(inpatientNo, admissTimes, ledger);
+        }
     }
 
 }

+ 27 - 29
src/main/java/thyyxxk/webserver/service/yibao/XiangMuLuRuService.java

@@ -54,44 +54,41 @@ public class XiangMuLuRuService {
         if (StringUtil.isBlank(param.getInpatientNo()) || param.getAdmissTimes() == null) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "住院号或住院次数为空 <br/>๑乛◡乛๑");
         }
-        log.info("查询患者费用==》住院号{},住院次数:{},项目名称:{},费用类型:{},科室:{},当前页:{},页大小:{}", param.getInpatientNo(), param.getAdmissTimes(),
-                param.getChargeCode(), param.getOrderNo(), param.getDept(), param.getCurrentPage(), param.getPageSize());
+        log.info("查询患者费用==》住院号{},住院次数:{},项目名称:{},费用类型:{},科室:{},当前页:{},页大小:{},退费:{},总数:{}", param.getInpatientNo(), param.getAdmissTimes(),
+                param.getChargeCode(), param.getOrderNo(), param.getDept(), param.getCurrentPage(), param.getPageSize(), param.getTuiFeiFlag(), param.getTotal());
         int infantFlag = 0;
         // 如果是婴儿的话那么就需要截取 字符串了 在通过婴儿标识来判断
         if (param.getInpatientNo().contains("$")) {
             param.setInpatientNo(param.getInpatientNo().split("\\$")[0]);
             infantFlag = 1;
         }
-        Page<ZyDetailCharge> page = new Page<>(param.getCurrentPage(), param.getPageSize(), false);
-        if (param.getFeiYongLeiXingCode() == 0) {
-            page.setTotal(dao.huanZheFeiYongCount(param.getInpatientNo(), param.getAdmissTimes(), param.getChargeCode(), infantFlag,
-                    param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getDept(), "not like"));
-            dao.huanZheXiangMuFeiYong(page, param.getInpatientNo(), param.getAdmissTimes(), param.getChargeCode(), infantFlag,
-                    param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getDept(), param.getRiQiPaiXu());
-        } else {
-            page.setTotal(dao.huanZheFeiYongCount(param.getInpatientNo(), param.getAdmissTimes(), param.getChargeCode(), infantFlag,
-                    param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getDept(), "like"));
-            dao.huanZheYaoPinFeiYong(page, param.getInpatientNo(), param.getAdmissTimes(), param.getChargeCode(), infantFlag,
-                    param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getDept(), param.getRiQiPaiXu());
+        if (param.getTuiFeiFlag() == null) {
+            param.setTuiFeiFlag(2);
         }
-        if (page.getTotal() == 0) {
-            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到符合费用。");
+        Page<ZyDetailCharge> page = new Page<>();
+        Integer ledgerSn = publicServer.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes());
+        if (param.getTotal() == 0) {
+            publicServer.genXingYuanLiuShuiBiaoZhi(param.getInpatientNo(), param.getAdmissTimes(), ledgerSn);
         }
-        List<ZyDetailCharge> tuiFeiList = dao.tuiFeiList(param.getInpatientNo(), param.getAdmissTimes(), infantFlag);
-        if (!tuiFeiList.isEmpty()) {
-            Map<Integer, Integer> map = new HashMap<>();
-            for (ZyDetailCharge zyDetailCharge : tuiFeiList) {
-                map.put(zyDetailCharge.getOriDetailSn(), zyDetailCharge.getDetailSn());
+
+        if (param.getFeiYongLeiXingCode() == 0) {
+            if (param.getTotal() == 0) {
+                page.setTotal(dao.huanZheFeiYongCount(param.getInpatientNo(), param.getAdmissTimes(), ledgerSn, param.getChargeCode(), infantFlag,
+                        param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getDept(), param.getTuiFeiFlag()));
             }
-            for (ZyDetailCharge zyDetailCharge : page.getRecords()) {
-                // 判断 退费的数据
-                if (map.containsKey(zyDetailCharge.getDetailSn())) {
-                    zyDetailCharge.setTuiFeiFlag(1);
-                }
-                if (zyDetailCharge.getOriDetailSn() != null) {
-                    zyDetailCharge.setTuiFeiFlag(1);
-                }
+            page.setRecords(dao.huanZheXiangMuFeiYong(param.getCurrentPage(), param.getPageSize(), param.getInpatientNo(), param.getAdmissTimes(), ledgerSn, param.getChargeCode(), infantFlag,
+                    param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getDept(), param.getRiQiPaiXu(), param.getTuiFeiFlag()));
+        } else {
+            if (param.getTotal() == 0) {
+                page.setTotal(dao.huanZheYaoPinFeiYongTotal(param.getInpatientNo(), param.getAdmissTimes(), ledgerSn, param.getChargeCode(), infantFlag,
+                        param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getDept(), param.getTuiFeiFlag()));
             }
+            page.setRecords(dao.huanZheYaoPinFeiYong(param.getCurrentPage(), param.getPageSize(), param.getInpatientNo(), param.getAdmissTimes(), ledgerSn, param.getChargeCode(), infantFlag,
+                    param.getStartTime(), param.getEndTime(), param.getOrderNo(), param.getDept(), param.getRiQiPaiXu(), param.getTuiFeiFlag()));
+        }
+
+        if (ListUtil.isBlank(page.getRecords())) {
+            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到符合费用。");
         }
         return ResultVoUtil.success(page);
     }
@@ -350,8 +347,9 @@ public class XiangMuLuRuService {
         }
         FeiYongLeiXin fy = JiSuanFeiYong.jiSuan(param.getList(), true);
         fy.setTotalCharge(sum);
+
         // 在此处 插入费用
-        dao.chaRuFeiYong(param, param.getList(), infantFlag);
+        dao.chaRuFeiYong(param, param.getList(), infantFlag, publicServer.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes()));
         dao.huanZheZongFeiYong(fy, param.getInpatientNo(), param.getAdmissTimes(), "zy_ledger_file");
         dao.huanZheZongFeiYong(fy, param.getInpatientNo(), param.getAdmissTimes(), "zy_actpatient");
         log.info("项目录入费用上传 ==》 操作人:{},数据:{}", param.getOpIdCode(), JSON.toJSONString(param));

+ 3 - 0
src/main/java/thyyxxk/webserver/service/zhuyuanyiji/QueRenYiZhuShouFeiServer.java

@@ -65,6 +65,9 @@ public class QueRenYiZhuShouFeiServer {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查看历史数据时需要携带医嘱时间");
             }
             liShi = "<>";
+        } else {
+            yzActOrder.setStartTimeString("");
+            yzActOrder.setEndTimeString("");
         }
         log.info("查询需确费医嘱:数据:{}", JSON.toJSONString(yzActOrder));
         String fenLei = "a.ward_code";

+ 2 - 3
src/main/java/thyyxxk/webserver/service/zhuyuanyiji/YiJiFeiYongLuRuServer.java

@@ -38,10 +38,10 @@ public class YiJiFeiYongLuRuServer {
      */
     public ResultVo<ZyActpatient> getHuanZheXinXi(String inpatientNo, Integer zaiYuanChuYuan, Integer admissTimes) {
         log.info("医技查询患者信息:住院号{},是否在院{},住院次数:{}", inpatientNo, zaiYuanChuYuan, admissTimes);
+
         if (StringUtil.isBlank(inpatientNo)) {
-            return ResultVoUtil.fail(ExceptionEnum.NEED_PROOFREAD, "住院号不能为空。");
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "住院号不能为空。");
         }
-
         String tableName;
         if (zaiYuanChuYuan == 0) {
             tableName = "zy_actpatient";
@@ -55,7 +55,6 @@ public class YiJiFeiYongLuRuServer {
         if (zyActpatient == null) {
             return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
         }
-
         if (zaiYuanChuYuan == 0) {
             Integer jieSuan = dao.getHuanZheSFJieSuan(publicServer.getInpatientNo(inpatientNo), zyActpatient.getAdmissTimes());
             if (jieSuan == null || jieSuan != 0) {

+ 1 - 1
src/main/resources/application.yml

@@ -8,7 +8,7 @@ spring:
     cache: false
   datasource:
     dynamic:
-      primary: his
+      primary: dev
       strict: false
       datasource:
         his: