feat: 거주자의견진술 등록 반영
parent
983b188343
commit
36555df311
@ -0,0 +1,96 @@
|
|||||||
|
package com.xit.biz.cmm.controller;
|
||||||
|
|
||||||
|
import com.xit.biz.ctgy.dto.MinInfoBoard680Dto;
|
||||||
|
import com.xit.biz.ctgy.entity.MinInfoBoard680;
|
||||||
|
import com.xit.biz.ctgy.service.ICtgyFileService;
|
||||||
|
import com.xit.core.api.IRestResponse;
|
||||||
|
import com.xit.core.api.RestResponse;
|
||||||
|
import com.xit.core.constant.ErrorCode;
|
||||||
|
import com.xit.core.exception.CustomBaseException;
|
||||||
|
import com.xit.core.util.AssertUtils;
|
||||||
|
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;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
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.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@Tag(name = "CtgyFileMgtController", description = "공지사항 / 게시판 관리")
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/api/v1/ctgy/cmm")
|
||||||
|
public class CmmFileController {
|
||||||
|
|
||||||
|
private final Environment env;
|
||||||
|
|
||||||
|
@Value("${file.cmm.upload.root:c:/data/file/upload}")
|
||||||
|
private String rootPath;
|
||||||
|
|
||||||
|
@Value("${file.cmm.upload.path:/kangnamSIM/simUpFile/}")
|
||||||
|
private String uploadPath;
|
||||||
|
|
||||||
|
@Value("${file.cmm.upload.url}")
|
||||||
|
private String serviceUrl;
|
||||||
|
|
||||||
|
private final ICtgyFileService service;
|
||||||
|
|
||||||
|
@GetMapping("/download/{inCode}")
|
||||||
|
public void download(@PathVariable Long inCode, HttpServletResponse response) {
|
||||||
|
|
||||||
|
MinInfoBoard680 entity = service.findFiles(inCode);
|
||||||
|
|
||||||
|
String absFile = "";
|
||||||
|
|
||||||
|
if (Arrays.asList(env.getActiveProfiles()).contains("prod"))
|
||||||
|
absFile = entity.getInFileurl() + File.separator + entity.getInFilename();
|
||||||
|
else
|
||||||
|
absFile = rootPath + entity.getInFileurl().split(serviceUrl)[1] + File.separator + entity.getInFilename();
|
||||||
|
|
||||||
|
Path path = Paths.get(absFile);
|
||||||
|
String contentType = null;
|
||||||
|
try {
|
||||||
|
contentType = Files.probeContentType(path);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new CustomBaseException(ErrorCode.FILE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(absFile);
|
||||||
|
byte[] fileByte = new byte[0];
|
||||||
|
try {
|
||||||
|
fileByte = FileUtils.readFileToByteArray(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new CustomBaseException(ErrorCode.FILE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
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_ENCODING, "binary");
|
||||||
|
response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getInFilesize()));
|
||||||
|
try {
|
||||||
|
response.getOutputStream().write(fileByte);
|
||||||
|
response.getOutputStream().flush();
|
||||||
|
response.getOutputStream().close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new CustomBaseException(ErrorCode.FILE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +1,12 @@
|
|||||||
package com.xit.biz.cmm.service;
|
package com.xit.biz.cmm.service;
|
||||||
|
|
||||||
import com.xit.biz.ctgy.entity.MinInfoBoard680;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Lim, Jong Uk (minuk926)
|
* @author Lim, Jong Uk (minuk926)
|
||||||
* @since 2021-07-16
|
* @since 2021-07-16
|
||||||
*/
|
*/
|
||||||
public interface ICmmFileService {
|
public interface ICmmFileService {
|
||||||
MinInfoBoard680 findFiles(Long inCode);
|
String uploadFiles(MultipartFile[] files, String rootPath, String uploadPath);
|
||||||
|
|
||||||
List<MinInfoBoard680> saveFiles(@Nonnull MinInfoBoard680 minInfoBoard680, MultipartFile[] files);
|
|
||||||
|
|
||||||
void removePublicBoardFile(Long inCode);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue