feat: 공지사항 저장 / 삭제 반영

dev
minuk926 3 years ago
parent d2469ee7ca
commit c332031b9b

@ -1,7 +1,5 @@
package com.xit.biz.ctgy.controller; package com.xit.biz.ctgy.controller;
import com.xit.biz.cmm.dto.CmmFileDto;
import com.xit.biz.cmm.entity.CmmFileMst;
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;
@ -18,7 +16,6 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
@ -37,47 +34,27 @@ public class CtgyFileMgtController {
return RestResponse.of(fileService.findFiles(inCode)); return RestResponse.of(fileService.findFiles(inCode));
} }
//@Operation(summary = "파일 저장" , description = "파일 저장") @Operation(summary = "공지사항 저장" , description = "공지사항 저장")
//@PostMapping() @PostMapping(value="/pboard", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
// public ResponseEntity<? extends IRestResponse> saveFiles2(CmmFileMst cmmFileMst, @RequestParam("files") MultipartFile[] files) { public ResponseEntity<? extends IRestResponse> savePublicBoardFiles(@Nonnull MinInfoBoard680Dto dto) {
// AssertUtils.isTrue(!Checks.isEmpty(cmmFileMst), "파일 정보가 존재하지 않습니다.");
// AssertUtils.isTrue(!Checks.isEmpty(cmmFileMst.getFileCtgCd()), "파일 구분 코드[fileCtgCd] 정보가 존재하지 않습니다.");
// AssertUtils.isTrue(!Checks.isEmpty(cmmFileMst.getFileBizId()), "파일 업무 ID[fileBizId] 정보가 존재하지 않습니다.");
// AssertUtils.isTrue(!Checks.isEmpty(files), "대상 파일이 존재하지 않습니다.");
// return RestResponse.of(fileService.saveFiles(cmmFileMst, files));
//
// RedirectAttributes redirectAttributes
// redirectAttributes.addFlashAttribute("message",
// "You successfully uploaded " + file.getOriginalFilename() + "!");
//
// return "redirect:/";
// }
@Operation(summary = "파일 저장" , description = "파일 저장")
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<? extends IRestResponse> saveFiles(@Nonnull MinInfoBoard680Dto dto) {
AssertUtils.isTrue(!Checks.isEmpty(dto), "파일 정보가 존재하지 않습니다."); AssertUtils.isTrue(!Checks.isEmpty(dto), "파일 정보가 존재하지 않습니다.");
// AssertUtils.isTrue(!Checks.isEmpty(cmmFileDto.getFileCtgCd()), "파일 구분 코드[fileCtgCd] 정보가 존재하지 않습니다.");
// AssertUtils.isTrue(!Checks.isEmpty(cmmFileDto.getFileBizId()), "파일 업무 ID[fileBizId] 정보가 존재하지 않습니다.");
// AssertUtils.isTrue(!Checks.isEmpty(cmmFileDto.getFiles()), "대상 파일이 존재하지 않습니다.");
// CmmFileMst cmmFileMst = CmmFileMst.builder()
// .fileMstId(cmmFileDto.getFileMstId())
// .fileCtgCd(cmmFileDto.getFileCtgCd())
// .fileBizId(cmmFileDto.getFileBizId())
// .build();
MinInfoBoard680 minInfoBoard680 = MinInfoBoard680.builder() MinInfoBoard680 minInfoBoard680 = MinInfoBoard680.builder()
.inCode(dto.getInCode()) .inCode(dto.getInCode())
.inBgubun(dto.getInBgubun()) .inBgubun(dto.getInBgubun())
.inTitle(dto.getInTitle()) .inTitle(dto.getInTitle())
.inContents(dto.getInContents()) .inContents(dto.getInContents())
.inFilename(dto.getInFilename())
.build(); .build();
//fileService.saveFiles(minInfoBoard680, dto.getFiles());
return RestResponse.of(fileService.saveFiles(minInfoBoard680, dto.getFiles())); return RestResponse.of(fileService.saveFiles(minInfoBoard680, dto.getFiles()));
}
@Operation(summary = "공지사항 삭제" , description = "공지사항 삭제")
@PostMapping(value="/pboard/{inCode}")
public ResponseEntity<? extends IRestResponse> removePublicBoardFile(@PathVariable @Nonnull final Long inCode) {
AssertUtils.isTrue(!Checks.isEmpty(inCode), "공지 사항이 선택되지 않았습니다.");
fileService.removePublicBoardFile(inCode);
// RedirectAttributes redirectAttributes return RestResponse.of(HttpStatus.OK);
// redirectAttributes.addFlashAttribute("message",
// "You successfully uploaded " + file.getOriginalFilename() + "!");
//
// return "redirect:/";
} }
} }

@ -15,4 +15,6 @@ public interface ICtgyFileService {
MinInfoBoard680 findFiles(Long inCode); MinInfoBoard680 findFiles(Long inCode);
List<MinInfoBoard680> saveFiles(@Nonnull MinInfoBoard680 minInfoBoard680, MultipartFile[] files); List<MinInfoBoard680> saveFiles(@Nonnull MinInfoBoard680 minInfoBoard680, MultipartFile[] files);
void removePublicBoardFile(Long inCode);
} }

@ -1,19 +1,13 @@
package com.xit.biz.ctgy.service.impl; package com.xit.biz.ctgy.service.impl;
import com.xit.biz.cmm.entity.CmmFileDtl;
import com.xit.biz.cmm.entity.CmmFileMst;
import com.xit.biz.cmm.entity.ids.CmmFileDtlIds;
import com.xit.biz.cmm.repository.ICmmFileDtlRepository;
import com.xit.biz.cmm.repository.ICmmFileMstRepository;
import com.xit.biz.cmm.service.ICmmFileService;
import com.xit.biz.ctgy.CtgyConstants;
import com.xit.biz.ctgy.entity.MinInfoBoard680; import com.xit.biz.ctgy.entity.MinInfoBoard680;
import com.xit.biz.ctgy.entity.Tf680Recall;
import com.xit.biz.ctgy.repository.IPublicBoardRepository; import com.xit.biz.ctgy.repository.IPublicBoardRepository;
import com.xit.biz.ctgy.service.ICtgyFileService; import com.xit.biz.ctgy.service.ICtgyFileService;
import com.xit.core.constant.ErrorCode;
import com.xit.core.exception.CustomBaseException;
import com.xit.core.support.jpa.JpaUtil; import com.xit.core.support.jpa.JpaUtil;
import com.xit.core.util.AssertUtils; import com.xit.core.util.AssertUtils;
import com.xit.core.util.CommUtil; import com.xit.core.util.Checks;
import com.xit.core.util.DateUtil; import com.xit.core.util.DateUtil;
import io.jsonwebtoken.lang.Assert; import io.jsonwebtoken.lang.Assert;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -72,9 +66,10 @@ public class CtgyFileService implements ICtgyFileService {
@Override @Override
@Transactional @Transactional
public List<MinInfoBoard680> saveFiles(@Nonnull MinInfoBoard680 entity, MultipartFile[] files) { public List<MinInfoBoard680> saveFiles(@Nonnull MinInfoBoard680 entity, MultipartFile[] files) {
String makePath = ""; List<MinInfoBoard680> entityList = new ArrayList<>();
makePath = File.separator + DateUtil.getToday(""); if(files != null && files.length > 0){
String makePath = File.separator + DateUtil.getToday("");
// 파일 경로 : upload root 제외 // 파일 경로 : upload root 제외
String urlPath = this.uploadPath + makePath; String urlPath = this.uploadPath + makePath;
@ -83,9 +78,8 @@ public class CtgyFileService implements ICtgyFileService {
File file = new File(fileUploadPath); File file = new File(fileUploadPath);
if(!file.exists()) file.mkdirs(); if(!file.exists()) file.mkdirs();
List<MinInfoBoard680> entityList = new ArrayList<>(); for(MultipartFile mf : files) {
for(MultipartFile mf : files){ if (!mf.isEmpty()) {
if(!mf.isEmpty()) {
String orgFileName = ""; String orgFileName = "";
try { try {
orgFileName = StringUtils.cleanPath(Objects.requireNonNull(mf.getOriginalFilename())); orgFileName = StringUtils.cleanPath(Objects.requireNonNull(mf.getOriginalFilename()));
@ -94,7 +88,11 @@ public class CtgyFileService implements ICtgyFileService {
MinInfoBoard680 savedEntity = repository.findById(entity.getInCode()).orElseGet(MinInfoBoard680::new); MinInfoBoard680 savedEntity = repository.findById(entity.getInCode()).orElseGet(MinInfoBoard680::new);
savedEntity.setInFilename(orgFileName); savedEntity.setInFilename(orgFileName);
savedEntity.setInFilesize(mf.getSize()); savedEntity.setInFilesize(mf.getSize());
savedEntity.setInFileurl(serviceUrl+urlPath); savedEntity.setInFileurl(serviceUrl + urlPath);
savedEntity.setInBgubun(entity.getInBgubun());
savedEntity.setInTitle(entity.getInTitle());
savedEntity.setInContents(entity.getInContents());
JpaUtil.saveIfNullId(savedEntity.getInCode(), repository, savedEntity); JpaUtil.saveIfNullId(savedEntity.getInCode(), repository, savedEntity);
entityList.add(savedEntity); entityList.add(savedEntity);
@ -105,7 +103,7 @@ public class CtgyFileService implements ICtgyFileService {
// copy의 옵션은 기존에 존재하면 REPLACE(대체한다), 오버라이딩 한다 // copy의 옵션은 기존에 존재하면 REPLACE(대체한다), 오버라이딩 한다
//Files.copy(multipartFile.getInputStream(), copyOfLocation, StandardCopyOption.REPLACE_EXISTING); //Files.copy(multipartFile.getInputStream(), copyOfLocation, StandardCopyOption.REPLACE_EXISTING);
}catch(IOException e){ } catch (IOException e) {
String errMsg = String.format("File Upload Error :: %s", orgFileName); String errMsg = String.format("File Upload Error :: %s", orgFileName);
//TODO : 에러처리 //TODO : 에러처리
//return RestError.of(String.format("File Upload Error :: %s", orgFileName)); //return RestError.of(String.format("File Upload Error :: %s", orgFileName));
@ -113,20 +111,31 @@ public class CtgyFileService implements ICtgyFileService {
} }
} }
} }
}else{
MinInfoBoard680 savedEntity = repository.findById(entity.getInCode()).orElseGet(MinInfoBoard680::new);
savedEntity.setInBgubun(entity.getInBgubun());
savedEntity.setInTitle(entity.getInTitle());
savedEntity.setInContents(entity.getInContents());
JpaUtil.saveIfNullId(savedEntity.getInCode(), repository, savedEntity);
}
return entityList; return entityList;
} }
// @Transactional @Override
// public void removeExistsUploadFile(String fileMstId, String orgFileNm){ public void removePublicBoardFile(Long inCode) {
// CmmFileDtl cmmFileDtl = cmmFileDtlRepository.findByFileMstIdAndOrgFileNmIgnoreCase(fileMstId, orgFileNm);
// if(cmmFileDtl != null){ MinInfoBoard680 savedEntity = repository.findById(inCode).orElseThrow(() -> new CustomBaseException(ErrorCode.NOT_FOUND));
// CmmFileDtlIds cmmFileDtlIds = new CmmFileDtlIds();
// cmmFileDtlIds.setFileMstId(fileMstId); File file = null;
// cmmFileDtlIds.setFileId(cmmFileDtl.getFileId()); if(Checks.isNotEmpty(savedEntity.getInFilename())){
// cmmFileDtlRepository.deleteById(cmmFileDtlIds); String absFile = rootPath + savedEntity.getInFileurl().split(serviceUrl)[1]+File.separator + savedEntity.getInFilename();
// new File(this.uploadPath + cmmFileDtl.getFileUpldPath() + File.separator + cmmFileDtl.getFileId()).delete(); file = new File(absFile);
// } }
// }
// 정보 삭제후 파일 삭제
repository.deleteById(inCode);
if(file.exists()) file.delete();
}
} }
/* /*

Loading…
Cancel
Save