feat: 添加访问统计模块
This commit is contained in:
17
Yi.BBS.Vue3/src/apis/accessApi.js
Normal file
17
Yi.BBS.Vue3/src/apis/accessApi.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
// 触发访问
|
||||||
|
export function access() {
|
||||||
|
return request({
|
||||||
|
url: '/access-log',
|
||||||
|
method: 'post'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 获取本周数据
|
||||||
|
export function getWeek() {
|
||||||
|
return request({
|
||||||
|
url: '/access-log/week',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -8,30 +8,34 @@ import { LineChart } from 'echarts/charts';
|
|||||||
import { UniversalTransition } from 'echarts/features';
|
import { UniversalTransition } from 'echarts/features';
|
||||||
import { CanvasRenderer } from 'echarts/renderers';
|
import { CanvasRenderer } from 'echarts/renderers';
|
||||||
import { ref ,onMounted} from 'vue';
|
import { ref ,onMounted} from 'vue';
|
||||||
|
import { getWeek } from '@/apis/accessApi.js'
|
||||||
echarts.use([GridComponent, LineChart, CanvasRenderer, UniversalTransition]);
|
echarts.use([GridComponent, LineChart, CanvasRenderer, UniversalTransition]);
|
||||||
|
|
||||||
const VisitsLineChart=ref(null);
|
const VisitsLineChart=ref(null);
|
||||||
|
|
||||||
onMounted(()=>{
|
onMounted(async()=>{
|
||||||
var myChart = echarts.init(VisitsLineChart.value, null, {
|
var myChart = echarts.init(VisitsLineChart.value, null, {
|
||||||
width: 320,
|
width: 320,
|
||||||
height: 230
|
height: 230
|
||||||
});
|
});
|
||||||
var option;
|
var option;
|
||||||
|
|
||||||
|
const response=await getWeek();
|
||||||
|
|
||||||
|
var numberData=response.data.map(x=>x.number);
|
||||||
|
|
||||||
option = {
|
option = {
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: 'category',
|
type: 'category',
|
||||||
boundaryGap: false,
|
boundaryGap: false,
|
||||||
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
type: 'value'
|
type: 'value'
|
||||||
},
|
},
|
||||||
series: [
|
series: [
|
||||||
{
|
{
|
||||||
data: [82, 93, 90, 93, 129, 133, 132],
|
data: numberData,
|
||||||
type: 'line',
|
type: 'line',
|
||||||
areaStyle: {}
|
areaStyle: {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ import AvatarInfo from '@/components/AvatarInfo.vue'
|
|||||||
import BottomInfo from '@/components/BottomInfo.vue'
|
import BottomInfo from '@/components/BottomInfo.vue'
|
||||||
import VisitsLineChart from '@/components/echars/VisitsLineChart.vue'
|
import VisitsLineChart from '@/components/echars/VisitsLineChart.vue'
|
||||||
|
|
||||||
|
import { access } from '@/apis/accessApi.js'
|
||||||
import { getList } from '@/apis/plateApi.js'
|
import { getList } from '@/apis/plateApi.js'
|
||||||
import { getList as bannerGetList } from '@/apis/bannerApi.js'
|
import { getList as bannerGetList } from '@/apis/bannerApi.js'
|
||||||
import { getList as discussGetList } from '@/apis/discussApi.js'
|
import { getList as discussGetList } from '@/apis/discussApi.js'
|
||||||
@@ -121,6 +122,7 @@ const query = reactive({
|
|||||||
|
|
||||||
//初始化
|
//初始化
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
await access();
|
||||||
plateList.value = (await getList()).data.items;
|
plateList.value = (await getList()).data.items;
|
||||||
discussList.value = (await discussGetList(query)).data.items;
|
discussList.value = (await discussGetList(query)).data.items;
|
||||||
bannerList.value = (await bannerGetList()).data.items
|
bannerList.value = (await bannerGetList()).data.items
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Yi.Furion.Application.Bbs.Services
|
||||||
|
{
|
||||||
|
public interface IAccessLogService
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Mapster;
|
||||||
|
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||||
|
using Yi.Furion.Core.Bbs.Dtos.AccessLog;
|
||||||
|
using Yi.Furion.Core.Bbs.Entities;
|
||||||
|
|
||||||
|
namespace Yi.Furion.Application.Bbs.Services.Impl
|
||||||
|
{
|
||||||
|
public class AccessLogService : IAccessLogService,IDynamicApiController
|
||||||
|
{
|
||||||
|
private readonly IRepository<AccessLogEntity> _repository;
|
||||||
|
public AccessLogService(IRepository<AccessLogEntity> repository) { _repository = repository; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 触发
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("")]
|
||||||
|
public async Task AccessAsync()
|
||||||
|
{
|
||||||
|
//可判断http重复,防止同一ip多次访问
|
||||||
|
var last = await _repository._DbQueryable.OrderByDescending(x => x.CreationTime).FirstAsync();
|
||||||
|
|
||||||
|
if (last is null || last.CreationTime.Date != DateTime.Today)
|
||||||
|
{
|
||||||
|
await _repository.InsertAsync(new AccessLogEntity());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _repository._Db.Updateable<AccessLogEntity>().SetColumns(it => it.Number == it.Number + 1).Where(it => it.Id == last.Id).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取当前周数据
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<AccessLogDto[]> GetWeekAsync()
|
||||||
|
{
|
||||||
|
var lastSeven = await _repository._DbQueryable.OrderByDescending(x => x.CreationTime).ToPageListAsync(1, 7);
|
||||||
|
|
||||||
|
return WeekTimeHandler(lastSeven.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
private AccessLogDto[] WeekTimeHandler(AccessLogEntity[] data)
|
||||||
|
{
|
||||||
|
data = data.Where(x => x.CreationTime.DayOfWeek == DateTime.Now.DayOfWeek).ToArray();
|
||||||
|
Dictionary<DayOfWeek, AccessLogDto> processedData = new Dictionary<DayOfWeek, AccessLogDto>();
|
||||||
|
|
||||||
|
// 初始化字典,将每天的数据都设为0
|
||||||
|
foreach (DayOfWeek dayOfWeek in Enum.GetValues(typeof(DayOfWeek)))
|
||||||
|
{
|
||||||
|
processedData.Add(dayOfWeek, new AccessLogDto());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理原始数据
|
||||||
|
foreach (var item in data)
|
||||||
|
{
|
||||||
|
DayOfWeek dayOfWeek = item.CreationTime.DayOfWeek;
|
||||||
|
// 如果当天有数据,则更新字典中的值为对应的Number
|
||||||
|
var sss= data.Adapt<AccessLogDto>();
|
||||||
|
processedData[dayOfWeek] = item.Adapt<AccessLogDto>();
|
||||||
|
|
||||||
|
}
|
||||||
|
return processedData.Values.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,6 +34,18 @@
|
|||||||
Label服务抽象
|
Label服务抽象
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Yi.Furion.Application.Bbs.Services.Impl.AccessLogService.AccessAsync">
|
||||||
|
<summary>
|
||||||
|
触发
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:Yi.Furion.Application.Bbs.Services.Impl.AccessLogService.GetWeekAsync">
|
||||||
|
<summary>
|
||||||
|
获取当前周数据
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="T:Yi.Furion.Application.Bbs.Services.Impl.AgreeService">
|
<member name="T:Yi.Furion.Application.Bbs.Services.Impl.AgreeService">
|
||||||
<summary>
|
<summary>
|
||||||
点赞功能
|
点赞功能
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Infrastructure.Helper;
|
||||||
|
|
||||||
|
namespace Yi.Furion.Core.Bbs.Dtos.AccessLog
|
||||||
|
{
|
||||||
|
public class AccessLogDto
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public long Number { get; set; }
|
||||||
|
public DateTime? LastModificationTime { get; set; }
|
||||||
|
public DateTime CreationTime { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SqlSugar;
|
||||||
|
using Yi.Framework.Infrastructure.Data.Auditing;
|
||||||
|
using Yi.Framework.Infrastructure.Ddd.Entities;
|
||||||
|
using Yi.Framework.Infrastructure.Helper;
|
||||||
|
|
||||||
|
namespace Yi.Furion.Core.Bbs.Entities
|
||||||
|
{
|
||||||
|
[SugarTable("AccessLog")]
|
||||||
|
public class AccessLogEntity : IEntity<long>, IHasModificationTime, IHasCreationTime
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey = true)]
|
||||||
|
public long Id { get; set; } = SnowflakeHelper.NextId;
|
||||||
|
public long Number { get; set; }
|
||||||
|
public DateTime? LastModificationTime { get; set; }
|
||||||
|
public DateTime CreationTime { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,10 +28,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Bbs\Dtos\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"Url": "DataSource=yi-sqlsugar-dev.db",
|
"Url": "DataSource=yi-sqlsugar-dev.db",
|
||||||
"DbType": "Sqlite",
|
"DbType": "Sqlite",
|
||||||
"EnabledReadWrite": false,
|
"EnabledReadWrite": false,
|
||||||
"EnabledCodeFirst": true,
|
"EnabledCodeFirst": false,
|
||||||
"ReadUrl": [
|
"ReadUrl": [
|
||||||
"DataSource=[xxxx]", //Sqlite
|
"DataSource=[xxxx]", //Sqlite
|
||||||
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]", //Mysql
|
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]", //Mysql
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
"EnabledDataSeed": true,
|
"EnabledDataSeed": false,
|
||||||
|
|
||||||
"JWTSettings": {
|
"JWTSettings": {
|
||||||
"ValidateIssuerSigningKey": true, // 是否验证密钥,bool 类型,默认true
|
"ValidateIssuerSigningKey": true, // 是否验证密钥,bool 类型,默认true
|
||||||
|
|||||||
Reference in New Issue
Block a user