| | |
| | | package cc.mrbird.febs.dapp.controller; |
| | | |
| | | import cc.mrbird.febs.common.annotation.EncryptEnable; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.dapp.dto.ApproveDto; |
| | | import cc.mrbird.febs.dapp.dto.ConnectDto; |
| | | import cc.mrbird.febs.dapp.dto.EncryptDto; |
| | | import cc.mrbird.febs.dapp.dto.SystemDto; |
| | | 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.vo.SimulateDataVo; |
| | | 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 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; |
| | | import com.mashape.unirest.http.HttpResponse; |
| | | import com.mashape.unirest.http.Unirest; |
| | | import com.mashape.unirest.http.exceptions.UnirestException; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiResponse; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author |
| | | * @author |
| | | * @date 2022-03-17 |
| | | **/ |
| | | @Slf4j |
| | | @EncryptEnable |
| | | //@EncryptEnable |
| | | @RequiredArgsConstructor |
| | | @CrossOrigin("*") |
| | | @RestController |
| | |
| | | public class ApiCommonController { |
| | | |
| | | private final DappMemberService dappMemberService; |
| | | private final DappSystemService dappSystemService; |
| | | private final DappSimulateDataService dappSimulateDataService; |
| | | private final IMallNewsInfoService newsService; |
| | | private final SoccerLeaguesMapper soccerLeaguesMapper; |
| | | private final SoccerGameMapper soccerGameMapper; |
| | | |
| | | // @ApiOperation(value = "授权接口", notes = "授权接口") |
| | | // @PostMapping(value = "/approve") |
| | | // public FebsResponse approve(@RequestBody ApproveDto approveDto) { |
| | | // dappMemberService.approve(approveDto); |
| | | // return new FebsResponse().success().message("授权成功"); |
| | | // } |
| | | // |
| | | // @ApiOperation(value = "是否授权接口", notes = "是否授权接口") |
| | | // @GetMapping(value = "/isApprove/{chain}/{address}") |
| | | // public FebsResponse isApprove(@PathVariable("address") String address,@PathVariable("chain") String chain) { |
| | | // return new FebsResponse().success().message("获取成功").data(dappMemberService.isApprove(address, chain)); |
| | | // } |
| | | @ApiOperation(value = "地址是否存在", notes = "地址是否存在") |
| | | @GetMapping(value = "/exist/{address}") |
| | | public FebsResponse exist(@PathVariable("address") String address) { |
| | | DappMemberEntity member = dappMemberService.findByAddress(address, "BSC"); |
| | | |
| | | int result = member == null ? 2 : 1; |
| | | return new FebsResponse().success().data(result); |
| | | } |
| | | |
| | | @ApiOperation(value = "链接接口", notes = "链接接口") |
| | | @PostMapping(value = "/connect") |
| | |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "头部数据", notes = "头部数据") |
| | | @GetMapping(value = "/totalIncome") |
| | | public FebsResponse totalIncome() { |
| | | return new FebsResponse().success().data(dappSystemService.findTotalInComeAndList()); |
| | | @ApiOperation(value = "首页轮播图", notes = "首页轮播图") |
| | | @GetMapping(value = "/bannerList") |
| | | public FebsResponse findPlatformBannerList() { |
| | | return dappMemberService.findAllBanner(); |
| | | } |
| | | |
| | | @PostMapping(value = "/encrypt") |
| | | public FebsResponse encryptTest(@RequestBody EncryptDto encryptDto) { |
| | | System.out.println(encryptDto.getTest()); |
| | | return new FebsResponse().success().data("123"); |
| | | @ApiOperation(value = "商品列表", notes = "商品列表") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "success", response = MallGoodsListVo.class) |
| | | }) |
| | | @PostMapping(value = "/findMallGoodsList") |
| | | public FebsResponse findMallGoodsList(@RequestBody MallGoodsQueryDto queryDto) { |
| | | return new FebsResponse().success().data(dappMemberService.findMallGoodsListInPage(queryDto)); |
| | | } |
| | | |
| | | @ApiOperation(value = "商品详情", notes = "商品详情") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "success", response = MallGoodsListVo.class) |
| | | }) |
| | | @GetMapping(value = "/goodsDetails/{id}") |
| | | public FebsResponse goodsDetails(@PathVariable("id") Long id) { |
| | | return new FebsResponse().success().data(dappMemberService.findGoodsDetailsById(id)); |
| | | } |
| | | |
| | | @ApiOperation(value = "新闻分类", notes = "新闻分类") |
| | | @GetMapping(value = "/findNewsInfoCategory") |
| | | public FebsResponse findNewsInfoCategory() { |
| | | return new FebsResponse().success().data(newsService.findNewsCategoryList()); |
| | | } |
| | | |
| | | @ApiOperation(value ="获取新闻列表-分页", notes = "获取新闻列表") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "success", response = NewsListVo.class) |
| | | }) |
| | | @PostMapping(value = "/findNewsInPage") |
| | | public FebsResponse findNewsInPage(@RequestBody NewsListDto newsListDto) { |
| | | return new FebsResponse().success().data(newsService.findNewsInPage(newsListDto)); |
| | | } |
| | | |
| | | @ApiOperation(value = "新闻列表", notes = "新闻列表") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "success", response = NewsListVo.class) |
| | | }) |
| | | @GetMapping(value = "/findNews") |
| | | public FebsResponse findNews() { |
| | | return new FebsResponse().success().data(newsService.findTopNews()); |
| | | } |
| | | |
| | | @ApiOperation(value = "新闻详情", notes = "新闻详情") |
| | | @GetMapping(value = "/newsDetails/{id}") |
| | | public FebsResponse newsDetails(@PathVariable("id") Long id) { |
| | | MallNewsInfo news = newsService.getById(id); |
| | | if (news == null) { |
| | | return new FebsResponse().fail().message("新闻不存在"); |
| | | } |
| | | return new FebsResponse().success().data(news); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取国家", notes = "获取国家") |
| | | @GetMapping(value = "/countries") |
| | | public FebsResponse testApi() { |
| | | HttpResponse<String> response = null; |
| | | try { |
| | | response = Unirest.get("http://v3.football.api-sports.io/countries") |
| | | .header("x-rapidapi-key", "87f8d87d629d1704ba49622cb978eb81") |
| | | .header("x-rapidapi-host", "v3.football.api-sports.io").asString(); |
| | | } catch (UnirestException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | log.info(String.valueOf(response)); |
| | | log.info(response.getBody()); |
| | | log.info(String.valueOf(response.getRawBody())); |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取联赛", notes = "获取联赛") |
| | | @PostMapping(value = "/leaguesApi") |
| | | public FebsResponse leaguesApi(LeaguesApiDto leaguesApiDto) { |
| | | HttpResponse<String> response = null; |
| | | int season = ObjectUtil.isEmpty(leaguesApiDto.getSeason()) ? DateUtil.date().year() : leaguesApiDto.getSeason(); |
| | | String current = ObjectUtil.isEmpty(leaguesApiDto.getCurrent()) ? "true" : leaguesApiDto.getCurrent(); |
| | | try { |
| | | /** |
| | | * https://v3.football.api-sports.io/leagues?season=2023¤t=true |
| | | */ |
| | | response = Unirest.get(" https://v3.football.api-sports.io/leagues") |
| | | .header("x-rapidapi-key", "87f8d87d629d1704ba49622cb978eb81") |
| | | .header("x-rapidapi-host", "v3.football.api-sports.io") |
| | | .queryString("season",season) |
| | | .queryString("current",current) |
| | | .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"); |
| | | JSONArray jsonArray = JSONUtil.parseArray(responseStr); |
| | | if(CollUtil.isNotEmpty(jsonArray)){ |
| | | for(Object list : jsonArray){ |
| | | cn.hutool.json.JSONObject parseObj1 = JSONUtil.parseObj(list); |
| | | Object leagueObj = parseObj1.get("league"); |
| | | cn.hutool.json.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); |
| | | |
| | | SoccerLeagues soccerLeagues = new SoccerLeagues(); |
| | | soccerLeagues.setLeaguesId(id); |
| | | soccerLeagues.setLeaguesName(name); |
| | | soccerLeagues.setLeaguesType(type); |
| | | soccerLeagues.setLeaguesLogo(logo); |
| | | soccerLeaguesMapper.insert(soccerLeagues); |
| | | } |
| | | } |
| | | System.out.println(jsonArray); |
| | | log.info(String.valueOf(response.getRawBody())); |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @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(); |
| | | } |
| | | 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); |
| | | |
| | | } |
| | | |
| | | |
| | | // @ApiOperation(value = "头部数据", notes = "头部数据") |
| | | // @GetMapping(value = "/totalIncome") |
| | | // public FebsResponse totalIncome() { |
| | | // return new FebsResponse().success().data(dappSystemService.findTotalInComeAndList()); |
| | | // } |
| | | } |