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

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.mvc.list.ListDataProvider;
import nckd.jxccl.base.sit.helper.SITHelper;

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

public class SinsurFileListDataProviderEx extends ListDataProvider {

    private static final Log log = LogFactory.getLog(SinsurFileListDataProviderEx.class);


    @Override
    public DynamicObjectCollection getData(int start, int limit) {
        DynamicObjectCollection rows = super.getData(start, limit);
        if(rows.isEmpty())
            return rows;
        //获取所有Id
        List<Long> employeeIds = rows.stream().map(dyx -> dyx.getLong("employee.id")).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, DynamicObject> protitleMap = helper.getProtitleLevelDynByEmployeeID(employeeIds);

        for(DynamicObject row : rows) {
            long employeeId = row.getLong("employee.id");
            row.set("nckd_joindate", joinDateMap.keySet().contains(employeeId) ? joinDateMap.get(employeeId) : null);
            row.set("nckd_leavedate", quitDateMap.keySet().contains(employeeId) ? quitDateMap.get(employeeId) : null);
            row.set("nckd_posname", zwcjMap.keySet().contains(employeeId) ? zwcjMap.get(employeeId) : null);
            row.set("nckd_prolevel", protitleMap.keySet().contains(employeeId) ? protitleMap.get(employeeId) : null);
        }


        return rows;
    }
}
