Sfoglia il codice sorgente

在线客服新增信息撤回接口

codingliang 6 mesi fa
parent
commit
3a562a9db6

+ 4 - 1
db/update_251222.sql

@@ -2,4 +2,7 @@
 alter table goods add vip_promotion varchar(1) not null default 0 comment '是否参与vip优惠 0否 1是' after shop_id;
 
 -- 更新商品是否参与vip优惠
-update goods set vip_promotion = 1 where shop_id in (select shop_id from goods_shop where vip_promotion = '1')
+update goods set vip_promotion = 1 where shop_id in (select shop_id from goods_shop where vip_promotion = '1')
+
+-- 会话内容添加撤回标识 0否 1是
+alter table chats_content add recall varchar(1) not null default 0 comment '是否撤回 0否 1是' after status;

+ 6 - 0
src/main/java/com/sqx/modules/chats/controller/ChatsContentController.java

@@ -46,6 +46,12 @@ public class ChatsContentController {
         return service.updateBody(entity);
     }
 
+    @PutMapping("recall/{chatContentId}")
+    @ApiOperation("撤回消息")
+    public Result recall(@PathVariable Long chatContentId) {
+        return service.recall(chatContentId);
+    }
+
     @GetMapping("/delete")
     @ApiOperation("删除聊天会话内容")
     public Result delete(String ids) {

+ 2 - 0
src/main/java/com/sqx/modules/chats/entity/ChatsContent.java

@@ -23,6 +23,8 @@ public class ChatsContent implements Serializable {
     private Integer type;
     @Column(columnDefinition = "int default 1  comment '是否已读(1未读 2已读)'")
     private Integer status;
+    @Column(columnDefinition = "varchar(1) comment '是否撤回 0否 1是'")
+    private String recall;
     @Column(columnDefinition = "varchar(255) comment '创建时间'")
     private String createTime;
     @Column(columnDefinition = "int(1) comment '消息来源(1用户消息 2后台消息)'")

+ 5 - 0
src/main/java/com/sqx/modules/chats/service/ChatsContentService.java

@@ -36,4 +36,9 @@ public interface ChatsContentService {
     //修改
     Result updateBody(ChatsContent entity);
 
+     /**
+     * 撤回消息
+     * @param chatContentId 会话内容id
+     */
+    Result recall(Long chatContentId);
 }

+ 23 - 14
src/main/java/com/sqx/modules/chats/service/ChatsContentServiceImpl.java

@@ -1,6 +1,8 @@
 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.ChatsContent;
 import com.sqx.modules.chats.respository.ChatContentRepository;
@@ -18,6 +20,7 @@ import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 @Service
 public class ChatsContentServiceImpl implements ChatsContentService {
@@ -34,13 +37,10 @@ public class ChatsContentServiceImpl implements ChatsContentService {
     @Override
     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);
         /*
@@ -70,13 +70,10 @@ public class ChatsContentServiceImpl implements ChatsContentService {
     @Override
     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);
         /*
@@ -124,6 +121,18 @@ public class ChatsContentServiceImpl implements ChatsContentService {
     }
 
     @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) {
         return ResultUtil.success(jpaRepository.findById(id).orElse(null));
     }