package com.style24.front.biz.web;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.mobile.device.Device;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gagaframework.web.parameter.GagaMap;
import com.gagaframework.web.util.GagaCookieUtil;
import com.style24.core.biz.service.TscEnvsetService;
import com.style24.core.biz.service.TscLookbookService;
import com.style24.core.support.env.TscConstants;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.front.biz.service.TsfCommonService;
import com.style24.front.biz.service.TsfDisplayService;
import com.style24.front.biz.service.TsfGoodsService;
import com.style24.front.biz.service.TsfPlanningService;
import com.style24.front.biz.service.TsfSocialService;
import com.style24.front.biz.thirdparty.EigeneaiApi;
import com.style24.front.biz.thirdparty.SearchEngineDiquest;
import com.style24.front.support.controller.TsfBaseController;
import com.style24.front.support.env.TsfConstants;
import com.style24.front.support.security.session.TsfSession;
import com.style24.persistence.TscPageRequest;
import com.style24.persistence.domain.BrandGroup;
import com.style24.persistence.domain.Cate1;
import com.style24.persistence.domain.Cate4Srch;
import com.style24.persistence.domain.Contents;
import com.style24.persistence.domain.GnbTab;
import com.style24.persistence.domain.Goods;
import com.style24.persistence.domain.Login;
import com.style24.persistence.domain.Lookbook;
import com.style24.persistence.domain.MainLayout;
import com.style24.persistence.domain.Plan;
import com.style24.persistence.domain.Popup;
import com.style24.persistence.domain.SearchKeyword;
import com.style24.persistence.domain.Social;
import com.style24.persistence.domain.eigene.Eigeneai.Result;
import com.style24.persistence.domain.eigene.Item;
import com.style24.persistence.domain.searchengine.AutoCompleteResponse;
import com.style24.persistence.domain.searchengine.Filter;
import com.style24.persistence.domain.searchengine.GoodsListResponse;
import com.style24.persistence.domain.searchengine.PlanningResponse;
import com.style24.persistence.domain.searchengine.SearchEngine;

import lombok.extern.slf4j.Slf4j;

/**
 * 전시 Controller
 *
 * @author gagamel
 * @since 2020. 12. 29
 */
@Controller
@RequestMapping("/display")
@Slf4j
public class TsfDisplayController extends TsfBaseController {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private TsfDisplayService displayService;

	@Autowired
	private TscEnvsetService envsetService;

	@Autowired
	private TsfGoodsService goodsService;

	@Autowired
	private TscLookbookService coreLookbookService;

	@Autowired
	private TsfPlanningService planningService;

	@Autowired
	private TsfSocialService socialService;

	@Autowired
	private SearchEngineDiquest diquest;

	@Autowired
	private TsfCommonService commonService;

	@Autowired
	private EigeneaiApi eigeneaiApi;

	@Autowired
	private Environment env;

	/**
	 * PC보기. 모바일에서 <PC> 형태로 볼 때
	 * @return
	 * @throws Exception
	 * @since 2021. 5. 18
	 */
	@GetMapping("/view/normal/form")
	public String viewNormal() {
		GagaCookieUtil.setCookie(TsfSession.getHttpServletResponse(), TsfConstants.CK_PREFIX + "_site_preference", "normal", -1);
		return "redirect:/display/mall/main/form";
	}

	/**
	 * 모바일보기. 모바일 디바이스에서 <PC보기> 클릭 후 접근한 담에 다시 <모바일보기> 클릭 시
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 18
	 */
	@GetMapping("/view/mobile/form")
	public String viewMobile() {
		GagaCookieUtil.deleteCookie(TsfSession.getHttpServletResponse(), TsfConstants.CK_PREFIX + "_site_preference");
		return "redirect:/display/mall/main/form";
	}

	/**
	 * 몰 메인
	 * @return
	 * @author gagamel
	 * @since 2021. 2. 3
	 */
	@GetMapping("/mall/main/form")
	public ModelAndView mallMain(Device device, @RequestParam HashMap<String, String> paramMap) {
		ModelAndView mav = new ModelAndView();
		MainLayout mallMainLayout = new MainLayout();
		// 로그인 유무 확인 (로그인이 되어 있지 않으면 regNo 를 0으로 장바구니에 저장한다.)
		Login login = new Login();
		if (TsfSession.isLogin()) {
			login = TsfSession.getInfo();
		} else {
			login.setCustNo(0);
		}

		String mainCateNo = "1700";
		// 몰메인 PC,MOBILE 동일하게 사용으로 인한 주석처리
//		if (device.isMobile() || "Y".equals(paramMap.get("mobileYn"))) {
//			mainCateNo = "1720";
//		} else {
//			mainCateNo = "1700";
//		}

		mallMainLayout.setCateNo(Integer.parseInt(mainCateNo));
		mallMainLayout.setPreview(paramMap.get("preview"));
		Collection<MainLayout> mainLayoutCollection = displayService.getMainLayout(mallMainLayout);

		Collection<MainLayout> mainLayoutList = new ArrayList<MainLayout>();

		for (MainLayout mainLayout : mainLayoutCollection) {
			String contentsLoc = mainLayout.getContentsLoc();
			Contents contents = new Contents();
			log.info("mallMain contentsLoc:::{}", contentsLoc);
			contents.setContentsCnt(mainLayout.getContentsCnt());
			contents.setContentsLoc(contentsLoc);
			contents.setPreview(paramMap.get("preview"));
			contents.setViewDt(paramMap.get("viewDt"));
			contents.setCateNo(Integer.parseInt(mainCateNo));
			if (contentsLoc.equals("SGNB001") || contentsLoc.equals("SGNB002") || contentsLoc.equals("STAB001") || contentsLoc.equals("SMM003") || contentsLoc.equals("SMM004") || contentsLoc.equals("SMM005") || contentsLoc.equals("SMM006")) {
				contents.setMaxRow(1);
			}
			if (contentsLoc.equals("SMM011")) {
				contents.setMaxRow(5);
			}

			Cate4Srch cate4Srch = new Cate4Srch();
			cate4Srch.setContentsLoc(contentsLoc);
			cate4Srch.setCustNo(login.getCustNo());
			cate4Srch = displayService.getCate4srch(cate4Srch);
			mainLayout.setCate4Srch(cate4Srch);

			if ("C".equals(mainLayout.getContentsYn())) {
				if(contentsLoc.equals("SMM007")){
					mainLayout.setContentsList(displayService.getBrandpickTitleBrandList(contents));
				}else{
					mainLayout.setContentsList(displayService.getContentsList(contents));
				}
			} else {
				log.info("nullpoint contentsLoc::::{}", contentsLoc);
				if ("SMM001".equals(contentsLoc)) {
					cate4Srch.setMaxRow(3);
				} else {
					cate4Srch.setMaxRow(20);
				}

				Collection<Goods> goodsList = goodsService.getContentsCategoryGoodsListMain(cate4Srch);
				mainLayout.setGoodsList(goodsList);

				if ("A".equals(mainLayout.getContentsYn())) {
					mainLayout.setContentsList(displayService.getContentsList(contents));
				}
			}

			if (contentsLoc.equals("SMM004")) {
				contents.setPageGb("MALL");
				mainLayout.setBestItemList(displayService.getBestItemForGoodsMain(contents));
			}

			if (contentsLoc.equals("SMM006")) {
				Social social = new Social();
				social.setSiteCd("G000_10");
				social.setFrontGb(TsfSession.getFrontGb());
				social.setMainYn("Y");
				mainLayout.setSocialInfo(socialService.getSocialForGoods(social));
			}

			if (contentsLoc.equals("SMM007")) {
				mainLayout.setBrandPickList(displayService.getContentsForGoodsMain(contents));
			}

			if (contentsLoc.equals("SMM009") || contentsLoc.equals("SMM012")) {
				if (contentsLoc.equals("SMM009")) {
					contents.setMaxRow(5);
				}
				mainLayout.setMdPickList(displayService.getContentsForGoodsMain(contents));
			}

			if (contentsLoc.equals("SMM003") || contentsLoc.equals("SBM007")) {
				if (Integer.parseInt(mainLayout.getContentsCnt()) > 0) {
					mainLayout.setNewItemList(displayService.getContentsForGoodsMain(contents));
				} else {
					mainLayout.setNewItemList(displayService.getMainNewGoodsList(contents));
				}
			}

			mainLayoutList.add(mainLayout);
		}

		mav.addObject((StringUtils.isBlank(paramMap.get("preview"))) ? "" : paramMap.get("preview"));
		mav.addObject((StringUtils.isBlank(paramMap.get("viewDt"))) ? "" : paramMap.get("viewDt"));
		mav.addObject("viewPage", "G037_20");
		//mav.addObject("popupCateNo", "");

		//log.info("mainLayoutList::{}", mainLayoutList);
		mav.addObject("mainLayoutList", mainLayoutList);
		mav.setViewName(super.getDeviceViewName("display/MallMainForm"));

		return mav;
	}

