멤버테이블 수정
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
package com.kamco.cd.kamcoback.postgres.core;
|
package com.kamco.cd.kamcoback.postgres.core;
|
||||||
|
|
||||||
import com.kamco.cd.kamcoback.config.BCryptSaltGenerator;
|
import com.kamco.cd.kamcoback.auth.BCryptSaltGenerator;
|
||||||
import com.kamco.cd.kamcoback.members.dto.MembersDto;
|
import com.kamco.cd.kamcoback.members.dto.MembersDto;
|
||||||
import com.kamco.cd.kamcoback.members.exception.MemberException;
|
import com.kamco.cd.kamcoback.members.exception.MemberException;
|
||||||
import com.kamco.cd.kamcoback.members.exception.MemberException.MemberNotFoundException;
|
import com.kamco.cd.kamcoback.members.exception.MemberException.MemberNotFoundException;
|
||||||
import com.kamco.cd.kamcoback.postgres.entity.MemberArchivedEntity;
|
import com.kamco.cd.kamcoback.postgres.entity.MemberArchivedEntity;
|
||||||
|
import com.kamco.cd.kamcoback.postgres.entity.MemberArchivedEntityId;
|
||||||
import com.kamco.cd.kamcoback.postgres.entity.MemberEntity;
|
import com.kamco.cd.kamcoback.postgres.entity.MemberEntity;
|
||||||
import com.kamco.cd.kamcoback.postgres.entity.MemberRoleEntity;
|
import com.kamco.cd.kamcoback.postgres.entity.MemberRoleEntity;
|
||||||
import com.kamco.cd.kamcoback.postgres.entity.MemberRoleEntityId;
|
import com.kamco.cd.kamcoback.postgres.entity.MemberRoleEntityId;
|
||||||
@@ -40,12 +41,12 @@ public class MembersCoreService {
|
|||||||
public Long saveMembers(MembersDto.AddReq addReq) {
|
public Long saveMembers(MembersDto.AddReq addReq) {
|
||||||
if (membersRepository.existsByEmployeeNo(addReq.getEmployeeNo())) {
|
if (membersRepository.existsByEmployeeNo(addReq.getEmployeeNo())) {
|
||||||
throw new MemberException.DuplicateMemberException(
|
throw new MemberException.DuplicateMemberException(
|
||||||
MemberException.DuplicateMemberException.Field.EMPLOYEE_NO, addReq.getEmployeeNo());
|
MemberException.DuplicateMemberException.Field.EMPLOYEE_NO, addReq.getEmployeeNo());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (membersRepository.existsByEmail(addReq.getEmail())) {
|
if (membersRepository.existsByEmail(addReq.getEmail())) {
|
||||||
throw new MemberException.DuplicateMemberException(
|
throw new MemberException.DuplicateMemberException(
|
||||||
MemberException.DuplicateMemberException.Field.EMAIL, addReq.getEmail());
|
MemberException.DuplicateMemberException.Field.EMAIL, addReq.getEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
MemberEntity memberEntity = new MemberEntity();
|
MemberEntity memberEntity = new MemberEntity();
|
||||||
@@ -65,7 +66,7 @@ public class MembersCoreService {
|
|||||||
*/
|
*/
|
||||||
public void updateMembers(UUID uuid, MembersDto.UpdateReq updateReq) {
|
public void updateMembers(UUID uuid, MembersDto.UpdateReq updateReq) {
|
||||||
MemberEntity memberEntity =
|
MemberEntity memberEntity =
|
||||||
membersRepository.findByUUID(uuid).orElseThrow(() -> new MemberNotFoundException());
|
membersRepository.findByUUID(uuid).orElseThrow(() -> new MemberNotFoundException());
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(memberEntity.getEmployeeNo())) {
|
if (StringUtils.isNotBlank(memberEntity.getEmployeeNo())) {
|
||||||
memberEntity.setEmployeeNo(updateReq.getEmployeeNo());
|
memberEntity.setEmployeeNo(updateReq.getEmployeeNo());
|
||||||
@@ -92,13 +93,13 @@ public class MembersCoreService {
|
|||||||
public void saveRoles(MembersDto.RolesDto rolesDto) {
|
public void saveRoles(MembersDto.RolesDto rolesDto) {
|
||||||
|
|
||||||
MemberEntity memberEntity =
|
MemberEntity memberEntity =
|
||||||
membersRepository
|
membersRepository
|
||||||
.findByUUID(rolesDto.getUuid())
|
.findByUUID(rolesDto.getUuid())
|
||||||
.orElseThrow(() -> new MemberNotFoundException());
|
.orElseThrow(() -> new MemberNotFoundException());
|
||||||
|
|
||||||
if (memberRoleRepository.findByUuidAndRoleName(rolesDto)) {
|
if (memberRoleRepository.findByUuidAndRoleName(rolesDto)) {
|
||||||
throw new MemberException.DuplicateMemberException(
|
throw new MemberException.DuplicateMemberException(
|
||||||
MemberException.DuplicateMemberException.Field.DEFAULT, "중복된 역할이 있습니다.");
|
MemberException.DuplicateMemberException.Field.DEFAULT, "중복된 역할이 있습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
MemberRoleEntityId memberRoleEntityId = new MemberRoleEntityId();
|
MemberRoleEntityId memberRoleEntityId = new MemberRoleEntityId();
|
||||||
@@ -119,9 +120,9 @@ public class MembersCoreService {
|
|||||||
*/
|
*/
|
||||||
public void deleteRoles(MembersDto.RolesDto rolesDto) {
|
public void deleteRoles(MembersDto.RolesDto rolesDto) {
|
||||||
MemberEntity memberEntity =
|
MemberEntity memberEntity =
|
||||||
membersRepository
|
membersRepository
|
||||||
.findByUUID(rolesDto.getUuid())
|
.findByUUID(rolesDto.getUuid())
|
||||||
.orElseThrow(() -> new MemberNotFoundException());
|
.orElseThrow(() -> new MemberNotFoundException());
|
||||||
|
|
||||||
MemberRoleEntityId memberRoleEntityId = new MemberRoleEntityId();
|
MemberRoleEntityId memberRoleEntityId = new MemberRoleEntityId();
|
||||||
memberRoleEntityId.setMemberUuid(rolesDto.getUuid());
|
memberRoleEntityId.setMemberUuid(rolesDto.getUuid());
|
||||||
@@ -141,9 +142,9 @@ public class MembersCoreService {
|
|||||||
*/
|
*/
|
||||||
public void updateStatus(MembersDto.StatusDto statusDto) {
|
public void updateStatus(MembersDto.StatusDto statusDto) {
|
||||||
MemberEntity memberEntity =
|
MemberEntity memberEntity =
|
||||||
membersRepository
|
membersRepository
|
||||||
.findByUUID(statusDto.getUuid())
|
.findByUUID(statusDto.getUuid())
|
||||||
.orElseThrow(() -> new MemberNotFoundException());
|
.orElseThrow(() -> new MemberNotFoundException());
|
||||||
|
|
||||||
memberEntity.setStatus(statusDto.getStatus());
|
memberEntity.setStatus(statusDto.getStatus());
|
||||||
memberEntity.setUpdatedDttm(ZonedDateTime.now());
|
memberEntity.setUpdatedDttm(ZonedDateTime.now());
|
||||||
@@ -157,13 +158,16 @@ public class MembersCoreService {
|
|||||||
*/
|
*/
|
||||||
public void deleteAccount(MembersDto.StatusDto statusDto) {
|
public void deleteAccount(MembersDto.StatusDto statusDto) {
|
||||||
MemberEntity memberEntity =
|
MemberEntity memberEntity =
|
||||||
membersRepository
|
membersRepository
|
||||||
.findByUUID(statusDto.getUuid())
|
.findByUUID(statusDto.getUuid())
|
||||||
.orElseThrow(() -> new MemberNotFoundException());
|
.orElseThrow(() -> new MemberNotFoundException());
|
||||||
|
|
||||||
|
MemberArchivedEntityId memberArchivedEntityId = new MemberArchivedEntityId();
|
||||||
|
memberArchivedEntityId.setUserId(memberEntity.getId());
|
||||||
|
memberArchivedEntityId.setUuid(memberEntity.getUuid());
|
||||||
|
|
||||||
MemberArchivedEntity memberArchivedEntity = new MemberArchivedEntity();
|
MemberArchivedEntity memberArchivedEntity = new MemberArchivedEntity();
|
||||||
memberArchivedEntity.setUuid(memberEntity.getUuid());
|
memberArchivedEntity.setId(memberArchivedEntityId);
|
||||||
memberArchivedEntity.setId(memberEntity.getId());
|
|
||||||
memberArchivedEntity.setEmployeeNo(memberEntity.getEmployeeNo());
|
memberArchivedEntity.setEmployeeNo(memberEntity.getEmployeeNo());
|
||||||
memberArchivedEntity.setName(memberEntity.getName());
|
memberArchivedEntity.setName(memberEntity.getName());
|
||||||
memberArchivedEntity.setPassword(memberEntity.getPassword());
|
memberArchivedEntity.setPassword(memberEntity.getPassword());
|
||||||
@@ -189,10 +193,10 @@ public class MembersCoreService {
|
|||||||
*/
|
*/
|
||||||
public void resetPassword(Long id) {
|
public void resetPassword(Long id) {
|
||||||
MemberEntity memberEntity =
|
MemberEntity memberEntity =
|
||||||
membersRepository.findById(id).orElseThrow(() -> new MemberNotFoundException());
|
membersRepository.findById(id).orElseThrow(() -> new MemberNotFoundException());
|
||||||
|
|
||||||
String salt =
|
String salt =
|
||||||
BCryptSaltGenerator.generateSaltWithEmployeeNo(memberEntity.getEmployeeNo().trim());
|
BCryptSaltGenerator.generateSaltWithEmployeeNo(memberEntity.getEmployeeNo().trim());
|
||||||
// 패스워드 암호화, 초기 패스워드 고정
|
// 패스워드 암호화, 초기 패스워드 고정
|
||||||
String hashedPassword = BCrypt.hashpw(password, salt);
|
String hashedPassword = BCrypt.hashpw(password, salt);
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package com.kamco.cd.kamcoback.postgres.entity;
|
package com.kamco.cd.kamcoback.postgres.entity;
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.EmbeddedId;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.UUID;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
@@ -18,12 +17,8 @@ import org.hibernate.annotations.ColumnDefault;
|
|||||||
@Table(name = "tb_member_archived")
|
@Table(name = "tb_member_archived")
|
||||||
public class MemberArchivedEntity {
|
public class MemberArchivedEntity {
|
||||||
|
|
||||||
@Id
|
@EmbeddedId
|
||||||
@Column(name = "uuid", nullable = false)
|
private MemberArchivedEntityId id;
|
||||||
private UUID uuid;
|
|
||||||
|
|
||||||
@Column(name = "id", nullable = false)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Size(max = 50)
|
@Size(max = 50)
|
||||||
@Column(name = "employee_no", length = 50)
|
@Column(name = "employee_no", length = 50)
|
||||||
@@ -56,4 +51,5 @@ public class MemberArchivedEntity {
|
|||||||
@ColumnDefault("now()")
|
@ColumnDefault("now()")
|
||||||
@Column(name = "archived_dttm", nullable = false)
|
@Column(name = "archived_dttm", nullable = false)
|
||||||
private ZonedDateTime archivedDttm;
|
private ZonedDateTime archivedDttm;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.kamco.cd.kamcoback.postgres.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Embeddable;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Embeddable
|
||||||
|
public class MemberArchivedEntityId implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7102800377481389036L;
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "user_id", nullable = false)
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name = "uuid", nullable = false)
|
||||||
|
private UUID uuid;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
MemberArchivedEntityId entity = (MemberArchivedEntityId) o;
|
||||||
|
return Objects.equals(this.userId, entity.userId) &&
|
||||||
|
Objects.equals(this.uuid, entity.uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(userId, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user