|
@@ -7,10 +7,12 @@ 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.NewStaffRequest |
|
|
import com.ffii.tsms.modules.user.entity.User |
|
|
import com.ffii.tsms.modules.user.entity.User |
|
|
import com.ffii.tsms.modules.user.entity.UserRepository |
|
|
import com.ffii.tsms.modules.user.entity.UserRepository |
|
|
|
|
|
import org.springframework.data.jpa.domain.AbstractPersistable_.id |
|
|
import org.springframework.security.crypto.password.PasswordEncoder |
|
|
import org.springframework.security.crypto.password.PasswordEncoder |
|
|
import org.springframework.stereotype.Service |
|
|
import org.springframework.stereotype.Service |
|
|
import org.springframework.transaction.annotation.Transactional |
|
|
import org.springframework.transaction.annotation.Transactional |
|
|
import java.util.* |
|
|
import java.util.* |
|
|
|
|
|
import java.util.stream.Collectors |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
@@ -26,6 +28,7 @@ open class StaffsService( |
|
|
private val salaryEffectiveRepository: SalaryEffectiveRepository, |
|
|
private val salaryEffectiveRepository: SalaryEffectiveRepository, |
|
|
private val salaryEffectiveService: SalaryEffectiveService, |
|
|
private val salaryEffectiveService: SalaryEffectiveService, |
|
|
private val departmentRepository: DepartmentRepository, |
|
|
private val departmentRepository: DepartmentRepository, |
|
|
|
|
|
private val staffSkillsetRepository: StaffSkillsetRepository, |
|
|
private val jdbcDao: JdbcDao, |
|
|
private val jdbcDao: JdbcDao, |
|
|
private val passwordEncoder: PasswordEncoder |
|
|
private val passwordEncoder: PasswordEncoder |
|
|
) : AbstractBaseEntityService<Staff, Long, StaffRepository>(jdbcDao, staffRepository) { |
|
|
) : AbstractBaseEntityService<Staff, Long, StaffRepository>(jdbcDao, staffRepository) { |
|
@@ -78,6 +81,16 @@ open class StaffsService( |
|
|
return staffRepository.findAllByTeamIdAndDeletedFalse(id); |
|
|
return staffRepository.findAllByTeamIdAndDeletedFalse(id); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open fun getStaff(args: Map<String, Any>): Optional<MutableMap<String, Any>>? { |
|
|
|
|
|
val sql = StringBuilder("select" |
|
|
|
|
|
+ " s.id as id," |
|
|
|
|
|
+ " s.name as label" |
|
|
|
|
|
+ " from staff s" |
|
|
|
|
|
+ " where s.deleted = :false " |
|
|
|
|
|
) |
|
|
|
|
|
return jdbcDao.queryForMap(sql.toString(), args) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
open fun saveStaff(req: NewStaffRequest): Staff { |
|
|
open fun saveStaff(req: NewStaffRequest): Staff { |
|
|
val currentPosition = positionRepository.findById(req.currentPositionId).orElseThrow() |
|
|
val currentPosition = positionRepository.findById(req.currentPositionId).orElseThrow() |
|
@@ -85,7 +98,6 @@ open class StaffsService( |
|
|
val company = companyRepository.findById(req.companyId).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 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 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 salary = salaryRepository.findById(req.salaryId).orElseThrow() |
|
|
// val salaryEffective = salaryEffectiveRepository.findById(req.salaryEffId).orElseThrow() |
|
|
// val salaryEffective = salaryEffectiveRepository.findById(req.salaryEffId).orElseThrow() |
|
|
val department = departmentRepository.findById(req.departmentId).orElseThrow() |
|
|
val department = departmentRepository.findById(req.departmentId).orElseThrow() |
|
@@ -121,12 +133,33 @@ open class StaffsService( |
|
|
this.company = company |
|
|
this.company = company |
|
|
this.grade = grade |
|
|
this.grade = grade |
|
|
this.team = team |
|
|
this.team = team |
|
|
this.skill = skill |
|
|
|
|
|
|
|
|
// this.skill = skill |
|
|
this.salary = salary |
|
|
this.salary = salary |
|
|
this.department = department |
|
|
this.department = department |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
staffRepository.save(staff) |
|
|
|
|
|
|
|
|
staffRepository.saveAndFlush(staff) |
|
|
|
|
|
if (!req.skillSetId.isNullOrEmpty()) { |
|
|
|
|
|
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 skillBatchInsertValues: MutableList<MutableMap<String, Any>> |
|
|
|
|
|
// if (!req.skillSetId.isNullOrEmpty()) { |
|
|
|
|
|
// skillBatchInsertValues = req.skillSetId.stream() |
|
|
|
|
|
// .map { skillId -> mutableMapOf<String, Any>(("staffId" to staff.id) as Pair<String, Any>, "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!!) |
|
|
salaryEffectiveService.saveSalaryEffective(staff.id!!, salary.id!!) |
|
|
return staff |
|
|
return staff |
|
@@ -138,7 +171,7 @@ open class StaffsService( |
|
|
val company = companyRepository.findById(req.companyId).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 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 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 skill = if (req.skillSetId != null && req.skillSetId > 0L) skillRepository.findById(req.skillSetId).orElseThrow() else null |
|
|
val salary = salaryRepository.findById(req.salaryId).orElseThrow() |
|
|
val salary = salaryRepository.findById(req.salaryId).orElseThrow() |
|
|
// val salaryEffective = salaryEffectiveRepository.findById(req.salaryEffId).orElseThrow() |
|
|
// val salaryEffective = salaryEffectiveRepository.findById(req.salaryEffId).orElseThrow() |
|
|
val department = departmentRepository.findById(req.departmentId).orElseThrow() |
|
|
val department = departmentRepository.findById(req.departmentId).orElseThrow() |
|
@@ -161,7 +194,7 @@ open class StaffsService( |
|
|
this.company = company |
|
|
this.company = company |
|
|
this.grade = grade |
|
|
this.grade = grade |
|
|
this.team = team |
|
|
this.team = team |
|
|
this.skill = skill |
|
|
|
|
|
|
|
|
// this.skill = skill |
|
|
this.salary = salary |
|
|
this.salary = salary |
|
|
this.department = department |
|
|
this.department = department |
|
|
} |
|
|
} |
|
|