From 75e6e1803563d9e59c6522fed1f20b5dfd61803d Mon Sep 17 00:00:00 2001 From: "cyril.tsui" Date: Fri, 6 Dec 2024 17:46:19 +0800 Subject: [PATCH] update staff search info --- .../modules/data/entity/projections/StaffSearchInfo.kt | 8 +++++++- .../com/ffii/tsms/modules/data/web/StaffsController.kt | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ffii/tsms/modules/data/entity/projections/StaffSearchInfo.kt b/src/main/java/com/ffii/tsms/modules/data/entity/projections/StaffSearchInfo.kt index 8b9b841..901a58d 100644 --- a/src/main/java/com/ffii/tsms/modules/data/entity/projections/StaffSearchInfo.kt +++ b/src/main/java/com/ffii/tsms/modules/data/entity/projections/StaffSearchInfo.kt @@ -1,6 +1,7 @@ package com.ffii.tsms.modules.data.entity.projections import org.springframework.beans.factory.annotation.Value +import java.time.LocalDate /** * Projection for {@link com.ffii.tsms.modules.data.entity.Staff} @@ -9,6 +10,12 @@ interface StaffSearchInfo { val id: Long? val staffId: String? val name: String? + val departDate: LocalDate? + + @get:Value("#{target.departDate == null " + + "|| (target.departDate?.isBefore(T(java.time.LocalDate).now()) == false " + + "&& target.departDate?.isEqual(T(java.time.LocalDate).now()) == false)}") + val active: Boolean? @get:Value("#{target.team?.code}") val team: String? @@ -24,5 +31,4 @@ interface StaffSearchInfo { @get:Value("#{target.user?.id}") val userId: Long? - } diff --git a/src/main/java/com/ffii/tsms/modules/data/web/StaffsController.kt b/src/main/java/com/ffii/tsms/modules/data/web/StaffsController.kt index aa7af12..6898e43 100644 --- a/src/main/java/com/ffii/tsms/modules/data/web/StaffsController.kt +++ b/src/main/java/com/ffii/tsms/modules/data/web/StaffsController.kt @@ -14,6 +14,7 @@ import liquibase.hub.model.Project import org.springframework.http.HttpStatus import org.springframework.web.bind.ServletRequestBindingException import org.springframework.web.bind.annotation.* +import java.time.LocalDate @RestController @@ -25,7 +26,10 @@ class StaffsController(private val staffsService: StaffsService) { } @GetMapping fun allStaff(): List { - return staffsService.allStaff() + return staffsService.allStaff().sortedWith(compareBy( { when (it.active) { + true -> 0 + else -> 1 // false + }}, { it.staffId })) } @GetMapping("/noteam")