package com.uas.finance.erp.service.impl;

import com.uas.finance.erp.model.CustInfo;
import com.uas.finance.erp.service.CustomerInfoDownService;
import com.uas.finance.model.CustomerInfo;
import com.uas.finance.util.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hejq on 2017-12-21.
 */
@Service
public class CustomerInfoDownServiceImpl implements CustomerInfoDownService {

    @Override
    public ModelMap covert(List<CustomerInfo> infos) {
        ModelMap map = new ModelMap();
        List<CustInfo> custInfos = new ArrayList<CustInfo>();
        //id 这边先提取出来，保存成功返回直接更新状态，轮询中间不作处理
        StringBuffer idStr = new StringBuffer();
        int size = 0;
        if(idStr.length() > 0)
            idStr.append(",");
        if(!CollectionUtils.isEmpty(infos)) {
            for(CustomerInfo info : infos) {
                custInfos.add(new CustInfo(info));
                idStr.append(info.getId());
                size = size + 1;
            }
        }
        map.put("custInfos", custInfos);
        map.put("idStr", idStr);
        map.put("size", size);
        return map;
    }
}
