@@ -10,4 +10,6 @@ import java.util.Map; | |||
public interface StaffRepository extends AbstractRepository<Staff, Long> { | |||
List<StaffSearchInfo> findStaffSearchInfoByAndDeletedFalse(); | |||
List<StaffSearchInfo> findAllStaffSearchInfoByIdIn(List<Long> ids); | |||
} |
@@ -27,9 +27,9 @@ open class StaffsService( | |||
private val jdbcDao: JdbcDao, | |||
private val passwordEncoder: PasswordEncoder | |||
) : AbstractBaseEntityService<Staff, Long, StaffRepository>(jdbcDao, staffRepository) { | |||
open fun getTeamLeads(): List<Staff> { | |||
// TODO: Replace with actual logic and make a projection instead of returning all fields | |||
return staffRepository.findAll() | |||
open fun getTeamLeads(): List<StaffSearchInfo> { | |||
// TODO: Replace by actual logic | |||
return staffRepository.findAllStaffSearchInfoByIdIn(listOf(1, 2)) | |||
} | |||
open fun allStaff(): List<StaffSearchInfo> { | |||
@@ -16,16 +16,16 @@ import org.springframework.web.bind.annotation.* | |||
class StaffsController(private val staffsService: StaffsService) { | |||
@GetMapping("/teamLeads") | |||
fun teamLeads(): List<StaffSearchInfo> { | |||
return staffsService.allStaff() | |||
return staffsService.getTeamLeads() | |||
} | |||
@GetMapping | |||
fun allStaff(): List<StaffSearchInfo> { | |||
return staffsService.allStaff() | |||
} | |||
@GetMapping("/list") | |||
fun list(): List<Staff> { | |||
return staffsService.getTeamLeads() | |||
} | |||
// @GetMapping("/list") | |||
// fun list(): List<Staff> { | |||
// return staffsService.getTeamLeads() | |||
// } | |||
@GetMapping("/{id}") | |||
fun getStaff(@PathVariable id: Long?): Map<String, Any> { | |||
@@ -4,20 +4,19 @@ import com.ffii.tsms.modules.data.entity.* | |||
import com.ffii.tsms.modules.data.service.CustomerContactService | |||
import com.ffii.tsms.modules.project.entity.projections.ProjectSearchInfo | |||
import com.ffii.tsms.modules.data.service.CustomerService | |||
import com.ffii.tsms.modules.project.entity.Project | |||
import com.ffii.tsms.modules.project.entity.ProjectCategory | |||
import com.ffii.tsms.modules.project.entity.ProjectCategoryRepository | |||
import com.ffii.tsms.modules.project.entity.ProjectRepository | |||
import com.ffii.tsms.modules.project.entity.* | |||
import com.ffii.tsms.modules.project.web.models.NewProjectRequest | |||
import org.springframework.stereotype.Service | |||
import org.springframework.transaction.annotation.Transactional | |||
@Service | |||
class ProjectsService( | |||
open class ProjectsService( | |||
private val projectRepository: ProjectRepository, | |||
private val customerService: CustomerService, | |||
private val customerContactService: CustomerContactService, | |||
private val projectCategoryRepository: ProjectCategoryRepository, | |||
private val staffRepository: StaffRepository, | |||
private val staffAllocationRepository: StaffAllocationRepository, | |||
private val fundingTypeRepository: FundingTypeRepository, | |||
private val serviceTypeRepository: ServiceTypeRepository, | |||
private val contractTypeRepository: ContractTypeRepository, | |||
@@ -25,15 +24,16 @@ class ProjectsService( | |||
private val buildingTypeRepository: BuildingTypeRepository, | |||
private val workNatureRepository: WorkNatureRepository | |||
) { | |||
fun allProjects(): List<ProjectSearchInfo> { | |||
open fun allProjects(): List<ProjectSearchInfo> { | |||
return projectRepository.findProjectSearchInfoBy() | |||
} | |||
fun allProjectCategories(): List<ProjectCategory> { | |||
open fun allProjectCategories(): List<ProjectCategory> { | |||
return projectCategoryRepository.findAll() | |||
} | |||
fun saveProject(request: NewProjectRequest): Project { | |||
@Transactional | |||
open fun saveProject(request: NewProjectRequest): Project { | |||
val projectCategory = | |||
projectCategoryRepository.findById(request.projectCategoryId).orElseThrow() | |||
val fundingType = fundingTypeRepository.findById(request.fundingTypeId).orElseThrow() | |||
@@ -47,12 +47,15 @@ class ProjectsService( | |||
val customer = customerService.findCustomer(request.clientId) | |||
val clientContact = customerContactService.findByContactId(request.clientContactId) | |||
// TODO: Add tasks, milestones, allocated staff | |||
// TODO: Add tasks, milestones | |||
val project = | |||
Project().apply { | |||
name = request.projectName | |||
description = request.projectDescription | |||
code = request.projectCode | |||
expectedTotalFee = request.expectedProjectFee | |||
this.projectCategory = projectCategory | |||
this.fundingType = fundingType | |||
this.serviceType = serviceType | |||
@@ -68,30 +71,39 @@ class ProjectsService( | |||
custLeadPhone = clientContact.phone | |||
} | |||
return projectRepository.save(project) | |||
val savedProject = projectRepository.save(project) | |||
val allocatedStaff = staffRepository.findAllById(request.allocatedStaffIds) | |||
val staffAllocations = allocatedStaff.map { staff -> StaffAllocation().apply { | |||
this.project = savedProject | |||
this.staff = staff | |||
} } | |||
staffAllocationRepository.saveAll(staffAllocations) | |||
return savedProject | |||
} | |||
fun allFundingTypes(): List<FundingType> { | |||
open fun allFundingTypes(): List<FundingType> { | |||
return fundingTypeRepository.findAll() | |||
} | |||
fun allLocationTypes(): List<Location> { | |||
open fun allLocationTypes(): List<Location> { | |||
return locationRepository.findAll() | |||
} | |||
fun allServiceTypes(): List<ServiceType> { | |||
open fun allServiceTypes(): List<ServiceType> { | |||
return serviceTypeRepository.findAll() | |||
} | |||
fun allContractTypes(): List<ContractType> { | |||
open fun allContractTypes(): List<ContractType> { | |||
return contractTypeRepository.findAll() | |||
} | |||
fun allBuildingTypes(): List<BuildingType> { | |||
open fun allBuildingTypes(): List<BuildingType> { | |||
return buildingTypeRepository.findAll() | |||
} | |||
fun allWorkNatures(): List<WorkNature> { | |||
open fun allWorkNatures(): List<WorkNature> { | |||
return workNatureRepository.findAll() | |||
} | |||
} |
@@ -23,11 +23,11 @@ data class NewProjectRequest( | |||
val clientContactId: Long, | |||
val clientSubsidiaryId: Long?, | |||
val tasks: Map<Long, TaskAllocation>, | |||
val allocatedStaffIds: List<Long>, | |||
val milestones: Map<Long, Milestone> | |||
val milestones: Map<Long, Milestone>, | |||
val expectedProjectFee: Double | |||
) | |||
data class TaskAllocation( | |||
@@ -0,0 +1,114 @@ | |||
-- liquibase formatted sql | |||
-- changeset wayne:mock_staffs | |||
INSERT INTO `user` (name, username, password) VALUES | |||
('Albert Lam','alam','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Bernard Chou','bchou','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Carl Junior','cjunior','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Denis Lau','dlau','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Edward Wong','ewong','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Fred Cheung','fcheung','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Gordon Ramsey','gramsey','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Heather Stewards','hstewards','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Ivan Foo','ifoo','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Jack Son','json','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Kurt Land','kland','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'), | |||
('Lawrence Arnold','larnold','$2a$10$65S7/AhKn8MldlYmvFN5JOfr1yaULwFNDIhTskLTuUCKgbbs8sFAi'); | |||
INSERT INTO staff (userId, name, staffId, companyId, teamId, salaryEffId) VALUES | |||
( | |||
(SELECT id from `user` where username = 'alam'), | |||
'Albert Lam', | |||
'003', | |||
1, | |||
1, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'bchou'), | |||
'Bernard Chou', | |||
'004', | |||
1, | |||
2, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'cjunior'), | |||
'Carl Junior', | |||
'005', | |||
1, | |||
1, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'dlau'), | |||
'Denis Lau', | |||
'006', | |||
1, | |||
2, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'ewong'), | |||
'Edward Wong', | |||
'007', | |||
1, | |||
1, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'fcheung'), | |||
'Fred Cheung', | |||
'008', | |||
1, | |||
2, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'gramsey'), | |||
'Gordon Ramsey', | |||
'009', | |||
1, | |||
1, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'hstewards'), | |||
'Heather Stewards', | |||
'010', | |||
1, | |||
2, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'ifoo'), | |||
'Ivan Foo', | |||
'011', | |||
1, | |||
1, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'json'), | |||
'Jack Son', | |||
'012', | |||
1, | |||
2, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'kland'), | |||
'Kurt Land', | |||
'013', | |||
1, | |||
1, | |||
1 | |||
), | |||
( | |||
(SELECT id from `user` where username = 'larnold'), | |||
'Lawrence Arnold', | |||
'014', | |||
1, | |||
2, | |||
1 | |||
); |