[공통 코드] 중간 커밋밋

This commit is contained in:
2025-08-26 15:50:43 +09:00
parent d37986558e
commit 88a508bd54
18 changed files with 1084 additions and 0 deletions

View File

@@ -1,4 +1,47 @@
create table st_common_code (
sort_order integer not null,
use_flag boolean not null,
created_at timestamp(6) not null,
created_oid bigint,
oid bigint not null,
updated_at timestamp(6) not null,
updated_oid bigint,
code varchar(50) not null unique,
group_code varchar(50) not null,
parent_code varchar(50),
character_ref1 varchar(100),
character_ref2 varchar(100),
character_ref3 varchar(100),
character_ref4 varchar(100),
character_ref5 varchar(100),
name varchar(100) not null,
description varchar(500),
created_id varchar(255),
updated_id varchar(255),
primary key (oid)
);
create table st_common_group_code (
sort_order integer not null,
use_flag boolean not null,
created_at timestamp(6) not null,
created_oid bigint,
oid bigint not null,
updated_at timestamp(6) not null,
updated_oid bigint,
code varchar(50) not null unique,
character_ref1_title varchar(100),
character_ref2_title varchar(100),
character_ref3_title varchar(100),
character_ref4_title varchar(100),
character_ref5_title varchar(100),
name varchar(100) not null,
created_id varchar(255),
updated_id varchar(255),
primary key (oid)
);
create table st_file (
use_flag boolean not null,
created_at timestamp(6) not null,
@@ -38,5 +81,27 @@
primary key (oid)
);
create index idx_common_code_code
on st_common_code (code);
create index idx_common_code_group_code
on st_common_code (group_code);
create index idx_common_code_parent_code
on st_common_code (parent_code);
create index idx_common_group_code_code
on st_common_group_code (code);
create index idx_member_user_id
on st_member (user_id);
alter table if exists st_common_code
add constraint FKdk30t67v5e2vo1k7gl5sk1jp9
foreign key (group_code)
references st_common_group_code (code);
alter table if exists st_common_code
add constraint FKgcyw9ydft76p31oox94ho93wf
foreign key (parent_code)
references st_common_code (code);

View File

