Search in sources :

Example 1 with ArticleViewData

use of com.buguagaoshu.porntube.vo.ArticleViewData in project PornTube by PuZhiweizuishuai.

the class ArticleServiceImpl method queryPage.

@Override
public PageUtils queryPage(Map<String, Object> params) {
    QueryWrapper<ArticleEntity> wrapper = new QueryWrapper<>();
    wrapper.eq("status", ArticleStatusEnum.NORMAL.getCode());
    wrapper.eq("examine_status", ExamineTypeEnum.SUCCESS.getCode());
    wrapper.orderByDesc("create_time");
    IPage<ArticleEntity> page = this.page(new Query<ArticleEntity>().getPage(params), wrapper);
    Set<Long> userIdList = page.getRecords().stream().map(ArticleEntity::getUserId).collect(Collectors.toSet());
    if (userIdList.size() == 0) {
        return null;
    }
    Map<Long, UserEntity> userEntityMap = userService.userMapList(userIdList);
    List<ArticleViewData> articleViewData = new ArrayList<>();
    page.getRecords().forEach(a -> {
        ArticleViewData viewData = new ArticleViewData();
        UserEntity userEntity = userEntityMap.get(a.getUserId());
        BeanUtils.copyProperties(a, viewData);
        viewData.setUsername(userEntity.getUsername());
        viewData.setAvatarUrl(userEntity.getAvatarUrl());
        articleViewData.add(viewData);
    });
    IPage<ArticleViewData> viewDataIPage = new IPage<ArticleViewData>() {

        @Override
        public List<OrderItem> orders() {
            return null;
        }

        @Override
        public List<ArticleViewData> getRecords() {
            return articleViewData;
        }

        @Override
        public IPage<ArticleViewData> setRecords(List<ArticleViewData> records) {
            return null;
        }

        @Override
        public long getTotal() {
            return page.getTotal();
        }

        @Override
        public IPage<ArticleViewData> setTotal(long total) {
            return null;
        }

        @Override
        public long getSize() {
            return page.getSize();
        }

        @Override
        public IPage<ArticleViewData> setSize(long size) {
            return null;
        }

        @Override
        public long getCurrent() {
            return page.getCurrent();
        }

        @Override
        public IPage<ArticleViewData> setCurrent(long current) {
            return null;
        }
    };
    return new PageUtils(viewDataIPage);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ArrayList(java.util.ArrayList) IPage(com.baomidou.mybatisplus.core.metadata.IPage) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) ArticleViewData(com.buguagaoshu.porntube.vo.ArticleViewData) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ArticleViewData

use of com.buguagaoshu.porntube.vo.ArticleViewData in project PornTube by PuZhiweizuishuai.

the class ArticleServiceImpl method getVideo.

@Override
public ArticleViewData getVideo(long id, HttpServletRequest request) {
    Claims user = JwtUtil.getUser(request);
    QueryWrapper<ArticleEntity> wrapper = new QueryWrapper<>();
    wrapper.eq("id", id);
    wrapper.eq("status", ArticleStatusEnum.NORMAL.getCode());
    // 非管理员添加审核条件
    boolean flag = true;
    if (user != null && RoleTypeEnum.ADMIN.getRole().equals(user.get(WebConstant.ROLE_KEY))) {
        flag = false;
    }
    long userId = -1;
    if (user != null) {
        userId = Long.parseLong(user.getId());
    }
    if (flag) {
        wrapper.eq("examine_status", ExamineTypeEnum.SUCCESS.getCode());
    }
    ArticleEntity articleEntity = this.getOne(wrapper);
    if (articleEntity == null) {
        ArticleViewData articleViewData = new ArticleViewData();
        articleViewData.setIsShow(false);
        return articleViewData;
    }
    ArticleViewData articleViewData = new ArticleViewData();
    BeanUtils.copyProperties(articleEntity, articleViewData);
    UserEntity author = userService.getById(articleEntity.getUserId());
    articleViewData.setUsername(author.getUsername());
    articleViewData.setFollowCount(author.getFollowCount());
    articleViewData.setAvatarUrl(author.getAvatarUrl());
    articleViewData.setIntroduction(author.getIntroduction());
    articleViewData.setDanmakuCount(articleEntity.getDanmakuCount());
    List<FileTableEntity> video = fileTableService.findArticleVideo(id);
    long time = System.currentTimeMillis();
    for (FileTableEntity f : video) {
        f.setKey(AesUtil.encrypt(userId + "#" + f.getId() + "#" + (time + WebConstant.KEY_EXPIRY_DATE) + "#" + f.getFileNewName(), WebConstant.AES_KEY));
    }
    articleViewData.setVideo(video);
    ObjectMapper mapper = new ObjectMapper();
    try {
        articleViewData.setTag((List<String>) mapper.readValue(articleEntity.getTag(), List.class));
    } catch (JsonProcessingException e) {
        log.warn("视频id为 {} 的投稿反序列化标签时出现异常,请及时检查!", articleEntity.getId());
    }
    CategoryEntity categoryEntity = categoryCache.getCategoryEntityMap().get(articleEntity.getCategory());
    articleViewData.setChildrenCategory(categoryEntity);
    if (categoryEntity.getFatherId() != 0) {
        CategoryEntity f = categoryCache.getCategoryEntityMap().get(categoryEntity.getFatherId());
        articleViewData.setFatherCategory(f);
    }
    articleViewData.setIsShow(true);
    return articleViewData;
}
Also used : Claims(io.jsonwebtoken.Claims) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ArticleViewData(com.buguagaoshu.porntube.vo.ArticleViewData) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 ArticleViewData (com.buguagaoshu.porntube.vo.ArticleViewData)2 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 OrderItem (com.baomidou.mybatisplus.core.metadata.OrderItem)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Claims (io.jsonwebtoken.Claims)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1