package com.engine.attendance.attendanceanalysis.cmd.item;

import com.engine.attendance.enums.AttendanceItemTypeEnum;
import com.engine.attendance.enums.WorkForTimeEnum;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.sun.jna.platform.win32.Shell32Util;
import lombok.extern.slf4j.Slf4j;
import weaver.general.Util;

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

/**
 * 出差考勤项目
 */
@Slf4j
public class BeAwayItemCmd extends AbstractCommonCommand<Map<String,Object>> {
    @Override
    public BizLogContext getLogContext() {
        return null;
    }
    public BeAwayItemCmd(Map<String,Object> params){
        this.params=params;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        //作用时段

        String workfor = Util.null2String(params.get("workfor"));
        //考勤项目
        List<Map<String,Object>> attendanceItems = (List<Map<String,Object>>)params.get("attendanceItems");

        Map<String, Object> resultMap = new HashMap<>();
        attendanceItems = attendanceItems.stream().filter(e -> {
            //项目类型
            String xmlx = Util.null2String(e.get("xmlx"));
            //作用时段
            String zysd = Util.null2String(e.get("zysd"));

            if(AttendanceItemTypeEnum.EVECTION.getKey().equals(xmlx) && (zysd.contains(workfor) || zysd.contains(WorkForTimeEnum.ALL_TIME.getKey()))) {
                return true;
            }else {
                return false;
            }
        }).collect(Collectors.toList());
        log.info("absenteeismCmd attendanceItems : [{}]",attendanceItems);
        resultMap.put("attendanceItems",attendanceItems);

        return resultMap;
    }
}
