LoveChatService.java
1.91 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
package com.pipihelper.project.feishu.service;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.pipihelper.project.feishu.bo.LoveChatVO;
import com.pipihelper.project.feishu.dao.LoveChatDao;
import com.pipihelper.project.feishu.entity.LoveChat;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class LoveChatService {
@Autowired
private LoveChatDao loveChatDao;
public List<LoveChatVO> list(String title, Integer pageNum, Integer pageSize) {
if(StringUtils.isBlank(title)){
title = null;
}
PageHelper.startPage(pageNum, pageSize);
List<LoveChat> chatList = loveChatDao.findList(title);
if (CollectionUtil.isEmpty(chatList)) {
return new ArrayList<>();
}
return chatList.stream().map(it -> {
LoveChatVO loveChatVO = new LoveChatVO();
loveChatVO.setTitle(it.getTitle());
loveChatVO.setId(it.getId());
List<SpeedContent> speedContentList = JSON.parseArray(it.getContent(), SpeedContent.class);
loveChatVO.setLoveChatDetails(speedContentList.stream().map(speedContent -> {
LoveChatVO.LoveChatDetail chatDetail = new LoveChatVO.LoveChatDetail();
chatDetail.setType("me".equals(speedContent.getObject()) ? 1 : 2);
chatDetail.setText(speedContent.getPlan());
return chatDetail;
}).collect(Collectors.toList()));
return loveChatVO;
}).collect(Collectors.toList());
}
@Data
private static class SpeedContent {
private String object;
private String plan;
}
}