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 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 WorkOvertimeItemCmd extends AbstractCommonCommand<Map<String,Object>> {
    @Override
    public BizLogContext getLogContext() {
        return null;
    }
    public WorkOvertimeItemCmd(Map<String,Object> params){
        this.params=params;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        //作用时段
        String workfor = Util.null2String(params.get("workfor"));
        //日期类型
        String rqlx = Util.null2String(params.get("rqlx"));
        //考勤项目
        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"));
            //项目绑定的日期类型
            String bddrqlx = Util.null2String(e.get("bddrqlx"));

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

        return resultMap;
    }
}
