Search in sources :

Example 1 with ResourceSort

use of com.moxi.mogublog.commons.entity.ResourceSort in project mogu_blog_v2 by moxi624.

the class ResourceSortServiceImpl method editResourceSort.

@Override
public String editResourceSort(ResourceSortVO resourceSortVO) {
    ResourceSort resourceSort = resourceSortService.getById(resourceSortVO.getUid());
    /**
     * 判断需要编辑的分类是否存在
     */
    if (!resourceSort.getSortName().equals(resourceSortVO.getSortName())) {
        QueryWrapper<ResourceSort> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(BaseSQLConf.SORT_NAME, resourceSortVO.getSortName());
        queryWrapper.eq(BaseSQLConf.STATUS, EStatus.ENABLE);
        ResourceSort tempSort = resourceSortService.getOne(queryWrapper);
        if (tempSort != null) {
            return ResultUtil.errorWithMessage(MessageConf.ENTITY_EXIST);
        }
    }
    resourceSort.setSortName(resourceSortVO.getSortName());
    resourceSort.setContent(resourceSortVO.getContent());
    resourceSort.setFileUid(resourceSortVO.getFileUid());
    resourceSort.setSort(resourceSortVO.getSort());
    resourceSort.setUpdateTime(new Date());
    resourceSort.updateById();
    return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ResourceSort(com.moxi.mogublog.commons.entity.ResourceSort)

Example 2 with ResourceSort

use of com.moxi.mogublog.commons.entity.ResourceSort in project mogu_blog_v2 by moxi624.

the class ResourceRestApi method getBlogByUid.

@ApiOperation(value = "通过分类来获取视频", notes = "通过Uid获取博客内容")
@GetMapping("/getStudyVideoBySort")
public String getBlogByUid(HttpServletRequest request, @ApiParam(name = "resourceSortUid", value = "资源分类UID", required = false) @RequestParam(name = "resourceSortUid", required = false) String resourceSortUid, @ApiParam(name = "currentPage", value = "当前页数", required = false) @RequestParam(name = "currentPage", required = false, defaultValue = "1") Long currentPage, @ApiParam(name = "pageSize", value = "每页显示数目", required = false) @RequestParam(name = "pageSize", required = false, defaultValue = "8") Long pageSize) {
    QueryWrapper<StudyVideo> queryWrapper = new QueryWrapper<>();
    Page<StudyVideo> page = new Page<>();
    page.setCurrent(currentPage);
    page.setSize(pageSize);
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    // 按点击数降序排列
    queryWrapper.orderByDesc(SQLConf.CLICK_COUNT);
    if (!StringUtils.isEmpty(resourceSortUid)) {
        queryWrapper.eq(SQLConf.RESOURCE_SORT_UID, resourceSortUid);
    }
    IPage<StudyVideo> pageList = studyVideoService.page(page, queryWrapper);
    List<StudyVideo> list = pageList.getRecords();
    // 获取所有的分类
    Set<String> resourceSortUids = new HashSet<>();
    String fileIds = "";
    for (StudyVideo item : list) {
        if (StringUtils.isNotEmpty(item.getResourceSortUid())) {
            resourceSortUids.add(item.getResourceSortUid());
        }
        if (StringUtils.isNotEmpty(item.getFileUid())) {
            fileIds = fileIds + item.getFileUid() + ",";
        }
    }
    // PictureList
    String result = this.pictureFeignClient.getPicture(fileIds, ",");
    List<Map<String, Object>> picList = webUtil.getPictureMap(result);
    // ResourceSort
    Collection<ResourceSort> resourceSortList = resourceSortService.listByIds(resourceSortUids);
    for (StudyVideo item : list) {
        List<String> photoList = new ArrayList<>();
        for (ResourceSort item2 : resourceSortList) {
            if (item.getResourceSortUid().equals(item2.getUid())) {
                item.setResourceSort(item2);
                break;
            }
        }
        for (Map<String, Object> map : picList) {
            // 因为资源可能有多个图片
            String fileUid = item.getFileUid();
            List<String> fileUids = StringUtils.changeStringToString(fileUid, ",");
            for (String uid : fileUids) {
                if (map.get("uid").toString().equals(uid)) {
                    photoList.add(map.get("url").toString());
                }
            }
        }
        item.setPhotoList(photoList);
    }
    log.info("返回结果");
    return ResultUtil.result(SysConf.SUCCESS, pageList);
}
Also used : StudyVideo(com.moxi.mogublog.commons.entity.StudyVideo) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) ResourceSort(com.moxi.mogublog.commons.entity.ResourceSort) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with ResourceSort

use of com.moxi.mogublog.commons.entity.ResourceSort in project mogu_blog_v2 by moxi624.

the class ResourceSortServiceImpl method addResourceSort.

