KKSU
2024-05-11 04b73bbb2b20f0c3bef5c8ca94edf97eeb9d0994
src/main/java/cc/mrbird/febs/dapp/controller/ApiCommonController.java
@@ -1,25 +1,25 @@
package cc.mrbird.febs.dapp.controller;
import cc.mrbird.febs.common.annotation.EncryptEnable;
import cc.mrbird.febs.common.contants.AppContants;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.dapp.dto.*;
import cc.mrbird.febs.dapp.dto.ConnectDto;
import cc.mrbird.febs.dapp.dto.MallGoodsQueryDto;
import cc.mrbird.febs.dapp.dto.NewsListDto;
import cc.mrbird.febs.dapp.entity.DappMemberEntity;
import cc.mrbird.febs.dapp.entity.MallNewsInfo;
import cc.mrbird.febs.dapp.service.DappMemberService;
import cc.mrbird.febs.dapp.service.DappSimulateDataService;
import cc.mrbird.febs.dapp.service.DappSystemService;
import cc.mrbird.febs.dapp.service.IMallNewsInfoService;
import cc.mrbird.febs.dapp.soccer.dto.GameApiDto;
import cc.mrbird.febs.dapp.soccer.dto.LeaguesApiDto;
import cc.mrbird.febs.dapp.soccer.entity.SoccerGame;
import cc.mrbird.febs.dapp.soccer.entity.SoccerLeagues;
import cc.mrbird.febs.dapp.soccer.mapper.SoccerGameMapper;
import cc.mrbird.febs.dapp.soccer.mapper.SoccerLeaguesMapper;
import cc.mrbird.febs.dapp.vo.MallGoodsListVo;
import cc.mrbird.febs.dapp.vo.NewsListVo;
import cc.mrbird.febs.dapp.vo.SimulateDataVo;
import cc.mrbird.febs.rabbit.producer.ChainProducer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
@@ -32,16 +32,17 @@
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jline.utils.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
/**
 * @author
 * @date 2022-03-17
 **/
@Slf4j
@EncryptEnable
//@EncryptEnable
@RequiredArgsConstructor
@CrossOrigin("*")
@RestController
@@ -52,6 +53,7 @@
    private final DappMemberService dappMemberService;
    private final IMallNewsInfoService newsService;
    private final SoccerLeaguesMapper soccerLeaguesMapper;
    private final SoccerGameMapper soccerGameMapper;
    @ApiOperation(value = "地址是否存在", notes = "地址是否存在")
    @GetMapping(value = "/exist/{address}")
