package com.style24.admin.biz.web;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
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.style24.admin.biz.service.TsaCardPromotionService;
import com.style24.admin.biz.service.TsaCommonService;
import com.style24.admin.biz.service.TsaFreegiftPromotionService;
import com.style24.admin.biz.service.TsaGiftCardService;
import com.style24.admin.biz.service.TsaMailTemplateService;
import com.style24.admin.biz.service.TsaMorebetterService;
import com.style24.admin.biz.service.TsaPlanService;
import com.style24.admin.biz.service.TsaPollService;
import com.style24.admin.biz.service.TsaRendererService;
import com.style24.admin.biz.service.TsaReviewService;
import com.style24.admin.biz.service.TsaSocialService;
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.biz.service.TscCouponService;
import com.style24.core.biz.service.TscMailTemplateService;
import com.style24.core.biz.service.TscPointService;
import com.style24.core.support.env.TscConstants;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.core.support.session.TscSession;
import com.style24.persistence.TscPageRequest;
import com.style24.persistence.domain.CardPromotion;
import com.style24.persistence.domain.CardPromotionTarget;
import com.style24.persistence.domain.CommonCode;
import com.style24.persistence.domain.Coupon;
import com.style24.persistence.domain.CouponLimitedTime;
import com.style24.persistence.domain.CouponRefval;
import com.style24.persistence.domain.CustCoupon;
import com.style24.persistence.domain.FreeGoodsPromotion;
import com.style24.persistence.domain.GiftCard;
import com.style24.persistence.domain.MailHeaderFooter;
import com.style24.persistence.domain.MailTemplate;
import com.style24.persistence.domain.MailTemplateCorner;
import com.style24.persistence.domain.MailTemplateGoods;
import com.style24.persistence.domain.MoreBetter;
import com.style24.persistence.domain.MoreBetterBurden;
import com.style24.persistence.domain.MoreBetterGoods;
import com.style24.persistence.domain.MoreBetterSection;
import com.style24.persistence.domain.Plan;
import com.style24.persistence.domain.Point;
import com.style24.persistence.domain.Poll;
import com.style24.persistence.domain.Review;
import com.style24.persistence.domain.Social;
import com.style24.persistence.domain.User;

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;

/**
 * 마케팅 Controller
 * @author xodud1202
 * @since 2020. 12.16
 */
@Controller
@RequestMapping("/marketing")
@Slf4j
public class TsaMarketingController extends TsaBaseController {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private Environment env;

	@Autowired
	private TsaFreegiftPromotionService freegiftService;

	@Autowired
	private TsaRendererService rendererService;

	@Autowired
	private TsaCommonService commonService;

	@Autowired
	private TsaMorebetterService morebetterService;

	@Autowired
	private TsaReviewService reviewService;

	@Autowired
	private TsaSystemService systemService;

	@Autowired
	private TscPointService corePointService;

	@Autowired
	private TsaMailTemplateService mailTemplateService;

	@Autowired
	private TscMailTemplateService coreMailTemplateService;

	@Autowired
	private TsaPollService pollService;

	@Autowired
	private TsaCardPromotionService cardPromotionService;

	@Autowired
	private TsaPlanService planService;

	@Autowired
	private TscCouponService coreCouponService;

	@Autowired
	private TsaSocialService socialService;

	@Autowired
	private TsaGiftCardService giftCardService;

	@Value("${upload.default.target.path}")
	private String uploadTargetPath;

	/**
	 * 상품평관리 화면
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 25
	 */
	@GetMapping("/review/form")
	public ModelAndView reviewForm() {
		ModelAndView mav = new ModelAndView("marketing/ReviewForm");

		// 사이즈점수
		mav.addObject("scoreSizeList", rendererService.getAvailCommonCodeList("G040"));

		// 색상점수
		mav.addObject("scoreColorList", rendererService.getAvailCommonCodeList("G039"));

		// 핏점수
		mav.addObject("scoreFitList", rendererService.getAvailCommonCodeList("G042"));

		// 두께감점수
		mav.addObject("scoreThickList", rendererService.getAvailCommonCodeList("G079"));

		// 무게감점수
		mav.addObject("scoreWeightList", rendererService.getAvailCommonCodeList("G080"));

		// 발볼넓이점수(G041)
		mav.addObject("scoreBallList", rendererService.getAvailCommonCodeList("G041"));

		// 포인트지급상태
		mav.addObject("pntGiveStatList", rendererService.getAvailCommonCodeList("G043"));

//		// 품목
//		mav.addObject("itemkindList", rendererService.getAllItemkindList());
//
//		// 브랜드그룹
//		mav.addObject("brandGrpNmList", rendererService.getBrandGroupList());
//
//		// MD
//		mav.addObject("brandMdList", rendererService.getBrandMdList());
//
//		// 카테고리
//		mav.addObject("tCateList", rendererService.getTCategoryList(""));
//
//		// 브랜드 조회
//		mav.addObject("brandList", rendererService.getSupplyCompanyBrandList(""));

		return mav;
	}

	/**
	 * 상품평 목록
	 * @param review - 상품평 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 25
	 */
	@PostMapping("/review/list")
	@ResponseBody
	public GagaMap getReviewList(@RequestBody Review review) {
		GagaMap result = new GagaMap();

		// multi row 검색관련 처리
		if (StringUtils.isNotBlank(review.getGoodsCd())) {
			review.setGoodsCds(review.getGoodsCd().replaceAll("\r", "").split("\n"));
		}

		// 상품평 목록
		Collection<Review> reviewList = reviewService.getReviewList(review);

		review.setPageable(new TscPageRequest(review.getPageNo() - 1, review.getPageSize()));
		review.getPageable().setTotalCount(reviewList.size());

		result.set("paging", review);
		result.set("dataList", reviewList);

		return result;
	}

	/**
	 * 상품평 상세 화면
	 * @param reviewSq - 상품평일련번호
	 * @return
	 * @author gagamel
	 * @since 2021. 4. 22
	 */
	@GetMapping("/review/detail/form")
	public ModelAndView reviewDetailForm(@RequestParam(value = "reviewSq") Integer reviewSq) {
		ModelAndView mav = new ModelAndView();

		// 상품평 상세
		mav.addObject("reviewInfo", reviewService.getReview(reviewSq));

		mav.setViewName("marketing/ReviewDetailForm");

		return mav;
	}

