瀏覽代碼

优化正负相抵,不用再勾选费用,直接把所能能抵的都抵掉。

lighter 4 年之前
父節點
當前提交
5fdf56546b

+ 3 - 0
src/main/java/thyyxxk/webserver/controller/yibao/PatientController.java

@@ -14,6 +14,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * @author dj
+ */
 @RestController
 @RequestMapping("/patient")
 public class PatientController {

+ 10 - 0
src/main/java/thyyxxk/webserver/dao/his/yibao/PatientDao.java

@@ -6,6 +6,7 @@ import thyyxxk.webserver.entity.yibao.patient.*;
 import thyyxxk.webserver.entity.yibao.dismiss.DisDiag;
 
 import java.util.Date;
+import java.util.LinkedList;
 import java.util.List;
 
 @Mapper
@@ -233,10 +234,19 @@ public interface PatientDao {
             "WHERE inpatient_no=#{inpatientNo} AND admiss_times=#{admissTimes}")
     List<IdCard> getScanFile(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes);
 
+
+    @Select("select detail_sn,rtrim(charge_code_mx) as chargeCodeMx,charge_fee from zy_detail_charge " +
+            "where inpatient_no=#{zyh} and admiss_times=#{zycs} and ledger_sn=#{sn} and isnull(trans_flag_yb,0) not in (1,2)")
+    LinkedList<FeeCounteract> selectAllNotUploadedFees(@Param("zyh") String zyh, @Param("zycs") Integer zycs, @Param("sn") Integer sn);
+
     @Update("update zy_detail_charge set trans_flag_yb=2 where inpatient_no=#{zyh} and " +
             "admiss_times=#{zycs} and detail_sn=#{sn}")
     void updateYbTransFlag(@Param("zyh") String zyh, @Param("zycs") Integer zycs, @Param("sn") Integer sn);
 
+    @Update("update zy_detail_charge set trans_flag_yb=2 where inpatient_no=#{zyh} and " +
+            "admiss_times=#{zycs} and detail_sn in (#{sn}, #{sn2})")
+    void updateYbTransFlagInPair(@Param("zyh") String zyh, @Param("zycs") Integer zycs, @Param("sn") Integer sn, @Param("sn2") Integer sn2);
+
     @Select("select settle_type from zy_ledger_file where inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes} " +
             "and ledger_sn=(select isnull(max ( ledger_sn ), min ( ledger_sn )) from zy_ledger_file where " +
             "inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes})")

+ 15 - 0
src/main/java/thyyxxk/webserver/entity/yibao/patient/FeeCounteract.java

@@ -0,0 +1,15 @@
+package thyyxxk.webserver.entity.yibao.patient;
+
+import lombok.Data;
+
+/**
+ * @description: 正负相抵的费用实体
+ * @author: DingJie
+ * @create: 2021-04-12 17:47:12
+ **/
+@Data
+public class FeeCounteract {
+    private Integer detailSn;
+    private String chargeCodeMx;
+    private String chargeFee;
+}

+ 3 - 3
src/main/java/thyyxxk/webserver/entity/yibao/patient/UpdateTransFlagParam.java

@@ -2,12 +2,12 @@ package thyyxxk.webserver.entity.yibao.patient;
 
 import lombok.Data;
 
-import java.util.List;
-
+/**
+ * @author dj
+ */
 @Data
 public class UpdateTransFlagParam {
     private String staffId;
     private String inpatientNo;
     private Integer admissTimes;
-    private List<Fee> list;
 }

+ 61 - 27
src/main/java/thyyxxk/webserver/service/yibao/PatientService.java

@@ -279,40 +279,74 @@ public class PatientService {
 
     public ResultVo<String> updateTransFlag(UpdateTransFlagParam param) {
         log.info("正负相抵操作:{}", param);
-        String verify = verifyTransFlags(param.getList());
-        log.info("正负相抵操作校验:{}", verify);
-        if ("success".equals(verify)) {
-            for (Fee fee : param.getList()) {
-                dao.updateYbTransFlag(param.getInpatientNo(), param.getAdmissTimes(), fee.getDetailSn());
-            }
-            return ResultVoUtil.success();
-        } else {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, verify);
+        int ledgerSn = dao.getLedgerSn(param.getInpatientNo(), param.getAdmissTimes());
+        Queue<FeeCounteract> fees = dao.selectAllNotUploadedFees(param.getInpatientNo(), param.getAdmissTimes(), ledgerSn);
+        if (null == fees || fees.isEmpty()) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有可以进行正负相抵的费用。");
         }
-    }
-
-    private String verifyTransFlags(List<Fee> list) {
-        HashMap<String, List<Fee>> map = new HashMap<>(Capacity.DEFAULT);
-        for (Fee fee : list) {
-            String code = fee.getHisItemCode();
-            if (map.containsKey(code)) {
-                map.get(code).add(fee);
+        Map<String, Map<String, List<FeeCounteract>>> feeMap = new HashMap<>(Capacity.DEFAULT);
+        while (!fees.isEmpty()) {
+            FeeCounteract fee = fees.poll();
+            String chargeCodeMx = fee.getChargeCodeMx();
+            if (feeMap.containsKey(chargeCodeMx)) {
+                if (fee.getChargeFee().startsWith("-")) {
+                    feeMap.get(chargeCodeMx).get("negative").add(fee);
+                } else {
+                    feeMap.get(chargeCodeMx).get("positive").add(fee);
+                }
             } else {
-                List<Fee> temp = new ArrayList<>();
-                temp.add(fee);
-                map.put(code, temp);
+                Map<String, List<FeeCounteract>> tempMap = new HashMap<>();
+                tempMap.put("positive", new ArrayList<>());
+                tempMap.put("negative", new ArrayList<>());
+                if (fee.getChargeFee().startsWith("-")) {
+                    tempMap.get("negative").add(fee);
+                } else {
+                    tempMap.get("positive").add(fee);
+                }
+                feeMap.put(chargeCodeMx, tempMap);
             }
         }
-        for (Map.Entry<String, List<Fee>> entry : map.entrySet()) {
-            String sum = "0.00";
-            for (Fee fee : entry.getValue()) {
-                sum = DecimalUtil.add(sum, fee.getChargeFee());
+        for (Map.Entry<String, Map<String, List<FeeCounteract>>> entry : feeMap.entrySet()) {
+            List<FeeCounteract> negativeList = entry.getValue().get("negative");
+            if (negativeList.isEmpty()) {
+                continue;
             }
-            if (DecimalUtil.compare(sum, "0") != 0) {
-                return "收费码:" + entry.getKey() + "的费用之和不为0,无法进行正负相抵!";
+            List<FeeCounteract> positiveList = entry.getValue().get("positive");
+            List<Integer> updatedSn = new ArrayList<>();
+            for (FeeCounteract negativeFee : negativeList) {
+                boolean found = false;
+                for (FeeCounteract positiveFee : positiveList) {
+                    if (updatedSn.contains(positiveFee.getDetailSn())) {
+                        continue;
+                    }
+                    if (DecimalUtil.negativeAndPositive(positiveFee.getChargeFee(), negativeFee.getChargeFee())) {
+                        found = true;
+                        updatedSn.add(positiveFee.getDetailSn());
+                        dao.updateYbTransFlagInPair(param.getInpatientNo(), param.getAdmissTimes(),
+                                negativeFee.getDetailSn(), positiveFee.getDetailSn());
+                        break;
+                    }
+                }
+                if (!found) {
+                    String positiveAmt = "0.00";
+                    List<Integer> detailSnList = new ArrayList<>();
+                    for (FeeCounteract positiveFee : positiveList) {
+                        if (updatedSn.contains(positiveFee.getDetailSn())) {
+                            continue;
+                        }
+                        detailSnList.add(positiveFee.getDetailSn());
+                        updatedSn.add(positiveFee.getDetailSn());
+                        positiveAmt = DecimalUtil.add(positiveAmt, positiveFee.getChargeFee());
+                        if (DecimalUtil.negativeAndPositive(positiveAmt, negativeFee.getChargeFee())) {
+                            dao.updateYbTransFlag(param.getInpatientNo(), param.getAdmissTimes(), negativeFee.getDetailSn());
+                            detailSnList.forEach(detailSn -> dao.updateYbTransFlag(param.getInpatientNo(), param.getAdmissTimes(),detailSn));
+                            break;
+                        }
+                    }
+                }
             }
         }
-        return "success";
+        return ResultVoUtil.success();
     }
 
     /**

+ 2 - 2
src/main/java/thyyxxk/webserver/utils/DecimalUtil.java

@@ -26,10 +26,10 @@ public class DecimalUtil {
         return ad.divide(bd, 2, BigDecimal.ROUND_DOWN).toString();
     }
 
-    public static int compare(String a, String b) {
+    public static boolean negativeAndPositive(String a, String b) {
         BigDecimal ad = new BigDecimal(a);
         BigDecimal bd = new BigDecimal(b);
-        return ad.compareTo(bd);
+        return ad.add(bd).compareTo(new BigDecimal("0")) == 0;
     }
 
     public static String moneyYuanToFen(BigDecimal fee) {