보증서 발행 완료 물건 파일 다운로드 개발

This commit is contained in:
Kang Jung Kyo 2024-09-24 16:33:56 +09:00
parent cec97c4e3d
commit 4cbca6fdf1
6 changed files with 194 additions and 62 deletions

View File

@ -1,14 +1,25 @@
package com.interplug.qcast.biz.excelDown;
import com.interplug.qcast.biz.excelDown.dto.*;
import java.util.List;
import org.springframework.http.HttpStatus;
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.excelDown.dto.NtrCtsCmpRequest;
import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpResponse;
import com.interplug.qcast.biz.excelDown.dto.QuotItemResponse;
import com.interplug.qcast.biz.excelDown.dto.QuotPlanResponse;
import com.interplug.qcast.biz.excelDown.dto.QuotRequest;
import com.interplug.qcast.biz.excelDown.dto.QuotResponse;
import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplRequest;
import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@ -16,36 +27,47 @@ import java.util.List;
@RequiredArgsConstructor
@Tag(name = "ExcelDownController", description = "과거데이터 엑셀다운로드 API")
public class ExcelDownController {
private final ExcelDownService excelDownService;
private final ExcelDownService excelDownService;
@Operation(description = "과거데이터_견적 엑셀다운로드 조회")
@PostMapping("/quot-excl-down-data")
@ResponseStatus(HttpStatus.OK)
public QuotResponse quotExclDownData(@RequestBody QuotRequest quotRequest) throws Exception {
@Operation(description = "과거데이터_견적 엑셀다운로드 조회")
@PostMapping("/quot-excl-down-data")
@ResponseStatus(HttpStatus.OK)
public QuotResponse quotExclDownData(@RequestBody QuotRequest quotRequest) throws Exception {
List<QuotPlanResponse> quotPlanExclDownData = excelDownService.selectQuotPlanExclDownData(quotRequest);
List<QuotItemResponse> quotItemExclDownData = excelDownService.selectQuotItemExclDownData(quotRequest);
List<QuotPlanResponse> quotPlanExclDownData =
excelDownService.selectQuotPlanExclDownData(quotRequest);
List<QuotItemResponse> quotItemExclDownData =
excelDownService.selectQuotItemExclDownData(quotRequest);
QuotResponse quotRes = new QuotResponse();
quotRes.setQuotPlanList(quotPlanExclDownData);
quotRes.setQuotItemList(quotItemExclDownData);
QuotResponse quotRes = new QuotResponse();
quotRes.setQuotPlanList(quotPlanExclDownData);
quotRes.setQuotItemList(quotItemExclDownData);
return quotRes;
}
return quotRes;
}
@Operation(description = "과거데이터_자연재해보상입력 엑셀다운로드 조회")
@PostMapping("/ntr-cts-cmp-excl-down-data")
@ResponseStatus(HttpStatus.OK)
public List<NtrCtsCmpResponse> ntrCtsCmpExclDownData(@RequestBody NtrCtsCmpRequest ntrCtsCmpRequest) throws Exception {
return excelDownService.selectNtrCtsCmpExclDownData(ntrCtsCmpRequest);
}
@Operation(description = "과거데이터_자연재해보상입력 엑셀다운로드 조회")
@PostMapping("/ntr-cts-cmp-excl-down-data")
@ResponseStatus(HttpStatus.OK)
public List<NtrCtsCmpResponse> ntrCtsCmpExclDownData(
@RequestBody NtrCtsCmpRequest ntrCtsCmpRequest) throws Exception {
return excelDownService.selectNtrCtsCmpExclDownData(ntrCtsCmpRequest);
}
@Operation(description = "과거데이터_보증서발행완료 물건 엑셀다운로드 조회")
@PostMapping("/wrnt-isnc-cmpl-excl-down-data")
@ResponseStatus(HttpStatus.OK)
public List<WrntIsncCmplResponse> warrantyIssuedCmpExclDownData(@RequestBody WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception {
return excelDownService.selectWarrantyIssuedCmpExclDownData(wrntIsncCmplRequest);
}
@Operation(description = "과거데이터_보증서발행완료 물건 엑셀다운로드 조회")
@PostMapping("/wrnt-isnc-cmpl-excl-down-data")
@ResponseStatus(HttpStatus.OK)
public List<WrntIsncCmplResponse> warrantyIssuedCmpExclDownData(
@RequestBody WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception {
return excelDownService.selectWarrantyIssuedCmpExclDownData(wrntIsncCmplRequest);
}
@Operation(description = "과거데이터_보증서발행완료 물건 파일 다운로드 조회")
@PostMapping("/wrnt-isnc-cmpl-file-down")
@ResponseStatus(HttpStatus.OK)
public void warrantyIssuedCmpFileDown(@RequestBody WrntIsncCmplRequest wrntIsncCmplRequest,
HttpServletResponse response) throws Exception {
excelDownService.selectWarrantyIssuedCmpFileData(wrntIsncCmplRequest, response);
}
}

View File

@ -1,17 +1,28 @@
package com.interplug.qcast.biz.excelDown;
import com.interplug.qcast.biz.excelDown.dto.*;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpRequest;
import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpResponse;
import com.interplug.qcast.biz.excelDown.dto.QuotItemResponse;
import com.interplug.qcast.biz.excelDown.dto.QuotPlanResponse;
import com.interplug.qcast.biz.excelDown.dto.QuotRequest;
import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplFileResponse;
import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplRequest;
import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplResponse;
@Mapper
interface ExcelDownMapper {
List<QuotPlanResponse> selectQuotPlanExclDownData(QuotRequest quotRequest) throws Exception;
List<QuotPlanResponse> selectQuotPlanExclDownData(QuotRequest quotRequest) throws Exception;
List<QuotItemResponse> selectQuotItemExclDownData(QuotRequest quotRequest) throws Exception;
List<QuotItemResponse> selectQuotItemExclDownData(QuotRequest quotRequest) throws Exception;
List<NtrCtsCmpResponse> selectNtrCtsCmpExclDownData(NtrCtsCmpRequest ntrCtsCmpRequest) throws Exception;
List<NtrCtsCmpResponse> selectNtrCtsCmpExclDownData(NtrCtsCmpRequest ntrCtsCmpRequest)
throws Exception;
List<WrntIsncCmplResponse> selectWarrantyIssuedCmpExclDownData(WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception;
List<WrntIsncCmplResponse> selectWarrantyIssuedCmpExclDownData(
WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception;
List<WrntIsncCmplFileResponse> selectWarrantyIssuedCmpFileData(
WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception;
}

View File

@ -1,31 +1,81 @@
package com.interplug.qcast.biz.excelDown;
import com.interplug.qcast.biz.excelDown.dto.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpRequest;
import com.interplug.qcast.biz.excelDown.dto.NtrCtsCmpResponse;
import com.interplug.qcast.biz.excelDown.dto.QuotItemResponse;
import com.interplug.qcast.biz.excelDown.dto.QuotPlanResponse;
import com.interplug.qcast.biz.excelDown.dto.QuotRequest;
import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplFileResponse;
import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplRequest;
import com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplResponse;
import com.interplug.qcast.config.Exception.BaseException;
import com.interplug.qcast.config.message.Messages;
import com.interplug.qcast.util.ZipFileManager;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor
public class ExcelDownService {
private final ExcelDownMapper excelDownMapper;
private final ExcelDownMapper excelDownMapper;
public List<QuotPlanResponse> selectQuotPlanExclDownData(QuotRequest quotRequest) throws Exception {
return excelDownMapper.selectQuotPlanExclDownData(quotRequest);
}
private final ZipFileManager zipFileManager;
public List<QuotItemResponse> selectQuotItemExclDownData(QuotRequest quotRequest) throws Exception {
return excelDownMapper.selectQuotItemExclDownData(quotRequest);
}
@Autowired
Messages message;
public List<NtrCtsCmpResponse> selectNtrCtsCmpExclDownData(NtrCtsCmpRequest ntrCtsCmpRequest) throws Exception {
return excelDownMapper.selectNtrCtsCmpExclDownData(ntrCtsCmpRequest);
}
@Value("${file.ini.root.path}")
private String baseDirPath;
public List<WrntIsncCmplResponse> selectWarrantyIssuedCmpExclDownData(WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception {
return excelDownMapper.selectWarrantyIssuedCmpExclDownData(wrntIsncCmplRequest);
public List<QuotPlanResponse> selectQuotPlanExclDownData(QuotRequest quotRequest)
throws Exception {
return excelDownMapper.selectQuotPlanExclDownData(quotRequest);
}
public List<QuotItemResponse> selectQuotItemExclDownData(QuotRequest quotRequest)
throws Exception {
return excelDownMapper.selectQuotItemExclDownData(quotRequest);
}
public List<NtrCtsCmpResponse> selectNtrCtsCmpExclDownData(NtrCtsCmpRequest ntrCtsCmpRequest)
throws Exception {
return excelDownMapper.selectNtrCtsCmpExclDownData(ntrCtsCmpRequest);
}
public List<WrntIsncCmplResponse> selectWarrantyIssuedCmpExclDownData(
WrntIsncCmplRequest wrntIsncCmplRequest) throws Exception {
return excelDownMapper.selectWarrantyIssuedCmpExclDownData(wrntIsncCmplRequest);
}
public void selectWarrantyIssuedCmpFileData(WrntIsncCmplRequest wrntIsncCmplRequest,
HttpServletResponse response) throws Exception {
List<WrntIsncCmplFileResponse> listData =
excelDownMapper.selectWarrantyIssuedCmpFileData(wrntIsncCmplRequest);
if (listData != null && listData.size() > 0) {
// 파일 목록 설정
List<Map<String, String>> listFile = new ArrayList<Map<String, String>>();
Map<String, String> mapFile = null;
for (WrntIsncCmplFileResponse res : listData) {
mapFile = new HashMap<String, String>();
mapFile.put("directory", res.getObjectNo());
mapFile.put("filename", baseDirPath + "\\" + res.getObjectNo() + "\\" + res.getFaileName());
listFile.add(mapFile);
}
zipFileManager.createZipFile(response, "Warranty-issued-completed-files", listFile);
} else {
throw new BaseException(message.getMessage("common.message.no.dataDown"));
}
}
}

View File

@ -0,0 +1,18 @@
package com.interplug.qcast.biz.excelDown.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class WrntIsncCmplFileResponse {
@Schema(description = "부동산 관리 번호")
private String objectNo;
@Schema(description = "계획")
private String planNo;
@Schema(description = "번호")
private String no;
@Schema(description = "파일명")
private String faileName;
}

View File

@ -5,9 +5,12 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.interplug.qcast.config.message.Messages;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -17,22 +20,26 @@ import lombok.extern.slf4j.Slf4j;
@RequiredArgsConstructor
public class ZipFileManager {
@Autowired
Messages message;
/**
* zip file을 생성하여 ZipOutputStream를 반환하는 method
*
* @param response HttpServletResponse
* @param strCreateFileName 생성할 file 이름
* @param listFilePath 파일 경로 목록
* @param listFilePath 파일 정보 목록
*/
public void createZipFile(HttpServletResponse response, String strCreateFileName,
List<String> listFilePath) throws Exception {
List<Map<String, String>> listFile) throws Exception {
// 압축될 파일명이 존재하지 않을 경우
if (strCreateFileName == null || "".equals(strCreateFileName))
throw new IllegalArgumentException("파일명이 존재하지 않습니다.");
throw new IllegalArgumentException(
message.getMessage("common.message.data.no.exists", "file name"));
// 파일이 존재하지 않을 경우
if (listFilePath == null || listFilePath.size() == 0)
throw new IllegalArgumentException("파일이 존재하지 않습니다.");
if (listFile == null || listFile.size() == 0)
throw new IllegalArgumentException(message.getMessage("common.message.no.dataDown"));
// zip 파일명
String strZipName = strCreateFileName + ".zip";
@ -43,12 +50,14 @@ public class ZipFileManager {
response.setStatus(HttpServletResponse.SC_OK);
try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
for (String strSourceFile : listFilePath) {
for (Map<String, String> mapFile : listFile) {
String strDirectory = mapFile.get("directory");
String strSourceFile = mapFile.get("filename");
Path path = Path.of(strSourceFile);
try (FileInputStream fis = new FileInputStream(path.toFile())) {
// 압축될 파일명을 ZipEntry에 담아준다
ZipEntry zipEntry = new ZipEntry(path.getFileName().toString());
ZipEntry zipEntry = new ZipEntry(strDirectory + "\\" + path.getFileName().toString());
// 압축될 파일명을 ZipOutputStream 담아준다
zos.putNextEntry(zipEntry);
@ -59,12 +68,14 @@ public class ZipFileManager {
zos.write(buffer, 0, length);
}
} catch (FileNotFoundException e) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
throw new IllegalArgumentException("파일 변환 작업중, [ " + strZipName + " ] 파일을 찾을 수 없습니다.");
// response.setStatus(HttpServletResponse.SC_NOT_FOUND);
// throw new IllegalArgumentException("파일 변환 작업중, [ " + strSourceFile + " ] 파일을 찾을 수
// 없습니다.");
log.debug("파일 변환 작업중, [ " + strSourceFile + " ] 파일을 찾을 수 없습니다.");
} catch (IOException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
throw new IllegalArgumentException(
"파일 변환 작업중, [ " + strZipName + " ] 파일을 다운로드 할 수 없습니다.");
"파일 변환 작업중, [ " + strSourceFile + " ] 파일을 다운로드 할 수 없습니다.");
} finally {
// ZipOutputStream 담아둔 압축될 파일명을 flush 시켜준다
zos.flush();

View File

@ -472,5 +472,25 @@
</where>
</sql>
<select id="selectWarrantyIssuedCmpFileData" parameterType="com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplRequest" resultType="com.interplug.qcast.biz.excelDown.dto.WrntIsncCmplFileResponse">
/* sqlid : com.interplug.qcast.api.excelDown.selectWarrantyIssuedCmpFileData (보증서발행완료 물건 파일 데이터 조회)*/
SELECT
A.OBJECT_NO /* 부동산 관리 번호 */
, A.PLAN_NO /* 계획 */
, F.NO
, F.FAILE_NAME
FROM T_GUARANTEE A
LEFT OUTER JOIN T_OBJECT B
ON A.OBJECT_NO = B.OBJECT_NO
AND B.DEL_FLG = 0
LEFT OUTER JOIN W_WARRANTY C
ON A.OBJECT_NO = C.OBJECT_NO
INNER JOIN T_UPLOAD F
ON A.OBJECT_NO = F.OBJECT_NO
AND F.DEL_FLG = '0'
AND F.CATEGORY <![CDATA[<]]> 9
AND F.CATEGORY != 7
<include refid="querySeachParameter" />
</select>
</mapper>