|
|
@@ -1,11 +1,14 @@
|
|
|
package com.style24.admin.biz.web;
|
|
|
|
|
|
+import java.awt.Image;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.swing.ImageIcon;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -1107,6 +1110,7 @@ public class TsaGoodsController extends TsaBaseController {
|
|
|
|
|
|
// 오류 파일 목록
|
|
|
Collection<File> errorFileList = new ArrayList<File>();
|
|
|
+ Collection<File> errorFileDextList = new ArrayList<File>();
|
|
|
|
|
|
// 1.업로드된 파일 rename 및 순서 재정렬
|
|
|
for (GoodsImg goodsImg : goodsImgList) {
|
|
|
@@ -1125,6 +1129,8 @@ public class TsaGoodsController extends TsaBaseController {
|
|
|
goods.setGoodsCd(goodsImg.getGoodsCd());
|
|
|
Goods goodsInfo = goodsService.getGoods(goods);
|
|
|
if (goodsInfo == null || goodsInfo.getGoodsCd().isEmpty()) {
|
|
|
+ deleteErrorFileList(errorFileList);
|
|
|
+ deleteErrorFileList(errorFileDextList);
|
|
|
throw new IllegalStateException(message.getMessage("FAIL_1001"));
|
|
|
}
|
|
|
|
|
|
@@ -1154,10 +1160,10 @@ public class TsaGoodsController extends TsaBaseController {
|
|
|
File newFile = new File(GagaFileUtil.getConcatenationPath(goodsUploadPath, uniqueFile.getName()));
|
|
|
//log.info("newFile.getPath(): {}", newFile.getPath());
|
|
|
|
|
|
- // resizing 처리 시 오류가 발생할 경우 삭제하기 위해 설정
|
|
|
errorFileList.add(newFile);
|
|
|
|
|
|
File oldFile = new File(GagaFileUtil.getConcatenationPath(dextUploadPath, goodsImg.getSysImgNm()));
|
|
|
+ errorFileDextList.add(oldFile);
|
|
|
//log.info("oldFile.getPath(): {}", oldFile.getPath());
|
|
|
|
|
|
File path = new File(goodsUploadPath);
|
|
|
@@ -1166,12 +1172,29 @@ public class TsaGoodsController extends TsaBaseController {
|
|
|
path.mkdir();
|
|
|
}
|
|
|
|
|
|
+ Image srcImg = getImageObject(oldFile);
|
|
|
+ int width = srcImg.getWidth(null);
|
|
|
+ int height = srcImg.getHeight(null);
|
|
|
+
|
|
|
+ if (newFile.getName().contains("_X1")) {
|
|
|
+// if (width != height) {
|
|
|
+ if (width != 1000 || height != 1000) {
|
|
|
+ deleteErrorFileList(errorFileList);
|
|
|
+ deleteErrorFileList(errorFileDextList);
|
|
|
+ throw new IllegalStateException("외부몰용 상품이미지가 정사각형(1000x1000)이 아닙니다.");
|
|
|
+ }
|
|
|
+ // 외부몰연동용 이미지로 설정
|
|
|
+ goodsImg.setExtmallImgYn("Y");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
boolean copyFlag = GagaFileUtil.copyFile(oldFile, newFile);
|
|
|
if (copyFlag) {
|
|
|
//기존이미지 삭제
|
|
|
GagaFileUtil.deleteFile(oldFile.getPath());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
goodsImg.setDispOrd(index++);
|
|
|
goodsImg.setOrgImgNm(GagaFileUtil.getConcatenationPath(brandYmdDir, newFile.getName()));
|
|
|
goodsImg.setSysImgNm(GagaFileUtil.getConcatenationPath(brandYmdDir, newFile.getName()));
|
|
|
@@ -1204,6 +1227,45 @@ public class TsaGoodsController extends TsaBaseController {
|
|
|
return super.ok(message.getMessage("SUCC_0007"));
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ * 이미지 파일 확인
|
|
|
+ */
|
|
|
+ public static Image getImageObject(File f) throws IOException {
|
|
|
+ Image objImg = null;
|
|
|
+ String suffix = f.getName().substring(f.getName().lastIndexOf('.') + 1).toLowerCase();
|
|
|
+// if (suffix.equals("bmp") || suffix.equals("png") || suffix.equals("gif") || suffix.equals("jpg")) {
|
|
|
+ if (suffix.equals("png") || suffix.equals("gif") || suffix.equals("jpg")) {
|
|
|
+ objImg = ImageIO.read(f);
|
|
|
+ } else {
|
|
|
+ // ImageIcon을 활용해서 Image 생성
|
|
|
+ // 이렇게 하는 이유는 getScaledInstance를 통해 구한 이미지를
|
|
|
+ // PixelGrabber.grabPixels로 리사이즈 할 때 빠르게 처리하기 위함이다.
|
|
|
+ objImg = new ImageIcon(f.toURI().toURL()).getImage();
|
|
|
+ }
|
|
|
+
|
|
|
+ return objImg;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 파일 삭제
|
|
|
+ *
|
|
|
+ * @param errorFileList
|
|
|
+ * @author eskim
|
|
|
+ * @since 2021. 5. 16
|
|
|
+ */
|
|
|
+ private void deleteErrorFileList(Collection<File> errorFileList) {
|
|
|
+ // 파일 삭제
|
|
|
+ if (errorFileList != null && !errorFileList.isEmpty()) {
|
|
|
+ for (File errorFile : errorFileList) {
|
|
|
+ try {
|
|
|
+ GagaFileUtil.deleteFile(errorFile.getPath());
|
|
|
+ } catch (IOException e) {
|
|
|
+ // Nothing Do
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 세트상품구성 화면
|
|
|
*
|