Selaa lähdekoodia

add 权限体系请求头

18339543638 3 vuotta sitten
vanhempi
commit
e2ec8be87a

+ 342 - 0
nb-common/ws-common/src/main/java/com/nb/common/websocket/ws/CloseRunnable.java

@@ -0,0 +1,342 @@
+/*
+	Apache License
+	Version 2.0, January 2004
+	http://www.apache.org/licenses/
+	
+	TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+	
+	1. Definitions.
+	
+	"License" shall mean the terms and conditions for use, reproduction, and
+	distribution as defined by Sections 1 through 9 of this document.
+	
+	"Licensor" shall mean the copyright owner or entity authorized by the copyright
+	owner that is granting the License.
+	
+	"Legal Entity" shall mean the union of the acting entity and all other entities
+	that control, are controlled by, or are under common control with that entity.
+	For the purposes of this definition, "control" means (i) the power, direct or
+	indirect, to cause the direction or management of such entity, whether by
+	contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
+	outstanding shares, or (iii) beneficial ownership of such entity.
+	
+	"You" (or "Your") shall mean an individual or Legal Entity exercising
+	permissions granted by this License.
+	
+	"Source" form shall mean the preferred form for making modifications, including
+	but not limited to software source code, documentation source, and configuration
+	files.
+	
+	"Object" form shall mean any form resulting from mechanical transformation or
+	translation of a Source form, including but not limited to compiled object code,
+	generated documentation, and conversions to other media types.
+	
+	"Work" shall mean the work of authorship, whether in Source or Object form, made
+	available under the License, as indicated by a copyright notice that is included
+	in or attached to the work (an example is provided in the Appendix below).
+	
+	"Derivative Works" shall mean any work, whether in Source or Object form, that
+	is based on (or derived from) the Work and for which the editorial revisions,
+	annotations, elaborations, or other modifications represent, as a whole, an
+	original work of authorship. For the purposes of this License, Derivative Works
+	shall not include works that remain separable from, or merely link (or bind by
+	name) to the interfaces of, the Work and Derivative Works thereof.
+	
+	"Contribution" shall mean any work of authorship, including the original version
+	of the Work and any modifications or additions to that Work or Derivative Works
+	thereof, that is intentionally submitted to Licensor for inclusion in the Work
+	by the copyright owner or by an individual or Legal Entity authorized to submit
+	on behalf of the copyright owner. For the purposes of this definition,
+	"submitted" means any form of electronic, verbal, or written communication sent
+	to the Licensor or its representatives, including but not limited to
+	communication on electronic mailing lists, source code control systems, and
+	issue tracking systems that are managed by, or on behalf of, the Licensor for
+	the purpose of discussing and improving the Work, but excluding communication
+	that is conspicuously marked or otherwise designated in writing by the copyright
+	owner as "Not a Contribution."
+	
+	"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
+	of whom a Contribution has been received by Licensor and subsequently
+	incorporated within the Work.
+	
+	2. Grant of Copyright License.
+	
+	Subject to the terms and conditions of this License, each Contributor hereby
+	grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
+	irrevocable copyright license to reproduce, prepare Derivative Works of,
+	publicly display, publicly perform, sublicense, and distribute the Work and such
+	Derivative Works in Source or Object form.
+	
+	3. Grant of Patent License.
+	
+	Subject to the terms and conditions of this License, each Contributor hereby
+	grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
+	irrevocable (except as stated in this section) patent license to make, have
+	made, use, offer to sell, sell, import, and otherwise transfer the Work, where
+	such license applies only to those patent claims licensable by such Contributor
+	that are necessarily infringed by their Contribution(s) alone or by combination
+	of their Contribution(s) with the Work to which such Contribution(s) was
+	submitted. If You institute patent litigation against any entity (including a
+	cross-claim or counterclaim in a lawsuit) alleging that the Work or a
+	Contribution incorporated within the Work constitutes direct or contributory
+	patent infringement, then any patent licenses granted to You under this License
+	for that Work shall terminate as of the date such litigation is filed.
+	
+	4. Redistribution.
+	
+	You may reproduce and distribute copies of the Work or Derivative Works thereof
+	in any medium, with or without modifications, and in Source or Object form,
+	provided that You meet the following conditions:
+	
+	You must give any other recipients of the Work or Derivative Works a copy of
+	this License; and
+	You must cause any modified files to carry prominent notices stating that You
+	changed the files; and
+	You must retain, in the Source form of any Derivative Works that You distribute,
+	all copyright, patent, trademark, and attribution notices from the Source form
+	of the Work, excluding those notices that do not pertain to any part of the
+	Derivative Works; and
+	If the Work includes a "NOTICE" text file as part of its distribution, then any
+	Derivative Works that You distribute must include a readable copy of the
+	attribution notices contained within such NOTICE file, excluding those notices
+	that do not pertain to any part of the Derivative Works, in at least one of the
+	following places: within a NOTICE text file distributed as part of the
+	Derivative Works; within the Source form or documentation, if provided along
+	with the Derivative Works; or, within a display generated by the Derivative
+	Works, if and wherever such third-party notices normally appear. The contents of
+	the NOTICE file are for informational purposes only and do not modify the
+	License. You may add Your own attribution notices within Derivative Works that
+	You distribute, alongside or as an addendum to the NOTICE text from the Work,
+	provided that such additional attribution notices cannot be construed as
+	modifying the License.
+	You may add Your own copyright statement to Your modifications and may provide
+	additional or different license terms and conditions for use, reproduction, or
+	distribution of Your modifications, or for any such Derivative Works as a whole,
+	provided Your use, reproduction, and distribution of the Work otherwise complies
+	with the conditions stated in this License.
+	
+	5. Submission of Contributions.
+	
+	Unless You explicitly state otherwise, any Contribution intentionally submitted
+	for inclusion in the Work by You to the Licensor shall be under the terms and
+	conditions of this License, without any additional terms or conditions.
+	Notwithstanding the above, nothing herein shall supersede or modify the terms of
+	any separate license agreement you may have executed with Licensor regarding
+	such Contributions.
+	
+	6. Trademarks.
+	
+	This License does not grant permission to use the trade names, trademarks,
+	service marks, or product names of the Licensor, except as required for
+	reasonable and customary use in describing the origin of the Work and
+	reproducing the content of the NOTICE file.
+	
+	7. Disclaimer of Warranty.
+	
+	Unless required by applicable law or agreed to in writing, Licensor provides the
+	Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+	including, without limitation, any warranties or conditions of TITLE,
+	NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
+	solely responsible for determining the appropriateness of using or
+	redistributing the Work and assume any risks associated with Your exercise of
+	permissions under this License.
+	
+	8. Limitation of Liability.
+	
+	In no event and under no legal theory, whether in tort (including negligence),
+	contract, or otherwise, unless required by applicable law (such as deliberate
+	and grossly negligent acts) or agreed to in writing, shall any Contributor be
+	liable to You for damages, including any direct, indirect, special, incidental,
+	or consequential damages of any character arising as a result of this License or
+	out of the use or inability to use the Work (including but not limited to
+	damages for loss of goodwill, work stoppage, computer failure or malfunction, or
+	any and all other commercial damages or losses), even if such Contributor has
+	been advised of the possibility of such damages.
+	
+	9. Accepting Warranty or Additional Liability.
+	
+	While redistributing the Work or Derivative Works thereof, You may choose to
+	offer, and charge a fee for, acceptance of support, warranty, indemnity, or
+	other liability obligations and/or rights consistent with this License. However,
+	in accepting such obligations, You may act only on Your own behalf and on Your
+	sole responsibility, not on behalf of any other Contributor, and only if You
+	agree to indemnify, defend, and hold each Contributor harmless for any liability
+	incurred by, or claims asserted against, such Contributor by reason of your
+	accepting any such warranty or additional liability.
+	
+	END OF TERMS AND CONDITIONS
+	
+	APPENDIX: How to apply the Apache License to your work
+	
+	To apply the Apache License to your work, attach the following boilerplate
+	notice, with the fields enclosed by brackets "{}" replaced with your own
+	identifying information. (Don't include the brackets!) The text should be
+	enclosed in the appropriate comment syntax for the file format. We also
+	recommend that a file or class name and description of purpose be included on
+	the same "printed page" as the copyright notice for easier identification within
+	third-party archives.
+	
+	   Copyright 2018 JFinal
+	
+	   Licensed under the Apache License, Version 2.0 (the "License");
+	   you may not use this file except in compliance with the License.
+	   You may obtain a copy of the License at
+	
+	     http://www.apache.org/licenses/LICENSE-2.0
+	
+	   Unless required by applicable law or agreed to in writing, software
+	   distributed under the License is distributed on an "AS IS" BASIS,
+	   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	   See the License for the specific language governing permissions and
+	   limitations under the License.
+*/
+package com.nb.common.websocket.ws;
+
+import java.util.concurrent.Executor;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tio.client.ClientChannelContext;
+import org.tio.client.ClientTioConfig;
+import org.tio.client.ReconnConf;
+import org.tio.core.ChannelContext;
+import org.tio.core.maintain.MaintainUtils;
+import org.tio.utils.SystemTimer;
+import org.tio.utils.queue.FullWaitQueue;
+import org.tio.utils.queue.TioFullWaitQueue;
+import org.tio.utils.thread.pool.AbstractQueueRunnable;
+
+/**
+ * 
+ * @author tanyaowu 
+ * 2017年10月19日 上午9:39:59
+ */
+public class CloseRunnable extends AbstractQueueRunnable<ChannelContext> {
+
+	private static Logger log = LoggerFactory.getLogger(CloseRunnable.class);
+
+	public CloseRunnable(Executor executor) {
+		super(executor);
+		getMsgQueue();
+	}
+	//	long count = 1;
+
+	@Override
+	public void runTask() {
+		if (msgQueue.isEmpty()) {
+			return;
+		}
+		ChannelContext channelContext = null;
+		while ((channelContext = msgQueue.poll()) != null) {
+			//			System.out.println(count++);
+			try {
+				boolean isNeedRemove = channelContext.closeMeta.isNeedRemove;
+				String remark = channelContext.closeMeta.remark;
+				Throwable throwable = channelContext.closeMeta.throwable;
+
+				//				WriteLock writeLock = channelContext.closeLock.writeLock();
+				//				boolean isLock = writeLock.tryLock();
+				//				if (!isLock) {
+				//					if (isNeedRemove) {
+				//						if (channelContext.isRemoved) {
+				//							return;
+				//						} else {
+				//							writeLock.lock();
+				//							isLock = true;
+				//						}
+				//					} else {
+				//						return;
+				//					}
+				//				}
+
+				channelContext.stat.timeClosed = SystemTimer.currTime;
+				if (channelContext.tioConfig.getAioListener() != null) {
+					try {
+						channelContext.tioConfig.getAioListener().onBeforeClose(channelContext, throwable, remark, isNeedRemove);
+					} catch (Throwable e) {
+						log.error(e.toString(), e);
+					}
+				}
+
+				try {
+					//					channelContext.traceClient(ChannelAction.UNCONNECT, null, null);
+
+					if (channelContext.isClosed && !isNeedRemove) {
+						log.debug("{}, {}已经关闭,备注:{},异常:{}", channelContext.tioConfig, channelContext, remark, throwable == null ? "无" : throwable.toString());
+						return;
+					}
+
+					if (channelContext.isRemoved) {
+						log.debug("{}, {}已经删除,备注:{},异常:{}", channelContext.tioConfig, channelContext, remark, throwable == null ? "无" : throwable.toString());
+						return;
+					}
+
+					//必须先取消任务再清空队列
+					channelContext.decodeRunnable.setCanceled(true);
+					channelContext.handlerRunnable.setCanceled(true);
+					channelContext.sendRunnable.setCanceled(true);
+
+					channelContext.decodeRunnable.clearMsgQueue();
+					channelContext.handlerRunnable.clearMsgQueue();
+					channelContext.sendRunnable.clearMsgQueue();
+
+					log.debug("{}, {} 准备关闭连接, isNeedRemove:{}, {}", channelContext.tioConfig, channelContext, isNeedRemove, remark);
+
+					try {
+						if (isNeedRemove) {
+							MaintainUtils.remove(channelContext);
+						} else {
+							ClientTioConfig clientTioConfig = (ClientTioConfig) channelContext.tioConfig;
+							clientTioConfig.closeds.add(channelContext);
+							clientTioConfig.connecteds.remove(channelContext);
+							MaintainUtils.close(channelContext);
+						}
+
+						channelContext.setRemoved(isNeedRemove);
+						if (channelContext.tioConfig.statOn) {
+							channelContext.tioConfig.groupStat.closed.incrementAndGet();
+						}
+						channelContext.stat.timeClosed = SystemTimer.currTime;
+						channelContext.setClosed(true);
+					} catch (Throwable e) {
+						log.error(e.toString(), e);
+					} finally {
+						if (!isNeedRemove && channelContext.isClosed && !channelContext.isServer()) //不删除且没有连接上,则加到重连队列中
+						{
+							ClientChannelContext clientChannelContext = (ClientChannelContext) channelContext;
+							ReconnConf.put(clientChannelContext);
+						}
+					}
+				} catch (Throwable e) {
+					log.error(throwable.toString(), e);
+				}
+				//				finally {
+				//					writeLock.unlock();
+				//				}
+			} finally {
+				channelContext.isWaitingClose = false;
+			}
+		}
+	}
+
+	@Override
+	public String logstr() {
+		return super.logstr();
+	}
+
+	/** The msg queue. */
+	private FullWaitQueue<ChannelContext> msgQueue = null;
+
+	@Override
+	public FullWaitQueue<ChannelContext> getMsgQueue() {
+		if (msgQueue == null) {
+			synchronized (this) {
+				if (msgQueue == null) {
+					msgQueue = new TioFullWaitQueue<ChannelContext>(Integer.getInteger("tio.fullqueue.capacity", null), false);
+				}
+			}
+		}
+		return msgQueue;
+	}
+}

