package com.style24.admin.biz.web;

import java.io.File;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.gagaframework.excel.GagaExcelUtil;
import com.gagaframework.shoplinker.GagaShoplinkertUtil;
import com.gagaframework.shoplinker.env.GagaShoplinkerConstants;
import com.gagaframework.web.parameter.GagaMap;
import com.gagaframework.web.rest.server.GagaResponse;
import com.gagaframework.web.util.GagaDateUtil;
import com.gagaframework.web.util.GagaFileUtil;
import com.style24.admin.biz.service.TsaOcmService;
import com.style24.admin.biz.service.TsaRendererService;
import com.style24.admin.biz.service.TsaShoplinkerService;
import com.style24.admin.support.controller.TsaBaseController;
import com.style24.admin.support.security.session.TsaSession;
import com.style24.core.biz.service.TscOrderOcmService;
import com.style24.core.biz.service.TscShoplinkerService;
import com.style24.core.support.env.TscConstants;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.TscPageRequest;
import com.style24.persistence.domain.CommonCode;
import com.style24.persistence.domain.Extmall;
import com.style24.persistence.domain.ShoplinkerGoods;
import com.style24.persistence.domain.ShoplinkerInvoice;
import com.style24.persistence.domain.ShoplinkerOrder;
import com.style24.persistence.domain.ShoplinkerSearch;

import lombok.extern.slf4j.Slf4j;

/**
 * 샵링커 Controller
 *
 * @author jmh
 * @since 2021. 5. 20
 */
@Controller
@RequestMapping("/shoplinker")
@Slf4j
public class TsaShoplinkerController extends TsaBaseController {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private Environment env;

	@Autowired
	private TscShoplinkerService tscShoplinkerService;

	@Autowired
	private TsaShoplinkerService admShoplinkerService;

	@Autowired
	private TsaOcmService ocmService;

	@Autowired
	private TscOrderOcmService orderOcmService;

	@Autowired
	private TsaRendererService rendererService;

	@Autowired
	private ObjectMapper mapper;

	private static final int EXCEL_ROW_COUNT = 500;



	/**
	 * 샵링커상품등록-화면
	 *
	 * @return
	 * @author jmh
	 * @since 2021. 5. 20
	 */
	@GetMapping("/goods/send/form")
	public ModelAndView goodsSendForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("shoplinker/ShoplinkerGoodsSendForm");

