Pārlūkot izejas kodu

优化门诊结算,主要针对结算超时的单边账

lighter 8 mēneši atpakaļ
vecāks
revīzija
86318bda89

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>SiMzFeeOprnSystm</artifactId>
-    <version>3.0.4</version>
+    <version>3.0.6</version>
     <name>SiMzFeeOprnSystm</name>
     <description>SiMzFeeOprnSystm</description>
     <properties>

+ 31 - 48
src/main/java/thyyxxk/simzfeeoprnsystm/dao/SiMzDao.java

@@ -2,7 +2,6 @@ package thyyxxk.simzfeeoprnsystm.dao;
 
 import thyyxxk.simzfeeoprnsystm.pojo.*;
 import org.apache.ibatis.annotations.*;
-import thyyxxk.simzfeeoprnsystm.pojo.mobilepay.*;
 
 import java.util.Date;
 import java.util.List;
@@ -10,25 +9,19 @@ import java.util.List;
 @Mapper
 public interface SiMzDao {
     @Select("select count(1) from t_si_pat_info where pat_no=#{patNo} and times=#{times}")
-    int selectExistCount(@Param("patNo") String patNo,
-                         @Param("times") int times);
+    int selectExistCount(String patNo, int times);
 
     @Update("update t_si_pat_info set times=#{times} where pat_no=#{patNo} and times=-1")
-    int updateMzTimes(@Param("patNo") String patNo,
-                      @Param("times") int times);
+    int updateMzTimes(String patNo, int times);
 
     @Delete("delete from t_si_pat_info where pat_no=#{patNo} and times=-1")
-    void deleteTempPatinfo(@Param("patNo") String patNo,
-                           @Param("times") int times);
+    void deleteTempPatinfo(String patNo, int times);
 
     @Select("select * from t_si_pat_info where pat_no=#{patNo} and times=#{times}")
-    SiPatInfo selectSiPatInfoForMz(@Param("patNo") String patNo,
-                                   @Param("times") int times);
+    SiPatInfo selectSiPatInfoForMz(String patNo, int times);
 
     @Update("update t_si_pat_info set mdtrt_id=#{nullCtnt}, setl_id=#{nullCtnt} where pat_no=#{patientId} and times=#{times} ")
-    void clearMdtrtIdForMz(@Param("patientId") String patientId,
-                           @Param("times") int times,
-                           @Param("nullCtnt") String nullCtnt);
+    void clearMdtrtIdForMz(String patientId, int times, String nullCtnt);
 
     @Select("select a.psn_no, mdtrtCertType='02',b.visit_date as begntime, " +
             "a.certno as mdtrtCertNo,a.psn_cert_type,a.certno,a.psn_name, " +
@@ -40,16 +33,14 @@ public interface SiMzDao {
             "(select t.si_caty from zd_unit_code t where t.code=b.visit_dept_code)) " +
             "from t_si_pat_info a, mz_visit_table b where a.pat_no=#{patNo} and a.times=#{times} " +
             "and a.pat_no=b.patient_id and a.times=b.times")
-    Regstrtn selectRegstrtn(@Param("patNo") String patNo, @Param("times") int times);
+    Regstrtn selectRegstrtn(String patNo, int times);
 
     @Select("select times from mz_patient_mi where patient_id=#{patientId} ")
-    Integer selectMaxTimes(@Param("patientId") String patientId);
+    Integer selectMaxTimes(String patientId);
 
     @Select("select insuplc_admdvs from t_si_pat_info where " +
             "pat_no=#{patNo} and times=#{times} and ledger_sn=#{ledgerSn}")
-    String selectAdmdvs(@Param("patNo") String patNo,
-                        @Param("times") int times,
-                        @Param("ledgerSn") int ledgerSn);
+    String selectAdmdvs(String patNo, int times, int ledgerSn);
 
     @Update("update t_si_pat_info set insuplc_admdvs=#{insuplcAdmdvs},psn_type=#{psnType},emp_name=#{empName}," +
             "mdtrt_id=#{mdtrtId},insutype=#{insutype},visit_datetime=#{visitDate},balc=#{balc} " +
@@ -57,7 +48,7 @@ public interface SiMzDao {
     void afterRegistrtn(MzPatientInfo p);
 
     @Update("update t_si_pat_info set med_type=#{medtype} where pat_no=#{patNo} and times=#{times}")
-    void updateMedtype(@Param("medtype") String medtype, @Param("patNo") String patNo, @Param("times") int times);
+    void updateMedtype(String medtype, String patNo, int times);
 
     @Select("select feedetlSn=(patient_id + '_' + cast(times as varchar) + '_' + cast(receipt_no as varchar) + '_' + " +
             "cast(order_no as varchar) + '_' + cast(item_no as varchar)), " +
@@ -71,27 +62,22 @@ public interface SiMzDao {
             "ordersDrCode=(select rtrim(yb_code) from a_employee_mi where code=input_staff), " +
             "input_man as bilgDrName,input_man as ordersDrName " +
             "from t_mt_receipt where patient_id=#{patNo} and times=#{times} and yb_trans_flag=0 ")
-    List<FeeDetail> selectOutpatientFees(@Param("patNo") String patNo, @Param("times") int times);
+    List<FeeDetail> selectOutpatientFees(String patNo, int times);
 
     @Update("update t_mt_receipt set yb_trans_flag=1,chrgitm_lv=#{chrgLv},med_chrgitm_type=#{chrgType} where " +
             "patient_id=#{patNo} and times=#{times} and receipt_no=#{recNo} and order_no=#{odrNo} and item_no=#{itmNo}")
-    void afterUploadFees(@Param("patNo") String patNo,
-                         @Param("times") int times,
-                         @Param("recNo") int recNo,
-                         @Param("odrNo") int odrNo,
-                         @Param("itmNo") int itmNo,
-                         @Param("chrgLv") String chrgLv,
-                         @Param("chrgType") String chrgType);
+    void afterUploadFees(String patNo, int times, int recNo, int odrNo,
+                         int itmNo, String chrgLv, String chrgType);
 
     @Update("update t_mt_receipt set yb_trans_flag=0 where patient_id=#{patNo} and times=#{times}")
-    void afterRevokeFees(@Param("patNo") String patNo, @Param("times") int times);
+    void afterRevokeFees(String patNo, int times);
 
     @Select("select psn_no,insuplc_admdvs,mdtrtCertType='02',certno as mdtrtCertNo,certno, " +
             "psn_cert_type,psn_type,psn_name,med_type,mdtrt_id,insutype, " +
             "medfeeSumamt=(select sum(t.charge_fee) from t_mt_receipt t where " +
             "t.patient_id=#{patNo} and t.times=#{times}) " +
             "from t_si_pat_info where pat_no=#{patNo} and times=#{times}")
-    MzPreSetlmt selectPreSetlmt(@Param("patNo") String patNo, @Param("times") int times);
+    MzPreSetlmt selectPreSetlmt(String patNo, int times);
 
     @Select("select diagType='1', " +
             "diagSrtNo=1, " +
@@ -103,18 +89,17 @@ public interface SiMzDao {
             "visit_date as diagTime, " +
             "valiFlag='1' " +
             "from mz_visit_table where patient_id=#{patNo} and times=#{times}")
-    Diagnoses selectDiseinfo(@Param("patNo") String patNo, @Param("times") int times);
+    Diagnoses selectDiseinfo(String patNo, int times);
 
     @Update("update t_si_pat_info set dise_code=#{code},dise_name=#{name} where pat_no=#{patNo} and times=#{times}")
-    void updatePatDiseinfo(@Param("patNo") String patNo, @Param("times") int times,
-                           @Param("code") String code, @Param("name") String name);
+    void updatePatDiseinfo(String patNo, int times, String code, String name);
 
     @Update("update t_si_pat_info set fulamt_ownpay_amt=#{fulamtOwnpayAmt}, overlmt_amt=#{overlmtAmt}, " +
             "preselfpay_amt=#{preselfpayAmt}, inscp_scp_amt=#{inscpScpAmt} where pat_no=#{patNo} and times=#{times}")
     void updateSortOfAmt(SiPatInfo patInfo);
 
     @Select("select top 1 * from t_si_setlinfo where pat_no=#{patNo} and times=#{times} and revoked=#{revoked} order by setl_time desc")
-    SiSetlinfo selectSettledInfo(@Param("patNo") String patNo, @Param("times") int times, @Param("revoked") int revoked);
+    SiSetlinfo selectSettledInfo(String patNo, int times, int revoked);
 
     @Select("select psn_no,certno as mdtrtCertNo,mdtrtCertType='02', " +
             "psn_cert_type,certno,med_type,insuplc_admdvs, " +
@@ -122,51 +107,49 @@ public interface SiMzDao {
             "mdtrt_id,insutype,fulamt_ownpay_amt,overlmt_amt as overlmtSelfpay, " +
             "preselfpay_amt,inscp_scp_amt " +
             "from t_si_pat_info where pat_no=#{patNo} and times=#{times}")
-    Setlmt selectSetlmt(@Param("patNo") String patNo, @Param("times") int times);
+    Setlmt selectSetlmt(String patNo, int times);
 
     @Update("update t_si_setlinfo set revoked=1,mz_saved=0 where pat_no=#{patNo} and times=#{times}")
-    void deleteSetlInfo(@Param("patNo") String patNo, @Param("times") int times);
+    void deleteSetlInfo(String patNo, int times);
 
     @Update("delete from t_si_setldetail where pat_no=#{patNo} and times=#{times}")
-    void deleteSetlDetail(@Param("patNo") String patNo, @Param("times") int times);
+    void deleteSetlDetail(String patNo, int times);
 
     @Update("update t_si_pat_info set rvk_setl_msgid=#{rvkSetlMsgid} where pat_no=#{patNo} and times=#{times}")
-    void updateRvkSetlMsgid(@Param("patNo") String patNo, @Param("times") int times, @Param("rvkSetlMsgid") String rvkSetlMsgid);
+    void updateRvkSetlMsgid(String patNo, int times, String rvkSetlMsgid);
 
     @Select("select a.diag_srt_no,a.diag_type,a.diag_code,a.diag_name,a.diag_dept, " +
             "a.dise_dor_name,a.diag_time,a.vali_flag,dise_dor_no=rtrim(b.yb_code) " +
             "from t_si_mz_diag a, a_employee_mi b where pat_no=#{patNo} and times=#{times} and a.dise_dor_no=b.code")
-    List<Diagnoses> selectMzDiags(@Param("patNo") String patNo, @Param("times") int times);
+    List<Diagnoses> selectMzDiags(String patNo, int times);
 
     @Select("select icd_code_new from mz_visit_table where patient_id=#{patNo} and times=#{times}")
-    String selectIcdCodeNew(@Param("patNo") String patNo, @Param("times") int times);
+    String selectIcdCodeNew(String patNo, int times);
 
     @Select("select top 1 rtrim(yb_name) from zd_icd_code_new where yb_code=#{code}")
-    String selectIcdTextNew(@Param("code") String code);
+    String selectIcdTextNew(String code);
 
     @Select("select visit_date from mz_visit_table with(nolock) where patient_id=#{patNo} and times=#{times} ")
-    Date selectBegntime(@Param("patNo") String patNo, @Param("times") int times);
+    Date selectBegntime(String patNo, int times);
 
     @Delete("delete from t_mt_receipt where patient_id=#{patNo} and times=#{times}")
-    void deleteAllReceipts(@Param("patNo") String patNo,
-                           @Param("times") Integer times);
+    void deleteAllReceipts(String patNo, int times);
 
     @Select("select b.si_caty as visitDeptCode,rtrim(c.name) as visitDeptName " +
             "from mz_visit_table a, zd_unit_code b, t_yb_dept c where " +
             "a.patient_id=#{patNo} and a.times=#{times} and a.visit_dept_code=b.code " +
             "and b.si_caty=c.code")
-    MzVisit selectMzVisitInfo(@Param("patNo") String patNo,
-                              @Param("times") Integer times);
+    MzVisit selectMzVisitInfo(String patNo, int times);
 
     @Select("select rtrim(dept_code) from a_employee_mi where code=#{code} and isnull(del_flag, '0')!='1'")
-    String selectStaffDepartment(@Param("code") String code);
+    String selectStaffDepartment(String code);
 
     @Select("select his_item_code from t_mt_receipt where patient_id=#{patNo} and times=#{times}")
-    List<String> selectHisChargeCodes(@Param("patNo") String patNo, @Param("times") int times);
+    List<String> selectHisChargeCodes(String patNo, int times);
 
     @Select("select acct_pay from t_si_presetlinfo where mdtrt_id=#{mdtrtId}")
-    Double selectAcctPayInPreSettle(@Param("mdtrtId") String mdtrtId);
+    Double selectAcctPayInPreSettle(String mdtrtId);
 
     @Select("select rtrim(social_no) from mz_patient_mi where patient_id=#{patNo}")
-    String selectSocialNo(@Param("patNo") String patNo);
+    String selectSocialNo(String patNo);
 }

+ 10 - 0
src/main/java/thyyxxk/simzfeeoprnsystm/pojo/SiSetldetail.java

@@ -11,6 +11,16 @@ public class SiSetldetail implements Serializable {
 
 	private static final long serialVersionUID =  1691016964788042310L;
 
+	/**
+	 * 结算ID
+	 * */
+	private String setlId;
+
+	/**
+	 * 序号
+	 * */
+	private Integer sortNo;
+
 	/**
 	 * 住院号/门诊号
 	 */

+ 3 - 0
src/main/java/thyyxxk/simzfeeoprnsystm/pojo/SiSetlinfo.java

@@ -8,6 +8,7 @@ import org.springframework.format.annotation.DateTimeFormat;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 @Data
 @TableName(value = "t_si_setlinfo")
@@ -284,4 +285,6 @@ public class SiSetlinfo implements Serializable {
 	private String clrOptinsName;
 	@TableField(exist = false)
 	private Integer payCount;
+	@TableField(exist = false)
+	private List<SiSetldetail> setldetail;
 }

+ 74 - 34
src/main/java/thyyxxk/simzfeeoprnsystm/service/SiMzFeeService.java

@@ -3,6 +3,7 @@ package thyyxxk.simzfeeoprnsystm.service;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.client.RestTemplate;
 import thyyxxk.simzfeeoprnsystm.dao.*;
 import thyyxxk.simzfeeoprnsystm.dicts.*;
 import thyyxxk.simzfeeoprnsystm.external.WebHisService;
@@ -458,6 +459,9 @@ public class SiMzFeeService {
         if (null == setlmt) {
             return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有此患者的医保就诊信息。");
         }
+        p.setInsuplcAdmdvs(setlmt.getInsuplcAdmdvs());
+        p.setPsnNo(setlmt.getPsnNo());
+        p.setMdtrtId(setlmt.getMdtrtId());
         JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_SETTLEMENT,
                 setlmt.getInsuplcAdmdvs(), p.getStaffId());
         ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
@@ -502,48 +506,84 @@ public class SiMzFeeService {
         if (infcode == 0) {
             JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo");
             SiSetlinfo setlEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class);
-            setlEntity.setPatNo(p.getPatNo());
-            setlEntity.setTimes(p.getTimes());
-            setlEntity.setLedgerSn(0);
-            setlEntity.setStaffId(p.getStaffId());
-            setlEntity.setRevoked(YesOrNo.NO.getCode());
-            setlEntity.setSetlType(ClrType.OUTPATIENT.getCode());
-            setlEntity.setInsuplcAdmdvs(setlmt.getInsuplcAdmdvs());
-            setlEntity.setBegntime(mzDao.selectBegntime(p.getPatNo(), p.getTimes()));
-            setlEntity.setEndtime(setlEntity.getSetlTime());
-            setlEntity.setMzSaved(p.getSaved());
-            BigDecimal hospitalPart = BigDecimal.ZERO;
+
+            List<SiSetldetail> fundList = new ArrayList<>();
             JSONArray setldetail = result.getJSONObject(OUTPUT).getJSONArray("setldetail");
             for (int i = 0; i < setldetail.size(); i++) {
                 SiSetldetail setldetailEntity = JSONObject.parseObject(setldetail.getJSONObject(i).toJSONString(),
                         SiSetldetail.class);
-                setldetailEntity.setPatNo(p.getPatNo());
-                setldetailEntity.setTimes(p.getTimes());
-                setldetailEntity.setLedgerSn(0);
-                if (setldetailEntity.getFundPayType().equals("999996") || setldetailEntity.getSetlProcInfo().equals("999996")) {
-                    hospitalPart = hospitalPart.add(BigDecimal.valueOf(setldetailEntity.getFundPayamt()));
-                }
-                setldetailDao.insert(setldetailEntity);
+                fundList.add(setldetailEntity);
             }
-            setlEntity.setHospPartAmt(hospitalPart.doubleValue());
-            setlinfoDao.insert(setlEntity);
-            setlinfoDao.updateSiZyInfoSetlId(p.getPatNo(), p.getTimes(), 0, setlEntity.getSetlId(),
-                    setlEntity.getMedinsSetlId(), input.getString("msgid"));
-            webHisService.saveCumInfo(webHisUrl, setlEntity);
-
-            if (!p.getStraitSettle() && BigDecimal.ZERO.compareTo(BigDecimal.valueOf(setlEntity.getPsnCashPay())) == 0) {
-                ResultVo<String> mzChargeResponse = mzHisChargeProcess(p.getPatNo(), p.getTimes(),
-                        String.valueOf(setlEntity.getMedfeeSumamt()));
-                if (mzChargeResponse.getCode() != ExceptionEnum.SUCCESS.getCode()) {
-                    revokeOutpatientSettlementForTask(setlEntity);
-                    return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, mzChargeResponse.getMessage());
-                }
+            setlEntity.setSetldetail(fundList);
+            return dealSetlEntity(p, setlEntity);
+        }
+        String errMsg = result.getString(ERROR_MESSAGE);
+        if (errMsg.contains("服务提供者后端服务响应超时")) {
+            SiSetlinfo setlEntity = querySettlementInfo(p);
+            if (null != setlEntity) {
+                return dealSetlEntity(p, setlEntity);
             }
+        }
+        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, errMsg);
+    }
 
-            setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes());
-            return getFundDetailFromSetlinfo(setlEntity);
+    private ResultVo<FundDetail> dealSetlEntity(MzPatientInfo p, SiSetlinfo setlEntity) {
+        saveSetlinfoToDatabase(setlEntity, p);
+        if (!p.getStraitSettle() && BigDecimal.ZERO.compareTo(BigDecimal.valueOf(setlEntity.getPsnCashPay())) == 0) {
+            ResultVo<String> mzChargeResponse = mzHisChargeProcess(p.getPatNo(), p.getTimes(),
+                    String.valueOf(setlEntity.getMedfeeSumamt()));
+            if (mzChargeResponse.getCode() != ExceptionEnum.SUCCESS.getCode()) {
+                revokeOutpatientSettlementForTask(setlEntity);
+                return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, mzChargeResponse.getMessage());
+            }
         }
-        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
+        setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes());
+        return getFundDetailFromSetlinfo(setlEntity);
+    }
+
+    private SiSetlinfo querySettlementInfo(MzPatientInfo p) {
+        String url = "http://172.16.32.167:8077/siQuery/querySettlementInfo";
+        JSONObject params = new JSONObject();
+        params.put("psnNo", p.getPsnNo());
+        params.put("mdtrtId", p.getMdtrtId());
+        ResultVo<SiSetlinfo> vo = new RestTemplate().postForObject(url, params, ResultVo.class);
+        if (null == vo || vo.getCode() != ExceptionEnum.SUCCESS.getCode()) {
+            return null;
+        }
+        return vo.getData();
+    }
+
+    private void saveSetlinfoToDatabase(SiSetlinfo setlEntity, MzPatientInfo p) {
+        setlEntity.setPatNo(p.getPatNo());
+        setlEntity.setTimes(p.getTimes());
+        setlEntity.setLedgerSn(0);
+        setlEntity.setStaffId(p.getStaffId());
+        setlEntity.setRevoked(YesOrNo.NO.getCode());
+        setlEntity.setSetlType(ClrType.OUTPATIENT.getCode());
+        setlEntity.setInsuplcAdmdvs(p.getInsuplcAdmdvs());
+        setlEntity.setBegntime(mzDao.selectBegntime(p.getPatNo(), p.getTimes()));
+        setlEntity.setEndtime(setlEntity.getSetlTime());
+        setlEntity.setMzSaved(p.getSaved());
+        BigDecimal hospitalPart = BigDecimal.ZERO;
+        List<SiSetldetail> fundList = setlEntity.getSetldetail();
+        fundList = null == fundList ? new ArrayList<>() : fundList;
+        for (int i = 0; i < fundList.size(); i++) {
+            SiSetldetail detail = fundList.get(i);
+            detail.setPatNo(p.getPatNo());
+            detail.setTimes(p.getTimes());
+            detail.setSetlId(setlEntity.getSetlId());
+            detail.setSortNo(i + 1);
+            detail.setLedgerSn(0);
+            if (detail.getFundPayType().equals("999996") || detail.getSetlProcInfo().equals("999996")) {
+                hospitalPart = hospitalPart.add(BigDecimal.valueOf(detail.getFundPayamt()));
+            }
+            setldetailDao.insert(detail);
+        }
+        setlEntity.setHospPartAmt(hospitalPart.doubleValue());
+        setlinfoDao.insert(setlEntity);
+        setlinfoDao.updateSiZyInfoSetlId(p.getPatNo(), p.getTimes(), 0, setlEntity.getSetlId(),
+                setlEntity.getMedinsSetlId(), setlEntity.getMedinsSetlId());
+        webHisService.saveCumInfo(webHisUrl, setlEntity);
     }
 
     public ResultVo<FundDetail> revokeOutpatientSettlement(MzPatientInfo p) {