package com.uas.finance.controller;

import com.uas.finance.model.AssociateCompany;
import com.uas.finance.service.AssociateCompanyService;
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/19
 **/
@Controller
@RequestMapping("/associate")
public class AssociateCompanyController {

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

    @Autowired
    private AssociateCompanyService service;

    /**
     * 关联企业保存
     *
     * @param company
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public List<AssociateCompany> save(@RequestBody AssociateCompany[] company) {
        logger.info("关联企业表单保存", "success");
        ArrayList<AssociateCompany> arrayList = new ArrayList<AssociateCompany>();
        for (AssociateCompany a : company) {
            AssociateCompany associateCompany = service.save(a);
            arrayList.add(associateCompany);
        }
        return arrayList;
    }
}
