package com.uas.platform.b2b.erp.controller;

import com.uas.platform.b2b.erp.model.AutOrder;
import com.uas.platform.b2b.erp.service.AutOrderService;
import com.uas.platform.core.util.serializer.FlexJsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;

/**
 * 自动生成订单接口
 *
 * Created by hejq on 2018-05-04.
 */
@RestController
@RequestMapping("/erp/saleOrder")
public class AutOrderController {

    @Autowired
    private AutOrderService orderService;
    /**
     * 保存数据
     *
     * @param data
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(method = RequestMethod.POST)
    public void saveOrders(@RequestParam("data") String data) throws UnsupportedEncodingException {
        String jsonStr = URLDecoder.decode(data, "UTF-8");
        List<AutOrder> orderList = FlexJsonUtils.fromJsonArray(jsonStr, AutOrder.class);
        orderService.saveOrder(orderList);
    }
}
