사용자 관리 추가

This commit is contained in:
2025-11-27 12:28:14 +09:00
parent 1dbb3e1b50
commit 510483a537
8 changed files with 231 additions and 10 deletions

View File

@@ -1,9 +1,11 @@
package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
import com.kamco.cd.kamcoback.postgres.repository.auth.AuthRepository;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
@Service
@@ -12,7 +14,7 @@ public class AuthCoreService {
private final AuthRepository authRepository;
/**
* 사용자 등록
* 관리자 등록
*
* @param signup
* @return
@@ -23,4 +25,23 @@ public class AuthCoreService {
}
return authRepository.signup(signup);
}
/**
* 시퀀스 id로 관리자 조회
* @param id
* @return
*/
public AuthDto.Basic findUserById(Long id){
UserEntity entity = authRepository.findUserById(id).orElseThrow(() -> new EntityNotFoundException("관리자를 찾을 수 없습니다. " + id));
return entity.toDto();
}
/**
* 관리자 목록 조회
* @param searchReq
* @return
*/
public Page<AuthDto.Basic> getUserList(AuthDto.SearchReq searchReq) {
return authRepository.getUserList(searchReq);
}
}

View File

@@ -99,7 +99,7 @@ public class MapSheetAnalDataEntity {
@Column(name = "anal_uid")
private Long analUid;
@Column(name = "map_sheep_num")
@Column(name = "map_sheet_num")
private Long mapSheepNum;
@Column(name = "detecting_cnt")

View File

@@ -1,5 +1,6 @@
package com.kamco.cd.kamcoback.postgres.entity;
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -83,4 +84,17 @@ public class UserEntity {
@NotNull
@Column(name = "emp_id", nullable = false)
private String empId;
public AuthDto.Basic toDto() {
return new AuthDto.Basic(
this.id,
this.userAuth,
this.userNm,
this.userId,
this.empId,
this.userEmail,
this.createdDttm
) ;
}
}

View File

@@ -1,11 +1,17 @@
package com.kamco.cd.kamcoback.postgres.repository.auth;
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
import java.util.Optional;
import org.springframework.data.domain.Page;
public interface AuthRepositoryCustom {
Long signup(AuthDto.Signup signup);
Optional<UserEntity> findByUserId(String userId);
Optional<UserEntity> findUserById(Long id);
Page<Basic> getUserList(AuthDto.SearchReq searchReq);
}

View File

@@ -1,11 +1,19 @@
package com.kamco.cd.kamcoback.postgres.repository.auth;
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
import com.kamco.cd.kamcoback.postgres.entity.QUserEntity;
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
@Repository
@@ -15,7 +23,7 @@ public class AuthRepositoryImpl implements AuthRepositoryCustom {
private final QUserEntity userEntity = QUserEntity.userEntity;
/**
* 사용자 등록
* 관리자 등록
*
* @param signup
* @return
@@ -42,7 +50,7 @@ public class AuthRepositoryImpl implements AuthRepositoryCustom {
}
/**
* 유저 아이디 조회
* 유저 아이디 조회
*
* @param userId
* @return
@@ -52,4 +60,59 @@ public class AuthRepositoryImpl implements AuthRepositoryCustom {
return Optional.ofNullable(
queryFactory.selectFrom(userEntity).where(userEntity.userId.eq(userId)).fetchOne());
}
/**
* 유저 시퀀스 id로 조회
* @param id
* @return
*/
@Override
public Optional<UserEntity> findUserById(Long id) {
return Optional.ofNullable(
queryFactory.selectFrom(userEntity).where(userEntity.id.eq(id)).fetchOne());
}
/**
* 관리자 목록 조회
* @param searchReq
* @return
*/
@Override
public Page<Basic> getUserList(AuthDto.SearchReq searchReq) {
Pageable pageable = searchReq.toPageable();
BooleanBuilder builder = new BooleanBuilder();
if (searchReq.getUserNm() != null && !searchReq.getUserNm().isEmpty()) {
builder.and(likeName(userEntity, searchReq.getUserNm()));
}
List<Basic> content =
queryFactory
.select(Projections.constructor(AuthDto.Basic.class,
userEntity.id,
userEntity.userAuth,
userEntity.userNm,
userEntity.userId,
userEntity.empId,
userEntity.userEmail,
userEntity.createdDttm
))
.from(userEntity)
.where(
builder
)
.orderBy(userEntity.userId.asc())
.fetch();
long total =
queryFactory.select(userEntity.id).from(userEntity).where(builder).fetchCount();
return new PageImpl<>(content, pageable, total);
}
private BooleanExpression likeName(QUserEntity entity, String nameStr) {
if (nameStr == null || nameStr.isEmpty()) {
return null;
}
// ex) WHERE LOWER(name) LIKE LOWER('%입력값%')
return entity.userNm.containsIgnoreCase(nameStr.trim());
}
}