Merge pull request '[1004] 1:1 문의게시판 추가' (#26) from feature/cha into dev
Reviewed-on: #26
This commit is contained in:
commit
07c9884d31
@ -2,18 +2,15 @@ package com.interplug.qcast.biz.community;
|
||||
|
||||
import com.interplug.qcast.biz.community.dto.BoardRequest;
|
||||
import com.interplug.qcast.biz.community.dto.BoardResponse;
|
||||
import com.interplug.qcast.biz.file.dto.FileRequest;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@ -38,6 +35,13 @@ public class BoardController {
|
||||
return boardService.getBoardDetail(boardRequest);
|
||||
}
|
||||
|
||||
@Operation(description = "문의를 저장한다.")
|
||||
@PostMapping("/saveQna")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public BoardResponse getBoardQnaSave(BoardRequest boardRequest, HttpServletRequest request) throws Exception {
|
||||
return boardService.getBoardQnaSave(boardRequest, request);
|
||||
}
|
||||
|
||||
@Operation(description = "커뮤니티(공지사항, FAQ, 자료다운로드) 파일 다운로드를 진행한다.")
|
||||
@GetMapping("/file/download")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
|
||||
@ -4,24 +4,36 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.interplug.qcast.biz.community.dto.BoardRequest;
|
||||
import com.interplug.qcast.biz.community.dto.BoardResponse;
|
||||
import com.interplug.qcast.biz.estimate.dto.EstimateApiResponse;
|
||||
import com.interplug.qcast.biz.file.dto.FileRequest;
|
||||
import com.interplug.qcast.config.Exception.ErrorCode;
|
||||
import com.interplug.qcast.config.Exception.QcastException;
|
||||
import com.interplug.qcast.config.message.Messages;
|
||||
import com.interplug.qcast.util.InterfaceQsp;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@Slf4j
|
||||
@ -66,18 +78,39 @@ public class BoardService {
|
||||
encodedSchTitle = URLEncoder.encode(boardRequest.getSchTitle(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
String url = QSP_API_URL + "/api/board/list";
|
||||
String apiUrl =
|
||||
UriComponentsBuilder.fromHttpUrl(url)
|
||||
.queryParam("noticeNo", boardRequest.getNoticeNo())
|
||||
.queryParam("schTitle", encodedSchTitle)
|
||||
.queryParam("schNoticeTpCd", boardRequest.getSchNoticeTpCd())
|
||||
.queryParam("schNoticeClsCd", boardRequest.getSchNoticeClsCd())
|
||||
.queryParam("startRow", boardRequest.getStartRow())
|
||||
.queryParam("endRow", boardRequest.getEndRow())
|
||||
.queryParam("schMainYn", boardRequest.getSchMainYn())
|
||||
.build()
|
||||
.toUriString();
|
||||
String url = null;
|
||||
String apiUrl = null;
|
||||
|
||||
if("QNA".equals(boardRequest.getSchNoticeClsCd())) {
|
||||
url = QSP_API_URL + "/api/qna/list";
|
||||
apiUrl = UriComponentsBuilder.fromHttpUrl(url)
|
||||
.queryParam("compCd", boardRequest.getCompCd())
|
||||
.queryParam("storeId", boardRequest.getStoreId())
|
||||
.queryParam("siteTpCd", boardRequest.getSiteTpCd())
|
||||
.queryParam("schTitle", encodedSchTitle)
|
||||
.queryParam("schRegId", boardRequest.getSchRegId())
|
||||
.queryParam("schFromDt", boardRequest.getSchFromDt())
|
||||
.queryParam("schToDt", boardRequest.getSchToDt())
|
||||
.queryParam("startRow", boardRequest.getStartRow())
|
||||
.queryParam("endRow", boardRequest.getEndRow())
|
||||
.queryParam("loginId", boardRequest.getLoginId())
|
||||
.queryParam("langCd", boardRequest.getLangCd())
|
||||
.build()
|
||||
.toUriString();
|
||||
|
||||
} else {
|
||||
url = QSP_API_URL + "/api/board/list";
|
||||
apiUrl = UriComponentsBuilder.fromHttpUrl(url)
|
||||
.queryParam("noticeNo", boardRequest.getNoticeNo())
|
||||
.queryParam("schTitle", encodedSchTitle)
|
||||
.queryParam("schNoticeTpCd", boardRequest.getSchNoticeTpCd())
|
||||
.queryParam("schNoticeClsCd", boardRequest.getSchNoticeClsCd())
|
||||
.queryParam("startRow", boardRequest.getStartRow())
|
||||
.queryParam("endRow", boardRequest.getEndRow())
|
||||
.queryParam("schMainYn", boardRequest.getSchMainYn())
|
||||
.build()
|
||||
.toUriString();
|
||||
}
|
||||
|
||||
/* [2]. QSP API CALL -> Response */
|
||||
String strResponse = interfaceQsp.callApi(HttpMethod.GET, apiUrl, null);
|
||||
@ -114,14 +147,26 @@ public class BoardService {
|
||||
message.getMessage("common.message.required.data", "Notice No"));
|
||||
}
|
||||
|
||||
/* [1]. QSP API (url + param) Setting */
|
||||
String url = QSP_API_URL + "/api/board/detail";
|
||||
String apiUrl =
|
||||
UriComponentsBuilder.fromHttpUrl(url)
|
||||
.queryParam("noticeNo", boardRequest.getNoticeNo())
|
||||
.build()
|
||||
.toUriString();
|
||||
String url = null;
|
||||
String apiUrl = null;
|
||||
|
||||
if("QNA".equals(boardRequest.getSchNoticeClsCd())) {
|
||||
url = QSP_API_URL + "/api/qna/detail";
|
||||
apiUrl = UriComponentsBuilder.fromHttpUrl(url)
|
||||
.queryParam("qnaNo", boardRequest.getQnaNo())
|
||||
.queryParam("compCd", boardRequest.getCompCd())
|
||||
.queryParam("loginId", boardRequest.getLoginId())
|
||||
.queryParam("langCd", boardRequest.getLangCd())
|
||||
.build()
|
||||
.toUriString();
|
||||
} else {
|
||||
/* [1]. QSP API (url + param) Setting */
|
||||
url = QSP_API_URL + "/api/board/detail";
|
||||
apiUrl = UriComponentsBuilder.fromHttpUrl(url)
|
||||
.queryParam("noticeNo", boardRequest.getNoticeNo())
|
||||
.build()
|
||||
.toUriString();
|
||||
}
|
||||
/* [2]. QSP API CALL -> Response */
|
||||
String strResponse = interfaceQsp.callApi(HttpMethod.GET, apiUrl, null);
|
||||
|
||||
@ -138,6 +183,138 @@ public class BoardService {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* ※ 게시판 저장 QSP -> Q.CAST3
|
||||
*
|
||||
* @param boardRequest
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public BoardResponse getBoardQnaSave(BoardRequest boardRequest, HttpServletRequest request) throws Exception {
|
||||
|
||||
|
||||
|
||||
BoardResponse response = null;
|
||||
|
||||
/* [0]. Validation Check */
|
||||
if (boardRequest.getCompCd() == null || boardRequest.getCompCd().isEmpty()) {
|
||||
// [msg] {0} is required input value.
|
||||
throw new QcastException(
|
||||
ErrorCode.INVALID_INPUT_VALUE,
|
||||
message.getMessage("common.message.required.data", "Comp Cd"));
|
||||
}
|
||||
if (boardRequest.getSiteTpCd() == null || boardRequest.getSiteTpCd().isEmpty()) {
|
||||
// [msg] {0} is required input value.
|
||||
throw new QcastException(
|
||||
ErrorCode.INVALID_INPUT_VALUE,
|
||||
message.getMessage("common.message.required.data", "Site Type Cd"));
|
||||
}
|
||||
if (boardRequest.getQnaClsLrgCd() == null || boardRequest.getQnaClsLrgCd().isEmpty()) {
|
||||
// [msg] {0} is required input value.
|
||||
throw new QcastException(
|
||||
ErrorCode.INVALID_INPUT_VALUE,
|
||||
message.getMessage("common.message.required.data", "Qna Cls Large Cd"));
|
||||
}
|
||||
if (boardRequest.getQnaClsMidCd() == null || boardRequest.getQnaClsMidCd().isEmpty()) {
|
||||
// [msg] {0} is required input value.
|
||||
throw new QcastException(
|
||||
ErrorCode.INVALID_INPUT_VALUE,
|
||||
message.getMessage("common.message.required.data", "Qna Cls Mid Cd"));
|
||||
}
|
||||
if (boardRequest.getTitle() == null || boardRequest.getTitle().isEmpty()) {
|
||||
// [msg] {0} is required input value.
|
||||
throw new QcastException(
|
||||
ErrorCode.INVALID_INPUT_VALUE,
|
||||
message.getMessage("common.message.required.data", "title"));
|
||||
}
|
||||
|
||||
if (boardRequest.getContents() == null || boardRequest.getContents().isEmpty()) {
|
||||
// [msg] {0} is required input value.
|
||||
throw new QcastException(
|
||||
ErrorCode.INVALID_INPUT_VALUE,
|
||||
message.getMessage("common.message.required.data", "contents"));
|
||||
}
|
||||
|
||||
if (boardRequest.getRegId() == null || boardRequest.getRegId().isEmpty()) {
|
||||
// [msg] {0} is required input value.
|
||||
throw new QcastException(
|
||||
ErrorCode.INVALID_INPUT_VALUE,
|
||||
message.getMessage("common.message.required.data", "Reg Id"));
|
||||
}
|
||||
|
||||
if (boardRequest.getRegUserNm() == null || boardRequest.getRegUserNm().isEmpty()) {
|
||||
// [msg] {0} is required input value.
|
||||
throw new QcastException(
|
||||
ErrorCode.INVALID_INPUT_VALUE,
|
||||
message.getMessage("common.message.required.data", "Reg User Nm"));
|
||||
}
|
||||
|
||||
String url = null;
|
||||
String apiUrl = null;
|
||||
BoardResponse boardResponse = null;
|
||||
if("QNA".equals(boardRequest.getSchNoticeClsCd())) {
|
||||
url = QSP_API_URL + "/api/qna/save";
|
||||
apiUrl = UriComponentsBuilder.fromHttpUrl(url)
|
||||
.queryParam("siteTpCd", boardRequest.getSiteTpCd())
|
||||
.queryParam("compCd", boardRequest.getCompCd())
|
||||
.queryParam("regId", boardRequest.getRegId())
|
||||
.queryParam("title", boardRequest.getTitle())
|
||||
.queryParam("qnaClsLrgCd", boardRequest.getQnaClsLrgCd() )
|
||||
.queryParam("qnaClsMidCd", boardRequest.getQnaClsMidCd())
|
||||
.queryParam("qnaClsSmlCd", boardRequest.getQnaClsSmlCd())
|
||||
.queryParam("contents", boardRequest.getContents())
|
||||
.queryParam("storeId", boardRequest.getStoreId())
|
||||
.queryParam("regUserNm", boardRequest.getRegUserNm())
|
||||
.queryParam("regUserTelNo", boardRequest.getRegUserTelNo())
|
||||
.queryParam("qstMail", boardRequest.getQstMail())
|
||||
// .queryParam("files", multipartFileList)
|
||||
.build()
|
||||
.toUriString();
|
||||
}
|
||||
|
||||
List<MultipartFile> multipartFileList = new ArrayList<>();
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, List<MultipartFile>> mapMultipart = multipartRequest.getMultiFileMap();
|
||||
|
||||
|
||||
String strParamKey;
|
||||
for (String s : mapMultipart.keySet()) {
|
||||
strParamKey = s;
|
||||
multipartFileList.addAll(mapMultipart.get(strParamKey));
|
||||
}
|
||||
|
||||
|
||||
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String responseStr;
|
||||
HttpStatus httpStatus = HttpStatus.CREATED;
|
||||
|
||||
for (MultipartFile file : multipartFileList) {
|
||||
if (!file.isEmpty()) {
|
||||
map.add("file", new MultipartInputStreamFileResource(file.getInputStream(), file.getOriginalFilename()));
|
||||
}
|
||||
}
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
|
||||
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
|
||||
String strResponse = restTemplate.postForObject(apiUrl, requestEntity, String.class);
|
||||
|
||||
//String strResponse = interfaceQsp.callApi(HttpMethod.POST, apiUrl, multipartFileList);
|
||||
|
||||
if (!"".equals(strResponse)) {
|
||||
|
||||
com.fasterxml.jackson.databind.ObjectMapper om =
|
||||
new com.fasterxml.jackson.databind.ObjectMapper()
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
response = om.readValue(strResponse, BoardResponse.class);
|
||||
} else {
|
||||
// [msg] No data
|
||||
throw new QcastException(ErrorCode.NOT_FOUND, message.getMessage("common.message.no.data"));
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
/**
|
||||
* ※ 게시판 파일 다운로드 QSP -> Q.CAST3
|
||||
*
|
||||
@ -202,3 +379,23 @@ public class BoardService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MultipartInputStreamFileResource extends InputStreamResource {
|
||||
|
||||
private final String filename;
|
||||
|
||||
MultipartInputStreamFileResource(InputStream inputStream, String filename) {
|
||||
super(inputStream);
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return this.filename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long contentLength() throws IOException {
|
||||
return -1; // we do not want to generally read the whole stream into memory ...
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,13 @@
|
||||
package com.interplug.qcast.biz.community.dto;
|
||||
|
||||
import com.interplug.qcast.biz.file.dto.FileRequest;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ -28,4 +34,37 @@ public class BoardRequest {
|
||||
/** 메인여부 */
|
||||
private String schMainYn;
|
||||
|
||||
//Company Code
|
||||
private String compCd;
|
||||
private String storeId;
|
||||
//Site Type Code
|
||||
private String siteTpCd;
|
||||
private String loginId;
|
||||
|
||||
//등록자 아이디
|
||||
private String schRegId;
|
||||
//검색 시작일시
|
||||
private String schFromDt;
|
||||
//검색 끝일시
|
||||
private String schToDt;
|
||||
|
||||
private String qnaNo;
|
||||
|
||||
private String langCd;
|
||||
|
||||
private String qnaClsLrgCd;
|
||||
private String qnaClsMidCd;
|
||||
private String qnaClsSmlCd;
|
||||
private String contents;
|
||||
private String regId;
|
||||
private String title;
|
||||
private String regUserNm;
|
||||
private String regUserTelNo;
|
||||
private String qstMail;
|
||||
|
||||
|
||||
@Schema(description = "첨부파일 목록")
|
||||
List<MultipartFile> fileList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user