feat:查询江体小程序场地信息
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.constants;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 13:46
|
||||
*/
|
||||
public class UrlConstant {
|
||||
|
||||
/**
|
||||
* 江南体育中心基础URL
|
||||
*/
|
||||
private final static String GNTYZX_BASE_URL = "https://jntyzx.cn:8443";
|
||||
|
||||
/**
|
||||
* 查询当天的场地信息
|
||||
*/
|
||||
public final static String QUERY_SUBSCRIBE_URL = GNTYZX_BASE_URL + "/GYM-JN/multi/Subscribe/getSubscribeByToday";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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.service.JntyzxService;
|
||||
import com.xiang.xservice.basic.common.resp.Result;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 14:28
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class VenueController {
|
||||
|
||||
private final JntyzxService jntyzxService;
|
||||
|
||||
@PostMapping("/queryVenue")
|
||||
public Result<VenueListDTO> queryVenue() {
|
||||
List<VenueListDTO> venueListDTOS = jntyzxService.queryAvailable();
|
||||
return Result.success(venueListDTOS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.entity.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-12-15 13:55
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class VenueListDTO {
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
private String date;
|
||||
|
||||
/**
|
||||
* 场地名称
|
||||
*/
|
||||
private String placeName;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
private String contacts;
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
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
|
||||
@@ -9,5 +13,5 @@ public interface JntyzxService {
|
||||
/**
|
||||
* 查询可用场地
|
||||
*/
|
||||
void queryAvailable() throws Exception;
|
||||
List<VenueListDTO> queryAvailable();
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package com.xiang.xservice.application.script.jntyzx.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.xiang.xmc.service.message.dingTalk.service.DingTalkService;
|
||||
import com.xiang.xservice.application.script.jntyzx.entity.resp.JntyzxResponse;
|
||||
import com.xiang.xservice.application.script.jntyzx.entity.resp.query.QueryVenueResponse;
|
||||
import com.xiang.xmc.service.http.helper.HttpHelper;
|
||||
import com.xiang.xservice.application.script.jntyzx.constants.UrlConstant;
|
||||
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.entity.resp.query.VenueList;
|
||||
import com.xiang.xservice.application.script.xb.common.URLConstants;
|
||||
import com.xiang.xservice.basic.utils.HttpUtils;
|
||||
import com.xiang.xservice.basic.utils.DateUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
@@ -30,54 +30,63 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public class JntyzxServiceImpl implements JntyzxService{
|
||||
|
||||
|
||||
private final DingTalkService dingTalkService;
|
||||
|
||||
@Value("${dingtalk.chatId}")
|
||||
private String chatId;
|
||||
|
||||
@Override
|
||||
public void queryAvailable() throws Exception {
|
||||
String url = URLConstants.JNTYZX_QUERY_TODAY_VENUE;
|
||||
public List<VenueListDTO> queryAvailable() {
|
||||
String url = UrlConstant.QUERY_SUBSCRIBE_URL;
|
||||
Map<String, String> header = Maps.newHashMap();
|
||||
header.put("X-Access-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NDcyMTAwNzQsInVzZXJuYW1lIjoid3hfb3Blbl9pZF9vMjFNWDR5N3doWENHanZVVEdQNkNUejJIYkQ4In0.0h_cAH_e5cCXDQlQN40jZDBgtfrzQWAmgl3YPQf0d-M");
|
||||
header.put("X-Access-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NjU3ODQ1NjMsInVzZXJuYW1lIjoid3hfb3Blbl9pZF9vMjFNWDR5N3doWENHanZVVEdQNkNUejJIYkQ4In0.QBzNQNvJZQPZZnzmbU8K5Liz0piHwercrDIq3kirUJk");
|
||||
String resp = null;
|
||||
Map<String, String> params = Maps.newHashMap();
|
||||
params.put("gid", "03");
|
||||
params.put("isWeekend", "1");
|
||||
try {
|
||||
resp = HttpUtils.doGet(url, header, null);
|
||||
resp = HttpHelper.doGet(url, header, params);
|
||||
} catch (Exception e) {
|
||||
log.error("[doGet] 江南体育中心查询当天场地 请求失败, url:{}", url);
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
if (StringUtils.isEmpty(resp)) {
|
||||
log.warn("[查询场地] 江南体育中心查询当天场地 请求结果为空, url:{}, resp:{}", url, resp);
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
JntyzxResponse response = JSONObject.parseObject(resp, JntyzxResponse.class);
|
||||
String message = "";
|
||||
if (Objects.nonNull(response)) {
|
||||
if (response.getSuccess()) {
|
||||
log.info("[查询场地] 江南体育中心查询当天场地 请求地址:{}, 请求结果:{}", url, resp);
|
||||
JSONObject object = (JSONObject) response.getResult();
|
||||
if (Objects.nonNull(object)) {
|
||||
QueryVenueResponse result = object.toJavaObject(QueryVenueResponse.class);
|
||||
if (Objects.nonNull(result)) {
|
||||
List<VenueList> venueLists = result.getVenue();
|
||||
if (!CollectionUtils.isEmpty(venueLists)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (VenueList venue : venueLists) {
|
||||
List<SitePositionList> positionList = venue.getSitePosition();
|
||||
positionList = positionList.stream().filter(this::filterTime).collect(Collectors.toList());
|
||||
for (SitePositionList sitePositionList : positionList) {
|
||||
sb.append(venue.getPlaceName()).append(":").append(sitePositionList.getSjName()).append(":预定人:").append(sitePositionList.getContacts()).append(",电话:").append(sitePositionList.getContactNumber()).append("\n");
|
||||
JSONObject jsonObject = JSON.parseObject(resp);
|
||||
if (Objects.isNull(jsonObject)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
String resultStr = JSON.toJSONString(jsonObject.get("result"));
|
||||
if (StringUtils.isBlank(resultStr)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
JSONObject result = JSON.parseObject(resultStr);
|
||||
if (Objects.isNull(result)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
String venueStr = JSON.toJSONString(result.get("venue"));
|
||||
if (StringUtils.isBlank(venueStr)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
List<VenueList> venueLists = JSON.parseArray(venueStr, VenueList.class);
|
||||
if (CollectionUtils.isEmpty(venueLists)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
List<VenueListDTO> res = Lists.newArrayList();
|
||||
for (VenueList venueList : venueLists) {
|
||||
List<SitePositionList> sitePositionList = venueList.getSitePosition();
|
||||
if (CollectionUtils.isEmpty(sitePositionList)) {
|
||||
continue;
|
||||
}
|
||||
for (SitePositionList sitePosition : 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);
|
||||
}
|
||||
}
|
||||
message = sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(message)) {
|
||||
dingTalkService.sendChatMessage(chatId, message);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user