forked from github/dataease
feat: 完善分享消息
This commit is contained in:
parent
0baff3bfd7
commit
8f2f6f1670
@ -46,6 +46,10 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
|
||||
|
||||
filterChainDefinitionMap.put("/system/ui/**", ANON);
|
||||
filterChainDefinitionMap.put("/**/*.js", ANON);
|
||||
filterChainDefinitionMap.put("/**/*.css", ANON);
|
||||
filterChainDefinitionMap.put("/**/*.map", ANON);
|
||||
// filterChainDefinitionMap.put("/axios.map", ANON);
|
||||
|
||||
filterChainDefinitionMap.put("/api/auth/login", ANON);
|
||||
filterChainDefinitionMap.put("/api/auth/logout", ANON);
|
||||
|
@ -12,6 +12,8 @@ public interface ExtPanelShareMapper {
|
||||
|
||||
int batchInsert(@Param("shares") List<PanelShare> shares);
|
||||
|
||||
int batchDelete(@Param("shareIds") List<Long> shareIds);
|
||||
|
||||
List<PanelSharePo> query(Map<String, Object> param);
|
||||
|
||||
List<PanelShare> queryWithResource(GridExample example);
|
||||
|
@ -16,6 +16,14 @@
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="batchDelete" parameterType="java.lang.Long" >
|
||||
delete from panel_share
|
||||
where share_id in
|
||||
<foreach collection="shareIds" item="shareId" open="(" separator="," close=")" >
|
||||
#{shareId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="query" resultMap="treeNodeMap">
|
||||
select distinct s.panel_group_id as id, g.create_by as creator, g.name
|
||||
from panel_share s
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.dataease.controller.panel.api;
|
||||
|
||||
import io.dataease.base.domain.PanelShare;
|
||||
import io.dataease.controller.request.panel.PanelShareFineDto;
|
||||
import io.dataease.controller.request.panel.PanelShareRequest;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.dto.panel.PanelShareDto;
|
||||
@ -31,5 +32,9 @@ public interface ShareApi {
|
||||
@PostMapping("/queryWithResourceId")
|
||||
List<PanelShare> queryWithResourceId(BaseGridRequest request);
|
||||
|
||||
|
||||
@ApiOperation("优化创建分享")
|
||||
@PostMapping("/fineSave")
|
||||
void fineSave(PanelShareFineDto panelShareFineDto);
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.dataease.controller.panel.server;
|
||||
|
||||
import io.dataease.base.domain.PanelShare;
|
||||
import io.dataease.controller.panel.api.ShareApi;
|
||||
import io.dataease.controller.request.panel.PanelShareFineDto;
|
||||
import io.dataease.controller.request.panel.PanelShareRequest;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.dto.panel.PanelShareDto;
|
||||
@ -32,4 +33,11 @@ public class ShareServer implements ShareApi {
|
||||
public List<PanelShare> queryWithResourceId(@RequestBody BaseGridRequest request) {
|
||||
return shareService.queryWithResource(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fineSave(@RequestBody PanelShareFineDto panelShareFineDto) {
|
||||
shareService.fineSave(panelShareFineDto);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
package io.dataease.controller.request.panel;
|
||||
|
||||
import io.dataease.commons.model.AuthURD;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
@Data
|
||||
public class PanelShareFineDto implements Serializable {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -792964171742204428L;
|
||||
|
||||
private String resourceId;
|
||||
|
||||
private AuthURD authURD;
|
||||
}
|
@ -14,12 +14,15 @@ import io.dataease.commons.model.AuthURD;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.commons.utils.CommonBeanFactory;
|
||||
import io.dataease.controller.request.panel.PanelShareFineDto;
|
||||
import io.dataease.controller.request.panel.PanelShareRequest;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.dto.panel.PanelShareDto;
|
||||
import io.dataease.dto.panel.PanelSharePo;
|
||||
import io.dataease.service.message.DeMsgutil;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -27,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
@Service
|
||||
@ -41,6 +45,176 @@ public class ShareService {
|
||||
@Resource
|
||||
private ExtPanelShareMapper extPanelShareMapper;
|
||||
|
||||
/**
|
||||
* 1.查询当前节点已经分享给了哪些目标
|
||||
* 2.过滤出新增的目标
|
||||
* 3.过滤出减少的目标
|
||||
* 4.批量删除
|
||||
* 5.批量新增
|
||||
* 6.发送取消分享消息
|
||||
* 7.发送新增分享消息
|
||||
* @param panelShareFineDto
|
||||
*/
|
||||
@Transactional
|
||||
public void fineSave(PanelShareFineDto panelShareFineDto) {
|
||||
|
||||
List<PanelShare> addShares = new ArrayList<>();//新增的分享
|
||||
List<Long> redShareIdLists = new ArrayList<>();//取消的分享
|
||||
|
||||
String panelGroupId = panelShareFineDto.getResourceId();
|
||||
AuthURD authURD = panelShareFineDto.getAuthURD();
|
||||
AuthURD sharedAuthURD = new AuthURD();
|
||||
AuthURD addAuthURD = new AuthURD();
|
||||
|
||||
|
||||
|
||||
Map<Integer, List<Long>> authURDMap = new HashMap<>();
|
||||
authURDMap.put(0, authURD.getUserIds());
|
||||
authURDMap.put(1, authURD.getRoleIds());
|
||||
authURDMap.put(2, authURD.getDeptIds());
|
||||
|
||||
PanelShareExample example = new PanelShareExample();
|
||||
example.createCriteria().andPanelGroupIdEqualTo(panelGroupId);
|
||||
List<PanelShare> panelShares = mapper.selectByExample(example);
|
||||
/*if (CollectionUtils.isEmpty(panelShares)) {
|
||||
return;
|
||||
}*/
|
||||
Map<Integer, List<TempShareNode>> typeSharedMap = panelShares.stream().map(this::convertNode).collect(Collectors.groupingBy(TempShareNode::getType));
|
||||
|
||||
for (Map.Entry<Integer, List<Long>> entry : authURDMap.entrySet()) {
|
||||
Integer key = entry.getKey();
|
||||
List<TempShareNode> shareNodes = null;
|
||||
if (null == typeSharedMap || null == typeSharedMap.get(key)) {
|
||||
shareNodes = new ArrayList<>();
|
||||
}else{
|
||||
shareNodes = typeSharedMap.get(key);
|
||||
}
|
||||
|
||||
if (null != authURDMap.get(key)) {
|
||||
Map<String, Object> dataMap = filterData(authURDMap.get(key), shareNodes);
|
||||
List<Long> newIds = (List<Long>)dataMap.get("add");
|
||||
for (int i = 0; i < newIds.size(); i++) {
|
||||
Long id = newIds.get(i);
|
||||
PanelShare share = new PanelShare();
|
||||
share.setCreateTime(System.currentTimeMillis());
|
||||
share.setPanelGroupId(panelGroupId);
|
||||
share.setTargetId(id);
|
||||
share.setType(key);
|
||||
addShares.add(share);
|
||||
}
|
||||
List<TempShareNode> redNodes = (List<TempShareNode>)dataMap.get("red");
|
||||
List<Long> redIds = redNodes.stream().map(TempShareNode::getShareId).distinct().collect(Collectors.toList());
|
||||
|
||||
redShareIdLists.addAll(redIds);
|
||||
buildRedAuthURD(key, redNodes.stream().map(TempShareNode::getTargetId).distinct().collect(Collectors.toList()) , sharedAuthURD);
|
||||
buildRedAuthURD(key, newIds, addAuthURD);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(redShareIdLists)){
|
||||
extPanelShareMapper.batchDelete(redShareIdLists);
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(addShares)){
|
||||
extPanelShareMapper.batchInsert(addShares);
|
||||
}
|
||||
|
||||
// 以上是业务代码
|
||||
// 下面是消息发送
|
||||
Set<Long> addUserIdSet = AuthUtils.userIdsByURD(addAuthURD);
|
||||
Set<Long> redUserIdSet = AuthUtils.userIdsByURD(sharedAuthURD);
|
||||
|
||||
|
||||
PanelGroup panelGroup = panelGroupMapper.selectByPrimaryKey(panelGroupId);;
|
||||
CurrentUserDto user = AuthUtils.getUser();
|
||||
Gson gson = new Gson();
|
||||
String msg = panelGroup.getName();
|
||||
|
||||
|
||||
List<String> msgParam = new ArrayList<String>();
|
||||
msgParam.add(panelGroupId);
|
||||
addUserIdSet.forEach(userId -> {
|
||||
if (!redUserIdSet.contains(userId)){
|
||||
DeMsgutil.sendMsg(userId, 0, user.getNickName()+" 分享了仪表板【"+msg+"】,请查收!", gson.toJson(msgParam));
|
||||
}
|
||||
});
|
||||
|
||||
redUserIdSet.forEach(userId -> {
|
||||
if (!addUserIdSet.contains(userId)){
|
||||
DeMsgutil.sendMsg(userId, 0, user.getNickName()+" 取消分享了仪表板【"+msg+"】,请查收!", gson.toJson(msgParam));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void buildRedAuthURD(Integer type, List<Long> redIds , AuthURD authURD) {
|
||||
if (type == 0) {
|
||||
authURD.setUserIds(redIds);
|
||||
}
|
||||
if (type == 1) {
|
||||
authURD.setRoleIds(redIds);
|
||||
}
|
||||
if (type == 2) {
|
||||
authURD.setDeptIds(redIds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param newTargets 新的分享目标
|
||||
* @param shareNodes 已景分享目标
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Object> filterData(List<Long> newTargets, List<TempShareNode> shareNodes) {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
/*if (null == newTargets) {
|
||||
result.put("add", new ArrayList<>());
|
||||
result.put("red", new ArrayList<>());
|
||||
return result;
|
||||
}*/
|
||||
List<Long> newUserIds = new ArrayList<>();
|
||||
for (int i = 0; i < newTargets.size(); i++) {
|
||||
Long newTargetId = newTargets.get(i);
|
||||
Boolean isNew = true;
|
||||
for (int j = 0; j < shareNodes.size(); j++) {
|
||||
TempShareNode shareNode = shareNodes.get(j);
|
||||
Long sharedId = shareNode.getTargetId();
|
||||
if (newTargetId == sharedId) {
|
||||
shareNode.setMatched(true); // 已分享 重新命中
|
||||
isNew = false;
|
||||
}
|
||||
}
|
||||
if (isNew) {
|
||||
// 获取新增的
|
||||
newUserIds.add(newTargetId);
|
||||
}
|
||||
}
|
||||
//获取需要取消分享的
|
||||
List<TempShareNode> missNodes = shareNodes.stream().filter(item -> !item.getMatched()).collect(Collectors.toList());
|
||||
result.put("add", newUserIds);
|
||||
result.put("red", missNodes);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Data
|
||||
private class TempShareNode {
|
||||
private Long shareId;
|
||||
private Integer type;
|
||||
private Long targetId;
|
||||
private Boolean matched = false;
|
||||
|
||||
public boolean targetMatch(Long tid) {
|
||||
return targetId == tid;
|
||||
}
|
||||
}
|
||||
|
||||
private TempShareNode convertNode(PanelShare panelShare) {
|
||||
return BeanUtils.copyBean(new TempShareNode(), panelShare);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void save(PanelShareRequest request){
|
||||
List<PanelGroup> panelGroups = queryGroup(request.getPanelIds());
|
||||
|
@ -27,3 +27,12 @@ export function loadTree(data) {
|
||||
})
|
||||
}
|
||||
|
||||
export function fineSave(data) {
|
||||
return request({
|
||||
url: '/api/share/fineSave',
|
||||
method: 'post',
|
||||
loading: true,
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ export function query(pageIndex, pageSize, data) {
|
||||
return request({
|
||||
url: '/api/sys_msg/list/' + pageIndex + '/' + pageSize,
|
||||
method: 'post',
|
||||
loading: true,
|
||||
loading: false,
|
||||
data
|
||||
})
|
||||
}
|
||||
|
@ -73,7 +73,8 @@ export default {
|
||||
currentPage: 1,
|
||||
pageSize: 5,
|
||||
total: 0
|
||||
}
|
||||
},
|
||||
timer: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -82,14 +83,20 @@ export default {
|
||||
created() {
|
||||
this.search()
|
||||
// 每30s定时刷新拉取消息
|
||||
setInterval(() => {
|
||||
this.timer = setInterval(() => {
|
||||
this.search()
|
||||
}, 30000)
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.timer && clearInterval(this.timer)
|
||||
},
|
||||
destroyed() {
|
||||
this.timer && clearInterval(this.timer)
|
||||
},
|
||||
methods: {
|
||||
handClick(lang) {
|
||||
console.log(lang)
|
||||
},
|
||||
// handClick(lang) {
|
||||
// console.log(lang)
|
||||
// },
|
||||
showDetail(row) {
|
||||
const param = { ...{ msgNotification: true, msgType: row.type, sourceParam: row.param }}
|
||||
this.visible = false
|
||||
|
@ -76,7 +76,7 @@ export const loadMenus = (next, to) => {
|
||||
buildMenus().then(res => {
|
||||
const filterDatas = filterRouter(res.data)
|
||||
const asyncRouter = filterAsyncRouter(filterDatas)
|
||||
addMsgMenu(asyncRouter)
|
||||
// addMsgMenu(asyncRouter)
|
||||
asyncRouter.push({ path: '*', redirect: '/404', hidden: true })
|
||||
store.dispatch('permission/GenerateRoutes', asyncRouter).then(() => { // 存储路由
|
||||
router.addRoutes(asyncRouter)
|
||||
|
@ -158,6 +158,12 @@ export default {
|
||||
return roots
|
||||
},
|
||||
|
||||
getSelected() {
|
||||
return {
|
||||
deptIds: this.$refs.table.store.states.selection.map(item => item.deptId)
|
||||
}
|
||||
},
|
||||
|
||||
save(msg) {
|
||||
const rows = this.$refs.table.store.states.selection
|
||||
const request = this.buildRequest(rows)
|
||||
|
@ -26,6 +26,7 @@
|
||||
import GrantDept from './dept'
|
||||
import GrantRole from './role'
|
||||
import GrantUser from './user'
|
||||
import { fineSave } from '@/api/panel/share'
|
||||
export default {
|
||||
name: 'GrantAuth',
|
||||
components: { GrantDept, GrantRole, GrantUser },
|
||||
@ -58,8 +59,27 @@ export default {
|
||||
this.showSearchInput = false
|
||||
},
|
||||
save() {
|
||||
this.$refs[this.activeName].save(this.$t('commons.share_success'))
|
||||
this.$emit('close-grant', 0)
|
||||
// this.$refs[this.activeName].save(this.$t('commons.share_success'))
|
||||
// this.$emit('close-grant', 0)
|
||||
this.fineSave()
|
||||
},
|
||||
fineSave() {
|
||||
let targetDto = {}
|
||||
this.tabNames.forEach(tabName => {
|
||||
if (this.$refs[tabName] && this.$refs[tabName].getSelected) {
|
||||
const tempSelected = this.$refs[tabName].getSelected()
|
||||
targetDto = Object.assign({}, targetDto, tempSelected)
|
||||
}
|
||||
})
|
||||
const resourceId = this.resourceId
|
||||
const param = {
|
||||
resourceId,
|
||||
authURD: targetDto
|
||||
}
|
||||
fineSave(param).then(res => {
|
||||
this.$success(this.$t('commons.share_success'))
|
||||
this.$emit('close-grant', 0)
|
||||
})
|
||||
},
|
||||
cancel() {
|
||||
this.$refs[this.activeName].cancel()
|
||||
|
@ -78,6 +78,13 @@ export default {
|
||||
this.setCheckNodes()
|
||||
})
|
||||
},
|
||||
|
||||
getSelected() {
|
||||
return {
|
||||
roleIds: this.$refs.table.store.states.selection.map(item => item.roleId)
|
||||
}
|
||||
},
|
||||
|
||||
save(msg) {
|
||||
const rows = this.$refs.table.store.states.selection
|
||||
const request = this.buildRequest(rows)
|
||||
|
@ -86,6 +86,12 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
getSelected() {
|
||||
return {
|
||||
userIds: this.$refs.table.store.states.selection.map(item => item.userId)
|
||||
}
|
||||
},
|
||||
|
||||
save(msg) {
|
||||
const rows = this.$refs.table.store.states.selection
|
||||
const request = this.buildRequest(rows)
|
||||
|
@ -114,7 +114,7 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
this.queryTreeDatas()
|
||||
console.log('permis:' + JSON.stringify(this.$store.getters.permissions))
|
||||
// console.log('permis:' + JSON.stringify(this.$store.getters.permissions))
|
||||
},
|
||||
methods: {
|
||||
filterNode(value, data) {
|
||||
@ -154,7 +154,7 @@ export default {
|
||||
return 'MySQL'
|
||||
} else if (type === 'sqlServer') {
|
||||
return 'SQL Server'
|
||||
}else if (type === 'oracle') {
|
||||
} else if (type === 'oracle') {
|
||||
return 'Oracle'
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user