WeChatItemServiceImpl.java
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.wecom.domain.WeChatItem;
import com.linkwechat.wecom.domain.WeChatSide;
import com.linkwechat.wecom.domain.WeMaterial;
import com.linkwechat.wecom.domain.dto.WeChatItemDto;
import com.linkwechat.wecom.domain.vo.WeChatSideVo;
import com.linkwechat.wecom.mapper.WeChatItemMapper;
import com.linkwechat.wecom.mapper.WeChatSideMapper;
import com.linkwechat.wecom.service.IWeChatItemService;
import com.linkwechat.wecom.service.IWeMaterialService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
*
* 聊天工具侧边栏
* @author kewen
*/
@Service
public class WeChatItemServiceImpl extends ServiceImpl<WeChatItemMapper, WeChatItem> implements IWeChatItemService {
@Autowired
private WeChatItemMapper weChatItemMapper;
@Autowired
private IWeMaterialService weMaterialService;
@Autowired
private WeChatSideMapper weChatSideMapper;
@Override
public int checkItems(WeChatItemDto chatItemDto) {
List<Long> materialIds=new ArrayList<>();
if("0".equals(chatItemDto.getCheckAll())){
List<WeMaterial> weMaterials = weMaterialService.findWeMaterials(null, null, chatItemDto.getMediaType());
if(CollectionUtils.isNotEmpty(weMaterials)){
materialIds= weMaterials.stream().map(WeMaterial::getId).collect(Collectors.toList());
}
}else {
materialIds= chatItemDto.getMaterialIds();
}
List<Long> finalMaterialIds = materialIds;
Optional.ofNullable(materialIds).ifPresent(
s->{
List<WeChatItem> items=new ArrayList<>();
finalMaterialIds.forEach(materialId->{
WeChatItem item=new WeChatItem();
item.setItemId(SnowFlakeUtil.nextId());
item.setMaterialId(materialId);
item.setSideId(chatItemDto.getSideId());
items.add(item);
});
weChatItemMapper.dropItem(chatItemDto.getSideId());
weChatItemMapper.addItem(items);
checkItemsTotal(chatItemDto, finalMaterialIds);
}
);
return 1;
}
@Override
public List<WeChatSideVo> chatItems(Long sideId,String keyword) {
return weChatItemMapper.findChatItems(sideId,keyword);
}
/**
* 更新该次选择的素材数
*
* @param chatItemDto 侧边栏信息
* @param finalMaterialIds 素材id列表
*/
private void checkItemsTotal(WeChatItemDto chatItemDto, List<Long> finalMaterialIds) {
WeChatSide side=new WeChatSide();
side.setSideId(chatItemDto.getSideId());
side.setTotal(finalMaterialIds.size());
weChatSideMapper.updateWeChatSideById(side);
}
}