Kaynağa Gözat

update teamLead col

tags/Baseline_30082024_BACKEND_UAT
MSI\derek 1 yıl önce
ebeveyn
işleme
d2da1b3557
5 değiştirilmiş dosya ile 50 ekleme ve 17 silme
  1. +11
    -3
      src/main/java/com/ffii/tsms/modules/data/entity/Team.java
  2. +11
    -7
      src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt
  3. +21
    -5
      src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt
  4. +2
    -2
      src/main/java/com/ffii/tsms/modules/data/web/TeamController.kt
  5. +5
    -0
      src/main/resources/db/changelog/changes/20240426_01_derek/01_addTeamLeadCol.sql

+ 11
- 3
src/main/java/com/ffii/tsms/modules/data/entity/Team.java Dosyayı Görüntüle

@@ -1,9 +1,8 @@
package com.ffii.tsms.modules.data.entity;

import com.ffii.core.entity.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import com.ffii.tsms.modules.user.entity.User;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;

@Entity
@@ -20,6 +19,11 @@ public class Team extends BaseEntity<Long> {
@Column(name = "code", length = 30)
private String code;

@NotNull
@OneToOne
@JoinColumn(name = "teamLead", unique = true)
private Staff staff;

public String getDescription() {
return description;
}
@@ -43,4 +47,8 @@ public class Team extends BaseEntity<Long> {
public void setCode(String code) {
this.code = code;
}

public Staff getStaff() { return staff;}

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

+ 11
- 7
src/main/java/com/ffii/tsms/modules/data/service/StaffsService.kt Dosyayı Görüntüle

@@ -80,13 +80,6 @@ open class StaffsService(

@Transactional(rollbackFor = [Exception::class])
open fun saveStaff(req: NewStaffRequest): Staff {
val user = userRepository.saveAndFlush(
User().apply {
username = req.name
password = passwordEncoder.encode("mms1234")
name = req.name
}
)
val currentPosition = positionRepository.findById(req.currentPositionId).orElseThrow()
val joinPosition = positionRepository.findById(req.joinPositionId).orElseThrow()
val company = companyRepository.findById(req.companyId).orElseThrow()
@@ -97,6 +90,17 @@ open class StaffsService(
// val salaryEffective = salaryEffectiveRepository.findById(req.salaryEffId).orElseThrow()
val department = departmentRepository.findById(req.departmentId).orElseThrow()

val user = userRepository.saveAndFlush(
User().apply {
username = req.name
password = passwordEncoder.encode("mms1234")
name = req.name
phone1 = req.phone1
// phone2 = req.phone2 ?: null
email = req.email ?: null
}
)

// // TODO: Add tasks, milestones, allocated
val staff = Staff().apply {
joinDate = req.joinDate


+ 21
- 5
src/main/java/com/ffii/tsms/modules/data/service/TeamService.kt Dosyayı Görüntüle

@@ -20,8 +20,20 @@ open class TeamService(
private val jdbcDao: JdbcDao,
) : AbstractBaseEntityService<Team, Long, TeamRepository>(jdbcDao, teamRepository) {

open fun allTeam(): List<Team> {
return teamRepository.findByDeletedFalse();
// open fun allTeam(): List<Team> {
// return teamRepository.findByDeletedFalse();
// }

open fun allTeam(args: Map<String, Any>): List<Map<String, Any>> {
val sql = StringBuilder("select"
+ " t.*, "
+ " s.staffId, "
+ " s.name as staffName"
+ " from team t "
+ " left join staff s on t.teamLead = s.id "
+ " where t.deleted = false "
)
return jdbcDao.queryForList(sql.toString(), args)
}

@Transactional(rollbackFor = [Exception::class])
@@ -53,21 +65,25 @@ open class TeamService(
open fun updateTeam(req: NewTeamRequest, team: Team): Team {
val addIds = req.addStaffIds ?: listOf<Int>()

val teamLead: Staff
val teamName: String
val teamCode: String

if (addIds.isNotEmpty()) {
val teamLead = staffRepository.findById(addIds[0].toLong()).orElseThrow()
teamName = "Team " + teamLead.name
val leader = staffRepository.findById(addIds[0].toLong()).orElseThrow()
teamName = "Team " + leader.name
teamLead = leader;

val initials = teamLead.name.split(" ").map { it.first() }
val initials = leader.name.split(" ").map { it.first() }
teamCode = initials.joinToString("")
} else {
teamLead = team.staff
teamName = team.name
teamCode = team.code
}

team.apply {
this.staff = teamLead
name = teamName
code = teamCode
description = req.description


+ 2
- 2
src/main/java/com/ffii/tsms/modules/data/web/TeamController.kt Dosyayı Görüntüle

@@ -18,8 +18,8 @@ import org.springframework.web.bind.annotation.*
class TeamController(private val teamService: TeamService) {

@GetMapping
fun allStaff(): List<Team> {
return teamService.allTeam()
fun allStaff(args: Map<String, Any>): List<Map<String, Any>> {
return teamService.allTeam(args)
}

@PostMapping("/save")


+ 5
- 0
src/main/resources/db/changelog/changes/20240426_01_derek/01_addTeamLeadCol.sql Dosyayı Görüntüle

@@ -0,0 +1,5 @@
-- liquibase formatted sql
-- changeset derek:add teamLead col in team

ALTER TABLE `team`
ADD COLUMN `teamLead` int(11) NULL AFTER `code`;

Yükleniyor…
İptal
Kaydet