浏览代码

新增文档协作成员时,发送即时消息。

wukai 1 年之前
父节点
当前提交
9d91a770ba

+ 39 - 4
doc-biz/src/main/java/com/doc/biz/controller/DocActorController.java

@@ -5,16 +5,21 @@ import com.doc.biz.domain.DocActorUser;
 import com.doc.biz.domain.DocInfo;
 import com.doc.biz.service.IDocActorService;
 import com.doc.biz.service.IDocActorUserService;
+import com.doc.biz.service.IDocInfoService;
+import com.doc.chat.domain.ChatMsg;
+import com.doc.chat.service.IChatMsgService;
 import com.doc.common.core.controller.BaseController;
 import com.doc.common.core.domain.AjaxResult;
 import com.doc.common.core.page.TableDataInfo;
 import com.doc.common.utils.SecurityUtils;
+import com.doc.system.service.ISysConfigService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -32,6 +37,12 @@ public class DocActorController extends BaseController {
     private IDocActorService docActorService;
     @Resource
     private IDocActorUserService actorUserService;
+    @Resource
+    private IChatMsgService msgService;
+    @Resource
+    private ISysConfigService configService;
+    @Resource
+    private IDocInfoService infoService;
 
     @ApiOperation("归档")
     @PutMapping("/{docId}")
@@ -46,9 +57,7 @@ public class DocActorController extends BaseController {
     @ApiOperation("获取已选择人员")
     @GetMapping("/{docId}")
     public List<DocActorUser> get(@ApiParam(value = "文件ID", required = true) @PathVariable(name = "docId") Long docId) {
-        DocActorUser actorUser = new DocActorUser();
-        actorUser.setDocId(docId);
-        return actorUserService.selectDocActorUserList(actorUser);
+        return actorUserService.selectDocActorUserListByDocId(docId);
     }
 
     @ApiOperation("添加协作人员")
@@ -60,12 +69,38 @@ public class DocActorController extends BaseController {
             actor.setDocId(docId);
             docActorService.insertDocActor(actor);
         }
-        actorUserService.deleteDocActorUserByDocId(docId);
+        /**查询出已有的协作人员*/
+        List<DocActorUser> actorUsers = actorUserService.selectDocActorUserListByDocId(docId);
+        List<Long> oldUsers = new ArrayList<>();
+        actorUsers.forEach(au -> {
+            if (!users.contains(au.getUserId())) {
+                //如果当前列表没有的人员,则删除数据库记录
+                actorUserService.delete(au);
+            } else {
+                //如果数据库中已有该用户,则记录下来,后面的逻辑中使用
+                oldUsers.add(au.getUserId());
+            }
+        });
+        String content = configService.selectConfigByKey("msg.actor.content");
+        DocInfo info = infoService.selectDocInfoByDocId(docId);
         users.forEach(u -> {
+            if (oldUsers.contains(u)) {
+                //如果数据库中已有,则不作任何处理
+                return;
+            }
             DocActorUser actorUser = new DocActorUser();
             actorUser.setUserId(u);
             actorUser.setDocId(docId);
             actorUserService.insertDocActorUser(actorUser);
+
+            //发送消息
+            ChatMsg msg = new ChatMsg();
+            String txt = content.replace("{from}", SecurityUtils.getLoginUser().getUser().getNickName()).replace("{file}", info.getFileName());
+            msg.setMsgType("2");
+            msg.setToId(u);
+            msg.setContent(txt);
+            msg.setFromId(SecurityUtils.getUserId());
+            msgService.send(msg);
         });
 
         return success();

+ 13 - 1
doc-biz/src/main/java/com/doc/biz/service/IDocActorUserService.java

@@ -25,7 +25,13 @@ public interface IDocActorUserService {
      * @param docActorUser 文档协作成员
      * @return 文档协作成员集合
      */
-    public List<DocActorUser> selectDocActorUserList(DocActorUser docActorUser);
+    public List<DocActorUser> selectDocActorUserList(DocActorUser docActorUser);  /**
+     * 查询文档协作成员列表
+     *
+     * @param docId 文档ID
+     * @return 文档协作成员集合
+     */
+    public List<DocActorUser> selectDocActorUserListByDocId(Long docId);
 
     /**
      * 新增文档协作成员
@@ -58,4 +64,10 @@ public interface IDocActorUserService {
      * @return 结果
      */
     public int deleteDocActorUserByDocId(Long docId);
+
+    /**
+     * 删除对象
+     * @param au 对象
+     */
+    void delete(DocActorUser au);
 }

+ 27 - 0
doc-biz/src/main/java/com/doc/biz/service/impl/DocActorUserServiceImpl.java

@@ -1,5 +1,6 @@
 package com.doc.biz.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.doc.biz.domain.DocActorUser;
 import com.doc.biz.mapper.DocActorUserMapper;
 import com.doc.biz.service.IDocActorUserService;
@@ -42,6 +43,19 @@ public class DocActorUserServiceImpl implements IDocActorUserService {
     }
 
     /**
+     * 查询文档协作成员列表
+     *
+     * @param docId 文档ID
+     * @return 文档协作成员集合
+     */
+    @Override
+    public List<DocActorUser> selectDocActorUserListByDocId(Long docId) {
+        DocActorUser au = new DocActorUser();
+        au.setDocId(docId);
+        return docActorUserMapper.selectDocActorUserList(au);
+    }
+
+    /**
      * 新增文档协作成员
      *
      * @param docActorUser 文档协作成员
@@ -84,4 +98,17 @@ public class DocActorUserServiceImpl implements IDocActorUserService {
     public int deleteDocActorUserByDocId(Long docId) {
         return docActorUserMapper.deleteDocActorUserByDocId(docId);
     }
+
+    /**
+     * 删除对象
+     *
+     * @param au 对象
+     */
+    @Override
+    public void delete(DocActorUser au) {
+        QueryWrapper<DocActorUser> queryWrapper = new QueryWrapper<>(au);
+//        queryWrapper.eq("doc_id", au.getDocId());
+//        queryWrapper.eq("user_id", au.getUserId());
+        docActorUserMapper.delete(queryWrapper);
+    }
 }