浏览代码

Save grade allocations for project creation

tags/Baseline_30082024_BACKEND_UAT
Wayne 1年前
父节点
当前提交
c66c2b1720
共有 3 个文件被更改,包括 26 次插入18 次删除
  1. +5
    -1
      src/main/java/com/ffii/tsms/modules/data/service/GradeService.kt
  2. +1
    -1
      src/main/java/com/ffii/tsms/modules/data/web/GradeController.kt
  3. +20
    -16
      src/main/java/com/ffii/tsms/modules/project/service/ProjectsService.kt

+ 5
- 1
src/main/java/com/ffii/tsms/modules/data/service/GradeService.kt 查看文件

@@ -24,7 +24,11 @@ open class GradeService(
return jdbcDao.queryForList(sql.toString(), args) return jdbcDao.queryForList(sql.toString(), args)
} }


open fun allGrades(): List<GradeInfo> {
open fun allGradeInfo(): List<GradeInfo> {
return gradeRepository.findGradeInfoByDeletedFalse() return gradeRepository.findGradeInfoByDeletedFalse()
} }

open fun allGrades(): List<Grade> {
return gradeRepository.findAll()
}
} }

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

@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RestController
class GradeController(private val gradeService: GradeService) { class GradeController(private val gradeService: GradeService) {
@GetMapping @GetMapping
fun allGrades(): List<GradeInfo> { fun allGrades(): List<GradeInfo> {
return gradeService.allGrades();
return gradeService.allGradeInfo();
} }


@GetMapping("/combo") @GetMapping("/combo")


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

@@ -4,6 +4,7 @@ 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.data.service.GradeService
import com.ffii.tsms.modules.project.entity.* import com.ffii.tsms.modules.project.entity.*
import com.ffii.tsms.modules.project.entity.projections.InvoiceInfoSearchInfo import com.ffii.tsms.modules.project.entity.projections.InvoiceInfoSearchInfo
import com.ffii.tsms.modules.project.entity.projections.InvoiceSearchInfo import com.ffii.tsms.modules.project.entity.projections.InvoiceSearchInfo
@@ -20,6 +21,7 @@ open class ProjectsService(
private val tasksService: TasksService, private val tasksService: TasksService,
private val customerContactService: CustomerContactService, private val customerContactService: CustomerContactService,
private val subsidiaryService: SubsidiaryService, private val subsidiaryService: SubsidiaryService,
private val gradeService: GradeService,
private val projectCategoryRepository: ProjectCategoryRepository, private val projectCategoryRepository: ProjectCategoryRepository,
private val staffRepository: StaffRepository, private val staffRepository: StaffRepository,
private val staffAllocationRepository: StaffAllocationRepository, private val staffAllocationRepository: StaffAllocationRepository,
@@ -71,6 +73,7 @@ open class ProjectsService(


val allTasksMap = tasksService.allTasks().associateBy { it.id } val allTasksMap = tasksService.allTasks().associateBy { it.id }
val taskGroupMap = tasksService.allTaskGroups().associateBy { it.id } val taskGroupMap = tasksService.allTaskGroups().associateBy { it.id }
val gradeMap = gradeService.allGrades().associateBy { it.id }


val project = val project =
Project().apply { Project().apply {
@@ -100,46 +103,47 @@ open class ProjectsService(


// Milestones and tasks // Milestones and tasks
val tasksToSave = mutableListOf<ProjectTask>() val tasksToSave = mutableListOf<ProjectTask>()
val milestones = request.milestones.entries.map { (taskStageId, requestMilestone) ->
val milestones = request.taskGroups.entries.map { (taskStageId, taskGroupAllocation) ->
Milestone().apply { Milestone().apply {
val newMilestone = this val newMilestone = this
val requestMilestone = request.milestones[taskStageId]
this.project = project this.project = project
this.taskGroup = taskGroupMap[taskStageId] this.taskGroup = taskGroupMap[taskStageId]
this.startDate = requestMilestone.startDate?.let { LocalDate.parse(it) }
this.endDate = requestMilestone.endDate?.let { LocalDate.parse(it) }
this.milestonePayments = requestMilestone.payments.map {
this.startDate = requestMilestone?.startDate?.let { LocalDate.parse(it) }
this.endDate = requestMilestone?.endDate?.let { LocalDate.parse(it) }
this.milestonePayments = requestMilestone?.payments?.map {
MilestonePayment().apply { MilestonePayment().apply {
this.description = it.description this.description = it.description
this.amount = it.amount this.amount = it.amount
this.date = LocalDate.parse(it.date) this.date = LocalDate.parse(it.date)
this.milestone = newMilestone this.milestone = newMilestone
} }
}.toMutableList()
}?.toMutableList() ?: mutableListOf()


// Tasks // Tasks
val taskGroupAllocation = request.taskGroups[taskStageId]
this.stagePercentAllocation = taskGroupAllocation?.percentAllocation
this.stagePercentAllocation = taskGroupAllocation.percentAllocation


taskGroupAllocation?.taskIds?.map { taskId -> ProjectTask().apply {
taskGroupAllocation.taskIds.map { taskId -> ProjectTask().apply {
this.project = project this.project = project
this.milestone = newMilestone this.milestone = newMilestone
this.task = allTasksMap[taskId] this.task = allTasksMap[taskId]
} }?.let { tasksToSave.addAll(it) }
} }.let { tasksToSave.addAll(it) }
} }
} }


// TODO: Get Grades from db
// Grade allocation (from manhourPercentageByGrade) // Grade allocation (from manhourPercentageByGrade)
// request.manhourPercentageByGrade.entries.map {
// GradeAllocation().apply {
// this.project = project
// this.manhour = it.value
// }
// }
val gradeAllocations = request.manhourPercentageByGrade.entries.map {
GradeAllocation().apply {
this.project = project
this.manhour = it.value
this.grade = gradeMap[it.key]
}
}


val savedProject = projectRepository.save(project) val savedProject = projectRepository.save(project)
milestoneRepository.saveAll(milestones) milestoneRepository.saveAll(milestones)
projectTaskRepository.saveAll(tasksToSave) projectTaskRepository.saveAll(tasksToSave)
gradeAllocationRepository.saveAll(gradeAllocations)


// Staff allocation // Staff allocation
val allocatedStaff = staffRepository.findAllById(request.allocatedStaffIds) val allocatedStaff = staffRepository.findAllById(request.allocatedStaffIds)


正在加载...
取消
保存