Explorar el Código

fix gpt车票更换候补

zoujiajian hace 2 años
padre
commit
9c45db1b33

+ 7 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GptTicketStandbyMapper.java

@@ -0,0 +1,7 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.GptTicketStandby;
+
+public interface GptTicketStandbyMapper extends BaseMapper<GptTicketStandby> {
+}

+ 10 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/GptTicketStandby.java

@@ -0,0 +1,10 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class GptTicketStandby extends BaseEntity{
+    private Long userId;
+}

+ 20 - 0
netflix-dao/src/main/java/com/cyksj/model/response/GptStandbyResp.java

@@ -0,0 +1,20 @@
+package com.cyksj.model.response;
+
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class GptStandbyResp {
+
+    /**
+     * 是否有账号
+     */
+    private Boolean isHasAccount;
+
+    /**
+     * 是否申请候补
+     */
+    private Boolean isApply;
+}

+ 53 - 0
netflix-web/src/main/java/com/cyksj/web/controller/group/GroupRelationController.java

@@ -31,6 +31,7 @@ import com.cyksj.model.entity.*;
 import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.request.OrderPayRequest;
 import com.cyksj.model.request.SpecialGoodsTicketReq;
+import com.cyksj.model.response.GptStandbyResp;
 import com.cyksj.model.views.*;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.chatgpt.ChatGptAuthService;
@@ -53,6 +54,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -109,6 +111,8 @@ public class GroupRelationController {
 
     private final SysConfigService sysConfigService;
 
+    private final GptTicketStandbyMapper gptTicketStandbyMapper;
+
     private final static Sequence SEQUENCE = new Sequence(0);
 
     @RequestMapping("/get/renewal")
@@ -584,4 +588,53 @@ public class GroupRelationController {
         long userId = StpUserUtil.getLoginIdAsLong();
         return GatewayResponse.SUCCESS.newBuilder().toResult(groupRelationFrontService.getAiVerifyCode(userId, relationId));
     }
+
+    /**
+     * 是否有gpt车票可候补
+     */
+    @GetMapping("/get/standby")
+    public Result<GptStandbyResp> getGptStandby() {
+        long userId = StpUserUtil.getLoginIdAsLong();
+        List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
+        Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
+                .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
+                .field(RenewalView::getYhsId, 0)
+                .field(RenewalView::getExpiryTime).op(Operator.NotNull)
+                .build());
+        GptStandbyResp gptStandbyResp = new GptStandbyResp();
+        gptStandbyResp.setIsHasAccount(number.intValue() > 0 ? true : false);
+        if (gptStandbyResp.getIsHasAccount()) {
+            Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
+                    .in(GptTicketStandby::getUserId, relationUserIdList));
+            gptStandbyResp.setIsApply(count > 0 ? true : false);
+        }
+        return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
+    }
+
+    /**
+     * 申请候补
+     */
+    @PostMapping("/apply/standby")
+    @NoSubmit
+    public Result<Boolean> applyGptStandby() {
+        long userId = StpUserUtil.getLoginIdAsLong();
+        List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
+        Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
+                .field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
+                .field(RenewalView::getYhsId, 0)
+                .field(RenewalView::getExpiryTime).op(Operator.NotNull)
+                .build());
+        if (number.intValue() == 0) {
+            throw BusinessRuntimeException.getInstance("你未有GPT plus账号");
+        }
+        Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
+                .in(GptTicketStandby::getUserId, relationUserIdList));
+        if (count > 0) {
+            throw BusinessRuntimeException.getInstance("你已申请GPT plus账号候补");
+        }
+        GptTicketStandby gptTicketStandby = new GptTicketStandby();
+        gptTicketStandby.setUserId(userId);
+        gptTicketStandbyMapper.insert(gptTicketStandby);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(number.intValue() > 0 ? true : false);
+    }
 }