Ver a proveniência

Update Salary Effective when update staff info

tags/Baseline_30082024_BACKEND_UAT
MSI\2Fi há 1 ano
ascendente
cometimento
24e6c1a120
6 ficheiros alterados com 95 adições e 2 eliminações
  1. +57
    -0
      src/main/java/com/ffii/tsms/modules/data/service/SalaryEffectiveService.kt
  2. +10
    -2
      src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt
  3. +7
    -0
      src/main/java/com/ffii/tsms/modules/data/web/SalaryEffectiveController.kt
  4. +1
    -0
      src/main/java/com/ffii/tsms/modules/data/web/StaffsController.kt
  5. +8
    -0
      src/main/java/com/ffii/tsms/modules/data/web/models/NewStaffRequest.kt
  6. +12
    -0
      src/main/java/com/ffii/tsms/modules/data/web/models/SalaryEffectiveResponse.kt

+ 57
- 0
src/main/java/com/ffii/tsms/modules/data/service/SalaryEffectiveService.kt Ver ficheiro

@@ -8,6 +8,8 @@ import com.ffii.tsms.modules.data.entity.SalaryEffectiveRepository
import com.ffii.tsms.modules.data.entity.SalaryRepository
import com.ffii.tsms.modules.data.entity.Staff
import com.ffii.tsms.modules.data.entity.StaffRepository
import com.ffii.tsms.modules.data.web.models.SalaryEffectiveInfo
import com.ffii.tsms.modules.data.web.models.SalaryEffectiveInfoResponse
import org.springframework.stereotype.Service
import java.math.BigDecimal
import java.time.LocalDate
@@ -44,6 +46,23 @@ open class SalaryEffectiveService(
return if(result > 0) result.toLong() else -1
}

open fun findSalaryEffectiveInfoByStaffId(staffId: Long): List<SalaryEffectiveInfoResponse> {
val sql = StringBuilder( " Select se.*, s.lowerLimit, s.upperLimit " +
" from salary_effective se " +
" join salary s on s.salaryPoint = se.salaryId " +
" where staffId = :staffId order by date ")
val result = jdbcDao.queryForList(sql.toString(), mapOf("staffId" to staffId)).map {
result -> SalaryEffectiveInfoResponse(
(result["id"] as Int).toLong(),
(result["salaryId"] as Int).toLong(),
(result["lowerLimit"] as Int),
(result["upperLimit"] as Int),
(result["date"] as java.sql.Date).toLocalDate(),
)
}
return result
}

open fun saveSalaryEffective (staffId: Long, salaryId: Long): SalaryEffective? {
// val existSalaryEffective = findByStaffIdAndSalaryId(staffId, salaryId)
//
@@ -62,6 +81,8 @@ open class SalaryEffectiveService(
val salary = salaryRepository.findBySalaryPoint(salaryId).orElseThrow()
val salaryEffective = SalaryEffective().apply {
date = LocalDate.now()
startDate = LocalDate.now()
endDate = LocalDate.of(2124, 1, 1)
this.staff = staff
this.salary = salary
}
@@ -71,6 +92,42 @@ open class SalaryEffectiveService(
return salaryEffective
}



open fun updateSalaryEffective(staffId: Long, salaryEffectiveInfo: List<SalaryEffectiveInfo>?){
salaryEffectiveInfo?.forEachIndexed { index, item ->
val staff = staffRepository.findById(staffId).orElseThrow()
val salary = salaryRepository.findBySalaryPoint(item.salaryPoint).orElseThrow()
val salaryEffective: SalaryEffective
val endDate: LocalDate
endDate = if(index == salaryEffectiveInfo.lastIndex){
LocalDate.of(2124, 1, 1)
}else{
salaryEffectiveInfo[index+1].date
}
if (salaryEffectiveRepository.findById(item.id).isEmpty) {
salaryEffective = SalaryEffective().apply {
date = item.date
startDate = item.date
this.endDate = endDate
this.staff = staff
this.salary = salary
}
} else {
salaryEffective = salaryEffectiveRepository.findById(item.id).get()
salaryEffective.apply {
date = item.date
startDate = item.date
this.endDate = endDate
this.staff = staff
this.salary = salary
}
}
salaryEffectiveRepository.save(salaryEffective)
}
}


data class SalaryData(val idInStaff: Long, val staffId: String, val financialYear: LocalDate, val hourlyRate: BigDecimal, val salaryPoint: Int)
data class StaffSalaryData(val staffId: String, val salaryData: List<SalaryData>)



+ 10
- 2
src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt Ver ficheiro

@@ -7,6 +7,7 @@ import com.ffii.tsms.modules.common.SecurityUtils
import com.ffii.tsms.modules.data.entity.*
import com.ffii.tsms.modules.data.entity.projections.StaffSearchInfo
import com.ffii.tsms.modules.data.web.models.NewStaffRequest
import com.ffii.tsms.modules.data.web.models.SalaryEffectiveInfo
import com.ffii.tsms.modules.user.entity.User
import com.ffii.tsms.modules.user.entity.UserRepository
import org.springframework.security.core.GrantedAuthority
@@ -199,7 +200,8 @@ open class StaffsService(
val company = companyRepository.findById(req.companyId).orElseThrow()
val grade = gradeRepository.findById(req.gradeId).orElseThrow()
val team = if (req.teamId != null && req.teamId > 0L) teamRepository.findById(req.teamId).orElseThrow() else null
val salary = salaryRepository.findBySalaryPoint(req.salaryId).orElseThrow()
val salaryPoint = checkLatestSalaryPoint(req?.salaryEffectiveInfo) ?: 0
val salary = salaryRepository.findBySalaryPoint(salaryPoint).orElseThrow()
val department = if (req.departmentId != null && req.departmentId > 0L) departmentRepository.findById(req.departmentId).orElseThrow() else null

staff.apply {
@@ -224,7 +226,8 @@ open class StaffsService(
this.department = department
}

salaryEffectiveService.saveSalaryEffective(staff.id!!, salary.salaryPoint.toLong())
// salaryEffectiveService.saveSalaryEffective(staff.id!!, salary.salaryPoint.toLong())
// salaryEffectiveService.updateSalaryEffective(staff.id!!, req.salaryEffectiveInfo?.sortedBy { it.date })

return staffRepository.save(staff)
}
@@ -259,4 +262,9 @@ open class StaffsService(
open fun currentAuthorities(): Collection<GrantedAuthority>? {
return SecurityUtils.getUser().getOrNull()?.authorities
}

open fun checkLatestSalaryPoint(salaryEffectInfo: List<SalaryEffectiveInfo>?): Long?{
val latestSalaryPoint = salaryEffectInfo?.maxByOrNull { it.date }?.salaryPoint
return latestSalaryPoint
}
}

+ 7
- 0
src/main/java/com/ffii/tsms/modules/data/web/SalaryEffectiveController.kt Ver ficheiro

@@ -3,6 +3,8 @@ package com.ffii.tsms.modules.data.web
import com.ffii.core.response.RecordsRes
import com.ffii.core.utils.CriteriaArgsBuilder
import com.ffii.tsms.modules.data.service.SalaryEffectiveService
import com.ffii.tsms.modules.data.web.models.SalaryEffectiveInfo
import com.ffii.tsms.modules.data.web.models.SalaryEffectiveInfoResponse
import jakarta.servlet.http.HttpServletRequest
import jakarta.validation.Valid
import org.springframework.web.bind.ServletRequestBindingException
@@ -18,6 +20,11 @@ class SalaryEffectiveController(private val salaryEffectiveService: SalaryEffect
fun test(@RequestParam startDate: LocalDate, @RequestParam endDate: LocalDate): List<SalaryEffectiveService.MonthlyStaffSalaryData> {
return salaryEffectiveService.getMonthlyStaffSalaryData(startDate, endDate)
}

@GetMapping
fun test2(@RequestParam staffId: Long): List<SalaryEffectiveInfoResponse> {
return salaryEffectiveService.findSalaryEffectiveInfoByStaffId(staffId)
}
// @GetMapping("/combo")
// @Throws(ServletRequestBindingException::class)
// fun combo(request: HttpServletRequest?): RecordsRes<Map<String, Any>> {


+ 1
- 0
src/main/java/com/ffii/tsms/modules/data/web/StaffsController.kt Ver ficheiro

@@ -59,6 +59,7 @@ class StaffsController(private val staffsService: StaffsService) {
}
@PostMapping("/save")
fun saveStaff(@Valid @RequestBody newStaff: NewStaffRequest): Staff {
println("---------------------------------------------------------")
return staffsService.saveOrUpdate(newStaff)
}
}

+ 8
- 0
src/main/java/com/ffii/tsms/modules/data/web/models/NewStaffRequest.kt Ver ficheiro

@@ -1,5 +1,6 @@
package com.ffii.tsms.modules.data.web.models

import com.ffii.tsms.modules.report.service.ReportService
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
import java.time.LocalDate
@@ -36,4 +37,11 @@ data class NewStaffRequest(
val departDate: LocalDate?,
val departReason: String?,
val remark: String?,
val salaryEffectiveInfo: List<SalaryEffectiveInfo>?
)

data class SalaryEffectiveInfo(
val id: Long,
val salaryPoint: Long,
val date: LocalDate
)

+ 12
- 0
src/main/java/com/ffii/tsms/modules/data/web/models/SalaryEffectiveResponse.kt Ver ficheiro

@@ -0,0 +1,12 @@
package com.ffii.tsms.modules.data.web.models

import org.hibernate.query.spi.Limit
import java.time.LocalDate

data class SalaryEffectiveInfoResponse (
val id: Long,
val salaryPoint: Long,
val lowerLimit: Int,
val upperLimit: Int,
val date: LocalDate
)

Carregando…
Cancelar
Guardar