|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.xit.biz.ctgy.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.xit.biz.ctgy.CtgyConstants;
|
|
|
|
|
import com.xit.biz.ctgy.dto.MinInfoBoard680Dto;
|
|
|
|
|
import com.xit.biz.ctgy.dto.struct.MinInfoBoard680Mapstruct;
|
|
|
|
|
import com.xit.biz.ctgy.entity.MinInfoBoard680;
|
|
|
|
|
import com.xit.biz.ctgy.repository.IPublicBoardRepository;
|
|
|
|
|
import com.xit.biz.ctgy.service.ICtgyFileService;
|
|
|
|
@ -13,6 +14,7 @@ import com.xit.core.util.DateUtil;
|
|
|
|
|
import io.jsonwebtoken.lang.Assert;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.mapstruct.factory.Mappers;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
@ -47,6 +49,7 @@ public class CtgyFileService implements ICtgyFileService {
|
|
|
|
|
private long maxSize;
|
|
|
|
|
|
|
|
|
|
private final IPublicBoardRepository repository;
|
|
|
|
|
private final MinInfoBoard680Mapstruct mapstruct = Mappers.getMapper(MinInfoBoard680Mapstruct.class);
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MinInfoBoard680 findFiles(Long inCode) {
|
|
|
|
@ -60,14 +63,14 @@ public class CtgyFileService implements ICtgyFileService {
|
|
|
|
|
* 신규등록시는 CmmFileMst.fileMstId가 null, 변경시 not null
|
|
|
|
|
* 변경시 동일한 파일 이름이 존재하면 DB 및 해당 파일 삭제후 신규로 생성
|
|
|
|
|
*
|
|
|
|
|
* @param entity MinInfoBoard680
|
|
|
|
|
* @param files MultipartFile[]
|
|
|
|
|
* @param dto MinInfoBoard680Dto
|
|
|
|
|
* @return CmmFileMst
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public List<MinInfoBoard680> saveFiles(@Nonnull MinInfoBoard680 entity, MultipartFile[] files) {
|
|
|
|
|
public List<MinInfoBoard680> saveFiles(@Nonnull MinInfoBoard680Dto dto) {
|
|
|
|
|
List<MinInfoBoard680> entityList = new ArrayList<>();
|
|
|
|
|
MultipartFile[] files = dto.getFiles();
|
|
|
|
|
|
|
|
|
|
if(files != null && files.length > 0){
|
|
|
|
|
String makePath = File.separator + DateUtil.getToday("");
|
|
|
|
@ -87,15 +90,21 @@ public class CtgyFileService implements ICtgyFileService {
|
|
|
|
|
MinInfoBoard680 savedEntity = null;
|
|
|
|
|
|
|
|
|
|
// 파일 저장 && 전송
|
|
|
|
|
if(Checks.isEmpty(entity.getInCode()))
|
|
|
|
|
savedEntity = new MinInfoBoard680();
|
|
|
|
|
else
|
|
|
|
|
savedEntity = repository.findById(entity.getInCode()).orElseGet(MinInfoBoard680::new);
|
|
|
|
|
savedEntity.setInFilename(orgFileName);
|
|
|
|
|
savedEntity.setInFilesize(mf.getSize());
|
|
|
|
|
savedEntity.setInFileurl(serviceUrl + urlPath);
|
|
|
|
|
setEntity(savedEntity, entity);
|
|
|
|
|
JpaUtil.saveIfNullId(entity.getInCode(), repository, savedEntity);
|
|
|
|
|
if(Checks.isEmpty(dto.getInCode())) {
|
|
|
|
|
dto.setInCode(repository.getInCodeByInBgubun());
|
|
|
|
|
dto.setInContentno(dto.getInCode());
|
|
|
|
|
dto.setInFilename(orgFileName);
|
|
|
|
|
dto.setInFilesize(mf.getSize());
|
|
|
|
|
dto.setInFileurl(serviceUrl + urlPath);
|
|
|
|
|
savedEntity = mapstruct.toEntity(dto); //MinInfoBoard680.builder().build();
|
|
|
|
|
}else {
|
|
|
|
|
savedEntity = repository.findById(dto.getInCode()).orElseThrow(() -> new CustomBaseException(ErrorCode.NOT_FOUND));
|
|
|
|
|
savedEntity.setInFilename(orgFileName);
|
|
|
|
|
savedEntity.setInFilesize(mf.getSize());
|
|
|
|
|
savedEntity.setInFileurl(serviceUrl + urlPath);
|
|
|
|
|
setEntity(savedEntity, dto);
|
|
|
|
|
}
|
|
|
|
|
JpaUtil.saveIfNullId(dto.getInCode(), repository, savedEntity);
|
|
|
|
|
|
|
|
|
|
entityList.add(savedEntity);
|
|
|
|
|
mf.transferTo(new File(fileUploadPath + File.separator + orgFileName));
|
|
|
|
@ -115,13 +124,15 @@ public class CtgyFileService implements ICtgyFileService {
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
MinInfoBoard680 savedEntity = null;
|
|
|
|
|
if(Checks.isEmpty(entity.getInCode()))
|
|
|
|
|
savedEntity = new MinInfoBoard680();
|
|
|
|
|
else
|
|
|
|
|
savedEntity = repository.findById(entity.getInCode()).orElseGet(MinInfoBoard680::new);
|
|
|
|
|
|
|
|
|
|
setEntity(savedEntity, entity);
|
|
|
|
|
JpaUtil.saveIfNullId(entity.getInCode(), repository, savedEntity);
|
|
|
|
|
if(Checks.isEmpty(dto.getInCode())) {
|
|
|
|
|
dto.setInCode(repository.getInCodeByInBgubun());
|
|
|
|
|
dto.setInContentno(dto.getInCode());
|
|
|
|
|
savedEntity = mapstruct.toEntity(dto);
|
|
|
|
|
}else {
|
|
|
|
|
savedEntity = repository.findById(dto.getInCode()).orElseThrow(() -> new CustomBaseException(ErrorCode.NOT_FOUND));
|
|
|
|
|
setEntity(savedEntity, dto);
|
|
|
|
|
}
|
|
|
|
|
JpaUtil.saveIfNullId(dto.getInCode(), repository, savedEntity);
|
|
|
|
|
}
|
|
|
|
|
return entityList;
|
|
|
|
|
}
|
|
|
|
@ -146,16 +157,10 @@ public class CtgyFileService implements ICtgyFileService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setEntity(MinInfoBoard680 savedEntity, MinInfoBoard680 entity){
|
|
|
|
|
savedEntity.setInBgubun(CtgyConstants.PublicBoard.GUBUN.getCode());
|
|
|
|
|
savedEntity.setInDept(entity.getInDept());
|
|
|
|
|
savedEntity.setInTitle(entity.getInTitle());
|
|
|
|
|
savedEntity.setInContents(entity.getInContents());
|
|
|
|
|
|
|
|
|
|
if(Checks.isEmpty(entity.getInCode())) {
|
|
|
|
|
savedEntity.setInCode(repository.getInCodeByInBgubun());
|
|
|
|
|
savedEntity.setInContentno(savedEntity.getInCode());
|
|
|
|
|
}
|
|
|
|
|
private void setEntity(MinInfoBoard680 savedEntity, MinInfoBoard680Dto dto){
|
|
|
|
|
savedEntity.setInDept(dto.getInDept());
|
|
|
|
|
savedEntity.setInTitle(dto.getInTitle());
|
|
|
|
|
savedEntity.setInContents(dto.getInContents());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|