package com.kingdee.eas.custom.sendmessage.utils.impl;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.custom.logs.MessageLogsInfo;
import com.kingdee.eas.custom.sendmessage.utils.TemplateStrategy;
import com.kingdee.eas.hr.affair.IResignBizBillEntry;
import com.kingdee.eas.hr.affair.ResignBizBillEntryCollection;
import com.kingdee.eas.hr.affair.ResignBizBillEntryFactory;
import com.kingdee.eas.hr.affair.ResignBizBillEntryInfo;
import com.kingdee.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

// ÀëÖ°Í¨ÖªÄ£°å
public class ResignationNoticeTemplate implements TemplateStrategy {
    @Override
    public LinkedHashMap<String,String>  getTemplate(Context ctx, Map<String,Object> paramMap, MessageLogsInfo messageLogsInfo) throws BOSException {
        LinkedHashMap<String,String> param = new LinkedHashMap();
//        IPersonContactMethod iPersonContactMethod = PersonContactMethodFactory.getLocalInstance(ctx);
//        PersonContactMethodInfo personContactMethodInfo = iPersonContactMethod
//                .getPersonContactMethodCollection("select * ,person.* where nCell = '" + phone + "'").get(0);
//        PersonInfo person = personContactMethodInfo.getPerson();

        PersonInfo personInfo = (PersonInfo) paramMap.get("personInfo");
        messageLogsInfo.setPerson(personInfo);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        IResignBizBillEntry iResignBizBillEntry = ResignBizBillEntryFactory.getLocalInstance(ctx);
        ResignBizBillEntryCollection resigCol = iResignBizBillEntry
                .getResignBizBillEntryCollection("where person = '" + personInfo.getId().toString() + "'") ;
        String lzDate = "";
        if(resigCol.size()>0){
            ResignBizBillEntryInfo  entryInfo = resigCol.get(0);
            Date bizDate = entryInfo.getBizDate();
            lzDate = format.format(bizDate);
        }
        param.put("name", personInfo.getName());
        param.put("lzDate", lzDate);
        param.put("urlPath", StringUtils.cnulls(paramMap.get("urlPath")));

        return param;
    }


}