From 186fb31d4c8cdd99d24c28b9f945fe3a46cb1b89 Mon Sep 17 00:00:00 2001 From: "Jonguk. Lim" Date: Wed, 19 Jun 2024 15:12:29 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=ED=8F=90=EA=B8=B0=EA=B2=B0=EA=B3=BC[?= =?UTF-8?q?=ED=86=B5=EB=B3=B4]=20=EB=B3=80=EA=B2=BD=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20=EB=B3=80=EA=B2=BD=20=20=20=20=20=20->?= =?UTF-8?q?=20=EB=AA=A8=EB=93=A0=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=9B=84=20insert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nims/service/bean/BizNimsServiceBean.java | 29 +++++++++++++++++-- .../sql/mapper/biz/nims-mysql-mapper.xml | 2 ++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/cokr/xit/adds/biz/nims/service/bean/BizNimsServiceBean.java b/src/main/java/cokr/xit/adds/biz/nims/service/bean/BizNimsServiceBean.java index cd7bbf8..a7532ea 100644 --- a/src/main/java/cokr/xit/adds/biz/nims/service/bean/BizNimsServiceBean.java +++ b/src/main/java/cokr/xit/adds/biz/nims/service/bean/BizNimsServiceBean.java @@ -288,7 +288,8 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe dtlCnt = dtlCnt + bizNimsMapper.insertDsuseMgtDtl(d); // FIXME: 파일 갯수 확인 - 프론트 파일 처리 완료시 까지 comment 처리 - d.setFileId(uploadFileAndSave(Constants.FILE_INF_TYPE.DSUSE_PRD_IMG.getCode(), reqDto.getDscdmngId(), sn, files.get(dtlCnt-1))); + d.setFileId( + uploadFileDeleteAndSave(Constants.FILE_INF_TYPE.DSUSE_PRD_IMG.getCode(), reqDto.getDscdmngId(), sn, files.get(dtlCnt-1))); } if(dtls.size() != dtlCnt) throw ApiCustomException.create("폐기 관리 상세 등록 실패"); } else { @@ -309,9 +310,15 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe reqDto.setRgtr(reqDto.getUserId()); if(bizNimsMapper.updateDsuseMgtRslt(reqDto) == 1){ + // 파일 삭제 + List fileIds = bizNimsMapper.selectFileId(Map.of("infType", Constants.FILE_INF_TYPE.DSUSE_IMG.getCode(), "infKey", reqDto.getDscdmngId())); + if(!fileIds.isEmpty()){ + fileService.delete(fileIds.toArray(new String[0])); + } + int idx = 1; for (MultipartFile mf : files) { - uploadFileAndSave(Constants.FILE_INF_TYPE.DSUSE_IMG.getCode(), reqDto.getDscdmngId(), String.valueOf(idx), mf); + uploadFileSave(Constants.FILE_INF_TYPE.DSUSE_IMG.getCode(), reqDto.getDscdmngId(), String.valueOf(idx), mf); idx++; } @@ -894,12 +901,28 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe * @return fileId * */ - private String uploadFileAndSave(String infType, String infKey, String subType, MultipartFile mf) { + private String uploadFileDeleteAndSave(String infType, String infKey, String subType, MultipartFile mf) { List fileIds = bizNimsMapper.selectFileId(Map.of("infType", infType, "infKey", infKey, "subType", subType)); if(!fileIds.isEmpty()){ fileService.delete(fileIds.toArray(new String[0])); } + return uploadFileSave(infType, infKey, subType, mf); + } + + /** + *
+	 * file 저장 처리
+	 * @param infType : 파일 정보 타입 : Constants.FILE_INFO_TYPE
+	 * @param infKey : 파일 정보 키 - 폐기관리ID
+	 * @param subType : 파일 정보 서브 타입
+	 *                  -> 폐기제품이미지 : 폐기관리상세의 순번
+	 *                  -> 폐기이미지 : 이미지 순서
+	 * @param mf	: MultipartFile
+	 * @return fileId
+	 * 
+ */ + private String uploadFileSave(String infType, String infKey, String subType, MultipartFile mf) { MultipartFile[] uploads = Collections.singletonList(mf).toArray(new MultipartFile[0]); List files = (new FileInfoFactory()).makeFileInfos((new FileInfo.Relation()).setInfoType(infType).setInfoKey(infKey).setSubType(subType), uploads); fileService.create(files); diff --git a/src/main/resources/sql/mapper/biz/nims-mysql-mapper.xml b/src/main/resources/sql/mapper/biz/nims-mysql-mapper.xml index d0ca9d7..869ca97 100644 --- a/src/main/resources/sql/mapper/biz/nims-mysql-mapper.xml +++ b/src/main/resources/sql/mapper/biz/nims-mysql-mapper.xml @@ -725,7 +725,9 @@ FROM tb_file WHERE INF_TYPE = #{infType} AND INF_KEY = #{infKey} + AND SUB_TYPE = #{subType} +