Search in sources :

Example 1 with PlayRecordingEntity

use of com.buguagaoshu.porntube.entity.PlayRecordingEntity in project PornTube by PuZhiweizuishuai.

the class PlayRecordingServiceImpl method queryPage.

@Override
public IPage<PlayRecordingEntity> queryPage(Map<String, Object> params, HttpServletRequest request) {
    Claims user = JwtUtil.getUser(request);
    Long userId = Long.parseLong(user.getId());
    QueryWrapper<PlayRecordingEntity> wrapper = new QueryWrapper<>();
    wrapper.eq("user_id", userId);
    wrapper.orderByDesc("update_time");
    IPage<PlayRecordingEntity> page = this.page(new Query<PlayRecordingEntity>().getPage(params), wrapper);
    return page;
}
Also used : PlayRecordingEntity(com.buguagaoshu.porntube.entity.PlayRecordingEntity) Claims(io.jsonwebtoken.Claims) Query(com.buguagaoshu.porntube.utils.Query) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)

Example 2 with PlayRecordingEntity

use of com.buguagaoshu.porntube.entity.PlayRecordingEntity in project PornTube by PuZhiweizuishuai.

the class PlayRecordingWithArticleServiceImpl method playRecordingList.

@Override
public PageUtils playRecordingList(Map<String, Object> params, HttpServletRequest request) {
    IPage<PlayRecordingEntity> page = playRecordingService.queryPage(params, request);
    Set<Long> aids = page.getRecords().stream().map(PlayRecordingEntity::getArticleId).collect(Collectors.toSet());
    List<ArticleEntity> articleEntities = articleService.listByIds(aids);
    List<PlayRecordingWithArticleVo> play = new LinkedList<>();
    if (articleEntities != null && articleEntities.size() != 0) {
        Map<Long, ArticleEntity> articleEntityMap = articleEntities.stream().collect(Collectors.toMap(ArticleEntity::getId, a -> a));
        for (PlayRecordingEntity playRecordingEntity : page.getRecords()) {
            PlayRecordingWithArticleVo playRecordingWithArticleVo = new PlayRecordingWithArticleVo();
            playRecordingWithArticleVo.setPlayRecordingEntity(playRecordingEntity);
            ArticleEntity articleEntity = articleEntityMap.get(playRecordingEntity.getArticleId());
            playRecordingWithArticleVo.setArticleEntity(articleEntity);
            play.add(playRecordingWithArticleVo);
        }
    }
    IPage<PlayRecordingWithArticleVo> iPage = new IPage<PlayRecordingWithArticleVo>() {

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

        @Override
        public List<PlayRecordingWithArticleVo> getRecords() {
            return play;
        }

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

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

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

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

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

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

        @Override
        public IPage<PlayRecordingWithArticleVo> setCurrent(long current) {
            return null;
        }
    };
    return new PageUtils(iPage);
}
Also used : PageUtils(com.buguagaoshu.porntube.utils.PageUtils) ArticleService(com.buguagaoshu.porntube.service.ArticleService) ArticleEntity(com.buguagaoshu.porntube.entity.ArticleEntity) PlayRecordingWithArticleVo(com.buguagaoshu.porntube.vo.PlayRecordingWithArticleVo) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) PlayRecordingService(com.buguagaoshu.porntube.service.PlayRecordingService) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Collectors(java.util.stream.Collectors) PlayRecordingEntity(com.buguagaoshu.porntube.entity.PlayRecordingEntity) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) Service(org.springframework.stereotype.Service) Map(java.util.Map) PlayRecordingWithArticleService(com.buguagaoshu.porntube.service.PlayRecordingWithArticleService) LinkedList(java.util.LinkedList) IPage(com.baomidou.mybatisplus.core.metadata.IPage) PlayRecordingWithArticleVo(com.buguagaoshu.porntube.vo.PlayRecordingWithArticleVo) LinkedList(java.util.LinkedList) PlayRecordingEntity(com.buguagaoshu.porntube.entity.PlayRecordingEntity) IPage(com.baomidou.mybatisplus.core.metadata.IPage) PageUtils(com.buguagaoshu.porntube.utils.PageUtils) ArticleEntity(com.buguagaoshu.porntube.entity.ArticleEntity) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) List(java.util.List) LinkedList(java.util.LinkedList)

Example 3 with PlayRecordingEntity

use of com.buguagaoshu.porntube.entity.PlayRecordingEntity in project PornTube by PuZhiweizuishuai.

the class PlayRecordingServiceImpl method saveHistory.

@Override
public long saveHistory(FileTableEntity file, Long userId, String ua) {
    long time = System.currentTimeMillis();
    // TODO 此处有并发bug,请求时间相近的情况下会写入两条相同的播放记录
    // 尤其是使用qq浏览器的时候
    PlayRecordingEntity playRecordingEntity = findPlayRecordingEntityByArticleIdAndVideoId(file.getArticleId(), file.getId(), userId);
    if (playRecordingEntity != null) {
        playRecordingEntity.setUpdateTime(time);
        playRecordingEntity.setUa(ua);
        this.updateById(playRecordingEntity);
        return 0;
    } else {
        playRecordingEntity = new PlayRecordingEntity();
        playRecordingEntity.setArticleId(file.getArticleId());
        playRecordingEntity.setCreateTime(time);
        playRecordingEntity.setUpdateTime(time);
        playRecordingEntity.setUserId(userId);
        playRecordingEntity.setVideoId(file.getId());
        playRecordingEntity.setUa(ua);
        // TODO 采用缓存
        // articleService.addViewCount(file.getArticleId(), 1L);
        // TODO 播放时间戳,视频个数
        this.save(playRecordingEntity);
        return file.getArticleId();
    }
}
Also used : PlayRecordingEntity(com.buguagaoshu.porntube.entity.PlayRecordingEntity)

Aggregations

PlayRecordingEntity (com.buguagaoshu.porntube.entity.PlayRecordingEntity)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 OrderItem (com.baomidou.mybatisplus.core.metadata.OrderItem)1 ArticleEntity (com.buguagaoshu.porntube.entity.ArticleEntity)1 ArticleService (com.buguagaoshu.porntube.service.ArticleService)1 PlayRecordingService (com.buguagaoshu.porntube.service.PlayRecordingService)1 PlayRecordingWithArticleService (com.buguagaoshu.porntube.service.PlayRecordingWithArticleService)1 PageUtils (com.buguagaoshu.porntube.utils.PageUtils)1 Query (com.buguagaoshu.porntube.utils.Query)1 PlayRecordingWithArticleVo (com.buguagaoshu.porntube.vo.PlayRecordingWithArticleVo)1 Claims (io.jsonwebtoken.Claims)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1