|
|
@@ -7,6 +7,7 @@ import com.ffii.tsms.modules.common.SecurityUtils |
|
|
|
import com.ffii.tsms.modules.data.entity.* |
|
|
|
import com.ffii.tsms.modules.data.entity.projections.StaffSearchInfo |
|
|
|
import com.ffii.tsms.modules.data.web.models.NewStaffRequest |
|
|
|
import com.ffii.tsms.modules.data.web.models.NewStaffResponse |
|
|
|
import com.ffii.tsms.modules.data.web.models.SalaryEffectiveInfo |
|
|
|
import com.ffii.tsms.modules.user.entity.User |
|
|
|
import com.ffii.tsms.modules.user.entity.UserRepository |
|
|
@@ -130,11 +131,17 @@ open class StaffsService( |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
|
open fun saveStaff(req: NewStaffRequest): Staff { |
|
|
|
open fun saveStaff(req: NewStaffRequest): NewStaffResponse { |
|
|
|
val checkStaffIdList: List<StaffSearchInfo> = staffRepository.findStaffSearchInfoByAndDeletedFalseOrderByStaffIdAsc() |
|
|
|
checkStaffIdList.forEach{ s -> |
|
|
|
if (s.staffId == req.staffId) { |
|
|
|
throw UnprocessableEntityException("Duplicated StaffId Found") |
|
|
|
return NewStaffResponse( |
|
|
|
id = null, |
|
|
|
name = req.name, |
|
|
|
staffId = req.staffId, |
|
|
|
message = "duplicated staff ID found", |
|
|
|
errorPosition = "code", |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
// val currentPosition = positionRepository.findById(req.currentPositionId).orElseThrow() |
|
|
@@ -188,7 +195,7 @@ open class StaffsService( |
|
|
|
this.department = department |
|
|
|
} |
|
|
|
|
|
|
|
staffRepository.saveAndFlush(staff) |
|
|
|
val savedStaff = staffRepository.saveAndFlush(staff) |
|
|
|
if (!req.skillSetId.isNullOrEmpty()) { |
|
|
|
for (skillId in req.skillSetId) { |
|
|
|
val skill = skillRepository.findById(skillId).orElseThrow() |
|
|
@@ -213,10 +220,28 @@ open class StaffsService( |
|
|
|
positionLogService.savePositionLogs(staff, req.positionHistory) |
|
|
|
} |
|
|
|
|
|
|
|
return staff |
|
|
|
return NewStaffResponse( |
|
|
|
id = savedStaff.id, |
|
|
|
name = savedStaff.name, |
|
|
|
staffId = savedStaff.staffId, |
|
|
|
message = null, |
|
|
|
errorPosition = null, |
|
|
|
) |
|
|
|
} |
|
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
|
open fun updateStaff(req: NewStaffRequest, staff: Staff): Staff { |
|
|
|
open fun updateStaff(req: NewStaffRequest, staff: Staff): NewStaffResponse { |
|
|
|
val checkStaffIdList: List<StaffSearchInfo> = staffRepository.findStaffSearchInfoByAndDeletedFalseOrderByStaffIdAsc() |
|
|
|
checkStaffIdList.forEach{ s -> |
|
|
|
if (s.id !== req.id && s.staffId == req.staffId) { |
|
|
|
return NewStaffResponse( |
|
|
|
id = null, |
|
|
|
name = req.name, |
|
|
|
staffId = req.staffId, |
|
|
|
message = "duplicated staff ID found", |
|
|
|
errorPosition = "code", |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
val args = java.util.Map.of<String, Any>("staffId", staff.id) |
|
|
|
if(!req.skillSetId.isNullOrEmpty()) { |
|
|
|
// remove all skills of the staff |
|
|
@@ -298,26 +323,24 @@ open class StaffsService( |
|
|
|
if (req.salaryEffectiveInfo != null && req.delSalaryEffectiveInfo != null) { |
|
|
|
salaryEffectiveService.updateSalaryEffective(staff.id!!, req.salaryEffectiveInfo.sortedBy { it.date }, req.delSalaryEffectiveInfo) |
|
|
|
} |
|
|
|
// else if (req.teamHistory != null && req.delTeamHistory != null) { |
|
|
|
// teamLogService.editTeamLog(req.teamHistory, req.delTeamHistory) |
|
|
|
// } else if (req.gradeHistory != null && req.delGradeHistory != null) { |
|
|
|
// gradeLogService.editGradeLog(req.gradeHistory, req.delGradeHistory) |
|
|
|
// } else if (req.positionHistory != null && req.delPositionHistory != null) { |
|
|
|
// positionLogService.editPositionLog(req.positionHistory, req.delPositionHistory) |
|
|
|
// } |
|
|
|
|
|
|
|
return staffRepository.save(staff) |
|
|
|
val savedStaff = staffRepository.saveAndFlush(staff) |
|
|
|
return NewStaffResponse( |
|
|
|
id = savedStaff.id, |
|
|
|
name = savedStaff.name, |
|
|
|
staffId = savedStaff.staffId, |
|
|
|
message = null, |
|
|
|
errorPosition = null, |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
|
open fun saveOrUpdate(req: NewStaffRequest): Staff { |
|
|
|
open fun saveOrUpdate(req: NewStaffRequest): NewStaffResponse { |
|
|
|
val staff = if(req.id != null) find(req.id).get() else Staff() |
|
|
|
if (req.id != null) { |
|
|
|
updateStaff(req, staff) |
|
|
|
return updateStaff(req, staff) |
|
|
|
} else { |
|
|
|
saveStaff(req) |
|
|
|
return saveStaff(req) |
|
|
|
} |
|
|
|
return staff; |
|
|
|
} |
|
|
|
|
|
|
|
open fun combo(args: Map<String, Any>): List<Map<String, Any>> { |
|
|
|