package com.engine.kq.wfset.util;

import com.alibaba.fastjson.JSON;
import com.engine.kq.biz.KQLeaveRulesComInfo;
import com.engine.kq.cmd.hrmAttProcSet.KqSplitActionEnum;
import com.engine.kq.enums.KqSplitFlowTypeEnum;
import com.engine.kq.log.KQLog;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.conn.RecordSet;
import weaver.general.StaticObj;
import weaver.general.Util;

/**
 * 考勤流程设置校验类
 */
public class KQAttFlowCheckUtil {

  public StaticObj staticobj = StaticObj.getInstance();

  /**
   * 考勤流程设置里的校验
   * @param param
   * @param kqSplitFlowTypeEnum
   * @return
   */
  public static Map<String,String> checkAttFlow(Map<String, Object> param,
      KqSplitFlowTypeEnum kqSplitFlowTypeEnum) {
    String isAttOk = "1";
    String msgAttError = "";
    Map<String,String> result = new HashMap<>();
    try{
      boolean is_flow_check = is_flow_check();
      if(!is_flow_check){
        result.put("isAttOk", isAttOk);
        result.put("msgAttError", msgAttError);
        return result;
      }
      boolean isKQFlow = isKQFlow(param);
      if(!isKQFlow){
        result.put("isAttOk", isAttOk);
        result.put("msgAttError", msgAttError);
        return result;
      }
      commonCheck(param,result,kqSplitFlowTypeEnum);

      if("0".equalsIgnoreCase(Util.null2s(result.get("isAttOk"),""))){
        return result;
      }
      if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.LEAVE){
        leaveCheck(param,result);
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.EVECTION){
        evectionCheck(param,result);
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.OUT){
        outCheck(param,result);
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.OVERTIME){
        overtimeCheck(param,result);
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.SHIFT){
        shiftCheck(param,result);
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.OTHER){
        otherCheck(param,result);
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.CARD){
        cardCheck(param,result);
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.LEAVEBACK){
        leavebackCheck(param,result);
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.PROCESSCHANGE){
        processchangeCheck(param,result);
      }else{
        isAttOk = "0";
        msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005362,weaver.general.ThreadVarLanguage.getLang())+"";
        result.put("isAttOk", isAttOk);
        result.put("msgAttError", msgAttError);
      }
    }catch (Exception e){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005362,weaver.general.ThreadVarLanguage.getLang())+"";
      result.put("isAttOk", isAttOk);
      result.put("msgAttError", msgAttError);
    }
    return result;
  }

  public static boolean isKQFlow(Map<String,Object> param) {
    String isAttOk = "1";
    String msgAttError = "";
    boolean isKQFlow = true;
    RecordSet rs = new RecordSet();
    String attid = Util.null2String(param.get("attid"));
    if(attid.length() > 0 && Util.getIntValue(attid, -1) > 0){
      String sql = " select *from kq_att_proc_set where field005 = 1 and id = ? ";
      rs.executeQuery(sql,attid);
      if(rs.next()){
      }else{
        isKQFlow = false;
      }
    }else{
      isKQFlow = false;
    }
    return isKQFlow;
  }

  private static void commonCheck(Map<String, Object> param, Map<String, String> result,
      KqSplitFlowTypeEnum kqSplitFlowTypeEnum) throws Exception{
    String isAttOk = "1";
    String msgAttError = "";
    RecordSet rs = new RecordSet();

    String[] fieldList = (String[])param.get("fields");
    String usedetail = Util.null2String(param.get("usedetail"));
    String detailtablename = Util.null2String(param.get("detailtablename"));
    String tablename = Util.null2String(param.get("tablename"));
    String attid = Util.null2String(param.get("attid"));

    if(attid.length() == 0) {
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005362,weaver.general.ThreadVarLanguage.getLang())+"";
    }else{
      List<String> actions = new ArrayList<>();
      String actionSql = "select * from kq_att_proc_action where field001= ? ";
      rs.executeQuery(actionSql, attid);
      while(rs.next()){
        String actionname = Util.null2String(rs.getString("field002"));
        String nodeid = Util.null2String(rs.getString("field006"));
        actions.add(actionname);
      }
      if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.LEAVE){
        if(!actions.contains(KqSplitActionEnum.LEAVE.getSplitAction())){
          isAttOk = "0";
          msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005363,weaver.general.ThreadVarLanguage.getLang())+"";
        }
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.EVECTION){
        if(!actions.contains(KqSplitActionEnum.EVECTION.getSplitAction())){
          isAttOk = "0";
          msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005363,weaver.general.ThreadVarLanguage.getLang())+"";
        }
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.OUT){
        if(!actions.contains(KqSplitActionEnum.OUT.getSplitAction())){
          isAttOk = "0";
          msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005363,weaver.general.ThreadVarLanguage.getLang())+"";
        }
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.OVERTIME){
        if(!actions.contains(KqSplitActionEnum.OVERTIME.getSplitAction())){
          isAttOk = "0";
          msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005363,weaver.general.ThreadVarLanguage.getLang())+"";
        }
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.SHIFT){
        if(!actions.contains(KqSplitActionEnum.SHIFT.getSplitAction())){
          isAttOk = "0";
          msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005363,weaver.general.ThreadVarLanguage.getLang())+"";
        }
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.OTHER){
        if(!actions.contains(KqSplitActionEnum.OTHER.getSplitAction())){
          isAttOk = "0";
          msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005363,weaver.general.ThreadVarLanguage.getLang())+"";
        }
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.CARD){
        if(!actions.contains(KqSplitActionEnum.Card.getSplitAction())){
          isAttOk = "0";
          msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005363,weaver.general.ThreadVarLanguage.getLang())+"";
        }
      }else if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.LEAVEBACK){
        if(!actions.contains(KqSplitActionEnum.LEAVEBACK.getSplitAction())){
          isAttOk = "0";
          msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005363,weaver.general.ThreadVarLanguage.getLang())+"";
        }
      }
    }
    if(fieldList == null || fieldList.length == 0 || Util.null2s(fieldList[0],"").length() == 0) {
      new KQLog().info("考勤流程fieldList有问题:"+ JSON.toJSONString(fieldList));
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005364,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("1".equalsIgnoreCase(usedetail) && detailtablename.length() == 0) {
      new KQLog().info("考勤流程有问题:detailtablename为空");
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005364,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if(kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.LEAVE || kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.EVECTION
        || kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.OUT || kqSplitFlowTypeEnum == KqSplitFlowTypeEnum.OVERTIME){
      if(!"1".equalsIgnoreCase(usedetail) && tablename.length() == 0) {
        new KQLog().info("考勤流程有问题:tablename为空");
        isAttOk = "0";
        msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005364,weaver.general.ThreadVarLanguage.getLang())+"";
      }
    }
    result.put("isAttOk", isAttOk);
    result.put("msgAttError", msgAttError);
  }

  public static void leavebackCheck(Map<String, Object> param, Map<String, String> result) throws Exception{
    String isAttOk = "1";
    String msgAttError = "";
    String[] fieldList = (String[])param.get("fields");

    if("".equalsIgnoreCase(fieldList[0]) || !fieldList[0].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005365,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[1]) || !fieldList[1].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005366,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[2]) || !fieldList[2].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005367,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[3]) || !fieldList[3].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005368,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[4]) || !fieldList[4].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005369,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[5]) || !fieldList[5].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005370,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[6]) || !fieldList[6].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005371,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[7]) || !fieldList[7].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005372,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[8]) || !fieldList[8].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005373,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[9]) || !fieldList[9].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005374,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[10]) || !fieldList[10].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005375,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[11]) || !fieldList[11].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005376,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[12]) || !fieldList[12].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005377,weaver.general.ThreadVarLanguage.getLang())+"";
    }else{
      if(!result.isEmpty()){
        return ;
      }
    }
    result.put("isAttOk", isAttOk);
    result.put("msgAttError", msgAttError);

  }

  public static void processchangeCheck(Map<String, Object> param, Map<String, String> result) throws Exception{
    String isAttOk = "1";
    String msgAttError = "";
    String[] fieldList = (String[])param.get("fields");

    if("".equalsIgnoreCase(fieldList[0]) || !fieldList[0].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005378,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[1]) || !fieldList[1].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005379,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[2]) || !fieldList[2].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005380,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[3]) || !fieldList[3].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005381,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[4]) || !fieldList[4].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005382,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[5]) || !fieldList[5].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005383,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[6]) || !fieldList[6].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005384,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[7]) || !fieldList[7].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005385,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[8]) || !fieldList[8].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005386,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[9]) || !fieldList[9].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005387,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[10]) || !fieldList[10].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005388,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[11]) || !fieldList[11].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005389,weaver.general.ThreadVarLanguage.getLang())+"";
    }
    if("".equalsIgnoreCase(fieldList[12]) || !fieldList[12].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005390,weaver.general.ThreadVarLanguage.getLang())+"";
    }else{
      if(!result.isEmpty()){
        return ;
      }
    }
    result.put("isAttOk", isAttOk);
    result.put("msgAttError", msgAttError);

  }

  public static void cardCheck(Map<String,Object> param,Map<String, String> result) throws Exception{
    String isAttOk = "1";
    String msgAttError = "";
    String[] fieldList = (String[])param.get("fields");

    if("".equalsIgnoreCase(fieldList[0]) || !fieldList[0].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005391,weaver.general.ThreadVarLanguage.getLang())+"";
      
    }
    if("".equalsIgnoreCase(fieldList[1]) || !fieldList[1].startsWith("field")){
      new KQLog().info("考勤流程字段【考勤开始日期】未对应");
    }
    if("".equalsIgnoreCase(fieldList[2]) || !fieldList[2].startsWith("field")){
      new KQLog().info("考勤流程字段【考勤结束日期】未对应");
    }
    if("".equalsIgnoreCase(fieldList[3]) || !fieldList[3].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005392,weaver.general.ThreadVarLanguage.getLang())+"";
      
    }
    if("".equalsIgnoreCase(fieldList[4]) || !fieldList[4].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005393,weaver.general.ThreadVarLanguage.getLang())+"";
      
    }
    if("".equalsIgnoreCase(fieldList[5]) || !fieldList[5].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005394,weaver.general.ThreadVarLanguage.getLang())+"";
      
    }
    if("".equalsIgnoreCase(fieldList[6]) || !fieldList[6].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005395,weaver.general.ThreadVarLanguage.getLang())+"";
      
    }
    if("".equalsIgnoreCase(fieldList[7]) || !fieldList[7].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005396,weaver.general.ThreadVarLanguage.getLang())+"";
      
    }
    result.put("isAttOk", isAttOk);
    result.put("msgAttError", msgAttError);

  }

  /**
   * 没有异常流程了。不作处理
   * @param param
   * @param result
   */
  public static void otherCheck(Map<String,Object> param,Map<String, String> result) throws Exception{

  }

  public static void shiftCheck(Map<String,Object> param,Map<String, String> result) throws Exception{
    String isAttOk = "1";
    String msgAttError = "";
    String[] fieldList = (String[])param.get("fields");

    if("".equalsIgnoreCase(fieldList[0]) || !fieldList[0].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005397,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[1]) || !fieldList[2].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005398,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[2]) || !fieldList[3].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005399,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[3]) || !fieldList[3].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005400,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    result.put("isAttOk", isAttOk);
    result.put("msgAttError", msgAttError);

  }

  public static void overtimeCheck(Map<String, Object> param, Map<String, String> result) throws Exception{
    String isAttOk = "1";
    String msgAttError = "";
    String[] fieldList = (String[])param.get("fields");

    if("".equalsIgnoreCase(fieldList[0]) || !fieldList[0].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005401,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[2]) || !fieldList[2].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005402,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[3]) || !fieldList[3].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005403,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[4]) || !fieldList[4].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005404,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[5]) || !fieldList[5].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005405,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[6]) || !fieldList[6].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005406,weaver.general.ThreadVarLanguage.getLang())+"";

    }else{
      if(!result.isEmpty()){
        return ;
      }
    }

    result.put("isAttOk", isAttOk);
    result.put("msgAttError", msgAttError);
  }

  public static void outCheck(Map<String, Object> param, Map<String, String> result) throws Exception{
    String isAttOk = "1";
    String msgAttError = "";
    String[] fieldList = (String[])param.get("fields");

    if("".equalsIgnoreCase(fieldList[0]) || !fieldList[0].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005401,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[2]) || !fieldList[2].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005402,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[3]) || !fieldList[3].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005403,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[4]) || !fieldList[4].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005404,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[5]) || !fieldList[5].startsWith("field")){
      isAttOk = "0";
      msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005405,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[6]) || !fieldList[6].startsWith("field")){
    }else{
      if(!result.isEmpty()){
        return ;
      }
    }

    result.put("isAttOk", isAttOk);
    result.put("msgAttError", msgAttError);
    
  }

  public static void evectionCheck(Map<String, Object> param, Map<String, String> result) throws Exception{
    String isAttOk = "1";
    String msgAttError = "";
    String[] fieldList = (String[])param.get("fields");

    if("".equalsIgnoreCase(fieldList[0]) || !fieldList[0].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005401,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[2]) || !fieldList[2].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005402,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[3]) || !fieldList[3].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005403,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[4]) || !fieldList[4].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005404,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[5]) || !fieldList[5].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005405,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[6]) || !fieldList[6].startsWith("field")){
    }else{
      if(!result.isEmpty()){
        return ;
      }
    }

    result.put("isAttOk", isAttOk);
    result.put("msgAttError", msgAttError);
  }

  public static void leaveCheck(Map<String, Object> param, Map<String, String> result) throws Exception{
    String isAttOk = "1";
    String msgAttError = "";
    String[] fieldList = (String[])param.get("fields");
    String attid = Util.null2String(param.get("attid"));

    if("".equalsIgnoreCase(fieldList[0]) || !fieldList[0].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005401,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[2]) || !fieldList[2].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005371,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[3]) || !fieldList[3].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005402,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[4]) || !fieldList[4].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005403,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[5]) || !fieldList[5].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005404,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[6]) || !fieldList[6].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005405,weaver.general.ThreadVarLanguage.getLang())+"";

    }
    if("".equalsIgnoreCase(fieldList[7]) || !fieldList[7].startsWith("field")){
    isAttOk = "0";
    msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005372,weaver.general.ThreadVarLanguage.getLang())+"";
    }else{
      if(!result.isEmpty()){
        return ;
      }
    }
    if("".equalsIgnoreCase(fieldList[8]) || !fieldList[8].startsWith("field")){
    new KQLog().info("考勤流程字段【假期余额】未对应");
    }

    result.put("isAttOk", isAttOk);
    result.put("msgAttError", msgAttError);
  }

  public static void duration_edit_check(String fieldid, Map<String, String> result) {
    if(true){
      //最终确认，不在发起流程的时候提示，在考勤流程字段对应里增加说明
      return ;
    }
  }

  public static void duration_edit_check_new(String fieldid, Map<String, String> result,
      int workflowid) {
    String isAttOk = "1";
    String msgAttError = "";
    RecordSet rs = new RecordSet();
    RecordSet rs1 = new RecordSet();
    String edit_sql = "select *  from workflow_nodeform where 1 = 1   and fieldid = ? and nodeid in("
        + " SELECT nodeid from workflow_flownode where workflowid=? ) ";
    rs.executeQuery(edit_sql,fieldid,workflowid);
    while (rs.next()){
      String isedit = Util.null2s(rs.getString("isedit"),"");
      String ismandatory = Util.null2s(rs.getString("ismandatory"),"");
      String isonlyshow = Util.null2s(rs.getString("isonlyshow"),"");
      if("1".equalsIgnoreCase(isedit) || "1".equalsIgnoreCase(ismandatory) || "1".equalsIgnoreCase(isonlyshow)){
        //如果字段是可编辑的或者是必填的，或者是禁止手工编辑的，都满足条件
      }else{
        String nodeid = Util.null2s(rs.getString("nodeid"),"");
        boolean isEnd = false;
        if(nodeid.length() > 0){
          String is_end_sql = "select 1 from workflow_nodebase where id= ? and  isend =1 ";
          rs1.executeQuery(is_end_sql, nodeid);
          if(rs1.next()){
            //如果是归档节点，可以不考虑
            isEnd = true;
          }
        }
        if(!isEnd){
          isAttOk = "0";
          msgAttError = ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005332,weaver.general.ThreadVarLanguage.getLang())+"";
          result.put("isAttOk", isAttOk);
          result.put("msgAttError", msgAttError);
          break;
        }
      }
    }
  }

  public void initLeaveUnit(){
    String half_leave_ruleid = "";
    String whole_leave_ruleid = "";
    KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
    while (kqLeaveRulesComInfo.next()){
      String ruleid = kqLeaveRulesComInfo.getId();
      String changeType = kqLeaveRulesComInfo.getMinimumUnit();
      boolean isHalf = "2".equals(changeType);
      boolean isWhole = "4".equals(changeType);
      if(isHalf){
        half_leave_ruleid += ","+ruleid;
      }
      if(isWhole){
        whole_leave_ruleid += ","+ruleid;
      }
    }
    if (half_leave_ruleid.length() > 0 &&!half_leave_ruleid.endsWith(",")){
      half_leave_ruleid+=",";
      staticobj.putObject("half_leave_ruleid", half_leave_ruleid);
    }
    if (whole_leave_ruleid.length() > 0 &&!whole_leave_ruleid.endsWith(",")){
      whole_leave_ruleid+=",";
      staticobj.putObject("whole_leave_ruleid", whole_leave_ruleid);
    }
  }

  /**
   * 是否开启流程设置校验
   * @return
   */
  public static boolean is_flow_check() {
    boolean is_flow_check = true;
    RecordSet rs = new RecordSet();
    String settingSql = "select * from KQ_SETTINGS where main_key='flow_check'";
    rs.executeQuery(settingSql);
    if(rs.next()){
      String main_val = rs.getString("main_val");
      if(!"1".equalsIgnoreCase(main_val)){
        is_flow_check = false;
      }
    }
    return is_flow_check;
  }
}