	/**
	 * 몰 메인 테스트 폼
	 * @return
	 * @author jmh
	 * @since 2021. 8. 4
	 */
	@GetMapping("/mall/main/form5")
	public ModelAndView mallMain5(Device device, @RequestParam HashMap<String, String> paramMap) {
		ModelAndView mav = new ModelAndView();
		MainLayout mallMainLayout = new MainLayout();
		// 로그인 유무 확인 (로그인이 되어 있지 않으면 regNo 를 0으로 장바구니에 저장한다.)
		Login login = new Login();
		if (TsfSession.isLogin()) {
			login = TsfSession.getInfo();
		} else {
			login.setCustNo(0);
		}

		String mainCateNo = "1700";
		// 몰메인 PC,MOBILE 동일하게 사용으로 인한 주석처리
//		if (device.isMobile() || "Y".equals(paramMap.get("mobileYn"))) {
//			mainCateNo = "1720";
//		} else {
//			mainCateNo = "1700";
//		}

		mallMainLayout.setCateNo(Integer.parseInt(mainCateNo));
		mallMainLayout.setPreview(paramMap.get("preview"));
		Collection<MainLayout> mainLayoutCollection = displayService.getMainLayout(mallMainLayout);

		Collection<MainLayout> mainLayoutList = new ArrayList<MainLayout>();

		for (MainLayout mainLayout : mainLayoutCollection) {
			String contentsLoc = mainLayout.getContentsLoc();
			Contents contents = new Contents();
			log.info("mallMain contentsLoc:::{}", contentsLoc);
			contents.setContentsCnt(mainLayout.getContentsCnt());
			contents.setContentsLoc(contentsLoc);
			contents.setPreview(paramMap.get("preview"));
			contents.setViewDt(paramMap.get("viewDt"));
			contents.setCateNo(Integer.parseInt(mainCateNo));
			if (contentsLoc.equals("SGNB001") || contentsLoc.equals("SGNB002") || contentsLoc.equals("STAB001") || contentsLoc.equals("SMM003") || contentsLoc.equals("SMM004") || contentsLoc.equals("SMM005") || contentsLoc.equals("SMM006")) {
				contents.setMaxRow(1);
			}
			if (contentsLoc.equals("SMM011")) {
				contents.setMaxRow(5);
			}

			Cate4Srch cate4Srch = new Cate4Srch();
			cate4Srch.setContentsLoc(contentsLoc);
			cate4Srch.setCustNo(login.getCustNo());
			cate4Srch = displayService.getCate4srch(cate4Srch);
			mainLayout.setCate4Srch(cate4Srch);

			if ("C".equals(mainLayout.getContentsYn())) {
				if(contentsLoc.equals("SMM007")){
					mainLayout.setContentsList(displayService.getBrandpickTitleBrandList(contents));
				}else{
					mainLayout.setContentsList(displayService.getContentsList(contents));
				}
			} else {
				log.info("nullpoint contentsLoc::::{}", contentsLoc);
				if ("SMM001".equals(contentsLoc)) {
					cate4Srch.setMaxRow(3);
				} else {
					cate4Srch.setMaxRow(20);
				}

				Collection<Goods> goodsList = goodsService.getContentsCategoryGoodsList(cate4Srch);
				mainLayout.setGoodsList(goodsList);

				if ("A".equals(mainLayout.getContentsYn())) {
					mainLayout.setContentsList(displayService.getContentsList(contents));
				}
			}

			if (contentsLoc.equals("SMM004")) {
				contents.setPageGb("MALL");
				mainLayout.setBestItemList(displayService.getBestItemForGoods(contents));
			}

			if (contentsLoc.equals("SMM006")) {
				Social social = new Social();
				social.setSiteCd("G000_10");
				social.setFrontGb(TsfSession.getFrontGb());
				social.setMainYn("Y");
				mainLayout.setSocialInfo(socialService.getSocialForGoods(social));
			}

			if (contentsLoc.equals("SMM007")) {
				mainLayout.setBrandPickList(displayService.getContentsForGoods(contents));
			}

			if (contentsLoc.equals("SMM009") || contentsLoc.equals("SMM012")) {
				if (contentsLoc.equals("SMM009")) {
					contents.setMaxRow(5);
				}
				mainLayout.setMdPickList(displayService.getContentsForGoods(contents));
			}

			if (contentsLoc.equals("SMM003") || contentsLoc.equals("SBM007")) {
				if (Integer.parseInt(mainLayout.getContentsCnt()) > 0) {
					mainLayout.setNewItemList(displayService.getContentsForGoods(contents));
				} else {
					mainLayout.setNewItemList(displayService.getMainNewGoodsList(contents));
				}
			}

			mainLayoutList.add(mainLayout);
		}

		mav.addObject((StringUtils.isBlank(paramMap.get("preview"))) ? "" : paramMap.get("preview"));
		mav.addObject((StringUtils.isBlank(paramMap.get("viewDt"))) ? "" : paramMap.get("viewDt"));
		mav.addObject("viewPage", "G037_20");
		//mav.addObject("popupCateNo", "");

		//log.info("mainLayoutList::{}", mainLayoutList);
		mav.addObject("mainLayoutList", mainLayoutList);
		mav.setViewName(super.getDeviceViewName("display/MallMainForm"));

		return mav;
	}


	/**
	 * GNB탭 > 브랜드그룹 목록
	 * @param contents - 컨텐츠 정보
	 * @return
	 * @throws Exception
	 * @author gagamel
	 * @since 2021. 3. 11
	 */
	@GetMapping("/gnb/brand/group/list")
	@ResponseBody
	public Collection<BrandGroup> getGnbBrandGroupList(Contents contents) {
		contents.setContentsLoc("STAB001");
		return displayService.getGnbBrandGroupList(contents);
	}

	/**
	 * GNB탭 > TOP BANNER 목록
	 * @param contents - 컨텐츠 정보
	 * @return
	 * @throws Exception
	 * @author bin2107
	 * @since 2021. 4. 11
	 */
	@GetMapping("/gnb/topbanner/list")
	@ResponseBody
	public Collection<Contents> getGnbTopBannerList(Contents contents, @RequestParam(value = "contentsLoc") String contentsLoc) {
		contents.setContentsLoc(contentsLoc);
		contents.setMaxRow(1);
		Collection<Contents> bannerList = displayService.getContentsList(contents);

//		for(Contents tempContents : bannerList){
//			tempContents.setHtml(GagaStringUtil.replace(GagaStringUtil.replace(tempContents.getHtml(), "&lt;", "<"), "&gt;", ">"));
//		}

		log.info("getGnbTopBannerList>>>>{}", bannerList);

		return bannerList;
	}

//	/**
//	 * 전체 카테고리 목록
//	 * @return
//	 * @author gagamel
//	 * @since 2021. 3. 15
//	 */
//	@GetMapping("/all/cate/list")
//	@ResponseBody
//	public Collection<Cate1> getAllCategoryList() {
//		return displayService.getAllCategoryList(TsfConstants.CateGb.BYITEM.value());
//	}

	/**
	 * GNB 탭 목록
	 * @param gnbTab - GNB탭 정보
	 * @return
	 * @throws Exception
	 * @author gagamel
	 * @since 2021. 3. 11
	 */
	@GetMapping("/gnb/tab/list")
	@ResponseBody
	public Collection<GnbTab> getGnbTabList(GnbTab gnbTab) {
		gnbTab.setGtabGb("C"); // 공통GNB
		return displayService.getGnbTabList(gnbTab);
	}

	/**
	 * 브랜드 메인
	 * @param device - 디바이스 정보
	 * @param paramMap - 파라미터 정보
	 * @param response - HttpServletResponse
	 * @return
	 * @throws IOException
	 * @author gagamel
	 * @since 2021. 3. 16
	 */
	@GetMapping("/brand/main/form")
	public ModelAndView brandMain(Device device, @RequestParam HashMap<String, String> paramMap, HttpServletResponse response) throws IOException {
		log.info("{}", paramMap);

		ModelAndView mav = new ModelAndView();

		if (StringUtils.isBlank(paramMap.get("brandGroupNo"))) {
			response.sendRedirect("/");
		}

		// 브랜드그룹 정보
		mav.addObject("brandGroupInfo", displayService.getGnbBrandGroup(Integer.parseInt(paramMap.get("brandGroupNo"))));

		// 브랜드 레이아웃
		MainLayout mainLayout = new MainLayout();
		String mainCateNo = "1711";
		// PC,MOBILE 동일 사용으로 인해 주석처리
//		if (device.isMobile() || "Y".equals(paramMap.get("mobileYn"))) {
//			mainCateNo = "1721";
//		} else {
//			mainCateNo = "1711";
//		}
		mainLayout.setCateNo(Integer.parseInt(mainCateNo));
		mainLayout.setBrandGroupNo(Integer.parseInt(paramMap.get("brandGroupNo")));
		Collection<MainLayout> mainLayoutCollection = displayService.getMainLayout(mainLayout);
		Collection<MainLayout> brandMainLayoutList = new ArrayList<MainLayout>();

		for (MainLayout brandMain : mainLayoutCollection) {
			String contentsLoc = brandMain.getContentsLoc();
			Contents contents = new Contents();
			contents.setContentsLoc(contentsLoc);
			contents.setPreview(paramMap.get("preview"));
			contents.setViewDt(paramMap.get("viewDt"));
			contents.setCateNo(Integer.parseInt(mainCateNo));
			contents.setBrandGroupNo((brandMain.getBrandGroupNo()).toString());
			if (contentsLoc.equals("SBM005") || contentsLoc.equals("SBM007") || contentsLoc.equals("SBM008") || contentsLoc.equals("SBM009") || contentsLoc.equals("SBM010") || contentsLoc.equals("SBM011") || contentsLoc.equals("SBM013") || contentsLoc.equals("SBM017") || contentsLoc.equals("SBM018") || contentsLoc.equals("SBM019")) {
				contents.setMaxRow(1);
			}

			Cate4Srch cate4Srch = new Cate4Srch();
			cate4Srch.setContentsLoc(contentsLoc);
			cate4Srch = displayService.getCate4srch(cate4Srch);
			brandMain.setCate4Srch(cate4Srch);

			if ("C".equals(brandMain.getContentsYn())) {
				if (contentsLoc.equals("SBM017") || contentsLoc.equals("SBM018") || contentsLoc.equals("SBM019")) {
					cate4Srch.setBrandGroupNo(brandMain.getBrandGroupNo());
					cate4Srch.setMaxRow(20);
					Collection<Goods> goodsList = goodsService.getContentsCategoryGoodsList(cate4Srch);
					brandMain.setGoodsList(goodsList);
				}
				brandMain.setContentsList(displayService.getContentsList(contents));
			} else if ("E".equals(brandMain.getContentsYn())) {
				Cate4Srch cate4Srch2 = new Cate4Srch();
				cate4Srch2.setBrandGroupNo(brandMain.getBrandGroupNo());
				cate4Srch2.setContentsLoc(contentsLoc);
				if (contentsLoc.equals("SBM013") || contentsLoc.equals("SBMM013")) {
					cate4Srch2.setMaxRow(50);
				} else {
					cate4Srch2.setMaxRow(20);
				}
				Collection<Goods> goodsList = goodsService.getContentsCategoryGoodsList(cate4Srch2);
				brandMain.setGoodsList(goodsList);
			} else {
				cate4Srch.setBrandGroupNo(brandMain.getBrandGroupNo());
				if (cate4Srch.getContentsLoc().equals("SBM008")) {
					cate4Srch.setMaxRow(10);
				} else if (cate4Srch.getContentsLoc().equals("SBM013") || cate4Srch.getContentsLoc().equals("SBMM013")) {
					cate4Srch.setMaxRow(50);
				} else {	// SBM007, SBM009
					cate4Srch.setMaxRow(20);
				}
				Collection<Goods> goodsList = goodsService.getContentsCategoryGoodsList(cate4Srch);
				brandMain.setGoodsList(goodsList);

				if ("A".equals(brandMain.getContentsYn())) {
					brandMain.setContentsList(displayService.getContentsList(contents));
				}
			}

			// 기획전 컨텐츠일때
			if ("SBM011".equals(brandMain.getContentsLoc()) || "SBMM011".equals(brandMain.getContentsLoc())) {
				Plan plan = new Plan();
				plan.setBrandGroupNo(Integer.parseInt(paramMap.get("brandGroupNo")));
				if ("SBM011".equals(brandMain.getContentsLoc())) {
					plan.setMaxRow(6);
				} else {
					plan.setMaxRow(2);
				}
				plan.setFrontGb(TsfSession.getFrontGb());
				plan.setSiteCd(TscConstants.Site.STYLE24.value());
				brandMain.setPlanningList(planningService.getPlanningMainList(plan));
			}

			// 룩북일때
			if ("SBM010".equals(brandMain.getContentsLoc()) || "SBMM010".equals(brandMain.getContentsLoc())) {
				Lookbook lookbook = new Lookbook();
				lookbook.setBrandCd(paramMap.get("brandGroupNo"));
				lookbook.setMainDispYn("Y");

				brandMain.setLookbookList(coreLookbookService.getLookbookListForGoods(lookbook));
			}
			brandMainLayoutList.add(brandMain);
		}

		mav.addObject("preview", paramMap.get("preview"));
		mav.addObject("viewDt", paramMap.get("viewDt"));
		mav.addObject("viewPage", "G037_31");
		mav.addObject("popupBrandCd", paramMap.get("brandGroupNo"));
		mav.addObject("brandGroupNo", paramMap.get("brandGroupNo"));

		//log.info("brandMainLayoutList::{}", brandMainLayoutList);
		mav.addObject("brandMainLayoutList", brandMainLayoutList);
		mav.setViewName(super.getDeviceViewName("display/BrandMainForm"));

		return mav;
	}

	/**
	 * 브랜드 GNB 탭 목록
	 * @param gnbTab - GNB탭 정보
	 * @return
	 * @throws Exception
	 * @author gagamel
	 * @since 2021. 3. 16
	 */
	@GetMapping("/brand/gnb/tab/list")
	@ResponseBody
	public Collection<GnbTab> getBrandGnbTabList(GnbTab gnbTab) {
		gnbTab.setGtabGb("B"); // 브랜드GNB
		return displayService.getGnbTabList(gnbTab);
	}

	/**
	 * 카테고리 메인
	 * @param cate - 카테고리 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 3. 25
	 */
	@GetMapping("/category/main/form")
	public ModelAndView categoryMain(Cate4Srch cate) {
		ModelAndView mav = new ModelAndView(super.getDeviceViewName("display/CategoryMainForm"));

		MainLayout mainLayout = new MainLayout();
		mainLayout.setCateNo(cate.getCate1No());
		Collection<MainLayout> mainLayoutCollection = displayService.getMainLayout(mainLayout);
		Collection<MainLayout> cateMainLayoutList = new ArrayList<MainLayout>();

		for (MainLayout cateMain : mainLayoutCollection) {
			if ("SCM001".equals(cateMain.getContentsLoc())) {
				// 기획전
				Contents contents = new Contents();
				contents.setContentsLoc("SCM001");
				contents.setCateNo(cate.getCate1No());
				mav.addObject("planningList", displayService.getGnbTabBannerlist(contents));
			} else if ("SCM002".equals(cateMain.getContentsLoc())) {
				// 신상품
				Contents contents = new Contents();
				contents.setContentsLoc("SCM002");
				contents.setCateNo(cate.getCate1No());
				contents.setMaxRow(1);
				Collection<Contents> conList = displayService.getContentsList(contents);
				mav.addObject("newGoodsList", null);
				if (Integer.parseInt(cateMain.getContentsCnt()) > 0) {
					for (Contents contentsData : conList) {
						cate.setContentsLoc("SCM002");
						cate.setMaxRow(20);
						mav.addObject("newGoodsList", goodsService.getContentsCategoryGoodsList(cate));
					}
				} else {
					Collection<Contents> contentsList = displayService.getBestItemCategoryList(contents);
					Cate4Srch tempCate = new Cate4Srch();
					for (Contents data : contentsList) {
						tempCate.setContentsLoc(data.getContentsLoc());
						tempCate.setMaxRow(20);
						tempCate.setCustNo(TsfSession.isLogin() ? TsfSession.getInfo().getCustNo() : 0);
						tempCate.setSiteCd(data.getSiteCd());
						tempCate.setCateGb(data.getCateGb());
						tempCate.setCate1No(data.getCateNo());
						
						// 2021.09.29 신상품조회시 frontGb, custGb 누락 추가
						tempCate.setFrontGb(TsfSession.getFrontGb());
						tempCate.setCustGb(TsfSession.getCustGb());
					}
					// 
					mav.addObject("newGoodsList", displayService.getContentsCategoryNewGoodsList(tempCate));
				}
			} else if ("SCM003".equals(cateMain.getContentsLoc())) {
				// 베스트품
				Contents contents = new Contents();
				contents.setContentsLoc("SCM003");
				contents.setCateNo(cate.getCate1No());
				contents.setMaxRow(1);
				Collection<Contents> conList = displayService.getContentsList(contents);
				mav.addObject("bestGoodsList", null);

				Collection<Goods> bestList = new ArrayList<>();
				for (Contents contentsData : conList) {
					cate.setContentsLoc("SCM003");
					cate.setMaxRow(Integer.parseInt(contentsData.getStrVar1()));
					cate.setCateNo(contents.getCateNo());
					bestList = goodsService.getContentsCategoryGoodsList(cate);
				}
				if(cate.getMaxRow()<1){
					cate.setMaxRow(20);
				}

				mav.addObject("bestGoodsList", bestList);
			}

			cateMainLayoutList.add(cateMain);
		}

		mav.addObject("cateMainLayoutList", cateMainLayoutList);
		mav.addObject("preview", cate.getPreview());
		mav.addObject("viewDt", cate.getViewDt());
		mav.addObject("viewPage", "G037_30");
		mav.addObject("popupCateNo", cate.getCate1No());

		mav.addObject("params", cate);

		return mav;
	}

	/**
	 * 룩북 메인
	 * @param lookbook
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 30
	 */
	@GetMapping("/lookbook/main/form")
	public ModelAndView lookbookMain(Lookbook lookbook) {
		ModelAndView mav = new ModelAndView();
		// 브랜드그룹 정보 : 브랜드메인 링크에 설정된 기획전으로 들어올때 GNB 변경때문에 사용
		if (lookbook.getBrandGroupNo() != null && !lookbook.getBrandGroupNo().equals("")) {
			lookbook.setBrandCd(lookbook.getBrandGroupNo().toString());
			lookbook.setLookbookGb("BL");
			mav.addObject("brandGroupInfo", displayService.getGnbBrandGroup(lookbook.getBrandGroupNo()));
			mav.setViewName(super.getDeviceViewName("display/BrandLookbookMainForm"));
		} else {
			lookbook.setLookbookGb("L");
			mav.addObject("brandGroupInfo", null);
			mav.setViewName(super.getDeviceViewName("display/LookbookMainForm"));
		}

		mav.addObject("lbInfo", lookbook);
		return mav;
	}

	/**
	 * 룩북 리스트
	 * @param lookbook
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 30
	 */
//	@GetMapping("/lookbook/main/list")
//	@ResponseBody
//	public Collection<Lookbook> lookbooklist(Lookbook lookbook) {
//		lookbook.setFrontGb(TsfSession.getFrontGb());
//		lookbook.setFrontYn("Y");
//		return coreLookbookService.getLookbookList(lookbook);
//	}
	@PostMapping("/lookbook/main/list")
	@ResponseBody
	public GagaMap lookbooklist(@RequestBody Lookbook params) {
		GagaMap result = new GagaMap();
		TscPageRequest pageable = new TscPageRequest((params.getPageNo() > 0 ? params.getPageNo() - 1 : 0), params.getPageSize(), params.getPageUnit());
		pageable.setTotalCount(coreLookbookService.getLookbookListCount(params));

		params.setPageable(pageable);
		result.set("paging", pageable);
		result.set("dataList", coreLookbookService.getLookbookList(params));
		return result;
	}

	@GetMapping("/lookbook/main/brand/list")
	@ResponseBody
	public Collection<Lookbook> lookbookBrandList(Lookbook lookbook) {
		return coreLookbookService.lookbookBrandList(lookbook);
	}

	/**
	 * 룩북 상세
	 * @param lookbook
	 * @return
	 * @author bin2107
	 * @since 2021. 4. 6
	 */
	@GetMapping("/lookbook/detail/form")
	public ModelAndView lookbookDetail(Lookbook lookbook) {
		ModelAndView mav = new ModelAndView();

		lookbook.setFrontGb(TsfSession.getFrontGb());
		Collection<Lookbook> lookbookList = coreLookbookService.getLookbookListForGoods(lookbook);
		String brandNm = "";
		String lookbookTitle = "";
		if (lookbookList != null) {
			for (Lookbook lbInfo : lookbookList) {
				brandNm = lbInfo.getBrandNm();
				lookbookTitle = lbInfo.getTitle();
			}
			lookbook.setBrandNm(brandNm);
			lookbook.setTitle(lookbookTitle);
		}

		mav.addObject("lookbookDetailList", lookbookList);
		mav.addObject("otherLookbookList", coreLookbookService.getOtherLookbookList(lookbook));
		mav.addObject("lookbookInfo", lookbook);
		// 브랜드그룹 정보 : 브랜드메인 링크에 설정된 기획전으로 들어올때 GNB 변경때문에 사용
		mav.addObject("brandGroupInfo", displayService.getGnbBrandGroup(lookbook.getBrandGroupNo()));

		mav.setViewName(super.getDeviceViewName("display/LookbookDetailForm"));
		return mav;
	}

	/**
	 * 팝업 목록
	 *
	 * @return
	 * @throws Exception
	 * @author eskim
	 * @since 2021. 3. 30
	 */
	@GetMapping("/popup/list")
	@ResponseBody
	public GagaMap getPopupList(@RequestParam HashMap<String, String> paramMap) {

		GagaMap result = new GagaMap();

		Popup popup = new Popup();
		popup.setFrontGb(TsfSession.getFrontGb());
		popup.setViewPage(paramMap.get("viewPage"));
		if (paramMap.get("cateNo") != null && paramMap.get("cateNo") != "") {
			popup.setCateNo(Integer.parseInt(paramMap.get("cateNo")));
		}
		popup.setBrandCd(paramMap.get("brandCd"));
		popup.setPlanSq((StringUtils.isBlank(paramMap.get("planSq").toString()) ? 0 : Integer.parseInt(paramMap.get("planSq"))));
		popup.setPreview(paramMap.get("preview"));
		popup.setViewDt(paramMap.get("viewDt"));

		//result.set("dataList", displayService.getPopupList(popup));

		return displayService.getPopupList(popup);
	}

	/**
	 * 카테고리 상품 목록
	 * @param params - 검색엔진 정보
	 * @return
	 * @author bin2107
	 * @since 2021. 4. 2
	 */
	@GetMapping("/category/goods/list/form")
	public ModelAndView categoryGoodsListForm(SearchEngine params) {
		ModelAndView mav = new ModelAndView();
		params.setBrandGroupNo(params.getBrandGroupNo() == null ? 0 : params.getBrandGroupNo());
		params.setFrontGb(TsfSession.getFrontGb());
		params.setSiteCd(TscConstants.Site.STYLE24.value());

		// 브랜드그룹 정보 : 브랜드메인 링크에 설정된 기획전으로 들어올때 GNB 변경때문에 사용
		if (params.getBrandGroupNo() != null && params.getBrandGroupNo() > 0) {
			mav.addObject("brandGroupInfo", displayService.getGnbBrandGroup(params.getBrandGroupNo()));
		}
		mav.addObject("cateInfo", params);

		Collection<Filter> filterList = new ArrayList<Filter>();

		// 검색엔진 연동 여부
//		String syncYn = commonService.getSearchEngineSyncYn();
//		if (syncYn.equals("Y")) { // 검색엔진을 통한 상품리스트 조회
		mav.setViewName(super.getDeviceViewName("display/CategoryGoodsListForm"));
		// 카테고리 목록
		mav.addObject("allCateList", displayService.getAllCategoryList("G032_101"));
		// 상품검색키워드 카테고리 목록
		SearchEngine cate1 = new SearchEngine();
		cate1.setBrandGroupNo(params.getBrandGroupNo() == null ? 0 : params.getBrandGroupNo());
		cate1.setFrontGb(TsfSession.getFrontGb());
		cate1.setSiteCd(TscConstants.Site.STYLE24.value());
		cate1.setCateGb("G032_101");
		cate1.setCate1No(params.getCate1No());
		mav.addObject("cateList", diquest.getCategoryList(cate1));
		if (params.getBrandGroupNo() != null && params.getBrandGroupNo() > 0) {
			cate1.setCate1No(null);
			mav.addObject("brandCateList", diquest.getCategoryList(cate1));
		}
		// 상품리스트 카테고리별 필터 목록
		filterList = diquest.getFilterList(params);
//		}else{
//			// 카테고리 목록
//			mav.addObject("cateList", displayService.getAllCategoryList(params.getCateGb()));
//			mav.setViewName(super.getDeviceViewName("display/CategoryGoodsListForm2"));
//			filterList = displayService.getGoodsListCategoryFilterList(params);
//		}

		// 필터 설정
		mav.addObject("filterBrandList", displayService.getCategoryFilterList(filterList, "BRAND"));
		mav.addObject("filterSizeList", displayService.getCategoryFilterList(filterList, "SIZE"));
		mav.addObject("filterPriceList", displayService.getCategoryFilterList(filterList, "PRICE"));
		mav.addObject("filterAgeList", displayService.getCategoryFilterList(filterList, "AGE"));
		mav.addObject("filterSeasonList", displayService.getCategoryFilterList(filterList, "SEASON"));
		mav.addObject("filterColorList", displayService.getCategoryFilterList(filterList, "COLOR"));
		mav.addObject("filterBenefitList", displayService.getCategoryFilterList(filterList, "BENEFIT"));
		if (params.getFormalGb() != null) {
			params.setFormalGb(params.getFormalGb().toUpperCase());
		}
		mav.addObject("params", params);

		log.info("categoryGoodsListForm params:::::{}", params);
		log.info("filterPriceList:::{}", displayService.getCategoryFilterList(filterList, "PRICE"));

		return mav;
	}

	/**
	 * 카테고리 상품 리스트 조회
	 * @param params - 검색엔진 정보
	 * @return
	 * @author bin2107
	 * @since 2021. 4. 7
	 */
	@PostMapping("/category/goods/list")
	@ResponseBody
	public GagaMap getGoodsList(@RequestBody SearchEngine params) {
		GagaMap result = new GagaMap();
		log.info("getGoodsList's parameter::: {}", params);
		TscPageRequest pageable = new TscPageRequest((params.getPageNo() > 0 ? params.getPageNo() - 1 : 0), params.getPageSize(), params.getPageUnit());

		if (TsfSession.isLogin()) {
			params.setCustNo(TsfSession.getInfo().getCustNo());
		}

		params.setSiteCd(TscConstants.Site.STYLE24.value());
		params.setFrontGb(TsfSession.getFrontGb());
		params.setCustGb(TsfSession.getCustGb());

		if (params.getBrandGroupNo() == null) {
			params.setBrandGroupNo(0);
		}

		Collection<SearchEngine> dataList = new ArrayList<SearchEngine>();

		log.info("params.getSortingType() ::: {}", params.getSortingType());

//		GoodsListResponse response = diquest.getGoodsList(params);
//		pageable.setTotalCount(response.getTotalCount());
//		dataList = response.getResponse();
//		result.set("paging", pageable);
//		result.set("dataList", dataList);

		String profiles = env.getProperty("spring.profiles.active").toLowerCase();
		GoodsListResponse response = null;
		if ("style".equals(profiles) || "stage".equals(profiles) || "locp".equals(profiles)) { // 검색엔진을 통한 상품리스트 조회
			response = diquest.getGoodsList(params);
			pageable.setTotalCount(response.getTotalCount());
			dataList = response.getResponse();
		} else { // DB를 통한 상품리스트 조회
			pageable.setTotalCount(goodsService.getSearchGoodsCount(params));
			params.setPageable(pageable);
			dataList = goodsService.getSearchGoodsList(params);
		}
		result.set("paging", pageable);
		result.set("dataList", dataList);

		log.info("pageable>>>>{}", pageable);
		log.info("dataList>>>>{}", dataList);

		return result;
	}

	/**
	 * 전체 브랜드
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 4. 12
	 */
	@GetMapping("/all/brand/form")
	public ModelAndView allBrandMain(BrandGroup brandGroup) {
		ModelAndView mav = new ModelAndView(super.getDeviceViewName("display/AllBrandForm"));

		brandGroup.setSelfYn("Y");
		mav.addObject("mainBrandList", displayService.getBrandImgList(brandGroup));

		return mav;
	}

	/**
	 * 전체 브랜드 리스트
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 4. 12
	 */
	@GetMapping("/all/brand/list")
	@ResponseBody
	public Collection<BrandGroup> getAllBrandList(BrandGroup brandGroup) {
		return displayService.getAllBrandList(brandGroup);
	}

	/**
	 * 브랜드 카테고리 목록
	 * @param brandGroupNo - 브랜드그룹번호
	 * @return
	 * @author gagamel
	 * @since 2021. 4. 12
	 */
	@GetMapping("/brand/cate/list")
	@ResponseBody
	public Collection<Cate1> getBrandCategoryList(Integer brandGroupNo) {
		return displayService.getBrandCategoryList(brandGroupNo);
	}

	/**
	 * 아울렛 카테고리 목록
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 5. 3
	 */
	@GetMapping("/category/reload/list")
	@ResponseBody
	public Collection<Cate1> getCategoryReloadList(String cateGb) {
		return displayService.getCategoryReloadList(cateGb);
	}

	/**
	 * 아울렛 카테고리 목록
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 5. 3
	 */
	@GetMapping("/outlet/cate/list")
	@ResponseBody
	public Collection<Cate1> getOutletCategoryList(String formalGb) {
		return displayService.getOutletCategoryList(formalGb);
	}

	/**
	 * 베스트 메인
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 4. 13
	 */
	@GetMapping("/best/main/form")
	public ModelAndView bestMain(Contents contents) {
		ModelAndView mav = new ModelAndView(super.getDeviceViewName("display/BestMainForm"));

		contents.setContentsLoc("SCM003");
		// 실시간 상품
		mav.addObject("viewBestGoodsList", eigeneaiApi.getRealtimeViewBestGoodsList(20, String.valueOf(contents.getCateNo())));
		// 카테고리 리스트
		mav.addObject("bestCateList", displayService.getBestItemCategoryList(contents));

		log.info("bestMain mav::::{}",mav);

		return mav;
	}

	/**
	 * 베스트 메인 상품 리스트 조회
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 4. 13
	 */
	@PostMapping("/best/main/goods/list")
	@ResponseBody
	public GagaMap getBestMainGoodsList(@RequestBody Contents contents) {
		GagaMap result = new GagaMap();
		TscPageRequest pageable = new TscPageRequest((contents.getPageNo() > 0 ? contents.getPageNo() - 1 : 0), contents.getPageSize(), contents.getPageUnit());

		contents.setContentsLoc("SCM003");
		contents.setPageGb("BEST");

		Collection<Goods> bestGoodsList = displayService.getBestItemCategoryGoodsList(contents);
		result.set("dataList", bestGoodsList);
//		int totalCnt = displayService.getContentsCategoryGoodsCount(contents);
		int totalCnt = bestGoodsList.size();
		pageable.setTotalCount(totalCnt);
		contents.setPageable(pageable);

		result.set("paging", contents);
		result.set("totalCnt", totalCnt);
		result.set("endRow", pageable.getEndRow());
		return result;
	}

	/**
	 * GNB TAB 기획전배너 리스트
	 * @param Contents
	 * @return
	 * @author bin2107
	 * @since 2021. 4. 14
	 */
	@GetMapping("/gnb/tab/banner/list")
	@ResponseBody
	public Collection<Contents> getGnbTabBannerlist(Contents contents) {
//		contents.setContentsLoc("STAB003");
		if (contents.getCateNo().equals(3000)) {
			contents.setContentsLoc("SOM005");
		} else {
			contents.setContentsLoc("SCM005");
		}
		contents.setMaxRow(2);

		return displayService.getGnbTabBannerlist(contents);
	}

	/**
	 * 브랜드 GNB 탭 추천상풍 목록
	 * @param
	 * @return
	 * @throws Exception
	 * @author bin2107
	 * @since 2021. 4. 15
	 */
	@GetMapping("/brand/gnb/tab/recommend/goods/list")
	@ResponseBody
	public Collection<Goods> getBrandGnbTabRecommendGoodsList(Cate4Srch cate4Srch) {
		Collection<Goods> goodsList = goodsService.getContentsCategoryGoodsList(cate4Srch);
		return goodsList;
	}

	/**
	 * 아울렛 메인
	 * @param cate - 카테고리 정보
	 * @return
	 * @author bin2107
	 * @since 2021. 4. 20
	 */
	@GetMapping("/outlet/main/form")
	public ModelAndView outletMain(Cate4Srch cate) {
		cate.setCate1No(1713);
		log.info("{}", cate);

		ModelAndView mav = new ModelAndView(super.getDeviceViewName("display/OutletMainForm"));

		MainLayout mainLayout = new MainLayout();
		mainLayout.setCateNo(cate.getCate1No());
		Collection<MainLayout> mainLayoutCollection = displayService.getMainLayout(mainLayout);
		Collection<MainLayout> outletMainLayoutList = new ArrayList<MainLayout>();

		for (MainLayout cateMain : mainLayoutCollection) {
			if ("SOM001".equals(cateMain.getContentsLoc())) {
				// 기획전
				Contents contents = new Contents();
				contents.setContentsLoc("SOM001");
				contents.setCateNo(cate.getCate1No());
				mav.addObject("planningList", displayService.getContentsList(contents));
			} else if ("SOM002".equals(cateMain.getContentsLoc())) {
				// md추천
				cate.setContentsLoc("SOM002");
				cate.setMaxRow(20);
				cate.setCate1No(3000);
				mav.addObject("mdPickGoodsList", goodsService.getContentsCategoryGoodsList(cate));
			} else if ("SOM003".equals(cateMain.getContentsLoc())) {
				// 베스트품
				Contents contents = new Contents();
				contents.setContentsLoc(cateMain.getContentsLoc());
				contents.setMaxRow(1);
				cateMain.setContentsList(displayService.getContentsList(contents));
				for(Contents tempContent: cateMain.getContentsList()){
					cate.setMaxRow(Integer.parseInt(tempContent.getStrVar1()));
				}
				if(cate.getMaxRow()<1){
					cate.setMaxRow(20);
				}
				cate.setContentsLoc("SOM003");
				cate.setCate1No(3000);
				mav.addObject("bestGoodsList", goodsService.getContentsCategoryGoodsList(cate));
			}

			outletMainLayoutList.add(cateMain);
		}

		mav.addObject("outletMainLayoutList", outletMainLayoutList);
		mav.addObject("preview", cate.getPreview());
		mav.addObject("viewDt", cate.getViewDt());
		mav.addObject("viewPage", "G037_32");
		//mav.addObject("popupCateNo", cate.getCate1No());

		mav.addObject("params", cate);

		return mav;
	}

	/**
	 * 검색상품 목록 화면
	 * @param keyword - 검색키워드
	 * @param brandGroupNo - 브랜드그룹번호
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 6
	 */
	@GetMapping("/search/goods/list/form")
	public ModelAndView searchGoodsListForm(@RequestParam(value = "keyword") String keyword, @RequestParam(value = "brandGroupNo", required = false) Integer brandGroupNo) {
		SearchEngine params = new SearchEngine();
		params.setKeyword(keyword);
		params.setBrandGroupNo(brandGroupNo == null ? 0 : brandGroupNo);
		params.setFrontGb(TsfSession.getFrontGb());

		ModelAndView mav = new ModelAndView(super.getDeviceViewName("display/SearchGoodsListForm"));

//		mav.addObject("cateInfo", params);

		Collection<Filter> filterList = new ArrayList<Filter>();

		// 카테고리 목록
		mav.addObject("allCateList", displayService.getAllCategoryList("G032_101"));

		// 검색엔진 연동 여부
		String syncYn = commonService.getSearchEngineSyncYn();
		if (syncYn.equals("Y")) { // 검색엔진을 통한 상품리스트 조회
			// 상품검색키워드 카테고리 목록
			mav.addObject("cateList", diquest.getCategoryList(params));

			// 상품리스트 카테고리별 필터 목록
			filterList = diquest.getFilterList(params);
		} else { // DB를 통한 상품리스트 조회
			// 상품검색키워드 카테고리 목록
			mav.addObject("cateList", displayService.getKeywordCategoryList(params.getKeyword()));

			// 상품리스트 카테고리별 필터 목록
			filterList = displayService.getSearchGoodsListCategoryFilterList(params);
		}

		// 필터 설정
		mav.addObject("filterBrandList", displayService.getCategoryFilterList(filterList, "BRAND"));
		mav.addObject("filterSizeList", displayService.getCategoryFilterList(filterList, "SIZE"));
		mav.addObject("filterPriceList", displayService.getCategoryFilterList(filterList, "PRICE"));
		mav.addObject("filterAgeList", displayService.getCategoryFilterList(filterList, "AGE"));
		mav.addObject("filterSeasonList", displayService.getCategoryFilterList(filterList, "SEASON"));
		mav.addObject("filterColorList", displayService.getCategoryFilterList(filterList, "COLOR"));
		mav.addObject("filterBenefitList", displayService.getCategoryFilterList(filterList, "BENEFIT"));
		mav.addObject("params", params);

		// 광고 배너 조회
		Contents adContents = new Contents();
		adContents.setContentsLoc("SAD001");
		adContents.setMaxRow(1);
		mav.addObject("adBannerList", displayService.getContentsList(adContents));

		log.info("filterPriceList:::{}", displayService.getCategoryFilterList(filterList, "PRICE"));

		return mav;
	}

	/**
	 * 검색상품 리스트 조회
	 * @param params - 검색엔진 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 6
	 */
	@PostMapping("/search/goods/list")
	@ResponseBody
	public GagaMap getSearchGoodsList(@RequestBody SearchEngine params) {
		GagaMap result = new GagaMap();

		TscPageRequest pageable = new TscPageRequest((params.getPageNo() > 0 ? params.getPageNo() - 1 : 0), params.getPageSize(), params.getPageUnit());

		if (TsfSession.isLogin()) {
			params.setCustNo(TsfSession.getInfo().getCustNo());
		}

		params.setFrontGb(TsfSession.getFrontGb());
		params.setCustGb(TsfSession.getCustGb());

		Collection<SearchEngine> dataList = new ArrayList<SearchEngine>();
		Collection<GoodsListResponse.Recommend> recommendList = new ArrayList<GoodsListResponse.Recommend>();
		log.info("getSearchGoodsList params::{}", params);
		// 검색엔진 연동 여부
//		String syncYn = commonService.getSearchEngineSyncYn();
		String profiles = env.getProperty("spring.profiles.active").toLowerCase();
		GoodsListResponse response = null;
		if ("style".equals(profiles) || "stage".equals(profiles) || "locp".equals(profiles)) { // 검색엔진을 통한 상품리스트 조회
			response = diquest.getGoodsList(params);
			pageable.setTotalCount(response.getTotalCount());
			dataList = response.getResponse();
			recommendList = response.getRecommend();
		} else { // DB를 통한 상품리스트 조회
			pageable.setTotalCount(goodsService.getSearchGoodsCount(params));
			params.setPageable(pageable);
			dataList = goodsService.getSearchGoodsList(params);
		}

		result.set("paging", pageable);
		result.set("dataList", dataList);
		result.set("recommendList", recommendList);

		return result;
	}

	/**
	 * 검색상품 리스트 수량 조회
	 * 검색팝업창에서 추천솔루선 리턴이 0일 때, 검색엔진 결과가 있는지 확인용
	 * @param params - 검색엔진 정보
	 * @return
	 * @author jmh
	 * @since 2021. 8. 29
	 */
	@PostMapping("/search/goods/list_cnt")
	@ResponseBody
	public GagaMap getSearchGoodsListCnt(@RequestBody SearchEngine params) {
		GagaMap result = new GagaMap();

		if (TsfSession.isLogin()) {
			params.setCustNo(TsfSession.getInfo().getCustNo());
		}

		params.setFrontGb(TsfSession.getFrontGb());
		params.setCustGb(TsfSession.getCustGb());
		log.info("getSearchGoodsList params::{}", params);

		// 검색엔진을 통한 상품리스트 조회
		GoodsListResponse response = diquest.getGoodsList(params);

		result.set("response_cnt", response.getTotalCount());

		return result;
	}

	/**
	 * 검색기획전 리스트 조회
	 * @param params - 검색엔진 정보
	 * @return
	 * @author bin2107
	 * @since 2021. 6. 14
	 */
	@PostMapping("/search/planning/list")
	@ResponseBody
	public GagaMap getSearchPlanningList(@RequestBody SearchEngine params) {
		GagaMap result = new GagaMap();

		TscPageRequest pageable = new TscPageRequest((params.getPageNo() > 0 ? params.getPageNo() - 1 : 0), params.getPageSize(), params.getPageUnit());
		if (TsfSession.isLogin()) {
			params.setCustNo(TsfSession.getInfo().getCustNo());
		}

		params.setFrontGb(TsfSession.getFrontGb());
		params.setCustGb(TsfSession.getCustGb());

		Collection<SearchEngine> planList = new ArrayList<SearchEngine>();

		PlanningResponse responsePlan = diquest.getPlanningList(params.getKeyword(), params.getPageNo(), params.getPageSize());
		pageable.setTotalCount(responsePlan.getTotalSize());
		planList = responsePlan.getResponse();

		result.set("paging", pageable);
		result.set("planList", planList);

		return result;
	}

	/**
	 * 검색이벤트 리스트 조회
	 * @param params - 검색엔진 정보
	 * @return
	 * @author bin2107
	 * @since 2021. 6. 14
	 */
	@PostMapping("/search/event/list")
	@ResponseBody
	public GagaMap getSearchEventList(@RequestBody SearchEngine params) {
		GagaMap result = new GagaMap();

		TscPageRequest pageable = new TscPageRequest((params.getPageNo() > 0 ? params.getPageNo() - 1 : 0), params.getPageSize(), params.getPageUnit());
		if (TsfSession.isLogin()) {
			params.setCustNo(TsfSession.getInfo().getCustNo());
		}

		params.setFrontGb(TsfSession.getFrontGb());
		params.setCustGb(TsfSession.getCustGb());

		Collection<SearchEngine> eventList = new ArrayList<SearchEngine>();

		PlanningResponse responsePlan = diquest.getEventList(params.getKeyword(), params.getPageNo(), params.getPageSize());
		pageable.setTotalCount(responsePlan.getTotalSize());
		eventList = responsePlan.getResponse();

		result.set("paging", pageable);
		result.set("eventList", eventList);

		return result;
	}

	/**
	 * 인기검색어 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 10
	 */
	@GetMapping("/search/trend/keyword/list")
	@ResponseBody
	public SearchEngine getSearchTrendKeywordList() {
		return diquest.getTrendKeywordList();
	}

	/**
	 * 검색어 레이어
	 * @param brandGroupNo - 브랜드그룹번호
	 * @return
	 * @throws UnsupportedEncodingException
	 * @author bin2107
	 * @since 2021. 5. 11
	 */
	@PostMapping("/search/layer")
	public ModelAndView searchLayerForm(@RequestParam(value = "brandGroupNo", required = false) Integer brandGroupNo) throws UnsupportedEncodingException {
		ModelAndView mav = new ModelAndView();

		// 최근검색어 목록
		Collection<String> recentlyKeywordList = new ArrayList<>();
		String ckKeywords = GagaCookieUtil.getCookie(TsfSession.getHttpServletRequest(), TsfConstants.CK_PREFIX + "_today_keyword");
		if (StringUtils.isNotBlank(ckKeywords)) {
			ckKeywords = URLDecoder.decode(ckKeywords, "UTF-8");
			String[] arrKeywords = ckKeywords.split("\\,");
			StringBuilder sql = new StringBuilder();
			if (arrKeywords.length > 0) {
				for (String keyword : arrKeywords) {
					if (!StringUtils.isBlank(keyword)) {
						recentlyKeywordList.add(keyword);
					}
				}
			}
		}
		mav.addObject("recentlyKeywordList", recentlyKeywordList);

		// 인기검색어
		mav.addObject("trendKeywordList", diquest.getTrendKeywordList());

		// 실시간 많이 조회하고 있는 상품
		mav.addObject("realtimeGoodsList", eigeneaiApi.getRealtimeViewGoodsList(20));

		mav.addObject("brandGroupNo", brandGroupNo);

		mav.setViewName(super.getDeviceViewName("display/SearchLayer"));
		return mav;
	}

	/**
	 * 검색어 자동완성
	 * @param params - 검색엔진 정보
	 * @return
	 * @author bin2107
	 * @since 2021. 6. 15
	 */
	@PostMapping("/search/auto/complete")
	@ResponseBody
	public GagaMap getSearchAutoCompleteList(@RequestBody SearchEngine params) {
		GagaMap result = new GagaMap();

		params.setFrontGb(TsfSession.getFrontGb());
		params.setCustGb(TsfSession.getCustGb());

		String[] autoKeywords;
		BrandGroup brand;
		Collection<Cate4Srch> cateList = new ArrayList<Cate4Srch>();
		Collection<SearchEngine> goodsList = new ArrayList<SearchEngine>();

		AutoCompleteResponse autoComplete = diquest.getAutoComplete(params.getKeyword());
		autoKeywords = autoComplete.getAutoKeywords();
		brand = autoComplete.getBrand();
		cateList = autoComplete.getCateList();
		goodsList = autoComplete.getGoodsList();

		result.set("autoKeywords", autoKeywords);
		result.set("brand", brand);
		result.set("cateList", cateList);
		result.set("goodsList", goodsList);

		return result;
	}

	/**
	 * 주간판매베스트추천상품 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 6. 29
	 */
	@GetMapping("/weekly/best/list")
	@ResponseBody
	public Collection<Result> getWeeklySellBestGoodsList() {
		return eigeneaiApi.getWeeklySellBestGoodsList(30);
	}

	/**
	 * 검색키워드 조회
	 * @param
	 * @return
	 * @throws Exception
	 * @author bin2107
	 * @since 2021. 7. 2
	 */
	@GetMapping("/search/keyword/list")
	@ResponseBody
	public Collection<SearchKeyword> getSearchKeywordList(SearchKeyword searchKeyword) {
		return displayService.getSearchKeywordList(searchKeyword);
	}

	/**
	 * 브랜드메인 검색어 레이어
	 * @param brandGroupNo - 브랜드그룹번호
	 * @return
	 * @throws UnsupportedEncodingException
	 * @author bin2107
	 * @since 2021. 7. 12
	 */
	@PostMapping("/brand/search/layer")
	public ModelAndView brandSearchLayerForm(@RequestParam(value = "brandGroupNo") Integer brandGroupNo) throws UnsupportedEncodingException {
		ModelAndView mav = new ModelAndView();

		// 최근검색어 목록
		Collection<String> recentlyKeywordList = new ArrayList<>();
		String ckKeywords = GagaCookieUtil.getCookie(TsfSession.getHttpServletRequest(), TsfConstants.CK_PREFIX + "_today_keyword");
		if (StringUtils.isNotBlank(ckKeywords)) {
			ckKeywords = URLDecoder.decode(ckKeywords, "UTF-8");
			String[] arrKeywords = ckKeywords.split("\\,");
			StringBuilder sql = new StringBuilder();
			if (arrKeywords.length > 0) {
				for (String keyword : arrKeywords) {
					if (!StringUtils.isBlank(keyword)) {
						recentlyKeywordList.add(keyword);
					}
				}
			}
		}
		mav.addObject("recentlyKeywordList", recentlyKeywordList);

		mav.addObject("brandGroupNo", brandGroupNo);

		// 실시간 많이 조회하고 있는 상품
		mav.addObject("realtimeGoodsList", eigeneaiApi.getRealtimeViewGoodsList(20));

		mav.setViewName(super.getDeviceViewName("display/BrandSearchLayer"));
		return mav;
	}

	/**
	 * 검색상품 목록 화면
	 * @param keyword - 검색키워드
	 * @param brandGroupNo - 브랜드그룹번호
	 * @return
	 * @author bin2107
	 * @since 2021. 7. 12
	 */
	@GetMapping("/brand/search/goods/list/form")
	public ModelAndView brandSearchGoodsListForm(@RequestParam(value = "keyword") String keyword, @RequestParam(value = "brandGroupNo") Integer brandGroupNo) {
		SearchEngine params = new SearchEngine();
		params.setKeyword(keyword);
		params.setBrandGroupNo(brandGroupNo == null ? 0 : brandGroupNo);
		params.setFrontGb(TsfSession.getFrontGb());

		ModelAndView mav = new ModelAndView(super.getDeviceViewName("display/BrandSearchGoodsListForm"));

		Collection<Filter> filterList = new ArrayList<Filter>();

		// 카테고리 목록
		mav.addObject("allCateList", displayService.getAllCategoryList("G032_101"));

		// 상품검색키워드 카테고리 목록
		mav.addObject("cateList", diquest.getCategoryList(params));

		// 상품리스트 카테고리별 필터 목록
		filterList = diquest.getFilterList(params);

		// 필터 설정
		mav.addObject("filterBrandList", displayService.getCategoryFilterList(filterList, "BRAND"));
		mav.addObject("filterSizeList", displayService.getCategoryFilterList(filterList, "SIZE"));
		mav.addObject("filterPriceList", displayService.getCategoryFilterList(filterList, "PRICE"));
		mav.addObject("filterAgeList", displayService.getCategoryFilterList(filterList, "AGE"));
		mav.addObject("filterSeasonList", displayService.getCategoryFilterList(filterList, "SEASON"));
		mav.addObject("filterColorList", displayService.getCategoryFilterList(filterList, "COLOR"));
		mav.addObject("filterBenefitList", displayService.getCategoryFilterList(filterList, "BENEFIT"));
		mav.addObject("params", params);

		if(!"".equals(brandGroupNo)){
			mav.addObject("brandGroupInfo", displayService.getGnbBrandGroup(brandGroupNo));
		}else{
			mav.addObject("brandGroupInfo", null);
		}

		// 광고 배너 조회
		Contents adContents = new Contents();
		adContents.setContentsLoc("SAD001");
		adContents.setMaxRow(1);
		mav.addObject("adBannerList", displayService.getContentsList(adContents));

		log.info("filterPriceList:::{}", displayService.getCategoryFilterList(filterList, "PRICE"));

		return mav;
	}

	/**
	 * 검색엔진 전체 카테고리 목록
	 * @return
	 * @author bin2107
	 * @since 2021. 7. 13
	 */
	@GetMapping("/searchengine/all/cate/list")
	@ResponseBody
	public Collection<Cate1> getSearchEngineAllCategoryList() {
		SearchEngine cate1 = new SearchEngine();
		cate1.setBrandGroupNo(0);
		cate1.setFrontGb(TsfSession.getFrontGb());
		cate1.setSiteCd(TscConstants.Site.STYLE24.value());
		cate1.setCateGb("G032_101");
//		cate1.setCate1No(params.getCate1No());

		return diquest.getCategoryList(cate1);
	}

	/**
	 * 베스트 실시간 상품 목록
	 * @return
	 * @author bin2107
	 * @since 2021. 7. 21
	 */
	@GetMapping("/realtime/best/list")
	@ResponseBody
	public Collection<Item> getRealtimeBestGoodsList(@RequestParam HashMap<String, String> paramMap) {
		String cateNo = paramMap.get("cateNo");
		Collection<Item> bestList = eigeneaiApi.getRealtimeViewBestGoodsList(20, cateNo);
		return bestList;
	}

	/**
	 * 검색레이어 실시간 상품 목록
	 * @return
	 * @author bin2107
	 * @since 2021. 7. 22
	 */
	@GetMapping("/realtime/goods/list")
	@ResponseBody
	public Collection<Item> getRealtimeViewGoodsList() {
		Collection<Item> goodsList = eigeneaiApi.getRealtimeViewGoodsList(20);
		return goodsList;
	}

	/**
	 * 검색어 연관 상품 추천 목록
	 * @return
	 * @author bin2107
	 * @since 2021. 7. 26
	 */
	@GetMapping("/recommend/item/list")
	@ResponseBody
	public Collection<Result> getRecommendItemList(@RequestParam HashMap<String, String> paramMap) {
		String keyword = paramMap.get("keyword");
		int size = 5;
		Collection<Result> itemList = eigeneaiApi.getRecommendItemList(size, keyword);

		return itemList;
	}

	@GetMapping("/test")
	public ModelAndView searchSample() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName(super.getDeviceViewName("display/SearchSampleForm"));

		return mav;
	}
}
