package com.cim.idm.service.Impl;

import com.cim.idm.exception.GlobalException;
import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.service.impl.ToSAPServiceImpl;
import com.cim.idm.utils.EventInfoUtil;
import com.cim.idm.wmspackage.materialpacking.MaterialPackingServiceProxy;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPacking;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPackingKey;
import com.cim.idm.wmspackage.materialpacking.management.info.SetEventInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("NoInvoiceManager")
public class NoInvoiceManagerServiceImpl {
	@Autowired
	private ToSAPServiceImpl toSAPService;

	private SDKMaterialPackingServiceImpl SDKMaterialPackingServiceImpl = new SDKMaterialPackingServiceImpl();


	
	
	
	@Transactional
	public void ZK(List<MaterialPacking> list,String locationName,String user,String supplierCharge,String opCode) {
//		String undoid = toSAPService.zkNoInvoice(list,locationName,user,opCode);
		EventInfo makeEventInfo = EventInfoUtil.makeEventInfo("ZK", user, "ZK", "", "");
		SetEventInfo setEventInfo = new SetEventInfo();
		HashMap<String, Object> hashMap = new HashMap<String,Object> ();
		hashMap.put("LocationName", locationName);
		hashMap.put("supplierCharge", supplierCharge);
		setEventInfo.setObjectValueUserColumns(hashMap);
		for (MaterialPacking materialPacking : list) {
			String materialPackingName = materialPacking.getMaterialPackingName();
			MaterialPackingKey materialPackingKey = new MaterialPackingKey("SDK", materialPackingName);
			MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, makeEventInfo, setEventInfo);
		}
//		SDKMaterialPackingServiceImpl.updateUndoIdByList(list, undoid, makeEventInfo);
	}

	/**
	 *
	 * @param list
	 * @param user
	 * @param commitDate
	 * @param opCode
	 */
	@Transactional
	public void PDAShelf(List<MaterialPacking> list,String user,String commitDate,String opCode) {
		EventInfo makeEventInfo = EventInfoUtil.makeEventInfo("Shelf", user, "Shelf", "", "");
		SetEventInfo setEventInfo = new SetEventInfo();
		HashMap<String, Object> hashMap = new HashMap<String,Object> ();
		setEventInfo.setObjectValueUserColumns(hashMap);
		for (MaterialPacking materialPacking : list) {
			String materialPackingName = materialPacking.getMaterialPackingName();
			hashMap.put("LocationName",materialPacking.getLocationName() );
			hashMap.put("supplierCharge", materialPacking.getSupplierCharge());
			MaterialPackingKey materialPackingKey = new MaterialPackingKey("SDK", materialPackingName);
			MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, makeEventInfo, setEventInfo);
		}
	}

	@Transactional
	public void ChangeChargeName(List<MaterialPacking> list,String user) {
		EventInfo makeEventInfo = EventInfoUtil.makeEventInfo("ChangeSupplierCharge", user, "ChangeSupplierCharge", "", "");
		SetEventInfo setEventInfo = new SetEventInfo();
		Map<String, Object> hashMap = new HashMap<String,Object> ();
		for (MaterialPacking materialPacking : list) {
			String supplierCharge = materialPacking.getSupplierCharge();
			String materialPackingName = materialPacking.getMaterialPackingName();
			hashMap.put("supplierCharge", supplierCharge);
			setEventInfo.setUserColumns(hashMap);
			MaterialPackingKey materialPackingKey = new MaterialPackingKey("SDK", materialPackingName);
			MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, makeEventInfo, setEventInfo);
		}
	}

}
