Organization_Management #142
@ -8,6 +8,7 @@
|
|||||||
public List<Guid>? WorkCategoryIds { get; set; }
|
public List<Guid>? WorkCategoryIds { get; set; }
|
||||||
public List<Guid>? ActivityIds { get; set; }
|
public List<Guid>? ActivityIds { get; set; }
|
||||||
public List<Guid>? UploadedByIds { get; set; }
|
public List<Guid>? UploadedByIds { get; set; }
|
||||||
|
public List<Guid>? ServiceIds { get; set; }
|
||||||
public DateTime? StartDate { get; set; }
|
public DateTime? StartDate { get; set; }
|
||||||
public DateTime? EndDate { get; set; }
|
public DateTime? EndDate { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
|
|
||||||
[HttpGet("images/{projectId}")]
|
[HttpGet("images/{projectId}")]
|
||||||
|
|
||||||
public async Task<IActionResult> GetImageList(Guid projectId, [FromQuery] string? filter, [FromQuery] int? pageNumber = 1, [FromQuery] int? pageSize = 10)
|
public async Task<IActionResult> GetImageList(Guid projectId, [FromQuery] string? filter, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10)
|
||||||
{
|
{
|
||||||
_logger.LogInfo("[GetImageList] Called by Employee for ProjectId: {ProjectId}", projectId);
|
_logger.LogInfo("[GetImageList] Called by Employee for ProjectId: {ProjectId}", projectId);
|
||||||
|
|
||||||
@ -79,6 +79,28 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var taskQuery = _context.TaskAllocations
|
||||||
|
.Include(t => t.Employee)
|
||||||
|
.Include(t => t.ReportedBy)
|
||||||
|
.Include(t => t.ApprovedBy)
|
||||||
|
.Include(t => t.WorkStatus)
|
||||||
|
.Include(t => t.WorkItem)
|
||||||
|
.ThenInclude(wi => wi!.ActivityMaster)
|
||||||
|
.ThenInclude(a => a!.ActivityGroup)
|
||||||
|
.ThenInclude(ag => ag!.Service)
|
||||||
|
.Include(t => t.WorkItem)
|
||||||
|
.ThenInclude(wi => wi!.WorkArea)
|
||||||
|
.ThenInclude(wa => wa!.Floor)
|
||||||
|
.ThenInclude(f => f!.Building)
|
||||||
|
.Include(t => t.WorkItem)
|
||||||
|
.ThenInclude(wi => wi!.WorkCategoryMaster)
|
||||||
|
.Where(t => t.WorkItem != null &&
|
||||||
|
t.WorkItem.WorkArea != null &&
|
||||||
|
t.WorkItem.WorkArea.Floor != null &&
|
||||||
|
t.WorkItem.WorkArea.Floor.Building != null &&
|
||||||
|
t.WorkItem.WorkArea.Floor.Building.ProjectId != projectId &&
|
||||||
|
t.TenantId == tenantId);
|
||||||
|
|
||||||
// Step 4: Extract filter values
|
// Step 4: Extract filter values
|
||||||
var buildingIds = imageFilter?.BuildingIds;
|
var buildingIds = imageFilter?.BuildingIds;
|
||||||
var floorIds = imageFilter?.FloorIds;
|
var floorIds = imageFilter?.FloorIds;
|
||||||
@ -88,71 +110,60 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
var startDate = imageFilter?.StartDate;
|
var startDate = imageFilter?.StartDate;
|
||||||
var endDate = imageFilter?.EndDate;
|
var endDate = imageFilter?.EndDate;
|
||||||
var uploadedByIds = imageFilter?.UploadedByIds;
|
var uploadedByIds = imageFilter?.UploadedByIds;
|
||||||
|
var serviceIds = imageFilter?.ServiceIds;
|
||||||
|
|
||||||
// Step 5: Fetch building > floor > area > work item hierarchy
|
if (buildingIds?.Any() ?? false)
|
||||||
List<Building>? buildings = null;
|
|
||||||
List<Floor>? floors = null;
|
|
||||||
List<WorkArea>? workAreas = null;
|
|
||||||
|
|
||||||
if (buildingIds != null && buildingIds.Count > 0)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
buildings = await _context.Buildings
|
taskQuery = taskQuery
|
||||||
.Where(b => b.ProjectId == projectId && buildingIds.Contains(b.Id))
|
.Where(t => t.WorkItem != null &&
|
||||||
.ToListAsync();
|
t.WorkItem.WorkArea != null &&
|
||||||
}
|
t.WorkItem.WorkArea.Floor != null &&
|
||||||
else
|
buildingIds.Contains(t.WorkItem.WorkArea.Floor.BuildingId));
|
||||||
{
|
|
||||||
buildings = await _context.Buildings
|
|
||||||
.Where(b => b.ProjectId == projectId)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
buildingIds = buildings.Select(b => b.Id).ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (floorIds != null && floorIds.Count > 0)
|
if (floorIds?.Any() ?? false)
|
||||||
{
|
{
|
||||||
floors = await _context.Floor
|
taskQuery = taskQuery
|
||||||
.Where(f => buildingIds.Contains(f.BuildingId) && floorIds.Contains(f.Id))
|
.Where(t => t.WorkItem != null &&
|
||||||
.ToListAsync();
|
t.WorkItem.WorkArea != null &&
|
||||||
}
|
floorIds.Contains(t.WorkItem.WorkArea.FloorId));
|
||||||
else
|
|
||||||
{
|
|
||||||
floors = await _context.Floor
|
|
||||||
.Where(f => buildingIds.Contains(f.BuildingId))
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
floorIds = floors.Select(f => f.Id).ToList();
|
|
||||||
}
|
|
||||||
if (workAreaIds != null && workAreaIds.Count > 0)
|
|
||||||
{
|
|
||||||
workAreas = await _context.WorkAreas
|
|
||||||
.Where(wa => floorIds.Contains(wa.FloorId) && workAreaIds.Contains(wa.Id))
|
|
||||||
.ToListAsync();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
workAreas = await _context.WorkAreas
|
|
||||||
.Where(wa => floorIds.Contains(wa.FloorId))
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
workAreaIds = workAreas.Select(wa => wa.Id).ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var workItemsQuery = _context.WorkItems.Include(w => w.ActivityMaster).Include(w => w.WorkCategoryMaster)
|
if (workAreaIds?.Any() ?? false)
|
||||||
.Where(wi => workAreaIds.Contains(wi.WorkAreaId));
|
{
|
||||||
if (activityIds?.Any() == true) workItemsQuery = workItemsQuery.Where(wi => activityIds.Contains(wi.ActivityId));
|
taskQuery = taskQuery
|
||||||
|
.Where(t => t.WorkItem != null &&
|
||||||
|
workAreaIds.Contains(t.WorkItem.WorkAreaId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (activityIds?.Any() == true)
|
||||||
|
{
|
||||||
|
taskQuery = taskQuery
|
||||||
|
.Where(t => t.WorkItem != null &&
|
||||||
|
activityIds.Contains(t.WorkItem.ActivityId));
|
||||||
|
}
|
||||||
|
|
||||||
if (workCategoryIds?.Any() == true)
|
if (workCategoryIds?.Any() == true)
|
||||||
{
|
{
|
||||||
workItemsQuery = workItemsQuery.Where(wi => wi.WorkCategoryMaster != null && workCategoryIds.Contains(wi.WorkCategoryMaster.Id));
|
taskQuery = taskQuery
|
||||||
|
.Where(t => t.WorkItem != null &&
|
||||||
|
t.WorkItem.WorkCategoryId.HasValue &&
|
||||||
|
workCategoryIds.Contains(t.WorkItem.WorkCategoryId.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serviceIds?.Any() ?? false)
|
||||||
|
{
|
||||||
|
taskQuery = taskQuery.Where(t => t.WorkItem != null &&
|
||||||
|
t.WorkItem.ActivityMaster != null &&
|
||||||
|
t.WorkItem.ActivityMaster.ActivityGroup != null &&
|
||||||
|
serviceIds.Contains(t.WorkItem.ActivityMaster.ActivityGroup.ServiceId));
|
||||||
}
|
}
|
||||||
var workItems = await workItemsQuery.ToListAsync();
|
|
||||||
var workItemIds = workItems.Select(wi => wi.Id).ToList();
|
|
||||||
|
|
||||||
// Step 6: Fetch task allocations and comments
|
// Step 6: Fetch task allocations and comments
|
||||||
var tasks = await _context.TaskAllocations.Include(t => t.ReportedBy)
|
var tasks = await taskQuery.ToListAsync();
|
||||||
.Where(t => workItemIds.Contains(t.WorkItemId)).ToListAsync();
|
|
||||||
var taskIds = tasks.Select(t => t.Id).ToList();
|
var taskIds = tasks.Select(t => t.Id).ToList();
|
||||||
|
|
||||||
var comments = await _context.TaskComments.Include(c => c.Employee)
|
var comments = await _context.TaskComments.Include(c => c.Employee)
|
||||||
@ -172,21 +183,21 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
{
|
{
|
||||||
docQuery = docQuery.Where(d => d.UploadedAt.Date >= startDate.Value.Date && d.UploadedAt.Date <= endDate.Value.Date);
|
docQuery = docQuery.Where(d => d.UploadedAt.Date >= startDate.Value.Date && d.UploadedAt.Date <= endDate.Value.Date);
|
||||||
}
|
}
|
||||||
if (pageNumber != null && pageSize != null)
|
|
||||||
|
int totalRecords = await docQuery.GroupBy(d => d.BatchId).CountAsync();
|
||||||
|
int totalPages = (int)Math.Ceiling((double)totalRecords / pageSize);
|
||||||
|
|
||||||
|
documents = await docQuery
|
||||||
|
.GroupBy(d => d.BatchId)
|
||||||
|
.OrderByDescending(g => g.Max(d => d.UploadedAt))
|
||||||
|
.Skip((pageNumber - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.Select(g => new DocumentBatchDto
|
||||||
{
|
{
|
||||||
documents = await docQuery
|
BatchId = g.Key,
|
||||||
.GroupBy(d => d.BatchId)
|
Documents = g.ToList()
|
||||||
.OrderByDescending(g => g.Max(d => d.UploadedAt))
|
})
|
||||||
.Skip((pageNumber.Value - 1) * pageSize.Value)
|
.ToListAsync();
|
||||||
.Take(pageSize.Value)
|
|
||||||
.Select(g => new DocumentBatchDto
|
|
||||||
{
|
|
||||||
BatchId = g.Key,
|
|
||||||
Documents = g.ToList()
|
|
||||||
})
|
|
||||||
.ToListAsync();
|
|
||||||
Console.Write("Pagenation Success");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Step 8: Build response
|
// Step 8: Build response
|
||||||
@ -209,10 +220,10 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
comment = comments.OrderBy(c => c.CommentDate).FirstOrDefault(c => c.TaskAllocationId == task.Id);
|
comment = comments.OrderBy(c => c.CommentDate).FirstOrDefault(c => c.TaskAllocationId == task.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
var workItem = workItems.FirstOrDefault(w => w.Id == task?.WorkItemId);
|
var workItem = task!.WorkItem;
|
||||||
var workArea = workAreas.FirstOrDefault(wa => wa.Id == workItem?.WorkAreaId);
|
var workArea = task!.WorkItem!.WorkArea;
|
||||||
var floor = floors.FirstOrDefault(f => f.Id == workArea?.FloorId);
|
var floor = task!.WorkItem!.WorkArea!.Floor;
|
||||||
var building = buildings.FirstOrDefault(b => b.Id == floor?.BuildingId);
|
var building = task!.WorkItem!.WorkArea!.Floor!.Building;
|
||||||
|
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
@ -249,8 +260,17 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
documentVM = documentVM.Where(d => d.Documents != null && d.Documents.Any(x => uploadedByIds.Contains(x.UploadedBy?.Id ?? Guid.Empty))).ToList();
|
documentVM = documentVM.Where(d => d.Documents != null && d.Documents.Any(x => uploadedByIds.Contains(x.UploadedBy?.Id ?? Guid.Empty))).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var VM = new
|
||||||
|
{
|
||||||
|
TotalCount = totalRecords,
|
||||||
|
TotalPages = totalPages,
|
||||||
|
CurrentPage = pageNumber,
|
||||||
|
PageSize = pageSize,
|
||||||
|
Data = documentVM
|
||||||
|
};
|
||||||
|
|
||||||
_logger.LogInfo("[GetImageList] Fetched {Count} documents for ProjectId: {ProjectId}", documentVM.Count, projectId);
|
_logger.LogInfo("[GetImageList] Fetched {Count} documents for ProjectId: {ProjectId}", documentVM.Count, projectId);
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(documentVM, $"{documentVM.Count} image records fetched successfully", 200));
|
return Ok(ApiResponse<object>.SuccessResponse(VM, $"{documentVM.Count} image records fetched successfully", 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("batch/{batchId}")]
|
[HttpGet("batch/{batchId}")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user