Browse Source

消息通知

zouxuan 1 year ago
parent
commit
4bf73814d0

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/SysMessageService.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.service;
 
+import com.dayaedu.cbs.common.enums.EClientType;
 import com.dayaedu.cbs.openfeign.wrapper.message.CbsMessageWrapper;
 import com.microsvc.toolkit.common.response.template.R;
 import com.ym.mec.biz.dal.dto.SysMessageVo;

+ 47 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CbsUserServiceImpl.java

@@ -0,0 +1,47 @@
+package com.ym.mec.biz.service.impl;
+
+import com.dayaedu.cbs.common.enums.EClientType;
+import com.dayaedu.cbs.openfeign.service.CbsUserService;
+import com.dayaedu.cbs.openfeign.wrapper.user.CbsUserWrapper;
+import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.biz.dal.dao.TeacherDao;
+import com.ym.mec.biz.dal.dto.SimpleUserDto;
+import com.ym.mec.biz.service.SysUserService;
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class CbsUserServiceImpl implements CbsUserService {
+
+    @Resource
+    private TeacherDao teacherDao;
+
+    @Override
+    public List<CbsUserWrapper.User> list(CbsUserWrapper.UserQuery query) {
+        if (query == null || CollectionUtils.isEmpty(query.getUserIds())) {
+            return new ArrayList<>();
+        }
+        List<Integer> userIds = new ArrayList<>();
+        for (Long userId : query.getUserIds()) {
+            userIds.add(userId.intValue());
+        }
+        List<SimpleUserDto> userDtoList = teacherDao.getUsersSimpleInfo(userIds);
+        List<CbsUserWrapper.User> result = new ArrayList<>();
+        if (CollectionUtils.isNotEmpty(userDtoList)){
+            for (SimpleUserDto simpleUserDto : userDtoList) {
+                CbsUserWrapper.User user = new CbsUserWrapper.User();
+                user.setId(simpleUserDto.getUserId().longValue());
+                user.setUsername(query.getClientType() == null || query.getClientType() == EClientType.STUDENT ?
+                        simpleUserDto.getNickName() : simpleUserDto.getRealName());
+                user.setPhone(simpleUserDto.getPhone());
+                result.add(user);
+            }
+        }
+        return result;
+    }
+
+}

+ 37 - 13
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysMessageServiceImpl.java

@@ -103,15 +103,41 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 		query.setUserId(queryInfo.getUserId().longValue());
 		query.setStatus(ESendStatus.SUCCESSED);
 		query.setAppKey(EAppKey.GYM);
-		query.setSendMode(queryInfo.getType() == null?null:queryInfo.getType() == 1? EMessageSendMode.SMS :
-				queryInfo.getType() == 2?EMessageSendMode.EMAIL:
-						queryInfo.getType() == 3?EMessageSendMode.PUSH:EMessageSendMode.SEO);
+		query.setSendMode(getMessageSendMode(queryInfo.getType()));
 		query.setTitle(queryInfo.getTitle());
-		query.setClientId(queryInfo.getJpushType());
+		query.setClientId(getClientType(queryInfo.getJpushType()));
 		query.setReadStatus(queryInfo.getReadStatus() == null?null:queryInfo.getReadStatus()==1);
 		return messageFeignClientService.sysMessagePage(query);
 	}
 
