fear:场地查询
This commit is contained in:
@@ -17,6 +17,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
"com.xiang.xservice.application.script.glados.repository",
|
||||
"com.xiang.xservice.application.script.xb.repository",
|
||||
"com.xiang.xservice.common.mapper",
|
||||
"com.xiang.xservice.application.script.jntyzx.mapper"
|
||||
})
|
||||
@ConfigurationPropertiesScan(basePackages = {
|
||||
"com.xiang.xservice.config"
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.entity.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 15:48
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("jntyzx_venue_info")
|
||||
public class VenueInfoDO {
|
||||
private Long id;
|
||||
/**
|
||||
* 场地名称
|
||||
*/
|
||||
private String placeName;
|
||||
|
||||
/**
|
||||
* 所属日期
|
||||
*/
|
||||
private LocalDate date;
|
||||
|
||||
/**
|
||||
* 场地信息三方主键
|
||||
*/
|
||||
private Long placeMainId;
|
||||
|
||||
/**
|
||||
* 场地id
|
||||
*/
|
||||
private Integer placeId;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Integer scheduleId;
|
||||
|
||||
/**
|
||||
* 时间范围
|
||||
*/
|
||||
private String sjName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
private String contacts;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer type;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.manage;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xiang.xservice.application.script.jntyzx.entity.pojo.VenueInfoDO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 15:50
|
||||
*/
|
||||
public interface IVenueInfoManage extends IService<VenueInfoDO> {
|
||||
|
||||
List<VenueInfoDO> queryByDate(LocalDate date);
|
||||
|
||||
List<VenueInfoDO> queryByType(LocalDate date, Integer type);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.manage;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiang.xservice.application.script.jntyzx.entity.pojo.VenueInfoDO;
|
||||
import com.xiang.xservice.application.script.jntyzx.mapper.JntyzxVenueInfoMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 15:51
|
||||
*/
|
||||
@Service
|
||||
public class VenueInfoManageImpl extends ServiceImpl<JntyzxVenueInfoMapper, VenueInfoDO> implements IVenueInfoManage {
|
||||
|
||||
public List<VenueInfoDO> queryByDate(LocalDate now) {
|
||||
LambdaQueryWrapper<VenueInfoDO> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(VenueInfoDO::getDate, now);
|
||||
return baseMapper.selectList(lqw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VenueInfoDO> queryByType(LocalDate date, Integer type) {
|
||||
LambdaQueryWrapper<VenueInfoDO> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(VenueInfoDO::getDate, date);
|
||||
lqw.eq(VenueInfoDO::getType, type);
|
||||
return baseMapper.selectList(lqw);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiang.xservice.application.script.jntyzx.entity.pojo.VenueInfoDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 15:48
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface JntyzxVenueInfoMapper extends BaseMapper<VenueInfoDO> {
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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.IVenueService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 16:12
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class VenuePeekSchedule {
|
||||
|
||||
private final IVenueService venueService;
|
||||
|
||||
@Scheduled(cron = "5 1 9-20 * * ?")
|
||||
public void peek() {
|
||||
List<VenueInfoDO> venueInfoDOS = venueService.queryCanBuyVenue();
|
||||
if (CollectionUtils.isEmpty(venueInfoDOS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
venueInfoDOS.parallelStream().forEach(item -> {
|
||||
// 请求接口创建订单不支付
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,105 +1,42 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.schedule;
|
||||
|
||||
import com.aliyun.core.utils.StringUtils;
|
||||
import com.google.common.collect.Maps;
|
||||
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.IVenueServiceHttp;
|
||||
import com.xiang.xservice.application.script.jntyzx.service.IVenueService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 15:02
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
public class VenueQuerySchedule {
|
||||
private final IVenueService venueService;
|
||||
|
||||
private final static String STATIC_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NjU3ODQ1NjMsInVzZXJuYW1lIjoid3hfb3Blbl9pZF9vMjFNWDR5N3doWENHanZVVEdQNkNUejJIYkQ4In0.QBzNQNvJZQPZZnzmbU8K5Liz0piHwercrDIq3kirUJk";
|
||||
private final IVenueServiceHttp venueServiceHttp;
|
||||
private final DingTalkScriptVenueService dingTalkScriptVenueService;
|
||||
@Scheduled(cron = "0 30 8 * * ?")
|
||||
public void venueQueryTask() {
|
||||
log.info("每日8:30拉取江体小程序数据定时任务");
|
||||
venueService.queryVenueService();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0/5 9-15 * * ?")
|
||||
@PostMapping("/venueQueryTask")
|
||||
@Scheduled(cron = "0 0/10 9-15 * * ?")
|
||||
public void venueQueryTask4Free() {
|
||||
venueQuery();
|
||||
log.info("每日空闲时刻拉取江体小程序数据定时任务");
|
||||
venueService.queryVenueService();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0/5 15-17 * * ?")
|
||||
@Scheduled(cron = "1 0/5 15-17 * * ?")
|
||||
public void venueQueryTask4Normal() {
|
||||
venueQuery();
|
||||
log.info("每日正常时刻拉取江体小程序数据定时任务");
|
||||
venueService.queryVenueService();
|
||||
}
|
||||
@Scheduled(cron = "0 0/5 17-20 * * ?")
|
||||
|
||||
@Scheduled(cron = "2 0/2 17-20 * * ?")
|
||||
public void venueQueryTask4Urgency() {
|
||||
venueQuery();
|
||||
}
|
||||
|
||||
private void venueQuery() {
|
||||
List<SitePositionList> sitePositionLists = venueServiceHttp.queryAvailable("1", STATIC_TOKEN);
|
||||
if (CollectionUtils.isEmpty(sitePositionLists)) {
|
||||
return;
|
||||
}
|
||||
// 6-8场地
|
||||
Map<String, List<SitePositionList>> map1 = Maps.newLinkedHashMap();
|
||||
// 8-10场地
|
||||
Map<String, List<SitePositionList>> map2 = Maps.newLinkedHashMap();
|
||||
sitePositionLists.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"))
|
||||
.forEach(item -> {
|
||||
if (StringUtils.equals(item.getSjName(), "18:00-19:00")) {
|
||||
putIntoMap(item, map1);
|
||||
}
|
||||
if (StringUtils.equals(item.getSjName(), "19:00-20:00")) {
|
||||
putIntoMap(item, map1);
|
||||
}
|
||||
if (StringUtils.equals(item.getSjName(), "20:00-21:00")) {
|
||||
putIntoMap(item, map2);
|
||||
}
|
||||
if (StringUtils.equals(item.getSjName(), "21:00-22:00")) {
|
||||
putIntoMap(item, map2);
|
||||
}
|
||||
});
|
||||
StringBuffer sb1 = new StringBuffer("查询江体小程序场地信息【18:00-20:00】\n");
|
||||
buildMsg(map1, sb1);
|
||||
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<SitePositionList>> map1, StringBuffer sb1) {
|
||||
map1.forEach((k, v) -> {
|
||||
SitePositionList sitePositionList1 = v.get(0);
|
||||
SitePositionList sitePositionList2 = v.get(1);
|
||||
String contacts = sitePositionList1.getContacts();
|
||||
if (!StringUtils.equals(sitePositionList1.getContacts(), sitePositionList2.getContacts())) {
|
||||
contacts = sitePositionList1.getContacts() + "," + sitePositionList2.getContacts();
|
||||
}
|
||||
sb1.append(k).append("场地,订购人:").append(contacts).append("\n");
|
||||
});
|
||||
}
|
||||
|
||||
private static void putIntoMap(SitePositionList item, Map<String, List<SitePositionList>> map1) {
|
||||
// if (map1.containsKey(item.getPlaceName())) {
|
||||
// List<SitePositionList> positionLists = map1.get(item.getPlaceName());
|
||||
// positionLists.add(item);
|
||||
// map1.put(item.getPlaceName(), positionLists);
|
||||
// } else {
|
||||
// map1.put(item.getPlaceName(), Collections.singletonList(item));
|
||||
// }
|
||||
map1.computeIfAbsent(item.getPlaceName(),
|
||||
k -> new ArrayList<>()
|
||||
).add(item);
|
||||
log.info("每日紧急时刻时刻拉取江体小程序数据定时任务");
|
||||
venueService.queryVenueService();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.service;
|
||||
|
||||
import com.xiang.xservice.application.script.jntyzx.entity.pojo.VenueInfoDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 16:07
|
||||
*/
|
||||
public interface IVenueService {
|
||||
|
||||
void queryVenueService();
|
||||
|
||||
List<VenueInfoDO> queryCanBuyVenue();
|
||||
}
|
||||
@@ -14,4 +14,6 @@ public interface IVenueServiceHttp {
|
||||
* 查询今日6-10可用场地
|
||||
*/
|
||||
List<SitePositionList> queryAvailable(String isWeekend, String token);
|
||||
|
||||
// Boolean createOrder();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.service;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
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.manage.IVenueInfoManage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 16:08
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class VenueServiceImpl implements IVenueService {
|
||||
|
||||
private final static String STATIC_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NjU3ODQ1NjMsInVzZXJuYW1lIjoid3hfb3Blbl9pZF9vMjFNWDR5N3doWENHanZVVEdQNkNUejJIYkQ4In0.QBzNQNvJZQPZZnzmbU8K5Liz0piHwercrDIq3kirUJk";
|
||||
private final IVenueServiceHttp venueServiceHttp;
|
||||
private final DingTalkScriptVenueService dingTalkScriptVenueService;
|
||||
private final IVenueInfoManage venueInfoManage;
|
||||
|
||||
@Override
|
||||
public void queryVenueService() {
|
||||
List<SitePositionList> sitePositionLists = venueServiceHttp.queryAvailable("1", STATIC_TOKEN);
|
||||
if (CollectionUtils.isEmpty(sitePositionLists)) {
|
||||
return;
|
||||
}
|
||||
// 6-8场地
|
||||
Map<String, List<SitePositionList>> map1 = Maps.newLinkedHashMap();
|
||||
// 8-10场地
|
||||
Map<String, List<SitePositionList>> map2 = Maps.newLinkedHashMap();
|
||||
sitePositionLists.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"))
|
||||
.forEach(item -> {
|
||||
if (StringUtils.equals(item.getSjName(), "18:00-19:00")) {
|
||||
putIntoMap(item, map1);
|
||||
}
|
||||
if (StringUtils.equals(item.getSjName(), "19:00-20:00")) {
|
||||
putIntoMap(item, map1);
|
||||
}
|
||||
if (StringUtils.equals(item.getSjName(), "20:00-21:00")) {
|
||||
putIntoMap(item, map2);
|
||||
}
|
||||
if (StringUtils.equals(item.getSjName(), "21:00-22:00")) {
|
||||
putIntoMap(item, map2);
|
||||
}
|
||||
});
|
||||
StringBuffer sb1 = new StringBuffer("查询江体小程序场地信息【18:00-20:00】\n");
|
||||
buildMsg(map1, sb1);
|
||||
StringBuffer sb2 = new StringBuffer("查询江体小程序场地信息【20:00-22:00】\n");
|
||||
buildMsg(map2, sb2);
|
||||
updateDatabase(sitePositionLists);
|
||||
dingTalkScriptVenueService.sendScriptMsg(sb1.toString());
|
||||
dingTalkScriptVenueService.sendScriptMsg(sb2.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VenueInfoDO> queryCanBuyVenue() {
|
||||
return venueInfoManage.queryByType(LocalDate.now(), 0);
|
||||
}
|
||||
|
||||
private void updateDatabase(List<SitePositionList> list) {
|
||||
List<VenueInfoDO> venueInfoDOS = venueInfoManage.queryByDate(LocalDate.now());
|
||||
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)));
|
||||
}
|
||||
List<VenueInfoDO> insertList = Lists.newArrayList();
|
||||
for (SitePositionList sitePositionList : list) {
|
||||
if (map.containsKey(sitePositionList.getId())) {
|
||||
VenueInfoDO venueInfoDO = map.get(sitePositionList.getId());
|
||||
if (!StringUtils.equals(venueInfoDO.getContacts(), sitePositionList.getContacts())) {
|
||||
venueInfoDO.setContacts(sitePositionList.getContacts());
|
||||
venueInfoManage.updateById(venueInfoDO);
|
||||
}
|
||||
} else {
|
||||
VenueInfoDO venueInfoDO = new VenueInfoDO();
|
||||
venueInfoDO.setPlaceName(sitePositionList.getPlaceName());
|
||||
venueInfoDO.setDate(LocalDate.now());
|
||||
venueInfoDO.setPlaceMainId(sitePositionList.getId());
|
||||
venueInfoDO.setPlaceId(sitePositionList.getPlaceId());
|
||||
venueInfoDO.setScheduleId(Integer.valueOf(sitePositionList.getScheduleId()));
|
||||
venueInfoDO.setSjName(sitePositionList.getSjName());
|
||||
venueInfoDO.setCreateTime(LocalDateTime.now());
|
||||
venueInfoDO.setContacts(sitePositionList.getContacts());
|
||||
insertList.add(venueInfoDO);
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(insertList)) {
|
||||
venueInfoManage.saveBatch(insertList);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildMsg(Map<String, List<SitePositionList>> map1, StringBuffer sb1) {
|
||||
map1.forEach((k, v) -> {
|
||||
SitePositionList sitePositionList1 = v.get(0);
|
||||
SitePositionList sitePositionList2 = v.get(1);
|
||||
String contacts = sitePositionList1.getContacts();
|
||||
if (!StringUtils.equals(sitePositionList1.getContacts(), sitePositionList2.getContacts())) {
|
||||
contacts = sitePositionList1.getContacts() + "," + sitePositionList2.getContacts();
|
||||
}
|
||||
sb1.append(k).append("场地,订购人:").append(contacts).append("\n");
|
||||
});
|
||||
}
|
||||
|
||||
private static void putIntoMap(SitePositionList item, Map<String, List<SitePositionList>> map1) {
|
||||
map1.computeIfAbsent(item.getPlaceName(),
|
||||
k -> new ArrayList<>()
|
||||
).add(item);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user