@@ -0,0 +1,208 @@
package com.bio.bio_backend.domain.admin.CommonCode.controller;
import com.bio.bio_backend.domain.admin.CommonCode.dto.*;
import com.bio.bio_backend.domain.admin.CommonCode.service.CommonCodeService;
import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonCodeMapper;
import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonGroupCodeMapper;
import com.bio.bio_backend.global.dto.ApiResponseDto;
import com.bio.bio_backend.global.constants.ApiResponseCode;
import com.bio.bio_backend.global.annotation.LogExecution;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
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 jakarta.validation.Valid;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/admin/common-code")
@RequiredArgsConstructor
@Tag(name = "공통 코드 관리", description = "공통 코드 및 그룹 코드 관리 API")
public class CommonCodeController {
private final CommonCodeService commonCodeService;
private final CommonCodeMapper commonCodeMapper;
private final CommonGroupCodeMapper commonGroupCodeMapper;
// 그룹 코드 관련 API
@LogExecution("그룹 코드 생성")
@Operation(summary = "그룹 코드 생성", description = "새로운 그룹 코드를 생성합니다.")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "그룹 코드 생성 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))),
@ApiResponse(responseCode = "409", description = "중복된 그룹 코드", content = @Content(schema = @Schema(implementation = ApiResponseDto.class)))
})
@PostMapping("/group")
public ResponseEntity<ApiResponseDto<CreateCommonGroupCodeResponseDto>> createGroupCode(@RequestBody @Valid CreateCommonGroupCodeRequestDto requestDto) {
CommonGroupCodeDto groupCodeDto = commonGroupCodeMapper.toCommonGroupCodeDto(requestDto);
CommonGroupCodeDto createdGroupCode = commonCodeService.createGroupCode(groupCodeDto);
CreateCommonGroupCodeResponseDto responseDto = commonGroupCodeMapper.toCreateCommonGroupCodeResponseDto(createdGroupCode);
ApiResponseDto<CreateCommonGroupCodeResponseDto> apiResponse = ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_CREATED, responseDto);
return ResponseEntity.status(HttpStatus.CREATED).body(apiResponse);
}
@LogExecution("그룹 코드 수정")
@Operation(summary = "그룹 코드 수정", description = "기존 그룹 코드를 수정합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "그룹 코드 수정 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))),
@ApiResponse(responseCode = "404", description = "그룹 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class)))
})
@PutMapping("/group/{code}")
public ResponseEntity<ApiResponseDto<String>> updateGroupCode(
@PathVariable String code,
@RequestBody @Valid UpdateCommonGroupCodeRequestDto requestDto) {
CommonGroupCodeDto groupCodeDto = commonGroupCodeMapper.toCommonGroupCodeDto(requestDto);
commonCodeService.updateGroupCode(code, groupCodeDto);
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_UPDATED));
}
@LogExecution("그룹 코드 삭제")
@Operation(summary = "그룹 코드 삭제", description = "그룹 코드를 삭제합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "그룹 코드 삭제 성공"),
@ApiResponse(responseCode = "400", description = "하위 공통 코드가 존재하여 삭제할 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))),
@ApiResponse(responseCode = "404", description = "그룹 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class)))
})
@DeleteMapping("/group/{code}")
public ResponseEntity<ApiResponseDto<Void>> deleteGroupCode(@PathVariable String code) {
commonCodeService.deleteGroupCode(code);
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_DELETED));
}
@LogExecution("그룹 코드 조회")
@Operation(summary = "그룹 코드 조회", description = "특정 그룹 코드를 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "그룹 코드 조회 성공"),
@ApiResponse(responseCode = "404", description = "그룹 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class)))
})
@GetMapping("/group/{code}")
public ResponseEntity<ApiResponseDto<CommonGroupCodeDto>> getGroupCode(@PathVariable String code) {
CommonGroupCodeDto groupCode = commonCodeService.getGroupCode(code);
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, groupCode));
}
@LogExecution("전체 그룹 코드 조회")
@Operation(summary = "전체 그룹 코드 조회", description = "모든 그룹 코드를 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "전체 그룹 코드 조회 성공")
})
@GetMapping("/group")
public ResponseEntity<ApiResponseDto<List<CommonGroupCodeDto>>> getAllGroupCodes() {
List<CommonGroupCodeDto> groupCodes = commonCodeService.getAllGroupCodes();
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, groupCodes));
}
@LogExecution("활성 그룹 코드 조회")
@Operation(summary = "활성 그룹 코드 조회", description = "사용 중인 그룹 코드만 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "활성 그룹 코드 조회 성공")
})
@GetMapping("/group/active")
public ResponseEntity<ApiResponseDto<List<CommonGroupCodeDto>>> getActiveGroupCodes() {
List<CommonGroupCodeDto> groupCodes = commonCodeService.getActiveGroupCodes();
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, groupCodes));
}
// 공통 코드 관련 API
@LogExecution("공통 코드 생성")
@Operation(summary = "공통 코드 생성", description = "새로운 공통 코드를 생성합니다.")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "공통 코드 생성 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))),
@ApiResponse(responseCode = "409", description = "중복된 공통 코드", content = @Content(schema = @Schema(implementation = ApiResponseDto.class)))
})
@PostMapping
public ResponseEntity<ApiResponseDto<CreateCommonCodeResponseDto>> createCode(@RequestBody @Valid CreateCommonCodeRequestDto requestDto) {
CommonCodeDto commonCodeDto = commonCodeMapper.toCommonCodeDto(requestDto);
CommonCodeDto createdCommonCode = commonCodeService.createCode(commonCodeDto);
CreateCommonCodeResponseDto responseDto = commonCodeMapper.toCreateCommonCodeResponseDto(createdCommonCode);
ApiResponseDto<CreateCommonCodeResponseDto> apiResponse = ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_CREATED, responseDto);
return ResponseEntity.status(HttpStatus.CREATED).body(apiResponse);
}
@LogExecution("공통 코드 수정")
@Operation(summary = "공통 코드 수정", description = "기존 공통 코드를 수정합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "공통 코드 수정 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))),
@ApiResponse(responseCode = "404", description = "공통 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class)))
})
@PutMapping("/{code}")
public ResponseEntity<ApiResponseDto<String>> updateCode(
@PathVariable String code,
@RequestBody @Valid UpdateCommonCodeRequestDto requestDto) {
CommonCodeDto commonCodeDto = commonCodeMapper.toCommonCodeDto(requestDto);
commonCodeService.updateCode(code, commonCodeDto);
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_UPDATED));
}
@LogExecution("공통 코드 삭제")
@Operation(summary = "공통 코드 삭제", description = "공통 코드를 삭제합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "공통 코드 삭제 성공"),
@ApiResponse(responseCode = "400", description = "하위 공통 코드가 존재하여 삭제할 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class))),
@ApiResponse(responseCode = "404", description = "공통 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class)))
})
@DeleteMapping("/{code}")
public ResponseEntity<ApiResponseDto<Void>> deleteCode(@PathVariable String code) {
commonCodeService.deleteCode(code);
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_DELETED));
}
@LogExecution("공통 코드 조회")
@Operation(summary = "공통 코드 조회", description = "특정 공통 코드를 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "공통 코드 조회 성공"),
@ApiResponse(responseCode = "404", description = "공통 코드를 찾을 수 없음", content = @Content(schema = @Schema(implementation = ApiResponseDto.class)))
})
@GetMapping("/{code}")
public ResponseEntity<ApiResponseDto<CommonCodeDto>> getCode(@PathVariable String code) {
CommonCodeDto commonCode = commonCodeService.getCode(code);
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, commonCode));
}
@LogExecution("그룹별 공통 코드 조회")
@Operation(summary = "그룹별 공통 코드 조회", description = "특정 그룹에 속한 공통 코드들을 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "그룹별 공통 코드 조회 성공")
})
@GetMapping("/group/{groupCode}/codes")
public ResponseEntity<ApiResponseDto<List<CommonCodeDto>>> getCodesByGroupCode(@PathVariable String groupCode) {
List<CommonCodeDto> commonCodes = commonCodeService.getActiveCodesByGroupCode(groupCode);
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, commonCodes));
}
@LogExecution("상위 코드별 공통 코드 조회")
@Operation(summary = "상위 코드별 공통 코드 조회", description = "특정 상위 코드에 속한 공통 코드들을 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "상위 코드별 공통 코드 조회 성공")
})
@GetMapping("/parent/{parentCode}/codes")
public ResponseEntity<ApiResponseDto<List<CommonCodeDto>>> getCodesByParentCode(@PathVariable String parentCode) {
List<CommonCodeDto> commonCodes = commonCodeService.getActiveCodesByParentCode(parentCode);
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, commonCodes));
}
@LogExecution("전체 공통 코드 조회")
@Operation(summary = "전체 공통 코드 조회", description = "모든 공통 코드를 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "전체 공통 코드 조회 성공")
})
@GetMapping
public ResponseEntity<ApiResponseDto<List<CommonCodeDto>>> getAllCodes() {
List<CommonCodeDto> commonCodes = commonCodeService.getAllCodes();
return ResponseEntity.ok(ApiResponseDto.success(ApiResponseCode.COMMON_SUCCESS_RETRIEVED, commonCodes));
}
}

