package com.dgtly.wxportal.utils;

import com.dgtly.wxportal.domain.SendOrderNoticeTaskModelCustomer;

import java.util.List;
import java.util.Map;

/**
 * 销售 获取发送文字的方法;
 */
public class CreditGetSendMessageSale<T> implements BatchSendGetSendMessage<T> {

    //发送信息模板
    private String temple;

    //经销商连接模版
    private String cusLintTemp;
    //文字参数集合
    private Map<T,List<SendOrderNoticeTaskModelCustomer>> map;
    public CreditGetSendMessageSale(String template,String cusLintTemp,Map<T,List<SendOrderNoticeTaskModelCustomer>> map){

        this.temple = template;
        this.cusLintTemp = cusLintTemp;
        this.map = map;
    }

    @Override
    public String getSendText(T code) {
        String str="";
        if(map.containsKey(code)){
            List<SendOrderNoticeTaskModelCustomer> list = map.get(code);
            if(list.size()>5){
                str = list.size()+"个";
            }else{
                for(SendOrderNoticeTaskModelCustomer cus:list){
                    str+="<a href='"+String.format(cusLintTemp,cus.getCustomerCode())+"'>"+cus.getCustomerName()+"</a>、";
                }
                str  = str.substring(0,str.length()-1);
            }
            return String.format(temple,str,code);
        }else{
            throw new RuntimeException("未找到code:"+code+"的文字内容");
        }

    }


}
