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

import com.uas.platform.b2b.erp.model.APCheck;
import com.uas.platform.b2b.erp.model.OrderSendStatusColumn;
import com.uas.platform.b2b.erp.service.OrderSendStatusService;
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;

/**
 * 订单同步更新id的接口
 *
 * Created by hejq on 2017-12-15.
 */
@RequestMapping("/erp/order")
@RestController
public class OrderSendStatusController {

    @Autowired
    private OrderSendStatusService orderService;

    /**
     * 通过订单的相关信息获取传输到平台的信息
     *
     * @param data 封装的OrderSendStatusColumn Json数据
     * @param callerName 平台对应的来源表
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public List<OrderSendStatusColumn> getByOrderInfo(@RequestParam("data") String data, @RequestParam("callerName") String callerName,
                                                      @RequestParam("role") String role) throws UnsupportedEncodingException {
        String jsonStr = URLDecoder.decode(data, "UTF-8");
        List<OrderSendStatusColumn> columns =  FlexJsonUtils.fromJsonArray(jsonStr, OrderSendStatusColumn.class);
        return orderService.getOrderInfo(columns, callerName, role);
    }
}
