package com.style24.batch.biz.job.delivery;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.gagaframework.web.parameter.GagaMap;
import com.style24.batch.biz.job.TsbAbstractJob;
import com.style24.batch.biz.service.TsbDeliveryService;
import com.style24.batch.biz.service.TsbWmsDeliveryService;
import com.style24.persistence.domain.Delivery;

import lombok.extern.slf4j.Slf4j;

/**
 * 회수예외 수신 (wmsif to mall) 
 *
 * @author moon
 * @since 2021. 03. 02
 */
@Component
@Slf4j
public class TsbWithdrawExcRcvJob extends TsbAbstractJob<Delivery, Delivery, Delivery> {

	@Autowired
	private TsbDeliveryService deliveryService;

	@Autowired
	private TsbWmsDeliveryService wmsDeliveryService
	
	;
	private int succCnt = 0;
	private int failCnt = 0;

	@Override
	public Delivery read() throws Exception {

		Delivery delivery = new Delivery();
		return delivery;
	}

	@Override
	public Delivery process(Delivery delivery) throws Exception {
		succCnt = 0;
		failCnt = 1;
		/**
		 * wms  회수예외 조회 
		 * mall 회수예외 등록
		 * wms  회수예외 update 
		 *  
		 * */

		// 1.wms  회수예외 조회 
		// 1-1. wms_if: TB_IF_RecallException  - select 
		Collection<Delivery> excList = wmsDeliveryService.getWmsIfWithdrawExcList();
		
		// 1-2. wms_if: TB_IF_RecallExceptionItem  - select 
		Collection<Delivery> itemList = wmsDeliveryService.getWmsIfWithdrawExcItemList();
		
		// 1-3. wms_if: TB_IF_RecallExceptionMemo  - select 
		Collection<Delivery> memoList = wmsDeliveryService.getWmsIfWithdrawExcMemoList();
		
		// 2. mall 회수예외 등록
		deliveryService.insertTbOrderRecallException(excList, itemList, memoList);
		
		// 3. wms  회수예외 수신완료 update 
		wmsDeliveryService.updateTbIfRecallException(excList, itemList, memoList);
		
		
		succCnt = 1;
		failCnt = 0;
		
		return delivery;
	}

	@Override
	public Delivery write(Delivery delivery) throws Exception {

		return delivery;
	}

	@Override
	public void notify(Delivery delivery) throws Exception {
		super.printResult(succCnt, failCnt);
	}

}