feat: 자료관리 파일 다운로드 반영

dev
minuk926 3 years ago
parent 7337874e34
commit b4a29faf95

@ -1,9 +1,14 @@
package com.xit.biz.cmm.controller;
import com.xit.biz.ctgy.CtgyConstants;
import com.xit.biz.ctgy.dto.GnRecallScDto;
import com.xit.biz.ctgy.entity.MinInfoBoard680;
import com.xit.biz.ctgy.service.ICtgyFileService;
import com.xit.biz.ctgy.service.IResidentAndDisabledService;
import com.xit.core.constant.ErrorCode;
import com.xit.core.exception.CustomBaseException;
import com.xit.core.util.Checks;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FileUtils;
@ -12,9 +17,12 @@ import org.springframework.core.env.Environment;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Nonnull;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@ -36,15 +44,20 @@ public class CmmFileController {
@Value("${file.cmm.upload.path:/kangnamSIM/simUpFile/}")
private String uploadPath;
@Value("${file.cmm.upload.simsaPath:[simUpFile_sc1]}")
private String[] judgeUploadPath;
@Value("${file.cmm.upload.url}")
private String serviceUrl;
private final ICtgyFileService service;
private final ICtgyFileService ctgyFileService;
private final IResidentAndDisabledService judgeService;
@Operation(summary = "공지사항 파일 다운로드" , description = "공지사항 파일 다운로드")
@GetMapping("/download/{inCode}")
public void download(@PathVariable Long inCode, HttpServletResponse response) {
MinInfoBoard680 entity = service.findFiles(inCode);
MinInfoBoard680 entity = ctgyFileService.findFiles(inCode);
String absFile = "";
@ -53,10 +66,41 @@ public class CmmFileController {
else
absFile = rootPath + entity.getInFileurl().split(serviceUrl)[1] + File.separator + entity.getInFilename();
download(absFile, entity.getInFilename(), response);
}
@Operation(summary = "거주자/장애인 심사자료 파일 다운로드" , description = "거주자/장애인 심사자료 파일 다운로드")
@GetMapping("/download/judge")
public void download(@Nonnull final String scDatagb, @Nonnull final Long scCode, @Nonnull String methodName, HttpServletResponse response) {
GnRecallScDto savedDto = judgeService.findJudgeData(scCode);
String fileName = "";
try {
Method method = GnRecallScDto.class.getMethod(methodName);
fileName = String.valueOf(method.invoke(savedDto));
if(Checks.isEmpty(fileName)) throw new CustomBaseException(ErrorCode.DATA_NOT_FOUND);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
String absFile = "";
if (Arrays.asList(env.getActiveProfiles()).contains("prod"))
absFile = "entity.getInFileurl()" + File.separator + fileName;
else
absFile = rootPath + (CtgyConstants.Judge.DATAGB_RESIDENT.getCode().equals(scDatagb)? judgeUploadPath[0] : judgeUploadPath[1]) + fileName;
download(absFile, fileName, response);
}
private void download(String absFile, String fileName, HttpServletResponse response) {
Path path = Paths.get(absFile);
String contentType = null;
long fileSize = 0L;
try {
contentType = Files.probeContentType(path);
fileSize = Files.size(path);
} catch (IOException e) {
throw new CustomBaseException(ErrorCode.FILE_NOT_FOUND);
}
@ -72,9 +116,9 @@ public class CmmFileController {
response.setContentType(contentType);
response.setHeader(HttpHeaders.CONTENT_TYPE, contentType);
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + URLEncoder.encode(entity.getInFilename(), StandardCharsets.UTF_8) + "\";");
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + URLEncoder.encode(fileName, StandardCharsets.UTF_8) + "\";");
//response.setHeader(HttpHeaders.CONTENT_ENCODING, "binary");
response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getInFilesize()));
response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(fileSize));
try {
response.getOutputStream().write(fileByte);
response.getOutputStream().flush();

@ -41,8 +41,6 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toMap;
@Service
@RequiredArgsConstructor
@Slf4j
@ -106,7 +104,7 @@ public class ResidentAndDisabledService implements IResidentAndDisabledService {
}
private void setFileInfoAndFileUpload(GnRecallScDto dto, MultipartFile[] mfs, String setMethodName) {
String makePath = fileService.uploadFiles(mfs, rootPath, uploadPath[0]);
String makePath = fileService.uploadFiles(mfs, rootPath, CtgyConstants.Judge.DATAGB_RESIDENT.getCode().equals(dto.getScDatagb())? uploadPath[0] : uploadPath[1]);
makePath = makePath + File.separator;
for(int idx = 0; idx < mfs.length; idx++){

Loading…
Cancel
Save