package com.engine.kq.cmd.hrmAttProcSet;

import com.engine.common.biz.SimpleBizLogger;
import com.engine.common.constant.BizLogSmallType;
import com.engine.common.constant.BizLogType;
import com.engine.common.entity.BizLogContext;
import java.util.Date;
import java.util.Map;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

/**
 * 考勤流程设置日志记录用工具类
 */
public class HrmAttProcSetLogUtil {

  private User user;
  private BizLogType logType;
  private BizLogSmallType belongType;
  private BizLogSmallType logSmallType;

  public HrmAttProcSetLogUtil() {
  }

  public HrmAttProcSetLogUtil(User user,BizLogType logType,BizLogSmallType belongType,BizLogSmallType logSmallType) {
    this.user = user;
    this.logType = logType;
    this.belongType = belongType;
    this.logSmallType = logSmallType;
  }

  /**
   * 返回考勤流程设置操作相应的logger
   * @param useSql 是否使用自定义的sql
   * @param realLogSql
   * @param params
   * @param sourceType
   * @return SimpleBizLogger
   */
  public SimpleBizLogger logStateSetLogSql(boolean useSql,String realLogSql,Map<String, Object> params,String sourceType){
    SimpleBizLogger logger = new SimpleBizLogger();
    BizLogContext logContext = new BizLogContext();
    logContext.setDateObject(new Date());
    logContext.setLogType(logType);
    logContext.setBelongType(belongType);
    logContext.setLogSmallType(logSmallType);
    logContext.setParams(params);
    logger.setUser(user);//当前操作人
    String mainSql = "select * from kq_ATT_PROC_SET ";
    if(useSql){
      if(realLogSql.length() > 0){
        mainSql = realLogSql;
      }
    }
    logger.setMainSql(mainSql);//主表sql
    logger.setMainPrimarykey("id");//主日志表唯一key
    logger.setMainTargetNameMethod(this.getClass().getName() + ".getTargetName", sourceType+"+"+user.getLanguage());
    logger.before(logContext);
    return logger;
  }

  /**
   * 获取日志对象的名称
   * @param id
   * @param para2
   * @return
   */
  public String getTargetName(String id,String para2){
    String[] otherParams = Util.TokenizerString2(para2, "+");
    String sourceType = Util.null2s(otherParams[0], "");
    int languageId = Util.getIntValue(otherParams[1], 7);
    String result = SystemEnv.getHtmlLabelName(82797, languageId);
    switch (sourceType){
      case "basicinfo":
        result = SystemEnv.getHtmlLabelName(10000610,weaver.general.Util.getIntValue(languageId));
        break;
      case "wffield":
        result = SystemEnv.getHtmlLabelName(10000611,weaver.general.Util.getIntValue(languageId));
        break;
      case "action":
        result = SystemEnv.getHtmlLabelName(10000612,weaver.general.Util.getIntValue(languageId));
        break;
      case "createForm":
        result = SystemEnv.getHtmlLabelName(10000613,weaver.general.Util.getIntValue(languageId));
        break;
      default:
        break;
    }
    return result;
  }
}
