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