View File

@@ -0,0 +1,29 @@
package com.bio.bio_backend.domain.admin.CommonCode.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CommonCodeDto {
private Long oid;
private String code;
private String name;
private String description;
private String groupCode;
private String parentCode;
private String characterRef1;
private String characterRef2;
private String characterRef3;
private String characterRef4;
private String characterRef5;
private Integer sortOrder;
private Boolean useFlag;
}

View File

@@ -0,0 +1,28 @@
package com.bio.bio_backend.domain.admin.CommonCode.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CommonGroupCodeDto {
private Long oid;
private String code;
private String name;
private String characterRef1Title;
private String characterRef2Title;
private String characterRef3Title;
private String characterRef4Title;
private String characterRef5Title;
private Integer sortOrder;
private Boolean useFlag;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}

View File

@@ -0,0 +1,55 @@
package com.bio.bio_backend.domain.admin.CommonCode.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CreateCommonCodeRequestDto {
@NotBlank(message = "코드는 필수입니다")
@Size(max = 50, message = "코드는 50자를 초과할 수 없습니다")
private String code;
@NotBlank(message = "이름은 필수입니다")
@Size(max = 100, message = "이름은 100자를 초과할 수 없습니다")
private String name;
@Size(max = 500, message = "설명은 500자를 초과할 수 없습니다")
private String description;
@NotBlank(message = "그룹 코드는 필수입니다")
@Size(max = 50, message = "그룹 코드는 50자를 초과할 수 없습니다")
private String groupCode;
@Size(max = 50, message = "상위 코드는 50자를 초과할 수 없습니다")
private String parentCode;
@Size(max = 100, message = "문자 참조1은 100자를 초과할 수 없습니다")
private String characterRef1;
@Size(max = 100, message = "문자 참조2는 100자를 초과할 수 없습니다")
private String characterRef2;
@Size(max = 100, message = "문자 참조3은 100자를 초과할 수 없습니다")
private String characterRef3;
@Size(max = 100, message = "문자 참조4는 100자를 초과할 수 없습니다")
private String characterRef4;
@Size(max = 100, message = "문자 참조5는 100자를 초과할 수 없습니다")
private String characterRef5;
@Builder.Default
private Integer sortOrder = 0;
@Builder.Default
private Boolean useFlag = true;
}

View File

