package com.style24.scm.biz.web;

import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.swing.ImageIcon;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.style24.core.support.env.TscConstants.GoodsType;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.TscPageRequest;
import com.style24.persistence.domain.CommonCode;
import com.style24.persistence.domain.FreeGoods;
import com.style24.persistence.domain.Goods;
import com.style24.persistence.domain.GoodsCompose;
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.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.SupplyCompany;
import com.style24.scm.biz.service.TssBusinessService;
import com.style24.scm.biz.service.TssCommonService;
import com.style24.scm.biz.service.TssGoodsService;
import com.style24.scm.biz.service.TssRendererService;
import com.style24.scm.support.controller.TssBaseController;
import com.style24.scm.support.security.session.TssSession;

import lombok.extern.slf4j.Slf4j;

import com.gagaframework.excel.GagaExcelUtil;
import com.gagaframework.web.parameter.GagaMap;
import com.gagaframework.web.rest.server.GagaResponse;
import com.gagaframework.web.rest.server.GagaResponseStatus;
import com.gagaframework.web.util.GagaDateUtil;
import com.gagaframework.web.util.GagaFileUtil;
import com.gagaframework.web.util.GagaStringUtil;

/**
 * 상품관리 Controller
 *
 * @author gagamel
 * @since 2020. 10. 19
 */
@Controller
@RequestMapping("/goods")
@Slf4j
public class TssGoodsController extends TssBaseController {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private Environment env;

	@Autowired
	private TssGoodsService goodsService;

	@Autowired
	private TssRendererService rendererService;

	@Autowired
	private TssBusinessService businessService;

	@Autowired
	private TssCommonService commonService;

	private static final int EXCEL_ROW_COUNT = 500;

	/**
	 * 상품목록 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@GetMapping("/list/form")
	public ModelAndView listForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		String selfYn = "Y";
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {	//입점업체담당자
			supplyCompCd = TssSession.getInfo().getSupplyCompCd();
			selfYn = "N";
		} else if ("G001_E000".equals(TssSession.getInfo().getRoleCd())) {	// 촬영업체
			supplyCompCd = TssSession.getInfo().getSupplyCompCd();
			selfYn = "Y";
		}
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, selfYn));
		// 상품상태
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));

		// 상품상태
		String[] statChangeExceptCds = {"G008_00", "G008_90"};
		mav.addObject("goodsStatChangeList", rendererService.getCommonCodeList("G008", "Y", statChangeExceptCds));
		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		// 성별
		mav.addObject("sexGbList", rendererService.getAvailCommonCodeList("G007"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 연령대
		mav.addObject("ageGrpCdList", rendererService.getAvailCommonCodeList("G023"));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());
		// 상품유형
		mav.addObject("goodsTypeList", rendererService.getAvailCommonCodeList("G056"));
		// MD
		mav.addObject("brandMdList", rendererService.getBrandMdList());

		mav.setViewName("goods/GoodsListForm");

		return mav;
	}

	/**
	 * 상품목록 조회
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 20
	 */
	@PostMapping("/list")
	@ResponseBody
	public GagaMap getGoodsList(@RequestBody GoodsSearch goodsSearch) {

		GagaMap result = new GagaMap();

		// 입점업체담당자는 업체코드 설정
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			goodsSearch.setSupplyCompCd(TssSession.getInfo().getSupplyCompCd());
//			goodsSearch.setMdNo(TssSession.getInfo().getUserNo().toString());
		}

		// multi row 검색관련 처리
		if (!StringUtils.isBlank(goodsSearch.getCondition())) {
			goodsSearch.setConditionList(goodsSearch.getCondition().replaceAll("\r", "").trim().split("\n"));

			if ("searchExtendGoodsCd".equals(goodsSearch.getSearch())) {
				goodsSearch.setSearchGb("EXTEND");
			} else if ("searchMasterGoodsCd".equals(goodsSearch.getSearch())) {
				goodsSearch.setSearchGb("MASTER");
			}
		}

		goodsSearch.setRegNo(TssSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		goodsSearch.setPageable(new TscPageRequest(goodsSearch.getPageNo() - 1, goodsSearch.getPageSize()));
		goodsSearch.getPageable().setTotalCount(goodsService.getGoodsListCount(goodsSearch));

		result.set("pageing", goodsSearch);
		result.set("goodsList", goodsService.getGoodsList(goodsSearch));

		return result;
	}

	/**
	 * 상품목록 - 기본정보 엑셀다운로드
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 10. 21
	 */
	@GetMapping("/info/excel/list")
	public ResponseEntity<InputStreamResource> downloadGoodsInfoExcelList(HttpServletRequest request, GoodsSearch goodsSearch) throws Exception {
		String excelfileName = "상품_기본정보_" + GagaDateUtil.getTodayDateTime() + ".xlsx";
		String excelFilenameWithPath = GagaFileUtil.getConcatenationPath(env.getProperty("download.path"), "excel", excelfileName);

		// 입점업체담당자는 업체코드 설정
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			goodsSearch.setSupplyCompCd(TssSession.getInfo().getSupplyCompCd());
//			goodsSearch.setMdNo(TssSession.getInfo().getUserNo().toString());
		}
		goodsSearch.setRegNo(TssSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용

		// multi row 검색관련 처리
		if (!StringUtils.isBlank(goodsSearch.getCondition())) {
			goodsSearch.setConditionList(goodsSearch.getCondition().replaceAll("\r", "").trim().split("\n"));

			if ("searchExtendGoodsCd".equals(goodsSearch.getSearch())) {
				goodsSearch.setSearchGb("EXTEND");
			} else if ("searchMasterGoodsCd".equals(goodsSearch.getSearch())) {
				goodsSearch.setSearchGb("MASTER");
			}
		}

		goodsSearch.setRegNo(TssSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		goodsSearch.setPageable(new TscPageRequest(goodsSearch.getPageNo() - 1, goodsSearch.getPageSize()));
		goodsSearch.getPageable().setTotalCount(goodsService.getGoodsListCount(goodsSearch));

		// 대용량엑셀파일다운로드는 이런 식으로 ...
		goodsService.getGoodsInfoExcelList(goodsSearch, excelFilenameWithPath);

		return GagaFileUtil.writeFile(request, excelFilenameWithPath);
	}

	/**
	 * 상품 수정 항목 일괄변경
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 01. 17
	 */
	@PostMapping("/state/update")
	@ResponseBody
	public GagaMap updateGoodsState(@RequestBody Goods goods) {

		GagaMap result = new GagaMap();
		result.set("status", GagaResponseStatus.SUCCESS.getCode()); // 200
		result.set("procJob", goods.getProcJob());
		// result.set("message", message.getMessage("SUCC_0001"));

		String returnGoods = "";
		String resultFlag = "SUCC";

		// 입점 담당자만 일괄 변경 가능
		if (!"G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			throw new IllegalStateException("권한이 없습니다.");
		}

		// 상품 상태 변경일 경우 체크
		if ("goodsStat".equals(goods.getProcJob()) && ("G008_40".equals(goods.getGoodsStat()))) {

			// 이미지
			Collection<Goods> goodsList = goodsService.getGoodsImgsYn(goods);

			for (Goods tmpGoods : goodsList) {
				if ("N".equals(tmpGoods.getGoodsImageYn())) {
					returnGoods += tmpGoods.getGoodsCd() + ",";
				} else {

					// 택가/판매가 입력 여부 확인
					Goods dataGoods = goodsService.getGoodsInfo(tmpGoods);
					if (dataGoods == null) {
						returnGoods += tmpGoods.getGoodsCd() + ",";
						continue;
					}
					if (dataGoods.getListPrice() <= 0 || dataGoods.getCurrPrice() <= 0) {
						returnGoods += tmpGoods.getGoodsCd() + ",";
						continue;
					}
					// 사이즈 등록 여부 확인
					if ("G056_N".equals(dataGoods.getGoodsType())) {
						Option stock = new Option();
						stock.setGoodsCd(tmpGoods.getGoodsCd());
						int stockCnt = goodsService.getGoodsOptionCount(stock);
						if (stockCnt <= 0) {
							returnGoods += tmpGoods.getGoodsCd() + ",";
							continue;
						}
					}

					//고시정보
					GoodsNotiInfo goodsNotiInfo = new GoodsNotiInfo();
					goodsNotiInfo.setGoodsCd(tmpGoods.getGoodsCd());
					goodsNotiInfo.setNiClsfCd(tmpGoods.getNiClsfCd());
					Collection<GoodsNotiInfo> goodsNotiInfoList = goodsService.getGoodsNotiInfoList(goodsNotiInfo);
					if (goodsNotiInfoList == null || goodsNotiInfoList.isEmpty()) {
						returnGoods += tmpGoods.getGoodsCd() + ",";
					} else {
						for (GoodsNotiInfo tmpGoodsNotiInfo : goodsNotiInfoList) {
							if (StringUtils.isBlank(tmpGoodsNotiInfo.getNiContent())) {
								returnGoods += tmpGoods.getGoodsCd() + ",";
								break;
							}
						}
					}
				}
			}

			if (returnGoods.length() > 0) {
				returnGoods = returnGoods.substring(0, returnGoods.lastIndexOf(","));
				//returnGoods = returnGoods.replaceAll(",", ",<br/>");
				resultFlag = "FAIL";
				result.set("resultFlag", resultFlag);
				result.set("returnGoods", returnGoods);
				return result;
			}
		}

		goodsService.updateGoodsState(goods);

		result.set("resultFlag", resultFlag);
		result.set("returnGoods", returnGoods);
		return result;
	}

	/**
	 * 엑셀조회용 상품 저장
	 *
	 * @param goods
	 * @return
	 * @throws Exception
	 * @author eskim
	 * @since 2020. 10. 20
	 */
	@PostMapping("/search/excelupload/save")
	@ResponseBody
	public GagaResponse saveExceluploadGoods(@RequestBody Goods goods) throws Exception {

		int cnt = 0;
		ObjectMapper mapper = new ObjectMapper();

		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");

		// DB 처리 시 사용되는 파라미터명(셀명) 설정
		String[] cellName = {"goodsCd"};

		Collection<GagaMap> ecxelGoodsList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, goods.getExcelFileNm()), 0, cellName, 0);

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

		Collection<Goods> goodsList = new ArrayList<>();
		for (GagaMap map : ecxelGoodsList) {
			Goods tmpGoods = mapper.convertValue(map, Goods.class);
			tmpGoods.setRegNo(TssSession.getInfo().getUserNo());
			tmpGoods.setProcJob(goods.getProcJob());
			goodsList.add(tmpGoods);
			cnt++;
		}

		goodsService.saveExceluploadGoods(goodsList, goods.getExcelFileNm());

		// 파일 삭제
		GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(targetPath, goods.getExcelFileNm()));

		return super.ok("");
	}

	/**
	 * 엑셀 업로드 상품 조회
	 *
	 * @param
	 * @return GagaMap
	 * @author eskim
	 * @since 2020. 11. 02
	 */
	@PostMapping("/excel/upload/goods/list")
	@ResponseBody
	public GagaMap getExcelUploadGoodsList() {
		GagaMap result = new GagaMap();
		GoodsSearch goodsSearch = new GoodsSearch();
		goodsSearch.setSearchGb("EXCEL");
		// 입점업체담당자는 업체코드 설정
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			goodsSearch.setSupplyCompCd(TssSession.getInfo().getSupplyCompCd());
//			goodsSearch.setMdNo(TssSession.getInfo().getUserNo().toString());
		}
		goodsSearch.setRegNo(TssSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		result.set("goodsExcelList", goodsService.getGoodsList(goodsSearch));
		return result;
	}

	/**
	 * 상품 상세 화면
	 *
	 * @param GoodsCd - 상품코드
	 * @return
	 * @author eskim
	 * @since 2020. 10. 23
	 */
	@GetMapping("/detail/form")
	@ResponseBody
	public ModelAndView detailForm(Goods goods) {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd));
//		String selfYn = "Y";
//		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
//			supplyCompCd = TssSession.getInfo().getSupplyCompCd();
//			selfYn = "N";
//		}
//		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, selfYn));

		String[] goodsStatExceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", goodsStatExceptCds));

		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		// 성별
		mav.addObject("sexGbList", rendererService.getAvailCommonCodeList("G007"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());
		// 정보고시 분류
		mav.addObject("niClsfCdList", rendererService.getAvailCommonCodeList("G004"));
		// 사용자 브랜드 조회
		mav.addObject("authBrandList", rendererService.getSupplyCompanyBrandList(TssSession.getInfo().getSupplyCompCd()));
		// 상품타입
		mav.addObject("goodsTypeList", rendererService.getAvailCommonCodeList("G056"));
		// 상품구분
		mav.addObject("goodsGbList", rendererService.getAvailCommonCodeList("G073"));
		// 유통구분
		//String[] distributionGbExceptCds = {"G065_20"};
		//mav.addObject("distributionGbList", rendererService.getCommonCodeList("G065", "Y", distributionGbExceptCds));
		mav.addObject("distributionGbList", rendererService.getCommonCodeList("G065", "Y"));
		// 상품연령대
		mav.addObject("ageGrpCdList", rendererService.getAvailCommonCodeList("G023"));
		// kc인증타입
		mav.addObject("certTypeList", rendererService.getAvailCommonCodeList("G081"));
		// kc인증대상구분
		mav.addObject("certTargetGbList", rendererService.getAvailCommonCodeList("G083"));
		// kc인증형태구분
		mav.addObject("certFormGbList", rendererService.getAvailCommonCodeList("G084"));
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 회원등급
		//mav.addObject("custGradeList", rendererService.getAvailCommonCodeList("G110"));
		// 출고처
		mav.addObject("deliveryLocList", rendererService.getSupplyDeliveryLocList(supplyCompCd));

		mav.addObject("params", goods);

		mav.setViewName("goods/GoodsDetailForm");

		return mav;
	}

	/**
	 * 상품 상세 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2019. 12. 11
	 */
	@PostMapping("/detail")
	@ResponseBody
	public Goods getGoodsDetail(Goods goods) {
		return goodsService.getGoods(goods);
	}

	/**
	 * 상품 이력 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2019. 12. 12
	 */
	@GetMapping("/detail/hst/list")
	@ResponseBody
	public Collection<GoodsHst> getGoodsDetailHstList(Goods goods) {
		return goodsService.getGoodsHstList(goods);
	}

	/**
	 * 컬러 옵셥 재고
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 26
	 */
	@PostMapping("/detail/sizeStock/form")
	public ModelAndView getGoodsDetailSizeStockForm(Goods goods) {

		ModelAndView mav = new ModelAndView();
		mav.addObject("goods", goodsService.getGoodsInfo(goods));
		mav.addObject("goodsSizeList", goodsService.getGoodsSizeList(goods));
		mav.addObject("goodsColorList", goodsService.getGoodsColorList(goods));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));

		mav.setViewName("goods/GoodsDetailSizeStockForm");

		return mav;
	}

	/**
	 * 상품 정보고시 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2019. 12. 12
	 */
	@PostMapping("/detail/notiInfo/list")
	@ResponseBody
	public Collection<GoodsNotiInfo> getGoodsDetailNotiInfoList(Goods goods) {

		GoodsNotiInfo goodsInfo = new GoodsNotiInfo();
		goodsInfo.setGoodsCd(goods.getGoodsCd());
		goodsInfo.setNiClsfCd(goods.getNiClsfCd());

		return goodsService.getGoodsNotiInfoList(goodsInfo);
	}

	/**
	 * 상품 구매등급 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 12. 11
	 */
	@PostMapping("/detail/order/grade/list")
	@ResponseBody
	public Collection<Goods> getGoodsDetailOrderGradeList(Goods goods) {
		return goodsService.getGoodsDetailOrderGradeList(goods);
	}

	/**
	 * 상품의 정보고시 항목 목록
	 *
	 * @param notiInfo
	 * @return
	 * @author eskim
	 * @since 2010. 11. 18
	 */
	@PostMapping("/noti/goodsInfo/list")
	@ResponseBody
	public Collection<NotiInfo> getNotiGoodsInfoList(NotiInfo notiInfo) {
		return goodsService.getNotiGoodsInfoList(notiInfo);
	}

	/**
	 * 상품 상세 저장
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 27
	 */
	@PostMapping("/detail/save")
	@ResponseBody
	public GagaResponse saveGoodsDetail(@RequestBody Goods goods) {

		// 상품상태에 따른 이미지 정보 확인 - 상품상태가 승인대기일 경우
		if ("G008_40".equals(goods.getGoodsStat())) {
			Collection<Goods> goodsList = goodsService.getGoodsImgsYn(goods);
			String goodsImageYn = "N";
			for (Goods tmpGoods : goodsList) {
				goodsImageYn = tmpGoods.getGoodsImageYn();
			}
			if ("N".equals(goodsImageYn)) {
				throw new IllegalStateException("필수 이미지가 등록되지 않은 상품은 '승인대기' 상태로 변경할 수 없습니다.");
			}
		}

		Collection<GoodsNotiInfo> notiList = null;
		Collection<GoodsCompose> goodComposeList = null;
		ObjectMapper mapper = new ObjectMapper();
		try {
			if (goods.getNotiList() != null) {
				notiList = mapper.readValue(goods.getNotiList(), new TypeReference<Collection<GoodsNotiInfo>>() {
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			if (goods.getGoodsComposeList() != null) {
				goodComposeList = mapper.readValue(goods.getGoodsComposeList(), new TypeReference<Collection<GoodsCompose>>() {
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		goods.setNotiListNew(notiList);
		goods.setGoodsComposeListNew(goodComposeList);

		goodsService.saveGoodsDetail(goods);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 상품 이미지 보기 화면
	 *
	 * @param GoodsCd - 상품코드
	 * @return
	 * @author eskim
	 * @since 2020. 12. 23
	 */
	@GetMapping("/image/form")
	@ResponseBody
	public ModelAndView imageForm(GoodsImg goodsImg) {
		ModelAndView mav = new ModelAndView();

		Collection<GoodsImg> goodsImgList = goodsService.getGoodsImgList(goodsImg);

		if (goodsImgList != null && !goodsImgList.isEmpty()) {

			mav.addObject("goodsImgList", goodsImgList);

			for (GoodsImg goodsImgInfo : goodsImgList) {
				if (goodsImgInfo.getDefaultImgYn().equals("Y")) {
					mav.addObject("defaultImgOrd", goodsImgInfo.getDispOrd());
				}
				if (goodsImgInfo.getMouseoverImgYn().equals("Y")) {
					mav.addObject("mouseoverImgOrd", goodsImgInfo.getDispOrd());
				}
				if (goodsImgInfo.getExtmallImgYn().equals("Y")) {
					mav.addObject("extmallImgOrd", goodsImgInfo.getDispOrd());
				}
			}
		} else { // 대표이미지와 마우스오버이미지가 없으면
			mav.addObject("goodsImgList", new ArrayList<GoodsImg>());
			mav.addObject("defaultImgOrd", "1");
			mav.addObject("mouseoverImgOrd", "1");
			mav.addObject("extmallImgOrd", "0");
		}

		GoodsImg goodsModelInfo = goodsService.getGoodsModelInfo(goodsImg);

		if (goodsModelInfo != null) {
			mav.addObject("modelInfo", goodsModelInfo.getModelInfo());
		} else {
			mav.addObject("modelInfo", "");
		}
		mav.addObject("goodsImg", goodsImg);
		mav.setViewName("goods/GoodsImageForm");
		return mav;
	}

	/**
	 * 상품 썸네일 이미지 저장 처리
	 * @param goodsImgList - 상품이미지 목록
	 * @return
	 * @throws Exception
	 * @author eskim
	 * @since 2020. 112. 23
	 */
	@RequestMapping(value = "/thumbnail/image/save", method = RequestMethod.POST)
	@ResponseBody
	public GagaResponse saveGoodsThumbnailImageList(@RequestBody Collection<GoodsImg> goodsImgList) throws Exception {
		if (goodsImgList == null || goodsImgList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		String dextUploadPath = env.getProperty("upload.dext.target.path");
		String goodsTargetPath = env.getProperty("upload.goods.target.path");

		int index = 1;
		String strBrandNo = "";
		GoodsImg goodsModelInfo = new GoodsImg();

		// 오류 파일 목록
		Collection<File> errorFileList = new ArrayList<File>();
		Collection<File> errorFileDextList = new ArrayList<File>();

		// 1.업로드된 파일 rename 및 순서 재정렬
		for (GoodsImg goodsImg : goodsImgList) {

			goodsModelInfo.setGoodsCd(goodsImg.getGoodsCd());
			goodsModelInfo.setModelInfo(goodsImg.getModelInfo());

			// dx5에서 삭제한 파일은 skip
			if (goodsImg.getMode().equals("D")) {
				continue;
			}

			// 상품의 브랜드 번호 추출
			if (strBrandNo.isEmpty()) {
				Goods goods = new Goods();
				goods.setGoodsCd(goodsImg.getGoodsCd());
				Goods goodsInfo = goodsService.getGoodsInfo(goods);
				if (goodsInfo == null || goodsInfo.getGoodsCd().isEmpty()) {
					deleteErrorFileList(errorFileList);
					deleteErrorFileList(errorFileDextList);
					throw new IllegalStateException(message.getMessage("FAIL_1001"));
				}

				strBrandNo = String.valueOf(goodsInfo.getBrandNo());
			}
			String brandDir = GagaStringUtil.getLPadding(strBrandNo, 10, "0");

			if (goodsImg.getMode().equals("C")) { // 업로드 된 파일 rename 처리
				String newFilename = goodsImg.getSysImgNm();

				//브랜드 폴더 확인
				String goodsUploadPath = GagaFileUtil.getConcatenationPath(goodsTargetPath, brandDir); // 브랜드 폴더
				File brandPath = new File(goodsUploadPath);
				if (!brandPath.exists()) {
					brandPath.mkdir();
				}

				goodsUploadPath = GagaFileUtil.getConcatenationPath(goodsUploadPath, GagaDateUtil.getToday());		//브랜드+/+YYYYMMDD(UPLOAD 일 )
				String brandYmdDir = GagaFileUtil.getConcatenationPath(brandDir, GagaDateUtil.getToday());	//디비 저장용

				File uniqueFile = GagaFileUtil.getUniqueFile(new File(GagaFileUtil.getConcatenationPath(goodsUploadPath, newFilename)));
				File newFile = new File(GagaFileUtil.getConcatenationPath(goodsUploadPath, uniqueFile.getName()));
				//log.info("newFile.getPath(): {}", newFile.getPath());

				// resizing 처리 시 오류가 발생할 경우 삭제하기 위해 설정
				errorFileList.add(newFile);

				File oldFile = new File(GagaFileUtil.getConcatenationPath(dextUploadPath, goodsImg.getSysImgNm()));
				errorFileDextList.add(oldFile);
				//log.info("oldFile.getPath(): {}", oldFile.getPath());

				File path = new File(goodsUploadPath);
				if (!path.exists()) {
					//log.info("mkdir ={}", goodsUploadPath);
					path.mkdir();
				}

				Image srcImg = getImageObject(oldFile);
				int width = srcImg.getWidth(null);
				int height = srcImg.getHeight(null);

				if (newFile.getName().contains("_X1")) {
//					if (width != height) {
					if (width != 1000 || height != 1000) {
						deleteErrorFileList(errorFileList);
						deleteErrorFileList(errorFileDextList);
						throw new IllegalStateException("외부몰용 상품이미지가 정사각형(1000x1000)이 아닙니다.");
					}
					// 외부몰연동용 이미지로 설정
					goodsImg.setExtmallImgYn("Y");
				}

				boolean copyFlag = GagaFileUtil.copyFile(oldFile, newFile);
				if (copyFlag) {
					//기존이미지 삭제
					GagaFileUtil.deleteFile(oldFile.getPath());
				}

				goodsImg.setDispOrd(index++);
				goodsImg.setOrgImgNm(GagaFileUtil.getConcatenationPath(brandYmdDir, newFile.getName()));
				goodsImg.setSysImgNm(GagaFileUtil.getConcatenationPath(brandYmdDir, newFile.getName()));

			} else {
				goodsImg.setOrgImgNm(GagaFileUtil.getConcatenationPath(goodsImg.getSysImgUrl(), goodsImg.getSysImgNm()));
				goodsImg.setSysImgNm(GagaFileUtil.getConcatenationPath(goodsImg.getSysImgUrl(), goodsImg.getSysImgNm()));
				goodsImg.setDispOrd(index++);
			}
		}

		// 2.dx5에서 삭제한 파일 실제 삭제 처리
		for (GoodsImg goodsImg : goodsImgList) {
			if (goodsImg.getMode().equals("D")) {
				//log.info("Original file to delete: {}", GagaFileUtil.getConcatenationPath(goodsTargetPath, goodsImg.getSysImgUrl(), goodsImg.getSysImgNm()));

				// 상품이미지 삭제
				GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(goodsTargetPath, goodsImg.getSysImgUrl(), goodsImg.getSysImgNm()));

			}
		}

		// 상품이미지 저장 처리
		goodsService.saveGoodsImageList(goodsImgList);

		// 모델정보 처리
		goodsModelInfo.setRegNo(TssSession.getInfo().getUserNo());
		goodsModelInfo.setUpdNo(TssSession.getInfo().getUserNo());
		goodsService.saveGoodsModelInfo(goodsModelInfo);

		return super.ok(message.getMessage("SUCC_0007"));
	}

	/**
	 * 상품 이미지 대량관리 화면
	 *
	 * @param GoodsCd - 상품코드
	 * @return
	 * @author eskim
	 * @since 2020. 11. 09
	 */
	@GetMapping("/image/mass/form")
	@ResponseBody
	public ModelAndView imageMassForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("goods/GoodsImageMassForm");
		return mav;
	}

	/**
	 * 상품 대량 썸네일 이미지 저장 처리
	 * @param goodsImgList - 상품이미지 목록
	 * @return
	 * @throws Exception
	 * @author eskim
	 * @since 2021. 5. 16
	 */
	@RequestMapping(value = "/thumbnail/image/mass/save", method = RequestMethod.POST)
	@ResponseBody
	public GagaResponse saveGoodsThumbnailImageMassList(@RequestBody Collection<GoodsImg> goodsImgList) throws Exception {
		if (goodsImgList == null || goodsImgList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		String dextUploadPath = env.getProperty("upload.dext.target.path");
		String goodsTargetPath = env.getProperty("upload.goods.target.path");

		//순서 재정렬된 파일 목록
		Collection<GoodsImg> resultGoodsImgList = new ArrayList<GoodsImg>();
		boolean procFlag = true;
		int index = 0;

		// 오류 파일 목록
		Collection<File> errorFileList = new ArrayList<File>();
		Collection<File> errorFileDextList = new ArrayList<File>();

//		log.debug("SORT 전 : goodsImgList {}", goodsImgList);

		String[] arrGoodsImg = new String[goodsImgList.size()];
		String[] arrGoodsCd = new String[goodsImgList.size()];

		index = 0;
		for (GoodsImg goodsImg : goodsImgList) {

			File massFile = new File(GagaFileUtil.getConcatenationPath(dextUploadPath, goodsImg.getSysImgNm()));
			errorFileDextList.add(massFile);

			int lastIdx = goodsImg.getSysImgNm().lastIndexOf('.');
			String orgFile = goodsImg.getSysImgNm().substring(0, lastIdx);
			String[] sysFileNmArr = orgFile.split("_");

			// 촬영업체 - 자사상품
			if ("G001_E000".equals(TssSession.getInfo().getRoleCd())) {
				if (sysFileNmArr.length != 3) {
					procFlag = false;
					break;
				}
				// 입점억체 - 입점상품	
			} else if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
				if (sysFileNmArr.length != 2) {
					procFlag = false;
					break;
				}
			} else {
				deleteErrorFileList(errorFileDextList);
				throw new IllegalStateException("권한이 없습니다.");
			}

			//for (int i = 0; i < sysFileNmArr.length; i++) log.debug("SORT 후 : sysFileNmArr[i] {}", sysFileNmArr[i]);
			arrGoodsImg[index] = goodsImg.getSysImgNm();
			arrGoodsCd[index] = sysFileNmArr[0];
			index++;
		}

		if (!procFlag) {
			String msg = "이미지파일 형식을 확인해주세요.(상품코드_컬러코드_순번.jpg)";
			if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
				msg = "이미지파일 형식을 확인해주세요.(상품코드_순번.jpg)";
			}
			deleteErrorFileList(errorFileDextList);
			throw new IllegalStateException(msg);
		}

		Arrays.sort(arrGoodsImg);

		//for (int i = 0; i < arrGoodsImg.length; i++) log.debug("SORT 후 : arrGoodsImg[i] {}", arrGoodsImg[i]);

		index = 0;
		for (int i = 0; i < arrGoodsImg.length; i++) {
			for (GoodsImg goodsImg : goodsImgList) {
				if (arrGoodsImg[i].equals(goodsImg.getSysImgNm())) {
					resultGoodsImgList.add(goodsImg);
					index++;
				}
			}
		}

//		log.debug("SORT 후 : resultGoodsImgList {}", resultGoodsImgList);

		index = 1;
		errorFileList.clear();

		String comGoodsCd = "";
		String comGoodsColor = "";
		String strBrandNo = "";
		String brandDir = "";

		// 1.업로드된 파일
		for (GoodsImg goodsImg : resultGoodsImgList) {

			int lastIdx = goodsImg.getSysImgNm().lastIndexOf('.');
			String orgFile = goodsImg.getSysImgNm().substring(0, lastIdx);
			String[] sysFileNmArr = orgFile.split("_");
			String selfGoodsYn = "Y";
			// 촬영업체
			if ("G001_E000".equals(TssSession.getInfo().getRoleCd())) {
				goodsImg.setGoodsCd(sysFileNmArr[0]);
				goodsImg.setColorCd(sysFileNmArr[1]);
				goodsImg.setDispOrd(index);
			} else {
				goodsImg.setGoodsCd(sysFileNmArr[0]);
				goodsImg.setColorCd("XX");
				goodsImg.setDispOrd(index);
			}

			if (!comGoodsCd.equals(goodsImg.getGoodsCd())) {
				comGoodsCd = goodsImg.getGoodsCd();
				comGoodsColor = goodsImg.getColorCd();
				index = 1;

				// 상품코드 확인
				Goods goods = new Goods();
				goods.setGoodsCd(comGoodsCd);
				Goods goodsInfo = goodsService.getGoodsInfo(goods);
				if (goodsInfo == null || goodsInfo.getGoodsCd().isEmpty()) {
					deleteErrorFileList(errorFileList);
					deleteErrorFileList(errorFileDextList);
					throw new IllegalStateException(goodsImg.getSysImgNm() + " 의" + comGoodsCd + " 상품코드가  존재하지 않습니다.");
				}

				//촬영업체
				if ("G001_E000".equals(TssSession.getInfo().getRoleCd())) {
					if (!"Y".equals(goodsInfo.getSelfGoodsYn())) {
						deleteErrorFileList(errorFileList);
						deleteErrorFileList(errorFileDextList);
						throw new IllegalStateException(goodsImg.getSysImgNm() + " 의" + comGoodsCd + " 상품코드를 확인해주세요.(자사상품만 등록 가능)");
					}
				} else {
					if (!"N".equals(goodsInfo.getSelfGoodsYn())) {
						deleteErrorFileList(errorFileList);
						deleteErrorFileList(errorFileDextList);
						throw new IllegalStateException(goodsImg.getSysImgNm() + " 의" + comGoodsCd + " 상품코드를 확인해주세요.(입점상품만 등록 가능)");
					}
				}

				strBrandNo = String.valueOf(goodsInfo.getBrandNo());
				brandDir = GagaStringUtil.getLPadding(strBrandNo, 10, "0");
				selfGoodsYn = goodsInfo.getSelfGoodsYn();
				// 일반상품이고 자사상품인 경우 색상 확인
				if (GoodsType.NORMAL.equals(goodsInfo.getGoodsType()) && "Y".equals(selfGoodsYn)) {
					Option option = new Option();
					option.setGoodsCd(comGoodsCd);
					option.setOptCd1(comGoodsColor);
					int opt1CdCnt = goodsService.getGoodsOption1Count(option);
					if (opt1CdCnt <= 0) {
						deleteErrorFileList(errorFileList);
						deleteErrorFileList(errorFileDextList);
						throw new IllegalStateException(goodsImg.getSysImgNm() + "의" + comGoodsCd + " 상품코드의  " + comGoodsColor + " 색상이  존재하지 않습니다.");
					}
				}
			}

			if (comGoodsCd.equals(goodsImg.getGoodsCd()) && !comGoodsColor.equals(goodsImg.getColorCd()) && "Y".equals(selfGoodsYn)) {

				comGoodsColor = goodsImg.getColorCd();
				index = 1;
				Option option = new Option();
				option.setGoodsCd(comGoodsCd);
				option.setOptCd1(comGoodsColor);
				int opt1CdCnt = goodsService.getGoodsOption1Count(option);
				if (opt1CdCnt <= 0) {
					deleteErrorFileList(errorFileList);
					deleteErrorFileList(errorFileDextList);
					throw new IllegalStateException(goodsImg.getSysImgNm() + "의" + comGoodsCd + " 상품코드의  " + comGoodsColor + " 색상이  존재하지 않습니다.");
				}
			}

			String newFilename = goodsImg.getSysImgNm();

			//브랜드 폴더 확인
			String goodsUploadPath = GagaFileUtil.getConcatenationPath(goodsTargetPath, brandDir); // 브랜드 폴더
			File brandPath = new File(goodsUploadPath);
			if (!brandPath.exists()) {
				brandPath.mkdir();
			}

			goodsUploadPath = GagaFileUtil.getConcatenationPath(goodsUploadPath, GagaDateUtil.getToday());		//브랜드+/+YYYYMMDD(UPLOAD 일 )
			String brandYmdDir = GagaFileUtil.getConcatenationPath(brandDir, GagaDateUtil.getToday());	//디비 저장용

			File uniqueFile = GagaFileUtil.getUniqueFile(new File(GagaFileUtil.getConcatenationPath(goodsUploadPath, newFilename)));
			File newFile = new File(GagaFileUtil.getConcatenationPath(goodsUploadPath, uniqueFile.getName()));
			//log.debug("newFile.getPath(): {}", newFile.getPath());

			// resizing 처리 시 오류가 발생할 경우 삭제하기 위해 설정
			errorFileList.add(newFile);

			File oldFile = new File(GagaFileUtil.getConcatenationPath(dextUploadPath, goodsImg.getSysImgNm()));
			//log.debug("oldFile.getPath(): {}", oldFile.getPath());

			File path = new File(goodsUploadPath);
			if (!path.exists()) {
				//log.info("mkdir ={}", goodsUploadPath);
				path.mkdir();
			}

			boolean copyFlag = GagaFileUtil.copyFile(oldFile, newFile);
			if (copyFlag) {
				//기존이미지 삭제
				GagaFileUtil.deleteFile(oldFile.getPath());
			}

			goodsImg.setDispOrd(index);
			goodsImg.setOrgImgNm(GagaFileUtil.getConcatenationPath(brandYmdDir, newFile.getName()));
			goodsImg.setSysImgNm(GagaFileUtil.getConcatenationPath(brandYmdDir, newFile.getName()));
			goodsImg.setDefaultImgYn("N");
			goodsImg.setMouseoverImgYn("N");
			goodsImg.setExtmallImgYn("N");
			goodsImg.setRegNo(TssSession.getInfo().getUserNo());

			// 첫번째 이미지이면 디폴트 이미지 설정
			if (index == 1) {
				goodsImg.setDefaultImgYn("Y");
			}

			// 두번째 이미지이면 마우스오버 이미지 설정
			if (index == 2) {
				goodsImg.setMouseoverImgYn("Y");
			}

			Image srcImg = getImageObject(newFile);
			int width = srcImg.getWidth(null);
			int height = srcImg.getHeight(null);

//			
			if (newFile.getName().contains("_X1")) {
//				if (width != height) {
				if (width == 1000 && height == 1000) {
					deleteErrorFileList(errorFileList);
					deleteErrorFileList(errorFileDextList);
					throw new IllegalStateException(comGoodsCd + " 상품코드의 외부몰용 상품이미지는 정사각형(1000x1000)이 아닙니다.");
				}
				// 외부몰연동용 이미지로 설정
				goodsImg.setExtmallImgYn("Y");
			}
			// 오류가 발생했으므로 
//			deleteErrorFileList(errorFileList);
//			deleteErrorFileList(errorFileDextList);
//			throw new IllegalStateException(goodsImg.getSysImgNm() + " 상품이미지 파일의 크기(" + width + "*" + height + ")가 맞지 않습니다. (올바른 크기: 1079*1499, 750*1041, 1000*1000)");

			index++;
		}

		//log.debug("resultGoodsImgList: {}", resultGoodsImgList);

		// 상품이미지 저장 처리
		goodsService.saveGoodsImageMassList(resultGoodsImgList);

		return super.ok(message.getMessage("SUCC_0007"));
	}

	/*
	 * 이미지 파일 확인
	 */
	public static Image getImageObject(File f) throws IOException {
		Image objImg = null;
		String suffix = f.getName().substring(f.getName().lastIndexOf('.') + 1).toLowerCase();
//		if (suffix.equals("bmp") || suffix.equals("png") || suffix.equals("gif") || suffix.equals("jpg")) {
		if (suffix.equals("png") || suffix.equals("gif") || suffix.equals("jpg")) {
			objImg = ImageIO.read(f);
		} else {
			// ImageIcon을 활용해서 Image 생성
			// 이렇게 하는 이유는 getScaledInstance를 통해 구한 이미지를
			// PixelGrabber.grabPixels로 리사이즈 할 때 빠르게 처리하기 위함이다.
			objImg = new ImageIcon(f.toURI().toURL()).getImage();
		}

		return objImg;
	}

	/**
	 * 파일 삭제
	 *
	 * @param errorFileList
	 * @author eskim
	 * @since 2021. 5. 16
	 */
	private void deleteErrorFileList(Collection<File> errorFileList) {
		// 파일 삭제
		if (errorFileList != null && !errorFileList.isEmpty()) {
			for (File errorFile : errorFileList) {
				try {
					GagaFileUtil.deleteFile(errorFile.getPath());
				} catch (IOException e) {
					// Nothing Do
				}
			}
		}
	}

	/**
	 * 상품 대량 등록 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@GetMapping("/mass/register/form")
	public ModelAndView massRegisterForm() {
		ModelAndView mav = new ModelAndView();

		// 상품상태
		mav.addObject("goodsStatList", rendererService.getAvailCommonCodeList("G008"));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// WMS 연동여부
		mav.addObject("wmsSyncYn", commonService.getWmsSyncYn());
		// 정보고시 목록
		mav.addObject("niClsfCdList", rendererService.getAvailCommonCodeList("G004"));
		// 사용자 업체
		String supplyCompCd = TssSession.getInfo().getSupplyCompCd();
		// 업체별 배송비 목록
		mav.addObject("supplyDeliveryFeePolicyList", rendererService.getSupplyDeliveryFeePolicyList(supplyCompCd));
		// 업체별 출고처 목록
		mav.addObject("supplyDeliveryLocList", rendererService.getSupplyDeliveryLocList(supplyCompCd));

		mav.addObject("supplyCompCd", supplyCompCd);
		mav.setViewName("goods/GoodsMassRegisterForm");

		return mav;
	}

	/**
	 * 상품 대량등록 결과 조회
	 *
	 * @param goodsSearch
	 * @return
	 * @author eskim
	 * @since 2020. 01. 13
	 */
	@PostMapping("/reg/log/list")
	@ResponseBody
	public Collection<GoodsMass> getGoodsRegLogList(@RequestBody GoodsSearch goodsSearch) {
		return goodsService.getGoodsRegLogList(goodsSearch);
	}

	/**
	 * 상품대량등록 엑셀 저장
	 *
	 * @param goodsMass
	 * @return
	 * @author eskim
	 * @since 2021. 01. 12
	 */
	@PostMapping("/mass/excelupload/create")
	@ResponseBody
	public GagaResponse createExceluploadGoods(@RequestBody GoodsMass goodsMass) throws Exception {
		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
		Collection<GagaMap> ecxelGoodsList = new ArrayList<>();
		// 자사상품등록
		if ("createSelfGoods".equals(goodsMass.getProcJob())) {
			if ("N".equals(commonService.getWmsSyncYn())) {
				// 파일 삭제
				GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(targetPath, goodsMass.getExcelFileNm()));
				throw new IllegalStateException("WMS 연동여부가 [N]입니다. 관리자에게 문의하세요.");
			}

			// DB 처리 시 사용되는 파라미터명(셀명) 설정
			String[] goodsNames = {"goodsNum", "brandCd", "goodsNm", "itemkindCd", "styleYear", "seasonCd",
				"sexGb", "formalGb", "ageGrpCd", "originCd", "makeYmd", "goodsTitles",
				"goodsContent", "goodsCharacter",
				"niClsfCd", "niContent1", "niContent2", "niContent3", "niContent4", "niContent5",
				"niContent6", "niContent7", "niContent8", "niContent9", "niContent10", "niContent11", "niContent12",
				"niContent13", "niContent14", "niContent15", "niContent16", "niContent17", "niContent18",
				"niContent19", "niContent20", "niContent21", "niContent22", "niContent23", "niContent24",
				"niContent25", "niContent26", "niContent27", "niContent28"};

			ecxelGoodsList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, goodsMass.getExcelFileNm()), 0, goodsNames, 0);

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

			for (GagaMap gagaMap : ecxelGoodsList) {
				goodsService.createExceluploadSelfGoods(gagaMap, goodsMass.getProcJob());
			}

		} else {
			// 입점상품등록
			// DB 처리 시 사용되는 파라미터명(셀명) 설정 -
			String[] goodsNames = {"supplyGoodsCd", "supplyCompCd", "brandCd", "goodsNm", "goodsTnm", "goodsSnm1", "itemkindCd",
				"sexGb", "listPrice", "currPrice", "goodsGb", "formalGb", "seasonCd", "originCd", "makeYmd", "taxGb", "ageGrpCd", "adultYn",
				"certTargetGb", "certFormGb", "certType", "certNum", "optStr", "goodsContent",
				"niClsfCd", "niContent1", "niContent2", "niContent3", "niContent4", "niContent5",
				"niContent6", "niContent7", "niContent8", "niContent9", "niContent10", "niContent11", "niContent12",
				"niContent13", "niContent14", "niContent15", "niContent16", "niContent17", "niContent18",
				"niContent19", "niContent20", "niContent21", "niContent22", "niContent23", "niContent24",
				"niContent25", "niContent26", "niContent27", "niContent28"};

			ecxelGoodsList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, goodsMass.getExcelFileNm()), 0, goodsNames, 0);

			//건수
			if (ecxelGoodsList != null && ecxelGoodsList.size() > 100) {  //안전인증 로직 추가로 건수 줄임
				throw new IllegalStateException("엑셀 파일의 건수를 100 건 이하로 사용하세요.");
			}

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

			if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
				if (mdBrandList == null || mdBrandList.isEmpty()) {
					throw new IllegalStateException("담당 브랜드가 없습니다. 권한이 없습니다.");
				}
			} else {
				throw new IllegalStateException("권한이 없습니다.");
			}

			for (GagaMap gagaMap : ecxelGoodsList) {
				goodsService.createExceluploadGoods(gagaMap, goodsMass.getProcJob(), goodsMass.getDelvFeeCd(), goodsMass.getDelvLocCd());
			}

		}

		// 파일 삭제
		GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(targetPath, goodsMass.getExcelFileNm()));

		return super.ok("");
	}

	/**
	 * 상품대량수정 엑셀 저장
	 *
	 * @param goodsMass
	 * @return
	 * @throws Exception
	 * @author eskim
	 * @since 2021. 1. 20
	 */
	@PostMapping("/mass/excelupload/update")
	@ResponseBody
	public GagaResponse updateMassExceluploadGoods(@RequestBody GoodsMass goodsMass) throws Exception {

		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
		Collection<GagaMap> ecxelGoodsList = new ArrayList<>();

		// 상품수장
		// DB 처리 시 사용되는 파라미터명(셀명) 설정 -
		String[] goodsNames = {"goodsCd", "goodsNm", "goodsTnm", "goodsSnm1", "itemkindCd", "seasonCd",
			"sexGb", "currPrice", "sellFeeRate", "goodsGb", "formalGb", "minOrdQty", "maxOrdQty", "dayMaxOrdQty",
			"giftPackYn", "newCustOrdYn", "pntPrate", "prePpntUsableYn", "pntMrate", "preMpntUsableYn",
			"returnableYn", "changeableYn", "taxGb", "ageGrpCd", "adultYn", "delvFeeCd", "optStr", "goodsContent",
			"niClsfCd", "niContent1", "niContent2",
			"niContent3", "niContent4", "niContent5", "niContent6", "niContent7", "niContent8", "niContent9",
			"niContent10", "niContent11", "niContent12", "niContent13", "niContent14", "niContent15", "niContent16",
			"niContent17", "niContent18", "niContent19", "niContent20", "niContent21", "niContent22", "niContent23",
			"niContent24", "niContent25", "niContent26", "niContent27", "niContent28"};

		ecxelGoodsList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, goodsMass.getExcelFileNm()), 0, goodsNames, 0);

		// 입점담당자
		if (!"G001_B000".equals(TssSession.getInfo().getRoleCd()) && !"G001_E000".equals(TssSession.getInfo().getRoleCd())) {
			throw new IllegalStateException("권한이 없습니다.");
		}

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

		for (GagaMap gagaMap : ecxelGoodsList) {
			goodsService.updateMassExceluploadGoods(gagaMap, goodsMass.getProcJob());
		}

		// 파일 삭제
		GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(targetPath, goodsMass.getExcelFileNm()));

		return super.ok("");
	}

	/**
	 * 입점 가격 관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@GetMapping("/supply/price/form")
	public ModelAndView priceForm() {
		ModelAndView mav = new ModelAndView();
		// 공급업체
		String supplyCompCd = "";
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			supplyCompCd = TssSession.getInfo().getSupplyCompCd();
		}
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, "N"));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 상품상태
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		mav.setViewName("goods/GoodsSupplyPriceForm");

		return mav;
	}

	/**
	 * 상품 가격승인관리 목록 조회
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 26
	 */
	@PostMapping("/supply/price/list")
	@ResponseBody
	public GagaMap getGoodsSupplyPriceList(@RequestBody GoodsSupplyPrice goodsSupplyPrice) {

		GagaMap result = new GagaMap();

		goodsSupplyPrice.setRegNo(TssSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		goodsSupplyPrice.setPageable(new TscPageRequest(goodsSupplyPrice.getPageNo() - 1, goodsSupplyPrice.getPageSize()));
		goodsSupplyPrice.getPageable().setTotalCount(goodsService.getGoodsSupplyPriceCount(goodsSupplyPrice));

		result.set("pageing", goodsSupplyPrice);
		result.set("goodsList", goodsService.getGoodsSupplyPriceList(goodsSupplyPrice));

		return result;
	}

	/**
	 * 상품 상세공지 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@GetMapping("/notice/form")
	public ModelAndView detailNoticeForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			supplyCompCd = TssSession.getInfo().getSupplyCompCd();
		}
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, "N"));

		mav.setViewName("goods/GoodsNoticeForm");

		return mav;
	}

	/**
	 * 상품 상세공지 목록
	 * @param notice - 공지사항 정보
	 * @return
	 * @author eskim
	 * @since 2020. 11. 27
	 */
	@PostMapping("/notice/list")
	@ResponseBody
	public Collection<Notice> getNoticeList(@RequestBody GoodsSearch goodsSearch) {

		// 입점업체담당자는 업체코드 설정
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			goodsSearch.setSupplyCompCd(TssSession.getInfo().getSupplyCompCd());
//			goodsSearch.setMdNo(TssSession.getInfo().getUserNo().toString());
		}

		// multi row 검색관련 처리
		if (!StringUtils.isBlank(goodsSearch.getCondition())) {
			goodsSearch.setConditionList(goodsSearch.getCondition().replaceAll("\r", "").trim().split("\n"));
		}

		return goodsService.getNoticeList(goodsSearch);
	}

	/**
	 * 상품 상세공지 상품목록
	 * @param notice - 공지사항 정보
	 * @return
	 * @author eskim
	 * @since 2020. 11. 27
	 */
	@GetMapping("/notice/goods/list/{noticeSq}")
	@ResponseBody
	public Collection<NoticeGoods> getNoticeGoodsList(@PathVariable Integer noticeSq) {
		Notice notice = new Notice();
		notice.setNoticeSq(noticeSq);
		return goodsService.getNoticeGoodsList(notice);
	}

	/**
	 * 상품 상세공지 저장/등록
	 *
	 * @param
	 * @return
	 * @author eskim
	 * @since 2020. 11. 27
	 */
	@PostMapping("/notice/save")
	@ResponseBody
	public GagaResponse saveNotice(@RequestBody Notice notice) {
		goodsService.saveNotice(notice);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 상품 상세공지상품 삭제
	 *
	 * @param
	 * @return
	 * @author eskim
	 * @since 2020. 11. 09
	 */
	@PostMapping("/notice/goods/delete")
	@ResponseBody
	public GagaResponse deleteNoticeGoods(@RequestBody NoticeGoods noticeGoods) {
		goodsService.deleteNoticeGoods(noticeGoods);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 상품조회 팝업
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 26
	 */
	@GetMapping("/popup/list/form")
	@ResponseBody
	public ModelAndView relationListForm(GoodsSearch goodsSearch) {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		String selfYn = "Y";
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			supplyCompCd = TssSession.getInfo().getSupplyCompCd();
			selfYn = "N";
		}
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, selfYn));
		//mav.addObject("supplyCompList", rendererService.getSupplyCompanyList());
		// 상품상태
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		// 성별
		mav.addObject("sexGbList", rendererService.getAvailCommonCodeList("G007"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 연령대
		mav.addObject("ageGrpCdList", rendererService.getAvailCommonCodeList("G023"));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());
		// 상품유형
		mav.addObject("goodsTypeList", rendererService.getAvailCommonCodeList("G056"));
		// MD
		mav.addObject("brandMdList", rendererService.getBrandMdList());
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));

		mav.addObject("params", goodsSearch);

		mav.setViewName("goods/GoodsPopupListForm");

		return mav;
	}

	/**
	 * 상품조회 팝업 조회
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 26
	 */
	@PostMapping("/popup/list")
	@ResponseBody
	public GagaMap getPopupGoodsList(@RequestBody GoodsSearch goodsSearch) {

		GagaMap result = new GagaMap();

		// 입점업체담당자는 업체코드 설정
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			goodsSearch.setSupplyCompCd(TssSession.getInfo().getSupplyCompCd());
//			goodsSearch.setMdNo(TssSession.getInfo().getUserNo().toString());
		}

		// multi row 검색관련 처리
		if (!StringUtils.isBlank(goodsSearch.getCondition())) {
			goodsSearch.setConditionList(goodsSearch.getCondition().replaceAll("\r", "").trim().split("\n"));

			if ("searchExtendGoodsCd".equals(goodsSearch.getSearch())) {
				goodsSearch.setSearchGb("EXTEND");
			} else if ("searchMasterGoodsCd".equals(goodsSearch.getSearch())) {
				goodsSearch.setSearchGb("MASTER");
			}
		}

		goodsSearch.setRegNo(TssSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		goodsSearch.setPageable(new TscPageRequest(goodsSearch.getPageNo() - 1, goodsSearch.getPageSize()));
		goodsSearch.getPageable().setTotalCount(goodsService.getGoodsListCount(goodsSearch));

		result.set("pageing", goodsSearch);
		result.set("goodsList", goodsService.getGoodsList(goodsSearch));

		return result;
	}

	/**
	 * 상품 품목 변경 저장
	 *
	 * @param goodsList
	 * @return
	 * @author eskim
	 * @since 2021. 01. 24
	 */
	@PostMapping("/itemKind/change/save")
	@ResponseBody
	public GagaResponse saveItemKindChange(@RequestBody Collection<Goods> goodsList) {
		goodsService.saveItemKindChange(goodsList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 사은품 화면
	 * @return
	 * @author eskim
	 * @since 2020. 12. 28
	 */
	@GetMapping("/freeGoods/form")
	public ModelAndView goodsfreeGoodsForm() {
		ModelAndView mav = new ModelAndView();

		String supplyCompCd = "";
		if ("G001_B000".equals(TssSession.getInfo().getRoleCd())) {
			supplyCompCd = TssSession.getInfo().getSupplyCompCd();
		}
		// 공급업체
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, "Y"));
		// 상품상태
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));

		mav.setViewName("goods/GoodsFreeGoodsForm");

		return mav;
	}

	/**
	 * 사은품 목록
	 * @param adKeywordSq
	 * @return
	 * @author eskim
	 * @since 2020. 12. 28
	 */
	@PostMapping("/freeGoods/list")
	@ResponseBody
	public Collection<FreeGoods> getFreeGoodsList(@RequestBody GoodsSearch goodsSearch) {

		// multi row 검색관련 처리
		if (!StringUtils.isBlank(goodsSearch.getCondition())) {
			goodsSearch.setConditionList(goodsSearch.getCondition().replaceAll("\r", "").trim().split("\n"));
		}

		return goodsService.getFreeGoodsList(goodsSearch);
	}

	/**
	 *  사은품 상품 저장
	 *
	 * @param freeGoods
	 * @return
	 * @author eskim
	 * @since 2020. 12. 28
	 */
	@PostMapping("/freeGoods/update")
	@ResponseBody
	public GagaResponse updateFreeGoods(@RequestBody FreeGoods freeGoods) {

		if (freeGoods.getNewSysImgNm() != null && !"".equals(freeGoods.getNewSysImgNm())) {
			String sysImgNm = freeGoods.getProductNo() + "_" + GagaDateUtil.getTodayDateTime() + "." + org.springframework.util.StringUtils.getFilenameExtension(freeGoods.getNewSysImgNm());

			String imgUploadPath = env.getProperty("upload.default.target.path");
			imgUploadPath = GagaFileUtil.getConcatenationPath(imgUploadPath, "display", "freegoods");

			//기존이미지 삭제
			try {
				GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(imgUploadPath, freeGoods.getSysImgNm()));
			} catch (IOException e) {
				//  nothing
				log.info("[updateFreeGoods 기존 이미지 삭제중 error]");
				//e.printStackTrace();
			}

			File uniqueFile = GagaFileUtil.getUniqueFile(new File(GagaFileUtil.getConcatenationPath(imgUploadPath, sysImgNm)));

			File file = new File(GagaFileUtil.getConcatenationPath(imgUploadPath, freeGoods.getNewSysImgNm()));

			// Rename a file
			file.renameTo(uniqueFile);

			freeGoods.setSysImgNm(sysImgNm);

		}
		goodsService.updateFreeGoods(freeGoods);
		return super.ok(message.getMessage("SUCC_0001"));
	}

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

	/**
	 * 상품 안전인증번호 저장
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 12. 07
	 */
	@PostMapping("/detail/certNum/save")
	@ResponseBody
	public GagaResponse saveGoodsDetailCertNum(@RequestBody GoodsSafeNo goodsSafeNo) {
		goodsService.saveGoodsDetailCertNum(goodsSafeNo);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 입점 상품  화면
	 *
	 * @return
	 * @author eskim
	 * @since 2021. 04. 21
	 */
	@GetMapping("/register/form")
	public ModelAndView registerForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String selfYn = "N";
		String supplyCompCd = TssSession.getInfo().getSupplyCompCd();
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, selfYn));

		SupplyCompany supplyCompany = new SupplyCompany();
		supplyCompany.setSupplyCompCd(supplyCompCd);
		Collection<SupplyCompany> supplyCompanyInfoList = businessService.getSupplyCompanyList(supplyCompany);
		mav.addObject("supplyCompanyInfo", supplyCompanyInfoList.iterator().next());

		// 배송비정보
		mav.addObject("delvFeeCdList", rendererService.getSupplyDeliveryFeePolicyList(supplyCompCd));

		String[] goodsStatExceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", goodsStatExceptCds));

		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		// 성별
		mav.addObject("sexGbList", rendererService.getAvailCommonCodeList("G007"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());
		// 정보고시 분류
		mav.addObject("niClsfCdList", rendererService.getAvailCommonCodeList("G004"));
		// 사용자 브랜드 조회
		mav.addObject("authBrandList", rendererService.getSupplyCompanyBrandList(supplyCompCd));
		// 상품타입
		mav.addObject("goodsTypeList", rendererService.getAvailCommonCodeList("G056"));
		// 상품구분
		mav.addObject("goodsGbList", rendererService.getAvailCommonCodeList("G073"));
		// 유통구분
		String[] distributionGbExceptCds = {"G065_10", "G065_11", "G065_12"};
		mav.addObject("distributionGbList", rendererService.getCommonCodeList("G065", "Y", distributionGbExceptCds));
		// 상품연령대
		mav.addObject("ageGrpCdList", rendererService.getAvailCommonCodeList("G023"));
		// 원산지
		mav.addObject("originCdList", rendererService.getAvailCommonCodeList("G076"));
		// kc인증타입
		mav.addObject("certTypeList", rendererService.getAvailCommonCodeList("G081"));
		// kc인증대상구분
		mav.addObject("certTargetGbList", rendererService.getAvailCommonCodeList("G083"));
		// kc인증형태구분
		mav.addObject("certFormGbList", rendererService.getAvailCommonCodeList("G084"));
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 회원등급
		//mav.addObject("custGradeList", rendererService.getAvailCommonCodeList("G110"));
		// 출고처
		mav.addObject("delvLocCdList", rendererService.getSupplyDeliveryLocList(supplyCompCd));

		//mav.addObject("params", goods);
		mav.setViewName("goods/GoodsRegisterForm");

		return mav;
	}

	/**
	 * 상품의 정보고시 항목 목록
	 *
	 * @param notiInfo
	 * @return
	 * @author eskim
	 * @since 2010. 11. 18
	 */
	@PostMapping("/notiInfo/list")
	@ResponseBody
	public Collection<NotiInfo> getNotiInfoItemList(NotiInfo notiInfo) {
		return goodsService.getNotiInfoItemList(notiInfo);
	}

	/**
	 * 입점 상품 등록
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2021. 04. 21
	 */
	@PostMapping("/detail/create")
	@ResponseBody
	public GagaMap createGoodsDetail(@RequestBody Goods goods) {
		GagaMap result = new GagaMap();
		Collection<GoodsNotiInfo> notiList = null;
		ObjectMapper mapper = new ObjectMapper();
		try {
			if (goods.getNotiList() != null) {
				notiList = mapper.readValue(goods.getNotiList(), new TypeReference<Collection<GoodsNotiInfo>>() {
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		goods.setNotiListNew(notiList);

		goodsService.createGoodsDetail(goods);
		result.set("goodsCd", goods.getGoodsCd());

		return result;

	}

	/**
	 * 딜상품구성 화면
	 *
	 * @param
	 * @return
	 * @author eskim
	 * @since 2021. 05. 26
	 */
	@GetMapping("/deal/form")
	@ResponseBody
	public ModelAndView dealForm(Goods goods) {
		ModelAndView mav = new ModelAndView();

		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		// 성별
		mav.addObject("sexGbList", rendererService.getAvailCommonCodeList("G007"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 스타일년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 매입유형
		mav.addObject("buyingTypeList", rendererService.getAvailCommonCodeList("G035"));
		// 색상
//		Color color = new Color();
//		mav.addObject("colorCdList", rendererService.getColorList(color));
		// 상품상태
		// mav.addObject("goodsStatList",
		// rendererService.getAvailCommonCodeList("G008"));
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		// 원산지
		mav.addObject("makOriginList", rendererService.getAvailCommonCodeList("G076"));

		mav.addObject("params", goods);
		mav.setViewName("goods/GoodsDealForm");
		return mav;
	}

	/**
	 * 딜 상품 등록
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2021. 05. 26
	 */
	@PostMapping("/deal/save")
	@ResponseBody
	public GagaResponse saveGoodsDeal(@RequestBody Goods goods) {
		goodsService.saveGoodsDeal(goods);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 구성상품 목록
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2021. 05. 26
	 */
	@GetMapping("/detail/compose/list")
	@ResponseBody
	public Collection<GoodsCompose> getGoodsDetailComposeList(Goods goods) {
		return goodsService.getGoodsDetailComposeList(goods);
	}

	/**
	 * 품목 목록
	 *
	 * @param itemkind
	 * @return
	 * @author eskim
	 * @since 2021. 06. 27
	 */
	@PostMapping("/itemkind/list")
	@ResponseBody
	public Collection<Itemkind> getItemkindList(Itemkind itemkind) {
		return goodsService.getItemkindList(itemkind);
	}
	
	/**
	 * 자사 상품  화면
	 *
	 * @return
	 * @author eskim
	 * @since 2021. 06. 30
	 */
	@GetMapping("/salf/register/form")
	public ModelAndView salfRegisterForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String selfYn = "Y";
		String supplyCompCd = TssSession.getInfo().getSupplyCompCd();
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, selfYn));

		// 배송비정보
		mav.addObject("delvFeeCdList", rendererService.getSupplyDeliveryFeePolicyList(supplyCompCd));

		String[] goodsStatExceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", goodsStatExceptCds));

		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		// 성별
		mav.addObject("sexGbList", rendererService.getAvailCommonCodeList("G007"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());
		// 정보고시 분류
		mav.addObject("niClsfCdList", rendererService.getAvailCommonCodeList("G004"));
		// 사용자 브랜드 조회
		mav.addObject("authBrandList", rendererService.getSupplyCompanyBrandList(supplyCompCd));
		// 상품타입
		mav.addObject("goodsTypeList", rendererService.getAvailCommonCodeList("G056"));
		// 상품구분
		mav.addObject("goodsGbList", rendererService.getAvailCommonCodeList("G073"));
		// 유통구분
		String[] distributionGbExceptCds = {"G065_20"};
		mav.addObject("distributionGbList", rendererService.getCommonCodeList("G065", "Y", distributionGbExceptCds));
		// 상품연령대
		mav.addObject("ageGrpCdList", rendererService.getAvailCommonCodeList("G023"));
		// 원산지
		mav.addObject("originCdList", rendererService.getAvailCommonCodeList("G076"));
		// kc인증타입
		mav.addObject("certTypeList", rendererService.getAvailCommonCodeList("G081"));
		// kc인증대상구분
		mav.addObject("certTargetGbList", rendererService.getAvailCommonCodeList("G083"));
		// kc인증형태구분
		mav.addObject("certFormGbList", rendererService.getAvailCommonCodeList("G084"));
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 회원등급
		//mav.addObject("custGradeList", rendererService.getAvailCommonCodeList("G110"));
		// 출고처
		mav.addObject("delvLocCdList", rendererService.getSupplyDeliveryLocList(supplyCompCd));

		//mav.addObject("params", goods);
		mav.setViewName("goods/GoodsSalfRegisterForm");

		return mav;
	}

	/**
	 * 자사 상품 등록
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2021. 07. 02
	 */
	@PostMapping("/salf/detail/create")
	@ResponseBody
	public GagaMap createSalfGoodsDetail(@RequestBody Goods goods) {
		GagaMap result = new GagaMap();
		Collection<GoodsNotiInfo> notiList = null;
		ObjectMapper mapper = new ObjectMapper();
		try {
			if (goods.getNotiList() != null) {
				notiList = mapper.readValue(goods.getNotiList(), new TypeReference<Collection<GoodsNotiInfo>>() {
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		goods.setNotiListNew(notiList);

		goodsService.createSalfGoodsDetail(goods);
		result.set("goodsCd", goods.getGoodsCd());

		return result;

	}

}
