package com.style24.admin.biz.web;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;

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.util.StringUtils;
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.admin.biz.service.TsaCommonService;
import com.style24.admin.biz.service.TsaGoodsService;
import com.style24.admin.biz.service.TsaRendererService;
import com.style24.admin.biz.service.TsaSystemService;
import com.style24.admin.support.controller.TsaBaseController;
import com.style24.admin.support.security.session.TsaSession;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.TsaPageRequest;
import com.style24.persistence.domain.AdKeyword;
import com.style24.persistence.domain.AdKeywordGoods;
import com.style24.persistence.domain.Color;
import com.style24.persistence.domain.Goods;
import com.style24.persistence.domain.GoodsCompose;
import com.style24.persistence.domain.GoodsEpSkip;
import com.style24.persistence.domain.GoodsHst;
import com.style24.persistence.domain.GoodsImg;
import com.style24.persistence.domain.GoodsNaverLowestPrice;
import com.style24.persistence.domain.GoodsNotiInfo;
import com.style24.persistence.domain.GoodsPriceRes;
import com.style24.persistence.domain.GoodsResSell;
import com.style24.persistence.domain.GoodsSearch;
import com.style24.persistence.domain.GoodsTnmRes;
import com.style24.persistence.domain.GoodsVideo;
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.ReinboundInform;
import com.style24.persistence.domain.User;
import com.style24.persistence.domain.Video;
import com.style24.persistence.domain.WmsColorMapping;
import com.style24.persistence.domain.WmsSeasonMapping;
import com.style24.persistence.domain.WmsStyleYearMapping;

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 eskim
 * @since 2020. 10. 16
 */
@Controller
@RequestMapping("/goods")
@Slf4j
public class TsaGoodsController extends TsaBaseController {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private Environment env;

	@Autowired
	private TsaGoodsService goodsService;

	@Autowired
	private TsaRendererService rendererService;

	@Autowired
	private TsaCommonService commonService;

	@Autowired
	private TsaSystemService systemService;

	/**
	 * 품목관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@GetMapping("/itemkind/base/form")
	public ModelAndView itemkindBaseForm() {
		ModelAndView mav = new ModelAndView();

		// 정보고시 목록
		mav.addObject("niClsfCdList", rendererService.getAvailCommonCodeList("G004"));

		mav.setViewName("goods/ItemkindBaseForm");

		return mav;
	}

	/**
	 * 품목관리 조회
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@PostMapping("/itemkind/base/list")
	@ResponseBody
	public Collection<Itemkind> getItemkindList(@RequestBody Itemkind itemkind) {
		return goodsService.getItemkindList(itemkind);
	}

	/**
	 * 품목 관리 저장/등록
	 *
	 * @param itemkindList
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@PostMapping("/itemkind/save")
	@ResponseBody
	public GagaResponse saveItemkindInfo(@RequestBody Collection<Itemkind> itemkindList) {
		goodsService.saveItemkindInfo(itemkindList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 품목관리 삭제
	 *
	 * @param itemkindList
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@PostMapping("/itemkind/delete")
	@ResponseBody
	public GagaResponse deleteItemkindInfo(@RequestBody Collection<Itemkind> itemkindList) {
		goodsService.deleteItemkindInfo(itemkindList);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 색상관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@GetMapping("/color/form")
	public ModelAndView colorForm() {
		ModelAndView mav = new ModelAndView();

		// 대표컬러목록
		mav.addObject("groupColorCodeList", rendererService.getColorGrpCdRgbList());
		// 대표컬러명목록
		mav.addObject("groupColorCodeNmList", rendererService.getCommonCodeList("G072"));

		mav.setViewName("goods/ColorForm");

		return mav;
	}

	/**
	 * 색상 조회
	 *
	 * @param color
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@PostMapping("/color/list")
	@ResponseBody
	public Collection<Color> getColorList(@RequestBody Color color) {
		return goodsService.getColorList(color);
	}

	/**
	 * 색상 저장
	 *
	 * @param color
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@PostMapping("/color/save")
	@ResponseBody
	public GagaResponse saveColor(@RequestBody Collection<Color> colorList) {

		goodsService.saveColor(colorList);

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

	/**
	 * WMS 시즌매핑 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@GetMapping("/wms/season/form")
	public ModelAndView seasonForm() {
		ModelAndView mav = new ModelAndView();

		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));

		mav.setViewName("goods/WmsSeasonMappingForm");

		return mav;
	}

	/**
	 * WMS 시즌 매핑 조회
	 *
	 * @param color
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@PostMapping("/wms/season/mapping/list")
	@ResponseBody
	public Collection<WmsSeasonMapping> getWmsSeasonMappingList(@RequestBody WmsSeasonMapping wmsSeasonMapping) {
		return goodsService.getWmsSeasonMappingList(wmsSeasonMapping);
	}

	/**
	 * WMS 시즌 매핑 저장
	 *
	 * @param color
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@PostMapping("/wms/season/mapping/save")
	@ResponseBody
	public GagaResponse saveWmsSeasonMapping(@RequestBody Collection<WmsSeasonMapping> wmsSeasonMappingList) {

		goodsService.saveWmsSeasonMapping(wmsSeasonMappingList);

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

	/**
	 * 고시정보관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@GetMapping("/notiinfo/form")
	public ModelAndView notiinfoForm() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 정보고시 분류별 항목
		mav.addObject("niItemCdList", rendererService.getAvailCommonCodeList("G005"));

		mav.setViewName("goods/NotiinfoForm");

		return mav;
	}

	/**
	 * 정보고시관리 조회
	 *
	 * @param notiInfo
	 * @return
	 * @author eskim
	 * @since 2010. 10. 19
	 */
	@PostMapping("/notiInfo/list")
	@ResponseBody
	public Collection<NotiInfo> getNotiInfoList(@RequestBody NotiInfo notiInfo) {
		return goodsService.getNotiInfoList(notiInfo);
	}

	/**
	 * 정보고시 항목 목록
	 *
	 * @param notiInfo
	 * @return
	 * @author eskim
	 * @since 2010. 10. 19
	 */
	@PostMapping("/notiInfo/item/list")
	@ResponseBody
	public Collection<NotiInfo> getNotiInfoItemList(@RequestBody NotiInfo notiInfo) {
		return goodsService.getNotiInfoItemList(notiInfo);
	}

	/**
	 * 정보고시 상세 저장
	 *
	 * @param notiInfoList
	 * @return
	 * @author eskim
	 * @since 2010. 10. 19
	 */
	@PostMapping("/notiInfo/item/save")
	@ResponseBody
	public GagaResponse saveNotiInfoItem(@RequestBody Collection<NotiInfo> notiInfoList) {

		goodsService.saveNotiInfoItem(notiInfoList);

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

	/**
	 * WMS 색상 매핑 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	@GetMapping("/wms/color/form")
	public ModelAndView wmsColorForm() {
		ModelAndView mav = new ModelAndView();

		Color color = new Color();
		mav.addObject("colorList", rendererService.getColorList(color));

		mav.setViewName("goods/WmsColorMappingForm");

		return mav;
	}

	/**
	 * WMS 색상 매핑 조회
	 *
	 * @param color
	 * @return
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	@PostMapping("/wms/color/mapping/list")
	@ResponseBody
	public Collection<WmsColorMapping> getWmsColorMappingList(@RequestBody WmsColorMapping wmsColorMapping) {
		return goodsService.getWmsColorMappingList(wmsColorMapping);
	}

	/**
	 * WMS 색상 매핑 저장
	 *
	 * @param color
	 * @return
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	@PostMapping("/wms/color/mapping/save")
	@ResponseBody
	public GagaResponse saveWmsColorMapping(@RequestBody Collection<WmsColorMapping> wmsColorMappingList) {

		goodsService.saveWmsColorMapping(wmsColorMappingList);

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

	/**
	 * WMS 스타일년도 매핑 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	@GetMapping("/wms/styleYear/form")
	public ModelAndView wmsStyleYearForm() {
		ModelAndView mav = new ModelAndView();

		// 년도
		int fromYear = Integer.parseInt("2008");
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy"));
		mav.addObject("styleYearList", rendererService.getYearList(fromYear, 0, toYear - fromYear + 3));

		mav.setViewName("goods/WmsStyleYearMappingForm");

		return mav;
	}

	/**
	 * WMS 스타일년도 매핑 조회
	 *
	 * @param color
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@PostMapping("/wms/styleYear/mapping/list")
	@ResponseBody
	public Collection<WmsStyleYearMapping> getWmsStyleYearMappingList(@RequestBody WmsStyleYearMapping wmsStyleYearMapping) {
		return goodsService.getWmsStyleYearMappingList(wmsStyleYearMapping);
	}

	/**
	 * WMS 스타일년도 매핑 저장
	 *
	 * @param color
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@PostMapping("/wms/styleYear/mapping/save")
	@ResponseBody
	public GagaResponse saveWmsStyleYearMapping(@RequestBody Collection<WmsStyleYearMapping> wmsStyleYearMappingList) {

		goodsService.saveWmsStyleYearMapping(wmsStyleYearMappingList);

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

	/**
	 * 상품목록 화면
	 *
	 * @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(TsaSession.getInfo().getRoleCd())) {
			supplyCompCd = TsaSession.getInfo().getSupplyCompCd();
			selfYn = "N";
		}
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, selfYn));
		// 상품상태
		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"));
		// 년도
		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(TsaSession.getInfo().getRoleCd())) {
			goodsSearch.setSupplyCompCd(TsaSession.getInfo().getSupplyCompCd());
			goodsSearch.setMdNo(TsaSession.getInfo().getUserNo().toString());
		}

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

			if ("searchExtendGoodsCd".equals(goodsSearch.getSearch())) {
				goodsSearch.setSearchGb("EXTEND");
			} else if ("searchMasterGoodsCd".equals(goodsSearch.getSearch())) {
				goodsSearch.setSearchGb("MASTER");
			}
		}
		log.info("[getGoodsList] goodsSearch=>{}", goodsSearch);
		goodsSearch.setRegNo(TsaSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		goodsSearch.setPageable(new TsaPageRequest(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(TsaSession.getInfo().getRoleCd())) {
			goodsSearch.setSupplyCompCd(TsaSession.getInfo().getSupplyCompCd());
			goodsSearch.setMdNo(TsaSession.getInfo().getUserNo().toString());
		}
		goodsSearch.setRegNo(TsaSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용

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

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

		// 대용량엑셀파일다운로드는 이런 식으로 ...
		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_0000".equals(TsaSession.getInfo().getRoleCd()) && !"G001_A000".equals(TsaSession.getInfo().getRoleCd())
			&& !"G001_A001".equals(TsaSession.getInfo().getRoleCd()) && !"G001_A100".equals(TsaSession.getInfo().getRoleCd())
			&& !"G001_A101".equals(TsaSession.getInfo().getRoleCd())) {
			throw new IllegalStateException("권한이 없습니다.");
		}

		// 상품 상태 변경일 경우 체크
		if ("goodsStat".equals(goods.getProcJob()) && ("G008_40".equals(goods.getGoodsStat()) || "G008_90".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.getGoods(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.setSupplyCompCd(tmpGoods.getSupplyCompCd());
					goodsNotiInfo.setNiClsfCd(tmpGoods.getNiClsfCd());
					Collection<GoodsNotiInfo> goodsNotiInfoList = goodsService.getGoodsNotiInfoList(goodsNotiInfo);
					if (goodsNotiInfoList == null || goodsNotiInfoList.isEmpty()) {
						returnGoods += tmpGoods.getGoodsCd() + ",";
					} else {
						for (GoodsNotiInfo tmpGoodsNotiInfo : goodsNotiInfoList) {
							if ("Y".equals(tmpGoodsNotiInfo.getReqYn()) || "Y".equals(tmpGoodsNotiInfo.getDispYn())) {
								if (StringUtils.isEmpty(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", "supplyGoodsCd"};

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

		Collection<Goods> goodsList = new ArrayList<>();
		for (GagaMap map : ecxelGoodsList) {
			Goods tmpGoods = mapper.convertValue(map, Goods.class);
			tmpGoods.setRegNo(TsaSession.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(TsaSession.getInfo().getRoleCd())) {
			goodsSearch.setSupplyCompCd(TsaSession.getInfo().getSupplyCompCd());
			goodsSearch.setMdNo(TsaSession.getInfo().getUserNo().toString());
		}
		goodsSearch.setRegNo(TsaSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		result.set("goodsExcelList", goodsService.getGoodsList(goodsSearch));
		return result;
	}

	/**
	 * 상품 상세 화면
	 *
	 * @param goodsCode - 상품코드
	 * @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(TsaSession.getInfo().getRoleCd())) {
//			supplyCompCd = TsaSession.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.getAuthBrandList(TsaSession.getInfo().getUserNo()));
		// 상품타입
		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"));
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 회원등급
		//mav.addObject("custGradeList", rendererService.getAvailCommonCodeList("G101"));

		mav.addObject("params", goods);

		mav.setViewName("goods/GoodsDetailForm");

		return mav;
	}

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

	/**
	 * 상품 이력 조회
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 23
	 */
	@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.getGoods(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 2020. 10. 26
	 */
	@PostMapping("/detail/notiInfo/list")
	@ResponseBody
	public Collection<GoodsNotiInfo> getGoodsDetailNotiInfoList(Goods goods) {

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

		return goodsService.getGoodsNotiInfoList(goodsInfo);
	}

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

	/**
	 * 상품 구매등급 조회
	 *
	 * @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 goods
	 * @return
	 * @author eskim
	 * @since 2020. 10. 27
	 */
	@GetMapping("/detail/compose/list")
	@ResponseBody
	public Collection<GoodsCompose> getGoodsDetailComposeList(Goods goods) {
		return goodsService.getGoodsDetailComposeList(goods);
	}

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

	/**
	 * 상품 상세 저장
	 *
	 * @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()) || "G008_90".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("필수 이미지나 고시정보가 등록되지 않은 상품은 <br/>'승인대기'나 '승인완료' 상태로 변경할 수 없습니다.");
			}
		}

		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 goodsCode - 상품코드
	 * @return
	 * @author eskim
	 * @since 2020. 11. 09
	 */
	@GetMapping("/image/form")
	@ResponseBody
	public ModelAndView imageMassForm(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());
				}
			}
		} else { // 대표이미지와 마우스오버이미지가 없으면
			mav.addObject("goodsImgList", new ArrayList<GoodsImg>());
			mav.addObject("defaultImgOrd", "1");
		}

		mav.addObject("goodsImg", goodsImg);
		mav.setViewName("goods/GoodsImageForm");
		return mav;
	}

	/**
	 * 상품 썸네일 이미지 저장 처리
	 * @param goodsImgList - 상품이미지 목록
	 * @return
	 * @throws Exception
	 * @author eskim
	 * @since 2020. 12. 21
	 */
	@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 = "";

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

		// 1.업로드된 파일 rename 및 순서 재정렬
		for (GoodsImg goodsImg : goodsImgList) {
			// dx5에서 삭제한 파일은 skip
			if (goodsImg.getMode().equals("D")) {
				continue;
			}

			// 상품의 브랜드 번호 추출
			if (strBrandNo.isEmpty()) {
				Goods goods = new Goods();
				goods.setGoodsCd(goodsImg.getGoodsCd());
				Goods goodsInfo = goodsService.getGoods(goods);
				if (goodsInfo == null || goodsInfo.getGoodsCd().isEmpty())
					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.getGoodsCd()
//						+ "_" + goodsImg.getColorCd()
//						+ "_" + String.valueOf(index)
//						+ "(" + GagaDateUtil.getTodayTime() + ")"
//						+ "." + StringUtils.getFilenameExtension(goodsImg.getSysImgNm());
				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()));
				log.info("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()));
			} 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);

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

	/**
	 * 세트상품구성 화면
	 *
	 * @param
	 * @return
	 * @author eskim
	 * @since 2020. 05. 26
	 */
	@GetMapping("/set/form")
	@ResponseBody
	public ModelAndView setForm(Goods goods) {
		ModelAndView mav = new ModelAndView();

		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 성별
		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));
		// 상품상태
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		// 원산지
		mav.addObject("originCdList", rendererService.getAvailCommonCodeList("G076"));

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

	/**
	 * 세트 상품 등록
	 *
	 * @param goods
	 * @return
	 * @author eskim
	 * @since 2020. 11. 04
	 */
	@PostMapping("/set/save")
	@ResponseBody
	public GagaResponse saveGoodsSet(@RequestBody Goods goods) {
		goodsService.saveGoodsSet(goods);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 딜상품구성 화면
	 *
	 * @param
	 * @return
	 * @author eskim
	 * @since 2020. 10. 29
	 */
	@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 2020. 10. 30
	 */
	@PostMapping("/deal/save")
	@ResponseBody
	public GagaResponse saveGoodsDeal(@RequestBody Goods goods) {
		goodsService.saveGoodsDeal(goods);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 상품 대량 등록 화면
	 *
	 * @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"));
		// ERP 연동여부
		mav.addObject("erpSyncYn", commonService.getErpSyncYn());
		// 정보고시 목록
		mav.addObject("niClsfCdList", rendererService.getAvailCommonCodeList("G004"));
		// 사용자 업체
		User loginInfo = systemService.getUser(TsaSession.getInfo().getUserNo());
		String supplyCompCd = "NONE";
		if (loginInfo != null) {
			supplyCompCd = loginInfo.getSupplyCompCd();
		}
		mav.addObject("supplyCompCd", supplyCompCd);
		mav.setViewName("goods/GoodsMassRegisterForm");

		return mav;
	}

	/**
	 * WMS입고상품관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@GetMapping("/wms/instock/form")
	public ModelAndView wmsInstockForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, "Y"));
		// 상품상태
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());

		mav.setViewName("goods/GoodsWmsInstockForm");

		return mav;
	}

	/**
	 * 상품품목변경관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 30
	 */
	@GetMapping("/itemkind/form")
	public ModelAndView itemkindForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		String selfYn = "Y";
		if ("G001_B000".equals(TsaSession.getInfo().getRoleCd())) {
			supplyCompCd = TsaSession.getInfo().getSupplyCompCd();
			selfYn = "N";
		}
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, selfYn));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());
		// 카테고리 구분
		mav.addObject("cateGbList", rendererService.getAvailCommonCodeList("G032"));
		// MD
		mav.addObject("brandMdList", rendererService.getBrandMdList());
		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));

		mav.setViewName("goods/GoodsItemkindForm");

		return mav;
	}

	/**
	 * 상품 품목 변경 저장
	 *
	 * @param goodsList
	 * @return
	 * @author eskim
	 * @since 2020. 10. 23
	 */
	@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. 10. 16
	 */
	@GetMapping("/supply/price/form")
	public ModelAndView priceForm() {
		ModelAndView mav = new ModelAndView();
		// 공급업체
		String supplyCompCd = "";
		if ("G001_B000".equals(TsaSession.getInfo().getRoleCd())) {
			supplyCompCd = TsaSession.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 Collection<GoodsPriceRes> getGoodsSupplyPriceList(@RequestBody GoodsPriceRes goodsPriceRes) {

		return goodsService.getGoodsSupplyPriceList(goodsPriceRes);
	}

	/**
	 * 상품 가격승인관리 승인 처리
	 *
	 * @param itemkindList
	 * @return
	 * @author eskim
	 * @since 2020. 11. 26
	 */
	@PostMapping("/supply/price/save")
	@ResponseBody
	public GagaResponse saveGoodsSupplyPrice(@RequestBody Collection<GoodsPriceRes> goodsPriceResList) {

		if (!"G001_0000".equals(TsaSession.getInfo().getRoleCd()) && !"G001_A000".equals(TsaSession.getInfo().getRoleCd())
			&& !"G001_A001".equals(TsaSession.getInfo().getRoleCd()) && !"G001_A100".equals(TsaSession.getInfo().getRoleCd())
			&& !"G001_A101".equals(TsaSession.getInfo().getRoleCd())) {
			throw new IllegalStateException("권한이 없습니다.");
		}
		goodsService.saveGoodsSupplyPrice(goodsPriceResList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 상품 타이틀예약관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 30
	 */
	@GetMapping("/title/reserve/form")
	public ModelAndView titleReserveForm() {
		ModelAndView mav = new ModelAndView();

		// 사이트
		String supplyCompCd = "";
		if ("G001_B000".equals(TsaSession.getInfo().getRoleCd())) {
			supplyCompCd = TsaSession.getInfo().getSupplyCompCd();
		}
		// 공급업체
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, "Y"));
		// 상품상태
		// mav.addObject("goodsStatList",
		// rendererService.getAvailCommonCodeList("G008"));
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 스타일년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());
		// MD
		mav.addObject("brandMdList", rendererService.getBrandMdList());

		mav.setViewName("goods/GoodsTitleReserveForm");

		return mav;
	}

	/**
	 * 상품 타이틀 관리 조회
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 30
	 */
	@PostMapping("/title/reserve/list")
	@ResponseBody
	public GagaMap goodsTitleReserveList(@RequestBody GoodsSearch goodsSearch) {

		GagaMap result = new GagaMap();

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

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

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

		result.set("pageing", goodsSearch);
		result.set("goodsTnmList", goodsService.getGoodsTitleReserveList(goodsSearch));

		return result;
	}

	/**
	 * 상품등록 타이틀 예약등록 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 02
	 */
	@GetMapping("/title/reserve/popup/form")
	@ResponseBody
	public ModelAndView goodsRsvtTnmListForm(GoodsTnmRes goodsTnmRes) {
		ModelAndView mav = new ModelAndView();

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

	/**
	 * 상품 타이틀 예약 저장
	 *
	 * @param goodsTnmRes
	 * @return
	 * @author eskim
	 * @since 2020. 11. 02
	 */
	@PostMapping("/title/reserve/save")
	@ResponseBody
	public GagaResponse saveGoodsRsvtTnm(@RequestBody GoodsTnmRes goodsTnmRes) {
		goodsService.saveGoodsRsvtTnm(goodsTnmRes);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 상품 타이틀 예약 삭제
	 *
	 * @param goodsTnmRes
	 * @return
	 * @author eskim
	 * @since 2020. 11. 02
	 */
	@PostMapping("/title/reserve/delete")
	@ResponseBody
	public GagaResponse deleteGoodsRsvtTnm(@RequestBody GoodsTnmRes goodsTnmRes) {
		goodsService.deleteGoodsRsvtTnm(goodsTnmRes);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 상품 동영상관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 16
	 */
	@GetMapping("/video/form")
	public ModelAndView videoForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("goods/GoodsVideoForm");

		return mav;
	}

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

	/**
	 * 상품 동영상 미노출 변경
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 16
	 */
	@PostMapping("/video/update/notUse")
	@ResponseBody
	public GagaResponse updateNotUseGoodsVideo(@RequestBody Collection<GoodsVideo> goodsVideos) {
		goodsService.updateNotUseGoodsVideo(goodsVideos);
		return super.ok(message.getMessage("SUCC_0009"));
	}

	/**
	 * 상품동영상 수정/저장
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 16
	 */
	@PostMapping("/video/save")
	@ResponseBody
	public GagaResponse saveGoodsVideo(@RequestBody Video video) {
		goodsService.saveGoodsVideo(video);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 상품동영상 엑셀 저장
	 *
	 * @param goods
	 * @return
	 * @throws Exception
	 * @author eskim
	 * @since 2020. 11. 16
	 */
	@PostMapping("/video/excel/save")
	@ResponseBody
	public GagaResponse saveExcelGoodsVideo(@RequestBody Video video) throws Exception {
		String[] cellName = null;
		// DB 처리 시 사용되는 파라미터명(셀명) 설정
		cellName = new String[2];
		cellName[0] = "displocVal";
		cellName[1] = "videoVal";
		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.default.target.path"), "excel");
		Collection<GagaMap> dataList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, video.getExcelFileNm()), 0, cellName);

		int cnt = goodsService.saveExcelGoodsVideo(dataList);

		GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(targetPath, video.getExcelFileNm()));

		return super.ok(cnt + " 건 처리되었습니다.");
	}

	/**
	 * 상품 EP제외상품관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 03
	 */
	@GetMapping("/ep/skip/form")
	public ModelAndView epSkipForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, "Y"));
		// 상품상태
		String[] exceptCds = {"G001_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());
		// MD
		mav.addObject("brandMdList", rendererService.getBrandMdList());

		mav.setViewName("goods/GoodsEpSkipForm");

		return mav;
	}

	/**
	 * 네이버 EP 제외 상품 조회
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 03
	 */
	@PostMapping("/ep/skip/list")
	@ResponseBody
	public GagaMap goodsEpSkipList(@RequestBody GoodsSearch goodsSearch) {

		GagaMap result = new GagaMap();

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

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

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

		result.set("pageing", goodsSearch);
		result.set("goodsEpSkipList", goodsService.getGoodsEpSkipList(goodsSearch));

		return result;
	}

	/**
	 * 네이버 EP 제외 상품 예약등록 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 03
	 */
	@GetMapping("/ep/skip/popup/form")
	@ResponseBody
	public ModelAndView goodsEpSkipPopupForm(GoodsEpSkip goodsEpSkip) {
		ModelAndView mav = new ModelAndView();

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

	/**
	 * 네이버 EP 제외 상품 예약 저장
	 *
	 * @param goodsEpSkip
	 * @return GagaResponse
	 * @author eskim
	 * @since 2020. 11. 03
	 */
	@PostMapping("/rsvt/ep/skip/save")
	@ResponseBody
	public GagaResponse saveGoodsRsvtEpSkip(@RequestBody GoodsEpSkip goodsEpSkip) {
		goodsService.saveGoodsRsvtEpSkip(goodsEpSkip);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 네이버 EP 제외 상품 예약 삭제
	 *
	 * @param goodsEpSkip
	 * @return GagaResponse
	 * @author eskim
	 * @since 2020. 11. 03
	 */
	@PostMapping("/rsvt/ep/skip/delete")
	@ResponseBody
	public GagaResponse deleteGoodsEpSkip(@RequestBody GoodsEpSkip goodsEpSkip) {
		goodsService.deleteGoodsEpSkip(goodsEpSkip);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 상품 재입고알림관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@GetMapping("/reinbound/inform/form")
	public ModelAndView reinboundInformForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, "Y"));
		// 카테고리 구분
		mav.addObject("cateGbList", rendererService.getAvailCommonCodeList("G032"));
		// 상품상태
		mav.addObject("goodsStatList", rendererService.getAvailCommonCodeList("G008"));

		mav.setViewName("goods/GoodsReinboundInformForm");

		return mav;
	}

	/**
	 * 재입고알림 목록 조회
	 *
	 * @param goodsSearch
	 * @return GagaMap
	 * @author daehyoung
	 * @since 2020. 07. 16
	 */
	@PostMapping("/reinbound/inform/list")
	@ResponseBody
	public GagaMap getReinboundInformList(@RequestBody GoodsSearch goodsSearch) {

		GagaMap result = new GagaMap();

		goodsSearch.setPageable(new TsaPageRequest(goodsSearch.getPageNo() - 1, goodsSearch.getPageSize()));
		goodsSearch.getPageable().setTotalCount(goodsService.getReinboundInformCount(goodsSearch));

		result.set("pageing", goodsSearch);
		result.set("reinboundInformList", goodsService.getReinboundInformList(goodsSearch));

		return result;
	}

	/**
	 * 재입고알림 발송 처리
	 *
	 * @param params
	 * @return GagaResponse
	 * @author eskim
	 * @since 2020. 12. 17
	 */
	@PostMapping("/reinbound/inform/send")
	@ResponseBody
	public GagaResponse sendReinboundInform(@RequestBody ReinboundInform reinboundInform) {
		goodsService.sendReinboundInform(reinboundInform);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 상품 예약판매관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 16
	 */
	@GetMapping("/reserve/sell/form")
	public ModelAndView reserveSellForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, "Y"));
		// 상품상태
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());
		// MD
		mav.addObject("brandMdList", rendererService.getBrandMdList());

		mav.setViewName("goods/GoodsReserveSellForm");

		return mav;
	}

	/**
	 * 상품예약판매 목록 조회
	 *
	 * @param goodsSearch
	 * @return GagaMap
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	@PostMapping("/reserve/sell/list")
	@ResponseBody
	public GagaMap goodsReserveSellList(@RequestBody GoodsSearch goodsSearch) {

		GagaMap result = new GagaMap();

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

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

		result.set("pageing", goodsSearch);
		result.set("goodsResSellList", goodsService.getGoodsResSellList(goodsSearch));

		return result;
	}

	/**
	 * 상품예약판매 등록 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	@GetMapping("/reserve/sell/popup/form")
	@ResponseBody
	public ModelAndView goodsReserveSellRegistForm() {
		ModelAndView mav = new ModelAndView();

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

	/**
	 * 상품예약판매 저장
	 *
	 * @param goodsResSell
	 * @return GagaResponse
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	@PostMapping("/reserve/sell/regist/save")
	@ResponseBody
	public GagaResponse saveGoodsResSell(@RequestBody GoodsResSell goodsResSell) {
		goodsService.saveGoodsResSell(goodsResSell);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 상품예약판매 삭제
	 *
	 * @param goodsResSell
	 * @return GagaResponse
	 * @author eskim
	 * @since 2020. 11. 12
	 */
	@PostMapping("/reserve/sell/delete")
	@ResponseBody
	public GagaResponse deleteGoodsResSell(@RequestBody GoodsResSell goodsResSell) {
		goodsService.deleteGoodsResSell(goodsResSell);
		return super.ok(message.getMessage("SUCC_0003"));
	}

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

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

		mav.setViewName("goods/GoodsNoticeForm");

		return mav;
	}

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

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

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

		return goodsService.getNoticeList(goodsSearch);
	}

	/**
	 * 상품 상세공지 상품목록
	 * @param notice - 공지사항 정보
	 * @return
	 * @author eskim
	 * @since 2020. 11. 06
	 */
	@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. 05
	 */
	@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(TsaSession.getInfo().getRoleCd())) {
			supplyCompCd = TsaSession.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(TsaSession.getInfo().getRoleCd())) {
			goodsSearch.setSupplyCompCd(TsaSession.getInfo().getSupplyCompCd());
			goodsSearch.setMdNo(TsaSession.getInfo().getUserNo().toString());
		}

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

			if ("searchExtendGoodsCd".equals(goodsSearch.getSearch())) {
				goodsSearch.setSearchGb("EXTEND");
			} else if ("searchMasterGoodsCd".equals(goodsSearch.getSearch())) {
				goodsSearch.setSearchGb("MASTER");
			}
		}
		log.info("[getPopupGoodsList] goodsSearch=>{}", goodsSearch);
		goodsSearch.setRegNo(TsaSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		goodsSearch.setPageable(new TsaPageRequest(goodsSearch.getPageNo() - 1, goodsSearch.getPageSize()));
		goodsSearch.getPageable().setTotalCount(goodsService.getGoodsListCount(goodsSearch));

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

		return result;
	}

	/**
	 * 상품 가격예약관리 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@GetMapping("/price/reserve/form")
	public ModelAndView priceReserveForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, "Y"));
		// 상품상태
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		// 정상이월
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		// 품목
		mav.addObject("itemkindList", rendererService.getAllItemkindList());
		// MD
		mav.addObject("brandMdList", rendererService.getBrandMdList());

		mav.setViewName("goods/GoodsPriceReserveForm");

		return mav;
	}

	/**
	 * 상품 가격예약 목록 조회
	 *
	 * @param goodsSearch
	 * @return GagaMap
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@PostMapping("/price/reserve/list")
	@ResponseBody
	public GagaMap goodsPriceReserveList(@RequestBody GoodsSearch goodsSearch) {

		GagaMap result = new GagaMap();

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

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

		result.set("pageing", goodsSearch);
		result.set("goodsPriceResList", goodsService.getGoodsPriceResList(goodsSearch));

		return result;
	}

	/**
	 * 상품 가격예약 등록 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@GetMapping("/price/reserve/popup/form")
	@ResponseBody
	public ModelAndView goodsPriceReserveRegistForm() {
		ModelAndView mav = new ModelAndView();

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

	/**
	 * 상품 가격예약 저장
	 *
	 * @param goodsResSell
	 * @return GagaResponse
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@PostMapping("/price/reserve/save")
	@ResponseBody
	public GagaResponse saveGoodsPriceRes(@RequestBody GoodsPriceRes goodsPriceRes) {
		goodsService.createGoodPriceRes(goodsPriceRes);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 상품 가격예약 삭제
	 *
	 * @param goodsResSell
	 * @return GagaResponse
	 * @author eskim
	 * @since 2020. 11. 13
	 */
	@PostMapping("/price/reserve/delete")
	@ResponseBody
	public GagaResponse deleteGoodsPriceRes(@RequestBody GoodsPriceRes goodsPriceRes) {
		goodsService.deleteGoodsPriceRes(goodsPriceRes);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 상품 가격예약 변경
	 *
	 * @param goods
	 * @return
	 * @throws Exception
	 * @author eskim
	 * @since 2020. 02. 20
	 */
	@PostMapping("/price/excelupload/save")
	@ResponseBody
	public GagaResponse saveGoodsPriceResvExcelupload(@RequestBody Goods goods) throws Exception {

		ObjectMapper mapper = new ObjectMapper();

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

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

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

		Collection<GoodsPriceRes> goodsPriceList = new ArrayList<>();
		for (GagaMap map : ecxelGoodsList) {
			GoodsPriceRes goodsPriceRes = mapper.convertValue(map, GoodsPriceRes.class);
			goodsPriceList.add(goodsPriceRes);
		}

		goodsService.saveGoodsPriceExcelupload(goodsPriceList, goods.getExcelFileNm());

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

		return super.ok("");
	}

	/**
	 * 네이버 최저가 조회 화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 12. 03
	 */
	@GetMapping("/naver/price/form")
	@ResponseBody
	public ModelAndView goodsNaverPriceForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		String supplyCompCd = "";
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(supplyCompCd, "Y"));
		// 시즌
		mav.addObject("seasonList", rendererService.getAvailCommonCodeList("G006"));
		// 년도
		int toYear = Integer.parseInt(GagaDateUtil.getToday("yyyy")) - 4;
		mav.addObject("styleYearList", rendererService.getYearList(toYear, 0, 5));

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

	/**
	 * 상품 네이버 최저가 조회
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 12. 03
	 */
	@PostMapping("/naver/price/list")
	@ResponseBody
	public Collection<GoodsNaverLowestPrice> getGoodsNaverPriceList(@RequestBody GoodsSearch goodsSearch) {

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

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

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

		return goodsService.getGoodsNaverPriceList(goodsSearch);
	}

	/**
	 * 네이버 최저가 상품 정보 조회
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 10. 03
	 */
	@PostMapping("/naver/lowest/price/save")
	@ResponseBody
	public Collection<GoodsNaverLowestPrice> saveGoodsNaverPrice(@RequestBody GoodsSearch goodsSearch) {

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

		return goodsService.saveGoodsNaverPrice(goodsSearch);
	}

	/**
	 * 광고 키워드 관리  화면
	 *
	 * @return
	 * @author eskim
	 * @since 2020. 12. 11
	 */
	@GetMapping("/ad/keyword/form")
	@ResponseBody
	public ModelAndView goodsAdForm() {
		ModelAndView mav = new ModelAndView();

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

	/**
	 * 광고 키워드 목록
	 * @param adKeyword
	 * @return
	 * @author eskim
	 * @since 2020. 12. 15
	 */
	@PostMapping("/ad/keyword/list")
	@ResponseBody
	public Collection<AdKeyword> getAdKeywordList(@RequestBody AdKeyword adKeyword) {
		return goodsService.getAdKeywordList(adKeyword);
	}

	/**
	 * 광고 키워드 상품목록
	 * @param adKeywordSq
	 * @return
	 * @author eskim
	 * @since 2020. 12. 15
	 */
	@GetMapping("/ad/keyword/goods/list/{adKeywordSq}")
	@ResponseBody
	public Collection<AdKeywordGoods> getAdKeywordGoodsList(@PathVariable Integer adKeywordSq) {
		AdKeyword adKeyword = new AdKeyword();
		adKeyword.setAdKeywordSq(adKeywordSq);
		return goodsService.getAdKeywordGoodsList(adKeyword);
	}

	/**
	 * 광고 키워드 저장/등록
	 *
	 * @param adKeyword
	 * @return
	 * @author eskim
	 * @since 2020. 12. 15
	 */
	@PostMapping("/ad/keyword/save")
	@ResponseBody
	public GagaResponse saveAdKeywordGoods(@RequestBody AdKeyword adKeyword) {
		goodsService.saveAdKeywordGoods(adKeyword);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 광고 키워드 상품 삭제
	 *
	 * @param adKeywordGoods
	 * @return
	 * @author eskim
	 * @since 2020. 12. 15
	 */
	@PostMapping("/ad/keyword/goods/delete")
	@ResponseBody
	public GagaResponse deleteAdKeywordGoods(@RequestBody AdKeywordGoods adKeywordGoods) {
		goodsService.deleteAdKeywordGoods(adKeywordGoods);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 상품고시정보 화면
	 * @return
	 * @author gagamel
	 * @since 2020. 12. 8
	 */
	@GetMapping("/noti/info/form")
	public ModelAndView goodsNotiInfoForm() {
		ModelAndView mav = new ModelAndView();

		// 고시분류
		mav.addObject("niClsfCdList", rendererService.getAvailCommonCodeList("G004"));

		mav.setViewName("goods/GoodsNotiInfoForm");

		return mav;
	}

}