@@ -0,0 +1,30 @@
package com.bio.bio_backend.domain.admin.CommonCode.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CreateCommonCodeResponseDto {
private Long oid;
private String code;
private String name;
private String description;
private String groupCode;
private String parentCode;
private String characterRef1;
private String characterRef2;
private String characterRef3;
private String characterRef4;
private String characterRef5;
private Integer sortOrder;
private Boolean useFlag;
private LocalDateTime createdAt;
}

View File

@@ -0,0 +1,45 @@
package com.bio.bio_backend.domain.admin.CommonCode.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CreateCommonGroupCodeRequestDto {
@NotBlank(message = "코드는 필수입니다")
@Size(max = 50, message = "코드는 50자를 초과할 수 없습니다")
private String code;
@NotBlank(message = "이름은 필수입니다")
@Size(max = 100, message = "이름은 100자를 초과할 수 없습니다")
private String name;
@Size(max = 100, message = "차트 참조1 제목은 100자를 초과할 수 없습니다")
private String characterRef1Title;
@Size(max = 100, message = "차트 참조2 제목은 100자를 초과할 수 없습니다")
private String characterRef2Title;
@Size(max = 100, message = "차트 참조3 제목은 100자를 초과할 수 없습니다")
private String characterRef3Title;
@Size(max = 100, message = "차트 참조4 제목은 100자를 초과할 수 없습니다")
private String characterRef4Title;
@Size(max = 100, message = "차트 참조5 제목은 100자를 초과할 수 없습니다")
private String characterRef5Title;
@Builder.Default
private Integer sortOrder = 0;
@Builder.Default
private Boolean useFlag = true;
}

View File

@@ -0,0 +1,27 @@
package com.bio.bio_backend.domain.admin.CommonCode.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CreateCommonGroupCodeResponseDto {
private Long oid;
private String code;
private String name;
private String characterRef1Title;
private String characterRef2Title;
private String characterRef3Title;
private String characterRef4Title;
private String characterRef5Title;
private Integer sortOrder;
private Boolean useFlag;
private LocalDateTime createdAt;
}

View File

@@ -0,0 +1,49 @@
package com.bio.bio_backend.domain.admin.CommonCode.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UpdateCommonCodeRequestDto {
@NotBlank(message = "이름은 필수입니다")
@Size(max = 100, message = "이름은 100자를 초과할 수 없습니다")
private String name;
@Size(max = 500, message = "설명은 500자를 초과할 수 없습니다")
private String description;
@NotBlank(message = "그룹 코드는 필수입니다")
@Size(max = 50, message = "그룹 코드는 50자를 초과할 수 없습니다")
private String groupCode;
@Size(max = 50, message = "상위 코드는 50자를 초과할 수 없습니다")
private String parentCode;
@Size(max = 100, message = "문자 참조1은 100자를 초과할 수 없습니다")
private String characterRef1;
@Size(max = 100, message = "문자 참조2는 100자를 초과할 수 없습니다")
private String characterRef2;
@Size(max = 100, message = "문자 참조3은 100자를 초과할 수 없습니다")
private String characterRef3;
@Size(max = 100, message = "문자 참조4는 100자를 초과할 수 없습니다")
private String characterRef4;
@Size(max = 100, message = "문자 참조5는 100자를 초과할 수 없습니다")
private String characterRef5;
private Integer sortOrder;
private Boolean useFlag;
}

View File

@@ -0,0 +1,39 @@
package com.bio.bio_backend.domain.admin.CommonCode.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UpdateCommonGroupCodeRequestDto {
@NotBlank(message = "이름은 필수입니다")
@Size(max = 100, message = "이름은 100자를 초과할 수 없습니다")
private String name;
@Size(max = 100, message = "문자 참조1 제목은 100자를 초과할 수 없습니다")
private String characterRef1Title;
@Size(max = 100, message = "문자 참조2 제목은 100자를 초과할 수 없습니다")
private String characterRef2Title;
@Size(max = 100, message = "문자 참조3 제목은 100자를 초과할 수 없습니다")
private String characterRef3Title;
@Size(max = 100, message = "문자 참조4 제목은 100자를 초과할 수 없습니다")
private String characterRef4Title;
@Size(max = 100, message = "문자 참조5 제목은 100자를 초과할 수 없습니다")
private String characterRef5Title;
private Integer sortOrder;
private Boolean useFlag;
}

View File

@@ -0,0 +1,73 @@
package com.bio.bio_backend.domain.admin.CommonCode.entity;
import com.bio.bio_backend.global.constants.AppConstants;
import com.bio.bio_backend.global.entity.BaseEntity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Entity
@Getter @Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(
name = AppConstants.TABLE_PREFIX + "common_code",
indexes = {
@Index(name = "idx_common_code_code", columnList = "code"),
@Index(name = "idx_common_code_group_code", columnList = "group_code"),
@Index(name = "idx_common_code_parent_code", columnList = "parent_code")
}
)
public class CommonCode extends BaseEntity {
@Column(name = "code", nullable = false, length = 50, unique = true)
private String code;
@Column(name = "name", nullable = false, length = 100)
private String name;
@Column(name = "description", length = 500)
private String description;
@Column(name = "group_code", nullable = false, length = 50)
private String groupCode;
@Column(name = "parent_code", length = 50)
private String parentCode;
@Column(name = "character_ref1", length = 100)
private String characterRef1;
@Column(name = "character_ref2", length = 100)
private String characterRef2;
@Column(name = "character_ref3", length = 100)
private String characterRef3;
@Column(name = "character_ref4", length = 100)
private String characterRef4;
@Column(name = "character_ref5", length = 100)
private String characterRef5;
@Column(name = "sort_order", nullable = false)
@Builder.Default
private Integer sortOrder = 0;
@Column(name = "use_flag", nullable = false)
@Builder.Default
private Boolean useFlag = true;
// 관계 설정
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "group_code", referencedColumnName = "code", insertable = false, updatable = false)
private CommonGroupCode commonGroupCode;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_code", referencedColumnName = "code", insertable = false, updatable = false)
private CommonCode parentCodeEntity;
}

View File

@@ -0,0 +1,53 @@
package com.bio.bio_backend.domain.admin.CommonCode.entity;
import com.bio.bio_backend.global.constants.AppConstants;
import com.bio.bio_backend.global.entity.BaseEntity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Entity
@Getter @Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(
name = AppConstants.TABLE_PREFIX + "common_group_code",
indexes = {
@Index(name = "idx_common_group_code_code", columnList = "code")
}
)
public class CommonGroupCode extends BaseEntity {
@Column(name = "code", nullable = false, length = 50, unique = true)
private String code;
@Column(name = "name", nullable = false, length = 100)
private String name;
@Column(name = "character_ref1_title", length = 100)
private String characterRef1Title;
@Column(name = "character_ref2_title", length = 100)
private String characterRef2Title;
@Column(name = "character_ref3_title", length = 100)
private String characterRef3Title;
@Column(name = "character_ref4_title", length = 100)
private String characterRef4Title;
@Column(name = "character_ref5_title", length = 100)
private String characterRef5Title;
@Column(name = "sort_order", nullable = false)
@Builder.Default
private Integer sortOrder = 0;
@Column(name = "use_flag", nullable = false)
@Builder.Default
private Boolean useFlag = true;
}

View File

@@ -0,0 +1,68 @@
package com.bio.bio_backend.domain.admin.CommonCode.mapper;
import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonCodeDto;
import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonCodeRequestDto;
import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonCodeResponseDto;
import com.bio.bio_backend.domain.admin.CommonCode.dto.UpdateCommonCodeRequestDto;
import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonCode;
import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper(componentModel = "spring")
public interface CommonCodeMapper {
CommonCodeMapper INSTANCE = Mappers.getMapper(CommonCodeMapper.class);
/**
* CommonCode 엔티티를 CommonCodeDto로 변환
*/
CommonCodeDto toCommonCodeDto(CommonCode entity);
/**
* CommonCodeDto를 CommonCode 엔티티로 변환
*/
@Mapping(target = "commonGroupCode", ignore = true)
@Mapping(target = "parentCodeEntity", ignore = true)
CommonCode toCommonCode(CommonCodeDto dto);
/**
* CommonCode 엔티티 리스트를 CommonCodeDto 리스트로 변환
*/
List<CommonCodeDto> toCommonCodeDtoList(List<CommonCode> entities);
/**
* CommonCodeDto 리스트를 CommonCode 엔티티 리스트로 변환
*/
List<CommonCode> toCommonCodeList(List<CommonCodeDto> dtos);
/**
* CommonCodeDto를 CreateCommonCodeResponseDto로 변환
*/
@Mapping(target = "createdAt", ignore = true)
CreateCommonCodeResponseDto toCreateCommonCodeResponseDto(CommonCodeDto dto);
/**
* CreateCommonCodeRequestDto를 CommonCodeDto로 변환
*/
@Mapping(target = "oid", ignore = true)
CommonCodeDto toCommonCodeDto(CreateCommonCodeRequestDto requestDto);
/**
* UpdateCommonCodeRequestDto를 CommonCodeDto로 변환
*/
@Mapping(target = "code", ignore = true)
@Mapping(target = "oid", ignore = true)
CommonCodeDto toCommonCodeDto(UpdateCommonCodeRequestDto requestDto);
/**
* CommonCodeDto의 값으로 CommonCode 엔티티를 업데이트 (null 값은 무시)
*/
@IgnoreBaseEntityMapping
@Mapping(target = "commonGroupCode", ignore = true)
@Mapping(target = "parentCodeEntity", ignore = true)
void updateCommonCodeFromDto(CommonCodeDto commonCodeDto, @org.mapstruct.MappingTarget CommonCode commonCode);
}

View File

@@ -0,0 +1,67 @@
package com.bio.bio_backend.domain.admin.CommonCode.mapper;
import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonGroupCodeDto;
import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonGroupCodeRequestDto;
import com.bio.bio_backend.domain.admin.CommonCode.dto.CreateCommonGroupCodeResponseDto;
import com.bio.bio_backend.domain.admin.CommonCode.dto.UpdateCommonGroupCodeRequestDto;
import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonGroupCode;
import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper(componentModel = "spring")
public interface CommonGroupCodeMapper {
CommonGroupCodeMapper INSTANCE = Mappers.getMapper(CommonGroupCodeMapper.class);
/**
* CommonGroupCode 엔티티를 CommonGroupCodeDto로 변환
*/
CommonGroupCodeDto toCommonGroupCodeDto(CommonGroupCode entity);
/**
* CommonGroupCodeDto를 CommonGroupCode 엔티티로 변환
*/
CommonGroupCode toCommonGroupCode(CommonGroupCodeDto dto);
/**
* CommonGroupCode 엔티티 리스트를 CommonGroupCodeDto 리스트로 변환
*/
List<CommonGroupCodeDto> toCommonGroupCodeDtoList(List<CommonGroupCode> entities);
/**
* CommonGroupCodeDto 리스트를 CommonGroupCode 엔티티 리스트로 변환
*/
List<CommonGroupCode> toCommonGroupCodeList(List<CommonGroupCodeDto> dtos);
/**
* CommonGroupCodeDto를 CreateCommonGroupCodeResponseDto로 변환
*/
CreateCommonGroupCodeResponseDto toCreateCommonGroupCodeResponseDto(CommonGroupCodeDto dto);
/**
* CreateCommonGroupCodeRequestDto를 CommonGroupCodeDto로 변환
*/
@Mapping(target = "oid", ignore = true)
@Mapping(target = "createdAt", ignore = true)
@Mapping(target = "updatedAt", ignore = true)
CommonGroupCodeDto toCommonGroupCodeDto(CreateCommonGroupCodeRequestDto requestDto);
/**
* UpdateCommonGroupCodeRequestDto를 CommonGroupCodeDto로 변환
*/
@Mapping(target = "oid", ignore = true)
@Mapping(target = "code", ignore = true)
@Mapping(target = "createdAt", ignore = true)
@Mapping(target = "updatedAt", ignore = true)
CommonGroupCodeDto toCommonGroupCodeDto(UpdateCommonGroupCodeRequestDto requestDto);
/**
* CommonGroupCodeDto의 값으로 CommonGroupCode 엔티티를 업데이트 (null 값은 무시)
*/
@IgnoreBaseEntityMapping
void updateCommonGroupCodeFromDto(CommonGroupCodeDto groupCodeDto, @org.mapstruct.MappingTarget CommonGroupCode groupCode);
}

View File

@@ -0,0 +1,32 @@
package com.bio.bio_backend.domain.admin.CommonCode.repository;
import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonCode;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface CommonCodeRepository extends JpaRepository<CommonCode, Long> {
Optional<CommonCode> findByCode(String code);
List<CommonCode> findByGroupCodeAndUseFlagOrderBySortOrderAsc(String groupCode, Boolean useFlag);
List<CommonCode> findByParentCodeAndUseFlagOrderBySortOrderAsc(String parentCode, Boolean useFlag);
@Query("SELECT cc FROM CommonCode cc WHERE cc.groupCode = :groupCode AND cc.useFlag = :useFlag ORDER BY cc.sortOrder ASC")
List<CommonCode> findActiveCodesByGroupCodeOrderBySortOrder(@Param("groupCode") String groupCode, @Param("useFlag") Boolean useFlag);
@Query("SELECT cc FROM CommonCode cc WHERE cc.parentCode = :parentCode AND cc.useFlag = :useFlag ORDER BY cc.sortOrder ASC")
List<CommonCode> findActiveCodesByParentCodeOrderBySortOrder(@Param("parentCode") String parentCode, @Param("useFlag") Boolean useFlag);
boolean existsByCode(String code);
boolean existsByGroupCode(String groupCode);
boolean existsByParentCode(String parentCode);
}

View File

@@ -0,0 +1,23 @@
package com.bio.bio_backend.domain.admin.CommonCode.repository;
import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonGroupCode;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface CommonGroupCodeRepository extends JpaRepository<CommonGroupCode, Long> {
Optional<CommonGroupCode> findByCode(String code);
List<CommonGroupCode> findByUseFlagOrderBySortOrderAsc(Boolean useFlag);
@Query("SELECT cgc FROM CommonGroupCode cgc WHERE cgc.useFlag = :useFlag ORDER BY cgc.sortOrder ASC")
List<CommonGroupCode> findActiveGroupCodesOrderBySortOrder(@Param("useFlag") Boolean useFlag);
boolean existsByCode(String code);
}

View File

@@ -0,0 +1,28 @@
package com.bio.bio_backend.domain.admin.CommonCode.service;
import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonCodeDto;
import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonGroupCodeDto;
import java.util.List;
public interface CommonCodeService {
// 그룹 코드 관련
CommonGroupCodeDto createGroupCode(CommonGroupCodeDto groupCodeDto);
void updateGroupCode(String code, CommonGroupCodeDto groupCodeDto);
void deleteGroupCode(String code);
CommonGroupCodeDto getGroupCode(String code);
List<CommonGroupCodeDto> getAllGroupCodes();
List<CommonGroupCodeDto> getActiveGroupCodes();
// 공통 코드 관련
CommonCodeDto createCode(CommonCodeDto codeDto);
void updateCode(String code, CommonCodeDto codeDto);
void deleteCode(String code);
CommonCodeDto getCode(String code);
List<CommonCodeDto> getCodesByGroupCode(String groupCode);
List<CommonCodeDto> getActiveCodesByGroupCode(String groupCode);
List<CommonCodeDto> getCodesByParentCode(String parentCode);
List<CommonCodeDto> getActiveCodesByParentCode(String parentCode);
List<CommonCodeDto> getAllCodes();
}

View File

