perf:芬玩岛下单优化1.0
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
package com.xiang.xservice.application.script.fwd.constants;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum PriceRange {
|
||||||
|
RANGE_600_900(0, BigDecimal.valueOf(600), BigDecimal.valueOf(900)),
|
||||||
|
RANGE_900_1300(1, BigDecimal.valueOf(900), BigDecimal.valueOf(1300)),
|
||||||
|
RANGE_1300_1600(2, BigDecimal.valueOf(1300), BigDecimal.valueOf(1600)),
|
||||||
|
RANGE_OVER_1600(3, BigDecimal.valueOf(1600), null),
|
||||||
|
RANGE_UNDER_600(4, null, BigDecimal.valueOf(600));
|
||||||
|
|
||||||
|
private final int index;
|
||||||
|
private final BigDecimal min;
|
||||||
|
private final BigDecimal max;
|
||||||
|
|
||||||
|
public boolean contains(BigDecimal price) {
|
||||||
|
boolean minCondition = min == null || price.compareTo(min) > 0;
|
||||||
|
boolean maxCondition = max == null || price.compareTo(max) <= 0;
|
||||||
|
return minCondition && maxCondition;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static PriceRange fromPrice(BigDecimal price) {
|
||||||
|
return Arrays.stream(values())
|
||||||
|
.filter(range -> range.contains(price))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Invalid price: " + price));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.xiang.xservice.application.script.fwd.service.impl;
|
package com.xiang.xservice.application.script.fwd.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.xiang.xservice.basic.config.MyThreadFactory;
|
import com.xiang.xservice.application.script.fwd.constants.PriceRange;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformConfig;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformConfig;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformProjectInfo;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformProjectInfo;
|
||||||
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformSeatInfo;
|
import com.xiang.xservice.application.script.fwd.entity.pojo.FPerformSeatInfo;
|
||||||
@@ -15,6 +15,7 @@ import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
|
|||||||
import com.xiang.xservice.application.script.fwd.service.DingTalkScriptFWDService;
|
import com.xiang.xservice.application.script.fwd.service.DingTalkScriptFWDService;
|
||||||
import com.xiang.xservice.application.script.fwd.service.IPerformService;
|
import com.xiang.xservice.application.script.fwd.service.IPerformService;
|
||||||
import com.xiang.xservice.application.script.fwd.service.IPerformServiceHttp;
|
import com.xiang.xservice.application.script.fwd.service.IPerformServiceHttp;
|
||||||
|
import com.xiang.xservice.basic.config.MyThreadFactory;
|
||||||
import com.xiang.xservice.http.helper.HttpRequestHelper;
|
import com.xiang.xservice.http.helper.HttpRequestHelper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -26,12 +27,15 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,12 +90,34 @@ public class PerformServiceImpl implements IPerformService {
|
|||||||
log.info("该projectId:{}暂无座位信息", projectId);
|
log.info("该projectId:{}暂无座位信息", projectId);
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
seatInfoByProjectId = seatInfoByProjectId.stream().filter(item -> 0== item.getSoldOut()).collect(Collectors.groupingBy())
|
Map<Long, List<FPerformSeatInfo>> performMap = seatInfoByProjectId.stream().filter(item -> 0 == item.getSoldOut()).collect(Collectors.groupingBy(FPerformSeatInfo::getPerformId));
|
||||||
for (FPerformSeatInfo fPerformSeatInfo : seatInfoByProjectId) {
|
for (Long performId : performMap.keySet()) {
|
||||||
if (1 == fPerformSeatInfo.getSoldOut()) {
|
List<FPerformSeatInfo> fPerformSeatInfos = performMap.get(performId);
|
||||||
continue;
|
AtomicReference<BigDecimal> atomicPrice = new AtomicReference<>();
|
||||||
}
|
fPerformSeatInfos.stream().map(FPerformSeatInfo::getPrice).max(BigDecimal::compareTo).ifPresent(atomicPrice::set);
|
||||||
ProjectOrderCreateReq projectOrderCreateReq = buildReq(projectId, frequentIds, fPerformSeatInfo);
|
BigDecimal price = atomicPrice.get();
|
||||||
|
// 排序座位
|
||||||
|
/*
|
||||||
|
0: 600-900
|
||||||
|
1: 900-1300
|
||||||
|
2: 1300-1600
|
||||||
|
3: >1600
|
||||||
|
4: <=600
|
||||||
|
*/
|
||||||
|
List<Long> seatIds = fPerformSeatInfos.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
seat -> PriceRange.fromPrice(seat.getPrice()),
|
||||||
|
Collectors.collectingAndThen(Collectors.toList(), list -> {
|
||||||
|
Collections.shuffle(list);
|
||||||
|
return list;
|
||||||
|
})
|
||||||
|
))
|
||||||
|
.entrySet().stream()
|
||||||
|
.sorted(Comparator.comparing(entry -> entry.getKey().getIndex()))
|
||||||
|
.flatMap(entry -> entry.getValue().stream())
|
||||||
|
.map(FPerformSeatInfo::getSeatPlanId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
ProjectOrderCreateReq projectOrderCreateReq = buildReqV2(projectId, frequentIds, seatIds, performId, price);
|
||||||
for (int i = 1; i <= 10; i++) {
|
for (int i = 1; i <= 10; i++) {
|
||||||
ProjectOrderCreateResp projectOrder = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.createProjectOrder(projectOrderCreateReq, availableUser.get(0).getToken()), "create-project-order");
|
ProjectOrderCreateResp projectOrder = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.createProjectOrder(projectOrderCreateReq, availableUser.get(0).getToken()), "create-project-order");
|
||||||
if (Objects.nonNull(projectOrder)) {
|
if (Objects.nonNull(projectOrder)) {
|
||||||
@@ -104,6 +130,98 @@ public class PerformServiceImpl implements IPerformService {
|
|||||||
}
|
}
|
||||||
dingTalkService.sendScriptMsg("【芬玩岛】下单失败❌❌❌,演出名称:" + performByProjectId.getProjectName());
|
dingTalkService.sendScriptMsg("【芬玩岛】下单失败❌❌❌,演出名称:" + performByProjectId.getProjectName());
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
|
// Map<Long, List<FPerformSeatInfo>> performMap = seatInfoByProjectId.stream().filter(item -> 0 == item.getSoldOut()).collect(Collectors.groupingBy(FPerformSeatInfo::getPerformId));
|
||||||
|
// for (Long performId : performMap.keySet()) {
|
||||||
|
// List<FPerformSeatInfo> fPerformSeatInfos = performMap.get(performId);
|
||||||
|
// AtomicReference<BigDecimal> atomicPrice = new AtomicReference<>();
|
||||||
|
// fPerformSeatInfos.stream().map(FPerformSeatInfo::getPrice).max(BigDecimal::compareTo).ifPresent(atomicPrice::set);
|
||||||
|
// BigDecimal price = atomicPrice.get();
|
||||||
|
// if (Objects.isNull(price)) {continue;}
|
||||||
|
// Map<Long, FPerformSeatInfo> seatInfoMap = fPerformSeatInfos.stream().collect(Collectors.toMap(FPerformSeatInfo::getSeatPlanId, Function.identity(), (a, b) -> a));
|
||||||
|
// Map<Integer, List<FPerformSeatInfo>> seatResult = Maps.newHashMap();
|
||||||
|
// seatResult.put(0, Lists.newArrayList());
|
||||||
|
// seatResult.put(1, Lists.newArrayList());
|
||||||
|
// seatResult.put(2, Lists.newArrayList());
|
||||||
|
// seatResult.put(3, Lists.newArrayList());
|
||||||
|
// seatResult.put(4, Lists.newArrayList());
|
||||||
|
// List<FPerformSeatInfo> seats = Lists.newArrayList();
|
||||||
|
// for (Long seatInfoId : seatInfoMap.keySet()) {
|
||||||
|
// /*
|
||||||
|
// 0: 600-900
|
||||||
|
// 1: 900-1300
|
||||||
|
// 2: 1300-1600
|
||||||
|
// 3: >1600
|
||||||
|
// 4: <=600
|
||||||
|
// */
|
||||||
|
// FPerformSeatInfo fPerformSeatInfo = seatInfoMap.get(seatInfoId);
|
||||||
|
// if (fPerformSeatInfo.getPrice().compareTo(BigDecimal.valueOf(600)) > 0 && fPerformSeatInfo.getPrice().compareTo(BigDecimal.valueOf(900)) <= 0) {
|
||||||
|
// List<FPerformSeatInfo> temp = seatResult.get(0);
|
||||||
|
// temp.add(fPerformSeatInfo);
|
||||||
|
// seatResult.put(0, temp);
|
||||||
|
// }
|
||||||
|
// if (fPerformSeatInfo.getPrice().compareTo(BigDecimal.valueOf(900)) > 0 && fPerformSeatInfo.getPrice().compareTo(BigDecimal.valueOf(1300)) <= 0) {
|
||||||
|
// List<FPerformSeatInfo> temp = seatResult.get(1);
|
||||||
|
// temp.add(fPerformSeatInfo);
|
||||||
|
// seatResult.put(1, temp);
|
||||||
|
// }
|
||||||
|
// if (fPerformSeatInfo.getPrice().compareTo(BigDecimal.valueOf(1300)) > 0 && fPerformSeatInfo.getPrice().compareTo(BigDecimal.valueOf(1600)) <= 0) {
|
||||||
|
// List<FPerformSeatInfo> temp = seatResult.get(2);
|
||||||
|
// temp.add(fPerformSeatInfo);
|
||||||
|
// seatResult.put(2, temp);
|
||||||
|
// }
|
||||||
|
// if (fPerformSeatInfo.getPrice().compareTo(BigDecimal.valueOf(1600)) >= 0) {
|
||||||
|
// List<FPerformSeatInfo> temp = seatResult.get(3);
|
||||||
|
// temp.add(fPerformSeatInfo);
|
||||||
|
// seatResult.put(3, temp);
|
||||||
|
// }
|
||||||
|
// if (fPerformSeatInfo.getPrice().compareTo(BigDecimal.valueOf(600)) <= 0) {
|
||||||
|
// List<FPerformSeatInfo> temp = seatResult.get(4);
|
||||||
|
// temp.add(fPerformSeatInfo);
|
||||||
|
// seatResult.put(4, temp);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// List<FPerformSeatInfo> seat0 = seatResult.get(0);
|
||||||
|
// List<FPerformSeatInfo> seat1 = seatResult.get(1);
|
||||||
|
// List<FPerformSeatInfo> seat2 = seatResult.get(2);
|
||||||
|
// List<FPerformSeatInfo> seat3 = seatResult.get(3);
|
||||||
|
// List<FPerformSeatInfo> seat4 = seatResult.get(4);
|
||||||
|
// seats.addAll(seat0);
|
||||||
|
// seats.addAll(seat1);
|
||||||
|
// seats.addAll(seat2);
|
||||||
|
// seats.addAll(seat3);
|
||||||
|
// seats.addAll(seat4);
|
||||||
|
// List<Long> seatIds = seats.stream().map(FPerformSeatInfo::getSeatPlanId).toList();
|
||||||
|
// ProjectOrderCreateReq projectOrderCreateReq = buildReqV2(projectId, frequentIds, seatIds, performId, price);
|
||||||
|
// for (int i = 1; i <= 10; i++) {
|
||||||
|
// ProjectOrderCreateResp projectOrder = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.createProjectOrder(projectOrderCreateReq, availableUser.get(0).getToken()), "create-project-order");
|
||||||
|
// if (Objects.nonNull(projectOrder)) {
|
||||||
|
// log.info("下单成功,订单信息:{}", JSONObject.toJSONString(projectOrder));
|
||||||
|
// String msg = "【芬玩岛】下单成功✅✅✅,演出名称:" + performByProjectId.getProjectName() + ",请在2分钟内完成付款!";
|
||||||
|
// dingTalkService.sendScriptMsg(msg);
|
||||||
|
// return Boolean.TRUE;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// dingTalkService.sendScriptMsg("【芬玩岛】下单失败❌❌❌,演出名称:" + performByProjectId.getProjectName());
|
||||||
|
// return Boolean.FALSE;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for (FPerformSeatInfo fPerformSeatInfo : seatInfoByProjectId) {
|
||||||
|
// if (1 == fPerformSeatInfo.getSoldOut()) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// ProjectOrderCreateReq projectOrderCreateReq = buildReq(projectId, frequentIds, fPerformSeatInfo);
|
||||||
|
// for (int i = 1; i <= 10; i++) {
|
||||||
|
// ProjectOrderCreateResp projectOrder = httpRequestHelper.fetchWithRetry(() -> performServiceHttp.createProjectOrder(projectOrderCreateReq, availableUser.get(0).getToken()), "create-project-order");
|
||||||
|
// if (Objects.nonNull(projectOrder)) {
|
||||||
|
// log.info("下单成功,订单信息:{}", JSONObject.toJSONString(projectOrder));
|
||||||
|
// String msg = "【芬玩岛】下单成功✅✅✅,演出名称:" + performByProjectId.getProjectName() + ",请在2分钟内完成付款!";
|
||||||
|
// dingTalkService.sendScriptMsg(msg);
|
||||||
|
// return Boolean.TRUE;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// dingTalkService.sendScriptMsg("【芬玩岛】下单失败❌❌❌,演出名称:" + performByProjectId.getProjectName());
|
||||||
|
// return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -128,6 +246,28 @@ public class PerformServiceImpl implements IPerformService {
|
|||||||
return projectOrderCreateReq;
|
return projectOrderCreateReq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static ProjectOrderCreateReq buildReqV2(Long projectId, List<Long> frequentIds, List<Long> seatPlanIds, Long perfomrId, BigDecimal price) {
|
||||||
|
ProjectOrderCreateReq projectOrderCreateReq = new ProjectOrderCreateReq();
|
||||||
|
projectOrderCreateReq.setDeliveryType(1);
|
||||||
|
projectOrderCreateReq.setContactName("朱吉祥");
|
||||||
|
projectOrderCreateReq.setContactPhone("15858717571");
|
||||||
|
projectOrderCreateReq.setPayment(price.multiply(BigDecimal.valueOf(frequentIds.size())).setScale(2));
|
||||||
|
projectOrderCreateReq.setTotalPrice(price.multiply(BigDecimal.valueOf(frequentIds.size())).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||||
|
projectOrderCreateReq.setPerformId(perfomrId);
|
||||||
|
projectOrderCreateReq.setProjectId(projectId.toString());
|
||||||
|
projectOrderCreateReq.setPrivilegeCodeList(new ArrayList<>());
|
||||||
|
projectOrderCreateReq.setAudienceCount(frequentIds.size());
|
||||||
|
projectOrderCreateReq.setFrequentIds(frequentIds);
|
||||||
|
projectOrderCreateReq.setSeatPlanIds(seatPlanIds);
|
||||||
|
projectOrderCreateReq.setBlackBox(":0");
|
||||||
|
projectOrderCreateReq.setCombineTicketVos(null);
|
||||||
|
projectOrderCreateReq.setOrdinaryTicketVos(null);
|
||||||
|
projectOrderCreateReq.setActivityId(Strings.EMPTY);
|
||||||
|
projectOrderCreateReq.setActivityType(0);
|
||||||
|
return projectOrderCreateReq;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<FPerformConfig> getAvailablePerform() {
|
public List<FPerformConfig> getAvailablePerform() {
|
||||||
return fwdPerformConfigMapper.getAvailablePerform();
|
return fwdPerformConfigMapper.getAvailablePerform();
|
||||||
|
|||||||
Reference in New Issue
Block a user