Browse Source

全自费缴费,但又进了医保的,缴费后撤销医保业务

lighter 1 year ago
parent
commit
b747964a45

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>wxservice-server</artifactId>
-    <version>12.1.4</version>
+    <version>12.1.6</version>
     <name>wxservice-server</name>
     <description>server for wxservice-web</description>
 

+ 1 - 4
src/main/java/thyyxxk/wxservice_server/controller/PayMzFeeController.java

@@ -9,10 +9,7 @@ import thyyxxk.wxservice_server.entity.paymzfee.MedinsPresettle;
 import thyyxxk.wxservice_server.service.PayMzFeeService;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author dj

+ 3 - 2
src/main/java/thyyxxk/wxservice_server/dao/WxApiDao.java

@@ -148,6 +148,7 @@ public interface WxApiDao {
     @Update("update t_si_setlinfo set mz_saved=1 where pat_no=#{patId} and times=#{times} and revoked=0")
     void updateMzSavedFlag(@Param("patId") String patId, @Param("times") String times);
 
-    @Select("select acct_pay from t_si_presetlinfo where pat_no=#{patNo} and times=#{times}")
-    Double selectPreSetlinfo(@Param("patNo") String patNo, @Param("times") String times);
+    @Select("select medfee_sumamt,fund_pay_sumamt,acct_pay,psn_cash_pay " +
+            "from t_si_presetlinfo where pat_no=#{patNo} and times=#{times}")
+    MedinsPresettle selectPreSetlinfo(@Param("patNo") String patNo, @Param("times") String times);
 }

+ 5 - 4
src/main/java/thyyxxk/wxservice_server/entity/paymzfee/MedinsPresettle.java

@@ -5,6 +5,7 @@ import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.Date;
 
 @Data
