forked from github/dataease
fix: 定时查询未读消息条数错误
This commit is contained in:
parent
d2b6fe4356
commit
2fbed9fdec
@ -45,6 +45,8 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
//验证链接
|
||||
filterChainDefinitionMap.put("/api/link/validate**", ANON);
|
||||
filterChainDefinitionMap.put("/api/map/areaEntitys/**", ANON);
|
||||
//未读消息数量
|
||||
filterChainDefinitionMap.put("/api/sys_msg/unReadCount", ANON);
|
||||
|
||||
filterChainDefinitionMap.put("/**/*.json", ANON);
|
||||
filterChainDefinitionMap.put("/system/ui/**", ANON);
|
||||
|
@ -6,6 +6,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import io.dataease.base.domain.SysMsgChannel;
|
||||
import io.dataease.base.domain.SysMsgSetting;
|
||||
import io.dataease.base.domain.SysMsgType;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.commons.utils.PageUtils;
|
||||
import io.dataease.commons.utils.Pager;
|
||||
@ -21,6 +22,7 @@ import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Api(tags = "系统:消息管理")
|
||||
@ -46,6 +48,16 @@ public class MsgController {
|
||||
return listPager;
|
||||
}
|
||||
|
||||
@ApiOperation("查询未读数量")
|
||||
@PostMapping("/unReadCount")
|
||||
public Long unReadCount(@RequestBody Map<String, Long> request) {
|
||||
if(null == request || null == request.get("userId")) {
|
||||
throw new RuntimeException("缺少用户ID");
|
||||
}
|
||||
Long userId = request.get("userId");
|
||||
return sysMsgService.queryCount(userId);
|
||||
}
|
||||
|
||||
@ApiOperation("设置已读")
|
||||
@PostMapping("/setReaded/{msgId}")
|
||||
public void setReaded(@PathVariable Long msgId) {
|
||||
|
@ -105,6 +105,13 @@ public class SysMsgService {
|
||||
return msgGridDtos;
|
||||
}
|
||||
|
||||
public Long queryCount(Long userId) {
|
||||
SysMsgExample example = new SysMsgExample();
|
||||
SysMsgExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andUserIdEqualTo(userId).andStatusEqualTo(false);
|
||||
return sysMsgMapper.countByExample(example);
|
||||
}
|
||||
|
||||
public void setReaded(Long msgId) {
|
||||
SysMsg sysMsg = new SysMsg();
|
||||
sysMsg.setMsgId(msgId);
|
||||
|
@ -9,6 +9,15 @@ export function query(pageIndex, pageSize, data) {
|
||||
})
|
||||
}
|
||||
|
||||
export function unReadCount(data) {
|
||||
return request({
|
||||
url: '/api/sys_msg/unReadCount',
|
||||
method: 'post',
|
||||
loading: false,
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function updateStatus(msgId) {
|
||||
return request({
|
||||
url: '/api/sys_msg/setReaded/' + msgId,
|
||||
|
@ -53,14 +53,14 @@
|
||||
class-name="notification"
|
||||
icon-class="notification"
|
||||
/>
|
||||
<span v-if="paginationConfig.total" class="msg-number">{{ paginationConfig.total }}</span>
|
||||
<span v-if="count || paginationConfig.total" class="msg-number">{{ count || paginationConfig.total }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-popover>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { query, updateStatus } from '@/api/system/msg'
|
||||
import { query, updateStatus, unReadCount } from '@/api/system/msg'
|
||||
import { getTypeName, loadMsgTypes } from '@/utils/webMsg'
|
||||
import { mapGetters } from 'vuex'
|
||||
import bus from '@/utils/bus'
|
||||
@ -76,21 +76,30 @@ export default {
|
||||
pageSize: 5,
|
||||
total: 0
|
||||
},
|
||||
timer: null
|
||||
timer: null,
|
||||
count: 0
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters([
|
||||
'permission_routes'
|
||||
'permission_routes',
|
||||
'user'
|
||||
])
|
||||
},
|
||||
watch: {
|
||||
'visible': function(newV, oldV) {
|
||||
if (newV && !oldV) {
|
||||
this.search()
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
// 先加载消息类型
|
||||
loadMsgTypes()
|
||||
this.search()
|
||||
this.queryCount()
|
||||
// 每30s定时刷新拉取消息
|
||||
this.timer = setInterval(() => {
|
||||
this.search()
|
||||
this.queryCount()
|
||||
}, 30000)
|
||||
},
|
||||
mounted() {
|
||||
@ -105,19 +114,11 @@ export default {
|
||||
this.timer && clearInterval(this.timer)
|
||||
},
|
||||
methods: {
|
||||
// handClick(lang) {
|
||||
// console.log(lang)
|
||||
// },
|
||||
|
||||
showDetail(row) {
|
||||
const param = { ...{ msgNotification: true, msgType: row.typeId, sourceParam: row.param }}
|
||||
this.visible = false
|
||||
// if (this.$route && this.$route.name && this.$route.name.includes('panel') && row.type === 0) {
|
||||
// bus.$emit('to-msg-share', param)
|
||||
// } else if (this.$route && this.$route.name && this.$route.name.includes('dataset') && row.type === 1) {
|
||||
// bus.$emit('to-msg-dataset', param)
|
||||
// } else {
|
||||
// this.$router.push({ name: row.router, params: param })
|
||||
// }
|
||||
|
||||
if (this.$route && this.$route.name && this.$route.name === row.router) {
|
||||
// 如果当前路由就是目标路由 那么使用router.push页面不会刷新 这时候要使用事件方式
|
||||
row.callback && bus.$emit(row.callback, param)
|
||||
@ -164,6 +165,31 @@ export default {
|
||||
this.$store.commit('permission/SET_CURRENT_ROUTES', route)
|
||||
// this.setSidebarHide(route)
|
||||
},
|
||||
queryCount() {
|
||||
const token = getToken()
|
||||
|
||||
if (!token || token === 'null' || token === 'undefined' || !this.user || !this.user.userId) {
|
||||
this.timer && clearInterval(this.timer)
|
||||
const message = this.$t('login.tokenError')
|
||||
this.$alert(message, {
|
||||
confirmButtonText: this.$t('login.re_login'),
|
||||
showClose: false,
|
||||
callback: function(action, instance) {
|
||||
if (action === 'confirm') {
|
||||
this.$store.dispatch('user/logout').then(() => {
|
||||
location.reload()
|
||||
})
|
||||
}
|
||||
}.bind(this)
|
||||
})
|
||||
}
|
||||
const param = {
|
||||
userId: this.user.userId
|
||||
}
|
||||
unReadCount(param).then(res => {
|
||||
this.count = res.data
|
||||
})
|
||||
},
|
||||
search() {
|
||||
const param = {
|
||||
status: false,
|
||||
|
@ -8,7 +8,7 @@ import i18n from '@/lang'
|
||||
import { tryShowLoading, tryHideLoading } from './loading'
|
||||
import { getLinkToken, setLinkToken } from '@/utils/auth'
|
||||
// import router from '@/router'
|
||||
const interruptTokenContineUrls = Config.interruptTokenContineUrls
|
||||
// const interruptTokenContineUrls = Config.interruptTokenContineUrls
|
||||
const TokenKey = Config.TokenKey
|
||||
const RefreshTokenKey = Config.RefreshTokenKey
|
||||
const LinkTokenKey = Config.LinkTokenKey
|
||||
@ -88,7 +88,8 @@ const checkAuth = response => {
|
||||
})
|
||||
}
|
||||
// token到期后自动续命 刷新token
|
||||
if (response.headers[RefreshTokenKey] && !interruptTokenContineUrls.some(item => response.config.url.indexOf(item) >= 0)) {
|
||||
// if (response.headers[RefreshTokenKey] && !interruptTokenContineUrls.some(item => response.config.url.indexOf(item) >= 0)) {
|
||||
if (response.headers[RefreshTokenKey]) {
|
||||
const refreshToken = response.headers[RefreshTokenKey]
|
||||
store.dispatch('user/refreshToken', refreshToken)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user