feat: 新增请求访问统计功能
This commit is contained in:
@@ -5,6 +5,7 @@ using Quartz;
|
||||
using Volo.Abp.BackgroundWorkers.Quartz;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Caches;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
@@ -15,7 +16,7 @@ namespace Yi.Framework.Bbs.Application.Jobs;
|
||||
public class AccessLogStoreJob : QuartzBackgroundWorkerBase
|
||||
{
|
||||
private readonly ISqlSugarRepository<AccessLogAggregateRoot> _repository;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 缓存前缀
|
||||
/// </summary>
|
||||
@@ -46,10 +47,13 @@ public class AccessLogStoreJob : QuartzBackgroundWorkerBase
|
||||
_repository = repository;
|
||||
JobDetail = JobBuilder.Create<AccessLogStoreJob>().WithIdentity(nameof(AccessLogStoreJob))
|
||||
.Build();
|
||||
|
||||
//每分钟执行一次
|
||||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(AccessLogStoreJob))
|
||||
.WithCronSchedule("* * * * *")
|
||||
.WithCronSchedule("0 * * * * ?")
|
||||
.Build();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Execute(IJobExecutionContext context)
|
||||
@@ -64,9 +68,20 @@ public class AccessLogStoreJob : QuartzBackgroundWorkerBase
|
||||
var entity = await _repository._DbQueryable.Where(x => x.AccessLogType == AccessLogTypeEnum.Request)
|
||||
.Where(x => x.CreationTime.Date == DateTime.Today)
|
||||
.FirstAsync();
|
||||
// _repository._Db.Storageable(list2).ExecuteCommandAsync();
|
||||
|
||||
|
||||
if (entity is not null)
|
||||
{
|
||||
entity.Number = number+1;
|
||||
await _repository.UpdateAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _repository.InsertAsync((new AccessLogAggregateRoot() { Number = number,AccessLogType = AccessLogTypeEnum.Request}));
|
||||
}
|
||||
|
||||
//删除前一天的缓存
|
||||
await RedisClient.DelAsync($"{CacheKeyPrefix}:{AccessLogCacheConst.Key}:{DateTime.Now.Date.AddDays(-1)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,9 +55,9 @@ namespace Yi.Framework.Bbs.Application.Services
|
||||
/// </summary>
|
||||
/// <param name="AccessLogType"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<AccessLogDto>> GetListAsync([FromQuery] AccessLogTypeEnum AccessLogType)
|
||||
public async Task<List<AccessLogDto>> GetListAsync([FromQuery] AccessLogTypeEnum accessLogType)
|
||||
{
|
||||
var entities = await _repository._DbQueryable.Where(x => x.AccessLogType == AccessLogType)
|
||||
var entities = await _repository._DbQueryable.Where(x => x.AccessLogType == accessLogType)
|
||||
.Where(x => x.CreationTime >= DateTime.Now.AddMonths(-3))
|
||||
.OrderBy(x => x.CreationTime).ToListAsync();
|
||||
var output = entities.Adapt<List<AccessLogDto>>();
|
||||
@@ -73,11 +73,11 @@ namespace Yi.Framework.Bbs.Application.Services
|
||||
public async Task AccessAsync()
|
||||
{
|
||||
//可判断http重复,防止同一ip多次访问
|
||||
var last = await _repository._DbQueryable.OrderByDescending(x => x.CreationTime).FirstAsync();
|
||||
var last = await _repository._DbQueryable.Where(x=>x.AccessLogType==AccessLogTypeEnum.HomeClick).OrderByDescending(x => x.CreationTime).FirstAsync();
|
||||
|
||||
if (last is null || last.CreationTime.Date != DateTime.Today)
|
||||
{
|
||||
await _repository.InsertAsync(new AccessLogAggregateRoot());
|
||||
await _repository.InsertAsync(new AccessLogAggregateRoot(){AccessLogType=AccessLogTypeEnum.HomeClick});
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -90,10 +90,10 @@ namespace Yi.Framework.Bbs.Application.Services
|
||||
/// 获取当前周首页点击数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<AccessLogDto[]> GetWeekAsync()
|
||||
public async Task<AccessLogDto[]> GetWeekAsync([FromQuery] AccessLogTypeEnum accessLogType)
|
||||
{
|
||||
var lastSeven = await _repository._DbQueryable
|
||||
.Where(x => x.AccessLogType == AccessLogTypeEnum.HomeClick)
|
||||
.Where(x => x.AccessLogType == accessLogType)
|
||||
.OrderByDescending(x => x.CreationTime).ToPageListAsync(1, 7);
|
||||
|
||||
return WeekTimeHandler(lastSeven.ToArray());
|
||||
|
||||
@@ -288,8 +288,8 @@ namespace Yi.Abp.Web
|
||||
//swagger
|
||||
app.UseYiSwagger();
|
||||
|
||||
//流量访问统计,不启用
|
||||
//app.UseAccessLog();
|
||||
//流量访问统计,需redis支持,否则不生效
|
||||
app.UseAccessLog();
|
||||
|
||||
//请求处理
|
||||
app.UseYiApiHandlinge();
|
||||
|
||||
@@ -9,16 +9,18 @@ export function access() {
|
||||
}
|
||||
|
||||
// 获取本周数据
|
||||
export function getWeek() {
|
||||
export function getWeek(data) {
|
||||
return request({
|
||||
url: "/access-log/week",
|
||||
method: "get",
|
||||
params :data
|
||||
});
|
||||
}
|
||||
// 获取全部数据
|
||||
export function getAccessList() {
|
||||
export function getAccessList(data) {
|
||||
return request({
|
||||
url: "/access-log",
|
||||
method: "get",
|
||||
params :data
|
||||
});
|
||||
}
|
||||
|
||||
@@ -37,7 +37,14 @@ const onClickText=()=>{
|
||||
.el-divider {
|
||||
margin: 0.2rem 0;
|
||||
}
|
||||
|
||||
.VisitsLineChart /deep/ .el-card__body{
|
||||
padding: 0 20px;
|
||||
}
|
||||
.box-card-info {
|
||||
width: 100%;
|
||||
height: v-bind(height);
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@@ -52,9 +59,4 @@ const onClickText=()=>{
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
.box-card {
|
||||
width: 100%;
|
||||
height: v-bind(height);
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
<el-row :gutter="20" class="top-div">
|
||||
<el-col :span="17">
|
||||
<div class="chat-hub">
|
||||
<p @click="onClickToChatHub">点击前往-最新上线<span>《聊天室》 </span>,现已支持<span>Ai助手</span>,希望能帮助大家</p>
|
||||
<p @click="onClickToChatHub">点击前往-最新上线<span>《聊天室》 </span>,现已支持<span>Ai助手</span>,希望能帮助大家
|
||||
</p>
|
||||
</div>
|
||||
<div class="scrollbar">
|
||||
<ScrollbarInfo />
|
||||
<ScrollbarInfo/>
|
||||
</div>
|
||||
|
||||
<el-row class="left-div">
|
||||
@@ -14,23 +15,23 @@
|
||||
'padding-left': i % 3 == 1 ? 0 : 0.2 + 'rem',
|
||||
'padding-right': i % 3 == 0 ? 0 : 0.2 + 'rem',
|
||||
}">
|
||||
<PlateCard :name="i.name" :introduction="i.introduction" :id="i.id" :isPublish="i.isDisableCreateDiscuss" />
|
||||
<PlateCard :name="i.name" :introduction="i.introduction" :id="i.id" :isPublish="i.isDisableCreateDiscuss"/>
|
||||
</el-col>
|
||||
<template v-if="isDiscussFinished">
|
||||
<el-col :span="24" v-for="i in discussList" :key="i.id">
|
||||
<DisscussCard :discuss="i" />
|
||||
<DisscussCard :discuss="i"/>
|
||||
</el-col>
|
||||
</template>
|
||||
<template v-else>
|
||||
<Skeleton :isBorder="true" />
|
||||
<Skeleton :isBorder="true"/>
|
||||
</template>
|
||||
<template v-if="isAllDiscussFinished">
|
||||
<el-col :span="24" v-for="i in allDiscussList" :key="i.id">
|
||||
<DisscussCard :discuss="i" />
|
||||
<DisscussCard :discuss="i"/>
|
||||
</el-col>
|
||||
</template>
|
||||
<template v-else>
|
||||
<Skeleton :isBorder="true" />
|
||||
<Skeleton :isBorder="true"/>
|
||||
</template>
|
||||
</el-row>
|
||||
</el-col>
|
||||
@@ -42,7 +43,7 @@
|
||||
<div class="carousel-font" :style="{ color: item.color }">
|
||||
{{ item.name }}
|
||||
</div>
|
||||
<el-image style="width: 100%; height: 100%" :src="item.logo" fit="cover" />
|
||||
<el-image style="width: 100%; height: 100%" :src="item.logo" fit="cover"/>
|
||||
</el-carousel-item>
|
||||
</el-carousel>
|
||||
</el-col>
|
||||
@@ -97,23 +98,26 @@
|
||||
<el-col :span="24">
|
||||
<InfoCard header="访问统计" class="VisitsLineChart" text="全站历史统计" @onClickText="onClickAccessLog">
|
||||
<template #content>
|
||||
<VisitsLineChart :option="statisOptions" class="statisChart" />
|
||||
<p class="switch-span" @click="onClickWeekSwitch">切换</p>
|
||||
<VisitsLineChart :option="statisOptions" class="statisChart"/>
|
||||
|
||||
</template>
|
||||
</InfoCard>
|
||||
|
||||
<el-dialog v-model="accessLogDialogVisible" title="全站历史统计" width="1200px" center>
|
||||
<el-tabs v-model="accessLogTab">
|
||||
<el-tab-pane label="访问统计(近3月)" name="AccessLogChart" style="display: flex;justify-content: center;">
|
||||
<AccessLogChart :option="accessLogOptins" style="height: 600px;width: 1200px;" />
|
||||
<el-tab-pane label="访问统计(近3月)" name="AccessLogChart"
|
||||
style="display: flex;justify-content: center;">
|
||||
<AccessLogChart :option="accessLogOptins" style="height: 600px;width: 1200px;"/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="注册统计(近3月)" name="RegisterChart" style="display: flex;justify-content: center;">
|
||||
<AccessLogChart :option="registerLogOptins" style="height: 600px;width: 1200px;" />
|
||||
<el-tab-pane label="注册统计(近3月)" name="RegisterChart"
|
||||
style="display: flex;justify-content: center;">
|
||||
<AccessLogChart :option="registerLogOptins" style="height: 600px;width: 1200px;"/>
|
||||
</el-tab-pane>
|
||||
|
||||
</el-tabs>
|
||||
|
||||
|
||||
|
||||
</el-dialog>
|
||||
</el-col>
|
||||
|
||||
@@ -129,16 +133,17 @@
|
||||
|
||||
<el-col :span="24">
|
||||
<template v-if="isPointFinished">
|
||||
<InfoCard :items="pointList" header="财富排行榜" text="查看我的位置" height="400" @onClickText="onClickMoneyTop">
|
||||
<InfoCard :items="pointList" header="财富排行榜" text="查看我的位置" height="400"
|
||||
@onClickText="onClickMoneyTop">
|
||||
<template #item="temp">
|
||||
<PointsRanking :pointsData="temp" />
|
||||
<PointsRanking :pointsData="temp"/>
|
||||
</template>
|
||||
</InfoCard>
|
||||
</template>
|
||||
<template v-else>
|
||||
<InfoCard header="本月排行" text="更多">
|
||||
<template #content>
|
||||
<Skeleton />
|
||||
<Skeleton/>
|
||||
</template>
|
||||
</InfoCard>
|
||||
</template>
|
||||
@@ -148,14 +153,14 @@
|
||||
<template v-if="isFriendFinished">
|
||||
<InfoCard :items="friendList" header="推荐好友" text="更多" height="400">
|
||||
<template #item="temp">
|
||||
<RecommendFriend :friendData="temp" />
|
||||
<RecommendFriend :friendData="temp"/>
|
||||
</template>
|
||||
</InfoCard>
|
||||
</template>
|
||||
<template v-else>
|
||||
<InfoCard header="推荐好友" text="更多">
|
||||
<template #content>
|
||||
<Skeleton />
|
||||
<Skeleton/>
|
||||
</template>
|
||||
</InfoCard>
|
||||
</template>
|
||||
@@ -164,21 +169,21 @@
|
||||
<template v-if="isThemeFinished">
|
||||
<InfoCard :items="themeList" header="推荐主题" text="更多" height="400">
|
||||
<template #item="temp">
|
||||
<ThemeData :themeData="temp" />
|
||||
<ThemeData :themeData="temp"/>
|
||||
</template>
|
||||
</InfoCard>
|
||||
</template>
|
||||
<template v-else>
|
||||
<InfoCard header="推荐主题" text="更多">
|
||||
<template #content>
|
||||
<Skeleton />
|
||||
<Skeleton/>
|
||||
</template>
|
||||
</InfoCard>
|
||||
</template>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="24" style="background: transparent">
|
||||
<BottomInfo />
|
||||
<BottomInfo/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
@@ -187,8 +192,8 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, ref, reactive, computed, nextTick, watch } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import {onMounted, ref, reactive, computed, nextTick, watch} from "vue";
|
||||
import {useRouter} from "vue-router";
|
||||
import DisscussCard from "@/components/DisscussCard.vue";
|
||||
import InfoCard from "@/components/InfoCard.vue";
|
||||
import PlateCard from "@/components/PlateCard.vue";
|
||||
@@ -196,11 +201,11 @@ import ScrollbarInfo from "@/components/ScrollbarInfo.vue";
|
||||
import BottomInfo from "@/components/BottomInfo.vue";
|
||||
import VisitsLineChart from "./components/VisitsLineChart/index.vue";
|
||||
import AccessLogChart from "./components/AccessLogChart/Index.vue"
|
||||
import { access, getAccessList } from "@/apis/accessApi.js";
|
||||
import { getList } from "@/apis/plateApi.js";
|
||||
import { getList as bannerGetList } from "@/apis/bannerApi.js";
|
||||
import { getHomeDiscuss } from "@/apis/discussApi.js";
|
||||
import { getWeek } from "@/apis/accessApi.js";
|
||||
import {access, getAccessList} from "@/apis/accessApi.js";
|
||||
import {getList} from "@/apis/plateApi.js";
|
||||
import {getList as bannerGetList} from "@/apis/bannerApi.js";
|
||||
import {getHomeDiscuss} from "@/apis/discussApi.js";
|
||||
import {getWeek} from "@/apis/accessApi.js";
|
||||
import {
|
||||
getRecommendedTopic,
|
||||
getRecommendedFriend,
|
||||
@@ -208,7 +213,7 @@ import {
|
||||
getUserAnalyse,
|
||||
getRegisterAnalyse
|
||||
} from "@/apis/analyseApi.js";
|
||||
import { getList as getAllDiscussList } from "@/apis/discussApi.js";
|
||||
import {getList as getAllDiscussList} from "@/apis/discussApi.js";
|
||||
import PointsRanking from "./components/PointsRanking/index.vue";
|
||||
import RecommendFriend from "./components/RecommendFriend/index.vue";
|
||||
import ThemeData from "./components/RecommendTheme/index.vue";
|
||||
@@ -238,15 +243,15 @@ const userAnalyseInfo = ref({});
|
||||
const onlineNumber = ref(0);
|
||||
const accessLogTab = ref()
|
||||
const activeList = [
|
||||
{ name: "签到", path: "/activity/sign", icon: "Present" },
|
||||
{ name: "等级", path: "/activity/level", icon: "Ticket" },
|
||||
{ name: "大转盘", path: "/activity/lucky", icon: "Sunny" },
|
||||
{ name: "银行", path: "/activity/bank", icon: "CreditCard" },
|
||||
{name: "签到", path: "/activity/sign", icon: "Present"},
|
||||
{name: "等级", path: "/activity/level", icon: "Ticket"},
|
||||
{name: "大转盘", path: "/activity/lucky", icon: "Sunny"},
|
||||
{name: "银行", path: "/activity/bank", icon: "CreditCard"},
|
||||
|
||||
{ name: "任务", path: "/activity/sign", icon: "Memo" },
|
||||
{ name: "排行榜", path: "/money", icon: "Money" },
|
||||
{ name: "开始", path: "/start", icon: "Position" },
|
||||
{ name: "聊天室", path: "/chat", icon: "ChatRound" },
|
||||
{name: "任务", path: "/activity/sign", icon: "Memo"},
|
||||
{name: "排行榜", path: "/money", icon: "Money"},
|
||||
{name: "开始", path: "/start", icon: "Position"},
|
||||
{name: "聊天室", path: "/chat", icon: "ChatRound"},
|
||||
];
|
||||
|
||||
//主题查询参数
|
||||
@@ -256,37 +261,38 @@ const query = reactive({
|
||||
isTop: true,
|
||||
});
|
||||
|
||||
const weekQuery = reactive({accessLogType: "Request"});
|
||||
//初始化
|
||||
onMounted(async () => {
|
||||
access();
|
||||
const { data: plateData } = await getList();
|
||||
const {data: plateData} = await getList();
|
||||
plateList.value = plateData.items;
|
||||
const { data: discussData, config: discussConfig } = await getHomeDiscuss();
|
||||
const {data: discussData, config: discussConfig} = await getHomeDiscuss();
|
||||
discussList.value = discussData;
|
||||
isDiscussFinished.value = discussConfig.isFinish;
|
||||
const { data: bannerData } = await bannerGetList();
|
||||
const {data: bannerData} = await bannerGetList();
|
||||
bannerList.value = bannerData.items;
|
||||
const { data: weekData } = await getWeek();
|
||||
const {data: weekData} = await getWeek(weekQuery);
|
||||
weekList.value = weekData;
|
||||
const { data: pointData, config: pointConfig } = await getRankingPoints();
|
||||
const {data: pointData, config: pointConfig} = await getRankingPoints();
|
||||
pointList.value = pointData.items;
|
||||
isPointFinished.value = pointConfig.isFinish;
|
||||
const { data: friendData, config: friendConfig } =
|
||||
await getRecommendedFriend();
|
||||
const {data: friendData, config: friendConfig} =
|
||||
await getRecommendedFriend();
|
||||
friendList.value = friendData;
|
||||
isFriendFinished.value = friendConfig.isFinish;
|
||||
const { data: themeData, config: themeConfig } = await getRecommendedTopic();
|
||||
const {data: themeData, config: themeConfig} = await getRecommendedTopic();
|
||||
themeList.value = themeData;
|
||||
isThemeFinished.value = themeConfig.isFinish;
|
||||
const { data: allDiscussData, config: allDiscussConfig } =
|
||||
await getAllDiscussList({
|
||||
Type: 0,
|
||||
skipCount: 1,
|
||||
maxResultCount: 30,
|
||||
});
|
||||
const {data: allDiscussData, config: allDiscussConfig} =
|
||||
await getAllDiscussList({
|
||||
Type: 0,
|
||||
skipCount: 1,
|
||||
maxResultCount: 30,
|
||||
});
|
||||
isAllDiscussFinished.value = allDiscussConfig.isFinish;
|
||||
allDiscussList.value = allDiscussData.items;
|
||||
const { data: userAnalyseInfoData } = await getUserAnalyse();
|
||||
const {data: userAnalyseInfoData} = await getUserAnalyse();
|
||||
onlineNumber.value = userAnalyseInfoData.onlineNumber;
|
||||
userAnalyseInfo.value = userAnalyseInfoData;
|
||||
});
|
||||
@@ -361,29 +367,28 @@ const handleToRouter = (path) => {
|
||||
// 推送的实时人数获取
|
||||
const currentOnlineNum = computed(() => useSocketStore().getOnlineNum());
|
||||
watch(
|
||||
() => currentOnlineNum.value,
|
||||
(val) => {
|
||||
onlineNumber.value = val;
|
||||
},
|
||||
{ deep: true }
|
||||
() => currentOnlineNum.value,
|
||||
(val) => {
|
||||
onlineNumber.value = val;
|
||||
},
|
||||
{deep: true}
|
||||
);
|
||||
watch(
|
||||
() => accessLogTab.value,
|
||||
async (value) => {
|
||||
switch (value) {
|
||||
case "AccessLogChart":
|
||||
const { data } = await getAccessList();
|
||||
accessAllList.value = data;
|
||||
() => accessLogTab.value,
|
||||
async (value) => {
|
||||
switch (value) {
|
||||
case "AccessLogChart":
|
||||
const {data} = await getAccessList(weekQuery);
|
||||
accessAllList.value = data;
|
||||
|
||||
break;
|
||||
case "RegisterChart":
|
||||
const { data: registerUserListData } = await getRegisterAnalyse();
|
||||
registerAllList.value = registerUserListData;
|
||||
break;
|
||||
case "RegisterChart":
|
||||
const {data: registerUserListData} = await getRegisterAnalyse();
|
||||
registerAllList.value = registerUserListData;
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
)
|
||||
const onClickAccessLog = async () => {
|
||||
accessLogDialogVisible.value = true;
|
||||
@@ -391,6 +396,17 @@ const onClickAccessLog = async () => {
|
||||
|
||||
}
|
||||
|
||||
//切换统计开关
|
||||
const onClickWeekSwitch = async () => {
|
||||
if (weekQuery.accessLogType === "HomeClick") {
|
||||
weekQuery.accessLogType= "Request";
|
||||
} else if (weekQuery.accessLogType === "Request") {
|
||||
weekQuery.accessLogType = "HomeClick";
|
||||
}
|
||||
|
||||
const {data: weekData} = await getWeek(weekQuery);
|
||||
weekList.value = weekData;
|
||||
}
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
.home-box {
|
||||
@@ -535,10 +551,17 @@ const onClickAccessLog = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
.VisitsLineChart>>>.el-card__body {
|
||||
.VisitsLineChart > > > .el-card__body {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
|
||||
.VisitsLineChart p{
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
color: #409eff;
|
||||
cursor: pointer;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.statisChart {
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
@@ -550,6 +573,7 @@ const onClickAccessLog = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//走马灯,聊天室链接
|
||||
.chat-hub {
|
||||
background-color: #E6A23C;
|
||||
|
||||
Reference in New Issue
Block a user