@@ -128,7 +130,7 @@
    }
    @ApiOperation(value = "获取国家", notes = "获取国家")
    @GetMapping(value = "/testApi")
    @GetMapping(value = "/countries")
    public FebsResponse testApi() {
        HttpResponse<String> response = null;
        try {
@@ -197,84 +199,249 @@
        return new FebsResponse().success();
    }
    public static void main(String[] args) {
        String json = "{\n" +
                "  \"get\": \"leagues\",\n" +
                "  \"parameters\": {\n" +
                "    \"id\": \"53\",\n" +
                "    \"season\": \"2023\",\n" +
                "    \"current\": \"true\"\n" +
                "  },\n" +
                "  \"errors\": [],\n" +
                "  \"results\": 1,\n" +
                "  \"paging\": {\n" +
                "    \"current\": 1,\n" +
                "    \"total\": 1\n" +
                "  },\n" +
                "  \"response\": [\n" +
                "    {\n" +
                "      \"league\": {\n" +
                "        \"id\": 53,\n" +
                "        \"name\": \"Non League Div One - Isthmian South Central\",\n" +
                "        \"type\": \"League\",\n" +
                "        \"logo\": \"https://media-4.api-sports.io/football/leagues/53.png\"\n" +
                "      },\n" +
                "      \"country\": {\n" +
                "        \"name\": \"England\",\n" +
                "        \"code\": \"GB\",\n" +
                "        \"flag\": \"https://media-4.api-sports.io/flags/gb.svg\"\n" +
                "      },\n" +
                "      \"seasons\": [\n" +
                "        {\n" +
                "          \"year\": 2023,\n" +
                "          \"start\": \"2023-08-12\",\n" +
                "          \"end\": \"2024-04-27\",\n" +
                "          \"current\": true,\n" +
                "          \"coverage\": {\n" +
                "            \"fixtures\": {\n" +
                "              \"events\": false,\n" +
                "              \"lineups\": false,\n" +
                "              \"statistics_fixtures\": false,\n" +
                "              \"statistics_players\": false\n" +
                "            },\n" +
                "            \"standings\": true,\n" +
                "            \"players\": true,\n" +
                "            \"top_scorers\": true,\n" +
                "            \"top_assists\": true,\n" +
                "            \"top_cards\": true,\n" +
                "            \"injuries\": false,\n" +
                "            \"predictions\": true,\n" +
                "            \"odds\": false\n" +
                "          }\n" +
                "        }\n" +
                "      ]\n" +
                "    }\n" +
                "  ]\n" +
                "}\n";
        JSONObject parseObj = JSONUtil.parseObj(json);
        Object response = parseObj.get("response");
        JSONArray jsonArray = JSONUtil.parseArray(response);
        if(CollUtil.isNotEmpty(jsonArray)){
            for(Object list : jsonArray){
                JSONObject parseObj1 = JSONUtil.parseObj(list);
                Object leagueObj = parseObj1.get("league");
                JSONObject parseObjLeague = JSONUtil.parseObj(leagueObj);
                JSONObject leagueStr = JSONUtil.parseObj(parseObjLeague);
                System.out.println(leagueStr);
                int id = (int)leagueStr.get("id");
                String type = (String)leagueStr.get("type");
                String name = (String)leagueStr.get("name");
                String logo = (String)leagueStr.get("logo");
                System.out.println(id);
                System.out.println(type);
                System.out.println(name);
                System.out.println(logo);
            }
    @ApiOperation(value = "获取联赛里面的剩余赛程", notes = "获取联赛里面的剩余赛程")
    @PostMapping(value = "/gameApi")
    public FebsResponse gameApi(GameApiDto gameApiDto) {
        HttpResponse<String> response = null;
        int league = ObjectUtil.isEmpty(gameApiDto.getLeague()) ? DateUtil.date().year() : gameApiDto.getLeague();
        int season = ObjectUtil.isEmpty(gameApiDto.getSeason()) ? DateUtil.date().year() : gameApiDto.getSeason();
        String fromDate = ObjectUtil.isEmpty(gameApiDto.getFromDate()) ? DateUtil.today() : gameApiDto.getFromDate();
        String toDate = ObjectUtil.isEmpty(gameApiDto.getToDate()) ? DateUtil.today() : gameApiDto.getToDate();
        String status = ObjectUtil.isEmpty(gameApiDto.getStatus()) ? "NS" : gameApiDto.getStatus();
        try {
            /**
             *  https://v3.football.api-sports.io/leagues?season=2023¤t=true
             */
            response = Unirest.get(" https://v3.football.api-sports.io/fixtures")
                    .header("x-rapidapi-key", "87f8d87d629d1704ba49622cb978eb81")
                    .header("x-rapidapi-host", "v3.football.api-sports.io")
                    .queryString("league",league)
                    .queryString("season",season)
                    .queryString("from",fromDate)
                    .queryString("to",toDate)
                    .queryString("status",status)
                    .queryString("timezone","UTC")
                    .asString();
        } catch (UnirestException e) {
            e.printStackTrace();
        }
        System.out.println(jsonArray);
        log.info(String.valueOf(response));
        log.info(response.getBody());
        JSONObject parseObj = JSONUtil.parseObj(response.getBody());
        Object responseStr = parseObj.get("response");
        if(ObjectUtil.isNotEmpty(responseStr)){
            JSONArray jsonArray = JSONUtil.parseArray(responseStr);
            if(CollUtil.isNotEmpty(jsonArray)){
                for(Object list : jsonArray){
                    JSONObject jsonObject = JSONUtil.parseObj(list);
                    Integer gameId = jsonObject.getJSONObject("fixture").getInt("id");
                    System.out.println(gameId);
                    String gameDateStr = jsonObject.getJSONObject("fixture").getStr("date");
                    List<String> split = StrUtil.split(gameDateStr, "+");
                    Date gameDate = DateUtil.parse(split.get(0));
                    System.out.println(gameDate);
                    String gameState = jsonObject.getJSONObject("fixture").getJSONObject("status").getStr("short");
                    System.out.println(gameState);
                    Integer leaguesId = jsonObject.getJSONObject("league").getInt("id");
                    System.out.println(leaguesId);
                    Integer leaguesSeason = jsonObject.getJSONObject("league").getInt("season");
                    System.out.println(leaguesSeason);
                    String leaguesRound = jsonObject.getJSONObject("league").getStr("round");
                    System.out.println(leaguesRound);
                    int homeId = jsonObject.getJSONObject("teams").getJSONObject("home").getInt("id");
                    System.out.println(homeId);
                    String homeName = jsonObject.getJSONObject("teams").getJSONObject("home").getStr("name");
                    System.out.println(homeName);
                    String homeLogo = jsonObject.getJSONObject("teams").getJSONObject("home").getStr("logo");
                    System.out.println(homeLogo);
                    String homeWinner = jsonObject.getJSONObject("teams").getJSONObject("home").getBool("winner").toString();
                    System.out.println(homeWinner);
                    int awayId = jsonObject.getJSONObject("teams").getJSONObject("away").getInt("id");
                    System.out.println(awayId);
                    String awayName = jsonObject.getJSONObject("teams").getJSONObject("away").getStr("name");
                    System.out.println(awayName);
                    String awayLogo = jsonObject.getJSONObject("teams").getJSONObject("away").getStr("logo");
                    System.out.println(awayLogo);
                    String awayWinner = jsonObject.getJSONObject("teams").getJSONObject("away").getBool("winner").toString();
                    System.out.println(awayWinner);
                    int homeGoal = jsonObject.getJSONObject("goals").getInt("home");
                    System.out.println(homeGoal);
                    int awayGoal = jsonObject.getJSONObject("goals").getInt("away");
                    System.out.println(awayGoal);
                    SoccerGame soccerGame = new SoccerGame();
                    soccerGame.setLeaguesId(leaguesId);
                    soccerGame.setLeaguesSeason(leaguesSeason);
                    soccerGame.setLeaguesRound(leaguesRound);
                    soccerGame.setGameId(gameId);
                    soccerGame.setGameState(gameState);
                    soccerGame.setGameDate(gameDate);
                    soccerGame.setHomeId(homeId);
                    soccerGame.setHomeName(homeName);
                    soccerGame.setHomeLogo(homeLogo);
                    soccerGame.setHomeGoal(homeGoal);
                    soccerGame.setHomeWinner(homeWinner);
                    soccerGame.setAwayId(awayId);
                    soccerGame.setAwayName(awayName);
                    soccerGame.setAwayLogo(awayLogo);
                    soccerGame.setAwayGoal(awayGoal);
                    soccerGame.setAwayWinner(awayWinner);
                    soccerGameMapper.insert(soccerGame);
                }
            }
            System.out.println(jsonArray);
        }
        log.info(String.valueOf(response.getRawBody()));
        return new FebsResponse().success();
    }
//    public static void main(String[] args) {
//        String today = DateUtil.today();
//        System.out.println(today);
//        int year = DateUtil.year(DateUtil.date());
//        System.out.println(year);
//    }
    /**
     * 获取联赛
     */
    public static void main(String[] args) {
        String list = "{\n" +
                "  \"fixture\": {\n" +
                "    \"id\": 971240,\n" +
                "    \"referee\": \"Nicolas Lamolina, Argentina\",\n" +
                "    \"timezone\": \"UTC\",\n" +
                "    \"date\": \"2023-09-21T00:00:00+00:00\",\n" +
                "    \"timestamp\": 1695254400,\n" +
                "    \"periods\": {\n" +
                "      \"first\": 1695254400,\n" +
                "      \"second\": 1695258000\n" +
                "    },\n" +
                "    \"venue\": {\n" +
                "      \"id\": 99,\n" +
                "      \"name\": \"Estadio Presidente Juan Domingo Perón\",\n" +
                "      \"city\": \"Avellaneda, Provincia de Buenos Aires\"\n" +
                "    },\n" +
                "    \"status\": {\n" +
                "      \"long\": \"Match Finished\",\n" +
                "      \"short\": \"FT\",\n" +
                "      \"elapsed\": 90\n" +
                "    }\n" +
                "  },\n" +
                "  \"league\": {\n" +
                "    \"id\": 1032,\n" +
                "    \"name\": \"Copa de la Liga Profesional\",\n" +
                "    \"country\": \"Argentina\",\n" +
                "    \"logo\": \"https://media-4.api-sports.io/football/leagues/1032.png\",\n" +
                "    \"flag\": \"https://media-4.api-sports.io/flags/ar.svg\",\n" +
                "    \"season\": 2023,\n" +
                "    \"round\": \"Round - 5\"\n" +
                "  },\n" +
                "  \"teams\": {\n" +
                "    \"home\": {\n" +
                "      \"id\": 436,\n" +
                "      \"name\": \"Racing Club\",\n" +
                "      \"logo\": \"https://media-4.api-sports.io/football/teams/436.png\",\n" +
                "      \"winner\": true\n" +
                "    },\n" +
                "    \"away\": {\n" +
                "      \"id\": 457,\n" +
                "      \"name\": \"Newells Old Boys\",\n" +
                "      \"logo\": \"https://media-4.api-sports.io/football/teams/457.png\",\n" +
                "      \"winner\": false\n" +
                "    }\n" +
                "  },\n" +
                "  \"goals\": {\n" +
                "    \"home\": 2,\n" +
                "    \"away\": 1\n" +
                "  },\n" +
                "  \"score\": {\n" +
                "    \"halftime\": {\n" +
                "      \"home\": 0,\n" +
                "      \"away\": 0\n" +
                "    },\n" +
                "    \"fulltime\": {\n" +
                "      \"home\": 2,\n" +
                "      \"away\": 1\n" +
                "    },\n" +
                "    \"extratime\": {\n" +
                "      \"home\": null,\n" +
                "      \"away\": null\n" +
                "    },\n" +
                "    \"penalty\": {\n" +
                "      \"home\": null,\n" +
                "      \"away\": null\n" +
                "    }\n" +
                "  }\n" +
                "}\n";
        JSONObject jsonObject = JSONUtil.parseObj(list);
        Integer gameId = jsonObject.getJSONObject("fixture").getInt("id");
        System.out.println(gameId);
        String gameDateStr = jsonObject.getJSONObject("fixture").getStr("date");
        List<String> split = StrUtil.split(gameDateStr, "+");
        Date gameDate = DateUtil.parse(split.get(0));
        System.out.println(gameDate);
        String gameState = jsonObject.getJSONObject("fixture").getJSONObject("status").getStr("short");
        System.out.println(gameState);
        Integer leaguesId = jsonObject.getJSONObject("league").getInt("id");
        System.out.println(leaguesId);
        Integer leaguesSeason = jsonObject.getJSONObject("league").getInt("season");
        System.out.println(leaguesSeason);
        String leaguesRound = jsonObject.getJSONObject("league").getStr("round");
        System.out.println(leaguesRound);
        int homeId = jsonObject.getJSONObject("teams").getJSONObject("home").getInt("id");
        System.out.println(homeId);
        String homeName = jsonObject.getJSONObject("teams").getJSONObject("home").getStr("name");
        System.out.println(homeName);
        String homeLogo = jsonObject.getJSONObject("teams").getJSONObject("home").getStr("logo");
        System.out.println(homeLogo);
        String homeWinner = jsonObject.getJSONObject("teams").getJSONObject("home").getBool("winner").toString();
        System.out.println(homeWinner);
        int awayId = jsonObject.getJSONObject("teams").getJSONObject("away").getInt("id");
        System.out.println(awayId);
        String awayName = jsonObject.getJSONObject("teams").getJSONObject("away").getStr("name");
        System.out.println(awayName);
        String awayLogo = jsonObject.getJSONObject("teams").getJSONObject("away").getStr("logo");
        System.out.println(awayLogo);
        String awayWinner = jsonObject.getJSONObject("teams").getJSONObject("away").getBool("winner").toString();
        System.out.println(awayWinner);
        int homeGoal = jsonObject.getJSONObject("goals").getInt("home");
        System.out.println(homeGoal);
        int awayGoal = jsonObject.getJSONObject("goals").getInt("away");
        System.out.println(awayGoal);
    }