package com.style24.front.biz.web;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.mobile.device.Device;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.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.gagaframework.web.parameter.GagaMap;
import com.gagaframework.web.parameter.GagaParameterUtil;
import com.gagaframework.web.rest.server.GagaResponse;
import com.gagaframework.web.rest.server.GagaResponseStatus;
import com.gagaframework.web.util.GagaCookieUtil;
import com.style24.core.biz.service.TscCouponService;
import com.style24.core.biz.service.TscCustomerService;
import com.style24.core.biz.service.TscEnvsetService;
import com.style24.core.biz.service.TscKakaotalkService;
import com.style24.core.biz.service.TscKcpService;
import com.style24.core.biz.service.TscMailService;
import com.style24.core.biz.service.TscOrderChangeService;
import com.style24.core.biz.service.TscOrderRefundService;
import com.style24.core.biz.service.TscOrderService;
import com.style24.core.biz.service.TscWmsService;
import com.style24.core.support.env.TscConstants;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.front.biz.service.TsfCartService;
import com.style24.front.biz.service.TsfCommonService;
import com.style24.front.biz.service.TsfCouponService;
import com.style24.front.biz.service.TsfCustomerService;
import com.style24.front.biz.service.TsfDeliveryService;
import com.style24.front.biz.service.TsfGiftcardService;
import com.style24.front.biz.service.TsfLoginService;
import com.style24.front.biz.service.TsfOrderChangeService;
import com.style24.front.biz.service.TsfOrderService;
import com.style24.front.biz.service.TsfPointService;
import com.style24.front.biz.service.TsfReinboundService;
import com.style24.front.biz.service.TsfRendererService;
import com.style24.front.biz.service.TsfReviewService;
import com.style24.front.biz.service.TsfWishlistService;
import com.style24.front.biz.thirdparty.NiceCertify;
import com.style24.front.support.controller.TsfBaseController;
import com.style24.front.support.env.TsfConstants;
import com.style24.front.support.security.session.TsfSession;
import com.style24.persistence.TscPageRequest;
import com.style24.persistence.domain.Cart;
import com.style24.persistence.domain.Coupon;
import com.style24.persistence.domain.CustAccount;
import com.style24.persistence.domain.CustContactHst;
import com.style24.persistence.domain.CustDeliveryAddr;
import com.style24.persistence.domain.Customer;
import com.style24.persistence.domain.GiftCard;
import com.style24.persistence.domain.Goods;
import com.style24.persistence.domain.Order;
import com.style24.persistence.domain.OrderChange;
import com.style24.persistence.domain.Point;
import com.style24.persistence.domain.ReinboundInform;
import com.style24.persistence.domain.Review;
import com.style24.persistence.domain.SweetTracker;
import com.style24.persistence.domain.WishList;

import lombok.extern.slf4j.Slf4j;

/**
 * 마이페이지 Controller
 * 
 * @author gagamel
 * @since 2020. 12. 29
 */
@Controller
@RequestMapping("/mypage")
@Slf4j
public class TsfMypageController extends TsfBaseController {

	@Autowired
	private Environment env;

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private TsfCustomerService customerService;

	@Autowired
	private TscCustomerService coreCustomerService;

	@Autowired
	private TsfOrderService orderService;

	@Autowired
	private TscOrderService coreOrderService;

	@Autowired
	private TsfOrderChangeService orderChangeService;

	@Autowired
	private TscOrderChangeService coreOrderChangeService;

	@Autowired
	private TscOrderRefundService coreOrderRefundService;

	@Autowired
	private TsfReviewService reviewService;

	@Autowired
	private TsfWishlistService wishListService;

	@Autowired
	private TsfPointService pointService;

	@Autowired
	private TsfGiftcardService giftcardService;

	@Autowired
	private TsfCouponService couponService;

	@Autowired
	private TsfRendererService rendererService;

	@Autowired
	private NiceCertify niceCertify;

	@Autowired
	private TscCouponService coreCouponService;

	@Autowired
	private TsfCartService cartService;

	@Autowired
	private TsfCommonService commonService;

	@Autowired
	private TscKcpService coreKcpService;

	@Autowired
	private TsfReinboundService reinboundService;
	
	@Autowired
	private TscWmsService coreWmsService;
	
	@Autowired
	private TsfDeliveryService deliveryService;
	
	@Autowired
	private TscEnvsetService eventService;

	@Autowired
	private TscKakaotalkService coreKakaotalkService;

	@Autowired
	private TscMailService mailService;

	@Autowired
	private TsfLoginService loginService;

	@Autowired
	private TscEnvsetService coreEnvsetService;

	/**
	 * 마이페이지 메인 화면
	 *
	 * @return
	 * @author card007
	 * @since 2021. 02. 04
	 */
	@GetMapping({"/main/form", "/order/list/form"})
	public ModelAndView mypageOrderListForm(HttpServletRequest request, @RequestBody(required = false) Order order) {
		ModelAndView mav = new ModelAndView();

		if (order == null) {
			order = new Order();
		}

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		order.setCustNo(custNo);

		// 고객정보 조회
		Customer customer = new Customer();
		customer.setSiteCd(TscConstants.Site.STYLE24.value());
		customer.setCustNo(custNo);
		customer.setCustStat(TscConstants.CustStat.ACTIVE.value());
		mav.addObject("customerInfo", coreCustomerService.getCustomerInfo(customer));

		// 쿠폰정보 조회
		mav.addObject("couponCnt", coreOrderService.getCouponInfo(order));

		order.setExpiredSoon("Y");
		mav.addObject("expiredSoonCouponCnt", coreOrderService.getCouponInfo(order));

		// 포인트 정보 조회
		mav.addObject("rmPntAmt", coreOrderService.getCustPointInfo(order));

		// 상품권 정보 조회
		mav.addObject("rmGfcdAmt", coreOrderService.getGiftcardInfo(order));

		// 주문 상태 별 수량 조회
		mav.addObject("orderCount", coreOrderService.getOrderStatCount(order));

		// 로그인여부 설정
		mav.addObject("isLogin", TsfSession.isLogin());
		
		// 2021.04.21 모바일에서 사용하려고 추가
		int totalCnt = orderService.getPagingOrdNoListCount(order);
		mav.addObject("totalCnt", totalCnt);
		
		// 2021.04.25 마이페이지 메인화면 판단기준
		if (request.getRequestURL().toString().indexOf("mypage/main/form") > 0) {
			mav.addObject("mypageMainYn", "Y");
		} else {
			mav.addObject("mypageMainYn", "N");
		}
		
		// 2021.04.30 모바일 추가
		String custGradeNm1Str = coreCustomerService.getCustomerInfo(customer).getCustGradeNm().substring(0,1);
		mav.addObject("custGradeNm1Str", custGradeNm1Str);

		// 주문상세상태코드 설정
		mav.addObject("ordDtlStatList", rendererService.getCommonCodeList("G013", "Y", new String[] {"G013_10", "G013_11", "G013_25", "G013_35", "G013_55", "G013_97", "G013_98", "G013_99"}));

		mav.setViewName(super.getDeviceViewName("mypage/MypageOrderListForm"));

		return mav;
	}

	/**
	 * 마이페이지 주문상세 화면
	 *
	 * @return
	 * @author card007
	 * @since 2021. 02. 15
	 */
	@GetMapping("/order/detail/form/{ordNo}")
	public ModelAndView mypageOrderDetailForm(@PathVariable(value = "ordNo") int ordNo) {
		ModelAndView mav = new ModelAndView();

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		mav.addObject("custNo", custNo);

		// 고객정보 조회
		Customer customer = new Customer();
		customer.setSiteCd(TscConstants.Site.STYLE24.value());
		customer.setCustNo(custNo);
		customer.setCustStat(TscConstants.CustStat.ACTIVE.value());
		customer = coreCustomerService.getCustomerInfo(customer);

		mav.addObject("customerInfo", customer);

		// 로그인여부 설정
		mav.addObject("isLogin", TsfSession.isLogin());

		// 주문번호 설정
		mav.addObject("ordNo", ordNo);

		Order order = new Order();
		order.setCustNo(custNo);
		order.setOrdNo(ordNo);
		order.setAutoDecideDay(coreEnvsetService.getAutoBuyConfirmDays(TscConstants.Site.STYLE24.value()));

		// 주문목록 조회
		Collection<GagaMap> orderList = orderService.getOrderListForMypage(order);

		if (orderList.size() == 0) {
			mav.setViewName("redirect:/mypage/order/list/form");
			return mav;
		}

		mav.addObject("orderList", orderList);
		mav.addObject("oneData", orderList.iterator().next().get("oneData"));
		mav.addObject("allCanYn", orderList.iterator().next().get("allCanYn"));
		mav.addObject("allDecideYn", orderList.iterator().next().get("allDecideYn"));
		mav.addObject("canChgAddr", orderList.iterator().next().get("canChgAddr"));

		// 주문정보 조회
		Order orderInfo = coreOrderService.getOrderInfoList(order).iterator().next();
		mav.addObject("orderInfo", orderInfo);

		// 주문 금액정보 조회
		mav.addObject("orderAmtInfo", orderService.getOrderAmtForMypage(order));

		// 주문 결제정보 조회
		mav.addObject("paymentInfo", orderService.getPaymentInfoForMypage(order));

		// 주문 배송지 정보 조회
		mav.addObject("deliveryAddrInfo", orderService.getOrderDeliveryAddrInfo(order));

		// 상품권 현금영수증 신청 정보 조회
		mav.addObject("cashReceiptsInfo", giftcardService.getCashReceiptsRequestInfo(order));

		// KCP 전표 경로 설정
		mav.addObject("kcpReceiptUrl", env.getProperty("pg.kcp.receipt.url"));

		// 주문일 경과 일
		long diffDays = 0;
		try {
			Calendar eddt = Calendar.getInstance();
			eddt.setTime(new Date());

			Date stdt = new SimpleDateFormat("yyyy.MM.dd").parse(orderInfo.getOrdDt());
			Calendar cmpDate = Calendar.getInstance();
			cmpDate.setTime(stdt);

			long diffSec = (eddt.getTimeInMillis() - cmpDate.getTimeInMillis()) / 1000;
			diffDays = diffSec / (24 * 60 * 60); // 일수
		} catch (Exception e) {

		}

		mav.addObject("diffDays", diffDays);

		mav.setViewName(super.getDeviceViewName("mypage/MypageOrderDetailForm"));

		return mav;
	}

	/**
	 * 마이페이지 주문목록 조회
	 * 
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 02. 18
	 */
	@PostMapping("/order/list")
	@ResponseBody
	public GagaMap getOrderList(@RequestBody Order order) {
		GagaMap map = new GagaMap();

		// 고객번호 설정
		int custNo = 0;
		if(TsfSession.isLogin()) {
			custNo = TsfSession.getInfo().getCustNo();
		}

		// 페이징 처리 설정
		order.setCustNo(custNo);
		TscPageRequest pageable = new TscPageRequest((order.getPageNo() > 0 ? order.getPageNo() - 1 : 0), order.getPageSize(), order.getPageUnit());
		pageable.setTotalCount(orderService.getPagingOrdNoListCount(order));
		order.setPageable(pageable);

		// 페이징 처리 및 주문정보 조회
		List<Integer> ordNoList = new ArrayList<>();

		for (Order tmpOrder : orderService.getPagingOrdNoList(order)) {
			ordNoList.add(tmpOrder.getOrdNo());
		}

		if (ordNoList.size() > 0) {
			order.setOrdNoList(ordNoList.stream().mapToInt(Integer::intValue).toArray());
			order.setAutoDecideDay(coreEnvsetService.getAutoBuyConfirmDays(TscConstants.Site.STYLE24.value()));
			map.set("orderList", orderService.getOrderListForMypage(order));
		}

		map.set("orderInfo", order);

		return map;
	}

