package com.style24.admin.biz.service;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.style24.admin.biz.dao.TsaGoodsDao;
import com.style24.admin.support.env.TsaConstants;
import com.style24.admin.support.security.session.TsaSession;
import com.style24.core.biz.service.TscCommonService;
import com.style24.core.biz.thirdparty.NaverLowestPriceApi;
import com.style24.core.biz.thirdparty.SafetyKoreaApi;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.domain.AdKeyword;
import com.style24.persistence.domain.AdKeywordGoods;
import com.style24.persistence.domain.Brand;
import com.style24.persistence.domain.Color;
import com.style24.persistence.domain.CommonCode;
import com.style24.persistence.domain.DelvFeePolicy;
import com.style24.persistence.domain.FreeGoods;
import com.style24.persistence.domain.Goods;
import com.style24.persistence.domain.GoodsCategory;
import com.style24.persistence.domain.GoodsCompose;
import com.style24.persistence.domain.GoodsContents;
import com.style24.persistence.domain.GoodsContentsData;
import com.style24.persistence.domain.GoodsDesc;
import com.style24.persistence.domain.GoodsEpSkip;
import com.style24.persistence.domain.GoodsHst;
import com.style24.persistence.domain.GoodsImg;
import com.style24.persistence.domain.GoodsMass;
import com.style24.persistence.domain.GoodsNaverLowestPrice;
import com.style24.persistence.domain.GoodsNotiInfo;
import com.style24.persistence.domain.GoodsPriceRes;
import com.style24.persistence.domain.GoodsResSell;
import com.style24.persistence.domain.GoodsSafeNo;
import com.style24.persistence.domain.GoodsSearch;
import com.style24.persistence.domain.GoodsSupplyPrice;
import com.style24.persistence.domain.GoodsTnmRes;
import com.style24.persistence.domain.GoodsVideo;
import com.style24.persistence.domain.IfIncomelot;
import com.style24.persistence.domain.IfProductSku;
import com.style24.persistence.domain.Itemkind;
import com.style24.persistence.domain.NaverLowestPrice;
import com.style24.persistence.domain.NotiInfo;
import com.style24.persistence.domain.Notice;
import com.style24.persistence.domain.NoticeGoods;
import com.style24.persistence.domain.Option;
import com.style24.persistence.domain.ReinboundInform;
import com.style24.persistence.domain.SearchData;
import com.style24.persistence.domain.SizeInfo;
import com.style24.persistence.domain.SupplyCompany;
import com.style24.persistence.domain.WmsColorMapping;
import com.style24.persistence.domain.WmsGoods;
import com.style24.persistence.domain.WmsSeasonMapping;
import com.style24.persistence.domain.WmsStyleYearMapping;

import io.netty.util.internal.StringUtil;

import lombok.extern.slf4j.Slf4j;

import com.gagaframework.excel.GagaExcelUtil;
import com.gagaframework.excel.env.GagaExcelConstants;
import com.gagaframework.web.parameter.GagaMap;
import com.gagaframework.web.util.GagaDateUtil;
import com.gagaframework.web.util.GagaFileUtil;
import com.gagaframework.web.util.GagaStringUtil;

/**
 *상품관리 Service
 *
 * @author eskim
 * @since 2020. 10. 16
 */
@Service
@Slf4j
public class TsaGoodsService {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private Environment env;

	@Autowired
	private TsaGoodsDao goodsDao;

	@Autowired
	private TsaBusinessService businessService;

	@Autowired
	private TsaCommonService commonService;

	@Autowired
	private TscCommonService tscCommonService;

	@Autowired
	private TsaNoticeService noticeService;

	@Autowired
	private TsaDisplayService displayService;

	@Autowired
	private TsaRendererService rendererService;

	@Autowired
	private SafetyKoreaApi safetyKoreaApi;

	@Autowired
	private NaverLowestPriceApi naverLowestPriceApi;

	@Autowired
	private TsaWmsGoodsService wmsGoodsService;

	@Autowired
	private ObjectMapper mapper;

	private static final String NUMBER_PATTERN = "^[0-9]+$";

	private static final String UPDATE_NO_PATTERN = "X";

	private static final String SELF_GOOODS_AFTER = "STY";

	private static final int EXCEL_ROW_COUNT = 500;

	/**
	 * 상품 할인율 계산
	 *
	 * @param value
	 * @param len
	 * @param pad
	 * @return
	 */
	private long getDcRate(int listPrice, int currPrice) {
		double rate = (double)(currPrice) / (double)(listPrice);
		return 100 - (long)((Math.round(rate * 100) / 100.0) * 100);
	}

	/**
	 * 품목 목록
	 * @param itemkind
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	public Collection<Itemkind> getItemkindList(Itemkind itemkind) {
		return goodsDao.getItemkindList(itemkind);
	}

	/**
	 * 품목 저장
	 *
	 * @param itemkindList - 품목 정보 목록
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@Transactional("shopTxnManager")
	public void saveItemkindInfo(Collection<Itemkind> itemkindList) {
		for (Itemkind itemkind : itemkindList) {
			itemkind.setRegNo(TsaSession.getInfo().getUserNo());
			itemkind.setUpdNo(TsaSession.getInfo().getUserNo());
//			itemkind.setItemkindNm(GagaStringUtil.replace(GagaStringUtil.replace(itemkind.getItemkindNm(), "&lt;", "<"), "&gt;", ">"));
			//itemkind.setItemkindEnm(GagaStringUtil.replace(GagaStringUtil.replace(itemkind.getItemkindEnm(), "&lt;", "<"),"&gt;", ">"));
			goodsDao.saveItemkindInfo(itemkind);
		}
	}

	/**
	 * 품목 삭제
	 *
	 * @param itemkindList - 품목 정보 목록
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@Transactional("shopTxnManager")
	public void deleteItemkindInfo(Collection<Itemkind> itemkindList) {
		for (Itemkind itemkind : itemkindList) {
			goodsDao.deleteItemkindInfo(itemkind);
		}
	}

	/**
	 * 색상목록 조회
	 *
	 * @param color
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	public Collection<Color> getColorList(Color color) {
		return goodsDao.getColorList(color);
	}

	/**
	 * 색상 저장
	 *
	 * @param colorList
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@Transactional("shopTxnManager")
	public void saveColor(Collection<Color> colorList) {

		for (Color color : colorList) {

			color.setRegNo(TsaSession.getInfo().getUserNo());
			color.setUpdNo(TsaSession.getInfo().getUserNo());

			goodsDao.saveColor(color);
		}
	}

	/**
	 * 상품정보고시 목록
	 *
	 * @param notiInfo
	 * @return
	 * @author eskim
	 * @since 2010. 10. 19
	 */
	public Collection<NotiInfo> getNotiInfoList(NotiInfo notiInfo) {
		return goodsDao.getNotiInfoList(notiInfo);
	}

	/**
	 * 상품정보고시 항목 목록
	 *
	 * @param notiInfo
	 * @return
	 * @author eskim
	 * @since 2010. 10. 19
	 */
	public Collection<NotiInfo> getNotiInfoItemList(NotiInfo notiInfo) {
		return goodsDao.getNotiInfoItemList(notiInfo);
	}