@@ -109,7 +110,7 @@ public class MedinsPresettle implements Serializable {
 	/**
 	 * 医疗费总额
 	 */
-	private String medfeeSumamt;
+	private BigDecimal medfeeSumamt;
 
 	/**
 	 * 全自费金额
@@ -184,7 +185,7 @@ public class MedinsPresettle implements Serializable {
 	/**
 	 * 基金支付总额
 	 */
-	private String fundPaySumamt;
+	private BigDecimal fundPaySumamt;
 
 	/**
 	 * 个人负担总金额
@@ -194,12 +195,12 @@ public class MedinsPresettle implements Serializable {
 	/**
 	 * 个人账户支出
 	 */
-	private String acctPay;
+	private BigDecimal acctPay;
 
 	/**
 	 * 个人现金支出
 	 */
-	private String psnCashPay;
+	private BigDecimal psnCashPay;
 
 	/**
 	 * 余额

+ 3 - 2
src/main/java/thyyxxk/wxservice_server/service/PayMzFeeService.java

@@ -19,6 +19,7 @@ import thyyxxk.wxservice_server.factory.thmz.model.QueryReceiptRequest;
 import thyyxxk.wxservice_server.utils.DecimalTool;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -99,8 +100,8 @@ public class PayMzFeeService {
         }
         if (null == presettle) {
             presettle = new MedinsPresettle();
-            presettle.setFundPaySumamt("0.00");
-            presettle.setAcctPay("0.00");
+            presettle.setFundPaySumamt(BigDecimal.ZERO);
+            presettle.setAcctPay(BigDecimal.ZERO);
             return presettle;
         }
         presettle.setInsutypeName(Insutype.getName(presettle.getInsutype()));

+ 22 - 9
src/main/java/thyyxxk/wxservice_server/service/SavePayResultService.java

@@ -16,6 +16,7 @@ import thyyxxk.wxservice_server.entity.PureCodeName;
 import thyyxxk.wxservice_server.entity.ResultVo;
 import thyyxxk.wxservice_server.entity.electronichealthcard.HisRegister;
 import thyyxxk.wxservice_server.entity.inpatient.GetZyFeeParam;
+import thyyxxk.wxservice_server.entity.paymzfee.MedinsPresettle;
 import thyyxxk.wxservice_server.entity.wxapi.PushMessageParam;
 import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
 import thyyxxk.wxservice_server.factory.thmz.ThmzService;
@@ -24,6 +25,7 @@ import thyyxxk.wxservice_server.factory.thmz.model.SaveClinicRegisterRequest;
 import thyyxxk.wxservice_server.factory.thmz.model.SaveMzPayRequest;
 import thyyxxk.wxservice_server.utils.*;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.concurrent.TimeUnit;
 
@@ -119,7 +121,7 @@ public class SavePayResultService {
         }
         if (dao.alreadyPayed(tradeNo) > 0) {
             log.info("订单号:{} 的门诊缴费信息已保存,无需再次保存。", tradeNo);
-            updateAppletHisChargeplStatus(hisOrdNum, tradeNo, order.getCouponId());
+            updateAppletHisChargeplStatus(hisOrdNum, tradeNo, order.getCouponId(), order.getCashpayAmt());
             return payTime;
         }
         PureCodeName status = dao.selectPayStatus(tradeNo);
@@ -145,14 +147,14 @@ public class SavePayResultService {
                 .psOrdNum(tradeNo).build();
         ResultVo<String> saveMzPayResponse = thmzService.saveMzPay(request);
         if (saveMzPayResponse.getCode() == ExceptionEnum.SUCCESS.getCode()) {
-            updateAppletHisChargeplStatus(hisOrdNum, tradeNo, order.getCouponId());
+            updateAppletHisChargeplStatus(hisOrdNum, tradeNo, order.getCouponId(), order.getCashpayAmt());
             int fundpayCount = dao.selectFundPayCount(tradeNo);
             String cardCostTypes = fundpayCount > 0 ? CardCostTypes.MED_INS : CardCostTypes.SELF_PAY;
             healthCardService.reportHisData(order.getPatientId(), "0101051", null, cardCostTypes);
             return payTime;
         }
         if (dao.alreadyPayed(tradeNo) > 0) {
-            updateAppletHisChargeplStatus(hisOrdNum, tradeNo, order.getCouponId());
+            updateAppletHisChargeplStatus(hisOrdNum, tradeNo, order.getCouponId(), order.getCashpayAmt());
             return payTime;
         }
         String refund = refundService.autoRefund(tradeNo, saveMzPayResponse.getMessage());
@@ -163,25 +165,36 @@ public class SavePayResultService {
         return "ERROR:【" + saveMzPayResponse.getMessage() +  "】自动退款失败,请联系服务中心进行退款。";
     }
 
-    private void updateAppletHisChargeplStatus(String hisOrdNum, String tradeNo, String couponId) {
+    private void updateAppletHisChargeplStatus(String hisOrdNum, String tradeNo, String couponId, BigDecimal cashpayAmt) {
         String[] patinfo = hisOrdNum.split("_");
-        medinsSettle(hisOrdNum);
+        medinsSettle(hisOrdNum, cashpayAmt);
         dao.updateMzSavedFlag(patinfo[0], patinfo[1]);
         dao.updateSuccessHisStatus(tradeNo);
         dao.couponUsed(couponId);
     }
 
-    public void medinsSettle(String hisOrdNum) {
+    private void medinsSettle(String hisOrdNum, BigDecimal cashpayAmt) {
         String[] arr = hisOrdNum.split("_");
-        Double acctPay = dao.selectPreSetlinfo(arr[0], arr[1]);
-        if (null != acctPay) {
+        MedinsPresettle presettle = dao.selectPreSetlinfo(arr[0], arr[1]);
+        if (null != presettle) {
+            BigDecimal medinsPayAmt = presettle.getFundPaySumamt().add(presettle.getAcctPay());
+
             JSONObject params = new JSONObject();
             params.put("patNo", arr[0]);
             params.put("times", arr[1]);
             params.put("staffId", "99999");
-            if (acctPay > 0) {
+            if (presettle.getAcctPay().compareTo(BigDecimal.ZERO) > 0) {
                 params.put("acctUsedFlag", "1");
             }
+
+            if (medinsPayAmt.compareTo(BigDecimal.ZERO) > 0) {
+                if (presettle.getMedfeeSumamt().compareTo(cashpayAmt) <= 0) {
+                    String url = siMzApiUrl + "/revokeOutpatientSettlement";
+                    String response = new RestTemplate().postForObject(url, params, String.class);
+                    log.info("患者全自费缴费,自动撤销医保业务:\n参数:{}\n:结果:{}", params, JSON.toJSON(response));
+                    return;
+                }
+            }
             String url = siMzApiUrl + "/outpatientSettlement";
             String response = new RestTemplate().postForObject(url, params, String.class);
             log.info("患者自助医保结算:\n参数:{}\n结果:{}", params, JSON.toJSON(response));

+ 4 - 4
src/main/java/thyyxxk/wxservice_server/service/WxApiService.java

@@ -222,8 +222,8 @@ public class WxApiService {
         order.setOrderType(OrderType.OUTPATIENT.getCode());
         order.setHisOrdNum(param.getHisOrdNum());
         MedinsPresettle presettle = getFundPayAmt(param.getHisOrdNum());
-        order.setFundpayAmt(new BigDecimal(presettle.getFundPaySumamt()));
-        order.setAcctpayAmt(new BigDecimal(presettle.getAcctPay()));
+        order.setFundpayAmt(presettle.getFundPaySumamt());
+        order.setAcctpayAmt(presettle.getAcctPay());
         order.setCashpayAmt(DecimalTool.moneyFenToYuan(param.getTotalAmt()));
         order.setCouponAmt(BigDecimal.ZERO);
         order.setTotalFee(order.getFundpayAmt().add(order.getAcctpayAmt().add(order.getCashpayAmt())));
@@ -291,8 +291,8 @@ public class WxApiService {
         }
         if (null == presettle) {
             presettle = new MedinsPresettle();
-            presettle.setFundPaySumamt("0.00");
-            presettle.setAcctPay("0.00");
+            presettle.setFundPaySumamt(BigDecimal.ZERO);
+            presettle.setAcctPay(BigDecimal.ZERO);
         }
         return presettle;
     }

+ 7 - 5
src/main/java/thyyxxk/wxservice_server/utils/DecimalTool.java

@@ -18,17 +18,19 @@ public class DecimalTool {
     }
 
     public static Integer moneyYuanToFen(BigDecimal fee) {
+        if (null == fee) {
+            return 0;
+        }
         BigDecimal hundred = new BigDecimal("100");
         return fee.multiply(hundred).intValue();
     }
 
-    public static String moneyYuanToFen2(String fee) {
-        if (StringUtil.isBlank(fee)) {
-            return "0.00";
+    public static BigDecimal moneyYuanToFen2(BigDecimal fee) {
+        if (null == fee) {
+            return BigDecimal.ZERO;
         }
         BigDecimal hundred = new BigDecimal("100");
-        BigDecimal feeDecimal = new BigDecimal(fee);
-        return feeDecimal.multiply(hundred).toPlainString();
+        return fee.multiply(hundred);
     }
 
     public static BigDecimal moneyFenToYuan(Integer fee) {