diff --git a/src/main/java/com/ffii/tsms/modules/data/entity/GradeLog.java b/src/main/java/com/ffii/tsms/modules/data/entity/GradeLog.java new file mode 100644 index 0000000..0f390dd --- /dev/null +++ b/src/main/java/com/ffii/tsms/modules/data/entity/GradeLog.java @@ -0,0 +1,55 @@ +package com.ffii.tsms.modules.data.entity; + +import com.ffii.core.entity.BaseEntity; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDate; + +@Entity +@Table(name = "grade_log") +public class GradeLog extends BaseEntity { + + @NotNull + @OneToOne + @JoinColumn(name = "staffId") + private Staff staff; + + @NotNull + @OneToOne + @JoinColumn(name = "gradeId") + private Grade grade; + + @NotNull + @OneToOne + @JoinColumn(name = "positionId") + private Position position; + + @NotNull + @Column(name = "from", length = 30) + private LocalDate from; + + @NotNull + @Column(name = "to", length = 30) + private LocalDate to; + + public Staff getStaff() { + return staff; + } + + public void setStaff(Staff staff) { + this.staff = staff; + } + + public Grade getGrade() { return grade; } + + public void setGrade(Grade grade) { this.grade = grade; } + + public Position getPosition() { return position; } + + public void setPosition(Position position) { this.position = position; } + + public LocalDate getFrom() { return from; } + + public void setFrom(LocalDate from) { this.from = from; } +} diff --git a/src/main/java/com/ffii/tsms/modules/data/entity/GradeLogRepository.java b/src/main/java/com/ffii/tsms/modules/data/entity/GradeLogRepository.java new file mode 100644 index 0000000..de1920e --- /dev/null +++ b/src/main/java/com/ffii/tsms/modules/data/entity/GradeLogRepository.java @@ -0,0 +1,10 @@ +package com.ffii.tsms.modules.data.entity; + +import com.ffii.core.support.AbstractRepository; +import com.ffii.tsms.modules.data.entity.projections.GradeLogInfo; + +import java.util.List; + +public interface GradeLogRepository extends AbstractRepository { + List findGradeLogInfoByStaffIdAndDeletedFalse(Long staffId); +} diff --git a/src/main/java/com/ffii/tsms/modules/data/entity/projections/GradeLogInfo.kt b/src/main/java/com/ffii/tsms/modules/data/entity/projections/GradeLogInfo.kt new file mode 100644 index 0000000..aee6ebd --- /dev/null +++ b/src/main/java/com/ffii/tsms/modules/data/entity/projections/GradeLogInfo.kt @@ -0,0 +1,25 @@ +package com.ffii.tsms.modules.data.entity.projections + +import com.ffii.tsms.modules.data.entity.Grade +import com.ffii.tsms.modules.data.entity.Position +import org.springframework.beans.factory.annotation.Value +import java.time.LocalDate + +interface GradeLogInfo { + val id: Long + + @get:Value("#{target.staff.id}") + val staffId: Long + + @get:Value("#{target.staff.name}") + val staffName: String + + @get:Value("#{target.staff.staffId}") + val staffCode: String + + val grade: Grade + val position: Position + val from: LocalDate + val to: LocalDate? +} + diff --git a/src/main/java/com/ffii/tsms/modules/data/service/GradeLogService.kt b/src/main/java/com/ffii/tsms/modules/data/service/GradeLogService.kt new file mode 100644 index 0000000..6e1b9a8 --- /dev/null +++ b/src/main/java/com/ffii/tsms/modules/data/service/GradeLogService.kt @@ -0,0 +1,21 @@ +package com.ffii.tsms.modules.data.service + +import com.ffii.core.support.AbstractBaseEntityService +import com.ffii.core.support.JdbcDao +import com.ffii.tsms.modules.data.entity.Department +import com.ffii.tsms.modules.data.entity.DepartmentRepository +import com.ffii.tsms.modules.data.entity.GradeLog +import com.ffii.tsms.modules.data.entity.GradeLogRepository +import com.ffii.tsms.modules.data.entity.projections.GradeLogInfo +import org.springframework.stereotype.Service + +@Service +open class GradeLogService( + private val gradeLogRepository: GradeLogRepository, + private val jdbcDao: JdbcDao, + ) : AbstractBaseEntityService(jdbcDao, gradeLogRepository) { + open fun allGradeLog(staffId: Long): List { + return gradeLogRepository.findGradeLogInfoByStaffIdAndDeletedFalse(staffId) + } + +} \ No newline at end of file diff --git a/src/main/java/com/ffii/tsms/modules/data/web/GradeLogController.kt b/src/main/java/com/ffii/tsms/modules/data/web/GradeLogController.kt new file mode 100644 index 0000000..fe18a68 --- /dev/null +++ b/src/main/java/com/ffii/tsms/modules/data/web/GradeLogController.kt @@ -0,0 +1,24 @@ +package com.ffii.tsms.modules.data.web + +import com.ffii.tsms.modules.data.entity.GradeLog +import com.ffii.tsms.modules.data.entity.GradeLogRepository +import com.ffii.tsms.modules.data.entity.projections.GradeLogInfo +import com.ffii.tsms.modules.data.service.GradeLogService +import com.ffii.tsms.modules.project.entity.projections.ProjectSearchInfo +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/gradeLog") +class GradeLogController( + private val gradeLogService: GradeLogService, + private val gradeLogRepository: GradeLogRepository, +) { + + @GetMapping("/{staffId}") + fun allGradeLog(@PathVariable staffId: Long): List { + return gradeLogService.allGradeLog(staffId) + } +} \ No newline at end of file diff --git a/src/main/resources/db/changelog/changes/20240830_01_derek/01_grade_log.sql b/src/main/resources/db/changelog/changes/20240830_01_derek/01_grade_log.sql new file mode 100644 index 0000000..c92e610 --- /dev/null +++ b/src/main/resources/db/changelog/changes/20240830_01_derek/01_grade_log.sql @@ -0,0 +1,22 @@ +-- liquibase formatted sql +-- changeset derek:create grade log table + +CREATE TABLE grade_log ( + id INT NOT NULL AUTO_INCREMENT, + version INT NOT NULL DEFAULT '0', + created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + createdBy VARCHAR(30) NULL, + modified DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + modifiedBy VARCHAR(30) NULL, + deleted TINYINT(1) NOT NULL DEFAULT '0', + staffId INT NOT NULL, + gradeId INT NOT NULL, + positionId INT NOT NULL, + `from` DATE NOT NULL, + `to` DATE NULL, + CONSTRAINT pk_grade_log PRIMARY KEY (id) +); + +ALTER TABLE grade_log ADD CONSTRAINT FK_GRADE_LOG_ON_STAFFID FOREIGN KEY (staffId) REFERENCES staff (id); +ALTER TABLE grade_log ADD CONSTRAINT FK_GRADE_LOG_ON_GRADEID FOREIGN KEY (gradeId) REFERENCES grade (id); +ALTER TABLE grade_log ADD CONSTRAINT FK_GRADE_LOG_ON_POSITIONID FOREIGN KEY (positionId) REFERENCES `position` (id); \ No newline at end of file