Search in sources :

Example 1 with SubjectItemVO

use of com.moxi.mogublog.xo.vo.SubjectItemVO in project mogu_blog_v2 by moxi624.

the class SubjectItemServiceImpl method editSubjectItemList.

@Override
public String editSubjectItemList(List<SubjectItemVO> subjectItemVOList) {
    List<String> subjectItemUidList = new ArrayList<>();
    subjectItemVOList.forEach(item -> {
        subjectItemUidList.add(item.getUid());
    });
    Collection<SubjectItem> subjectItemCollection = null;
    if (subjectItemUidList.size() > 0) {
        subjectItemCollection = subjectItemService.listByIds(subjectItemUidList);
        if (subjectItemCollection.size() > 0) {
            HashMap<String, SubjectItemVO> subjectItemVOHashMap = new HashMap<>();
            subjectItemVOList.forEach(item -> {
                subjectItemVOHashMap.put(item.getUid(), item);
            });
            // 修改排序字段
            List<SubjectItem> subjectItemList = new ArrayList<>();
            subjectItemCollection.forEach(item -> {
                SubjectItemVO subjectItemVO = subjectItemVOHashMap.get(item.getUid());
                item.setSubjectUid(subjectItemVO.getSubjectUid());
                item.setBlogUid(subjectItemVO.getBlogUid());
                item.setStatus(EStatus.ENABLE);
                item.setSort(subjectItemVO.getSort());
                item.setUpdateTime(new Date());
                subjectItemList.add(item);
            });
            subjectItemService.updateBatchById(subjectItemList);
        }
    }
    return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
Also used : SubjectItemVO(com.moxi.mogublog.xo.vo.SubjectItemVO) SubjectItem(com.moxi.mogublog.commons.entity.SubjectItem)

Example 2 with SubjectItemVO

use of com.moxi.mogublog.xo.vo.SubjectItemVO in project mogu_blog_v2 by moxi624.

the class SubjectItemServiceImpl method addSubjectItemList.

@Override
public String addSubjectItemList(List<SubjectItemVO> subjectItemVOList) {
    List<String> blogUidList = new ArrayList<>();
    String subjectUid = "";
    for (SubjectItemVO subjectItemVO : subjectItemVOList) {
        blogUidList.add(subjectItemVO.getBlogUid());
        if (StringUtils.isEmpty(subjectUid) && StringUtils.isNotEmpty(subjectItemVO.getSubjectUid())) {
            subjectUid = subjectItemVO.getSubjectUid();
        }
    }
    // 查询SubjectItem中是否包含重复的博客
    QueryWrapper<SubjectItem> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq(SQLConf.SUBJECT_UID, subjectUid);
    queryWrapper.in(SQLConf.BLOG_UID, blogUidList);
    List<SubjectItem> repeatSubjectItemList = subjectItemService.list(queryWrapper);
    // 找出重复的博客UID
    List<String> repeatBlogList = new ArrayList<>();
    repeatSubjectItemList.forEach(item -> {
        repeatBlogList.add(item.getBlogUid());
    });
    List<SubjectItem> subjectItemList = new ArrayList<>();
    for (SubjectItemVO subjectItemVO : subjectItemVOList) {
        if (StringUtils.isEmpty(subjectItemVO.getSubjectUid()) || StringUtils.isEmpty(subjectItemVO.getBlogUid())) {
            return ResultUtil.errorWithMessage(MessageConf.PARAM_INCORRECT);
        }
        // 判断是否重复添加
        if (repeatBlogList.contains(subjectItemVO.getBlogUid())) {
            continue;
        } else {
            SubjectItem subjectItem = new SubjectItem();
            subjectItem.setSubjectUid(subjectItemVO.getSubjectUid());
            subjectItem.setBlogUid(subjectItemVO.getBlogUid());
            subjectItem.setStatus(EStatus.ENABLE);
            subjectItemList.add(subjectItem);
        }
    }
    if (subjectItemList.size() <= 0) {
        if (repeatBlogList.size() == 0) {
            return ResultUtil.errorWithMessage(MessageConf.INSERT_FAIL);
        } else {
            return ResultUtil.errorWithMessage(MessageConf.INSERT_FAIL + ",已跳过" + repeatBlogList.size() + "个重复数据");
        }
    } else {
        subjectItemService.saveBatch(subjectItemList);
        if (repeatBlogList.size() == 0) {
            return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);
        } else {
            return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS + ",已跳过" + repeatBlogList.size() + "个重复数据,成功插入" + (subjectItemVOList.size() - repeatBlogList.size()) + "条数据");
        }
    }
}
Also used : SubjectItemVO(com.moxi.mogublog.xo.vo.SubjectItemVO) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) SubjectItem(com.moxi.mogublog.commons.entity.SubjectItem)

Aggregations

SubjectItem (com.moxi.mogublog.commons.entity.SubjectItem)2 SubjectItemVO (com.moxi.mogublog.xo.vo.SubjectItemVO)2 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1