@Override
public String addResourceSort(ResourceSortVO resourceSortVO) {
    /**
     * 判断需要增加的分类是否存在
     */
    QueryWrapper<ResourceSort> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq(BaseSQLConf.SORT_NAME, resourceSortVO.getSortName());
    queryWrapper.eq(BaseSQLConf.STATUS, EStatus.ENABLE);
    ResourceSort tempSort = resourceSortService.getOne(queryWrapper);
    if (tempSort != null) {
        return ResultUtil.errorWithMessage(MessageConf.ENTITY_EXIST);
    }
    ResourceSort resourceSort = new ResourceSort();
    resourceSort.setSortName(resourceSortVO.getSortName());
    resourceSort.setContent(resourceSortVO.getContent());
    resourceSort.setFileUid(resourceSortVO.getFileUid());
    resourceSort.setSort(resourceSortVO.getSort());
    resourceSort.setStatus(EStatus.ENABLE);
    resourceSort.insert();
    return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ResourceSort(com.moxi.mogublog.commons.entity.ResourceSort)

Example 4 with ResourceSort

use of com.moxi.mogublog.commons.entity.ResourceSort in project mogu_blog_v2 by moxi624.

the class ResourceSortServiceImpl method stickResourceSort.

@Override
public String stickResourceSort(ResourceSortVO resourceSortVO) {
    ResourceSort resourceSort = resourceSortService.getById(resourceSortVO.getUid());
    // 查找出最大的那一个
    QueryWrapper<ResourceSort> queryWrapper = new QueryWrapper<>();
    queryWrapper.orderByDesc(BaseSQLConf.SORT);
    Page<ResourceSort> page = new Page<>();
    page.setCurrent(0);
    page.setSize(1);
    IPage<ResourceSort> pageList = resourceSortService.page(page, queryWrapper);
    List<ResourceSort> list = pageList.getRecords();
    ResourceSort maxSort = list.get(0);
    if (StringUtils.isEmpty(maxSort.getUid())) {
        return ResultUtil.errorWithMessage(MessageConf.PARAM_INCORRECT);
    }
    if (maxSort.getUid().equals(resourceSort.getUid())) {
        return ResultUtil.errorWithMessage(MessageConf.THIS_SORT_IS_TOP);
    }
    Integer sortCount = maxSort.getSort() + 1;
    resourceSort.setSort(sortCount);
    resourceSort.setUpdateTime(new Date());
    resourceSort.updateById();
    return ResultUtil.successWithMessage(MessageConf.OPERATION_SUCCESS);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) ResourceSort(com.moxi.mogublog.commons.entity.ResourceSort)

Example 5 with ResourceSort

use of com.moxi.mogublog.commons.entity.ResourceSort in project mogu_blog_v2 by moxi624.

the class ResourceSortServiceImpl method getPageList.

@Override
public IPage<ResourceSort> getPageList(ResourceSortVO resourceSortVO) {
    QueryWrapper<ResourceSort> queryWrapper = new QueryWrapper<>();
    if (StringUtils.isNotEmpty(resourceSortVO.getKeyword()) && !StringUtils.isEmpty(resourceSortVO.getKeyword().trim())) {
        queryWrapper.like(BaseSQLConf.SORT_NAME, resourceSortVO.getKeyword().trim());
    }
    Page<ResourceSort> page = new Page<>();
    page.setCurrent(resourceSortVO.getCurrentPage());
    page.setSize(resourceSortVO.getPageSize());
    queryWrapper.eq(BaseSQLConf.STATUS, EStatus.ENABLE);
    queryWrapper.orderByDesc(BaseSQLConf.SORT);
    IPage<ResourceSort> pageList = resourceSortService.page(page, queryWrapper);
    List<ResourceSort> list = pageList.getRecords();
    final StringBuffer fileUids = new StringBuffer();
    list.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getFileUid())) {
            fileUids.append(item.getFileUid() + BaseSysConf.FILE_SEGMENTATION);
        }
    });
    String pictureResult = null;
    Map<String, String> pictureMap = new HashMap<>();
    if (fileUids != null) {
        pictureResult = this.pictureFeignClient.getPicture(fileUids.toString(), BaseSysConf.FILE_SEGMENTATION);
    }
    List<Map<String, Object>> picList = webUtil.getPictureMap(pictureResult);
    picList.forEach(item -> {
        pictureMap.put(item.get(SysConf.UID).toString(), item.get(SysConf.URL).toString());
    });
    for (ResourceSort item : list) {
        // 获取图片
        if (StringUtils.isNotEmpty(item.getFileUid())) {
            List<String> pictureUidsTemp = StringUtils.changeStringToString(item.getFileUid(), BaseSysConf.FILE_SEGMENTATION);
            List<String> pictureListTemp = new ArrayList<>();
            pictureUidsTemp.forEach(picture -> {
                pictureListTemp.add(pictureMap.get(picture));
            });
            item.setPhotoList(pictureListTemp);
        }
    }
    pageList.setRecords(list);
    return pageList;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) ResourceSort(com.moxi.mogublog.commons.entity.ResourceSort)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)6 ResourceSort (com.moxi.mogublog.commons.entity.ResourceSort)6 IPage (com.baomidou.mybatisplus.core.metadata.IPage)4 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)4 StudyVideo (com.moxi.mogublog.commons.entity.StudyVideo)2 ApiOperation (io.swagger.annotations.ApiOperation)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1