perf:get请求发送优化

This commit is contained in:
xiang
2025-08-03 17:39:54 +08:00
parent f25e8638d2
commit 1fc66ca0f4
4 changed files with 119 additions and 11 deletions

14
pom.xml
View File

@@ -7,7 +7,7 @@
<parent>
<groupId>com.xiang</groupId>
<artifactId>xservice-basic</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.0</version>
</parent>
<groupId>com.xiang</groupId>
@@ -30,27 +30,27 @@
<dependency>
<groupId>com.xiang</groupId>
<artifactId>xservice-common</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.xiang</groupId>
<artifactId>xservice-third-part</artifactId>
<version>1.1-snapshot</version>
<artifactId>xservice-message-starter</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.xiang</groupId>
<artifactId>xservice-schedule-starter</artifactId>
<version>1.1-snapshot</version>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.xiang</groupId>
<artifactId>xservice-cache</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.xiang</groupId>
<artifactId>xservice-http-starter</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
</dependency>
</dependencies>

View File

@@ -1,7 +1,7 @@
package com.xiang.xservice.fwd.schedule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.xiang.xservice.basic.utils.DateUtils;
import com.xiang.xservice.basic.utils.PrimaryKeyUtils;
@@ -9,11 +9,14 @@ import com.xiang.xservice.basic.xservice.dingTalk.service.DingTalkService;
import com.xiang.xservice.fwd.entity.param.FwdOrderTaskParam;
import com.xiang.xservice.fwd.entity.pojo.FPerformConfig;
import com.xiang.xservice.fwd.entity.pojo.FPerformProjectInfo;
import com.xiang.xservice.fwd.entity.pojo.FPerformSeatInfo;
import com.xiang.xservice.fwd.entity.resp.http.perform.*;
import com.xiang.xservice.fwd.mapper.FwdAudienceConfigMapper;
import com.xiang.xservice.fwd.mapper.FwdPerformConfigMapper;
import com.xiang.xservice.fwd.mapper.FwdPerformProjectInfoMapper;
import com.xiang.xservice.fwd.mapper.FwdUserConfigMapper;
import com.xiang.xservice.fwd.service.IPerformService;
import com.xiang.xservice.fwd.service.IPerformServiceHttp;
import com.xiang.xservice.schedule.core.DynamicTaskScheduler;
import com.xiang.xservice.schedule.entity.ScheduledTaskEntity;
import com.xiang.xservice.schedule.entity.TaskConfig;
@@ -28,6 +31,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
@@ -36,6 +40,8 @@ import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -46,6 +52,7 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
@Slf4j
@RestController
@RequestMapping("/system/job/fwd")
public class FwdImportantMsgJob {
private final FwdPerformProjectInfoMapper performProjectInfoMapper;
@@ -56,6 +63,7 @@ public class FwdImportantMsgJob {
private final FwdAudienceConfigMapper fwdAudienceConfigMapper;
private final IPerformService iPerformService;
private final IDynamicTaskSchedulerService dynamicTaskSchedulerService;
private final IPerformServiceHttp iPerformServiceHttp;
@Value("${DingTalk.chatId}")
private String chatId;
@@ -120,10 +128,111 @@ public class FwdImportantMsgJob {
savaTask(data, taskId, params);
}
msg.append("请注意进行数据库配置的更改!");
dingTalkService.sendChatMessage(chatId, msg.toString());
dingTalkService.sendRobotMessage(msg.toString());
log.info("【芬玩岛】演唱会预售定时任务结束time:{}", System.currentTimeMillis());
}
@Scheduled(cron = "0 10 8 1/1 * ?")
@PostMapping("/presaleSeatReminderJob")
public void presaleSeatReminderJob() {
ScheduledTaskEntity entity = new ScheduledTaskEntity();
entity.setStatus(TaskStatusEnum.UN_START.getCode());
List<ScheduledTaskEntity> taskList = dynamicTaskSchedulerService.getTaskList(entity);
if (CollectionUtils.isEmpty(taskList)) {
log.info("今天暂无预售的演出time:{}", LocalDateTime.now());
return;
}
log.info("今天:{}的预售的项目信息:{}", LocalDateTime.now(), JSON.toJSONString(taskList));
LocalDateTime todayStartTime = LocalDate.now().atTime(0, 0, 0);
LocalDateTime todayEndTime = LocalDate.now().atTime(23, 59, 59);
StringBuffer msg = new StringBuffer();
taskList.forEach(taskEntity -> {
String parameters = taskEntity.getParameters();
JSONObject jsonObject = JSON.parseObject(parameters);
Long projectId = null;
try {
projectId = (Long) jsonObject.get("projectId");
} catch (Exception e) {
log.error("异常错误信息:{}", JSON.toJSONString(taskEntity), e);
}
if (Objects.nonNull(projectId)) {
Perform performsByProjectIdFromHttp = iPerformServiceHttp.getPerformsByProjectIdFromHttp(projectId);
if (Objects.nonNull(performsByProjectIdFromHttp)) {
for (PerformInfo performInfo : performsByProjectIdFromHttp.getPerformInfos()) {
for (PerformDetail performDetail : performInfo.getPerformInfo()) {
LocalDateTime saleTime = DateUtils.getTimeFromStr(performDetail.getSaleTime());
if (saleTime.isAfter(todayStartTime) && saleTime.isBefore(todayEndTime)) {
List<SeatPlan> seatPlans = performDetail.getSeatPlans();
Map<Long, SeatPlan> seatPlanMap = seatPlans.stream().collect(Collectors.toMap(SeatPlan::getSeatPlanId, Function.identity(), (a, b) -> a));
List<Long> seatPlanIds = seatPlans.stream().map(SeatPlan::getSeatPlanId).collect(Collectors.toList());
List<SeatPlanStatus> seatPlanStatusFromHttp = iPerformServiceHttp.getSeatPlanStatusFromHttp(seatPlanIds);
for (SeatPlanStatus seatPlanStatus : seatPlanStatusFromHttp) {
if (!seatPlanStatus.getSoldOutFlag()) {
FPerformSeatInfo seatInfoBySeatId = iPerformService.getSeatInfoBySeatId(seatPlanStatus.getSeatPlanId());
if (Objects.nonNull(seatInfoBySeatId)) {
seatInfoBySeatId.setSoldOut(0);
iPerformService.updateSeatInfo(seatInfoBySeatId);
msg.append("演出任务名称").append(taskEntity.getTaskName()).append("的场次信息")
.append(performDetail.getName()).append("的座位信息")
.append(seatInfoBySeatId.getSeatPlanName()).append("信息已更新\n");
} else {
if (seatPlanMap.containsKey(seatPlanStatus.getSeatPlanId())) {
SeatPlan seatPlan = seatPlanMap.get(seatPlanStatus.getSeatPlanId());
FPerformSeatInfo fPerformSeatInfo = new FPerformSeatInfo();
fPerformSeatInfo.setSeatPlanId(seatInfoBySeatId.getSeatPlanId());
fPerformSeatInfo.setSeatPlanName(seatPlan.getSeatPlanName());
fPerformSeatInfo.setPerformId(seatInfoBySeatId.getPerformId());
fPerformSeatInfo.setPerformName(seatInfoBySeatId.getPerformName());
fPerformSeatInfo.setStopSale(seatInfoBySeatId.getStopSale());
fPerformSeatInfo.setShelfStatus(seatInfoBySeatId.getShelfStatus());
fPerformSeatInfo.setPrice(seatInfoBySeatId.getPrice());
fPerformSeatInfo.setDiscountPrice(seatInfoBySeatId.getDiscountPrice());
fPerformSeatInfo.setSubStatus(seatInfoBySeatId.getSubStatus());
fPerformSeatInfo.setQuantity(seatInfoBySeatId.getQuantity());
fPerformSeatInfo.setStatus(seatInfoBySeatId.getStatus());
fPerformSeatInfo.setMaxSellStock(seatInfoBySeatId.getMaxSellStock());
fPerformSeatInfo.setSoldStock(seatInfoBySeatId.getSoldStock());
fPerformSeatInfo.setLeftStock(seatInfoBySeatId.getLeftStock());
fPerformSeatInfo.setAbleSaleQuantity(seatInfoBySeatId.getAbleSaleQuantity());
fPerformSeatInfo.setAshShow(seatInfoBySeatId.getAshShow());
fPerformSeatInfo.setAshShowDesc(seatInfoBySeatId.getAshShowDesc());
fPerformSeatInfo.setSelectable(seatInfoBySeatId.getSelectable());
fPerformSeatInfo.setDisplay(seatInfoBySeatId.getDisplay());
fPerformSeatInfo.setAvailableTicketQuantity(seatInfoBySeatId.getAvailableTicketQuantity());
fPerformSeatInfo.setAvailableAllTicketQuantity(seatInfoBySeatId.getAvailableAllTicketQuantity());
fPerformSeatInfo.setSaleTime(seatInfoBySeatId.getSaleTime());
fPerformSeatInfo.setProjectId(seatInfoBySeatId.getProjectId());
fPerformSeatInfo.setSoldOut(seatInfoBySeatId.getSoldOut());
iPerformService.addSeatInfo(fPerformSeatInfo);
msg.append("演出任务名称").append(taskEntity.getTaskName()).append("的场次信息")
.append(performDetail.getName()).append("的座位信息")
.append(seatPlan.getSeatPlanName()).append("信息已更新\n");
}
}
} else {
log.info("演出:{},座位:{},已售罄", performDetail.getName(), seatPlanStatus.getSeatPlanId());
msg.append("演出任务名称").append(taskEntity.getTaskName()).append("的场次信息")
.append(performDetail.getName()).append("的座位信息").append("已售罄\n");
}
}
}
}
}
}
}
});
try {
dingTalkService.sendRobotMessage(msg.toString());
} catch (Exception e) {
log.error("信息发送异常, 信息:{}", msg, e);
}
}
private void savaTask(FPerformProjectInfo data, long taskId, Map<String, Object> params) {
ScheduledTaskEntity entity = new ScheduledTaskEntity();
entity.setId(taskId);

View File

@@ -91,7 +91,7 @@ public class PullDataFromFWDJob {
performProjectInfoMapper.insert(fPerformProjectInfo);
}
@Scheduled(cron = "0 10 8 1/1 * ?")
// @Scheduled(cron = "0 10 8 1/1 * ?")
@PostMapping("/pullSeatDataJob")
public void pullSeatDataJob() {
List<FPerformConfig> availablePerform = performConfigMapper.getAvailablePerform();

View File

@@ -174,7 +174,6 @@ public class PerformServiceHttpServiceImpl implements IPerformServiceHttp {
Map<String, String> headers = Maps.newHashMap();
headers.put("Host", "api.livelab.com.cn");
headers.put("Connection", "keep-alive");
headers.put("Content-Length", "316");
headers.put("platform-type", "%E7%BA%B7%E7%8E%A9%E5%B2%9B%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F");
headers.put("content-type", "application/json");
headers.put("x-fwd-anonymousId", "ocXac5C25MY5O3UM_EfL0oTgm7Jw");