| | |
| | | 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.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.*; |
| | | 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.LeaguesApiDto; |
| | | import cc.mrbird.febs.dapp.soccer.entity.SoccerLeagues; |
| | | 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.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 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.*; |
| | | |
| | | /** |
| | | * @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; |
| | | |
| | | // @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 = "/testApi") |
| | | 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(); |
| | | } |
| | | |
| | | 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); |
| | | |
| | | |
| | | } |
| | | } |
| | | System.out.println(jsonArray); |
| | | } |
| | | |
| | | |
| | | // @ApiOperation(value = "头部数据", notes = "头部数据") |
| | | // @GetMapping(value = "/totalIncome") |
| | | // public FebsResponse totalIncome() { |
| | | // return new FebsResponse().success().data(dappSystemService.findTotalInComeAndList()); |
| | | // } |
| | | } |