Просмотр исходного кода

Merge branch 'feature/im_update_conversation' into 'develop'

im 聊天模块 群属性修改功能

See merge request o2oa/o2oa!911
楼国栋 5 лет назад
Родитель
Сommit
bc9d2c2f87

+ 6 - 0
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ActionConversationCreate.java

@@ -64,6 +64,12 @@ public class ActionConversationCreate extends BaseAction {
                 }
             }
 
+            //群聊添加管理员
+            if (conversation.getType().equals(CONVERSATION_TYPE_GROUP)) {
+                conversation.setAdminPerson(effectivePerson.getDistinguishedName());
+            }
+
+            //处理标题
             if (conversation.getTitle() == null || conversation.getTitle().isEmpty()) {
                 String title = "";
                 if (conversation.getType().equals(CONVERSATION_TYPE_SINGLE)) {

+ 133 - 0
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ActionConversationUpdate.java

@@ -0,0 +1,133 @@
+package com.x.message.assemble.communicate.jaxrs.im;
+
+import com.google.gson.JsonElement;
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.entity.JpaObject;
+import com.x.base.core.entity.annotation.CheckPersistType;
+import com.x.base.core.project.annotation.FieldDescribe;
+import com.x.base.core.project.bean.WrapCopier;
+import com.x.base.core.project.bean.WrapCopierFactory;
+import com.x.base.core.project.gson.GsonPropertyObject;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.base.core.project.tools.ListTools;
+import com.x.message.assemble.communicate.Business;
+import com.x.message.core.entity.IMConversation;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Date;
+import java.util.List;
+
+import static com.x.message.core.entity.IMConversation.CONVERSATION_TYPE_GROUP;
+import static com.x.message.core.entity.IMConversation.CONVERSATION_TYPE_SINGLE;
+
+
+public class ActionConversationUpdate extends BaseAction {
+
+    private static Logger logger = LoggerFactory.getLogger(ActionConversationUpdate.class);
+
+    ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement)  throws Exception {
+
+        logger.debug("receive{}.", jsonElement);
+
+        try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+            Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
+            if (StringUtils.isEmpty(wi.getId())) {
+                throw  new ExceptionEmptyId();
+            }
+            IMConversation conversation = emc.find(wi.getId(), IMConversation.class);
+            if (conversation.getType().equals(CONVERSATION_TYPE_SINGLE)) {
+                throw new ExceptionSingleConvNotUpdate();
+            }
+            if (!effectivePerson.getDistinguishedName().equals(conversation.getAdminPerson())) {
+                throw new ExceptionConvUpdateNoPermission();
+            }
+            emc.beginTransaction(IMConversation.class);
+            if (StringUtils.isNotEmpty(wi.getTitle())) {
+                conversation.setTitle(wi.getTitle());
+            }
+            if (StringUtils.isNotEmpty(wi.getNote())) {
+                conversation.setNote(wi.getNote());
+            }
+            if (wi.getPersonList() != null && !wi.getPersonList().isEmpty()) {
+                conversation.setPersonList(wi.getPersonList());
+            }
+            conversation.setUpdateTime(new Date());
+            emc.check(conversation, CheckPersistType.all);
+            emc.commit();
+
+            ActionResult<Wo> result = new ActionResult<>();
+            Wo wo = Wo.copier.copy(conversation);
+            result.setData(wo);
+            return result;
+        }
+    }
+
+
+    public static class Wi extends GsonPropertyObject {
+        @FieldDescribe("id")
+        private String id;
+        @FieldDescribe("会话标题")
+        private String title;
+        @FieldDescribe("会话公告")
+        private String note;
+        @FieldDescribe("会话对象")
+        private List<String> personList;
+        @FieldDescribe("会话管理员")
+        private String adminPerson;
+
+
+        public String getId() {
+            return id;
+        }
+
+        public void setId(String id) {
+            this.id = id;
+        }
+
+        public String getTitle() {
+            return title;
+        }
+
+        public void setTitle(String title) {
+            this.title = title;
+        }
+
+        public String getNote() {
+            return note;
+        }
+
+        public void setNote(String note) {
+            this.note = note;
+        }
+
+        public List<String> getPersonList() {
+            return personList;
+        }
+
+        public void setPersonList(List<String> personList) {
+            this.personList = personList;
+        }
+
+        public String getAdminPerson() {
+            return adminPerson;
+        }
+
+        public void setAdminPerson(String adminPerson) {
+            this.adminPerson = adminPerson;
+        }
+    }
+
+
+    public static class Wo extends IMConversation {
+
+        private static final long serialVersionUID = 3434938936805201380L;
+        static WrapCopier<IMConversation, Wo> copier = WrapCopierFactory.wo(IMConversation.class, Wo.class, null,
+                JpaObject.FieldsInvisible);
+    }
+
+
+}

