| | |
| | | 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; |
| | |
| | | news.setShow(news.getUserId().equals(SecurityUtils.getCurrentUserId())); |
| | | } |
| | | if (StringUtils.isNotEmpty(news.getImgUrl())) { |
| | | news.setImgUrl(news.getImgUrl()); |
| | | news.setImgUrl(Constants.IMAGES_HTTP+news.getImgUrl()); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | String page_no = request.getParameter("page_no"); |
| | | String language = request.getParameter("language"); |
| | | String token = request.getParameter("token"); |
| | | String partyId = request.getParameter("partyId"); |
| | | if (StringUtils.isNullOrEmpty(page_no)) { |
| | | page_no = "1"; |
| | | } |
| | |
| | | } |
| | | int page_no_int = Integer.valueOf(page_no).intValue(); |
| | | List<News> list = new ArrayList<News>(); |
| | | if (StringUtils.isEmptyString(token)) { |
| | | LambdaQueryWrapper<News> lambdaQueryWrapper = Wrappers.<News>query().lambda().eq(News::getLanguage, language).eq(News::isPopUp, |
| | | true); |
| | | if(StringUtils.isNotEmpty(partyId)){ |
| | | LambdaQueryWrapper<News> lambdaQueryWrapper = Wrappers.<News>query().lambda() |
| | | .eq(News::getLanguage, language) |
| | | .eq(News::isPopUp, true) |
| | | // 核心修改:外层and包裹,内部直接用or连接三个条件 |
| | | .and(wrapper -> wrapper |
| | | .eq(News::getUserId, partyId) // 条件1:userId=partyId |
| | | .or().isNull(News::getUserId) // 条件2:userId=null |
| | | .or().eq(News::getUserId, "") // 条件3:userId=空字符串 |
| | | ); |
| | | Page<News> page = new Page<>(1, 1000000); |
| | | newsService.page(page, lambdaQueryWrapper); |
| | | list = page.getRecords(); |
| | | } else { |
| | | String partyId = SecurityUtils.getUser().getUserId(); |
| | | LambdaQueryWrapper<News> lambdaQueryWrapper = Wrappers.<News>query().lambda().eq(News::getLanguage, language).eq(News::isPopUp, |
| | | true).eq(News::getUserId, partyId); |
| | | LambdaQueryWrapper<News> lambdaQueryWrapper = Wrappers.<News>query().lambda() |
| | | .eq(News::getLanguage, language) |
| | | .eq(News::isPopUp, true) |
| | | .and(wrapper -> wrapper |
| | | .isNull(News::getUserId) // 条件1:userId为null |
| | | .or() // 或者 |
| | | .eq(News::getUserId, "") // 条件2:userId为空字符串 |
| | | ); |
| | | Page<News> page = new Page<>(1, 1000000); |
| | | newsService.page(page, lambdaQueryWrapper); |
| | | list = page.getRecords(); |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |