158 lines
7.2 KiB
Java
158 lines
7.2 KiB
Java
package com.erp.controller;
|
|
|
|
import com.erp.dto.ApiResponse;
|
|
import com.erp.service.CascadingHierarchyService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.*;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/cascading-hierarchy")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
public class CascadingHierarchyController {
|
|
private final CascadingHierarchyService cascadingHierarchyService;
|
|
|
|
// Pipeline api_test compatibility alias
|
|
@GetMapping("/list")
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> getGroupListAlias(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@RequestParam Map<String, Object> params) {
|
|
params.put("company_code", companyCode);
|
|
return ResponseEntity.ok(ApiResponse.success(cascadingHierarchyService.getCascadingHierarchyGroupList(params)));
|
|
}
|
|
|
|
@GetMapping
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> getGroupList(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@RequestParam Map<String, Object> params) {
|
|
params.put("company_code", companyCode);
|
|
return ResponseEntity.ok(ApiResponse.success(cascadingHierarchyService.getCascadingHierarchyGroupList(params)));
|
|
}
|
|
|
|
@GetMapping("/{groupCode}")
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> getGroupDetail(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@PathVariable String groupCode) {
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("company_code", companyCode);
|
|
params.put("group_code", groupCode);
|
|
Map<String, Object> result = cascadingHierarchyService.getCascadingHierarchyGroupDetail(params);
|
|
if (result == null) {
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
|
.body(ApiResponse.error("계층 그룹을 찾을 수 없습니다."));
|
|
}
|
|
return ResponseEntity.ok(ApiResponse.success(result));
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> createGroup(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@RequestAttribute(value = "user_id", required = false) String userId,
|
|
@RequestBody Map<String, Object> body) {
|
|
body.put("company_code", companyCode);
|
|
if (userId != null) body.put("user_id", userId);
|
|
return ResponseEntity.status(HttpStatus.CREATED)
|
|
.body(ApiResponse.success(cascadingHierarchyService.insertCascadingHierarchyGroup(body)));
|
|
}
|
|
|
|
@PutMapping("/{groupCode}")
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> updateGroup(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@RequestAttribute(value = "user_id", required = false) String userId,
|
|
@PathVariable String groupCode,
|
|
@RequestBody Map<String, Object> body) {
|
|
body.put("company_code", companyCode);
|
|
body.put("group_code", groupCode);
|
|
if (userId != null) body.put("user_id", userId);
|
|
Map<String, Object> result = cascadingHierarchyService.updateCascadingHierarchyGroup(body);
|
|
if (result == null) {
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
|
.body(ApiResponse.error("계층 그룹을 찾을 수 없습니다."));
|
|
}
|
|
return ResponseEntity.ok(ApiResponse.success(result));
|
|
}
|
|
|
|
@DeleteMapping("/{groupCode}")
|
|
public ResponseEntity<ApiResponse<Void>> deleteGroup(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@PathVariable String groupCode) {
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("company_code", companyCode);
|
|
params.put("group_code", groupCode);
|
|
boolean deleted = cascadingHierarchyService.deleteCascadingHierarchyGroup(params);
|
|
if (!deleted) {
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
|
.body(ApiResponse.error("계층 그룹을 찾을 수 없습니다."));
|
|
}
|
|
return ResponseEntity.ok(ApiResponse.success(null));
|
|
}
|
|
|
|
@PostMapping("/{groupCode}/levels")
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> addLevel(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@PathVariable String groupCode,
|
|
@RequestBody Map<String, Object> body) {
|
|
body.put("company_code", companyCode);
|
|
body.put("group_code", groupCode);
|
|
Map<String, Object> result = cascadingHierarchyService.addCascadingHierarchyLevel(body);
|
|
if (result == null) {
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
|
.body(ApiResponse.error("계층 그룹을 찾을 수 없습니다."));
|
|
}
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(ApiResponse.success(result));
|
|
}
|
|
|
|
@PutMapping("/levels/{levelId}")
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> updateLevel(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@PathVariable Long levelId,
|
|
@RequestBody Map<String, Object> body) {
|
|
body.put("company_code", companyCode);
|
|
body.put("level_id", levelId);
|
|
Map<String, Object> result = cascadingHierarchyService.updateCascadingHierarchyLevel(body);
|
|
if (result == null) {
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
|
.body(ApiResponse.error("레벨을 찾을 수 없습니다."));
|
|
}
|
|
return ResponseEntity.ok(ApiResponse.success(result));
|
|
}
|
|
|
|
@DeleteMapping("/levels/{levelId}")
|
|
public ResponseEntity<ApiResponse<Void>> deleteLevel(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@PathVariable Long levelId) {
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("company_code", companyCode);
|
|
params.put("level_id", levelId);
|
|
boolean deleted = cascadingHierarchyService.deleteCascadingHierarchyLevel(params);
|
|
if (!deleted) {
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
|
.body(ApiResponse.error("레벨을 찾을 수 없습니다."));
|
|
}
|
|
return ResponseEntity.ok(ApiResponse.success(null));
|
|
}
|
|
|
|
@GetMapping("/{groupCode}/options/{levelOrder}")
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> getLevelOptions(
|
|
@RequestAttribute("company_code") String companyCode,
|
|
@PathVariable String groupCode,
|
|
@PathVariable Integer levelOrder,
|
|
@RequestParam(required = false) String parentValue) {
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("company_code", companyCode);
|
|
params.put("group_code", groupCode);
|
|
params.put("level_order", levelOrder);
|
|
if (parentValue != null) params.put("parent_value", parentValue);
|
|
Map<String, Object> result = cascadingHierarchyService.getLevelOptions(params);
|
|
if (result == null) {
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
|
.body(ApiResponse.error("레벨을 찾을 수 없습니다."));
|
|
}
|
|
return ResponseEntity.ok(ApiResponse.success(result));
|
|
}
|
|
}
|