package com.engine.attendance.attendanceanalysis.service.impl;

import com.engine.attendance.attendanceanalysis.cmd.item.ForGetClockItemCmd;
import com.engine.attendance.attendanceanalysis.service.ForgetClockInService;
import com.engine.attendance.enums.AttendanceItemTypeEnum;
import com.engine.attendance.enums.SystemItemEnum;
import com.engine.common.util.Utils;
import com.engine.core.impl.Service;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import weaver.general.Util;

import java.util.List;
import java.util.Map;

@Slf4j
public class ForgetClockInServiceImpl extends Service implements ForgetClockInService {

    @Override
    public List<Map<String,Object>> forgetClockInAllDays(Map<String,Object> params) {
        Map<String,Object> forgetParam = Maps.newHashMap();
        forgetParam.put("item", SystemItemEnum.MISSING_CLOCK_IN.getKey());
        forgetParam.put("itemduration", 1);
        List<Map<String,Object>> resultList = Lists.newArrayList();
        resultList.add(forgetParam);
        return resultList;
    }

    @Override
    public List<Map<String,Object>> forgetClockIn(Map<String, Object> params) {
        Map<String, Object> classInfo = (Map<String, Object>)params.get("classInfo");

        //班段类型
        String bdlx = Util.null2String(classInfo.get("bdlx"));

        String workFor = Utils.getWorkFor(bdlx);
        params.put("workfor",workFor);
        params.put("key",SystemItemEnum.MISSING_CLOCK_IN.getKey());

        Map<String,Object> result = commandExecutor.execute(new ForGetClockItemCmd(params));
        List<Map<String,Object>> resultList = Lists.newArrayList();
        List<Map<String,Object>> forgerAttendanceItems = (List<Map<String,Object>>)result.get("attendanceItems");
       if (forgerAttendanceItems.size() > 0){
           Map<String,Object> forgetParam = Maps.newHashMap();
           forgetParam.put("item", forgerAttendanceItems.get(0).get("key"));
           forgetParam.put("itemduration", 1);
           forgetParam.put("itemType", AttendanceItemTypeEnum.MISSE_CARD);
           resultList.add(forgetParam);
       }
        return resultList;
    }
}
