When sending the report before data has been taken from cache not from database change it to both
This commit is contained in:
parent
7b2a3887de
commit
328c6ec4e3
@ -110,6 +110,19 @@ namespace Marco.Pms.CacheHelper
|
||||
|
||||
return project;
|
||||
}
|
||||
public async Task<ProjectMongoDB?> GetProjectDetailsWithBuildingsFromCache(Guid projectId)
|
||||
{
|
||||
|
||||
// Build filter and projection to exclude large 'Buildings' list
|
||||
var filter = Builders<ProjectMongoDB>.Filter.Eq(p => p.Id, projectId.ToString());
|
||||
|
||||
// Perform query
|
||||
var project = await _projectCollection
|
||||
.Find(filter)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return project;
|
||||
}
|
||||
public async Task<List<ProjectMongoDB>> GetProjectDetailsListFromCache(List<Guid> projectIds)
|
||||
{
|
||||
List<string> stringProjectIds = projectIds.Select(p => p.ToString()).ToList();
|
||||
|
@ -370,84 +370,6 @@ namespace Marco.Pms.Services.Controllers
|
||||
200));
|
||||
}
|
||||
|
||||
//[HttpPost("add-report-mail1")]
|
||||
//public async Task<IActionResult> StoreProjectStatistics1()
|
||||
//{
|
||||
|
||||
// Guid tenantId = _userHelper.GetTenantId();
|
||||
|
||||
// // Use AsNoTracking() for read-only queries to improve performance
|
||||
// List<MailDetails> mailDetails = await _context.MailDetails
|
||||
// .AsNoTracking()
|
||||
// .Include(m => m.MailBody)
|
||||
// .Where(m => m.TenantId == tenantId)
|
||||
// .ToListAsync();
|
||||
|
||||
// var groupedMails = mailDetails
|
||||
// .GroupBy(m => new { m.ProjectId, m.MailListId })
|
||||
// .Select(g => new
|
||||
// {
|
||||
// ProjectId = g.Key.ProjectId,
|
||||
// MailListId = g.Key.MailListId,
|
||||
// Recipients = g.Select(m => m.Recipient).Distinct().ToList(),
|
||||
// MailBody = g.FirstOrDefault()?.MailBody?.Body ?? "",
|
||||
// Subject = g.FirstOrDefault()?.MailBody?.Subject ?? string.Empty,
|
||||
// })
|
||||
// .ToList();
|
||||
// foreach (var groupMail in groupedMails)
|
||||
// {
|
||||
// var projectId = groupMail.ProjectId;
|
||||
// var body = groupMail.MailBody;
|
||||
// var subject = groupMail.Subject;
|
||||
// var receivers = groupMail.Recipients;
|
||||
// if (projectId == Guid.Empty)
|
||||
// {
|
||||
// _logger.LogError("Provided empty project ID while fetching project report.");
|
||||
// return NotFound(ApiResponse<object>.ErrorResponse("Provided empty Project ID.", "Provided empty Project ID.", 400));
|
||||
// }
|
||||
|
||||
|
||||
// var statisticReport = await _reportHelper.GetDailyProjectReport(projectId, tenantId);
|
||||
|
||||
// if (statisticReport == null)
|
||||
// {
|
||||
// _logger.LogWarning("User attempted to fetch project progress for project ID {ProjectId} but not found.", projectId);
|
||||
// return NotFound(ApiResponse<object>.ErrorResponse("Project not found.", "Project not found.", 404));
|
||||
// }
|
||||
// var date = statisticReport.Date.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture);
|
||||
|
||||
// // Send Email
|
||||
// var emailBody = await _emailSender.SendProjectStatisticsEmail(new List<string>(), body, subject, statisticReport);
|
||||
// var subjectReplacements = new Dictionary<string, string>
|
||||
// {
|
||||
// {"DATE", date },
|
||||
// {"PROJECT_NAME", statisticReport.ProjectName}
|
||||
// };
|
||||
// foreach (var item in subjectReplacements)
|
||||
// {
|
||||
// subject = subject.Replace($"{{{{{item.Key}}}}}", item.Value);
|
||||
// }
|
||||
// string env = _configuration["environment:Title"] ?? string.Empty;
|
||||
// if (string.IsNullOrWhiteSpace(env))
|
||||
// {
|
||||
// subject = $"{subject}";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// subject = $"({env}) {subject}";
|
||||
// }
|
||||
// var mail = new ProjectReportEmailMongoDB
|
||||
// {
|
||||
// IsSent = false,
|
||||
// Body = emailBody,
|
||||
// Receivers = receivers,
|
||||
// Subject = subject,
|
||||
// };
|
||||
// await _cache.AddProjectReportMail(mail);
|
||||
// }
|
||||
// return Ok(ApiResponse<object>.SuccessResponse("Project Report Mail is stored in MongoDB", "Project Report Mail is stored in MongoDB", 200));
|
||||
//}
|
||||
|
||||
[HttpPost("add-report-mail")]
|
||||
public async Task<IActionResult> StoreProjectStatistics()
|
||||
{
|
||||
|
@ -200,7 +200,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occurred while adding project {ProjectId} to Cache: {Error}", project.Id, ex.Message);
|
||||
_logger.LogError(ex, "Error occurred while adding project {ProjectId} to Cache", project.Id);
|
||||
}
|
||||
}
|
||||
public async Task AddProjectDetailsList(List<Project> projects)
|
||||
@ -415,7 +415,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occurred while adding project list to Cache: {Error}", ex.Message);
|
||||
_logger.LogError(ex, "Error occurred while adding project list to Cache");
|
||||
}
|
||||
}
|
||||
public async Task<bool> UpdateProjectDetailsOnly(Project project)
|
||||
@ -429,7 +429,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while updating project {ProjectId} to Cache: {Error}", project.Id, ex.Message);
|
||||
_logger.LogError(ex, "Error occured while updating project {ProjectId} to Cache", project.Id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -442,7 +442,20 @@ namespace Marco.Pms.Services.Helpers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while getting project {ProjectId} to Cache: {Error}", ex.Message);
|
||||
_logger.LogError(ex, "Error occured while getting project {ProjectId} to Cache");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public async Task<ProjectMongoDB?> GetProjectDetailsWithBuildings(Guid projectId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _projectCache.GetProjectDetailsWithBuildingsFromCache(projectId);
|
||||
return response;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error occured while getting project {ProjectId} to Cache");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -462,7 +475,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while getting list of project details from to Cache: {Error}", ex.Message);
|
||||
_logger.LogError(ex, "Error occured while getting list of project details from to Cache");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -474,7 +487,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error occured while deleting project from to Cache: {Error}", ex.Message);
|
||||
_logger.LogError(ex, "Error occured while deleting project from to Cache");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
{
|
||||
// await _cache.GetBuildingAndFloorByWorkAreaId();
|
||||
DateTime reportDate = DateTime.UtcNow.AddDays(-1).Date;
|
||||
var project = await _cache.GetProjectDetails(projectId);
|
||||
var project = await _cache.GetProjectDetailsWithBuildings(projectId);
|
||||
if (project == null)
|
||||
{
|
||||
var projectSQL = await _context.Projects
|
||||
@ -91,7 +91,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
BuildingName = b.BuildingName,
|
||||
Description = b.Description
|
||||
}).ToList();
|
||||
if (buildings == null)
|
||||
if (!buildings.Any())
|
||||
{
|
||||
buildings = await _context.Buildings
|
||||
.Where(b => b.ProjectId == projectId)
|
||||
@ -113,7 +113,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
BuildingId = f.BuildingId,
|
||||
FloorName = f.FloorName
|
||||
})).ToList();
|
||||
if (floors == null)
|
||||
if (!floors.Any())
|
||||
{
|
||||
var buildingIds = buildings.Select(b => Guid.Parse(b.Id)).ToList();
|
||||
floors = await _context.Floor
|
||||
@ -131,7 +131,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
areas = project.Buildings
|
||||
.SelectMany(b => b.Floors)
|
||||
.SelectMany(f => f.WorkAreas).ToList();
|
||||
if (areas == null)
|
||||
if (!areas.Any())
|
||||
{
|
||||
var floorIds = floors.Select(f => Guid.Parse(f.Id)).ToList();
|
||||
areas = await _context.WorkAreas
|
||||
@ -149,7 +149,7 @@ namespace Marco.Pms.Services.Helpers
|
||||
|
||||
// fetch Work Items
|
||||
workItems = await _cache.GetWorkItemsByWorkAreaIds(areaIds);
|
||||
if (workItems == null)
|
||||
if (workItems == null || !workItems.Any())
|
||||
{
|
||||
workItems = await _context.WorkItems
|
||||
.Include(w => w.ActivityMaster)
|
||||
|
Loading…
x
Reference in New Issue
Block a user