Procházet zdrojové kódy

检验检查预约30分钟后未缴费自动取消。

lighter před 4 roky
rodič
revize
aae3cc01b3

+ 1 - 1
pom.xml

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

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

@@ -22,6 +22,7 @@ public class BookableController {
     @Autowired
     public BookableController(BookableService service) {
         this.service = service;
+        this.service.startAutoCancelUnpaidOrderTask();
     }
 
     @GetMapping("/getBookableData")

+ 3 - 0
src/main/java/thyyxxk/wxservice_server/dao/BookableDao.java

@@ -28,4 +28,7 @@ public interface BookableDao {
             "order_code=#{code} and req_doctor='99999'")
     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);
 }

+ 19 - 2
src/main/java/thyyxxk/wxservice_server/entity/bookable/BookedExamination.java

@@ -2,12 +2,18 @@ package thyyxxk.wxservice_server.entity.bookable;
 
 import lombok.Data;
 
+import java.util.Date;
+import java.util.concurrent.Delayed;
+import java.util.concurrent.TimeUnit;
+
 /**
  * @author: DingJie
  * @create: 2021-04-25 14:15:23
  **/
 @Data
-public class BookedExamination {
+public class BookedExamination implements Delayed {
+    private Integer id;
+    private Integer reqNo;
     private String patientId;
     private String execUnit;
     private String code;
@@ -15,5 +21,16 @@ public class BookedExamination {
     private String recordDate;
     private String beginTime;
     private String endTime;
-    private Integer id;
+    private Date createTime;
+    private Date cancelTime;
+
+    @Override
+    public long getDelay(TimeUnit unit) {
+        return unit.convert(cancelTime.getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
+    }
+
+    @Override
+    public int compareTo(Delayed o) {
+        return this.getCancelTime().compareTo(((BookedExamination) o).getCancelTime());
+    }
 }

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

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
@@ -19,10 +20,8 @@ import thyyxxk.wxservice_server.utils.CastUtil;
 import thyyxxk.wxservice_server.utils.DateUtil;
 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.*;
+import java.util.concurrent.DelayQueue;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -33,6 +32,7 @@ import java.util.concurrent.TimeUnit;
 @Service
 public class BookableService {
     private final BookableDao dao;
+    DelayQueue<BookedExamination> queue = new DelayQueue<>();
 
     @Value("${hrgApiUrl}")
     private String hrgApiUrl;
@@ -46,6 +46,26 @@ public class BookableService {
         return ResultVoUtil.success(dao.getBookableData(tableName));
     }
 
+    @Async
+    @SuppressWarnings("InfiniteLoopStatement")
+    public void startAutoCancelUnpaidOrderTask() {
+        log.info("开启自动取消未支付的检验检查预约任务");
+        RestTemplate restTemplate = new RestTemplate();
+        while (true) {
+            try {
+                BookedExamination bookedItem = queue.take();
+                Integer payMark = dao.selectPayMarkByReqNo(bookedItem.getReqNo());
+                if (null != payMark && payMark == 5) {
+                    String url = hrgApiUrl + "/cancelApplyScheduleOfMedical?scheduleId=" + bookedItem.getId();
+                    HrgCommonResponse res = restTemplate.getForObject(url, HrgCommonResponse.class);
+                    log.info("自动取消未支付的检验检查预约结果:{},容器剩余:{}", res, queue.size());
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
     public ResultVo<Map<String, Object>> getFullScheduleOfMedicalForPlatform(BookedExamination exam) {
         String[] dateRange = DateUtil.getDatesInOneWeek();
         RestTemplate restTemplate = new RestTemplate();
@@ -125,6 +145,14 @@ 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());
     }
+
 }

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

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

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

@@ -8,7 +8,7 @@ spring:
   thymeleaf:
     cache: false
   datasource:
-    url: jdbc:jtds:sqlserver://172.16.32.179:1433/thxyhisdb
+    url: jdbc:jtds:sqlserver://172.16.32.168:1433/thxyhisdb
     hikari:
       username: sa
       password:
@@ -30,5 +30,6 @@ mybatis:
   configuration:
     map-underscore-to-camel-case: true
 
-hrgApiUrl: http://172.16.30.33:8089/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