Explorar el Código

cursor生成订单倒计时

jyc hace 1 mes
padre
commit
1ea917e800

+ 3 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/LawyerConsultationOrderVO.java

@@ -141,6 +141,9 @@ public class LawyerConsultationOrderVO implements Serializable {
     @ApiModelProperty(value = "问题场景列表")
     private List<String> lawyerLegalProblemScenarioList;
 
+    @ApiModelProperty(value = "倒計時(秒),僅待支付訂單有效,30分鐘有效期")
+    private Long countdownSeconds;
+
     @ApiModelProperty(value = "领域信息")
     private String expertiseAreaInfo;
 }

+ 50 - 5
alien-store/src/main/java/shop/alien/store/service/impl/LawyerConsultationOrderServiceImpl.java

@@ -8,12 +8,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import net.sf.jsqlparser.expression.StringValue;
 import org.apache.commons.lang.math.RandomUtils;
-import org.apache.commons.lang.time.DateUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.beans.BeanUtils;
 import org.springframework.util.StringUtils;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.LawyerConsultationOrder;
@@ -21,7 +19,6 @@ import shop.alien.entity.store.LawyerServiceArea;
 import shop.alien.entity.store.LawyerUser;
 import shop.alien.entity.store.dto.LawyerConsultationOrderDto;
 import shop.alien.entity.store.vo.LawyerConsultationOrderVO;
-import shop.alien.entity.store.vo.LifeCouponVo;
 import shop.alien.mapper.LawyerConsultationOrderMapper;
 import shop.alien.mapper.LawyerServiceAreaMapper;
 import shop.alien.mapper.LawyerUserMapper;
@@ -54,7 +51,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
 
     @Override
     public R<IPage<LawyerConsultationOrderVO>> getConsultationOrderList(int pageNum, int pageSize, String orderNumber,
-                                                                        Integer clientUserId, Integer lawyerUserId, String lawyerName, Integer orderStatus) {
+                                                                 Integer clientUserId, Integer lawyerUserId, String lawyerName, Integer orderStatus) {
         log.info("LawyerConsultationOrderServiceImpl.getConsultationOrderList?pageNum={},pageSize={},orderNumber={},clientUserId={},lawyerUserId={},lawyerName={},orderStatus={}",
                 pageNum, pageSize, orderNumber, clientUserId, lawyerUserId, lawyerName, orderStatus);
         
@@ -85,6 +82,30 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
         IPage<LawyerConsultationOrderVO> voPage = consultationOrderMapper.getConsultationOrderListWithLawyer(
                 page, orderNumber, clientUserId, lawyerUserId, lawyerName, orderStatus, lawyerUserIds);
 
+        // 為待支付訂單計算倒計時(30分鐘有效期)
+        if (voPage != null && voPage.getRecords() != null) {
+            Date now = new Date();
+            long validitySeconds = 30 * 60; // 30分鐘 = 1800秒
+            
+            for (LawyerConsultationOrderVO vo : voPage.getRecords()) {
+                // 僅對待支付訂單(orderStatus=0)計算倒計時
+                if (vo.getOrderStatus() != null && vo.getOrderStatus() == 0) {
+                    Date orderTime = vo.getOrderTime();
+                    if (orderTime != null) {
+                        long elapsedSeconds = (now.getTime() - orderTime.getTime()) / 1000;
+                        long remainingSeconds = validitySeconds - elapsedSeconds;
+                        // 如果已過期,設置為0
+                        vo.setCountdownSeconds(Math.max(0, remainingSeconds));
+                    } else {
+                        vo.setCountdownSeconds(0L);
+                    }
+                } else {
+                    // 非待支付訂單,倒計時為null
+                    vo.setCountdownSeconds(null);
+                }
+            }
+        }
+
         return R.data(voPage);
     }
 
@@ -326,6 +347,30 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
         
         // 填充律师问题场景信息
         fillLawyerServiceArea(voPage);
+
+        // 為待支付訂單計算倒計時(30分鐘有效期)
+        if (voPage != null && voPage.getRecords() != null) {
+            Date now = new Date();
+            long validitySeconds = 30 * 60; // 30分鐘 = 1800秒
+
+            for (LawyerConsultationOrderVO vo : voPage.getRecords()) {
+                // 僅對待支付訂單(orderStatus=0)計算倒計時
+                if (vo.getOrderStatus() != null && vo.getOrderStatus() == 0) {
+                    Date orderTime = vo.getOrderTime();
+                    if (orderTime != null) {
+                        long elapsedSeconds = (now.getTime() - orderTime.getTime()) / 1000;
+                        long remainingSeconds = validitySeconds - elapsedSeconds;
+                        // 如果已過期,設置為0
+                        vo.setCountdownSeconds(Math.max(0, remainingSeconds));
+                    } else {
+                        vo.setCountdownSeconds(0L);
+                    }
+                } else {
+                    // 非待支付訂單,倒計時為null
+                    vo.setCountdownSeconds(null);
+                }
+            }
+        }
         
         return R.data(voPage);
     }