package com.style24.admin.biz.web;

import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.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.rest.server.GagaResponse;
import com.gagaframework.web.rest.server.GagaResponseStatus;
import com.style24.admin.biz.service.TsaRendererService;
import com.style24.admin.support.controller.TsaBaseController;
import com.style24.admin.support.security.session.TsaSession;
import com.style24.core.biz.service.TscOrderChangeService;
import com.style24.core.biz.service.TscOrderRefundService;
import com.style24.core.biz.service.TscOrderService;
import com.style24.core.support.env.TscConstants;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.domain.Order;
import com.style24.persistence.domain.OrderChange;

import lombok.extern.slf4j.Slf4j;

/**
 * 취소관리 Controller
 *
 * @author jsh77b
 * @since 2020. 11. 16
 */
@Controller
@RequestMapping("/orderChange")
@Slf4j
public class TsaOrderChangeController extends TsaBaseController {
	
	@Autowired
	private TscMessageByLocale message;
	
	@Autowired
	private TsaRendererService rendererService;
	
	@Autowired
	private TscOrderService orderService;
	
	@Autowired
	private TscOrderChangeService orderChangeService;
	
	@Autowired
	private TscOrderRefundService orderRefundService;
	
	/**
	 * 취소요청, 취소완료 통합 화면 (관리자)
	 * 
	 * @param ordNo - 주문번호
	 * @param cncWait - 취소대기요청 구분
	 * @return ModelAndView
	 * @author jsh77b
	 * @since 2020. 12. 22
	 */
	@GetMapping("/cncl/req/form")
	public ModelAndView cnclReqForm(@RequestParam(value = "ordNo") int ordNo, @RequestParam(value = "ordChgSq") int ordChgSq) {

		Order order = new Order();
		ModelAndView mav = new ModelAndView();
		order.setOrdNo(ordNo);
		order.setOrdChgSq(ordChgSq);
				
		// 1. 취소가능 주문상세상탭값 설정
		String[] ordDtlStatArr = new String[4];
		ordDtlStatArr[0] = TscConstants.OrderDetailStat.DEPOSIT_WAIT.value();
		ordDtlStatArr[1] = TscConstants.OrderDetailStat.PAYMENT_COMPLETE.value();
		ordDtlStatArr[2] = TscConstants.OrderDetailStat.GOODS_PREPARE.value();
		ordDtlStatArr[3] = TscConstants.OrderDetailStat.DELIVERY_PREPARE.value();
		order.setOrdDtlStatArr(ordDtlStatArr);
		
		// 2. 변경신청된 주문상세번호를 체크 후 있으면 해당 취소가능수량값 업데이트 
		List<Order> cancelRequestTargetList 		= orderChangeService.getCancelRequestTargetList(order);
		List<Order> orderChangeDetailList 			= orderChangeService.getOrderChangeDetailList(order);
		Collection<Order> orderInfoList 			= orderService.getOrderInfoList(order);
		
		// 3. 화면으로 데이타 전송
		// 2021.01.26 취소요청 화면, 취소요청정보확인 화면 통합
		mav.addObject("chgReasonList"				, rendererService.getAvailCommonCodeList("G686"));				// 취소사유
		mav.addObject("cancelRequestTargetList"		, cancelRequestTargetList);										// 변경신청대상목록 (취소/반품/교환)
		mav.addObject("orderInfoList"				, orderInfoList);												// 주문정보
		mav.addObject("ordNo"						, ordNo);														// 주문번호
		mav.addObject("ordChgSq"					, ordChgSq);													// 주문변경번호
		mav.addObject("orderChangeDetailList"		, orderChangeDetailList);										// 변경신청목록 (취소/반품/교환)
		
		String viewName = "";
		
		/*
		if (ordChgSq > 0) {
			viewName = "order/CnclReqViewForm";		// 변경요청확인화면 (취소요청정보화면)
		} else {
			viewName = "order/CnclReqForm";		// 변경요청화면 (취소요청화면)
		}
		*/
		
		viewName = "order/CnclReqForm";		// 변경요청화면, 변경요청확인화면 (취소요청화면) (통합)

		mav.setViewName(viewName);
		
		return mav;
	}

