1. 파일압축 라이브러리 추가

2. 모자이크 위치, 크기 정보로 마스킹처리된 이미지 파일 생성하는 메소드 추가
3. 외주파일생성 메소드 수정
main
이범준 11 months ago
parent ebd6a40122
commit 5706cb72a9

@ -89,6 +89,14 @@
<version>0.5</version> <version>0.5</version>
</dependency> </dependency>
<!-- 파일압축 라이브러리 -->
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>2.11.5</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -1,5 +1,7 @@
package cokr.xit.fims.cmmn; package cokr.xit.fims.cmmn;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@ -21,7 +23,12 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.imageio.ImageIO;
import org.apache.commons.io.FilenameUtils;
import cokr.xit.fims.sndb.service.bean.SndngBean; import cokr.xit.fims.sndb.service.bean.SndngBean;
import cokr.xit.foundation.data.DataObject;
public class CmmnUtil { public class CmmnUtil {
@ -59,6 +66,63 @@ public class CmmnUtil {
return Pattern.matches(REGEXP_PATTERN_KOR, str); return Pattern.matches(REGEXP_PATTERN_KOR, str);
} }
/**
* .
* @param index , startFromZero 0( 1 )
* @return (A~Z)
*/
public static String indexToAlphabet(int index, boolean startFromZero) {
int charCode = 64;
charCode += index;
if(startFromZero) {
charCode++;
}
if(charCode < 65 || charCode > 90) {
return "";
}
return ""+(char)charCode;
}
/**
* .
* @param orgnFileName , append
* @return
*/
public static String appendFileName(String orgnFileName, String append) {
return FilenameUtils.removeExtension(orgnFileName) + append + "." + FilenameUtils.getExtension(orgnFileName);
}
/**
* .
* @param source , target , mosaicInfos
* @return
*/
public static void createMaskedImage(File source, File target, List<DataObject> mosaicInfos) {
BufferedImage buffer_black_image = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
String extension = FilenameUtils.getExtension(target.getName());
try {
BufferedImage buffer_original_image = ImageIO.read(source);
Graphics2D graphic = buffer_original_image.createGraphics();
for(DataObject mosaicInfo : mosaicInfos){
int mosaicX = mosaicInfo.number("X_AXS").intValue();
int mosaicY = mosaicInfo.number("Y_AXS").intValue();
int mosaicWidth = mosaicInfo.number("MOSC_LT").intValue();
int mosaicHeight = mosaicInfo.number("MOSC_HG").intValue();
graphic.drawImage(buffer_black_image, mosaicX, mosaicY, mosaicWidth, mosaicHeight, null);
}
ImageIO.write(buffer_original_image, extension, target);
} catch (IOException e) {
throw new RuntimeException("이미지 모자이크 처리 중 오류가 발생하였습니다.");
}
}
/** /**
* . * .
@ -358,4 +422,5 @@ public class CmmnUtil {
return band6; return band6;
} }
} }

@ -1,8 +1,16 @@
package cokr.xit.fims.sprt.service.bean; package cokr.xit.fims.sprt.service.bean;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -22,6 +30,8 @@ import org.springframework.stereotype.Service;
import cokr.xit.base.file.service.FileQuery; import cokr.xit.base.file.service.FileQuery;
import cokr.xit.base.file.service.bean.FileBean; import cokr.xit.base.file.service.bean.FileBean;
import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.Hangul;
import cokr.xit.fims.cmmn.hwp.AddUtil; import cokr.xit.fims.cmmn.hwp.AddUtil;
import cokr.xit.fims.cmmn.hwp.HWPFormatWriter; import cokr.xit.fims.cmmn.hwp.HWPFormatWriter;
import cokr.xit.fims.cmmn.hwp.HWPPrintUtil; import cokr.xit.fims.cmmn.hwp.HWPPrintUtil;
@ -37,6 +47,7 @@ import cokr.xit.fims.cmmn.pdf.PstnAndSize;
import cokr.xit.fims.cmmn.pdf.format.Advntce; import cokr.xit.fims.cmmn.pdf.format.Advntce;
import cokr.xit.fims.cmmn.pdf.format.Nht; import cokr.xit.fims.cmmn.pdf.format.Nht;
import cokr.xit.fims.cmmn.service.bean.FactionBean; import cokr.xit.fims.cmmn.service.bean.FactionBean;
import cokr.xit.fims.cmmn.service.bean.MosaicBean;
import cokr.xit.fims.cmmn.service.bean.StngBean; import cokr.xit.fims.cmmn.service.bean.StngBean;
import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.Crdn;
import cokr.xit.fims.crdn.CrdnQuery; import cokr.xit.fims.crdn.CrdnQuery;
@ -53,6 +64,7 @@ import cokr.xit.foundation.data.DataObject;
import kr.dogfoot.hwplib.object.HWPFile; import kr.dogfoot.hwplib.object.HWPFile;
import kr.dogfoot.hwplib.reader.HWPReader; import kr.dogfoot.hwplib.reader.HWPReader;
import kr.dogfoot.hwplib.writer.HWPWriter; import kr.dogfoot.hwplib.writer.HWPWriter;
import net.lingala.zip4j.ZipFile;
/** . /** .
* *
@ -89,6 +101,9 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv
@Resource(name = "otptStngMapper") @Resource(name = "otptStngMapper")
protected OtptStngMapper otptStngMapper; protected OtptStngMapper otptStngMapper;
@Resource(name="mosaicBean")
private MosaicBean mosaicBean;
@Override @Override
public List<DataObject> getIntegrationDataList(SprtQuery query) { public List<DataObject> getIntegrationDataList(SprtQuery query) {
return sprt01Bean.getIntegrationDataList(query); return sprt01Bean.getIntegrationDataList(query);
@ -511,9 +526,115 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv
@Override @Override
public Map<String, String> makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds) { public Map<String, String> makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds) {
return null; Map<String,String> result = new HashMap<>();
Hangul hangul = new Hangul(2);
SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String currentTime = ymdhmsFormat.format(new Date());
String year = currentTime.substring(0, 4);
String month = currentTime.substring(4, 6);
String day = currentTime.substring(6, 8);
String yyyymmdd = year+month+day;
String outsourcingResultPath = "files"+File.separator+"result"+File.separator+"outsourcing"
+ File.separator + year + File.separator + month + File.separator + day
+ File.separator + currentTime;
File folder = new File(outsourcingResultPath);
if(!folder.exists()) {
folder.mkdirs();
}
String printKorName = "사전통지";
try {
SprtQuery sprtQuery = new SprtQuery();
sprtQuery.setCrdnIDs(crdnIds);
List<DataObject> dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
String imagesFolderName = yyyymmdd + printKorName;
String metaFileName = yyyymmdd + printKorName + "(외주파일).txt";
String imagesFolderPath = outsourcingResultPath + File.separator + imagesFolderName;
String metaFilePath = outsourcingResultPath + File.separator + metaFileName;
for(int i=0; i < dataObjectList.size(); i++) {
DataObject dataObject = dataObjectList.get(i);
FileQuery fileQuery = new FileQuery();
fileQuery.setInfoType(Crdn.INF_TYPE);
fileQuery.setInfoKeys(dataObject.string("CRDN_ID"));
List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);
if(fileInfoList == null) {
fileInfoList = new ArrayList<DataObject>();
}
for(int j=0; j < fileInfoList.size(); j++){
DataObject fileInfo = fileInfoList.get(j);
List<DataObject> mosaicInfos = mosaicBean.getMosaicList(fileInfo.string("FILE_ID"));
File orgnFile = new File(fileInfo.string("FILE_PATH"));
String modifiedFileName = "P"+fileInfo.string("INF_KEY")+CmmnUtil.indexToAlphabet(j, true)+"."+"JPG";
String modifiedFilePath = imagesFolderPath + File.separator + modifiedFileName;
File modifiedFile = new File(modifiedFilePath);
if(mosaicInfos != null) {
CmmnUtil.createMaskedImage(orgnFile, modifiedFile, mosaicInfos);
} else {
Files.copy(orgnFile.toPath(), modifiedFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
dataObject.set("CRDN_PHOTO"+(j+1), modifiedFilePath);
} }
}
File file = new File(metaFilePath);
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file);
BufferedWriter writer = new BufferedWriter(fw);
//외주파일 설정
List<DataObject> printItems = new ArrayList<DataObject>();
for(int i=0; i < dataObjectList.size(); i++) {
DataObject dataObject = dataObjectList.get(i);
if(i != 0) {
writer.write("\n");
}
String line = "";
for(DataObject printItem : printItems){
String colNm = printItem.string("COL_NM");
int byteCnt = printItem.number("BYTE_CNT").intValue();
line += hangul.rpadByte(dataObject.string(colNm), byteCnt, " ");
}
writer.write(line);
}
writer.close();
String zipFileName = yyyymmdd + printKorName + ".zip";
String zipFilePath = outsourcingResultPath + File.separator + zipFileName;
ZipFile zipFile = new ZipFile(zipFilePath);
zipFile.addFile(new File(metaFilePath));
zipFile.addFolder(new File(imagesFolderPath));
zipFile.close();
result.put("filePath", zipFilePath);
result.put("fileName", zipFileName);
} catch (IOException e) {
throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다.");
}
return result;
}
} }

Loading…
Cancel
Save