@@ -0,0 +1,165 @@
package com.bio.bio_backend.domain.admin.CommonCode.service;
import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonCodeDto;
import com.bio.bio_backend.domain.admin.CommonCode.dto.CommonGroupCodeDto;
import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonCode;
import com.bio.bio_backend.domain.admin.CommonCode.entity.CommonGroupCode;
import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonCodeMapper;
import com.bio.bio_backend.domain.admin.CommonCode.mapper.CommonGroupCodeMapper;
import com.bio.bio_backend.domain.admin.CommonCode.repository.CommonCodeRepository;
import com.bio.bio_backend.domain.admin.CommonCode.repository.CommonGroupCodeRepository;
import com.bio.bio_backend.global.exception.ApiException;
import com.bio.bio_backend.global.constants.ApiResponseCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CommonCodeServiceImpl implements CommonCodeService {
private final CommonGroupCodeRepository commonGroupCodeRepository;
private final CommonCodeRepository commonCodeRepository;
private final CommonCodeMapper commonCodeMapper;
private final CommonGroupCodeMapper commonGroupCodeMapper;
// 그룹 코드 관련 메서드들
@Override
@Transactional
public CommonGroupCodeDto createGroupCode(CommonGroupCodeDto groupCodeDto) {
if (commonGroupCodeRepository.existsByCode(groupCodeDto.getCode())) {
throw new ApiException(ApiResponseCode.USER_ID_DUPLICATE, "이미 존재하는 그룹 코드입니다: " + groupCodeDto.getCode());
}
CommonGroupCode groupCode = commonGroupCodeMapper.toCommonGroupCode(groupCodeDto);
CommonGroupCode savedGroupCode = commonGroupCodeRepository.save(groupCode);
return commonGroupCodeMapper.toCommonGroupCodeDto(savedGroupCode);
}
@Override
@Transactional
public void updateGroupCode(String code, CommonGroupCodeDto groupCodeDto) {
CommonGroupCode existingGroupCode = commonGroupCodeRepository.findByCode(code)
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "그룹 코드를 찾을 수 없습니다: " + code));
commonGroupCodeMapper.updateCommonGroupCodeFromDto(groupCodeDto, existingGroupCode);
commonGroupCodeRepository.save(existingGroupCode);
}
@Override
@Transactional
public void deleteGroupCode(String code) {
CommonGroupCode groupCode = commonGroupCodeRepository.findByCode(code)
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "그룹 코드를 찾을 수 없습니다: " + code));
// 하위 공통 코드가 있는지 확인
if (commonCodeRepository.existsByGroupCode(code)) {
throw new ApiException(ApiResponseCode.COMMON_BAD_REQUEST, "하위 공통 코드가 존재하여 삭제할 수 없습니다: " + code);
}
commonGroupCodeRepository.delete(groupCode);
}
@Override
public CommonGroupCodeDto getGroupCode(String code) {
CommonGroupCode groupCode = commonGroupCodeRepository.findByCode(code)
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "그룹 코드를 찾을 수 없습니다: " + code));
return commonGroupCodeMapper.toCommonGroupCodeDto(groupCode);
}
@Override
public List<CommonGroupCodeDto> getAllGroupCodes() {
List<CommonGroupCode> groupCodes = commonGroupCodeRepository.findAll();
return commonGroupCodeMapper.toCommonGroupCodeDtoList(groupCodes);
}
@Override
public List<CommonGroupCodeDto> getActiveGroupCodes() {
List<CommonGroupCode> groupCodes = commonGroupCodeRepository.findByUseFlagOrderBySortOrderAsc(true);
return commonGroupCodeMapper.toCommonGroupCodeDtoList(groupCodes);
}
// 공통 코드 관련 메서드들
@Override
@Transactional
public CommonCodeDto createCode(CommonCodeDto commonCodeDto) {
if (commonCodeRepository.existsByCode(commonCodeDto.getCode())) {
throw new ApiException(ApiResponseCode.USER_ID_DUPLICATE, "이미 존재하는 공통 코드입니다: " + commonCodeDto.getCode());
}
// 그룹 코드 존재 여부 확인
if (!commonGroupCodeRepository.existsByCode(commonCodeDto.getGroupCode())) {
throw new ApiException(ApiResponseCode.COMMON_BAD_REQUEST, "존재하지 않는 그룹 코드입니다: " + commonCodeDto.getGroupCode());
}
CommonCode commonCode = commonCodeMapper.toCommonCode(commonCodeDto);
CommonCode savedCommonCode = commonCodeRepository.save(commonCode);
return commonCodeMapper.toCommonCodeDto(savedCommonCode);
}
@Override
@Transactional
public void updateCode(String code, CommonCodeDto commonCodeDto) {
CommonCode existingCommonCode = commonCodeRepository.findByCode(code)
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "공통 코드를 찾을 수 없습니다: " + code));
commonCodeMapper.updateCommonCodeFromDto(commonCodeDto, existingCommonCode);
commonCodeRepository.save(existingCommonCode);
}
@Override
@Transactional
public void deleteCode(String code) {
CommonCode commonCode = commonCodeRepository.findByCode(code)
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "공통 코드를 찾을 수 없습니다: " + code));
// 하위 공통 코드가 있는지 확인
if (commonCodeRepository.existsByParentCode(code)) {
throw new ApiException(ApiResponseCode.COMMON_BAD_REQUEST, "하위 공통 코드가 존재하여 삭제할 수 없습니다: " + code);
}
commonCodeRepository.delete(commonCode);
}
@Override
public CommonCodeDto getCode(String code) {
CommonCode commonCode = commonCodeRepository.findByCode(code)
.orElseThrow(() -> new ApiException(ApiResponseCode.COMMON_NOT_FOUND, "공통 코드를 찾을 수 없습니다: " + code));
return commonCodeMapper.toCommonCodeDto(commonCode);
}
@Override
public List<CommonCodeDto> getCodesByGroupCode(String groupCode) {
List<CommonCode> commonCodes = commonCodeRepository.findByGroupCodeAndUseFlagOrderBySortOrderAsc(groupCode, true);
return commonCodeMapper.toCommonCodeDtoList(commonCodes);
}
@Override
public List<CommonCodeDto> getActiveCodesByGroupCode(String groupCode) {
List<CommonCode> commonCodes = commonCodeRepository.findActiveCodesByGroupCodeOrderBySortOrder(groupCode, true);
return commonCodeMapper.toCommonCodeDtoList(commonCodes);
}
@Override
public List<CommonCodeDto> getCodesByParentCode(String parentCode) {
List<CommonCode> commonCodes = commonCodeRepository.findByParentCodeAndUseFlagOrderBySortOrderAsc(parentCode, true);
return commonCodeMapper.toCommonCodeDtoList(commonCodes);
}
@Override
public List<CommonCodeDto> getActiveCodesByParentCode(String parentCode) {
List<CommonCode> commonCodes = commonCodeRepository.findActiveCodesByParentCodeOrderBySortOrder(parentCode, true);
return commonCodeMapper.toCommonCodeDtoList(commonCodes);
}
@Override
public List<CommonCodeDto> getAllCodes() {
List<CommonCode> commonCodes = commonCodeRepository.findAll();
return commonCodeMapper.toCommonCodeDtoList(commonCodes);
}
}