use of com.moxi.mogublog.commons.entity.SubjectItem 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);
}
use of com.moxi.mogublog.commons.entity.SubjectItem 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()) + "条数据");
}
}
}
use of com.moxi.mogublog.commons.entity.SubjectItem in project mogu_blog_v2 by moxi624.
the class SubjectItemServiceImpl method sortByCreateTime.
@Override
public String sortByCreateTime(String subjectUid, Boolean isDesc) {
QueryWrapper<SubjectItem> queryWrapper = new QueryWrapper();
queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
queryWrapper.eq(SQLConf.SUBJECT_UID, subjectUid);
// 查询出所有的专题列表
List<SubjectItem> subjectItemList = subjectItemService.list(queryWrapper);
// 获取专题中的博客uid
List<String> blogUidList = new ArrayList<>();
subjectItemList.forEach(item -> {
blogUidList.add(item.getBlogUid());
});
if (blogUidList.size() == 0) {
return ResultUtil.errorWithMessage(MessageConf.UPDATE_FAIL);
}
Collection<Blog> blogList = blogService.listByIds(blogUidList);
List<Blog> tempBlogList = new ArrayList<>();
// 升序排列或降序排列
if (isDesc) {
tempBlogList = blogList.stream().sorted(Comparator.comparing(Blog::getCreateTime).reversed()).collect(Collectors.toList());
} else {
tempBlogList = blogList.stream().sorted(Comparator.comparing(Blog::getCreateTime)).collect(Collectors.toList());
}
// 设置初始化最大的sort值
int maxSort = tempBlogList.size();
Map<String, Integer> subjectItemSortMap = new HashMap<>();
for (Blog item : tempBlogList) {
subjectItemSortMap.put(item.getUid(), maxSort--);
}
// 设置更新后的排序值
for (SubjectItem item : subjectItemList) {
item.setSort(subjectItemSortMap.get(item.getBlogUid()));
}
subjectItemService.updateBatchById(subjectItemList);
return ResultUtil.successWithMessage(MessageConf.OPERATION_SUCCESS);
}
Aggregations