package com.engine.kq.cmd.attendanceEvent;

import com.engine.kq.biz.KQAttProcSetComInfo;
import com.engine.kq.enums.KqSplitFlowTypeEnum;
import com.engine.kq.log.KQLog;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.util.AbstractMap.SimpleEntry;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import weaver.general.Util;
import weaver.hrm.User;

/**
 * 给小e单独做的重复校验的接口接口
 */
public class CheckRuleUtil4E {
  private KQLog kqLog = new KQLog();

  public Map<String, Object> checkDuplicate(Map<String,String> params){
    String workflowid = Util.null2String(params.get("workflowid"));
    String userid = Util.null2String(params.get("userid"));
    String fromdate = Util.null2String(params.get("fromdate"));
    String fromtime = Util.null2String(params.get("fromtime"));
    String todate = Util.null2String(params.get("todate"));
    String totime =  Util.null2String(params.get("totime"));
    kqLog.info("checkDuplicate params:"+params);
    Map<String, Object> retmap = Maps.newHashMap();
    User user = new User(Util.getIntValue(userid));
    if(workflowid.length() > 0 && userid.length() > 0 && fromdate.length() > 0 && fromtime.length() > 0
        && todate.length() > 0 && totime.length() > 0){
      KQAttProcSetComInfo kqAttProcSetComInfo = new KQAttProcSetComInfo();
      String kqtype = kqAttProcSetComInfo.getkqType(workflowid);
      String attid = kqAttProcSetComInfo.getAttid(workflowid);
      CheckRuleUtil checkDuplicateUtil = new CheckRuleUtil();
      Set<Entry<String, Object>> checkRuleDataSet = Sets.newHashSet();
      if(kqtype.equalsIgnoreCase(""+KqSplitFlowTypeEnum.LEAVE.getFlowtype())){
        String checkRuleData2json = userid+"_"+fromdate+"_"+fromtime+"_"+todate+"_"+totime;
        Map.Entry<String,Object> me = new SimpleEntry<String,Object>("1",checkRuleData2json);
        checkRuleDataSet.add(me);
        checkDuplicateUtil.checkRule(checkRuleDataSet,retmap,user, kqtype,0,0,attid);
      }else if(kqtype.equalsIgnoreCase(""+KqSplitFlowTypeEnum.EVECTION.getFlowtype())){
        String checkRuleData2json = userid+"_"+fromdate+"_"+fromtime+"_"+todate+"_"+totime+"_";
        Map.Entry<String,Object> me = new SimpleEntry<String,Object>("1",checkRuleData2json);
        checkRuleDataSet.add(me);
        checkDuplicateUtil.checkRule(checkRuleDataSet,retmap,user, kqtype,0,0,attid);
      }
    }
    if(retmap.isEmpty()){
      retmap.put("status", "1");
    }

    return retmap;
  }
}
