Prechádzať zdrojové kódy

驳回预约自动退款。

lighter 4 rokov pred
rodič
commit
56056afce0

+ 5 - 1
src/main/java/thyyxxk/wxservice_server/controller/BookableController.java

@@ -37,8 +37,12 @@ public class BookableController {
     }
 
     @PostMapping("/saveBookPrescription")
-    public ResultVo<String> saveBookPrescription(@RequestBody BookedExamination param) throws InterruptedException {
+    public ResultVo<Integer> saveBookPrescription(@RequestBody BookedExamination param) throws InterruptedException {
         return service.saveBookPrescription(param);
     }
 
+    @GetMapping("/revokeBookPrescription")
+    public ResultVo<String> revokeBookPrescription(@RequestParam("reqNo") Integer reqNo) {
+        return service.revokeBookPrescription(reqNo);
+    }
 }

+ 13 - 2
src/main/java/thyyxxk/wxservice_server/dao/BookableDao.java

@@ -3,7 +3,9 @@ package thyyxxk.wxservice_server.dao;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
 import thyyxxk.wxservice_server.entity.bookable.ExamItem;
+import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
 
 import java.util.List;
 
@@ -20,15 +22,24 @@ public interface BookableDao {
     List<ExamItem> getBookableData(@Param("tableName") String tableName);
 
     @Select("select count(1) from mz_yj_req where patient_id=#{patientId} and pay_mark=5 and " +
-            "order_code=#{code} and req_doctor='99999'")
+            "order_code=#{code} and isnull(del_flag,0)=0 and req_doctor='99999' and datediff(day,req_date,getdate())<=3")
     int reqNoExist(@Param("patientId") String patientId,
                         @Param("code") String code);
 
     @Select("select req_no from mz_yj_req where patient_id=#{patientId} and pay_mark=5 and " +
-            "order_code=#{code} and req_doctor='99999'")
+            "order_code=#{code} and isnull(del_flag,0)=0 and req_doctor='99999' and datediff(day,req_date,getdate())<=3")
     Integer selectReqNo(@Param("patientId") String patientId,
                         @Param("code") String code);
 
     @Select("select pay_mark from mz_yj_req where req_no=#{reqNo}")
     Integer selectPayMarkByReqNo(@Param("reqNo") int reqNo);
+
+    /**
+     * @param flag 0:正常,1:自动取消,2:驳回
+     * */
+    @Update("update mz_yj_req set del_flag=#{flag} where req_no=#{reqNo}")
+    void revokeMzYjReq(@Param("reqNo") int reqNo, @Param("flag") int flag);
+
+    @Select("select * from t_wechat_pay_order where yj_req_no=#{reqNo}")
+    WxPayOrder selectWxPayOrder(@Param("reqNo") int reqNo);
 }

+ 1 - 0
src/main/java/thyyxxk/wxservice_server/entity/appointment/WeChatPayParam.java

@@ -28,6 +28,7 @@ public class WeChatPayParam {
     private String patientId;
     private String hisOrdNum;
     private Integer mzyRequestId;
+    private Integer yjReqNo;
     private String inpatientNo;
     private Integer admissTimes;
 }

+ 1 - 0
src/main/java/thyyxxk/wxservice_server/entity/wxapi/WxPayOrder.java

