Prechádzať zdrojové kódy

优化费用上传偶尔有遗漏的问题。

lighter 3 rokov pred
rodič
commit
e6ccad11e8

+ 5 - 5
src/main/java/thyyxxk/sizyfeeoprnsystm/dao/SiZyDao.java

@@ -90,7 +90,7 @@ public interface SiZyDao {
             "medType=(select med_type from t_si_pat_info b where b.pat_no=inpatient_no and b.times=admiss_times and b.ledger_sn=a.ledger_sn), " +
             "medListCodg=isnull((select max(national_code) from yp_zd_dict where code=charge_code_mx),(select max(national_code) from zd_charge_item where code=charge_code_mx)), " +
             "bilgDeptName=(select name from zd_unit_code where code=ward_code), " +
-            "bilgDrCodg=(select rtrim(yb_code) from a_employee_mi where code=isnull(isnull(doctor_code,refer_physician), op_id_code)) , " +
+            "bilgDrCodg=(select rtrim(isnull(yb_code,code)) from a_employee_mi where code=isnull(isnull(doctor_code,refer_physician), op_id_code)) , " +
             "bilgDrName=isnull(isnull((select rtrim(name) from a_employee_mi where code=doctor_code), " +
             "(select rtrim(name) from a_employee_mi where code=refer_physician)),(select rtrim(name) from a_employee_mi where code=op_id_code)) " +
             "from zy_detail_charge a where inpatient_no=#{patNo} and admiss_times=#{times} and " +
@@ -126,7 +126,7 @@ public interface SiZyDao {
             "medType=(select med_type from t_si_pat_info b where b.pat_no=inpatient_no and b.times=admiss_times and b.ledger_sn=a.ledger_sn), " +
             "medListCodg=isnull((select max(national_code) from yp_zd_dict where code=charge_code_mx),(select max(national_code) from zd_charge_item where code=charge_code_mx)), " +
             "bilgDeptName=(select name from zd_unit_code where code=ward_code), " +
-            "bilgDrCodg=(select rtrim(yb_code) from a_employee_mi where code=isnull(isnull(doctor_code,refer_physician), op_id_code)) , " +
+            "bilgDrCodg=(select rtrim(isnull(yb_code,code)) from a_employee_mi where code=isnull(isnull(doctor_code,refer_physician), op_id_code)) , " +
             "bilgDrName=isnull(isnull((select rtrim(name) from a_employee_mi where code=doctor_code), " +
             "(select rtrim(name) from a_employee_mi where code=refer_physician)),(select rtrim(name) from a_employee_mi where code=op_id_code)) " +
             "from zy_detail_charge a where inpatient_no=#{patNo} and admiss_times=#{times} and " +
@@ -152,7 +152,7 @@ public interface SiZyDao {
             "</script>")
     void updateTransFlag(@Param("patNo") String patNo,
                          @Param("times") int times,
-                         @Param("fees") List<FeeDtle> fees);
+                         @Param("fees") List<SiChargeTemp> fees);
 
     @Insert("<script>" +
             "insert into t_si_charge_temp (pat_no, times, ledger_sn, feedetl_sn, det_item_fee_sumamt, cnt, " +
@@ -274,7 +274,7 @@ public interface SiZyDao {
             "medType=(select med_type from t_si_pat_info b where b.pat_no=inpatient_no and b.times=admiss_times and b.ledger_sn=a.ledger_sn), " +
             "medListCodg=isnull((select max(national_code) from yp_zd_dict where code=charge_code_mx),(select max(national_code) from zd_charge_item where code=charge_code_mx)), " +
             "bilgDeptName=(select name from zd_unit_code where code=ward_code), " +
-            "bilgDrCodg=(select rtrim(yb_code) from a_employee_mi where code=isnull(isnull(doctor_code,refer_physician), op_id_code)) , " +
+            "bilgDrCodg=(select rtrim(isnull(yb_code,code)) from a_employee_mi where code=isnull(isnull(doctor_code,refer_physician), op_id_code)) , " +
             "bilgDrName=isnull(isnull((select rtrim(name) from a_employee_mi where code=doctor_code), " +
             "(select rtrim(name) from a_employee_mi where code=refer_physician)),(select rtrim(name) from a_employee_mi where code=op_id_code)) " +
             "from zy_detail_charge a where inpatient_no=#{patNo} and admiss_times=#{times} and " +
@@ -310,7 +310,7 @@ public interface SiZyDao {
             "medType=(select med_type from t_si_pat_info b where b.pat_no=inpatient_no and b.times=admiss_times and b.ledger_sn=a.ledger_sn), " +
             "medListCodg=isnull((select max(national_code) from yp_zd_dict where code=charge_code_mx),(select max(national_code) from zd_charge_item where code=charge_code_mx)), " +
             "bilgDeptName=(select name from zd_unit_code where code=ward_code), " +
-            "bilgDrCodg=(select rtrim(yb_code) from a_employee_mi where code=isnull(isnull(doctor_code,refer_physician), op_id_code)) , " +
+            "bilgDrCodg=(select rtrim(isnull(yb_code,code)) from a_employee_mi where code=isnull(isnull(doctor_code,refer_physician), op_id_code)) , " +
             "bilgDrName=isnull(isnull((select rtrim(name) from a_employee_mi where code=doctor_code), " +
             "(select rtrim(name) from a_employee_mi where code=refer_physician)),(select rtrim(name) from a_employee_mi where code=op_id_code)) " +
             "from zy_detail_charge a where inpatient_no=#{patNo} and admiss_times=#{times} and " +

+ 57 - 20
src/main/java/thyyxxk/sizyfeeoprnsystm/service/SiZyFeeService.java

@@ -105,8 +105,6 @@ public class SiZyFeeService {
         p.setPsnNo(siPatInfo.getPsnNo());
         p.setMedType(siPatInfo.getMedType());
         p.setAdmdvs(siPatInfo.getInsuplcAdmdvs());
-
-        Queue<FeeDtle> allPositiveFees, allNegativeFees;
         if (o.getMidSetl()) {
             List<Integer> notAllowedSns = zyDao.selectNotAllowedSnForMidSetl(o.getInpatientNo(), o.getAdmissTimes(),
                     o.getLedgerSn(), o.getEndtime());
@@ -125,6 +123,37 @@ public class SiZyFeeService {
                     revokeUploadFees(p);
                 }
             }
+        }
+        Map<String, Queue<FeeDtle>> allFees = getAllFeesNotUploaded(o);
+        Queue<FeeDtle> allPositiveFees = allFees.get("positive");
+        Queue<FeeDtle> allNegativeFees = allFees.get("negative");
+        if (allPositiveFees.size() == 0 && allNegativeFees.size() == 0) {
+            return hospitalizationPreSettlement(p, o);
+        }
+        int index = 0;
+        int feeSize = allPositiveFees.size() + allNegativeFees.size();
+
+        int[] pstvres = prepareUploadFees(allPositiveFees, index, feeSize, p, o.getSid());
+        index = pstvres[0];
+        int[] ngtvres = prepareUploadFees(allNegativeFees, index, feeSize, p, o.getSid());
+        index = ngtvres[0];
+
+        if (pstvres[1] == 1 || ngtvres[1] == 1) {
+            allFees = getAllFeesNotUploaded(o);
+            allPositiveFees = allFees.get("positive");
+            allNegativeFees = allFees.get("negative");
+
+            log.info("医保中心数据有遗漏,继续上传遗漏部分。");
+            index = prepareUploadFees(allPositiveFees, index, feeSize, p, o.getSid())[0];
+            prepareUploadFees(allNegativeFees, index, feeSize, p, o.getSid());
+        }
+
+        return hospitalizationPreSettlement(p, o);
+    }
+
+    private Map<String, Queue<FeeDtle>> getAllFeesNotUploaded(Overview o) {
+        Queue<FeeDtle> allPositiveFees, allNegativeFees;
+        if (o.getMidSetl()) {
             allPositiveFees = zyDao.selectNotUploadedPositiveFeesForMidSetl(o.getInpatientNo(), o.getAdmissTimes(),
                     o.getLedgerSn(), o.getBegntime(), o.getEndtime());
             allNegativeFees = zyDao.selectNotUploadedNegativeFeesForMidSetl(o.getInpatientNo(), o.getAdmissTimes(),
@@ -137,15 +166,10 @@ public class SiZyFeeService {
             allNegativeFees = zyDao.selectNotUploadedNegativeFees(o.getInpatientNo(), o.getAdmissTimes(),
                     o.getLedgerSn(), today);
         }
-
-        if (allPositiveFees.size() == 0 && allNegativeFees.size() == 0) {
-            return hospitalizationPreSettlement(p, o);
-        }
-        int index = 0;
-        int feeSize = allPositiveFees.size() + allNegativeFees.size();
-        index = prepareUploadFees(allPositiveFees, index, feeSize, p, o.getSid());
-        prepareUploadFees(allNegativeFees, index, feeSize, p, o.getSid());
-        return hospitalizationPreSettlement(p, o);
+        Map<String, Queue<FeeDtle>> result = new HashMap<>();
+        result.put("positive", allPositiveFees);
+        result.put("negative", allNegativeFees);
+        return result;
     }
 
     private String getTodayEndTime() {
@@ -154,7 +178,11 @@ public class SiZyFeeService {
         return date + " 23:59:59.999";
     }
 
-    private int prepareUploadFees(Queue<FeeDtle> feeQueue, int index, int feeSize, ZyPatientInfo p, String sid) {
+    private int[] prepareUploadFees(Queue<FeeDtle> feeQueue, int index, int feeSize, ZyPatientInfo p, String sid) {
+        int[] result = new int[] {0,0};
+        if (feeQueue.size() == 0) {
+            return result;
+        }
         JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_HOSPITALIZATION_FEE_DETAILS,
                 p.getAdmdvs(), p.getStaffId());
         JSONObject socketMessage = new JSONObject();
@@ -167,33 +195,37 @@ public class SiZyFeeService {
             assert feeDtle != null;
             tempList.add(feeDtle);
             if (tempList.size() == 100) {
-                executeUploadFees(input, tempList, p);
+                int[] upldres = executeUploadFees(input, tempList, p);
+                index += upldres[0];
+                if (upldres[1] > 0) {
+                    result[1] = 1;
+                }
                 tempList.clear();
-                index += 100;
                 socketMessage.replace("percentage", makePercentage(index, feeSize));
                 template.postForObject(upldNotifyUrl + "/sendById",
                         new PureCodeName(sid, socketMessage.toJSONString()), String.class);
             }
         }
         if (tempList.size() > 0) {
-            executeUploadFees(input, tempList, p);
-            index += tempList.size();
+            int[] upldres = executeUploadFees(input, tempList, p);
+            index += upldres[0];
+            if (upldres[1] > 0) {
+                result[1] = 1;
+            }
             socketMessage.replace("percentage", makePercentage(index, feeSize));
             template.postForObject(upldNotifyUrl + "/sendById",
                     new PureCodeName(sid, socketMessage.toJSONString()), String.class);
         }
-        return index;
+        return result;
     }
 
-    private void executeUploadFees(JSONObject input, List<FeeDtle> fees, ZyPatientInfo p) {
+    private int[] executeUploadFees(JSONObject input, List<FeeDtle> fees, ZyPatientInfo p) {
         String ref = JSONArray.toJSONString(fees);
         input.getJSONObject("input").put("feedetail", JSONArray.parse(ref));
         JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_HOSPITALIZATION_FEE_DETAILS);
         log.info("【操作员:{}】,医保费用上传结果:{}", p.getStaffId(), result);
-        RestTemplate template = new RestTemplate();
         if (null != result) {
             if (result.getIntValue(RESULT_CODE) == 0) {
-                zyDao.updateTransFlag(p.getInpatientNo(), p.getAdmissTimes(), fees);
                 JSONArray array = result.getJSONObject(OUTPUT).getJSONArray("result");
                 List<SiChargeTemp> tempList = new ArrayList<>();
                 for (int i = 0; i < array.size(); i++) {
@@ -204,8 +236,11 @@ public class SiZyFeeService {
                     chrgtemp.setLedgerSn(p.getLedgerSn());
                     tempList.add(chrgtemp);
                 }
+                zyDao.updateTransFlag(p.getInpatientNo(), p.getAdmissTimes(), tempList);
                 zyDao.insertSiChargeTempFeeBatch(tempList);
+                return new int[] {tempList.size(), fees.size() - tempList.size()};
             } else {
+                RestTemplate template = new RestTemplate();
                 String message = result.getString(ERROR_MESSAGE);
                 JSONObject socketMsg = new JSONObject();
                 socketMsg.put("name", "uploadFeeResponse");
@@ -218,8 +253,10 @@ public class SiZyFeeService {
                         p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn()));
                 template.postForObject(upldNotifyUrl + "/sendById",
                         new PureCodeName(p.getSid(), socketMsg.toJSONString()), String.class);
+                return new int[] {fees.size(), 0};
             }
         }
+        return new int[]{0, 0};
     }
 
     public ResultVo<String> hospitalizationPreSettlement(ZyPatientInfo p, Overview o) {