From 561e8590782ccea6037fcd50d24429ce8757cb64 Mon Sep 17 00:00:00 2001 From: 44323 <443237572@qq.com> Date: 星期一, 09 十月 2023 09:23:58 +0800 Subject: [PATCH] 广告修改 --- cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/GameDataController.java | 222 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 192 insertions(+), 30 deletions(-) diff --git a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/GameDataController.java b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/GameDataController.java index c01991c..609b06e 100644 --- a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/GameDataController.java +++ b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/GameDataController.java @@ -7,6 +7,8 @@ import com.dsh.guns.modular.system.service.ISiteBookingService; import com.dsh.guns.modular.system.service.IStoreService; import com.dsh.guns.modular.system.service.ITSiteService; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -26,6 +28,8 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; import java.net.URL; import java.text.DecimalFormat; import java.text.SimpleDateFormat; @@ -45,26 +49,105 @@ private IStoreService storeService; @Autowired private ISiteBookingService siteBookingService; + + + + @RequestMapping("/listAll") + @ResponseBody + public Object list(String spaceId,String type,String date,String cityCode){ + if(spaceId==null){ + spaceId=""; + } + if(type==null){ + type="y"; + } + if(date==null){ + date=""; + } + if(cityCode==null){ + cityCode=""; + } + String apiUrl1 = "https://try.daowepark.com/v7/user_api/general/cityGameRanking?space_id="+spaceId+"&type="+type+"&date="+date+"&city_code="+cityCode; + URL url1 = null; + try { + url1 = new URL(apiUrl1); + HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection(); + connection1.setRequestMethod("GET"); + // 发送请求并获取响应 + int responseCode1 = connection1.getResponseCode(); + if (responseCode1 == HttpURLConnection.HTTP_OK) { + BufferedReader reader1 = new BufferedReader(new InputStreamReader(connection1.getInputStream())); + String line1; + StringBuilder response1 = new StringBuilder(); + while ((line1 = reader1.readLine()) != null) { + response1.append(line1); + } + reader1.close(); + // 处理响应数据 + String data1 = response1.toString(); + // 使用Jackson库将JSON字符串转换为Java对象 + ObjectMapper objectMapper1 = new ObjectMapper(); + CityGameOne res1 = objectMapper1.readValue(data1, CityGameOne.class); + List<CityGameDataOne> data2 = res1.getData(); + return data2; + } + } catch (ProtocolException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return new ArrayList<>(); + } /** * 跳转到充值记录页面 */ @RequestMapping("") public String index(Model model) { + try { + // 年度数据 + // 创建 HttpClient 实例 + HttpClient httpClient = HttpClients.createDefault(); + // 创建 POST 请求 + HttpPost httpPost = new HttpPost("https://try.daowepark.com/v7/user_api/general/gameList"); + // 设置请求体数据 + String postData = "sign=0DB011836143EEE2C2E072967C9F4E4B&space_id=1001&sutu_id=1001"; + + StringEntity entity = new StringEntity(postData, ContentType.APPLICATION_FORM_URLENCODED); + httpPost.setEntity(entity); + // 执行请求 + HttpResponse response = httpClient.execute(httpPost); + // 处理响应 + HttpEntity responseEntity = response.getEntity(); + if (responseEntity != null) { + String responseData = EntityUtils.toString(responseEntity); + ObjectMapper objectMapper = new ObjectMapper(); + GameList res = objectMapper.readValue(responseData, GameList.class); + List<GameListData> list = res.getData(); + model.addAttribute("games",list); + } + } catch (IOException e) { + e.printStackTrace(); + } List<String> strings = new ArrayList<>(); List<TSite> list = siteService.list(new QueryWrapper<TSite>()); List<TSite> result = new ArrayList<>(); for (TSite tSite : list) { - if (!strings.contains(tSite.getCity())){ + if (!strings.contains(tSite.getCity())) { strings.add(tSite.getCity()); result.add(tSite); } } List<TStore> stores = storeService.list(new QueryWrapper<TStore>()); - model.addAttribute("list",result); - model.addAttribute("stores",stores); - model.addAttribute("sites",list); + model.addAttribute("list", result); + model.addAttribute("stores", stores); + model.addAttribute("sites", list); return PREFIX + "GameData.html"; } + /** * 获取激战球场统计 */ @@ -79,7 +162,7 @@ // 创建 POST 请求 HttpPost httpPost = new HttpPost("https://try.daowepark.com/v7/user_api/general/getBatterData"); // 设置请求体数据 - String postData = "sign=0DB011836143EEE2C2E072967C9F4E4B&space_id=1001&date_type=y"; + String postData = "sign=0DB011836143EEE2C2E072967C9F4E4B&space_id="+""+"&date_type=y"; StringEntity entity = new StringEntity(postData, ContentType.APPLICATION_FORM_URLENCODED); httpPost.setEntity(entity); @@ -91,17 +174,17 @@ String responseData = EntityUtils.toString(responseEntity); ObjectMapper objectMapper = new ObjectMapper(); Batter batter = objectMapper.readValue(responseData, Batter.class); - result.put("totalNumber",batter.getData().getAll_batter_num()); - result.put("totalTime",batter.getData().getAll_batter_time()); + result.put("totalNumber", batter.getData().getAll_batter_num()); + result.put("totalTime", batter.getData().getAll_batter_time()); List<BatterData> dataList = batter.getData().getList(); // 年份 List<String> yearList = new ArrayList<>(); for (BatterData data : dataList) { yearList.add(data.getDate()); } - result.put("yearList",yearList); + result.put("yearList", yearList); // 年度数据 - result.put("yDataList",dataList); + result.put("yDataList", dataList); } // 获取月度数据 (今年的十二个月数据) Calendar calendar = Calendar.getInstance(); @@ -124,18 +207,19 @@ String responseData = EntityUtils.toString(responseEntity1); ObjectMapper objectMapper = new ObjectMapper(); Batter batter = objectMapper.readValue(responseData, Batter.class); - result.put("totalNumber",batter.getData().getAll_batter_num()); - result.put("totalTime",batter.getData().getAll_batter_time()); + result.put("totalNumber", batter.getData().getAll_batter_num()); + result.put("totalTime", batter.getData().getAll_batter_time()); List<BatterData> dataList = batter.getData().getList(); // 月度数据 - result.put("mDataList",dataList); + result.put("mDataList", dataList); } } catch (Exception e) { e.printStackTrace(); } return result; } + /** * 获取SUTU智慧球门统计 */ @@ -170,8 +254,8 @@ for (SUTUData sutuData : list) { games.add(sutuData.getGame_name()); } - result.put("data1",list); - result.put("games",games); + result.put("data1", list); + result.put("games", games); return result; } else { System.out.println("请求失败: " + responseCode); @@ -181,15 +265,16 @@ } return result; } + /** * 获取SUTU智慧球门统计 */ @RequestMapping("/listSUTU1") @ResponseBody - public Object listSUTU1() { + public Object listSUTU1(String gameId, String time, String spaceId, String cityCode) { Map<String, Object> result = new HashMap<>(); try { - String apiUrl = "https://try.daowepark.com/v7/user_api/general/getSingleGameData?game_id=1&date_type=d&date=2021-02"; + String apiUrl = "https://try.daowepark.com/v7/user_api/general/getSingleGameData?game_id=" + gameId + "&date_type=" + "y" + "&date=" + "" + "&space_id=" + spaceId + "&city_code=" + cityCode; URL url = new URL(apiUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); @@ -207,31 +292,108 @@ String data = response.toString(); // 使用Jackson库将JSON字符串转换为Java对象 ObjectMapper objectMapper = new ObjectMapper(); - SUTU res = objectMapper.readValue(data, SUTU.class); + SUTUOne res = objectMapper.readValue(data, SUTUOne.class); // 场地总入场人数 - String totalNum = res.getData().getTotal_num(); - List<SUTUData> list = res.getData().getList(); - List<String> games = new ArrayList<>(); - for (SUTUData sutuData : list) { - games.add(sutuData.getGame_name()); + List<SUTUDataOne> list = res.getData().getList(); + List<String> years = new ArrayList<>(); + for (SUTUDataOne sutuDataOne : list) { + years.add(sutuDataOne.getDate()); } - result.put("data1",list); - result.put("games",games); - return result; - } else { - System.out.println("请求失败: " + responseCode); + result.put("data1", list); + result.put("years", years); + String monthUrl = ""; + // 月度 + if (!time.contains("-")) { + monthUrl = "https://try.daowepark.com/v7/user_api/general/getSingleGameData?game_id=" + gameId + "&date_type=" + "m" + "&date=" + time + "&space_id=" + spaceId + "&city_code=" + cityCode; + } else { + monthUrl = "https://try.daowepark.com/v7/user_api/general/getSingleGameData?game_id=" + gameId + "&date_type=" + "d" + "&date=" + time + "&space_id=" + spaceId + "&city_code=" + cityCode; + } + URL url1 = new URL(monthUrl); + HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection(); + connection1.setRequestMethod("GET"); + // 发送请求并获取响应 + int responseCode1 = connection1.getResponseCode(); + if (responseCode1 == HttpURLConnection.HTTP_OK) { + BufferedReader reader1 = new BufferedReader(new InputStreamReader(connection1.getInputStream())); + String line1; + StringBuilder response1 = new StringBuilder(); + while ((line1 = reader1.readLine()) != null) { + response1.append(line1); + } + reader1.close(); + // 处理响应数据 + String data1 = response1.toString(); + // 使用Jackson库将JSON字符串转换为Java对象 + ObjectMapper objectMapper1 = new ObjectMapper(); + SUTUOne res1 = objectMapper1.readValue(data1, SUTUOne.class); + List<SUTUDataOne> list2 = res1.getData().getList(); + List<String> monthOrDays = new ArrayList<>(); + for (SUTUDataOne sutuDataOne : list2) { + monthOrDays.add(sutuDataOne.getDate()); + } + result.put("data2", list2); + result.put("monthOrDays", monthOrDays); + return result; + } else { + System.out.println("请求失败: " + responseCode1); + } } + return result; + } catch (ProtocolException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } catch (MalformedURLException e) { + e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; } + /** + * 获取跨城赛统计 + */ + @RequestMapping("/cityGame") + @ResponseBody + public Object cityGame() { + Map<String, Object> result = new HashMap<>(); + try { + String apiUrl = "https://try.daowepark.com/v7/user_api/general/getCityGameCount"; + URL url = new URL(apiUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + // 发送请求并获取响应 + int responseCode = connection.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + StringBuilder response = new StringBuilder(); + while ((line = reader.readLine()) != null) { + response.append(line); + } + reader.close(); + // 处理响应数据 + String data = response.toString(); + // 使用Jackson库将JSON字符串转换为Java对象 + ObjectMapper objectMapper = new ObjectMapper(); + CityGame res = objectMapper.readValue(data, CityGame.class); + // 场地总入场人数 + String totalNum = ""; + for (CityGameData datum : res.getData()) { + totalNum = datum.getTotal_num(); + } + result.put("totalNum", totalNum); - - + return result; + } + } + catch (IOException e) { + e.printStackTrace(); + } + return result; + } } - -- Gitblit v1.7.1