|
|
@ -3,6 +3,7 @@ package com.xit.biz.ctgy.controller;
|
|
|
|
import com.xit.biz.ctgy.dto.MinInfoBoard680Dto;
|
|
|
|
import com.xit.biz.ctgy.dto.MinInfoBoard680Dto;
|
|
|
|
|
|
|
|
|
|
|
|
import com.xit.biz.ctgy.entity.MinInfoBoard680;
|
|
|
|
import com.xit.biz.ctgy.entity.MinInfoBoard680;
|
|
|
|
|
|
|
|
import com.xit.biz.ctgy.entity.MinSimsa680;
|
|
|
|
import com.xit.biz.ctgy.service.ICtgyFileService;
|
|
|
|
import com.xit.biz.ctgy.service.ICtgyFileService;
|
|
|
|
import com.xit.core.api.IRestResponse;
|
|
|
|
import com.xit.core.api.IRestResponse;
|
|
|
|
import com.xit.core.api.RestResponse;
|
|
|
|
import com.xit.core.api.RestResponse;
|
|
|
@ -11,6 +12,9 @@ import com.xit.core.util.Checks;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
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.http.HttpStatus;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
@ -18,6 +22,12 @@ import org.springframework.lang.NonNull;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
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.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@Tag(name = "CtgyFileMgtController", description = "파일 관리")
|
|
|
|
@Tag(name = "CtgyFileMgtController", description = "파일 관리")
|
|
|
@ -25,13 +35,25 @@ import java.util.List;
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@RequestMapping("/api/v1/ctgy/file")
|
|
|
|
@RequestMapping("/api/v1/ctgy/file")
|
|
|
|
public class CtgyFileMgtController {
|
|
|
|
public class CtgyFileMgtController {
|
|
|
|
private final ICtgyFileService fileService;
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "파일 조회" , description = "등록된 파일 조회")
|
|
|
|
@Operation(summary = "파일 조회" , description = "등록된 파일 조회")
|
|
|
|
@GetMapping("/{id}")
|
|
|
|
@GetMapping("/{id}")
|
|
|
|
public ResponseEntity<? extends IRestResponse> findFiles(@PathVariable("inCode") @NonNull final Long inCode) {
|
|
|
|
public ResponseEntity<? extends IRestResponse> findFiles(@PathVariable("inCode") @NonNull final Long inCode) {
|
|
|
|
AssertUtils.isTrue(!Checks.isEmpty(inCode), "대상 게시글[inCode]을 선택해 주세요.");
|
|
|
|
AssertUtils.isTrue(!Checks.isEmpty(inCode), "대상 게시글[inCode]을 선택해 주세요.");
|
|
|
|
return RestResponse.of(fileService.findFiles(inCode));
|
|
|
|
return RestResponse.of(service.findFiles(inCode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "공지사항 저장" , description = "공지사항 저장")
|
|
|
|
@Operation(summary = "공지사항 저장" , description = "공지사항 저장")
|
|
|
@ -46,15 +68,40 @@ public class CtgyFileMgtController {
|
|
|
|
.inContents(dto.getInContents())
|
|
|
|
.inContents(dto.getInContents())
|
|
|
|
.inFilename(dto.getInFilename())
|
|
|
|
.inFilename(dto.getInFilename())
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
return RestResponse.of(fileService.saveFiles(minInfoBoard680, dto.getFiles()));
|
|
|
|
return RestResponse.of(service.saveFiles(minInfoBoard680, dto.getFiles()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "공지사항 삭제" , description = "공지사항 삭제")
|
|
|
|
@Operation(summary = "공지사항 삭제" , description = "공지사항 삭제")
|
|
|
|
@PostMapping(value="/pboard/{inCode}")
|
|
|
|
@PostMapping(value="/pboard/{inCode}")
|
|
|
|
public ResponseEntity<? extends IRestResponse> removePublicBoardFile(@PathVariable @Nonnull final Long inCode) {
|
|
|
|
public ResponseEntity<? extends IRestResponse> removePublicBoardFile(@PathVariable @Nonnull final Long inCode) {
|
|
|
|
AssertUtils.isTrue(!Checks.isEmpty(inCode), "공지 사항이 선택되지 않았습니다.");
|
|
|
|
AssertUtils.isTrue(!Checks.isEmpty(inCode), "공지 사항이 선택되지 않았습니다.");
|
|
|
|
fileService.removePublicBoardFile(inCode);
|
|
|
|
service.removePublicBoardFile(inCode);
|
|
|
|
|
|
|
|
|
|
|
|
return RestResponse.of(HttpStatus.OK);
|
|
|
|
return RestResponse.of(HttpStatus.OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/download/{inCode}")
|
|
|
|
|
|
|
|
public void download(@PathVariable Long inCode, HttpServletResponse response) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte[] fileByte = FileUtils.readFileToByteArray(new File(absFile));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment; fileName=\"" + URLEncoder.encode(entity.getInFilename(), StandardCharsets.UTF_8)+"\";");
|
|
|
|
|
|
|
|
response.setHeader("Content-Transfer-Encoding", "binary");
|
|
|
|
|
|
|
|
response.setHeader("Content-Length", String.valueOf(entity.getInFilesize()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.getOutputStream().write(fileByte);
|
|
|
|
|
|
|
|
response.getOutputStream().flush();
|
|
|
|
|
|
|
|
response.getOutputStream().close();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|