+ 2 - 0
nb-common/ws-common/src/main/java/com/nb/common/websocket/ws/HeartBeatConfig.java

@@ -4,6 +4,7 @@ import com.nb.common.websocket.handler.WsHandler;
 import lombok.AllArgsConstructor;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.context.annotation.Configuration;
+import org.tio.core.task.CloseRunnable;
 import org.tio.websocket.starter.TioWebSocketServerBootstrap;
 
 import java.util.List;
@@ -24,5 +25,6 @@ public class HeartBeatConfig implements CommandLineRunner {
     @Override
     public void run(String... args) {
         serverTioConfig.getServerTioConfig().setServerAioListener(new DefaultWsServerAioListener(wsHandlers));
+        serverTioConfig.getServerTioConfig().closeRunnable=new CloseRunnable(serverTioConfig.getServerTioConfig().tioExecutor);
     }
 }

+ 5 - 5
nb-im/src/main/java/com/nb/im/controller/ChatRooMsgController.java → nb-im/src/main/java/com/nb/im/controller/ImRooMsgController.java

@@ -3,8 +3,8 @@ package com.nb.im.controller;
 import com.baomidou.mybatisplus.core.mapper.Mapper;
 import com.nb.common.crud.BaseService;
 import com.nb.common.crud.controller.BaseCrudController;
