|
|
@@ -1,6 +1,8 @@ |
|
|
package com.ffii.tsms.modules.timesheet.service |
|
|
package com.ffii.tsms.modules.timesheet.service |
|
|
|
|
|
|
|
|
import com.ffii.core.exception.BadRequestException |
|
|
import com.ffii.core.exception.BadRequestException |
|
|
|
|
|
import com.ffii.tsms.modules.data.entity.Staff |
|
|
|
|
|
import com.ffii.tsms.modules.data.entity.StaffRepository |
|
|
import com.ffii.tsms.modules.data.service.StaffsService |
|
|
import com.ffii.tsms.modules.data.service.StaffsService |
|
|
import com.ffii.tsms.modules.data.service.TeamService |
|
|
import com.ffii.tsms.modules.data.service.TeamService |
|
|
import com.ffii.tsms.modules.project.entity.ProjectRepository |
|
|
import com.ffii.tsms.modules.project.entity.ProjectRepository |
|
|
@@ -24,8 +26,8 @@ open class TimesheetsService( |
|
|
private val projectRepository: ProjectRepository, |
|
|
private val projectRepository: ProjectRepository, |
|
|
private val taskRepository: TaskRepository, |
|
|
private val taskRepository: TaskRepository, |
|
|
private val staffsService: StaffsService, |
|
|
private val staffsService: StaffsService, |
|
|
private val teamService: TeamService |
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
private val teamService: TeamService, private val staffRepository: StaffRepository |
|
|
|
|
|
) { |
|
|
@Transactional |
|
|
@Transactional |
|
|
open fun saveTimesheet(recordTimeEntry: Map<LocalDate, List<TimeEntry>>): Map<String, List<TimeEntry>> { |
|
|
open fun saveTimesheet(recordTimeEntry: Map<LocalDate, List<TimeEntry>>): Map<String, List<TimeEntry>> { |
|
|
// Need to be associated with a staff |
|
|
// Need to be associated with a staff |
|
|
@@ -59,9 +61,14 @@ open class TimesheetsService( |
|
|
|
|
|
|
|
|
@Transactional |
|
|
@Transactional |
|
|
open fun saveMemberTimeEntry(staffId: Long, entry: TimeEntry, recordDate: LocalDate?): Map<String, List<TimeEntry>> { |
|
|
open fun saveMemberTimeEntry(staffId: Long, entry: TimeEntry, recordDate: LocalDate?): Map<String, List<TimeEntry>> { |
|
|
val currentStaff = staffsService.currentStaff() ?: throw BadRequestException() |
|
|
|
|
|
// Make sure current staff is a team lead |
|
|
|
|
|
teamService.getMyTeamForStaff(currentStaff) ?: throw BadRequestException() |
|
|
|
|
|
|
|
|
val authorities = staffsService.currentAuthorities() ?: throw BadRequestException() |
|
|
|
|
|
|
|
|
|
|
|
if (!authorities.stream().anyMatch { it.authority.equals("MAINTAIN_TIMESHEET") }) { |
|
|
|
|
|
throw BadRequestException() |
|
|
|
|
|
} |
|
|
|
|
|
// val currentStaff = staffsService.currentStaff() ?: throw BadRequestException() |
|
|
|
|
|
// // Make sure current staff is a team lead |
|
|
|
|
|
// teamService.getMyTeamForStaff(currentStaff) ?: throw BadRequestException() |
|
|
|
|
|
|
|
|
val memberStaff = staffsService.getStaff(staffId) |
|
|
val memberStaff = staffsService.getStaff(staffId) |
|
|
|
|
|
|
|
|
@@ -101,22 +108,29 @@ open class TimesheetsService( |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
open fun getTeamMemberTimesheet(): Map<Long, TeamMemberTimeEntries> { |
|
|
open fun getTeamMemberTimesheet(): Map<Long, TeamMemberTimeEntries> { |
|
|
val currentStaff = staffsService.currentStaff() ?: return emptyMap() |
|
|
|
|
|
// Get team where current staff is team lead |
|
|
|
|
|
val myTeam = teamService.getMyTeamForStaff(currentStaff) ?: return emptyMap() |
|
|
|
|
|
|
|
|
|
|
|
val teamMembers = staffsService.findAllByTeamId(myTeam.id!!).getOrDefault(emptyList()) |
|
|
|
|
|
|
|
|
|
|
|
return teamMembers.associate { member -> |
|
|
|
|
|
Pair( |
|
|
|
|
|
member.id!!, |
|
|
|
|
|
TeamMemberTimeEntries( |
|
|
|
|
|
staffId = member.staffId, |
|
|
|
|
|
name = member.name, |
|
|
|
|
|
timeEntries = transformToTimeEntryMap(timesheetRepository.findAllByStaff(member)) |
|
|
|
|
|
|
|
|
val authorities = staffsService.currentAuthorities() ?: return emptyMap() |
|
|
|
|
|
if (authorities.stream().anyMatch { it.authority.equals("MAINTAIN_TIMESHEET")}) { |
|
|
|
|
|
val currentStaff = staffsService.currentStaff() |
|
|
|
|
|
// Get team where current staff is team lead |
|
|
|
|
|
|
|
|
|
|
|
val myTeam = if (currentStaff != null) teamService.getMyTeamForStaff(currentStaff) else null |
|
|
|
|
|
val teamMembers = if (myTeam != null) { |
|
|
|
|
|
staffsService.findAllByTeamId(myTeam.id!!).getOrDefault(emptyList()) |
|
|
|
|
|
} else { |
|
|
|
|
|
staffsService.findAll().getOrDefault(emptyList()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return teamMembers.associate { member -> |
|
|
|
|
|
Pair( |
|
|
|
|
|
member.id!!, |
|
|
|
|
|
TeamMemberTimeEntries( |
|
|
|
|
|
staffId = member.staffId, |
|
|
|
|
|
name = member.name, |
|
|
|
|
|
timeEntries = transformToTimeEntryMap(timesheetRepository.findAllByStaff(member)) |
|
|
|
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} else return emptyMap() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private fun transformToTimeEntryMap(timesheets: List<Timesheet>): Map<String, List<TimeEntry>> { |
|
|
private fun transformToTimeEntryMap(timesheets: List<Timesheet>): Map<String, List<TimeEntry>> { |
|
|
|