	/**
	 * 상품평 관리자 답변 저장
	 * @param review - 상품평 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 4. 22
	 */
	@PostMapping("/review/user/reply/save")
	@ResponseBody
	public GagaResponse updateReviewUserReply(@RequestBody Review review) {
		review.setAdmRplRegNo(TsaSession.getInfo().getUserNo());
		review.setUpdNo(TsaSession.getInfo().getUserNo());

		reviewService.updateReviewUserReply(review);

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

	/**
	 * 상품평 동영상 노출 처리
	 * @param reviewSq - 상품평일련번호
	 * @return
	 * @author gagamel
	 * @since 2021. 4. 22
	 */
	@PostMapping("/review/video/display/update/{reviewSq}")
	@ResponseBody
	public GagaResponse updateVideoReviewDisplay(@PathVariable("reviewSq") Integer reviewSq) {
		Review review = new Review();
		review.setReviewSq(reviewSq);
		review.setUpdNo(TsaSession.getInfo().getUserNo());
		reviewService.updateVideoReviewDisplay(review);
		return super.ok(message.getMessage("SUCC_0004"));
	}

	/**
	 * 베스트상품평선정 처리
	 * @param reviewList - 상품평 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 4. 27
	 */
	@PostMapping("/review/best/list/save")
	@ResponseBody
	public GagaResponse saveBestReviewList(@RequestBody Collection<Review> reviewList) {
		if (reviewList == null || reviewList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		reviewService.saveBestReviewList(reviewList);

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

	/* xodud1202 진행 */
	/**
	 * 사은품 프로모션 관리 화면
	 * @author xodud1202
	 * @since 2020. 12. 16
	 */
	@GetMapping("/freegoods/promotion/form")
	public ModelAndView freeGoodsPromotionForm() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("marketing/FreeGoodsPromotionForm");
		return mav;
	}

	/**
	 * 사은품 프로모션 목록 조회
	 * @author xodud1202
	 * @since 2020. 12. 16
	 */
	@PostMapping("/freegoods/promotion/list")
	@ResponseBody
	public GagaMap getFreeGoodsPromotionList(@RequestBody FreeGoodsPromotion param) {
		GagaMap result = new GagaMap();

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

		result.set("pageing", param);
		result.set("freeGoodsList", freegiftService.getFreeGoodsPromotionList(param));

		return result;
	}

	/**
	 * 사은품 프로모션 등록 팝업창
	 * @param param
	 * @return ModelAndView
	 * @author xodud1202
	 * @since 2020. 12. 23
	 */
	@ResponseBody
	@GetMapping("/freegoods/promotion/popup/form")
	public ModelAndView freeGoodsRegiForm(FreeGoodsPromotion param) {
		ModelAndView mav = new ModelAndView();

		String num = "";
		CommonCode temp = new CommonCode();

		// 행사기간 시 리스트 세팅
		Collection<CommonCode> hhList = new ArrayList<CommonCode>();
		for (int i = 0; i < 24; i++) {
			num = "";
			temp = new CommonCode();
			if (i < 10) {
				num = "0" + i;
			} else {
				num = String.valueOf(i);
			}

			temp.setCd(num);
			temp.setCdNm(num + "시");
			hhList.add(temp);
		}

		// 행사기간 분 리스트 세팅
		Collection<CommonCode> mmList = new ArrayList<CommonCode>();
		for (int i = 0; i < 60; i++) {
			num = "";
			temp = new CommonCode();
			if (i < 10) {
				num = "0" + i;
			} else {
				num = String.valueOf(i);
			}

			temp.setCd(num);
			temp.setCdNm(num + "분");
			mmList.add(temp);
		}

		mav.addObject("hhList", hhList);	// 행사기간 시 리스트 세팅
		mav.addObject("mmList", mmList);	// 행사기간 분 리스트 세팅
		String[] exceptCds = {"G008_00"};		// 상품상태
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		mav.addObject("param", param);

		mav.setViewName("marketing/FreeGoodsPromotionRegiForm");
		return mav;
	}

	/**
	 * 사은품 프로모션 상세 조회
	 * @author xodud1202
	 * @since 2021. 01. 28
	 */
	@PostMapping("/freegoods/promotion/detail")
	@ResponseBody
	public GagaMap getFreeGoodsPromotionDetail(FreeGoodsPromotion param) {
		return freegiftService.getFreegiftDetailInfo(param);
	}

	/**
	 * 사은품 프로모션 등록
	 * @param param
	 * @return ModelAndView
	 * @author xodud1202
	 * @since 2021. 01. 14
	 */
	@ResponseBody
	@PostMapping("/freegoods/promotion/save")
	public GagaResponse freeGoodsPromotionSave(@RequestBody FreeGoodsPromotion param) {
		try {
			freegiftService.saveFreegoodsPromotionInfo(param);
		} catch (Exception e) {
			e.printStackTrace();
			return super.error(message.getMessage("FAIL_0001"));
		}

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

	/**
	 * 사은품 프로모션 등록
	 * @param param
	 * @return ModelAndView
	 * @author xodud1202
	 * @since 2021. 01. 14
	 */
	@ResponseBody
	@PostMapping("/freegoods/promotion/name/save")
	public GagaResponse freeGoodsPromotionNameSave(@RequestBody FreeGoodsPromotion param) {
		try {
			freegiftService.saveFreegoodsPromotionNameInfo(param);
		} catch (Exception e) {
			e.printStackTrace();
			return super.error(message.getMessage("FAIL_0001"));
		}

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

	/**
	 * 사은품 프로모션 등록
	 * @param param
	 * @return ModelAndView
	 * @author xodud1202
	 * @since 2021. 01. 14
	 */
	@ResponseBody
	@PostMapping("/freegoods/promotion/change/stat")
	public GagaResponse freeGoodsPromotionChangeStat(@RequestBody FreeGoodsPromotion param) {
		try {
			freegiftService.updateFreegoodsPromotionStat(param);
		} catch (Exception e) {
			e.printStackTrace();
			return super.error(message.getMessage("FAIL_0001"));
		}

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

	/* // xodud1202 진행 */

	/* JSM 진행 */
	/**
	 * 쿠폰 리스트 목록 화면
	 * @author xyzp1539
	 * @since 2020-12-21
	 */
	@GetMapping("/coupon/form")
	public ModelAndView couponListForm() {
		ModelAndView mav = new ModelAndView();

		// 쿠폰상태 목록
		mav.addObject("cpnStatList", rendererService.getAvailCommonCodeList("G232"));
		// 쿠폰 유형 조회
		mav.addObject("cpnTypeList", rendererService.getCommonCodeList("G230", "Y"));
		// 할인 유형 조회
		mav.addObject("dcWayList", rendererService.getCommonCodeList("G240"));
		// 사이트 조회
		mav.addObject("siteCdList", rendererService.getCommonCodeList("G000"));
		// 사용가능 고객구분 조회
		mav.addObject("usableCustGbList", rendererService.getCommonCodeList("G100"));

		mav.setViewName("marketing/CouponListForm");

		return mav;
	}

	/**
	 * 쿠폰 리스트 조회
	 * @param  param
	 * @return GagaMap
	 * @author xyzp1539
	 * @since 2020-12-22
	 */
	@PostMapping("/coupon/list")
	@ResponseBody
	public GagaMap getCouponList(@RequestBody Coupon param) {
		GagaMap result = new GagaMap();

//		ArrayList<Coupon> cpnList = coreCouponService.getCouponList(param);
//		int cpnTotCnt = coreCouponService.getCouponListCnt(param);

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

		result.set("pageing", param);
//		result.set("cpnTotCnt", cpnTotCnt);
		result.set("cpnList", coreCouponService.getCouponList(param));

		return result;
	}

	/**
	 * 쿠폰 등록 팝업 화면
	 * @return ModelAndView
	 * @author xyzp1539
	 * @since 2020-12-23
	 */
	@GetMapping("/coupon/popup/form")
	@ResponseBody
	public ModelAndView couponCreatePopup(@RequestParam(value = "mode") String mode, @RequestParam(value = "cpnId", required = false) Integer cpnId) {
		ModelAndView mav = new ModelAndView();
		String num = "";
		int issueCnt = 0;

		// 일시 시 리스트 세팅
		Collection<CommonCode> hhList = new ArrayList<CommonCode>();
		for (int i = 0; i < 24; i++) {
			num = "";
			CommonCode temp = new CommonCode();
			if (i < 10) {
				num = "0" + i;
			} else {
				num = String.valueOf(i);
			}

			temp.setCd(num);
			temp.setCdNm(num + "시");

			hhList.add(temp);
		}
		// 일시 분 리스트 세팅
		Collection<CommonCode> mmList = new ArrayList<CommonCode>();
		for (int i = 0; i < 60; i++) {
			num = "";
			CommonCode temp = new CommonCode();
			if (i < 10) {
				num = "0" + i;
			} else {
				num = String.valueOf(i);
			}
			temp.setCd(num);
			temp.setCdNm(num + "분");

			mmList.add(temp);
		}
		// 시간 분 리스트 세팅
		mav.addObject("mmList", mmList);
		// 시간 시 리스트 세팅
		mav.addObject("hhList", hhList);
		// 상품상태
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));
		// 입점업체 조회
		mav.addObject("ibSupplyCompList", rendererService.getSupplyCompanyList("", "N"));
		// 할인 쿠폰 코드 조회
		mav.addObject("dcCdList", rendererService.getCommonCodeList("G233", "Y"));
		// 정상/이월 조회
		mav.addObject("formalGbList", rendererService.getCommonCodeList("G009"));
		// 카테고리 구분 조회
		mav.addObject("cateGbList", rendererService.getCommonCodeList("G032"));
		// 자사 브랜드 조회
		mav.addObject("selfBrandList", rendererService.getSelfBrandList());
		// 사이트코드 조회
		mav.addObject("siteCdList", rendererService.getCommonCodeList("G000"));
		// 쿠폰상태 조회
		mav.addObject("cpnStatList", rendererService.getCommonCodeList("G232"));
		// 쿠폰 유형 조회
		mav.addObject("cpnTypeList", rendererService.getCommonCodeList("G230", "Y"));
		// 사용가능 고객구분 조회
		String[] exceptCds1 = {"G100_00"};
		mav.addObject("usableCustGbList", rendererService.getCommonCodeList("G100", "Y", exceptCds1));
		// 사용가능 고객등급 조회
		mav.addObject("usableCustGradeList", rendererService.getCommonCodeList("G110"));
		// 재발급 여부 조회
		mav.addObject("reissuanceList", rendererService.getCommonCodeList("G231"));
		// 할인방식 조회
		mav.addObject("dcWayList", rendererService.getCommonCodeList("G240"));
		// 쿠폰다운로드 방식 조회
		mav.addObject("dnGbList", rendererService.getCommonCodeList("G058"));
		// 결제수단 조회
		String[] exceptCds2 = {"INICIS", "ISTYLE", "NAVER_ORDER", "NICE"};
		mav.addObject("payTypeList", rendererService.getCommonCodeList("G015", "Y", exceptCds2));
		// 상위제휴채널 조회
		mav.addObject("upperAfLinkCdList", rendererService.getCommonCodeList("G053"));
		// 선착순쿠폰 조회
		mav.addObject("limitedTimeCpnList", new Coupon());
		// 제휴채널 조회
		mav.addObject("channelList", rendererService.getCommonCodeList("G053", "Y"));
		// 이미 쿠폰 아이디가 있으면 적용대상 조회
		if (mode.equals("U")) {
			issueCnt = coreCouponService.getCouponIssueCnt(cpnId);
			// 쿠폰상세조회
			mav.addObject("cpnDetail", coreCouponService.getCouponDetail(cpnId));
			// 쿠폰적용대상 - 공급업체 조회
			mav.addObject("cpnDtlRefvalSupplyCompList", coreCouponService.getCouponRefvalSupplyCompList(cpnId));
			// 쿠폰적용대상 - 적용상품 조회
			mav.addObject("cpnDtlRefvalApplyGoodsList", coreCouponService.getCouponRefvalGoodsList(cpnId, "G260_10"));
			// 쿠폰적용대상 - 카테고리 조회
			mav.addObject("cpnDtlRefvalCateList", coreCouponService.getCouponRefvalCategoryList(cpnId));
			// 쿠폰적용대상 - 브랜드 조회
			mav.addObject("cpnDtlRefvalBrandList", coreCouponService.getCouponRefvalBrandList(cpnId));
			// 쿠폰적용대상 - 제외상품 조회
			mav.addObject("cpnDtlRefvalExceptGoodsList", coreCouponService.getCouponRefvalGoodsList(cpnId, "G260_14"));
			// 쿠폰 입점업체분담율 조회
			mav.addObject("cpnDtlBurdenList", coreCouponService.getCouponBurdenList(cpnId));
			// 시리얼 및 난수 쿠폰 조회
			mav.addObject("randomCpnList", coreCouponService.getRandomCouponInfo(cpnId));
			// 쿠폰사용가능고객구분 조회
			mav.addObject("cpnCustGbList", coreCouponService.getCouponCustGbList(cpnId));
			// 쿠폰사용가능고객등급 조회
			mav.addObject("cpnCustGradeList", coreCouponService.getCouponCustGradeList(cpnId));
			// 쿠폰사용가능결제수단 조회
			mav.addObject("cpnPayTypeList", coreCouponService.getCouponPayTypeList(cpnId));
			// 선착순쿠폰 조회
			mav.addObject("limitedTimeCpnList", coreCouponService.getLimitedTimeCouponList(cpnId));
			// 등록했던 제휴채널
			mav.addObject("afChannelList", coreCouponService.getCouponAfChannelList(cpnId));
		}

		//issueCnt = 3;

		mav.addObject("mode", mode);
		mav.addObject("issueCnt", issueCnt);

		mav.setViewName("marketing/CouponPopupForm");
		return mav;
	}

	/**
	 * 쿠폰 저장
	 * @param coupon - 쿠폰 정보
	 * @return
	 * @author xyzp1539
	 * @since 2021. 1. 11
	 */
	@PostMapping("/coupon/save")
	@ResponseBody
	public GagaResponse saveCoupon(@RequestBody Coupon coupon) {
		log.info("couponSave : {}", coupon);
		coupon.setRegNo(TsaSession.getInfo().getUserNo());
		coupon.setUpdNo(TsaSession.getInfo().getUserNo());
		String result = coreCouponService.saveCoupon(coupon);
		if (!"SUCCESS".equals(result)) {
			return super.error(message.getMessage(result));
		}

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

	/**
	 * 쿠폰 적용대상 삭제수정
	 * @param CouponRefval
	 * @return
	 * @author xyzp1539
	 * @since 2021-01-19
	 */
	@PostMapping("/coupon/refval/update")
	@ResponseBody
	public GagaResponse updateCouponRefval(@RequestBody CouponRefval CouponRefval) {
		log.info("couponSave : {}", CouponRefval);
		CouponRefval.setUpdNo(TsaSession.getInfo().getUserNo());
		coreCouponService.updateCouponRefval(CouponRefval);

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

	/**
	 * 쿠폰발행팝업
	 * @param
	 * @return
	 * @author xyzp1539
	 * @since 2021-01-21
	 */
	@GetMapping("/coupon/cpnPubForCust/popup/form")
	@ResponseBody
	public ModelAndView couponPubForCustPopup() {
		ModelAndView mav = new ModelAndView();
		String num = "";
		// 일시 시 리스트 세팅
		Collection<CommonCode> hhList = new ArrayList<CommonCode>();
		for (int i = 0; i < 24; i++) {
			num = "";
			CommonCode temp = new CommonCode();
			if (i < 10) {
				num = "0" + i;
			} else {
				num = String.valueOf(i);
			}

			// 상품상태
			String[] exceptCds = {"G008_00"};
			mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));

			temp.setCd(num);
			temp.setCdNm(num + "시");

			hhList.add(temp);
		}
		// 일시 분 리스트 세팅
		Collection<CommonCode> mmList = new ArrayList<CommonCode>();
		for (int i = 0; i < 60; i++) {
			num = "";
			CommonCode temp = new CommonCode();
			if (i < 10) {
				num = "0" + i;
			} else {
				num = String.valueOf(i);
			}
			temp.setCd(num);
			temp.setCdNm(num + "분");

			mmList.add(temp);
		}
		// 시간 분 리스트 세팅
		mav.addObject("mmList", mmList);
		// 시간 시 리스트 세팅
		mav.addObject("hhList", hhList);
		// 사이트조회
		mav.addObject("siteCdList", rendererService.getCommonCodeList("G000"));
		// 사용가능 고객구분 조회
		String[] exceptCds1 = {"G100_00"};
		mav.addObject("usableCustGbList", rendererService.getCommonCodeList("G100", "Y", exceptCds1));
		// 사용가능 고객등급 조회
		mav.addObject("usableCustGradeList", rendererService.getCommonCodeList("G110"));
		// 쿠폰발행사유 조회
		mav.addObject("cpnPubReasonList", rendererService.getCommonCodeList("G068"));

		mav.setViewName("marketing/CouponPubForCustPopupForm");

		return mav;
	}

	/**
	 * 고객 쿠폰 발행
	 * @param  custCoupon
	 * @return
	 * @author xyzp1539
	 * @since 2021-01-21
	 */
	@PostMapping("/coupon/insertCustPub")
	@ResponseBody
	public GagaResponse saveCouponCustPub(@RequestBody CustCoupon custCoupon) {
		custCoupon.setRegNo(TsaSession.getInfo().getUserNo());
		custCoupon.setUpdNo(TsaSession.getInfo().getUserNo());
		coreCouponService.saveCouponCustPub(custCoupon);
		return super.ok(message.getMessage("SUCC_0006"));

	}
	/* // JSM 진행 */

	/* CSB 진행 */
	/**
	 * 다다익선 화면
	 * @author bin2107
	 * @since 2020. 12. 28
	 */
	@GetMapping("/morebetter/form")
	public ModelAndView morebetterForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("marketing/MorebetterListForm");
		return mav;
	}

	/**
	 * 다다익선 리스트 조회
	 * @author bin2107
	 * @since 2020. 12. 28
	 */
	@PostMapping("/morebetter/list")
	@ResponseBody
	public GagaMap getMorebetterList(@RequestBody MoreBetter param) {
		GagaMap result = new GagaMap();

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

		result.set("pageing", param);
		result.set("morebetterList", morebetterService.getMorebetterList(param));

		return result;
	}

	/**
	 * 다다익선 등록 화면
	 *
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2020. 12. 29
	 */
	@ResponseBody
	@GetMapping("/morebetterPopup/form")
	public ModelAndView morebetterRegForm(@RequestParam(value = "mode") String mode, @RequestParam(value = "tmtbSeq", required = false) Integer tmtbSeq, MoreBetter moreBetter) {
		ModelAndView mav = new ModelAndView();

		// 상품상태 : 등록일때는 '대기'
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));

		// 할인구간 목록
		mav.addObject("sectionGbList", rendererService.getAvailCommonCodeList("G810"));

		// 할인구분 목록
		mav.addObject("dcWayList", rendererService.getAvailCommonCodeList("G240"));

		// 적용 상품구분 목록
		String[] exceptGoodsCds = {"G800_30", "G800_40"};
		mav.addObject("applyGoodsGbList", rendererService.getCommonCodeList("G800", "Y", exceptGoodsCds));

		// 제외 상품구분 목록
		mav.addObject("exceptGoodsGbList", rendererService.getAvailCommonCodeList("G800"));

		// 다다익선 상태 목록
		mav.addObject("tmtbStatList", rendererService.getAvailCommonCodeList("G232"));

		if ("U".equals(mode)) {
			// 다다익선 정보
			mav.addObject("tmtbMstInfo", morebetterService.getMorebetterMstInfo(tmtbSeq));
			mav.addObject("tmtbSupplyCompList", morebetterService.getMorebetterSupplyCompList(tmtbSeq, "G260_13"));
			mav.addObject("tmtbBrandList", morebetterService.getMorebetterBrandList(tmtbSeq, "G260_12"));
			mav.addObject("tmtbApplyGoodsList", morebetterService.getMorebetterApplyGoodsList(tmtbSeq, "G260_10"));
			mav.addObject("tmtbExceptGoodsList", morebetterService.getMorebetterExceptGoodsList(tmtbSeq, "G260_10"));
			mav.addObject("tmtbSectionValList", morebetterService.getMorebetterSectionValList(tmtbSeq));
			mav.addObject("tmtbBurdenList", morebetterService.getMorebetterBurdenList(tmtbSeq));
		} else {
			mav.addObject("tmtbMstInfo", new MoreBetter());
			mav.addObject("tmtbSupplyCompList", new MoreBetterGoods());
			mav.addObject("tmtbBrandList", new MoreBetterGoods());
			mav.addObject("tmtbApplyGoodsList", new MoreBetterGoods());
			mav.addObject("tmtbExceptGoodsList", new MoreBetterGoods());
			mav.addObject("tmtbSectionValList", new MoreBetterSection());
			mav.addObject("tmtbBurdenList", new MoreBetterBurden());
			// 날짜형식
			MoreBetter moreBetter1 = new MoreBetter();
			Calendar calendar = Calendar.getInstance();
			calendar.add(Calendar.DAY_OF_MONTH, 1);

			moreBetter1.setEventStdt(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
			moreBetter1.setEventEdHH(new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime()));
			moreBetter1.setEventEdHH("24");
			moreBetter1.setEventEdMM("00");
			mav.addObject("tmtbMstInfo", moreBetter1);
		}

		mav.addObject("mode", mode);
		mav.addObject("tmtbSeq", tmtbSeq);
		mav.addObject("params", moreBetter);
		log.info("MorebetterPopupForm tmtbSeq::{}", tmtbSeq);
		mav.setViewName("marketing/MorebetterPopupForm");
		return mav;
	}

	/**
	 * 다다익선 등록
	 *
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 5
	 */
	@PostMapping("/morebetter/save")
	@ResponseBody
	public GagaMap saveMorebetterDetail(@RequestBody MoreBetter moreBetter) {
		String result = "";
		GagaMap map = new GagaMap();

		try {
			MoreBetterGoods moreBetterGoods = new MoreBetterGoods();
			// 적용상품 으로 tb_goods 조회해서 temp 테이블 insert
			morebetterService.insertMorebetterApplyGoodsTemp(moreBetter);
			morebetterService.saveMoreBetterDetail(moreBetter);

			moreBetterGoods.setTmtbSq(moreBetter.getTmtbSq());
			moreBetterGoods.setRegNo(TsaSession.getInfo().getUserNo());
			// 다른 다다에서 사용중인 상품 조회
			Collection<MoreBetterGoods> duplicateGoodsList = morebetterService.getMorebetterDuplicateList(moreBetterGoods);
			// SELECT -> 지금 내가 선택한 업체&브랜드 + 적용상품에 해당하는 상품 조회 MINUS TMTB_GOODS_TEMP 상품
			// 조회 건수 있으면 -> 해당 상품코드 엑셀로 던져주기
			if (duplicateGoodsList.size() > 0) {
				map.set("duplicateYn", "Y");
				map.set("duplicateGoodsList", duplicateGoodsList);
			} else {
				// 조회 건수 없으면 -> 저장으로 넘어감
				map.set("duplicateYn", "N");
			}
			map.set("message", message.getMessage("SUCC_0001"));
		} catch (Exception e) {
			e.printStackTrace();
			map.set("message", message.getMessage("FAIL_0001"));
			return map;
		}
		return map;
	}

