공통코드 기능 수정

This commit is contained in:
2025-11-19 10:09:06 +09:00
parent a63b4c33f3
commit 3053b0552e
8 changed files with 288 additions and 64 deletions

View File

@@ -2,6 +2,7 @@ package com.kamco.cd.kamcoback.postgres.entity;
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
@@ -14,9 +15,8 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.ZonedDateTime;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -29,23 +29,23 @@ public class CommonCodeEntity extends CommonDateEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "code_id", nullable = false)
@Column(name = "code_id", nullable = false, updatable = false)
private Long id;
@Size(max = 255)
@Column(name = "code_cd")
private String codeCd;
@Column(name = "code_cd", updatable = false)
private String code;
@Size(max = 255)
@Column(name = "cd_ct")
private String cdCt;
private String description;
@Size(max = 255)
@Column(name = "cd_nm")
private String cdNm;
private String name;
@Column(name = "cd_odr")
private Integer cdOdr;
private Integer order;
@Column(name = "used")
private Boolean used;
@@ -55,35 +55,53 @@ public class CommonCodeEntity extends CommonDateEntity {
private Boolean deleted = false;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
@JoinColumn(name = "parent_id", updatable = false)
private CommonCodeEntity parent;
@OneToMany(mappedBy = "parent")
private Set<CommonCodeEntity> tbCmCds = new LinkedHashSet<>();
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<CommonCodeEntity> children = new ArrayList<>();
public CommonCodeEntity(String codeCd, String cdNm, String cdCt, Integer cdOdr, Boolean used) {
this.codeCd = codeCd;
this.cdNm = cdNm;
this.cdCt = cdCt;
this.cdOdr = cdOdr;
public CommonCodeEntity(String code, String name, String description, Integer order, Boolean used) {
this.code = code;
this.name = name;
this.description = description;
this.order = order;
this.used = used;
}
public CommonCodeEntity(Long id, String name, String description, Integer order, Boolean used, Boolean deleted) {
this.id = id;
this.name = name;
this.description = description;
this.order = order;
this.used = used;
this.deleted = deleted;
}
public CommonCodeDto.Basic toDto() {
return new CommonCodeDto.Basic(
this.id,
this.codeCd,
this.cdCt,
this.cdNm,
this.cdOdr,
this.code,
this.description,
this.name,
this.order,
this.used,
this.deleted,
this.parent,
this.children.stream().map(CommonCodeEntity::toDto).toList(),
super.getCreatedDate(),
super.getModifiedDate());
super.getModifiedDate());
}
public void addParent(CommonCodeEntity parent) {
this.parent = parent;
}
public boolean isDeleted() {
return deleted;
}
public void deleted() {
this.deleted = true;
}
}