|
|
@@ -34,6 +34,7 @@ open class TeamService( |
|
|
|
val team = Team().apply { |
|
|
|
name = teamName |
|
|
|
code = teamCode |
|
|
|
description = req.description |
|
|
|
} |
|
|
|
teamRepository.saveAndFlush(team) |
|
|
|
for (id in ids) { |
|
|
@@ -46,6 +47,61 @@ open class TeamService( |
|
|
|
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>> { |
|
|
|
val sql = StringBuilder("select" |
|
|
|
+ " t.id as id," |
|
|
|