|
|
@@ -0,0 +1,118 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.client.message.service.impl;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.client.entity.Message;
|
|
|
+import org.springblade.client.message.mapper.MessageMapper;
|
|
|
+import org.springblade.client.message.service.IMessageService;
|
|
|
+import org.springblade.client.vo.MessageVO;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2021-12-20
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements IMessageService
|
|
|
+{
|
|
|
+ private final IUserClient userClient;
|
|
|
+
|
|
|
+ private final ISysClient sysClient;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<MessageVO> selectMessagePage(IPage<MessageVO> page, MessageVO message) {
|
|
|
+ return page.setRecords(baseMapper.selectMessagePage(page, message));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void pushByUserId(Long userId, String Message, Integer MessageType)
|
|
|
+ {
|
|
|
+ Message message=new Message();
|
|
|
+ message.setUserId(AuthUtil.getUserId());
|
|
|
+ message.setUserName(AuthUtil.getUserName());
|
|
|
+ message.setToUserId(userId);
|
|
|
+ message.setMessageType(MessageType);
|
|
|
+ message.setMessageBody(Message);
|
|
|
+ message.setIsRead(0);
|
|
|
+ message.setTenantId(AuthUtil.getTenantId());
|
|
|
+ message.setCreateUser(AuthUtil.getUserId());
|
|
|
+ message.setCreateTime(new Date());
|
|
|
+ message.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ baseMapper.insert(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void pushByUserRole(String roleAlias, String Message, Integer MessageType)
|
|
|
+ {
|
|
|
+ //查询角色别名对应的角色id
|
|
|
+ R<Long> roleByAlias = sysClient.getRoleByAlias(roleAlias);
|
|
|
+ if(!roleByAlias.isSuccess())
|
|
|
+ {
|
|
|
+ throw new SecurityException("查询角色信息错误");
|
|
|
+ }
|
|
|
+ //角色id
|
|
|
+ Long roleId = roleByAlias.getData();
|
|
|
+ //查询此角色下全部用户
|
|
|
+ R<List<User>> listR = userClient.listUserByRoleId(roleId);
|
|
|
+ if(!listR.isSuccess())
|
|
|
+ {
|
|
|
+ throw new SecurityException("查询用户列表信息错误");
|
|
|
+ }
|
|
|
+ //查询符合条件的全部用户
|
|
|
+ List<Long> userIds = listR.getData().stream().map(User::getId).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isNotEmpty(userIds))
|
|
|
+ {
|
|
|
+ throw new SecurityException("查询用户id集合信息错误");
|
|
|
+ }
|
|
|
+ //开始推送相关人员
|
|
|
+ userIds.forEach(e->{
|
|
|
+ Message message=new Message();
|
|
|
+ message.setUserId(AuthUtil.getUserId());
|
|
|
+ message.setUserName(AuthUtil.getUserName());
|
|
|
+ message.setToUserId(e);
|
|
|
+ message.setMessageType(MessageType);
|
|
|
+ message.setMessageBody(Message);
|
|
|
+ message.setIsRead(0);
|
|
|
+ message.setTenantId(AuthUtil.getTenantId());
|
|
|
+ message.setCreateUser(AuthUtil.getUserId());
|
|
|
+ message.setCreateTime(new Date());
|
|
|
+ message.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ baseMapper.insert(message);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|