|
@@ -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());
|
|
|
}
|
|
|
+
|
|
|
}
|