package com.style24.scm.biz.service;

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.core.biz.thirdparty.SafetyKoreaApi;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.domain.Brand;
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.GoodsDesc;
import com.style24.persistence.domain.GoodsHst;
import com.style24.persistence.domain.GoodsImg;
import com.style24.persistence.domain.GoodsMass;
import com.style24.persistence.domain.GoodsNotiInfo;
import com.style24.persistence.domain.GoodsSafeNo;
import com.style24.persistence.domain.GoodsSearch;
import com.style24.persistence.domain.GoodsSupplyPrice;
import com.style24.persistence.domain.IfProductSku;
import com.style24.persistence.domain.Itemkind;
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.SearchData;
import com.style24.persistence.domain.SupplyCompany;
import com.style24.persistence.domain.WmsGoods;
import com.style24.scm.biz.dao.TssGoodsDao;
import com.style24.scm.support.env.TssConstants;
import com.style24.scm.support.security.session.TssSession;

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 gagamel
 * @since 2020. 10. 19
 */
@Service
@Slf4j
public class TssGoodsService {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private Environment env;

	@Autowired
	private TssGoodsDao goodsDao;

	@Autowired
	private TssCommonService commonService;

	@Autowired
	private TssBusinessService businessService;

	@Autowired
	private TssNoticeService noticeService;

	@Autowired
	private TssDisplayService displayService;

	@Autowired
	private TssRendererService rendererService;

	@Autowired
	private TssWmsGoodsService wmsGoodsService;

	@Autowired
	private SafetyKoreaApi safetyKoreaApi;

	@Autowired
	private ObjectMapper mapper;

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

	private static final String ALPHA_NUMERIC = "^[a-zA-Z0-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 goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 10. 20
	 */
	public int getGoodsListCount(GoodsSearch goodsSearch) {
		goodsSearch.setRoleCd(TssSession.getInfo().getRoleCd());
		return goodsDao.getGoodsListCount(goodsSearch);
	}

	/**
	 * 상품 목록
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 10. 20
	 */
	public Collection<Goods> getGoodsList(GoodsSearch goodsSearch) {
		goodsSearch.setRoleCd(TssSession.getInfo().getRoleCd());
		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 = {"이미지", "상품코드", "업체명", "브랜드명", "상품명", "품목",
				"전시재고", "상품상태", "스타일년도", "시즌", "정상가", "판매가",
				"할인율", "가격변경일", "정상이월구분", "반품가능 여부"};

			// 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",
				"DC_RATE", "PRICE_UPD_DT", "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()};

			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");
					} else {
						gagaMap.set("SYS_IMG_NM", env.getProperty("domain.uximage") + "/image/no.png");
					}
				}
			}

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

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

			// 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",
				"DC_RATE", "PRICE_UPD_DT", "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()};

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

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

	/**
	 * 상품 수정 항목 일괄변경
	 *
	 * @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(TssSession.getInfo().getUserNo());
		goods.setUpdNo(TssSession.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 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 goods
	 * @return
	 * @author eskim
	 * @since 2021. 5. 16
	 */
	public Goods getGoodsInfo(Goods goods) {
		// 상품기본정보
		Goods resultGoods = goodsDao.getGoods(goods);
		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 goods
	 * @return
	 * @author eskim
	 * @since 2020. 11. 18
	 */
	public Collection<Goods> getGoodsDetailOrderGradeList(Goods goods) {
		return goodsDao.getGoodsDetailOrderGradeList(goods);
	}

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

	/**
	 * 엑셀조회용 상품 저장
	 *
	 * @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) {

			//업체상품코드여부 확인
			GoodsSearch goodsSearch = new GoodsSearch();
			goodsSearch.setGoodsCd(goods.getGoodsCd());
			goodsSearch.setSupplyCompCd(TssSession.getInfo().getSupplyCompCd());
			if (goodsDao.getGoodsListCount(goodsSearch) <= 0) {
				throw new IllegalStateException(goodsSearch.getGoodsCd() + " 상품코드가 업체 상품코드인지 확인해 주세요.");
			}

			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 goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 27
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsDetail(Goods goods) {

		// <,> replace 처리
		goods.setRegNo(TssSession.getInfo().getUserNo());
		goods.setUpdNo(TssSession.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 ("Y".equals(goods.getChCfrmYn())) {
				GoodsSupplyPrice GoodsSupplyPrice = new GoodsSupplyPrice();
				GoodsSupplyPrice.setGoodsCd(goods.getGoodsCd());
				if (goods.getCurrPrice() != goods.getCurrPriceOrg()) {
					GoodsSupplyPrice.setSupplyGoodsPrice(goods.getCurrPrice());
				}
				if (goods.getSellFeeRate() != goods.getSellFeeRateOrg()) {
					GoodsSupplyPrice.setSupplySellFeeRate(goods.getSellFeeRate());
				}
				GoodsSupplyPrice.setCfrmYn("N");
				GoodsSupplyPrice.setRegNo(goods.getRegNo());
				GoodsSupplyPrice.setUpdNo(goods.getUpdNo());
				goodsDao.createGoodSupplyPrice(GoodsSupplyPrice);

				goods.setCurrPrice(goods.getCurrPriceOrg());
				goods.setSellFeeRate(goods.getSellFeeRateOrg());
			}

		}

		// 사용자 검색어를 검색어에 적용
		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(TssSession.getInfo().getUserNo());
				regGoodsExtend.setUpdNo(TssSession.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.setCertTargetGb(goods.getCertTargetGb());
			goodsSafeNo.setCertFormGb(goods.getCertFormGb());
			goodsSafeNo.setCertType(goods.getCertType());
			goodsSafeNo.setCertNum(goods.getCertNum());
			this.saveGoodsDetailCertNum(goodsSafeNo);
		}
		
		// 상품 구매등급 적용 - SCM 미적용
		//		if (goods.getGoodsOrderGrade() != null && goods.getGoodsOrderGrade().length > 0) {
		//			Goods goodsOrderGrade = new Goods();
		//			goodsOrderGrade.setGoodsCd(goods.getGoodsCd());
		//			goodsOrderGrade.setRegNo(TssSession.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(TssSession.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);

		// 상세 타이틀
		if (!StringUtils.isEmpty(goods.getGoodsTitlesDesc())) {
			goodsDesc.setDescGb("10");
			goodsDesc.setGoodsDesc(goods.getGoodsTitlesDesc());
			this.saveGoodsDesc(goodsDesc);
		}

		// 상세 내용
		if (!StringUtils.isEmpty(goods.getGoodsContentsDesc())) {
			goodsDesc.setDescGb("20");
			goodsDesc.setGoodsDesc(goods.getGoodsContentsDesc());
			this.saveGoodsDesc(goodsDesc);
		}

		// 상세 특징
		if (!StringUtils.isEmpty(goods.getGoodsCharacterDesc())) {
			goodsDesc.setDescGb("30");
			goodsDesc.setGoodsDesc(goods.getGoodsCharacterDesc());
			this.saveGoodsDesc(goodsDesc);
		}

		// PC 상단
		if (!StringUtils.isEmpty(goods.getGoodsPcTopDesc())) {
			goodsDesc.setDescGb("40");
			goodsDesc.setGoodsDesc(goods.getGoodsPcTopDesc());
			this.saveGoodsDesc(goodsDesc);
		}

		// PC 하단
		if (!StringUtils.isEmpty(goods.getGoodsPcTopDesc())) {
			goodsDesc.setDescGb("50");
			goodsDesc.setGoodsDesc(goods.getGoodsPcTopDesc());
			this.saveGoodsDesc(goodsDesc);
		}

		// MO 상단
		if (!StringUtils.isEmpty(goods.getGoodsMobileTopDesc())) {
			goodsDesc.setDescGb("60");
			goodsDesc.setGoodsDesc(goods.getGoodsMobileTopDesc());
			this.saveGoodsDesc(goodsDesc);
		}

		// MO 하단
		if (!StringUtils.isEmpty(goods.getGoodsMobileDownDesc())) {
			goodsDesc.setDescGb("70");
			goodsDesc.setGoodsDesc(goods.getGoodsMobileDownDesc());
			this.saveGoodsDesc(goodsDesc);
		}

		// 상품상세(as-is,입점)
		if (!StringUtils.isEmpty(goods.getGoodsDesc())) {
			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);
			if (StringUtils.isBlank(optCd)) {
				int goodsOptionCnt = goodsDao.getGoodsOptionCount(stock);	// 등록 옵션수 count
				optCd = goods.getGoodsCd() + "-" + (goodsOptionCnt + 1);
			}

			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()) {
				goodsNotiInfo.setGoodsCd(goods.getGoodsCd());
				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 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
	 * @return
	 * @author eskim
	 * @since 2020. 11. 17
	 */
	public int getGoodsOptionCount(Option option) {

		return goodsDao.getGoodsOptionCount(option);
	}

	/**
	 * 상품 가격승인관리 목록 건수
	 *
	 * @param goodsPriceHst
	 * @return
	 * @author eskim
	 * @since 2020. 11. 26
	 */
	public int getGoodsSupplyPriceCount(GoodsSupplyPrice goodsSupplyPrice) {

		return goodsDao.getGoodsSupplyPriceCount(goodsSupplyPrice);
	}

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

		return goodsDao.getGoodsSupplyPriceList(goodsSupplyPrice);
	}

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

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

	/**
	 * 공지사항 저장
	 * 
	 * @param notice - 공지사항 정보
	 * @return
	 * @author eskim
	 * @since 2020. 11. 27
	 */
	@Transactional("shopTxnManager")
	public void saveNotice(Notice notice) {
		notice.setRegNo(TssSession.getInfo().getUserNo());
		notice.setUpdNo(TssSession.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(TssSession.getInfo().getUserNo());
				noticeGoods.setUpdNo(TssSession.getInfo().getUserNo());

				goodsDao.saveNoticeGoods(noticeGoods);
			}

		}
	}

	/**
	 * 공지사항 상품 삭제
	 * 
	 * @param noticeGoods
	 * @return
	 * @author eskim
	 * @since 2020. 11. 27
	 */
	@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(TssSession.getInfo().getUserNo());
				noticeGoods.setUpdNo(TssSession.getInfo().getUserNo());

				goodsDao.deleteNoticeGoods(noticeGoods);
			}
		}
	}

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

	/**
	 * 상품이미지 저장 처리
	 * 
	 * @param goodsImgList - 상품이미지 목록
	 * @throws
	 * @author eskim
	 * @since 2020. 12. 23
	 */
	@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(TssSession.getInfo().getUserNo());
				goodsDao.createGoodsImage(goodsImg);
			}
		}
	}

	/**
	 * 상품이미지 저장 처리
	 * 
	 * @param goodsImgList - 상품이미지 목록
	 * @throws
	 * @author eskim
	 * @since 2020. 12. 23
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsImageMassList(Collection<GoodsImg> goodsImgList) {
		for (GoodsImg goodsImg : goodsImgList) {
			goodsDao.deleteGoodsImage(goodsImg);
			goodsDao.createGoodsImage(goodsImg);
		}
	}

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

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

	/**
	 * 상품대량등록 엑셀 저장 - 자사상품
	 *
	 * @param ecxelGoodsList, excelFilename, procJob(자사:createSelfGoods, 입점:createGoods)
	 * @return
	 * @author eskim
	 * @since 2021. 01. 12
	 */
	@Transactional("shopTxnManager")
	public String createExceluploadSelfGoods(GagaMap gagaMap, String procJob) {

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

		// 상품기본정보
		Goods goods = this.createSelfGoodsInfo(goodsMass, procJob);

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

		// 상품고시정보 - 항목및 기본값
		Collection<GoodsNotiInfo> goodsNotiList = goodsDao.getItemkindNotiInfoList(goods);
		if (goodsNotiList == null || goodsNotiList.isEmpty()) {
			goods.setGoodsRegMsg("품목의 고시정보 없음");
			goods.setGoodsStat("10");
			this.setGoodsRegResult(goods, goodsMass, procJob);
			return goods.getGoodsStat();
		}

		// 할인율
		goods.setDcRate((int)(this.getDcRate(goods.getListPrice(), goods.getCurrPrice())));

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

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

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

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

		goodsMass.setGoodsCd(goods.getGoodsCd());

		// 상품사이즈 정보
		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(Integer.parseInt(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(TssSession.getInfo().getUserNo());
				goodsStock.setUpdNo(TssSession.getInfo().getUserNo());
				goodsDao.saveStock(goodsStock);
				index++;
			}
		}

		// 상품 색상 , 사이즈 옵션 정보 조회
		GoodsMass goodsColorSize = goodsDao.getGoodsColorSize(goods);
		if (goodsColorSize != null && !StringUtils.isBlank(goodsColorSize.getMainColorCd())) {
			goodsColorSize.setUpdNo(TssSession.getInfo().getUserNo());
			goodsDao.updateGoodsMainColorCd(goodsColorSize); // 대표색상 설정
		}
		int index = 0;
		// 자사 상품 등록시 고시정보 처리
		for (GoodsNotiInfo goodsNotiInfo : goodsNotiList) {

			if (!StringUtils.isBlank(gagaMap.getString("niContent" + (index + 1)))) {
				goodsNotiInfo.setNiContent(gagaMap.getString("niContent" + (index + 1)).trim());
			}

//			if ("G005_003".equals(goodsNotiInfo.getNiItemCd())) {	// 색상
//
//				if (!StringUtils.isBlank(goodsColorSize.getOpt1Str())) {
//					goodsNotiInfo.setNiContent(goodsColorSize.getOpt1Str());
//				}
//			} else if ("G005_004".equals(goodsNotiInfo.getNiItemCd())) {	//치수
//				if (!StringUtils.isBlank(goodsColorSize.getOpt2Str())) {
//					goodsNotiInfo.setNiContent(goodsColorSize.getOpt2Str());
//				}
//			} else if ("G005_006".equals(goodsNotiInfo.getNiItemCd())) {	//제조국
//				if (!StringUtils.isBlank(goods.getOriginNm())) {
//					goodsNotiInfo.setNiContent(goods.getOriginNm());
//				}
//			} else if ("G005_009".equals(goodsNotiInfo.getNiItemCd())) {	//제조년월
//				if (!StringUtils.isBlank(goods.getMakeYmd())) {
//					goodsNotiInfo.setNiContent(goods.getMakeYmd());
//				}
//			} else if ("G005_097".equals(goodsNotiInfo.getNiItemCd())) {	//수입여부
//				if (!StringUtils.isBlank(goods.getOriginNm()) &&
//					(goods.getOriginNm().indexOf("대한민국") >= 0 || goods.getOriginNm().indexOf("한국") >= 0 || goods.getOriginNm().toUpperCase().indexOf("KOREA") >= 0)) {
//					goodsNotiInfo.setNiContent("N");
//				} else {
//					goodsNotiInfo.setNiContent("Y");
//				}
//			} else if ("G005_099".equals(goodsNotiInfo.getNiItemCd())) {	//종류
//				if (!StringUtils.isBlank(goods.getItemkindNm())) {
//					goodsNotiInfo.setNiContent(goods.getItemkindNm());
//				}
//			}
			index++;
		}

		//고시항목 필수값 확인
		goods = this.getGoodsNotiCheck(goods, goodsNotiList, gagaMap, procJob);

		//고시 필수 항목 미입력으로 상품 상태 변경
		if ("G008_20".equals(goods.getGoodsStat())) {
			goodsDao.updateGoodsStatOnly(goods);
		}

		this.createGoodsNoti(gagaMap, goodsNotiList); // 상품고시정보 저장

		GoodsDesc goodsDesc = new GoodsDesc();
		goodsDesc.setGoodsCd(goods.getGoodsCd());
		goodsDesc.setRegNo(goods.getRegNo());
		goodsDesc.setUpdNo(goods.getUpdNo());
		// 상품상세 타이틀 확인
		if (!StringUtils.isBlank(goodsMass.getGoodsTitles())) {
			goodsDesc.setDescGb("10");
			goodsDesc.setGoodsDesc(goodsMass.getGoodsTitles().trim());
			this.saveGoodsDesc(goodsDesc);
		}

		// 상품상세 타이틀 내용 확인
		if (!StringUtils.isBlank(goodsMass.getGoodsContent())) {
			String[] arrString = goodsMass.getGoodsContent().split("\n");
			StringBuffer sb = new StringBuffer();
			for (String descData : arrString) {
				sb.append("<p>").append(descData).append("</b>");
			}
			goodsDesc.setDescGb("20");
			goodsDesc.setGoodsDesc(sb.toString());
			this.saveGoodsDesc(goodsDesc);
		}

		// 상품상세 상품 상세 특징 확인
		if (!StringUtils.isBlank(goodsMass.getGoodsCharacter())) {
			String[] arrString = goodsMass.getGoodsCharacter().split("\n");
			StringBuffer sb = new StringBuffer();
			for (String descData : arrString) {
				sb.append("<p>").append(descData).append("</b>");
			}
			goodsDesc.setDescGb("30");
			goodsDesc.setGoodsDesc(sb.toString());
			this.saveGoodsDesc(goodsDesc);
		}

		// 사용자 검색어를 검색어에 적용
		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);

		goodsDao.createCategoryGoods(goods);

		this.setGoodsRegResult(goods, goodsMass, procJob);

		return goods.getGoodsStat();

	}

	/**
	 * 상품등록 - 상품기본정보 - 자사상품
	 *
	 * @param goodsMass
	 * @param excelFilename
	 * @author eskim
	 * @since 2021. 01. 12
	 */
	private Goods createSelfGoodsInfo(GoodsMass goodsMass, String procJob) {

		Goods goods = new Goods();
		goods.setGoodsStat("G008_20"); // 상품상태
		goods.setGoodsRegMsg("이미지 등록 필요");
		goods.setRegNo(TssSession.getInfo().getUserNo());
		goods.setUpdNo(TssSession.getInfo().getUserNo());

		// 품번정보 확인 (길이 10, FRJ '-' 삭제)
		if (StringUtils.isBlank(goodsMass.getGoodsNum()) || goodsMass.getGoodsNum().trim().replace("-", "").length() != 10) {
			goods.setGoodsRegMsg("품번코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}

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

		// 상품코드 중복여부 확인
		Goods goodsDup = goodsDao.getGoods(goods);
		if (goodsDup != null) {
			goods.setGoodsRegMsg("상품코드(품번) 중복등록요청");
			goods.setGoodsStat("10");
			return goods;
		}

		// wms 상품 정보 확인
		WmsGoods wmsGoodsInfo = goodsDao.getWmsGoodsInfo(goods);
		if (wmsGoodsInfo == null) {
			goods.setGoodsRegMsg("미입고 상품코드");
			goods.setGoodsStat("10");
			return goods;
		}

		// 품번코드
		goods.setGoodsNum(goodsMass.getGoodsNum().trim().toUpperCase());
		// 입점상품코드
		goods.setSupplyGoodsCd(goodsMass.getGoodsNum().trim().toUpperCase());

		// 브랜드
		if (StringUtils.isBlank(goodsMass.getBrandCd())) {
			goods.setGoodsRegMsg("브랜드코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setBrandCd(goodsMass.getBrandCd().trim().toUpperCase()); // 브랜드 코드

		// 상품명
		if (StringUtils.isBlank(goodsMass.getGoodsNm())) {
			goods.setGoodsRegMsg("상품명 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		if (StringUtils.length(goodsMass.getGoodsNm()) > 66) {
			goods.setGoodsRegMsg("상품명 길이 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setGoodsNm(goodsMass.getGoodsNm().trim().replaceAll("(\\r\\n|\\r|\\n|\\n\\r)", ""));

		// 품목코드
		if (StringUtils.isBlank(goodsMass.getItemkindCd())) {
			goods.setGoodsRegMsg("품목코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setItemkindCd(goodsMass.getItemkindCd().trim().toUpperCase());

		Itemkind itemkind = new Itemkind();
		itemkind.setItemkindCd(goods.getItemkindCd());
		itemkind.setUseYn("Y");
		Collection<Itemkind> getItemkindList = goodsDao.getItemkindList(itemkind);
		if (getItemkindList == null || getItemkindList.size() == 0) {
			goods.setGoodsRegMsg("품목코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setItemkindNm(getItemkindList.iterator().next().getItemkindLeafNm());	//LEAF품목명

		// 스타일 년도
		if (StringUtils.isBlank(goodsMass.getStyleYear()) || goodsMass.getStyleYear().trim().length() != 4 || !goodsMass.getStyleYear().trim().matches(NUMBER_PATTERN)) {
			goods.setGoodsRegMsg("스타일 년도 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setStyleYear(goodsMass.getStyleYear().trim());

		// 시즌
		if (StringUtils.isBlank(goodsMass.getSeasonCd())) {
			goods.setGoodsRegMsg("시즌 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setSeasonCd(goodsMass.getSeasonCd().trim().toUpperCase()); // 시즌

		CommonCode commonCode = new CommonCode();
		commonCode.setUseYn("Y");
		commonCode.setCdGb("G006"); // 시즌
		commonCode.setCd(goods.getSeasonCd());
		Collection<CommonCode> styleYearList = rendererService.getCommonCodeList(commonCode);
		if (styleYearList == null || styleYearList.isEmpty()) {
			goods.setGoodsRegMsg("시즌 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 성별
		if (StringUtils.isBlank(goodsMass.getSexGb())) {
			goods.setGoodsRegMsg("성별 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setSexGb(goodsMass.getSexGb().trim().toUpperCase()); // 성별
		commonCode.setCdGb("G007"); // 성별
		commonCode.setCd(goods.getSexGb());
		Collection<CommonCode> sexGbList = rendererService.getCommonCodeList(commonCode);
		if (sexGbList == null || sexGbList.isEmpty()) {
			goods.setGoodsRegMsg("성별 오류");
			goods.setGoodsStat("10");
			return goods;
		}

//		// 정상가
//		if (StringUtils.isBlank(goodsMass.getListPrice())) {
//			goods.setGoodsRegMsg("정상가 오류");
//			goods.setGoodsStat("10");
//			return goods;
//		}
//		if (!GagaStringUtil.replace(goodsMass.getListPrice().trim(), ",", "").trim().matches(NUMBER_PATTERN)) {
//			goods.setGoodsRegMsg("정상가 오류");
//			goods.setGoodsStat("10");
//			return goods;
//		}
//
//		// 판매가
//		if (StringUtils.isBlank(goodsMass.getCurrPrice())) {
//			goods.setGoodsRegMsg("판매가 오류");
//			goods.setGoodsStat("10");
//			return goods;
//		}
//		if (!GagaStringUtil.replace(goodsMass.getCurrPrice().trim(), ",", "").trim().matches(NUMBER_PATTERN)) {
//			goods.setGoodsRegMsg("판매가 오류");
//			goods.setGoodsStat("10");
//			return goods;
//		}
//
//		int listPrice = Integer.parseInt(GagaStringUtil.replace(goodsMass.getListPrice().trim(), ",", ""));
//		int currPrice = Integer.parseInt(GagaStringUtil.replace(goodsMass.getCurrPrice().trim(), ",", ""));
//
//		if (currPrice > listPrice) {
//			goods.setGoodsRegMsg("판매가 오류");
//			goods.setGoodsStat("10");
//			return goods;
//		}

		// 정상가
		goods.setListPrice(0);	// 기본처리
		// 판매가
		goods.setCurrPrice(0);	// 기본처리

		// 원가
		goods.setCostPrice(0);	// 기본처리
		// FRJ 필수 확인
//		if ("S006".equals(goods.getBrandCd())) {
//			if (StringUtils.isBlank(goodsMass.getCostPrice())) {
//				goods.setGoodsRegMsg("원가 오류");
//				goods.setGoodsStat("10");
//				return goods;
//			}
//			if (!GagaStringUtil.replace(goodsMass.getCostPrice().trim(), ",", "").matches(NUMBER_PATTERN)) {
//				goods.setGoodsRegMsg("원가 오류");
//				goods.setGoodsStat("10");
//				return goods;
//			}
//			int costPrice = Integer.parseInt(GagaStringUtil.replace(goodsMass.getCostPrice().trim(), ",", ""));
//			// 원가
//			goods.setCostPrice(costPrice);
//		} else {
//			goods.setCostPrice(0);
//		}

		// 정상이월
		if (StringUtils.isBlank(goodsMass.getFormalGb())) {
			goods.setGoodsRegMsg("정상이월 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setFormalGb(goodsMass.getFormalGb().trim().toUpperCase());
		commonCode.setCdGb("G009"); 	//정상이월
		commonCode.setCd(goods.getFormalGb());
		Collection<CommonCode> formalGbList = rendererService.getCommonCodeList(commonCode);
		if (formalGbList == null || formalGbList.isEmpty()) {
			goods.setGoodsRegMsg("정상이월구분 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		//상품연령
		if (StringUtils.isNotBlank(goodsMass.getAgeGrpCd())) {
			goods.setAgeGrpCd(goodsMass.getAgeGrpCd().trim().toUpperCase());
			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;
			}
		}

		// 브랜드 확인
		Brand brand = new Brand();
		brand.setBrandCd(goods.getBrandCd());
		Collection<Brand> brandList = businessService.getBrandList(brand);
		if (brandList == null || brandList.isEmpty()) {
			goods.setGoodsRegMsg("브랜드 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		float pntPrate = 0f;
		float pntMrate = 0f;
//		float sellFeeRate = 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();
			}
//			sellFeeRate = tmpBrand.getSellFeeRate();	//판매수수료율
			distributionGb = tmpBrand.getDistributionGb(); //유통구분
		}
		goods.setPntPrate(pntPrate); // 포인트적립율(PC)
		goods.setPntMrate(pntMrate); // 포인트적립율(MOBILE)

		//출고처 코드
		goods.setDelvLocCd("DL001"); // 자사상품 출고처 코드 고정
		// 업체코드 조회
		Collection<Brand> brandSupplyList = businessService.getBrandSupplyList(goods.getBrandCd());
		String supplyCompCd = brandSupplyList.iterator().next().getSupplyCompCd();
		goods.setSupplyCompCd(supplyCompCd); // 업체코드
		goodsMass.setSupplyCompCd(supplyCompCd); // 업체 코드

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

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

		// 배송비 정책 적용
		Collection<CommonCode> supplyDeliveryFeePolicyList = rendererService.getSupplyDeliveryFeePolicyList(goods.getSupplyCompCd());
		if (supplyDeliveryFeePolicyList != null && !supplyDeliveryFeePolicyList.isEmpty()) {
			goods.setDelvFeeCd(supplyDeliveryFeePolicyList.iterator().next().getCd());
		} else {
			throw new IllegalStateException(message.getMessage("상품의 업체 배송비정책을 확인해 주세요."));
		}

		// 원산지 / 제조국
		if (StringUtils.isBlank(goodsMass.getOriginCd())) {
			goods.setGoodsRegMsg("원산지 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setOriginCd(goodsMass.getOriginCd().trim().toUpperCase());
		commonCode.setCdGb("G076"); // 원산지
		commonCode.setCd(goods.getOriginCd());
		Collection<CommonCode> originCdList = rendererService.getCommonCodeList(commonCode);
		if (originCdList == null || originCdList.isEmpty()) {
			goods.setGoodsRegMsg("원산지 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setOriginNm(originCdList.iterator().next().getCdNm());	//고시정보 적용용

		// 제조년월
		if (StringUtils.isBlank(goodsMass.getMakeYmd())) {
			goods.setGoodsRegMsg("제조년월일 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setMakeYmd(goodsMass.getMakeYmd().trim());

		SimpleDateFormat dateFormatParser = new SimpleDateFormat("yyyyMMdd");
		dateFormatParser.setLenient(false);
		try {
			dateFormatParser.parse(goods.getMakeYmd());
		} catch (Exception e) {
			goods.setGoodsRegMsg("제조년월일 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 상품상세 타이틀 확인
		if (!StringUtils.isBlank(goodsMass.getGoodsTitles())) {
			if (goodsMass.getGoodsTitles().toLowerCase().indexOf("script") >= 0) {
				goods.setGoodsRegMsg("상품타이틀 script 선언 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		}

		// 상품상세 타이틀 내용 확인
		if (!StringUtils.isBlank(goodsMass.getGoodsContent())) {
			if (goodsMass.getGoodsContent().toLowerCase().indexOf("script") >= 0) {
				goods.setGoodsRegMsg("상품타이틀 내용 script 선언 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		}

		// 상품상세 상품 상세 특징 확인
		if (!StringUtils.isBlank(goodsMass.getGoodsCharacter())) {
			if (goodsMass.getGoodsCharacter().toLowerCase().indexOf("script") >= 0) {
				goods.setGoodsRegMsg("상세 특징 내용 script 선언 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		}

		goods.setGoodsType("G056_N"); //상품타입
		goods.setFormalGb("G009_10"); // 정상이월 구분
		goods.setGoodsGb("G073_11"); //상품구분
		goods.setDistributionGb(distributionGb); //유통구분
//		if ("S006".equals(goods.getBrandCd())) { //frj 사입처리
//			goods.setDistributionGb("G065_11"); //자사 - 사입
//		}
		goods.setTaxGb("10"); // 과세구분 10: 과세, 20:비과세
		goods.setSelfGoodsYn("Y"); // 자사상품여부
		goods.setSelfMallYn("Y"); //자사몰 노출여부
		goods.setErpStockLinkYn("Y"); // ERP재고연동여부
		goods.setTobeFormYn("Y"); // 상품상세신규폼사용여부
		goods.setGiftPackYn("Y"); // 선물여부

		return goods;
	}

	/**
	 * 상품 대량 등록 결과 정보
	 *
	 * @param goods
	 * @author eskim
	 * @since 2021. 01. 12
	 */
	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(TssSession.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);
	}

	/**
	 * 상품등록 - 상품고시정보 check
	 *
	 * @param goods
	 * @param goodsNotiList
	 * @return Goods
	 * @author eskim
	 * @since 2021. 01. 12
	 */
	private Goods getGoodsNotiCheck(Goods goods, Collection<GoodsNotiInfo> goodsNotiList, GagaMap excelMap, String procJob) {
		// 고시항목 필수값 입력 확인
		int index = 0;

		if ("createSelfGoods".equals(procJob)) {
			for (GoodsNotiInfo goodsNotiInfo : goodsNotiList) {
				if (StringUtils.isBlank(goodsNotiInfo.getNiContent())) {
					goods.setGoodsRegMsg("고시항목 정보 오류");
					goods.setGoodsStat("G008_20");
					return goods;
				}
			}
		} else {
			for (GoodsNotiInfo goodsNotiInfo : goodsNotiList) {
				if (StringUtils.isBlank(excelMap.getString("niContent" + (index + 1)))) {
					goods.setGoodsRegMsg("고시정보 없음 (" + (index + 1) + "번째 항목) - " + goodsNotiInfo.getNiItemCd() + "(" + goodsNotiInfo.getNiItemNm() + ")");
					goods.setGoodsStat("10");
					return goods;
				}
			}
			index++;

		}

		return goods;
	}

	/**
	 * 상품등록 - 상품고시정보
	 *
	 * @param goods
	 * @param excelMap
	 * @return Goods
	 * @author eskim
	 * @since 2021. 01. 12
	 */
	private void createGoodsNoti(GagaMap excelMap, Collection<GoodsNotiInfo> goodsNotiList) {

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

//			if (StringUtils.isBlank(excelMap.getString("niContent" + (index + 1)))) {
//				goodsNotiInfo.setNiContent(goodsNotiInfo.getNiContent());
//			} else {
//				goodsNotiInfo.setNiContent(excelMap.getString("niContent" + (index + 1)).trim());
//			}
			goodsNotiInfo.setRegNo(TssSession.getInfo().getUserNo());
			goodsNotiInfo.setUpdNo(TssSession.getInfo().getUserNo());
			goodsDao.saveGoodsNotiInfo(goodsNotiInfo);
			index++;
		}
	}

	/**
	 * 상품대량등록 엑셀 저장 - 입점상품
	 *
	 * @param ecxelGoodsList, excelFilename, procJob(자사:createSelfGoods, 입점:createGoods)
	 * @return
	 * @author eskim
	 * @since 2021. 01. 19
	 */
	@Transactional("shopTxnManager")
	public String createExceluploadGoods(GagaMap gagaMap, String procJob, String delvFeeCd, String delvLocCd) {

		GoodsMass goodsMass = mapper.convertValue(gagaMap, GoodsMass.class);
		goodsMass.setDelvFeeCd(delvFeeCd);	// 화면입력값 적용- 배송비
		goodsMass.setDelvLocCd(delvLocCd);	// 화면입력값 적용- 출고처

		// 상품기본정보
		Goods goods = this.createGoodsInfo(goodsMass, procJob);

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

		//상품코드 생성
		goods.setGoodsCd(this.getGoodsCodeSeq("E", goods.getBrandCd())); // 입점상품 상품코드 생성

		//배송비 정책 코드
		goods.setDelvFeeCd(delvFeeCd);

		// 상품고시정보 - 항목및 기본값
		Collection<GoodsNotiInfo> goodsNotiList = goodsDao.getItemkindNotiInfoList(goods);
		if (goodsNotiList == null || goodsNotiList.isEmpty()) {
			goods.setGoodsRegMsg("품목의 고시정보 없음");
			goods.setGoodsStat("10");
			this.setGoodsRegResult(goods, goodsMass, procJob);
			return goods.getGoodsStat();
		}

		// 할인율
		goods.setDcRate((int)(this.getDcRate(goods.getListPrice(), goods.getCurrPrice())));

		Collection<Option> stockList = new ArrayList<>();
		// 입점상품 사이즈 작업
		if (StringUtils.isBlank(goodsMass.getOptStr())) {
			goods.setGoodsRegMsg("옵션 정보 없음");
			goods.setGoodsStat("10");
			this.setGoodsRegResult(goods, goodsMass, procJob);
			return goods.getGoodsStat();
		}

		//옵션1[필수]^옵션2[필수]^추가금액[필수,없을경우0]^안전재고[필수]^판매재고[필수]  |
		//검정^90^0^0^10|검정^95^0^0^8|검정^100^0^0^5|파랑^90^0^0^15|파랑^95^0^0^5|파랑^100^0^0^1|파랑^105^0^0^7

		String[] arrSizeCd = goodsMass.getOptStr().trim().split("\\|");
		for (int i = 0; i < arrSizeCd.length; i++) {
			String[] arrOptCd = arrSizeCd[i].split("\\^");
			if (arrOptCd.length != 5) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 옵션구분자[^] 갯수 상이");
				goods.setGoodsStat("10");
				break;
			}

			// 옵션1 - 필수
			if (StringUtils.isBlank(arrOptCd[0])) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 옵션1 정보없음");
				goods.setGoodsStat("10");
				break;
			}

			if (StringUtils.length(arrOptCd[0]) > 66) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 옵션1명 길이 오류");
				goods.setGoodsStat("10");
			}

			// 옵션2 - 필수
			if (StringUtils.isBlank(arrOptCd[1])) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 옵션2 정보없음");
				goods.setGoodsStat("10");
				break;
			}
			if (StringUtils.length(arrOptCd[0]) > 66) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 옵션2명 길이 오류");
				goods.setGoodsStat("10");
			}
			// 추가금액 - 필수
			if (StringUtils.isBlank(arrOptCd[2])) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 추가금액 정보없음");
				goods.setGoodsStat("10");
				break;
			}
			if (!arrOptCd[2].trim().matches(NUMBER_PATTERN)) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 추가금액 숫자 오류");
				goods.setGoodsStat("10");
				break;
			}
			// 안전재고 - 필수
			if (StringUtils.isBlank(arrOptCd[3])) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 안전재고 정보없음");
				goods.setGoodsStat("10");
				break;
			}
			if (!arrOptCd[3].trim().matches(NUMBER_PATTERN)) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 안전재고 숫자 오류");
				goods.setGoodsStat("10");
				break;
			}
			// 판매재고 - 필수
			if (StringUtils.isBlank(arrOptCd[4])) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 판매재고 정보없음");
				goods.setGoodsStat("10");
				break;
			}
			if (!arrOptCd[4].trim().matches(NUMBER_PATTERN)) {
				goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 판매재고 숫자 오류");
				goods.setGoodsStat("10");
				break;
			}

			Option goodsStock = new Option();
			goodsStock.setGoodsCd(goods.getGoodsCd());
			goodsStock.setOptCd(goods.getGoodsCd() + "-" + (i + 1));
			goodsStock.setOptCd1(arrOptCd[0].trim());
			goodsStock.setOptCd2(arrOptCd[1].trim());
			goodsStock.setAddPrice(Integer.parseInt(arrOptCd[2]));
			goodsStock.setBaseStockQty(Integer.parseInt(arrOptCd[3]));
			goodsStock.setCurrStockQty(Integer.parseInt(arrOptCd[4]));
			goodsStock.setSoldoutYn("N");
			goodsStock.setDispOrd(i + 1);
			goodsStock.setDispYn("Y");
			goodsStock.setRegNo(goods.getRegNo());
			goodsStock.setUpdNo(goods.getUpdNo());

			stockList.add(goodsStock);
		}

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

		// 상품상세 확인
		if (!StringUtils.isBlank(goodsMass.getGoodsContent())) {
			if (goodsMass.getGoodsContent().toLowerCase().indexOf("script") >= 0) {
				goods.setGoodsRegMsg("상품상세 html script 선언 오류");
				goods.setGoodsStat("10");
				this.setGoodsRegResult(goods, goodsMass, procJob);
				return goods.getGoodsStat();
			}
		}

		goods.setSellStdt(GagaDateUtil.getToday() + "000000");
		goods.setSellEddt("30001231235959");

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

		this.createGoodsSize(goods, stockList); // 입점 상품사이즈 정보 자장

		goodsMass.setGoodsCd(goods.getGoodsCd());

		int index = 0;
		// 상품 등록시 고시정보 처리
		for (GoodsNotiInfo goodsNotiInfo : goodsNotiList) {
			if (!StringUtils.isBlank(gagaMap.getString("niContent" + (index + 1)))) {
				goodsNotiInfo.setNiContent(gagaMap.getString("niContent" + (index + 1)));
			}

//			if ("G005_006".equals(goodsNotiInfo.getNiItemCd())) {	//제조국
//				if (!StringUtils.isBlank(goods.getOriginNm())) {
//					goodsNotiInfo.setNiContent(goods.getOriginNm());
//				}
//			} else if ("G005_009".equals(goodsNotiInfo.getNiItemCd())) {	//제조년월
//				if (!StringUtils.isBlank(goods.getMakeYmd())) {
//					goodsNotiInfo.setNiContent(goods.getMakeYmd());
//				}
//			} else if ("G005_097".equals(goodsNotiInfo.getNiItemCd())) {	//수입여부
//				if (!StringUtils.isBlank(goods.getOriginNm()) &&
//					(goods.getOriginNm().indexOf("대한민국") >= 0 || goods.getOriginNm().indexOf("한국") >= 0 || goods.getOriginNm().toUpperCase().indexOf("KOREA") >= 0)) {
//					goodsNotiInfo.setNiContent("N");
//				} else {
//					goodsNotiInfo.setNiContent("Y");
//				}
//			} else if ("G005_099".equals(goodsNotiInfo.getNiItemCd())) {	//종류
//				if (!StringUtils.isBlank(goods.getItemkindNm())) {
//					goodsNotiInfo.setNiContent(goods.getItemkindNm());
//				}
//			}
			index++;
		}

		//고시항목 필수값 확인
		goods = this.getGoodsNotiCheck(goods, goodsNotiList, gagaMap, procJob);

		//고시 필수 항목 미입력으로 상품 상태 변경
		if ("G008_20".equals(goods.getGoodsStat())) {
			goodsDao.updateGoodsStatOnly(goods);
		}

		this.createGoodsNoti(gagaMap, goodsNotiList); // 상품고시정보 저장

		// 상품상세(입점)
		if (!StringUtils.isBlank(goodsMass.getGoodsContent())) {
			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);
		}

		// 사용자 검색어를 검색어에 적용
		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);

		// 전시카테고리 작업
		goodsDao.createCategoryGoods(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);
		}

		this.setGoodsRegResult(goods, goodsMass, procJob);

		return goods.getGoodsStat();

	}

	/**
	 * 상품등록 - 상품기본정보 - 입점상품
	 *
	 * @param goodsMass
	 * @param excelFilename
	 * @author eskim
	 * @since 2021. 01. 19
	 */
	private Goods createGoodsInfo(GoodsMass goodsMass, String procJob) {

		Goods goods = new Goods();
		goods.setGoodsStat("G008_20"); // 상품상태
		goods.setGoodsRegMsg("이미지 등록 필요");
		goods.setRegNo(TssSession.getInfo().getUserNo());
		goods.setUpdNo(TssSession.getInfo().getUserNo());

		//log.info("goodsMass= > {}" ,goodsMass);
		if (StringUtils.isBlank(goodsMass.getSupplyGoodsCd())) {
			goods.setGoodsRegMsg("공급업체 상품코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}

//		if (!GagaStringUtil.replace(goodsMass.getSupplyGoodsCd().trim(), ",", "").matches(ALPHA_NUMERIC)) {
//			goods.setGoodsRegMsg("공급업체 상품코드 오류");
//			goods.setGoodsStat("10");
//			return goods;
//		}

		goods.setSupplyGoodsCd(goodsMass.getSupplyGoodsCd().trim().toUpperCase());

		if (StringUtils.isBlank(goodsMass.getSupplyCompCd())) {
			goods.setGoodsRegMsg("공급업체 코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setSupplyCompCd(goodsMass.getSupplyCompCd().trim().toUpperCase());

		// 사용자와 엑셀정보의 업체코드 확인
		if (!goods.getSupplyCompCd().equals(TssSession.getInfo().getSupplyCompCd())) {
			goods.setGoodsRegMsg("공급업체 코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 상품코드 중복여부 확인 - 입점업체코드+입점상품코드
		Goods goodsDup = goodsDao.getGoods(goods);
		if (goodsDup != null) {
			goods.setGoodsRegMsg("상품코드 중복등록요청");
			goods.setGoodsStat("10");
			return goods;
		}

		// 브랜드
		if (StringUtils.isBlank(goodsMass.getBrandCd())) {
			goods.setGoodsRegMsg("브랜드코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setBrandCd(goodsMass.getBrandCd().trim().toUpperCase()); // 브랜드 코드

		// 상품명
		if (StringUtils.isBlank(goodsMass.getGoodsNm())) {
			goods.setGoodsRegMsg("상품명 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		if (StringUtils.length(goodsMass.getGoodsNm()) > 66) {
			goods.setGoodsRegMsg("상품명 길이 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		goods.setGoodsNm(goodsMass.getGoodsNm().trim().replaceAll("(\\r\\n|\\r|\\n|\\n\\r)", ""));

		if (!StringUtils.isBlank(goodsMass.getGoodsTnm())) {
			if (StringUtils.length(goodsMass.getGoodsTnm()) > 33) {
				goods.setGoodsRegMsg("상품타이틀명 길이 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setGoodsTnm(goodsMass.getGoodsTnm().trim().replaceAll("(\\r\\n|\\r|\\n|\\n\\r)", "")); // 상품 타이틀
		}

		if (!StringUtils.isBlank(goodsMass.getGoodsSnm1())) {
			if (StringUtils.length(goodsMass.getGoodsSnm1()) > 1000) {
				goods.setGoodsRegMsg("상품검색명 길이 오류");
				goods.setGoodsStat("10");
				return goods;
			}

			goods.setGoodsSnm1(goodsMass.getGoodsSnm1().trim().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());

		Itemkind itemkind = new Itemkind();
		itemkind.setItemkindCd(goods.getItemkindCd());
		itemkind.setUseYn("Y");
		Collection<Itemkind> getItemkindList = goodsDao.getItemkindList(itemkind);
		if (getItemkindList == null || getItemkindList.size() == 0) {
			goods.setGoodsRegMsg("품목코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setItemkindNm(getItemkindList.iterator().next().getItemkindLeafNm());	//LEAF품목명
		String safeNiClsfCd = getItemkindList.iterator().next().getNiClsfCd(); // 안전인증확인용 고시분류- 유아용품 G004_23

		// 성별
		if (StringUtils.isBlank(goodsMass.getSexGb())) {
			goods.setGoodsRegMsg("성별 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setSexGb(goodsMass.getSexGb().trim().toUpperCase()); // 성별
		CommonCode commonCode = new CommonCode();
		commonCode.setUseYn("Y");
		commonCode.setCdGb("G007"); // 성별
		commonCode.setCd(goods.getSexGb());
		Collection<CommonCode> sexGbList = rendererService.getCommonCodeList(commonCode);
		if (sexGbList == null || sexGbList.isEmpty()) {
			goods.setGoodsRegMsg("성별 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 정상가
		if (StringUtils.isBlank(goodsMass.getListPrice())) {
			goods.setGoodsRegMsg("정상가 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		if (!GagaStringUtil.replace(goodsMass.getListPrice().trim(), ",", "").matches(NUMBER_PATTERN)) {
			goods.setGoodsRegMsg("정상가 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 판매가
		if (StringUtils.isBlank(goodsMass.getCurrPrice())) {
			goods.setGoodsRegMsg("판매가 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		if (!GagaStringUtil.replace(goodsMass.getCurrPrice().trim(), ",", "").matches(NUMBER_PATTERN)) {
			goods.setGoodsRegMsg("판매가 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		int listPrice = Integer.parseInt(GagaStringUtil.replace(goodsMass.getListPrice().trim(), ",", ""));
		int currPrice = Integer.parseInt(GagaStringUtil.replace(goodsMass.getCurrPrice().trim(), ",", ""));

		if (currPrice > listPrice) {
			goods.setGoodsRegMsg("판매가 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 정상가
		goods.setListPrice(listPrice);
		// 판매가
		goods.setCurrPrice(currPrice);
		// 원가
		goods.setCostPrice(0);

		// 상품구분
		if (StringUtils.isBlank(goodsMass.getGoodsGb())) {
			goods.setGoodsRegMsg("상품구분 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setGoodsGb(goodsMass.getGoodsGb().trim().toUpperCase());
		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;
		}

		// 정상이월
		if (StringUtils.isBlank(goodsMass.getFormalGb())) {
			goods.setGoodsRegMsg("정상이월 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setFormalGb(goodsMass.getFormalGb().trim().toUpperCase());
		commonCode.setCdGb("G009"); 	//정상이월
		commonCode.setCd(goods.getFormalGb());
		Collection<CommonCode> formalGbList = rendererService.getCommonCodeList(commonCode);
		if (formalGbList == null || formalGbList.isEmpty()) {
			goods.setGoodsRegMsg("정상이월구분 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 시즌
		if (StringUtils.isBlank(goodsMass.getSeasonCd())) {
			goods.setGoodsRegMsg("시즌코드 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setSeasonCd(goodsMass.getSeasonCd().trim().toUpperCase());
		commonCode.setCdGb("G006"); 	//시즌
		commonCode.setCd(goods.getSeasonCd());
		Collection<CommonCode> seasonCdList = rendererService.getCommonCodeList(commonCode);
		if (seasonCdList == null || seasonCdList.isEmpty()) {
			goods.setGoodsRegMsg("시즌코드구분 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 브랜드 확인
		Brand brand = new Brand();
		brand.setBrandCd(goods.getBrandCd());
		Collection<Brand> brandList = businessService.getBrandList(brand);
		if (brandList == null || brandList.isEmpty()) {
			goods.setGoodsRegMsg("브랜드 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		float pntPrate = 0f;
		float pntMrate = 0f;
		String distributionGb = "G065_20";
		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)

		// 판매수수료율
		SupplyCompany supplyCompany = new SupplyCompany();
		supplyCompany.setSupplyCompCd(goods.getSupplyCompCd());
		Collection<SupplyCompany> supplyCompanyList = businessService.getSupplyCompanyList(supplyCompany);
		if (supplyCompanyList == null || supplyCompanyList.isEmpty()) {
			goods.setGoodsRegMsg("업체 판매수수율를 확인");
			goods.setGoodsStat("10");
			return goods;
		}

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

		// 배송비 정책 적용
		boolean deliveryFolicy = false;
		Collection<CommonCode> supplyDeliveryFeePolicyList = rendererService.getSupplyDeliveryFeePolicyList(goods.getSupplyCompCd());
		if (supplyDeliveryFeePolicyList != null && !supplyDeliveryFeePolicyList.isEmpty()) {
			for (CommonCode supplyDeliveryFeePolicy : supplyDeliveryFeePolicyList) {
				if (goodsMass.getDelvFeeCd().equals(supplyDeliveryFeePolicy.getCd())) {
					deliveryFolicy = true;
					break;
				}
			}
			if (!deliveryFolicy) {
				goods.setGoodsRegMsg("배송비정책 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		} else {
			goods.setGoodsRegMsg("배송비정책 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 배송비 정책
		goods.setDelvFeeCd(goodsMass.getDelvFeeCd()); // 화면에서 받은값

		// 출고처 적용
		boolean delvLocCd = false;
		Collection<CommonCode> supplyDeliveryLocList = rendererService.getSupplyDeliveryLocList(goods.getSupplyCompCd());
		if (supplyDeliveryLocList != null && !supplyDeliveryLocList.isEmpty()) {
			for (CommonCode supplyDeliveryLoc : supplyDeliveryLocList) {
				if (goodsMass.getDelvLocCd().equals(supplyDeliveryLoc.getCd())) {
					delvLocCd = true;
					break;
				}
			}
			if (!delvLocCd) {
				goods.setGoodsRegMsg("출고처 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		} else {
			goods.setGoodsRegMsg("출고처 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 출고처 정책
		goods.setDelvLocCd(goodsMass.getDelvLocCd()); // 화면에서 받은값

		// 원산지 / 제조국
		if (StringUtils.isBlank(goodsMass.getOriginCd())) {
			goods.setGoodsRegMsg("원산지 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setOriginCd(goodsMass.getOriginCd().trim().toUpperCase());

		commonCode.setCdGb("G076"); // 원산지
		commonCode.setCd(goods.getOriginCd());
		Collection<CommonCode> originCdList = rendererService.getCommonCodeList(commonCode);
		if (originCdList == null || originCdList.isEmpty()) {
			goods.setGoodsRegMsg("원산지 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setOriginNm(originCdList.iterator().next().getCdNm());	//고시정보 적용용

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

		//상품연령
		if (StringUtils.isNotBlank(goodsMass.getAgeGrpCd())) {
			goods.setAgeGrpCd(goodsMass.getAgeGrpCd().trim().toUpperCase());

			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;
			}
		}

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

		// 제조년월
		if (StringUtils.isBlank(goodsMass.getMakeYmd())) {
			goods.setGoodsRegMsg("제조년월일 오류");
			goods.setGoodsStat("10");
			return goods;
		}
		goods.setMakeYmd(goodsMass.getMakeYmd().trim());

		SimpleDateFormat dateFormatParser = new SimpleDateFormat("yyyyMMdd");
		dateFormatParser.setLenient(false);
		try {
			dateFormatParser.parse(goods.getMakeYmd());
		} catch (Exception e) {
			goods.setGoodsRegMsg("제조년월일 오류");
			goods.setGoodsStat("10");
			return goods;
		}

		// 안전인증 체크
		if (!StringUtils.isBlank(goodsMass.getCertTargetGb())) {

			//인증대상구분
			commonCode.setCdGb("G083");
			commonCode.setCd(goodsMass.getCertTargetGb());
			Collection<CommonCode> certTargetGbList = rendererService.getCommonCodeList(commonCode);
			if (certTargetGbList == null || certTargetGbList.isEmpty()) {
				goods.setGoodsRegMsg("인증대상 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setCertTargetGb(goodsMass.getCertTargetGb().trim());

			if (!"G083_1".equals(goodsMass.getCertTargetGb())) {
				if (!StringUtils.isBlank(goodsMass.getCertNum()) ||
					!StringUtils.isBlank(goodsMass.getCertFormGb()) ||
					!StringUtils.isBlank(goodsMass.getCertType())) {
					goods.setGoodsRegMsg("인증정보 오류(인증대상만 입력)");
					goods.setGoodsStat("10");
					return goods;
				}
			}

			//인증형태구분
			if (StringUtils.isBlank(goodsMass.getCertFormGb())) {
				goods.setGoodsRegMsg("인증형태 오류");
				goods.setGoodsStat("10");
				return goods;
			}

			commonCode.setCdGb("G084");
			commonCode.setCd(goodsMass.getCertFormGb());
			Collection<CommonCode> certFormGbList = rendererService.getCommonCodeList(commonCode);
			if (certFormGbList == null || certFormGbList.isEmpty()) {
				goods.setGoodsRegMsg("인증형태 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setCertFormGb(goodsMass.getCertFormGb().trim());

			//인증타입
			if (StringUtils.isBlank(goodsMass.getCertType())) {
				goods.setGoodsRegMsg("인증타입 오류");
				goods.setGoodsStat("10");
				return goods;
			}

			commonCode.setCdGb("G081");
			commonCode.setCd(goodsMass.getCertType());
			Collection<CommonCode> certTypeList = rendererService.getCommonCodeList(commonCode);
			if (certTypeList == null || certTypeList.isEmpty()) {
				goods.setGoodsRegMsg("인증타입 오류");
				goods.setGoodsStat("10");
				return goods;
			}
			goods.setCertType(goodsMass.getCertType().trim());

			if ("G081_1".equals(goodsMass.getCertType()) || "G081_2".equals(goodsMass.getCertType())) {
				if (StringUtils.isBlank(goodsMass.getCertNum())) {
					goods.setGoodsRegMsg("인증번호 오류");
					goods.setGoodsStat("10");
					return goods;
				}
			}
			if (!StringUtils.isBlank(goodsMass.getCertNum())) {
				goods.setCertNum(goodsMass.getCertNum().trim()); //안전인증번호
			}

		}
		else {
			if (!StringUtils.isBlank(goodsMass.getCertFormGb()) || 
				!StringUtils.isBlank(goodsMass.getCertType()) || 
				!StringUtils.isBlank(goodsMass.getCertNum())) {
				goods.setGoodsRegMsg("인증대상 오류");
				goods.setGoodsStat("10");
				return goods;
			}
		}

		goods.setGoodsType("G056_N"); //상품타입
		goods.setDistributionGb(distributionGb); //유통구분
		goods.setSelfGoodsYn("N"); // 자사상품여부
		goods.setSelfMallYn("Y"); //자사몰 노출여부
		goods.setErpStockLinkYn("N"); // ERP재고연동여부
		goods.setMainColorCd("XX"); // 무의미 데이터
		goods.setTobeFormYn("N"); // 입점 신규 기본값

		return goods;
	}

	/**
	 * 상품 코드 생성
	 *
	 * @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 goods
	 * @param excelMap
	 * @return Goods
	 * @author eskim
	 * @since 2021. 01. 19
	 */
	private void createGoodsSize(Goods goods, Collection<Option> stockist) {

		for (Option stock : stockist) {
			goodsDao.saveStock(stock);
		}
	}

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

		// 사용자의 관리 브랜드 조회
		Collection<CommonCode> mdBrandList = rendererService.getSupplyCompanyBrandList(TssSession.getInfo().getSupplyCompCd());

		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, mdBrandList, goodsOrigin);

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

		// 옵션
		Collection<Option> stockList = new ArrayList<>();
		if (!UPDATE_NO_PATTERN.equals(goodsMass.getOptStr().trim())) {

			//옵션1[필수]^옵션2[선택]^추가금액^안전재고[필수]^판매재고[필수]  |
			//검정^90^0^0^10|검정^95^0^0^8|검정^100^0^0^5|파랑^90^0^0^15|파랑^95^0^0^5|파랑^100^0^0^1|파랑^105^0^0^7

			Option dupOption = new Option();
			dupOption.setGoodsCd(goodsMass.getGoodsCd());
			int cnt = goodsDao.getGoodsOptionCount(dupOption); // 기 등록된 옵션 건수 조회

			String[] arrSizeCd = goodsMass.getOptStr().trim().split("\\|");
			for (int i = 0; i < arrSizeCd.length; i++) {
				String[] arrOptCd = arrSizeCd[i].split("\\^");
				//log.info("[ arrOptCd.length] {}", arrOptCd.length);
				if (arrOptCd.length != 5) {
					goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 옵션구분자[^] 갯수 상이");
					goods.setGoodsStat("10");
					break;
				}

				// 옵션1 - 필수
				if (StringUtils.isBlank(arrOptCd[0])) {
					goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 옵션1 정보없음");
					goods.setGoodsStat("10");
					break;
				}
				// 추가금액 - 필수
				if (StringUtils.isBlank(arrOptCd[2])) {
					goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 추가금액 정보없음");
					goods.setGoodsStat("10");
					break;
				}
				if (!arrOptCd[2].trim().matches(NUMBER_PATTERN)) {
					goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 추가금액 숫자 오류");
					goods.setGoodsStat("10");
					break;
				}
				// 안전재고 - 필수
				if (StringUtils.isBlank(arrOptCd[3])) {
					goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 안전재고 정보없음");
					goods.setGoodsStat("10");
					break;
				}
				if (!arrOptCd[3].trim().matches(NUMBER_PATTERN)) {
					goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 안전재고 숫자 오류");
					goods.setGoodsStat("10");
					break;
				}
				// 판매재고 - 필수
				if (StringUtils.isBlank(arrOptCd[4])) {
					goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 판매재고 정보없음");
					goods.setGoodsStat("10");
					break;
				}
				if (!arrOptCd[4].trim().matches(NUMBER_PATTERN)) {
					goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 판매재고 숫자 오류");
					goods.setGoodsStat("10");
					break;
				}

				// 옵션 중복 여부 확인
				String optCd1 = arrOptCd[0];
				String optCd2 = arrOptCd[1];
				dupOption.setOptCd1(optCd1);
				dupOption.setOptCd2(optCd2);

				//상품옵션 중복건수여부 확인
				int dupOptionCnt = goodsDao.getGoodsOptionDupCountCheck(dupOption);
				if (dupOptionCnt > 0) {
					goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 옵션1과 옵션2가 중복되는 옵션이 존재합니다.");
					goods.setGoodsStat("10");
					break;
				}

				//상품옵션 패턴조회
				Option goodsOption = goodsDao.getGoodsOption(dupOption);
				if (goodsOption != null) {
					if (StringUtils.isBlank(goodsOption.getOptCd2()) == !StringUtils.isBlank(optCd2) || !StringUtils.isBlank(goodsOption.getOptCd2()) == StringUtils.isBlank(optCd2)) {
						goods.setGoodsRegMsg("옵션(SKU) " + (i + 1) + "번째 옵션2가 기 등록된 옵션2의 패턴과 다릅니다.");
						goods.setGoodsStat("10");
						break;
					}
				}

				Option goodsStock = new Option();
				goodsStock.setGoodsCd(goods.getGoodsCd());
				goodsStock.setOptCd(goods.getGoodsCd() + "-" + (cnt + (i + 1)));
				goodsStock.setOptCd1(arrOptCd[0].trim());
				goodsStock.setOptCd2(arrOptCd[1].trim());
				goodsStock.setAddPrice(Integer.parseInt(arrOptCd[2]));
				goodsStock.setBaseStockQty(Integer.parseInt(arrOptCd[3]));
				goodsStock.setCurrStockQty(Integer.parseInt(arrOptCd[4]));
				goodsStock.setSoldoutYn("N");
				goodsStock.setDispOrd(cnt + (i + 1));
				goodsStock.setDispYn("Y");
				goodsStock.setRegNo(goods.getRegNo());
				goodsStock.setUpdNo(goods.getUpdNo());

				stockList.add(goodsStock);
			}
		}

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

		// 상품 고시
		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(TssSession.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(TssSession.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(goodsMass.getOptStr().trim()) && stockList != null && !stockList.isEmpty()) {
			goods.setSelfGoodsYn(goodsOrigin.getSelfGoodsYn());
			this.createGoodsSize(goods, stockList); // 입점 상품사이즈 정보 자장
		}

		// 품목변경시 카테고리 자동 전시
		if ("Y".equals(goods.getChDataYn()) && !UPDATE_NO_PATTERN.equals(goods.getItemkindCd().trim())) {
			GoodsCategory goodsCategory = new GoodsCategory();
			goodsCategory.setRegNo(TssSession.getInfo().getUserNo());
			goodsCategory.setUpdNo(TssSession.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 goodsMass
	 * @param excelFilename
	 * @author eskim
	 * @since 2021. 1. 20
	 */
	private Goods updateMassGoodsInfo(GoodsMass goodsMass, String procJob, Collection<CommonCode> mdBrandList, Goods goodsOrigin) {

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

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

		//촬영업체 skip(상품정보 수정할수 없음)
		if ("G001_E000".equals(TssSession.getInfo().getRoleCd())) {
			return goods;
		}

		// 입점담당자 해당 브랜드 체크
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			// 해당MD 조회
			if (mdBrandList == null || mdBrandList.isEmpty()) {
				goods.setGoodsRegMsg("미관리 브랜드");
				goods.setGoodsStat("10");
				return goods;
			}
			boolean mdBrandFlag = false;
			for (CommonCode commonCode : mdBrandList) {
				if (goodsOrigin.getBrandCd().equals(commonCode.getCd())) {
					mdBrandFlag = true;
				}
			}
			if (!mdBrandFlag) {
				goods.setGoodsRegMsg("미관리 브랜드");
				goods.setGoodsStat("10");
				return goods;
			}
		}

		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 {
				//입점
				GoodsSupplyPrice goodsSupplyPrice = new GoodsSupplyPrice();
				goodsSupplyPrice.setGoodsCd(goods.getGoodsCd());
				if (goods.getCurrPrice() != goods.getCurrPriceOrg()) {
					goodsSupplyPrice.setSupplyGoodsPrice(goods.getCurrPrice());
				}
				if (goods.getSellFeeRate() != goods.getSellFeeRateOrg()) {
					goodsSupplyPrice.setSupplySellFeeRate(goods.getSellFeeRate());
				}
				goodsSupplyPrice.setCfrmYn("N");
				goodsSupplyPrice.setRegNo(goods.getRegNo());
				goodsSupplyPrice.setUpdNo(goods.getUpdNo());
				goodsDao.createGoodSupplyPrice(goodsSupplyPrice);

				// 상품테이블에 바로 변경하지 않고 입점상품가격관리에서 승인해야함
				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
	 * @return Goods
	 * @author eskim
	 * @since 2021. 01. 20
	 */
	//	private Goods getUpdateMassGoodsNotiCheck_org(Goods goods, GagaMap excelMap, Goods goodsOrigin) {
	//
	//		// 고시분류 확인
	//		// 고시분류의 항목과 엑셀데이터 매핑
	//		// 필수
	//		String oldItemKindCd = goodsOrigin.getItemkindCd();
	//		String itemkindCd = goods.getItemkindCd();
	//		if (UPDATE_NO_PATTERN.equals(goods.getItemkindCd())) {
	//			itemkindCd = oldItemKindCd;
	//		}
	//		// old 품목고시분류 조회
	//		String oldNiClsfCd = "";
	//		Goods goodsNoti = new Goods();
	//		goodsNoti.setGoodsCd(goods.getGoodsCd());
	//		goodsNoti.setSupplyVendorCd(goodsOrigin.getSupplyVendorCd());
	//		goodsNoti.setItemkindCd(oldItemKindCd);
	//		Collection<GoodsNotiInfo> oldGoodsNotiList = goodsDao.getItemkindNotiInfoList(goodsNoti);
	//		if (oldGoodsNotiList != null && oldGoodsNotiList.isEmpty()) {
	//			for (GoodsNotiInfo oldGoodsNotiInfo : oldGoodsNotiList) {
	//				oldNiClsfCd = oldGoodsNotiInfo.getNiClsfCd();
	//				break;
	//			}
	//		}
	//		// 품목코드가 변경되었을 경우
	//		if (!oldItemKindCd.equals(itemkindCd)) {
	//			goods.setChNotiYn("Y");
	//
	//			// new 품목고시분류 조회
	//			String newNiClsfCd = "";
	//			goodsNoti.setItemkindCd(itemkindCd);
	//			Collection<GoodsNotiInfo> newGoodsNotiList = goodsDao.getItemkindNotiInfoList(goodsNoti);
	//			if (newGoodsNotiList == null || newGoodsNotiList.isEmpty()) {
	//				goods.setGoodsRegMsg("품목의 고시정보 없음");
	//				goods.setGoodsStat("10");
	//				return goods;
	//			} else {
	//				for (GoodsNotiInfo newGoodsNotiInfo : newGoodsNotiList) {
	//					newNiClsfCd = newGoodsNotiInfo.getNiClsfCd();
	//					break;
	//				}
	//			}
	//
	//			if (!oldNiClsfCd.equals(newNiClsfCd) && !UPDATE_NO_PATTERN.equals(excelMap.getString("niClsfCd"))) {
	//				goods.setGoodsRegMsg("고시분류 오류");
	//				goods.setGoodsStat("10");
	//				return goods;
	//			}
	//
	//			// 상품고시정보
	//			Collection<GoodsNotiInfo> goodsNotiList = goodsDao.getItemkindNotiInfoList(goodsNoti);
	//			if (goodsNotiList == null || goodsNotiList.isEmpty()) {
	//				goods.setGoodsRegMsg("품목의 고시정보 없음");
	//				goods.setGoodsStat("10");
	//				return goods;
	//			}
	//		} else {
	//			if (!UPDATE_NO_PATTERN.equals(excelMap.getString("niClsfCd"))
	//				&& !oldNiClsfCd.equals(excelMap.getString("niClsfCd"))) {
	//				goods.setGoodsRegMsg("고시분류 오류..");
	//				goods.setGoodsStat("10");
	//				return goods;
	//			}
	//		}
	//
	//		for (int i = 0; i < 28; i++) {
	//			String niContentVal = excelMap.getString("niContent" + (i + 1));
	//			if (!UPDATE_NO_PATTERN.equals(niContentVal)) {
	//				goods.setChNotiYn("Y");
	//			}
	//		}
	//
	//		return goods;
	//	}

	/**
	 * 상품대량수정 - 상품고시정보 check
	 *
	 * @param goods
	 * @param excelMap
	 * @param goodsOrigin
	 * @param newGoodsNotiList
	 * @return Goods
	 * @author eskim
	 * @since 2021. 01. 20
	 */
	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(TssSession.getInfo().getUserNo());
			goodsNotiInfoTmp.setUpdNo(TssSession.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 goodsList
	 * @return
	 * @author eskim
	 * @since 2021. 01. 24
	 */
	@Transactional("shopTxnManager")
	//@CacheEvict(value = "cate", allEntries = true)
	public void saveItemKindChange(Collection<Goods> goodsList) {
		for (Goods goods : goodsList) {
			goods.setRegNo(TssSession.getInfo().getUserNo());
			goods.setUpdNo(TssSession.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(TssSession.getInfo().getUserNo());
			//				goodsNotiInfo.setUpdNo(TssSession.getInfo().getUserNo());
			//				goodsNotiInfo.setGoodsCd(goods.getGoodsCd());
			//				goodsDao.saveGoodsNotiInfo(goodsNotiInfo);
			//			}

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

	/**
	 * 사은품 목록
	 *
	 * @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(TssSession.getInfo().getUserNo());
		goodsDao.updateFreeGoods(freeGoods);
	}

	/**
	 * 상품 안전인증 조회
	 *
	 * @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. 12. 07
	 */
	@Transactional("shopTxnManager")
	public void saveGoodsDetailCertNum(GoodsSafeNo goodsSafeNo) {
		try {
			goodsSafeNo.setRegNo(TssSession.getInfo().getUserNo());
			goodsSafeNo.setUpdNo(TssSession.getInfo().getUserNo());
			//인증대상
			if ("G083_1".equals(goodsSafeNo.getCertTargetGb())) {

				//인증형태 (방송통신, 위해) or 인증타입 - 공급자적합성,해당없음
				if ("G084_4".equals(goodsSafeNo.getCertFormGb()) || "G084_5".equals(goodsSafeNo.getCertFormGb()) || "G081_3".equals(goodsSafeNo.getCertType()) || "G081_4".equals(goodsSafeNo.getCertType())) {
					goodsSafeNo.setCertDt("");
					goodsSafeNo.setCertState("");
					goodsSafeNo.setCertDiv("");
					goodsSafeNo.setCertOrganName("");
					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());
						goodsDao.saveGoodsSafeNo(goodsSafeNo);
					} else {
						goodsSafeNo.setCertDt("");
						goodsSafeNo.setCertState("");
						goodsSafeNo.setCertDiv("");
						goodsSafeNo.setCertOrganName("");
						goodsDao.saveGoodsSafeNo(goodsSafeNo);
					}
				}
			} else {	//인증대상 그외 - 인증처리 안해도 됨
				goodsSafeNo.setCertDt("");
				goodsSafeNo.setCertState("");
				goodsSafeNo.setCertDiv("");
				goodsSafeNo.setCertOrganName("");
				goodsDao.saveGoodsSafeNo(goodsSafeNo);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

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

	/**
	 * 입점 상품 등록
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2021. 04. 21
	 */
	@Transactional("shopTxnManager")
	public void createGoodsDetail(Goods goods) {

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

		//log.info("[createGoodsDetail 11] goods=>{}", goods);
		// 상품코드 생성
		goods.setGoodsCd(this.getGoodsCodeSeq("E", goods.getBrandCd())); // 입점상품 상품코드 생성
		goods.setErpStockLinkYn("N");
		goods.setGoodsStat("G008_20");
		goods.setNewCustOrdYn("N");
		goods.setMainColorCd("XX");
		goods.setSelfGoodsYn("N");
		goods.setGoodsType("G056_N");
		goods.setTobeFormYn("N");
		
		// <,> replace 처리
		goods.setRegNo(TssSession.getInfo().getUserNo());
		goods.setUpdNo(TssSession.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");
		
		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;
		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.setPrePpntUsableYn("N");
		goods.setPreMpntUsableYn("N");

		//log.info("[createGoodsDetail 22 ] goods=>{}", goods);
		// 기본정보 생성
		goodsDao.createGoods(goods); // 상품기본 저장
		goodsDao.createGoodsSmmary(goods); // 상품통계 생성

		// 사용자 검색어를 검색어에 적용
		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);
		}

		//log.info("[createGoodsDetail 33 ] goods.getGoodsSnm()=>{}", goods.getGoodsSnm());

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

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

		// 옵션/재고 저장
		int index = 0;
		for (String optCd1 : goods.getOptCd1()) {
			String optCd = goods.getGoodsCd() + "-" + (index + 1);

			Option goodsStock = new Option();
			goodsStock.setGoodsCd(goods.getGoodsCd()); // 구성상품 코드
			goodsStock.setOptCd(optCd);
			goodsStock.setOptCd1(optCd1);
			goodsStock.setOptCd2(goods.getOptCd2()[index]);
			goodsStock.setAddPrice(Integer.parseInt(goods.getAddPrice()[index]));
			goodsStock.setBaseStockQty(Integer.parseInt(goods.getBaseStockQty()[index]));
			goodsStock.setCurrStockQty(Integer.parseInt(goods.getEditCurrStockQty()[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());
			goodsStock.setSelfGoodsYn(goods.getSelfGoodsYn());
			//log.info("[createGoodsDetail 44 ] goodsStock=>{}", goodsStock);
			goodsDao.saveStock(goodsStock);
			index++;
		}

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

		// 전시카테고리 작업
		goodsDao.createCategoryGoods(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 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);
	}

	/**
	 * 상품옵션1 존재 여부 확인
	 *
	 * @param
	 * @return
	 * @author eskim
	 * @since 2021. 05. 16
	 */
	public int getGoodsOption1Count(Option option) {

		return goodsDao.getGoodsOption1Count(option);
	}

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

		Goods regGoods = new Goods();

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

		//상품코드 생성
		regGoods.setGoodsType("G056_D");
//		regGoods.setGoodsNm(GagaStringUtil.replace(GagaStringUtil.replace(goods.getGoodsNm(), "&lt;", "<"), "&gt;", ">"));
		regGoods.setGoodsNm(goods.getGoodsNm());
		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.setTaxGb("10"); // 과세구분
		regGoods.setTobeFormYn("N");
		regGoods.setSeasonCd(goods.getSeasonCd());	//시즌

		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) {

			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())));
			}
		}

		String goodsCd = this.getGoodsCodeSeq("E", regGoods.getBrandCd()); // 입점상품 상품코드 생성
		regGoods.setGoodsCd(goodsCd);
		regGoods.setSupplyGoodsCd(goodsCd);

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

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

	/**
	 * 딜 상품 관련 저장
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2021. 05. 26
	 */
	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); // 유통구분

		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");

		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 goods
	 * @return
	 * @author eskim
	 * @since 2021. 05. 26
	 */
	public Collection<GoodsCompose> getGoodsDetailComposeList(Goods goods) {
		return goodsDao.getGoodsDetailComposeList(goods);
	}

	/**
	 * 품목 목록
	 * @param itemkind - 품목 정보
	 * @return 품목 목록
	 * @author eskim
	 * @since 2021. 06. 17
	 */
	public Collection<Itemkind> getItemkindList(Itemkind itemkind) {
		return goodsDao.getItemkindList(itemkind);
	}

	/**
	 * 자사 상품 등록
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2021. 07. 02
	 */
	@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(TssSession.getInfo().getUserNo());
		goods.setUpdNo(TssSession.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());
		// 정상가
		goods.setListPrice(0);	// 기본처리
		// 판매가
		goods.setCurrPrice(0);	// 기본처리
		// 원가
		goods.setCostPrice(0);	// 기본처리	
		
		// 판매수수료율
		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(TssSession.getInfo().getUserNo());
		wmsGoods.setGoodsRegGb("G"); // G: 상품, F: 사은품
		wmsGoods.setModelNo(goods.getGoodsCd());

		goodsDao.saveGoodsWmsIncomelot(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(Integer.parseInt(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(TssSession.getInfo().getUserNo());
				goodsStock.setUpdNo(TssSession.getInfo().getUserNo());
				goodsDao.saveStock(goodsStock);
				index++;
			}
		}

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

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

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

	}

}
