Seprated the service ID in task list from filter
This commit is contained in:
parent
162d735d16
commit
0d4d4c3754
@ -5,6 +5,7 @@
|
||||
public List<Guid>? BuildingIds { get; set; }
|
||||
public List<Guid>? FloorIds { get; set; }
|
||||
public List<Guid>? ActivityIds { get; set; }
|
||||
public List<Guid>? ServiceIds { get; set; }
|
||||
public DateTime? dateFrom { get; set; }
|
||||
public DateTime? dateTo { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -430,37 +430,14 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
|
||||
[HttpGet("list")]
|
||||
public async Task<IActionResult> GetTasksList([FromQuery] Guid projectId, [FromQuery] string? filter, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 20,
|
||||
[FromQuery] string? dateFrom = null, [FromQuery] string? dateTo = null)
|
||||
public async Task<IActionResult> GetTasksList([FromQuery] Guid projectId, [FromQuery] string? filter, [FromQuery] Guid? serviceId,
|
||||
[FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 20)
|
||||
{
|
||||
_logger.LogInfo("GetTasksList called for projectId: {ProjectId}, dateFrom: {DateFrom}, dateTo: {DateTo}", projectId, dateFrom ?? "", dateTo ?? "");
|
||||
_logger.LogInfo("GetTasksList called for projectId: {ProjectId}", projectId);
|
||||
|
||||
Guid tenantId = GetTenantId();
|
||||
DateTime fromDate = new DateTime();
|
||||
DateTime toDate = new DateTime();
|
||||
|
||||
// 1. Parse and validate dateFrom
|
||||
if (dateFrom != null && !DateTime.TryParse(dateFrom, out fromDate))
|
||||
{
|
||||
_logger.LogWarning("Invalid starting date provided: {DateFrom}", dateFrom);
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid starting date.", "Invalid starting date.", 400));
|
||||
}
|
||||
|
||||
// 2. Parse and validate dateTo
|
||||
if (dateTo != null && !DateTime.TryParse(dateTo, out toDate))
|
||||
{
|
||||
_logger.LogWarning("Invalid ending date provided: {DateTo}", dateTo);
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid ending date.", "Invalid ending date.", 400));
|
||||
}
|
||||
|
||||
// 3. Set default date range if not provided
|
||||
fromDate = dateFrom == null ? DateTime.UtcNow.Date : fromDate;
|
||||
toDate = dateTo == null ? fromDate.AddDays(1) : toDate;
|
||||
|
||||
|
||||
_logger.LogInfo("Fetching task allocations between {FromDate} and {ToDate}", fromDate, toDate);
|
||||
|
||||
// 4. Get task allocations in the specified date range
|
||||
// 1. Get task allocations in the specified date range
|
||||
var taskAllocationQuery = _context.TaskAllocations
|
||||
.Include(t => t.Employee)
|
||||
.Include(t => t.ReportedBy)
|
||||
@ -481,8 +458,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
t.WorkItem.WorkArea.Floor != null &&
|
||||
t.WorkItem.WorkArea.Floor.Building != null &&
|
||||
t.WorkItem.WorkArea.Floor.Building.ProjectId != projectId &&
|
||||
t.AssignmentDate.Date >= fromDate.Date &&
|
||||
t.AssignmentDate.Date <= toDate.Date &&
|
||||
t.TenantId == tenantId);
|
||||
|
||||
var taskFilter = TryDeserializeFilter(filter);
|
||||
@ -507,13 +482,19 @@ namespace MarcoBMS.Services.Controllers
|
||||
taskAllocationQuery = taskAllocationQuery.Where(t => t.WorkItem != null &&
|
||||
taskFilter.ActivityIds.Contains(t.WorkItem.ActivityId));
|
||||
}
|
||||
if (taskFilter.ServiceIds?.Any() ?? false)
|
||||
if (taskFilter.dateFrom.HasValue && taskFilter.dateTo.HasValue)
|
||||
{
|
||||
taskAllocationQuery = taskAllocationQuery.Where(t => t.AssignmentDate.Date >= taskFilter.dateFrom.Value.Date &&
|
||||
t.AssignmentDate.Date <= taskFilter.dateTo.Value.Date);
|
||||
}
|
||||
}
|
||||
|
||||
if (serviceId.HasValue)
|
||||
{
|
||||
taskAllocationQuery = taskAllocationQuery.Where(t => t.WorkItem != null &&
|
||||
t.WorkItem.ActivityMaster != null &&
|
||||
t.WorkItem.ActivityMaster.ActivityGroup != null &&
|
||||
taskFilter.ServiceIds.Contains(t.WorkItem.ActivityMaster.ActivityGroup.ServiceId));
|
||||
}
|
||||
t.WorkItem.ActivityMaster.ActivityGroup.ServiceId == serviceId);
|
||||
}
|
||||
|
||||
|
||||
@ -528,14 +509,14 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
var taskIds = taskAllocations.Select(t => t.Id).ToList();
|
||||
|
||||
// 5. Load team members
|
||||
// 2. Load team members
|
||||
_logger.LogInfo("Loading task members and related employee data.");
|
||||
var teamMembers = await _context.TaskMembers
|
||||
.Include(t => t.Employee)
|
||||
.Where(t => taskIds.Contains(t.TaskAllocationId))
|
||||
.ToListAsync();
|
||||
|
||||
// 6. Load task comments
|
||||
// 3. Load task comments
|
||||
_logger.LogInfo("Fetching comments and attachments.");
|
||||
var allComments = await _context.TaskComments
|
||||
.Include(c => c.Employee)
|
||||
@ -543,14 +524,14 @@ namespace MarcoBMS.Services.Controllers
|
||||
.ToListAsync();
|
||||
var commentIds = allComments.Select(c => c.Id).ToList();
|
||||
|
||||
// 7. Load all attachments (task and comment)
|
||||
// 4. Load all attachments (task and comment)
|
||||
var attachments = await _context.TaskAttachments
|
||||
.Where(t => taskIds.Contains(t.ReferenceId) || commentIds.Contains(t.ReferenceId))
|
||||
.ToListAsync();
|
||||
|
||||
var documentIds = attachments.Select(t => t.DocumentId).ToList();
|
||||
|
||||
// 8. Load actual documents from attachment references
|
||||
// 5. Load actual documents from attachment references
|
||||
var documents = await _context.Documents
|
||||
.Where(d => documentIds.Contains(d.Id))
|
||||
.ToListAsync();
|
||||
|
Loading…
x
Reference in New Issue
Block a user