- ErrorCodes.ServiceScopeRequired("133") 추가
- SpmsException.Forbidden 팩토리 추가
- ServiceCodeMiddleware 3-카테고리 라우팅 (SKIP/REQUIRED/OPTIONAL_FOR_ADMIN)
- Swagger 필터 stats/device-list X-Service-Code optional 표시
- StatsController/DeviceController GetOptionalServiceId() 적용
- IStatsService/IDeviceService/레포지토리 시그니처 long? serviceId 변경
- StatsService/DeviceService null serviceId 전체 서비스 모드 처리
Closes #199
55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using SPMS.Domain.Entities;
|
|
using SPMS.Domain.Interfaces;
|
|
|
|
namespace SPMS.Infrastructure.Persistence.Repositories;
|
|
|
|
public class DailyStatRepository : Repository<DailyStat>, IDailyStatRepository
|
|
{
|
|
public DailyStatRepository(AppDbContext context) : base(context) { }
|
|
|
|
public async Task<IReadOnlyList<DailyStat>> GetByDateRangeAsync(long? serviceId, DateOnly startDate, DateOnly endDate)
|
|
{
|
|
var query = _dbSet.Where(s => s.StatDate >= startDate && s.StatDate <= endDate);
|
|
if (serviceId.HasValue)
|
|
query = query.Where(s => s.ServiceId == serviceId.Value);
|
|
return await query.OrderByDescending(s => s.StatDate).ToListAsync();
|
|
}
|
|
|
|
public async Task<DailyStat?> GetByDateAsync(long? serviceId, DateOnly date)
|
|
{
|
|
var query = _dbSet.Where(s => s.StatDate == date);
|
|
if (serviceId.HasValue)
|
|
query = query.Where(s => s.ServiceId == serviceId.Value);
|
|
return await query.FirstOrDefaultAsync();
|
|
}
|
|
|
|
public async Task UpsertAsync(long serviceId, DateOnly statDate, int sentCnt, int successCnt, int failCnt, int openCnt)
|
|
{
|
|
var existing = await _dbSet
|
|
.FirstOrDefaultAsync(s => s.ServiceId == serviceId && s.StatDate == statDate);
|
|
|
|
if (existing != null)
|
|
{
|
|
existing.SentCnt = sentCnt;
|
|
existing.SuccessCnt = successCnt;
|
|
existing.FailCnt = failCnt;
|
|
existing.OpenCnt = openCnt;
|
|
_context.Entry(existing).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
await _dbSet.AddAsync(new DailyStat
|
|
{
|
|
ServiceId = serviceId,
|
|
StatDate = statDate,
|
|
SentCnt = sentCnt,
|
|
SuccessCnt = successCnt,
|
|
FailCnt = failCnt,
|
|
OpenCnt = openCnt,
|
|
CreatedAt = DateTime.UtcNow
|
|
});
|
|
}
|
|
}
|
|
}
|