| @@ -2,5 +2,10 @@ package com.ffii.tsms.modules.data.entity; | |||||
| import com.ffii.core.support.AbstractRepository; | import com.ffii.core.support.AbstractRepository; | ||||
| import com.ffii.tsms.modules.data.entity.projections.StaffSearchInfo; | |||||
| import java.util.List; | |||||
| public interface StaffRepository extends AbstractRepository<Staff, Long> { | public interface StaffRepository extends AbstractRepository<Staff, Long> { | ||||
| List<StaffSearchInfo> findStaffSearchInfoBy(); | |||||
| } | } | ||||
| @@ -0,0 +1,22 @@ | |||||
| package com.ffii.tsms.modules.data.entity.projections | |||||
| import org.springframework.beans.factory.annotation.Value | |||||
| /** | |||||
| * Projection for {@link com.ffii.tsms.modules.data.entity.Staff} | |||||
| */ | |||||
| interface StaffSearchInfo { | |||||
| val id: Long? | |||||
| val staffId: String? | |||||
| val name: String? | |||||
| @get:Value("#{target.team.code}") | |||||
| val team: String? | |||||
| @get:Value("#{target.grade.name}") | |||||
| val grade: String? | |||||
| @get:Value("#{target.currentPosition.name}") | |||||
| val currentPosition: String? | |||||
| } | |||||
| @@ -10,6 +10,7 @@ import com.ffii.tsms.modules.data.entity.TeamRepository | |||||
| import com.ffii.tsms.modules.data.entity.SkillRepository | import com.ffii.tsms.modules.data.entity.SkillRepository | ||||
| import com.ffii.tsms.modules.data.entity.SalaryEffectiveRepository | import com.ffii.tsms.modules.data.entity.SalaryEffectiveRepository | ||||
| import com.ffii.tsms.modules.data.entity.DepartmentRepository | import com.ffii.tsms.modules.data.entity.DepartmentRepository | ||||
| import com.ffii.tsms.modules.data.entity.projections.StaffSearchInfo | |||||
| import com.ffii.tsms.modules.project.web.models.NewStaffRequest | import com.ffii.tsms.modules.project.web.models.NewStaffRequest | ||||
| // import com.ffii.tsms.modules.data.web.models.NewStaffRequest | // import com.ffii.tsms.modules.data.web.models.NewStaffRequest | ||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
| @@ -35,18 +36,26 @@ public final class StaffsService( | |||||
| return staffRepository.findAll() | return staffRepository.findAll() | ||||
| } | } | ||||
| fun fetchStaffList(args: Map<String, Any>): List<Map<String, Any>> { | |||||
| val sql = StringBuilder("select" | |||||
| + " s.*," | |||||
| + " date_format(s.created, '%Y-%m-%d') as created," | |||||
| + " date_format(s.departDate, '%Y-%m-%d') as departDate," | |||||
| + " date_format(s.joinDate, '%Y-%m-%d') as joinDate" | |||||
| + " from staff s" | |||||
| + " where s.deleted = false" | |||||
| ) | |||||
| return jdbcDao.queryForList(sql.toString(), args) | |||||
| fun allStaff(): List<StaffSearchInfo> { | |||||
| return staffRepository.findStaffSearchInfoBy(); | |||||
| } | } | ||||
| // fun fetchStaffList(args: Map<String, Any>): List<Map<String, Any>> { | |||||
| // val sql = StringBuilder("select" | |||||
| // + " s.*," | |||||
| // + " date_format(s.created, '%Y-%m-%d') as created," | |||||
| // + " date_format(s.departDate, '%Y-%m-%d') as departDate," | |||||
| // + " date_format(s.joinDate, '%Y-%m-%d') as joinDate" | |||||
| // + " from staff s" | |||||
| // + " where s.deleted = false" | |||||
| // ) | |||||
| // if (args != null) { | |||||
| // if (args.containsKey("staffId")) | |||||
| // sql.append(" AND s.staffId = :staffId "); | |||||
| // } | |||||
| // return jdbcDao.queryForList(sql.toString(), args) | |||||
| // } | |||||
| fun saveStaff(req: NewStaffRequest): Staff { | fun saveStaff(req: NewStaffRequest): Staff { | ||||
| val user = userRepository.findById(req.userId).orElseThrow() | val user = userRepository.findById(req.userId).orElseThrow() | ||||
| val currentPosition = positionRepository.findById(req.currentPositionId).orElseThrow() | val currentPosition = positionRepository.findById(req.currentPositionId).orElseThrow() | ||||
| @@ -8,13 +8,13 @@ import org.springframework.web.bind.annotation.RestController | |||||
| import org.springframework.web.bind.annotation.PostMapping | import org.springframework.web.bind.annotation.PostMapping | ||||
| import org.springframework.web.bind.annotation.RequestBody | import org.springframework.web.bind.annotation.RequestBody | ||||
| import com.ffii.tsms.modules.project.web.models.NewStaffRequest | import com.ffii.tsms.modules.project.web.models.NewStaffRequest | ||||
| // import com.ffii.tsms.modules.data.web.models.NewStaffRequest | |||||
| import jakarta.validation.Valid | import jakarta.validation.Valid | ||||
| import org.springframework.web.bind.annotation.* | import org.springframework.web.bind.annotation.* | ||||
| import jakarta.servlet.http.HttpServletRequest; | import jakarta.servlet.http.HttpServletRequest; | ||||
| import com.ffii.core.utils.CriteriaArgsBuilder; | import com.ffii.core.utils.CriteriaArgsBuilder; | ||||
| import com.ffii.core.response.IdRes; | import com.ffii.core.response.IdRes; | ||||
| import com.ffii.core.response.RecordsRes; | import com.ffii.core.response.RecordsRes; | ||||
| import com.ffii.tsms.modules.data.entity.projections.StaffSearchInfo | |||||
| @RestController | @RestController | ||||
| @RequestMapping("/staffs") | @RequestMapping("/staffs") | ||||
| @@ -23,7 +23,10 @@ class StaffsController(private val staffsService: StaffsService) { | |||||
| fun teamLeads(): List<Staff> { | fun teamLeads(): List<Staff> { | ||||
| return staffsService.getTeamLeads() | return staffsService.getTeamLeads() | ||||
| } | } | ||||
| @GetMapping | |||||
| fun allStaff(): List<StaffSearchInfo> { | |||||
| return staffsService.allStaff() | |||||
| } | |||||
| @GetMapping("/list") | @GetMapping("/list") | ||||
| fun list(): List<Staff> { | fun list(): List<Staff> { | ||||
| return staffsService.getTeamLeads() | return staffsService.getTeamLeads() | ||||
| @@ -34,11 +37,12 @@ class StaffsController(private val staffsService: StaffsService) { | |||||
| return staffsService.saveStaff(newStaff) | return staffsService.saveStaff(newStaff) | ||||
| } | } | ||||
| @GetMapping("/newlist") | |||||
| fun list(request: HttpServletRequest): RecordsRes<Map<String, Any>> { | |||||
| return RecordsRes(staffsService.fetchStaffList( | |||||
| CriteriaArgsBuilder.withRequest(request) | |||||
| .build() | |||||
| )) | |||||
| } | |||||
| // @GetMapping("/newlist") | |||||
| // fun list(request: HttpServletRequest): RecordsRes<Map<String, Any>> { | |||||
| // return RecordsRes(staffsService.fetchStaffList( | |||||
| // CriteriaArgsBuilder.withRequest(request) | |||||
| // .addString("staffId") | |||||
| // .build() | |||||
| // )) | |||||
| // } | |||||
| } | } | ||||