parent
037f7208bb
commit
c1c36c56ca
@ -0,0 +1,41 @@
|
||||
package com.example.flower.service;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import com.example.flower.mapper.ImSingleDao;
|
||||
import com.example.flower.entity.ImSingle;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ImSingleService {
|
||||
|
||||
@Resource
|
||||
private ImSingleDao imSingleDao;
|
||||
|
||||
public ImSingle add(ImSingle imSingle) {
|
||||
imSingle.setReaded(0);
|
||||
imSingleDao.insert(imSingle);
|
||||
return imSingle;
|
||||
}
|
||||
public List<ImSingle> findByUsername(String fromUser, String toUser) {
|
||||
List<ImSingle> list = imSingleDao.findByUsername(fromUser, toUser);
|
||||
list.forEach(x -> {
|
||||
if (x.getTouser().equals(fromUser) && x.getFromuser().equals(toUser)) {
|
||||
x.setReaded(1);
|
||||
imSingleDao.updateById(x);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
public Dict findUnReadNums(String toUsername) {
|
||||
List<ImSingle> list = imSingleDao.findByToUsername(toUsername);
|
||||
Map<String, List<ImSingle>> collect = list.stream().collect(Collectors.groupingBy(ImSingle::getFromuser));
|
||||
Dict dict = Dict.create();
|
||||
collect.forEach((k,v) -> dict.set(k, v.size()));
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue