@@ -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.SalaryRepository | ||||
import com.ffii.tsms.modules.data.entity.Staff | import com.ffii.tsms.modules.data.entity.Staff | ||||
import com.ffii.tsms.modules.data.entity.StaffRepository | 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 org.springframework.stereotype.Service | ||||
import java.math.BigDecimal | import java.math.BigDecimal | ||||
import java.time.LocalDate | import java.time.LocalDate | ||||
@@ -44,6 +46,23 @@ open class SalaryEffectiveService( | |||||
return if(result > 0) result.toLong() else -1 | 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? { | open fun saveSalaryEffective (staffId: Long, salaryId: Long): SalaryEffective? { | ||||
// val existSalaryEffective = findByStaffIdAndSalaryId(staffId, salaryId) | // val existSalaryEffective = findByStaffIdAndSalaryId(staffId, salaryId) | ||||
// | // | ||||
@@ -62,6 +81,8 @@ open class SalaryEffectiveService( | |||||
val salary = salaryRepository.findBySalaryPoint(salaryId).orElseThrow() | val salary = salaryRepository.findBySalaryPoint(salaryId).orElseThrow() | ||||
val salaryEffective = SalaryEffective().apply { | val salaryEffective = SalaryEffective().apply { | ||||
date = LocalDate.now() | date = LocalDate.now() | ||||
startDate = LocalDate.now() | |||||
endDate = LocalDate.of(2124, 1, 1) | |||||
this.staff = staff | this.staff = staff | ||||
this.salary = salary | this.salary = salary | ||||
} | } | ||||
@@ -71,6 +92,42 @@ open class SalaryEffectiveService( | |||||
return salaryEffective | 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 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>) | data class StaffSalaryData(val staffId: String, val salaryData: List<SalaryData>) | ||||
@@ -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.* | ||||
import com.ffii.tsms.modules.data.entity.projections.StaffSearchInfo | 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.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.User | ||||
import com.ffii.tsms.modules.user.entity.UserRepository | import com.ffii.tsms.modules.user.entity.UserRepository | ||||
import org.springframework.security.core.GrantedAuthority | import org.springframework.security.core.GrantedAuthority | ||||
@@ -199,7 +200,8 @@ open class StaffsService( | |||||
val company = companyRepository.findById(req.companyId).orElseThrow() | val company = companyRepository.findById(req.companyId).orElseThrow() | ||||
val grade = gradeRepository.findById(req.gradeId).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 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 | val department = if (req.departmentId != null && req.departmentId > 0L) departmentRepository.findById(req.departmentId).orElseThrow() else null | ||||
staff.apply { | staff.apply { | ||||
@@ -224,7 +226,8 @@ open class StaffsService( | |||||
this.department = department | 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) | return staffRepository.save(staff) | ||||
} | } | ||||
@@ -259,4 +262,9 @@ open class StaffsService( | |||||
open fun currentAuthorities(): Collection<GrantedAuthority>? { | open fun currentAuthorities(): Collection<GrantedAuthority>? { | ||||
return SecurityUtils.getUser().getOrNull()?.authorities | return SecurityUtils.getUser().getOrNull()?.authorities | ||||
} | } | ||||
open fun checkLatestSalaryPoint(salaryEffectInfo: List<SalaryEffectiveInfo>?): Long?{ | |||||
val latestSalaryPoint = salaryEffectInfo?.maxByOrNull { it.date }?.salaryPoint | |||||
return latestSalaryPoint | |||||
} | |||||
} | } |
@@ -3,6 +3,8 @@ package com.ffii.tsms.modules.data.web | |||||
import com.ffii.core.response.RecordsRes | import com.ffii.core.response.RecordsRes | ||||
import com.ffii.core.utils.CriteriaArgsBuilder | import com.ffii.core.utils.CriteriaArgsBuilder | ||||
import com.ffii.tsms.modules.data.service.SalaryEffectiveService | 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.servlet.http.HttpServletRequest | ||||
import jakarta.validation.Valid | import jakarta.validation.Valid | ||||
import org.springframework.web.bind.ServletRequestBindingException | 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> { | fun test(@RequestParam startDate: LocalDate, @RequestParam endDate: LocalDate): List<SalaryEffectiveService.MonthlyStaffSalaryData> { | ||||
return salaryEffectiveService.getMonthlyStaffSalaryData(startDate, endDate) | return salaryEffectiveService.getMonthlyStaffSalaryData(startDate, endDate) | ||||
} | } | ||||
@GetMapping | |||||
fun test2(@RequestParam staffId: Long): List<SalaryEffectiveInfoResponse> { | |||||
return salaryEffectiveService.findSalaryEffectiveInfoByStaffId(staffId) | |||||
} | |||||
// @GetMapping("/combo") | // @GetMapping("/combo") | ||||
// @Throws(ServletRequestBindingException::class) | // @Throws(ServletRequestBindingException::class) | ||||
// fun combo(request: HttpServletRequest?): RecordsRes<Map<String, Any>> { | // fun combo(request: HttpServletRequest?): RecordsRes<Map<String, Any>> { | ||||
@@ -59,6 +59,7 @@ class StaffsController(private val staffsService: StaffsService) { | |||||
} | } | ||||
@PostMapping("/save") | @PostMapping("/save") | ||||
fun saveStaff(@Valid @RequestBody newStaff: NewStaffRequest): Staff { | fun saveStaff(@Valid @RequestBody newStaff: NewStaffRequest): Staff { | ||||
println("---------------------------------------------------------") | |||||
return staffsService.saveOrUpdate(newStaff) | return staffsService.saveOrUpdate(newStaff) | ||||
} | } | ||||
} | } |
@@ -1,5 +1,6 @@ | |||||
package com.ffii.tsms.modules.data.web.models | 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.NotBlank | ||||
import jakarta.validation.constraints.NotNull | import jakarta.validation.constraints.NotNull | ||||
import java.time.LocalDate | import java.time.LocalDate | ||||
@@ -36,4 +37,11 @@ data class NewStaffRequest( | |||||
val departDate: LocalDate?, | val departDate: LocalDate?, | ||||
val departReason: String?, | val departReason: String?, | ||||
val remark: String?, | val remark: String?, | ||||
val salaryEffectiveInfo: List<SalaryEffectiveInfo>? | |||||
) | |||||
data class SalaryEffectiveInfo( | |||||
val id: Long, | |||||
val salaryPoint: Long, | |||||
val date: LocalDate | |||||
) | ) |
@@ -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 | |||||
) |