공통코드 저장 parent null인 경우 수정

This commit is contained in:
2025-12-10 11:06:14 +09:00
parent c9094f04c2
commit 04ebed5cca
2 changed files with 11 additions and 2 deletions

View File

@@ -76,9 +76,11 @@ public class CommonCodeCoreService
"parent id 를 찾을 수 없습니다. id : " + req.getParentId()));
entity.addParent(parentCommonCodeEntity);
} else {
entity.addParent(null);
}
commonCodeRepository.save(entity).toDto();
return new ResponseObj(ApiResponseCode.OK, "");
}

View File

@@ -4,6 +4,7 @@ import static com.kamco.cd.kamcoback.postgres.entity.QCommonCodeEntity.commonCod
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
import com.kamco.cd.kamcoback.postgres.entity.QCommonCodeEntity;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import java.util.Optional;
@@ -106,10 +107,16 @@ public class CommonCodeRepositoryImpl implements CommonCodeRepositoryCustom {
return queryFactory
.select(commonCodeEntity.code.count())
.from(commonCodeEntity)
.where(commonCodeEntity.parent.id.eq(parentId), commonCodeEntity.code.eq(code))
.where(conditionParentId(parentId), commonCodeEntity.code.eq(code))
.fetchOne();
}
private BooleanExpression conditionParentId(Long parentId) {
return parentId == null
? commonCodeEntity.parent.id.isNull()
: commonCodeEntity.parent.id.eq(parentId);
}
private List<CommonCodeEntity> findAllByIds(Set<Long> ids) {
return queryFactory
.selectFrom(commonCodeEntity)