Unverified 提交 24ed0bae authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw 提交者: GitHub

Merge pull request #644 from dataease/pr@dev@fix_msg_timer_error

fix: 定时查询未读消息条数错误
...@@ -45,6 +45,8 @@ public class ShiroServiceImpl implements ShiroService { ...@@ -45,6 +45,8 @@ public class ShiroServiceImpl implements ShiroService {
//验证链接 //验证链接
filterChainDefinitionMap.put("/api/link/validate**", ANON); filterChainDefinitionMap.put("/api/link/validate**", ANON);
filterChainDefinitionMap.put("/api/map/areaEntitys/**", ANON); filterChainDefinitionMap.put("/api/map/areaEntitys/**", ANON);
//未读消息数量
filterChainDefinitionMap.put("/api/sys_msg/unReadCount", ANON);
filterChainDefinitionMap.put("/**/*.json", ANON); filterChainDefinitionMap.put("/**/*.json", ANON);
filterChainDefinitionMap.put("/system/ui/**", ANON); filterChainDefinitionMap.put("/system/ui/**", ANON);
......
...@@ -6,6 +6,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiSupport; ...@@ -6,6 +6,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.base.domain.SysMsgChannel; import io.dataease.base.domain.SysMsgChannel;
import io.dataease.base.domain.SysMsgSetting; import io.dataease.base.domain.SysMsgSetting;
import io.dataease.base.domain.SysMsgType; import io.dataease.base.domain.SysMsgType;
import io.dataease.commons.exception.DEException;
import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.PageUtils; import io.dataease.commons.utils.PageUtils;
import io.dataease.commons.utils.Pager; import io.dataease.commons.utils.Pager;
...@@ -21,6 +22,7 @@ import org.apache.commons.lang3.ObjectUtils; ...@@ -21,6 +22,7 @@ import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Api(tags = "系统:消息管理") @Api(tags = "系统:消息管理")
...@@ -46,6 +48,16 @@ public class MsgController { ...@@ -46,6 +48,16 @@ public class MsgController {
return listPager; 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("设置已读") @ApiOperation("设置已读")
@PostMapping("/setReaded/{msgId}") @PostMapping("/setReaded/{msgId}")
public void setReaded(@PathVariable Long msgId) { public void setReaded(@PathVariable Long msgId) {
......
...@@ -105,6 +105,13 @@ public class SysMsgService { ...@@ -105,6 +105,13 @@ public class SysMsgService {
return msgGridDtos; 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) { public void setReaded(Long msgId) {
SysMsg sysMsg = new SysMsg(); SysMsg sysMsg = new SysMsg();
sysMsg.setMsgId(msgId); sysMsg.setMsgId(msgId);
......
...@@ -9,6 +9,15 @@ export function query(pageIndex, pageSize, data) { ...@@ -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) { export function updateStatus(msgId) {
return request({ return request({
url: '/api/sys_msg/setReaded/' + msgId, url: '/api/sys_msg/setReaded/' + msgId,
......
...@@ -53,14 +53,14 @@ ...@@ -53,14 +53,14 @@
class-name="notification" class-name="notification"
icon-class="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>
</div> </div>
</el-popover> </el-popover>
</template> </template>
<script> <script>
import { query, updateStatus } from '@/api/system/msg' import { query, updateStatus, unReadCount } from '@/api/system/msg'
import { getTypeName, loadMsgTypes } from '@/utils/webMsg' import { getTypeName, loadMsgTypes } from '@/utils/webMsg'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import bus from '@/utils/bus' import bus from '@/utils/bus'
...@@ -76,21 +76,30 @@ export default { ...@@ -76,21 +76,30 @@ export default {
pageSize: 5, pageSize: 5,
total: 0 total: 0
}, },
timer: null timer: null,
count: 0
} }
}, },
computed: { computed: {
...mapGetters([ ...mapGetters([
'permission_routes' 'permission_routes',
'user'
]) ])
}, },
watch: {
'visible': function(newV, oldV) {
if (newV && !oldV) {
this.search()
}
}
},
created() { created() {
// 先加载消息类型 // 先加载消息类型
loadMsgTypes() loadMsgTypes()
this.search() this.queryCount()
// 每30s定时刷新拉取消息 // 每30s定时刷新拉取消息
this.timer = setInterval(() => { this.timer = setInterval(() => {
this.search() this.queryCount()
}, 30000) }, 30000)
}, },
mounted() { mounted() {
...@@ -105,19 +114,11 @@ export default { ...@@ -105,19 +114,11 @@ export default {
this.timer && clearInterval(this.timer) this.timer && clearInterval(this.timer)
}, },
methods: { methods: {
// handClick(lang) {
// console.log(lang)
// },
showDetail(row) { showDetail(row) {
const param = { ...{ msgNotification: true, msgType: row.typeId, sourceParam: row.param }} const param = { ...{ msgNotification: true, msgType: row.typeId, sourceParam: row.param }}
this.visible = false 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) { if (this.$route && this.$route.name && this.$route.name === row.router) {
// 如果当前路由就是目标路由 那么使用router.push页面不会刷新 这时候要使用事件方式 // 如果当前路由就是目标路由 那么使用router.push页面不会刷新 这时候要使用事件方式
row.callback && bus.$emit(row.callback, param) row.callback && bus.$emit(row.callback, param)
...@@ -164,6 +165,31 @@ export default { ...@@ -164,6 +165,31 @@ export default {
this.$store.commit('permission/SET_CURRENT_ROUTES', route) this.$store.commit('permission/SET_CURRENT_ROUTES', route)
// this.setSidebarHide(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() { search() {
const param = { const param = {
status: false, status: false,
......
...@@ -8,7 +8,7 @@ import i18n from '@/lang' ...@@ -8,7 +8,7 @@ import i18n from '@/lang'
import { tryShowLoading, tryHideLoading } from './loading' import { tryShowLoading, tryHideLoading } from './loading'
import { getLinkToken, setLinkToken } from '@/utils/auth' import { getLinkToken, setLinkToken } from '@/utils/auth'
// import router from '@/router' // import router from '@/router'
const interruptTokenContineUrls = Config.interruptTokenContineUrls // const interruptTokenContineUrls = Config.interruptTokenContineUrls
const TokenKey = Config.TokenKey const TokenKey = Config.TokenKey
const RefreshTokenKey = Config.RefreshTokenKey const RefreshTokenKey = Config.RefreshTokenKey
const LinkTokenKey = Config.LinkTokenKey const LinkTokenKey = Config.LinkTokenKey
...@@ -88,7 +88,8 @@ const checkAuth = response => { ...@@ -88,7 +88,8 @@ const checkAuth = response => {
}) })
} }
// token到期后自动续命 刷新token // 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] const refreshToken = response.headers[RefreshTokenKey]
store.dispatch('user/refreshToken', refreshToken) store.dispatch('user/refreshToken', refreshToken)
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论