package com.uas.finance.controller;

import com.uas.finance.service.ShareholdersService;
import com.uas.finance.model.Shareholders;
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 javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * 股东信息表
 * created by shicr on 2017/12/19
 **/
@Controller
@RequestMapping("/shareholders")
public class ShareholdersController {

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

    @Autowired
    private ShareholdersService shareholdersService;


    /**
     * 股东信息表保存
     *
     * @param shareholders
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public List<Shareholders> save(@RequestBody Shareholders[] shareholders, HttpServletRequest request) {
        logger.info("股东信息表保存", "success");
        ArrayList<Shareholders> arrayList = new ArrayList<Shareholders>();

        for (Shareholders s : shareholders) {
            Shareholders shareholders1 = shareholdersService.save(s);
            arrayList.add(shareholders1);
        }

        return arrayList;
    }
}
