package com.uas.finance.controller;

import com.uas.finance.service.ChangesInstructionService;
import com.uas.finance.model.ChangesInstruction;
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/20
 **/
@Controller
@RequestMapping("/changesInstruction")
public class ChangesInstructionController {

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

    @Autowired
    private ChangesInstructionService service;

    /**
     * 变更内容保存
     *
     * @param instructions
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public List<ChangesInstruction> save(@RequestBody ChangesInstruction[] instructions) {
        logger.info("变更内容保存", "success");
        ArrayList<ChangesInstruction> arrayList = new ArrayList<ChangesInstruction>();
        for (ChangesInstruction c : instructions) {
            ChangesInstruction changesInstruction = service.save(c);
            arrayList.add(changesInstruction);
        }
        return arrayList;
    }
}
