新版仿ok交易所-后端
1
zj
8 days ago 579177ac64462d0fec885eb10af3097245134f80
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiNewsController.java
@@ -1,14 +1,20 @@
package com.yami.trading.api.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.trading.bean.cms.News;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.constants.RedisKeys;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.DateUtils;
import com.yami.trading.common.util.RedisUtil;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.huobi.hobi.http.HttpHelper;
import com.yami.trading.huobi.hobi.http.HttpMethodType;
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.service.AwsS3OSSFileService;
import com.yami.trading.service.cms.NewsSerivce;
@@ -75,10 +81,10 @@
            page_no = "1";
        }
        if (!StringUtils.isInteger(page_no)) {
            throw new YamiShopBindException("页码不是整数");
            throw new YamiShopBindException("Page number must be an integer");
        }
        if (Integer.valueOf(page_no).intValue() <= 0) {
            throw new YamiShopBindException("页码不能小于等于0");
            throw new YamiShopBindException("Page number must be greater than 0");
        }
        int page_no_int = Integer.valueOf(page_no).intValue();
        Page<News> page = new Page<>(1, 1000000);
@@ -130,10 +136,10 @@
            page_no = "1";
        }
        if (!StringUtils.isInteger(page_no)) {
            throw new YamiShopBindException("页码不是整数");
            throw new YamiShopBindException("Page number must be an integer");
        }
        if (Integer.valueOf(page_no).intValue() <= 0) {
            throw new YamiShopBindException("页码不能小于等于0");
            throw new YamiShopBindException("Page number must be greater than 0");
        }
        int page_no_int = Integer.valueOf(page_no).intValue();
        List<News> list = new ArrayList<News>();
@@ -177,10 +183,10 @@
            page_no = "1";
        }
        if (!StringUtils.isInteger(page_no)) {
            throw new YamiShopBindException("页码不是整数");
            throw new YamiShopBindException("Page number must be an integer");
        }
        if (Integer.valueOf(page_no).intValue() <= 0) {
            throw new YamiShopBindException("页码不能小于等于0");
            throw new YamiShopBindException("Page number must be greater than 0");
        }
        int page_no_int = Integer.valueOf(page_no).intValue();
        List<News> list = new ArrayList<News>();
@@ -223,4 +229,22 @@
        return Result.succeed(list);
    }
    /**
     * 获取 新闻 列表
     */
    @RequestMapping(action + "getUsHeadNews.action")
    public Object getUsHeadNews(HttpServletRequest request) {
        JSONObject jsonObject = RedisUtil.get(RedisKeys.NEWS_TOP_HEADLINES);
        if (jsonObject == null || jsonObject.isEmpty()) {
            String result = HttpHelper.getJSONFromHttp("https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey=f39cfa8922534af295491f38f664ea3d", null, HttpMethodType.GET);
            JSONObject resultJson = JSON.parseObject(result);
            String status = resultJson.getString("status");
            if ("ok".equals(status)) {
                RedisUtil.set(RedisKeys.NEWS_TOP_HEADLINES, resultJson);
                jsonObject = resultJson;
            }
        }
        return jsonObject;
    }
}