diff --git a/README.md b/README.md index 30ca7ab..b50580c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### swagger -[API URL](http://localhost:8081/swagger-ui.html) +[API URL](http://localhost:9076/swagger-ui.html) ### API 결과 수신 diff --git a/pom.xml b/pom.xml index 0085b6a..fc8c2e0 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,11 @@ 23.04.01-SNAPSHOT + + cokr.xit.base + xit-file + 23.04.01-SNAPSHOT + jakarta.xml.bind 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 d637c87..3c75f8c 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 @@ -5,6 +5,7 @@ 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; import java.util.List; import java.util.Map; @@ -31,6 +32,9 @@ import cokr.xit.adds.inf.nims.model.NimsApiRequest; import cokr.xit.adds.inf.nims.model.NimsApiRequest.BsshInfoReq; import cokr.xit.adds.inf.nims.model.NimsApiResult; import cokr.xit.adds.inf.nims.service.InfNimsService; +import cokr.xit.base.file.FileInfo; +import cokr.xit.base.file.service.FileService; +import cokr.xit.base.file.web.FileInfoFactory; import cokr.xit.foundation.component.AbstractServiceBean; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -76,6 +80,7 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); private final InfNimsService infNimsService; private final BizNimsMapper bizNimsMapper; + private final FileService fileService; //------------------------------------------------------------------------------------------------------ // NIMS API CALL @@ -372,15 +377,18 @@ 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"); d.setDscdmngId(dto.getDscdmngId()); - d.setDscdmngSn(StringUtils.leftPad(dtlCnt + 1 + "", 3, "0")); + d.setDscdmngSn(sn); d.setRgtr(dto.getUserId()); dtlCnt = dtlCnt + bizNimsMapper.insertDsuseMgtDtl(d); - // FIXME : file upload - // files[dtlCnt].transferTo(new File("path")); - //d.setDsusePrdImgFile(null); + uploadFileAndSave("100", dto.getDscdmngId(), sn, files.get(dtlCnt-1), dirPath); } if(dtls.size() != dtlCnt) throw ApiCustomException.create("폐기 관리 상세 등록 실패"); } else { @@ -401,27 +409,14 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe dto.setRgtr(dto.getUserId()); if(bizNimsMapper.updateDsuseMgtRslt(dto) == 1){ - int dtlCnt = 0; 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) { - 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())); - } - //d.setDsusePrdImgFile(null); + uploadFileAndSave("110", dto.getDscdmngId(), String.valueOf(idx), mf, dirPath); + idx++; } } else { @@ -884,36 +879,107 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe /** *
-	 * 마약류 취급자 업체 추가 정보 set
-	 * 허가번호(prmisnNo), 대표자명(rprsntvNm) set
-	 * @param resList List
+	 * 상품정보에 제조번호 목록 추가
+	 * @param list List
 	 * 
*/ - private void setAddBsshInfo(List resList) { - for (BizNimsResponse.DsuseRptInfoRes r : resList) { - r.setRptTyCdNm(Constants.RPT_TY_CD.getName(r.getRptTyCd())); - r.setDsuseSeCdNm(Constants.DSUSE_SE_CD.getName(r.getDsuseSeCd())); - r.setDsusePrvCdNm(Constants.DSUSE_PRV_CD.getName(r.getDsusePrvCd())); - r.setDsuseMthCdNm(Constants.DSUSE_MTH_CD.getName(r.getDsuseMthCd())); - - if (isEmpty(r.getPrmisnNo())) { - List list = saveBsshInfoSt( - BsshInfoReq.builder() + private void productInfoaddMnfSeqs(List list) { + String productCd = ""; + + try { + + for (NimsApiDto.ProductInfoKd d : list) { + productCd = d.getPrductCd(); + + List mnfList = getMnfSeqInfo( + NimsApiRequest.MnfSeqInfoReq.builder() .fg("1") .pg("1") - .bc(r.getBsshCd()) + .p(d.getPrductCd()) .build() ); - if (isEmpty(list)) { - // FIXME : 데이타 정상 흐름 확인후 comment 제거 - continue; - //throw ApiCustomException.create(String.format("데이타 오류(마약류취급자식별번호[%s]에 해당하는 데이타가 없습니다)", r.getBsshCd())); - } - r.setPrmisnNo(list.get(0).getPrmisnNo()); - r.setRprsntvNm(list.get(0).getRprsntvNm()); + d.getMnfSeqInfos().addAll(mnfList); } - } - } + + }catch (Exception e){ + if( e instanceof ApiCustomException){ + throw ApiCustomException.create(String.format("[%s]의 제조번호 정보를 찾을수 없습니다.", productCd)); + } + throw ApiCustomException.create(e.getMessage()); + } + } + + private void uploadFileAndSave(String infoType, String infoKey, String subType, MultipartFile mf, String dirPath) { + 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); + + + 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())); + } + } + + + + + + + + + + + + + + + + + + + + /** + *
+	 * 마약류 취급자 업체 추가 정보 set
+	 * 허가번호(prmisnNo), 대표자명(rprsntvNm) set
+	 * @param resList List
+	 * 
+ */ + private void setAddBsshInfo(List resList) { + for (BizNimsResponse.DsuseRptInfoRes r : resList) { + r.setRptTyCdNm(Constants.RPT_TY_CD.getName(r.getRptTyCd())); + r.setDsuseSeCdNm(Constants.DSUSE_SE_CD.getName(r.getDsuseSeCd())); + r.setDsusePrvCdNm(Constants.DSUSE_PRV_CD.getName(r.getDsusePrvCd())); + r.setDsuseMthCdNm(Constants.DSUSE_MTH_CD.getName(r.getDsuseMthCd())); + + if (isEmpty(r.getPrmisnNo())) { + List list = saveBsshInfoSt( + BsshInfoReq.builder() + .fg("1") + .pg("1") + .bc(r.getBsshCd()) + .build() + ); + if (isEmpty(list)) { + // FIXME : 데이타 정상 흐름 확인후 comment 제거 + continue; + //throw ApiCustomException.create(String.format("데이타 오류(마약류취급자식별번호[%s]에 해당하는 데이타가 없습니다)", r.getBsshCd())); + } + r.setPrmisnNo(list.get(0).getPrmisnNo()); + r.setRprsntvNm(list.get(0).getRprsntvNm()); + } + } + } /** *
@@ -925,29 +991,29 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe
 	 */
 	private void setAddProductInfo(List dtlList) {
 
-        for (NimsApiDto.DsuseRptInfoDtl r : dtlList) {//if()
-            // 마약항정구분(nrcdSeNm), 중점일반구분(prtmSenm)
+		for (NimsApiDto.DsuseRptInfoDtl r : dtlList) {//if()
+			// 마약항정구분(nrcdSeNm), 중점일반구분(prtmSenm)
 			if (isEmpty(r.getNrcdSeNm()) || isEmpty(r.getPrtmSeNm())) {
-                //NimsApiResult.Response result = infNimsService.getProductInfoKd(
+				//NimsApiResult.Response result = infNimsService.getProductInfoKd(
 
-                List list = saveProductInfoKd(
-                    NimsApiRequest.ProductInfoReq.builder()
-                        .fg("1")
-                        .pg("1")
-                        .p(r.getPrductCd())
-                        .build(),
+				List list = saveProductInfoKd(
+					NimsApiRequest.ProductInfoReq.builder()
+						.fg("1")
+						.pg("1")
+						.p(r.getPrductCd())
+						.build(),
 					false
-                );
-                if (isEmpty(list)) {
-                    // FIXME : 데이타 정상 흐름 확인후 comment 제거
-                    continue;
-                    //throw ApiCustomException.create(String.format("데이타 오류(제품코드[%s]에 해당하는 데이타가 없습니다)", r.getPrductCd()));
-                }
-                r.setNrcdSeNm(list.get(0).getNrcdSeNm());
-                r.setPrtmSeNm(list.get(0).getPrtmSeNm());
+				);
+				if (isEmpty(list)) {
+					// FIXME : 데이타 정상 흐름 확인후 comment 제거
+					continue;
+					//throw ApiCustomException.create(String.format("데이타 오류(제품코드[%s]에 해당하는 데이타가 없습니다)", r.getPrductCd()));
+				}
+				r.setNrcdSeNm(list.get(0).getNrcdSeNm());
+				r.setPrtmSeNm(list.get(0).getPrtmSeNm());
 				r.setStdPackngStleNm(list.get(0).getStdPackngStleNm());
 				r.setPceCoUnitNm(list.get(0).getPceCoUnitNm());
-            }
+			}
 
 			// 제조수입자명(bsshNm)
 			if (isEmpty(r.getBsshNm()) && !isEmpty(r.getBsshCd())) {
@@ -965,50 +1031,9 @@ public class BizNimsServiceBean extends AbstractServiceBean implements BizNimsSe
 				}
 				r.setBsshNm(list.get(0).getBsshNm());
 			}
-        }
-    }
-
-	/**
-	 * 
-	 * 상품정보에 제조번호 목록 추가
-	 * @param list List
-	 * 
- */ - private void productInfoaddMnfSeqs(List list) { - String productCd = ""; - - try { - - for (NimsApiDto.ProductInfoKd d : list) { - productCd = d.getPrductCd(); - - List mnfList = getMnfSeqInfo( - NimsApiRequest.MnfSeqInfoReq.builder() - .fg("1") - .pg("1") - .p(d.getPrductCd()) - .build() - ); - d.getMnfSeqInfos().addAll(mnfList); - } - - }catch (Exception e){ - if( e instanceof ApiCustomException){ - throw ApiCustomException.create(String.format("[%s]의 제조번호 정보를 찾을수 없습니다.", productCd)); - } - throw ApiCustomException.create(e.getMessage()); } } - - - - - - - - - // @Override // public List getJurisdictionGovInfo(NimsApiRequest.JurisdictionGovInfoRequest dto) { // NimsApiResult.Response result = infNimsService.getJurisdictionGovInfo(dto); diff --git a/src/main/java/cokr/xit/base/FileController.java b/src/main/java/cokr/xit/base/FileController.java new file mode 100644 index 0000000..2d6605a --- /dev/null +++ b/src/main/java/cokr/xit/base/FileController.java @@ -0,0 +1,6 @@ +package cokr.xit.base; + +import org.springframework.stereotype.Controller; + +@Controller +public class FileController extends cokr.xit.base.file.web.FileController {} \ No newline at end of file diff --git a/src/main/resources/sql/mapper/base/file-mapper.xml b/src/main/resources/sql/mapper/base/file-mapper.xml new file mode 100644 index 0000000..e48c2a1 --- /dev/null +++ b/src/main/resources/sql/mapper/base/file-mapper.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + +SELECT INF_TYPE + , CONCAT('d:/data/adds/files/', '2024050001', '/', DIR) DIR + FROM ( + SELECT '00' INF_TYPE, 'attachment/' DIR FROM DUAL UNION + SELECT '01' INF_TYPE, 'document/' DIR FROM DUAL UNION + SELECT '02' INF_TYPE, 'article/' DIR FROM DUAL UNION + + SELECT '100' INF_TYPE, '' DIR FROM DUAL UNION /* 폐기상품이미지 */ + SELECT '110' INF_TYPE, '' DIR FROM DUAL UNION /* 폐기 이미지 */ + SELECT '200' INF_TYPE, '' DIR FROM DUAL /* 폐기보고 문서 */ + ) FILE_DIRS + + + +SELECT A.*, FILE_PATH URL + FROM TB_FILE A + WHERE FILE_ID IN (#{fileID}) + ORDER BY FILE_ID + +SELECT A.*, FILE_PATH URL + FROM TB_FILE A + + AND A.INF_TYPE = #{infoType} + AND INF_KEY IN (#{infoKey}) + AND USE_YN = 'Y' + + + + + + + + + + +/* 파일 등록(fileMapper.insertFile) */ + +SELECT NEW_ID, CONCAT(DIR, NEW_ID, '.', #{file.extension}) PATH + FROM ( + SELECT NVL(MAX(FILE_ID) + 1, CONCAT(THIS_DAY, '00001')) NEW_ID + FROM TB_FILE A, () B + WHERE FILE_ID LIKE CONCAT(THIS_DAY, '%') + ) T1, ( + + WHERE INF_TYPE = #{file.infoType} + ) T2 +INSERT INTO TB_FILE ( + FILE_ID + , INF_TYPE + , INF_KEY + , SUB_TYPE + , FILE_NM + , FILE_PATH + , MIME_TYPE + , FILE_SIZE + , DNLD_CNT + , SRT_ORD + , RGTR + , REG_DT + , USE_YN +) VALUES ( + #{file.id} + , #{file.infoType} + , #{file.infoKey} + , #{file.subType} + , #{file.name} + , #{file.path} + , #{file.mimeType} + , #{file.size} + , #{file.downloadCount} + , #{file.sortOrder} + , #{currentUser.id} + , + , 'Y' +) + + +/* 파일 순서 변경(fileMapper.reorder) */ +UPDATE TB_FILE SET + SRT_ORD = CASE FILE_ID + WHEN #{fileID} THEN #{index} + + ELSE SRT_ORD END +WHERE FILE_ID IN (#{fileID}) + +/* 다운로드 횟수 증가(fileMapper.updateDownloadCount) */ +UPDATE TB_FILE SET + DNLD_CNT = DNLD_CNT + 1 + WHERE USE_YN = 'Y' + AND FILE_ID IN (#{fileID}) + +/* 파일 제거(fileMapper.removeFiles) */ +UPDATE TB_FILE SET + USE_YN = 'N' + WHERE USE_YN = 'Y' + AND FILE_ID IN (#{fileID}) + + AND INF_TYPE = #{infoType} + AND INF_KEY IN (#{infoKey}) + +/* 파일 삭제(fileMapper.deleteFiles) */ +DELETE FROM TB_FILE +WHERE FILE_ID IN (#{fileID}) + + + diff --git a/src/main/resources/sql/mapper/base/utility.xml b/src/main/resources/sql/mapper/base/utility.xml new file mode 100644 index 0000000..7f335db --- /dev/null +++ b/src/main/resources/sql/mapper/base/utility.xml @@ -0,0 +1,37 @@ + + + + + + +SELECT QROWS.* FROM ( + SELECT ROW_NUMBER() OVER() ROW_NUM + , COUNT(*) OVER() TOT_CNT, QBODY.* + FROM ( + + ) QBODY + ) QROWS +WHERE ROW_NUM BETWEEN ((#{pageNum} - 1) * #{fetchSize}) + 1 AND (#{pageNum} * #{fetchSize}) + + + +ORDER BY ${orderBy} + + + +DATE_FORMAT(CURRENT_TIMESTAMP, '%Y%m%d%H%i%s') +TO_CHAR(CURRENT_TIMESTAMP, 'YYYYMMDDHH24MISS') + +SELECTNOW FROM DUAL + +DATE_FORMAT(CURRENT_DATE, '%Y%m%d') +TO_CHAR(CURRENT_DATE, 'YYYYMMDD') + +SELECTTODAY FROM DUAL + +NVL(#{thisDay},) + +SELECTTHIS_DAY FROM DUAL + + \ No newline at end of file