+	private EMessageSendMode getMessageSendMode(Integer type){
+		if(type == null){
+			return null;
+		}else if(type == 1){
+			return EMessageSendMode.SMS;
+		}else if(type == 2){
+			return EMessageSendMode.EMAIL;
+		}else if(type == 3){
+			return EMessageSendMode.PUSH;
+		}else {
+			return EMessageSendMode.SEO;
+		}
+	}
+
+	public EClientType getClientType(String jpushType){
+		if(StringUtils.isEmpty(jpushType)){
+			return null;
+		}else if(StringUtils.equals(jpushType, "STUDENT")){
+			return EClientType.STUDENT;
+		}else if(StringUtils.equals(jpushType, "TEACHER")){
+			return EClientType.TEACHER;
+		}else if(StringUtils.equals(jpushType, "SCHOOL")){
+			return EClientType.SCHOOL;
+		}else {
+			return EClientType.BACKEND;
+		}
+	}
+
 	@Override
 	public boolean batchSeoMessage(Set<Integer> userIds, MessageTypeEnum messageType,String memo, Object... args) {
 		if(userIds != null){
@@ -127,9 +153,9 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 			CbsMessageWrapper.MessageParam messageParam = new CbsMessageWrapper.MessageParam();
 			messageParam.setUserId(user.getUserId().longValue());
 			messageParam.setAppKey(EAppKey.GYM);
-			messageParam.setClientType(EClientType.BACKEND.getCode());
+			messageParam.setClientType(EClientType.BACKEND);
 			messageParam.setType(messageType.getCode());
-			Map<Long, String> params = new HashMap<>();
+			Map<Long, String> params = new HashMap<>(1);
 			params.put(user.getUserId().longValue(), user.getPhone());
 			messageParam.setReceivers(params);
 			messageParam.setRealSend(!debugMode);
@@ -422,7 +448,7 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 			CbsMessageWrapper.MessageParam messageParam = new CbsMessageWrapper.MessageParam();
 			messageParam.setUserId(user.getUserId().longValue());
 			messageParam.setAppKey(EAppKey.GYM);
-			messageParam.setClientType(jpushType);
+			messageParam.setClientType(getClientType(jpushType));
 			messageParam.setType(type.getCode());
 			messageParam.setUrl(url);
 			Map<Long, String> params = new HashMap<>();
@@ -490,7 +516,7 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 			CbsMessageWrapper.MessageParam messageParam = new CbsMessageWrapper.MessageParam();
 			messageParam.setUserId(user.getUserId().longValue());
 			messageParam.setAppKey(EAppKey.GYM);
-			messageParam.setClientType(EClientType.STUDENT.getCode());
+			messageParam.setClientType(EClientType.STUDENT);
 			messageParam.setType(type.getCode());
 			messageParam.setUrl(url);
 			Map<Long, String> params = new HashMap<>();
@@ -556,12 +582,10 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 	public Map<String, Integer> queryCountOfUnread(MessageSendMode type, Integer userId, String jpushType, Integer tenantId) {
 		CbsMessageWrapper.SysMessageQuery query = new CbsMessageWrapper.SysMessageQuery();
 		query.setUserId(userId.longValue());
-		query.setClientType(jpushType);
+		query.setClientType(getClientType(jpushType));
 		query.setStatus(ESendStatus.SUCCESSED);
 		query.setAppKey(EAppKey.GYM);
-		query.setSendMode(type == null?null:type == MessageSendMode.SMS?EMessageSendMode.SMS:
-				type == MessageSendMode.EMAIL?EMessageSendMode.EMAIL:
-						type == MessageSendMode.PUSH?EMessageSendMode.PUSH:EMessageSendMode.SEO);
+		query.setSendMode(getMessageSendMode(type.getCode()));
 		query.setReadStatus(false);
 		List<CbsMessageWrapper.MessageUnreadStat> messageUnreadStats = messageFeignClientService.messageUnreadStat(query).feignData();
 //		List<Mapper> mappers = sysMessageDao.queryCountOfUnread(type, userId, jpushType, tenantId);
@@ -606,7 +630,7 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 		CbsMessageWrapper.MessageRead messageRead = new CbsMessageWrapper.MessageRead();
 		messageRead.setUserId(userId.longValue());
 		messageRead.setAppKey(EAppKey.GYM);
-		messageRead.setClientType(jpushType);
+		messageRead.setClientType(getClientType(jpushType));
 		return messageFeignClientService.batchSetRead(messageRead).feignData();
 	}
 

+ 16 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysUserServiceImpl.java

@@ -2,6 +2,7 @@ package com.ym.mec.biz.service.impl;
 
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.dayaedu.cbs.common.enums.EAppKey;
+import com.dayaedu.cbs.common.enums.EClientType;
 import com.dayaedu.cbs.openfeign.client.MessageFeignClientService;
 import com.dayaedu.cbs.openfeign.wrapper.message.CbsMessageWrapper;
 import com.google.common.collect.Lists;
@@ -155,7 +156,7 @@ public class SysUserServiceImpl implements SysUserService {
         CbsMessageWrapper.UpdateDevice updateDevice = new CbsMessageWrapper.UpdateDevice();
         updateDevice.setUserId(info.getUserId().longValue());
         updateDevice.setDeviceIds(Lists.newArrayList(info.getImDeviceId()));
-        updateDevice.setClientType(info.getClient().getCode());
+        updateDevice.setClientType(getClientType(info.getClient().getCode()));
         updateDevice.setAppKey(EAppKey.GYM);
         R<Boolean> booleanR = messageFeignClientService.updateDevice(updateDevice);
         if (booleanR != null && booleanR.feignData()) {
@@ -164,6 +165,20 @@ public class SysUserServiceImpl implements SysUserService {
         log.error("更新用户设备信息失败,userId:{}", info.getUserId());
     }
 
+    public EClientType getClientType(String jpushType){
+        if(StringUtils.isEmpty(jpushType)){
+            return null;
+        }else if(StringUtils.equals(jpushType, "STUDENT")){
+            return EClientType.STUDENT;
+        }else if(StringUtils.equals(jpushType, "TEACHER")){
+            return EClientType.TEACHER;
+        }else if(StringUtils.equals(jpushType, "SCHOOL")){
+            return EClientType.SCHOOL;
+        }else {
+            return EClientType.BACKEND;
+        }
+    }
+
     @Nullable
     private String getTeacherDeviceId(UserInfoWrapper.UpdateUser info, String teacherDeviceId) {
         Teacher teacher1 = teacherDao.get(info.getUserId());