| @@ -3,10 +3,12 @@ package com.ffii.tsms.config.security.jwt.web; | |||||
| import java.time.Instant; | import java.time.Instant; | ||||
| import java.util.HashSet; | import java.util.HashSet; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.Objects; | |||||
| import java.util.Set; | import java.util.Set; | ||||
| 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.service.StaffsService; | |||||
| import com.ffii.tsms.modules.user.service.GroupService; | import com.ffii.tsms.modules.user.service.GroupService; | ||||
| import org.apache.commons.lang3.exception.ExceptionUtils; | import org.apache.commons.lang3.exception.ExceptionUtils; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -58,6 +60,9 @@ public class JwtAuthenticationController { | |||||
| @Autowired | @Autowired | ||||
| private GroupService groupService; | private GroupService groupService; | ||||
| @Autowired | |||||
| private StaffsService staffsService; | |||||
| @Autowired | @Autowired | ||||
| private StaffRepository staffRepository; | private StaffRepository staffRepository; | ||||
| @@ -102,7 +107,7 @@ public class JwtAuthenticationController { | |||||
| final Map<String, Object> args = Map.of("userId", user.getId()); | final Map<String, Object> args = Map.of("userId", user.getId()); | ||||
| final String role = groupService.getGroupName(args); | final String role = groupService.getGroupName(args); | ||||
| final Staff staff = staffRepository.findIdAndNameByUserIdAndDeletedFalse(user.getId()).orElse(null); | |||||
| final Map<String, Object> staff = Objects.requireNonNull(staffsService.getCurrentStaff(user.getId())).orElse(null); | |||||
| Set<AbilityModel> abilities = new HashSet<>(); | Set<AbilityModel> abilities = new HashSet<>(); | ||||
| userAuthorityService.getUserAuthority(user).forEach(auth -> abilities.add(new AbilityModel(auth.getAuthority()))); | userAuthorityService.getUserAuthority(user).forEach(auth -> abilities.add(new AbilityModel(auth.getAuthority()))); | ||||
| @@ -1,6 +1,7 @@ | |||||
| package com.ffii.tsms.model; | package com.ffii.tsms.model; | ||||
| import java.io.Serializable; | import java.io.Serializable; | ||||
| import java.util.Map; | |||||
| import java.util.Set; | import java.util.Set; | ||||
| import com.ffii.tsms.modules.data.entity.Staff; | import com.ffii.tsms.modules.data.entity.Staff; | ||||
| @@ -16,11 +17,9 @@ public class JwtResponse implements Serializable { | |||||
| private final String refreshToken; | private final String refreshToken; | ||||
| private final String role; | private final String role; | ||||
| private final Set<AbilityModel> abilities; | private final Set<AbilityModel> abilities; | ||||
| private final Staff staff; | |||||
| private final Map<String, Object> staff; | |||||
| public JwtResponse(String accessToken, String refreshToken, String role, User user, Set<AbilityModel> abilities, Staff staff) { | |||||
| public JwtResponse(String accessToken, String refreshToken, String role, User user, Set<AbilityModel> abilities, Map<String, Object> staff) { | |||||
| this.accessToken = accessToken; | this.accessToken = accessToken; | ||||
| this.refreshToken = refreshToken; | this.refreshToken = refreshToken; | ||||
| this.role = role; | this.role = role; | ||||
| @@ -55,7 +54,7 @@ public class JwtResponse implements Serializable { | |||||
| return email; | return email; | ||||
| } | } | ||||
| public Staff getStaff() { return staff; } | |||||
| public Map<String, Object> getStaff() { return staff; } | |||||
| public Set<AbilityModel> getAbilities() { | public Set<AbilityModel> getAbilities() { | ||||
| @@ -93,6 +93,27 @@ open class StaffsService( | |||||
| return jdbcDao.queryForMap(sql.toString(), args) | return jdbcDao.queryForMap(sql.toString(), args) | ||||
| } | } | ||||
| open fun getCurrentStaff(userId: Long): Optional<MutableMap<String, Any>>? { | |||||
| val staff = staffRepository.findByUserId(userId).orElse(null) | |||||
| logger.info(staff) | |||||
| if (staff == null) { | |||||
| return Optional.ofNullable(null) | |||||
| } | |||||
| val sql = StringBuilder("select " + | |||||
| " s.id as id, " + | |||||
| " t.id as teamId, " + | |||||
| " case when t.teamLead = s.id then true else false end as isTeamLead " + | |||||
| " from staff s " + | |||||
| " left join team t on t.id = s.teamId " + | |||||
| " where s.deleted = false " | |||||
| + " and s.id = " + staff.id | |||||
| ) | |||||
| return jdbcDao.queryForMap(sql.toString()) | |||||
| } | |||||
| @Transactional(rollbackFor = [Exception::class]) | @Transactional(rollbackFor = [Exception::class]) | ||||
| open fun saveStaff(req: NewStaffRequest): Staff { | open fun saveStaff(req: NewStaffRequest): Staff { | ||||
| val checkStaffIdList: List<StaffSearchInfo> = staffRepository.findStaffSearchInfoByAndDeletedFalse() | val checkStaffIdList: List<StaffSearchInfo> = staffRepository.findStaffSearchInfoByAndDeletedFalse() | ||||