|
@@ -1,6 +1,8 @@
|
|
|
package com.sqx.modules.chats.service;
|
|
package com.sqx.modules.chats.service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import com.sqx.common.exception.SqxException;
|
|
|
import com.sqx.modules.chats.entity.Chats;
|
|
import com.sqx.modules.chats.entity.Chats;
|
|
|
import com.sqx.modules.chats.entity.ChatsContent;
|
|
import com.sqx.modules.chats.entity.ChatsContent;
|
|
|
import com.sqx.modules.chats.respository.ChatContentRepository;
|
|
import com.sqx.modules.chats.respository.ChatContentRepository;
|
|
@@ -18,6 +20,7 @@ import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
import javax.persistence.criteria.Root;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
public class ChatsContentServiceImpl implements ChatsContentService {
|
|
public class ChatsContentServiceImpl implements ChatsContentService {
|
|
@@ -34,13 +37,10 @@ public class ChatsContentServiceImpl implements ChatsContentService {
|
|
|
@Override
|
|
@Override
|
|
|
public Result findAll(Long chatId) {
|
|
public Result findAll(Long chatId) {
|
|
|
//构造自定义查询条件
|
|
//构造自定义查询条件
|
|
|
- Specification<ChatsContent> queryCondition = new Specification<ChatsContent>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public Predicate toPredicate(Root<ChatsContent> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
|
|
|
- List<Predicate> predicateList = new ArrayList<>();
|
|
|
|
|
- predicateList.add(criteriaBuilder.equal(root.get("chatId"), chatId));
|
|
|
|
|
- return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Specification<ChatsContent> queryCondition = (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
|
+ List<Predicate> predicateList = new ArrayList<>();
|
|
|
|
|
+ predicateList.add(criteriaBuilder.equal(root.get("chatId"), chatId));
|
|
|
|
|
+ return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
};
|
|
};
|
|
|
List<ChatsContent> list = jpaRepository.findAll(queryCondition);
|
|
List<ChatsContent> list = jpaRepository.findAll(queryCondition);
|
|
|
/*
|
|
/*
|
|
@@ -70,13 +70,10 @@ public class ChatsContentServiceImpl implements ChatsContentService {
|
|
|
@Override
|
|
@Override
|
|
|
public Result storeList(Long chatId) {
|
|
public Result storeList(Long chatId) {
|
|
|
//构造自定义查询条件
|
|
//构造自定义查询条件
|
|
|
- Specification<ChatsContent> queryCondition = new Specification<ChatsContent>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public Predicate toPredicate(Root<ChatsContent> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
|
|
|
- List<Predicate> predicateList = new ArrayList<>();
|
|
|
|
|
- predicateList.add(criteriaBuilder.equal(root.get("chatId"), chatId));
|
|
|
|
|
- return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Specification<ChatsContent> queryCondition = (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
|
+ List<Predicate> predicateList = new ArrayList<>();
|
|
|
|
|
+ predicateList.add(criteriaBuilder.equal(root.get("chatId"), chatId));
|
|
|
|
|
+ return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
};
|
|
};
|
|
|
List<ChatsContent> list = jpaRepository.findAll(queryCondition);
|
|
List<ChatsContent> list = jpaRepository.findAll(queryCondition);
|
|
|
/*
|
|
/*
|
|
@@ -124,6 +121,18 @@ public class ChatsContentServiceImpl implements ChatsContentService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ public Result recall(Long chatContentId) {
|
|
|
|
|
+ ChatsContent chatsContent = jpaRepository.findById(chatContentId).orElse(null);
|
|
|
|
|
+ if (ObjectUtil.isNull(chatsContent)){
|
|
|
|
|
+ throw new SqxException("消息不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ //撤回消息
|
|
|
|
|
+ chatsContent.setRecall("1");
|
|
|
|
|
+ jpaRepository.save(chatsContent);
|
|
|
|
|
+ return ResultUtil.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
public Result findOne(Long id) {
|
|
public Result findOne(Long id) {
|
|
|
return ResultUtil.success(jpaRepository.findById(id).orElse(null));
|
|
return ResultUtil.success(jpaRepository.findById(id).orElse(null));
|
|
|
}
|
|
}
|