feat:定时任务查询
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package com.xiang.xservice.application.script.jntyzx.controller;
|
package com.xiang.xservice.application.script.jntyzx.controller;
|
||||||
|
|
||||||
import com.xiang.xservice.application.script.jntyzx.entity.dto.VenueListDTO;
|
import com.xiang.xservice.application.script.jntyzx.entity.resp.query.SitePositionList;
|
||||||
import com.xiang.xservice.application.script.jntyzx.service.JntyzxService;
|
import com.xiang.xservice.application.script.jntyzx.service.IVenueServiceHttp;
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -17,11 +17,15 @@ import java.util.List;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class VenueController {
|
public class VenueController {
|
||||||
|
|
||||||
private final JntyzxService jntyzxService;
|
private final IVenueServiceHttp venueServiceHttp;
|
||||||
|
|
||||||
|
private final static String STATIC_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NjU3ODQ1NjMsInVzZXJuYW1lIjoid3hfb3Blbl9pZF9vMjFNWDR5N3doWENHanZVVEdQNkNUejJIYkQ4In0.QBzNQNvJZQPZZnzmbU8K5Liz0piHwercrDIq3kirUJk";
|
||||||
|
|
||||||
@PostMapping("/queryVenue")
|
@PostMapping("/queryVenue")
|
||||||
public Result<VenueListDTO> queryVenue() {
|
public Result<SitePositionList> queryVenue() {
|
||||||
List<VenueListDTO> venueListDTOS = jntyzxService.queryAvailable();
|
List<SitePositionList> venueListDTOS = venueServiceHttp.queryAvailable("1", STATIC_TOKEN);
|
||||||
return Result.success(venueListDTOS);
|
return Result.success(venueListDTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ public class VenueListDTO {
|
|||||||
*/
|
*/
|
||||||
private String date;
|
private String date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间
|
||||||
|
*/
|
||||||
|
private String sjName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 场地名称
|
* 场地名称
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
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 lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-12-15 15:02
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class VenueQuerySchedule {
|
||||||
|
|
||||||
|
private final static String STATIC_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NjU3ODQ1NjMsInVzZXJuYW1lIjoid3hfb3Blbl9pZF9vMjFNWDR5N3doWENHanZVVEdQNkNUejJIYkQ4In0.QBzNQNvJZQPZZnzmbU8K5Liz0piHwercrDIq3kirUJk";
|
||||||
|
private final IVenueServiceHttp venueServiceHttp;
|
||||||
|
private final DingTalkScriptVenueService dingTalkScriptVenueService;
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0/5 9-15 * * ?")
|
||||||
|
public void venueQueryTask4Free() {
|
||||||
|
venueQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0/5 15-17 * * ?")
|
||||||
|
public void venueQueryTask4Normal() {
|
||||||
|
venueQuery();
|
||||||
|
}
|
||||||
|
@Scheduled(cron = "0 0/5 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.newHashMap();
|
||||||
|
// 8-10场地
|
||||||
|
Map<String, List<SitePositionList>> map2 = Maps.newHashMap();
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.xiang.xservice.application.script.jntyzx.service;
|
||||||
|
|
||||||
|
import com.xiang.xmc.service.message.dingTalk.service.DingTalkService;
|
||||||
|
import com.xiang.xservice.config.DingTalkRobotVenueConfig;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-07 10:30
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DingTalkScriptVenueService {
|
||||||
|
|
||||||
|
private final DingTalkService dingTalkService;
|
||||||
|
private final DingTalkRobotVenueConfig dingTalkRobotVenueConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送脚本消息
|
||||||
|
* @param msg 消息
|
||||||
|
*/
|
||||||
|
public void sendScriptMsg(String msg) {
|
||||||
|
try {
|
||||||
|
dingTalkService.sendRobotMessage(dingTalkRobotVenueConfig.getSecret(), dingTalkRobotVenueConfig.getToken(),
|
||||||
|
dingTalkRobotVenueConfig.getUsers(), msg);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("信息发送异常, 信息:{}", msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.xiang.xservice.application.script.jntyzx.service;
|
||||||
|
|
||||||
|
import com.xiang.xservice.application.script.jntyzx.entity.resp.query.SitePositionList;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-12-15 14:47
|
||||||
|
*/
|
||||||
|
public interface IVenueServiceHttp {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询今日6-10可用场地
|
||||||
|
*/
|
||||||
|
List<SitePositionList> queryAvailable(String isWeekend, String token);
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.xiang.xservice.application.script.jntyzx.service;
|
|
||||||
|
|
||||||
import com.xiang.xservice.application.script.jntyzx.entity.dto.VenueListDTO;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: xiang
|
|
||||||
* @Date: 2025-05-14 14:06
|
|
||||||
*/
|
|
||||||
public interface JntyzxService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询可用场地
|
|
||||||
*/
|
|
||||||
List<VenueListDTO> queryAvailable();
|
|
||||||
}
|
|
||||||
@@ -28,17 +28,17 @@ import java.util.Objects;
|
|||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class JntyzxServiceImpl implements JntyzxService{
|
public class VenueServiceHttpImpl implements IVenueServiceHttp {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VenueListDTO> queryAvailable() {
|
public List<SitePositionList> queryAvailable(String isWeekend, String token) {
|
||||||
String url = UrlConstant.QUERY_SUBSCRIBE_URL;
|
String url = UrlConstant.QUERY_SUBSCRIBE_URL;
|
||||||
Map<String, String> header = Maps.newHashMap();
|
Map<String, String> header = Maps.newHashMap();
|
||||||
header.put("X-Access-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NjU3ODQ1NjMsInVzZXJuYW1lIjoid3hfb3Blbl9pZF9vMjFNWDR5N3doWENHanZVVEdQNkNUejJIYkQ4In0.QBzNQNvJZQPZZnzmbU8K5Liz0piHwercrDIq3kirUJk");
|
header.put("X-Access-Token", token);
|
||||||
String resp = null;
|
String resp = null;
|
||||||
Map<String, String> params = Maps.newHashMap();
|
Map<String, String> params = Maps.newHashMap();
|
||||||
params.put("gid", "03");
|
params.put("gid", "03");
|
||||||
params.put("isWeekend", "1");
|
params.put("isWeekend", isWeekend);
|
||||||
try {
|
try {
|
||||||
resp = HttpHelper.doGet(url, header, params);
|
resp = HttpHelper.doGet(url, header, params);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -69,22 +69,13 @@ public class JntyzxServiceImpl implements JntyzxService{
|
|||||||
if (CollectionUtils.isEmpty(venueLists)) {
|
if (CollectionUtils.isEmpty(venueLists)) {
|
||||||
return Lists.newArrayList();
|
return Lists.newArrayList();
|
||||||
}
|
}
|
||||||
List<VenueListDTO> res = Lists.newArrayList();
|
List<SitePositionList> res = Lists.newArrayList();
|
||||||
for (VenueList venueList : venueLists) {
|
for (VenueList venueList : venueLists) {
|
||||||
List<SitePositionList> sitePositionList = venueList.getSitePosition();
|
List<SitePositionList> sitePositionList = venueList.getSitePosition();
|
||||||
if (CollectionUtils.isEmpty(sitePositionList)) {
|
if (CollectionUtils.isEmpty(sitePositionList)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (SitePositionList sitePosition : sitePositionList) {
|
res.addAll(sitePositionList);
|
||||||
if (!filterTime(sitePosition)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
VenueListDTO venueListDTO = new VenueListDTO();
|
|
||||||
venueListDTO.setDate(DateUtils.getDateFromDate(LocalDate.now()) + " " + sitePosition.getSjName());
|
|
||||||
venueListDTO.setPlaceName(sitePosition.getPlaceName());
|
|
||||||
venueListDTO.setContacts(sitePosition.getContacts());
|
|
||||||
res.add(venueListDTO);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.xiang.xservice.config;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-12-15 15:20
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties(prefix = "dingtalk.robot.venue")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class DingTalkRobotVenueConfig {
|
||||||
|
private String token;
|
||||||
|
private String secret;
|
||||||
|
private List<String> users;
|
||||||
|
}
|
||||||
@@ -51,3 +51,8 @@ dingtalk:
|
|||||||
secret: SECc09d8aad6635f1a4cbadb7c0ab365523c46299f138438cd885e445e0f5f4d730
|
secret: SECc09d8aad6635f1a4cbadb7c0ab365523c46299f138438cd885e445e0f5f4d730
|
||||||
users:
|
users:
|
||||||
- 450841600726084717
|
- 450841600726084717
|
||||||
|
venue:
|
||||||
|
token: 6a218646972c684c75832b0229ea93a234778af537d7469ce96bef290faf530e
|
||||||
|
secret: SEC9018755ba86d3e5c1ed2fbfa1d6953d84bb2a6c8ebe7ed4e318457bfed5e0465
|
||||||
|
users:
|
||||||
|
- 450841600726084717
|
||||||
Reference in New Issue
Block a user