package com.iamberry.wechat.handles.order.orderListener;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;

import com.iamberry.wechat.core.entity.order.Order;
import com.iamberry.wechat.face.mq.EfastOrderService;
import com.iamberry.wechat.face.order.AdminOrderService;

public class OrderEfastListener {
	
	@Autowired
	private AdminOrderService adminOrderService;
	@Autowired
	private EfastOrderService efastOrderService;
	
	public void getEfastOrderInfo() throws Exception{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Order order = new Order();
		order.setSalesStatus(2);
		List<Order> orders = new ArrayList<Order>();
		//获取已支付待发货的订单号
//		List<Order> orderList = adminOrderService.getOrderList(order);
//		if (orderList == null || orderList.size() == 0) {
//			return;
//		}
		//从百胜获取已发货的订单
		JSONObject respData = efastOrderService.selectEfastSendOrderList();
		if (respData == null) {
			return;
		}
		JSONArray list = respData.getJSONArray("list");
		if (list == null || list.size() == 0) {
			return;
		}
		//对比从百胜获取的订单与我们系统中已支付待发货的订单号，将该订单号封装在集合中
		for (int i = 0;i < list.size();i++) {
			JSONObject orderJson = list.getJSONObject(i);
//			for (Order orderInfo : orderList) {
//				if (orderInfo.getSalesOrderid().equals(orderJson.get("deal_code"))) {
//					orderInfo.setSalesPostFirm(orderJson.getString("shipping_name"));
//					orderInfo.setSalesPostNum(orderJson.getString("invoice_no"));
//					Long time=new Long(orderJson.getString("delivery_time"));  
//					String date_string = sdf.format(new Date(time * 1000L));
//				    Date date=sdf.parse(date_string);
//					orderInfo.setSalesSendDate(date);
//					orders.add(orderInfo);
//				}
//			}
		}
//		//将已支付待发货的订单状态批量修改为已发货的状态
//		if (null != orders && orders.size() > 0) {
//			adminOrderService.updateOrderListStatus(orders);
//		}
	}
}
