浏览代码

Mock staffs and allocate staff in project creation

tags/Baseline_30082024_BACKEND_UAT
Wayne 1年前
父节点
当前提交
313eca4e56
共有 6 个文件被更改,包括 155 次插入27 次删除
  1. +2
    -0
      src/main/java/com/ffii/tsms/modules/data/entity/StaffRepository.java
  2. +3
    -3
      src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt
  3. +5
    -5
      src/main/java/com/ffii/tsms/modules/data/web/StaffsController.kt
  4. +28
    -16
      src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt
  5. +3
    -3
      src/main/java/com/ffii/tsms/modules/project/web/models/NewProjectRequest.kt
  6. +114
    -0
      src/main/resources/db/changelog/changes/20240414_01_wayne/01_mock_staffs.sql

+ 2
- 0
src/main/java/com/ffii/tsms/modules/data/entity/StaffRepository.java 查看文件

@@ -10,4 +10,6 @@ import java.util.Map;


public interface StaffRepository extends AbstractRepository<Staff, Long> { public interface StaffRepository extends AbstractRepository<Staff, Long> {
List<StaffSearchInfo> findStaffSearchInfoByAndDeletedFalse(); List<StaffSearchInfo> findStaffSearchInfoByAndDeletedFalse();

List<StaffSearchInfo> findAllStaffSearchInfoByIdIn(List<Long> ids);
} }

+ 3
- 3
src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt 查看文件

@@ -27,9 +27,9 @@ open class StaffsService(
private val jdbcDao: JdbcDao, private val jdbcDao: JdbcDao,
private val passwordEncoder: PasswordEncoder private val passwordEncoder: PasswordEncoder
) : AbstractBaseEntityService<Staff, Long, StaffRepository>(jdbcDao, staffRepository) { ) : 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> { open fun allStaff(): List<StaffSearchInfo> {


+ 5
- 5
src/main/java/com/ffii/tsms/modules/data/web/StaffsController.kt 查看文件

@@ -16,16 +16,16 @@ import org.springframework.web.bind.annotation.*
class StaffsController(private val staffsService: StaffsService) { class StaffsController(private val staffsService: StaffsService) {
@GetMapping("/teamLeads") @GetMapping("/teamLeads")
fun teamLeads(): List<StaffSearchInfo> { fun teamLeads(): List<StaffSearchInfo> {
return staffsService.allStaff()
return staffsService.getTeamLeads()
} }
@GetMapping @GetMapping
fun allStaff(): List<StaffSearchInfo> { fun allStaff(): List<StaffSearchInfo> {
return staffsService.allStaff() return staffsService.allStaff()
} }
@GetMapping("/list")
fun list(): List<Staff> {
return staffsService.getTeamLeads()
}
// @GetMapping("/list")
// fun list(): List<Staff> {
// return staffsService.getTeamLeads()
// }


@GetMapping("/{id}") @GetMapping("/{id}")
fun getStaff(@PathVariable id: Long?): Map<String, Any> { fun getStaff(@PathVariable id: Long?): Map<String, Any> {


+ 28
- 16
src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt 查看文件

@@ -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()
} }
} }

+ 3
- 3
src/main/java/com/ffii/tsms/modules/project/web/models/NewProjectRequest.kt 查看文件

@@ -23,11 +23,11 @@ data class NewProjectRequest(
val clientContactId: Long, val clientContactId: Long,
val clientSubsidiaryId: Long?, val clientSubsidiaryId: Long?,


val tasks: Map<Long, TaskAllocation>,

val allocatedStaffIds: List<Long>, val allocatedStaffIds: List<Long>,


val milestones: Map<Long, Milestone>
val milestones: Map<Long, Milestone>,

val expectedProjectFee: Double
) )


data class TaskAllocation( data class TaskAllocation(


+ 114
- 0
src/main/resources/db/changelog/changes/20240414_01_wayne/01_mock_staffs.sql 查看文件

@@ -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
);

正在加载...
取消
保存