package nckd.jxccl.sit.hcsi.formplugin.web.file;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.sdk.plugin.Plugin;
import nckd.jxccl.base.sit.helper.SITHelper;

import java.util.Date;
import java.util.EventObject;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Tyx 2026-01-05
 * 社保档案表单插件，查询入职日期，离职日期，党政职务，技术职称
 */
public class SinsurFileEditEx extends AbstractFormPlugin implements Plugin {


    @Override
    public void beforeBindData(EventObject e) {
        super.beforeBindData(e);
        getRelatedData();
    }

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
    }

    /**
     * 查询相关信息:
     * 查询入职日期，离职日期，党政职务，技术职称
     */
    public void getRelatedData(){
        IDataModel model = this.getModel();
        DynamicObject dyn = model.getDataEntity();
        Long employeeId = dyn.getLong("employee.id");
        List<Long> employeeIds = Stream.of(employeeId).collect(Collectors.toList());
        
        SITHelper helper = new SITHelper();
        Map<Long, Date> joinDateMap = helper.getJoinDateByEmployeeID(employeeIds);
        Map<Long, Date> quitDateMap = helper.getQuitDateByEmployeeID(employeeIds);
        Map<Long, String> zwcjMap = helper.getZwcjByEmployeeID(employeeIds);
        Map<Long, Long> protitleMap = helper.getProtitleLevelIdByEmployeeID(employeeIds);

        model.setValue("nckd_joindate", joinDateMap.keySet().contains(employeeId) ? joinDateMap.get(employeeId) : null);
        model.setValue("nckd_leavedate", quitDateMap.keySet().contains(employeeId) ? quitDateMap.get(employeeId) : null);
        model.setValue("nckd_posname", zwcjMap.keySet().contains(employeeId) ? zwcjMap.get(employeeId) : null);
        model.setValue("nckd_prolevel", protitleMap.keySet().contains(employeeId) ? protitleMap.get(employeeId) : 0L);
    }


}