|
|
@@ -56,10 +56,9 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author chan
|
|
|
@@ -117,6 +116,8 @@ public class GroupRelationController {
|
|
|
|
|
|
private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
|
|
|
|
+ private final AccountBlockedReplaceRecordMapper accountBlockedReplaceRecordMapper;
|
|
|
+
|
|
|
private final static Sequence SEQUENCE = new Sequence(0);
|
|
|
|
|
|
@RequestMapping("/get/renewal")
|
|
|
@@ -599,19 +600,46 @@ public class GroupRelationController {
|
|
|
public Result<GptStandbyResp> getGptStandby() {
|
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
|
|
|
+ String condition = "(a.account like '%@yinhe.ac.cn%' or exists (select id from account_blocked_replace_record abrr where abrr.account = a.account and abrr.goods_id = g.id limit 1))";
|
|
|
+ List<RenewalView> renewalViewList = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
|
|
|
.field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
|
|
|
.field(RenewalView::getGoodsId, 26)
|
|
|
- .field(RenewalView::getAccount, "@yinhe.ac.cn").op(Operator.Contain)
|
|
|
- .field(RenewalView::getExpiryTime, DateUtil.offsetDay(DateTime.now(), 10)).op(Operator.GreaterThan)
|
|
|
+ .put("condition", condition)
|
|
|
+ .field(RenewalView::getExpiryTime).op(Operator.NotNull)
|
|
|
+ .onlySelect(RenewalView::getAccount, RenewalView::getExpiryTime)
|
|
|
.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);
|
|
|
+ if (renewalViewList.isEmpty()) {
|
|
|
+ gptStandbyResp.setIsHasAccount(false);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<RenewalView> overTen = new ArrayList<>();
|
|
|
+ List<RenewalView> underTen = new ArrayList<>();
|
|
|
+ DateTime now = DateTime.now();
|
|
|
+ renewalViewList.forEach(e -> {
|
|
|
+ if (e.getExpiryTime().compareTo(DateUtil.offsetDay(now, 10)) > 0) {
|
|
|
+ overTen.add(e);
|
|
|
+ } else underTen.add(e);
|
|
|
+ });
|
|
|
+
|
|
|
+ Integer accountBlockedCount = 1;
|
|
|
+ if (overTen.size() > 1) {
|
|
|
+ List<String> accountList = overTen.stream().map(RenewalView::getAccount).distinct().collect(Collectors.toList());
|
|
|
+ accountBlockedCount = accountBlockedReplaceRecordMapper.selectCount(Wrappers.lambdaQuery(AccountBlockedReplaceRecord.class)
|
|
|
+ .eq(AccountBlockedReplaceRecord::getGoodsId, 26)
|
|
|
+ .in(AccountBlockedReplaceRecord::getAccount, accountList));
|
|
|
+ }
|
|
|
+ if (accountBlockedCount > 1) {
|
|
|
+ gptStandbyResp.setIsHasAccount(false);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
|
|
|
}
|
|
|
+ gptStandbyResp.setIsHasAccount(true);
|
|
|
+ gptStandbyResp.setOverTen(overTen);
|
|
|
+ gptStandbyResp.setUnderTen(underTen);
|
|
|
+ Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
|
|
|
+ .in(GptTicketStandby::getUserId, relationUserIdList));
|
|
|
+ gptStandbyResp.setIsApply(count > 0 ? true : false);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(gptStandbyResp);
|
|
|
}
|
|
|
|
|
|
@@ -623,13 +651,15 @@ public class GroupRelationController {
|
|
|
public Result<Boolean> applyGptStandby() {
|
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
|
|
|
+ String condition = "(a.account like '%@yinhe.ac.cn%' or exists (select id from account_blocked_replace_record abrr where abrr.account = a.account and abrr.goods_id = g.id limit 1))";
|
|
|
+ List<RenewalView> renewalViewList = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
|
|
|
.field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
|
|
|
.field(RenewalView::getGoodsId, 26)
|
|
|
- .field(RenewalView::getAccount, "@yinhe.ac.cn").op(Operator.Contain)
|
|
|
+ .put("condition", condition)
|
|
|
.field(RenewalView::getExpiryTime, DateUtil.offsetDay(DateTime.now(), 10)).op(Operator.GreaterThan)
|
|
|
+ .onlySelect(RenewalView::getAccount)
|
|
|
.build());
|
|
|
- if (number.intValue() == 0) {
|
|
|
+ if (renewalViewList.isEmpty()) {
|
|
|
throw BusinessRuntimeException.getInstance("你未有车票账号");
|
|
|
}
|
|
|
Integer count = gptTicketStandbyMapper.selectCount(Wrappers.lambdaQuery(GptTicketStandby.class)
|
|
|
@@ -637,10 +667,19 @@ public class GroupRelationController {
|
|
|
if (count > 0) {
|
|
|
throw BusinessRuntimeException.getInstance("你已申请车票账号候补");
|
|
|
}
|
|
|
+ if (renewalViewList.size() > 1) {
|
|
|
+ Set<String> accountSet = renewalViewList.stream().map(RenewalView::getAccount).collect(Collectors.toSet());
|
|
|
+ Integer accountBlockedCount = accountBlockedReplaceRecordMapper.selectCount(Wrappers.lambdaQuery(AccountBlockedReplaceRecord.class)
|
|
|
+ .eq(AccountBlockedReplaceRecord::getGoodsId, 26)
|
|
|
+ .in(AccountBlockedReplaceRecord::getAccount, accountSet));
|
|
|
+ if (accountBlockedCount > 1) {
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
GptTicketStandby gptTicketStandby = new GptTicketStandby();
|
|
|
gptTicketStandby.setUserId(userId);
|
|
|
gptTicketStandbyMapper.insert(gptTicketStandby);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(number.intValue() > 0 ? true : false);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(true);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -651,11 +690,12 @@ public class GroupRelationController {
|
|
|
public Result<String> ticketRefundOrders(@PathVariable Long relationId) throws Exception {
|
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
+ String condition = "(a.account like '%@yinhe.ac.cn%' or exists (select id from account_blocked_replace_record abrr where abrr.account = a.account and abrr.goods_id = g.id limit 1))";
|
|
|
RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
|
|
|
.field(RenewalView::getRelationId, relationId)
|
|
|
.field(RenewalView::getUserId, relationUserIdList).op(Operator.InList)
|
|
|
+ .put("condition", condition)
|
|
|
.field(RenewalView::getGoodsId, 26)
|
|
|
- .field(RenewalView::getAccount, "@yinhe.ac.cn").op(Operator.Contain)
|
|
|
.field(RenewalView::getExpiryTime, DateUtil.offsetDay(DateTime.now(), 10)).op(Operator.LessEqual)
|
|
|
.build());
|
|
|
if (renewalView == null) {
|