From eeff4ee7716d31dcbd4eb20b64f11be0960c9647 Mon Sep 17 00:00:00 2001 From: "Jonguk. Lim" Date: Tue, 28 May 2024 15:18:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B3=B5=ED=86=B5=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=EB=B0=8F=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adds/biz/nims/model/BizNimsRequest.java | 5 +- .../nims/service/bean/BizNimsServiceBean.java | 47 +++++------- .../java/cokr/xit/adds/core/Constants.java | 76 +++++++++++++++++-- .../resources/sql/mapper/base/file-mapper.xml | 2 +- .../sql/mapper/biz/nims-mysql-mapper.xml | 5 ++ 5 files changed, 96 insertions(+), 39 deletions(-) diff --git a/src/main/java/cokr/xit/adds/biz/nims/model/BizNimsRequest.java b/src/main/java/cokr/xit/adds/biz/nims/model/BizNimsRequest.java index 956e5ec..41c20aa 100644 --- a/src/main/java/cokr/xit/adds/biz/nims/model/BizNimsRequest.java +++ b/src/main/java/cokr/xit/adds/biz/nims/model/BizNimsRequest.java @@ -494,9 +494,8 @@ public class BizNimsRequest { @Positive(message = "폐기 수량은 0보다 커야 합니다") private Integer dsuseQy; - // @Schema(title = "폐기제품이미지", example = " ") - // //@NotEmpty(message = "폐기제품이미지는 필수 입니다") - // private MultipartFile dsusePrdImgFile; + @Schema(title = "폐기제품이미지파일ID", example = " ") + private String fileId; /** * 사용자보고식별번호 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 3c75f8c..fd791aa 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 @@ -1,9 +1,5 @@ package cokr.xit.adds.biz.nims.service.bean; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -38,7 +34,6 @@ import cokr.xit.base.file.web.FileInfoFactory; import cokr.xit.foundation.component.AbstractServiceBean; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import lombok.val; /** *
@@ -377,9 +372,6 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe
 
 		if(bizNimsMapper.insertDsuseMgtReceipt(dto) == 1){
 			int dtlCnt = 0;
-			String dirPath = dsuseImgPath + Constants.FILE_DLMTR + dto.getDscdmngId();
-			File f = new File(dirPath);
-			if(!f.exists()) f.mkdirs();
 
 			for (BizNimsRequest.DsuseMgtDtl d : dtls) {
 				String sn = StringUtils.leftPad(dtlCnt + 1 + "", 3, "0");
@@ -388,7 +380,7 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe
 				d.setRgtr(dto.getUserId());
 				dtlCnt = dtlCnt + bizNimsMapper.insertDsuseMgtDtl(d);
 
-				uploadFileAndSave("100", dto.getDscdmngId(), sn, files.get(dtlCnt-1), dirPath);
+				d.setFileId(uploadFileAndSave(Constants.FILE_INF_TYPE.DSUSE_PRD_IMG.getCode(), dto.getDscdmngId(), sn, files.get(dtlCnt-1)));
 			}
 			if(dtls.size() != dtlCnt) throw ApiCustomException.create("폐기 관리 상세 등록 실패");
 		} else {
@@ -409,13 +401,9 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe
 		dto.setRgtr(dto.getUserId());
 
 		if(bizNimsMapper.updateDsuseMgtRslt(dto) == 1){
-			String dirPath = dsuseImgPath + Constants.FILE_DLMTR + dto.getDscdmngId();
-			File f = new File(dirPath);
-			if(!f.exists()) f.mkdirs();
-
 			int idx = 1;
 			for (MultipartFile mf : files) {
-				uploadFileAndSave("110", dto.getDscdmngId(), String.valueOf(idx), mf, dirPath);
+				uploadFileAndSave(Constants.FILE_INF_TYPE.DSUSE_IMG.getCode(), dto.getDscdmngId(), String.valueOf(idx), mf);
 				idx++;
 			}
 
@@ -909,25 +897,24 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe
 		}
 	}
 
-	private void uploadFileAndSave(String infoType, String infoKey, String subType, MultipartFile mf, String dirPath) {
+	/**
+	 * 
+	 * file 저장 처리
+	 * @param infoType : 파일 정보 타입 : Constants.FILE_INFO_TYPE
+	 * @param infoKey : 파일 정보 키 - 폐기관리ID
+	 * @param subType : 파일 정보 서브 타입
+	 *                  -> 폐기제품이미지 : 폐기관리상세의 순번
+	 *                  -> 폐기이미지 : 이미지 순서
+	 * @param mf	: MultipartFile
+	 * @return fileId
+	 * 
+ */ + private String uploadFileAndSave(String infoType, String infoKey, String subType, MultipartFile mf) { MultipartFile[] uploads = Arrays.asList(mf).toArray(new MultipartFile[0]); List files = (new FileInfoFactory()).makeFileInfos((new FileInfo.Relation()).setInfoType(infoType).setInfoKey(infoKey).setSubType(subType), uploads); - int affected = fileService.create(files); + fileService.create(files); - - val name = mf.getOriginalFilename(); - val ext = name.substring(name.lastIndexOf(".")); - val filename = name.substring(0, name.lastIndexOf(".")); - - Path path = Paths.get(dirPath + Constants.FILE_DLMTR, name); - - // FIXME : file upload - try { - mf.transferTo(path); - //FileCopyUtils.copy(mf.getInputStream(), Files.newOutputStream(path)); - } catch (IOException e) { - throw ApiCustomException.create(String.format("폐기 통보[결과] 처리:파일 업로드 실패[%s]", e.getMessage())); - } + return files.get(0).getId(); } diff --git a/src/main/java/cokr/xit/adds/core/Constants.java b/src/main/java/cokr/xit/adds/core/Constants.java index becad1e..86113cd 100644 --- a/src/main/java/cokr/xit/adds/core/Constants.java +++ b/src/main/java/cokr/xit/adds/core/Constants.java @@ -64,7 +64,6 @@ public class Constants { .findFirst() .map(RPT_TY_CD::getNm) .orElseThrow(() -> ApiCustomException.create(String.format("미 정의된 보고 유형 코드[%s]", code))); - //return eNum.getNm(); } } @@ -97,7 +96,6 @@ public class Constants { .findFirst() .map(DSUSE_SE_CD::getNm) .orElseThrow(() -> ApiCustomException.create(String.format("미 정의된 폐기 보고 코드[%s]", code))); - //return eNum.getNm(); } } @@ -137,7 +135,6 @@ public class Constants { .findFirst() .map(DSUSE_PRV_CD::getNm) .orElseThrow(() -> ApiCustomException.create(String.format("미 정의된 폐기 사유 코드[%s]", code))); - //return eNum.getNm(); } } @@ -177,7 +174,6 @@ public class Constants { .findFirst() .map(DSUSE_MTH_CD::getNm) .orElseThrow(() -> ApiCustomException.create(String.format("미 정의된 폐기 방법 코드[%s]", code))); - //return eNum.getNm(); } } @@ -219,10 +215,80 @@ public class Constants { .findFirst() .map(PRGRS_STTS_CD::getNm) .orElseThrow(() -> ApiCustomException.create(String.format("미 정의된 폐기 관리 진행 상태 코드[%s]", code))); - //return eNum.getNm(); } } + /** + *
+     * 파일 관련정보유형
+     * 100-폐기제품이미지
+     * 110-폐기이미지
+     * 200-폐기보고문서
+     * 
+ */ + @Getter + public enum FILE_INF_TYPE { + // 폐기보고신청서의 데이타 입력 생성 - 폐기관리 데이타 생성 + DSUSE_PRD_IMG("100", "폐기제품이미지"), + DSUSE_IMG("110", "폐기이미지"), + DSUSE_RPT_DOC("200", "폐기보고문서"), + ; + + private final String code; + private final String nm; + + FILE_INF_TYPE(String code, String nm) { + this.code = code; + this.nm = nm; + } + + public static String getName(final String code){ + if(StringUtils.isEmpty(code)) return StringUtils.EMPTY; + + return Arrays.stream(FILE_INF_TYPE.values()) + .filter(ssc -> ssc.getCode().equals(code)) + .findFirst() + .map(FILE_INF_TYPE::getNm) + .orElseThrow(() -> ApiCustomException.create(String.format("미 정의된 파일 관련 정보 유형 코드[%s]", code))); + } + } + + /** + *
+     * 파일 서브 타입 - 보고 문서의
+     * 01 - 폐기결과통보서
+     * 02- 폐기결과보고서
+     * 03 - 폐기현황
+     * 04 - 폐기처리내역서
+     * 
+ */ + @Getter + public enum FILE_RPT_DOC_SUB_TYPE { + // 폐기보고신청서의 데이타 입력 생성 - 폐기관리 데이타 생성 + DSUSE_RSLT_NOTICE("01", "폐기결과통보서"), + DSUSE_RSLT_RPT("02", "폐기결과보고서"), + DSUSE_BOARD("03", "폐기현황"), + DSUSE_PRCS_STTS("04", "폐기처리내역서") + ; + + private final String code; + private final String nm; + + FILE_RPT_DOC_SUB_TYPE(String code, String nm) { + this.code = code; + this.nm = nm; + } + + public static String getName(final String code){ + if(StringUtils.isEmpty(code)) return StringUtils.EMPTY; + + return Arrays.stream(FILE_RPT_DOC_SUB_TYPE.values()) + .filter(ssc -> ssc.getCode().equals(code)) + .findFirst() + .map(FILE_RPT_DOC_SUB_TYPE::getNm) + .orElseThrow(() -> ApiCustomException.create(String.format("미 정의된 파일 폐기 보고 문서 서브 타입 코드[%s]", code))); + } + } /** *
diff --git a/src/main/resources/sql/mapper/base/file-mapper.xml b/src/main/resources/sql/mapper/base/file-mapper.xml
index 2a19917..1a59c59 100644
--- a/src/main/resources/sql/mapper/base/file-mapper.xml
+++ b/src/main/resources/sql/mapper/base/file-mapper.xml
@@ -20,7 +20,7 @@
 
 
 SELECT INF_TYPE
-     , CONCAT('d:/data/adds/files/', DIR, DATE_FORMAT(CURRENT_DATE, '/%Y/%m/%d/')) DIR
+     , CONCAT('/data/adds/files/', DIR, DATE_FORMAT(CURRENT_DATE, '/%Y/%m/%d/')) DIR
   FROM (
 	   SELECT '00' INF_TYPE, 'attachment' DIR FROM DUAL UNION
 	   SELECT '01' INF_TYPE, 'document' DIR FROM DUAL UNION
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 cc64a0f..56d9d01 100644
--- a/src/main/resources/sql/mapper/biz/nims-mysql-mapper.xml
+++ b/src/main/resources/sql/mapper/biz/nims-mysql-mapper.xml
@@ -363,6 +363,7 @@
                tdmd.use_yn,
                tdmd.reg_dt,
                tdmd.rgtr,
+               tf.file_id,               /* 파일ID-폐기제품이미지 */
                tpi.nrcd_se_nm,           /* 마약항정구분 */
                tpi.prtm_se_nm,           /* 중점일반구분 */
                tpi.std_packng_stle_nm,   /* 제품최소유통단위 */
@@ -370,6 +371,10 @@
                tpi.bssh_cd,              /* 제조수입자 */
                tbi.bssh_nm               /* 제조수입자명 */
           FROM tb_dsuse_mgt_dtl tdmd
+          LEFT JOIN tb_file tf
+            ON (tdmd.dscdmng_id = tf.inf_key
+                AND tf.inf_type = '100'
+                AND tdmd.dscdmng_sn = tf.sub_type)
           LEFT JOIN tb_prduct_info tpi
             ON (tdmd.prduct_cd = tpi.prduct_cd)
         --    AND tdmd.use_yn = 'Y')