(1) 로그인 qsp 연동 개발, (2) qsp url 설정
This commit is contained in:
parent
d65065ccee
commit
9c2d1c48af
6
pom.xml
6
pom.xml
@ -105,6 +105,12 @@
|
|||||||
<version>3.16.0</version>
|
<version>3.16.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.18.0-rc1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -1,11 +1,21 @@
|
|||||||
package com.interplug.qcast.biz.login;
|
package com.interplug.qcast.biz.login;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.PatchMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.interplug.qcast.biz.login.dto.JoinUser;
|
||||||
import com.interplug.qcast.biz.login.dto.LoginUser;
|
import com.interplug.qcast.biz.login.dto.LoginUser;
|
||||||
|
import com.interplug.qcast.biz.login.dto.UserLoginResponse;
|
||||||
|
import com.interplug.qcast.biz.login.dto.UserPassword;
|
||||||
import com.interplug.qcast.biz.login.dto.UserResponse;
|
import com.interplug.qcast.biz.login.dto.UserResponse;
|
||||||
|
import com.interplug.qcast.util.DefaultResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@ -15,15 +25,10 @@ public class LoginController {
|
|||||||
// @Autowired private LoginService loginService;
|
// @Autowired private LoginService loginService;
|
||||||
private final LoginService loginService;
|
private final LoginService loginService;
|
||||||
|
|
||||||
|
@Operation(description = "Q.CAST III에 로그인하여 사용자 정보를 획득한다.")
|
||||||
@PostMapping("/v1.0/login")
|
@PostMapping("/v1.0/login")
|
||||||
@ResponseStatus(HttpStatus.OK)
|
public UserLoginResponse login(@RequestBody LoginUser loginUser) throws Exception {
|
||||||
public void login(@RequestBody LoginUser loginUser) {
|
return loginService.getLogin(loginUser);
|
||||||
log.warn(String.valueOf(log.isDebugEnabled()));
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Login username : " + loginUser.getUsername());
|
|
||||||
log.debug("Login password : " + loginUser.getPassword());
|
|
||||||
log.debug("isLogin : " + loginService.getLogin(loginUser));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/v1.0/user")
|
@PostMapping("/v1.0/user")
|
||||||
@ -31,4 +36,23 @@ public class LoginController {
|
|||||||
public UserResponse getUser(@RequestBody LoginUser loginUser) {
|
public UserResponse getUser(@RequestBody LoginUser loginUser) {
|
||||||
return loginService.getUser(loginUser);
|
return loginService.getUser(loginUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(description = "가입 신청 정보를 등록한다.")
|
||||||
|
@PostMapping("/v1.0/user/join")
|
||||||
|
@ResponseStatus(HttpStatus.CREATED)
|
||||||
|
public DefaultResponse joinUser(@RequestBody JoinUser joinUser) throws Exception {
|
||||||
|
return loginService.joinUser(joinUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(description = "비밀번호를 초기화한다.")
|
||||||
|
@PatchMapping("/v1.0/user/init-password")
|
||||||
|
public DefaultResponse initPassword(@RequestBody UserPassword userPassword) throws Exception {
|
||||||
|
return loginService.initPassword(userPassword);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(description = "비밀번호를 변경한다.")
|
||||||
|
@PatchMapping("/v1.0/user/change-password")
|
||||||
|
public DefaultResponse changePassword(@RequestBody UserPassword userPassword) throws Exception {
|
||||||
|
return loginService.changePassword(userPassword);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,19 @@
|
|||||||
package com.interplug.qcast.biz.login;
|
package com.interplug.qcast.biz.login;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.interplug.qcast.biz.login.dto.JoinUser;
|
||||||
import com.interplug.qcast.biz.login.dto.LoginUser;
|
import com.interplug.qcast.biz.login.dto.LoginUser;
|
||||||
|
import com.interplug.qcast.biz.login.dto.UserLoginResponse;
|
||||||
|
import com.interplug.qcast.biz.login.dto.UserPassword;
|
||||||
import com.interplug.qcast.biz.login.dto.UserResponse;
|
import com.interplug.qcast.biz.login.dto.UserResponse;
|
||||||
|
import com.interplug.qcast.util.DefaultResponse;
|
||||||
|
import com.interplug.qcast.util.InterfaceQsp;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -12,13 +21,180 @@ import org.springframework.stereotype.Service;
|
|||||||
public class LoginService {
|
public class LoginService {
|
||||||
// @Autowired LoginMapper loginMapper;
|
// @Autowired LoginMapper loginMapper;
|
||||||
private final LoginMapper loginMapper;
|
private final LoginMapper loginMapper;
|
||||||
|
private final InterfaceQsp interfaceQsp;
|
||||||
|
|
||||||
public boolean getLogin(LoginUser loginUser) {
|
@Value("${qsp.url}")
|
||||||
return loginMapper.getLogin(loginUser);
|
private String qspUrl;
|
||||||
|
|
||||||
|
// 로그인 처리
|
||||||
|
public UserLoginResponse getLogin(LoginUser loginUser) throws Exception {
|
||||||
|
if (loginUser == null)
|
||||||
|
throw new IllegalArgumentException("DTO 설정이 필요합니다.");
|
||||||
|
|
||||||
|
if (loginUser.getLangCd() == null || "".equals(loginUser.getLangCd()))
|
||||||
|
throw new IllegalArgumentException("Language Code" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (loginUser.getLastEditUser() == null || "".equals(loginUser.getLastEditUser()))
|
||||||
|
throw new IllegalArgumentException("Last Edit User Id" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (loginUser.getLoginId() == null || "".equals(loginUser.getLoginId()))
|
||||||
|
throw new IllegalArgumentException("Login Id" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (loginUser.getPwd() == null || "".equals(loginUser.getPwd()))
|
||||||
|
throw new IllegalArgumentException("Password" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
UserLoginResponse userLoginResponse = null;
|
||||||
|
|
||||||
|
// QSP API Call..
|
||||||
|
// Q.CAST 로그인
|
||||||
|
// post
|
||||||
|
// /api/user/login
|
||||||
|
String strResponse =
|
||||||
|
interfaceQsp.callApi(HttpMethod.POST, qspUrl + "/api/user/login", loginUser);
|
||||||
|
if (!"".equals(strResponse)) {
|
||||||
|
ObjectMapper om =
|
||||||
|
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
userLoginResponse = om.readValue(strResponse, UserLoginResponse.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
return userLoginResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserResponse getUser(LoginUser loginUser) {
|
public UserResponse getUser(LoginUser loginUser) {
|
||||||
log.info("Build Test");
|
log.info("Build Test");
|
||||||
return loginMapper.getUser(loginUser);
|
return loginMapper.getUser(loginUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 가입 신청 등록
|
||||||
|
public DefaultResponse joinUser(JoinUser joinUser) throws Exception {
|
||||||
|
if (joinUser == null)
|
||||||
|
throw new IllegalArgumentException("DTO 설정이 필요합니다.");
|
||||||
|
|
||||||
|
if (joinUser.getLangCd() == null || "".equals(joinUser.getLangCd()))
|
||||||
|
throw new IllegalArgumentException("Language Code" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getLastEditUser() == null || "".equals(joinUser.getLastEditUser()))
|
||||||
|
throw new IllegalArgumentException("Last Edit User Id" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getStoreQcastNm() == null || "".equals(joinUser.getStoreQcastNm()))
|
||||||
|
throw new IllegalArgumentException("Store QCast Name" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getStoreQcastNmKana() == null || "".equals(joinUser.getStoreQcastNmKana()))
|
||||||
|
throw new IllegalArgumentException("Store QCast Name Kana" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getPostCd() == null || "".equals(joinUser.getPostCd()))
|
||||||
|
throw new IllegalArgumentException("Postal Code" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getAddr() == null || "".equals(joinUser.getAddr()))
|
||||||
|
throw new IllegalArgumentException("Address" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getTelNo() == null || "".equals(joinUser.getTelNo()))
|
||||||
|
throw new IllegalArgumentException("Telephone" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getFax() == null || "".equals(joinUser.getFax()))
|
||||||
|
throw new IllegalArgumentException("Fax" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getUserInfo() == null)
|
||||||
|
throw new IllegalArgumentException("사용자 정보 DTO 설정이 필요합니다.");
|
||||||
|
|
||||||
|
if (joinUser.getUserInfo().getUserId() == null || "".equals(joinUser.getUserInfo().getUserId()))
|
||||||
|
throw new IllegalArgumentException("User Id" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getUserInfo().getUserNm() == null || "".equals(joinUser.getUserInfo().getUserNm()))
|
||||||
|
throw new IllegalArgumentException("Name" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getUserInfo().getUserNmKana() == null
|
||||||
|
|| "".equals(joinUser.getUserInfo().getUserNmKana()))
|
||||||
|
throw new IllegalArgumentException("Name_Kana" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getUserInfo().getTelNo() == null || "".equals(joinUser.getUserInfo().getTelNo()))
|
||||||
|
throw new IllegalArgumentException("Telephone" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getUserInfo().getFax() == null || "".equals(joinUser.getUserInfo().getFax()))
|
||||||
|
throw new IllegalArgumentException("Fax" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (joinUser.getUserInfo().getEmail() == null || "".equals(joinUser.getUserInfo().getEmail()))
|
||||||
|
throw new IllegalArgumentException("E-Mail" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
// QSP API Call..
|
||||||
|
// Q.CAST 신규 사용자 요청
|
||||||
|
// post
|
||||||
|
// /api/user/newUserIdReq
|
||||||
|
DefaultResponse defaultResponse = null;
|
||||||
|
String strResponse =
|
||||||
|
interfaceQsp.callApi(HttpMethod.POST, qspUrl + "/api/user/newUserIdReq", joinUser);
|
||||||
|
if (!"".equals(strResponse)) {
|
||||||
|
ObjectMapper om =
|
||||||
|
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
defaultResponse = om.readValue(strResponse, DefaultResponse.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 비밀번호 초기화
|
||||||
|
public DefaultResponse initPassword(UserPassword userPassword) throws Exception {
|
||||||
|
if (userPassword == null)
|
||||||
|
throw new IllegalArgumentException("DTO 설정이 필요합니다.");
|
||||||
|
|
||||||
|
if (userPassword.getLangCd() == null || "".equals(userPassword.getLangCd()))
|
||||||
|
throw new IllegalArgumentException("Language Code" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (userPassword.getLastEditUser() == null || "".equals(userPassword.getLastEditUser()))
|
||||||
|
throw new IllegalArgumentException("Last Edit User Id" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (userPassword.getLoginId() == null || "".equals(userPassword.getLoginId()))
|
||||||
|
throw new IllegalArgumentException("Login Id" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (userPassword.getEmail() == null || "".equals(userPassword.getEmail()))
|
||||||
|
throw new IllegalArgumentException("E-Mail" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
// QSP API Call..
|
||||||
|
// Q.CAST 비밀번호 초기화
|
||||||
|
// post
|
||||||
|
// /api/user/initUserPwd
|
||||||
|
DefaultResponse defaultResponse = null;
|
||||||
|
String strResponse =
|
||||||
|
interfaceQsp.callApi(HttpMethod.POST, qspUrl + "/api/user/initUserPwd", userPassword);
|
||||||
|
if (!"".equals(strResponse)) {
|
||||||
|
ObjectMapper om =
|
||||||
|
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
defaultResponse = om.readValue(strResponse, DefaultResponse.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 비밀번호 변경
|
||||||
|
public DefaultResponse changePassword(UserPassword userPassword) throws Exception {
|
||||||
|
if (userPassword == null)
|
||||||
|
throw new IllegalArgumentException("DTO 설정이 필요합니다.");
|
||||||
|
|
||||||
|
if (userPassword.getLangCd() == null || "".equals(userPassword.getLangCd()))
|
||||||
|
throw new IllegalArgumentException("Language Code" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (userPassword.getLastEditUser() == null || "".equals(userPassword.getLastEditUser()))
|
||||||
|
throw new IllegalArgumentException("Last Edit User Id" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (userPassword.getPwd() == null || "".equals(userPassword.getPwd()))
|
||||||
|
throw new IllegalArgumentException("Now Password" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
if (userPassword.getChgPwd() == null || "".equals(userPassword.getChgPwd()))
|
||||||
|
throw new IllegalArgumentException("Change Password" + "은(는) 필수값입니다.");
|
||||||
|
|
||||||
|
// QSP API Call..
|
||||||
|
// Q.CAST 비밀번호 변경
|
||||||
|
// post
|
||||||
|
// /api/user/userPwdChg
|
||||||
|
DefaultResponse defaultResponse = null;
|
||||||
|
String strResponse =
|
||||||
|
interfaceQsp.callApi(HttpMethod.POST, qspUrl + "/api/user/userPwdChg", userPassword);
|
||||||
|
if (!"".equals(strResponse)) {
|
||||||
|
ObjectMapper om =
|
||||||
|
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
defaultResponse = om.readValue(strResponse, DefaultResponse.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultResponse;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
package com.interplug.qcast.biz.login.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class JoinUser {
|
||||||
|
private String langCd; // Language Code
|
||||||
|
private String lastEditUser; // Last Edit User Id
|
||||||
|
private String storeQcastNm; // Store QCast Name
|
||||||
|
private String storeQcastNmKana; // Store QCast Name Kana
|
||||||
|
private String postCd; // Postal Code
|
||||||
|
private String addr; // Address
|
||||||
|
private String telNo; // Telephone
|
||||||
|
private String fax; // Fax
|
||||||
|
private String payTermsCd; // Pay Terms Code
|
||||||
|
private String kamId; // Kam Id
|
||||||
|
private String qtCompNm; // Quotation Company name
|
||||||
|
private String qtPostCd; // Quotation Postal Code
|
||||||
|
private String qtAddr; // Quotation Address
|
||||||
|
private String qtTelNo; // Quotation Telephone
|
||||||
|
private String qtFax; // Quotation Fax
|
||||||
|
private String qtEmail; // Quotation E-Mail
|
||||||
|
private UserInfo userInfo; // user information
|
||||||
|
}
|
||||||
@ -4,6 +4,8 @@ import lombok.Data;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class LoginUser {
|
public class LoginUser {
|
||||||
private String username;
|
private String langCd; // Language Code
|
||||||
private String password;
|
private String lastEditUser; // Last Edit User Id
|
||||||
|
private String loginId; // Login Id
|
||||||
|
private String pwd; // Password
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.interplug.qcast.biz.login.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class UserInfo {
|
||||||
|
private String userId; // User Id
|
||||||
|
private String userNm; // Name
|
||||||
|
private String userNmKana; // Name_Kana
|
||||||
|
private String telNo; // Telephone
|
||||||
|
private String fax; // Fax
|
||||||
|
private String email; // E-Mail
|
||||||
|
private String category; // Category
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package com.interplug.qcast.biz.login.dto;
|
||||||
|
|
||||||
|
import com.interplug.qcast.util.DefaultResponse;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class UserLoginResponse extends DefaultResponse {
|
||||||
|
private UserResponse data;
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package com.interplug.qcast.biz.login.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class UserPassword {
|
||||||
|
private String langCd; // Language Code
|
||||||
|
private String lastEditUser; // Last Edit User Id
|
||||||
|
private String loginId; // Login Id
|
||||||
|
private String email; // Email
|
||||||
|
private String pwd; // Now Password
|
||||||
|
private String chgPwd; // Change Password
|
||||||
|
}
|
||||||
@ -12,4 +12,15 @@ public class UserResponse {
|
|||||||
private String name;
|
private String name;
|
||||||
private String mail;
|
private String mail;
|
||||||
private String tel;
|
private String tel;
|
||||||
|
|
||||||
|
private String storeId; // Store Id
|
||||||
|
// private String userId; // User Id
|
||||||
|
private String userNm; // Name
|
||||||
|
private String userNmKana; // Name_Kana
|
||||||
|
private String category; // Category
|
||||||
|
private String telNo; // Telephone
|
||||||
|
private String fax; // Fax
|
||||||
|
private String email; // E-Mail
|
||||||
|
private String pwdInitYn; // Password Init Yn
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/main/java/com/interplug/qcast/util/DefaultResponse.java
Normal file
10
src/main/java/com/interplug/qcast/util/DefaultResponse.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package com.interplug.qcast.util;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class DefaultResponse {
|
||||||
|
private DefaultResponseResult result;
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package com.interplug.qcast.util;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class DefaultResponseResult {
|
||||||
|
private int code; // Result Code(success : 200, error : 400)
|
||||||
|
private String message; // Result Message
|
||||||
|
private String resultCode; // Result Code2(success : S, error : E)
|
||||||
|
private String resultMsg; // Result Message2
|
||||||
|
}
|
||||||
76
src/main/java/com/interplug/qcast/util/InterfaceQsp.java
Normal file
76
src/main/java/com/interplug/qcast/util/InterfaceQsp.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package com.interplug.qcast.util;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class InterfaceQsp {
|
||||||
|
/**
|
||||||
|
* API Call
|
||||||
|
*
|
||||||
|
* @param apiPath
|
||||||
|
* @param requestObject
|
||||||
|
* @return String
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public String callApi(HttpMethod httpMethod, String apiPath, Object requestObject)
|
||||||
|
throws Exception {
|
||||||
|
|
||||||
|
URL url = null;
|
||||||
|
HttpURLConnection con = null;
|
||||||
|
OutputStreamWriter osw = null;
|
||||||
|
BufferedReader br = null;
|
||||||
|
StringBuilder sb = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
url = new URL(apiPath);
|
||||||
|
con = (HttpURLConnection) url.openConnection();
|
||||||
|
con.setConnectTimeout(5000); // 서버에 연결되는 Timeout 시간 설정
|
||||||
|
con.setReadTimeout(5000); // InputStream 읽어 오는 Timeout 시간 설정
|
||||||
|
con.setRequestMethod(httpMethod.toString());
|
||||||
|
con.setRequestProperty("Content-Type", "application/json");
|
||||||
|
con.setDoInput(true);
|
||||||
|
con.setDoOutput(true); // POST 데이터를 OutputStream으로 넘겨 주겠다는 설정
|
||||||
|
con.setUseCaches(false);
|
||||||
|
con.setDefaultUseCaches(false);
|
||||||
|
|
||||||
|
ObjectMapper om = new ObjectMapper();
|
||||||
|
osw = new OutputStreamWriter(con.getOutputStream());
|
||||||
|
osw.write(om.writeValueAsString(requestObject)); // json 형식의 message 전달
|
||||||
|
osw.flush();
|
||||||
|
|
||||||
|
sb = new StringBuilder();
|
||||||
|
if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||||
|
br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
|
||||||
|
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (osw != null)
|
||||||
|
osw.close();
|
||||||
|
if (br != null)
|
||||||
|
br.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb != null ? sb.toString() : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
86
src/main/java/com/interplug/qcast/util/ZipFileManager.java
Normal file
86
src/main/java/com/interplug/qcast/util/ZipFileManager.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package com.interplug.qcast.util;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ZipFileManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* zip file을 생성하여 ZipOutputStream를 반환하는 method
|
||||||
|
*
|
||||||
|
* @param response HttpServletResponse
|
||||||
|
* @param strCreateFileName 생성할 file 이름
|
||||||
|
* @param listFilePath 파일 경로 목록
|
||||||
|
*/
|
||||||
|
public void createZipFile(HttpServletResponse response, String strCreateFileName,
|
||||||
|
List<String> listFilePath) throws Exception {
|
||||||
|
// 압축될 파일명이 존재하지 않을 경우
|
||||||
|
if (strCreateFileName == null || "".equals(strCreateFileName))
|
||||||
|
throw new IllegalArgumentException("파일명이 존재하지 않습니다.");
|
||||||
|
|
||||||
|
// 파일이 존재하지 않을 경우
|
||||||
|
if (listFilePath == null || listFilePath.size() == 0)
|
||||||
|
throw new IllegalArgumentException("파일이 존재하지 않습니다.");
|
||||||
|
|
||||||
|
// zip 파일명
|
||||||
|
String strZipName = strCreateFileName + ".zip";
|
||||||
|
|
||||||
|
// response 설정
|
||||||
|
response.setContentType("application/zip");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=" + strZipName + ";");
|
||||||
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
|
||||||
|
try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
|
||||||
|
for (String strSourceFile : listFilePath) {
|
||||||
|
Path path = Path.of(strSourceFile);
|
||||||
|
|
||||||
|
try (FileInputStream fis = new FileInputStream(path.toFile())) {
|
||||||
|
// 압축될 파일명을 ZipEntry에 담아준다
|
||||||
|
ZipEntry zipEntry = new ZipEntry(path.getFileName().toString());
|
||||||
|
|
||||||
|
// 압축될 파일명을 ZipOutputStream 에 담아준다
|
||||||
|
zos.putNextEntry(zipEntry);
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
|
||||||
|
while ((length = fis.read(buffer)) >= 0) {
|
||||||
|
zos.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
throw new IllegalArgumentException("파일 변환 작업중, [ " + strZipName + " ] 파일을 찾을 수 없습니다.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"파일 변환 작업중, [ " + strZipName + " ] 파일을 다운로드 할 수 없습니다.");
|
||||||
|
} finally {
|
||||||
|
// ZipOutputStream 에 담아둔 압축될 파일명을 flush 시켜준다
|
||||||
|
zos.flush();
|
||||||
|
// ZipOutputStream 에 담아둔 압축될 파일명을 close 시켜준다
|
||||||
|
zos.closeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
// response 에 담아둔 파일을 flush 시켜준다
|
||||||
|
response.flushBuffer();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,3 +22,7 @@ spring:
|
|||||||
pool-name: Read-HikariPool
|
pool-name: Read-HikariPool
|
||||||
jackson:
|
jackson:
|
||||||
time-zone: Asia/Seoul
|
time-zone: Asia/Seoul
|
||||||
|
|
||||||
|
#QSP
|
||||||
|
qsp:
|
||||||
|
url: http://172.23.4.129:8120
|
||||||
|
|||||||
@ -23,3 +23,6 @@ spring:
|
|||||||
jackson:
|
jackson:
|
||||||
time-zone: Asia/Seoul
|
time-zone: Asia/Seoul
|
||||||
|
|
||||||
|
#QSP
|
||||||
|
qsp:
|
||||||
|
url: http://localhost:8120
|
||||||
|
|||||||
@ -22,3 +22,7 @@ spring:
|
|||||||
pool-name: Read-HikariPool
|
pool-name: Read-HikariPool
|
||||||
jackson:
|
jackson:
|
||||||
time-zone: Asia/Seoul
|
time-zone: Asia/Seoul
|
||||||
|
|
||||||
|
#QSP
|
||||||
|
qsp:
|
||||||
|
url: http://jp.qsalesplatform.com
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user