feat: 관리자 - 팝업 관리 > 특정 글 수정 시, 파일 여러개 일 경우 파일 목록이 안 나타나는 문제 수정
parent
11ca97d87c
commit
44b2507d99
|
|
@ -88,13 +88,13 @@ public class PopUpApiController {
|
|||
@AuthenticationPrincipal LoginVO loginVO,
|
||||
final MultipartHttpServletRequest multiRequest,
|
||||
CreatePopupVO createPopupVO,
|
||||
@RequestParam(required = false) MultipartFile file
|
||||
@RequestParam(required = false) MultipartFile[] files
|
||||
) throws Exception {
|
||||
|
||||
ResultVO resultVO = new ResultVO();
|
||||
|
||||
try {
|
||||
resultVO = popUpApiService.contentsApiPopUpManageCreate(resultVO, request, loginVO, multiRequest, createPopupVO, file);
|
||||
resultVO = popUpApiService.contentsApiPopUpManageCreate(resultVO, request, loginVO, multiRequest, createPopupVO, files);
|
||||
} catch (Exception e) {
|
||||
resultVO.setResultCode(ResponseCode.FAILED.getCode());
|
||||
resultVO.setResultMessage(e.getMessage());
|
||||
|
|
@ -129,14 +129,14 @@ public class PopUpApiController {
|
|||
HttpServletRequest request,
|
||||
@AuthenticationPrincipal LoginVO loginVO,
|
||||
UpdatePopupVO updatePopupVO,
|
||||
@RequestParam(required = false) MultipartFile file,
|
||||
@RequestParam(required = false) MultipartFile[] files,
|
||||
@PathVariable("popupId") Long popupId
|
||||
) throws Exception {
|
||||
|
||||
ResultVO resultVO = new ResultVO();
|
||||
|
||||
try {
|
||||
resultVO = popUpApiService.contentsApiPopUpManageUpdate(resultVO, request, loginVO, updatePopupVO, file, popupId);
|
||||
resultVO = popUpApiService.contentsApiPopUpManageUpdate(resultVO, request, loginVO, updatePopupVO, files, popupId);
|
||||
} catch (Exception e) {
|
||||
resultVO.setResultCode(ResponseCode.FAILED.getCode());
|
||||
resultVO.setResultMessage(e.getMessage());
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ import javax.servlet.http.HttpServletRequest;
|
|||
|
||||
public interface PopUpApiService {
|
||||
public ResultVO contentsApiPopUpManageList(ResultVO resultVO, HttpServletRequest request, LoginVO user, Pageable pageable) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageCreate(ResultVO resultVO, HttpServletRequest request, LoginVO user, final MultipartHttpServletRequest multiRequest, CreatePopupVO createPopupVO, MultipartFile file) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageRead(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long popupId) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile file, Long popupId) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageDelete(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long popupId) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageUpdateActivationSwitch(ResultVO resultVO, HttpServletRequest request, LoginVO user, String checked, Long popupId) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageCreate(ResultVO resultVO, HttpServletRequest request, LoginVO user, final MultipartHttpServletRequest multiRequest, CreatePopupVO createPopupVO, MultipartFile[] files) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageRead(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long popupSeq) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile[] files, Long popupSeq) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageDelete(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long popupSeq) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageUpdateActivationSwitch(ResultVO resultVO, HttpServletRequest request, LoginVO user, String checked, Long popupSeq) throws Exception;
|
||||
|
||||
}
|
||||
|
|
@ -103,7 +103,7 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
|
||||
|
||||
@Override
|
||||
public ResultVO contentsApiPopUpManageCreate(ResultVO resultVO, HttpServletRequest request, LoginVO user, final MultipartHttpServletRequest multiRequest, CreatePopupVO createPopupVO, MultipartFile file) throws Exception {
|
||||
public ResultVO contentsApiPopUpManageCreate(ResultVO resultVO, HttpServletRequest request, LoginVO user, final MultipartHttpServletRequest multiRequest, CreatePopupVO createPopupVO, MultipartFile[] files) throws Exception {
|
||||
|
||||
System.out.println(
|
||||
"\n--------------------------------------------------------------\n" +
|
||||
|
|
@ -115,7 +115,7 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
);
|
||||
|
||||
|
||||
String fileGrpId = fileService.addTnAttachFile(request, user, file, this.getMiddlePath());
|
||||
String fileGrpId = fileService.addTnAttachFile(request, user, files, this.getMiddlePath());
|
||||
|
||||
Map<String, Object> response = tnPopupMngRepository.spAddTnPopupMng(
|
||||
createPopupVO.getTitle(),
|
||||
|
|
@ -173,13 +173,24 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
dto.put("schdulEndde", tnPopupMng.getPopupEndDate().plusHours(9).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); // 날짜/시간의 종료 일시 - yyyyMMddHHmmss
|
||||
|
||||
//첨부파일명을 가져온다.
|
||||
TnAttachFile tnAttachFile = tnAttachFileRepository.findByFileGrpId(tnPopupMng.getFileGrpId()).orElse(null);
|
||||
List<TnAttachFile> tnAttachFileList = tnAttachFileRepository.findByFileGrpId(tnPopupMng.getFileGrpId()).orElse(null);
|
||||
|
||||
if( tnAttachFile != null ) {
|
||||
dto.put("fileName", tnAttachFile.getFileOldName());
|
||||
} else {
|
||||
dto.put("fileName", null);
|
||||
if( tnAttachFileList != null ) {
|
||||
List<Map<String, Object>> files = new ArrayList<Map<String, Object>>();
|
||||
for (TnAttachFile item : tnAttachFileList) {
|
||||
Map<String, Object> fileDto = new HashMap<String, Object>();
|
||||
fileDto.put("seq", item.getFileSeq());
|
||||
fileDto.put("name", item.getFileOldName());
|
||||
files.add(fileDto);
|
||||
}
|
||||
dto.put("files", files);
|
||||
} else {
|
||||
dto.put("files", null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
resultVO.setResult(dto);
|
||||
resultVO.setResultCode(ResponseCode.SUCCESS.getCode());
|
||||
|
|
@ -189,20 +200,20 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
}
|
||||
|
||||
@Override
|
||||
public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile file, Long popupId) throws Exception {
|
||||
public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile[] files, Long popupSeq) throws Exception {
|
||||
System.out.println(
|
||||
"\n--------------------------------------------------------------\n" +
|
||||
request.getRequestURI() + " IN:" +
|
||||
"\n--------------------------------------------------------------\n" +
|
||||
"updatePopupVO:" + "\n" +
|
||||
updatePopupVO.toString() + "\n" +
|
||||
"popupId:" + "\n" +
|
||||
popupId + "\n" +
|
||||
"popupSeq:" + "\n" +
|
||||
popupSeq + "\n" +
|
||||
"\n--------------------------------------------------------------\n"
|
||||
);
|
||||
|
||||
// 유효성 검사 실시
|
||||
int isValid = tnPopupMngRepository.spIsValidTnPopupMngId( popupId.intValue() );
|
||||
int isValid = tnPopupMngRepository.spIsValidTnPopupMngId( popupSeq.intValue() );
|
||||
|
||||
if( isValid == 0 ) {
|
||||
throw new Exception("대상이 존재하지 않습니다.");
|
||||
|
|
@ -212,10 +223,14 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
throw new Exception("종료일시는 시작일시보다 앞 설 수 없습니다.");
|
||||
}
|
||||
|
||||
String fileGrpId = fileService.addTnAttachFile(request, user, file, this.getMiddlePath());
|
||||
// 기존 첨부된 file이 있다면 기존 fileGrpId을 활용한다.
|
||||
TnPopupMng tnPopupMng = tnPopupMngRepository.findByPopupSeq(popupSeq);
|
||||
|
||||
String fileGrpId = tnPopupMng.getFileGrpId();
|
||||
fileGrpId = fileService.addTnAttachFile(request, user, files, this.getMiddlePath(), fileGrpId);
|
||||
|
||||
Map<String, Object> response = tnPopupMngRepository.spUpdateTnPopupMng(
|
||||
popupId.intValue(),
|
||||
popupSeq.intValue(),
|
||||
updatePopupVO.getTitle(),
|
||||
updatePopupVO.getStartDate(),
|
||||
updatePopupVO.getEndDate(),
|
||||
|
|
@ -230,7 +245,7 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
|
||||
Map<String, Object> dto = new HashMap<String, Object>();
|
||||
dto.put("errorMessage", response.get("_error_message") );
|
||||
dto.put("popupId", popupId);
|
||||
dto.put("popupId", popupSeq);
|
||||
|
||||
resultVO.setResult(dto);
|
||||
resultVO.setResultCode(ResponseCode.SUCCESS.getCode());
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@ import org.springframework.data.jpa.repository.Query;
|
|||
import org.springframework.data.jpa.repository.query.Procedure;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface TnAttachFileRepository extends JpaRepository<TnAttachFile, Integer> {
|
||||
|
||||
Optional<TnAttachFile> findByFileGrpId(String fileGrpId);
|
||||
Optional<List<TnAttachFile>> findByFileGrpId(String fileGrpId);
|
||||
|
||||
@Procedure("make_file_grp_id")
|
||||
String makeFileGrpId( String modiId );
|
||||
|
|
|
|||
|
|
@ -13,10 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
|
|
@ -32,7 +29,7 @@ public class FileService {
|
|||
if(tnAttachFile.getFileSeq()!=null){
|
||||
tnAttachFile = tnAttachFileRepository.findById(tnAttachFile.getFileSeq()).orElse(null);
|
||||
}else{
|
||||
tnAttachFile = tnAttachFileRepository.findByFileGrpId(tnAttachFile.getFileGrpId()).orElse(null);
|
||||
tnAttachFile = Objects.requireNonNull(tnAttachFileRepository.findByFileGrpId(tnAttachFile.getFileGrpId()).orElse(null)).get(0);
|
||||
}
|
||||
int downCnt = tnAttachFile.getDownCnt()==null?0: tnAttachFile.getDownCnt();
|
||||
tnAttachFile.setDownCnt(downCnt+1);
|
||||
|
|
@ -50,30 +47,54 @@ public class FileService {
|
|||
* TN_ATTACH_FILE 참고.
|
||||
* @param request
|
||||
* @param user
|
||||
* @param file
|
||||
* @param files
|
||||
* @param middlePath 파일이 저장될 중간 경로다.
|
||||
* D:/kcscUploadFiles/XXXX/abc.jpg XXXX에 해당하는 경로다.
|
||||
* 참고로 D:/kcscUploadFiles 값은 application-xxx.properties에 있는 Globals.fileStorePath를 통해 얻는다.
|
||||
* @return 파일 그룹 ID
|
||||
* @throws Exception
|
||||
*/
|
||||
public String addTnAttachFile(HttpServletRequest request, LoginVO user, MultipartFile[] files, String middlePath) throws Exception {
|
||||
return this.addTnAttachFile(request, user, files, middlePath, null);
|
||||
}
|
||||
|
||||
public String addTnAttachFile(HttpServletRequest request, LoginVO user, MultipartFile file, String middlePath) throws Exception {
|
||||
MultipartFile[] files = new MultipartFile[1];
|
||||
return this.addTnAttachFile(request, user, files, middlePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* TN_ATTACH_FILE table에 insert 후, 파일 그룹 ID를 return 한다.
|
||||
* TN_ATTACH_FILE 참고.
|
||||
* @param request
|
||||
* @param user
|
||||
* @param files
|
||||
* @param middlePath 파일이 저장될 중간 경로다.
|
||||
* D:/kcscUploadFiles/XXXX/abc.jpg XXXX에 해당하는 경로다.
|
||||
* 참고로 D:/kcscUploadFiles 값은 application-xxx.properties에 있는 Globals.fileStorePath를 통해 얻는다.
|
||||
* @return 파일 그룹 ID
|
||||
* @throws Exception
|
||||
*/
|
||||
public String addTnAttachFile(HttpServletRequest request, LoginVO user, MultipartFile[] files, String middlePath, String fileGrpId) throws Exception {
|
||||
String ipAddress = NetworkUtil.getClientIpAddress(request);
|
||||
|
||||
String fileGrpId = null;
|
||||
if( file != null && !file.isEmpty()) {
|
||||
|
||||
if( fileGrpId == null || fileGrpId.trim().isEmpty()) {
|
||||
//String fileGrpId = UUID.randomUUID().toString();
|
||||
fileGrpId = tnAttachFileRepository.makeFileGrpId(user.getId());
|
||||
}
|
||||
|
||||
|
||||
for (MultipartFile file : files) {if( file != null && !file.isEmpty()) {
|
||||
|
||||
Map<String, MultipartFile> filesMap = new HashMap<String, MultipartFile>();
|
||||
filesMap.put("file", file);
|
||||
|
||||
//String fileGrpId = UUID.randomUUID().toString();
|
||||
fileGrpId = tnAttachFileRepository.makeFileGrpId(user.getId());
|
||||
|
||||
List<FileVO> files = fileUtil.parseFileInf(filesMap, "", 0, middlePath, null);
|
||||
List<FileVO> fileVoList = fileUtil.parseFileInf(filesMap, "", 0, middlePath, null);
|
||||
|
||||
int nCount = 1;
|
||||
// 업로드된 file을 tnAttachFile에 insert한다.
|
||||
for (Iterator<FileVO> iter = files.iterator(); iter.hasNext(); nCount++) {
|
||||
for (Iterator<FileVO> iter = fileVoList.iterator(); iter.hasNext(); nCount++) {
|
||||
|
||||
FileVO item = iter.next();
|
||||
|
||||
|
|
@ -94,6 +115,9 @@ public class FileService {
|
|||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return fileGrpId;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue