浏览代码

中间断账后插入一条预交金以平衡上一个账页的结余

lighter 2 年之前
父节点
当前提交
28ce3b3a47

+ 24 - 1
src/main/java/thyyxxk/webserver/dao/his/inpatient/DismissDao.java

@@ -278,6 +278,28 @@ public interface DismissDao {
                                        @Param("times") Integer times,
                                        @Param("ledgerSn") int ledgerSn);
 
+    @Select("select top 1 inpatient_no, admiss_times, depo_times, depo_date, op_id_code, depo_amount, depo_type, " +
+            "status, ledger_sn, window_no, deleted from zy_deposit_file where inpatient_no=#{patNo} " +
+            "and admiss_times=#{times} order by depo_times desc")
+    DepositFile selectLatestDepositFile(@Param("patNo") String patNo,
+                                        @Param("times") Integer times);
+
+    @Select("select settle from zy_ledger_file where inpatient_no=#{patNo} and admiss_times=#{times} and " +
+            "ledger_sn=#{ledgerSn}")
+    String selectLastLedgerSettle(@Param("patNo") String patNo,
+                                  @Param("times") Integer times,
+                                  @Param("ledgerSn") Integer ledgerSn);
+
+    @Insert("insert into zy_deposit_file (inpatient_no, admiss_times, depo_times, depo_date, op_id_code, " +
+            "depo_amount, depo_type, status, ledger_sn, window_no, deleted) " +
+            "values (#{inpatientNo},#{admissTimes},#{depoTimes},#{depoDate},#{opIdCode},#{depoAmount}, " +
+            "#{depoType},#{status},#{ledgerSn},#{windowNo},#{deleted})")
+    void insertNewDeposit(DepositFile depositFile);
+
+    @Delete("delete from zy_deposit_file where inpatient_no=#{patNo} and admiss_times=#{times} and depo_type='B' ")
+    void deleteZjdzSettleDeposit(@Param("patNo") String patNo,
+                                 @Param("times") Integer times);
+
     @Update("update zy_detail_charge set ledger_sn=#{ledgerSn} where inpatient_no=#{patNo} " +
             "and admiss_times=#{times} and ledger_sn=#{lastSn} and charge_date>#{zjdzDate}")
     void updateFeesLedgerSn(@Param("patNo") String patNo,
@@ -350,7 +372,8 @@ public interface DismissDao {
                               @Param("ledgerSn") int ledgerSn);
 
     @Select("select cast(isnull(sum(depo_amount),0) as varchar(16)) from zy_deposit_file where " +
-            "inpatient_no=#{patNo} and admiss_times=#{times} and ledger_sn=#{ledgerSn} and status in (1,2) ")
+            "inpatient_no=#{patNo} and admiss_times=#{times} and ledger_sn=#{ledgerSn} and " +
+            "depo_type!='B' and status in (1,2) ")
     String selectDepositSumamt(@Param("patNo") String patNo,
                                @Param("times") int times,
                                @Param("ledgerSn") int ledgerSn);

+ 40 - 0
src/main/java/thyyxxk/webserver/entity/inpatient/dismiss/DepositFile.java

@@ -0,0 +1,40 @@
+package thyyxxk.webserver.entity.inpatient.dismiss;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class DepositFile {
+    private String inpatientNo;
+    private Integer admissTimes;
+    private Integer ledgerSn;
+    private Integer depoTimes;
+    private Date depoDate;
+    private String opIdCode;
+    private String depoAmount;
+    private String depoType;
+    private String status;
+    private String windowNo;
+    private Integer deleted;
+
+    public DepositFile() {
+    }
+
+    public DepositFile(String inpatientNo, Integer admissTimes, Integer ledgerSn) {
+        this.inpatientNo = inpatientNo;
+        this.admissTimes = admissTimes;
+        this.ledgerSn = ledgerSn;
+    }
+
+    public void initZjdzSettleDeposit(String depoAmount) {
+        this.depoTimes += 1;
+        this.depoDate = new Date();
+        this.opIdCode = "00000";
+        this.depoAmount = depoAmount;
+        this.depoType = "B";
+        this.status = "1";
+        this.windowNo = "1";
+        this.deleted = 0;
+    }
+}

+ 37 - 22
src/main/java/thyyxxk/webserver/service/inpatient/DismissService.java

