feat:捡漏下单
This commit is contained in:
@@ -1,13 +1,24 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.schedule;
|
||||
|
||||
import com.xiang.xservice.application.script.jntyzx.entity.pojo.VenueInfoDO;
|
||||
import com.xiang.xservice.application.script.jntyzx.service.DingTalkScriptVenueService;
|
||||
import com.xiang.xservice.application.script.jntyzx.service.IJntyzxHttpService;
|
||||
import com.xiang.xservice.application.script.jntyzx.service.IUserTokenInfoService;
|
||||
import com.xiang.xservice.application.script.jntyzx.service.IVenueService;
|
||||
import com.xiang.xservice.application.script.jntyzx.utils.VenueInfoUtils;
|
||||
import com.xiang.xservice.common.entity.SysConfigDO;
|
||||
import com.xiang.xservice.common.service.ISysConfigService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
@@ -18,16 +29,76 @@ import java.util.List;
|
||||
public class VenuePeekSchedule {
|
||||
|
||||
private final IVenueService venueService;
|
||||
private final IJntyzxHttpService jntyzxHttpService;
|
||||
private final ISysConfigService sysConfigService;
|
||||
private final IUserTokenInfoService userTokenInfoService;
|
||||
private final DingTalkScriptVenueService dingTalkScriptVenueService;
|
||||
|
||||
@Scheduled(cron = "5 1 9-20 * * ?")
|
||||
public void peek() {
|
||||
public void peek8210() {
|
||||
SysConfigDO config = sysConfigService.getByName("jntyzx.venue.peek.switch");
|
||||
boolean peekSwitch;
|
||||
if (Objects.isNull(config)) {
|
||||
peekSwitch = false;
|
||||
} else {
|
||||
if (StringUtils.equals(config.getValue(), "true")) {
|
||||
peekSwitch = true;
|
||||
} else {
|
||||
peekSwitch = false;
|
||||
}
|
||||
}
|
||||
if (peekSwitch) {
|
||||
List<VenueInfoDO> venueInfoDOS = venueService.queryCanBuyVenue();
|
||||
if (CollectionUtils.isEmpty(venueInfoDOS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
venueInfoDOS.parallelStream().forEach(item -> {
|
||||
// 请求接口创建订单不支付
|
||||
Map<String, List<VenueInfoDO>> map = venueInfoDOS.stream().filter(VenueInfoUtils::get8210VenueInfo).collect(Collectors.groupingBy(VenueInfoDO::getPlaceName));
|
||||
String token = userTokenInfoService.getToken("Xiang");
|
||||
if (StringUtils.isBlank(token)) {
|
||||
return;
|
||||
}
|
||||
map.keySet().parallelStream().forEach(placeName -> {
|
||||
List<VenueInfoDO> venueInfoDOList = map.get(placeName);
|
||||
Boolean order = jntyzxHttpService.createOrder(venueInfoDOList, token);
|
||||
if (order) {
|
||||
dingTalkScriptVenueService.sendScriptMsg("场地:" + placeName + "下单成功,请付款!时间:" + LocalDateTime.now());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "5 1 9-20 * * ?")
|
||||
public void peek628() {
|
||||
SysConfigDO config = sysConfigService.getByName("jntyzx.venue.peek.switch");
|
||||
boolean peekSwitch;
|
||||
if (Objects.isNull(config)) {
|
||||
peekSwitch = false;
|
||||
} else {
|
||||
if (StringUtils.equals(config.getValue(), "true")) {
|
||||
peekSwitch = true;
|
||||
} else {
|
||||
peekSwitch = false;
|
||||
}
|
||||
}
|
||||
if (peekSwitch) {
|
||||
List<VenueInfoDO> venueInfoDOS = venueService.queryCanBuyVenue();
|
||||
if (CollectionUtils.isEmpty(venueInfoDOS)) {
|
||||
return;
|
||||
}
|
||||
Map<String, List<VenueInfoDO>> map = venueInfoDOS.stream()
|
||||
.filter(VenueInfoUtils::get628VenueInfo)
|
||||
.collect(Collectors.groupingBy(VenueInfoDO::getPlaceName));
|
||||
String token = userTokenInfoService.getToken("Xiang");
|
||||
if (StringUtils.isBlank(token)) {
|
||||
return;
|
||||
}
|
||||
map.keySet().parallelStream().forEach(placeName -> {
|
||||
List<VenueInfoDO> venueInfoDOList = map.get(placeName);
|
||||
Boolean order = jntyzxHttpService.createOrder(venueInfoDOList, token);
|
||||
if (order) {
|
||||
dingTalkScriptVenueService.sendScriptMsg("场地:" + placeName + "下单成功,请付款!时间:" + LocalDateTime.now());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ import com.xiang.xservice.application.script.jntyzx.entity.pojo.VenueInfoDO;
|
||||
import com.xiang.xservice.application.script.jntyzx.entity.resp.query.SitePositionList;
|
||||
import com.xiang.xservice.application.script.jntyzx.service.DingTalkScriptVenueService;
|
||||
import com.xiang.xservice.application.script.jntyzx.service.IVenueService;
|
||||
import com.xiang.xservice.common.entity.SysConfigDO;
|
||||
import com.xiang.xservice.common.service.ISysConfigService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -15,6 +18,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
@@ -27,6 +31,7 @@ public class VenueQuerySchedule {
|
||||
|
||||
private final IVenueService venueService;
|
||||
private final DingTalkScriptVenueService dingTalkScriptVenueService;
|
||||
private final ISysConfigService sysConfigService;
|
||||
|
||||
@Scheduled(cron = "0 30 8 * * ?")
|
||||
public void venueQueryTask() {
|
||||
@@ -85,6 +90,18 @@ public class VenueQuerySchedule {
|
||||
if (CollectionUtils.isEmpty(venueInfoDOS)) {
|
||||
return;
|
||||
}
|
||||
SysConfigDO config = sysConfigService.getByName("jntyzx.order.create.xiaoguan.switch");
|
||||
boolean orderSwitch;
|
||||
if (Objects.nonNull(config)) {
|
||||
String value = config.getValue();
|
||||
if (StringUtils.equals(value, "true")) {
|
||||
orderSwitch = true;
|
||||
} else {
|
||||
orderSwitch = false;
|
||||
}
|
||||
} else {
|
||||
orderSwitch = false;
|
||||
}
|
||||
// 6-8场地
|
||||
Map<String, List<VenueInfoDO>> map1 = Maps.newLinkedHashMap();
|
||||
// 8-10场地
|
||||
@@ -92,6 +109,12 @@ public class VenueQuerySchedule {
|
||||
venueInfoDOS.stream()
|
||||
.filter(item -> StringUtils.equals(item.getSjName(), "18:00-19:00") || StringUtils.equals(item.getSjName(), "19:00-20:00")
|
||||
|| StringUtils.equals(item.getSjName(), "20:00-21:00") || StringUtils.equals(item.getSjName(), "21:00-22:00"))
|
||||
.filter(item -> {
|
||||
if (!orderSwitch) {
|
||||
return !item.getPlaceName().contains("小馆");
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.forEach(item -> {
|
||||
if (StringUtils.equals(item.getSjName(), "18:00-19:00")) {
|
||||
putIntoMap(item, map1);
|
||||
@@ -106,13 +129,17 @@ public class VenueQuerySchedule {
|
||||
putIntoMap(item, map2);
|
||||
}
|
||||
});
|
||||
if (MapUtils.isNotEmpty(map1)) {
|
||||
StringBuffer sb1 = new StringBuffer("查询江体小程序场地信息【18:00-20:00】\n");
|
||||
buildMsg(map1, sb1);
|
||||
dingTalkScriptVenueService.sendScriptMsg(sb1.toString());
|
||||
}
|
||||
if (MapUtils.isNotEmpty(map1)) {
|
||||
StringBuffer sb2 = new StringBuffer("查询江体小程序场地信息【20:00-22:00】\n");
|
||||
buildMsg(map2, sb2);
|
||||
dingTalkScriptVenueService.sendScriptMsg(sb1.toString());
|
||||
dingTalkScriptVenueService.sendScriptMsg(sb2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildMsg(Map<String, List<VenueInfoDO>> map1, StringBuffer sb1) {
|
||||
map1.forEach((k, v) -> {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class VenueServiceImpl implements IVenueService {
|
||||
if (CollectionUtils.isEmpty(sitePositionLists)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
updateDatabase(sitePositionLists);
|
||||
updateDatabase(sitePositionLists, true);
|
||||
return sitePositionLists;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class VenueServiceImpl implements IVenueService {
|
||||
if (CollectionUtils.isEmpty(sitePositionLists)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
updateDatabase(sitePositionLists);
|
||||
updateDatabase(sitePositionLists, false);
|
||||
return sitePositionLists;
|
||||
}
|
||||
|
||||
@@ -55,8 +55,14 @@ public class VenueServiceImpl implements IVenueService {
|
||||
return venueInfoManage.queryByType(LocalDate.now(), 0);
|
||||
}
|
||||
|
||||
private void updateDatabase(List<SitePositionList> list) {
|
||||
List<VenueInfoDO> venueInfoDOS = venueInfoManage.queryByDate(LocalDate.now());
|
||||
private void updateDatabase(List<SitePositionList> list, boolean isToday) {
|
||||
List<VenueInfoDO> venueInfoDOS = Lists.newArrayList();
|
||||
if (isToday) {
|
||||
venueInfoDOS.addAll(venueInfoManage.queryByDate(LocalDate.now()));
|
||||
} else {
|
||||
venueInfoDOS.addAll(venueInfoManage.queryByDate(LocalDate.now().plusDays(1)));
|
||||
}
|
||||
|
||||
Map<Long, VenueInfoDO> map = Maps.newHashMap();
|
||||
if (CollectionUtils.isNotEmpty(venueInfoDOS)) {
|
||||
map.putAll(venueInfoDOS.stream().filter(Objects::nonNull).collect(Collectors.toMap(VenueInfoDO::getPlaceMainId, Function.identity(), (a, b) -> a)));
|
||||
|
||||
@@ -16,6 +16,9 @@ public class VenueInfoUtils {
|
||||
return StringUtils.equals(venueInfoDO.getSjName(), "12:00-13:00") || StringUtils.equals(venueInfoDO.getSjName(), "13:00-14:00");
|
||||
}
|
||||
|
||||
public static boolean get628VenueInfo(VenueInfoDO venueInfoDO) {
|
||||
return StringUtils.equals(venueInfoDO.getSjName(), "18:00-19:00") || StringUtils.equals(venueInfoDO.getSjName(), "19:00-20:00");
|
||||
}
|
||||
public static boolean get8210VenueInfo(VenueInfoDO venueInfoDO) {
|
||||
return StringUtils.equals(venueInfoDO.getSjName(), "20:00-21:00") || StringUtils.equals(venueInfoDO.getSjName(), "21:00-22:00");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.xiang.xservice.common.service;
|
||||
|
||||
import com.xiang.xservice.common.entity.SysConfigDO;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-16 11:19
|
||||
*/
|
||||
public interface ISysConfigService {
|
||||
|
||||
SysConfigDO getByName(String name);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.xiang.xservice.common.service;
|
||||
|
||||
import com.xiang.xservice.common.entity.SysConfigDO;
|
||||
import com.xiang.xservice.common.mapper.SysConfigMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-16 11:20
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysConfigServiceImpl implements ISysConfigService {
|
||||
private final SysConfigMapper sysConfigMapper;
|
||||
@Override
|
||||
public SysConfigDO getByName(String name) {
|
||||
return sysConfigMapper.getByName(name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user