공통코드 추가

This commit is contained in:
2025-11-18 11:35:28 +09:00
parent 1657045f6d
commit 725cad510e
9 changed files with 319 additions and 2 deletions

View File

@@ -14,11 +14,11 @@ import org.springframework.data.annotation.LastModifiedDate;
public class CommonDateEntity {
@CreatedDate
@Column(name = "created_date", updatable = false, nullable = false)
@Column(name = "created_dttm", updatable = false, nullable = false)
private ZonedDateTime createdDate;
@LastModifiedDate
@Column(name = "modified_date", nullable = false)
@Column(name = "updated_dttm", nullable = false)
private ZonedDateTime modifiedDate;
@PrePersist

View File

@@ -0,0 +1,53 @@
package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto.Basic;
import com.kamco.cd.kamcoback.common.service.BaseCoreService;
import com.kamco.cd.kamcoback.postgres.entity.AnimalEntity;
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
import com.kamco.cd.kamcoback.postgres.entity.ZooEntity;
import com.kamco.cd.kamcoback.postgres.repository.CommonCodeRepository;
import com.kamco.cd.kamcoback.zoo.dto.AnimalDto.SearchReq;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CommonCodeCoreService implements BaseCoreService<CommonCodeDto.Basic, Long, SearchReq> {
private final CommonCodeRepository commonCodeRepository;
public CommonCodeDto.Basic save(CommonCodeDto.AddReq req) {
CommonCodeEntity code = null;
// if (req.getZooUuid() != null) {
// zoo =
// zooRepository
// .getZooByUuid(req.getZooUuid())
// .orElseThrow(
// () ->
// new EntityNotFoundException("Zoo not found with uuid: " + req.getZooUuid()));
// }
CommonCodeEntity entity = new CommonCodeEntity(req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed());
CommonCodeEntity saved = commonCodeRepository.save(entity);
return saved.toDto();
}
@Override
public void remove(Long aLong) {
}
@Override
public Basic getOneById(Long aLong) {
return null;
}
@Override
public Page<Basic> search(SearchReq searchReq) {
return null;
}
}

View File

@@ -0,0 +1,85 @@
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.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
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 lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "tb_cm_cd")
public class CommonCodeEntity extends CommonDateEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "code_id", nullable = false)
private Long id;
@Size(max = 255)
@Column(name = "code_cd")
private String codeCd;
@Size(max = 255)
@Column(name = "cd_ct")
private String cdCt;
@Size(max = 255)
@Column(name = "cd_nm")
private String cdNm;
@Column(name = "cd_odr")
private Integer cdOdr;
@Column(name = "used")
private Boolean used;
@NotNull
@Column(name = "deleted", nullable = false)
private Boolean deleted = false;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private CommonCodeEntity parent;
@OneToMany(mappedBy = "parent")
private Set<CommonCodeEntity> tbCmCds = new LinkedHashSet<>();
public CommonCodeEntity(String codeCd, String cdNm, String cdCt, Integer cdOdr, Boolean used) {
this.codeCd = codeCd;
this.cdNm = cdNm;
this.cdCt = cdCt;
this.cdOdr = cdOdr;
this.used = used;
}
public CommonCodeDto.Basic toDto() {
return new CommonCodeDto.Basic(
this.id,
this.codeCd,
this.cdCt,
this.cdNm,
this.cdOdr,
this.used,
this.deleted,
this.parent,
super.getCreatedDate(),
super.getModifiedDate());
}
}

View File

@@ -0,0 +1,8 @@
package com.kamco.cd.kamcoback.postgres.repository;
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CommonCodeRepository extends JpaRepository<CommonCodeEntity, Long>, CommonCodeRepositoryCustom {
}

View File

@@ -0,0 +1,5 @@
package com.kamco.cd.kamcoback.postgres.repository;
public interface CommonCodeRepositoryCustom {
}

View File

@@ -0,0 +1,5 @@
package com.kamco.cd.kamcoback.postgres.repository;
public class CommonCodeRepositoryImpl {
}