Commit 9bf520c8 by leejoker

🐛修复当items列表为空时,sql执行错误

1 parent fe302ca3
...@@ -21,8 +21,8 @@ import java.util.Optional; ...@@ -21,8 +21,8 @@ import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
*
* 聊天工具侧边栏 * 聊天工具侧边栏
*
* @author kewen * @author kewen
*/ */
@Service @Service
...@@ -39,65 +39,39 @@ public class WeChatItemServiceImpl extends ServiceImpl<WeChatItemMapper, WeChatI ...@@ -39,65 +39,39 @@ public class WeChatItemServiceImpl extends ServiceImpl<WeChatItemMapper, WeChatI
@Override @Override
public int checkItems(WeChatItemDto chatItemDto) { public int checkItems(WeChatItemDto chatItemDto) {
List<Long> materialIds = new ArrayList<>();
if ("0".equals(chatItemDto.getCheckAll())) {
List<Long> materialIds=new ArrayList<>();
if("0".equals(chatItemDto.getCheckAll())){
List<WeMaterial> weMaterials = weMaterialService.findWeMaterials(null, null, chatItemDto.getMediaType()); List<WeMaterial> weMaterials = weMaterialService.findWeMaterials(null, null, chatItemDto.getMediaType());
if (CollectionUtils.isNotEmpty(weMaterials)) {
if(CollectionUtils.isNotEmpty(weMaterials)){ materialIds = weMaterials.stream().map(WeMaterial::getId).collect(Collectors.toList());
materialIds= weMaterials.stream().map(WeMaterial::getId).collect(Collectors.toList());
} }
} else {
}else { materialIds = chatItemDto.getMaterialIds();
materialIds= chatItemDto.getMaterialIds();
} }
List<Long> finalMaterialIds = materialIds; List<Long> finalMaterialIds = materialIds;
Optional.ofNullable(materialIds).ifPresent( Optional.ofNullable(materialIds).ifPresent(
s -> {
s->{ List<WeChatItem> items = new ArrayList<>();
finalMaterialIds.forEach(materialId -> {
List<WeChatItem> items=new ArrayList<>(); WeChatItem item = new WeChatItem();
finalMaterialIds.forEach(materialId->{
WeChatItem item=new WeChatItem();
item.setItemId(SnowFlakeUtil.nextId()); item.setItemId(SnowFlakeUtil.nextId());
item.setMaterialId(materialId); item.setMaterialId(materialId);
item.setSideId(chatItemDto.getSideId()); item.setSideId(chatItemDto.getSideId());
items.add(item); items.add(item);
}); });
weChatItemMapper.dropItem(chatItemDto.getSideId()); weChatItemMapper.dropItem(chatItemDto.getSideId());
if (CollectionUtils.isNotEmpty(items)) {
weChatItemMapper.addItem(items); weChatItemMapper.addItem(items);
}
checkItemsTotal(chatItemDto, finalMaterialIds); checkItemsTotal(chatItemDto, finalMaterialIds);
} }
); );
return 1; return 1;
} }
@Override @Override
public List<WeChatSideVo> chatItems(Long sideId,String keyword,String mediaType,String userId) { public List<WeChatSideVo> chatItems(Long sideId, String keyword, String mediaType, String userId) {
return weChatItemMapper.findChatItems(sideId,keyword,mediaType,userId); return weChatItemMapper.findChatItems(sideId, keyword, mediaType, userId);
} }
/** /**
...@@ -107,16 +81,9 @@ public class WeChatItemServiceImpl extends ServiceImpl<WeChatItemMapper, WeChatI ...@@ -107,16 +81,9 @@ public class WeChatItemServiceImpl extends ServiceImpl<WeChatItemMapper, WeChatI
* @param finalMaterialIds 素材id列表 * @param finalMaterialIds 素材id列表
*/ */
private void checkItemsTotal(WeChatItemDto chatItemDto, List<Long> finalMaterialIds) { private void checkItemsTotal(WeChatItemDto chatItemDto, List<Long> finalMaterialIds) {
WeChatSide side = new WeChatSide();
WeChatSide side=new WeChatSide();
side.setSideId(chatItemDto.getSideId()); side.setSideId(chatItemDto.getSideId());
side.setTotal(finalMaterialIds.size()); side.setTotal(finalMaterialIds.size());
weChatSideMapper.updateWeChatSideById(side); weChatSideMapper.updateWeChatSideById(side);
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!