|
|
@ -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();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|