package com.uas.finance.service.Impl;

import com.uas.finance.dao.AccountInfoDao;
import com.uas.finance.model.AccountInfo;
import com.uas.finance.service.AccountInfoService;
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 2017/12/21
 **/
@Service
public class AccountInfoSerivceImpl implements AccountInfoService {

    @Autowired
    private AccountInfoDao accountInfoDao;

    /**
     * 财务数据保存
     *
     * @param accountInfo
     * @return
     */
    @Override
    public AccountInfo save(AccountInfo accountInfo) {
        return accountInfoDao.save(accountInfo);
    }

    /**
     * 财务数据更新
     *
     * @param accountInfos
     * @return
     */
    @Override
    public List<Map<String, Long>> update(List<AccountInfo> accountInfos) {

        List<Map<String, Long>> list = new ArrayList<Map<String, Long>>();
        for (AccountInfo accountInfo : accountInfos) {
            Map<String, Long> map = new HashMap<String, Long>();
            AccountInfo accountInfo1 = accountInfoDao.save(accountInfo);
            map.put("id", accountInfo1.getId());
            map.put("ai_id", accountInfo1.getErpId());
            list.add(map);
        }
        return list;
    }
}
