package com.youzi.portal.service.impl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.youzi.http.response.entity.ResultEntity;
import com.youzi.portal.pojo.OrderInfo;
import com.youzi.portal.service.OrderService;
import com.youzi.utils.FastJsonUtils;
import com.youzi.utils.HttpClientUtils;
import com.youzi.utils.JsonUtils;

/**
 * 订单service
 * 
 * @author xiaoysec
 *
 */
@Service
public class OrderServiceImpl implements OrderService {

	@Value("${ORDER_BASE_URL}")
	private String ORDER_BASE_URL;
	@Value("${ORDER_CREATE_URL}")
	private String ORDER_CREATE_URL;

	@Override
	public String createOrder(OrderInfo orderInfo) {
		// 把OrderInfo转换成json
		String json = JsonUtils.objectToJson(orderInfo);
		// 提交订单数据
		String jsonResult = HttpClientUtils.doPost(ORDER_BASE_URL + ORDER_CREATE_URL, json);
		// 转换成java对象
		ResultEntity result = FastJsonUtils.JsonToObject(jsonResult,ResultEntity.class);
		// 取订单号
		String orderId = result.getObj().toString();
		return orderId;
	}
}
