forked from github/dataease
feat: everyone默认订阅仪表板分享、任务失败消息通知
This commit is contained in:
parent
38f700f560
commit
1e33054903
@ -16,4 +16,8 @@ public class SysMsgSetting implements Serializable {
|
||||
private Boolean enable;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public Boolean match(SysMsgSetting setting) {
|
||||
return setting.getTypeId() == typeId && setting.getChannelId() == channelId;
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package io.dataease.base.mapper.ext;
|
||||
|
||||
import io.dataease.base.domain.SysMsgExample;
|
||||
import io.dataease.base.domain.SysMsgSetting;
|
||||
import io.dataease.controller.message.dto.BatchSettingRequest;
|
||||
import io.dataease.controller.message.dto.MsgGridDto;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -34,6 +36,8 @@ public interface ExtSysMsgMapper {
|
||||
})
|
||||
int batchDelete(@Param("msgIds") List<Long> msgIds);
|
||||
|
||||
int batchInsert(@Param("settings") List<SysMsgSetting> settings);
|
||||
|
||||
|
||||
List<MsgGridDto> queryGrid(SysMsgExample example);
|
||||
|
||||
|
@ -57,4 +57,13 @@
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="batchInsert" parameterType="io.dataease.base.domain.SysMsgSetting">
|
||||
INSERT INTO sys_msg_setting (user_id,type_id,channel_id,enable)
|
||||
VALUES
|
||||
<foreach collection="settings" item="setting" separator=",">
|
||||
(#{setting.userId}, #{setting.typeId}, #{setting.channelId}, #{setting.enable})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
@ -8,10 +8,7 @@ import io.dataease.base.domain.SysMsgType;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.commons.utils.PageUtils;
|
||||
import io.dataease.commons.utils.Pager;
|
||||
import io.dataease.controller.message.dto.MsgGridDto;
|
||||
import io.dataease.controller.message.dto.MsgRequest;
|
||||
import io.dataease.controller.message.dto.MsgSettingRequest;
|
||||
import io.dataease.controller.message.dto.SettingTreeNode;
|
||||
import io.dataease.controller.message.dto.*;
|
||||
import io.dataease.service.message.SysMsgService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -90,4 +87,10 @@ public class MsgController {
|
||||
List<SysMsgType> sysMsgTypes = sysMsgService.queryMsgTypes();
|
||||
return sysMsgTypes;
|
||||
}
|
||||
|
||||
@PostMapping("/batchUpdate")
|
||||
public void batchUpdate(@RequestBody BatchSettingRequest request) {
|
||||
Long userId = AuthUtils.getUser().getUserId();
|
||||
sysMsgService.batchUpdate(request, userId);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package io.dataease.controller.message.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class BatchSettingRequest implements Serializable {
|
||||
|
||||
private List<Long> typeIds;
|
||||
|
||||
private Long channelId;
|
||||
|
||||
private Boolean enable;
|
||||
}
|
@ -176,9 +176,28 @@ public class SysMsgService {
|
||||
SysMsgSettingExample example = new SysMsgSettingExample();
|
||||
example.createCriteria().andUserIdEqualTo(userId);
|
||||
List<SysMsgSetting> sysMsgSettings = sysMsgSettingMapper.selectByExample(example);
|
||||
sysMsgSettings = addDefault(sysMsgSettings);
|
||||
return sysMsgSettings;
|
||||
}
|
||||
|
||||
public List<SysMsgSetting> defaultSettings() {
|
||||
Long userId = AuthUtils.getUser().getUserId();
|
||||
SysMsgSetting sysMsgSetting1 = new SysMsgSetting();
|
||||
sysMsgSetting1.setTypeId(2L);
|
||||
sysMsgSetting1.setChannelId(1L);
|
||||
sysMsgSetting1.setEnable(true);
|
||||
// sysMsgSetting1.setUserId(userId);
|
||||
SysMsgSetting sysMsgSetting2 = new SysMsgSetting();
|
||||
sysMsgSetting2.setTypeId(6L);
|
||||
sysMsgSetting2.setChannelId(1L);
|
||||
sysMsgSetting2.setEnable(true);
|
||||
//sysMsgSetting2.setUserId(userId);
|
||||
List<SysMsgSetting> lists = new ArrayList<>();
|
||||
lists.add(sysMsgSetting1);
|
||||
lists.add(sysMsgSetting2);
|
||||
return lists;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改了订阅信息 需要清除缓存
|
||||
* @param request
|
||||
@ -200,14 +219,42 @@ public class SysMsgService {
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
SysMsgSetting sysMsgSetting = new SysMsgSetting();
|
||||
sysMsgSetting.setEnable(true);
|
||||
|
||||
sysMsgSetting.setChannelId(channelId);
|
||||
sysMsgSetting.setTypeId(typeId);
|
||||
|
||||
List<SysMsgSetting> defaultSettings = defaultSettings();
|
||||
|
||||
sysMsgSetting.setEnable(!defaultSettings.stream().anyMatch(setting -> setting.match(sysMsgSetting)));
|
||||
|
||||
sysMsgSetting.setUserId(userId);
|
||||
|
||||
sysMsgSettingMapper.insert(sysMsgSetting);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
@CacheEvict(value = SysMsgConstants.SYS_MSG_USER_SUBSCRIBE, key = "#userId")
|
||||
public void batchUpdate(BatchSettingRequest request, Long userId) {
|
||||
// 先删除
|
||||
SysMsgSettingExample example = new SysMsgSettingExample();
|
||||
example.createCriteria().andUserIdEqualTo(userId).andChannelIdEqualTo(request.getChannelId()).andTypeIdIn(request.getTypeIds());
|
||||
sysMsgSettingMapper.deleteByExample(example);
|
||||
// 再写入
|
||||
List<SysMsgSetting> settings = request.getTypeIds().stream().map(typeId -> {
|
||||
SysMsgSetting sysMsgSetting = new SysMsgSetting();
|
||||
sysMsgSetting.setUserId(userId);
|
||||
sysMsgSetting.setTypeId(typeId);
|
||||
sysMsgSetting.setChannelId(request.getChannelId());
|
||||
sysMsgSetting.setEnable(request.getEnable());
|
||||
return sysMsgSetting;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
extSysMsgMapper.batchInsert(settings);
|
||||
}
|
||||
|
||||
public void sendMsg(Long userId, Long typeId, Long channelId, String content, String param) {
|
||||
SysMsg sysMsg = new SysMsg();
|
||||
sysMsg.setUserId(userId);
|
||||
@ -229,6 +276,9 @@ public class SysMsgService {
|
||||
SysMsgSettingExample example = new SysMsgSettingExample();
|
||||
example.createCriteria().andUserIdEqualTo(userId).andEnableEqualTo(true);
|
||||
List<SysMsgSetting> sysMsgSettings = sysMsgSettingMapper.selectByExample(example);
|
||||
// 添加默认订阅
|
||||
sysMsgSettings = addDefault(sysMsgSettings);
|
||||
// sysMsgSettings.addAll(defaultSettings());
|
||||
List<SubscribeNode> resultLists = sysMsgSettings.stream().map(item -> {
|
||||
SubscribeNode subscribeNode = new SubscribeNode();
|
||||
subscribeNode.setTypeId(item.getTypeId());
|
||||
@ -238,4 +288,15 @@ public class SysMsgService {
|
||||
return resultLists;
|
||||
}
|
||||
|
||||
public List<SysMsgSetting> addDefault(List<SysMsgSetting> sourceLists) {
|
||||
List<SysMsgSetting> defaultSettings = defaultSettings();
|
||||
|
||||
defaultSettings.forEach(setting -> {
|
||||
if (!sourceLists.stream().anyMatch(item -> item.match(setting))){
|
||||
sourceLists.add(setting);
|
||||
}
|
||||
});
|
||||
return sourceLists;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,6 +59,15 @@ export function updateSetting(data) {
|
||||
})
|
||||
}
|
||||
|
||||
export function batchUpdate(data) {
|
||||
return request({
|
||||
url: '/api/sys_msg/batchUpdate',
|
||||
method: 'post',
|
||||
loading: true,
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function allTypes(data) {
|
||||
return request({
|
||||
url: '/api/sys_msg/types',
|
||||
|
@ -21,18 +21,15 @@
|
||||
<span style="margin-left: 6px">{{ $t('webmsg.' + data.name) }}</span>
|
||||
</span>
|
||||
<span @click.stop>
|
||||
<!-- <div v-if="setting_data[data.id]">
|
||||
<span v-for="channel in setting_data[data.id]" :key="channel.channelId" class="auth-span">
|
||||
<a href="javascript:;" @click="clickAuth(data.id,channel)">
|
||||
<svg-icon style="width: 25px;height: 25px" :icon-class="channel.enable ? 'lock_open' : 'lock_closed'" />
|
||||
</a>
|
||||
</span>
|
||||
</div> -->
|
||||
|
||||
<div>
|
||||
<span v-for="channel in msg_channels" :key="channel.msgChannelId" class="auth-span">
|
||||
<a href="javascript:;" @click="clickAuth(node,channel)">
|
||||
<!-- <a href="javascript:;" @click="clickAuth(node,channel)">
|
||||
<svg-icon style="width: 25px;height: 25px" :icon-class="checkBoxStatus(node, channel)?'lock_open':'lock_closed'" />
|
||||
</a>
|
||||
</a> -->
|
||||
<el-checkbox v-if="data.children && data.children.length > 0" v-model="data.check_all_map[channel.msgChannelId]" :indeterminate="data.indeterminate_map[channel.msgChannelId]" @change="parentBoxChange(node, channel)" />
|
||||
<el-checkbox v-else v-model="data.check_map[channel.msgChannelId]" @change="childBoxChange(node, channel)" />
|
||||
|
||||
</span>
|
||||
</div></span>
|
||||
</span>
|
||||
@ -44,7 +41,7 @@
|
||||
|
||||
<script>
|
||||
import LayoutContent from '@/components/business/LayoutContent'
|
||||
import { treeList, channelList, settingList, updateSetting } from '@/api/system/msg'
|
||||
import { treeList, channelList, settingList, updateSetting, batchUpdate } from '@/api/system/msg'
|
||||
export default {
|
||||
name: 'LazyTree',
|
||||
components: { LayoutContent },
|
||||
@ -78,9 +75,47 @@ export default {
|
||||
// 加载树节点数据
|
||||
loadTreeData() {
|
||||
treeList().then(res => {
|
||||
this.treeData = res.data
|
||||
const datas = res.data
|
||||
datas.forEach(data => this.formatTreeNode(data))
|
||||
this.treeData = datas
|
||||
})
|
||||
},
|
||||
formatTreeNode(node) {
|
||||
if (node.children && node.children.length > 0) {
|
||||
node.check_all_map = {}
|
||||
node.indeterminate_map = {}
|
||||
node.indeterminate_number_map = {}
|
||||
const kidSize = node.children.length
|
||||
node.children.forEach(kid => {
|
||||
this.formatTreeNode(kid)
|
||||
const isLeaf = !kid.children || kid.children.length === 0
|
||||
const tempMap = isLeaf ? kid.check_map : kid.indeterminate_map
|
||||
for (const key in tempMap) {
|
||||
if (Object.hasOwnProperty.call(tempMap, key)) {
|
||||
const element = tempMap[key]
|
||||
node.indeterminate_number_map[key] = node.indeterminate_number_map[key] || 0
|
||||
if (element) {
|
||||
node.indeterminate_number_map[key]++
|
||||
}
|
||||
|
||||
if (node.indeterminate_number_map[key] === kidSize && (isLeaf || kid.check_all_map[key])) {
|
||||
node.check_all_map[key] = true
|
||||
node.indeterminate_map[key] = false
|
||||
} else if (node.indeterminate_number_map[key] > 0) {
|
||||
node.check_all_map[key] = false
|
||||
node.indeterminate_map[key] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
node.check_map = {}
|
||||
this.msg_channels.forEach(channel => {
|
||||
node.check_map[channel.msgChannelId] = this.checkBoxStatus(node, channel)
|
||||
})
|
||||
// this.checkBoxStatus(node, )
|
||||
}
|
||||
},
|
||||
// 加载消息渠道
|
||||
loadChannelData() {
|
||||
channelList().then(res => {
|
||||
@ -105,7 +140,8 @@ export default {
|
||||
})
|
||||
},
|
||||
checkBoxStatus(node, channel) {
|
||||
const nodeId = node.data.id
|
||||
// const nodeId = node.data.id
|
||||
const nodeId = node.id
|
||||
return this.setting_data[nodeId] && this.setting_data[nodeId].some(item => item.channelId === channel.msgChannelId && item.enable)
|
||||
},
|
||||
clickAuth(node, channel) {
|
||||
@ -120,7 +156,72 @@ export default {
|
||||
})
|
||||
},
|
||||
nodeClick(data, node) {
|
||||
console.log(data)
|
||||
// console.log(data)
|
||||
},
|
||||
getAllKidId(node, ids) {
|
||||
if (node.children && node.children.length > 0) {
|
||||
node.children.forEach(item => this.getAllKidId(item, ids))
|
||||
} else {
|
||||
ids.push(node.id)
|
||||
}
|
||||
},
|
||||
parentBoxChange(node, channel) {
|
||||
const typeIds = []
|
||||
this.getAllKidId(node.data, typeIds)
|
||||
const channelId = channel.msgChannelId
|
||||
|
||||
const data = node.data
|
||||
const enable = data.check_all_map && data.check_all_map[channelId]
|
||||
node.data.check_all_map[channelId] = enable
|
||||
node.data.indeterminate_map[channelId] = false
|
||||
node.data.children.forEach(item => {
|
||||
item.check_map = item.check_map || {}
|
||||
item.check_map[channelId] = enable
|
||||
})
|
||||
|
||||
const param = {
|
||||
typeIds: typeIds,
|
||||
channelId: channelId,
|
||||
enable
|
||||
}
|
||||
// console.log(param)
|
||||
batchUpdate(param).then(res => {
|
||||
this.loadSettingData()
|
||||
})
|
||||
},
|
||||
childBoxChange(node, channel) {
|
||||
const channelId = channel.msgChannelId
|
||||
const parent = node.parent
|
||||
if (parent) {
|
||||
const data = parent.data
|
||||
const kids = data.children
|
||||
const kidSize = kids.length
|
||||
let index = 0
|
||||
kids.forEach(kid => {
|
||||
if (kid.check_map[channelId]) {
|
||||
index++
|
||||
}
|
||||
})
|
||||
if (index === kidSize) {
|
||||
node.parent.data.check_all_map[channelId] = true
|
||||
node.parent.data.indeterminate_map[channelId] = false
|
||||
} else if (index > 0) {
|
||||
node.parent.data.check_all_map[channelId] = false
|
||||
node.parent.data.indeterminate_map[channelId] = true
|
||||
} else {
|
||||
node.parent.data.check_all_map[channelId] = false
|
||||
node.parent.data.indeterminate_map[channelId] = false
|
||||
}
|
||||
// this.formatTreeNode(node.parent.data)
|
||||
}
|
||||
|
||||
const param = {
|
||||
typeId: node.data.id,
|
||||
channelId: channelId
|
||||
}
|
||||
updateSetting(param).then(res => {
|
||||
this.loadSettingData()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user