|
@@ -4,20 +4,19 @@ import com.ffii.tsms.modules.data.entity.* |
|
|
import com.ffii.tsms.modules.data.service.CustomerContactService |
|
|
import com.ffii.tsms.modules.data.service.CustomerContactService |
|
|
import com.ffii.tsms.modules.project.entity.projections.ProjectSearchInfo |
|
|
import com.ffii.tsms.modules.project.entity.projections.ProjectSearchInfo |
|
|
import com.ffii.tsms.modules.data.service.CustomerService |
|
|
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 com.ffii.tsms.modules.project.web.models.NewProjectRequest |
|
|
import org.springframework.stereotype.Service |
|
|
import org.springframework.stereotype.Service |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
class ProjectsService( |
|
|
|
|
|
|
|
|
open class ProjectsService( |
|
|
private val projectRepository: ProjectRepository, |
|
|
private val projectRepository: ProjectRepository, |
|
|
private val customerService: CustomerService, |
|
|
private val customerService: CustomerService, |
|
|
private val customerContactService: CustomerContactService, |
|
|
private val customerContactService: CustomerContactService, |
|
|
private val projectCategoryRepository: ProjectCategoryRepository, |
|
|
private val projectCategoryRepository: ProjectCategoryRepository, |
|
|
private val staffRepository: StaffRepository, |
|
|
private val staffRepository: StaffRepository, |
|
|
|
|
|
private val staffAllocationRepository: StaffAllocationRepository, |
|
|
private val fundingTypeRepository: FundingTypeRepository, |
|
|
private val fundingTypeRepository: FundingTypeRepository, |
|
|
private val serviceTypeRepository: ServiceTypeRepository, |
|
|
private val serviceTypeRepository: ServiceTypeRepository, |
|
|
private val contractTypeRepository: ContractTypeRepository, |
|
|
private val contractTypeRepository: ContractTypeRepository, |
|
@@ -25,15 +24,16 @@ class ProjectsService( |
|
|
private val buildingTypeRepository: BuildingTypeRepository, |
|
|
private val buildingTypeRepository: BuildingTypeRepository, |
|
|
private val workNatureRepository: WorkNatureRepository |
|
|
private val workNatureRepository: WorkNatureRepository |
|
|
) { |
|
|
) { |
|
|
fun allProjects(): List<ProjectSearchInfo> { |
|
|
|
|
|
|
|
|
open fun allProjects(): List<ProjectSearchInfo> { |
|
|
return projectRepository.findProjectSearchInfoBy() |
|
|
return projectRepository.findProjectSearchInfoBy() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fun allProjectCategories(): List<ProjectCategory> { |
|
|
|
|
|
|
|
|
open fun allProjectCategories(): List<ProjectCategory> { |
|
|
return projectCategoryRepository.findAll() |
|
|
return projectCategoryRepository.findAll() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fun saveProject(request: NewProjectRequest): Project { |
|
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
|
open fun saveProject(request: NewProjectRequest): Project { |
|
|
val projectCategory = |
|
|
val projectCategory = |
|
|
projectCategoryRepository.findById(request.projectCategoryId).orElseThrow() |
|
|
projectCategoryRepository.findById(request.projectCategoryId).orElseThrow() |
|
|
val fundingType = fundingTypeRepository.findById(request.fundingTypeId).orElseThrow() |
|
|
val fundingType = fundingTypeRepository.findById(request.fundingTypeId).orElseThrow() |
|
@@ -47,12 +47,15 @@ class ProjectsService( |
|
|
val customer = customerService.findCustomer(request.clientId) |
|
|
val customer = customerService.findCustomer(request.clientId) |
|
|
val clientContact = customerContactService.findByContactId(request.clientContactId) |
|
|
val clientContact = customerContactService.findByContactId(request.clientContactId) |
|
|
|
|
|
|
|
|
// TODO: Add tasks, milestones, allocated staff |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Add tasks, milestones |
|
|
val project = |
|
|
val project = |
|
|
Project().apply { |
|
|
Project().apply { |
|
|
name = request.projectName |
|
|
name = request.projectName |
|
|
description = request.projectDescription |
|
|
description = request.projectDescription |
|
|
code = request.projectCode |
|
|
code = request.projectCode |
|
|
|
|
|
expectedTotalFee = request.expectedProjectFee |
|
|
this.projectCategory = projectCategory |
|
|
this.projectCategory = projectCategory |
|
|
this.fundingType = fundingType |
|
|
this.fundingType = fundingType |
|
|
this.serviceType = serviceType |
|
|
this.serviceType = serviceType |
|
@@ -68,30 +71,39 @@ class ProjectsService( |
|
|
custLeadPhone = clientContact.phone |
|
|
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() |
|
|
return fundingTypeRepository.findAll() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fun allLocationTypes(): List<Location> { |
|
|
|
|
|
|
|
|
open fun allLocationTypes(): List<Location> { |
|
|
return locationRepository.findAll() |
|
|
return locationRepository.findAll() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fun allServiceTypes(): List<ServiceType> { |
|
|
|
|
|
|
|
|
open fun allServiceTypes(): List<ServiceType> { |
|
|
return serviceTypeRepository.findAll() |
|
|
return serviceTypeRepository.findAll() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fun allContractTypes(): List<ContractType> { |
|
|
|
|
|
|
|
|
open fun allContractTypes(): List<ContractType> { |
|
|
return contractTypeRepository.findAll() |
|
|
return contractTypeRepository.findAll() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fun allBuildingTypes(): List<BuildingType> { |
|
|
|
|
|
|
|
|
open fun allBuildingTypes(): List<BuildingType> { |
|
|
return buildingTypeRepository.findAll() |
|
|
return buildingTypeRepository.findAll() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fun allWorkNatures(): List<WorkNature> { |
|
|
|
|
|
|
|
|
open fun allWorkNatures(): List<WorkNature> { |
|
|
return workNatureRepository.findAll() |
|
|
return workNatureRepository.findAll() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |