package com.style24.admin.biz.web;

import java.util.Collection;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.style24.admin.biz.service.TsaBusinessService;
import com.style24.admin.biz.service.TsaDisplayService;
import com.style24.admin.biz.service.TsaRendererService;
import com.style24.admin.support.controller.TsaBaseController;
import com.style24.admin.support.security.session.TsaSession;
import com.style24.core.biz.service.TscLookbookService;
import com.style24.core.biz.service.TscPopupService;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.TscPageRequest;
import com.style24.persistence.domain.Brand;
import com.style24.persistence.domain.Category;
import com.style24.persistence.domain.CategoryGoods;
import com.style24.persistence.domain.Contents;
import com.style24.persistence.domain.GnbTab;
import com.style24.persistence.domain.GoodsCategory;
import com.style24.persistence.domain.ItemkindCategory;
import com.style24.persistence.domain.Lookbook;
import com.style24.persistence.domain.LookbookGoods;
import com.style24.persistence.domain.MainDisplay;
import com.style24.persistence.domain.Popup;
import com.style24.persistence.domain.SearchKeyword;
import com.style24.persistence.domain.SplashImage;

import lombok.extern.slf4j.Slf4j;

import com.gagaframework.web.parameter.GagaMap;
import com.gagaframework.web.rest.server.GagaResponse;
import com.gagaframework.web.util.GagaDateUtil;

/**
 * 전시 Controller
 *
 * @author
 * @since 2020. 12. 16
 */
@Controller
@RequestMapping("/display")
@Slf4j
public class TsaDisplayController extends TsaBaseController {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private TsaRendererService rendererService;

	@Autowired
	private TsaDisplayService displayService;

	@Autowired
	private TsaBusinessService businessService;

	@Autowired
	private TscPopupService corePopupService;

	@Autowired
	private TscLookbookService coreLookbookService;

	@Autowired
	private ObjectMapper mapper;

	/**
	 * 카테고리관리 화면
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 4
	 */
	@GetMapping("/category/form")
	public ModelAndView categoryForm() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("siteList", rendererService.getAvailCommonCodeList("G000"));
		mav.addObject("cateGbList", rendererService.getAvailCommonCodeList("G032"));
		mav.addObject("cateTypeList", rendererService.getAvailCommonCodeList("G031"));
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		mav.addObject("contentsLocList", rendererService.getAvailCommonCodeList("G028"));

		mav.setViewName("display/CategoryForm");

		return mav;
	}

	/**
	 * 카테고리 목록
	 * @param category - 카테고리 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 4
	 */
	@PostMapping("/category/list")
	@ResponseBody
	public Collection<Category> getCategoryList(@RequestBody Category category) {
		return displayService.getCategoryList(category);
	}

	/**
	 * 카테고리 저장
	 * @param category - 카테고리 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 4
	 */
	@PostMapping("/category/save")
	@ResponseBody
	public GagaResponse saveCategory(@RequestBody Category category) {
		displayService.saveCategory(category);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 카테고리 갱신
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 4
	 */
	@PostMapping("/category/refresh")
	@ResponseBody
	public GagaResponse refreshCategory() {
		displayService.refreshCategory();
		return super.ok(message.getMessage("SUCC_0010"));
	}

	/**
	 * 품목카테고리매핑관리 화면
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 5
	 */
	@GetMapping("/itemkind/category/mapping/form")
	public ModelAndView itemkindCategoryMappingForm() {
		ModelAndView mav = new ModelAndView();

		// 카테고리구분
		mav.addObject("cateGbList", rendererService.getAvailCommonCodeList("G032"));

		mav.setViewName("display/ItemkindCategoryForm");

		return mav;
	}

	/**
	 * 카테고리구분 목록
	 * @param cateGb - 카테고리구분
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 6
	 */
	@GetMapping("/category/gb/list/{cateGb}")
	@ResponseBody
	public Collection<Category> getCategoryGbList(@PathVariable String cateGb) {
		return displayService.getCategoryGbList(cateGb);
	}

	/**
	 * 품목카테고리매핑 저장
	 * @param itemkindCateList - 품목카테고리 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 6
	 */
	@PostMapping("/itemkind/category/mapping/save")
	@ResponseBody
	public GagaResponse saveItemkindCategoryMappingList(@RequestBody Collection<ItemkindCategory> itemkindCateList) {
		if (itemkindCateList == null || itemkindCateList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		displayService.saveItemkindCategoryMappingList(itemkindCateList);

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

	/**
	 * 품목카테고리매핑 삭제
	 * @param itemkindCateList - 품목카테고리 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 6
	 */
	@PostMapping("/itemkind/category/mapping/delete")
	@ResponseBody
	public GagaResponse deleteItemkindCategoryMappingList(@RequestBody Collection<ItemkindCategory> itemkindCateList) {
		if (itemkindCateList == null || itemkindCateList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1004"));
		}

		displayService.deleteItemkindCategoryMappingList(itemkindCateList);

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

	/**
	 * 품목카테고리매핑 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 5
	 */
	@GetMapping("/itemkind/category/mapping/list/{itemkindCd}")
	@ResponseBody
	public Collection<ItemkindCategory> getItemkindCategoryMappingList(@PathVariable String itemkindCd) {
		return displayService.getItemkindCategoryMappingList(itemkindCd);
	}

	/**
	 * 카테고리 목록 화면(팝업)
	 * @param category
	 * @return
	 * @author xyzp1539
	 * @since 2021. 01. 11
	 */
	@GetMapping("/category/popup/form")
	public ModelAndView categorySearchForm(Category category) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("siteList", rendererService.getAvailCommonCodeList("G000"));
		mav.addObject("cateGbList", rendererService.getAvailCommonCodeList("G032"));
		mav.addObject("cateTypeList", rendererService.getAvailCommonCodeList("G031"));
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		mav.addObject("conentsLocList", rendererService.getAvailCommonCodeList("G028"));
		mav.addObject("params", category);

		mav.setViewName("display/CategorySearchForm");
		return mav;
	}

	/**
	 * 상품별카테고리전시관리 화면
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 13
	 */
	@GetMapping("/goods/category/form")
	public ModelAndView goodsCategoryForm() {
		ModelAndView mav = new ModelAndView();

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

		// 카테고리 등록/수정
		mav.addObject("cateGbList", rendererService.getAvailCommonCodeList("G032"));

		mav.setViewName("display/GoodsCategoryForm");

		return mav;
	}

	/**
	 * 상품별카테고리전시관리 조회
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 15
	 */
	@PostMapping("/goods/category/list")
	@ResponseBody
	public GagaMap getGoodsCategoryList(@RequestBody GoodsCategory goodsCategory) {
		GagaMap result = new GagaMap();

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

			if ("searchExtendGoodsCd".equals(goodsCategory.getSearch())) {
				goodsCategory.setSearchGb("EXTEND");
			} else if ("searchMasterGoodsCd".equals(goodsCategory.getSearch())) {
				goodsCategory.setSearchGb("MASTER");
			}
		}
		if (!StringUtils.isBlank(goodsCategory.getBrandList())) {
			try {
				String[] arrBrandCd = mapper.readValue(goodsCategory.getBrandList(), String[].class);
				goodsCategory.setMultiBrand(arrBrandCd);
			} catch (Exception e) {
				e.printStackTrace();
				throw new IllegalStateException("브랜드코드 검색중 오류로 인해 조회되지 않았습니다.");
			}
		}

		if (!StringUtils.isBlank(goodsCategory.getSupplyCompList())) {
			try {
				String[] arrSupplyComp = mapper.readValue(goodsCategory.getSupplyCompList(), String[].class);
				goodsCategory.setMultiSupplyCompCd(arrSupplyComp);
			} catch (Exception e) {
				e.printStackTrace();
				throw new IllegalStateException("업체코드 검색중 오류로 인해 조회되지 않았습니다.");
			}
		}

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

		result.set("pageing", goodsCategory);
		result.set("goodsCategoryList", displayService.getGoodsCategoryList(goodsCategory));

		return result;
	}

	/**
	 * 상품별카테고리전시 저장
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 17
	 */
	@PostMapping("/goods/category/save")
	@ResponseBody
	public GagaResponse saveGoodsCategory(@RequestBody GoodsCategory goodsCategory) {
		log.info("saveGoodsCategory goodsCategory::::::::{}", goodsCategory);
		displayService.saveGoodsCategory(goodsCategory);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 상품별카테고리 리스트 조회
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 18
	 */
	@GetMapping("/goods/category/view/list")
	@ResponseBody
	public Collection<GoodsCategory> getGoodsCategoryViewList(@RequestParam(value = "goodsCd") String goodsCd) {
		return displayService.getGoodsCategoryViewList(goodsCd);
	}

	/**
	 * 상품별카테고리 삭제
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 18
	 */
	@PostMapping("/goods/category/delete")
	@ResponseBody
	public GagaResponse deleteGoodsCategory(@RequestBody GoodsCategory goodsCategory) {
		displayService.deleteGoodsCategoryList(goodsCategory);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 카테고리별상품전시관리 화면
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 19
	 */
	@GetMapping("/category/goods/form")
	public ModelAndView CategoryGoodsForm() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("siteList", rendererService.getAvailCommonCodeList("G000"));
		// 카테고리구분
		mav.addObject("cateGbList", rendererService.getAvailCommonCodeList("G032"));

		mav.addObject("cateTypeList", rendererService.getAvailCommonCodeList("G031"));
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		mav.addObject("conentsLocList", rendererService.getAvailCommonCodeList("G028"));
		mav.addObject("goodsStatList", rendererService.getAvailCommonCodeList("G008"));

		mav.setViewName("display/CategoryGoodsForm");

		return mav;
	}

	/**
	 * 카테고리별상품 조회
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 27
	 */
	@PostMapping("/category/goods/list")
	@ResponseBody
	public GagaMap getCategoryGoodsList(@RequestBody CategoryGoods categoryGoods) {
		GagaMap result = new GagaMap();

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

		result.set("pageing", categoryGoods);
		result.set("categoryGoodsList", displayService.getCategoryGoodsList(categoryGoods));

		return result;
	}

	/**
	 * 카테고리별상품전시 상품이동/복사
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 15
	 */
	@PostMapping("/category/goods/move")
	@ResponseBody
	public GagaResponse moveCategoryGoods(@RequestBody CategoryGoods categoryGoods) {
		categoryGoods.setRegNo(TsaSession.getInfo().getUserNo());
		displayService.moveCategoryGoods(categoryGoods);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 카테고리별상품전시 상품삭제
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 15
	 */
	@PostMapping("/category/goods/delete")
	@ResponseBody
	public GagaResponse deleteCategoryGoods(@RequestBody CategoryGoods categoryGoods) {
		categoryGoods.setRegNo(TsaSession.getInfo().getUserNo());
		displayService.deleteCategoryGoods(categoryGoods);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 카테고리별상품전시 상품추가
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 15
	 */
	@PostMapping("/category/goods/save")
	@ResponseBody
	public GagaResponse insertCategoryGoods(@RequestBody CategoryGoods categoryGoods) {
		categoryGoods.setRegNo(TsaSession.getInfo().getUserNo());
		displayService.insertCategoryGoods(categoryGoods);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 전시 상품 순서변경 팝업
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 18
	 */
	@GetMapping("/goods/dispord/change/popup/form")
	public ModelAndView goodsDispOrdChangePopupForm(CategoryGoods categoryGoods) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("params", categoryGoods);
		mav.setViewName("display/GoodsDispOrdChangePopupForm");
		return mav;
	}

	/**
	 * 전시 상품 순서변경 리스트
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 18
	 */
	@PostMapping("/goods/dispord/change/popup/list")
	@ResponseBody
	public GagaMap getGoodsDispOrdChangePopupList(@RequestBody CategoryGoods categoryGoods) {
		GagaMap result = new GagaMap();

		log.info("getGoodsDispOrdChangePopupList categoryGoods::{}", categoryGoods);
		categoryGoods.setRegNo(TsaSession.getInfo().getUserNo());	//엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		categoryGoods.setPageable(new TscPageRequest(categoryGoods.getPageNo() - 1, categoryGoods.getPageSize()));
		categoryGoods.getPageable().setTotalCount(displayService.getCategoryGoodsListCount(categoryGoods));
		categoryGoods.setDispUseGb("Y");
		result.set("pageing", categoryGoods);
		result.set("categoryGoodsList", displayService.getCategoryGoodsList(categoryGoods));

		return result;
	}

	/**
	 * 전시 상품 순서변경 상품삭제
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 19
	 */
	@PostMapping("/goods/dispord/change/delete")
	@ResponseBody
	public GagaResponse deleteDispOrdChangeGoods(@RequestBody CategoryGoods categoryGoods) {
		categoryGoods.setRegNo(TsaSession.getInfo().getUserNo());
		displayService.deleteDispOrdChangeGoods(categoryGoods);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 전시 상품 순서변경 전시초기화
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 19
	 */
	@PostMapping("/category/goods/dispord/init")
	@ResponseBody
	public GagaResponse updateCategoryGoodsDispOrdInit(@RequestBody CategoryGoods categoryGoods) {
		categoryGoods.setRegNo(TsaSession.getInfo().getUserNo());
		displayService.updateCategoryGoodsDispOrdInit(categoryGoods);
		return super.ok(message.getMessage("SUCC_0009"));
	}

	/**
	 * 전시 상품 순서변경 최상단/하단 이동
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 19
	 */
	@PostMapping("/category/goods/dispord/updown")
	@ResponseBody
	public GagaResponse updateCategoryGoodsDispOrdUpdown(@RequestBody CategoryGoods categoryGoods) {
		int size = categoryGoods.getGoodsCdArr().length - 1;

		for (int i = size; i >= 0; i--) {
			categoryGoods.setGoodsCd(categoryGoods.getGoodsCdArr()[i]);
			categoryGoods.setDispOrd(categoryGoods.getDispOrdArr()[i]);
			displayService.updateCategoryGoodsDispOrdUpdown(categoryGoods);
		}
		return super.ok(message.getMessage("SUCC_0009"));
	}

	/**
	 * 전시 상품 순서변경 저장
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 19
	 */
	@PostMapping("/category/goods/dispord/update")
	@ResponseBody
	public GagaResponse updateCategoryGoodsDispOrd(@RequestBody CategoryGoods categoryGoods) {
		displayService.updateCategoryGoodsDispOrd(categoryGoods);
		return super.ok(message.getMessage("SUCC_0009"));
	}

	/**
	 * 메인전시관리 화면
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 22
	 */
	@GetMapping("/main/form")
	public ModelAndView mainListForm() {
		ModelAndView mav = new ModelAndView();
		Category category = new Category();
		Brand brand = new Brand();
		category.setClsLvl(1);
		mav.addObject("mainCategoryList", displayService.getMainCategoryList(category));
		brand.setUseYn("Y");
		brand.setSelfYn("Y");
		mav.addObject("brandCdList", businessService.getBrandList(brand));
		mav.addObject("contentsLocList", rendererService.getAvailCommonCodeList("G028"));

		mav.setViewName("display/MainListForm");
		return mav;
	}

	/**
	 * 메인전시 카테고리 목록
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 22
	 */
	@PostMapping("/main/category/list")
	@ResponseBody
	public Collection<Category> getMainCategoryList(@RequestBody Category category) {
		return displayService.getMainCategoryList(category);
	}

	/**
	 * 메인전시 레이아웃 목록
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 22
	 */
	@PostMapping("/main/layout/list")
	@ResponseBody
	public Collection<MainDisplay> getMainLayoutList(@RequestBody MainDisplay mainDisplay) {
		return displayService.getMainLayoutList(mainDisplay);
	}

	/**
	 * 메인전시 레이아웃 저장
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 22
	 */
	@PostMapping("/main/layout/save")
	@ResponseBody
	public GagaResponse saveMainLayout(@RequestBody Collection<MainDisplay> mainDisplayList) {
		displayService.saveMainLayout(mainDisplayList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 메인전시 컨텐츠 수정 팝업
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 22
	 */
	@GetMapping("/main/contents/popup/form")
	public ModelAndView mainContentsPopupForm(@RequestParam(value = "cateNo") String cateNo, @RequestParam(value = "contentsLoc") String contentsLoc, @RequestParam(value = "brandGroupNo", required = false) String brandGroupNo) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("cateNo", cateNo);
		mav.addObject("contentsLoc", contentsLoc);
		mav.addObject("brandGroupNo", brandGroupNo);
		mav.addObject("contentsDesc", displayService.getContentsDesc(contentsLoc));
		mav.addObject("contentsLocList", rendererService.getAvailCommonCodeList("G028"));
		mav.addObject("cate1List", rendererService.getCate1List());

		mav.setViewName("display/MainContentsPopupForm");
		return mav;
	}

	/**
	 * 메인전시 컨텐츠 미리보기 리스트
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 23
	 */
	@PostMapping("/contents/preview/list")
	@ResponseBody
	public Collection<Contents> getContentsPreviewList(@RequestBody Contents contents) {
		return displayService.getContentsPreviewList(contents);
	}

	/**
	 * 메인전시 컨텐츠 탭영역 미리보기 리스트
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 18
	 */
	@PostMapping("/contents/gnbtab/brand/preview/list")
	@ResponseBody
	public Collection<Contents> getContentsTabPreviewList(@RequestBody Contents contents) {
		return displayService.getContentsTabPreviewList(contents);
	}

	/**
	 * 메인전시 컨텐츠 탭영역 미리보기 리스트
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 18
	 */
	@PostMapping("/contents/gnbtab/category/preview/list")
	@ResponseBody
	public Collection<GnbTab> getGnbtabPreviewList(@RequestBody GnbTab gnbTab) {
		return displayService.getGnbtabPreviewList(gnbTab);
	}

	/**
	 * 메인전시 컨텐츠 탭영역 카테고리 미리보기 저장
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 19
	 */
	@PostMapping("/contents/gnbtab/preview/save")
	@ResponseBody
	public GagaResponse saveGnbtabPreview(@RequestBody Collection<GnbTab> gnbTabList) {
		log.info("saveGnbtabPreview:::{}", gnbTabList);
		displayService.saveGnbtabPreview(gnbTabList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 메인전시 컨텐츠 gnbtab 저장
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 19
	 */
	@PostMapping("/contents/gnbtab/save")
	@ResponseBody
	public GagaResponse saveGnbtabContents(@RequestBody GnbTab gnbTab) {
		log.info("controller saveGnbtabContents gnbTab::: {}", gnbTab);
		displayService.saveGnbtabContents(gnbTab);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 메인전시 컨텐츠 미리보기 저장
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 23
	 */
	@PostMapping("/contents/preview/save")
	@ResponseBody
	public GagaResponse saveContentsPreview(@RequestBody Collection<Contents> contentsList) {
		displayService.saveContentsPreview(contentsList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 메인전시 컨텐츠 저장
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 23
	 */
	@PostMapping("/contents/save")
	@ResponseBody
	public GagaResponse saveContents(@RequestBody Contents contents) {
		displayService.saveContents(contents);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * CATEGORY4SRCH 조회
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 24
	 */
	@PostMapping("/category4srch/list")
	@ResponseBody
	public Category getCategory4srch(@RequestBody Category category) {
		return displayService.getCategory4srch(category);
	}

	/**
	 * 메인전시 컨텐츠 멀티 수정 팝업
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 24
	 */
	@GetMapping("/main/multicontents/popup/form")
	public ModelAndView mainMultiContentsPopupForm(@RequestParam(value = "cateNo") String cateNo, @RequestParam(value = "contentsLoc") String contentsLoc, @RequestParam(value = "brandGroupNo", required = false) String brandGroupNo) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("cateNo", cateNo);
		mav.addObject("contentsLoc", contentsLoc);
		mav.addObject("brandGroupNo", brandGroupNo);
		mav.addObject("contentsDesc", displayService.getContentsDesc(contentsLoc));
		mav.addObject("contentsLocList", rendererService.getAvailCommonCodeList("G028"));

		mav.setViewName("display/MainMultiContentsPopupForm");
		return mav;
	}

	/**
	 * 팝업관리 화면
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 3
	 */
	@GetMapping("/popup/form")
	public ModelAndView popupListForm() {
		ModelAndView mav = new ModelAndView();
		mav.addObject("siteCdList", rendererService.getAvailCommonCodeList("G000"));
		mav.addObject("viewPageList", rendererService.getAvailCommonCodeList("G037"));
		mav.addObject("cateNoList", rendererService.getCate1List());
		mav.setViewName("display/PopupListForm");
		return mav;
	}

	/**
	 * 팝업관리 리스트
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 3
	 */
	@PostMapping("/popup/list")
	@ResponseBody
	public GagaMap getPopupList(@RequestBody Popup popup) {
		GagaMap result = new GagaMap();

		popup.setRegNo(TsaSession.getInfo().getUserNo());
		popup.setPageable(new TscPageRequest(popup.getPageNo() - 1, popup.getPageSize()));
		popup.getPageable().setTotalCount(corePopupService.getPopupListCount(popup));

		result.set("pageing", popup);
		result.set("popupList", corePopupService.getPopupList(popup));
		return result;
	}

	/**
	 * 팝업관리 저장
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 3
	 */
	@PostMapping("/popup/save")
	@ResponseBody
	public GagaResponse savePopup(@RequestBody Popup popup) {
		popup.setRegNo(TsaSession.getInfo().getUserNo());
		popup.setUpdNo(TsaSession.getInfo().getUserNo());
		corePopupService.savePopup(popup);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 팝업관리 삭제
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 4
	 */
	@PostMapping("/popup/delete")
	@ResponseBody
	public GagaResponse deletePopup(@RequestBody Popup popup) {
		popup.setRegNo(TsaSession.getInfo().getUserNo());
		popup.setUpdNo(TsaSession.getInfo().getUserNo());
		corePopupService.deletePopup(popup);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 팝업관리 프론트 적용
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 4
	 */
	@PostMapping("/popupfront/save")
	@ResponseBody
	public GagaResponse savePopupFront(@RequestBody Popup popup) {
		popup.setRegNo(TsaSession.getInfo().getUserNo());
		popup.setUpdNo(TsaSession.getInfo().getUserNo());
		corePopupService.savePopupFront(popup);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 룩북관리 화면
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 4
	 */
	@GetMapping("/lookbook/form")
	public ModelAndView lookbookListForm() {
		ModelAndView mav = new ModelAndView();
		mav.addObject("siteCdList", rendererService.getAvailCommonCodeList("G000"));
		mav.addObject("brandGroupList", rendererService.getSelfBrandGroupList());
		mav.setViewName("display/LookbookListForm");
		return mav;
	}

	/**
	 * 룩북 등록/수정 상세 팝업
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 5
	 */
	@GetMapping("/lookbook/banner/popup/form")
	public ModelAndView lookbookBannerPopupForm(@RequestParam(value = "mode") String mode, @RequestParam(value = "lookbookSq", required = false) Integer lookbookSq) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("mode", mode);
		mav.addObject("lookbookSq", lookbookSq);
		mav.addObject("brandGroupList", rendererService.getSelfBrandGroupList());

		if (!"".equals(lookbookSq)) {
			mav.addObject("lookbookMstInfo", coreLookbookService.getLookbookMstInfo(lookbookSq));
			mav.addObject("lookbookBannerList", coreLookbookService.getLookbookBannerDetailList(lookbookSq));
		}
		mav.setViewName("display/LookbookBannerPopupForm");
		return mav;
	}

	/**
	 * 룩북 등록/수정
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 5
	 */
	@PostMapping("/lookbook/save")
	@ResponseBody
	public GagaResponse saveLookbook(@RequestBody Lookbook lookbook) {
		lookbook.setRegNo(TsaSession.getInfo().getUserNo());
		lookbook.setUpdNo(TsaSession.getInfo().getUserNo());
		coreLookbookService.saveLookbook(lookbook);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 룩북 리스트
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 3
	 */
	@PostMapping("/lookbook/list")
	@ResponseBody
	public GagaMap getLookbookList(@RequestBody Lookbook lookbook) {
		GagaMap result = new GagaMap();
		if (lookbook.getDispStdt() != null) {
			lookbook.setDispStdt(lookbook.getDispStdt().replaceAll("-", ""));
		}
		if (lookbook.getDispEddt() != null) {
			lookbook.setDispEddt(lookbook.getDispEddt().replaceAll("-", ""));
		}

		lookbook.setRegNo(TsaSession.getInfo().getUserNo());
		lookbook.setPageable(new TscPageRequest(lookbook.getPageNo() - 1, lookbook.getPageSize()));
		lookbook.getPageable().setTotalCount(coreLookbookService.getLookbookListCount(lookbook));

		result.set("pageing", lookbook);
		result.set("lookbookList", coreLookbookService.getLookbookList(lookbook));
		return result;
	}

	/**
	 * 룩북 삭제
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 5
	 */
	@PostMapping("/lookbook/delete")
	@ResponseBody
	public GagaResponse deleteLookbook(@RequestBody Lookbook lookbook) {
		lookbook.setRegNo(TsaSession.getInfo().getUserNo());
		lookbook.setUpdNo(TsaSession.getInfo().getUserNo());
		coreLookbookService.deleteLookbook(lookbook);
		return super.ok(message.getMessage("SUCC_0009"));
	}

	/**
	 * 룩북 배너 피커 팝업
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 9
	 */
	@GetMapping("/lookbook/banner/picker/popup/form")
	public ModelAndView lookbookBannerPickerForm(@RequestParam(value = "lookbookbSq") Integer lookbookbSq, @RequestParam(value = "imgNm") String imgNm) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("lookbookbSq", lookbookbSq);
		mav.addObject("imgNm", imgNm);
		mav.addObject("lookbookBannerPickerList", coreLookbookService.getLookbookBannerPickerList(lookbookbSq));

		if (coreLookbookService.getLookbookBannerPickerList(lookbookbSq).size() > 0) {
			mav.addObject("mode", "U");
		} else {
			mav.addObject("mode", "N");
		}

		mav.setViewName("display/LookbookBannerPickerPopupForm");
		return mav;
	}

	/**
	 * 룩북 배너 피커 등록/수정
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 9
	 */
	@PostMapping("/lookbook/banner/picker/save")
	@ResponseBody
	public GagaResponse saveLookbookPicker(@RequestBody LookbookGoods lookbookGoods) {
		lookbookGoods.setRegNo(TsaSession.getInfo().getUserNo());
		lookbookGoods.setUpdNo(TsaSession.getInfo().getUserNo());
		coreLookbookService.saveLookbookPicker(lookbookGoods);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 룩북 메인룩북 등록
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 15
	 */
	@PostMapping("/mainlookbook/save")
	@ResponseBody
	public GagaResponse saveMainLookbook(@RequestBody Lookbook lookbook) {
		lookbook.setRegNo(TsaSession.getInfo().getUserNo());
		lookbook.setUpdNo(TsaSession.getInfo().getUserNo());
		coreLookbookService.saveMainLookbook(lookbook);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 메인전시 컨텐츠 GNB TAB 수정 팝업
	 * @return
	 * @author bin2107
	 * @since 2021. 3. 10
	 */
	@GetMapping("/main/gnbcontents/popup/form")
	public ModelAndView mainGnbContentsPopupForm(@RequestParam(value = "cateNo") String cateNo, @RequestParam(value = "contentsLoc") String contentsLoc, @RequestParam(value = "brandGroupNo", required = false) String brandGroupNo) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("cateNo", cateNo);
		mav.addObject("contentsLoc", contentsLoc);
		mav.addObject("brandGroupNo", brandGroupNo);
		mav.addObject("contentsDesc", displayService.getContentsDesc(contentsLoc));
		mav.addObject("contentsLocList", rendererService.getAvailCommonCodeList("G028"));
		mav.addObject("cate1List", rendererService.getCate1List());

		mav.setViewName("display/MainGnbContentsPopupForm");
		return mav;
	}

	/**
	 * 검색키워드 관리 화면
	 * @return
	 * @author bin2107
	 * @since 2021. 7. 1
	 */
	@GetMapping("/keyword/form")
	public ModelAndView searchKeywordForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("display/SearchKeywordForm");

		return mav;
	}

	/**
	 * 검색 키워드 저장/등록
	 *
	 * @param adKeyword
	 * @return
	 * @author eskim
	 * @since 2020. 12. 15
	 */
	@PostMapping("/search/keyword/save")
	@ResponseBody
	public GagaResponse saveSearchKeyword(@RequestBody SearchKeyword searchKeyword) {
		displayService.saveSearchKeyword(searchKeyword);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 검색 키워드 목록
	 * @param SearchKeyword
	 * @return
	 * @author bin2107
	 * @since 2021. 7. 2
	 */
	@PostMapping("/search/keyword/list")
	@ResponseBody
	public Collection<SearchKeyword> getSearchKeywordList(@RequestBody SearchKeyword searchKeyword) {
		return displayService.getSearchKeywordList(searchKeyword);
	}

	/**
	 * 스플래시이미지관리 화면
	 * @return
	 * @author gagamel
	 * @since 2021. 7. 2
	 */
	@GetMapping("/splash/image/form")
	public ModelAndView splashImageForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("display/SplashImageForm");

		return mav;
	}

	/**
	 * 스플래시이미지 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 7. 2
	 */
	@GetMapping("/splash/image/list")
	@ResponseBody
	public Collection<SplashImage> getSplashImageList() {
		return displayService.getSplashImageList();
	}

	/**
	 * 스플래시이미지 등록/수정 처리
	 * @param splashImg - 스플래시이미지 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 7. 2
	 */
	@PostMapping("/splash/image/save")
	@ResponseBody
	public GagaResponse saveSplashImage(@RequestBody SplashImage splashImg) {
		splashImg.setRegNo(TsaSession.getInfo().getUserNo());
		splashImg.setUpdNo(TsaSession.getInfo().getUserNo());
		displayService.saveSplashImage(splashImg);
		return super.ok(message.getMessage("SUCC_0001"));
	}

}
