package com.engine.kq.cmd.hrmAttProcSet;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.biz.SimpleBizLogger;
import com.engine.common.constant.BizLogSmallType4Hrm;
import com.engine.common.constant.BizLogType;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.wfset.attendance.manager.HrmAttProcActionManagerE9;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import weaver.common.StringUtil;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

/**
 * 保存考勤流程设置的 动作设置
 * @author pzy
 *
 */
public class SaveStateProcSetFlowWfSetCmd extends AbstractCommonCommand<Map<String, Object>>{
	
  private HttpServletRequest request;
  private HttpServletResponse response;
  private SimpleBizLogger logger;

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

	public SaveStateProcSetFlowWfSetCmd(Map<String, Object> params, HttpServletRequest request,HttpServletResponse response,User user) {
		this.user = user;
		this.params = params;
		this.request = request;
		this.response = response;
    HrmAttProcSetLogUtil hrmAttProcSetLogUtil = new HrmAttProcSetLogUtil(user,BizLogType.HRM_ENGINE, BizLogSmallType4Hrm.HRM_ENGINE_HRM_ATT_PROCSET, BizLogSmallType4Hrm.HRM_ENGINE_HRM_ATT_PROCSET);
    String realLogSql = "select * from kq_ATT_PROC_ACTION";
    this.logger = hrmAttProcSetLogUtil.logStateSetLogSql(true, realLogSql, params,"action");
  }

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

  @Override
  public List<BizLogContext> getLogContexts() {
    return logger.getBizLogContexts();
  }

	@Override
	public Map<String, Object> execute(CommandContext commandContext) {
		Map<String,Object> retmap = new HashMap<String,Object>();
		 
		try {
			if(!HrmUserVarify.checkUserRight("HrmAttendanceProcess:setting", user)){
				retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
				return retmap;
			}
			
			HrmAttProcActionManagerE9 attProcActionManager = new HrmAttProcActionManagerE9();
			String field001 = StringUtil.vString(params.get("field001"));
			String field002 = StringUtil.vString(params.get("field002"));
			
			String result = attProcActionManager.save(request, response,field001,field002);

			if(result.length() == 0){
        retmap.put("status", "1");
      }else if("1".equalsIgnoreCase(result)){
        retmap.put("status", "-1");
        retmap.put("message",  SystemEnv.getHtmlLabelName(389757,user.getLanguage()));
      }else if("2".equalsIgnoreCase(result)){
        retmap.put("status", "-1");
        retmap.put("message",  SystemEnv.getHtmlLabelName(389468,user.getLanguage()));
      }

		} catch (Exception e) {
			retmap.put("status", "-1");
			retmap.put("message",  SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
			writeLog(e);
		}
			
		return retmap;
	}
}
