diff --git a/src/main/java/com/ffii/tsms/modules/data/entity/StaffSkillsetRepository.java b/src/main/java/com/ffii/tsms/modules/data/entity/StaffSkillsetRepository.java index f99a39a..86f2c50 100644 --- a/src/main/java/com/ffii/tsms/modules/data/entity/StaffSkillsetRepository.java +++ b/src/main/java/com/ffii/tsms/modules/data/entity/StaffSkillsetRepository.java @@ -1,6 +1,11 @@ package com.ffii.tsms.modules.data.entity; import com.ffii.core.support.AbstractRepository; +import org.springframework.data.repository.query.Param; + +import java.util.List; public interface StaffSkillsetRepository extends AbstractRepository { + + List findByStaff(@Param("staff") Staff staff); } \ No newline at end of file diff --git a/src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt b/src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt index aaefa49..00075f3 100644 --- a/src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt +++ b/src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt @@ -95,7 +95,6 @@ open class StaffsService( @Transactional(rollbackFor = [Exception::class]) open fun saveStaff(req: NewStaffRequest): Staff { -// if (req.staffId) val checkStaffIdList: List = staffRepository.findStaffSearchInfoByAndDeletedFalse() checkStaffIdList.forEach{ s -> if (s.staffId == req.staffId) { @@ -158,31 +157,31 @@ open class StaffsService( staffSkillsetRepository.save(ss) } } - -// val skillBatchInsertValues: MutableList> -// if (!req.skillSetId.isNullOrEmpty()) { -// skillBatchInsertValues = req.skillSetId.stream() -// .map { skillId -> mutableMapOf(("staffId" to staff.id) as Pair, "skillId" to skillId) } -// .collect(Collectors.toList()) -// jdbcDao.batchUpdate( -// "INSERT IGNORE INTO staff_skillset (staffId, skillId)" -// + " VALUES (:staffId, :skillId)", -// skillBatchInsertValues); -// } - salaryEffectiveService.saveSalaryEffective(staff.id!!, salary.id!!) return staff } @Transactional(rollbackFor = [Exception::class]) open fun updateStaff(req: NewStaffRequest, staff: Staff): Staff { + val args = java.util.Map.of("staffId", staff.id) + if(!req.skillSetId.isNullOrEmpty()) { + // remove all skills of the staff + jdbcDao.executeUpdate("DELETE FROM staff_skillset WHERE staffId = :staffId", args); + // add skiils + for (skillId in req.skillSetId) { + val skill = skillRepository.findById(skillId).orElseThrow() + val ss = StaffSkillset().apply { + this.staff = staff + this.skill = skill + } + staffSkillsetRepository.save(ss) + } + } val currentPosition = positionRepository.findById(req.currentPositionId).orElseThrow() val joinPosition = positionRepository.findById(req.joinPositionId).orElseThrow() val company = companyRepository.findById(req.companyId).orElseThrow() val grade = if (req.gradeId != null && req.gradeId > 0L) gradeRepository.findById(req.gradeId).orElseThrow() else null val team = if (req.teamId != null && req.teamId > 0L) teamRepository.findById(req.teamId).orElseThrow() else null -// val skill = if (req.skillSetId != null && req.skillSetId > 0L) skillRepository.findById(req.skillSetId).orElseThrow() else null val salary = salaryRepository.findById(req.salaryId).orElseThrow() -// val salaryEffective = salaryEffectiveRepository.findById(req.salaryEffId).orElseThrow() val department = departmentRepository.findById(req.departmentId).orElseThrow() staff.apply { @@ -203,7 +202,6 @@ open class StaffsService( this.company = company this.grade = grade this.team = team -// this.skill = skill this.salary = salary this.department = department }