	/**
	 * 취소요청철회 (관리자)
	 * @param OrderChange - 주문취소신청정보
	 * @return
	 * @author jsh77b
	 * @since 2021. 01. 20
	 */
	@PostMapping("/cnclReqCancel")
	@ResponseBody
	public GagaResponse cnclReqCancel(@RequestBody OrderChange cnclReq) {
		
		if (cnclReq== null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		
		// 1. 세션회원조회
		int userNo = TsaSession.getInfo().getUserNo();
		
		GagaMap mav = new GagaMap();
		mav.set("ordNo"			, cnclReq.getOrdNo());
		mav.set("ordChgSq"		, cnclReq.getOrdChgSq());
		
		// 2.취소요청철회 
		mav = orderChangeService.cnclReqCancel(mav, userNo);
		
		return super.ok("성공");
	}
	
	/**
	 * 취소요청, 취소요청완료, 취소완료 기능 통합 (관리자)
	 * @param Collection<Order> - 주문취소신청목록
	 * @return
	 * @author jsh77b
	 * @since 2020. 12. 29
	 */
	@PostMapping("/cnclComplete")
	@ResponseBody
	public GagaResponse cnclComplete(@RequestBody OrderChange cnclReq) {
		
		if (cnclReq== null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		
		GagaMap mav = new GagaMap();
		
		List<Order> cnclReqList = cnclReq.getCancelReqList(); // 변경요청정보
		
		// TODO
		// @ 결품취소로직 추가
		// @ 주문취소시 상태값 체크
		// @ 취소, 반품시 배송비 체크 로직 (선결제 로직)
		
		// 1. 세션회원조회
		int userNo = TsaSession.getInfo().getUserNo();
		
		// 2. 환불금액계산
		// 2021.01.19 취소신청정보를 목록 (주문상세번호, 취소/반품수량) 으로 표현
		mav = orderRefundService.cnclRtnRefundAmt(cnclReqList);
		
		// 3. 주문변경 기본정보 설정
		mav.set("ordNo"			, cnclReq.getOrdNo());				// 주문번호
		mav.set("ordChgSq"		, cnclReq.getOrdChgSq());			// 주문변경번호
		mav.set("chgReason"		, cnclReq.getChgReason());			// 변경사유
		mav.set("chgMemo"		, cnclReq.getChgMemo());			// 변경메모
		
		mav.set("accountNo"		, cnclReq.getAccountNo());			// 환불계좌번호
		mav.set("accountNm"		, cnclReq.getAccountNm());			// 환불계좌예금주명
		mav.set("bankCd"		, cnclReq.getBankCd());				// 환불계좌은행코드
		
		mav.set("allCanYn"		, cnclReq.getAllCanYn());			// 무통장입금전 전체취소 여부
		mav.set("isCustomer"	, cnclReq.getIsCustomer());			// 변경사유 (고객, 회사)
		
		// 4. 주문변경 회수지정보 추가
		mav.set("chgerNm"		, cnclReq.getChgerNm());			// 변경자명
		mav.set("chgerEmail"	, cnclReq.getChgerEmail());			// 변경자이메일주소
		mav.set("chgerPhnno"	, cnclReq.getChgerPhnno());			// 변경자핸드폰번호
		mav.set("chgerTelno"	, cnclReq.getChgerTelno());			// 변경자전화번호
		
		mav.set("reqGbn"		, cnclReq.getReqGbn());				// 신청구분
				
		// 5. 주문변경 DB 등록 (TB_ORDER_CHANGE, TB_ORDER_CHANGE_DETAIL)
		orderChangeService.cnclComplete(mav, userNo);
		
		return super.ok("성공");
	}
	
	/**
	 * 반품요청 화면 (관리자)
	 * 
	 * @param ordNo - 주문번호
	 * @param cncWait - 취소대기요청 구분
	 * @return ModelAndView
	 * @author jsh77b
	 * @since 2020. 12. 22
	 */
	@GetMapping("/rtn/req/form")
	public ModelAndView rtnReqForm(@RequestParam(value = "ordNo") int ordNo, @RequestParam(value = "ordChgSq") int ordChgSq) {

		Order order = new Order();
		ModelAndView mav = new ModelAndView();
		
		order.setOrdNo(ordNo);
		order.setOrdChgSq(ordChgSq);
		
		// 반품가능 주문상세상탭값 설정
		String[] ordDtlStatArr = new String[3];
		ordDtlStatArr[0] = TscConstants.OrderDetailStat.SHIPPING.value();
		ordDtlStatArr[1] = TscConstants.OrderDetailStat.SHIP_COMPLETE.value();
		ordDtlStatArr[2] = TscConstants.OrderDetailStat.DELIVERY_COMPLETE.value();
		order.setOrdDtlStatArr(ordDtlStatArr);
		
		// 2. 변경신청된 주문상세번호를 체크 후 있으면 해당 취소가능수량값 업데이트 
		List<Order> cancelRequestTargetList 		= orderChangeService.getCancelRequestTargetList(order);
		List<Order> orderChangeDetailList 			= orderChangeService.getOrderChangeDetailList(order);
		Collection<Order> orderInfoList 			= orderService.getOrderInfoList(order);

		if (ordChgSq > 0) {
			Collection<Order> exchangeInfoList = orderChangeService.getExchangeInfo(order);
			mav.addObject("exchangeInfoList"		, exchangeInfoList);								// 교환정보
		}
		
		// 3. 화면으로 데이타 전송
		// 2021.01.26 취소요청 화면, 취소요청정보확인 화면 통합
		mav.addObject("chgReasonList"				, rendererService.getAvailCommonCodeList("G688"));				// 취소사유
		mav.addObject("cancelRequestTargetList"		, cancelRequestTargetList);										// 취소요청대상 목록
		mav.addObject("orderInfoList"				, orderInfoList);												// 주문정보
		mav.addObject("ordNo"						, ordNo);														// 주문번호
		mav.addObject("ordChgSq"					, ordChgSq);													// 주문변경번호
		mav.addObject("orderChangeDetailList"		, orderChangeDetailList);										// 변경신청목록 (취소/반품/교환)
		
		mav.addObject("orderDelvRtnAddrInfo"		, orderService.getDeliveryAddrList(order));						// 배송정보
		mav.addObject("TelExcNoList"				, rendererService.getAvailCommonCodeList("G095"));				// 전화번호국번
		mav.addObject("PhnExcNoList"				, rendererService.getAvailCommonCodeList("G096"));				// (휴대전화)번호국번

		mav.setViewName("order/RtnReqForm");
		
		return mav;
	}
	
	/**
	 * 반품신청 (관리자)
	 * @param Collection<Order> - 주문취소신청목록
	 * @return
	 * @author jsh77b
	 * @since 2020. 12. 29
	 */
	@PostMapping("/rtnReq")
	@ResponseBody
	public GagaResponse rtnReq(@RequestBody OrderChange rtnReq) {
		
		GagaMap mav = new GagaMap();
		
		if (rtnReq== null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		List<Order> cancelReqList = rtnReq.getCancelReqList(); // 변경요청정보
		
		// TODO
		// @ 주문취소시 상태값 체크
		// @ 취소, 반품시 배송비 체크 로직 (선결제 로직)
		
		// 1. 세션회원조회
		int userNo = TsaSession.getInfo().getUserNo();
		
		// 2. 환불금액계산
		mav = orderRefundService.cnclRtnRefundAmt(cancelReqList);
		
		// 3. 주문변경 기본정보 설정
		mav.set("ordNo"			, rtnReq.getOrdNo());				// 주문번호
		mav.set("ordChgSq"		, rtnReq.getOrdChgSq());			// 주문변경번호
		mav.set("chgReason"		, rtnReq.getChgReason());			// 변경사유
		mav.set("chgMemo"		, rtnReq.getChgMemo());				// 변경메모
			
		mav.set("accountNo"		, rtnReq.getAccountNo());			// 환불계좌번호
		mav.set("accountNm"		, rtnReq.getAccountNm());			// 환불계좌예금주명
		mav.set("bankCd"		, rtnReq.getBankCd());				// 환불계좌은행코드
		
		mav.set("allCanYn"		, rtnReq.getAllCanYn());			// 무통장입금전 전체취소 여부 
		mav.set("isCustomer"	, rtnReq.getIsCustomer());			// 변경사유 (고객, 회사)
		mav.set("wdGb"			, rtnReq.getWdGb());				// 회수방법
		
		// 4. 주문변경 회수지정보 추가
		mav.set("chgerNm"		, rtnReq.getChgerNm());				// 변경자명
		mav.set("chgerEmail"	, rtnReq.getChgerEmail());			// 변경자이메일주소
		mav.set("chgerZipcode"	, rtnReq.getChgerZipcode());		// 회수지우편번호
		mav.set("chgerBaseAddr"	, rtnReq.getChgerBaseAddr());		// 회수지기본주소
		mav.set("chgerDtlAddr"	, rtnReq.getChgerDtlAddr());		// 회수지상세주소
		mav.set("chgerPhnno"	, rtnReq.getChgerPhnno());			// 변경자핸드폰번호
		mav.set("chgerTelno"	, rtnReq.getChgerTelno());			// 변경자전화번호
		mav.set("chgerRtnMemo"	, rtnReq.getChgerRtnMemo());		// 반품메모
		
		// 5. 주문변경 DB 등록 (TB_ORDER_CHANGE, TB_ORDER_CHANGE_DETAIL, TB_REFUND)
		orderChangeService.rtnReq(mav, userNo);
		
		return super.ok("성공");
	}
	
	/**
	 * 취소요청철회 (관리자)
	 * @param OrderChange - 주문취소신청정보
	 * @return
	 * @author jsh77b
	 * @since 2021. 01. 20
	 */
	@PostMapping("/rtnReqCancel")
	@ResponseBody
	public GagaResponse rtnReqCancel(@RequestBody OrderChange cnclReq) {
		
		if (cnclReq== null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		
		// 1. 세션회원조회
		int userNo = TsaSession.getInfo().getUserNo();
		
		GagaMap mav = new GagaMap();
		mav.set("ordNo"			, cnclReq.getOrdNo());
		mav.set("ordChgSq"		, cnclReq.getOrdChgSq());
		
		// 2.취소요청철회 
		mav = orderChangeService.rtnReqCancel(mav, userNo);
		
		return super.ok("성공");
	}
	
	/**
	 * 주문 취소/반품 신청환불금액 계산
	 * @param Collection<Order>- 주문취소신청목록
	 * @return
	 * @author jsh77b
	 * @since 2020. 12. 29
	 */
	@PostMapping("/cancel/refundAmt")
	@ResponseBody
	public GagaMap orderCancelRefundAmt(@RequestBody List<Order> cancelReqList) {
		
		GagaMap mav = new GagaMap();
		
		if (cancelReqList == null || cancelReqList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		
		// 1. 환불금액정보 계산 & 조회
		mav = orderRefundService.cnclRtnRefundAmt(cancelReqList);
		
		return mav;
	}
	
	/**
	 * 환불계좌목록
	 *
	 * @param ordNo - 주문번호
	 * @param custNo - 고객고유번호
	 * @return Collection<TsaOrder>
	 * @author jsshin
	 * @since 2020. 10. 16.
	 */
	@GetMapping("/refund/account/info/list")
	@ResponseBody
	public Collection<Order> getRefundAccountInfoList(@RequestParam(value = "ordNo") int ordNo) {
		Order order = new Order();
		order.setOrdNo(ordNo);

		Collection<Order> orderRfAccountInfo = orderChangeService.getRefundAccount(order);

		return orderRfAccountInfo;
	}
	
	/**
	 * 환불계좌등록 화면
	 *
	 * @param ordNo - 주문번호
	 * @param custNo - 고객고유번호
	 * @return ModelAndView
	 * @author jsh77b
	 * @since 2021. 01. 04.
	 */
	@GetMapping("/refund/account/create/form")
	public ModelAndView refundAccountCreateForm(@RequestParam(value = "ordNo") int ordNo) {
		ModelAndView mav = new ModelAndView();
		Order order = new Order();
		order.setOrdNo(ordNo);

		Collection<Order> orderBasic 			= orderService.getOrderInfoList(order);
		Collection<Order> orderRfAccountInfo 	= orderChangeService.getRefundAccount(order);

		mav.addObject("bankList"				, rendererService.getCommonCodeList("G940"));
		mav.addObject("orderRfAccountInfo"		, orderRfAccountInfo);
		mav.addObject("orderBasic"				, orderBasic);

		mav.setViewName("order/RefundAccountRegistForm");
		
		return mav;
	}
	
	/**
	 * 환불계좌등록
	 *
	 * @param order - 환불계좌정보
	 * @return GagaResponse
	 * @author jsh77b
	 * @since 2021. 01. 04.
	 */
	@PostMapping("/account/save")
	@ResponseBody
	public GagaResponse saveRefundAccount(@RequestBody Order order) {
		
		int userNo = TsaSession.getInfo().getUserNo();
		order.setUpdNo(userNo);
		order.setRegNo(userNo);
		
		String accountCheck = "Y";
		
		// TODO
		// @ 환불계좌인증
		
		if ("Y".equals(accountCheck)) {
			orderChangeService.saveRefundAccount(order);
		} else {
			throw new IllegalStateException("환불계좌정보가 맞지 않습니다!");
		}

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

	/**
	 * 교환요청 화면
	 *
	 * @param ordNo - 주문번호
	 * @return ModelAndView
	 * @author card007
	 * @since 2021. 01. 14
	 */
	@GetMapping("/exchange/request/form")
	public ModelAndView exchangeRequestFrom(@RequestParam(value = "ordNo") int ordNo, @RequestParam(value = "ordChgSq") int ordChgSq) {

		Order order = new Order();
		ModelAndView mav = new ModelAndView();

		order.setOrdNo(ordNo);
		order.setOrdChgSq(ordChgSq);

		// 교환가능 주문상세상탭값 설정
		String[] ordDtlStatArr = new String[3];
		ordDtlStatArr[0] = TscConstants.OrderDetailStat.SHIPPING.value();
		ordDtlStatArr[1] = TscConstants.OrderDetailStat.SHIP_COMPLETE.value();
		ordDtlStatArr[2] = TscConstants.OrderDetailStat.DELIVERY_COMPLETE.value();
		order.setOrdDtlStatArr(ordDtlStatArr);

		Collection<Order> cancelRequestTargetList = orderChangeService.getCancelRequestTargetList(order);
		Collection<Order> orderInfoList = orderService.getOrderInfoList(order);

		if (ordChgSq > 0) {
			Collection<Order> exchangeInfoList = orderChangeService.getExchangeInfo(order);
			mav.addObject("exchangeInfoList"		, exchangeInfoList);								// 교환정보
		}

		mav.addObject("chgReasonList"				, rendererService.getAvailCommonCodeList("G689"));	// 교환사유
		mav.addObject("cancelRequestTargetList"		, cancelRequestTargetList);							// 교환요청대상 목록
		mav.addObject("orderInfoList"				, orderInfoList);									// 주문정보
		mav.addObject("ordNo"						, ordNo);											// 주문번호
		mav.addObject("ordChgSq"					, ordChgSq);										// 주문변경번호
		mav.addObject("orderDelvAddrInfo"			, orderService.getDeliveryAddrList(order));			// 배송정보
		mav.addObject("TelExcNoList"				, rendererService.getAvailCommonCodeList("G095"));	// 전화번호국번
		mav.addObject("PhnExcNoList"				, rendererService.getAvailCommonCodeList("G096"));	// (휴대전화)번호국번

		mav.setViewName("order/ExchangeRequestForm");

		return mav;
	}

	/**
	 * 교환신청 (관리자)
	 *
	 * @param Collection<OrderChange>
	 * @return
	 * @author card007
	 * @since 2021. 01. 22
	 */
	@PostMapping("/exchangeRequest")
	@ResponseBody
	public GagaMap orderExchangeRequest(@RequestBody OrderChange excReq) {
		GagaMap result = new GagaMap();
		result.set("status", GagaResponseStatus.FAIL.getCode());

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

		// 세션 회원번호 설정
		int userNo = TsaSession.getInfo().getUserNo();
		excReq.setUpdNo(userNo);
		excReq.setRegNo(userNo);

		// 교환처리
		result = orderChangeService.exchReq(excReq);

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

	/**
	 * 교환철회 (관리자)
	 *
	 * @param Collection<OrderChange>
	 * @return
	 * @author card007rtn
	 * @since 2021. 01. 22
	 */
	@PostMapping("/exchangeCancelRequest")
	@ResponseBody
	public GagaMap orderExchangeCancelRequest(@RequestBody OrderChange excReq) {
		GagaMap result = new GagaMap();
		result.set("status", GagaResponseStatus.FAIL.getCode());

		// 교환철회 요청 데이터 확인
		if (excReq == null) {
			result.set("message", message.getMessage("FAIL_1001"));
			return result;
		}

		// 세션 회원번호 설정
		int userNo = TsaSession.getInfo().getUserNo();
		excReq.setUpdNo(userNo);
		excReq.setRegNo(userNo);

		// 교환철회 처리
		result = orderChangeService.exchangeCancel(excReq);

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

		return result;
	}

	/**
	 * 취소요청 (ADMIN, NAPY, 외부몰) (배치) (사용안함)
	 * 
	 * @param OrderChange - 주문취소신청정보
	 * @return
	 * @author jsh77b
	 * @since 2021. 01. 20
	 */
	@PostMapping("/cnclReq")
	@ResponseBody
	public GagaResponse cnclReq(@RequestBody OrderChange cnclReq) {
		
		GagaMap mav = new GagaMap();
		
		if (cnclReq== null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		
		List<Order> cnclReqList = cnclReq.getCancelReqList(); // 취소요청정보목록
		
		// TODO
		// @ 결품취소로직 추가
		// @ 주문취소시 상태값 체크
		// @ 취소, 반품시 배송비 체크 로직 (선결제 로직)
		
		// 1. 세션회원조회
		int userNo = TsaSession.getInfo().getUserNo();
		
		// 2. 환불금액계산
		// 2021.01.19 취소신청정보를 목록 (주문상세번호, 취소/반품수량) 으로 표현
		mav = orderRefundService.cnclRtnRefundAmt(cnclReqList);
		
		// 3. 주문변경 기본정보 설정
		mav.set("ordNo"			, cnclReq.getOrdNo());				// 주문번호
		mav.set("chgReason"		, cnclReq.getChgReason());			// 변경사유
		mav.set("chgMemo"		, cnclReq.getChgMemo());			// 변경메모
		
		mav.set("accountNo"		, cnclReq.getAccountNo());			// 환불계좌번호
		mav.set("accountNm"		, cnclReq.getAccountNm());			// 환불계좌예금주명
		mav.set("bankCd"		, cnclReq.getBankCd());				// 환불계좌은행코드
		
		mav.set("allCanYn"		, cnclReq.getAllCanYn());			// 무통장입금전 전체취소 여부
		mav.set("isCustomer"	, cnclReq.getIsCustomer());			// 변경사유 (고객, 회사)
		
		// 4. 주문변경 회수지정보 추가
		mav.set("chgerNm"		, cnclReq.getChgerNm());			// 변경자명
		mav.set("chgerEmail"	, cnclReq.getChgerEmail());			// 변경자이메일주소
		mav.set("chgerPhnno"	, cnclReq.getChgerPhnno());			// 변경자핸드폰번호
		mav.set("chgerTelno"	, cnclReq.getChgerTelno());			// 변경자전화번호
		
		mav.set("reqGbn"		, cnclReq.getReqGbn());				// 신청구분
						
		// 5. 주문변경 DB 등록 (TB_ORDER_CHANGE, TB_ORDER_CHANGE_DETAIL, TB_REFUND)
		orderChangeService.cnclComplete(mav, userNo);
		
		return super.ok("성공");
	}
	
	/**
	 * 취소요청승인 (관리자)
	 * @param OrderChange - 주문취소신청정보
	 * @return
	 * @author jsh77b
	 * @since 2021. 01. 20
	 */
	@PostMapping("/cnclReqComplete")
	@ResponseBody
	public GagaResponse cnclReqComplete(@RequestBody OrderChange cnclReq) {
		
		if (cnclReq== null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}
		
		// 1. 세션회원조회
		int userNo = TsaSession.getInfo().getUserNo();
		
		GagaMap mav = new GagaMap();
		mav.set("ordNo"			, cnclReq.getOrdNo());
		mav.set("ordChgSq"		, cnclReq.getOrdChgSq());
		
		// 2.취소요청철회 
		mav = orderChangeService.cnclComplete(mav, userNo);
		
		return super.ok("성공");
	}
}










