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. 08
 */
@Component
@Slf4j
public class TsbDeliveryExcRcvJob 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_DeliveryException  - select 
		Collection<Delivery> excList = wmsDeliveryService.getWmsIfDeliveryExcList();
		
		// 1-2. wms_if: TB_IF_DeliveryExceptionItem  - select 
		Collection<Delivery> itemList = wmsDeliveryService.getWmsIfDeliveryExcItemList();
				
		// 2. mall 출고예외 등록
		deliveryService.insertTbOrderDeliveryException(excList, itemList);
		
		// 3. wms  출고예외 수신완료 update 
		wmsDeliveryService.updateTbIfDeliveryException(excList, itemList);
		
		
		
		
		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);
	}

}