		return mav;
	}

	/**
	 * 샵링커상품등록-전송목록조회
	 *
	 * @return shoplinkerSearch
	 * @author jmh
	 * @since 2021. 5. 20
	 */
	@PostMapping("/goods/send/list")
	@ResponseBody
	public GagaMap getSendGoodsList(@RequestBody ShoplinkerSearch shoplinkerSearch) {

		GagaMap result = new GagaMap();

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

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

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

		result.set("pageing", shoplinkerSearch);
		result.set("goodsList", admShoplinkerService.getGoodsSendList(shoplinkerSearch));

		return result;
	}

	/**
	 * 샵링커상품등록-상품등록엑셀업로드 수량체크
	 *
	 * @param paramMap
	 * @return GagaMap
	 * @throws Exception
	 * @author jmh
	 * @since 2021.5.20
	 */
	@PostMapping("/goods/send/excelupload/register/chk")
	@ResponseBody
	public GagaResponse shoplinkerGoodsRegisterChk(@RequestBody ShoplinkerGoods shoplinkerGoods) throws Exception {

		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
		Collection<GagaMap> ecxelGoodsList = new ArrayList<>();
		String[] goodsNames = {"goodsCd"};
		ecxelGoodsList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, shoplinkerGoods.getExcelFileNm()), 0, goodsNames, 0);

		if (ecxelGoodsList != null && ecxelGoodsList.size() > EXCEL_ROW_COUNT) {
			GagaFileUtil.deleteFile(GagaFileUtil.getConcatenationPath(targetPath, shoplinkerGoods.getExcelFileNm()));
			throw new IllegalStateException("엑셀 파일의 건수를 " +EXCEL_ROW_COUNT + "건 이하로 사용하세요.");
		}

		return super.ok("");
	}

	/**
	 * 샵링커상품등록-상품등록엑셀업로드
	 *
	 * @param paramMap
	 * @return GagaMap
	 * @throws Exception
	 * @author jmh
	 * @since 2021.5.20
	 */
	@PostMapping("/goods/send/excelupload/register")
	@ResponseBody
	public void shoplinkerGoodsRegister(@RequestParam HashMap<String, String> paramMap) throws Exception {

		ShoplinkerGoods shoplinkerGoods = new ShoplinkerGoods();
		shoplinkerGoods.setExcelFileNm(paramMap.get("excelFileNm"));

		String profiles = env.getProperty("spring.profiles.active").toLowerCase();
		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
		Collection<GagaMap> ecxelGoodsList = new ArrayList<>();

		// API 호출 중인건수 있는지 확인
		ShoplinkerSearch slkSearch = new ShoplinkerSearch();
		slkSearch.setApiType("GOODS");
		slkSearch.setSid(paramMap.get("sid"));
		slkSearch.setRegNo(TsaSession.getInfo().getUserNo());
		ShoplinkerSearch runMap = tscShoplinkerService.getCallRunableInfoGoods(slkSearch);

log.info(" #### SHOPLINKER CHKE 1 - "+runMap.getRunCnt()+" | "+runMap.getSidOverlapCnt() +" | "+paramMap.get("sid"));
		if( runMap.getRunCnt() < 1 && runMap.getSidOverlapCnt() < 1 ) {
			try {
				// 1. API 호출 이력 저장 시작(실행중 재호출 금지하기 위함)
				tscShoplinkerService.saveCallApiRunable(slkSearch);

				// 2. 엑셀데이터 확인 및 xml 관련 위치 확인
				String[] goodsNames = {"goodsCd"};
				ecxelGoodsList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, shoplinkerGoods.getExcelFileNm()), 0, goodsNames, 0);

				if (ecxelGoodsList != null && ecxelGoodsList.size() > EXCEL_ROW_COUNT) {
					throw new IllegalStateException("엑셀 파일의 건수를 " +EXCEL_ROW_COUNT + "건 이하로 사용하세요.");
				}

				// xml 생성경로
				shoplinkerGoods.setXmlPath(env.getProperty("shoplinker.xml.path")+"/goods_reg");
				// xml 확인domain url
				shoplinkerGoods.setDomainUrl(env.getProperty("shoplinker.xml.view")+"/goods_reg");

				// 샵링커 기본폴더 존재여부 확인
				String slFolder = GagaFileUtil.getConcatenationPath(env.getProperty("shoplinker.xml.path"));
				File slPath = new File(slFolder);
				if (!slPath.exists()) {
					slPath.mkdir();
				}
				//하위폴더존재확인(상품등록)
				slFolder = GagaFileUtil.getConcatenationPath(shoplinkerGoods.getXmlPath());
				slPath = new File(slFolder);
				if (!slPath.exists()) {
					slPath.mkdir();
				}

				// 3. xml 데이터 생성
				shoplinkerGoods.setCustomerId(env.getProperty("shoplinker.customer_id"));
				shoplinkerGoods.setRegNo(TsaSession.getInfo().getUserNo());
				admShoplinkerService.createShoplinkerXml(ecxelGoodsList, shoplinkerGoods);

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

				slkSearch.setRunStat(TscConstants.ShoplinkerApiStat.END.value());	// 상태값지정

			}catch (Exception e) {

				log.error("TsaShoplinkerController.orderReceiveList => error \n"+e);
				slkSearch.setRunStat(TscConstants.ShoplinkerApiStat.ERROR.value());	// 상태값지정

			}finally {
				// 5. API 호출 이력 저장 종료
				tscShoplinkerService.saveCallApiRunable(slkSearch);
			}
		}
	}

	/**
	 * 샵링커상품등록- 엑셀다운로드
	 *
	 * @param shoplinkerSearch
	 * @return
	 * @author jmh
	 * @since 2021. 06. 29
	 */
	@GetMapping("/goods/excel/list")
	public ResponseEntity<InputStreamResource> downloadGoodsInfoExcelList(HttpServletRequest request, ShoplinkerSearch shoplinkerSearch) throws Exception {
		String excelfileName = "샵링커_상품_" + GagaDateUtil.getTodayDateTime() + ".xlsx";
		String excelFilenameWithPath = GagaFileUtil.getConcatenationPath(env.getProperty("download.path"), "excel", excelfileName);

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

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

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

		admShoplinkerService.getGoodsSendExcelList(shoplinkerSearch, excelFilenameWithPath);

		return GagaFileUtil.writeFile(request, excelFilenameWithPath);
	}


	/**
	 * 재고이력-화면
	 * @return ModelAndView
	 * @author jmh
	 * @since 2021. 5. 20
	 */
	@GetMapping("/stock/result/form")
	public ModelAndView stockHistoryForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("shoplinker/ShoplinkerStockForm");

		return mav;
	}

	/**
	 * 재고이력-목록조회
	 *
	 * @param shoplinkerSearch
	 * @return GagaMap
	 * @author jmh
	 * @since 2021. 5. 20
	 */
	@PostMapping("/stock/result/list")
	@ResponseBody
	public GagaMap getStockHistoryList(@RequestBody ShoplinkerSearch shoplinkerSearch) {

		GagaMap result = new GagaMap();

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

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

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

		result.set("pageing", shoplinkerSearch);
		result.set("stockList", admShoplinkerService.getStockList(shoplinkerSearch));

		return result;
	}

	/**
	 * 재고이력-엑셀다운로드
	 *
	 * @param shoplinkerSearch
	 * @return
	 * @author jmh
	 * @since 2021. 06. 29
	 */
	@GetMapping("/stock/excel/list")
	public ResponseEntity<InputStreamResource> downloadStockInfoExcelList(HttpServletRequest request, ShoplinkerSearch shoplinkerSearch) throws Exception {
		String excelfileName = "샵링커_재고_" + GagaDateUtil.getTodayDateTime() + ".xlsx";
		String excelFilenameWithPath = GagaFileUtil.getConcatenationPath(env.getProperty("download.path"), "excel", excelfileName);

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

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

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

		admShoplinkerService.getStockExcelList(shoplinkerSearch, excelFilenameWithPath);

		return GagaFileUtil.writeFile(request, excelFilenameWithPath);
	}


	/**
	 * 주문수집관리-화면
	 * @return
	 * @author jmh
	 * @since 2021. 5. 20
	 */
	@GetMapping("/order/collection/form")
	public ModelAndView orderCollectionForm() {
		ModelAndView mav = new ModelAndView();

		// 제휴몰벤더
		mav.addObject("vendorList", rendererService.getCommonCodeList("G003", "Y", TsaSession.getInfo().getSupplyCompCd()));

		// 제휴몰
		Extmall extmall = new Extmall();
		extmall.setVendorId(TscConstants.VendorId.SHOPLINKER.value()); // 샵링커
		mav.addObject("extmallList", ocmService.getExtmallList(extmall));

		// 업로드상태 콤보박스 목록
		CommonCode commoncode = new CommonCode();
		commoncode.setCdGb("G021");
		commoncode.setUseYn("Y");
		mav.addObject("uploadStatList", rendererService.getCommonCodeList(commoncode));

		// 업로드실패사유 콤보박스 목록
		commoncode.setCdGb("G022");
		mav.addObject("uploadFailList", rendererService.getCommonCodeList(commoncode));

		mav.setViewName("shoplinker/ShoplinkerOrderForm");

		return mav;
	}

	/**
	 * 주문수집관리-목록조회
	 *
	 * @return shoplinkerOrder
	 * @author jmh
	 * @since 2021. 5. 20
	 */
	@PostMapping("/order/collection/list")
	@ResponseBody
	public GagaMap getCollectionList(@RequestBody ShoplinkerOrder shoplinkerOrder) {

		GagaMap result = new GagaMap();

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

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

		result.set("pageing", shoplinkerOrder);
		result.set("shoplinkerOrderList", admShoplinkerService.getShoplinkerOrderList(shoplinkerOrder));

		return result;
	}

	/**
	 * 주문수집관리-주문상세 화면
	 *
	 * @param ordNo - 주문번호
	 * @return ModelAndView
	 * @author jmh
	 * @since 2021. 5. 20
	 */
	@GetMapping("/order/collection/info")
	@ResponseBody
	public ModelAndView collectionOrderForm(@RequestParam(value = "shoplinkerOrderId") String shoplinkerOrderId) {
		ModelAndView mav = new ModelAndView();

		ShoplinkerOrder order = new ShoplinkerOrder();
		order.setShoplinkerOrderId(shoplinkerOrderId);

		mav.addObject("slkOrderInfo", admShoplinkerService.getShoplinkerOrderInfo(order));
		mav.addObject("extOrderInfo", admShoplinkerService.getExtmallOrderInfo(shoplinkerOrderId));

		mav.setViewName("shoplinker/ShoplinkerOrderDetailForm");

		return mav;
	}

	/**
	 * 주문수집관리-주문수집 api 호출
	 * @param apiStDate
	 * @author jmh
	 * @throws Exception
	 * @since 2021. 5. 20
	 */
	@PostMapping("/order/collection/receiveList/{apiStDate}")
	@ResponseBody
	public void orderReceiveList(@PathVariable("apiStDate") String apiStDate) throws Exception {

		GagaMap rtnMap = new GagaMap();

		ShoplinkerOrder shoplinkerOrder = new ShoplinkerOrder();
		shoplinkerOrder.setStDate(apiStDate);
		shoplinkerOrder.setEdDate(apiStDate);
		shoplinkerOrder.setInfoStr(apiStDate);	// shoplinker_runable.txt 에 참고할 텍스트

		// 서버타입
		String profiles = env.getProperty("spring.profiles.active").toLowerCase();
		// xml path
		shoplinkerOrder.setXmlPath(env.getProperty("shoplinker.xml.path")+"/order");
		// xml 확인domain url
		shoplinkerOrder.setDomainUrl(env.getProperty("shoplinker.xml.view")+"/order");

		// 하위폴더존재확인(주문)
		String slFolder = GagaFileUtil.getConcatenationPath(shoplinkerOrder.getXmlPath());
		File slPath = new File(slFolder);
		if (!slPath.exists()) {
			slPath.mkdir();
		}

		// API 호출 중인건수 있는지 확인
		ShoplinkerSearch slkSearch = new ShoplinkerSearch();
		slkSearch.setApiType("ORDER");
		slkSearch.setRegNo(TsaSession.getInfo().getUserNo());
		ShoplinkerSearch runMap = tscShoplinkerService.getCallRunableInfo(slkSearch);

		if( runMap.getRunCnt() < 1 ) {
			try {
				// 1. API 호출 이력 저장 시작(실행중 재호출 금지하기 위함)
				slkSearch.setSid(GagaDateUtil.getTodayDateTime());
				tscShoplinkerService.saveCallApiRunable(slkSearch);

				// 2. 샵링커 api 호출 샵링커주문수집 등록
				shoplinkerOrder.setSid(slkSearch.getSid());
				shoplinkerOrder.setProfiles(profiles);
				shoplinkerOrder.setCustomerId(env.getProperty("shoplinker.customer_id"));
				shoplinkerOrder.setShoplinkerId(env.getProperty("shoplinker.shoplinker_id"));
				shoplinkerOrder.setRegNo(TsaSession.getInfo().getUserNo());
				shoplinkerOrder.setAcType("ADMMIN");
				rtnMap = tscShoplinkerService.insertShoplinkerOrderStep1(shoplinkerOrder);

				if(TscConstants.ShoplinkerApiStat.TRUE.value().equals(rtnMap.getString("RESULT_TYPE"))) {
					// 3. 제휴몰 주문등록
					slkSearch.setTxt("=>제휴몰");
					tscShoplinkerService.updateCallApiRunable(slkSearch);
					tscShoplinkerService.insertShoplinkerOrderStep2(shoplinkerOrder);

					// 4. 스타일24 주문등록 (제휴몰 - 대기상태인 것들)
					slkSearch.setTxt("=>스타일24");
					tscShoplinkerService.updateCallApiRunable(slkSearch);
					orderOcmService.createShoplinkerOrder("S", TsaSession.getInfo().getUserNo());
				}

				slkSearch.setRunStat(TscConstants.ShoplinkerApiStat.END.value());	// 상태값지정
				slkSearch.setTxt("=>FINISH");

			}catch (Exception e) {

				log.error("TsaShoplinkerController.orderReceiveList => error \n"+e);
				slkSearch.setRunStat(TscConstants.ShoplinkerApiStat.ERROR.value());	// 상태값지정
				slkSearch.setTxt("=>ERROR : "+StringUtils.abbreviate(e.getMessage(), 0 , 120));

			}finally {
				// 4. API 호출 이력 저장 종료
				tscShoplinkerService.saveCallApiRunable(slkSearch);
			}
		}
	}

	/**
	 * 주문수집관리-엑셀다운로드
	 *
	 * @param shoplinkerOrder
	 * @return
	 * @author jmh
	 * @since 2021. 06. 29
	 */
	@GetMapping("/order/excel/list")
	public ResponseEntity<InputStreamResource> downloadOrderInfoExcelList(HttpServletRequest request, ShoplinkerOrder shoplinkerOrder) throws Exception {
		String excelfileName = "샵링커_주문_" + GagaDateUtil.getTodayDateTime() + ".xlsx";
		String excelFilenameWithPath = GagaFileUtil.getConcatenationPath(env.getProperty("download.path"), "excel", excelfileName);

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

		admShoplinkerService.getOrderExcelList(shoplinkerOrder, excelFilenameWithPath);

		return GagaFileUtil.writeFile(request, excelFilenameWithPath);
	}


	/**
	 * 송장전송관리-화면
	 * @return ModelAndView
	 * @author jmh
	 * @since 2021. 5. 20
	 */
	@GetMapping("/invoice/send/form")
	public ModelAndView invoiceSendForm() {
		ModelAndView mav = new ModelAndView();

		// 제휴몰벤더
		mav.addObject("vendorList", rendererService.getCommonCodeList("G003", "Y", TsaSession.getInfo().getSupplyCompCd()));

		// 제휴몰
		Extmall extmall = new Extmall();
		extmall.setVendorId(TscConstants.VendorId.SHOPLINKER.value()); // 샵링커
		mav.addObject("extmallList", ocmService.getExtmallList(extmall));

		mav.setViewName("shoplinker/ShoplinkerInvoiceSendForm");

		return mav;
	}

	/**
	 * 송장전송관리-전송목록조회
	 *
	 * @param shoplinkerInvoice
	 * @return GagaMap
	 * @author jmh
	 * @since 2021. 5. 20
	 */
	@PostMapping("/invoice/send/list")
	@ResponseBody
	public GagaMap getInvoiceSendList(@RequestBody ShoplinkerInvoice shoplinkerInvoice) {

		GagaMap result = new GagaMap();

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

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

		result.set("pageing", shoplinkerInvoice);
		result.set("invoiceList", admShoplinkerService.getSendInvoiceList(shoplinkerInvoice));

		return result;
	}

	/**
	 * 송장전송관리-송장전송
	 *
	 * @param
	 * @throws Exception
	 * @author jmh
	 * @since 2021.5.20
	 */
	@PostMapping("/invoice/send/register")
	@ResponseBody
	public void shoplinkerSendInvoice(@RequestParam(value = "stDate") String stDate, @RequestParam(value = "edDate") String edDate) throws Exception {

		// API 호출 중인건수 있는지 확인
		ShoplinkerSearch slkSearch = new ShoplinkerSearch();
		slkSearch.setApiType("INVOICE");
		ShoplinkerSearch runMap = tscShoplinkerService.getCallRunableInfo(slkSearch);

		if( runMap.getRunCnt() < 1 ) {
			try {
				// 1. API 호출 이력 저장 시작(실행중 재호출 금지하기 위함)
				slkSearch.setSid(GagaDateUtil.getTodayDateTime());
				slkSearch.setRegNo(TsaSession.getInfo().getUserNo());
				tscShoplinkerService.saveCallApiRunable(slkSearch);

				ShoplinkerInvoice shoplinkerInvoice = new ShoplinkerInvoice();
				shoplinkerInvoice.setStDate(stDate);
				shoplinkerInvoice.setEdDate(edDate);

				// xml 생성경로
				shoplinkerInvoice.setXmlPath(env.getProperty("shoplinker.xml.path")+"/invoice");
				// xml 확인domain url
				shoplinkerInvoice.setDomainUrl(env.getProperty("shoplinker.xml.view")+"/invoice");

				// 샵링커 기본폴더 존재여부 확인
				String slFolder = GagaFileUtil.getConcatenationPath(env.getProperty("shoplinker.xml.path"));
				File slPath = new File(slFolder);
				if (!slPath.exists()) {
					slPath.mkdir();
				}
				//하위폴더존재확인(상품등록)
				slFolder = GagaFileUtil.getConcatenationPath(shoplinkerInvoice.getXmlPath());
				slPath = new File(slFolder);
				if (!slPath.exists()) {
					slPath.mkdir();
				}

				// 2. xml 데이터 생성
				shoplinkerInvoice.setCustomerId(env.getProperty("shoplinker.customer_id"));
				Collection<ShoplinkerInvoice> sendList = tscShoplinkerService.getShoplinkerInvoiceOrdDtlSendList();
				tscShoplinkerService.createShoplinkerInvoiceXml(shoplinkerInvoice, sendList);

				slkSearch.setRunStat(TscConstants.ShoplinkerApiStat.END.value());	// 상태값지정
				slkSearch.setTxt("=>FINISH");

			}catch (Exception e) {

				log.error("TsaShoplinkerController.shoplinkerInvoiceRegister => error \n"+e);
				slkSearch.setRunStat(TscConstants.ShoplinkerApiStat.ERROR.value());	// 상태값지정
				slkSearch.setTxt("=>ERROR : "+StringUtils.abbreviate(e.getMessage(), 0 , 120));

			}finally {
				// 3. API 호출 이력 저장 종료
				tscShoplinkerService.saveCallApiRunable(slkSearch);
			}
		}
	}

	/**
	 * 송장전송- 엑셀다운로드
	 *
	 * @param shoplinkerInvoice
	 * @return
	 * @author jmh
	 * @since 2021. 06. 29
	 */
	@GetMapping("/invoice/excel/list")
	public ResponseEntity<InputStreamResource> downloadOrderInfoExcelList(HttpServletRequest request, ShoplinkerInvoice shoplinkerInvoice) throws Exception {
		String excelfileName = "샵링커_송장_" + GagaDateUtil.getTodayDateTime() + ".xlsx";
		String excelFilenameWithPath = GagaFileUtil.getConcatenationPath(env.getProperty("download.path"), "excel", excelfileName);



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

		admShoplinkerService.getInvoiceExcelList(shoplinkerInvoice, excelFilenameWithPath);

		return GagaFileUtil.writeFile(request, excelFilenameWithPath);
	}

	/**
	 * 송장전송관리-송장전송(업로드엑셀용)
	 *
	 * @param shoplinkerGoods
	 * @return GagaMap
	 * @throws Exception
	 * @author jmh
	 * @since 2021.5.20
	 */
	/******************************************************************************************
	@PostMapping("/invoice/send/excelupload/register")
	@ResponseBody
	public GagaMap shoplinkerInvoiceRegister(@RequestBody ShoplinkerInvoice shoplinkerInvoice) throws Exception {

		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String datestr = sdf.format(cal.getTime());

		GagaMap rtnMap = new GagaMap();
		boolean a_bool = true;
		String profiles = env.getProperty("spring.profiles.active").toLowerCase();
		String targetPath = GagaFileUtil.getConcatenationPath(env.getProperty("upload.excel.target.path"), "excel");
		Collection<GagaMap> ecxelGoodsList = new ArrayList<>();

		// API 호출 중인건수 있는지 확인
		ShoplinkerSearch slkSearch = new ShoplinkerSearch();
		slkSearch.setApiType("INVOICE");
		ShoplinkerSearch runMap = shoplinkerService.getCallRunableInfo(slkSearch);
		if( null != runMap ) {
			a_bool = false;
			// 현재 실행중인값 존재
			rtnMap.setString("RESULT_TYPE", TscConstants.ShoplinkerApiStat.RUN.value());
			rtnMap.setString("RESULT_MSG", runMap.getRunStdt()+"에 호출한 건이 현재 실행중입니다.");
		}

		if( a_bool ) {
			try {
				// 1. API 호출 이력 저장 시작(실행중 재호출 금지하기 위함)
				slkSearch.setSid(datestr);
				slkSearch.setRegNo(TsaSession.getInfo().getUserNo());
				tscShoplinkerService.saveCallApiRunable(slkSearch);

				// 2. 엑셀데이터 확인 및 xml 관련 위치 확인
				String[] goodsNames = {"ordNo", "supplyCompCd"};
				ecxelGoodsList = GagaExcelUtil.getList(GagaFileUtil.getConcatenationPath(targetPath, shoplinkerInvoice.getExcelFileNm()), 0, goodsNames, 0);

				if (ecxelGoodsList != null && ecxelGoodsList.size() > EXCEL_ROW_COUNT) {
					throw new IllegalStateException("엑셀 파일의 건수를 " +EXCEL_ROW_COUNT + "건 이하로 사용하세요.");
				}

				// xml 생성경로
				shoplinkerInvoice.setXmlPath(env.getProperty("shoplinker.xml.path")+"/invoice");
				// xml 확인domain url
				shoplinkerInvoice.setDomainUrl(env.getProperty("shoplinker.xml.view")+"/invoice");

				// 샵링커 기본폴더 존재여부 확인
				String slFolder = GagaFileUtil.getConcatenationPath(env.getProperty("shoplinker.xml.path"));
				File slPath = new File(slFolder);
				if (!slPath.exists()) {
					slPath.mkdir();
				}
				//하위폴더존재확인(상품등록)
				slFolder = GagaFileUtil.getConcatenationPath(shoplinkerInvoice.getXmlPath());
				slPath = new File(slFolder);
				if (!slPath.exists()) {
					slPath.mkdir();
				}

				// 2. xml 데이터 생성
				shoplinkerInvoice.setCustomerId(env.getProperty("shoplinker.customer_id"));
				shoplinkerService.createShoplinkerInvoiceXml(ecxelGoodsList, shoplinkerInvoice);

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

				slkSearch.setRunStat(TscConstants.ShoplinkerApiStat.END.value());	// 상태값지정
				slkSearch.setTxt("=>FINISH");

			}catch (Exception e) {

				log.error("TsaShoplinkerController.shoplinkerInvoiceRegister => error \n"+e);
				slkSearch.setRunStat(TscConstants.ShoplinkerApiStat.ERROR.value());	// 상태값지정
				slkSearch.setTxt("=>ERROR : "+StringUtils.abbreviate(e.getMessage(), 0 , 120));

			}finally {
				// 4. API 호출 이력 저장 종료
				tscShoplinkerService.saveCallApiRunable(slkSearch);
			}
		}

		return rtnMap;
	}
	 ******************************************************************************************/


	/**
	 * 공통-api 실행여부확인
	 *
	 * @param slkSearch - 주문번호
	 * @return ShoplinkerSearch
	 * @author jmh
	 * @since 2020. 11. 26
	 */
	@PostMapping("/check/api_runable")
	@ResponseBody
	public ShoplinkerSearch apiRunable(@RequestBody ShoplinkerSearch slkSearch) throws Exception {

		slkSearch.setRegNo(TsaSession.getInfo().getUserNo());
		ShoplinkerSearch runMap = tscShoplinkerService.getCallRunableInfo(slkSearch);
		return runMap;
	}



	/*
	 *
	 * api test
	 */
	@PostMapping("/apiTest2")
	@ResponseBody
	public GagaResponse apiTest3(@RequestBody ShoplinkerGoods shoplinkerGoods) throws Exception {

		int i=0;
		System.out.println("############### test api ###############");
		try {
			GagaShoplinkertUtil shoplinkerUtil = new GagaShoplinkertUtil("MS949");

			String responseXmlData = "";

			com.gagaframework.shoplinker.domain.goods.result.Shoplinker shoplinkerResult;
			com.gagaframework.shoplinker.domain.goods.result.ResultMessage resultMsg;
			com.gagaframework.shoplinker.domain.invoice.ObjectFactory obf;

			/**** 송장전송테스트 ************/
			com.gagaframework.shoplinker.domain.invoice.ResultMessage invoceMsg;
			responseXmlData = "<?xml version='1.0' encoding='euc-kr'?>\r\n"
					+ "<ResultMessage>\r\n"
					+ "<result>false</result>\r\n"
					+ "<id>123</id>\r\n"
					+ "<message><![CDATA[택배사 명칭이 일치하지 않거나 코드가 일치하지 않습니다. 재전송 바랍니다.]]></message>\r\n"
					+ "</ResultMessage>";


			//xx invoceMsg = (com.gagaframework.shoplinker.domain.invoice.ResultMessage) shoplinkerUtil.unmarshal(null, responseXmlData);
			//xx obf = (com.gagaframework.shoplinker.domain.invoice.ObjectFactory) shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.invoice.ObjectFactory.class, responseXmlData);

			//invoceMsg = (com.gagaframework.shoplinker.domain.invoice.ResultMessage) shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.invoice.ResultMessage, responseXmlData);

			/*
			com.style24.admin.support.util.ResultMessage22 re;

			 JAXBContext jaxbContext = JAXBContext.newInstance(new Class[] {com.style24.admin.support.util.ResultMessage22.class});
			 Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
			 System.out.println("####### :: "+unmarshaller.unmarshal((Reader)new StringReader(responseXmlData)));
			 re = (ResultMessage22) unmarshaller.unmarshal((Reader)new StringReader(responseXmlData));
System.out.println("####### : "+re.getMessage());
System.out.println("####### : "+re.getId());
System.out.println("####### : "+re.getResult());
*/
			// System.out.println(" hmj obf :: "+ obf);
			// invoceMsg = (com.gagaframework.shoplinker.domain.invoice.ResultMessage) unmarshaller.unmarshal((Reader)new StringReader(responseXmlData));
			// invoceMsg.getId();

		    // invoceMsg =  (ResultMessage) unmarshaller.unmarshal((Reader)new StringReader(responseXmlData));

			//shoplinkerResult = (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			//invoceMsg = shoplinkerResult.getResultMessage();
			//System.out.println("HMj 2 : ");
			//invoceMsg = responseXmlData;

		//	System.out.println(" HMJ invoice2 : "+invoceMsg);
		//	System.out.println(" HMJ invoice3 : "+invoceMsg.getResult());
		//	System.out.println(" HMJ invoice4 : "+invoceMsg.getMessage());
		//	System.out.println(" HMJ invoice5 : "+invoceMsg.getId());

			/**** 송장전송테스트 끝 ************/


			//1 상품등록 테스트
			String testXmlUrl;

			/*for( i=2; i< 87; i++) {
				testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/T142TS200P/option_"+i+".xml";
				responseXmlData =    shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/attribute_insert.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "" );
				shoplinkerResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
				resultMsg = shoplinkerResult.getResultMessage();
				System.out.println(i+"\n### 1.단품 result1 :: "+resultMsg.getResult());
			  	System.out.println(i+"### 1.단품 result2 :: "+resultMsg.getMessage());
			}*/

			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/T142TS200P/product.xml";
			responseXmlData =   shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/attribute_prod_insert.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "");
			shoplinkerResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			resultMsg = shoplinkerResult.getResultMessage();
			System.out.println("\n\n\n### 2.상품 result1 :: "+resultMsg.getResult());
			System.out.println(" :: "+responseXmlData);
			System.out.println("### 2.상품 result2 :: "+resultMsg.getMessage());

	for( i=1; i< 1; i++) {

			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/option_1.xml";
			responseXmlData =    shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/attribute_insert.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "" );
			shoplinkerResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			resultMsg = shoplinkerResult.getResultMessage();
			System.out.println("\n### 1.단품 result1 :: "+resultMsg.getResult());
		  	System.out.println("### 1.단품 result2 :: "+resultMsg.getMessage());


			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/option_2.xml";
			responseXmlData =    shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/attribute_insert.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "" );
			shoplinkerResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			resultMsg = shoplinkerResult.getResultMessage();
			System.out.println("\n### 1.단품 result1 :: "+resultMsg.getResult());
			System.out.println("### 1.단품 result2 :: "+resultMsg.getMessage());

			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/option_3.xml";
			responseXmlData =    shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/attribute_insert.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "" );
			shoplinkerResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			resultMsg = shoplinkerResult.getResultMessage();
			System.out.println("\n### 1.단품 result1 :: "+resultMsg.getResult());
			System.out.println("### 1.단품 result2 :: "+resultMsg.getMessage());

			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/option_4.xml";
			responseXmlData =    shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/attribute_insert.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "" );
			shoplinkerResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			resultMsg = shoplinkerResult.getResultMessage();
			System.out.println("\n### 1.단품 result1 :: "+resultMsg.getResult());
			System.out.println("### 1.단품 result2 :: "+resultMsg.getMessage());

			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/product.xml";
			responseXmlData =   shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/attribute_prod_insert.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "");
			shoplinkerResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			resultMsg = shoplinkerResult.getResultMessage();
			System.out.println("\n\n\n### 2.상품 result1 :: "+resultMsg.getResult());
			System.out.println("### 2.상품 result2 :: "+resultMsg.getMessage());

			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/goods.xml";
			responseXmlData = shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/goods_info_reg.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "");
			shoplinkerResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			resultMsg = shoplinkerResult.getResultMessage();
			System.out.println("\n### 3.품목(고시) result1 :: "+resultMsg.getResult());
			System.out.println("### 3.품목(고시) result2 :: "+resultMsg.getMessage());

			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/cert.xml"; //ok
			responseXmlData = shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/cert_info_reg.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "");
			shoplinkerResult = (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			resultMsg = shoplinkerResult.getResultMessage();
			System.out.println("\n### 4.인증 result1 :: "+resultMsg.getResult());
			System.out.println("### 4.인증 result2 :: "+resultMsg.getMessage());

			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/image_MOM0HZNN04.xml";
			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/image.xml";

			responseXmlData =     shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/product_image_register.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "");
			shoplinkerResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			resultMsg = shoplinkerResult.getResultMessage();
			System.out.println("\n### 5.이미지 result1 :: "+resultMsg.getResult());
			System.out.println("### 5.이미지 result2 :: "+resultMsg.getMessage());
	}

			//2 재고
