package com.uas.finance.controller;

import com.uas.finance.model.Updowncast;
import com.uas.finance.service.UpdowncastService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * 上下游表单信息
 * created by shicr on 2017/12/21
 **/
@Controller
@RequestMapping("/updowncast")
public class UpdowncastController {

    private final static Logger logger = LoggerFactory.getLogger(UpdowncastController.class);

    @Autowired
    private UpdowncastService updowncastService;

    /**
     * 上下游表单信息保存
     *
     * @param updowncasts
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public List<Updowncast> updowncastList(@RequestBody Updowncast[] updowncasts) {
        logger.info("上下游表单信息保存", "success");
        ArrayList<Updowncast> arrayList = new ArrayList<Updowncast>();
        for (Updowncast updowncast : updowncasts) {
            Updowncast updowncast1 = updowncastService.save(updowncast);
            arrayList.add(updowncast1);
        }

        return arrayList;
    }
}
