From f5894c88dfaeabbed6323bf3cd53ace151a1f69b Mon Sep 17 00:00:00 2001 From: minuk926 Date: Mon, 18 Apr 2022 20:19:11 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctgy/controller/MinUserController.java | 23 +++++++++- .../com/xit/biz/ctgy/dto/MinUserinfoDto.java | 8 ++-- .../com/xit/biz/ctgy/entity/MinUserinfo.java | 40 +++++++++--------- .../xit/biz/ctgy/service/IMinUserService.java | 5 +++ .../biz/ctgy/service/impl/MinUserService.java | 42 +++++++++++++------ 5 files changed, 82 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java b/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java index aef8d70..8b179d7 100644 --- a/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java +++ b/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java @@ -15,12 +15,15 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.mapstruct.factory.Mappers; import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; + @Tag(name = "MinUserController", description = "사용자 관리") @RestController @RequestMapping("/api/v1/ctgy/user") @@ -37,13 +40,13 @@ public class MinUserController { @Parameters({ @Parameter(in = ParameterIn.QUERY, name = "userid", description = "사용자ID", required = false, example = " "), @Parameter(in = ParameterIn.QUERY, name = "name", description = "이름", required = false, example = " "), + @Parameter(in = ParameterIn.QUERY, name = "team", description = "팀", required = false, example = "001"), @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") }) @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity findMinUsers( @Parameter(hidden = true) - @ModelAttribute("minUserinfoDto") final MinUserinfoDto minUserinfoDto, @Parameter(hidden = true) final Pageable pageable) { @@ -64,4 +67,22 @@ public class MinUserController { public ResponseEntity getMinUser(@PathVariable final String userid) { return RestResponse.of(service.findMinUserByUserid(userid)); } + + @Operation(summary = "사용자 정보 저장" , description = "사용자 정보 저장") + @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity saveMinUser( + @Valid + final MinUserinfoDto minUserinfoDto) { + service.saveMinUser(minUserinfoDto); + return RestResponse.of(HttpStatus.OK); + } + + @Operation(summary = "사용자 삭제" , description = "사용자 삭제") + @PutMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity removeMinUser( + @Valid + final MinUserinfoDto minUserinfoDto) { + service.removeMinUser(minUserinfoDto); + return RestResponse.of(HttpStatus.OK); + } } diff --git a/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java b/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java index c2d2a82..1e0f46c 100644 --- a/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java +++ b/src/main/java/com/xit/biz/ctgy/dto/MinUserinfoDto.java @@ -1,14 +1,10 @@ package com.xit.biz.ctgy.dto; -import com.xit.biz.ctgy.entity.MinSimsaUser680; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; -import javax.persistence.*; import java.io.Serializable; -import java.util.HashSet; import java.util.Objects; -import java.util.Set; @Schema(name = "MinUserinfoDto", description = "사용자 DTO") @Getter @@ -51,6 +47,10 @@ public class MinUserinfoDto implements Serializable { @Schema(required = false, title = "구청코드", example = " ", description = "Input Description...") private String gu; + + @Schema(required = true, title = "신규유저여부", example = "true", description = "신규유저여부: 'Y'인경우 id duplication check") + private String newYn; + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/com/xit/biz/ctgy/entity/MinUserinfo.java b/src/main/java/com/xit/biz/ctgy/entity/MinUserinfo.java index a181c26..3ad72f4 100644 --- a/src/main/java/com/xit/biz/ctgy/entity/MinUserinfo.java +++ b/src/main/java/com/xit/biz/ctgy/entity/MinUserinfo.java @@ -1,6 +1,5 @@ package com.xit.biz.ctgy.entity; -import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import org.hibernate.annotations.DynamicInsert; @@ -8,10 +7,10 @@ import org.hibernate.annotations.DynamicUpdate; import org.springframework.data.domain.Persistable; import javax.persistence.*; -import java.io.Serializable; -import java.util.HashSet; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Objects; -import java.util.Set; @Schema(name = "MinUserinfo", description = "null") @Table(name = "min_userinfo", schema = "", catalog = "") @@ -59,10 +58,11 @@ public class MinUserinfo implements Persistable { @Schema(required = false, title = "등록일시", example = " ", description = "Input Description...") @Column(name = "regdate", nullable = true) - private java.sql.Date regdate; + private LocalDate regdate; @Schema(required = false, title = "사용여부", example = " ", description = "Input Description...") @Column(name = "isenable", nullable = true, length = 1) + @Setter private String isenable; @Schema(required = false, title = "구청코드", example = " ", description = "Input Description...") @@ -81,20 +81,22 @@ public class MinUserinfo implements Persistable { } - //@Transient - //@JsonIgnore - //@OneToMany(targetEntity = MinSimsaUser680.class, mappedBy = "minUserinfo") //, fetch = FetchType.EAGER)//, cascade = CascadeType.ALL, orphanRemoval = true) - //private final Set minSimsaUser680s = new HashSet<>(); - -// public void addMinSimsaUser680(final MinSimsaUser680 minSimsaUser680){ -// minSimsaUser680s.add(minSimsaUser680); -// minSimsaUser680.setMinUserinfo(this); -// } -// -// public void removeSimsaUser680(final MinSimsaUser680 minSimsaUser680){ -// minSimsaUser680s.remove(minSimsaUser680); -// minSimsaUser680.setMinUserinfo(null); -// } + @PrePersist + public void onPrePersist(){ + LocalDateTime localDateTime = LocalDateTime.now(); + this.regdate = LocalDate.parse(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + this.isenable = "1"; + this.gu = "680"; + } + + @PreUpdate + public void onPreUpdate(){ +// LocalDateTime localDateTime = LocalDateTime.now(); +// this.inNalja = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); +// this.inTime = localDateTime.format(DateTimeFormatter.ofPattern("HH:mm")); +// this.inName = HeaderUtil.getUserName(); +// this.inHit = this.inHit + 1; + } @Override public boolean equals(Object o) { diff --git a/src/main/java/com/xit/biz/ctgy/service/IMinUserService.java b/src/main/java/com/xit/biz/ctgy/service/IMinUserService.java index 61fda32..f8a3c10 100644 --- a/src/main/java/com/xit/biz/ctgy/service/IMinUserService.java +++ b/src/main/java/com/xit/biz/ctgy/service/IMinUserService.java @@ -1,6 +1,7 @@ package com.xit.biz.ctgy.service; import com.xit.biz.cmm.entity.CmmUser; +import com.xit.biz.ctgy.dto.MinUserinfoDto; import com.xit.biz.ctgy.entity.MinUserinfo; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -14,4 +15,8 @@ public interface IMinUserService { MinUserinfo findMinUser(); MinUserinfo findMinUserByUserid(final String userId); + + void saveMinUser(MinUserinfoDto dto); + + void removeMinUser(MinUserinfoDto dto); } diff --git a/src/main/java/com/xit/biz/ctgy/service/impl/MinUserService.java b/src/main/java/com/xit/biz/ctgy/service/impl/MinUserService.java index 0e7c58e..3cf67f5 100644 --- a/src/main/java/com/xit/biz/ctgy/service/impl/MinUserService.java +++ b/src/main/java/com/xit/biz/ctgy/service/impl/MinUserService.java @@ -1,34 +1,35 @@ package com.xit.biz.ctgy.service.impl; +import com.xit.biz.ctgy.dto.MinUserinfoDto; +import com.xit.biz.ctgy.dto.struct.MinUserinfoMapstruct; import com.xit.biz.ctgy.entity.MinUserinfo; import com.xit.biz.ctgy.repository.IMinUserRepository; import com.xit.biz.ctgy.service.IMinUserService; +import com.xit.core.constant.ErrorCode; +import com.xit.core.exception.CustomBaseException; import com.xit.core.oauth2.utils.HeaderUtil; -import com.xit.core.support.jpa.JpaUtil; -import org.springframework.data.domain.Example; -import org.springframework.data.domain.ExampleMatcher; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; +import lombok.AllArgsConstructor; +import org.mapstruct.factory.Mappers; +import org.springframework.data.domain.*; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Optional; - import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains; +@AllArgsConstructor @Service public class MinUserService implements IMinUserService { + private final PasswordEncoder passwordEncoder; private final IMinUserRepository repository; - public MinUserService(IMinUserRepository repository) { - this.repository = repository; - } + private final MinUserinfoMapstruct mapstruct = Mappers.getMapper(MinUserinfoMapstruct.class); @Transactional//(readOnly = true) public Page findMinUsers(final MinUserinfo minUserinfo, Pageable pageable) { - //Sort sort = Sort.by(Sort.Direction.ASC, "codeOrdr"); - pageable = JpaUtil.getPagingInfo(pageable); + Sort sort = Sort.by(Sort.Direction.ASC, "team", "name"); + pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll() .withMatcher("userid", contains()) .withMatcher("name", contains()); @@ -47,7 +48,24 @@ public class MinUserService implements IMinUserService { } @Override + @Transactional(readOnly = true) public MinUserinfo findMinUserByUserid(final String userid) { return repository.findMinUserinfoByUserid(userid); } + + @Override + @Transactional + public void saveMinUser(MinUserinfoDto dto) { + if("Y".equals(dto.getNewYn()) && repository.findByUserid(dto.getUserid()).isPresent()) throw new CustomBaseException(ErrorCode.MEMBER_EXISTS); + dto.setPasswd(passwordEncoder.encode(dto.getPasswd())); + repository.save(mapstruct.toEntity(dto)); + } + + @Override + @Transactional + public void removeMinUser(MinUserinfoDto dto) { + MinUserinfo entity = repository.findByUserid(dto.getUserid()).orElseThrow(()-> new CustomBaseException(ErrorCode.USER_NOT_FOUND)); + entity.setIsenable("0"); + repository.save(entity); + } }