|
|
@@ -2,12 +2,87 @@ package com.ffii.tsms.modules.data.service |
|
|
|
|
|
|
|
import com.ffii.tsms.modules.data.entity.Staff
|
|
|
|
import com.ffii.tsms.modules.data.entity.StaffRepository
|
|
|
|
import com.ffii.tsms.modules.user.entity.UserRepository
|
|
|
|
import com.ffii.tsms.modules.data.entity.PositionRepository
|
|
|
|
import com.ffii.tsms.modules.data.entity.CompanyRepository
|
|
|
|
import com.ffii.tsms.modules.data.entity.GradeRepository
|
|
|
|
import com.ffii.tsms.modules.data.entity.TeamRepository
|
|
|
|
import com.ffii.tsms.modules.data.entity.SkillRepository
|
|
|
|
import com.ffii.tsms.modules.data.entity.SalaryEffectiveRepository
|
|
|
|
import com.ffii.tsms.modules.data.entity.DepartmentRepository
|
|
|
|
import com.ffii.tsms.modules.project.web.models.NewStaffRequest
|
|
|
|
// import com.ffii.tsms.modules.data.web.models.NewStaffRequest
|
|
|
|
import org.springframework.stereotype.Service
|
|
|
|
import com.ffii.core.support.JdbcDao;
|
|
|
|
import com.ffii.core.support.AbstractBaseEntityService;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
class StaffsService(private val staffRepository: StaffRepository) {
|
|
|
|
public final class StaffsService(
|
|
|
|
private val staffRepository: StaffRepository,
|
|
|
|
private val userRepository: UserRepository,
|
|
|
|
private val positionRepository: PositionRepository,
|
|
|
|
private val companyRepository: CompanyRepository,
|
|
|
|
private val gradeRepository: GradeRepository,
|
|
|
|
private val teamRepository: TeamRepository,
|
|
|
|
private val skillRepository: SkillRepository,
|
|
|
|
private val salaryEffectiveRepository: SalaryEffectiveRepository,
|
|
|
|
private val departmentRepository: DepartmentRepository,
|
|
|
|
private val jdbcDao: JdbcDao,
|
|
|
|
) {
|
|
|
|
|
|
|
|
fun getTeamLeads(): List<Staff> {
|
|
|
|
// TODO: Replace with actual logic and make a projection instead of returning all fields
|
|
|
|
return staffRepository.findAll()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun fetchStaffList(args: Map<String, Any>): List<Map<String, Any>> {
|
|
|
|
val sql = StringBuilder("select"
|
|
|
|
+ " s.*,"
|
|
|
|
+ " date_format(s.created, '%Y-%m-%d') as created,"
|
|
|
|
+ " date_format(s.departDate, '%Y-%m-%d') as departDate,"
|
|
|
|
+ " date_format(s.joinDate, '%Y-%m-%d') as joinDate"
|
|
|
|
+ " from staff s"
|
|
|
|
+ " where s.deleted = false"
|
|
|
|
)
|
|
|
|
return jdbcDao.queryForList(sql.toString(), args)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun saveStaff(req: NewStaffRequest): Staff {
|
|
|
|
val user = userRepository.findById(req.userId).orElseThrow()
|
|
|
|
val currentPosition = positionRepository.findById(req.currentPositionId).orElseThrow()
|
|
|
|
val joinPosition = positionRepository.findById(req.joinPositionId).orElseThrow()
|
|
|
|
val company = companyRepository.findById(req.companyId).orElseThrow()
|
|
|
|
val grade = gradeRepository.findById(req.gradeId).orElseThrow()
|
|
|
|
val team = teamRepository.findById(req.teamId).orElseThrow()
|
|
|
|
val skill = skillRepository.findById(req.skillSetId).orElseThrow()
|
|
|
|
val salaryEffective = salaryEffectiveRepository.findById(req.salaryEffId).orElseThrow()
|
|
|
|
val department = departmentRepository.findById(req.departmentId).orElseThrow()
|
|
|
|
|
|
|
|
// // TODO: Add tasks, milestones, allocated
|
|
|
|
val staff = Staff().apply {
|
|
|
|
joinDate = req.joinDate
|
|
|
|
name = req.name
|
|
|
|
staffId = req.staffId
|
|
|
|
phone1 = req.phone1
|
|
|
|
phone2 = req.phone2
|
|
|
|
email = req.email
|
|
|
|
emergContactName = req.emergContactName
|
|
|
|
emergContactPhone = req.emergContactPhone
|
|
|
|
employType = req.employType
|
|
|
|
departDate = req.departDate
|
|
|
|
departReason = req.departReason
|
|
|
|
remark = req.remark
|
|
|
|
this.user = user
|
|
|
|
this.currentPosition = currentPosition
|
|
|
|
this.joinPosition = joinPosition
|
|
|
|
this.company = company
|
|
|
|
this.grade = grade
|
|
|
|
this.team = team
|
|
|
|
this.skill = skill
|
|
|
|
this.salaryEffective = salaryEffective
|
|
|
|
this.department = department
|
|
|
|
}
|
|
|
|
|
|
|
|
return staffRepository.save(staff)
|
|
|
|
}
|
|
|
|
} |