	/**
	 * 상품정보고시 항목 저장
	 *
	 * @param notiInfoList
	 * @return
	 * @author eskim
	 * @since 2010. 10. 19
	 */
	@Transactional("shopTxnManager")
	public void saveNotiInfoItem(Collection<NotiInfo> notiInfoList) {
		if (notiInfoList == null || notiInfoList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		for (NotiInfo notiInfo : notiInfoList) {
			if (!StringUtils.isBlank(notiInfo.getNiContent())) {
//				notiInfo.setNiContent(GagaStringUtil.replace(GagaStringUtil.replace(notiInfo.getNiContent(), "&lt;", "<"), "&gt;", ">"));
			}
			notiInfo.setRegNo(TsaSession.getInfo().getUserNo());
			notiInfo.setUpdNo(TsaSession.getInfo().getUserNo());
			goodsDao.saveNotiInfo(notiInfo);
		}
	}

	/**
	 * WMS 색상 매핑목록 조회
	 *
	 * @param color
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	public Collection<WmsColorMapping> getWmsColorMappingList(WmsColorMapping wmsColorMapping) {
		return goodsDao.getWmsColorMappingList(wmsColorMapping);
	}

	/**
	 * WMS 색상 매핑 저장
	 *
	 * @param colorList
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@Transactional("shopTxnManager")
	public void saveWmsColorMapping(Collection<WmsColorMapping> wmsColorMappingList) {

		for (WmsColorMapping wmsColorMapping : wmsColorMappingList) {

			wmsColorMapping.setRegNo(TsaSession.getInfo().getUserNo());
			wmsColorMapping.setUpdNo(TsaSession.getInfo().getUserNo());

			goodsDao.saveWmsColorMapping(wmsColorMapping);
		}
	}

	/**
	 * WMS 스타일년도 매핑목록 조회
	 *
	 * @param wmsStyleYearMapping
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	public Collection<WmsStyleYearMapping> getWmsStyleYearMappingList(WmsStyleYearMapping wmsStyleYearMapping) {
		return goodsDao.getWmsStyleYearMappingList(wmsStyleYearMapping);
	}

	/**
	 * WMS 스타일년도 매핑 저장
	 *
	 * @param wmsStyleYearMappingList
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@Transactional("shopTxnManager")
	public void saveWmsStyleYearMapping(Collection<WmsStyleYearMapping> wmsStyleYearMappingList) {

		for (WmsStyleYearMapping wmsStyleYearMapping : wmsStyleYearMappingList) {

			wmsStyleYearMapping.setRegNo(TsaSession.getInfo().getUserNo());
			wmsStyleYearMapping.setUpdNo(TsaSession.getInfo().getUserNo());

			goodsDao.saveWmsStyleYearMapping(wmsStyleYearMapping);
		}
	}

	/**
	 * WMS 시즌 매핑목록 조회
	 *
	 * @param wmsSeasonMapping
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	public Collection<WmsSeasonMapping> getWmsSeasonMappingList(WmsSeasonMapping wmsSeasonMapping) {
		return goodsDao.getWmsSeasonMappingList(wmsSeasonMapping);
	}

	/**
	 * WMS 시즌 매핑 저장
	 *
	 * @param wmsSeasonMappingList
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@Transactional("shopTxnManager")
	public void saveWmsSeasonMapping(Collection<WmsSeasonMapping> wmsSeasonMappingList) {

		for (WmsSeasonMapping wmsSeasonMapping : wmsSeasonMappingList) {

			wmsSeasonMapping.setRegNo(TsaSession.getInfo().getUserNo());
			wmsSeasonMapping.setUpdNo(TsaSession.getInfo().getUserNo());

			goodsDao.saveWmsSeasonMapping(wmsSeasonMapping);
		}
	}

	/**
	 * 상품 목록 건수
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 10. 20
	 */
	public int getGoodsListCount(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsListCount(goodsSearch);
	}

	/**
	 * 상품 목록
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 10. 20
	 */
	public Collection<Goods> getGoodsList(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsList(goodsSearch);
	}

	/**
	 * 상품목록 - 기본정보 엑셀다운로드
	 *
	 * @param goodsSearch
	 * @param excelFilenameWithPath - 경로를 포함한 엑셀파일명
	 * @return
	 * @author eskim
	 * @since 2020. 10. 21
	 */
	public void getGoodsInfoExcelList(GoodsSearch goodsSearch, String excelFilenameWithPath) {

		if ("Y".equals(goodsSearch.getImageViewYn())) {
			// 헤더 title 설정
			String[] listTitles = {"이미지", "상품코드", "업체명", "브랜드명", "상품명", "품목", "전시재고", "상품상태", "스타일년도", "시즌",
				"정상가", "판매가", "자사즉시할인가", "가격변경일", "ERP재고연동여부", "정상이월구분", "반품가능 여부"};

			// DB 처리 시 사용되는 파라미터명(셀명) 설정
			String[] cellNames = {"SYS_IMG_NM", "GOODS_CD", "SUPPLY_COMP_CD", "BRAND_ENM", "GOODS_NM", "ITEMKIND_NM",
				"STOCK_QTY_SUM", "GOODS_STAT", "STYLE_YEAR", "SEASON_CD", "LIST_PRICE", "CURR_PRICE",
				"BENEFIT_PRICE", "PRICE_UPD_DT", "ERP_STOCK_LINK_YN", "FORMAL_GB", "RETURNABLE_YN"};

			String[] cellTypes = {GagaExcelConstants.CellType.IMAGE.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_RIGHT.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_RIGHT.name(),
				GagaExcelConstants.CellType.CHAR_RIGHT.name(), GagaExcelConstants.CellType.CHAR_RIGHT.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name()};

			String targetPath = env.getProperty("upload.goods.view");
			Collection<GagaMap> dataList = goodsDao.getGoodsInfoExcelList(goodsSearch); // map형식으로 조회
			if (dataList != null && !dataList.isEmpty()) {
				for (GagaMap gagaMap : dataList) {
					if (!StringUtils.isBlank(gagaMap.get("SYS_IMG_NM").toString())) {
						gagaMap.set("SYS_IMG_NM", targetPath + '/' + gagaMap.get("SYS_IMG_NM").toString() + "?RS=60");
					}
				}
			}

			try {
				GagaExcelUtil.createExcel(excelFilenameWithPath, dataList, "상품 정보", listTitles, cellNames, cellTypes, TsaConstants.EXCEL_FOOTER_TITLE);
			} catch (Exception e) {
				throw new IllegalStateException(e);
			}

		} else {
			// 헤더 title 설정
			String[] listTitles = {"상품코드", "업체명", "브랜드명", "상품명", "품목", "전시재고", "상품상태", "스타일년도", "시즌",
				"정상가", "판매가", "자사즉시할인가", "가격변경일", "ERP재고연동여부", "정상이월구분", "반품가능 여부"};

			// DB 처리 시 사용되는 파라미터명(셀명) 설정
			String[] cellNames = {"GOODS_CD", "SUPPLY_COMP_CD", "BRAND_ENM", "GOODS_NM", "ITEMKIND_NM", "STOCK_QTY_SUM", "GOODS_STAT", "STYLE_YEAR",
				"SEASON_CD", "LIST_PRICE", "CURR_PRICE", "BENEFIT_PRICE", "PRICE_UPD_DT", "ERP_STOCK_LINK_YN", "FORMAL_GB", "RETURNABLE_YN"};

			String[] cellTypes = {
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_RIGHT.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_RIGHT.name(),
				GagaExcelConstants.CellType.CHAR_RIGHT.name(), GagaExcelConstants.CellType.CHAR_RIGHT.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name(),
				GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name()};

			Collection<GagaMap> dataList = goodsDao.getGoodsInfoExcelList(goodsSearch);

			try {
				GagaExcelUtil.createExcel(excelFilenameWithPath, dataList, "상품 정보", listTitles, cellNames, cellTypes, TsaConstants.EXCEL_FOOTER_TITLE);
			} catch (Exception e) {
				throw new IllegalStateException(e);
			}
		}
	}

	/**
	 * 상품 이미지 등록여부 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 21
	 */
	public Collection<Goods> getGoodsImgsYn(Goods goods) {
		return goodsDao.getGoodsImgsYn(goods);
	}

	/**
	 * 상품 상세
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 22
	 */
	public Goods getGoods(Goods goods) {
		// 상품기본정보
		Goods resultGoods = goodsDao.getGoods(goods);

		// 상품 상세
		this.getGoodsDesc(resultGoods);
		return resultGoods;
	}

	/**
	 * 상품 상세 조회
	 *
	 * @param resultGoods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 22
	 */
	private Goods getGoodsDesc(Goods resultGoods) {

		GoodsDesc goods = new GoodsDesc();
		goods.setGoodsCd(resultGoods.getGoodsCd());

		// 상품 상세 타이틀
		goods.setDescGb("10");
		String goodsTitlesDesc = this.getGoodsDescList(goods);
		resultGoods.setGoodsTitlesDesc(goodsTitlesDesc);

		// 상품 상세 내용
		goods.setDescGb("20");
		String goodsContentsDesc = this.getGoodsDescList(goods);
		resultGoods.setGoodsContentsDesc(goodsContentsDesc);

		// 상품 상세 특징
		goods.setDescGb("30");
		String goodsCharacterDesc = this.getGoodsDescList(goods);
		resultGoods.setGoodsCharacterDesc(goodsCharacterDesc);

		// 상품 상세 pc 상단
		goods.setDescGb("40");
		String goodsPcTopDesc = this.getGoodsDescList(goods);
		resultGoods.setGoodsPcTopDesc(goodsPcTopDesc);

		// 상품 상세  pc 하단
		goods.setDescGb("50");
		String goodsPcDownDesc = this.getGoodsDescList(goods);
		resultGoods.setGoodsPcDownDesc(goodsPcDownDesc);

		// 상품 상세 mobile 상단
		goods.setDescGb("60");
		String goodsMobileTopDesc = this.getGoodsDescList(goods);
		resultGoods.setGoodsMobileTopDesc(goodsMobileTopDesc);

		// 상품 상세 mobile 하단
		goods.setDescGb("70");
		String goodsMobileDownDesc = this.getGoodsDescList(goods);
		resultGoods.setGoodsMobileDownDesc(goodsMobileDownDesc);

		// 상품 상세 (as-is)
		goods.setDescGb("80");
		String goodsDesc = this.getGoodsDescList(goods);
		resultGoods.setGoodsDesc(goodsDesc);

		return resultGoods;
	}

	/**
	 * 상품 상세구분별 컨텐츠 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 22
	 */
	private String getGoodsDescList(GoodsDesc goodsDesc) {
		Collection<GoodsDesc> goodsDescList = goodsDao.getGoodsDescList(goodsDesc);
		StringBuilder goodsDescSb = new StringBuilder();
		if (goodsDescList != null && !goodsDescList.isEmpty()) {
			for (GoodsDesc tmpGoodsDesc : goodsDescList) {
				goodsDescSb.append(tmpGoodsDesc.getGoodsDesc());
			}
		} else {
			goodsDescSb.append("");
		}
		return goodsDescSb.toString();
	}

	/**
	 * 상품 정보 이력 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2019. 12. 12
	 */
	public Collection<GoodsHst> getGoodsHstList(Goods goods) {
		return goodsDao.getGoodsHstList(goods);
	}

	/**
	 * 상품 옵션 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 26
	 */
	public Collection<Option> getGoodsSizeList(Goods goods) {
		return goodsDao.getGoodsSizeList(goods);
	}

	/**
	 * 상품 색상목록 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 11. 18
	 */
	public Collection<GoodsImg> getGoodsColorList(Goods goods) {
		return goodsDao.getGoodsColorList(goods);
	}

	/**
	 * 상품 정보고시 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 22
	 */
	public Collection<GoodsNotiInfo> getGoodsNotiInfoList(GoodsNotiInfo goodsNotiInfo) {
		return goodsDao.getGoodsNotiInfoList(goodsNotiInfo);
	}

	/**
	 * 상품의 정보고시 항목 목록
	 *
	 * @param notiInfo
	 * @return
	 * @author eskim
	 * @since 2020. 11. 18
	 */
	public Collection<NotiInfo> getNotiGoodsInfoList(NotiInfo notiInfo) {
		return goodsDao.getNotiGoodsInfoList(notiInfo);
	}

	/**
	 * 상품 구매등급 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 11. 18
	 */
	public Collection<Goods> getGoodsDetailOrderGradeList(Goods goods) {
		return goodsDao.getGoodsDetailOrderGradeList(goods);
	}

	/**
	 * 상품 안전인증 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2021. 05. 10
	 */
	public GoodsSafeNo getGoodsDetailSafe(Goods goods) {
		return goodsDao.getGoodsDetailSafe(goods);
	}

	/**
	 * 구성상품 목록
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 27
	 */
	public Collection<GoodsCompose> getGoodsDetailComposeList(Goods goods) {
		return goodsDao.getGoodsDetailComposeList(goods);
	}

	/**
	 * 안전인증번호
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 12. 07
	 */
	public GagaMap getGoodsDetailCertNum(String goodsCd) {
		GagaMap result = new GagaMap();
		return result;
	}

	/**
	 * 안전인증번호 저장
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 12. 07
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsDetailCertNum(GoodsSafeNo goodsSafeNo) {
		try {
			//인증대상
			if ("G083_1".equals(goodsSafeNo.getCertTargetGb())) {

				//인증형태 (방송통신, 위해) or 인증타입 - 공급자적합성
				if ("G084_4".equals(goodsSafeNo.getCertFormGb()) || "G084_5".equals(goodsSafeNo.getCertFormGb()) || "G081_3".equals(goodsSafeNo.getCertType())) {
					goodsSafeNo.setCertDt("");
//					goodsSafeNo.setCertNum("");
					goodsSafeNo.setCertState("");
					goodsSafeNo.setCertDiv("");
					goodsSafeNo.setCertOrganName("");
					goodsSafeNo.setRegNo(TsaSession.getInfo().getUserNo());
					goodsSafeNo.setUpdNo(TsaSession.getInfo().getUserNo());
					goodsDao.saveGoodsSafeNo(goodsSafeNo);
				} else {
					GagaMap result = safetyKoreaApi.getKoreaCertifyDetail(goodsSafeNo.getCertNum());
					if (result != null || !StringUtil.isNullOrEmpty(result.get("certNum").toString())) {
						goodsSafeNo.setCertDt(result.get("certDt").toString());
						goodsSafeNo.setCertState(result.get("certState").toString());
						goodsSafeNo.setCertDiv(result.get("certDiv").toString());
						goodsSafeNo.setCertOrganName(result.get("certOrganName").toString());
						goodsSafeNo.setRegNo(TsaSession.getInfo().getUserNo());
						goodsSafeNo.setUpdNo(TsaSession.getInfo().getUserNo());
						goodsDao.saveGoodsSafeNo(goodsSafeNo);
					} else {
						throw new IllegalStateException(message.getMessage("FAIL_1001"));
					}
				}
			} else {	//인증대상 그외 - 인증처리 안해도 됨
				goodsSafeNo.setCertDt("");
//				goodsSafeNo.setCertNum("");
				goodsSafeNo.setCertState("");
				goodsSafeNo.setCertDiv("");
				goodsSafeNo.setCertOrganName("");
				goodsSafeNo.setRegNo(TsaSession.getInfo().getUserNo());
				goodsSafeNo.setUpdNo(TsaSession.getInfo().getUserNo());
				goodsDao.saveGoodsSafeNo(goodsSafeNo);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 상품 수정 항목 일괄변경
	 *
	 * @param goods
	 * @author eskim
	 * @since 2020. 01. 17
	 */
	@Transactional("shopTxnManager")
	public void updateGoodsState(Goods goods) {
		if (goods == null || (goods.getArrGoodsCd() == null && goods.getArrGoodsCd().length <= 0)) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		goods.setRegNo(TsaSession.getInfo().getUserNo());
		goods.setUpdNo(TsaSession.getInfo().getUserNo());

		if (goods.getArrGoodsCd().length > 0) {
			for (String goodsCd : goods.getArrGoodsCd()) {

				goods.setGoodsCd(goodsCd);
				// 이력생성
				goodsDao.createGoodsHst(goods);

				if ("formalGb".equals(goods.getProcJob())) {
					// 상품브랜드 조회
					Goods originGoods = goodsDao.getGoods(goods);
					// 브랜드 확인
					goods.setPntPrate(originGoods.getPntPrate()); // 포인트적립율(PC)
					goods.setPntMrate(originGoods.getPntMrate()); // 포인트적립율(MOBILE)
					Brand brand = new Brand();
					brand.setBrandCd(originGoods.getBrandCd());
					Collection<Brand> brandList = businessService.getBrandList(brand);
					if (brandList != null && !brandList.isEmpty()) {
						float pntPrate = 0f;
						float pntMrate = 0f;
						for (Brand tmpBrand : brandList) {
							if ("G009_10".equals(goods.getFormalGb())) {
								pntPrate = tmpBrand.getPntPrate10();
								pntMrate = tmpBrand.getPntMrate10();
							} else {
								pntPrate = tmpBrand.getPntPrate20();
								pntMrate = tmpBrand.getPntMrate20();
							}
						}
						goods.setPntPrate(pntPrate); // 포인트적립율(PC)
						goods.setPntMrate(pntMrate); // 포인트적립율(MOBILE)
					}
				} else if ("goodsStat".equals(goods.getProcJob())) {
					// 상품브랜드 조회
					Goods originGoods = goodsDao.getGoods(goods);

					// 승인일
					if (!goods.getGoodsStat().equals(originGoods.getGoodsStat()) && "G008_90".equals(goods.getGoodsStat())) {
						goods.setChGoodsStatYn("Y");
					}
				}
				// 상품정보 변경
				goodsDao.updateGoodsState(goods);
			}

		} else {

			// 이력생성
			goodsDao.createGoodsHst(goods);
			if ("formalGb".equals(goods.getProcJob())) {
				// 상품브랜드 조회
				Goods originGoods = goodsDao.getGoods(goods);
				// 브랜드 확인
				goods.setPntPrate(originGoods.getPntPrate()); // 포인트적립율(PC)
				goods.setPntMrate(originGoods.getPntMrate()); // 포인트적립율(MOBILE)
				Brand brand = new Brand();
				brand.setBrandCd(originGoods.getBrandCd());
				Collection<Brand> brandList = businessService.getBrandList(brand);
				if (brandList != null && !brandList.isEmpty()) {
					float pntPrate = 0f;
					float pntMrate = 0f;
					for (Brand tmpBrand : brandList) {
						if ("G009_10".equals(goods.getFormalGb())) {
							pntPrate = tmpBrand.getPntPrate10();
							pntMrate = tmpBrand.getPntMrate10();
						} else {
							pntPrate = tmpBrand.getPntPrate20();
							pntMrate = tmpBrand.getPntMrate20();
						}
					}
					goods.setPntPrate(pntPrate); // 포인트적립율(PC)
					goods.setPntMrate(pntMrate); // 포인트적립율(MOBILE)
				}
			}
			// 상품정보 변경
			goodsDao.updateGoodsState(goods);
		}
	}

	/**
	 * 엑셀조회용 상품 저장
	 *
	 * @param procJob : goodsExcelUpload
	 * @param goodsList
	 * @return
	 * @author eskim
	 * @since 2020. 10. 22
	 */
	@Transactional("shopTxnManager")
	public void saveExceluploadGoods(Collection<Goods> goodsList, String excelFilename) {

		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
		if (goodsList == null || goodsList.isEmpty()) {
			this.deleteExceluploadFile(targetPath, excelFilename);
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		//건수
		if (goodsList != null && goodsList.size() > EXCEL_ROW_COUNT) {
			throw new IllegalStateException("엑셀 파일의 건수를 " + EXCEL_ROW_COUNT + "건 이하로 사용하세요.");
		}

		int index = 0;
		String goodsCdFlag = "";
		String goodsNumFlag = "";
		for (Goods goods : goodsList) {

			SearchData searchData = new SearchData();
			searchData.setRegNo(goods.getRegNo());
			searchData.setSearchCd(goods.getGoodsCd());
			if (index == 0) {
				commonService.deleteExceluploadSearCh(searchData);
			}

			commonService.createExceluploadSearch(searchData);
			index++;
		}
	}

	/**
	 * 파일 삭제
	 *
	 * @param targetPath
	 * @param excelFilename
	 * @author eskim
	 * @since 2020. 10. 22
	 */
	private void deleteExceluploadFile(String targetPath, String excelFilename) {
		// 파일 삭제
		try {
			GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(targetPath, excelFilename));
		} catch (IOException e) {
			// Nothing Do
		}
	}

	/**
	 * 상품 품목 변경 저장
	 *
	 * @param goodsList
	 * @return
	 * @author eskim
	 * @since 2020. 10. 23
	 */
	@Transactional("shopTxnManager")
	//@CacheEvict(value = "cate", allEntries = true)
	public void saveItemKindChange(Collection<Goods> goodsList) {
		for (Goods goods : goodsList) {
			goods.setRegNo(TsaSession.getInfo().getUserNo());
			goods.setUpdNo(TsaSession.getInfo().getUserNo());
			goods.setItemkindCd(goods.getItemkindCd().toUpperCase());
			// 품목확인
			Itemkind itemkind = new Itemkind();
			itemkind.setItemkindCd(goods.getItemkindCd());
			itemkind.setUseYn("Y");
			Collection<Itemkind> itemkindList = goodsDao.getItemkindList(itemkind);
			if (itemkindList == null || itemkindList.isEmpty()) {
				throw new IllegalStateException(goods.getGoodsCd() + " 상품의 품목코드를 확인해주세요.");
			}

			// 상품이력
			goodsDao.createGoodsHst(goods);
			// 품목변경
			goodsDao.updateGoodItemKindCd(goods);

			// 검색어 변경
			String goodsSnm = goodsDao.getGoodsSnm(goods.getGoodsCd());
			Goods tmpGoods = goodsDao.getGoods(goods);
			if (tmpGoods != null && !StringUtils.isBlank(tmpGoods.getGoodsSnm1())) {
				String[] arrGoodsSnm = tmpGoods.getGoodsSnm1().split("\\;");
				StringBuilder tempGoodsSnm = new StringBuilder();
				for (String loopGoodsSnm : arrGoodsSnm) {
					if (goodsSnm.toUpperCase().indexOf(loopGoodsSnm.toUpperCase()) <= -1) {
						tempGoodsSnm.append(loopGoodsSnm).append(";");
					}
				}
				goods.setGoodsSnm(tempGoodsSnm.toString() + goodsSnm);

			} else {
				goods.setGoodsSnm(goodsSnm);
			}
			goodsDao.updateGoodsSnm(goods);

			//상품 등록후에는 고시정보는 품목과 상관없이 변경처리 가능하게
//			Collection<GoodsNotiInfo> goodsNotiInfoList = goodsDao.getNewNotiInfo(goods);
//			goodsDao.deleteGoodsNotiInfo(goods);
//
//			for (GoodsNotiInfo goodsNotiInfo : goodsNotiInfoList) {
//				goodsNotiInfo.setRegNo(TsaSession.getInfo().getUserNo());
//				goodsNotiInfo.setUpdNo(TsaSession.getInfo().getUserNo());
//				goodsNotiInfo.setGoodsCd(goods.getGoodsCd());
//				goodsDao.saveGoodsNotiInfo(goodsNotiInfo);
//			}

			// 품목변경시 카테고리 전시카테고리 변경
			GoodsCategory goodsCategory = new GoodsCategory();
			goodsCategory.setRegNo(TsaSession.getInfo().getUserNo());
			goodsCategory.setUpdNo(TsaSession.getInfo().getUserNo());
			goodsCategory.setGoodsCd(goods.getGoodsCd());
			goodsCategory.setCateType("G031_10");	//상품분류카테고리
			displayService.deleteGoodsCategory(goodsCategory);
			goodsDao.createCategoryGoods(goods);

		}
	}

	/**
	 * 상품 저장
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 27
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsDetail(Goods goods) {

		// <,> replace 처리
		goods.setRegNo(TsaSession.getInfo().getUserNo());
		goods.setUpdNo(TsaSession.getInfo().getUserNo());

//		goods.setGoodsDesc(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsDesc(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsPcTopDesc(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsPcTopDesc(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsMobileTopDesc(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsMobileTopDesc(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsPcDownDesc(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsPcDownDesc(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsMobileDownDesc(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsMobileDownDesc(), "&lt;", "<"), "&gt;", ">"));

//		goods.setGoodsNm(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsNm(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsTnm(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsTnm(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsSnm1(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsSnm1(), "&lt;", "<"), "&gt;", ">"));

		// 딜상품의 대표상품 변경여부 확인
		if ("G056_D".equals(goods.getGoodsType())) {

			String newRepGoodsCd = "";
			int newRepGoodsPrice = 0;
			Collection<GoodsCompose> goodsExtendList = goods.getGoodsComposeListNew();
			for (GoodsCompose regGoodsExtend : goodsExtendList) {
				if ("Y".equals(regGoodsExtend.getRepYn())) {
					newRepGoodsCd = regGoodsExtend.getCompsGoodsCd();
					newRepGoodsPrice = regGoodsExtend.getCurrPrice();
				}
			}

			// 1순 : 대표상품 변경, 2순 : 판매가 변경
			if (!newRepGoodsCd.equals(goods.getRepGoodsCd())) {
				goods.setCurrBprice(goods.getCurrPriceOrg());
				goods.setCurrPrice(newRepGoodsPrice);
				goods.setListPrice(newRepGoodsPrice);
				goods.setDcRate(0);
				goods.setChDataYn("Y");
			} else {
				if (goods.getCurrPrice() != goods.getCurrPriceOrg()) {
					goods.setCurrBprice(goods.getCurrPriceOrg());
					goods.setListPrice(goods.getCurrPrice());
					goods.setDcRate(0);
				}
			}

		} else {
			// 가격변경일
			if (goods.getCurrPrice() != goods.getCurrPriceOrg()) {
				goods.setCurrBprice(goods.getCurrPriceOrg());
			} else {
				goods.setCurrPrice(goods.getCurrPriceOrg());
			}
		}

		// 승인일
		if (!goods.getGoodsStat().equals(goods.getGoodsStatOrg()) && "G008_90".equals(goods.getGoodsStat())) {
			goods.setChGoodsStatYn("Y");
		}
		// 사용자 검색어를 검색어에 적용
		String goodsSnm = goodsDao.getGoodsSnm(goods.getGoodsCd());
		if (!StringUtils.isBlank(goods.getGoodsSnm1())) {
			goods.setGoodsSnm1(GagaStringUtil.replace(goods.getGoodsSnm1(), " ", "")); // 빈값 삭제
			String[] arrGoodsSnm = goods.getGoodsSnm1().split("\\;");
			StringBuilder tempGoodsSnm = new StringBuilder();
			for (String loopGoodsSnm : arrGoodsSnm) {
				if (goodsSnm.toUpperCase().indexOf(loopGoodsSnm.toUpperCase()) <= -1) {
					tempGoodsSnm.append(loopGoodsSnm).append(";");
				}
			}
			goods.setGoodsSnm(tempGoodsSnm.toString() + goodsSnm);

		} else if (!goodsSnm.equals(goods.getGoodsSnm())) {
			goods.setGoodsSnm(goodsSnm);
		}

		goods.setFormalGb(goods.getFormalGb());
		// 브랜드 확인
		if (!"G056_N".equals(goods.getGoodsType())) {
			if (!goods.getFormalGb().equals(goods.getFormalGbOrg())) {
				Brand brand = new Brand();
				brand.setBrandCd(goods.getBrandCd());
				Collection<Brand> brandList = businessService.getBrandList(brand);
				if (brandList != null && !brandList.isEmpty()) {
					float pntPrate = 0f;
					float pntMrate = 0f;
					for (Brand tmpBrand : brandList) {
						if ("G009_10".equals(goods.getFormalGb())) {
							pntPrate = tmpBrand.getPntPrate10();
							pntMrate = tmpBrand.getPntMrate10();
						} else {
							pntPrate = tmpBrand.getPntPrate20();
							pntMrate = tmpBrand.getPntMrate20();
						}
					}
					goods.setPntPrate(pntPrate); // 포인트적립율(PC)
					goods.setPntMrate(pntMrate); // 포인트적립율(MOBILE)
				}
			}
		}

		// 판매기간설정 eskim
		goods.setSellStdt(goods.getSellStYMD().replaceAll("-", "") + goods.getSellStHH() + "0000");
		goods.setSellEddt(goods.getSellEdYMD().replaceAll("-", "") + goods.getSellEdHH() + "5959");

		// 신규가입기간
		if (!StringUtils.isEmpty(goods.getNewCustOrdStdt())) {
			goods.setNewCustOrdStdt(goods.getNewCustOrdStdt().replaceAll("-", "") + "000000");
			goods.setNewCustOrdEddt(goods.getNewCustOrdEddt().replaceAll("-", "") + "235959");
		}

		// 기본정보 변경
		if ("Y".equals(goods.getChDataYn())) {
			goodsDao.createGoodsHst(goods);
			goodsDao.updateGoods(goods);
		}

		// 상품상세정보 변경
		if (!"Y".equals(goods.getChkDescKeep())) {
			this.saveGoodsDetailDesc(goods);
		}

		int idx = 1;
		// 구성상품 변경
		if (!"G056_N".equals(goods.getGoodsType())) {

			Collection<GoodsCompose> goodsExtendList = goods.getGoodsComposeListNew();
			for (GoodsCompose regGoodsExtend : goodsExtendList) {
				regGoodsExtend.setDispOrd(idx);
				regGoodsExtend.setRegNo(TsaSession.getInfo().getUserNo());
				regGoodsExtend.setUpdNo(TsaSession.getInfo().getUserNo());
				goodsDao.saveGoodsCompose(regGoodsExtend); // 구성상품기본 저장

				idx++;
			}
		}

		// 옵션/재고 변경
		if (goods.getOptCd() != null && goods.getOptCd().length > 0 && "Y".equals(goods.getChStockDataYn())) {
			this.saveStock(goods);
		}

		// 상품 정보고시 변경
		this.saveGoodsNotiInfo(goods);

		// 안전인증정보
		if (!StringUtils.isEmpty(goods.getCertTargetGb())) {
			GoodsSafeNo goodsSafeNo = new GoodsSafeNo();
			goodsSafeNo.setGoodsCd(goods.getGoodsCd());
			goodsSafeNo.setCertFormGb(goods.getCertFormGb());
			goodsSafeNo.setCertTargetGb(goods.getCertTargetGb());
			goodsSafeNo.setCertType(goods.getCertType());
			goodsSafeNo.setCertNum(goods.getCertNum());
			log.info("goodsSafeNo ==>{}", goodsSafeNo);
			this.saveGoodsDetailCertNum(goodsSafeNo);	
		}

		// 상품 구매등급 적용
		if (goods.getGoodsOrderGrade() != null && goods.getGoodsOrderGrade().length > 0) {
			Goods goodsOrderGrade = new Goods();
			goodsOrderGrade.setGoodsCd(goods.getGoodsCd());
			goodsOrderGrade.setRegNo(TsaSession.getInfo().getUserNo());
			goodsDao.deleteGoodsCustGrade(goodsOrderGrade);
			for (String custGrade : goods.getGoodsOrderGrade()) {
				goodsOrderGrade.setCustGrade(custGrade);
				goodsDao.createGoodsCustGrade(goodsOrderGrade);
			}
		} else {
			Goods goodsOrderGrade = new Goods();
			goodsOrderGrade.setGoodsCd(goods.getGoodsCd());
			goodsOrderGrade.setRegNo(TsaSession.getInfo().getUserNo());
			goodsDao.deleteGoodsCustGrade(goodsOrderGrade);
		}

	}

	/**
	 * 상품상세정보 변경 - 상품상세
	 *
	 * @param goods
	 * @author eskim
	 * @since 2020. 10. 27.
	 */
	private void saveGoodsDetailDesc(Goods goods) {
		// 상품상세 구분(10:상품타이틀,20:상품타이틀내용,30:상품특징,40:상위컨텐츠,50:하위컨텐츠,60:하위컨텐츠-모바일,70:상위컨텐츠-모바일,80:상품상세(as-is))
		GoodsDesc goodsDesc = new GoodsDesc();
		goodsDesc.setGoodsCd(goods.getGoodsCd());
		goodsDesc.setRegNo(goods.getRegNo());
		goodsDesc.setUpdNo(goods.getUpdNo());

		// AS-IS 상세 정보 이력 처리
		goodsDao.createGoodsDetailDescHst(goodsDesc);

		// 상세 타이틀
		goodsDesc.setDescGb("10");
		goodsDesc.setGoodsDesc(goods.getGoodsTitlesDesc());
		this.saveGoodsDesc(goodsDesc);

		// 상세 내용
		goodsDesc.setDescGb("20");
		goodsDesc.setGoodsDesc(goods.getGoodsContentsDesc());
		this.saveGoodsDesc(goodsDesc);

		// 상세 특징
		goodsDesc.setDescGb("30");
		goodsDesc.setGoodsDesc(goods.getGoodsCharacterDesc());
		this.saveGoodsDesc(goodsDesc);

		// PC 상단
		goodsDesc.setDescGb("40");
		goodsDesc.setGoodsDesc(goods.getGoodsPcTopDesc());
		this.saveGoodsDesc(goodsDesc);

		// PC 하단
		goodsDesc.setDescGb("50");
		goodsDesc.setGoodsDesc(goods.getGoodsPcDownDesc());
		this.saveGoodsDesc(goodsDesc);

		// MO 상단
		goodsDesc.setDescGb("60");
		goodsDesc.setGoodsDesc(goods.getGoodsMobileTopDesc());
		this.saveGoodsDesc(goodsDesc);

		// MO 하단
		goodsDesc.setDescGb("70");
		goodsDesc.setGoodsDesc(goods.getGoodsMobileDownDesc());
		this.saveGoodsDesc(goodsDesc);

		// 상품상세(as-is,입점
		goodsDesc.setDescGb("80");
		goodsDesc.setGoodsDesc(goods.getGoodsDesc());
		this.saveGoodsDesc(goodsDesc);
	}

	/**
	 * 상품 상세 저장
	 *
	 * @param goodsDesc
	 * @return
	 * @author eskim
	 * @since 2020. 10. 27
	 */
	private void saveGoodsDesc(GoodsDesc goodsDesc) {

		goodsDao.deleteGoodsDesc(goodsDesc);

		String[] arrProdHtml = null;
		arrProdHtml = makeArrayToString(goodsDesc.getGoodsDesc(), 3900);
		if (arrProdHtml.length > 0) {
			for (int i = 0; i < arrProdHtml.length; i++) {
				if (!arrProdHtml[i].isEmpty()) {
					goodsDesc.setSeq(i + 1);
					goodsDesc.setGoodsDesc(arrProdHtml[i]);
					goodsDao.createGoodsDesc(goodsDesc);
				}
			}
		}
	}

	/**
	 * String => byte array
	 *
	 * @param raw
	 * @param len
	 * @return
	 * @author eskim
	 * @since 2020. 10. 27
	 */
	public static String[] makeArrayToString(String raw, int len) {

		String[] ary = null;

		if (raw == null) {
			return ary;
		}

		try {

			// raw 의 byte
			byte[] rawBytes = raw.getBytes("UTF-8"); // MS949
			int rawLength = rawBytes.length;

			if (rawLength > len) {
				int aryLength = (rawLength / len) + (rawLength % len != 0 ? 1 : 0);
				ary = new String[aryLength];

				int endCharIndex = 0; // 문자열이 끝나는 위치
				String tmp;
				for (int i = 0; i < aryLength; i++) {

					if (i == (aryLength - 1)) {
						tmp = raw.substring(endCharIndex);
					} else {

						int useByteLength = 0;
						int rSize = 0;
						for (; endCharIndex < raw.length(); endCharIndex++) {

							if (raw.charAt(endCharIndex) > 0x007F) {
								useByteLength += 3;
							} else {
								useByteLength++;
							}
							if (useByteLength > len) {
								break;
							}
							rSize++;
						}
						tmp = raw.substring((endCharIndex - rSize), endCharIndex);
					}

					ary[i] = tmp;
				}

			} else {
				ary = new String[] {raw};
			}

		} catch (java.io.UnsupportedEncodingException e) {
		}

		return ary;
	}

	/**
	 * 옵션/재고 변경 - 상품상세
	 *
	 * @param goods
	 * @param index
	 * @author eskim
	 * @since 2020. 10. 27
	 */
	private void saveStock(Goods goods) {
		int index = 0;
		Option stock = new Option();
		stock.setGoodsCd(goods.getGoodsCd());
		stock.setUpdNo(goods.getUpdNo());
		stock.setRegNo(goods.getRegNo());
//		goodsDao.createStockHst(stock);
		//log.info("saveStock goods={}", goods);
		for (String optCd : goods.getOptCd()) {
			//log.info("saveStock index={}", index);
			//log.info("saveStock optCd={}", optCd);
			Option goodsStock = new Option();
			goodsStock.setGoodsCd(goods.getCompsGoodsCd()[index]); // 구성상품 코드
			goodsStock.setOptCd(optCd);
			goodsStock.setOptCd1(goods.getOptCd1()[index]);
			goodsStock.setOptCd2(goods.getOptCd2()[index]);
			goodsStock.setAddPrice(Integer.parseInt(goods.getAddPrice()[index]));
			goodsStock.setBaseStockQty(Integer.parseInt(goods.getBaseStockQty()[index]));
			goodsStock.setSoldoutYn(goods.getSoldoutYn()[index]);
			goodsStock.setDispOrd(Integer.parseInt(goods.getDispOrd()[index]));
			goodsStock.setDispYn(goods.getDispYn()[index]);
			goodsStock.setRegNo(goods.getRegNo());
			goodsStock.setUpdNo(goods.getUpdNo());

			if ("N".equals(goods.getSelfGoodsYn())) {
				goodsStock.setSelfGoodsYn(goods.getSelfGoodsYn());
				goodsStock.setCurrStockQty(Integer.parseInt(goods.getEditCurrStockQty()[index]));
				goodsStock.setStoreMaxQty(Integer.parseInt(goods.getEditCurrStockQty()[index]));
			}
			goodsDao.createStockHst(goodsStock);
			goodsDao.saveStock(goodsStock);
			index++;
		}
	}

	/**
	 * 상품 사이즈 옵션정보 이력 생성
	 *
	 * @param goods
	 * @author eskim
	 * @since 2020. 11. 17
	 */
	@Transactional("shopTxnManager")
	public void createStockHst(Option option) {
		goodsDao.createStockHst(option);
	}

	/**
	 * 상품 정보고시 변경 - 상품상세
	 *
	 * @param goods
	 * @author eskim
	 * @since 2020. 10. 27
	 */
	private void saveGoodsNotiInfo(Goods goods) {
		int index;
		if (goods.getNotiListNew() != null && !goods.getNotiListNew().isEmpty()) {
			index = 0;
			for (GoodsNotiInfo goodsNotiInfo : goods.getNotiListNew()) {
				if (index == 0) {
					goodsDao.deleteGoodsNotiInfo(goods);
				}
//				goodsNotiInfo.setNiContent(GagaStringUtil.replace(GagaStringUtil.replace(goodsNotiInfo.getNiContent(), "&lt;", "<"), "&gt;", ">"));
				goodsNotiInfo.setRegNo(goods.getRegNo());
				goodsNotiInfo.setUpdNo(goods.getUpdNo());
				goodsDao.saveGoodsNotiInfo(goodsNotiInfo);
				index++;
			}
		}
	}

	/**
	 * 딜상품 저장
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 30
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsDeal(Goods goods) {

		Goods regGoods = new Goods();

		// <,> replace 처리
		regGoods.setRegNo(TsaSession.getInfo().getUserNo());
		regGoods.setUpdNo(TsaSession.getInfo().getUserNo());

		String goodsCd = this.getGoodsCodeSeq("D", "D");
		regGoods.setGoodsCd(goodsCd);
		regGoods.setSupplyGoodsCd(goodsCd);
		regGoods.setGoodsType("G056_D");
		regGoods.setSupplyCompCd(goods.getSupplyCompCd());
		regGoods.setBrandCd(goods.getBrandCd());
		regGoods.setItemkindCd(goods.getItemkindCd());
//		regGoods.setGoodsNm(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsNm(), "&lt;", "<"), "&gt;", ">"));
		regGoods.setGoodsNm(goods.getGoodsNm());
		regGoods.setStyleYear(goods.getStyleYear());
		regGoods.setSeasonCd(goods.getSeasonCd());
		regGoods.setSexGb(goods.getSexGb());
		regGoods.setMainColorCd("XX");
		regGoods.setOriginCd(goods.getOriginCd());
		regGoods.setMakeYmd(goods.getMakeYmd());
		regGoods.setSelfMallYn(goods.getSelfMallYn());
		regGoods.setGoodsStat("G008_20"); // 정보부족
		regGoods.setFormalGb("G009_10"); // 정상 기본값 처리
		regGoods.setGoodsGb("G073_11"); // 자사상품은 신규
		//regGoods.setDistributionGb("G065_12"); // 유통구분
		regGoods.setTaxGb("10"); // 과세구분
		regGoods.setTobeFormYn("Y");
		regGoods.setGoodsNum(goodsCd);

		Collection<GoodsCompose> goodsComposeList = null;
		try {
			goodsComposeList = mapper.readValue(goods.getGoodsComposeList(), new TypeReference<Collection<GoodsCompose>>() {
			});
		} catch (Exception e) {
			e.printStackTrace();
			throw new IllegalStateException(message.getMessage("딜상품 저장 중 오류로 인해 저장되지 않았습니다."));
		}

		for (GoodsCompose goodsCompose : goodsComposeList) {
			goodsCompose.setGoodsCd(regGoods.getGoodsCd());
			goodsCompose.setGoodsType(regGoods.getGoodsType());
			goodsCompose.setRegNo(TsaSession.getInfo().getUserNo());
			goodsCompose.setUpdNo(TsaSession.getInfo().getUserNo());

			Goods extendGoods = new Goods();
			extendGoods.setGoodsCd(goodsCompose.getCompsGoodsCd());
			extendGoods = goodsDao.getGoods(extendGoods);
			if (StringUtils.isBlank(extendGoods.getBrandCd())) {
				throw new IllegalStateException(message.getMessage("구성상품 중 " + goodsCompose.getCompsGoodsCd() + " 상품 정보를 확인해 주세요."));
			}

			if ("Y".equals(goodsCompose.getBaseYn())) {
				regGoods.setBrandCd(extendGoods.getBrandCd());
				regGoods.setItemkindCd(extendGoods.getItemkindCd());
				regGoods.setSupplyCompCd(extendGoods.getSupplyCompCd());
				regGoods.setFormalGb(extendGoods.getFormalGb());
				regGoods.setSelfGoodsYn(extendGoods.getSelfGoodsYn());
				regGoods.setDelvLocCd(extendGoods.getDelvLocCd()); //출고처
			}

			if ("Y".equals(goodsCompose.getRepYn())) {
				regGoods.setListPrice(extendGoods.getCurrPrice());
				regGoods.setCurrPrice(extendGoods.getCurrPrice());
				regGoods.setDcRate((int)(this.getDcRate(regGoods.getListPrice(), regGoods.getCurrPrice())));
			}
		}

		this.createGoodsCompose(regGoods, goodsComposeList); // 딜상품 관련 정보 저장
	}

	/**
	 * 세트상품 저장
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 11. 04
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsSet(Goods goods) {

		Goods regGoods = new Goods();

		// <,> replace 처리
		regGoods.setRegNo(TsaSession.getInfo().getUserNo());
		regGoods.setUpdNo(TsaSession.getInfo().getUserNo());

		String goodsCd = this.getGoodsCodeSeq("S", "S");
		regGoods.setGoodsCd(goodsCd);
		regGoods.setSupplyGoodsCd(goodsCd);
		regGoods.setGoodsType("G056_S");
		regGoods.setSupplyCompCd(goods.getSupplyCompCd());
		regGoods.setBrandCd(goods.getBrandCd());
		regGoods.setItemkindCd(goods.getItemkindCd());
//		regGoods.setGoodsNm(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsNm(), "&lt;", "<"), "&gt;", ">"));
		regGoods.setGoodsNm(goods.getGoodsNm());
		regGoods.setStyleYear(goods.getStyleYear());
		regGoods.setSeasonCd(goods.getSeasonCd());
		regGoods.setSexGb(goods.getSexGb());
		regGoods.setMainColorCd("XX");
		regGoods.setOriginCd(goods.getOriginCd());
		regGoods.setMakeYmd(goods.getMakeYmd());
		regGoods.setSelfMallYn(goods.getSelfMallYn());
		regGoods.setGoodsStat("G008_20"); // 정보부족
		regGoods.setFormalGb("G009_10"); // 정상 기본값 처리
		regGoods.setGoodsGb("G073_11"); // 자사상품은 신규
		//regGoods.setDistributionGb("G065_12"); // 유통구분
		regGoods.setTaxGb("10"); // 과세구분
		regGoods.setTobeFormYn("Y");
		regGoods.setGoodsNum(goodsCd);

		Collection<GoodsCompose> goodsComposeList = null;
		try {
			goodsComposeList = mapper.readValue(goods.getGoodsComposeList(), new TypeReference<Collection<GoodsCompose>>() {
			});
		} catch (Exception e) {
			throw new IllegalStateException(message.getMessage("세트상품 저장 중 오류로 인해 저장되지 않았습니다."));
		}

		int listPriceSum = 0;
		int currPriceSum = 0;
		for (GoodsCompose goodsCompose : goodsComposeList) {
			goodsCompose.setGoodsCd(regGoods.getGoodsCd());
			goodsCompose.setGoodsType(regGoods.getGoodsType());
			goodsCompose.setRegNo(TsaSession.getInfo().getUserNo());
			goodsCompose.setUpdNo(TsaSession.getInfo().getUserNo());

			Goods extendGoods = new Goods();
			extendGoods.setGoodsCd(goodsCompose.getCompsGoodsCd());
			extendGoods = goodsDao.getGoods(extendGoods);
			if (StringUtils.isBlank(extendGoods.getBrandCd())) {
				throw new IllegalStateException(message.getMessage("구성상품 중 " + goodsCompose.getCompsGoodsCd() + " 상품 정보를 확인해 주세요."));
			}
			listPriceSum += extendGoods.getListPrice() * goodsCompose.getQty();
			currPriceSum += goodsCompose.getCompsCurrPrice(); // 입력값

			if ("Y".equals(goodsCompose.getBaseYn())) {
				regGoods.setBrandCd(extendGoods.getBrandCd());
				regGoods.setItemkindCd(extendGoods.getItemkindCd());
				regGoods.setGoodsNum(extendGoods.getGoodsNum());
				regGoods.setSupplyCompCd(extendGoods.getSupplyCompCd());
				regGoods.setFormalGb(extendGoods.getFormalGb());
				regGoods.setSelfGoodsYn(extendGoods.getSelfGoodsYn());
				regGoods.setDelvLocCd(extendGoods.getDelvLocCd()); //출고처
			}
		}

		regGoods.setListPrice(listPriceSum);
		regGoods.setCurrPrice(currPriceSum);
		regGoods.setCostPrice(0);	// 원가 0원처리
		regGoods.setDcRate((int)(this.getDcRate(listPriceSum, currPriceSum)));

		this.createGoodsCompose(regGoods, goodsComposeList); // 세트상품 관련 정보 저장
	}

	/**
	 * 세트/딜 상품 관련 저장
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 30
	 */
	private void createGoodsCompose(Goods regGoods, Collection<GoodsCompose> goodsComposeList) {
		// 브랜드 확인
		Brand brand = new Brand();
		brand.setBrandCd(regGoods.getBrandCd());
		brand.setSupplyCompCd(regGoods.getSupplyCompCd());
		Collection<Brand> brandList = businessService.getBrandList(brand);
		if (brandList == null || brandList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("구성상품 중 기준 상품의 브랜드를 확인해 주세요."));
		}

		float pntPrate = 0f;
		float pntMrate = 0f;
		String distributionGb = "";
		for (Brand tmpBrand : brandList) {

			if ("G009_10".equals(regGoods.getFormalGb())) {
				pntPrate = tmpBrand.getPntPrate10();
				pntMrate = tmpBrand.getPntMrate10();
			} else {
				pntPrate = tmpBrand.getPntPrate20();
				pntMrate = tmpBrand.getPntMrate20();
			}
			distributionGb = tmpBrand.getDistributionGb(); // 유통구분
		}

		regGoods.setPntPrate(pntPrate); // 포인트적립율(PC)
		regGoods.setPntMrate(pntMrate); // 포인트적립율(MOBILE)
		regGoods.setDistributionGb(distributionGb); // 유통구분
		//regGoods.setSelfGoodsYn("Y");

		SupplyCompany supplyCompany = new SupplyCompany();
		supplyCompany.setSupplyCompCd(regGoods.getSupplyCompCd());
		Collection<SupplyCompany> supplyCompanyList = businessService.getSupplyCompanyList(supplyCompany);
		if (supplyCompanyList == null || supplyCompanyList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("구성상품 중 기준 상품의 업체(판매수수율를 확인해 주세요."));
		}
		regGoods.setSellFeeRate(supplyCompanyList.iterator().next().getSellFeeRate()); // 판매수수료율

		DelvFeePolicy delvFeePolicy = new DelvFeePolicy();
		delvFeePolicy.setSupplyCompCd(regGoods.getSupplyCompCd());
		Collection<DelvFeePolicy> deliveryFeePolicyList = businessService.getDeliveryFeePolicyList(delvFeePolicy);
		if (deliveryFeePolicyList == null || deliveryFeePolicyList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("구성상품 중 기준 상품의 업체(배송비정책)를 확인해 주세요."));
		}
		regGoods.setDelvFeeCd(deliveryFeePolicyList.iterator().next().getDelvFeeCd());// 배송비정책코드

		// 스타일 연도
		regGoods.setStyleYear(regGoods.getStyleYear());

		// 판매기간설정
		regGoods.setSellStdt(GagaDateUtil.getToday() + "000000");
		regGoods.setSellEddt("30001231235959");
		regGoods.setTobeFormYn("Y");

		goodsDao.createGoods(regGoods); // 상품기본 저장
		goodsDao.createGoodsSmmary(regGoods); // 상품통계 생성

		StringBuilder goodsDescSb = new StringBuilder(); // 상품상세

		int dispOrd = 1;
		for (GoodsCompose regGoodsExtend : goodsComposeList) {
			regGoodsExtend.setDispOrd(dispOrd);
			goodsDao.saveGoodsCompose(regGoodsExtend); // 구성상품기본 저장
			dispOrd++;
		}

		// 사용자 검색어를 검색어에 적용
		String goodsSnm = goodsDao.getGoodsSnm(regGoods.getGoodsCd());
		regGoods.setGoodsSnm(goodsSnm);
		goodsDao.updateGoodsSnm(regGoods);

		goodsDao.createCategoryGoods(regGoods);

	}

//	/**
//	 * 품 이미지 경로생성
//	 *
//	 * @param goodsCd
//	 * @param brandCd
//	 * @return String
//	 * @author eskim
//	 * @since 2020. 10. 30
//	 */
//	private String getGoodsImgPath(String goodsCd, String brandCd) {
//		return "/" + goodsCd.substring(0, 1) + "/" + goodsCd.substring(0, 3) + "/" + goodsCd + "/1000/" + goodsCd + "_";
//	}

	/**
	 * 상품 코드 생성
	 *
	 * @param goodsType - 상품타입
	 * @param goodsCdAfter - 상품시퀀스 앞에 붙는명
	 * @return
	 * @author eskim
	 * @since 2020. 10. 30
	 */
	public String getGoodsCodeSeq(String goodsType, String goodsCdAfter) {

		//상품코드 12자리
		String goodsCd = "";
		Goods goods = new Goods();
		goodsDao.createGoodsSequence(goods);
		String goodsSeq = GagaStringUtil.getLPadding(Integer.toString(goods.getGoodsSq()), 8, "0");
		if ("S".equals(goodsType) || "D".equals(goodsType)) {
			goodsCd = SELF_GOOODS_AFTER + goodsCdAfter + goodsSeq;

		} else {
			goodsCd = goodsCdAfter + goodsSeq; // 입점 : 브랜드코드
		}
		return goodsCd;
	}

	/**
	 * 상품 타이틀 관리 목록 건수
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 11 .02
	 */
	public int getGoodsTitleReserveCount(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsTitleReserveCount(goodsSearch);
	}

	/**
	 * 상품 타이틀 관리 목록
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 11 .02
	 */
	public Collection<GoodsTnmRes> getGoodsTitleReserveList(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsTitleReserveList(goodsSearch);
	}

	/**
	 * 상품 타이틀 예약 등록
	 *
	 * @param goodsTnmRes
	 * @author eskim
	 * @since 2020. 11 .02
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsRsvtTnm(GoodsTnmRes goodsTnmRes) {
		if (goodsTnmRes.getArrGoodsCd().length <= 0) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

//		goodsTnmRes.setGoodsTnm(GagaStringUtil.replace(GagaStringUtil.replace(goodsTnmRes.getGoodsTnm(), "&lt;", "<"), "&gt;", ">"));

		for (String goodsCd : goodsTnmRes.getArrGoodsCd()) {

			goodsTnmRes.setGoodsCd(goodsCd);
			goodsTnmRes.setRegNo(TsaSession.getInfo().getUserNo());
			goodsTnmRes.setUpdNo(TsaSession.getInfo().getUserNo());

			if (goodsDao.getGoodsTnmDupChkCount(goodsTnmRes) > 0) {
				throw new IllegalStateException("이미 등록된 상품 타이틀예약이 등록하려는 예약기간내에 존재합니다. \n(상품코드 : " + goodsCd + ")");
			}

			goodsDao.createGoodTnmRes(goodsTnmRes);

			// 현재일자가 예약기간에 포함되어 있으면 바로 적용한다.
			String toDaytime = GagaDateUtil.getTodayDateTime();
			if (Long.parseLong(toDaytime) >= Long.parseLong(goodsTnmRes.getApplyStdt()) && Long.parseLong(toDaytime) <= Long.parseLong(goodsTnmRes.getApplyEddt())) {

				// 이력생성 및 상품타이틀 수정
				Goods goods = new Goods();
				goods.setGoodsCd(goodsCd);
				goods.setGoodsTnm(goodsTnmRes.getGoodsTnm());
				goods.setRegNo(TsaSession.getInfo().getUserNo());
				goods.setUpdNo(TsaSession.getInfo().getUserNo());

				goodsDao.createGoodsHst(goods);
				goodsDao.updateGoodTnm(goods);
			}

		}
	}

	/**
	 * 상품 타이틀 예약 삭제
	 *
	 * @param goodsTnmRes
	 * @author eskim
	 * @since 2020. 11 .02
	 */
	@Transactional("shopTxnManager")
	public void deleteGoodsRsvtTnm(GoodsTnmRes goodsTnmRes) {
		if (goodsTnmRes.getArrGoodsCd().length <= 0) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		int idx = 0;
		for (String goodsCd : goodsTnmRes.getArrGoodsCd()) {

			// 상품 타이틀 예약 삭제
			goodsTnmRes.setGoodsTnmResSq(goodsTnmRes.getArrGoodsTnmResSq()[idx]);
			goodsDao.deleteGoodTnmRes(goodsTnmRes);

			// 상품 타이틀 예약건 초기화
			Goods goods = new Goods();
			goods.setGoodsCd(goodsCd);
			goods = goodsDao.getGoodTnmInit(goods);
			goods.setRegNo(TsaSession.getInfo().getUserNo());
			goods.setUpdNo(TsaSession.getInfo().getUserNo());

			if (!StringUtils.isBlank(goods.getGoodsTnm()) && !goods.getGoodsTnm().equals(goods.getGoodTnmInit())) {

				// 상품이력 먼저 쌓기
				goodsDao.createGoodsHst(goods);
				// 정보수정
				goods.setGoodsTnm(goods.getGoodTnmInit());
				goodsDao.updateGoodTnm(goods);

			}
			idx++;
		}
	}

	/**
	 * 네이버 EP 제외 상품 목록 건수
	 *
	 * @param goodsSearch
	 * @return int
	 * @author eskim
	 * @since 2020. 11. 03
	 */
	public int getGoodsEpSkipCount(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsEpSkipCount(goodsSearch);
	}

	/**
	 * 네이버 EP 제외 상품 목록
	 *
	 * @param goodsSearch
	 * @return Collection<TsaGoodsEpSkip>
	 * @author eskim
	 * @since 2020. 11. 03
	 */
	public Collection<GoodsEpSkip> getGoodsEpSkipList(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsEpSkipList(goodsSearch);
	}

	/**
	 * 네이버 EP 제외 상품 예약 등록
	 *
	 * @param goodsEpSkip
	 * @return void
	 * @author eskim
	 * @since 2020. 11. 03
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsRsvtEpSkip(GoodsEpSkip goodsEpSkip) {
		if (goodsEpSkip.getArrGoodsCd().length <= 0) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		for (String goodsCd : goodsEpSkip.getArrGoodsCd()) {

			goodsEpSkip.setGoodsCd(goodsCd);
			goodsEpSkip.setRegNo(TsaSession.getInfo().getUserNo());
			goodsEpSkip.setUpdNo(TsaSession.getInfo().getUserNo());

			if (goodsDao.getGoodsEpSkipDupChkCount(goodsEpSkip) > 0) {
				throw new IllegalStateException("비노출예약이 중복된 상품이 존재합니다.<br/>(상품코드 : " + goodsCd + ")");
			}
			goodsDao.createGoodEpSkip(goodsEpSkip);
		}
	}

	/**
	 * 네이버 EP 제외 상품 예약 삭제
	 *
	 * @param goodsEpSkip
	 * @return void
	 * @author eskim
	 * @since 2020. 11. 03
	 */
	@Transactional("shopTxnManager")
	public void deleteGoodsEpSkip(GoodsEpSkip goodsEpSkip) {
		if (goodsEpSkip.getArrGoodsCd().length <= 0) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		int idx = 0;
		for (String goodsCd : goodsEpSkip.getArrGoodsCd()) {
			goodsEpSkip.setGoodsEpSkipSq(goodsEpSkip.getArrGoodsEpSkipSq()[idx]);
			goodsDao.deleteGoodEpSkip(goodsEpSkip);
			idx++;
		}
	}

	/**
	 * 상품예약판매 목록 건수
	 *
	 * @param goodsSearch
	 * @return Integer
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	public int getGoodsResSellCount(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsResSellCount(goodsSearch);
	}

	/**
	 * 상품예약판매 목록
	 *
	 * @param goodsSearch
	 * @return Collection<TsaGoodsResSell>
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	public Collection<GoodsResSell> getGoodsResSellList(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsResSellList(goodsSearch);
	}

	/**
	 * 상품예약판매 등록
	 *
	 * @param goodsResSell
	 * @return void
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsResSell(GoodsResSell goodsResSell) {
		if (goodsResSell.getArrGoodsCd().length <= 0) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		for (String goodsCd : goodsResSell.getArrGoodsCd()) {

			goodsResSell.setGoodsCd(goodsCd);
			goodsResSell.setRegNo(TsaSession.getInfo().getUserNo());
			goodsResSell.setUpdNo(TsaSession.getInfo().getUserNo());

			if (goodsDao.getGoodsResSellDupChkCount(goodsResSell) > 0) {
				throw new IllegalStateException("이미 등록된 상품예약판매가 존재합니다. \n(상품코드 : " + goodsCd + ")");
			}

			goodsDao.createGoodResSell(goodsResSell);

			Goods goods = new Goods();
			goods.setRegNo(TsaSession.getInfo().getUserNo());
			goods.setUpdNo(TsaSession.getInfo().getUserNo());
			goods.setGoodsCd(goodsResSell.getGoodsCd());

			// 재고연동 비활성화
			goodsDao.createGoodsHst(goods);
			goodsDao.updateGoodsErpStockLinkYn(goods);

		}
	}

	/**
	 * 상품예약판매 삭제
	 *
	 * @param goodsResSell
	 * @return void
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	@Transactional("shopTxnManager")
	public void deleteGoodsResSell(GoodsResSell goodsResSell) {
		if (goodsResSell.getArrGoodsCd().length <= 0) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		int idx = 0;
		for (String goodsCd : goodsResSell.getArrGoodsCd()) {
			goodsResSell.setGoodsResSellSq(goodsResSell.getArrGoodsResSellSq()[idx]);
			goodsDao.deleteGoodResSell(goodsResSell);
			idx++;
		}
	}

	/**
	 * 상품 상세공지 목록
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 11. 05
	 */
	public Collection<Notice> getNoticeList(GoodsSearch goodsSearch) {
		return goodsDao.getNoticeList(goodsSearch);
	}

	/**
	 * 상품 상세공지 상품 목록
	 *
	 * @param notice
	 * @return
	 * @author eskim
	 * @since 2020. 11. 06
	 */
	public Collection<NoticeGoods> getNoticeGoodsList(Notice notice) {
		return goodsDao.getNoticeGoodsList(notice);
	}

	/**
	 * 공지사항 저장
	 * @param notice - 공지사항 정보
	 * @return
	 * @author eskim
	 * @since 2020. 11. 05
	 */
	@Transactional("shopTxnManager")
	public void saveNotice(Notice notice) {
		notice.setRegNo(TsaSession.getInfo().getUserNo());
		notice.setUpdNo(TsaSession.getInfo().getUserNo());

		// 신규 일때
		if (notice.getNoticeSq() == null) {
			// 공지사항 저장
			noticeService.createNotice(notice);

			// 등록된 사용자번호 값 가져오기
			Integer noticeSq = notice.getNoticeSq();

			notice.setNoticeSq(noticeSq);

		} else {
			// 공지사항 수정
			noticeService.updateNotice(notice);
		}

		if (!StringUtils.isBlank(notice.getGoodsList())) {
			Collection<NoticeGoods> noticeGoodsList = null;
			try {
				noticeGoodsList = mapper.readValue(notice.getGoodsList(), new TypeReference<Collection<NoticeGoods>>() {
				});
			} catch (Exception e) {
				e.printStackTrace();
				throw new IllegalStateException(message.getMessage("상품상세공지 저장 중 오류로 인해 저장되지 않았습니다."));
			}
			//log.info("noticeGoodsList: {}", noticeGoodsList);
			for (NoticeGoods noticeGoods : noticeGoodsList) {
				noticeGoods.setNoticeSq(notice.getNoticeSq());
				noticeGoods.setRegNo(TsaSession.getInfo().getUserNo());
				noticeGoods.setUpdNo(TsaSession.getInfo().getUserNo());

				goodsDao.saveNoticeGoods(noticeGoods);
			}

		}
	}

	/**
	 * 공지사항 상품 삭제
	 * @param noticeGoods
	 * @return
	 * @author eskim
	 * @since 2020. 11. 06
	 */
	@Transactional("shopTxnManager")
	public void deleteNoticeGoods(NoticeGoods noticeGoods) {

		if (noticeGoods == null || (noticeGoods.getArrGoodsCd() == null && noticeGoods.getArrGoodsCd().length <= 0)) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		if (noticeGoods.getArrGoodsCd().length > 0) {
			for (String goodsCd : noticeGoods.getArrGoodsCd()) {
				noticeGoods.setGoodsCd(goodsCd);
				noticeGoods.setRegNo(TsaSession.getInfo().getUserNo());
				noticeGoods.setUpdNo(TsaSession.getInfo().getUserNo());

				goodsDao.deleteNoticeGoods(noticeGoods);
			}
		}

	}

	/**
	 * 상품 가격예약 목록 건수
	 *
	 * @param goodsSearch
	 * @return Integer
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	public int getGoodsPriceResCount(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsPriceResCount(goodsSearch);
	}

	/**
	 * 상품 가격예약 목록
	 *
	 * @param goodsSearch
	 * @return Collection<TsaGoodsResSell>
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	public Collection<GoodsPriceRes> getGoodsPriceResList(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsPriceResList(goodsSearch);
	}

	/**
	 * 상품 가격예약 등록
	 *
	 * @param goodsPriceRes
	 * @return void
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@Transactional("shopTxnManager")
	public void createGoodPriceRes(GoodsPriceRes goodsPriceRes) {
		if (goodsPriceRes.getArrGoodsCd().length <= 0) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		int idx = 0;
		for (String goodsCd : goodsPriceRes.getArrGoodsCd()) {

			goodsPriceRes.setGoodsCd(goodsCd);
			goodsPriceRes.setEndGoodsPrice(goodsPriceRes.getArrEndGoodsPrice()[idx]);
			goodsPriceRes.setRegNo(TsaSession.getInfo().getUserNo());
			goodsPriceRes.setUpdNo(TsaSession.getInfo().getUserNo());

			if (goodsDao.getGoodsPriceResDupChkCount(goodsPriceRes) > 0) {
				throw new IllegalStateException("이미 등록된 상품 가격예약이 존재합니다. \n(상품코드 : " + goodsCd + ")");
			}

			goodsDao.createGoodPriceRes(goodsPriceRes);

			Goods goods = new Goods();
			goods.setRegNo(TsaSession.getInfo().getUserNo());
			goods.setUpdNo(TsaSession.getInfo().getUserNo());
			goods.setGoodsCd(goodsPriceRes.getGoodsCd());
			idx++;
		}
	}

	/**
	 * 상품 가격예약 삭제
	 *
	 * @param goodsPriceRes
	 * @return void
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@Transactional("shopTxnManager")
	public void deleteGoodsPriceRes(GoodsPriceRes goodsPriceRes) {
		if (goodsPriceRes.getArrGoodsCd().length <= 0) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		int idx = 0;
		for (String goodsCd : goodsPriceRes.getArrGoodsCd()) {
			goodsPriceRes.setGoodsPriceResSq(goodsPriceRes.getArrGoodsPriceResSq()[idx]);
			goodsDao.deleteGoodPriceRes(goodsPriceRes);
			idx++;
		}
	}

	/**
	 * 상품 가격예약 저장
	 *
	 * @param goodsPriceList
	 * @return
	 * @author eskim
	 * @since 2020. 11. 16
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsPriceExcelupload(Collection<GoodsPriceRes> goodsPriceList, String excelFilename) {

		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
		if (goodsPriceList == null || goodsPriceList.isEmpty()) {
			this.deleteExceluploadFile(targetPath, excelFilename);
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		//건수
		if (goodsPriceList != null && goodsPriceList.size() > EXCEL_ROW_COUNT) {
			throw new IllegalStateException("엑셀 파일의 건수를 " + EXCEL_ROW_COUNT + "건 이하로 사용하세요.");
		}

		// 입력값 확인
		String goodsPriceResvCheck = getGoodsPriceResvCheck(goodsPriceList);
		if (!"SUCC".equals(goodsPriceResvCheck)) {
			this.deleteExceluploadFile(targetPath, excelFilename);
			throw new IllegalStateException(goodsPriceResvCheck);
		}

		int index = 0;
		for (GoodsPriceRes goodsPriceRes : goodsPriceList) {
			goodsPriceRes.setUpdNo(TsaSession.getInfo().getUserNo());
			goodsPriceRes.setRegNo(TsaSession.getInfo().getUserNo());

//			//예약일시 시분 설정
//			goodsPriceRes.setApplyStdt(goodsPriceRes.getApplyStdt() + "0000");
//			goodsPriceRes.setApplyEddt(goodsPriceRes.getApplyEddt() + "5959");

			// 엑셀조회를 위한 SEARCH 테이블 생성
			SearchData searchData = new SearchData();
			searchData.setRegNo(goodsPriceRes.getRegNo());
			searchData.setSearchCd(goodsPriceRes.getGoodsCd());
			searchData.setDispOrd(index);
			if (index == 0) {
				commonService.deleteExceluploadSearCh(searchData);
			}

			commonService.createExceluploadSearch(searchData);

			goodsDao.createGoodPriceRes(goodsPriceRes);

			index++;
		}
	}

	/*
	 * 상품 가격예약 엑셀조회용 상품 저장 - 입력값 확인
	 */
	private String getGoodsPriceResvCheck(Collection<GoodsPriceRes> goodsPriceList) {

		int cnt = 0;
		for (GoodsPriceRes goodsPriceRes : goodsPriceList) {

			if (StringUtils.isBlank(goodsPriceRes.getGoodsCd())) {
				return (cnt + 2) + "행의 상품코드를 확인해주세요";
			}
			if (StringUtils.isBlank(Integer.toString(goodsPriceRes.getResGoodsPrice()))) {
				return (cnt + 2) + "행의 예약가격을 확인해주세요.";
			}
			if (goodsPriceRes.getResGoodsPrice() <= 0) {
				return (cnt + 2) + "행의 예약가격을 확인해주세요.";
			}

			String nowDate = GagaDateUtil.getToday("yyyyMMddHH");	//yyyyMMddHH
			SimpleDateFormat dateFormatParser = new SimpleDateFormat("yyyyMMddHH");
			dateFormatParser.setLenient(false);
			try {
				dateFormatParser.parse(goodsPriceRes.getApplyStdt());
			} catch (Exception e) {
				return (cnt + 2) + "행의 예약시작일시을 확인해주세요.";
			}
			try {
				dateFormatParser.parse(goodsPriceRes.getApplyEddt());
			} catch (Exception e) {
				return (cnt + 2) + "행의 예약종료일시을 확인해주세요.";
			}

			if (Integer.parseInt(goodsPriceRes.getApplyStdt()) > Integer.parseInt(goodsPriceRes.getApplyEddt())) {
				return (cnt + 2) + "행의 예약 시작일시은 종료일시보다 보다 클 수 없습니다.";
			}

			if (Integer.parseInt(goodsPriceRes.getApplyStdt()) <= Integer.parseInt(nowDate)) {
				return (cnt + 2) + "행의 예약 시작일시는 현재일시 보다 작거나 같을 수 없습니다.";
			}

			//정상가와 비교
			Goods searchGoods = new Goods();
			searchGoods.setGoodsCd(goodsPriceRes.getGoodsCd());
			Goods goods = goodsDao.getGoods(searchGoods);
			if (goods == null) {
				return (cnt + 2) + "행의 상품코드를 확인해주세요";
			}
			if (goods.getListPrice() < goodsPriceRes.getResGoodsPrice()) {
				return (cnt + 2) + "행의 상품 정상가보다 예약판매가가 더 큽니다.";
			}
//			if (!"Y".equals(goods.getSelfGoodsYn())) {
//				return (cnt + 2) + "행의 상품은 자사상품이 아닙니다.";
//			}

			goodsPriceRes.setApplyStdt(goodsPriceRes.getApplyStdt() + "0000");
			goodsPriceRes.setApplyEddt(goodsPriceRes.getApplyEddt() + "5959");

			if (goodsDao.getGoodsPriceResDupChkCount(goodsPriceRes) > 0) {
				return (cnt + 2) + "행의 상품 " + goodsPriceRes.getGoodsCd() + "은 이미 등록된 상품 가격예약이 존재합니다.";
			}

			goodsPriceRes.setEndGoodsPrice(goods.getCurrPrice());

			cnt++;
		}

		return "SUCC";
	}

	/**
	 * 상품 동영상 목록 조회
	 *
	 * @param goodsVideo
	 * @return
	 * @author eskim
	 * @since 2020. 11. 16
	 */
	public Collection<GoodsVideo> getGoodsVideoList(GoodsVideo goodsVideo) {
		return goodsDao.getGoodsVideoList(goodsVideo);
	}

	/**
	 * 상품 동영상 삭제로 변경
	 *
	 * @param goodsVideo
	 * @return
	 * @author eskim
	 * @since 2020. 11. 16
	 */
	@Transactional("shopTxnManager")
	public void updateNotUseGoodsVideo(Collection<GoodsVideo> goodsVideos) {
		for (GoodsVideo goodsVideo : goodsVideos) {
			goodsVideo.setUpdNo(TsaSession.getInfo().getUserNo());
			goodsDao.updateNotUseGoodsVideo(goodsVideo);
		}
	}

	/**
	 * 상품동영상 수정/저장
	 *
	 * @param video
	 * @return
	 * @author eskim
	 * @since 2020. 11. 16
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsVideo(GoodsVideo goodsVideo) {
		GoodsSearch goodsSearch = new GoodsSearch();
		goodsSearch.setGoodsCd(goodsVideo.getGoodsCd());
		int goodsCnt = goodsDao.getGoodsListCount(goodsSearch);
		if (goodsCnt <= 0) {
			throw new IllegalStateException(goodsVideo.getGoodsCd() + "의 상품코드를 확인해 주세요.");
		}
		goodsVideo.setRegNo(TsaSession.getInfo().getUserNo());
		goodsVideo.setUpdNo(TsaSession.getInfo().getUserNo());

		if (goodsVideo.getVideoSq() == null || goodsVideo.getVideoSq() == 0) {

			if ("Y".equals(goodsVideo.getVideoGb())) {
				Collection<GoodsVideo> goodsVideoList = goodsDao.getGoodsVideoList(goodsVideo);
				if (goodsVideoList != null && goodsVideoList.size() > 0) {
					GoodsVideo orgingGoodsVideo = goodsVideoList.iterator().next();
					goodsVideo.setVideoSq(orgingGoodsVideo.getVideoSq());
				}
			}
			goodsDao.createGoodsVideo(goodsVideo);

		} else {
			goodsDao.updateGoodsVideo(goodsVideo);
		}
	}

	/**
	 * 상품동영상 엑셀파일 등록
	 *
	 * @param dataList
	 * @return
	 * @author eskim
	 * @since 2020. 11. 16
	 */
	@Transactional("shopTxnManager")
	public int saveExcelGoodsVideo(Collection<GagaMap> dataList) {

		int cnt = 0;

		for (GagaMap map : dataList) {
			GoodsVideo goodsVideo = mapper.convertValue(map, GoodsVideo.class);

			GoodsSearch goodsSearch = new GoodsSearch();
			goodsSearch.setGoodsCd(goodsVideo.getGoodsCd());
			int goodsCnt = goodsDao.getGoodsListCount(goodsSearch);
			if (goodsCnt <= 0) {
				throw new IllegalStateException(goodsVideo.getGoodsCd() + "의 상품코드를 확인해 주세요.");
			}

			Collection<GoodsVideo> goodsVideoList = goodsDao.getGoodsVideoList(goodsVideo);
			if (goodsVideoList != null && goodsVideoList.size() > 0) {
				GoodsVideo orgingGoodsVideo = goodsVideoList.iterator().next();
				goodsVideo.setUpdNo(TsaSession.getInfo().getUserNo());
				goodsVideo.setVideoGb("Y");
				goodsVideo.setDispYn(orgingGoodsVideo.getDispYn());
				goodsDao.updateGoodsVideo(goodsVideo);

			} else {
				goodsVideo.setUpdNo(TsaSession.getInfo().getUserNo());
				goodsVideo.setRegNo(TsaSession.getInfo().getUserNo());
				goodsVideo.setDispYn("Y");
				goodsVideo.setVideoGb("Y");
				goodsDao.createGoodsVideo(goodsVideo);
			}

			cnt++;
		}

		return cnt;
	}

	/**
	 * 상품별 옵션 등록 여부 확인
	 *
	 * @param
	 * @return
	 * @author eskim
	 * @since 2020. 11. 17
	 */
	public int getGoodsOptionCount(Option option) {

		return goodsDao.getGoodsOptionCount(option);
	}

	/**
	 * 상품 가격승인관리 목록 조회
	 *
	 * @param goodsSupplyPrice
	 * @return
	 * @author eskim
	 * @since 2020. 11. 26
	 */
	public Collection<GoodsSupplyPrice> getGoodsSupplyPriceList(GoodsSupplyPrice goodsSupplyPrice) {

		return goodsDao.getGoodsSupplyPriceList(goodsSupplyPrice);
	}

	/**
	 * 상품 가격승인관리 승인 처리
	 *
	 * @param goodsPriceHstList - 상품 가격 승인 목록
	 * @author eskim
	 * @since 2020. 11. 26
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsSupplyPrice(Collection<GoodsSupplyPrice> goodsSupplyPriceList) {

		for (GoodsSupplyPrice goodsSupplyPrice : goodsSupplyPriceList) {
			goodsSupplyPrice.setRegNo(TsaSession.getInfo().getUserNo());
			goodsSupplyPrice.setUpdNo(TsaSession.getInfo().getUserNo());

			Goods goods = new Goods();
			goods.setRegNo(TsaSession.getInfo().getUserNo());
			goods.setUpdNo(TsaSession.getInfo().getUserNo());
			goods.setGoodsCd(goodsSupplyPrice.getGoodsCd());

			goodsDao.createGoodsHst(goods);

			// 판매가 변경
			if (goodsSupplyPrice.getSupplyGoodsPrice() > 0) {
				goods.setDcRate((int)(this.getDcRate(goodsSupplyPrice.getListPrice(), goodsSupplyPrice.getSupplyGoodsPrice())));
				goods.setCurrBprice(goodsSupplyPrice.getCurrPrice());
				goods.setCurrPrice(goodsSupplyPrice.getSupplyGoodsPrice());
				goodsDao.updateGoodsPrice(goods);
			}

			// 판매수수료율 변경
			if (Float.compare(goodsSupplyPrice.getSupplySellFeeRate(), 0) > 0) {
				goods.setSellFeeRate(goodsSupplyPrice.getSupplySellFeeRate());
				goodsDao.updateSellFeeRate(goods);
			}

			goodsDao.updateGoodsSupplyPricecfrmDt(goodsSupplyPrice);
		}
	}

	/**
	 * 상품 네이버 최저가 목록
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 12. 08
	 */
	public Collection<GoodsNaverLowestPrice> getGoodsNaverPriceList(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsNaverPriceList(goodsSearch);
	}

	/**
	 * 상품 네이버 최저가 엑셀다운로드
	 *
	 * @param goodsSearch
	 * @param excelFilenameWithPath - 경로를 포함한 엑셀파일명
	 * @return
	 * @author eskim
	 * @since 2021. 07. 09
	 */
	public void getGoodsNaverExcelList(GoodsSearch goodsSearch, String excelFilenameWithPath) {

		// 헤더 title 설정
		String[] listTitles = {"상품코드", "브랜드명", "상품명", "정상가", "판매가", "자사즉시할인가", "네이버최저가", "차액",
			"최저가몰명", "최저가몰링크"};

		// DB 처리 시 사용되는 파라미터명(셀명) 설정
		String[] cellNames = {"GOODS_CD", "BRAND_ENM", "GOODS_NM", "LIST_PRICE", "CURR_PRICE", "BENEFIT_PRICE", "LOWEST_PRICE", "PRICE",
			"MALL_NM", "MALL_LINK"};

		String[] cellTypes = {
			GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name(),
			GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_RIGHT.name(),
			GagaExcelConstants.CellType.CHAR_RIGHT.name(), GagaExcelConstants.CellType.CHAR_RIGHT.name(),
			GagaExcelConstants.CellType.CHAR_RIGHT.name(), GagaExcelConstants.CellType.CHAR_RIGHT.name(),
			GagaExcelConstants.CellType.CHAR_CENTER.name(), GagaExcelConstants.CellType.CHAR_CENTER.name()};

		Collection<GagaMap> dataList = goodsDao.getGoodsNaverExcelList(goodsSearch);

		try {
			GagaExcelUtil.createExcel(excelFilenameWithPath, dataList, "상품 네이버 가격", listTitles, cellNames, cellTypes, TsaConstants.EXCEL_FOOTER_TITLE);
		} catch (Exception e) {
			throw new IllegalStateException(e);
		}

	}

	/**
	 * 상품 네이버 최저가 목록
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 12. 08
	 */
	@Transactional("shopTxnManager")
	public Collection<GoodsNaverLowestPrice> saveGoodsNaverPrice(GoodsSearch goodsSearch) {

		// 1. 조회 상품 TB_SEARCH_DATA 담기
		int index = 0;
		for (String goodsCd : goodsSearch.getConditionList()) {

			SearchData searchData = new SearchData();
			searchData.setRegNo(TsaSession.getInfo().getUserNo());
			searchData.setSearchCd(goodsCd);
			if (index == 0) {
				commonService.deleteExceluploadSearCh(searchData);
			}

			commonService.createExceluploadSearch(searchData);
			index++;
		}

		// 2. 일 최초 조회이면 테이블 삭제
		String regYmd = goodsDao.getGoodsNaverLowestPriceReqYmd();
		if (!StringUtils.isBlank(regYmd) && !regYmd.equals(GagaDateUtil.getToday())) {
			goodsDao.deleteGoodsNaverLowestPrice();
		}

		// 3. 네이버 최저가 조회 저장
		saveGoodsNaverLowestPrice(goodsSearch);

		// 4. 최저가 상품 조회
		goodsSearch.setSearchGb("EXCEL");
		goodsSearch.setRegNo(TsaSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		return goodsDao.getGoodsNaverPriceList(goodsSearch);
	}

	/**
	 * 상품 네이버 최저가 목록
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 12. 08
	 */
	private void saveGoodsNaverLowestPrice(GoodsSearch goodsSearch) {

		for (String goodsCd : goodsSearch.getConditionList()) {
			try {
				//log.info("saveGoodsNaverLowestPrice  11 =  {}", GagaDateUtil.getTodayDateTime());
				TaskSleeep();
				//log.info("saveGoodsNaverLowestPrice  22 =  {}", GagaDateUtil.getTodayDateTime());
				NaverLowestPrice naverLowestPrice = naverLowestPriceApi.getLowestPrice(goodsCd);

				//log.info("[saveGoodsNaverLowestPrice] naverLowestPrice= {}", naverLowestPrice);
				if (naverLowestPrice != null && naverLowestPrice.getTotal() > 0) {
					GoodsNaverLowestPrice goodsNaverLowestPrice = new GoodsNaverLowestPrice();
					goodsNaverLowestPrice.setReqYmd(GagaDateUtil.getToday());
					goodsNaverLowestPrice.setGoodsCd(goodsCd);
					goodsNaverLowestPrice.setMallNm(naverLowestPrice.getItems().iterator().next().getMallName());
					goodsNaverLowestPrice.setMallLink(naverLowestPrice.getItems().iterator().next().getLink());
					goodsNaverLowestPrice.setLowestPrice(Integer.parseInt(naverLowestPrice.getItems().iterator().next().getLprice().toString()));
					goodsNaverLowestPrice.setRegNo(TsaSession.getInfo().getUserNo());
					goodsNaverLowestPrice.setUpdNo(TsaSession.getInfo().getUserNo());
					//log.info("[saveGoodsNaverLowestPrice] goodsNaverLowestPrice= {}", goodsNaverLowestPrice);
					goodsDao.saveGoodsNaverLowestPrice(goodsNaverLowestPrice);

				}

			} catch (Exception e) {
				e.printStackTrace();
			}

		}

	}

	/**
	 *
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 12. 08
	 */
	static void TaskSleeep() {
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 광고 키워드 목록
	 *
	 * @param adKeyword
	 * @return
	 * @author eskim
	 * @since 2020. 12. 15
	 */
	public Collection<AdKeyword> getAdKeywordList(AdKeyword adKeyword) {
		return goodsDao.getAdKeywordList(adKeyword);
	}

	/**
	 * 광고 키워드 상품 목록
	 *
	 * @param adKeyword
	 * @return
	 * @author eskim
	 * @since 2020. 12. 15
	 */
	public Collection<AdKeywordGoods> getAdKeywordGoodsList(AdKeyword adKeyword) {
		return goodsDao.getAdKeywordGoodsList(adKeyword);
	}

	/**
	 * 광고 키워드 저장
	 * @param adKeyword
	 * @return
	 * @author eskim
	 * @since 2020. 12. 15
	 */
	@Transactional("shopTxnManager")
	public void saveAdKeywordGoods(AdKeyword adKeyword) {
		adKeyword.setRegNo(TsaSession.getInfo().getUserNo());
		adKeyword.setUpdNo(TsaSession.getInfo().getUserNo());

		// 신규 일때
		if (adKeyword.getAdKeywordSq() == null) {
			// 공지사항 저장
			goodsDao.saveAdKeyword(adKeyword);

			// 등록된 사용자번호 값 가져오기
			Integer noticeSq = adKeyword.getAdKeywordSq();

			adKeyword.setAdKeywordSq(noticeSq);

		} else {
			// 공지사항 수정
			goodsDao.saveAdKeyword(adKeyword);
		}

		if (!StringUtils.isBlank(adKeyword.getGoodsList())) {
			Collection<AdKeywordGoods> adKeywordGoodsList = null;
			try {
				adKeywordGoodsList = mapper.readValue(adKeyword.getGoodsList(), new TypeReference<Collection<AdKeywordGoods>>() {
				});
			} catch (Exception e) {
				e.printStackTrace();
				throw new IllegalStateException(message.getMessage("광고 키워드 저장 중 오류로 인해 저장되지 않았습니다."));
			}
			//log.info("adKeywordGoodsList: {}", adKeywordGoodsList);

			int idx = 0;
			for (AdKeywordGoods adKeywordGoods : adKeywordGoodsList) {
				if (idx == 0) {
					goodsDao.deleteAdKeywordGoods(adKeywordGoods); // 전체 상품 삭제
				}
				adKeywordGoods.setAdKeywordSq(adKeyword.getAdKeywordSq());
				adKeywordGoods.setRegNo(TsaSession.getInfo().getUserNo());
				adKeywordGoods.setUpdNo(TsaSession.getInfo().getUserNo());

				goodsDao.saveAdKeywordGoods(adKeywordGoods);
				idx++;
			}
		}
	}

	/**
	 * 광고 키워드 상품 삭제
	 * @param adKeywordGoods
	 * @return
	 * @author eskim
	 * @since 2020. 12. 15
	 */
	@Transactional("shopTxnManager")
	public void deleteAdKeywordGoods(AdKeywordGoods adKeywordGoods) {

		if (adKeywordGoods == null || (adKeywordGoods.getArrGoodsCd() == null && adKeywordGoods.getArrGoodsCd().length <= 0)) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		if (adKeywordGoods.getArrGoodsCd().length > 0) {
			goodsDao.deleteAdKeywordGoods(adKeywordGoods);
		}
	}

	/**
	 * 재입고알림 목록 건수
	 *
	 * @param goodsSearch
	 * @return Integer
	 * @author eskim
	 * @since 2020. 12. 16
	 */
	public int getReinboundInformCount(GoodsSearch goodsSearch) {
		return goodsDao.getReinboundInformCount(goodsSearch);
	}

	/**
	 * 재입고알림 목록
	 *
	 * @param goodsSearch
	 * @return Collection<ReinboundInform>
	 * @author eskim
	 * @since 2020. 12. 16
	 */
	public Collection<ReinboundInform> getReinboundInformList(GoodsSearch goodsSearch) {
		return goodsDao.getReinboundInformList(goodsSearch);
	}

	/**
	 * 재입고알림 발송 처리
	 *
	 * @param params
	 * @return void
	 * @author daehyoung
	 * @since 2020. 07 .21
	 */
	@Transactional("shopTxnManager")
	public void sendReinboundInform(ReinboundInform reinboundInform) {
		goodsDao.updateReinboundInform(reinboundInform);
	}

	/**
	 * 상품이미지 목록
	 *
	 * @param goodsImg
	 * @return Collection<GoodsImg>
	 * @author eskim
	 * @since 2020. 12. 18
	 */
	public Collection<GoodsImg> getGoodsImgList(GoodsImg goodsImg) {
		return goodsDao.getGoodsImageList(goodsImg);
	}

	/**
	 * 상품이미지 저장 처리
	 * @param goodsImgList - 상품이미지 목록
	 * @throws AdmBizException
	 * @author eskim
	 * @since 2020. 12. 21
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsImageList(Collection<GoodsImg> goodsImgList) {
		int index = 0;
		for (GoodsImg goodsImg : goodsImgList) {
			// 상품이미지 전체 삭제
			if (index++ == 0) {
				goodsDao.deleteGoodsImageTotal(goodsImg);
			}

			if (!goodsImg.getMode().equals("D")) {
				// 상품이미지 등록
				goodsImg.setRegNo(TsaSession.getInfo().getUserNo());
				goodsDao.createGoodsImage(goodsImg);
			}
		}
	}

	/**
	 * 사은품 목록
	 *
	 * @param goodsSearch
	 * @return Collection<FreeGoods>
	 * @author eskim
	 * @since 2020. 12. 28
	 */
	public Collection<FreeGoods> getFreeGoodsList(GoodsSearch goodsSearch) {
		return goodsDao.getFreeGoodsList(goodsSearch);
	}

	/**
	 * 사은품 정보 수정
	 * @param goodsImgList - 상품이미지 목록
	 * @throws AdmBizException
	 * @author eskim
	 * @since 2020. 12. 21
	 */
	@Transactional("shopTxnManager")
	public void updateFreeGoods(FreeGoods freeGoods) {

		freeGoods.setUpdNo(TsaSession.getInfo().getUserNo());
		goodsDao.updateFreeGoods(freeGoods);
	}

	/**
	 * WMS입고상품관리 목록 건수
	 *
	 * @param goodsSearch
	 * @return Collection<WmsGoods>
	 * @author eskim
	 * @since 2021. 01. 04
	 */
	public int getGoodsWmsIncomelotListCount(WmsGoods wmsGoods) {
		return goodsDao.getGoodsWmsIncomelotListCount(wmsGoods);
	}

	/**
	 * WMS입고상품관리 목록 조회
	 *
	 * @param goodsSearch
	 * @return Collection<WmsGoods>
	 * @author eskim
	 * @since 2021. 01. 04
	 */
	public Collection<WmsGoods> getGoodsWmsIncomelotList(WmsGoods wmsGoods) {
		return goodsDao.getGoodsWmsIncomelotList(wmsGoods);
	}

	/**
	 * WMS 입고상품 사은품 등록
	 * @param wmsGoodsList
	 * @author eskim
	 * @since 2021. 01. 05
	 */
	@Transactional("shopTxnManager")
	public void saveFreeGoods(Collection<WmsGoods> wmsGoodsList) {

		for (WmsGoods wmsGoods : wmsGoodsList) {
			FreeGoods freeGoods = new FreeGoods();
			freeGoods.setProductNo(wmsGoods.getProductNo());
			freeGoods.setProductCode(wmsGoods.getProductCode());
			freeGoods.setGoodsNm(wmsGoods.getProductName());
			freeGoods.setBrandCd(wmsGoods.getBrandCd());
			freeGoods.setUseYn("Y");
			freeGoods.setUpdNo(TsaSession.getInfo().getUserNo());
			freeGoods.setRegNo(TsaSession.getInfo().getUserNo());
			goodsDao.saveFreeGoods(freeGoods);

			//WMS 상품등록구분
			wmsGoods.setGoodsRegGb("F");
			wmsGoods.setUpdNo(TsaSession.getInfo().getUserNo());
			wmsGoods.setRegNo(TsaSession.getInfo().getUserNo());
			goodsDao.saveGoodsWmsIncomelot(wmsGoods);
		}
	}

	/**
	 * 고시분류별 상품고시정보 목록
	 * @param goodsNotiInfo - 상품고시정보
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 21
	 */
	public Collection<GoodsNotiInfo> getGoodsNotiInfoListByNotiClsf(GoodsNotiInfo goodsNotiInfo) {
		return goodsDao.getGoodsNotiInfoListByNotiClsf(goodsNotiInfo);
	}

	/**
	 * 고시분류 칼럼 정보
	 * @param niClsfCd - 고시분류코드
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 21
	 */
	public GoodsNotiInfo getNotiClsfColumnInfo(String niClsfCd) {
		return goodsDao.getNotiClsfColumnInfo(niClsfCd);
	}

	/**
	 * 상품대량수정 엑셀 저장
	 *
	 * @param ecxelGoodsList, procJob(updateGoods)
	 * @return
	 * @author eskim
	 * @since 2021. 01. 25
	 */
	@Transactional("shopTxnManager")
	public String updateMassExceluploadGoods(GagaMap gagaMap, String procJob) {

		GoodsMass goodsMass = mapper.convertValue(gagaMap, GoodsMass.class);

		if (StringUtils.isBlank(goodsMass.getGoodsCd())) {
			throw new IllegalStateException("상품코드는 필수입니다.");
		}

		// 상품기본정보
		Goods goodsData = new Goods();
		goodsData.setGoodsCd(goodsMass.getGoodsCd().trim().toUpperCase());
		Goods goodsOrigin = goodsDao.getGoods(goodsData);
		if (goodsOrigin == null) {
			goodsData.setGoodsRegMsg("미등록 상품코드");
			goodsData.setGoodsStat("10");
			this.setGoodsRegResult(goodsData, goodsMass, procJob);
			return goodsData.getGoodsStat();
		}
		Goods goods = this.updateMassGoodsInfo(goodsMass, procJob, goodsOrigin);

		if ("10".equals(goods.getGoodsStat())) { // 정보 오류
			this.setGoodsRegResult(goods, goodsMass, procJob);
			return goods.getGoodsStat();
		}

		// 옵션
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getOptStr().trim())) {
			goods.setGoodsRegMsg("옵션은 변경할 수 없습니다.");
			goods.setGoodsStat("10");
			this.setGoodsRegResult(goods, goodsMass, procJob);
			return goods.getGoodsStat();
		}

		// 상품 고시
		Collection<GoodsNotiInfo> newGoodsNotiList = new ArrayList<>(); //적용할 고시 정보
		goods = this.getUpdateMassGoodsNotiCheck(goods, gagaMap, goodsOrigin, newGoodsNotiList);
		if ("10".equals(goods.getGoodsStat())) { // 정보 오류
			this.setGoodsRegResult(goods, goodsMass, procJob);
			return goods.getGoodsStat();
		}

		// 상품상세 (html, as-is/입점) - 일반상품만 적용
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getGoodsContent().trim()) && "G056_N".equals(goodsOrigin.getGoodsType())) {
			if (goodsMass.getGoodsContent().toLowerCase().indexOf("script") >= 0) {
				goods.setGoodsRegMsg("상품상세 html script 선언 오류");
				goods.setGoodsStat("10");
				this.setGoodsRegResult(goods, goodsMass, procJob);
				return goods.getGoodsStat();
			}
			goods.setChkDescKeep("Y");
		}

		if ("N".equals(goods.getChDataYn()) && "N".equals(goods.getChkDescKeep()) && "N".equals(goods.getChNotiYn())) {
			goods.setGoodsRegMsg("변경정보 없음");
			goods.setGoodsStat("10");
			this.setGoodsRegResult(goods, goodsMass, procJob);
			return goods.getGoodsStat();
		}

		//상품 기본정보 변경여부 와 촬영업체가 아닌경우
		if ("Y".equals(goods.getChDataYn()) && !"G001_E000".equals(TsaSession.getInfo().getRoleCd())) {

			goodsDao.createGoodsHst(goods); // 이력생성
			goodsDao.updateGoodsMass(goods); // 상품기본 저장

			if (!StringUtils.isBlank(goods.getGoodsSnm1()) && !UPDATE_NO_PATTERN.equals(goods.getGoodsSnm1())) {
				// 사용자 검색어를 검색어에 적용
				String goodsSnm = goodsDao.getGoodsSnm(goods.getGoodsCd());

				String[] arrGoodsSnm = goods.getGoodsSnm1().split("\\;");
				StringBuilder tempGoodsSnm = new StringBuilder();
				for (String loopGoodsSnm : arrGoodsSnm) {
					if (goodsSnm.toUpperCase().indexOf(loopGoodsSnm.toUpperCase()) <= -1) {
						tempGoodsSnm.append(loopGoodsSnm).append(";");
					}
				}
				goods.setGoodsSnm(tempGoodsSnm.toString() + goodsSnm);
				goodsDao.updateGoodsSnm(goods);
			}
		}

		//상품 상세 변경여부 와 촬영업체가 아닌경우
		if ("Y".equals(goods.getChkDescKeep()) && !"G001_E000".equals(TsaSession.getInfo().getRoleCd()) && "G056_N".equals(goodsOrigin.getGoodsType())) {
			GoodsDesc goodsDesc = new GoodsDesc();
			goodsDesc.setGoodsCd(goods.getGoodsCd());
			goodsDesc.setRegNo(goods.getRegNo());
			goodsDesc.setUpdNo(goods.getUpdNo());

			goodsDesc.setDescGb("80");
			goodsDesc.setGoodsDesc(goodsMass.getGoodsContent().trim());
			this.saveGoodsDesc(goodsDesc);
		}

		// 상품고시정보 적용
		if ("Y".equals(goods.getChNotiYn()) && newGoodsNotiList != null && !newGoodsNotiList.isEmpty()) {

			int index = 0;
			for (GoodsNotiInfo goodsNotiInfo : newGoodsNotiList) {

				if (index == 0) {
					goodsDao.deleteGoodsNotiInfo(goods);
				}
				goodsDao.saveGoodsNotiInfo(goodsNotiInfo);
				index++;
			}
		}

		// 품목변경시 카테고리 자동 전시
		if (!UPDATE_NO_PATTERN.equals(goods.getItemkindCd().trim())) {
			GoodsCategory goodsCategory = new GoodsCategory();
			goodsCategory.setRegNo(TsaSession.getInfo().getUserNo());
			goodsCategory.setUpdNo(TsaSession.getInfo().getUserNo());
			goodsCategory.setGoodsCd(goods.getGoodsCd());
			goodsCategory.setCateType("G031_10");	//상품분류카테고리
			displayService.deleteGoodsCategory(goodsCategory);
			goodsDao.createCategoryGoods(goods);

		}

		this.setGoodsRegResult(goods, goodsMass, procJob);

		return goods.getGoodsStat();
	}

	/**
	 * 상품 대량 등록 결과 정보
	 *
	 * @param goods
	 * @author eskim
	 * @since 2021. 01. 25
	 */
	private void setGoodsRegResult(Goods goods, GoodsMass goodsMass, String procJob) {
		// 결과 저장
		goodsMass.setBrandCd(goods.getBrandCd());
		goodsMass.setGoodsStat(goods.getGoodsStat());
		goodsMass.setRegSuccYn("Y");
		goodsMass.setRegFailRsn(goods.getGoodsRegMsg());
		goodsMass.setRegNo(TsaSession.getInfo().getUserNo());
		//model은 string 테이블은 number 형이라 ,,,
//		if (StringUtils.isBlank(goodsMass.getListPrice())) {
//			goodsMass.setListPrice("0");
//		}
//		if (UPDATE_NO_PATTERN.equals(goodsMass.getCurrPrice()) || StringUtils.isBlank(goodsMass.getCurrPrice())) {
//			goodsMass.setCurrPrice("0");
//		}
//		if (StringUtils.isBlank(goodsMass.getCostPrice())) {
//			goodsMass.setCostPrice("0");
//		}
//		if ("10".equals(goods.getGoodsStat())) {
//			goodsMass.setRegSuccYn("N");
//		}
		goodsMass.setProcGb("C");
		if ("updateGoods".equals(procJob)) {
			goodsMass.setProcGb("U");
		}
		goodsDao.createGoodsRegLog(goodsMass);
	}

	/**
	 * 상품대량수정 - 상품기본정보
	 *
	 * @param goodsMass
	 * @param excelFilename
	 * @author eskim
	 * @since 2021. 1. 20
	 */
	private Goods updateMassGoodsInfo(GoodsMass goodsMass, String procJob, Goods goodsOrigin) {

		Goods goods = new Goods();
		goods.setChDataYn("N"); // 데이터 변경여부
		goods.setGoodsRegMsg("상품정보 변경");
		goods.setRegNo(TsaSession.getInfo().getUserNo());
		goods.setUpdNo(TsaSession.getInfo().getUserNo());

		goods.setGoodsCd(goodsMass.getGoodsCd().toUpperCase().trim().toUpperCase()); // 상품코드

		if (StringUtils.isBlank(goodsMass.getGoodsNm())) {
			goods.setGoodsRegMsg("상품명 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setGoodsNm(goodsMass.getGoodsNm().trim()); // 상품명
		if (!UPDATE_NO_PATTERN.equals(goods.getGoodsNm())) {
			goods.setGoodsNm(goods.getGoodsNm().replaceAll("(\\r\\n|\\r|\\n|\\n\\r)", "")); // 상품명
			goods.setChDataYn("Y");
		}
		goods.setGoodsTnm(goodsMass.getGoodsTnm().trim()); // 상품 타이틀
		if (!UPDATE_NO_PATTERN.equals(goods.getGoodsTnm())) {
			goods.setChDataYn("Y");
			if (!StringUtils.isBlank(goods.getGoodsTnm())) {
				goods.setGoodsTnm(goods.getGoodsTnm().replaceAll("(\\r\\n|\\r|\\n|\\n\\r)", "")); // 상품 타이틀
			}
		}
		goods.setGoodsSnm1(goodsMass.getGoodsSnm1().trim()); // 상품 사용자 검색어
		if (!UPDATE_NO_PATTERN.equals(goods.getGoodsSnm1())) {
			goods.setChDataYn("Y");
			if (!StringUtils.isBlank(goods.getGoodsSnm1())) {
				goods.setGoodsSnm1(goods.getGoodsSnm1().replaceAll("(\\r\\n|\\r|\\n|\\n\\r|\\s)", "")); // 상품 사용자 검색어
			}
		}
		// 품목확인
		if (StringUtils.isBlank(goodsMass.getItemkindCd())) {
			goods.setGoodsRegMsg("품목코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setItemkindCd(goodsMass.getItemkindCd().trim().toUpperCase()); // 품목

		if (!UPDATE_NO_PATTERN.equals(goods.getItemkindCd())) {
			Itemkind itemkind = new Itemkind();
			itemkind.setItemkindCd(goods.getItemkindCd());
			itemkind.setUseYn("Y");
			Collection<Itemkind> itemkindList = goodsDao.getItemkindList(itemkind);
			if (itemkindList == null || itemkindList.isEmpty()) {
				goods.setGoodsRegMsg("품목 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}

		CommonCode commonCode = new CommonCode();
		commonCode.setUseYn("Y");
		// 시즌코드
		if (StringUtils.isBlank(goodsMass.getSeasonCd())) {
			goods.setGoodsRegMsg("시즌코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setSeasonCd(goodsMass.getSeasonCd().trim().toUpperCase());
		if (!UPDATE_NO_PATTERN.equals(goods.getSeasonCd())) {
			commonCode.setCdGb("G006"); // 시즌
			commonCode.setCd(goods.getSeasonCd());
			Collection<CommonCode> seassonList = rendererService.getCommonCodeList(commonCode);
			if (seassonList == null || seassonList.isEmpty()) {
				goods.setGoodsRegMsg("시즌 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}
		// 성별
		if (StringUtils.isBlank(goodsMass.getSexGb())) {
			goods.setGoodsRegMsg("성별코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setSexGb(goodsMass.getSexGb().trim().toUpperCase());
		// 성별
		if (!UPDATE_NO_PATTERN.equals(goods.getSexGb())) {
			commonCode.setCdGb("G007"); // 성별
			commonCode.setCd(goods.getSexGb());
			Collection<CommonCode> genderList = rendererService.getCommonCodeList(commonCode);
			if (genderList == null || genderList.isEmpty()) {
				goods.setGoodsRegMsg("성별 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}
		//판매가
		if (StringUtils.isBlank(goodsMass.getCurrPrice())) {
			goods.setGoodsRegMsg("판매가 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		if (UPDATE_NO_PATTERN.equals(goodsMass.getCurrPrice().trim())) {
			goods.setCurrPrice(0);
		} else {

			if (!GagaStringUtil.replace(goodsMass.getCurrPrice().trim(), ",", "").matches(NUMBER_PATTERN)) {
				goods.setGoodsRegMsg("판매가 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			if (Integer.parseInt(goodsMass.getCurrPrice().trim()) == 0) {
				goods.setGoodsRegMsg("판매가 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		}
		//판매수수료율
		if (StringUtils.isBlank(goodsMass.getSellFeeRate())) {
			goods.setGoodsRegMsg("판매수수료율 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		float sellFeeRate = 0f;
		if (UPDATE_NO_PATTERN.equals(goodsMass.getSellFeeRate().trim())) {
			goods.setSellFeeRate(0);
		} else {
			try {
				sellFeeRate = Float.valueOf(goodsMass.getSellFeeRate().trim());
				//goods.setSellFeeRate(sellFeeRate);
			} catch (Exception e) {
				goods.setGoodsRegMsg("판매수수료율 오류");
				goods.setGoodsStat("10");
				return goods;
			}

			//비교값 크면 1, 같으면 0, 작은면 -1 리턴
			if (Float.compare(sellFeeRate, 0) == 0) {
				goods.setGoodsRegMsg("판매수수료율 오류");
				goods.setGoodsStat("10");
				return goods;
			}

			if (Float.compare(sellFeeRate, 100) >= 0) {
				goods.setGoodsRegMsg("판매수수료율 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		}

		//판매가나 판매수수료율이 변경되었을 때
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getCurrPrice().trim()) || !UPDATE_NO_PATTERN.equals(goodsMass.getSellFeeRate().trim())) {
			//자사
			if ("Y".equals(goodsOrigin.getSelfGoodsYn())) {
				//판매가 변경시
				if (!UPDATE_NO_PATTERN.equals(goodsMass.getCurrPrice().trim())) {
					goods.setCurrPrice(Integer.parseInt(GagaStringUtil.replace(goodsMass.getCurrPrice().trim(), ",", ""))); // 판매가
					goods.setCurrBprice(goodsOrigin.getCurrPrice());
					goods.setDcRate((int)(this.getDcRate(goodsOrigin.getListPrice(), goods.getCurrPrice())));
					goods.setChDataYn("Y");
				}
				//판매수수료율 변경시
				if (!UPDATE_NO_PATTERN.equals(goodsMass.getSellFeeRate().trim())) {
					goods.setSellFeeRate(sellFeeRate); // 판매수수료율
					goods.setChDataYn("Y");
				}
			} else {
				//입점
				GoodsPriceRes goodsPriceRes = new GoodsPriceRes();
				goodsPriceRes.setGoodsCd(goods.getGoodsCd());
				if (goods.getCurrPrice() != goodsOrigin.getCurrPrice()) {
					goodsPriceRes.setResGoodsPrice(goods.getCurrPrice());
					goodsPriceRes.setEndGoodsPrice(goods.getCurrPrice());
				}
				if (goods.getSellFeeRate() != goodsOrigin.getSellFeeRate()) {
					goodsPriceRes.setSellFeeRate(sellFeeRate);
				}
				goodsPriceRes.setApplyStdt(GagaDateUtil.getTodayDateTime());	//yyyymmddhhmiss
				int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) + 4;
				goodsPriceRes.setApplyEddt(Integer.toString(toYear) + "1231235959");	//yyyymmddhhmiss
				goodsPriceRes.setCfrmYn("N");
				goodsPriceRes.setApplyYn("N");
				goodsPriceRes.setRegNo(goods.getRegNo());
				goodsPriceRes.setUpdNo(goods.getUpdNo());
				goodsDao.createGoodPriceRes(goodsPriceRes);

				// 상품테이블에 바로 변경하지 않고 입점상품가격관리에서 승인해야함
				goods.setCurrPrice(goodsOrigin.getCurrPrice());
				goods.setSellFeeRate(goodsOrigin.getSellFeeRate());
			}
		}

		// 상품구분
		if (StringUtils.isBlank(goodsMass.getGoodsGb())) {
			goods.setGoodsRegMsg("상품구분 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setGoodsGb(goodsMass.getGoodsGb().trim().toUpperCase());
		// 상품구분
		if (!UPDATE_NO_PATTERN.equals(goods.getGoodsGb())) {
			commonCode.setCdGb("G073"); // 상품구분
			commonCode.setCd(goods.getGoodsGb());
			Collection<CommonCode> goodsGbList = rendererService.getCommonCodeList(commonCode);
			if (goodsGbList == null || goodsGbList.isEmpty()) {
				goods.setGoodsRegMsg("상품구분 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}

		//정상이월구분
		if (StringUtils.isBlank(goodsMass.getFormalGb())) {
			goods.setGoodsRegMsg("정상이월구분 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setFormalGb(goodsMass.getFormalGb().trim().toUpperCase()); // 정상이월
		if (!UPDATE_NO_PATTERN.equals(goods.getFormalGb())
			&& !"G009_10".equals(goods.getFormalGb())
			&& !"G009_20".equals(goods.getFormalGb())) {
			goods.setGoodsRegMsg("정상이월구분 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		if (!UPDATE_NO_PATTERN.equals(goods.getFormalGb())) {
			goods.setPntPrate(goodsOrigin.getPntPrate()); // 포인트적립율(PC)
			goods.setPntMrate(goodsOrigin.getPntMrate()); // 포인트적립율(MOBILE)
			Brand brand = new Brand();
			brand.setBrandCd(goodsOrigin.getBrandCd());
			Collection<Brand> brandList = businessService.getBrandList(brand);
			if (brandList != null && !brandList.isEmpty()) {
				// 브랜드 확인
				float pntPrate = 0f;
				float pntMrate = 0f;
				for (Brand tmpBrand : brandList) {
					if ("G009_10".equals(goods.getFormalGb())) {
						pntPrate = tmpBrand.getPntPrate10();
						pntMrate = tmpBrand.getPntMrate10();
					} else {
						pntPrate = tmpBrand.getPntPrate20();
						pntMrate = tmpBrand.getPntMrate20();
					}
				}
				goods.setPntPrate(pntPrate); // 포인트적립율(PC)
				goods.setPntMrate(pntMrate); // 포인트적립율(MOBILE)
			}
			goods.setChDataYn("Y");
		}

		//최소주문수량
		if (UPDATE_NO_PATTERN.equals(goodsMass.getMinOrdQty().trim())) {
			goods.setMinOrdQty(0);
		} else {
			if (!goodsMass.getMinOrdQty().trim().matches(NUMBER_PATTERN) || Integer.parseInt(goodsMass.getMinOrdQty().trim()) == 0) {
				goods.setGoodsRegMsg("최소주문수량 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setMinOrdQty(Integer.parseInt(goodsMass.getMinOrdQty().trim()));
			goods.setChDataYn("Y");
		}
		//최대주문수량
		if (UPDATE_NO_PATTERN.equals(goodsMass.getMaxOrdQty().trim())) {
			goods.setMaxOrdQty(0);
		} else {
			if (!goodsMass.getMaxOrdQty().trim().matches(NUMBER_PATTERN) || Integer.parseInt(goodsMass.getMaxOrdQty().trim()) == 0) {
				goods.setGoodsRegMsg("최대주문수량 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setMaxOrdQty(Integer.parseInt(goodsMass.getMaxOrdQty().trim()));
			goods.setChDataYn("Y");
		}
		//ID당1일최대주문수량
		if (UPDATE_NO_PATTERN.equals(goodsMass.getDayMaxOrdQty().trim())) {
			goods.setMaxOrdQty(0);
		} else {
			if (!goodsMass.getDayMaxOrdQty().trim().matches(NUMBER_PATTERN) || Integer.parseInt(goodsMass.getDayMaxOrdQty().trim()) == 0) {
				goods.setGoodsRegMsg("ID당1일최대주문수량 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setDayMaxOrdQty(Integer.parseInt(goodsMass.getDayMaxOrdQty().trim()));
			goods.setChDataYn("Y");
		}

		if (goods.getMinOrdQty() > goods.getMaxOrdQty()) {
			goods.setGoodsRegMsg("최소주문수량 오류(최대주문수량보다 클 수 없음)");
			goods.setGoodsStat("10");
			return goods;
		}

		if (goods.getMaxOrdQty() > goods.getDayMaxOrdQty()) {
			goods.setGoodsRegMsg("최대주문수량 오류(ID당1일최대구매수량보다 클 수 없음)");
			goods.setGoodsStat("10");
			return goods;
		}

		//선물주문가능여부
		if (StringUtils.isBlank(goodsMass.getGiftPackYn())) {
			goods.setGoodsRegMsg("선물주문가능여부 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		if ("Y".equals(goodsOrigin.getSelfGoodsYn())) {
			if (!UPDATE_NO_PATTERN.equals(goodsMass.getGiftPackYn().trim().toUpperCase())) {
				goods.setGiftPackYn(goodsMass.getGiftPackYn().trim().toUpperCase());
				if (!"Y".equals(goods.getGiftPackYn()) && !"N".equals(goods.getGiftPackYn())) {
					goods.setGoodsRegMsg("선물주문가능여부 오류");
					goods.setGoodsStat("10");
					return goods;
				}
				goods.setChDataYn("Y");
			}
		} else {
			goods.setGiftPackYn(goodsOrigin.getGiftPackYn().trim().toUpperCase());
		}

		//신규가입구매가능여부
		if (StringUtils.isBlank(goodsMass.getNewCustOrdYn())) {
			goods.setGoodsRegMsg("신규가입구매가능여부 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		if ("Y".equals(goodsOrigin.getSelfGoodsYn())) {
			if (!UPDATE_NO_PATTERN.equals(goodsMass.getNewCustOrdYn().trim().toUpperCase())) {
				goods.setNewCustOrdYn(goodsMass.getNewCustOrdYn().trim().toUpperCase());
				if (!"Y".equals(goods.getNewCustOrdYn()) && !"N".equals(goods.getNewCustOrdYn())) {
					goods.setGoodsRegMsg("신규가입구매가능여부 오류");
					goods.setGoodsStat("10");
					return goods;
				}
				goods.setChDataYn("Y");
			}
		} else {
			goods.setNewCustOrdYn(goodsOrigin.getNewCustOrdYn().toUpperCase());
		}

		//반품여부
		if (StringUtils.isBlank(goodsMass.getReturnableYn())) {
			goods.setGoodsRegMsg("반품여부 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setReturnableYn(goodsMass.getReturnableYn().trim().toUpperCase());
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getReturnableYn().trim())) {
			if (!"Y".equals(goods.getReturnableYn()) && !"N".equals(goods.getReturnableYn())) {
				goods.setGoodsRegMsg("반품여부 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}

		//교환여부
		if (StringUtils.isBlank(goodsMass.getChangeableYn())) {
			goods.setGoodsRegMsg("교환여부 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setChangeableYn(goodsMass.getChangeableYn().trim().toUpperCase());
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getChangeableYn().trim())) {
			if (!"Y".equals(goods.getChangeableYn()) && !"N".equals(goods.getChangeableYn())) {
				goods.setGoodsRegMsg("교환여부 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}

		//과세구분
		if (StringUtils.isBlank(goodsMass.getTaxGb())) {
			goods.setGoodsRegMsg("과세구분 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setTaxGb(goodsMass.getTaxGb().trim().toUpperCase());
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getTaxGb().trim())) {
			if (!"10".equals(goods.getTaxGb()) && !"20".equals(goods.getTaxGb()) && !"30".equals(goods.getTaxGb())) {
				goods.setGoodsRegMsg("과세구분 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}

		//상품연령
		if (StringUtils.isBlank(goodsMass.getAgeGrpCd())) {
			goods.setGoodsRegMsg("상품연령 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setAgeGrpCd(goodsMass.getAgeGrpCd().trim().toUpperCase());
		if (!UPDATE_NO_PATTERN.equals(goods.getAgeGrpCd())) {
			commonCode.setCdGb("G023");
			commonCode.setCd(goods.getAgeGrpCd());
			Collection<CommonCode> ageGrpCdList = rendererService.getCommonCodeList(commonCode);
			if (ageGrpCdList == null || ageGrpCdList.isEmpty()) {
				goods.setGoodsRegMsg("상품연령 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}

		//성인용품여부
		if (StringUtils.isBlank(goodsMass.getAdultYn())) {
			goods.setGoodsRegMsg("성인용품여부 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setAdultYn(goodsMass.getAdultYn().trim().toUpperCase());
		if (!UPDATE_NO_PATTERN.equals(goods.getAdultYn())) {
			if (!"Y".equals(goods.getAdultYn()) && !"N".equals(goods.getAdultYn())) {
				goods.setGoodsRegMsg("성인용품여부 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}

		//PC포인트적립율
		if (StringUtils.isBlank(goodsMass.getPntPrate())) {
			goods.setGoodsRegMsg("PC포인트적립율 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getPntPrate().trim())) {
			try {
				float pntPrate = Float.valueOf(goodsMass.getPntPrate().trim());
				goods.setPntPrate(pntPrate);
			} catch (Exception e) {
				goods.setGoodsRegMsg("PC포인트적립율 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}

		if (StringUtils.isBlank(goodsMass.getPrePpntUsableYn())) {
			goods.setGoodsRegMsg("PC선포인트 사용여부 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getPrePpntUsableYn().trim())) {
			if ("Y".equals(goodsMass.getPrePpntUsableYn().trim()) || "N".equals(goodsMass.getPrePpntUsableYn().trim())) {
				goods.setPrePpntUsableYn(goodsMass.getPrePpntUsableYn().trim());
				goods.setChDataYn("Y");
			} else {
				goods.setGoodsRegMsg("PC선포인트 사용여부 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		}

		if (StringUtils.isBlank(goodsMass.getPntMrate())) {
			goods.setGoodsRegMsg("모바일포인트적립율 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getPntMrate().trim())) {
			try {
				int pntMrate = Integer.parseInt(goodsMass.getPntMrate().trim());
				goods.setPntMrate(pntMrate);
			} catch (Exception e) {
				goods.setGoodsRegMsg("모바일포인트적립율 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setChDataYn("Y");
		}

		if (StringUtils.isBlank(goodsMass.getPreMpntUsableYn())) {
			goods.setGoodsRegMsg("모바일선포인트 사용여부 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getPreMpntUsableYn().trim())) {
			if ("Y".equals(goodsMass.getPreMpntUsableYn().trim()) || "N".equals(goodsMass.getPreMpntUsableYn().trim())) {
				goods.setPreMpntUsableYn(goodsMass.getPreMpntUsableYn().trim());
				goods.setChDataYn("Y");
			} else {
				goods.setGoodsRegMsg("모바일선포인트 사용여부 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		}

		// 배송비 정책 확인
		if (StringUtils.isBlank(goodsMass.getDelvFeeCd())) {
			goods.setGoodsRegMsg("배송비정책코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setDelvFeeCd(goodsMass.getDelvFeeCd().trim().toUpperCase());
		if (!UPDATE_NO_PATTERN.equals(goods.getDelvFeeCd())) {

			DelvFeePolicy delvFeePolicy = new DelvFeePolicy();
			delvFeePolicy.setSupplyCompCd(goods.getSupplyCompCd());
			delvFeePolicy.setDelvFeeCd(goods.getDelvFeeCd());
			delvFeePolicy.setUseYn("Y");
			Collection<DelvFeePolicy> deliveryFeePolicyList = businessService.getDeliveryFeePolicyList(delvFeePolicy);
			if (deliveryFeePolicyList != null && !deliveryFeePolicyList.isEmpty()) {
				goods.setGoodsRegMsg("배송비정책코드 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		}

		return goods;
	}

	/**
	 * 상품대량수정 - 상품고시정보 check
	 *
	 * @param goods
	 * @param excelMap
	 * @param goodsOrigin
	 * @param newGoodsNotiList
	 * @return Goods
	 * @author eskim
	 * @since 2021. 01. 25
	 */
	private Goods getUpdateMassGoodsNotiCheck(Goods goods, GagaMap excelMap, Goods goodsOrigin, Collection<GoodsNotiInfo> newGoodsNotiList) {

		goods.setChNotiYn("N");
		String oldNiClsfCd = "";
		String newNiClsfCd = "";

		newNiClsfCd = excelMap.getString("niClsfCd").trim();
		for (int i = 0; i < 28; i++) {
			if (StringUtils.isBlank(excelMap.getString("niContent" + (i + 1)))) {
				goods.setGoodsRegMsg("고시항목정보 없음 (" + (i + 1) + "번째 항목)");
				goods.setGoodsStat("10");
				return goods;
			}
			if (!UPDATE_NO_PATTERN.equals(excelMap.getString("niContent" + (i + 1)).trim())) {
				goods.setChNotiYn("Y");
			}
		}
		// 변경사항이 있는지 확인
		if (UPDATE_NO_PATTERN.equals(newNiClsfCd) && "N".equals(goods.getChNotiYn())) {
			return goods;
		}

		Collection<GoodsNotiInfo> goodsNotiList = new ArrayList<>();
		//고시분류 코드의 고시항목 조회
		NotiInfo notiInfo = new NotiInfo();
		notiInfo.setSupplyCompCd(goodsOrigin.getSupplyCompCd());
		if (!UPDATE_NO_PATTERN.equals(newNiClsfCd)) {
			notiInfo.setNiClsfCd(newNiClsfCd);
		} else {
			GoodsNotiInfo goodsNotiInfo = new GoodsNotiInfo();
			goodsNotiInfo.setGoodsCd(goods.getGoodsCd());
			goodsNotiList = goodsDao.getGoodsNotiInfoList(goodsNotiInfo);
			if (goodsNotiList != null && !goodsNotiList.isEmpty()) {
				oldNiClsfCd = goodsNotiList.iterator().next().getNiClsfCd();
			}
			notiInfo.setNiClsfCd(oldNiClsfCd);
			newNiClsfCd = oldNiClsfCd;
		}
		Collection<NotiInfo> notiInfolist = goodsDao.getNotiInfoItemList(notiInfo);  // 항목별 기본값 조회
		// 상품의 고시 분류코드 조회
		if (notiInfolist == null || notiInfolist.isEmpty()) {
			goods.setGoodsRegMsg("고시분류정보 없음");
			goods.setGoodsStat("10");
			return goods;
		}

		int index = 0;
		// 같은 고시분류 일경우 기존 고시항목 정보 적용
		if (oldNiClsfCd.equals(newNiClsfCd)) {
			for (NotiInfo notiInfoData : notiInfolist) {
				for (GoodsNotiInfo goodsNotiInfoTemp : goodsNotiList) {
					if (notiInfoData.getNiItemCd().equals(goodsNotiInfoTemp.getNiItemCd())) {
						notiInfoData.setNiContent(goodsNotiInfoTemp.getNiContent());
						break;
					}
				}
				index++;
			}
		}

		index = 0;
		for (NotiInfo notiInfoTmp : notiInfolist) {
			GoodsNotiInfo goodsNotiInfoTmp = new GoodsNotiInfo();
			goodsNotiInfoTmp.setGoodsCd(goods.getGoodsCd());
			goodsNotiInfoTmp.setNiClsfCd(notiInfoTmp.getNiClsfCd());
			goodsNotiInfoTmp.setNiItemCd(notiInfoTmp.getNiItemCd());
			goodsNotiInfoTmp.setDispOrd(index + 1);
			goodsNotiInfoTmp.setRegNo(TsaSession.getInfo().getUserNo());
			goodsNotiInfoTmp.setUpdNo(TsaSession.getInfo().getUserNo());
			if (UPDATE_NO_PATTERN.equals(excelMap.getString("niContent" + (index + 1)))) {
				goodsNotiInfoTmp.setNiContent(notiInfoTmp.getNiContent());
			} else {
				goodsNotiInfoTmp.setNiContent(excelMap.getString("niContent" + (index + 1)));
			}

			newGoodsNotiList.add(goodsNotiInfoTmp);
			index++;
		}

		return goods;
	}

	/**
	 * 상품등록로그 목록
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 01. 25
	 */
	public Collection<GoodsMass> getGoodsRegLogList(GoodsSearch goodsSearch) {

		// 입점업체담당자는 업체코드 설정
		if ("G001_B000".equals(TsaSession.getInfo().getRoleCd()) || "G001_E000".equals(TsaSession.getInfo().getRoleCd())) {
			goodsSearch.setSupplyCompCd(TsaSession.getInfo().getSupplyCompCd());
			goodsSearch.setRegNo(TsaSession.getInfo().getUserNo());
		}
		return goodsDao.getGoodsRegLogList(goodsSearch);
	}

	/**
	 * 사이즈 정보 목록
	 *
	 * @param sizeInfo
	 * @return
	 * @author eskim
	 * @since 2021. 01. 26
	 */
	public Collection<SizeInfo> getSizeInfoList(SizeInfo sizeInfo) {
		return goodsDao.getSizeInfoList(sizeInfo);
	}

	/**
	 * 사이즈 정보 저장
	 *
	 * @param sizeInfo
	 * @return
	 * @author eskim
	 * @since 2021. 01. 27
	 */
	public void saveSizeInfo(SizeInfo sizeInfo) {

		//log.info("[saveSizeInfo] sizeInfo {}", sizeInfo);
		String sizeCate1Cd = "";
		String sizeCate2Cd = "";
		if ("1".equals(sizeInfo.getSizeGb())) {

			if (StringUtils.isBlank(sizeInfo.getSizeCate1Cd())) {
				sizeCate1Cd = "00";
				if ("Y".equals(sizeInfo.getSelfYn())) {
					sizeCate1Cd = sizeInfo.getBrandCd();
				}
				sizeInfo.setSizeCate1Cd(sizeCate1Cd);
			}

			if (StringUtils.isBlank(sizeInfo.getSizeCate2Cd())) {
				sizeCate2Cd = tscCommonService.getNextSequence("SEQ_CATE").toString();
				sizeInfo.setSizeCate2Cd(sizeCate2Cd);
			}

		} else {

			if (StringUtils.isBlank(sizeInfo.getSizeCate1Cd())) {
				sizeCate1Cd = tscCommonService.getNextSequence("SEQ_CATE").toString();
				sizeInfo.setSizeCate1Cd(sizeCate1Cd);
				sizeInfo.setSizeCate2Cd(sizeCate1Cd);
			}

		}

		sizeInfo.setRegNo(TsaSession.getInfo().getUserNo());
		sizeInfo.setUpdNo(TsaSession.getInfo().getUserNo());
		goodsDao.saveSizeInfo(sizeInfo);
	}

	/**
	 * 총알배송 제외 상품 건수
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2021. 02. 25
	 */
	public int getGoodsQuikDeleverySkipCount(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsQuikDeleverySkipCount(goodsSearch);
	}

	/**
	 * 총알배송 제외 상품 목록
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2021. 02. 25
	 */
	public Collection<Goods> getGoodsQuikDeleverySkipList(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsQuikDeleverySkipList(goodsSearch);
	}

	/**
	 * 총알배송 제외 상품 저장
	 *
	 * @param goods
	 * @author eskim
	 * @since 2021. 02. 25
	 */
	@Transactional("shopTxnManager")
	public void createGoodsQuikDeleverySkip(Goods goods) {
		if (goods.getArrGoodsCd().length <= 0) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		GoodsSearch search = new GoodsSearch();
		search.setConditionList(goods.getArrGoodsCd());
		search.setSearch("searchGoodsCd");
		int cnt = getGoodsListCount(search);
		if (cnt < goods.getArrGoodsCd().length) {
			throw new IllegalStateException("상품코드를 확인해주세요.");
		}

		goods.setRegNo(TsaSession.getInfo().getUserNo());
		goods.setUpdNo(TsaSession.getInfo().getUserNo());

		for (String goodsCd : goods.getArrGoodsCd()) {

			goods.setGoodsCd(goodsCd);

			goodsDao.createGoodsQuikDeleverySkip(goods);

		}
	}

	/**
	 * 총알배송 제외 상품 삭제
	 *
	 * @param goods
	 * @author eskim
	 * @since 2021. 02. 25
	 */
	@Transactional("shopTxnManager")
	public void deleteGoodsQuikDeleverySkip(Goods goods) {
		if (goods.getArrGoodsCd().length <= 0) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		goodsDao.deleteGoodsQuikDeleverySkip(goods);
	}

	/**
	 * 상품 입출고 엑셀조회용 상품 저장
	 *
	 * @param procJob : goodsExcelUpload
	 * @param goodsSizeList
	 * @return
	 * @author eskim
	 * @since 2020. 02. 13
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsSizeSoldoutExcelupload(Collection<Goods> goodsList, String excelFilename) {

		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
		if (goodsList == null || goodsList.isEmpty()) {
			this.deleteExceluploadFile(targetPath, excelFilename);
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		//건수
		if (goodsList != null && goodsList.size() > EXCEL_ROW_COUNT) {
			throw new IllegalStateException("엑셀 파일의 건수를 " + EXCEL_ROW_COUNT + "건 이하로 사용하세요.");
		}

		// 검증
		GoodsSearch search = new GoodsSearch();
		search.setSearch("searchGoodsCd");

		int index = 0;
		for (Goods goods : goodsList) {

			search.setGoodsCd(goods.getGoodsCd());
			int cnt = getGoodsListCount(search);
			if (cnt == 0) {
				throw new IllegalStateException("상품코드를 확인해주세요.");
			}

			goods.setRegNo(TsaSession.getInfo().getUserNo());

			// 엑셀조회를 위한 SEARCH 테이블 생성
			SearchData searchData = new SearchData();
			searchData.setRegNo(goods.getRegNo());
			searchData.setSearchCd(goods.getGoodsCd());
			searchData.setDispOrd(index);
			if (index == 0) {
				commonService.deleteExceluploadSearCh(searchData);
			}

			commonService.createExceluploadSearch(searchData);

			goodsDao.createGoodsQuikDeleverySkip(goods);

			index++;
		}

	}

	/**
	 * 상품 모델 정보
	 *
	 * @param goodsImg
	 * @return
	 * @author eskim
	 * @since 2021. 04. 27
	 */
	public GoodsImg getGoodsModelInfo(GoodsImg goodsImg) {
		return goodsDao.getGoodsModelInfo(goodsImg);
	}

	/**
	 * 상품 모델 정보 저장
	 *
	 * @param goodsImg
	 * @return
	 * @author eskim
	 * @since 2020.04. 27
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsModelInfo(GoodsImg goodsImg) {
		goodsDao.saveGoodsModelInfo(goodsImg);
	}

	/**
	 * WMS입고단품목록 건수
	 *
	 * @param goodsSearch
	 * @return Collection<WmsGoods>
	 * @author eskim
	 * @since 2021. 06. 28
	 */
	public int getGoodsWmsIncomelotSkuListCount(IfIncomelot iIfIncomelot) {
		return goodsDao.getGoodsWmsIncomelotSkuListCount(iIfIncomelot);
	}

	/**
	 * WMS입고단품목록 조회
	 *
	 * @param goodsSearch
	 * @return Collection<WmsGoods>
	 * @author eskim
	 * @since 2021. 06. 28
	 */
	public Collection<WmsGoods> getGoodsWmsIncomelotSkuList(IfIncomelot ifIncomelot) {
		return goodsDao.getGoodsWmsIncomelotSkuList(ifIncomelot);
	}

	/**
	 * 자사 상품 등록
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2021. 07. 04
	 */
	@Transactional("shopTxnManager")
	public void createSalfGoodsDetail(Goods goods) {

		// 중복여부 확인
		Goods goodsDup = goodsDao.getGoods(goods);
		if (goodsDup != null) {
			throw new IllegalStateException("자사상품코드 중복요청입니다.");
		}

		// 입고여부확인
		WmsGoods WmsGoods = goodsDao.getWmsGoodsInfo(goods);
		if (WmsGoods == null) {
			throw new IllegalStateException("미입고 상품코드입니다.");
		}

		Brand brand = new Brand();
		brand.setSupplyCompCd(goods.getSupplyCompCd());
		brand.setBrandCd(goods.getBrandCd());
		int brandCount = goodsDao.getBrandSupplyCount(brand);
		if (brandCount != 1) {
			throw new IllegalStateException("미입고 상품의 업체/브랜드코드와 상품의 업체/브랜드코드가 상이합니다.");
		}

		goods.setErpStockLinkYn("Y");
		goods.setGoodsStat("G008_20");
		goods.setNewCustOrdYn("N");
		goods.setSelfGoodsYn("Y");
		goods.setGoodsType("G056_N");
		goods.setTobeFormYn("Y");

		// <,> replace 처리
		goods.setRegNo(TsaSession.getInfo().getUserNo());
		goods.setUpdNo(TsaSession.getInfo().getUserNo());

//		goods.setGoodsDesc(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsDesc(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsPcTopDesc(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsPcTopDesc(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsMobileTopDesc(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsMobileTopDesc(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsPcDownDesc(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsPcDownDesc(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsMobileDownDesc(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsMobileDownDesc(), "&lt;", "<"), "&gt;", ">"));
//
//		goods.setGoodsNm(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsNm(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsTnm(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsTnm(), "&lt;", "<"), "&gt;", ">"));
//		goods.setGoodsSnm1(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsSnm1(), "&lt;", "<"), "&gt;", ">"));

		// 판매기간설정 eskim
		goods.setSellStdt(goods.getSellStYMD().replaceAll("-", "") + goods.getSellStHH() + "0000");
		goods.setSellEddt(goods.getSellEdYMD().replaceAll("-", "") + goods.getSellEdHH() + "5959");

		// 품번코드
		goods.setGoodsNum(goods.getGoodsCd());
		// 입점상품코드
		goods.setSupplyGoodsCd(goods.getGoodsCd());

		if (goods.getListPrice() < goods.getCurrPrice()) {
			throw new IllegalStateException("판매가를 올바르게 입력해주세요.");
		}

		// 판매수수료율
		SupplyCompany supplyCompany = new SupplyCompany();
		supplyCompany.setSupplyCompCd(goods.getSupplyCompCd());
		Collection<SupplyCompany> supplyCompanyList = businessService.getSupplyCompanyList(supplyCompany);
		if (supplyCompanyList == null || supplyCompanyList.isEmpty()) {
			throw new IllegalStateException("업체정보를 확인해 주세요.");
		}

		goods.setSellFeeRate(supplyCompanyList.iterator().next().getSellFeeRate()); // 판매수수료율

		// 적립포인트 관련 브랜드 확인
//		Brand brand = new Brand();
		brand.setBrandCd(goods.getBrandCd());
		Collection<Brand> brandList = businessService.getBrandList(brand);
		if (brandList == null || brandList.isEmpty()) {
			throw new IllegalStateException("상품브랜드를 확인해 주세요.");
		}

		float pntPrate = 0f;
		float pntMrate = 0f;
		String distributionGb = "G065_12";
		for (Brand tmpBrand : brandList) {
			if ("G009_10".equals(goods.getFormalGb())) {
				pntPrate = tmpBrand.getPntPrate10();
				pntMrate = tmpBrand.getPntMrate10();
			} else {
				pntPrate = tmpBrand.getPntPrate20();
				pntMrate = tmpBrand.getPntMrate20();
			}
			distributionGb = tmpBrand.getDistributionGb(); //유통구분
		}
		goods.setPntPrate(pntPrate); // 포인트적립율(PC)
		goods.setPntMrate(pntMrate); // 포인트적립율(MOBILE)
		goods.setPrePpntUsableYn("N");
		goods.setPreMpntUsableYn("N");
		goods.setDistributionGb(distributionGb);

		//출고처 코드
		goods.setDelvLocCd("DL001"); // 자사상품 출고처 코드 고정		

		// 기본정보 생성
		goodsDao.createGoods(goods); // 상품기본 저장
		goodsDao.createGoodsSmmary(goods); // 상품통계 생성

		WmsGoods wmsGoods = new WmsGoods();
		wmsGoods.setUpdNo(TsaSession.getInfo().getUserNo());
		wmsGoods.setGoodsRegGb("G"); // G: 상품, F: 사은품
		wmsGoods.setModelNo(goods.getGoodsCd());

		goodsDao.saveGoodsWmsIncomelotByModelNo(wmsGoods); // wms 상품 상품등록일 변경

		// 사용자 검색어를 검색어에 적용
		String goodsSnm = goodsDao.getGoodsSnm(goods.getGoodsCd());
		if (!StringUtils.isBlank(goods.getGoodsSnm1())) {
			String[] arrGoodsSnm = goods.getGoodsSnm1().split("\\;");
			StringBuilder tempGoodsSnm = new StringBuilder();
			for (String loopGoodsSnm : arrGoodsSnm) {
				if (goodsSnm.toUpperCase().indexOf(loopGoodsSnm.toUpperCase()) <= -1) {
					tempGoodsSnm.append(loopGoodsSnm).append(";");
				}
			}
			goods.setGoodsSnm(tempGoodsSnm.toString() + goodsSnm);

		} else if (!goodsSnm.equals(goods.getGoodsSnm())) {
			goods.setGoodsSnm(goodsSnm);
		}

		// 상품타이틀 수정
		goodsDao.updateGoodsSnm(goods);

		// 상품사이즈 정보
		Collection<IfProductSku> goodsWmsSizeList = wmsGoodsService.getGoodsWmsSizeList(goods.getGoodsCd());

		if (goodsWmsSizeList == null || goodsWmsSizeList.isEmpty()) {
			throw new IllegalStateException("WMS의 TB_IF_PRODUCTSKU 에  " + goods.getGoodsCd() + " 상품이 존재하지 않습니다.");
		} else {
			int index = 1;
			for (IfProductSku ifProductSku : goodsWmsSizeList) {

				Option wmsOption = goodsDao.getWmsColorStock(ifProductSku);
				if (wmsOption == null) {
					throw new IllegalStateException(goods.getGoodsCd() + " 의 WMS의 색상 " + ifProductSku.getWmsColorCd() + "이(가) WMS색상관리에 없습니다.");
				}

				Option goodsStock = new Option();
				goodsStock.setGoodsCd(goods.getGoodsCd());
				goodsStock.setOptCd(ifProductSku.getSkucode());
				goodsStock.setOptCd1(wmsOption.getOptCd1());
				goodsStock.setOptCd2(ifProductSku.getOption2());
				goodsStock.setSkuModelNo(ifProductSku.getSkumodelno());
				goodsStock.setProductNo(ifProductSku.getProductno());
				goodsStock.setProductCode(ifProductSku.getProductcode());
				goodsStock.setBaseStockQty(0);
				goodsStock.setCurrStockQty(wmsOption.getCurrStockQty());
				goodsStock.setStoreStockQty(0);
				goodsStock.setStoreMaxQty(wmsOption.getCurrStockQty());
				goodsStock.setAddPrice(0);
				goodsStock.setSoldoutYn("N");
				goodsStock.setDispOrd(index);
				goodsStock.setDispYn("Y");
				goodsStock.setRegNo(TsaSession.getInfo().getUserNo());
				goodsStock.setUpdNo(TsaSession.getInfo().getUserNo());
				goodsDao.saveStock(goodsStock);
				index++;
			}
		}

		// 상품 색상 , 사이즈 옵션 정보 조회
		Goods goodsColorSize = goodsDao.getGoodsColorSize(goods);
		if (goodsColorSize != null && !StringUtils.isBlank(goodsColorSize.getMainColorCd())) {
			goodsColorSize.setUpdNo(TsaSession.getInfo().getUserNo());
			goodsDao.updateGoodsMainColorCd(goodsColorSize); // 대표색상 설정
		}

		// 상품상세정보 저장
		this.saveGoodsDetailDesc(goods);

		// 상품 정보고시 변경
		this.saveGoodsNotiInfo(goods);

		// 전시카테고리 작업
		goodsDao.createCategoryGoods(goods);

		log.info("goods = {}", goods);
		// 안전안증작업
		if (!StringUtils.isEmpty(goods.getCertTargetGb())) {
			GoodsSafeNo goodsSafeNo = new GoodsSafeNo();
			goodsSafeNo.setGoodsCd(goods.getGoodsCd());
			goodsSafeNo.setCertTargetGb(goods.getCertTargetGb());
			goodsSafeNo.setCertFormGb(goods.getCertFormGb());
			goodsSafeNo.setCertType(goods.getCertType());
			goodsSafeNo.setCertNum(goods.getCertNum());
			saveGoodsDetailCertNum(goodsSafeNo);

		}

	}

	/**
	 * 상품 상세 컨텐츠 목록
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2021. 07. 14
	 */
	public Collection<GoodsContents> getGoodsContentsList(GoodsSearch goodsSearch) {
		return goodsDao.getGoodsContentsList(goodsSearch);
	}

	/**
	 * 상품 상세 컨텐츠 상품 목록
	 *
	 * @param notice
	 * @return
	 * @author eskim
	 * @since 2021. 07. 14
	 */
	public Collection<GoodsContentsData> getGoodsContentsDataList(GoodsContents goodsContents) {
		return goodsDao.getGoodsContentsDataList(goodsContents);
	}

	/**
	 * 상품 상세 컨텐츠 저장
	 * @param notice - 공지사항 정보
	 * @return
	 * @author eskim
	 * @since 2021. 07. 14
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsContent(GoodsContents goodsContents) {
		goodsContents.setRegNo(TsaSession.getInfo().getUserNo());
		goodsContents.setUpdNo(TsaSession.getInfo().getUserNo());

		//신규이미지가 있을 경우
		if(!StringUtils.isEmpty(goodsContents.getNewImgPath())){
            String displayUploadPath = env.getProperty("upload.default.target.path");
            displayUploadPath = GagaFileUtil.getConcatenationPath(displayUploadPath, "goodscontents");
            File file = new File(GagaFileUtil.getConcatenationPath(displayUploadPath, goodsContents.getNewImgPath()));

            String yearMonth = GagaDateUtil.getToday().substring(0, 6);
            displayUploadPath = GagaFileUtil.getConcatenationPath(displayUploadPath, yearMonth); 
            log.info("displayUploadPath {}", displayUploadPath);
            
            File contentsPath = new File(displayUploadPath);
			if (!contentsPath.exists()) {
				contentsPath.mkdir();
			}
			
            String newFilename = "GOODSCONTENTS_" + GagaDateUtil.getTodayDateTime() + "." + org.springframework.util.StringUtils.getFilenameExtension(goodsContents.getNewImgPath());
            File uniqueFile = GagaFileUtil.getUniqueFile(new File(GagaFileUtil.getConcatenationPath(displayUploadPath, newFilename)));
            

            // 기존이미지 삭제
            try{
                GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(displayUploadPath, goodsContents.getImgPath()));
            }catch (IOException e){
                //  nothing
                log.info("[saveGoodsContent 기존 이미지 삭제중 error]");
                //e.printStackTrace();
            }
           
            // Rename a file
            file.renameTo(uniqueFile);

            goodsContents.setImgPath("/goodscontents/"+ yearMonth +'/'+ newFilename);
        }

		log.info("saveGoodsContent  =={}", goodsContents);
		// 신규 일때
		if (goodsContents.getGoodsContentsSq() == null) {
			// 저장
			goodsDao.createGoodsContents(goodsContents);

			// 등록된  값 가져오기
			Integer goodsContentsSq = goodsContents.getGoodsContentsSq();

			goodsContents.setGoodsContentsSq(goodsContentsSq);

		} else {
			// 수정
			goodsDao.updateGoodsContents(goodsContents);
		}

		if (!StringUtils.isBlank(goodsContents.getGoodsList())) {
			Collection<GoodsContentsData> noticeGoodsList = null;
			try {
				noticeGoodsList = mapper.readValue(goodsContents.getGoodsList(), new TypeReference<Collection<GoodsContentsData>>() {
				});
			} catch (Exception e) {
				e.printStackTrace();
				throw new IllegalStateException(message.getMessage("상품상세컨텐츠 상품 저장 중 오류로 인해 저장되지 않았습니다."));
			}
			//log.info("noticeGoodsList: {}", noticeGoodsList);
			for (GoodsContentsData goodsContentsData : noticeGoodsList) {
				goodsContentsData.setGoodsContentsSq(goodsContents.getGoodsContentsSq());
				goodsContentsData.setRegNo(TsaSession.getInfo().getUserNo());
				goodsContentsData.setUpdNo(TsaSession.getInfo().getUserNo());

				goodsDao.saveGoodsContent(goodsContentsData);
			}

		}
	}

	/**
	 * 상품 상세 컨텐츠 상품 삭제
	 * @param noticeGoods
	 * @return
	 * @author eskim
	 * @since 2021. 07. 14
	 */
	@Transactional("shopTxnManager")
	public void deleteGoodsContentGoods(GoodsContentsData goodsContentsData) {

		if (goodsContentsData == null || (goodsContentsData.getArrGoodsCd() == null && goodsContentsData.getArrGoodsCd().length <= 0)) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		if (goodsContentsData.getArrGoodsCd().length > 0) {
			for (String goodsCd : goodsContentsData.getArrGoodsCd()) {
				goodsContentsData.setGoodsCd(goodsCd);
				goodsContentsData.setRegNo(TsaSession.getInfo().getUserNo());
				goodsContentsData.setUpdNo(TsaSession.getInfo().getUserNo());

				goodsDao.deleteGoodsContentGoods(goodsContentsData);
			}
		}

	}

}
