package com.uas.finance.service.Impl;

import com.uas.finance.dao.RepaymentPlanDao;
import com.uas.finance.model.RepaymentPlan;
import com.uas.finance.service.RepaymentPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 还款计划接口实现层
 * created by shicr on 2018/2/24
 **/
@Service
public class RepaymentPlanServiceImpl implements RepaymentPlanService {

    @Autowired
    private RepaymentPlanDao repaymentPlanDao;

    /**
     * 保存还款计划
     *
     * @param repaymentPlans
     * @return
     */
    @Override
    public List<Map<String, Long>> save(List<RepaymentPlan> repaymentPlans) {

        List<Map<String, Long>> list = new ArrayList<Map<String, Long>>();
        for (RepaymentPlan repaymentPlan1 : repaymentPlans) {
            RepaymentPlan repaymentPlan = repaymentPlanDao.save(repaymentPlan1);
            Map<String, Long> map = new HashMap<String, Long>();
            map.put("id", repaymentPlan.getId());
            map.put("rp_id", repaymentPlan.getRp_id());
            list.add(map);
        }
        return list;
    }

    /**
     * 找到某出账单下的还款计划
     *
     * @param aaid 出账单id
     * @return
     */
    @Override
    public List<RepaymentPlan> findByAaid(Long aaid) {
        return repaymentPlanDao.findByAaid(aaid);
    }
}
