Ver código fonte

update

tags/Baseline_30082024_BACKEND_UAT
MSI\derek 1 ano atrás
pai
commit
0bb062115e
6 arquivos alterados com 96 adições e 7 exclusões
  1. +35
    -0
      src/main/java/com/ffii/tsms/modules/data/entity/StaffSkillset.java
  2. +6
    -0
      src/main/java/com/ffii/tsms/modules/data/entity/StaffSkillsetRepository.java
  3. +38
    -5
      src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt
  4. +2
    -2
      src/main/java/com/ffii/tsms/modules/data/web/models/NewStaffRequest.kt
  5. +6
    -0
      src/main/resources/db/changelog/changes/20240430_01_derek/addCol.sql
  6. +9
    -0
      src/main/resources/db/changelog/changes/20240430_01_derek/addStaffSkillset.sql

+ 35
- 0
src/main/java/com/ffii/tsms/modules/data/entity/StaffSkillset.java Ver arquivo

@@ -0,0 +1,35 @@
package com.ffii.tsms.modules.data.entity;

import com.ffii.core.entity.BaseEntity;
import com.ffii.core.entity.IdEntity;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;

import java.time.LocalDate;

@Entity
@Table(name = "staff_skillset")
public class StaffSkillset extends IdEntity<Long> {

@ManyToOne
@JoinColumn(name = "staffId")
@NotNull
private Staff staff;

@ManyToOne
@JoinColumn(name = "skillId")
@NotNull
private Skill skill;

public Staff getStaff() {
return staff;
}

public void setStaff(Staff staff) {
this.staff = staff;
}

public Skill getSkill() { return skill; }

public void setSkill(Skill skill) { this.skill = skill; }
}

+ 6
- 0
src/main/java/com/ffii/tsms/modules/data/entity/StaffSkillsetRepository.java Ver arquivo

@@ -0,0 +1,6 @@
package com.ffii.tsms.modules.data.entity;

import com.ffii.core.support.AbstractRepository;

public interface StaffSkillsetRepository extends AbstractRepository<StaffSkillset, Long> {
}

+ 38
- 5
src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt Ver arquivo

@@ -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.user.entity.User
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.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*
import java.util.stream.Collectors


@Service
@@ -26,6 +28,7 @@ open class StaffsService(
private val salaryEffectiveRepository: SalaryEffectiveRepository,
private val salaryEffectiveService: SalaryEffectiveService,
private val departmentRepository: DepartmentRepository,
private val staffSkillsetRepository: StaffSkillsetRepository,
private val jdbcDao: JdbcDao,
private val passwordEncoder: PasswordEncoder
) : AbstractBaseEntityService<Staff, Long, StaffRepository>(jdbcDao, staffRepository) {
@@ -78,6 +81,16 @@ open class StaffsService(
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])
open fun saveStaff(req: NewStaffRequest): Staff {
val currentPosition = positionRepository.findById(req.currentPositionId).orElseThrow()
@@ -85,7 +98,6 @@ open class StaffsService(
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()
@@ -121,12 +133,33 @@ open class StaffsService(
this.company = company
this.grade = grade
this.team = team
this.skill = skill
// this.skill = skill
this.salary = salary
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!!)
return staff
@@ -138,7 +171,7 @@ open class StaffsService(
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 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()
@@ -161,7 +194,7 @@ open class StaffsService(
this.company = company
this.grade = grade
this.team = team
this.skill = skill
// this.skill = skill
this.salary = salary
this.department = department
}


+ 2
- 2
src/main/java/com/ffii/tsms/modules/data/web/models/NewStaffRequest.kt Ver arquivo

@@ -18,10 +18,10 @@ data class NewStaffRequest(
@field:NotNull(message = "Staff salaryId cannot be empty")
val salaryId: Long,
// @field:NotNull(message = "Staff skillSetId cannot be empty")
val skillSetId: Long?,
val skillSetId: List<Long>?,
val joinDate: LocalDate,
val currentPositionId: Long,
val salaryEffId: Long,
// val salaryEffId: Long,
val joinPositionId: Long,
val gradeId: Long?,
val teamId: Long?,


+ 6
- 0
src/main/resources/db/changelog/changes/20240430_01_derek/addCol.sql Ver arquivo

@@ -0,0 +1,6 @@
-- liquibase formatted sql
-- changeset derek:add_col_to_staff_skillset

ALTER TABLE `staff_skillset`
ADD COLUMN `id` INT NOT NULL AUTO_INCREMENT FIRST,
ADD PRIMARY KEY (`id`);

+ 9
- 0
src/main/resources/db/changelog/changes/20240430_01_derek/addStaffSkillset.sql Ver arquivo

@@ -0,0 +1,9 @@
-- liquibase formatted sql
-- changeset derek:add_staff_skillset

CREATE TABLE `staff_skillset` (
`staffId` int NOT NULL,
`skillId` int NOT NULL,
FOREIGN KEY (`staffId`) REFERENCES `staff` (`id`),
FOREIGN KEY (`skillId`) REFERENCES `skill` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Carregando…
Cancelar
Salvar