ChatLogService.java
3.2 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
package com.w1hd.zzhnc.service;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.testng.collections.Maps;
import org.testng.internal.annotations.Sets;
import com.beust.jcommander.internal.Lists;
import com.w1hd.zzhnc.dao.ChatlogDao;
import com.w1hd.zzhnc.dao.FansDao;
import com.w1hd.zzhnc.model.Chatlog;
import com.w1hd.zzhnc.util.PageResults;
import com.w1hd.zzhnc.vo.ChatLog_DistinctFansIdVO;
import com.w1hd.zzhnc.vo.Chatlog_Vo;
import com.w1hd.zzhnc.vo.Vo_msg;
import tk.mybatis.mapper.entity.Example;
@Service
public class ChatLogService {
@Autowired
ChatlogDao chatlogDao;
@Autowired
FansDao fansDao;
public PageResults<Chatlog_Vo> getChatLogList(Integer page, Integer replytype, String date1, String date2,
String keyword) {
List<Chatlog_Vo> list = chatlogDao.getChatlogList((page - 1) * 10, 10, replytype, date1, date2, keyword);
Integer total = chatlogDao.getChatlogCount(replytype, date1, date2, keyword);
PageResults<Chatlog_Vo> pageResults = new PageResults<>();
pageResults.setPage(page);
pageResults.setPageSize(10);
pageResults.setRows(list);
pageResults.setTotal(total);
return pageResults;
}
public int insertChatLog(Chatlog log) {
log.setId(null);
return chatlogDao.insertSelective(log);
}
public void updateChatLogUnReaded(Integer... ids) {
Example example = new Example(Chatlog.class);
List<Integer> asList = Arrays.asList(ids);
example.createCriteria().andIn("id", asList);
Chatlog log = new Chatlog();
log.setReaded(true);
log.setReadTime(new Date());
chatlogDao.updateByExampleSelective(log, example);
}
public Vo_msg getChatListDistinctFansIdIn(int page,int pageRow,Integer salesId) {
List<ChatLog_DistinctFansIdVO> data = Lists.newArrayList();
data = fansDao.getFansListForChat(page,pageRow,salesId);
return new Vo_msg(0, data);
}
public Vo_msg getChatLogListBySalesId(Integer fromId, Integer fansid, int page,int pageSize) {
Set<Integer> fansIds = null;
if (fansid == null || fansid <= 0) {
return getChatListDistinctFansIdIn((page-1)*pageSize,pageSize,fromId);
} else {
fansIds = Sets.newHashSet();
fansIds.add(fansid);
}
Map<String, Object> result = Maps.newHashMap();
List<Integer> ids =Lists.newArrayList();
ids.add(fromId);
List<Chatlog_Vo> chatLogs = Lists.newArrayList();
for (Integer integer : fansIds) {
List<Chatlog_Vo> logListBySalesId = chatlogDao.getChatLogListBySalesId((page - 1) * pageSize, pageSize, ids,
integer);
Integer chatlogCountBySalesId = chatlogDao.getChatlogCountBySalesId(fromId, integer);
if (!logListBySalesId.isEmpty()) {
chatLogs.addAll(logListBySalesId);
result.put("data", chatLogs);
result.put("count", chatlogCountBySalesId);
}
}
return new Vo_msg(0, result);
}
public void updateChatLogUnReaded(Integer salesId, Integer fansid) {
Example example = new Example(Chatlog.class);
example.createCriteria().andEqualTo("fansid", fansid).andEqualTo("readed",
false);
Chatlog log = new Chatlog();
log.setReaded(true);
log.setReadTime(new Date());
chatlogDao.updateByExampleSelective(log, example);
}
}