package nckd.jimin.jyyy.hr.hspm.formplugin.web.file.ermanfile.ext.service.card;

import kd.hr.haos.business.servicehelper.OrgBatchBillHelper;
import kd.sdk.hr.hspm.common.ext.file.CardBindDataDTO;
import kd.sdk.hr.hspm.common.vo.CardViewCompareVo;
import kd.sdk.hr.hspm.formplugin.web.file.ermanfile.ext.service.card.IFileCardPluginService;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

public class EmpPosFileCardPluginEx implements IFileCardPluginService {
    @Override
    public void prefixHandleModify(CardBindDataDTO bindData) {
        IFileCardPluginService.super.prefixHandleModify(bindData);
        String entityId = bindData.getView().getEntityId();
        //任职经历
        if("hspm_empposorgrel_dv".equals(entityId)){
            CardViewCompareVo compareVo = bindData.getCompareVo();
            String curFields = compareVo.getHeadFields();
            curFields = curFields + ",startdate";
            compareVo.setHeadFields(curFields);
        }
    }

    @Override
    public void batchQueryDataList(CardBindDataDTO bindData) {
        //处理组织长名称 根据Id + 时间去查询
        List<Map<String, Object>> dataList = bindData.getDataList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            for (Map map : dataList) {
                String dateStr = map.get("startdate").toString();
                Long orgId = Long.valueOf(map.get("adminorg_id").toString());
                String orgLongName = OrgBatchBillHelper.getOrgLongName(orgId, sdf.parse(dateStr), null);
                map.put("startdate", orgLongName);
            }
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        IFileCardPluginService.super.batchQueryDataList(bindData);
    }

    @Override
    public boolean changeLabelValueModify(CardBindDataDTO bindData) {
        String entityId = bindData.getView().getEntityId();
        //任职经历
        if("hspm_empposorgrel_dv".equals(entityId)){
//            CardViewCompareVo compareVo = bindData.getCompareVo();
//            String curFields = compareVo.getHeadFields();
//            curFields = curFields + ",startdate";
//            compareVo.setHeadFields(curFields);
        }
        return IFileCardPluginService.super.changeLabelValueModify(bindData);

    }
}
