@@ -11,6 +11,7 @@ import java.util.Optional; | |||||
public interface StaffRepository extends AbstractRepository<Staff, Long> { | public interface StaffRepository extends AbstractRepository<Staff, Long> { | ||||
List<StaffSearchInfo> findStaffSearchInfoByAndDeletedFalse(); | List<StaffSearchInfo> findStaffSearchInfoByAndDeletedFalse(); | ||||
List<StaffSearchInfo> findStaffSearchInfoByAndDeletedFalseAndTeamIdIsNull(); | |||||
List<StaffSearchInfo> findAllStaffSearchInfoByIdIn(List<Long> ids); | List<StaffSearchInfo> findAllStaffSearchInfoByIdIn(List<Long> ids); | ||||
Optional<Staff> findByStaffId(@Param("staffId") String staffId); | Optional<Staff> findByStaffId(@Param("staffId") String staffId); |
@@ -13,6 +13,9 @@ interface StaffSearchInfo { | |||||
@get:Value("#{target.team?.code}") | @get:Value("#{target.team?.code}") | ||||
val team: String? | val team: String? | ||||
@get:Value("#{target.team?.id}") | |||||
val teamId: Long? | |||||
@get:Value("#{target.grade?.name}") | @get:Value("#{target.grade?.name}") | ||||
val grade: String? | val grade: String? | ||||
@@ -37,6 +37,9 @@ open class StaffsService( | |||||
open fun allStaff(): List<StaffSearchInfo> { | open fun allStaff(): List<StaffSearchInfo> { | ||||
return staffRepository.findStaffSearchInfoByAndDeletedFalse(); | return staffRepository.findStaffSearchInfoByAndDeletedFalse(); | ||||
} | } | ||||
open fun StaffWithoutTeam(): List<StaffSearchInfo> { | |||||
return staffRepository.findStaffSearchInfoByAndDeletedFalseAndTeamIdIsNull(); | |||||
} | |||||
open fun getStaff(id: Long): Staff { | open fun getStaff(id: Long): Staff { | ||||
return staffRepository.findById(id).orElseThrow(); | return staffRepository.findById(id).orElseThrow(); | ||||
@@ -34,6 +34,7 @@ open class TeamService( | |||||
val team = Team().apply { | val team = Team().apply { | ||||
name = teamName | name = teamName | ||||
code = teamCode | code = teamCode | ||||
description = req.description | |||||
} | } | ||||
teamRepository.saveAndFlush(team) | teamRepository.saveAndFlush(team) | ||||
for (id in ids) { | for (id in ids) { | ||||
@@ -46,6 +47,61 @@ open class TeamService( | |||||
return team | return team | ||||
} | } | ||||
@Transactional(rollbackFor = [Exception::class]) | |||||
open fun updateTeam(req: NewTeamRequest, team: Team): Team { | |||||
val ids = req.addStaffIds | |||||
val teamLead = staffRepository.findById(ids[0]).orElseThrow() | |||||
val teamName = "Team " + teamLead.name | |||||
val initials = teamLead.name.split(" ").map { it.first() } | |||||
val teamCode = initials.joinToString("") | |||||
team.apply { | |||||
name = teamName | |||||
code = teamCode | |||||
description = req.description | |||||
} | |||||
for (id in ids) { | |||||
val staff = staffRepository.findById(id).orElseThrow() | |||||
staff.apply { | |||||
this.team = team | |||||
} | |||||
staffRepository.save(staff) | |||||
} | |||||
return team | |||||
} | |||||
open fun saveOrUpdate(req: NewTeamRequest): Team { | |||||
val team = if(req.id != null) find(req.id).get() else Team() | |||||
if (req.id != null) { | |||||
updateTeam(req, team) | |||||
} else { | |||||
saveTeam(req) | |||||
} | |||||
return team | |||||
} | |||||
open fun getTeamDetail(args: Map<String, Any>): List<Map<String, Any>> { | |||||
val sql = StringBuilder("select" | |||||
+ " t.id as teamId, " | |||||
+ " t.name, " | |||||
+ " t.code, " | |||||
+ " t.description, " | |||||
+ " s.id, " | |||||
+ " s.staffId, " | |||||
+ " s.name as staffName, " | |||||
+ " p.name as posLabel, " | |||||
+ " p.code as posCode " | |||||
+ " from team t " | |||||
+ " inner join staff s on s.teamId = t.id " | |||||
+ " inner join position p on p.id = s.currentPosition " | |||||
+ " where t.deleted = false " | |||||
// + " and t.id = :id " | |||||
) | |||||
return jdbcDao.queryForList(sql.toString(), args) | |||||
} | |||||
open fun combo(args: Map<String, Any>): List<Map<String, Any>> { | open fun combo(args: Map<String, Any>): List<Map<String, Any>> { | ||||
val sql = StringBuilder("select" | val sql = StringBuilder("select" | ||||
+ " t.id as id," | + " t.id as id," | ||||
@@ -26,6 +26,11 @@ class StaffsController(private val staffsService: StaffsService) { | |||||
fun allStaff(): List<StaffSearchInfo> { | fun allStaff(): List<StaffSearchInfo> { | ||||
return staffsService.allStaff() | return staffsService.allStaff() | ||||
} | } | ||||
@GetMapping("/noteam") | |||||
fun StaffWithoutTeam(): List<StaffSearchInfo> { | |||||
return staffsService.StaffWithoutTeam() | |||||
} | |||||
// @GetMapping("/list") | // @GetMapping("/list") | ||||
// fun list(): List<Staff> { | // fun list(): List<Staff> { | ||||
// return staffsService.getTeamLeads() | // return staffsService.getTeamLeads() | ||||
@@ -2,11 +2,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.entity.Staff | |||||
import com.ffii.tsms.modules.data.entity.Team | import com.ffii.tsms.modules.data.entity.Team | ||||
import com.ffii.tsms.modules.data.entity.projections.StaffSearchInfo | |||||
import com.ffii.tsms.modules.data.service.TeamService | import com.ffii.tsms.modules.data.service.TeamService | ||||
import com.ffii.tsms.modules.data.web.models.NewStaffRequest | |||||
import com.ffii.tsms.modules.data.web.models.NewTeamRequest | import com.ffii.tsms.modules.data.web.models.NewTeamRequest | ||||
import jakarta.servlet.http.HttpServletRequest | import jakarta.servlet.http.HttpServletRequest | ||||
import jakarta.validation.Valid | import jakarta.validation.Valid | ||||
@@ -25,7 +22,14 @@ class TeamController(private val teamService: TeamService) { | |||||
@PostMapping("/save") | @PostMapping("/save") | ||||
fun saveStaff(@Valid @RequestBody newTeam: NewTeamRequest): Team { | fun saveStaff(@Valid @RequestBody newTeam: NewTeamRequest): Team { | ||||
return teamService.saveTeam(newTeam) | |||||
return teamService.saveOrUpdate(newTeam) | |||||
} | |||||
@GetMapping("/detail") | |||||
fun getTeamDetail(): List<Map<String, Any>> { | |||||
val args: MutableMap<String, Any> = HashMap() | |||||
// args["id"] = id; | |||||
return teamService.getTeamDetail(args); | |||||
} | } | ||||
@GetMapping("/combo") | @GetMapping("/combo") | ||||
@@ -0,0 +1,9 @@ | |||||
package com.ffii.tsms.modules.data.web.models | |||||
import com.ffii.tsms.modules.data.entity.Staff | |||||
data class NewStaffResponse ( | |||||
val staff: Staff, | |||||
val message: String, | |||||
) |
@@ -0,0 +1,19 @@ | |||||
package com.ffii.tsms.modules.project.web.models | |||||
import jakarta.validation.constraints.NotBlank | |||||
data class NewSubsidiaryRequest( | |||||
@field:NotBlank(message = "subsidary code cannot be empty") | |||||
val code: String, | |||||
@field:NotBlank(message = "subsidary name cannot be empty") | |||||
val name: String, | |||||
val brNo: String, | |||||
val contactName: String, | |||||
val phone: String, | |||||
val address: String, | |||||
val district: String, | |||||
val email: String, | |||||
val allocatedCustomerIds: List<Long>, | |||||
) |
@@ -6,5 +6,8 @@ import java.time.LocalDate | |||||
data class NewTeamRequest ( | data class NewTeamRequest ( | ||||
@field:NotNull(message = "ids cannot be empty") | @field:NotNull(message = "ids cannot be empty") | ||||
val addStaffIds: List<Long> | |||||
val addStaffIds: List<Long>, | |||||
val deleteStaffIds: List<Long>?, | |||||
val description: String, | |||||
val id: Long? | |||||
) | ) |