@@ -467,34 +467,37 @@ public class DismissService {
 
     private int setHisStatusOut(MedinsSettleFee settle) {
         final Date disDate;
+        String patNo = settle.getInpatientNo();
+        int times = settle.getAdmissTimes();
         if ("zy_actpatient".equals(settle.getTable())) {
-            disDate = dao.selectActOrderDisDate(settle.getInpatientNo(), settle.getAdmissTimes());
+            disDate = dao.selectActOrderDisDate(patNo, times);
         } else {
-            disDate = dao.selectActOrderDisDate2(settle.getInpatientNo(), settle.getAdmissTimes());
+            disDate = dao.selectActOrderDisDate2(patNo, times);
         }
-        if (dao.updateZyActpatient(settle.getInpatientNo(), settle.getAdmissTimes(),
+        if (dao.updateZyActpatient(patNo, times,
                 disDate, settle.getStaffId(), settle.getTable()) < 1) {
             return -1;
         }
         if ("zy_actpatient".equals(settle.getTable())) {
-            dao.deleteZyInactpatient(settle.getInpatientNo(), settle.getAdmissTimes());
-            if (dao.insertZyInactpatient(settle.getInpatientNo(), settle.getAdmissTimes()) < 1) {
+            dao.deleteZyInactpatient(patNo, times);
+            if (dao.insertZyInactpatient(patNo, times) < 1) {
                 return -2;
             }
         }
-        final String patNo1 = settle.getInpatientNo() + "$1";
-        final String patNo6 = settle.getInpatientNo() + "$6";
-        dao.updateZyActpatientAgain(patNo1, patNo6, settle.getAdmissTimes(), disDate, settle.getTable());
+        final String patNo1 = patNo + "$1";
+        final String patNo6 = patNo + "$6";
+        dao.updateZyActpatientAgain(patNo1, patNo6, times, disDate, settle.getTable());
         if ("zy_actpatient".equals(settle.getTable())) {
-            dao.insertZyInactpatientAgain(patNo1, patNo6, settle.getAdmissTimes());
+            dao.insertZyInactpatientAgain(patNo1, patNo6, times);
         }
-        if (dao.updateZyAdt(settle.getInpatientNo(), settle.getAdmissTimes(), settle.getWardCode(), settle.getDeptCode(),
+        if (dao.updateZyAdt(patNo, times, settle.getWardCode(), settle.getDeptCode(),
                 settle.getBedNo(), disDate) < 1) {
             return -3;
         }
-        dao.updateZyBedMi(settle.getInpatientNo(), settle.getAdmissTimes());
-        dao.deleteZyActpatient(settle.getInpatientNo());
-        dao.deleteZyActpatientAgain(patNo1, patNo6, settle.getAdmissTimes());
+        dao.updateZyBedMi(patNo, times);
+        dao.deleteZyActpatient(patNo);
+        dao.deleteZyActpatientAgain(patNo1, patNo6, times);
+        dao.deleteZjdzSettleDeposit(patNo, times);
         return insertNewZyWorkLog(settle);
     }
 
@@ -506,15 +509,27 @@ public class DismissService {
     }
 
     private int hisMiddleSettle(MedinsSettleFee param) {
-        param.setLedgerSn(dao.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes()));
-        int newLedgerSn = param.getLedgerSn() + 1;
-        dao.updateTimesBilledByIncreaseOne(param.getInpatientNo(), param.getAdmissTimes(), param.getTable());
-        dao.insertNewLedgerFile(param.getInpatientNo(), param.getAdmissTimes(), newLedgerSn);
-        dao.updateFeesLedgerSn(param.getInpatientNo(), param.getAdmissTimes(), newLedgerSn,
-                param.getLedgerSn(), param.getZjdzDatetime());
-        dao.updateZyLedgerFileTotalCharge(param.getInpatientNo(), param.getAdmissTimes(), param.getLedgerSn());
-        dao.updateZyLedgerFileTotalCharge(param.getInpatientNo(), param.getAdmissTimes(), newLedgerSn);
-        dao.clearMedinsInfo(param.getInpatientNo(), param.getAdmissTimes(), DateUtil.addOneSecond(param.getZjdzDatetime()));
+        String patNo = param.getInpatientNo();
+        int times = param.getAdmissTimes();
+        int currentLedgerSn = dao.getLedgerSn(patNo, times);
+        int newLedgerSn = currentLedgerSn + 1;
+
+        dao.updateTimesBilledByIncreaseOne(patNo, times, param.getTable());
+        dao.insertNewLedgerFile(patNo, times, newLedgerSn);
+        dao.updateFeesLedgerSn(patNo, times, newLedgerSn, currentLedgerSn, param.getZjdzDatetime());
+        dao.updateZyLedgerFileTotalCharge(patNo, times, currentLedgerSn);
+        dao.updateZyLedgerFileTotalCharge(patNo, times, newLedgerSn);
+
+        DepositFile depositFile = dao.selectLatestDepositFile(patNo, times);
+        if (null == depositFile) {
+            depositFile = new DepositFile(patNo, times, newLedgerSn);
+        }
+        depositFile.initZjdzSettleDeposit(dao.selectLastLedgerSettle(patNo, times, currentLedgerSn));
+        dao.insertNewDeposit(depositFile);
+
+        dao.clearMedinsInfo(patNo, times, DateUtil.addOneSecond(param.getZjdzDatetime()));
+
+        param.setLedgerSn(currentLedgerSn);
         return insertNewZyWorkLog(param);
     }