feat: 공통 파일업로드 및 저장 적용

dev
Jonguk. Lim 6 months ago
parent 49af878af2
commit eeff4ee771

@ -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;
/**
*

@ -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;
/**
* <pre>
@ -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) {
/**
* <pre>
* file
* @param infoType : : Constants.FILE_INFO_TYPE
* @param infoKey : - ID
* @param subType :
* -> :
* -> :
* @param mf : MultipartFile
* @return fileId
* </pre>
*/
private String uploadFileAndSave(String infoType, String infoKey, String subType, MultipartFile mf) {
MultipartFile[] uploads = Arrays.asList(mf).toArray(new MultipartFile[0]);
List<FileInfo> 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();
}

@ -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();
}
}
/**
* <pre>
*
* 100-
* 110-
* 200-
* </pre>
*/
@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)));
}
}
/**
* <pre>
* -
* 01 -
* 02-
* 03 -
* 04 -
* </pre>
*/
@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)));
}
}
/**
* <pre>

@ -20,7 +20,7 @@
</resultMap>
<sql id="fileDirs">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

@ -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')

Loading…
Cancel
Save