package com.uas.finance.service.Impl;

import com.uas.finance.model.AssociateCompany;
import com.uas.finance.service.AssociateCompanyService;
import com.uas.finance.dao.AssociateCompanyDao;
import com.uas.finance.model.AssociateCompany;
import com.uas.finance.service.AssociateCompanyService;
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/19
 **/
@Service
public class AssociateCompanyServiceImpl implements AssociateCompanyService {

    @Autowired
    private AssociateCompanyDao associateCompanyDao;

    /**
     * 关联企业保存
     *
     * @param company
     * @return
     */
    @Override
    public AssociateCompany save(AssociateCompany company) {
        return associateCompanyDao.save(company);
    }

    /**
     * 关联企业资料更新
     *
     * @param companies
     * @return
     */
    @Override
    public List<Map<String, Long>> update(List<AssociateCompany> companies) {
        List<Map<String, Long>> list = new ArrayList<Map<String, Long>>();
        for (AssociateCompany company : companies) {
            Map<String, Long> map = new HashMap<>();
            AssociateCompany company1 = associateCompanyDao.save(company);
            map.put("id", company1.getId());
            map.put("cud_id", company1.getErpId());
            list.add(map);
        }
        return list;
    }
}
