From 5ed807b7170cb174557c966cd3d8d08a18842278 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Thu, 7 Jul 2022 19:31:54 +0900 Subject: [PATCH] config: config set --- build.gradle | 7 +++- .../cmm/repository/ICmmUserRepository.java | 3 ++ .../impl/CustomMinOAuth2UserService.java | 10 ++--- .../impl/CustomMinUserDetailsService.java | 4 +- .../ctgy/repository/IMinUserRepository.java | 30 ------------- .../xit/biz/ctgy/v2/repository/UserDao.java | 42 ++++++++++++++++++- .../ctgy/v2/service/impl/MinUserService.java | 7 +--- 7 files changed, 57 insertions(+), 46 deletions(-) delete mode 100644 src/main/java/com/xit/biz/ctgy/repository/IMinUserRepository.java diff --git a/build.gradle b/build.gradle index c8aaf2f..434d5a5 100644 --- a/build.gradle +++ b/build.gradle @@ -135,6 +135,9 @@ dependencies { //-----------------------------------------------------------------------------------// runtimeOnly 'com.h2database:h2:1.4.199' // 2.0.202 사용시 에러 발생 // implementation 'org.postgresql:postgresql:42.3.1' + // https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc8 + //implementation group: 'com.oracle.jdbc', name: 'ojdbc8', version: '12.2.0.1' + //-----------------------------------------------------------------------------------// @@ -209,8 +212,8 @@ dependencies { testImplementation 'org.springframework.security:spring-security-test' // querydsl - testImplementation "com.querydsl:querydsl-jpa:${queryDslVersion}" - testAnnotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}" + //testImplementation "com.querydsl:querydsl-jpa:${queryDslVersion}" + //testAnnotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}" testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/com/xit/biz/cmm/repository/ICmmUserRepository.java b/src/main/java/com/xit/biz/cmm/repository/ICmmUserRepository.java index cc7d0f3..65030a4 100644 --- a/src/main/java/com/xit/biz/cmm/repository/ICmmUserRepository.java +++ b/src/main/java/com/xit/biz/cmm/repository/ICmmUserRepository.java @@ -1,3 +1,4 @@ +/* package com.xit.biz.cmm.repository; import com.xit.biz.cmm.entity.CmmUser; @@ -13,3 +14,5 @@ public interface ICmmUserRepository extends JpaRepository { //Optional findOneWithAuthorities(String userId); } +*/ + diff --git a/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinOAuth2UserService.java b/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinOAuth2UserService.java index 2dbc5cc..975b336 100644 --- a/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinOAuth2UserService.java +++ b/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinOAuth2UserService.java @@ -1,9 +1,8 @@ package com.xit.biz.ctgy.auth.service.impl; import com.xit.biz.ctgy.auth.UserMinPrincipal; -import com.xit.biz.ctgy.dto.MinUserinfoDto; import com.xit.biz.ctgy.entity.MinUserinfo; -import com.xit.biz.ctgy.repository.IMinUserRepository; +import com.xit.biz.ctgy.v2.repository.UserDao; import com.xit.core.oauth2.oauth.entity.ProviderType; import com.xit.core.oauth2.oauth.info.AbstractOAuth2UserInfo; import com.xit.core.oauth2.oauth.info.OAuth2UserInfoFactory; @@ -22,7 +21,7 @@ import java.util.Optional; @RequiredArgsConstructor public class CustomMinOAuth2UserService extends DefaultOAuth2UserService { - private final IMinUserRepository userRepository; + private final UserDao userDao; @Override public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException { @@ -44,7 +43,7 @@ public class CustomMinOAuth2UserService extends DefaultOAuth2UserService { AbstractOAuth2UserInfo userInfo = OAuth2UserInfoFactory.getOAuth2UserInfo(providerType, user.getAttributes()); MinUserinfo savedUser = null; - Optional optionalCmmUser = userRepository.findByUserid(userInfo.getId()); + Optional optionalCmmUser = userDao.findByUseridUseAuth(userInfo.getId()); if(optionalCmmUser.isPresent()) { // savedUser = optionalCmmUser.get(); @@ -81,7 +80,8 @@ public class CustomMinOAuth2UserService extends DefaultOAuth2UserService { .name(userInfo.getName()) .email(userInfo.getEmail()) .build(); - return userRepository.saveAndFlush(user); + userDao.insertMinUserinfo(user); + return userDao.findByUseridUseAuth(userInfo.getId()).get(); } // private void updateUser(MinUserinfo user, AbstractOAuth2UserInfo userInfo) { diff --git a/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinUserDetailsService.java b/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinUserDetailsService.java index f6a9d48..93f87db 100644 --- a/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinUserDetailsService.java +++ b/src/main/java/com/xit/biz/ctgy/auth/service/impl/CustomMinUserDetailsService.java @@ -16,11 +16,11 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class CustomMinUserDetailsService implements UserDetailsService { - private final UserDao minUserinfoDao; + private final UserDao userDao; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - MinUserinfoDto user = minUserinfoDao.findByUserid(username).orElseThrow(() -> new CustomBaseException(ErrorCode.USER_NOT_FOUND)); + MinUserinfoDto user = userDao.findByUserid(username).orElseThrow(() -> new CustomBaseException(ErrorCode.USER_NOT_FOUND)); return UserMinPrincipal.create(MinUserinfo.builder() .userid(user.getUserid()) .passwd(user.getPasswd()) diff --git a/src/main/java/com/xit/biz/ctgy/repository/IMinUserRepository.java b/src/main/java/com/xit/biz/ctgy/repository/IMinUserRepository.java deleted file mode 100644 index 90a0476..0000000 --- a/src/main/java/com/xit/biz/ctgy/repository/IMinUserRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.xit.biz.ctgy.repository; - -import com.xit.biz.ctgy.CtgyConstants; -import com.xit.biz.ctgy.entity.MinUserinfo; -import com.xit.core.oauth2.utils.SecurityUtil; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Optional; - -public interface IMinUserRepository extends JpaRepository { - Optional findByUserid(final String userid); - - @Query(value = "SELECT TRAFFIC.ECL_ENCRYPT(?1) AS passwd FROM DUAL C", nativeQuery = true) - //@Query(value = "SELECT ECL_ENCRYPT(?1) AS passwd", nativeQuery = true) - String queryGetPasswdEncode(@Param("passwd") final String passwd); - - @Query(value = "SELECT ECL_DECRYPT(MU.passwd) AS passwd FROM min_userinfo MU WHERE MU.userid = ?1", nativeQuery = true) - String queryGetPasswd(@Param("userid") final String userid); - - MinUserinfo findMinUserinfoByUserid(final String userid); - - //------------------------------------------------------------------------- - // 주정차위반 심사대상 등록 - 등록 대상 심사자 조회 - //------------------------------------------------------------------------- - List findAllByTeamAndIsenableAndAccesstype(String msuTeam, String isenabled, String accesstype); -} \ No newline at end of file diff --git a/src/main/java/com/xit/biz/ctgy/v2/repository/UserDao.java b/src/main/java/com/xit/biz/ctgy/v2/repository/UserDao.java index 2b5202d..1d7b950 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/repository/UserDao.java +++ b/src/main/java/com/xit/biz/ctgy/v2/repository/UserDao.java @@ -1,6 +1,7 @@ package com.xit.biz.ctgy.v2.repository; import com.xit.biz.ctgy.dto.MinUserinfoDto; +import com.xit.biz.ctgy.entity.MinUserinfo; import com.xit.core.config.database.BaseMpowerDaoSupport; import com.xit.core.support.sql.parser.QueryGenerator; import lombok.extern.slf4j.Slf4j; @@ -25,6 +26,14 @@ public class UserDao extends BaseMpowerDaoSupport { return Optional.ofNullable(selectOne(MinUserinfoDto.class, sql, fieldsStrs)); } + public Optional findByUseridUseAuth(@NotNull final String userid){ + final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectUserInfo") + .setParameter("userid", userid) + .getQueryString(); + final String fieldsStrs = "userid, passwd, name, regnum, mphone, email, accesstype, team, isenable, gu"; + return Optional.ofNullable(selectOne(MinUserinfo.class, sql, fieldsStrs)); + } + public String queryGetPasswdEncode(@NotNull final String passwd){ final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "selectPasswdEnc") .setParameter("passwd", passwd) @@ -78,7 +87,36 @@ public class UserDao extends BaseMpowerDaoSupport { return selectList(MinUserinfoDto.class, listSql, cntSql, fieldStrs, pageable); } - public void insertMinUserinfo(@NotNull final MinUserinfoDto dto) { + public void insertMinUserinfoDto(@NotNull final MinUserinfoDto dto) { + final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "insertMinUserinfo") + .setParameter("userid", dto.getUserid()) + .setParameter("accesstype", dto.getAccesstype()) + .setParameter("email", dto.getEmail()) + .setParameter("isenable", dto.getIsenable()) + .setParameter("mphone", dto.getMphone()) + .setParameter("name", dto.getName()) + .setParameter("passwd", dto.getPasswd()) + .setParameter("regdate", dto.getRegdate()) + .setParameter("team", dto.getTeam()) + .setParameter("gu", dto.getGu()) + .getQueryString(); + insert(sql); + } + + public void updateMinUserinfoDto(MinUserinfoDto dto) { + final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "updateMinUserinfo") + .setParameter("userid", dto.getUserid()) + .setParameter("accesstype", dto.getAccesstype()) + .setParameter("email", dto.getEmail()) + .setParameter("mphone", dto.getMphone()) + .setParameter("name", dto.getName()) + .setParameter("passwd", dto.getPasswd()) + .setParameter("team", dto.getTeam()) + .getQueryString(); + update(sql); + } + + public void insertMinUserinfo(@NotNull final MinUserinfo dto) { final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "insertMinUserinfo") .setParameter("userid", dto.getUserid()) .setParameter("accesstype", dto.getAccesstype()) @@ -94,7 +132,7 @@ public class UserDao extends BaseMpowerDaoSupport { insert(sql); } - public void updateMinUserinfo(MinUserinfoDto dto) { + public void updateMinUserinfo(MinUserinfo dto) { final String sql = QueryGenerator.createNamedQuery(NAME_SPACE, "updateMinUserinfo") .setParameter("userid", dto.getUserid()) .setParameter("accesstype", dto.getAccesstype()) diff --git a/src/main/java/com/xit/biz/ctgy/v2/service/impl/MinUserService.java b/src/main/java/com/xit/biz/ctgy/v2/service/impl/MinUserService.java index 98d8cd2..9ea98f9 100644 --- a/src/main/java/com/xit/biz/ctgy/v2/service/impl/MinUserService.java +++ b/src/main/java/com/xit/biz/ctgy/v2/service/impl/MinUserService.java @@ -1,7 +1,6 @@ package com.xit.biz.ctgy.v2.service.impl; import com.xit.biz.ctgy.dto.MinUserinfoDto; -import com.xit.biz.ctgy.entity.MinUserinfo; import com.xit.biz.ctgy.v2.repository.UserDao; import com.xit.biz.ctgy.v2.service.IMinUserService; import com.xit.core.constant.ErrorCode; @@ -16,8 +15,6 @@ 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 { @@ -51,11 +48,11 @@ public class MinUserService implements IMinUserService { if("Y".equals(dto.getNewYn())){ if(opUser.isPresent() && !Checks.isEmpty(opUser.get().getUserid())) throw new CustomBaseException(ErrorCode.MEMBER_EXISTS); dto.setSaveInit(); - userDao.insertMinUserinfo(dto); + userDao.insertMinUserinfoDto(dto); }else{ // 비밀번호가 다른 경우 //if(!savedDto.get().getPasswd().equals(encPasswd)) dto.setPasswd(encPasswd); - userDao.updateMinUserinfo(dto); + userDao.updateMinUserinfoDto(dto); } }