/*
			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/goods_reg/option_stock_upd.xml";
			responseXmlData =     shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Product/attribute_modify.php?iteminfo_url="+URLEncoder.encode(testXmlUrl), "");
			shoplinkerResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
			resultMsg = shoplinkerResult.getResultMessage();
			System.out.println("\n### 6.재고upd result1 :: "+resultMsg.getResult());
			System.out.println("### 6.재고upd result2 :: "+resultMsg.getMessage());
*/

			//99 주문수집 목록확인
/*
			List<com.gagaframework.shoplinker.domain.orderlist.Order> rOrdList;
			com.gagaframework.shoplinker.domain.orderlist.Header rHeader;
			com.gagaframework.shoplinker.domain.orderlist.Shoplinker shoplinkerOrdResult;

			testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/order/order_time.xml"; // 20210401  143000 ~ 150000
			//testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/order/0528/order_real_1.xml";	// 28~31일 15시~07시
			//testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/order/0528/order_real_28.xml";	// 28 15시~235959  7개
			//testXmlUrl = "http://ts5000.ipdisk.co.kr:8999/shoplinker/order/0528/order_real_31.xml";	// 31일 000000시~07시  5582개
			responseXmlData =   shoplinkerUtil.callShoplinkerApiByGet(GagaShoplinkerConstants.API_DOMAIN+"/Order/orderlist.php?iteminfo_url="+testXmlUrl, "");


			shoplinkerOrdResult = (com.gagaframework.shoplinker.domain.orderlist.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.orderlist.Shoplinker.class, responseXmlData);
			rHeader = shoplinkerOrdResult.getHeader();
			rOrdList = shoplinkerOrdResult.getOrder();
			if( null == rHeader) {
				com.gagaframework.shoplinker.domain.goods.result.Shoplinker orderFailResult;
				com.gagaframework.shoplinker.domain.goods.result.ResultMessage orderFailResultMsg;

				orderFailResult =  (com.gagaframework.shoplinker.domain.goods.result.Shoplinker)shoplinkerUtil.unmarshal(com.gagaframework.shoplinker.domain.goods.result.Shoplinker.class, responseXmlData);
				orderFailResultMsg = orderFailResult.getResultMessage();
				System.out.println("\n### 주문실패 stat :: "+orderFailResultMsg.getResult());
				System.out.println("### 주문실패 msg :: "+orderFailResultMsg.getMessage());

			}else {
				System.out.println("\n\n\n### 7.주문 result1 :: "+responseXmlData);

				//System.out.println(" url chk:: "+GagaShoplinkerConstants.API_DOMAIN+"/Order/orderlist.php?iteminfo_url="+ testXmlUrl);
				System.out.println("### 7.주문 result2 :: "+rHeader.toString());
				System.out.println("### 7.주문 result22 :: "+rHeader.getTotalCount()); // 1233
				System.out.println("### 7.주문 result23 :: "+rHeader.getTotalPage()); //3
				System.out.println("### 7.주문 result24 :: "+rHeader.getCurrentlyPage()); //1
				System.out.println("### 7.주문 result24 :: "+rHeader.getCurrentlyCount()); //500

				//ExtmallOrder extmallOrder = mapper.convertValue(gagaMap, ExtmallOrder.class);
				//ShoplinkerOrder slOrder;
				//for(com.gagaframework.shoplinker.domain.orderlist.Order ord : rOrdList) {
				//	slOrder = mapper.convertValue(ord, ShoplinkerOrder.class);
				//	System.out.println("### :: 11 "+slOrder.getOrderFlag());
				//}

			}
*/
			//99 주문수집 목록확인 끝

		}catch(Exception e) {
			System.out.println("error :: "+e);
		}
		return super.ok("");
	}


}

