package com.style24.scm.biz.service;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.domain.Pos;
import com.style24.scm.biz.dao.TssWmsPosDao;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;

/**
 *  wms Service
 *
 * @author moon
 * @since 2021. 08. 09
 */
@Service
@Slf4j
public class TssWmsPosService {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private TssWmsPosDao wmsPosDao;

	/**
	 * WMS_IF 출고요청 등록
	 * @param Collection<Delivery>
	 * @return 
	 * @author moon
	 * @since  2021. 04. 08
	 */
	@Transactional("wmsTxnManager")
	public void insertWmsDelivery(Collection<Pos> list) {

		// TB_IF_DeliveryOrder
		String uuid = UUID.randomUUID().toString();
		Pos dataM = list.iterator().next();	

		dataM.setOrderguid(uuid);

		
		wmsPosDao.insertWmsTbIfDeliveryOrder(dataM);
		Integer ordPk = dataM.getDeliveryorderno();

		log.info("ordPk: "+ordPk);
		for (Pos data : list) {
			// TB_IF_DeliveryOrderItem
			data.setDeliveryorderno(ordPk);
			data.setIfyn("Y");
			wmsPosDao.insertWmsTbIfDeliveryOrderItem(data);
			
			wmsPosDao.insertWmsTbIfDeliveryInvoice(data);
			
		}

		
	}

}