-import com.nb.im.entity.ChatRoomMsgEntity;
-import com.nb.im.service.LocalChatRoomMsgService;
+import com.nb.im.entity.ImMsgEntity;
+import com.nb.im.service.LocalImMsgService;
 import io.swagger.annotations.Api;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -21,11 +21,11 @@ import org.springframework.web.bind.annotation.RestController;
 @AllArgsConstructor
 @RequestMapping("/im/msg")
 @Api(tags = "聊天室消息")
-public class ChatRooMsgController extends BaseCrudController<ChatRoomMsgEntity, String> {
-    private final LocalChatRoomMsgService chatRoomMsgService;
+public class ImRooMsgController extends BaseCrudController<ImMsgEntity, String> {
+    private final LocalImMsgService chatRoomMsgService;
 
     @Override
-    public BaseService<? extends Mapper<ChatRoomMsgEntity>, ChatRoomMsgEntity, String> getService() {
+    public BaseService<? extends Mapper<ImMsgEntity>, ImMsgEntity, String> getService() {
         return chatRoomMsgService;
     }
 }

+ 11 - 13
nb-im/src/main/java/com/nb/im/controller/ChatRoomController.java → nb-im/src/main/java/com/nb/im/controller/ImRoomController.java

@@ -5,17 +5,15 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.Mapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.nb.auth.utils.SecurityUtil;
 import com.nb.common.crud.BaseService;
-import com.nb.common.crud.controller.BaseCrudController;
 import com.nb.common.crud.controller.BaseSaveController;
 import com.nb.core.result.R;
+import com.nb.im.entity.ImRoomEntity;
 import com.nb.im.service.dto.ChatRoomDto;
-import com.nb.im.entity.ChatRoomEntity;
 import com.nb.im.enums.ImStatusEnum;
 import com.nb.im.enums.SponsorEnum;
-import com.nb.im.service.LocalChatRoomService;
+import com.nb.im.service.LocalImRoomService;
 import com.nb.im.service.dto.ChatRoomQuery;
 import com.nb.im.service.dto.ChatRoomResult;
 import io.swagger.annotations.Api;
@@ -38,11 +36,11 @@ import org.springframework.web.bind.annotation.RestController;
 @AllArgsConstructor
 @RequestMapping("/im/room")
 @Api(tags = "聊天室")
-public class ChatRoomController implements BaseSaveController<ChatRoomEntity,String> {
-    private final LocalChatRoomService chatRoomService;
+public class ImRoomController implements BaseSaveController<ImRoomEntity,String> {
+    private final LocalImRoomService chatRoomService;
 
     @Override
-    public BaseService<? extends Mapper<ChatRoomEntity>, ChatRoomEntity, String> getService() {
+    public BaseService<? extends Mapper<ImRoomEntity>, ImRoomEntity, String> getService() {
         return chatRoomService;
     }
 
@@ -50,14 +48,14 @@ public class ChatRoomController implements BaseSaveController<ChatRoomEntity,Str
     @ApiOperation(value = "查询并自动创建与病人看护人的聊天室",notes = "若存在,则返回聊天室信息,若不存在,则返回空")
     @PostMapping("/look")
     public R getChatRoom(@RequestBody@Validated ChatRoomDto source){
-        ChatRoomEntity chatRoom = chatRoomService.getOne(new QueryWrapper<ChatRoomEntity>()
+        ImRoomEntity chatRoom = chatRoomService.getOne(new QueryWrapper<ImRoomEntity>()
                 .lambda()
-                .eq(ChatRoomEntity::getAssistId, source.getAssistId())
-                .eq(ChatRoomEntity::getDoctorId, source.getDoctorId())
-                .eq(ChatRoomEntity::getPatientId, source.getPatientId())
-                .nested(i->i.eq(ChatRoomEntity::getStatus, ImStatusEnum.WAITING)
+                .eq(ImRoomEntity::getAssistId, source.getAssistId())
+                .eq(ImRoomEntity::getDoctorId, source.getDoctorId())
+                .eq(ImRoomEntity::getPatientId, source.getPatientId())
+                .nested(i->i.eq(ImRoomEntity::getStatus, ImStatusEnum.WAITING)
                         .or()
-                        .eq(ChatRoomEntity::getStatus,ImStatusEnum.SUCCESS))
+                        .eq(ImRoomEntity::getStatus,ImStatusEnum.SUCCESS))
                 .last("limit 1"));
         if(chatRoom==null&&source.isAutoCreate()){
             source.setTotalCount(0);

+ 4 - 4
nb-im/src/main/java/com/nb/im/entity/ChatRoomMsgEntity.java → nb-im/src/main/java/com/nb/im/entity/ImMsgEntity.java

@@ -13,20 +13,20 @@ import lombok.ToString;
 /**
  * @author lifang
  * @version 1.0.0
- * @ClassName ChatRoomEntity.java
+ * @ClassName ImRoomEntity.java
  * @Description TODO
  * @createTime 2022年08月16日 09:02:00
  */
 @EqualsAndHashCode(callSuper = true)
 @Data
-@TableName(value = "chat_room_msg",autoResultMap = true)
+@TableName(value = "im_msg",autoResultMap = true)
 @ApiModel(value="聊天室消息")
 @ToString
 @NoArgsConstructor
-public class ChatRoomMsgEntity extends GenericEntity<String> {
+public class ImMsgEntity extends GenericEntity<String> {
 
     @ApiModelProperty(value = "聊天室id",required = true)
-    private String chatRoomId;
+    private String imRoomId;
 
     @ApiModelProperty(value = "消息内容",required = true)
     private String payload;

+ 3 - 3
nb-im/src/main/java/com/nb/im/entity/ChatRoomEntity.java → nb-im/src/main/java/com/nb/im/entity/ImRoomEntity.java

@@ -19,17 +19,17 @@ import java.util.Date;
 /**
  * @author lifang
  * @version 1.0.0
- * @ClassName ChatRoomEntity.java
+ * @ClassName ImRoomEntity.java
  * @Description TODO
  * @createTime 2022年08月16日 09:22:00
  */
 @EqualsAndHashCode(callSuper = true)
 @Data
-@TableName(value = "chat_room",autoResultMap = true)
+@TableName(value = "im_room",autoResultMap = true)
 @ApiModel(value="聊天室")
 @ToString
 @NoArgsConstructor
-public class ChatRoomEntity extends GenericEntity<String> {
+public class ImRoomEntity extends GenericEntity<String> {
     @ApiModelProperty(value = "病人id",required = true)
     @NotNull(message = "病人id不能为空",groups = Insert.class)
     private String patientId;

+ 8 - 17
nb-im/src/main/java/com/nb/im/entity/ChatRoomUserEntity.java → nb-im/src/main/java/com/nb/im/entity/ImRoomUserEntity.java

@@ -15,40 +15,31 @@ import java.util.Date;
 /**
  * @author lifang
  * @version 1.0.0
- * @ClassName ChatRoomEntity.java
+ * @ClassName ImRoomEntity.java
  * @Description TODO
  * @createTime 2022年08月16日 09:02:00
  */
 @EqualsAndHashCode(callSuper = true)
 @Data
-@TableName(value = "chat_room_user",autoResultMap = true)
+@TableName(value = "im_room_user",autoResultMap = true)
 @ApiModel(value="聊天室参与人")
 @ToString
 @NoArgsConstructor
-public class ChatRoomUserEntity extends GenericEntity<String> {
+public class ImRoomUserEntity extends GenericEntity<String> {
 
     @ApiModelProperty(value = "聊天室id",required = true)
-    private String chatRoomId;
+    private String imRoomId;
 
     @ApiModelProperty(value = "是否置顶,默认 否")
     private Boolean top;
 
     @ApiModelProperty(value = "参与人id",required = true)
-    private String participantsId;
+    private String userId;
 
     @ApiModelProperty(value = "参与人类型",required = true,allowableValues = "0(看护人发起) 1(医生发起)")
-    private SponsorEnum participantsType;
+    private SponsorEnum userType;
 
-    @ApiModelProperty(value = "该参与人在此聊天室中的发送消息个数",readOnly = true)
-    private Integer sendCount;
-
-    @ApiModelProperty(value = "该参与人在此聊天室中的已读消息个数",readOnly = true)
-    private Integer readCount;
-
-    @ApiModelProperty("最后一次发送消息时间")
-    private Date lastSendTime;
-
-    @ApiModelProperty("最后一次读取消息时间")
-    private Date lastReadTime;
+    @ApiModelProperty("已读消息数量")
+    private int readCount;
 
 }

+ 23 - 28
nb-im/src/main/java/com/nb/im/listener/ConsultMsgListener.java

@@ -3,23 +3,21 @@ package com.nb.im.listener;
 import com.nb.app.msg.bean.MsgBean;
 import com.nb.app.msg.enums.MsgEnum;
 import com.nb.app.msg.event.SaveMsgEvent;
-import com.nb.im.entity.ChatRoomEntity;
-import com.nb.im.entity.ChatRoomMsgEntity;
-import com.nb.im.entity.ChatRoomUserEntity;
+import com.nb.im.entity.ImRoomEntity;
+import com.nb.im.entity.ImMsgEntity;
+import com.nb.im.entity.ImRoomUserEntity;
 import com.nb.im.enums.ImStatusEnum;
 import com.nb.im.enums.ImMsgType;
 import com.nb.im.enums.SponsorEnum;
-import com.nb.im.service.LocalChatRoomMsgService;
-import com.nb.im.service.LocalChatRoomService;
-import com.nb.im.service.LocalChatRoomUserService;
+import com.nb.im.service.LocalImMsgService;
+import com.nb.im.service.LocalImRoomService;
+import com.nb.im.service.LocalImRoomUserService;
 import lombok.AllArgsConstructor;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.event.EventListener;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
-
 /**
  * @author lifang
  * @version 1.0.0
@@ -31,9 +29,9 @@ import java.util.Date;
 @AllArgsConstructor
 public class ConsultMsgListener {
 
-    private final LocalChatRoomMsgService chatRoomMsgService;
-    private final LocalChatRoomUserService roomUserService;
-    private final LocalChatRoomService chatRoomService;
+    private final LocalImMsgService chatRoomMsgService;
+    private final LocalImRoomUserService roomUserService;
+    private final LocalImRoomService chatRoomService;
 
     @EventListener
     @Async
@@ -47,9 +45,9 @@ public class ConsultMsgListener {
         if (!MsgEnum.CONSUL.equals(msgType)&&!MsgEnum.PAIN_CALL.equals(msgType)) {
             return;
         }
-        ChatRoomEntity room = createRoom(payload);
+        ImRoomEntity room = createRoom(payload);
         createRoomUser(payload, room);
-        ChatRoomMsgEntity roomMsg = createRoomMsg(payload, room);
+        ImMsgEntity roomMsg = createRoomMsg(payload, room);
         room.setLastMsgId(roomMsg.getId());
         chatRoomService.save(room);
     }
@@ -59,10 +57,10 @@ public class ConsultMsgListener {
      * @author lifang
      * @date 2022/8/16 10:38
      * @param source
-     * @return ChatRoomEntity
+     * @return ImRoomEntity
      */
-    private ChatRoomEntity createRoom(MsgBean source){
-        ChatRoomEntity result = new ChatRoomEntity();
+    private ImRoomEntity createRoom(MsgBean source){
+        ImRoomEntity result = new ImRoomEntity();
         result.setAssistId(source.getSenderId());
         result.setPatientId(source.getPatientId());
         result.setPatientCode(source.getPatientCode());
@@ -78,9 +76,9 @@ public class ConsultMsgListener {
     }
 
 
-    private ChatRoomMsgEntity createRoomMsg(MsgBean msg,ChatRoomEntity source){
-        ChatRoomMsgEntity result = new ChatRoomMsgEntity();
-        result.setChatRoomId(source.getId());
+    private ImMsgEntity createRoomMsg(MsgBean msg, ImRoomEntity source){
+        ImMsgEntity result = new ImMsgEntity();
+        result.setImRoomId(source.getId());
         result.setPayload(msg.getPayload());
         result.setMsgType(ImMsgType.hyperlinks);
         result.setSenderId(msg.getSenderId());
@@ -104,17 +102,14 @@ public class ConsultMsgListener {
      * @date 2022/8/16 10:40
      * @param source 聊天室
      * @param  msg 消息
-     * @return ChatRoomUserEntity
+     * @return ImRoomUserEntity
      */
-    private ChatRoomUserEntity createRoomUser(MsgBean msg,ChatRoomEntity source){
-        ChatRoomUserEntity result = new ChatRoomUserEntity();
-        result.setChatRoomId(source.getId());
+    private ImRoomUserEntity createRoomUser(MsgBean msg, ImRoomEntity source){
+        ImRoomUserEntity result = new ImRoomUserEntity();
+        result.setImRoomId(source.getId());
         result.setTop(false);
-        result.setParticipantsId(msg.getReceiverId());
-        result.setParticipantsType(SponsorEnum.assist);
-        result.setSendCount(1);
-        result.setReadCount(1);
-        result.setLastSendTime(new Date());
+        result.setUserId(msg.getReceiverId());
+        result.setUserType(SponsorEnum.assist);
         roomUserService.save(result);
         return result;
     }

+ 11 - 25
nb-im/src/main/java/com/nb/im/listener/PubMsgListener.java

@@ -5,12 +5,10 @@ import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.nb.common.websocket.MessagingRequest;
 import com.nb.common.websocket.event.PubMsgEvent;
-import com.nb.im.entity.ChatRoomEntity;
-import com.nb.im.entity.ChatRoomMsgEntity;
-import com.nb.im.entity.ChatRoomUserEntity;
-import com.nb.im.service.LocalChatRoomMsgService;
-import com.nb.im.service.LocalChatRoomService;
-import com.nb.im.service.LocalChatRoomUserService;
+import com.nb.im.entity.ImRoomEntity;
+import com.nb.im.entity.ImMsgEntity;
+import com.nb.im.service.LocalImMsgService;
+import com.nb.im.service.LocalImRoomService;
 import com.nb.im.ws.PubMsgInfo;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -19,9 +17,6 @@ import org.springframework.context.event.EventListener;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
-import java.util.Optional;
-
 /**
  * @author lifang
  * @version 1.0.0
@@ -34,9 +29,8 @@ import java.util.Optional;
 @Slf4j
 public class PubMsgListener {
 
-    private final LocalChatRoomMsgService chatRoomMsgService;
-    private final LocalChatRoomUserService roomUserService;
-    private final LocalChatRoomService roomService;
+    private final LocalImMsgService chatRoomMsgService;
+    private final LocalImRoomService roomService;
 
     @EventListener
     @Async
@@ -47,22 +41,14 @@ public class PubMsgListener {
         PubMsgInfo pubMsgInfo =null;
 
         pubMsgInfo = JSONUtil.toBean(JSONUtil.toJsonStr(payload), PubMsgInfo.class);
-        ChatRoomMsgEntity roomMsg = BeanUtil.toBean(pubMsgInfo, ChatRoomMsgEntity.class);
+        ImMsgEntity roomMsg = BeanUtil.toBean(pubMsgInfo, ImMsgEntity.class);
         chatRoomMsgService.save(roomMsg);
-        //更新最新发送消息记录
-        roomUserService.update(new UpdateWrapper<ChatRoomUserEntity>()
-                .lambda()
-                .eq(ChatRoomUserEntity::getChatRoomId,pubMsgInfo.getChatRoomId())
-                .eq(ChatRoomUserEntity::getParticipantsId,pubMsgInfo.getSenderId())
-                .eq(ChatRoomUserEntity::getParticipantsType,pubMsgInfo.getSenderType())
-                .set(ChatRoomUserEntity::getLastSendTime, Optional.ofNullable(roomMsg.getCreateTime()).orElse(new Date()))
-        );
         //更新聊天室信息
-        roomService.update(new UpdateWrapper<ChatRoomEntity>()
+        roomService.update(new UpdateWrapper<ImRoomEntity>()
                 .lambda()
-                .eq(ChatRoomEntity::getId,pubMsgInfo.getChatRoomId())
-                .set(ChatRoomEntity::getLastMsgId,roomMsg.getId())
-                .set(ChatRoomEntity::getLastMsgTime,roomMsg.getCreateTime())
+                .eq(ImRoomEntity::getId,pubMsgInfo.getChatRoomId())
+                .set(ImRoomEntity::getLastMsgId,roomMsg.getId())
+                .set(ImRoomEntity::getLastMsgTime,roomMsg.getCreateTime())
                 .setSql("total_count=total_count+1"));
     }
 }

+ 2 - 2
nb-im/src/main/java/com/nb/im/mapper/ChatRoomMapper.java

@@ -3,7 +3,7 @@ package com.nb.im.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.nb.im.entity.ChatRoomEntity;
+import com.nb.im.entity.ImRoomEntity;
 import com.nb.im.service.dto.ChatRoomQuery;
 import com.nb.im.service.dto.ChatRoomResult;
 import org.apache.ibatis.annotations.Mapper;
@@ -17,7 +17,7 @@ import org.apache.ibatis.annotations.Param;
  * @createTime 2022年08月16日 09:27:00
  */
 @Mapper
-public interface ChatRoomMapper extends BaseMapper<ChatRoomEntity> {
+public interface ChatRoomMapper extends BaseMapper<ImRoomEntity> {
 
     /**
      * 描述: 分页查询(查询条件不包含信息内容)

+ 2 - 2
nb-im/src/main/java/com/nb/im/mapper/ChatRoomMsgMapper.java

@@ -1,7 +1,7 @@
 package com.nb.im.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.nb.im.entity.ChatRoomMsgEntity;
+import com.nb.im.entity.ImMsgEntity;
 import org.apache.ibatis.annotations.Mapper;
 
 /**
@@ -12,5 +12,5 @@ import org.apache.ibatis.annotations.Mapper;
  * @createTime 2022年08月16日 09:27:00
  */
 @Mapper
-public interface ChatRoomMsgMapper extends BaseMapper<ChatRoomMsgEntity> {
+public interface ChatRoomMsgMapper extends BaseMapper<ImMsgEntity> {
 }

+ 2 - 2
nb-im/src/main/java/com/nb/im/mapper/ChatRoomUserMapper.java

@@ -1,7 +1,7 @@
 package com.nb.im.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.nb.im.entity.ChatRoomUserEntity;
+import com.nb.im.entity.ImRoomUserEntity;
 import org.apache.ibatis.annotations.Mapper;
 
 /**
@@ -12,5 +12,5 @@ import org.apache.ibatis.annotations.Mapper;
  * @createTime 2022年08月16日 09:27:00
  */
 @Mapper
-public interface ChatRoomUserMapper extends BaseMapper<ChatRoomUserEntity> {
+public interface ChatRoomUserMapper extends BaseMapper<ImRoomUserEntity> {
 }

+ 4 - 4
nb-im/src/main/java/com/nb/im/service/LocalChatRoomMsgService.java → nb-im/src/main/java/com/nb/im/service/LocalImMsgService.java

@@ -1,7 +1,7 @@
 package com.nb.im.service;
 
 import com.nb.common.crud.BaseService;
-import com.nb.im.entity.ChatRoomMsgEntity;
+import com.nb.im.entity.ImMsgEntity;
 import com.nb.im.mapper.ChatRoomMsgMapper;
 import org.springframework.stereotype.Service;
 
@@ -13,14 +13,14 @@ import org.springframework.stereotype.Service;
  * @createTime 2022年08月16日 09:31:00
  */
 @Service
-public class LocalChatRoomMsgService extends BaseService<ChatRoomMsgMapper, ChatRoomMsgEntity,String> {
+public class LocalImMsgService extends BaseService<ChatRoomMsgMapper, ImMsgEntity,String> {
     @Override
-    public void validateBeforeSave(ChatRoomMsgEntity entity) {
+    public void validateBeforeSave(ImMsgEntity entity) {
 
     }
 
     @Override
-    public void validateBeforeUpdate(ChatRoomMsgEntity entity) {
+    public void validateBeforeUpdate(ImMsgEntity entity) {
 
     }
 

+ 10 - 10
nb-im/src/main/java/com/nb/im/service/LocalChatRoomService.java → nb-im/src/main/java/com/nb/im/service/LocalImRoomService.java

@@ -2,7 +2,7 @@ package com.nb.im.service;
 
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.nb.common.crud.BaseService;
-import com.nb.im.entity.ChatRoomEntity;
+import com.nb.im.entity.ImRoomEntity;
 import com.nb.im.enums.ImStatusEnum;
 import com.nb.im.enums.SponsorEnum;
 import com.nb.im.mapper.ChatRoomMapper;
@@ -20,18 +20,18 @@ import org.springframework.transaction.annotation.Transactional;
  * @createTime 2022年08月16日 09:30:00
  */
 @Service
-public class LocalChatRoomService extends BaseService<ChatRoomMapper, ChatRoomEntity,String> {
+public class LocalImRoomService extends BaseService<ChatRoomMapper, ImRoomEntity,String> {
     @Autowired
     @Lazy
-    private LocalChatRoomUserService chatRoomUserService;
+    private LocalImRoomUserService chatRoomUserService;
 
     @Override
-    public void validateBeforeSave(ChatRoomEntity entity) {
+    public void validateBeforeSave(ImRoomEntity entity) {
 
     }
 
     @Override
-    public void validateBeforeUpdate(ChatRoomEntity entity) {
+    public void validateBeforeUpdate(ImRoomEntity entity) {
 
     }
 
@@ -49,8 +49,8 @@ public class LocalChatRoomService extends BaseService<ChatRoomMapper, ChatRoomEn
      * @return void
      */
     @Transactional(rollbackFor = Exception.class)
-    public ChatRoomEntity createChatRoom(ChatRoomDto source) {
-        ChatRoomEntity result = new ChatRoomEntity();
+    public ImRoomEntity createChatRoom(ChatRoomDto source) {
+        ImRoomEntity result = new ImRoomEntity();
         result.setAssistId(source.getAssistId());
         result.setPatientId(source.getPatientId());
         result.setPatientAge(source.getPatientAge());
@@ -80,10 +80,10 @@ public class LocalChatRoomService extends BaseService<ChatRoomMapper, ChatRoomEn
     @Transactional(rollbackFor = Exception.class)
     public void successChatRoom(String chatRoomId,String doctorId) {
         chatRoomUserService.createRoomUser(chatRoomId,doctorId,SponsorEnum.doctor);
-        this.update(new UpdateWrapper<ChatRoomEntity>()
+        this.update(new UpdateWrapper<ImRoomEntity>()
                 .lambda()
-                .eq(ChatRoomEntity::getId,chatRoomId)
-                .set(ChatRoomEntity::getStatus,ImStatusEnum.SUCCESS)
+                .eq(ImRoomEntity::getId,chatRoomId)
+                .set(ImRoomEntity::getStatus,ImStatusEnum.SUCCESS)
         );
     }
 

+ 9 - 13
nb-im/src/main/java/com/nb/im/service/LocalChatRoomUserService.java → nb-im/src/main/java/com/nb/im/service/LocalImRoomUserService.java

@@ -1,7 +1,7 @@
 package com.nb.im.service;
 
 import com.nb.common.crud.BaseService;
-import com.nb.im.entity.ChatRoomUserEntity;
+import com.nb.im.entity.ImRoomUserEntity;
 import com.nb.im.enums.SponsorEnum;
 import com.nb.im.mapper.ChatRoomUserMapper;
 import org.springframework.stereotype.Service;
@@ -17,16 +17,14 @@ import java.util.Date;
  * @createTime 2022年08月16日 09:32:00
  */
 @Service
-public class LocalChatRoomUserService extends BaseService<ChatRoomUserMapper, ChatRoomUserEntity,String> {
+public class LocalImRoomUserService extends BaseService<ChatRoomUserMapper, ImRoomUserEntity,String> {
     @Override
-    public void validateBeforeSave(ChatRoomUserEntity entity) {
+    public void validateBeforeSave(ImRoomUserEntity entity) {
         entity.setTop(false);
-        entity.setSendCount(0);
-        entity.setReadCount(0);
     }
 
     @Override
-    public void validateBeforeUpdate(ChatRoomUserEntity entity) {
+    public void validateBeforeUpdate(ImRoomUserEntity entity) {
 
     }
 
@@ -38,14 +36,12 @@ public class LocalChatRoomUserService extends BaseService<ChatRoomUserMapper, Ch
 
 
     @Transactional(rollbackFor = Exception.class)
-    public ChatRoomUserEntity createRoomUser(String roomId, String partId, SponsorEnum partType){
-        ChatRoomUserEntity result = new ChatRoomUserEntity();
-        result.setChatRoomId(roomId);
+    public ImRoomUserEntity createRoomUser(String roomId, String partId, SponsorEnum partType){
+        ImRoomUserEntity result = new ImRoomUserEntity();
+        result.setImRoomId(roomId);
         result.setTop(false);
-        result.setParticipantsId(partId);
-        result.setParticipantsType(partType);
-        result.setSendCount(0);
-        result.setReadCount(0);
+        result.setUserId(partId);
+        result.setUserType(partType);
         result.setLastSendTime(new Date());
         this.save(result);
         return result;

+ 0 - 28
nb-im/src/main/java/com/nb/im/ws/PubMsgInfo.java

@@ -76,32 +76,4 @@ public class PubMsgInfo implements Serializable {
             throw new RuntimeException("发送人类型不能为空");
         }
     }
-
-
-    public static void main(String[] args) {
-        PubMsgInfo payload = new PubMsgInfo();
-        payload.setMsgId(UUID.randomUUID().toString());
-        payload.setChatRoomId("123");
-        payload.setPayload("你好,医生");
-        payload.setSenderType(SponsorEnum.assist);
-        payload.setSenderId("1");
-        payload.setSenderNickname("我叫白小飞");
-        payload.setMsgType(ImMsgType.txt);
-
-        MessagingRequest pub = new MessagingRequest();
-        pub.setId("im");
-        pub.setMsgId(UUID.randomUUID().toString());
-        pub.setType(MessagingRequest.Type.pub);
-        pub.setParams(Arrays.asList("123"));
-        pub.setPayload(payload);
-
-        System.out.println(JSONUtil.toJsonStr(pub));
-
-
-        MessagingRequest sub = new MessagingRequest();
-        sub.setId("im");
-        sub.setType(MessagingRequest.Type.sub);
-        sub.setParams(Arrays.asList("123"));
-        System.out.println(JSONUtil.toJsonStr(sub));
-    }
 }

+ 4 - 2
nb-service/web-service/src/main/java/com/nb/web/service/bus/hospital/config/HospitalFinishMonitorConfigHandler.java

@@ -96,7 +96,8 @@ public class HospitalFinishMonitorConfigHandler extends AbstractHospitalConfigHa
                 .timestamp(new Date())
                 .build();
 
-        lastNoSignalFinish = new DelayMessage(Value.simple(body), HandlerConstant.CLINIC_AUTO_FINISH, DelayMessageProperties.of(TimeUnit.DAYS, config.getNoSignalInterval()));
+//        lastNoSignalFinish = new DelayMessage(Value.simple(body), HandlerConstant.CLINIC_AUTO_FINISH, DelayMessageProperties.of(TimeUnit.DAYS, config.getNoSignalInterval()));
+        lastNoSignalFinish = new DelayMessage(Value.simple(body), HandlerConstant.CLINIC_AUTO_FINISH, DelayMessageProperties.of(TimeUnit.SECONDS, config.getNoSignalInterval()));
         delayMessageManager.add(lastNoSignalFinish);
     }
 
@@ -126,7 +127,8 @@ public class HospitalFinishMonitorConfigHandler extends AbstractHospitalConfigHa
                     .tenantId(source.getTenantId())
                     .timestamp(new Date())
                     .build();
-            lastShutDownFinish = new DelayMessage(Value.simple(body), HandlerConstant.CLINIC_AUTO_FINISH, DelayMessageProperties.of(TimeUnit.DAYS, config.getShutDownInterval()));
+//            lastShutDownFinish = new DelayMessage(Value.simple(body), HandlerConstant.CLINIC_AUTO_FINISH, DelayMessageProperties.of(TimeUnit.DAYS, config.getShutDownInterval()));
+            lastShutDownFinish = new DelayMessage(Value.simple(body), HandlerConstant.CLINIC_AUTO_FINISH, DelayMessageProperties.of(TimeUnit.SECONDS, config.getShutDownInterval()));
             delayMessageManager.add(lastShutDownFinish);
         }
     }

+ 2 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/LocalBusClinicService.java

@@ -1,6 +1,7 @@
 package com.nb.web.service.bus.service;
 
 import cn.hutool.extra.spring.SpringUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -91,6 +92,7 @@ public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClini
      */
     @Transactional(rollbackFor = Exception.class)
     public void finish(List<String> clinicIds,Date finishTime, String tenantId) {
+        log.info("结束临床{}管理", JSONUtil.toJsonStr(clinicIds));
         this.update(new UpdateWrapper<BusClinicEntity>().lambda()
                 .in(BusClinicEntity::getId,clinicIds)
                 .set(BusClinicEntity::getFinished,true)