feat: Postplus API file 연계 반영

dev
gitea-관리자 1 year ago
parent 58b158fe37
commit c9109fb599

@ -305,6 +305,15 @@
</dependency>
<!-- fasterxml.jackson -->
<!-- JSONArray -->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<!-- JSONArray -->
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>

@ -1,5 +1,7 @@
package kr.xit.biz.ens.model.cmm;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
@ -9,7 +11,6 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.validator.constraints.NotEmpty;
/**
* <pre>
@ -30,14 +31,14 @@ import org.hibernate.validator.constraints.NotEmpty;
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(Include.NON_ABSENT)
public class CmmEnsRequestDTO implements Serializable {
/**
*
*/
@Schema(requiredMode = RequiredMode.REQUIRED, title = "시군구코드", example = "88328")
@NotEmpty(message = "시군구 코드는 필수 입니다")
@Size(max = 10)
@Size(min = 1, max = 10, message = "시군구 코드는 필수 입니다")
@JsonProperty("signguCode")
private String signguCode;
@ -45,8 +46,7 @@ public class CmmEnsRequestDTO implements Serializable {
*
*/
@Schema(requiredMode = RequiredMode.REQUIRED, title = "과태료코드", example = "11")
@NotEmpty(message = "과태료 코드는 필수 입니다")
@Size(max = 2)
@Size(min = 1, max = 2, message = "과태료 코드는 필수 입니다")
@JsonProperty("ffnlgCode")
private final String ffnlgCode = "11";
private String ffnlgCode = "11";
}