	/**
	 * 마이페이지 주문상세 주문내역 삭제
	 *
	 * @return
	 * @author card007
	 * @since 2021. 02. 15
	 */
	@PostMapping("/order/delete")
	@ResponseBody
	public GagaMap deleteOrder(@RequestBody Order order) {
		GagaMap result = new GagaMap();

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		order.setUpdNo(custNo);

		// 주문내역 삭제 처리
		int chk = orderService.updateOrderDisplayYn(order);

		if (chk > 0) {
			result.set("message", message.getMessage("SUCC_0003"));
			result.set("status", GagaResponseStatus.SUCCESS.getCode());
		} else {
			result.set("message", message.getMessage("FAIL_0003"));
			result.set("status", GagaResponseStatus.FAIL.getCode());
		}

		return result;
	}

	/**
	 * 마이페이지 구매확정 처리
	 *
	 * @return
	 * @author card007
	 * @since 2021. 02. 17
	 */
	@PostMapping("/order/decision")
	@ResponseBody
	public GagaMap decideOrder(@RequestBody Order order) {
		GagaMap result = new GagaMap();

		if (order.getOrdDtlNoArr().length == 0) {
			result.set("message", message.getMessage("FAIL_1003"));
			result.set("status", GagaResponseStatus.FAIL.getCode());
			return result;
		}

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		order.setCustNo(custNo);
		order.setRegNo(custNo);
		order.setUpdNo(custNo);

		// 구매확정 처리
		result = coreOrderService.decideOrder(order);

		return result;
	}

	/**
	 * 마이페이지 교환신청 화면
	 *
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 02. 22
	 */
	@GetMapping("/exchange/form")
	@ResponseBody
	public ModelAndView exchangeForm(Order order) {
		ModelAndView mav = new ModelAndView();

		// 주문번호 설정
		mav.addObject("ordNo", order.getOrdNo());

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		order.setCustNo(custNo);
		mav.addObject("custNo", custNo);

		// 고객정보 조회
		Customer customer = new Customer();
		customer.setSiteCd(TscConstants.Site.STYLE24.value());
		customer.setCustNo(custNo);
		customer.setCustStat(TscConstants.CustStat.ACTIVE.value());
		customer = coreCustomerService.getCustomerInfo(customer);

		mav.addObject("customerInfo", customer);

		// 로그인여부 설정
		mav.addObject("isLogin", TsfSession.isLogin());

		// 교환 가능 리스트 조회
		order.setChgGb(TscConstants.OrderChangeGb.EXCHANGE.value());
		GagaMap map = orderChangeService.getReturnListForMypage(order);
		Order oneData = (Order)map.get("oneData");
		mav.addObject("exchangeList", map);
		mav.addObject("oneData", oneData);

		// 주문 배송지 정보 조회
		mav.addObject("deliveryAddrInfo", orderService.getOrderDeliveryAddrInfo(order));

		// 교환 사유 목록 조회
		mav.addObject("exchangeReason", rendererService.getCommonCodeList("G689", "Y"));

		// 2021.08.26 card007 택배사목록 추가
		mav.addObject("shipCompanyList", rendererService.getShipCompanyList());

		mav.setViewName(super.getDeviceViewName("/mypage/MypageExchangeForm"));

		return mav;
	}

	/**
	 * 마이페이지 교환 옵션 변경 팝업
	 *
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 03. 30
	 */
	@PostMapping("/change/option/popup/form")
	@ResponseBody
	public ModelAndView changeOptionPopupForm(OrderChange orderChange) {
		ModelAndView mav = new ModelAndView();

		// custNo 설정
		if (TsfSession.isLogin()) {
			orderChange.setCustNo(TsfSession.getInfo().getCustNo());
		} else {
			orderChange.setCustNo(0);
		}

		// 교환 옵션 정보 조회
		Collection<OrderChange> exchangeOptionInfo = orderChangeService.getExchangeOptionInfo(orderChange);
		mav.addObject("exchangeOptionInfo"	, exchangeOptionInfo);
		mav.addObject("oneData"				, exchangeOptionInfo.iterator().next());
		mav.addObject("ordDtlNo"			, orderChange.getOrdDtlNo());
		mav.addObject("chgQty"				, orderChange.getChgQty());
		mav.addObject("title"				, "교환 옵션 변경");

		mav.setViewName(super.getDeviceViewName("mypage/ChangeOptionPopupForm"));

		return mav;
	}

