package com.engine.kq.cmd.schedulesignimport;

import com.engine.common.biz.SimpleBizLogger;
import com.engine.common.constant.BizLogSmallType4Hrm;
import com.engine.common.constant.BizLogType;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import com.engine.kq.biz.KQScheduleSignImport;
import weaver.systeminfo.SystemEnv;

public class SynDataCmd extends AbstractCommonCommand<Map<String, Object>> {
	protected HttpServletRequest request;

  private SimpleBizLogger logger;
  public SynDataCmd() {

  }

	public SynDataCmd(Map<String, Object> params, User user) {
		this.user = user;
		this.params = params;
//    this.logger = new SimpleBizLogger();
//    BizLogContext logContext = new BizLogContext();
//    logContext.setDateObject(new Date());
//    logContext.setLogType(BizLogType.HRM_ENGINE);
//    logContext.setBelongType(BizLogSmallType4Hrm.HRM_ENGINE_HRM_SCHEDULESIGN_IMPORT);
//    logContext.setLogSmallType(BizLogSmallType4Hrm.HRM_ENGINE_HRM_SCHEDULESIGN_IMPORT);
//    logContext.setParams(params);
//    logger.setUser(user);//当前操作人
//
//    String mainSql = "select a.* from hrmschedulesign a ";
//    logger.setMainSql(mainSql);//主表sql
//    logger.setMainPrimarykey("id");//主日志表唯一key
//    logger.setMainTargetNameMethod(this.getClass().getName() + ".getTargetName", "column:userid");
//    logger.before(logContext);
  }

  /**
   * 获取日志对象的名称
   * @param id
   * @param para2
   * @return
   */
  public String getTargetName(String id,String para2){
    ResourceComInfo rc = null;
    String userid = Util.null2s(para2, "");
    try {
      rc = new ResourceComInfo();
      return rc.getLastname(userid);
    } catch (Exception e) {
      e.printStackTrace();
      return "";
    }
  }

	@Override
	public Map<String, Object> execute(CommandContext commandContext) {
		Map<String, Object> retmap = new HashMap<String, Object>();
		try {
			if (!HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user)) {
				retmap.put("status", "-1");
				retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
				return retmap;
			}
			String fromdate = Util.null2String(params.get("fromdate")); 
			String enddate = Util.null2String(params.get("enddate"));
			//手工同步
      new KQScheduleSignImport().importData(fromdate, enddate,true);
			retmap.put("status", "1");
			retmap.put("message", SystemEnv.getHtmlLabelName(30109,user.getLanguage()));
		} catch (Exception e) {
			writeLog("同步外部考勤数据：" + e);
			retmap.put("status", "-1");
		}
		return retmap;
	}

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

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

}
