package com.weaver.seconddev.interfaces.k3;

import  com.weaver.seconddev.interfaces.k3.GiftQtyServiceStub.*;
import java.lang.String;
import java.util.HashMap;
import java.util.Map;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import com.weaver.seconddev.interfaces.prop.ConfigProp;
import org.apache.axis2.kernel.http.HTTPConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import java.lang.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.weaver.verupgrade.general.BaseBean;
import com.weaver.verupgrade.general.Util;
import org.springframework.stereotype.Component;

@Component
public class GiftQtyService extends BaseBean {

	private static final org.slf4j.Logger logger_a44d19bf = LoggerFactory.getLogger(GiftQtyService.class);
	@Autowired
	private ConfigProp configProp;
	public Map<String, String> call(ArrayOfGiftStockDt param) {
//		String url = Util.null2String(I18nContextUtilcus.getBean(Environment.class).getProperty("htk3oasync.lplysl_url")).trim();


		Map<String, String> map = new HashMap<String, String>();
		try {
			logger_a44d19bf.error(String.valueOf("GiftQtyService ------------ start "));
			logger_a44d19bf.error("lplysl_url == " + configProp.getLplysl_url());
			String url = configProp.getLplysl_url();
			logger_a44d19bf.error(String.valueOf("configProp htk3oasync.lplysl_url" + url));
			logger_a44d19bf.error(String.valueOf("GiftQtyService--start"));
			GiftQtyServiceStub stub = new GiftQtyServiceStub(url);
			stub._getServiceClient().getOptions().setProperty("__CHUNKED__", Boolean.FALSE);
			stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(300000);
			stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT,300000);
			stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT,300000);
			GiftStockReq req = new GiftStockReq();
			req.setUser("oa");
			req.setPwd("k3cloud_htgd");
			req.setFCompanyNumber("Z010");
			req.setGifts(param);
			GetGiftQty getQty = new GetGiftQty();
			getQty.setObj(req);
			GetGiftQtyResponse res = stub.getGiftQty(getQty);
			GiftStockRes result = res.getGetGiftQtyResult();
			if ("1".equals(result.getCode())) {
				ArrayOfGiftStockDt returnGifts = result.getReturnGifts();
				GiftStockDt[] giftStockDt = returnGifts.getGiftStockDt();
				for (int i = 0; i < giftStockDt.length; i++) {
					map.put(giftStockDt[i].getFNumber(), giftStockDt[i].getFQty());
					logger_a44d19bf.error("GiftQtyService--result-[" + giftStockDt[i].getFNumber() + "-" + giftStockDt[i].getFQty() + "]");
				}
			}
			map.put("code", result.getCode());
			map.put("msg", result.getMessage());
		} catch (Exception e) {
			map.put("code", "0");
			map.put("msg", e.toString());
			logger_a44d19bf.error(String.valueOf("GiftQtyService--error:" + e.toString()));
		}
		return map;
	}
}