	/**
	 * 교환신청
	 *
	 * @param OrderChange
	 * @return GagaMap
	 * @author card007
	 * @since 2021. 04. 06
	 */
	@SuppressWarnings("unchecked")
	@PostMapping("/exchange")
	@ResponseBody
	public GagaMap excReq(@RequestBody OrderChange orderChange) {
		GagaMap result = new GagaMap();

		// 교환요청 데이터 확인
		if (orderChange == null) {
			result.set("status", GagaResponseStatus.FAIL.getCode());
			result.set("message", message.getMessage("FAIL_1001"));
			return result;
		}

		// 세션 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		orderChange.setUpdNo(custNo);
		orderChange.setRegNo(custNo);

		// 교환처리
		result = coreOrderChangeService.exchReq(orderChange);
		int ordChgSq = result.getInt("ordChgSq");
		int addPayCost = result.getInt("addPayCost");

		if (ordChgSq > 0) {
			try {
				// 교환 알림톡 관련 정보 조회
				orderChange = coreOrderChangeService.getKakaoOrderReturnInfo(ordChgSq);

				// 교환 알림톡 발송
				if (StringUtils.isNotBlank(orderChange.getOrdPhnno())) {
					coreKakaotalkService.sendOrderExchangeRequest(orderChange, custNo);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}

			try {
				// 교환배송비 있을 시 추가결제완료 로직에서 메일 발송
				if (addPayCost == 0) {
					// 교환 안내 메일 정보 조회
					GagaMap replaceInfo = coreOrderChangeService.getMailOrderExchangeReplaceInfo(orderChange);

					// 교환 안내 메일 발송
					if (StringUtils.isNotBlank(replaceInfo.getString("ordEmail"))) {
						mailService.sendOrderExchange(replaceInfo, custNo);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		// 처리 결과 코드에 따른 메세지 설정
		if (result.get("status").equals(GagaResponseStatus.SUCCESS.getCode())) {
			if (orderChange.getAddPayCost() == 0) {
				result.set("message", message.getMessage("EXCHANGE_0001"));
			}
		} else {
			result.set("message", message.getMessage("FAIL_0004"));
		}

		return result;
	}

	/**
	 * 교환요청철회
	 *
	 * @param OrderChange
	 * @return GagaResponse
	 * @author card007
	 * @since 2021. 04. 20
	 */
	@PostMapping("/exchange/cancel")
	@ResponseBody
	public GagaResponse exchangeRequestCancel(@RequestBody OrderChange orderChange) {

		if (orderChange== null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		// 1. 교환요청철회 정보 설정
		int custNo = TsfSession.isLogin() ? TsfSession.getInfo().getCustNo() : 0;
		orderChange.setCustNo(custNo);
		orderChange.setRegNo(custNo);
		orderChange.setUpdNo(custNo);
		
		String ipAddress = TsfSession.getIpAddress();
		orderChange.setIpAddress(ipAddress);

		// 2.교환요청철회 
		coreOrderChangeService.exchangeCancel(orderChange);

		return super.ok(message.getMessage("EXCHANGE_0002"));
		// return super.ok();
	}

	/**
	 * 마이페이지 등급쿠폰 다운 처리
	 *
	 * @return
	 * @author card007
	 * @since 2021. 02. 17
	 */
	@PostMapping("/coupon/download/all")
	@ResponseBody
	public GagaMap createCustGradeAllCoupon(@RequestBody Coupon coupon) {
		GagaMap result = new GagaMap();

		// 고객정보 조회
		Customer customer = new Customer();
		customer.setSiteCd(TscConstants.Site.STYLE24.value());
		customer.setCustNo(coupon.getCustNo());
		customer.setCustStat(TscConstants.CustStat.ACTIVE.value());
		customer = coreCustomerService.getCustomerInfo(customer);

		// 고객정보 설정
		coupon.setCustGb(customer.getCustGb());
		coupon.setCustGrade(customer.getCustGrade());

		// 등급쿠폰 다운 처리
		int count = couponService.createCustGradeAllCoupon(coupon);

		result.set("status", GagaResponseStatus.SUCCESS.getCode());

		if (count == 0) {
			result.set("message", message.getMessage("COUPON_0002"));
		} else {
			result.set("message", message.getMessage("COUPON_0001", new Object[] {count}));
		}

		return result;
	}

	/**
	 * 마이페이지 쿠폰 수량 조회
	 *
	 * @return
	 * @author card007
	 * @since 2021. 02. 25
	 */
	@PostMapping("/coupon/count")
	@ResponseBody
	public GagaMap fnReloadCouponCount() {
		GagaMap result = new GagaMap();

		// 쿠폰정보 조회
		Order order = new Order();
		order.setCustNo(TsfSession.getInfo().getCustNo());
		result.set("couponCnt", coreOrderService.getCouponInfo(order));

		order.setExpiredSoon("Y");
		result.set("expiredSoonCouponCnt", coreOrderService.getCouponInfo(order));

		result.set("status", GagaResponseStatus.SUCCESS.getCode());

		return result;
	}

	/**
	 * 마이페이지 상태별 수량 조회
	 *
	 * @return
	 * @author card007
	 * @since 2021. 02. 25
	 */
	@PostMapping("/status/count")
	@ResponseBody
	public GagaMap fnReloadStatusCount() {
		GagaMap result = new GagaMap();

		// 쿠폰정보 조회
		Order order = new Order();
		order.setCustNo(TsfSession.getInfo().getCustNo());
		result.set("orderCount", coreOrderService.getOrderStatCount(order));

		result.set("status", GagaResponseStatus.SUCCESS.getCode());

		return result;
	}

	/**
	 * 마이페이지 반품신청 화면
	 *
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 02. 25
	 */
	@GetMapping("/return/form")
	@ResponseBody
	public ModelAndView returnForm(Order order) {
		ModelAndView mav = new ModelAndView();

		// 주문번호 설정
		mav.addObject("ordNo", order.getOrdNo());

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		order.setCustNo(custNo);
		mav.addObject("custNo", custNo);

		// 고객정보 조회
		Customer customer = new Customer();
		customer.setSiteCd(TscConstants.Site.STYLE24.value());
		customer.setCustNo(custNo);
		customer.setCustStat(TscConstants.CustStat.ACTIVE.value());
		customer = coreCustomerService.getCustomerInfo(customer);

		mav.addObject("customerInfo", customer);

		// 로그인여부 설정
		mav.addObject("isLogin", TsfSession.isLogin());

		// 반품 가능 리스트 조회
		order.setChgGb(TscConstants.OrderChangeGb.RETURN.value());
		GagaMap map = orderChangeService.getReturnListForMypage(order);
		Order oneData = (Order)map.get("oneData");
		mav.addObject("returnList", map);
		mav.addObject("oneData", oneData);

		// 주문 결제정보 조회
		mav.addObject("paymentInfo", orderService.getPaymentInfoForMypage(order));

		// 주문 배송지 정보 조회
		mav.addObject("deliveryAddrInfo", orderService.getOrderDeliveryAddrInfo(order));

		// 반품 사유 목록 조회
		mav.addObject("returnReason", rendererService.getCommonCodeList("G688", "Y"));
		
		// 2021.05.03 은행목록추가
		mav.addObject("bankList", rendererService.getCommonCodeList("G942", "Y"));

		// 2021.08.26 card007 택배사목록 추가
		mav.addObject("shipCompanyList", rendererService.getShipCompanyList());

		mav.setViewName(super.getDeviceViewName("/mypage/MypageReturnForm"));

		return mav;
	}

	/**
	 * 반품신청
	 * 
	 * @param OrderChange
	 * @return GagaMap
	 * @author card007
	 * @since 2021. 03. 30
	 */
	@SuppressWarnings("unchecked")
	@PostMapping("/return")
	@ResponseBody
	public GagaMap rtnReq(@RequestBody OrderChange orderChange) {
		if (orderChange == null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		// 1. 세션회원조회
		int custNo = TsfSession.getInfo().getCustNo();
		orderChange.setCustNo(custNo);

		GagaMap map = coreOrderChangeService.returnReq(orderChange);

		int ordChgSq = map.getInt("ordChgSq");
		int addPayCost = map.getInt("addPayCost");

		if (ordChgSq > 0) {
			try {
				// 반품 알림톡 관련 정보 조회
				orderChange = coreOrderChangeService.getKakaoOrderReturnInfo(ordChgSq);

				// 반품 알림톡 발송
				if (StringUtils.isNotBlank(orderChange.getOrdPhnno())) {
					coreKakaotalkService.sendOrderReturnRequest(orderChange, custNo);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}

			try {
				// 반품배송비 있을 시 추가결제완료 로직에서 메일 전송
				if (addPayCost == 0) {
					// 반품 안내 메일 정보 조회
					GagaMap replaceInfo = coreOrderChangeService.getMailOrderReturnReplaceInfo(orderChange);

					// 반품 안내 메일 발송
					if (StringUtils.isNotBlank(replaceInfo.getString("ordEmail"))) {
						mailService.sendOrderReturn(replaceInfo, custNo);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		map.set("status", GagaResponseStatus.SUCCESS.getCode());
		if (orderChange.getAddPayCost() == 0) {
			map.set("message", message.getMessage("RETURN_0001"));
		}

		return map;
	}

	/**
	 * 반품요청철회
	 * 
	 * @param OrderChange
	 * @return GagaResponse
	 * @author card007
	 * @since 2021. 04. 20
	 */
	@PostMapping("/return/cancel")
	@ResponseBody
	public GagaResponse rtnReqCancel(@RequestBody OrderChange orderChange) throws Exception {

		if (orderChange== null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		// 1. 반품요청철회 정보 설정
		int custNo = TsfSession.isLogin() ? TsfSession.getInfo().getCustNo() : 0;
		GagaMap map = new GagaMap();
		map.set("ordNo"			, orderChange.getOrdNo());
		map.set("ordChgSq"		, orderChange.getOrdChgSq());
		map.set("custNo"		, custNo);
		map.set("ipAddress"		, TsfSession.getIpAddress());

		// 2.반품요청철회 
		coreOrderChangeService.rtnReqCancel(map, custNo);

		return super.ok(message.getMessage("RETURN_0002"));
		// return super.ok();
	}

	/**
	 * 마이페이지 취소신청 화면
	 *
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 03. 19
	 */
	@GetMapping("/cancel/form")
	@ResponseBody
	public ModelAndView cancelForm(Order order) {
		ModelAndView mav = new ModelAndView();

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		order.setCustNo(custNo);
		
		// 2021.05.07 고객정보 조회
		Customer customer = new Customer();
		customer.setSiteCd(TscConstants.Site.STYLE24.value());
		customer.setCustNo(custNo);
		customer.setCustStat(TscConstants.CustStat.ACTIVE.value());
		customer = coreCustomerService.getCustomerInfo(customer);
		
		mav.addObject("customerInfo", customer);

		// 취소 가능 리스트 조회
		GagaMap map = orderChangeService.getCancelListForMypage(order);
		Order oneData = (Order)map.get("oneData");
		mav.addObject("cancelList", map);
		mav.addObject("oneData", oneData);

		// 주문 결제정보 조회
		mav.addObject("paymentInfo", orderService.getPaymentInfoForMypage(order));

		// 2021.05.03 은행목록추가
		mav.addObject("bankList", rendererService.getCommonCodeList("G942", "Y"));

		// 로그인여부 설정
		mav.addObject("isLogin", TsfSession.isLogin());

		mav.setViewName(super.getDeviceViewName("/mypage/MypageCancelForm"));

		return mav;
	}

	/**
	 * 마이페이지 취소신청
	 *
	 * @param Collection<Order>
	 * @return GagaMap
	 * @author card007
	 * @since 2021. 03. 22
	 */
	@SuppressWarnings("unchecked")
	@PostMapping("/cancel")
	@ResponseBody
	public GagaMap cancel(@RequestBody OrderChange orderChange) {
		if (orderChange == null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		// 1. 세션회원조회
		int custNo = TsfSession.getInfo().getCustNo();
		orderChange.setCustNo(custNo);
		orderChange.setIpAddress(TsfSession.getIpAddress());

		// 2. 취소완료 처리
		GagaMap result = coreOrderChangeService.orderCancelPreInfo(orderChange, custNo);

		// 3. 취소완료 카카오알림톡 발송
		int ordChgSq = result.getInt("ordChgSq");
		
		if (ordChgSq > 0) {
			try {
				// 취소 알림톡 관련 정보 조회
				orderChange = coreOrderChangeService.getKakaoOrderCancelInfo(ordChgSq);

				// 취소 알림톡 발송
				if (StringUtils.isNotBlank(orderChange.getOrdPhnno())) {
					coreKakaotalkService.sendOrderCancelComplete(orderChange, custNo);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			try {
				// 취소 안내 메일 정보 조회
				GagaMap replaceInfo = coreOrderChangeService.getMailOrderCancelReplaceInfo(orderChange);

				// 취소 안내 메일 발송
				if (orderChange != null && StringUtils.isNotBlank(replaceInfo.getString("ordEmail"))) {
					mailService.sendOrderCancel(replaceInfo, custNo);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		result.set("status", GagaResponseStatus.SUCCESS.getCode());
		result.set("message", message.getMessage("CANCEL_0001"));

		return result;
	}

	/**
	 * 마이페이지 장바구니 관련 정보 조회
	 * 
	 * @param Cart
	 * @return Collecion<Cart>
	 * @author card007
	 * @since 2021. 03. 26
	 */
	@PostMapping("/cart/add/info")
	@ResponseBody
	public Collection<Cart> getAddCartInfo(@RequestBody Cart cart) {
		return cartService.getAddCartInfoForMypage(cart);
	}

	/**
	 * 환불계좌 등록 팝업
	 * 
	 * @param OrderChange
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 04. 05
	 */
	@ResponseBody
	@RequestMapping(value = "/refund/account/register/popup/form")
	public ModelAndView registerRefundAccountPopupForm(@RequestBody OrderChange orderChange) {
		ModelAndView mav = new ModelAndView();

		// 계좌인증용 은행코드 조회
		mav.addObject("bankList", rendererService.getAvailCommonCodeList("G942"));

		// 계좌주명 설정
		mav.addObject("accountNm", orderChange.getAccountNm());

		// 주문번호 설정
		mav.addObject("ordNo", orderChange.getOrdNo());

		mav.setViewName(super.getDeviceViewName("popup/RefundAccountAddPopupForm"));

		return mav;
	}

	/**
	 * 마이페이지 취반교 목록 화면
	 *
	 * @return
	 * @author card007
	 * @since 2021. 02. 04
	 */
	@GetMapping("/cre/list/form")
	public ModelAndView mypageCreListForm() {
		ModelAndView mav = new ModelAndView();

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		mav.addObject("custNo", custNo);

		// 주문 상태 별 수량 조회
		Order order = new Order();
		order.setCustNo(custNo);
		mav.addObject("orderCount", coreOrderService.getOrderStatCount(order));
		
		// 2021.04.21 모바일에서 사용하려고 추가
		OrderChange orderChange = new OrderChange();
		orderChange.setCustNo(custNo);
		int totalCnt = orderChangeService.getPagingCreListCount(orderChange);
		mav.addObject("totalCnt", totalCnt);

		// 로그인여부 설정
		mav.addObject("isLogin", TsfSession.isLogin());

		// 주문상세상태코드 설정
		mav.addObject("chgStatList", rendererService.getCommonCodeList("G685", "Y", new String[] {"G685_10", "G685_11", "G685_19"}));

		mav.setViewName(super.getDeviceViewName("mypage/MypageCreListForm"));

		return mav;
	}

	/**
	 * 마이페이지 취반교 목록 조회
	 *
	 * @param OrderChange
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 02. 18
	 */
	@PostMapping("/cre/list")
	@ResponseBody
	public GagaMap getCreList(@RequestBody OrderChange orderChange) {
		GagaMap map = new GagaMap();

		// 고객번호 설정
		int custNo = 0;
		if(TsfSession.isLogin()) {
			custNo = TsfSession.getInfo().getCustNo();
		}

		// 페이징 처리 설정
		orderChange.setCustNo(custNo);
		TscPageRequest pageable = new TscPageRequest((orderChange.getPageNo() > 0 ? orderChange.getPageNo() - 1 : 0), orderChange.getPageSize(), orderChange.getPageUnit());
		pageable.setTotalCount(orderChangeService.getPagingCreListCount(orderChange));
		orderChange.setPageable(pageable);

		// 페이징 처리 및 주문정보 조회
		List<Integer> ordChgSqList = new ArrayList<>();

		for (OrderChange tmpOrderChange : orderChangeService.getPagingCreList(orderChange)) {
			ordChgSqList.add(tmpOrderChange.getOrdChgSq());
		}

		if (ordChgSqList.size() > 0) {
			orderChange.setOrdChgSqArr(ordChgSqList.stream().mapToInt(Integer::intValue).toArray());
			map.set("creList", orderChangeService.getCreList(orderChange));
		}

		map.set("creInfo", orderChange);

		return map;
	}

	/**
	 * 마이페이지 취반교 취소 상세 화면
	 *
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 04. 12
	 */
	@GetMapping("/cre/cancel/detail/form")
	public ModelAndView mypageCreCancelDetailForm(OrderChange orderChange) {
		ModelAndView mav = new ModelAndView();

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		mav.addObject("custNo", custNo);

		// 취소상세 데이터 조회
		orderChange.setCustNo(custNo);
		GagaMap map = coreOrderChangeService.getCreCancelDetailInfo(orderChange);
		OrderChange oneData = (OrderChange) map.get("oneData");
		mav.addObject("cancelDetailList", map);
		mav.addObject("oneData", oneData);
		mav.addObject("refundYn", map.getString("refundYn"));

		// 주문 결제정보 조회
		Order order = new Order();
		order.setOrdNo(orderChange.getOrdNo());
		mav.addObject("paymentInfo", orderService.getPaymentInfoForMypage(order));

		// 로그인여부 설정
		mav.addObject("isLogin", TsfSession.isLogin());

		// KCP 전표 경로 설정
		mav.addObject("kcpReceiptUrl", env.getProperty("pg.kcp.receipt.url"));

		mav.setViewName(super.getDeviceViewName("mypage/MypageCreCancelDetailForm"));

		return mav;
	}

	/**
	 * 마이페이지 취반교 반품 상세 화면
	 *
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 04. 13
	 */
	@GetMapping("/cre/return/detail/form")
	public ModelAndView mypageCreReturnDetailForm(OrderChange orderChange) {
		ModelAndView mav = new ModelAndView();

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		mav.addObject("custNo", custNo);

		// 로그인여부 설정
		mav.addObject("isLogin", TsfSession.isLogin());

		// 취소상세 데이터 조회
		orderChange.setCustNo(custNo);
		GagaMap map = coreOrderChangeService.getCreReturnDetailInfo(orderChange);
		OrderChange oneData = (OrderChange) map.get("oneData");
		mav.addObject("returnDetailList", map);
		mav.addObject("oneData", oneData);
		mav.addObject("refundYn", map.getString("refundYn"));

		// 주문 결제정보 조회
		Order order = new Order();
		order.setOrdNo(orderChange.getOrdNo());
		mav.addObject("paymentInfo", orderService.getPaymentInfoForMypage(order));

		// KCP 전표 경로 설정
		mav.addObject("kcpReceiptUrl", env.getProperty("pg.kcp.receipt.url"));

		mav.setViewName(super.getDeviceViewName("mypage/MypageCreReturnDetailForm"));

		return mav;
	}

	/**
	 * 마이페이지 취반교 교환 상세 화면
	 *
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 04. 13
	 */
	@GetMapping("/cre/exchange/detail/form")
	public ModelAndView mypageCreExchangeDetailForm(OrderChange orderChange) {
		ModelAndView mav = new ModelAndView();

		// 고객번호 설정
		int custNo = TsfSession.getInfo().getCustNo();
		mav.addObject("custNo", custNo);

		// 로그인여부 설정
		mav.addObject("isLogin", TsfSession.isLogin());

		// 취소상세 데이터 조회
		orderChange.setCustNo(custNo);
		GagaMap map = coreOrderChangeService.getCreExchangeDetailInfo(orderChange);
		OrderChange oneData = (OrderChange) map.get("oneData");
		mav.addObject("exchangeDetailList", map);
		mav.addObject("oneData", oneData);

		// KCP 전표 경로 설정
		mav.addObject("kcpReceiptUrl", env.getProperty("pg.kcp.receipt.url"));

		mav.setViewName(super.getDeviceViewName("mypage/MypageCreExchangeDetailForm"));

		return mav;
	}

	/**
	 * WMS 주문 취소 가능 여부 조회
	 * 
	 * @param
	 * @return
	 * @author card007
	 * @since 2021. 04. 22
	 */
	@PostMapping("/wms/cancel/available")
	@ResponseBody
	public GagaMap getWmsCancelYn(@RequestBody OrderChange orderChange) {
		GagaMap result = new GagaMap();
		String cancelYn = "Y";

		Integer ordNo = orderChange.getOrdNo();

		for (Integer ordDtlNo : orderChange.getOrdDtlNoArr()) {
			String rst = coreWmsService.getCancelYn(ordNo, ordDtlNo);
			
			if ("Y".equals(cancelYn) && "N".equals(rst)) {
				cancelYn = "N";
			}
		}

		result.setString("cancelYn", cancelYn);

		return result;
	}

	/**
	 * 상품권 KCP 현금영수증 신청
	 * 
	 * @param Order
	 * @return GagaResponse
	 * @author card007
	 * @since 2021. 04. 25
	 */
	@PostMapping("/cash/receipts/request")
	@ResponseBody
	public GagaMap requestCashReceipts(@RequestBody GiftCard giftCard) {
		GagaMap map = new GagaMap();
		// 상품권 KCP 현금영수증 신청 정보 조회
		giftCard = giftcardService.getCashReceiptsInfo(giftCard);

		if (giftCard == null || giftCard.getUsGfcdAmt() == 0) {
			throw new IllegalStateException(message.getMessage("FAIL_0004"));
		}

		// 상품권 KCP 현금영수증 신청
		GiftCard result = orderService.kcpCashReceiptsRequest(giftCard);

		// 결과 처리
		if("0000".equals(result.getResultCd())) {
			map.set("status", GagaResponseStatus.SUCCESS.getCode());
			map.set("message", message.getMessage("SUCC_0004"));
		} else {
			map.set("status", GagaResponseStatus.SUCCESS.getCode());
			map.set("message", message.getMessage("FAIL_0004"));
		}

		return map;
	}
	

	/**
	 * 마이페이지 STYLE24 포인트화면
	 *
	 * @param 
	 * @return ModelAndView
	 * @author csh9191
	 * @since 2021. 02. 25
	 */
	@GetMapping("/point/form")
	public ModelAndView stylePointForm(Point point) {
		ModelAndView mav = new ModelAndView();

		int custNo = TsfSession.getInfo().getCustNo();
		point.setCustNo(custNo);
		// 잔여포인트
		mav.addObject("rmPntAmt", pointService.getUsablePointInfo(point));
		// 적립예정포인트 expectedPntAmt
		mav.addObject("expectedPntAmt", pointService.getExpectedPointInfo(point));
		// 한달 이내 소멸 예정 포인트
		mav.addObject("expectedExpirePntAmt", pointService.getExtinctPointInfo(point));
		// 전체내역 조회
		mav.addObject("allPointList", pointService.getAllPointList(point));
		// 적립내역 조회
		mav.addObject("accumulatePointList", pointService.getAccumulatePointList(point));
		// 사용내역 조회
		mav.addObject("usePointList", pointService.getUsePointList(point));
		// 최근 12개월
		mav.addObject("date", pointService.getRecentlyDate());
		mav.setViewName(super.getDeviceViewName("mypage/MypagePointForm"));
		return mav;
	}

	/**
	 * 마이페이지 STYLE24 포인트 전체,적립,사용내역
	 *
	 * @param param
	 * @return GagaMap
	 * @author csh9191
	 * @since 2021. 03. 02
	 */
	@PostMapping("/allpoint/list")
	@ResponseBody
	public GagaMap getAllPointList(@RequestBody Point point) {
		GagaMap result = new GagaMap();

		int custNo = TsfSession.getInfo().getCustNo();
		point.setCustNo(custNo);

		// 전체내역 조회
		result.set("allPointList", pointService.getAllPointList(point));
		// 적립내역 조회
		result.set("accumulatePointList", pointService.getAccumulatePointList(point));
		// 사용내역 조회
		result.set("usePointList", pointService.getUsePointList(point));

		return result;
	}

	/**
	 * 마이페이지 반품신청 환불금액 계산
	 *
	 * @param Order
	 * @return GagaMap
	 * @author card007
	 * @since 2021. 02. 26
	 */
	@SuppressWarnings("unchecked")
	@PostMapping("/cancel/refund/amt/calculate")
	@ResponseBody
	public GagaMap calculateRefundAmt(@RequestBody OrderChange orderChange) {
		if (orderChange == null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		// 1. 세션회원조회
		int custNo = TsfSession.getInfo().getCustNo();
		orderChange.setCustNo(custNo);

		// 2. 환불 사전 정보 조회
		GagaMap refundPreInfo = coreOrderChangeService.getRefundPreInfo(orderChange);
		List<Order> cnclReqList = (List<Order>)refundPreInfo.get("cnclReqList");

		return coreOrderRefundService.cnclRtnRefundAmt(cnclReqList);
	}

	/**
	 * 마이페이지 배송지 정보 수정
	 *
	 * @param Order
	 * @return GagaMap
	 * @author card007
	 * @since 2021. 04. 04
	 */
	@PostMapping("/change/delvery/addr")
	@ResponseBody
	public GagaMap changeDelveryAddr(@RequestBody Order order) {
		GagaMap result = new GagaMap();
		result.set("status", GagaResponseStatus.SUCCESS.getCode());
		result.set("message", message.getMessage("DELV_0001"));

		if (TsfSession.isLogin()) {
			order.setCustNo(TsfSession.getInfo().getCustNo());
		} else {
			order.setCustNo(0);
		}

		try {
			// 배송지 수정 처리
			commonService.updateDeliverAddr(order);

			// WMS 배송지 수정 처리
			coreWmsService.updateWmsDeliveryChangeAddr(order);
		} catch (Exception e) {
			result.set("status", GagaResponseStatus.FAIL.getCode());
			result.set("message", message.getMessage("FAIL_0002"));
		}

		return result;
	}

	/**
	 * 마이페이지 배송 메모 수정
	 *
	 * @param Order
	 * @return GagaMap
	 * @author card007
	 * @since 2021. 04. 04
	 */
	@PostMapping("/change/delvery/memo")
	@ResponseBody
	public GagaMap changeDelveryAddrDelvMemo(@RequestBody Order order) {
		GagaMap result = new GagaMap();
		result.set("status", GagaResponseStatus.SUCCESS.getCode());
		result.set("message", message.getMessage("DELV_0002"));

		if (TsfSession.isLogin()) {
			order.setCustNo(TsfSession.getInfo().getCustNo());
		} else {
			order.setCustNo(0);
		}

		try {
			// 배송메모 수정 처리
			commonService.updateDeliverAddrDelvMemo(order);

			// WMS 배송메모 수정 처리
			coreWmsService.updateWmsDeliveryMemo(order);
		} catch (Exception e) {
			result.set("status", GagaResponseStatus.FAIL.getCode());
			result.set("message", message.getMessage("FAIL_0002"));
		}

		return result;
	}

	/**
	 * 마이페이지 회수지 정보 수정
	 *
	 * @param OrderChange
	 * @return GagaMap
	 * @author card007
	 * @since 2021. 04. 13
	 */
	@PostMapping("/change/chger/addr")
	@ResponseBody
	public GagaMap changeChgerAddr(@RequestBody OrderChange orderChange) {
		GagaMap result = new GagaMap();
		result.set("status", GagaResponseStatus.SUCCESS.getCode());
		result.set("message", message.getMessage("DELV_0003"));

		try {
			orderChange.setUpdNo(TsfSession.getInfo().getCustNo());

			// 회수지 정보 수정 처리
			coreOrderChangeService.updateChgerAddr(orderChange);

			// WMS 회수지 정보 수정 처리
			Order order = new Order();
			order.setOrdNo(orderChange.getOrdNo());
			order.setChgerZipcode(orderChange.getChgerZipcode());
			order.setChgerBaseAddr(orderChange.getChgerBaseAddr());
			order.setChgerDtlAddr(orderChange.getChgerDtlAddr());
			order.setChgerRtnMemo(orderChange.getChgerRtnMemo());
			order.setOrdChgSq(orderChange.getOrdChgSq());

			coreWmsService.updateWmsRecallChangeAddr(order);
		} catch (Exception e) {
			result.set("status", GagaResponseStatus.FAIL.getCode());
			result.set("message", message.getMessage("FAIL_0002"));
		}

		return result;
	}

	/**
	 * 마이페이지 반품메모 수정
	 *
	 * @param Order
	 * @return GagaMap
	 * @author card007
	 * @since 2021. 04. 13
	 */
	@PostMapping("/change/chger/rtn/memo")
	@ResponseBody
	public GagaMap changeChgerRtnMemo(@RequestBody OrderChange orderChange) {
		GagaMap result = new GagaMap();
		result.set("status", GagaResponseStatus.SUCCESS.getCode());
		result.set("message", message.getMessage("DELV_0004"));

		try {
			orderChange.setUpdNo(TsfSession.getInfo().getCustNo());

			// 반품메모 수정 처리
			coreOrderChangeService.updateChgerRtnMemo(orderChange);

			// WMS IF 반품메모 수정 처리
			Order order = new Order();
			order.setOrdNo(orderChange.getOrdNo());
			order.setChgerRtnMemo(orderChange.getChgerRtnMemo());
			order.setOrdChgSq(orderChange.getOrdChgSq());
			coreWmsService.updateWmsRecallChangeMemo(order);
		} catch (Exception e) {
			throw new IllegalStateException(message.getMessage("FAIL_0002"));
		}

		return result;
	}

	/**
	 * 배송조회 화면
	 * 
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since  2021. 05. 04
	 */
	@GetMapping("/delivery/info/form")
	@ResponseBody
	public ModelAndView deliveryInfoForm(Order order) {
		ModelAndView mav = new ModelAndView();
		
		// 고객번호 설정
		order.setCustNo(TsfSession.getInfo().getCustNo());

		// 주문번호 설정
		mav.addObject("ordNo", order.getOrdNo());

		// 로그인여부 설정
		mav.addObject("isLogin", TsfSession.isLogin());

		// 주문목록 조회
		order.setAutoDecideDay(coreEnvsetService.getAutoBuyConfirmDays(TscConstants.Site.STYLE24.value()));
		Collection<GagaMap> orderList = orderService.getOrderListForMypage(order);

		if (orderList.size() == 0) {
			mav.setViewName("redirect:/mypage/order/list/form");
			return mav;
		}

		mav.addObject("orderList", orderList);
		mav.addObject("oneData", orderList.iterator().next().get("oneData"));


		// 주문 배송지 정보 조회
		mav.addObject("deliveryAddrInfo", orderService.getOrderDeliveryAddrInfo(order));

		// 스윗트래커 정보 조회
		SweetTracker sweetTracker = new SweetTracker();
		sweetTracker.setShipCompCd(order.getShipCompCd());
		sweetTracker.setInvoiceNo(order.getInvoiceNo());
		mav.addObject("sweetTrackerInfoList", deliveryService.getSweetTrackerDeliveryInfo(sweetTracker));

		mav.setViewName(super.getDeviceViewName("mypage/MypageDeliveryInfoForm"));
		
		return mav;
	}

	/**
	 * 회수 배송 조회 팝업
	 *
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 03. 30
	 */
	@PostMapping("/track/withdraw/popup/form")
	@ResponseBody
	public ModelAndView trackWithdrawPopupForm(@RequestBody OrderChange orderChange) {
		ModelAndView mav = new ModelAndView();

		// 스윗트래커 정보 조회
		SweetTracker sweetTracker = new SweetTracker();
		sweetTracker.setShipCompCd(orderChange.getShipCompCd());
		sweetTracker.setInvoiceNo(orderChange.getWdInvoiceNo());
		mav.addObject("sweetTrackerInfoList", deliveryService.getSweetTrackerDeliveryInfo(sweetTracker));

		mav.setViewName(super.getDeviceViewName("popup/TrackWithdrawPopupForm"));

		return mav;
	}

	/**
	 * 위시리스트 등록처리
	 *
	 * @param wishList 
	 * @return GagaResponse
	 * @author eskim
	 * @since 2021. 03. 08
	 */
	@PostMapping("/wish/list/put")
	@ResponseBody
	public GagaMap createWishList(@RequestBody Collection<WishList> wishList) throws Exception {
		GagaMap result = new GagaMap();

		customerService.createWishList(wishList);
		result.set("status", "200");

		return result;
	}

	/**
	 * 위시리스트 삭제처리
	 *
	 * @param wishList
	 * @return GagaResponse
	 * @throws Exception
	 * @author eskim
	 * @since 2021. 03. 08
	 */
	@PostMapping("/wish/list/delete")
	@ResponseBody
	public GagaMap deleteWishList(@RequestBody Collection<WishList> wishList) throws Exception {
		GagaMap result = new GagaMap();

		customerService.deleteWishList(wishList);
		result.set("status", "200");

		return result;
	}

	/* 김소원 상품권 쿠폰 리뷰 위시리스트 시작 */
	/**
	 * 마이페이지 상품권화면
	 *
	 * @return
	 * @author sowon	
	 * @since 2021. 03. 12
	 */
	@GetMapping("/gift/card/form")
	public ModelAndView mypageGiftcardForm(GiftCard giftcard, Device device) {
		ModelAndView mav = new ModelAndView();
		// 상품권 기본정보
		mav.addObject("giftcardInfo", giftcardService.getGiftcardInfo(giftcard));

		// 최근 12개월 년,월
		mav.addObject("date", giftcardService.getRecentlyDate());
		mav.setViewName(super.getDeviceViewName("mypage/MypageGiftcardForm"));

		return mav;
	}

	/**
	 * 마이페이지 상품권 사용 리스트
	 *
	 * @return
	 * @author sowon	
	 * @since 2021. 03. 12
	 */
	@PostMapping("/gift/use/list")
	@ResponseBody
	public GagaMap getGiftcardUseList(@RequestBody GiftCard giftcard) {
		GagaMap result = new GagaMap();
		result.set("giftcardUseList", giftcardService.getGiftcardUseList(giftcard));
		return result;
	}

	/**
	 * 마이페이지 상품권 보유 리스트
	 *
	 * @return
	 * @author sowon	
	 * @since 2021. 03. 12
	 */
	@PostMapping("/gift/own/list")
	@ResponseBody
	public GagaMap getGiftcardOwnList(@RequestBody GiftCard giftcard) {
		GagaMap result = new GagaMap();
		result.set("giftcardOwnList", giftcardService.getGiftcardOwnList(giftcard));
		return result;
	}

	/**
	 * 마이페이지 상품권 저장
	 *
	 * @return
	 * @author sowon
	 * @throws Exception
	 * @since 2021. 03. 15
	 */
	@PostMapping("/gift/use/confirm")
	@ResponseBody
	public GagaMap createGiftcardUseConfirm(@RequestBody GiftCard giftcard) throws Exception {
		return giftcardService.createGiftcardUseConfirm(giftcard);
	}

	/**
	 * 마이페이지 쿠폰화면
	 *
	 * @return
	 * @author sowon	
	 * @since 2021. 03. 16
	 */
	@GetMapping("/coupon/form")
	public ModelAndView mypageCouponForm(Coupon coupon) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("couponList", couponService.getMypageCouponList(coupon));
		mav.addObject("couponInfo", couponService.getMypageCouponInfo(coupon));
		mav.setViewName(super.getDeviceViewName("mypage/MypageCouponForm"));

		return mav;
	}
	
	/**
	 * 퀵메뉴 보유한 쿠폰리스트
	 * @return
	 * @author sowon
	 * @since 2021. 4. 14
	 */
	@GetMapping("/quick/own/coupon/list")
	@ResponseBody
	public Collection<Coupon> getQuickOwnCouponList() {
		Coupon coupon = new Coupon();
		Collection<Coupon> ownCouponList = new ArrayList<>();
		coupon.setQuickYn("Y");
		ownCouponList  = couponService.getMypageCouponList(coupon);
		return ownCouponList;
	}
	
	/**
	 * 퀵메뉴 다운가능한 쿠폰리스트
	 * @return
	 * @author sowon
	 * @since 2021. 4. 23
	 */
	@GetMapping("/quick/down/coupon/list")
	@ResponseBody
	public GagaMap getQuickDownCouponList() {
		GagaMap result = new GagaMap();
		Coupon coupon = new Coupon();
		coupon.setQuickYn("N");
		Collection<Coupon> ownCouponList = couponService.getQuickCouponDownList(coupon);
		result.set("ownCouponList", ownCouponList);
		result.set("couponCount",couponService.getMypageCouponInfo(coupon));
		return result;
	}
	
	/**
	 * 퀵메뉴 쿠폰 다운
	 * @return
	 * @author sowon
	 * @since 2021. 4. 23
	 */
	@PostMapping("/quick/coupon/download")
	@ResponseBody
	public GagaMap downQuickCoupon(@RequestBody Coupon coupon) {
		GagaMap result = new GagaMap();
		String couponResult = couponService.saveQuickCoupon(coupon);
		if ("ERROR_10".equals(couponResult)) {
			result.set("message", "발급가능 쿠폰이 없습니다.");
		}else if("ERROR_20".equals(couponResult)){
			result.set("message", "죄송합니다. 해당 쿠폰은 다운로드가 불가합니다.");
		}else if("ERROR_30".equals(couponResult)){
			result.set("message", "죄송합니다. 해당 쿠폰은 다운로드가 불가합니다.");
		}else {
			result.set("message", "쿠폰이 발급되었습니다.");
		}
		coupon.setQuickYn("Y");
		result.set("status", "200");
		result.set("couponList", couponService.getQuickCouponDownList(coupon));
		return result;
	}


	/**
	 * 마이페이지 쿠폰 상세보기 팝업
	 *
	 * @return
	 * @author sowon	
	 * @since 2021. 03. 17
	 */
	@PostMapping(value = "/coupon/detailPop")
	public ModelAndView mypageCouponDetailPop(@RequestBody Coupon coupon) {
		ModelAndView mav = new ModelAndView();

		// 쿠폰 - 기본정보
		mav.addObject("couponDetailInfo", couponService.getCouponDetailInfo(coupon));
		
		mav.setViewName(super.getDeviceViewName("mypage/MypageCouponDetailForm"));
		return mav;
	}

	/**
	 * 마이페이지 리뷰화면
	 *
	 * @return
	 * @author sowon
	 * @since 2021. 03. 24
	 */
	@GetMapping("/review/form")
	public ModelAndView mypageReviewForm(Review review) {
		ModelAndView mav = new ModelAndView();

		review.setCustNo(TsfSession.getInfo().getCustNo());
		review.setSiteCd(TscConstants.Site.STYLE24.value());
		// 작성가능한 리뷰 카운트
		review.setReviewExpireDay(eventService.getGoodsReviewRegisterDays(TscConstants.Site.STYLE24.value()));
		mav.addObject("completeReviewCount", reviewService.getCompleteReviewList(review).size());

		// 작성한 리뷰 카운트
		mav.addObject("alreadyReviewCount", reviewService.getAlreadyReviewList(review).size());

		// 관리자 댓글확인 
		mav.addObject("adminCount", reviewService.getAdminConfirmCount(review));

		// 리뷰 이미지/동영상
		mav.addObject("alreadyReviewAttach", reviewService.getReviewAttach(review));

		mav.setViewName(super.getDeviceViewName("mypage/MypageReviewForm"));

		return mav;
	}

	/**
	 * 마이페이지 작성가능한 리뷰 목록
	 * @param review
	 * @return
	 * @author sowon
	 * @since 2021. 03. 25
	 */
	@PostMapping("/complete/review/list")
	@ResponseBody
	public GagaMap getMypageCompleteReviewList(@RequestBody Review review) {
		review.setSiteCd(TscConstants.Site.STYLE24.value());
		if (TsfSession.isLogin()) {
			review.setCustNo(TsfSession.getInfo().getCustNo());
		}
		GagaMap result = new GagaMap();
		int reviewExpireDay = eventService.getGoodsReviewRegisterDays(TscConstants.Site.STYLE24.value());
		review.setReviewExpireDay(reviewExpireDay);
		result.set("completeReviewCount", reviewService.getCompleteReviewList(review).size());
		
		TscPageRequest pageable = new TscPageRequest((review.getPageNo() > 0 ? review.getPageNo() - 1 : 0), review.getPageSize(), review.getPageUnit());
		int totalCnt = reviewService.getCompleteReviewList(review).size();
		pageable.setTotalCount(totalCnt);
		review.setPageable(pageable);
		result.set("paging1", review);
		result.set("totalCnt", totalCnt);
		result.set("endRow", pageable.getEndRow());
		result.set("dataList1", reviewService.getCompleteReviewList(review));

		return result;
	}

	/**
	 * 마이페이지 작성한 리뷰 목록
	 * @param review
	 * @return
	 * @author sowon
	 * @since 2021. 03. 26
	 */
	@PostMapping("/already/review/list")
	@ResponseBody
	public GagaMap getMypageAlreadyReviewList(@RequestBody Review review) {
		review.setSiteCd(TscConstants.Site.STYLE24.value());
		GagaMap result = new GagaMap();
		if (TsfSession.isLogin()) {
			review.setCustNo(TsfSession.getInfo().getCustNo());
		}
		
		review.setReviewExpireDay(eventService.getGoodsReviewPointExpireDays(TscConstants.Site.STYLE24.value()));
		result.set("alreadyReviewCount", reviewService.getAlreadyReviewList(review).size());
		TscPageRequest pageable = new TscPageRequest((review.getPageNo() > 0 ? review.getPageNo() - 1 : 0), review.getPageSize(), review.getPageUnit());
		int totalCnt = reviewService.getAlreadyReviewList(review).size();
		pageable.setTotalCount(totalCnt);
		review.setPageable(pageable);
		result.set("paging2", review);
		result.set("totalCnt", totalCnt);
		result.set("endRow", pageable.getEndRow());
		result.set("dataList2", reviewService.getAlreadyReviewList(review));

		return result;
	}

	/**
	 * 마이페이지 리뷰작성화면
	 *
	 * @return
	 * @author sowon	
	 * @since 2021. 03. 25
	 */
	@PostMapping("/review/create/form")
	public ModelAndView mypageReviewCreateForm(Review review) {
		ModelAndView mav = new ModelAndView();
		
		review.setCustNo(TsfSession.getInfo().getCustNo());
		review.setSiteCd(TscConstants.Site.STYLE24.value());
		
		mav.addObject("reviewStat", review.getReviewStat());
		if (review.getReviewStat().equals("u")) {
			// 리뷰 이미지/동영상
			mav.addObject("alreadyReviewAttach", reviewService.getReviewAttach(review));
		}
		review.setReviewExpireDay(eventService.getGoodsReviewRegisterDays(TscConstants.Site.STYLE24.value()));
		mav.addObject("reviewInfo", reviewService.getReviewGoodsInfo(review));
		
		mav.setViewName(super.getDeviceViewName("mypage/MypageReviewCreateForm"));

		return mav;
	}

	/**
	 * 마이페이지 리뷰 저장
	 * @param review
	 * @return
	 * @author sowon
	 * @since 2021. 03. 25
	 */
	@PostMapping("/review/save")
	@ResponseBody
	public GagaMap mypageReviewSave(@RequestBody Review review) {

		GagaMap result = new GagaMap();
		review.setCustNo(TsfSession.getInfo().getCustNo());

		String resultStr = reviewService.saveMypageReview(review);
		
		result.set("status"		, "200");
		result.set("resultStr"	, resultStr);
		
		return result;
	}
	
	/**
	 * 마이페이지 리뷰 업데이트
	 * @param review
	 * @return
	 * @author sowon
	 * @since 2021. 04. 28
	 */
	@PostMapping("/review/update")
	@ResponseBody
	public GagaMap mypageReviewUpdate(@RequestBody Review review) {

		GagaMap result = new GagaMap();
		review.setCustNo(TsfSession.getInfo().getCustNo());
		/*
		 * if (reviewService.reviewDeleteConfirm(review).getCount() > 0) {
		 * review.setReviewSq(reviewService.reviewDeleteConfirm(review).getReviewSq());
		 * }
		 */

		reviewService.updateMypageReview(review);
		result.set("status", "200");

		return result;
	}

	/**
	 * 마이페이지 리뷰 삭제처리
	 *
	 * @param review
	 * @return 
	 * @throws Exception
	 * @author sowon
	 * @since 2021. 03. 26
	 */
	@PostMapping("/review/delete")
	@ResponseBody
	public GagaMap mypageReviewDelete(@RequestBody Review review) throws Exception {
		GagaMap result = new GagaMap();
		review.setCustNo(TsfSession.getInfo().getCustNo());
		review.setSiteCd(TscConstants.Site.STYLE24.value());
		reviewService.reviewDelete(review);
		result.set("alreadyReviewCount",reviewService.getAlreadyReviewList(review).size());
		result.set("completeReviewCount",reviewService.getCompleteReviewList(review).size());
		result.set("status", "200");
		return result;
	}
	
	/**
	 * 상품상세 -  상품평 상세 레이어
	 * @return
	 * @author sowon
	 * @since 2021. 5. 3
	 */
	@PostMapping("/review/detail/layer")
	public ModelAndView mypageReviewDetailForm(Review review) {
		ModelAndView mav = new ModelAndView();
		// 상품관련 기본값 설정(회원 등급, 앱, PC/모바일 등)
		Goods paramsGoods = new Goods();
		paramsGoods.setGoodsCd(review.getGoodsCd());

		// 상품 기본정보
		mav.addObject("params", paramsGoods);

		mav.addObject("review", review);

		mav.addObject("reviewList", reviewService.getMypageReviewList(review));

		mav.setViewName(super.getDeviceViewName("mypage/MypageReviewDetailForm"));
		return mav;
	}
	
	/**
	 * 상품상세 -  상품평 상세 레이어
	 * @return
	 * @author sowon
	 * @since 2021. 3. 8
	 */
	@PostMapping("/review/detail/list")
	@ResponseBody
	public GagaMap getReviewDetailList(@RequestBody Review review) {
		log.info("getReviewDetailList {}", review);
		GagaMap result = new GagaMap();
		result.set("reviewList", reviewService.getMypageReviewList(review));
		return result;
	}
	
	/**
	 * 마이페이지 어드민 댓글 확인
	 *
	 * @param review
	 * @return 
	 * @throws Exception
	 * @author sowon
	 * @since 2021. 04. 15
	 */
	@PostMapping("/review/customer/confirm")
	@ResponseBody
	public GagaMap mypageReviewCustomerConfirm(@RequestBody Review review) throws Exception {
		GagaMap result = new GagaMap();
		reviewService.reviewCustomerConfirm(review);
		result.set("status", "200");
		return result;
	}

	/**
	 * 마이페이지 위시리스트화면
	 *
	 * @return
	 * @author sowon	
	 * @since 2021. 03. 29
	 */
	@GetMapping("/wish/list/form")
	public ModelAndView mypageWishListForm(WishList wishList, Device device) {
		ModelAndView mav = new ModelAndView(super.getDeviceViewName("mypage/MypageWishListForm"));
		wishList.setSiteCd(TscConstants.Site.STYLE24.value());
		wishList.setFrontGb(TsfSession.getFrontGb());
		wishList.setCustGb(TsfSession.getCustGb());
		// 위시리스트 달
		mav.addObject("wishMonth", wishListService.getWishListMonth(wishList));
		return mav;
	}

	/**
	 * 마이페이지 상품목록 가져오기
	 *
	 * @return
	 * @author sowon	
	 * @since 2021. 03. 29
	 */
	@GetMapping("/wish/list")
	@ResponseBody
	public Collection<Goods> getWishList() {
		Collection<Goods> wishList = new ArrayList<>();
		WishList wish = new WishList();
		wish.setSiteCd(TscConstants.Site.STYLE24.value());
		wish.setFrontGb(TsfSession.getFrontGb());
		wish.setCustGb(TsfSession.getCustGb());
		// 위시리스트 상품목록
		wishList = wishListService.getWishListGoodsList(wish);
		return wishList;
	}

	/*신주승 시작*/

	/**
	 * 마이페이지 - 회원정보확인 화면
	 *
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 03. 15
	*/
	@GetMapping("/customer/confirm/form")
	public ModelAndView getCustomerConfirmForm() {
		ModelAndView mav = new ModelAndView();
		Customer customer = customerService.getCustomerFindByCustNo(TsfSession.getInfo().getCustNo());

		mav.addObject("custId", customer.getCustId());

		mav.addObject("snsType", StringUtils.defaultString(customer.getSnsType(), ""));

		// 1.간편가입인데 처음 마이페지로 진입 했을떄
		if (StringUtils.isNotBlank(customer.getSnsType()) && StringUtils.isBlank(customer.getPasswd())) {
			mav.setViewName(super.getDeviceViewName("mypage/MypageCustSnsJoinInitPwdForm"));
		} else {
			mav.setViewName(super.getDeviceViewName("mypage/MypageCustConfirmForm"));
		}

		return mav;
	}

	/**
	 * 마이페이지 - 회원정보확인처리
	 *
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 03. 15
	 */
	@PostMapping("/customer/password/confirm")
	@ResponseBody
	public GagaMap customerPasswordConfirm(@RequestBody Customer customer) {
		GagaMap result = new GagaMap();
		boolean isMatch = customerService.customerPasswordConfirm(customer);
		result.setBoolean("isMatch", isMatch);
		return result;
	}

	/**
	 * 마이페이지 - 회원정보수정 화면
	 *
	 * @param
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 03. 15
	 */
	@RequestMapping("/customer/modify/form")
	public ModelAndView getCustomerModifyForm(@RequestParam(value = "sEncData", required = false) String sEncData ,
											  @RequestParam(value = "authMethod", required = false) String authMethod,
											  HttpServletRequest request) {
		ModelAndView mav = new ModelAndView();
		String referer = StringUtils.defaultIfBlank(TsfSession.getHttpServletRequest().getHeader("referer"), "");
		boolean redirect = false;

		GagaMap custInfoMap = GagaParameterUtil.getParameterMap(request);
		Customer customer = new Customer();
		customer.setPasswd(custInfoMap.getString("passwd"));
		boolean isMatch = customerService.customerPasswordConfirm(customer);

		if (StringUtils.isBlank(referer)) {
			redirect = true;
		}

		if (!isMatch) {
			redirect = true;
		}

		if (!referer.contains("/mypage/customer/confirm/form")) {
			redirect = true;
		}

		if (referer.contains("/customer/nice/certify/callback")) {
			redirect = false;
		}

		if (redirect) {
			mav.setViewName("redirect:/mypage/customer/confirm/form");
			return mav;
		}

		mav.addObject("sEncData", sEncData);
		mav.addObject("authMethod", authMethod);

		mav.addObject("bankList", rendererService.getCommonCodeList("G942", "Y"));

		mav.setViewName(super.getDeviceViewName("mypage/MypageCustModifyForm"));
		return mav;
	}

	/**
	 * 마이페이지 - 회원정보조회
	 *
	 * @return Customer - 고객정보
	 * @author jsshin
	 * @since 2021. 03. 15
	 */
	@GetMapping("/customer/info")
	@ResponseBody
	public Customer getCustomerInfo() {
		Integer custNo = TsfSession.getInfo().getCustNo();
		return customerService.getCustomerFindByCustNo(custNo);
	}

	/**
	 * 마이페이지 - 계좌정보
	 *
	 * @return Customer - 고객정보
	 * @author jsshin
	 * @since 2021. 03. 15
	 */
	@GetMapping("/customer/account/info")
	@ResponseBody
	public CustAccount getCustomerAccuontInfo() {
		Integer custNo = TsfSession.getInfo().getCustNo();
		return customerService.getCustomerAccuontInfo(custNo);
	}

	/**
	 * 마이페이지 - 개명본인인증, 휴대폰 본인인증
	 *
	 * @return GagaMap - 결과
	 * @param customer - 본인인증 값
	 * @author jsshin
	 * @since 2021. 03. 15
	 */
	@PostMapping("/customer/auth/update")
	@ResponseBody
	public GagaMap updateCustomerAuth(@RequestBody Customer customer) {
		GagaMap authInfo = niceCertify.getCertifyCellPhoneResultInfo(customer);
		customer.setSexGb(authInfo.getString("sGender"));
		customer.setCustNo(TsfSession.getInfo().getCustNo());
		customer.setCellPhnno(authInfo.getString("sMobileNo"));
		customer.setCustNm(authInfo.getString("sName"));
		customer.setBirthYmd(authInfo.getString("sBirthDate"));
		return customerService.updateCustomerAuth(customer);
	}

	/**
	 * 마이페이지 - 확인(수정)
	 *
	 * @return GagaMap - 결과
	 * @param customer - 수정 데이터
	 * @author jsshin
	 * @since 2021. 03. 15
	 */
	@PostMapping("/customer/info/save")
	@ResponseBody
	public GagaMap updateCustomerInfo(@RequestBody Customer customer) {
		CustAccount custAccount = new CustAccount();
		custAccount.setIpAddress(TsfSession.getIpAddress());
		custAccount.setAccountNm(customer.getAccountNm());
		custAccount.setAccountNo(customer.getAccountNo());
		custAccount.setBankCd(customer.getBankCd());

		if ("Y".equals(customer.getAccountModifyYn())) {
			GagaMap result = coreKcpService.checkAccount(custAccount);
			if (!"0000".equals(result.get("resCd"))) {
				result.setBoolean("isSuccess", false);
				result.setString("resultType", "INVALID_ACCOUNT");
				return result;
			}
		}

		return customerService.saveCustomerInfo(customer);
	}

	/**
	 * 마이페이지 - 계좌인증
	 *
	 * @return GagaMap - 결과
	 * @author jsshin
	 * @since 2021. 03. 16
	 */
	@PostMapping("/account/check")
	@ResponseBody
	public GagaMap getAccountCheck(@RequestBody CustAccount custAccount) {
		boolean isValid = false;
		GagaMap result = coreKcpService.checkAccount(custAccount);
		if ("0000".equals(result.get("resCd"))) {
			isValid = true;

			// 환불계좌 등록 처리
			if (TsfSession.isLogin()) {
				Integer custNo = TsfSession.getInfo().getCustNo();
				Order refundAccount = new Order();
				refundAccount.setCustNo(custNo);
				refundAccount.setBankCd(custAccount.getBankCd());
				refundAccount.setAccountNo(custAccount.getAccountNo());
				refundAccount.setAccountNm(custAccount.getAccountNm());
				refundAccount.setRegNo(custNo);
				refundAccount.setUpdNo(custNo);
				refundAccount.encryptData();

				coreOrderChangeService.saveRefundAccount(refundAccount);
			}
		}
		result.setBoolean("isValid", isValid);
		return result;
	}

	/**
	 * 마이페이지 - 회원탈퇴 화면
	 *
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 03. 16
	 */
	@GetMapping("/customer/secede/form")
	public ModelAndView getCustomerSecedeForm() {
		ModelAndView mav = new ModelAndView();

		Order order = new Order();
		order.setCustNo(TsfSession.getInfo().getCustNo());

		Point point = new Point();
		point.setCustNo(TsfSession.getInfo().getCustNo());

		// 주문 상태 별 수량 조회
		mav.addObject("orderStatInfo", coreOrderService.getOrderStatCount(order));

		// 포인트정보
		mav.addObject("pointInfo", pointService.getCustomerPoint(point));

		// 상품권 정보 조회
		mav.addObject("rmGfcdAmt", coreOrderService.getGiftcardInfo(order));

		// 쿠폰정보 조회
		mav.addObject("couponCnt", coreOrderService.getCouponInfo(order));

		Customer customer = customerService.getCustomerFindByCustNo(TsfSession.getInfo().getCustNo());

		mav.addObject("snsType", customer.getSnsType());

		mav.addObject("custId", customer.getCustId());

		mav.addObject("custNm", customer.getCustNm());

		if (StringUtils.isNotBlank(customer.getSnsType()) && StringUtils.isBlank(customer.getPasswd())) {
			mav.setViewName("redirect:/mypage/customer/confirm/form");
			return mav;
		}

		mav.setViewName(super.getDeviceViewName("mypage/MypageCustSecedeForm"));

		return mav;
	}

	/**
	 * 마이페이지 - 회원탈퇴
	 *
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 03. 16
	 */
	@PostMapping("/customer/secede/complete/form")
	public ModelAndView getCustomerSecedeCompleteForm(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		Integer custNo = TsfSession.getInfo().getCustNo();

		Order order = new Order();
		order.setCustNo(custNo);

		Point point = new Point();
		point.setCustNo(custNo);

		// 주문 상태 별 수량 조회
		mav.addObject("orderStatInfo", coreOrderService.getOrderStatCount(order));

		// 포인트정보
		mav.addObject("pointInfo", pointService.getCustomerPoint(point));

		// 상품권 정보 조회
		mav.addObject("rmGfcdAmt", coreOrderService.getGiftcardInfo(order));

		// 쿠폰정보 조회
		mav.addObject("couponCnt", coreOrderService.getCouponInfo(order));

		mav.addObject("custNm", TsfSession.getInfo().getCustNm());

		Customer customer = new Customer();
		customer.setCustId(TsfSession.getInfo().getCustId());
		customer.setCustNm(TsfSession.getInfo().getCustNm());
		customer.setEmail(TsfSession.getInfo().getEmail());
		customer.setCustNo(custNo);
		customer.setRegNo(custNo);
		customer.setUpdNo(custNo);
		customer.setSiteCd(TscConstants.Site.STYLE24.value());

		GagaMap result = customerService.saveCustomerSecede(customer);

		boolean isSuccess = result.getBoolean("isSuccess");
		if (!isSuccess) {
			mav.setViewName("redirect:/mypage/customer/secede/form");
			return mav;
		}

		try {
			customer.setRejoinRejectDay(result.getInt("rejoinRejectDay"));
			customer.setSecedeDt(result.getString("secedeDt"));
			customer.setSnsType(result.getString("snsType"));
			mailService.sendSecedComplete(customer, custNo);
		} catch (Exception e) {
			log.error(e.getMessage());
		}

		// RememberMe 쿠키가 있으면
		String ckRememberMe = GagaCookieUtil.getCookie(request, TsfConstants.CK_PREFIX + "_remember-me");

		if (StringUtils.isNotBlank(ckRememberMe)) {
			// 로그인유지토큰 삭제
			loginService.deletePersistentToken(ckRememberMe);

			// RememberMe 쿠키 삭제
			GagaCookieUtil.deleteCookie(response, TsfConstants.CK_PREFIX + "_remember-me");
		}

		//sessionInfo
		TsfSession.invalidate(request);
		mav.addObject("sessionInfo", null);

		mav.setViewName(super.getDeviceViewName("mypage/MypageCustSecedeCompleteForm"));

		return mav;
	}

	/**
	 * 마이페이지 - 비밀번호 변경 팝업
	 *
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 04. 01
	 */
	@PostMapping("/password/modify/form")
	public ModelAndView pwdModifyForm() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("custId", TsfSession.getInfo().getCustId());

		mav.setViewName(super.getDeviceViewName("mypage/MypageCustPwdModifyForm"));

		return mav;
	}

	/**
	 * 마이페이지 - 비밀번호 변경
	 *
	 * @return GagaMap
	 * @author jsshin
	 * @since 2021. 04. 01
	 */
	@PostMapping("/password/change")
	@ResponseBody
	public GagaMap changePassword(@RequestBody Customer customer) {
		Integer custNo = TsfSession.getInfo().getCustNo();
		customer.setCustNo(custNo);
		customer.setRegNo(custNo);
		customer.setUpdNo(custNo);
		return customerService.changePassword(customer);
	}

	/**
	 * 마이페이지 - 배송지관리
	 *
	 * @return ModelAndView
	 * @author jsshin
	 * @since 2021. 04. 01
	 */
	@GetMapping("/delivery/addr/form")
	public ModelAndView getDeliveryListForm() {
		ModelAndView mav = new ModelAndView();
		
		CustDeliveryAddr custDeliveryAddr = new CustDeliveryAddr();
		custDeliveryAddr.setCustNo(TsfSession.getInfo().getCustNo());
		
		Collection<CustDeliveryAddr> deliveryAddrList = customerService.getCustomerDeliveryAddrList(custDeliveryAddr);
		int index 				= 0;
		int deliveryAddrCnt 	= deliveryAddrList.size();
		
		for (CustDeliveryAddr deliveryAddr : deliveryAddrList) {
			if (index == 0) {
				if (deliveryAddr.getRecipZipcode() == null || "".equals(deliveryAddr.getRecipZipcode())) {
					deliveryAddrCnt = 0;
				}
			}
		}
		
		mav.addObject("deliveryAddrCnt"		, deliveryAddrCnt);			// 배송지등록수
		mav.setViewName(super.getDeviceViewName("mypage/MypageCustDeliveryAddrForm"));

		return mav;
	}

	/**
	 * 마이페이지 - 배송지목록
	 *
	 * @return Collection<CustDeliveryAddr>
	 * @author jsshin
	 * @since 2021. 04. 02
	 */
	@GetMapping("/customer/delivery/addr/list")
	@ResponseBody
	public Collection<CustDeliveryAddr> getCustomerDeliveryAddrList() {
		CustDeliveryAddr custDeliveryAddr = new CustDeliveryAddr();
		custDeliveryAddr.setCustNo(TsfSession.getInfo().getCustNo());
		return customerService.getCustomerDeliveryAddrList(custDeliveryAddr);
	}

	/**
	 * 마이페이지 - 배송지 삭제
	 *
	 * @return Collection<CustDeliveryAddr>
	 * @author jsshin
	 * @since 2021. 04. 05
	 */
	@PostMapping("/customer/delivery/addr/delete")
	@ResponseBody
	public GagaMap deleteCustDeliveryAddr(@RequestBody CustDeliveryAddr custDeliveryAddr) {
		return customerService.deleteCustDeliveryAddr(custDeliveryAddr);
	}

	/*신주승 끝*/

	/**
	 * 마이페이지 - 재입고알림
	 * @return ModelAndView
	 * @author gagamel
	 * @since 2021. 4. 13
	 */
	@GetMapping("/restock/form")
	public ModelAndView restockForm() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName(super.getDeviceViewName("mypage/RestockForm"));
		return mav;
	}

	/**
	 * 마이페이지 - 재입고알림 목록
	 * @return
	 * @author gagamel
	 * @since 2021. 4. 13
	 */
	@GetMapping("/restock/list")
	@ResponseBody
	public Collection<ReinboundInform> getRestockList() {
		return reinboundService.getReinboundInformList(TsfSession.getInfo().getCustNo());
	}

	/**
	 * 마이페이지 - 재입고알림 목록
	 * @param params - 재입고알림 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 4. 13
	 */
	@PostMapping("/restock/continue/update")
	@ResponseBody
	public GagaResponse updateRestockContinue(@RequestBody ReinboundInform params) {
		params.setCustNo(TsfSession.getInfo().getCustNo());
		params.setUpdNo(TsfSession.getInfo().getCustNo());
		reinboundService.updateReinboundInformContinue(params);

		return super.ok("알림 기한을 15일로 연장하였습니다.");
	}
	
	/**
	 * 마이페이지 주문목록 조회 (모바일)
	 * 
	 * @param Order
	 * @return ModelAndView
	 * @author jsh77b
	 * @since 2021. 04. 19
	 */
	@ResponseBody
	@PostMapping("/order/listInfo")
	public ModelAndView getOrderListInfo(@RequestBody Order order) {
		
		// 주문목록조회
		ModelAndView mav = new ModelAndView();
		
		// 페이징 처리 설정
		TscPageRequest pageable = new TscPageRequest((order.getPageNo() > 0 ? order.getPageNo() - 1 : 0), order.getPageSize(), order.getPageUnit());
		int totalCnt = orderService.getPagingOrdNoListCount(order);
		pageable.setTotalCount(totalCnt);
		order.setPageable(pageable);
		
		// 페이징 처리 및 주문정보 조회
		List<Integer> ordNoList = new ArrayList<>();

		for (Order tmpOrder : orderService.getPagingOrdNoList(order)) {
			ordNoList.add(tmpOrder.getOrdNo());
		}
		
		if (ordNoList.size() > 0) {
			order.setOrdNoList(ordNoList.stream().mapToInt(Integer::intValue).toArray());
		}

		order.setAutoDecideDay(coreEnvsetService.getAutoBuyConfirmDays(TscConstants.Site.STYLE24.value()));
		Collection<GagaMap> orderList = orderService.getOrderListForMypage(order);
				
		mav.addObject("orderList"		, 	orderList);
		mav.addObject("orderListCnt"	, 	orderList.size());
		mav.addObject("pageNo"			, 	order.getPageNo());
		
		mav.setViewName(super.getDeviceViewName("mypage/MypageOrderListInfo"));

		return mav;
	}
	
	/**
	 * 마이페이지 주문목록 조회 (모바일)
	 * 
	 * @param Order
	 * @return ModelAndView
	 * @author jsh77b
	 * @since 2021. 04. 19
	 */
	@ResponseBody
	@PostMapping("/order/listInfo2")
	public GagaMap getOrderListInfo2(@RequestBody Order order) {
		
		GagaMap result = new GagaMap();
		
		// 페이징 처리 설정
		TscPageRequest pageable = new TscPageRequest((order.getPageNo() > 0 ? order.getPageNo() - 1 : 0), order.getPageSize(), order.getPageUnit());
		int totalCnt = orderService.getPagingOrdNoListCount(order);
		pageable.setTotalCount(orderService.getPagingOrdNoListCount(order));
		order.setPageable(pageable);

		order.setAutoDecideDay(coreEnvsetService.getAutoBuyConfirmDays(TscConstants.Site.STYLE24.value()));

		result.set("paging"		, order);
		result.set("totalCnt"	, totalCnt);
		result.set("endRow"		, pageable.getEndRow());
		result.set("orderList"	, orderService.getOrderListForMypage(order));
		
		// 주문목록조회
		//ModelAndView mav = new ModelAndView();
		//mav.addObject("orderList", orderService.getOrderListForMypage(order));
		//mav.setViewName(super.getDeviceViewName("mypage/MypageOrderListInfo"));

		return result;
	}

	/**
	 * 마이페이지 주문목록 사전 정보 조회 (모바일)
	 * 
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 05. 27
	 */
	@ResponseBody
	@PostMapping("/order/list/pre/info")
	public GagaMap getOrderListPreInfo(@RequestBody Order order) {
		GagaMap result = new GagaMap();

		// 페이징 처리 설정
		TscPageRequest pageable = new TscPageRequest((order.getPageNo() > 0 ? order.getPageNo() - 1 : 0), order.getPageSize(), order.getPageUnit());
		pageable.setTotalCount(orderService.getPagingOrdNoListCount(order));
		order.setPageable(pageable);

		result.set("paging"		, pageable);
		result.set("ordNoList"	, orderService.getPagingOrdNoList(order));

		return result;
	}

	/**
	 * 마이페이지 주문목록 조회 (모바일)
	 *
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 05. 27
	 */
	@ResponseBody
	@PostMapping("/order/list/info")
	public ModelAndView getOrderListInfo3(@RequestBody Order order) {
		// 주문목록조회
		ModelAndView mav = new ModelAndView();

		order.setAutoDecideDay(coreEnvsetService.getAutoBuyConfirmDays(TscConstants.Site.STYLE24.value()));
		Collection<GagaMap> orderList = orderService.getOrderListForMypage(order);

		mav.addObject("orderList"		, 	orderList);
		mav.addObject("orderListCnt"	, 	orderList.size());
		mav.addObject("pageNo"			, 	order.getPageNo());

		mav.setViewName(super.getDeviceViewName("mypage/MypageOrderListInfo"));

		return mav;
	}
	
	/**
	 * 마이페이지 취반교 목록 조회
	 *
	 * @param OrderChange
	 * @return ModelAndView
	 * @author jsh77b
	 * @since 2021. 02. 18
	 */
	@PostMapping("/cre/listInfo")
	@ResponseBody
	public ModelAndView getCreListInfo(@RequestBody OrderChange orderChange) {
		// 주문목록조회
		ModelAndView mav = new ModelAndView();

		// 페이징 처리 설정
		TscPageRequest pageable = new TscPageRequest((orderChange.getPageNo() > 0 ? orderChange.getPageNo() - 1 : 0), orderChange.getPageSize(), orderChange.getPageUnit());
		pageable.setTotalCount(orderChangeService.getPagingCreListCount(orderChange));
		orderChange.setPageable(pageable);

		// 페이징 처리 및 주문정보 조회
		List<Integer> ordChgSqList = new ArrayList<>();

		for (OrderChange tmpOrderChange : orderChangeService.getPagingCreList(orderChange)) {
			ordChgSqList.add(tmpOrderChange.getOrdChgSq());
		}

		if (ordChgSqList.size() > 0) {
			orderChange.setOrdChgSqArr(ordChgSqList.stream().mapToInt(Integer::intValue).toArray());
		}

		mav.addObject("creList", orderChangeService.getCreList(orderChange));
		mav.addObject("creInfo", orderChange);
		mav.setViewName(super.getDeviceViewName("mypage/MypageCreListInfo"));

		return mav;
	}

	/**
	 * 마이페이지 취반교목록 사전 정보 조회 (모바일)
	 *
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 05. 27
	 */
	@ResponseBody
	@PostMapping("/cre/list/pre/info")
	public GagaMap getCreListPreInfo(@RequestBody OrderChange orderChange) {
		GagaMap result = new GagaMap();
		
		orderChange.setCustNo(TsfSession.getInfo().getCustNo());

		// 페이징 처리 설정
		TscPageRequest pageable = new TscPageRequest((orderChange.getPageNo() > 0 ? orderChange.getPageNo() - 1 : 0), orderChange.getPageSize(), orderChange.getPageUnit());
		pageable.setTotalCount(orderChangeService.getPagingCreListCount(orderChange));
		orderChange.setPageable(pageable);

		result.set("paging"		, pageable);
		result.set("creList"	, orderChangeService.getPagingCreList(orderChange));

		return result;
	}

	/**
	 * 마이페이지 취반교목록 조회 (모바일)
	 *
	 * @param Order
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 05. 27
	 */
	@ResponseBody
	@PostMapping("/cre/list/info")
	public ModelAndView getCreListInfo2(@RequestBody OrderChange orderChange) {
		// 주문목록조회
		ModelAndView mav = new ModelAndView();

		orderChange.setCustNo(TsfSession.getInfo().getCustNo());

		Collection<GagaMap> creList = orderChangeService.getCreList(orderChange);

		mav.addObject("creList"			, 	creList);
		mav.addObject("creListCnt"		, 	creList.size());
		mav.addObject("pageNo"			, 	orderChange.getPageNo());

		mav.setViewName(super.getDeviceViewName("mypage/MypageCreListInfo"));

		return mav;
	}

	/**
	 * 선물하기 알림톡 재전송
	 * 
	 * @param order
	 * @return GagaResponse
	 * @author card007
	 * @since 2021. 06. 03
	 */
	@ResponseBody
	@PostMapping("/gift/kakao/resend")
	public GagaResponse resendGiftKakao(@RequestBody Order order) {
		// 선물하기 알림톡 이전 발송이력 조회
		CustContactHst custContactHst = new CustContactHst();
		custContactHst.setContactType(TscConstants.ContactType.GIFT.value());
		custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
		custContactHst.setContactMemo(String.valueOf(order.getOrdNo()));

		int count = customerService.getGiftKakaoSendInfo(custContactHst);
		
		if (count > 0) {
			return super.error("선물하기 SMS를 조금 전 다시 발송하였습니다. 잠시 후 다시 시도해주세요.");
		}

		// 선물하기 알림톡 전송 관련 정보 조회
		GagaMap resultMap = coreOrderService.getOrderCompleteInfo(order);
		Order orderInfo = (Order) resultMap.get("orderInfo");
		orderInfo.setGoodsNm((String) resultMap.get("goodsNm"));
		orderInfo.setGoodsCnt(String.valueOf(resultMap.get("goodsCnt")));
		
		try {
			// 선물하기 알림톡 전송
			coreKakaotalkService.sendOrderGiftComplete(orderInfo, TsfSession.getInfo().getCustNo());
		} catch (Exception e) {
			return super.error(e.getMessage());
		}
		
		return super.ok(env.getProperty("SUCC_0005"));
	}
	
	
	/**
	 * 위시리스트 상품여부 
	 * 
	 * @return
	 * @author eskim
	 * @since 2021. 6. 30
	 */
	@GetMapping("/wish/list/check/{goodsCd}")
	@ResponseBody
	public String getAjaxWishListCheck(@PathVariable(value = "goodsCd") String goodsCd) {
		String result = "N";
		if (wishListService.getWishListGoodsCount(goodsCd) > 0) {
			result = "Y";
		}
		return result;
	}
	
	
}