feat: position field + menu role permissions management
This commit is contained in:
@@ -289,6 +289,7 @@ public class EmployeeController {
|
||||
if (row.containsKey("생년월일")) emp.setBirthDate(java.time.LocalDate.parse(row.get("생년월일")));
|
||||
if (row.containsKey("학력")) emp.setEducation(row.get("학력"));
|
||||
if (row.containsKey("학교명")) emp.setSchoolName(row.get("학교명"));
|
||||
if (row.containsKey("직급")) emp.setPosition(row.get("직급"));
|
||||
if (row.containsKey("학과")) emp.setMajor(row.get("학과"));
|
||||
if (row.containsKey("입사일")) emp.setJoinedDate(java.time.LocalDate.parse(row.get("입사일")));
|
||||
return emp;
|
||||
@@ -328,7 +329,7 @@ public class EmployeeController {
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
@GetMapping("/batch/template")
|
||||
public ResponseEntity<byte[]> downloadTemplate() throws Exception {
|
||||
String[] headers = {"로그인ID", "이름", "이메일", "전화번호", "권한", "재직상태", "파견상태", "생년월일", "학력", "학교명", "학과", "입사일"};
|
||||
String[] headers = {"로그인ID", "이름", "이메일", "전화번호", "권한", "재직상태", "파견상태", "생년월일", "학력", "학교명", "직급", "학과", "입사일"};
|
||||
Map<Integer, String[]> dropdowns = Map.of(
|
||||
4, new String[]{"ADMIN", "MANAGER", "EMPLOYEE"},
|
||||
5, new String[]{"ACTIVE", "ON_LEAVE", "RESIGNED"},
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.srsystem.controller;
|
||||
|
||||
import com.srsystem.dto.ApiResponse;
|
||||
import com.srsystem.entity.MenuPermission;
|
||||
import com.srsystem.repository.MenuPermissionRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/menu-permissions")
|
||||
@RequiredArgsConstructor
|
||||
public class MenuPermissionController {
|
||||
|
||||
private final MenuPermissionRepository repository;
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyRole('EMPLOYEE', 'MANAGER', 'ADMIN')")
|
||||
public ApiResponse<List<MenuPermission>> getAll() {
|
||||
return ApiResponse.ok(repository.findAllByOrderBySortOrderAsc());
|
||||
}
|
||||
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
@PutMapping("/{menuKey}")
|
||||
public ApiResponse<MenuPermission> update(@PathVariable String menuKey, @RequestBody Map<String, String> body) {
|
||||
MenuPermission perm = repository.findByMenuKey(menuKey)
|
||||
.orElseThrow(() -> new RuntimeException("Menu not found: " + menuKey));
|
||||
if (body.containsKey("allowedRoles")) {
|
||||
perm.setAllowedRoles(body.get("allowedRoles"));
|
||||
}
|
||||
return ApiResponse.ok(repository.save(perm));
|
||||
}
|
||||
}
|
||||
@@ -22,5 +22,6 @@ public record EmployeeSummary(
|
||||
LocalDate graduationDate,
|
||||
String residence,
|
||||
String profileImage,
|
||||
String schoolName
|
||||
String schoolName,
|
||||
String position
|
||||
) {}
|
||||
|
||||
@@ -77,6 +77,9 @@ public class Employee extends BaseEntity {
|
||||
@Column(name = "school_name", length = 200)
|
||||
private String schoolName;
|
||||
|
||||
@Column(name = "position", length = 50)
|
||||
private String position;
|
||||
|
||||
@Column(name = "graduation_date")
|
||||
private LocalDate graduationDate;
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.srsystem.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.SQLRestriction;
|
||||
|
||||
@Entity
|
||||
@Table(name = "tb_menu_permission")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@SQLDelete(sql = "UPDATE tb_menu_permission SET is_deleted = 'Y' WHERE id = ?")
|
||||
@SQLRestriction("is_deleted = 'N'")
|
||||
public class MenuPermission extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sq_menu_permissions")
|
||||
@SequenceGenerator(name = "sq_menu_permissions", sequenceName = "sq_menu_permissions", allocationSize = 50)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "menu_key", nullable = false, unique = true, length = 100)
|
||||
private String menuKey;
|
||||
|
||||
@Column(name = "menu_name", nullable = false, length = 200)
|
||||
private String menuName;
|
||||
|
||||
@Column(name = "parent_key", length = 100)
|
||||
private String parentKey;
|
||||
|
||||
@Column(name = "allowed_roles", nullable = false, columnDefinition = "TEXT")
|
||||
private String allowedRoles;
|
||||
|
||||
@Column(name = "sort_order")
|
||||
private Integer sortOrder;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.srsystem.repository;
|
||||
|
||||
import com.srsystem.entity.MenuPermission;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface MenuPermissionRepository extends JpaRepository<MenuPermission, Long> {
|
||||
List<MenuPermission> findAllByOrderBySortOrderAsc();
|
||||
Optional<MenuPermission> findByMenuKey(String menuKey);
|
||||
}
|
||||
@@ -107,6 +107,7 @@ public class EmployeeService {
|
||||
employee.setResidence(updateRequest.getResidence());
|
||||
employee.setProfileImage(updateRequest.getProfileImage());
|
||||
employee.setSchoolName(updateRequest.getSchoolName());
|
||||
employee.setPosition(updateRequest.getPosition());
|
||||
|
||||
return employee;
|
||||
}
|
||||
@@ -173,7 +174,8 @@ public class EmployeeService {
|
||||
employee.getGraduationDate(),
|
||||
employee.getResidence(),
|
||||
employee.getProfileImage(),
|
||||
employee.getSchoolName()
|
||||
employee.getSchoolName(),
|
||||
employee.getPosition()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
ALTER TABLE tb_employee ADD COLUMN IF NOT EXISTS position VARCHAR(50);
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS sq_menu_permissions INCREMENT BY 50;
|
||||
|
||||
CREATE TABLE tb_menu_permission (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
menu_key VARCHAR(100) NOT NULL UNIQUE,
|
||||
menu_name VARCHAR(200) NOT NULL,
|
||||
parent_key VARCHAR(100),
|
||||
allowed_roles TEXT NOT NULL DEFAULT '["ADMIN","MANAGER","EMPLOYEE"]',
|
||||
sort_order INTEGER DEFAULT 0,
|
||||
created_at TIMESTAMP,
|
||||
updated_at TIMESTAMP,
|
||||
is_deleted CHAR(1) DEFAULT 'N'
|
||||
);
|
||||
|
||||
INSERT INTO tb_menu_permission (menu_key, menu_name, parent_key, allowed_roles, sort_order) VALUES
|
||||
('dashboard', 'Dashboard', null, '["ADMIN","MANAGER","EMPLOYEE"]', 1),
|
||||
('issues', 'SR Issues', null, '["ADMIN","MANAGER","EMPLOYEE"]', 2),
|
||||
('dispatch', 'Dispatch', null, '["ADMIN","MANAGER","EMPLOYEE"]', 3),
|
||||
('itam', 'ITAM (Assets)', null, '["ADMIN","MANAGER"]', 4),
|
||||
('itam-hub', 'Asset Hub', 'itam', '["ADMIN","MANAGER"]', 5),
|
||||
('itam-register', 'Register', 'itam', '["ADMIN","MANAGER"]', 6),
|
||||
('itam-checkout', 'Check-out', 'itam', '["ADMIN","MANAGER"]', 7),
|
||||
('itam-checkin', 'Check-in', 'itam', '["ADMIN","MANAGER"]', 8),
|
||||
('employees', 'Employees', null, '["ADMIN","MANAGER"]', 5),
|
||||
('projects', 'Projects', null, '["ADMIN","MANAGER"]', 6),
|
||||
('reports', 'Work Reports', null, '["ADMIN","MANAGER","EMPLOYEE"]', 7),
|
||||
('reports-review', 'Report Review', null, '["ADMIN","MANAGER"]', 8),
|
||||
('training', 'Training', null, '["ADMIN","MANAGER","EMPLOYEE"]', 9),
|
||||
('calendar', 'Calendar', null, '["ADMIN","MANAGER","EMPLOYEE"]', 10),
|
||||
('profile', 'Profile', null, '["ADMIN","MANAGER","EMPLOYEE"]', 11),
|
||||
('profile-portfolio', 'Portfolio', 'profile', '["ADMIN","MANAGER","EMPLOYEE"]', 12),
|
||||
('settings', 'Admin', null, '["ADMIN"]', 99),
|
||||
('settings-codes', 'Codes', 'settings', '["ADMIN"]', 100),
|
||||
('settings-accounts', 'Accounts', 'settings', '["ADMIN"]', 101),
|
||||
('settings-batch-employees', 'Batch Employees', 'settings', '["ADMIN"]', 102),
|
||||
('settings-system', 'System', 'settings', '["ADMIN"]', 103),
|
||||
('settings-notification', 'Notification', 'settings', '["ADMIN"]', 104),
|
||||
('settings-audit', 'Audit Log', 'settings', '["ADMIN"]', 105),
|
||||
('settings-menus', 'Menu Permissions', 'settings', '["ADMIN"]', 106);
|
||||
|
||||
INSERT INTO tb_common_code (id, group_code, code_value, code_name, sort_order, is_active, created_at, updated_at)
|
||||
SELECT nextval('sq_common_codes'), 'POSITION', 'STAFF', '사원', 1, 'Y', NOW(), NOW()
|
||||
WHERE NOT EXISTS (SELECT 1 FROM tb_common_code WHERE group_code = 'POSITION' AND code_value = 'STAFF');
|
||||
|
||||
INSERT INTO tb_common_code (id, group_code, code_value, code_name, sort_order, is_active, created_at, updated_at)
|
||||
SELECT nextval('sq_common_codes'), 'POSITION', 'SENIOR', '주임', 2, 'Y', NOW(), NOW()
|
||||
WHERE NOT EXISTS (SELECT 1 FROM tb_common_code WHERE group_code = 'POSITION' AND code_value = 'SENIOR');
|
||||
|
||||
INSERT INTO tb_common_code (id, group_code, code_value, code_name, sort_order, is_active, created_at, updated_at)
|
||||
SELECT nextval('sq_common_codes'), 'POSITION', 'ASSISTANT_MANAGER', '대리', 3, 'Y', NOW(), NOW()
|
||||
WHERE NOT EXISTS (SELECT 1 FROM tb_common_code WHERE group_code = 'POSITION' AND code_value = 'ASSISTANT_MANAGER');
|
||||
|
||||
INSERT INTO tb_common_code (id, group_code, code_value, code_name, sort_order, is_active, created_at, updated_at)
|
||||
SELECT nextval('sq_common_codes'), 'POSITION', 'MANAGER', '과장', 4, 'Y', NOW(), NOW()
|
||||
WHERE NOT EXISTS (SELECT 1 FROM tb_common_code WHERE group_code = 'POSITION' AND code_value = 'MANAGER');
|
||||
|
||||
INSERT INTO tb_common_code (id, group_code, code_value, code_name, sort_order, is_active, created_at, updated_at)
|
||||
SELECT nextval('sq_common_codes'), 'POSITION', 'DEPUTY_GENERAL_MANAGER', '차장', 5, 'Y', NOW(), NOW()
|
||||
WHERE NOT EXISTS (SELECT 1 FROM tb_common_code WHERE group_code = 'POSITION' AND code_value = 'DEPUTY_GENERAL_MANAGER');
|
||||
|
||||
INSERT INTO tb_common_code (id, group_code, code_value, code_name, sort_order, is_active, created_at, updated_at)
|
||||
SELECT nextval('sq_common_codes'), 'POSITION', 'GENERAL_MANAGER', '부장', 6, 'Y', NOW(), NOW()
|
||||
WHERE NOT EXISTS (SELECT 1 FROM tb_common_code WHERE group_code = 'POSITION' AND code_value = 'GENERAL_MANAGER');
|
||||
|
||||
INSERT INTO tb_common_code (id, group_code, code_value, code_name, sort_order, is_active, created_at, updated_at)
|
||||
SELECT nextval('sq_common_codes'), 'POSITION', 'DIRECTOR', '이사', 7, 'Y', NOW(), NOW()
|
||||
WHERE NOT EXISTS (SELECT 1 FROM tb_common_code WHERE group_code = 'POSITION' AND code_value = 'DIRECTOR');
|
||||
Reference in New Issue
Block a user