Преглед на файлове

收费后医保结算,修改处方后关闭订单

lighter преди 1 година
родител
ревизия
8456fd5d79

+ 12 - 1
src/main/java/thyyxxk/wxservice_server/controller/WxApiController.java

@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import thyyxxk.wxservice_server.config.auth.PassToken;
+import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
 import thyyxxk.wxservice_server.entity.ResultVo;
 import thyyxxk.wxservice_server.entity.appointment.DoctorInfo;
 import thyyxxk.wxservice_server.entity.wxapi.*;
@@ -99,7 +100,17 @@ public class WxApiController {
     @PassToken
     @PostMapping("/closeWxOrder")
     public ResultVo<String> closeWxOrder(@RequestBody WxPayOrder order) {
-        return service.closeWxOrder(order);
+        String response = service.closeWxOrder(order);
+        if (response.equals("SUCCESS")) {
+            return ResultVoUtil.success("关闭订单成功。");
+        }
+        return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, response);
+    }
+
+    @PassToken
+    @PostMapping("/closeUnpaidWxOrder")
+    public void closeUnpaidWxOrder(@RequestParam("hisOrdNum") String hisOrdNum) {
+        service.closeUnpaidWxOrder(hisOrdNum);
     }
 
     @PassToken

+ 7 - 0
src/main/java/thyyxxk/wxservice_server/dao/WxApiDao.java

@@ -118,6 +118,10 @@ public interface WxApiDao {
             "a.code not in ('00000', '00026') and isnull(a.del_flag,0)<>1")
     DoctorInfo selectDoctorInfo(@Param("doctorCode") String doctorCode);
 
+    @Select("select trade_no from t_wechat_pay_order where his_ord_num=#{hisOrdNum} " +
+            "and trade_state not in ('SUCCESS','CLOSED')")
+    List<String> selectTradeNoByHisOrdNum(@Param("hisOrdNum") String hisOrdNum);
+
     @Select("select trade_state from t_wechat_pay_order with(nolock) where trade_no=#{tradeNo}")
     Transaction.TradeStateEnum selectOrderStatus(@Param("tradeNo") String tradeNo);
 
@@ -133,4 +137,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);
 }

+ 24 - 1
src/main/java/thyyxxk/wxservice_server/service/SavePayResultService.java

@@ -5,15 +5,19 @@ import com.alibaba.fastjson.JSONObject;
 import com.wechat.pay.java.service.payments.model.Transaction;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
 import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
 import thyyxxk.wxservice_server.constant.CardCostTypes;
+import thyyxxk.wxservice_server.constant.medins.FundDetail;
 import thyyxxk.wxservice_server.dao.InpatientDao;
 import thyyxxk.wxservice_server.dao.WxApiDao;
 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;
@@ -39,6 +43,8 @@ public class SavePayResultService {
     private final WxRefundService refundService;
     private final PushWxMessageService pushWxMessageService;
     private final ElectronicHealthCardService healthCardService;
+    @Value("${siMzApiUrl}")
+    private String siMzApiUrl;
 
     @Autowired
     public SavePayResultService(WxApiDao dao, InpatientDao yjjDao, ThmzService thmzService, WxRefundService refundService,
@@ -151,13 +157,30 @@ public class SavePayResultService {
         return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【" + saveMzPayResponse.getMessage() +  "】自动退款失败,请联系服务中心进行退款。");
     }
 
-
     private void updateAppletHisChargeplStatus(String hisOrdNum, String tradeNo) {
         String[] patinfo = hisOrdNum.split("_");
+        medinsSettle(hisOrdNum);
         dao.updateMzSavedFlag(patinfo[0], patinfo[1]);
         dao.updateSuccessHisStatus(tradeNo);
     }
 
+    public void medinsSettle(String hisOrdNum) {
+        String[] arr = hisOrdNum.split("_");
+        Double acctPay = dao.selectPreSetlinfo(arr[0], arr[1]);
+        if (null != acctPay) {
+            JSONObject params = new JSONObject();
+            params.put("patNo", arr[0]);
+            params.put("times", arr[1]);
+            params.put("staffId", "99999");
+            if (acctPay > 0) {
+                params.put("acctUsedFlag", "1");
+            }
+            String url = siMzApiUrl + "/outpatientSettlement";
+            String response = new RestTemplate().postForObject(url, params, String.class);
+            log.info("患者自助医保结算:\n参数:{}\n结果:{}", params, JSON.toJSON(response));
+        }
+    }
+
     public ResultVo<Object> saveZyYjjInfo(WxPayOrder order) {
         int savedCount = yjjDao.selectSavedCount(order.getTradeNo(), order.getSerialNo());
         if (savedCount > 0) {

+ 23 - 11
src/main/java/thyyxxk/wxservice_server/service/WxApiService.java

@@ -252,24 +252,36 @@ public class WxApiService {
         return ResultVoUtil.success(map);
     }
 
-    public ResultVo<String> closeWxOrder(WxPayOrder order) {
-        Transaction.TradeStateEnum tradeState = dao.selectOrderStatus(order.getTradeNo());
-        if (null == tradeState) {
-            return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "订单不存在,请检查订单号是否正确。");
+    public String closeWxOrder(WxPayOrder order) {
+        String tradeNo = order.getTradeNo();
+        if (StringUtil.isBlank(tradeNo)) {
+            return "参数错误:[tradeNo]不能为空!";
         }
-        if (tradeState == Transaction.TradeStateEnum.CLOSED) {
-            return ResultVoUtil.success("订单已是关闭状态,请勿重复关闭订单。");
+        Transaction.TradeStateEnum tradeState = dao.selectOrderStatus(tradeNo);
+        if (null == tradeState) {
+            return "订单不存在。";
         }
         if (tradeState == Transaction.TradeStateEnum.SUCCESS) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR,"订单已支付,无法关闭。");
+            return "订单已支付,无法关闭。";
+        }
+        if (tradeState == Transaction.TradeStateEnum.CLOSED) {
+            return "SUCCESS";
         }
-
         WechatPayGlobalRequest request = new WechatPayGlobalRequest.Builder()
-                .outTradeNo(order.getTradeNo()).build();
+                .outTradeNo(tradeNo).build();
         new WeChatPayService().closeOrder(request);
+        dao.updatePayStatusOnly(tradeNo, Transaction.TradeStateEnum.CLOSED);
+        return "SUCCESS";
+    }
 
-        dao.updatePayStatusOnly(order.getTradeNo(), Transaction.TradeStateEnum.CLOSED);
-        return ResultVoUtil.success("关闭订单成功。");
+    public void closeUnpaidWxOrder(String hisOrdNum) {
+        List<String> tradeNos = dao.selectTradeNoByHisOrdNum(hisOrdNum);
+        for (String tradeNo : tradeNos) {
+            WechatPayGlobalRequest request = new WechatPayGlobalRequest.Builder()
+                    .outTradeNo(tradeNo).build();
+            new WeChatPayService().closeOrder(request);
+            dao.updatePayStatusOnly(tradeNo, Transaction.TradeStateEnum.CLOSED);
+        }
     }
 
     public ResultVo<DoctorInfo> getDoctorInfo(String doctorCode) {