@ -1,9 +1,9 @@
package kr.xit.biz.ens.model.pplus;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import kr.xit.biz.ens.model.cmm.CmmEnsRequestDTO;
@ -69,10 +69,9 @@ public class PplusDTO {
* / data file,
* </pre>
*/
//@JsonIgnore
@JsonIgnore
@Schema(requiredMode = RequiredMode.AUTO, title = "첨부파일", example = " ")
@NotEmpty(message = "첨부파일은 필수 입니다")
private MultipartFile[] pstFile;
private MultipartFile pstFile;
}
/**
@ -82,20 +81,38 @@ public class PplusDTO {
* Response: PpCommonResponse
* </pre>
*/
@Schema(name = "PpAcceptRequest2", description = "Postplus 우편제작 접수 요청 DTO")
@Schema(name = "PpAcceptRequestStruct", description = "Postplus 우편제작 접수 요청 구조 DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class PpAcceptRequest2 extends CmmEnsRequestDTO {
public static class PpAcceptRequestStruct extends CmmEnsRequestDTO {
@Schema(requiredMode = RequiredMode.REQUIRED)
@Valid
private ReqMstData master;
private PpAcceptReqDataStruct master;
@Schema(requiredMode = RequiredMode.REQUIRED)
@Valid
private ReqDtlData detail;
private PpAcceptReqDataStruct detail;
}
/**
* <pre>
* Postplus Data DTO
* </pre>
*/
@Schema(name = "PpAcceptReqDataStruct", description = "Postplus 우편제작 접수 요청 Data 구조 DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class PpAcceptReqDataStruct {
@NotBlank
private String cols;
@NotBlank
private String rows;
}
/**
@ -136,51 +153,13 @@ public class PplusDTO {
* Postplus Data Master DTO
* </pre>
*/
@Schema(name = "ReqMstData", description = "Postplus 우편제작 접수 요청 Data Master DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class ReqMstData {
@NotBlank
private List<String> cols;
@NotBlank
private List<String> rows;
}
/**
* <pre>
* Postplus Data Detail DTO
* </pre>
*/
@Schema(name = "ReqDtlData", description = "Postplus 우편제작 접수 요청 Data Dtl DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class ReqDtlData {
@NotBlank
private List<String> cols;
@NotBlank
private List<List<String>> rows;
}
/**
* <pre>
* Postplus Data Master DTO
* </pre>
*/
@Schema(name = "ReqDataMst", description = "Postplus 우편제작 접수 요청 Data master DTO")
@Schema(name = "PpAcceptReqDataMst", description = "Postplus 우편제작 접수 요청 Data master DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class ReqDataMst {
public static class PpAcceptReqDataMst {
//-----------------------------------------------------------------------
// 필수
//-----------------------------------------------------------------------
@ -344,7 +323,8 @@ public class PplusDTO {
*/
@Schema(requiredMode = RequiredMode.REQUIRED, title = "반송여부유무", example = "N")
@NotEmpty(message = "반송여부는 필수입니다(Y|N)")
private final String = "N";
//private final String 반송여부 = "N";
private final String[] = new String[]{"Y", "N"};
/**
* <pre>
@ -445,13 +425,13 @@ public class PplusDTO {
* Postplus Data Detail DTO
* </pre>
*/
@Schema(name = "ReqDataDtl", description = "Postplus 우편제작 접수 요청 Data detail DTO")
@Schema(name = "PpAcceptReqDataDtl", description = "Postplus 우편제작 접수 요청 Data detail DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class ReqDataDtl {
public static class PpAcceptReqDataDtl {
//-----------------------------------------------------------------------
// 필수
//-----------------------------------------------------------------------

@ -143,14 +143,14 @@ public class BouncyUtils {
}
}
public static void encryptionFile(String key, String filePath) throws IOException {
public static void encryptionFile(final String key, final String filePath, final String fileName) throws IOException {
byte[] plainFileBytes = FileUtil.getFileBytesFrom(filePath);
FileUtil.saveFile(filePath, encrypt(key, plainFileBytes));
FileUtil.saveFile(filePath, fileName, encrypt(key, plainFileBytes));
}
public static void decryptionFile(String key, String filePath) throws IOException {
public static void decryptionFile(final String key, final String filePath, final String fileName) throws IOException {
byte[] encryptedFileBytes = FileUtil.getFileBytesFrom(filePath);
FileUtil.saveFile(filePath, BouncyDecUtils.decrypt(key, encryptedFileBytes));
FileUtil.saveFile(filePath, fileName, BouncyDecUtils.decrypt(key, encryptedFileBytes));
}
/**

@ -47,6 +47,7 @@ import reactor.core.publisher.Mono;
* @see ClientError
* @see ServerError
* @see ErrorParse
* @see kr.xit.core.spring.config.support.CustomJacksonConfig
*/
@Slf4j
@Component

@ -1,8 +1,27 @@
package kr.xit.core.support.utils;
import static java.nio.file.Files.probeContentType;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import kr.xit.core.exception.BizRuntimeException;
import java.io.*;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
/**
* <pre>
@ -19,6 +38,8 @@ import java.io.*;
*
* </pre>
*/
@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class FileUtil {
public static byte[] getFileBytesFrom(String path) {
@ -36,12 +57,158 @@ public class FileUtil {
return fileBytes;
}
public static void saveFile(String path, byte[] fileData) {
public static void saveFile(String path, String fileName, byte[] fileData) {
Path p = Paths.get(path);
try(FileOutputStream fos = new FileOutputStream(path);){
if(!Files.isDirectory(p)){
try {
Files.createDirectory(p);
} catch (IOException e) {
throw BizRuntimeException.create(e.getMessage());
}
}
try(FileOutputStream fos = new FileOutputStream(path + "/" + fileName);){
fos.write(fileData);
} catch (IOException e) {
throw BizRuntimeException.create(e.getMessage());
}
}
/**
* + MultipartFile return
* @param fileNm
* @param filePath
* @return MultipartFile
*/
@SuppressWarnings("DuplicatedCode")
public static MultipartFile createMutipartFile(final String fileNm, final String filePath){
File file = new File(filePath+"/"+fileNm);
try {
FileItem fileItem = new DiskFileItem(fileNm, probeContentType(file.toPath()), false, file.getName(), (int) file.length(), file.getParentFile());
try(InputStream input = Files.newInputStream(file.toPath());
OutputStream os = fileItem.getOutputStream()) {
IOUtils.copy(input, os);
}catch(IOException e){
throw BizRuntimeException.create(e.getMessage());
}
return new CommonsMultipartFile(fileItem);
} catch (IOException ex) {
throw BizRuntimeException.create(ex.getMessage());
}
}
/**
* binary(byte) MultipartFile GET
* @param fileNm
* @param filePath - MultipartFile
* @param data byte
* @param isFileDelete
* @return MultipartFile MultipartFile
*/
@SuppressWarnings("DuplicatedCode")
public static MultipartFile createMutipartFileFromBytes(final String fileNm, final String filePath, final byte[] data, boolean isFileDelete){
File file = new File(filePath+"/"+fileNm);
try {
FileUtils.writeByteArrayToFile(file, data);
FileItem fileItem = new DiskFileItem(fileNm, probeContentType(file.toPath()), false, file.getName(), (int) file.length(), file.getParentFile());
try(InputStream input = Files.newInputStream(file.toPath());
OutputStream os = fileItem.getOutputStream()) {
IOUtils.copy(input, os);
}catch(IOException e){
throw BizRuntimeException.create(e.getMessage());
}
if(isFileDelete && file.exists()) {
//noinspection ResultOfMethodCallIgnored
file.delete();
}
return new CommonsMultipartFile(fileItem);
} catch (IOException ex) {
throw BizRuntimeException.create(ex.getMessage());
}
}
/**
* zip
* @param filePath source file path
* @param fileNameList source file name list
* @param zipFilePath zip file folder
* @param zipFileName zip file name
*/
public static String compressZip(final String filePath, final List<String> fileNameList, final String zipFilePath, final String zipFileName) {
List<File> fileList = new ArrayList<>();
fileNameList.forEach(s -> fileList.add(new File(filePath, s)));
return compressZip(fileList, zipFilePath, zipFileName);
}
/**
* Zip
* @param fileList zip file name list
* @param zipFilePath zip file folder
* @param zipFileName zip file name
*/
public static String compressZip(final List<File> fileList, final String zipFilePath, final String zipFileName) {
File zipFile = new File(zipFilePath, zipFileName);
byte[] buff = new byte[4096];
// 압축파일 생성
try(ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile))){
// 파일 압축
fileList.forEach(f -> {
try(FileInputStream fis = new FileInputStream(f)){
// 압축파일 지정
ZipEntry ze = new ZipEntry(f.getName());
zos.putNextEntry(ze);
// 압축 파일에 추가
int len;
while ((len = fis.read(buff)) > 0) zos.write(buff, 0, len);
zos.closeEntry();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
return zipFilePath + "/" + zipFileName;
} catch (FileNotFoundException e) {
log.error("zip파일 생성 오류::{}", e.getLocalizedMessage());
throw BizRuntimeException.create("zip 파일생성 오류[대상파일 미존재]");
} catch (IOException e) {
log.error("zip파일 생성 오류::{}", e.getLocalizedMessage());
throw BizRuntimeException.create("zip 파일생성 오류[대상파일 미존재]");
}
}
/**
* <pre>
* path (directory )
* @param path String
* </pre>
*/
public static void removeDirectyAndFiles(String path){
try {
// 작업 파일 삭제
Path dir = Paths.get(path);
Files.walk(dir) // Traverse the file tree in depth-first order
.sorted(Comparator.reverseOrder())
.forEach(f -> {
try {
Files.delete(f); //delete each file or directory
} catch (IOException e) {
log.error(e.getLocalizedMessage());
e.printStackTrace();
}
});
}catch (IOException ie){
log.error(ie.getLocalizedMessage());
ie.printStackTrace();
}
}
}

@ -1,15 +1,8 @@
package kr.xit.core.support.utils;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@ -18,9 +11,25 @@ import kr.xit.core.spring.util.SpringUtils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
/**
* JSON Util Class
* <pre>
* description : JSON Utility
*
* packageName : kr.xit.core.support.utils
* fileName : JsonUtils
* author : limju
* date : 2023-09-04
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-04 limju
*
* </pre>
* @see kr.xit.core.spring.config.support.CustomJacksonConfig
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class JsonUtils {
@ -75,8 +84,11 @@ public class JsonUtils {
* @return T
*/
public static <T> T toObjByObj(final Object obj, final Class<T> cls) {
final String str = toJson(obj);
return str != null ? toObject(str, cls) : null;
try {
return obj != null ? OM.convertValue(obj, cls) : null;
} catch (IllegalArgumentException e) {
throw BizRuntimeException.create(e.getLocalizedMessage());
}
}
/**
@ -111,6 +123,91 @@ public class JsonUtils {
}
}
/**
* Object key value
* -> key, value JSONObject return
* @param obj key, value Object
* @param keyName key JSON key name
* @param valueName value JSON key name
* @return JSONObject key, value JSONObject
*/
public static JSONObject extractObjKeyValue(final Object obj, final String keyName, final String valueName){
return extractJsonKeyValue(toObjByObj(obj, JSONObject.class), keyName, valueName);
}
/**
* JSONObject key value
* -> key, value JSONObject return
* @param json
* @param keyName key JSON key name
* @param valueName value JSON key name
* @return JSONObject key, value JSONObject
*/
public static JSONObject extractJsonKeyValue(final JSONObject json, final String keyName, final String valueName){
final JSONObject rtnJson = new JSONObject();
final JSONArray keys = new JSONArray();
final JSONArray values = new JSONArray();
for (Object key : json.keySet()) {
Object value = json.get(key);
if (value instanceof JSONObject)
extractJsonKeyValue((JSONObject)value, keyName, valueName);
else if (value instanceof JSONArray)
((JSONArray)value).forEach(obj -> extractJsonKeyValue((JSONObject)obj, keyName, valueName));
else{
//System.out.println(key + ", " + value);
keys.add(String.valueOf(key));
values.add(value);
}
}
rtnJson.put(keyName, keys);
rtnJson.put(valueName, values);
return rtnJson;
}
/**
* JSONArray key value
* -> key, value JSONObject return
* @param jsons JSONArray
* @param keyName key JSON key name
* @param valueName value JSON key name
* @return JSONObject key, value JSONObject
*/
public static JSONObject extractJsonArrayKeyValue(final net.sf.json.JSONArray jsons, final String keyName, final String valueName){
final JSONObject rtnJson = new JSONObject();
final JSONArray keys = new JSONArray();
final JSONArray values = new JSONArray();
for(int i = 0; i<jsons.size(); i++){
JSONObject json = extract(jsons.getJSONObject(i), keyName, valueName);
if(i == 0) rtnJson.put(keyName, json.get(keyName));
values.add(json.get(valueName));
}
rtnJson.put(valueName, values);
return rtnJson;
}
private static JSONObject extract(net.sf.json.JSONObject json, String keyName, String valueName) {
final JSONObject rtnJson = new JSONObject();
final JSONArray keys = new JSONArray();
final JSONArray values = new JSONArray();
for (Object key : json.keySet()) {
Object value = json.get(key);
if (value instanceof JSONObject)
extractJsonKeyValue((JSONObject)value, keyName, valueName);
else if (value instanceof JSONArray)
((JSONArray)value).forEach(obj -> extractJsonKeyValue((JSONObject)obj, keyName, valueName));
else{
//System.out.println(key + ", " + value);
keys.add(String.valueOf(key));
values.add(value);
}
}
rtnJson.put(keyName, keys);
rtnJson.put(valueName, values);
return rtnJson;
}
/**
* Json .
* @param obj Object json
@ -125,25 +222,6 @@ public class JsonUtils {
}
}
private static ObjectMapper getObjectMapper() {
final ObjectMapper om = new ObjectMapper();
om.setSerializationInclusion(Include.NON_NULL);
// No serializer found for class 에러 - private 필드
om.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, false);
om.coercionConfigDefaults()
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull);
// om.coercionConfigFor(LogicalType.Enum)
// .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull);
// om.coercionConfigFor(LogicalType.POJO)
// .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsNull);
return om;
}
/**
* Json .
* @param json String json

Loading…
Cancel
Save