From dadeb745b4c5262da640aabfb285025174cd83c3 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Sat, 3 Jul 2021 18:01:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E5=90=8C=E6=AD=A5=E6=B6=88=E6=81=AF=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataease/auth/service/ExtAuthService.java | 12 ++++ .../auth/service/impl/ExtAuthServiceImpl.java | 63 +++++++++++++++++++ .../base/mapper/ext/ExtAuthMapper.java | 17 +++++ .../base/mapper/ext/ExtAuthMapper.xml | 27 ++++++++ .../base/mapper/ext/ExtPanelShareMapper.xml | 6 +- .../io/dataease/commons/model/AuthURD.java | 19 ++++++ .../io/dataease/commons/utils/AuthUtils.java | 26 ++++++-- .../service/dataset/ExtractDataService.java | 29 +++++++-- .../dataease/service/message/DeMsgutil.java | 16 ++++- .../dataease/service/panel/ShareService.java | 39 ++++++++---- .../src/components/Notification/index.vue | 20 +++--- frontend/src/lang/en.js | 7 +++ frontend/src/lang/tw.js | 7 +++ frontend/src/lang/zh.js | 7 +++ frontend/src/utils/webMsg.js | 9 ++- frontend/src/views/dataset/data/ViewTable.vue | 7 +++ frontend/src/views/dataset/index.vue | 23 ++++++- frontend/src/views/msg/all.vue | 8 +-- frontend/src/views/msg/readed.vue | 11 ++-- frontend/src/views/msg/unread.vue | 11 ++-- .../src/views/panel/GrantAuth/shareTree.vue | 53 +++++++++++++--- frontend/src/views/panel/index.vue | 3 +- frontend/src/views/panel/list/PanelMain.vue | 19 ++++-- 23 files changed, 371 insertions(+), 68 deletions(-) create mode 100644 backend/src/main/java/io/dataease/auth/service/ExtAuthService.java create mode 100644 backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java create mode 100644 backend/src/main/java/io/dataease/base/mapper/ext/ExtAuthMapper.java create mode 100644 backend/src/main/java/io/dataease/base/mapper/ext/ExtAuthMapper.xml create mode 100644 backend/src/main/java/io/dataease/commons/model/AuthURD.java diff --git a/backend/src/main/java/io/dataease/auth/service/ExtAuthService.java b/backend/src/main/java/io/dataease/auth/service/ExtAuthService.java new file mode 100644 index 0000000000..7a69be10b3 --- /dev/null +++ b/backend/src/main/java/io/dataease/auth/service/ExtAuthService.java @@ -0,0 +1,12 @@ +package io.dataease.auth.service; + +import io.dataease.commons.model.AuthURD; + +import java.util.Set; + +public interface ExtAuthService { + + Set userIdsByRD(AuthURD request); + + AuthURD resourceTarget(String resourceId); +} diff --git a/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java b/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java new file mode 100644 index 0000000000..f38f9272a0 --- /dev/null +++ b/backend/src/main/java/io/dataease/auth/service/impl/ExtAuthServiceImpl.java @@ -0,0 +1,63 @@ +package io.dataease.auth.service.impl; + +import io.dataease.auth.service.ExtAuthService; +import io.dataease.base.domain.SysAuth; +import io.dataease.base.domain.SysAuthExample; +import io.dataease.base.mapper.SysAuthMapper; +import io.dataease.base.mapper.ext.ExtAuthMapper; +import io.dataease.commons.model.AuthURD; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +@Service +public class ExtAuthServiceImpl implements ExtAuthService { + + @Resource + private ExtAuthMapper extAuthMapper; + + @Resource + private SysAuthMapper sysAuthMapper; + + @Override + public Set userIdsByRD(AuthURD request) { + Set result = new HashSet<>(); + List roleIds = request.getRoleIds(); + List deptIds = request.getDeptIds(); + if (!CollectionUtils.isEmpty(roleIds)) { + result.addAll(extAuthMapper.queryUserIdWithRoleIds(roleIds)); + } + if (!CollectionUtils.isEmpty(deptIds)) { + result.addAll(extAuthMapper.queryUserIdWithDeptIds(deptIds)); + } + + return result; + } + + @Override + public AuthURD resourceTarget(String resourceId) { + AuthURD authURD = new AuthURD(); + SysAuthExample example = new SysAuthExample(); + example.createCriteria().andAuthSourceEqualTo(resourceId); + List sysAuths = sysAuthMapper.selectByExample(example); + Map> authMap = sysAuths.stream().collect(Collectors.groupingBy(SysAuth::getAuthTargetType)); + if (!CollectionUtils.isEmpty(authMap.get("user"))) { + authURD.setUserIds(authMap.get("user").stream().map(item -> Long.parseLong(item.getAuthTarget())).collect(Collectors.toList())); + } + + if (!CollectionUtils.isEmpty(authMap.get("role"))) { + authURD.setUserIds(authMap.get("role").stream().map(item -> Long.parseLong(item.getAuthTarget())).collect(Collectors.toList())); + } + + if (!CollectionUtils.isEmpty(authMap.get("dept"))) { + authURD.setUserIds(authMap.get("dept").stream().map(item -> Long.parseLong(item.getAuthTarget())).collect(Collectors.toList())); + } + return authURD; + } +} diff --git a/backend/src/main/java/io/dataease/base/mapper/ext/ExtAuthMapper.java b/backend/src/main/java/io/dataease/base/mapper/ext/ExtAuthMapper.java new file mode 100644 index 0000000000..fe7d57a75b --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/ext/ExtAuthMapper.java @@ -0,0 +1,17 @@ +package io.dataease.base.mapper.ext; + + +import org.apache.ibatis.annotations.Param; + +import java.util.List; + + +public interface ExtAuthMapper { + + List queryUserIdWithRoleIds(@Param("roleIds") List roleIds); + + List queryUserIdWithDeptIds(@Param("deptIds") List deptIds); + + + // Set queryUserIdWithRD(@Param("roleIds") List roleIds, @Param("deptIds") List deptIds); +} diff --git a/backend/src/main/java/io/dataease/base/mapper/ext/ExtAuthMapper.xml b/backend/src/main/java/io/dataease/base/mapper/ext/ExtAuthMapper.xml new file mode 100644 index 0000000000..991709ff3b --- /dev/null +++ b/backend/src/main/java/io/dataease/base/mapper/ext/ExtAuthMapper.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + diff --git a/backend/src/main/java/io/dataease/base/mapper/ext/ExtPanelShareMapper.xml b/backend/src/main/java/io/dataease/base/mapper/ext/ExtPanelShareMapper.xml index e116764758..f288f31e74 100644 --- a/backend/src/main/java/io/dataease/base/mapper/ext/ExtPanelShareMapper.xml +++ b/backend/src/main/java/io/dataease/base/mapper/ext/ExtPanelShareMapper.xml @@ -46,9 +46,9 @@ - select user_id - from sys_user + from sys_users_roles where role_id in #{roleId} @@ -56,7 +56,7 @@ - select user_id from sys_user where dept_id in diff --git a/backend/src/main/java/io/dataease/commons/model/AuthURD.java b/backend/src/main/java/io/dataease/commons/model/AuthURD.java new file mode 100644 index 0000000000..cf16b9bda6 --- /dev/null +++ b/backend/src/main/java/io/dataease/commons/model/AuthURD.java @@ -0,0 +1,19 @@ +package io.dataease.commons.model; + + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class AuthURD implements Serializable { + + private List userIds; + + private List deptIds; + + private List roleIds; + + +} diff --git a/backend/src/main/java/io/dataease/commons/utils/AuthUtils.java b/backend/src/main/java/io/dataease/commons/utils/AuthUtils.java index fbfce091f0..1462859425 100644 --- a/backend/src/main/java/io/dataease/commons/utils/AuthUtils.java +++ b/backend/src/main/java/io/dataease/commons/utils/AuthUtils.java @@ -1,23 +1,41 @@ package io.dataease.commons.utils; import io.dataease.auth.api.dto.CurrentUserDto; -import io.dataease.service.sys.SysUserService; +import io.dataease.auth.service.ExtAuthService; +import io.dataease.commons.model.AuthURD; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.Set; @Component public class AuthUtils { - private static SysUserService sysUserService; + private static ExtAuthService extAuthService; @Autowired - public void setSysUserService(SysUserService sysUserService) { - AuthUtils.sysUserService = sysUserService; + public void setExtAuthService(ExtAuthService extAuthService) { + AuthUtils.extAuthService = extAuthService; } public static CurrentUserDto getUser(){ CurrentUserDto userDto = (CurrentUserDto)SecurityUtils.getSubject().getPrincipal(); return userDto; } + + //根据组织 角色 用户 获取下属用户ID + public static Set userIdsByURD(AuthURD request) { + Set userIds = extAuthService.userIdsByRD(request); + if (!CollectionUtils.isEmpty(request.getUserIds())) { + userIds.addAll(request.getUserIds()); + } + return userIds; + } + + // 获取资源对那些人/角色/组织 有权限 + public static AuthURD authURDR(String resourceId) { + return extAuthService.resourceTarget(resourceId); + } } diff --git a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java index 0f08c76a57..b91388babe 100644 --- a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java +++ b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java @@ -10,10 +10,8 @@ import io.dataease.commons.constants.JdbcConstants; import io.dataease.commons.constants.JobStatus; import io.dataease.commons.constants.ScheduleType; import io.dataease.commons.constants.UpdateType; -import io.dataease.commons.utils.CommonBeanFactory; -import io.dataease.commons.utils.DorisTableUtils; -import io.dataease.commons.utils.HttpClientUtil; -import io.dataease.commons.utils.LogUtil; +import io.dataease.commons.model.AuthURD; +import io.dataease.commons.utils.*; import io.dataease.datasource.constants.DatasourceTypes; import io.dataease.datasource.dto.DorisConfigration; import io.dataease.datasource.dto.MysqlConfigration; @@ -27,6 +25,7 @@ import io.dataease.dto.dataset.DataTableInfoDTO; import io.dataease.exception.DataEaseException; import io.dataease.listener.util.CacheUtils; import io.dataease.provider.QueryProvider; +import io.dataease.service.message.DeMsgutil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; @@ -77,8 +76,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.InetAddress; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @Service @@ -209,10 +207,12 @@ public class ExtractDataService { extractData(datasetTable, "all_scope"); replaceTable(DorisTableUtils.dorisName(datasetTableId)); saveSucessLog(datasetTableTaskLog); + sendWebMsg(datasetTable, taskId,true); deleteFile("all_scope", datasetTableId); updateTableStatus(datasetTableId, datasetTable, JobStatus.Completed, execTime); }catch (Exception e){ saveErrorLog(datasetTableId, taskId, e); + sendWebMsg(datasetTable, taskId,false); updateTableStatus(datasetTableId, datasetTable, JobStatus.Error, null); dropDorisTable(DorisTableUtils.dorisTmpName(DorisTableUtils.dorisName(datasetTableId))); deleteFile("all_scope", datasetTableId); @@ -233,6 +233,7 @@ public class ExtractDataService { Long execTime = System.currentTimeMillis(); extractData(datasetTable, "incremental_add"); saveSucessLog(datasetTableTaskLog); + sendWebMsg(datasetTable, taskId,true); updateTableStatus(datasetTableId, datasetTable, JobStatus.Completed, execTime); }else { DatasetTableIncrementalConfig datasetTableIncrementalConfig = dataSetTableService.incrementalConfig(datasetTableId); @@ -270,12 +271,14 @@ public class ExtractDataService { extractData(datasetTable, "incremental_delete"); } saveSucessLog(datasetTableTaskLog); + sendWebMsg(datasetTable, taskId,true); deleteFile("incremental_add", datasetTableId); deleteFile("incremental_delete", datasetTableId); updateTableStatus(datasetTableId, datasetTable, JobStatus.Completed, execTime); } }catch (Exception e){ saveErrorLog(datasetTableId, taskId, e); + sendWebMsg(datasetTable, taskId,false); updateTableStatus(datasetTableId, datasetTable, JobStatus.Error, null); deleteFile("incremental_add", datasetTableId); deleteFile("incremental_delete", datasetTableId); @@ -297,6 +300,20 @@ public class ExtractDataService { } + private void sendWebMsg(DatasetTable datasetTable, String taskId, Boolean status) { + String msg = status ? "成功" : "失败"; + String id = datasetTable.getId(); + AuthURD authURD = AuthUtils.authURDR(id); + Set userIds = AuthUtils.userIdsByURD(authURD); + Gson gson = new Gson(); + userIds.forEach(userId -> { + Map param = new HashMap<>(); + param.put("tableId", id); + param.put("taskId", taskId); + DeMsgutil.sendMsg(userId, 1, "数据集【"+datasetTable.getName()+"】同步"+msg, gson.toJson(param)); + }); + } + private void updateTableStatus(String datasetTableId, DatasetTable datasetTable, JobStatus completed, Long execTime) { datasetTable.setSyncStatus(completed.name()); if(execTime != null){ diff --git a/backend/src/main/java/io/dataease/service/message/DeMsgutil.java b/backend/src/main/java/io/dataease/service/message/DeMsgutil.java index 0ffceb99ff..fc1b3d354b 100644 --- a/backend/src/main/java/io/dataease/service/message/DeMsgutil.java +++ b/backend/src/main/java/io/dataease/service/message/DeMsgutil.java @@ -16,8 +16,8 @@ public class DeMsgutil { @PostConstruct public void init() { routerMap = new HashMap<>(); - routerMap.put(0, "/panel/index"); - routerMap.put(1, "/dataset/index"); + routerMap.put(0, "panel"); + routerMap.put(1, "dataset"); } private static SysMsgService sysMsgService; @@ -38,4 +38,16 @@ public class DeMsgutil { sysMsgService.save(sysMsg); } + public static void sendMsg(Long userId, int type, String content, String param) { + SysMsg sysMsg = new SysMsg(); + sysMsg.setUserId(userId); + sysMsg.setType(type); + sysMsg.setContent(content); + sysMsg.setRouter(routerMap.get(type)); + sysMsg.setStatus(false); + sysMsg.setCreateTime(System.currentTimeMillis()); + sysMsg.setParam(param); + sysMsgService.save(sysMsg); + } + } diff --git a/backend/src/main/java/io/dataease/service/panel/ShareService.java b/backend/src/main/java/io/dataease/service/panel/ShareService.java index 3df81fedd1..c80551437c 100644 --- a/backend/src/main/java/io/dataease/service/panel/ShareService.java +++ b/backend/src/main/java/io/dataease/service/panel/ShareService.java @@ -1,12 +1,16 @@ package io.dataease.service.panel; +import com.google.gson.Gson; import io.dataease.auth.api.dto.CurrentRoleDto; import io.dataease.auth.api.dto.CurrentUserDto; +import io.dataease.base.domain.PanelGroup; import io.dataease.base.domain.PanelShare; import io.dataease.base.domain.PanelShareExample; +import io.dataease.base.mapper.PanelGroupMapper; import io.dataease.base.mapper.PanelShareMapper; import io.dataease.base.mapper.ext.ExtPanelShareMapper; import io.dataease.base.mapper.ext.query.GridExample; +import io.dataease.commons.model.AuthURD; import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.BeanUtils; import io.dataease.commons.utils.CommonBeanFactory; @@ -31,12 +35,15 @@ public class ShareService { @Autowired(required = false) private PanelShareMapper mapper; + @Resource + private PanelGroupMapper panelGroupMapper; + @Resource private ExtPanelShareMapper extPanelShareMapper; @Transactional public void save(PanelShareRequest request){ - + List panelGroups = queryGroup(request.getPanelIds()); //1.先根据仪表板删除所有已经分享的 Integer type = request.getType(); List panelIds = request.getPanelIds(); @@ -67,26 +74,32 @@ public class ShareService { // 下面是发送提醒消息逻辑 Set userIdSet = new HashSet(); + AuthURD authURD = new AuthURD(); if (type == 0) { - userIdSet.addAll(targetIds); - }else if(type == 1) { - Map> param = new HashMap<>(); - param.put("roleIds", targetIds); - List userIdList = extPanelShareMapper.queryUserIdWithRoleIds(param); - userIdSet.addAll(userIdList); - } else if (type == 2) { - Map> param = new HashMap<>(); - param.put("deptIds", targetIds); - List userIdList = extPanelShareMapper.queryUserIdWithDeptIds(param); - userIdSet.addAll(userIdList); + authURD.setUserIds(targetIds); } + if (type == 1) { + authURD.setRoleIds(targetIds); + } + if(type == 2) { + authURD.setDeptIds(targetIds); + } + userIdSet = AuthUtils.userIdsByURD(authURD); + CurrentUserDto user = AuthUtils.getUser(); + String msg = StringUtils.joinWith(",", panelGroups.stream().map(PanelGroup::getName).collect(Collectors.toList())); + Gson gson = new Gson(); userIdSet.forEach(userId -> { - DeMsgutil.sendMsg(userId, 0, "用户 [" + user.getNickName()+"] 分享了仪表板给您,请查收!"); + // DeMsgutil.sendMsg(userId, 0, user.getNickName()+" 分享了仪表板【"+msg+"】给您,请查收!"); + DeMsgutil.sendMsg(userId, 0, user.getNickName()+" 分享了仪表板【"+msg+"】给您,请查收!", gson.toJson(panelIds)); }); } + private List queryGroup(List panelIds) { + return panelIds.stream().map(panelGroupMapper::selectByPrimaryKey).collect(Collectors.toList()); + } + /** * panel_group_id建了索引 效率不会很差 * @param panel_group_id diff --git a/frontend/src/components/Notification/index.vue b/frontend/src/components/Notification/index.vue index 2a1c692936..f4ccc0e370 100644 --- a/frontend/src/components/Notification/index.vue +++ b/frontend/src/components/Notification/index.vue @@ -11,7 +11,7 @@ >
- 站内消息通知 + {{ $t('webmsg.web_msg') }}
消息规则 @@ -31,7 +31,7 @@
-
【{{ getTypeName(scope.row.type) }}】  {{ scope.row.content }}
+
【{{ $t(getTypeName(scope.row.type)) }}】  {{ scope.row.content }}
{{ scope.row.createTime | timestampFormatDate }}
- + @@ -40,6 +40,27 @@ export default { mounted() { removeClass(document.body, 'showRightPanel') }, + created() { + this.$store.dispatch('app/toggleSideBarHide', true) + let routerParam + if ((routerParam = this.$router.currentRoute.params) !== null && routerParam.msgNotification) { + // 说明是从消息通知跳转过来的 + if (routerParam.msgType === 1) { // 是数据集同步 + if (routerParam.sourceParam) { + try { + const msgParam = JSON.parse(routerParam.sourceParam) + this.param = msgParam.tableId + this.component = ViewTable + this.$nextTick(() => { + this.$refs.dynamic_component.msg2Current(routerParam.sourceParam) + }) + } catch (error) { + console.error(error) + } + } + } + } + }, methods: { switchComponent(c) { this.param = c.param diff --git a/frontend/src/views/msg/all.vue b/frontend/src/views/msg/all.vue index 997f4e1320..576a634137 100644 --- a/frontend/src/views/msg/all.vue +++ b/frontend/src/views/msg/all.vue @@ -2,7 +2,7 @@ - {{ item.label }} + {{ $t(item.label) }} @@ -104,8 +104,8 @@ export default { this.search() }, toDetail(row) { - const param = { ...{ msgNotification: true, msgType: row.type }} - this.$router.push({ name: 'panel', params: param }) + const param = { ...{ msgNotification: true, msgType: row.type, sourceParam: row.param }} + this.$router.push({ name: row.router, params: param }) this.setReaded(row) }, // 设置已读 diff --git a/frontend/src/views/msg/readed.vue b/frontend/src/views/msg/readed.vue index 552d294d2c..4683d5f533 100644 --- a/frontend/src/views/msg/readed.vue +++ b/frontend/src/views/msg/readed.vue @@ -2,7 +2,7 @@ - {{ item.label }} + {{ $t(item.label) }} @@ -87,10 +87,9 @@ export default { search() { const param = {} - + param.status = true if (this.selectType >= 0) { param.type = this.selectType - param.status = true } const { currentPage, pageSize } = this.paginationConfig query(currentPage, pageSize, param).then(response => { @@ -105,8 +104,8 @@ export default { this.search() }, toDetail(row) { - const param = { ...{ msgNotification: true, msgType: row.type }} - this.$router.push({ name: 'panel', params: param }) + const param = { ...{ msgNotification: true, msgType: row.type, sourceParam: row.param }} + this.$router.push({ name: row.router, params: param }) } } diff --git a/frontend/src/views/msg/unread.vue b/frontend/src/views/msg/unread.vue index c789e0f5ee..ee069a5921 100644 --- a/frontend/src/views/msg/unread.vue +++ b/frontend/src/views/msg/unread.vue @@ -2,7 +2,7 @@ - {{ item.label }} + {{ $t(item.label) }} @@ -87,10 +87,9 @@ export default { search() { const param = {} - + param.status = false if (this.selectType >= 0) { param.type = this.selectType - param.status = false } const { currentPage, pageSize } = this.paginationConfig query(currentPage, pageSize, param).then(response => { @@ -105,8 +104,8 @@ export default { this.search() }, toDetail(row) { - const param = { ...{ msgNotification: true, msgType: row.type }} - this.$router.push({ name: 'panel', params: param }) + const param = { ...{ msgNotification: true, msgType: row.type, sourceParam: row.param }} + this.$router.push({ name: row.router, params: param }) this.setReaded(row) }, // 设置已读 diff --git a/frontend/src/views/panel/GrantAuth/shareTree.vue b/frontend/src/views/panel/GrantAuth/shareTree.vue index acc3747ce4..f9b353538c 100644 --- a/frontend/src/views/panel/GrantAuth/shareTree.vue +++ b/frontend/src/views/panel/GrantAuth/shareTree.vue @@ -1,9 +1,9 @@