44323
2023-10-10 794546783a941be444319d98b1947dac23d65c2b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
package com.dsh.guns.modular.system.controller.code;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.course.feignClient.other.model.Site;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.modular.system.model.*;
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;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.io.BufferedReader;
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;
import java.util.*;
 
/**
 * 智慧球场统计控制器
 *
 */
@Controller
@RequestMapping("/gameData")
public class GameDataController extends BaseController {
    private String PREFIX = "/system/gameData/";
    @Autowired
    private ITSiteService siteService;
    @Autowired
    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("/listAll1")
    @ResponseBody
    public Object listAll1(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/accuracyGameRanking?space_id=1001"+spaceId+"&type="+type+"&date="+date+"&city_code="+cityCode;
        String apiUrl1 = "https://try.daowepark.com/v7/user_api/general/accuracyGameRanking?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();
                AccuracyGameOne res1 = objectMapper1.readValue(data1, AccuracyGameOne.class);
                List<AccuracyGameDataOne> 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())) {
                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);
        return PREFIX + "GameData.html";
    }
 
    /**
     * 获取激战球场统计
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object list(String storeId) {
        Map<String, Object> result = new HashMap<>();
        try {
            // 年度数据
            // 创建 HttpClient 实例
            HttpClient httpClient = HttpClients.createDefault();
            // 创建 POST 请求
            HttpPost httpPost = new HttpPost("https://try.daowepark.com/v7/user_api/general/getBatterData");
            // 设置请求体数据
            String postData = "sign=0DB011836143EEE2C2E072967C9F4E4B&space_id="+storeId+"&date_type=y"+"&year=";
 
            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();
                Batter batter = objectMapper.readValue(responseData, Batter.class);
                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("yDataList", dataList);
            }
            // 获取月度数据 (今年的十二个月数据)
            Calendar calendar = Calendar.getInstance();
            // 当前年份
            int year = calendar.get(Calendar.YEAR);
            // 月度数据
            // 创建 HttpClient 实例
            HttpClient httpClient1 = HttpClients.createDefault();
            // 创建 POST 请求
            HttpPost httpPost1 = new HttpPost("https://try.daowepark.com/v7/user_api/general/getBatterData");
            // 设置请求体数据
            String postData1 = "sign=0DB011836143EEE2C2E072967C9F4E4B&space_id=1001"+""+"&date_type=m"+"&year="+year;
            StringEntity entity1 = new StringEntity(postData1, ContentType.APPLICATION_FORM_URLENCODED);
            httpPost1.setEntity(entity1);
            // 执行请求
            HttpResponse response1 = httpClient1.execute(httpPost1);
            // 处理响应
            HttpEntity responseEntity1 = response1.getEntity();
            if (responseEntity1 != null) {
                String responseData1 = EntityUtils.toString(responseEntity1);
                ObjectMapper objectMapper = new ObjectMapper();
                Batter batter = objectMapper.readValue(responseData1, Batter.class);
                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);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
 
    /**
     * 获取SUTU智慧球门统计
     */
    @RequestMapping("/listSUTU")
    @ResponseBody
    public Object listSUTU() {
        Map<String, Object> result = new HashMap<>();
        try {
            String apiUrl = "https://try.daowepark.com/v7/user_api/general/gameDataRate";
            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();
                SUTU res = objectMapper.readValue(data, SUTU.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());
                }
                result.put("data1", list);
                result.put("games", games);
                return result;
            } else {
                System.out.println("请求失败: " + responseCode);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
 
    /**
     * 获取SUTU智慧球门统计
     */
    @RequestMapping("/listSUTU1")
    @ResponseBody
    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=" + gameId + "&date_type=" + "y" + "&date=" + "" + "&space_id=" + spaceId + "&city_code=" + cityCode;
            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();
                SUTUOne res = objectMapper.readValue(data, SUTUOne.class);
                // 场地总入场人数
                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("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;
    }
    /**
     * 获取90°准度赛全球总数
     */
    @RequestMapping("/cityGameOne")
    @ResponseBody
    public Object cityGameOne() {
        Map<String, Object> result = new HashMap<>();
        try {
            String apiUrl = "https://try.daowepark.com/v7/user_api/general/getAccuracyGameCount?space_id=";
            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);
                result.put("totalNum", res.getData().getTotal_num());
                    return result;
                }
            }
         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);
                result.put("totalNum", res.getData().getTotal_num());
                return result;
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}