+ 0 - 1
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ActionUploadFile.java

@@ -5,7 +5,6 @@ import com.x.base.core.container.factory.EntityManagerContainerFactory;
 import com.x.base.core.entity.annotation.CheckPersistType;
 import com.x.base.core.project.annotation.FieldDescribe;
 import com.x.base.core.project.config.StorageMapping;
-import com.x.base.core.project.exception.PromptException;
 import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
 import com.x.base.core.project.jaxrs.WoId;

+ 14 - 0
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ExceptionConvUpdateNoPermission.java

@@ -0,0 +1,14 @@
+package com.x.message.assemble.communicate.jaxrs.im;
+
+import com.x.base.core.project.exception.PromptException;
+
+class ExceptionConvUpdateNoPermission extends PromptException {
+
+	private static final long serialVersionUID = 4132300948670472899L;
+
+	ExceptionConvUpdateNoPermission() {
+		super("没有权限修改会话属性");
+	}
+
+
+}

+ 14 - 0
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ExceptionEmptyId.java

@@ -0,0 +1,14 @@
+package com.x.message.assemble.communicate.jaxrs.im;
+
+import com.x.base.core.project.exception.PromptException;
+
+class ExceptionEmptyId extends PromptException {
+
+	private static final long serialVersionUID = 4132300948670472899L;
+
+	ExceptionEmptyId() {
+		super("Id不能为空");
+	}
+
+
+}

+ 14 - 0
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ExceptionSingleConvNotUpdate.java

@@ -0,0 +1,14 @@
+package com.x.message.assemble.communicate.jaxrs.im;
+
+import com.x.base.core.project.exception.PromptException;
+
+class ExceptionSingleConvNotUpdate extends PromptException {
+
+	private static final long serialVersionUID = 4132300948670472899L;
+
+	ExceptionSingleConvNotUpdate() {
+		super("单聊会话无法修改属性");
+	}
+
+
+}

+ 19 - 0
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ImAction.java

@@ -52,6 +52,25 @@ public class ImAction extends StandardJaxrsAction {
         asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
     }
 
+
+    @JaxrsMethodDescribe(value = "修改会话.", action = ActionConversationUpdate.class)
+    @PUT
+    @Path("conversation")
+    @Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+    @Consumes(MediaType.APPLICATION_JSON)
+    public void update(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+                       JsonElement jsonElement) {
+        ActionResult<ActionConversationUpdate.Wo> result = new ActionResult<>();
+        EffectivePerson effectivePerson = this.effectivePerson(request);
+        try {
+            result = new ActionConversationUpdate().execute( effectivePerson, jsonElement );
+        } catch (Exception e) {
+            logger.error(e, effectivePerson, request, jsonElement);
+            result.error(e);
+        }
+        asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+    }
+
     //conversation/{id}  GET 如果没有扩展就创建扩展
     @JaxrsMethodDescribe(value = "会话对象.", action = ActionGetConversation.class)
     @GET