@@ -40,6 +40,7 @@ public class WxPayOrder {
     private Date payDatetime;
     private String hisOrdNum;
     private Integer mzyRequestId;
+    private Integer yjReqNo;
     /**
      * 订单状态,99:初值,0:未支付,1:支付成功,2:已关闭,3:支付失败,4:已退款,5:已接收,等待扣款,6:用户支付中,7:退款失败
      * */

+ 22 - 4
src/main/java/thyyxxk/wxservice_server/service/BookableService.java

@@ -16,6 +16,7 @@ import thyyxxk.wxservice_server.entity.bookable.BookedExamination;
 import thyyxxk.wxservice_server.entity.bookable.Prescription;
 import thyyxxk.wxservice_server.entity.hrgresponse.HrgCommonResponse;
 import thyyxxk.wxservice_server.entity.hrgresponse.SaveMzFeeResponse;
+import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
 import thyyxxk.wxservice_server.utils.CastUtil;
 import thyyxxk.wxservice_server.utils.DateUtil;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
@@ -32,14 +33,16 @@ import java.util.concurrent.TimeUnit;
 @Service
 public class BookableService {
     private final BookableDao dao;
+    private final WxApiService wxApiService;
     DelayQueue<BookedExamination> queue = new DelayQueue<>();
 
     @Value("${hrgApiUrl}")
     private String hrgApiUrl;
 
     @Autowired
-    public BookableService(BookableDao dao) {
+    public BookableService(BookableDao dao, WxApiService wxApiService) {
         this.dao = dao;
+        this.wxApiService = wxApiService;
     }
 
     public ResultVo<List<ExamItem>> getBookableData(String tableName) {
@@ -58,6 +61,7 @@ public class BookableService {
                 if (null != payMark && payMark == 5) {
                     String url = hrgApiUrl + "/cancelApplyScheduleOfMedical?scheduleId=" + bookedItem.getId();
                     HrgCommonResponse res = restTemplate.getForObject(url, HrgCommonResponse.class);
+                    dao.revokeMzYjReq(bookedItem.getReqNo(), 1);
                     log.info("自动取消未支付的检验检查预约结果:{},容器剩余:{}", res, queue.size());
                 }
             } catch (InterruptedException e) {
@@ -103,7 +107,7 @@ public class BookableService {
         return ResultVoUtil.success(resultMap);
     }
 
-    public ResultVo<String> saveBookPrescription(BookedExamination param) throws InterruptedException {
+    public ResultVo<Integer> saveBookPrescription(BookedExamination param) throws InterruptedException {
         int reqNoExist = dao.reqNoExist(param.getPatientId(), param.getCode());
         if (reqNoExist > 0) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您有未缴费的相同预约,无法继续预约,敬请谅解。");
@@ -145,14 +149,28 @@ public class BookableService {
         if (0 != hrgCommonResponse.getCode()) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgCommonResponse.getMessage());
         }
-
         long beginTime = System.currentTimeMillis();
         param.setReqNo(reqNo);
         param.setCreateTime(new Date());
         param.setCancelTime(new Date(beginTime + 30 * 60 * 1000L));
         queue.add(param);
         log.info("添加新的检验检查预约到待支付列表:{},容器剩余:{}", param.getId(), queue.size());
-        return ResultVoUtil.success(hrgCommonResponse.getMessage());
+        return ResultVoUtil.success(reqNo);
     }
 
+    public ResultVo<String> revokeBookPrescription(Integer reqNo) {
+        dao.revokeMzYjReq(reqNo, 2);
+        queue.removeIf(item -> item.getReqNo().equals(reqNo));
+        log.info("【reqNo: {}】驳回检查预约,容器剩余:{}", reqNo, queue.size());
+        WxPayOrder order = dao.selectWxPayOrder(reqNo);
+        if (order.getPayStatus() == 1) {
+            ResultVo<String> refund = wxApiService.autoRefund(order.getTradeNo(), "驳回检查检验预约,自动退款。");
+            log.info("【reqNo: {}】驳回检查预约,自动退款结果:{}", reqNo, refund);
+            if (null != refund && refund.getCode() == 200) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【reqNo: " + reqNo + "】已驳回检查检验预约,自动退款成功。");
+            }
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【reqNo: " + reqNo + "】已驳回检查检验预约,自动退款失败。");
+        }
+        return ResultVoUtil.success();
+    }
 }

+ 5 - 0
src/main/java/thyyxxk/wxservice_server/utils/DateUtil.java

@@ -27,4 +27,9 @@ public class DateUtil {
         }
         return result;
     }
+
+    public static boolean orderValid(Date create) {
+        long offset = System.currentTimeMillis() - create.getTime();
+        return (offset / 1000 / 60) < 60;
+    }
 }

+ 1 - 1
src/main/resources/application-prod.yml

@@ -1,5 +1,5 @@
 server:
-  port: 8083
+  port: 8085
   servlet:
     context-path: /wxserver
 spring:

+ 3 - 3
src/main/resources/application.yml

@@ -8,7 +8,7 @@ spring:
   thymeleaf:
     cache: false
   datasource:
-    url: jdbc:jtds:sqlserver://172.16.32.168:1433/thxyhisdb
+    url: jdbc:jtds:sqlserver://172.16.32.179:1433/thxyhisdb
     hikari:
       username: sa
       password:
@@ -30,6 +30,6 @@ mybatis:
   configuration:
     map-underscore-to-camel-case: true
 
-#hrgApiUrl: http://172.16.30.33:8089/thmz/api/v1
-hrgApiUrl: http://webhis.thyy.cn:81/thmz/api/v1
+hrgApiUrl: http://172.16.30.33:8089/thmz/api/v1
+#hrgApiUrl: http://webhis.thyy.cn:81/thmz/api/v1
 inspectionUrl: http://172.16.32.178:622/pushservice.asmx?wsdl