package com.uas.finance.controller;

import com.uas.finance.model.AccountApply;
import com.uas.finance.service.AccountApplyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

import java.util.List;

/**
 * 应收账款转让控制类
 * created by shicr on 2018/1/27
 **/
@RequestMapping("/accountapply")
@RestController
public class AccountApplyController {

    private Logger logger = LoggerFactory.getLogger(AccountApplyController.class);

    @Autowired
    private AccountApplyService service;

    /**
     * 出账申请保存
     * @param accountApply
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public AccountApply save(@RequestBody AccountApply accountApply){
        logger.info("出账申请保存","success");
        AccountApply a =  service.save(accountApply);
        return  a;
    }

    /**
     * 出账申请提交
     * @param accountApply
     * @return
     */
    @RequestMapping(value = "/submit",method = RequestMethod.POST)
    public AccountApply submit(@RequestBody AccountApply accountApply){
        logger.info("出账申请正式提交","success");
        AccountApply a = service.submit(accountApply);
        return a;
    }

    /**
     * 找到某买方下面的所有出账申请
     * @param id
     * @return
     */
    @RequestMapping(value = "/find",method = RequestMethod.GET)
    public List<AccountApply> find(Long id){
        logger.info("查找某买方客户的所有出账申请","success");
        List<AccountApply> accountApplies = service.findByCq_id(id);
        return accountApplies;
    }

    /**
     * 找到某条出账单
     * @param id
     * @return
     */
    @RequestMapping(value = "/findone",method = RequestMethod.GET)
    public AccountApply findone(Long id){
        logger.info("查找某条出账单","success");
        AccountApply accountApply = service.findOne(id);
        return accountApply;
    }
}
