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);
}
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;
}
Aggregations