	/**
	 * 다다익선 공급업체 삭제
	 *
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 12
	 */
	@PostMapping("/morebetter/supplyCompany/delete")
	@ResponseBody
	public GagaResponse deleteTmtbSupplyCompanyList(@RequestBody MoreBetterGoods moreBetterGoods) {
		morebetterService.deleteTmtbSupplyCompanyList(moreBetterGoods);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 다다익선 브랜드 삭제
	 *
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 12
	 */
	@PostMapping("/morebetter/brand/delete")
	@ResponseBody
	public GagaResponse deleteTmtbBrandList(@RequestBody MoreBetterGoods moreBetterGoods) {
		morebetterService.deleteTmtbBrandList(moreBetterGoods);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 다다익선 적용상품 삭제
	 *
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 12
	 */
	@PostMapping("/morebetter/applyGoods/delete")
	@ResponseBody
	public GagaResponse deleteTmtbApplyGoodsList(@RequestBody MoreBetterGoods moreBetterGoods) {
		morebetterService.deleteTmtbApplyGoodsList(moreBetterGoods);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 다다익선 제외상품 삭제
	 *
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 12
	 */
	@PostMapping("/morebetter/exceptGoods/delete")
	@ResponseBody
	public GagaResponse deleteTmtbExceptGoodsList(@RequestBody MoreBetterGoods moreBetterGoods) {
		morebetterService.deleteTmtbExceptGoodsList(moreBetterGoods);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 다다익선 할인구간 삭제
	 *
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 5
	 */
	@PostMapping("/morebetter/sectionVal/delete")
	@ResponseBody
	public GagaResponse deleteTmtbSectionValList(@RequestBody MoreBetterSection moreBetterSection) {
		morebetterService.deleteTmtbSectionValList(moreBetterSection);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 다다익선 업체분담율 삭제
	 *
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 12
	 */
	@PostMapping("/morebetter/burden/delete")
	@ResponseBody
	public GagaResponse deleteTmtbBurdenList(@RequestBody MoreBetterBurden moreBetterBurden) {
		morebetterService.deleteTmtbBurdenList(moreBetterBurden);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 다다익선 진행 상태 변경
	 *
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 1. 26
	 */
	@PostMapping("/morebetter/changeStat")
	@ResponseBody
	public GagaMap updateMorebetterStat(@RequestBody MoreBetter moreBetter) {
		GagaMap map = new GagaMap();

		try {
			log.info("getTmtbStat :::{}", moreBetter.getTmtbStat());
			MoreBetterGoods moreBetterGoods = new MoreBetterGoods();

			if ("G232_11".equals(moreBetter.getTmtbStat())) {
				// 적용상품 으로 tb_goods 조회해서 temp 테이블 insert
				morebetterService.insertMorebetterApplyGoodsTemp(moreBetter);

				// 다른 다다에서 사용중인 상품 조회
				moreBetterGoods.setTmtbSq(moreBetter.getTmtbSq());
				moreBetterGoods.setRegNo(TsaSession.getInfo().getUserNo());
				Collection<MoreBetterGoods> duplicateGoodsList = morebetterService.getMorebetterDuplicateList(moreBetterGoods);

				// 조회 건수 있으면 -> 해당 상품코드 엑셀로 던져주기
				if (duplicateGoodsList.size() > 0) {
					map.set("duplicateYn", "Y");
					map.set("duplicateGoodsList", duplicateGoodsList);
					map.set("message", message.getMessage("FAIL_0001"));
				} else {
					// 조회 건수 없으면 -> 저장으로 넘어감
					map.set("duplicateYn", "N");
					morebetterService.saveMoreBetterDetail(moreBetter);
					//morebetterService.updateMorebetterStat(moreBetter);
					map.set("message", message.getMessage("SUCC_0002"));
				}
			} else {
				morebetterService.updateMorebetterStat(moreBetter);
				map.set("message", message.getMessage("SUCC_0002"));
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.set("message", message.getMessage("FAIL_0001"));
			return map;
		}

		return map;
	}

	/**
	 * 쿠폰발급받은 회원리스트 팝업
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021-02-03
	 */
	@GetMapping("/coupon/pubCust/popup/form")
	@ResponseBody
	public ModelAndView couponPubCustListPopup(@RequestParam(value = "cpnId", required = true) Integer cpnId) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("cpnPubCustList", coreCouponService.getCpnPubCustList(cpnId));
		TscSession.setAttribute("maskingYn", TsaSession.getInfo().getMaskingYn());
		mav.setViewName("marketing/CouponPubCustListPopupForm");
		return mav;
	}

	/**
	 * 선착순쿠폰 삭제
	 *
	 * @param
	 * @return
	 * @author bin2107
	 * @since 2021. 2. 5
	 */
	@PostMapping("/coupon/limitedtime/coupon/update")
	@ResponseBody
	public GagaResponse updateLimitedTimeCouponList(@RequestBody CouponLimitedTime couponLimitedTime) {
		couponLimitedTime.setRegNo(TsaSession.getInfo().getUserNo());
		couponLimitedTime.setUpdNo(TsaSession.getInfo().getUserNo());
		coreCouponService.updateLimitedTimeCouponList(couponLimitedTime);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 쿠폰 상태 변경
	 * @param coupon
	 * @return
	 * @author bin2107
	 * @since 2021. 02. 05
	 */
	@ResponseBody
	@PostMapping("/coupon/changeStat")
	public GagaResponse updateCouponStat(@RequestBody Coupon coupon) {
		try {
			coupon.setUpdNo(TsaSession.getInfo().getUserNo());
			coreCouponService.updateCouponStat(coupon);
		} catch (Exception e) {
			e.printStackTrace();
			return super.error(message.getMessage("FAIL_0001"));
		}

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

	/* 최수환 진행 */
	/**
	 * 메일헤더푸터관리 화면
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 11
	 */
	@GetMapping("/mail/headerfooter/form")
	public ModelAndView mailHeaderFooterForm() {
		ModelAndView mav = new ModelAndView("marketing/MailHeaderFooterForm");
		return mav;
	}

	/**
	 * 메일헤더푸터 목록
	 * @param mailhf - 메일헤더푸터 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 13
	 */
	@PostMapping("/mail/headerfooter/list")
	@ResponseBody
	public Collection<MailHeaderFooter> getMailHeaderFooterList(@RequestBody MailHeaderFooter mailhf) {
		return mailTemplateService.getMailHeaderFooterList(mailhf);
	}

	/**
	 * 메일헤더푸터 상세 화면
	 * @param mode - 모드(N:신규, U:상세)
	 * @param mailhfSq - 메일헤더푸터일련번호
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 13
	 */
	@GetMapping("/mail/headerfooter/detail/form")
	public ModelAndView mailHeadeFooterDetailForm(@RequestParam(value = "mode") String mode, @RequestParam(value = "mailhfSq", required = false) Integer mailhfSq) {
		ModelAndView mav = new ModelAndView();

		// 모드 값
		mav.addObject("mode", mode);

		if ("U".equals(mode)) {
			mav.addObject("mailhfInfo", mailTemplateService.getMailHeaderFooter(mailhfSq));
		}

		mav.setViewName("marketing/MailHeaderFooterDetailForm");

		return mav;
	}

	/**
	 * 메일헤더푸터 저장 처리
	 * @param mailhf - 메일헤더푸터 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 13
	 */
	@PostMapping("/mail/headerfooter/save")
	@ResponseBody
	public GagaResponse saveMailHeaderFooter(@RequestBody MailHeaderFooter mailhf) {
		mailTemplateService.saveMailHeaderFooter(mailhf);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 메일헤더푸터 삭제
	 * @param mailhfSq - 메일헤더푸더일련번호
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 13
	 */
	@PostMapping("/mail/headerfooter/delete/{mailhfSq}")
	@ResponseBody
	public GagaResponse deleteMailHeaderFooterList(@PathVariable Integer mailhfSq) {
		mailTemplateService.deleteMailHeaderFooter(mailhfSq);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 메일헤더푸터 목록 삭제
	 * @param mailhfList - 메일헤더푸더 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 13
	 */
	@PostMapping("/mail/headerfooter/list/delete")
	@ResponseBody
	public GagaResponse deleteMailHeaderFooterList(@RequestBody Collection<MailHeaderFooter> mailhfList) {
		if (mailhfList == null || mailhfList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		mailTemplateService.deleteMailHeaderFooterList(mailhfList);

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

	/**
	 * 메일템플릿관리 화면
	 * @param
	 * @return
	 * @author csh9191
	 * @since 2021. 02. 05
	 */
	@GetMapping("/mailtemplate/form")
	public ModelAndView mailTemplateForm() {
		ModelAndView mav = new ModelAndView("marketing/MailTemplateForm");
		return mav;
	}

	/**
	 * 메일템플릿 목록
	 * @param mailTemplate - 메일템플릿 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 11
	 */
	@PostMapping("/mailtemplate/list")
	@ResponseBody
	public Collection<MailTemplate> getMailTemplateList(@RequestBody MailTemplate mailTemplate) {
		return mailTemplateService.getMailTemplateList(mailTemplate);
	}

	/**
	 * 메일템플릿 상세 화면
	 * @param mode - 모드(N:신규, U:상세)
	 * @param mailtSq - 메일템플릿일련번호
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 11
	 */
	@GetMapping("/mailtemplate/detail/form")
	public ModelAndView mailTemplateDetailForm(@RequestParam(value = "mode") String mode, @RequestParam(value = "mailtSq", required = false) Integer mailtSq) {
		ModelAndView mav = new ModelAndView("marketing/MailTemplateDetailForm");

		// 메일헤더 목록
		mav.addObject("mhList", mailTemplateService.getMailHeaderFooterComboList("H"));

		// 메일푸터 목록
		mav.addObject("mfList", mailTemplateService.getMailHeaderFooterComboList("F"));

		// 판매상태
		String[] mailCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", mailCds));

		mav.addObject("mode", mode);

		if ("U".equals(mode)) {
			// 메일템플릿 정보
			MailTemplate mtInfo = coreMailTemplateService.getMailTemplate(mailtSq);
			mav.addObject("mtInfo", mtInfo);
		}

		return mav;
	}

	/**
	 * 메일템플릿코너 목록
	 * @param mailtSq - 메일템플릿일련번호
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 12
	 */
	@GetMapping("/mailtemplate/corner/list/{mailtSq}")
	@ResponseBody
	public Collection<MailTemplateCorner> getMailTemplateCornerList(@PathVariable Integer mailtSq) {
		return coreMailTemplateService.getMailTemplateCornerList(mailtSq);
	}

	/**
	 * 메일템플릿 저장 처리
	 * @param mailTemplate - 메일템플릿 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 11
	 */
	@PostMapping("/mailtemplate/save")
	@ResponseBody
	public GagaResponse saveMailTemplate(@RequestBody MailTemplate mailTemplate) {
		mailTemplateService.saveMailTemplate(mailTemplate);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 메일템플릿 목록 삭제
	 * @param mailTemplateList - 메일템플릿 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 11
	 */
	@PostMapping("/mailtemplate/list/delete")
	@ResponseBody
	public GagaResponse deleteMailTemplateList(@RequestBody Collection<MailTemplate> mailTemplateList) {
		if (mailTemplateList == null || mailTemplateList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		mailTemplateService.deleteMailTemplateList(mailTemplateList);

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

	/**
	 * 메일템플릿코너 삭제
	 * @param mailtcSq - 메일템플릿코너일련번호
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 12
	 */
	@PostMapping("/mailtemplate/corner/delete/{mailtcSq}")
	@ResponseBody
	public GagaResponse deleteMktCorner(@PathVariable Integer mailtcSq) {
		mailTemplateService.deleteMailTemplateCorner(mailtcSq);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 메일템플릿코너상품 목록 삭제
	 * @param mtcgList - 메일템플릿코너상품 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 12
	 */
	@PostMapping("/mailtemplate/goods/list/delete")
	@ResponseBody
	public GagaResponse deleteMailTemplateCornerGoodsList(@RequestBody Collection<MailTemplateGoods> mtcgList) {
		if (mtcgList == null || mtcgList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		mailTemplateService.deleteMailTemplateCornerGoodsList(mtcgList);

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

	/**
	 * 메일템플릿관리 - 메일미리보기
	 * @param mailtSq - 메일템플릿일련번호
	 * @return
	 * @author gagamel
	 * @since 2021. 5. 11
	 */
	@GetMapping("/mailtemplate/preview/form/{mailtSq}")
	@ResponseBody
	public ModelAndView mailTemplatePreviewForm(@PathVariable Integer mailtSq) {
		ModelAndView mav = new ModelAndView("marketing/MailTemplatePreviewForm");

		// 메일템플릿 미리보기 정보
		mav.addObject("previewInfo", coreMailTemplateService.getMailTemplatePreview(mailtSq));

		return mav;
	}
	/* // CSB 진행 */

	/**
	 * 쿠폰조회 팝업
	 * @param returnCode - 반환할코드. 필수
	 * @param returnName - 반환할명칭. 필수
	 * @param cpnNm - 쿠폰명. 옵션
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 8
	 */
	@GetMapping("/coupon/retrieve/form")
	@ResponseBody
	public ModelAndView couponRetrieveForm(@RequestParam(value = "returnCode") String returnCode, @RequestParam(value = "returnName") String returnName, @RequestParam(value = "cpnNm", required = false) String cpnNm) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("returnCode", returnCode);
		mav.addObject("returnName", returnName);
		mav.addObject("cpnNm", StringUtils.defaultString(cpnNm, ""));

		// 사이트 목록
		mav.addObject("siteList", rendererService.getAvailCommonCodeList("G000"));

		// 사용가능고객구분 목록
		mav.addObject("usableCustGbList", rendererService.getAvailCommonCodeList("G100"));

		// 쿠폰유형 목록
		mav.addObject("cpnTypeList", rendererService.getAvailCommonCodeList("G230"));

		// 할인방식 목록
		mav.addObject("dcWayList", rendererService.getAvailCommonCodeList("G240"));

		// 쿠폰상태 목록
		mav.addObject("cpnStatList", rendererService.getAvailCommonCodeList("G232"));
		mav.setViewName("marketing/CouponRetrievePopupForm");

		return mav;
	}

	/**
	 * 쿠폰조회 목록
	 * @param coupon - 쿠폰 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 8
	 */
	@PostMapping("/coupon/retrieve/list")
	@ResponseBody
	public Collection<Coupon> getCouponRetrieveList(@RequestBody Coupon coupon) {
		return coreCouponService.getCouponRetrieveList(coupon);
	}

	/**
	 * 포인트부여 팝업
	 * @param elementCustNo - 고객일련번호
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 1. 27
	 */
	@GetMapping("/point/grant/popup/form")
	@ResponseBody
	public ModelAndView pointGrantPopupForm(@RequestParam(value = "elementCustNo") String elementCustNo) {
		if (StringUtils.isBlank(elementCustNo)) {
			throw new IllegalStateException("고객정보가 없습니다.");
		}

		ModelAndView mav = new ModelAndView();

		mav.addObject("elementCustNo", elementCustNo);

		// 사이트 목록
		mav.addObject("siteCdList", rendererService.getAvailCommonCodeList("G000"));

		// 포인트발생구분
		mav.addObject("occurGbList", rendererService.getCommonCodeList("G069", "Y"));

		mav.addObject("expBeDt", GagaDateUtil.getToday("yyyy-MM-dd"));

		User user = systemService.getUser(TsaSession.getInfo().getUserNo());

		// 관리자 포인트할당금액
		mav.addObject("pntAssignAmt", user.getPntAssignAmt());

		mav.setViewName("marketing/PointGrantPopupForm");
		return mav;
	}

	/**
	 * 포인트 부여
	 * @param point - 포인트 정보
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 1. 27
	 */
	@PostMapping("/point/save")
	@ResponseBody
	public GagaResponse savePoint(@RequestBody Point point) {
		if (point.getCustNo() == null || point.getCustNo() <= 0 ) {
			throw new IllegalStateException("고객정보가 없습니다.");
		}
		Integer userNo = TsaSession.getInfo().getUserNo();
		point.setRegNo(userNo);
		point.setUpdNo(userNo);
		point.setPntUploadStat(TscConstants.PntUploadStat.APPLY_COMPLETE.value());
		point.setGvPntAmt(point.getPntAmt());
		point.setRmPntAmt(point.getPntAmt());
		corePointService.saveCustomerPoint(point);
		return super.ok(message.getMessage("SUCC_0004"));
	}

	/**
	 * 쿠폰발급 팝업
	 * @param elementCustNo - 고객일련번호
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 1. 28
	 */
	@GetMapping("/coupon/issue/popup/form")
	@ResponseBody
	public ModelAndView couponIssuePopupForm(@RequestParam(value = "elementCustNo") String elementCustNo) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("elementCustNo", elementCustNo);

		// 사이트 목록
		mav.addObject("siteList", rendererService.getAvailCommonCodeList("G000"));

		// 사용가능고객구분 목록
		mav.addObject("usableCustGbList", rendererService.getAvailCommonCodeList("G100"));

		// 쿠폰유형 목록
		mav.addObject("cpnTypeList", rendererService.getAvailCommonCodeList("G230"));

		// 할인방식 목록
		mav.addObject("dcWayList", rendererService.getAvailCommonCodeList("G240"));

		// 쿠폰발행사유 조회
		mav.addObject("cpnPubReasonList", rendererService.getCommonCodeList("G068"));

		mav.setViewName("marketing/CouponIssuePopupForm");

		return mav;
	}

	/**
	 * 회원상세 - 쿠폰발급
	 * @param custCoupon - 쿠폰정보
	 * @return GagaResponse
	 * @author jsshin
	 * @since 2021. 1. 29
	 */
	@PostMapping("/coupon/issue/save")
	@ResponseBody
	public GagaResponse saveCouponIssue(@RequestBody CustCoupon custCoupon) {
		Integer userNo = TsaSession.getInfo().getUserNo();
		custCoupon.setRegNo(userNo);
		custCoupon.setUpdNo(userNo);
		coreCouponService.createCustCoupon(custCoupon);
		return super.ok(message.getMessage("SUCC_0006"));
	}

	/**
	 *   카드관련 작업 시작 - eskim
	 */

	/**
	 * 카드무이자할부 관리
	 * @param
	 * @return
	 * @author eskim
	 * @since 2021. 1. 29
	 */
	@GetMapping("/card/interest/form")
	@ResponseBody
	public ModelAndView cardInterestForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("marketing/CardInterestForm");
		return mav;
	}

	/**
	 * 카드무이자할부 목록
	 * @param cardPromotion
	 * @return
	 * @author eskim
	 * @since 2021. 1. 29
	 */
	@PostMapping("/card/interest/list")
	@ResponseBody
	public GagaMap getCardInterestList(@RequestBody CardPromotion cardPromotion) {

		GagaMap result = new GagaMap();

		cardPromotion.setPageable(new TscPageRequest(cardPromotion.getPageNo() - 1, cardPromotion.getPageSize()));
		cardPromotion.getPageable().setTotalCount(cardPromotionService.getCardInterestListCount(cardPromotion));

		result.set("pageing", cardPromotion);
		result.set("cardPromotionList", cardPromotionService.getCardInterestList(cardPromotion));

		return result;
	}

	/**
	 * 카드무이자할부 팝업
	 * @param
	 * @return
	 * @author eskim
	 * @since 2021. 2. 1
	 */
	@GetMapping("/card/interest/popup/form/{cardPrmtSq}")
	@ResponseBody
	public ModelAndView cardInterestPopupForm(@PathVariable Integer cardPrmtSq) {

		ModelAndView mav = new ModelAndView();

		mav.addObject("cardPrmt", cardPromotionService.getCardInterest(cardPrmtSq));

		mav.addObject("cardPrmtSq", cardPrmtSq);
		mav.setViewName("marketing/CardInterestPopupForm");
		return mav;
	}

	/**
	 * 카드목록 팝업
	 * @param
	 * @return
	 * @author eskim
	 * @since 2021. 2. 1
	 */
	@GetMapping("/card/list/popup/form")
	@ResponseBody
	public ModelAndView cardListtPopupForm(CardPromotionTarget cardPromotionTarget) {

		ModelAndView mav = new ModelAndView();

		// 카드목록
		mav.addObject("cardList", rendererService.getAvailCommonCodeList("G941"));

		mav.addObject("params", cardPromotionTarget);

		mav.setViewName("marketing/CardListPopupForm");
		return mav;
	}

	/**
	 * 카드무이자할부 저장
	 * @param cardPromotion
	 * @return
	 * @author eskim
	 * @since 2021. 2. 2
	 */
	@PostMapping("/card/interest/save")
	@ResponseBody
	public GagaResponse saveCardInterest(@RequestBody CardPromotion cardPromotion) {
		cardPromotionService.saveCardInterest(cardPromotion);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 카드프로모션 비노출 처리
	 * @param cardPromotion
	 * @return
	 * @author eskim
	 * @since 2021. 2. 3
	 */
	@PostMapping("/card/promotion/dispYn/update")
	@ResponseBody
	public GagaResponse updateCardPromotionDsipYn(@RequestBody CardPromotion cardPromotion) {
		cardPromotionService.updateCardPromotionDsipYn(cardPromotion);
		return super.ok(message.getMessage("SUCC_0009"));	//성공적 변경
	}

	/**
	 * 카드프로모션 삭제 처리
	 * @param cardPromotion
	 * @return
	 * @author eskim
	 * @since 2021. 2. 3
	 */
	@PostMapping("/card/promotion/delete")
	@ResponseBody
	public GagaResponse deleteCardPromotion(@RequestBody CardPromotion cardPromotion) {
		cardPromotionService.deleteCardPromotion(cardPromotion);
		return super.ok(message.getMessage("SUCC_0003"));	//성공적 변경
	}

	/**
	 * 카드프로모션 관리
	 * @param
	 * @return
	 * @author eskim
	 * @since 2021. 02. 03
	 */
	@GetMapping("/card/promotion/form")
	@ResponseBody
	public ModelAndView cardPromotionForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("marketing/CardPromotionForm");
		return mav;
	}

	/**
	 * 카드프로모션 목록
	 * @param cardPromotion
	 * @return
	 * @author eskim
	 * @since 2021. 1. 29
	 */
	@PostMapping("/card/promotion/list")
	@ResponseBody
	public GagaMap getCardPromotionList(@RequestBody CardPromotion cardPromotion) {

		GagaMap result = new GagaMap();

		cardPromotion.setPageable(new TscPageRequest(cardPromotion.getPageNo() - 1, cardPromotion.getPageSize()));
		cardPromotion.getPageable().setTotalCount(cardPromotionService.getCardPromotionListCount(cardPromotion));

		result.set("pageing", cardPromotion);
		result.set("cardPromotionList", cardPromotionService.getCardPromotionList(cardPromotion));

		return result;
	}

	/**
	 * 카드프로모션 팝업
	 * @param
	 * @return
	 * @author eskim
	 * @since 2021. 2. 1
	 */
	@GetMapping("/card/promotion/popup/form/{cardPrmtSq}")
	@ResponseBody
	public ModelAndView cardProMotionPopupForm(@PathVariable Integer cardPrmtSq) {

		ModelAndView mav = new ModelAndView();

		mav.addObject("cardPrmt", cardPromotionService.getCardPromotion(cardPrmtSq));

		mav.addObject("cardPrmtSq", cardPrmtSq);
		mav.setViewName("marketing/CardPromotionPopupForm");
		return mav;
	}

	/**
	 *   카드관련 작업 종료 - eskim
	 */

	/**
	 *   기획전 작업 시작 - sowon
	 */

	/**
	 * 기획전 관리
	 * @param
	 * @return
	 * @author sowon
	 * @since 2021. 2. 3
	 */
	@GetMapping("/planning/form")
	public ModelAndView planListForm() {
		ModelAndView mav = new ModelAndView();
		// 사이트 목록
		mav.addObject("siteCdList", rendererService.getCommonCodeList("G000"));
		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));
		mav.setViewName("marketing/PlanListForm");
		return mav;
	}

	/**
	 * 기획전 웹 등록/수정 화면
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 04
	 */
	@GetMapping("/planning/detail/form")
	public ModelAndView planDetailForm(Plan param) {
		ModelAndView mav = new ModelAndView();

		if (param.getMode().equals("N")) { // 신규 일 때
			// 기획전 전체 목록
			mav.addObject("planList", planService.getPlanAllList(param));

			// 브랜드 목록
			mav.addObject("brandList", rendererService.getSupplyCompanyBrandList(""));

			// 사용가능고객구분 목록
			mav.addObject("usableCustGbList", rendererService.getAvailCommonCodeList("G100"));

			// 상위제휴채널 조회
			mav.addObject("upperAfLinkCdList", rendererService.getAvailCommonCodeList("G053"));
			

		} else if (param.getMode().equals("U")) { // 상세 일 때
			mav.addObject("planInfo", planService.getPlanDetailInfo(param));

			// 등록했던 브랜드
			mav.addObject("planBrandList", planService.getPlanBrandList(param));

			// 등록했던 카테고리
			mav.addObject("planCateList", planService.getPlanCateList(param));

			// 등록했던 제휴채널
			mav.addObject("afChannelList", planService.getPlanAfChannelList(param));

			// 등록했던 이벤트 혜택
			mav.addObject("benefitList", planService.getPlanAttendBenefitList(param));

			mav.addObject("brandList", rendererService.getSupplyCompanyBrandList(""));

			// 사용가능고객구분 목록
			mav.addObject("usableCustGbList", rendererService.getAvailCommonCodeList("G100"));

			// 상위제휴채널 조회
			mav.addObject("upperAfLinkCdList", rendererService.getAvailCommonCodeList("G053"));
			
			// 선택한 회원유형
			mav.addObject("gbList", planService.getPlanCustGbList(param));

			// 선택한 회원등급
			mav.addObject("gradeList", planService.getPlanCustGradeList(param));
		}

		// 사이트 목록
		mav.addObject("siteList", rendererService.getAvailCommonCodeList("G000"));
		
		// 카테고리 리스트
		mav.addObject("cateList", planService.getPlanningCategoryList(param));

		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));

		// 사용가능 고객등급 조회
		mav.addObject("usableCustGradeList", rendererService.getAvailCommonCodeList("G110"));

		mav.addObject("mode", param.getMode());
		mav.setViewName("marketing/PlanDetailPopupForm");
		return mav;
	}

	/**
	 * 기획전 등록
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 4
	 */
	@PostMapping("/planning/detail/create")
	@ResponseBody
	public GagaResponse createPlanInfo(@RequestBody Plan param) {
		planService.createPlanInfo(param);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 기획전관리 목록
	 *
	 * @param
	 * @return 기획전 목록
	 * @author sowon
	 * @since 2021. 2. 5
	 */
	@PostMapping("/planning/list")
	@ResponseBody
	public GagaMap getPlanList(@RequestBody Plan param) {
		GagaMap result = new GagaMap();

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

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

		Collection<Plan> planList = planService.getPlanList(param);

		result.set("pageing", param);
		result.set("planList", planList);

		log.debug("dataList: {}", planList);

		return result;
	}

	/**
	 * 기획전관리 목록
	 *
	 * @param
	 * @return 기획전 팝업 목록
	 * @author sowon
	 * @since 2021. 2. 16
	 */
	@PostMapping("/planning/list/detail/popup")
	@ResponseBody
	public Collection<Plan> getPlanListPop(@RequestBody Plan param) {
		Collection<Plan> planList = planService.getPlanList(param);
		return planList;
	}

	/**
	 * 기획전관리 목록
	 *
	 * @param
	 * @return 기획전 삭제
	 * @author sowon
	 * @since 2021. 2. 8
	 */
	@PostMapping("/planning/delete")
	@ResponseBody
	public GagaResponse deletePlan(@RequestBody Collection<Plan> paramList) {
		planService.deletePlan(paramList);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 기획전 웹 수정
	 *
	 * @return
	 * @author sowon		
	 * @since 2021. 2. 8
	 */
	@PostMapping("/plan/detail/update")
	@ResponseBody
	public GagaResponse updatePlanInfo(@RequestBody Plan param) {
		planService.updatePlanInfo(param);
		return super.ok(message.getMessage("SUCC_0002"));
	}

	/**
	 * 기획전 등록 화면 기획전 복사
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 8
	 */
	@PostMapping("/planning/copy")
	@ResponseBody
	public Plan copyPlan(@RequestBody Plan param) {
		return planService.copyPlan(param);
	}

	/**
	 * 기획전 조회 팝업
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 15
	 */
	@GetMapping("/planning/list/popup")
	public ModelAndView planPopup(Plan plan) {
		ModelAndView mav = new ModelAndView();

		// 웹/모바일 구분
		mav.addObject("wmGbList", rendererService.getCommonCodeList("G093", "Y"));

		// 사이트 목록
		mav.addObject("siteList", rendererService.getCommonCodeList("G000", "Y"));

		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));

		// 파라메터
		mav.addObject("params", plan);

		mav.setViewName("marketing/PlanPopupForm");

		return mav;
	}

	/**
	 * 기획전 코너 팝업 화면
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 16
	 */
	@GetMapping("/planning/corner/list/form")
	public ModelAndView planCornerListForm(Plan param) {
		ModelAndView mav = new ModelAndView();

		// 코너유형목록
		mav.addObject("cornerDispTypeList", rendererService.getCommonCodeList("G045", "Y"));

		// 코너유형
		mav.addObject("planDtlStatList", rendererService.getCommonCodeList("G044", "Y"));

		// 상품상태
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y"));

		// 기획전 상세 정보
		mav.addObject("planInfo", planService.getPlanDetailInfo(param));

		mav.setViewName("marketing/PlanCornerListForm");

		return mav;
	}

	/**
	 * 기획전 댓글 팝업 화면
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 5. 24
	 */
	@GetMapping("/planning/reply/form")
	public ModelAndView planReplyListForm(Plan param) {
		ModelAndView mav = new ModelAndView();

		// 기획전 상세 정보
		mav.addObject("planInfo", planService.getPlanDetailInfo(param));

		mav.setViewName("marketing/PlanReplyListForm");

		return mav;
	}

	/**
	 * 기획전 댓글 리스트
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 5. 24
	 */
	@PostMapping("/planning/reply/list")
	@ResponseBody
	public GagaMap planReplyL(@RequestBody Plan param) {
		GagaMap result = new GagaMap();

		// 기획전 상세 정보
		param.setPageable(new TscPageRequest(param.getPageNo() - 1, param.getPageSize()));
		param.getPageable().setTotalCount(planService.getPlanReplyListCount(param));

		Collection<Plan> planReplyList = planService.getPlanReplyList(param);

		result.set("pageing", param);
		result.set("planReplyList", planReplyList);
		return result;
	}

	/**
	 * 기획전 댓글 삭제
	 *
	 * @param
	 * @return 기획전 댓글 삭제
	 * @author sowon
	 * @since 2021. 5. 24
	 */
	@PostMapping("/planning/reply/delete")
	@ResponseBody
	public GagaResponse deleteReply(@RequestBody Collection<Plan> paramList) {
		planService.deleteReply(paramList);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 기획전 댓글 상세 팝업 화면
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 5. 24
	 */
	@GetMapping("/planning/reply/detail/form")
	public ModelAndView planReplyDetailForm(Plan param) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("attachList", planService.getPlanReplyAttachList(param));
		mav.addObject("replyInfo", planService.getPlanReplyList(param));
		mav.setViewName("marketing/PlanReplyDetailForm");

		return mav;
	}

	/**
	 * 기획전 코너 목록
	 *
	 * @return
	 * @author sowon
	 * @since 2020. 1. 2
	 */
	@PostMapping("/planning/corner/list")
	@ResponseBody
	public Collection<Plan> getPlanCornerList(@RequestBody Plan param) {
		return planService.getPlanCornerList(param);
	}

	/**
	 * 기획전 코너 상품 조회
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 16
	 */
	@PostMapping("/planning/corner/goods/list")
	@ResponseBody
	public GagaMap getPlanGoodsList(@RequestBody Plan plan) {
		GagaMap result = new GagaMap();

		if ("Y".equals(plan.getPageYn())) {
			plan.setPageable(new TscPageRequest(plan.getPageNo() - 1, plan.getPageSize()));
			plan.getPageable().setTotalCount(planService.getPlanGoodsListCount(plan));
		}
		result.set("pageing", plan);
		result.set("planGoodsList", planService.getPlanGoodsList(plan));
		return result;
	}

	/**
	 * 기획전 코너 시퀀스 번호
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 16
	 */
//	@GetMapping("/planning/corner/plandtlsq")
//	@ResponseBody
//	public long getPlanDtlSq(Plan param) {
//		return planService.getPlanDtlSq(param);
//	}
//	
	/**
	 * 기획전 코너 삭제
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 17
	 */
	@PostMapping("/planning/corner/delete")
	@ResponseBody
	public GagaResponse deletePlanCornerInfo(@RequestBody Collection<Plan> paramList) {
		planService.deletePlanCornerInfo(paramList);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 기획전 코너 저장
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 17
	 */
	@PostMapping("/planning/corner/save")
	@ResponseBody
	public GagaResponse savePlanCornerInfo(@RequestBody Collection<Plan> paramList) {
		planService.savePlanCornerInfo(paramList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 기획전 코너 상품 추가
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 17
	 */
	@PostMapping("/planning/corner/goods/save")
	@ResponseBody
	public GagaResponse savePlanGoods(@RequestBody Collection<Plan> paramList) {
		planService.savePlanGoods(paramList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 기획전 코너 상품 삭제
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 18
	 */
	@PostMapping("/planning/corner/goods/delete")
	@ResponseBody
	public GagaResponse deletePlanCornerGoods(@RequestBody Collection<Plan> paramList) {
		planService.deletePlanCornerGoods(paramList);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 기획전 코너 복사
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 18
	 */
	@GetMapping("/planning/corner/copy/list/form")
	public ModelAndView planCornerCopyForm(Plan param) {
		ModelAndView mav = new ModelAndView();

		// 코너유형목록
		mav.addObject("cornerDispTypeCopyList", rendererService.getCommonCodeList("G045", "Y"));

		// 코너유형
		mav.addObject("planDtlStatCopyList", rendererService.getCommonCodeList("G044", "Y"));

		// 코너 조회
		mav.addObject("planList", planService.getPlanAllList(param));

		if (param.getCopyMode().equals("CORNER")) { // 코너 복사
			// 기획전 일련번호
			mav.addObject("planSq", param.getPlanSq());
		}

		// 모드
		mav.addObject("copyMode", param.getCopyMode());

		mav.setViewName("marketing/PlanCornerCopyForm");

		return mav;
	}

	/**
	 * 기획전 코너 복사
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 18
	 */
	@PostMapping("/planning/corner/copy")
	@ResponseBody
	public GagaResponse copyPlanCorner(@RequestBody Collection<Plan> paramList) {
		planService.copyPlanCorner(paramList);
		return super.ok(message.getMessage("SUCC_0004"));
	}

	/**
	 * 기획전 코너 상품 엑셀상품추가
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 18
	 */
	@PostMapping("/planning/corner/goods/excelupload")
	@ResponseBody
	public GagaMap createExceluploadGoods(@RequestBody Plan param) throws Exception {
		String targetPath = env.getProperty("upload.excel.target.path") + "/excel/";
		String[] goodsNames = {"planDtlSq", "goodsCd"};

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

		try {
			planService.createExceluploadGoods(ecxelGoodsList, param);
		} catch (Exception e) {
			// 파일 삭제
			GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(targetPath, param.getExcelFileNm()));
			throw new IllegalStateException(e.getMessage());
		}

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

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

	/**
	 * 기획전 템플릿 팝업
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 18
	 */
	@GetMapping("/planning/detail/template/form")
	public ModelAndView planTemplateForm(Plan param, @RequestParam(value = "planSq") Integer planSq) {
		ModelAndView mav = new ModelAndView();

		// 템플릿 등록이 최조인지 확인
		if (planService.getPlanContentsCount(param) > 0) {
			mav.addObject("mode", "U");

			//리뷰리스트
			param.setPlanSq(planSq);
			param.setTmplType("G082_10");
			mav.addObject("reviewList", planService.getPlanContentReviewList(param));

			//쿠폰리스트
			param.setTmplType("G082_20");
			mav.addObject("couponList", planService.getPlanContentCouponList(param));
			mav.addObject("couponNotice", planService.getPlanContentCouponNotice(param));

			//파일리스트
			param.setTmplType("G082_30");
			mav.addObject("fileList", planService.getPlanContentFileList(param));

			//유의사항리스트
			param.setTmplType("G082_60");
			mav.addObject("noticeList", planService.getPlanContentNoticeList(param));

			//html 리스트 - 상단
			param.setFontGb("T");
			mav.addObject("fsrcListTop", planService.getPlanContentFsrcList(param));

			//html 리스트 - 하단
			param.setFontGb("B");
			mav.addObject("fsrcListBtm", planService.getPlanContentFsrcList(param));

			//상품 리스트
			mav.addObject("goodsList", planService.getPlanContentGoodsList(param));

			Collection<Plan> goodsList = planService.getPlanContentGoodsList(param);
			Iterator<Plan> iter = goodsList.iterator();
			int i = 1;
			while (iter.hasNext()) {

				Integer planContSq = iter.next().getPlanContSq();
				param.setPlanContSq(planContSq);
				mav.addObject("goodsDetailList" + i, planService.getPlanContentGoodsDetailList(param));
				i++;
			}

		} else {
			mav.addObject("mode", "C");

		}
		// 상품상태
		String[] exceptCds = {"G008_00"};
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y", exceptCds));

		mav.addObject("planSq", planSq);
		mav.setViewName("marketing/PlanTemplatePopupForm");
		return mav;
	}

	/**
	 * 첨부파일 삭제
	 * @param plan_content - 기획전템플릿 첨부파일
	 * @return
	 * @throws IOException
	 * @author sowon
	 * @since 2021. 3. 2
	 */
	@PostMapping("/planning/detail/template/file/delete")
	@ResponseBody
	public GagaResponse deletePlanTemplateFile(@RequestBody Plan plan) throws IOException {
		// 파일 삭제
		String fileName = GagaFileUtil.getConcatenationPath(uploadTargetPath, "planning", plan.getFileItemVal());

		GagaFileUtil.deleteFile(fileName);

		// 삭제된 파일 DB 처리
		planService.deletePlanTemplateFile(plan);

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

	/**
	 * 기회전템플릿 상품 삭제
	 * @param plan_content - 기획전템플릿 상품삭제
	 * @return
	 * @throws IOException
	 * @author sowon
	 * @since 2021. 3. 3
	 */
	@PostMapping("/planning/detail/template/goods/delete")
	@ResponseBody
	public GagaMap deletePlanTemplateGoods(@RequestBody Collection<Plan> param) throws IOException {
		GagaMap result = new GagaMap();
		Integer planContSq = null;
		Iterator<Plan> list = param.iterator();
		while (list.hasNext()) {
			planContSq = list.next().getPlanContSq();
		}
		planService.deletePlanContentItemGoods(planContSq);
		planService.deletePlanContentItem(planContSq);
		result.set("status", GagaResponseStatus.SUCCESS.getCode());
		return result;
	}

	/**
	 * 기획전 템플릿 저장
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 2. 18
	 */
	@PostMapping("/planning/detail/template/save")
	@ResponseBody
	public GagaResponse planTemplateSave(@RequestBody Plan param) {
		// 기획전 컨텐츠 등록
		planService.createPlanContents(param);

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

	/**
	 *   기획전 작업 종료 - sowon
	 */

	/**
	 *   poll 작업 시작 - sowon
	 */

	/**
	 * poll 관리
	 * @param
	 * @return
	 * @author sowon
	 * @since 2021. 2. 19
	 */
	@GetMapping("/poll/list/form")
	public ModelAndView pollListForm() {
		ModelAndView mav = new ModelAndView();
		// 사이트 목록
		mav.addObject("siteList", rendererService.getCommonCodeList("G000"));

		// 사용여부
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));

		// 문제유형
		mav.addObject("pollQtype", rendererService.getPollQtypeList());

		mav.setViewName("marketing/PollListForm");
		return mav;
	}

	/**
	 * POLL 저장
	 *
	 * @param POLL 목록
	 * @return
	 * @author sowon
	 * @since 2021. 02. 19
	 */
	@PostMapping("/poll/create")
	@ResponseBody
	public GagaResponse createPoll(@RequestBody Collection<Poll> params) {
		pollService.createPoll(params);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * POLL 단일문항 삭제
	 *
	 * @param POLL 목록
	 * @return
	 * @author sowon
	 * @since 2021. 05. 02
	 */
	@PostMapping("/poll/question/remove")
	@ResponseBody
	public GagaMap removeQuestion(@RequestBody Poll poll) {
		GagaMap result = new GagaMap();
		pollService.removeQuestion(poll);
		result.set("status", "200");
		return result;
	}

	/**
	 * POLL 목록
	 *
	 * @param POLL 조회 정보
	 * @return POLL 목록
	 * @author sowon
	 * @since 2021. 2. 19
	 */
	@PostMapping("/poll/list")
	@ResponseBody
	public Collection<Poll> getPollList(@RequestBody Poll poll) {
		return pollService.getPollList(poll);
	}

	/**
	 * POLL 투표자 목록
	 *
	 * @param POLL 조회 정보
	 * @return POLL 목록
	 * @author sowon
	 * @since 2021. 2. 22
	 */
	@PostMapping("/poll/voter/list")
	@ResponseBody
	public GagaMap getPollVoterList(@RequestBody Poll poll) {
		GagaMap result = new GagaMap();
		Collection<Poll> pollList = pollService.getPollVoterList(poll);
		Collection<Poll> questionList = pollService.getPollAllQuestionList(poll);
		result.put("pollList", pollList);
		result.put("questionList", questionList);
		return result;
	}

	/**
	 * POLL detail 투표율
	 * 
	 * @param POLL 투표율
	 * @return POLL 목록
	 * @author sowon
	 * @since 2021. 2. 22
	 */
	@GetMapping("/poll/voter/list/popup/form")
	public ModelAndView pollVoterRate(Poll param) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("pollQList", pollService.getPollQuestion(param));
		mav.addObject("pollAList", pollService.getPollAnswer(param));
		mav.setViewName("marketing/PollVoteRatePopupForm");
		return mav;
	}

	/**
	 *   poll 작업 종료 - sowon
	 */

	/**
	 *   소셜관리 작업 시작 - sowon
	 */

	/**
	 * 소셜쇼핑관리 화면
	 *
	 * @author sowon
	 * @since 2021. 3. 3 
	 */
	@GetMapping(value = "/social/form")
	@ResponseBody
	public ModelAndView socialShoppingListForm() {
		ModelAndView mav = new ModelAndView();

		// 사이트코드 G000
		mav.addObject("siteList", rendererService.getAvailCommonCodeList("G000"));

		// 사용여부 G002
		mav.addObject("useYnList", rendererService.getAvailCommonCodeList("G002"));

		// 소셜 유형 G062
		mav.addObject("socialTypeList", rendererService.getAvailCommonCodeList("G062"));

		// 기획전 전체 목록
		Plan plan = new Plan();
		mav.addObject("planList", planService.getPlanAllList(plan));

		mav.setViewName("marketing/SocialShoppingListForm");
		return mav;
	}

	/**
	 * 소셜 저장
	 *
	 * @param  param - 소셜정보
	 * @return GagaResponse - 메시지
	 * @author sowon
	 * @since 2021. 3. 3
	 */
	@PostMapping("/social/save")
	@ResponseBody
	public GagaResponse saveSocial(@RequestBody Social param) {
		log.debug("param : {}", param);
		socialService.saveSocial(param);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 소셜 목록
	 *
	 * @param params - 소셜정보
	 * @return GagaResponse - 결과메시지
	 * @author sowon
	 * @since 2021. 3. 3
	 */
	@PostMapping("/social/list")
	@ResponseBody
	public GagaMap getSocialList(@RequestBody Social params) {
		GagaMap result = new GagaMap();

		Collection<Social> socialList = socialService.getSocialList(params);

		params.setPageable(new TscPageRequest(params.getPageNo() - 1, params.getPageSize()));
		params.getPageable().setTotalCount(socialService.getSocialCount(params));

		result.set("pageing", params);
		result.set("socialList", socialList);
		return result;
	}

	/**
	 * 소셜 상품 저장
	 *
	 * @param  paramList - 소셜상품정보
	 * @return GagaResponse - 결과메시지
	 * @author sowon
	 * @since 2021. 3. 4
	 */
	@PostMapping("/social/goods/save")
	@ResponseBody
	public GagaResponse saveSocialGoods(@RequestBody Collection<Social> paramList) {
		socialService.saveSocialGoods(paramList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 소셜 상품 목록
	 *
	 * @param params - 소셜상품정보
	 * @return Collection<Social> - 소셜상품목록
	 * @author sowon
	 * @since 2021. 3. 4
	 */
	@PostMapping("/social/goods/list")
	@ResponseBody
	public Collection<Social> getSocialGoodsList(@RequestBody Social params) {
		Collection<Social> socialList = socialService.getSocialGoodsList(params);
		return socialList;
	}

	/**
	 * 소셜 상품 삭제
	 *
	 * @param paramList - 소셜상품정보
	 * @return GagaResponse - 결과메시지
	 * @author sowon
	 * @since 2021. 3. 4
	 */
	@PostMapping("/social/goods/delete")
	@ResponseBody
	public GagaResponse deleteSocialGoods(@RequestBody Collection<Social> paramList) {
		socialService.deleteSocialGoods(paramList);
		return super.ok(message.getMessage("SUCC_0003"));
	}
	
	/**
	 * 출석체크 쿠폰 유효 확인
	 *
	 * @param plan 조회 정보
	 * @return plan 목록
	 * @author sowon
	 * @since 2021. 6. 9
	 */
	@PostMapping("/planning/attend/coupon")
	@ResponseBody
	public Collection<Plan> getPlanAttendCoupon(@RequestBody Plan plan) {
		return planService.getPlanAttendCoupon(plan);
	}

	/**
	 * 상품권 대량 등록 화면
	 *
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 05. 13
	 */
	@GetMapping("/giftcard/list/form")
	public ModelAndView getGiftCardListForm() {
		ModelAndView mav = new ModelAndView();

		// 사이트 목록
		mav.addObject("siteList", rendererService.getCommonCodeList("G000", "Y"));

		mav.setViewName("marketing/GiftCardListForm");

		return mav;
	}

	/**
	 * 상품권 등록 목록
	 *
	 * @param giftCard - 검색조건
	 * @return GagaMap - 페이징, 결과
	 * @author jsshin
	 * @since 2021. 01. 12
	 */
	@PostMapping("/giftcard/list")
	@ResponseBody
	public GagaMap getGiftCardList(@RequestBody GiftCard giftCard) {
		GagaMap result = new GagaMap();
		giftCard.setRegNo(TsaSession.getInfo().getUserNo());
		giftCard.setPageable(new TscPageRequest(giftCard.getPageNo() - 1, giftCard.getPageSize()));
		giftCard.getPageable().setTotalCount(giftCardService.getGiftCardListCount(giftCard));
		TscSession.setAttribute("maskingYn", TsaSession.getInfo().getMaskingYn());
		result.set("pageing", giftCard);
		result.set("giftCardList", giftCardService.getGiftCardList(giftCard));
		return result;
	}

	/**
	 * 상품권대량 업로드 엑셀 저장
	 *
	 * @param giftCard - 검색조건
	 * @return
	 * @author jsshin
	 * @since 2021. 01. 12
	 */
	@PostMapping("/upload/giftcard/bulk/reg")
	@ResponseBody
	public GagaResponse uploadGiftCardBulkReg(@RequestBody GiftCard giftCard) throws Exception {
		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
		String[] giftGardNames = {"custId", "gfcdNo"};
		Collection<GagaMap> excelGiftCardList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, giftCard.getExcelFileNm()), 0, giftGardNames, 0);

		for (GagaMap gagaMap : excelGiftCardList) {
			if (StringUtils.isNotBlank(gagaMap.getString("custId")) && StringUtils.isNotBlank(gagaMap.getString("gfcdNo"))) {
				giftCardService.saveGiftcardUseConfirm(gagaMap);
			}
		}
		return super.ok(message.getMessage("SUCC_0001"));
	}
	
	/**
	 * 소셜쇼핑관리 화면
	 *
	 * @author sowon
	 * @since 2021. 6. 29 
	 */
	@GetMapping("/shot/delivery/form")
	public ModelAndView shotDeliveryForm() {
		ModelAndView mav = new ModelAndView();
		
		// 코너유형목록
		mav.addObject("cornerDispTypeList", rendererService.getCommonCodeList("G045", "Y"));
		// 상품상태
		mav.addObject("goodsStatList", rendererService.getCommonCodeList("G008", "Y"));
		
		mav.setViewName("marketing/ShotDeliveryForm");
		return mav;
	}
	
	/**
	 * 총알배송 브랜드 그룹 목록
	 *
	 * @return
	 * @author sowon
	 * @since 2020. 6. 29
	 */
	@PostMapping("/shot/delivery/brand/list")
	@ResponseBody
	public Collection<Plan> getShotSelfBrandList() {
		return planService.getShotSelfBrandList();
	}

	/**
	 *  총알배송 브랜드 그룹 저장
	 *
	 * @return
	 * @author sowon
	 * @since 2020. 6. 29
	 */
	@PostMapping("/shot/delivery/brand/update")
	@ResponseBody
	public GagaResponse updateShotBrand(@RequestBody Collection<Plan> paramList) {
		planService.updateShotBrand(paramList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 총알배송 브랜드 상품조회
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 6. 29
	 */
	@PostMapping("/shot/delivery/goods/list")
	@ResponseBody
	public GagaMap getShotBrandGoodsList(@RequestBody Plan plan) {
		GagaMap result = new GagaMap();

		if ("Y".equals(plan.getPageYn())) {
			plan.setPageable(new TscPageRequest(plan.getPageNo() - 1, plan.getPageSize()));
			plan.getPageable().setTotalCount(planService.getShotBrandGoodsListCount(plan));
		}
		result.set("pageing", plan);
		result.set("brandGoodsList", planService.getShotBrandGoodsList(plan));
		return result;
	}
	
	/**
	 * 총알배송 브랜드 상품추가
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 6. 29
	 */
	@PostMapping("/shot/delivery/goods/save")
	@ResponseBody
	public GagaResponse saveShotBrandGoods(@RequestBody Collection<Plan> paramList) {
		planService.saveShotBrandGoods(paramList);
		return super.ok(message.getMessage("SUCC_0001"));
	}
	
	/**
	 * 총알배송 브랜드 상품 삭제
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 6. 29
	 */
	@PostMapping("/shot/delivery/goods/delete")
	@ResponseBody
	public GagaResponse deleteShotBrandGoods(@RequestBody Collection<Plan> paramList) {
		planService.deleteShotBrandGoods(paramList);
		return super.ok(message.getMessage("SUCC_0003"));
	}
}
