package com.engine.kq.cmd.attendanceEvent;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.enums.KqSplitFlowTypeEnum;
import com.engine.kq.log.KQLog;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

/**
 * 加班流程提交校验
 */
public class CheckOvertimeCmd extends AbstractCommonCommand<Map<String, Object>> {

	public CheckOvertimeCmd(Map<String, Object> params, User user) {
		this.user = user;
		this.params = params;
	}

	@Override
	public Map<String, Object> execute(CommandContext commandContext) {
		Map<String, Object> retmap = new HashMap<String, Object>();
		RecordSet rs = new RecordSet();
		try{
      String attid = Util.null2String(params.get("attid"));
      String checkDurationData2json = Util.null2String(params.get("checkDurationData2json"));
      String checkRuleData2json = Util.null2String(params.get("checkRuleData2json"));
      int workflowid = Util.getIntValue(Util.null2String(params.get("workflowid")));
      int nodeid = Util.getIntValue(Util.null2String(params.get("nodeid")));
      int requestid = Util.getIntValue(Util.null2String(params.get("requestid")));
      int nodetype = Util.getIntValue(Util.null2String(params.get("nodetype")));
      int currentnodetype = Util.getIntValue(Util.null2String(params.get("currentnodetype")));
      new KQLog().info("checkRuleData2json:"+checkRuleData2json);
      new KQLog().info("检测每次提交的时候，页面上的时长是多少 checkDurationData2json:"+checkDurationData2json);
      JSONObject checkRuleData2jsonObject = (JSONObject) JSON.parse(checkRuleData2json);
      if(!checkRuleData2jsonObject.isEmpty()){
        CheckRuleUtil checkDuplicateUtil = new CheckRuleUtil();
        Set<Entry<String, Object>> checkRuleDataSet = checkRuleData2jsonObject.entrySet();
        checkDuplicateUtil.checkRule(checkRuleDataSet,retmap,user,""+ KqSplitFlowTypeEnum.OVERTIME.getFlowtype(),
            requestid,currentnodetype,attid);
      }
      if(retmap.isEmpty()){
        retmap.put("status", "1");
      }
    }catch (Exception e) {
			retmap.put("status", "-1");
			retmap.put("message",  SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
			writeLog(e);
		}
		return retmap;
	}

	@Override
	public BizLogContext getLogContext() {
		return null;
	}

}
