KKSU
2023-11-30 93a790d54eaf6041039f96bd5d585c6333262fe2
后台修改
2 files modified
3 files added
394 ■■■■ changed files
src/main/java/cc/mrbird/febs/dapp/controller/ApiCommonController.java 320 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/soccer/dto/GameApiDto.java 25 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/soccer/entity/SoccerGame.java 33 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/soccer/mapper/SoccerGameMapper.java 7 ●●●●● patch | view | raw | blame | history
src/main/resources/templates/febs/views/dapp/soccerLeagues.html 9 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/controller/ApiCommonController.java
@@ -10,16 +10,21 @@
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.DateTime;
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;
@@ -35,6 +40,13 @@
import org.jline.utils.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
/**
 * @author
@@ -52,6 +64,7 @@
    private final DappMemberService dappMemberService;
    private final IMallNewsInfoService newsService;
    private final SoccerLeaguesMapper soccerLeaguesMapper;
    private final SoccerGameMapper soccerGameMapper;
    @ApiOperation(value = "地址是否存在", notes = "地址是否存在")
    @GetMapping(value = "/exist/{address}")
@@ -197,85 +210,250 @@
        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);
    @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.getSeason();
        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();
        }
        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 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);
                    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);
    }
//    @ApiOperation(value = "头部数据", notes = "头部数据")
src/main/java/cc/mrbird/febs/dapp/soccer/dto/GameApiDto.java
New file
@@ -0,0 +1,25 @@
package cc.mrbird.febs.dapp.soccer.dto;
import lombok.Data;
@Data
public class GameApiDto {
    /**
     * integer = 4 characters YYYY
     * The season of the league
     */
    private Integer league;
    /**
     * integer = 4 characters YYYY
     * The season of the league
     */
    private Integer season;
    private String fromDate;
    private String toDate;
    private String status;
    private String timezone;
}
src/main/java/cc/mrbird/febs/dapp/soccer/entity/SoccerGame.java
New file
@@ -0,0 +1,33 @@
package cc.mrbird.febs.dapp.soccer.entity;
import cc.mrbird.febs.common.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
@Data
@TableName("soccer_game")
public class SoccerGame extends BaseEntity {
    private Integer leaguesId;
    private Integer leaguesSeason;
    private String leaguesRound;
    private Integer gameId;
    private String gameState;
    private Date gameDate;
    private Integer homeId;
    private String homeName;
    private String homeLogo;
    private Integer homeGoal;
    private String homeWinner;
    private Integer awayId;
    private String awayName;
    private String awayLogo;
    private Integer awayGoal;
    private String awayWinner;
}
src/main/java/cc/mrbird/febs/dapp/soccer/mapper/SoccerGameMapper.java
New file
@@ -0,0 +1,7 @@
package cc.mrbird.febs.dapp.soccer.mapper;
import cc.mrbird.febs.dapp.soccer.entity.SoccerGame;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface SoccerGameMapper extends BaseMapper<SoccerGame> {
}
src/main/resources/templates/febs/views/dapp/soccerLeagues.html
@@ -51,7 +51,7 @@
        // 初始化表格操作栏各个按钮功能
        table.on('tool(goodsTable)', function (obj) {
        table.on('tool(leaguesTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'seeImgThumb') {
@@ -98,15 +98,12 @@
                url: ctx + 'member/leaguesList',
                cols: [[
                    {field: 'leaguesId', title: '联赛ID', minWidth: 100},
                    {field: 'leaguesName', title: '联赛名称', minWidth: 100},
                    {field: 'leaguesType', title: '联赛类型', minWidth: 130},
                    {field: 'leaguesName', title: '联赛名称', minWidth: 200},
                    {field: 'leaguesType', title: '联赛类型', minWidth: 100},
                    {field: 'leaguesLogo', title: '联赛LOGO',
                        templet: function (d) {
                            return '<a lay-event="seeImgThumb"><img id="seeImgThumb'+d.id+'" src="'+d.leaguesLogo+'" alt=""></a>';
                        }, minWidth: 150,align:'center'},
                    {field: 'leaguesLogo', title: '联赛LOGO', minWidth: 130},
                    {field: 'leaguesStart', title: '开始时间', minWidth: 130},
                    {field: 'leaguesEnd', title: '结束时间', minWidth: 130},
                ]]
            });
        }