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.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 2020. 12. 08
 */
@Component
@Slf4j
public class TsbDailyDeliveryZoneJob 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;
		/**
		 * 1. wms_if: TB_IF_DailyDeliveryZone 조회 
		 * 2. mall: TB_DailyDeliveryZone merge 
		 * */
		
		// 1. wms_if: TB_IF_DailyDeliveryZone 조회 
		Collection<Delivery> dailyDeliZoneList = wmsDeliveryService.getWmsIfDailyDeliveryZoneList();
		
		// 2. mall: TB_DailyDeliveryZone merge 
		deliveryService.mergeDailyDeliveryZone(dailyDeliZoneList);
		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);
	}

}