package com.chenyang.nse.bussiness.tools.expression;

import com.chenyang.nse.bussiness.tools.string.AesTool;
import com.chenyang.nse.bussiness.tools.string.BinaryConversion;
import com.chenyang.nse.bussiness.tools.string.RandomnumTool;
import com.chenyang.nse.bussiness.tools.string.StringTool;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.MapContext;
import org.apache.commons.jexl3.internal.Engine;
import org.apache.commons.lang.StringUtils;

public class ExpressionTool {
   private static ExpressionTool et = null;
   private static List<String> funcLst = new ArrayList();
   Map<String, Object> map = new HashMap();
   private static JexlEngine jexlEngine = new Engine();
   private Map<String, JexlExpression> jexlExpMap = new HashMap();
   private static RandomnumTool randomnum = null;

   public void init() {
      try {
         jexlEngine = new Engine();
         funcLst = new ArrayList();
         funcLst.add("indexof");
         funcLst.add("reverse");
         funcLst.add("ascii");
         funcLst.add("concat");
         funcLst.add("instr");
         funcLst.add("length");
         funcLst.add("lower");
         funcLst.add("upper");
         funcLst.add("lpad");
         funcLst.add("ltrim");
         funcLst.add("replacechr");
         funcLst.add("replacestr");
         funcLst.add("rpad");
         funcLst.add("rtrim");
         funcLst.add("substr");
         funcLst.add("reg_extract");
         funcLst.add("reg_match");
         funcLst.add("reg_replace");
         funcLst.add("add_to_date");
         funcLst.add("date_compare");
         funcLst.add("date_diff");
         funcLst.add("get_date_part");
         funcLst.add("trunc");
         funcLst.add("aes_decrypt");
         funcLst.add("aes_encrypt");
         funcLst.add("dec_base64");
         funcLst.add("enc_base64");
         funcLst.add("md5");
         funcLst.add("decompress");
         funcLst.add("compress");
         funcLst.add("convert_base");
         funcLst.add("rand");
         funcLst.add("abs");
         funcLst.add("floor");
         funcLst.add("mod");
         funcLst.add("round");
         funcLst.add("is_number");
         funcLst.add("is_spaces");
         funcLst.add("isnull");
         funcLst.add("to_bigint");
         funcLst.add("to_char");
         funcLst.add("to_date");
         funcLst.add("to_decimal");
         funcLst.add("to_float");
         funcLst.add("to_integer");
         funcLst.add("iif");
         funcLst.add("decode");
         funcLst.add("chr");
         funcLst.add("rsa_encrypt");
         funcLst.add("rsa_decrypt");
         funcLst.add("watermark");
         funcLst.add("key_water_mark");
         funcLst.add("key_digital_water_mark");
      } catch (Exception var2) {
      }

   }

   public Integer indexof(String value, Object... objects) {
      Integer returnValue = 0;
      if (StringUtils.isNotBlank(value)) {
         int whileSize = objects.length;
         String lastParamType = "";
         Object lastObj = objects[objects.length - 1];
         lastParamType = lastObj.getClass().getName();
         Boolean ignorecaseFlg = false;
         if (null == lastObj || lastParamType.contains("Interger") || "0" == String.valueOf(lastObj)) {
            --whileSize;
            ignorecaseFlg = true;
         }

         for(int i = 0; i < whileSize; ++i) {
            if (ignorecaseFlg) {
               if (value.equalsIgnoreCase(String.valueOf(objects[i]))) {
                  returnValue = i + 1;
                  break;
               }
            } else if (value.equals(String.valueOf(objects[i]))) {
               returnValue = i + 1;
               break;
            }
         }
      } else {
         returnValue = null;
      }

      return returnValue;
   }

   public String reverse(String value) {
      String reStr = "";
      if (StringUtils.isNotBlank(value)) {
         char[] c = new char[value.length()];

         for(int i = 0; i < value.length(); ++i) {
            c[i] = value.charAt(value.length() - 1 - i);
         }

         reStr = String.valueOf(c);
      }

      return reStr;
   }

   public Integer ascii(String value) {
      if (null == value) {
         return null;
      } else {
         Integer re = 0;
         char[] charValue = value.toCharArray();
         if (null != charValue && charValue.length > 0) {
            re = Integer.valueOf(charValue[0]);
         }

         return re;
      }
   }

   public String chr(Integer value) {
      if (null == value)
         return null;
      char a = (char)value.intValue();
      return String.valueOf(a);
   }

   public String concat(Object a, Object b) {
      String reStr = "";
      if (null == a && null == b) {
         reStr = null;
      } else if (null != a && null == b) {
         reStr = a.toString();
      } else if (null == a && null != b) {
         reStr = b.toString();
      } else if (null != a && null != b) {
         reStr = a.toString().concat(b.toString());
      }

      return reStr;
   }

   public int instr1(String value, String str) {
      int reInt = 0;
      if (StringUtils.isNotBlank(value)) {
         if (value.indexOf(str) == -1) {
            reInt = 0;
         }

         reInt = value.indexOf(str) + 1;
      }

      return reInt;
   }

   public static Integer instr(Object valueObj, String str, Integer... ints) {
      Integer reInt = 0;
      int i = 0;
      if (null != valueObj) {
         String value = valueObj.toString();
         if (ints.length == 0) {
            reInt = value.indexOf(str) + 1;
         } else if (ints.length == 1) {
            if (ints[0] >= 0) {
               reInt = value.indexOf(str, ints[0] - 1) + 1;
            } else if (ints[0] < 0) {
               reInt = value.lastIndexOf(str) + 1;
            }
         } else if (ints.length == 2) {
            int index = 0;

            for(String strValue = value; i < ints[1]; ++index) {
               if (ints[0] >= 0) {
                  if (i == 0) {
                     index = strValue.indexOf(str, index + ints[0] - 1);
                  } else {
                     index = strValue.indexOf(str, index);
                  }
               } else if (ints[0] < 0) {
                  index = strValue.lastIndexOf(str);
                  if (-1 == index) {
                     index = 0;
                     break;
                  }

                  strValue = value.substring(0, index);
               }

               ++i;
            }

            reInt = index;
         } else if (ints.length == 3) {
         }
      } else {
         reInt = null;
      }

      return reInt;
   }

   public Integer length(String value) {
      Integer reLen = null;
      if (null != value) {
         reLen = value.length();
      }

      return reLen;
   }

   public String lower(String value) {
      String reStr = null;
      if (null != value) {
         reStr = value.toLowerCase();
      }

      return reStr;
   }

   public String upper(String value) {
      String reStr = null;
      if (null != value) {
         reStr = value.toUpperCase();
      }

      return reStr;
   }

   public String lpad(String value, int length) {
      if (null != value && length >= 0) {
         String reStr = "";
         if (value.length() < length) {
            for(int i = 0; i < length - value.length(); ++i) {
               reStr = reStr + " ";
            }

            reStr = reStr + value;
         } else {
            reStr = value.substring(0, length);
         }

         return reStr;
      } else {
         return null;
      }
   }

   public String lpad(String value, int length, String addstr) {
      if (null != value && length >= 0) {
         if (StringUtils.isBlank(addstr)) {
            return value;
         } else {
            String reStr = "";
            char[] addchar = addstr.toCharArray();
            int charLength = addstr.length();
            if (value.length() < length) {
               int strDif = length - value.length();
               if (strDif > charLength) {
                  for(int i = 0; i < strDif / charLength; ++i) {
                     reStr = reStr + addstr;
                  }
               }

               for(int i = 0; i < strDif % charLength; ++i) {
                  reStr = reStr + addchar[i];
               }

               reStr = reStr + value;
            } else {
               reStr = value.substring(0, length);
            }

            return reStr;
         }
      } else {
         return null;
      }
   }

   public String ltrim(String value) {
      String reStr = null;
      if (null != value) {
         String resultStr;
         for(resultStr = value; resultStr.startsWith(" ") || resultStr.startsWith("\t") || resultStr.startsWith("\\s"); resultStr = resultStr.replaceFirst("\\s*", "")) {
         }

         reStr = resultStr;
      }

      return reStr;
   }

   public String ltrim(String value, String str) {
      if (null != value && null != str) {
         String reStr = "";
         if (StringUtils.isNotBlank(value) || StringUtils.isNotBlank(str)) {
            char[] charValue = value.toCharArray();
            char[] charStr = str.toCharArray();
            reStr = "";
            List<Character> list = new ArrayList();

            for(int i = 0; i < charValue.length; ++i) {
               list.add(charValue[i]);
            }

            int j = 0;

            for(int z = 0; j < charValue.length; ++z) {
               if (z >= charStr.length) {
                  z = 0;
               }

               if (charValue[j] != charStr[z]) {
                  break;
               }

               list.remove(0);
               ++j;
            }

            for(int i = 0; i < list.size(); ++i) {
               reStr = reStr + ((Character)list.get(i)).toString();
            }
         }

         return reStr;
      } else {
         return null;
      }
   }

   public static String replacecharJava(Integer caseFlag, String value, String oldCharSet, String newChar) {
      if (null == value) {
         return null;
      } else if (StringUtils.isBlank(oldCharSet)) {
         return value;
      } else {
         String isCaseSensitive = "";
         if (null == caseFlag || 0 == caseFlag) {
            isCaseSensitive = "(?i)";
         }

         char[] oldCharArr = oldCharSet.toCharArray();

         for(int i = 0; i < oldCharArr.length; ++i) {
            char oldChar = oldCharArr[i];
            if (StringUtils.isBlank(newChar)) {
               value = value.replaceAll(isCaseSensitive + oldChar, "");
            } else {
               char[] newCharArr = newChar.toCharArray();
               value = value.replaceAll(isCaseSensitive + oldChar, newCharArr[0] + "");
            }
         }

         return value;
      }
   }

   public static String replacestr(Integer caseFlag, String value, String... strings) {
      if (null == value) {
         return null;
      } else {
         String newAllStr = "";
         String reStr = "";
         String resultstr = value;
         String regular = "";
         String newStr = strings[strings.length - 1];
         if (null == caseFlag || 0 == caseFlag) {
            regular = "(?i)";
         }

         if (null == newStr) {
            newStr = "";
         }

         String substringpre = "";
         if (value != "") {
            for(int i = 0; i < strings.length - 1; ++i) {
               strings[i] = strings[i].trim();
               int newStrindex = 0;
               if (null != caseFlag && 0 != caseFlag) {
                  newStrindex = resultstr.indexOf(strings[i]);
               } else {
                  newStrindex = resultstr.toUpperCase().indexOf(strings[i].toUpperCase());
               }

               if (newStrindex >= 0) {
                  substringpre = resultstr.substring(0, newStrindex + strings[i].length());
                  resultstr = resultstr.substring(newStrindex + strings[i].length());
                  substringpre = substringpre.replaceAll(regular + strings[i], newStr);
                  newAllStr = newAllStr + substringpre;
               }
            }

            if (resultstr != "") {
               newAllStr = newAllStr + resultstr;
            }
         }

         return newAllStr;
      }
   }

   public String rpad(String value, int length) {
      if (null != value && length >= 0) {
         String reStr = "";
         if (value.length() < length) {
            for(int i = 0; i < length - value.length(); ++i) {
               reStr = reStr + " ";
            }

            reStr = value + reStr;
         } else {
            reStr = value.substring(0, length);
         }

         return reStr;
      } else {
         return null;
      }
   }

   public String rpad(String value, int length, String addstr) {
      if (null != value && length >= 0) {
         if (StringUtils.isBlank(addstr)) {
            return value;
         } else {
            String reStr = "";
            char[] addchar = addstr.toCharArray();
            int charLength = addstr.length();
            int strDif = length - value.length();
            if (value.length() < length) {
               if (charLength <= strDif) {
                  for(int i = 0; i < strDif / charLength; ++i) {
                     reStr = reStr + addstr;
                  }
               }

               for(int i = 0; i < strDif % charLength; ++i) {
                  reStr = reStr + addchar[i];
               }

               reStr = value + reStr;
            } else {
               reStr = value.substring(0, length);
            }

            return reStr;
         }
      } else {
         return null;
      }
   }

   public String rtrim(String value) {
      if (null == value) {
         return null;
      } else {
         String reStr = "";
         if (StringUtils.isNotBlank(value)) {
            String resultStr;
            for(resultStr = value; resultStr.endsWith(" ") || resultStr.startsWith("\t") || resultStr.startsWith("\\s"); resultStr = resultStr.substring(0, resultStr.length() - 1)) {
            }

            reStr = resultStr;
         }

         return reStr;
      }
   }

   public String rtrim(String value, String str) {
      if (null == value) {
         return null;
      } else {
         StringBuilder reStr = new StringBuilder();
         if (StringUtils.isNotBlank(value) || StringUtils.isNotBlank(str)) {
            List<Character> valList = new ArrayList();
            char[] valueArr = value.toCharArray();

            for(int i = 0; i < valueArr.length; ++i) {
               valList.add(valueArr[i]);
            }

            char[] replaceCharArr = str.toCharArray();

            for(int i = 0; i < replaceCharArr.length; ++i) {
               for(int j = valList.size() - 1; j >= 0 && (Character)valList.get(j) == replaceCharArr[i]; --j) {
                  valList.remove(j);
               }
            }

            for(Character s : valList) {
               reStr.append(s);
            }
         }

         return reStr.toString();
      }
   }

   public static String substr(String value, int start) {
      if (null == value) {
         return null;
      } else {
         if (start > 0) {
            --start;
            if (start > value.length()) {
               return "";
            }
         } else if (start < 0) {
            start += value.length();
            if (0 > start) {
               start = 0;
            }
         }

         value = value.substring(start);
         return value;
      }
   }

   public static String substr(String value, int start, int len) {
      if (len <= 0) {
         return "";
      } else if (null == value) {
         return null;
      } else {
         if (start > 0) {
            --start;
            if (start > value.length()) {
               return "";
            }
         } else if (start < 0) {
            start += value.length();
            if (0 > start) {
               start = 0;
            }
         }

         int endIndex = start + len <= value.length() ? start + len : value.length();
         value = value.substring(start, endIndex);
         return value;
      }
   }

   public String reg_extract(String value, String divisor) {
      if (!StringUtils.isBlank(value) && null != divisor) {
         String reStr = "";
         Pattern pattern = Pattern.compile(divisor);

         for(Matcher matcher = pattern.matcher(value); matcher.find(); reStr = matcher.group(1)) {
         }

         return reStr;
      } else {
         return null;
      }
   }

   public String reg_extract(String value, String divisor, int subPatternNum) {
      if (!StringUtils.isBlank(value) && null != divisor) {
         String reStr = "";
         Pattern pattern = Pattern.compile(divisor);

         for(Matcher matcher = pattern.matcher(value); matcher.find(); reStr = matcher.group(subPatternNum)) {
         }

         return reStr;
      } else {
         return null;
      }
   }

   public String reg_extract(String value, String divisor, int subPatternNum, int match_from_start) {
      if (!StringUtils.isBlank(value) && null != divisor) {
         value = substr(value, match_from_start);
         String reStr = "";
         Pattern pattern = Pattern.compile(divisor);

         for(Matcher matcher = pattern.matcher(value); matcher.find(); reStr = matcher.group(subPatternNum)) {
         }

         return reStr;
      } else {
         return null;
      }
   }

   public Boolean reg_match(String value, String pattern) {
      if (!StringUtils.isBlank(value) && null != pattern) {
         boolean isMatch = Pattern.matches(pattern, value);
         return isMatch;
      } else {
         return null;
      }
   }

   public String reg_replace(String value, String pattern, String replace) {
      String reStr = value.replaceAll(pattern, replace);
      return reStr;
   }

   public String reg_replace(String value, String pattern, String replace, int numReplacements) {
      String reStr = "";
      int i = 0;
      int index = 0;
      String subvalue = value;
      int patternl = pattern.length();
      int local = 0;
      String beforeStr = "";

      while(true) {
         if (numReplacements <= 1 || i >= numReplacements) {
            if (numReplacements < 1) {
               reStr = value;
            } else if (numReplacements == 1) {
               reStr = value.replaceFirst(pattern, replace);
            } else {
               subvalue.replaceFirst(pattern, replace);
               beforeStr = value.substring(0, index + 1).replace(pattern, replace);
               reStr = beforeStr + value.substring(index + 1);
            }
            break;
         }

         local = subvalue.indexOf(pattern);
         if (local == -1) {
            reStr = value;
            break;
         }

         index += subvalue.indexOf(pattern) + patternl;
         subvalue = value.substring(index);
         ++i;
      }

      return reStr;
   }

   public static Date add_to_java_date(Object dataObj, String format, int amount) {
      if (null == dataObj) {
         return null;
      } else {
         Date data = Object2Date(dataObj);
         Date reDate = null;
         Calendar cal = Calendar.getInstance();
         cal.setTime(data);
         if (!"Y".equalsIgnoreCase(format) && !"YY".equalsIgnoreCase(format) && !"YYY".equalsIgnoreCase(format) && !"YYYY".equalsIgnoreCase(format)) {
            if (!"MM".equalsIgnoreCase(format) && !"MON".equalsIgnoreCase(format) && !"MONTH".equalsIgnoreCase(format)) {
               if (!"D".equalsIgnoreCase(format) && !"DD".equalsIgnoreCase(format) && !"DDD".equalsIgnoreCase(format) && !"DY".equalsIgnoreCase(format) && !"DAY".equalsIgnoreCase(format)) {
                  if (!"HH".equalsIgnoreCase(format) && !"HH12".equalsIgnoreCase(format) && !"HH24".equalsIgnoreCase(format)) {
                     if ("MI".equalsIgnoreCase(format)) {
                        cal.add(12, amount);
                     } else if ("SS".equalsIgnoreCase(format)) {
                        cal.add(13, amount);
                     } else if ("MS".equalsIgnoreCase(format)) {
                        cal.add(14, amount);
                     } else if ("US".equalsIgnoreCase(format)) {
                        cal.add(14, amount / 1000);
                     }
                  } else {
                     cal.add(10, amount);
                  }
               } else {
                  cal.add(5, amount);
               }
            } else {
               cal.add(2, amount);
            }
         } else {
            cal.add(1, amount);
         }

         reDate = cal.getTime();
         return reDate;
      }
   }

   public static Integer date_compare(Object dataObj1, Object dataObj2) {
      if (null != dataObj1 && null != dataObj2) {
         Date data1 = Object2Date(dataObj1);
         Date data2 = Object2Date(dataObj2);
         return data1.compareTo(data2);
      } else {
         return null;
      }
   }

   public static Double date_diff(Object dataObj1, Object dataObj2, String format) {
      if (null != dataObj1 && null != dataObj2) {
         Date data1 = Object2Date(dataObj1);
         Date data2 = Object2Date(dataObj2);
         Double reTime = null;
         long dateMillis1 = data1.getTime();
         long dateMillis2 = data2.getTime();
         if (!"Y".equalsIgnoreCase(format) && !"YY".equalsIgnoreCase(format) && !"YYY".equalsIgnoreCase(format) && !"YYYY".equalsIgnoreCase(format)) {
            if (!"MM".equalsIgnoreCase(format) && !"MON".equalsIgnoreCase(format) && !"MONTH".equalsIgnoreCase(format)) {
               if (!"D".equalsIgnoreCase(format) && !"DD".equalsIgnoreCase(format) && !"DDD".equalsIgnoreCase(format) && !"DY".equalsIgnoreCase(format) && !"DAY".equalsIgnoreCase(format)) {
                  if (!"HH".equalsIgnoreCase(format) && !"HH12".equalsIgnoreCase(format) && !"HH24".equalsIgnoreCase(format)) {
                     if ("MI".equalsIgnoreCase(format)) {
                        reTime = new Double((double)((dateMillis1 - dateMillis2) / 1000L / 60L));
                     } else if ("SS".equalsIgnoreCase(format)) {
                        reTime = new Double((double)((dateMillis1 - dateMillis2) / 1000L));
                     } else if ("MS".equalsIgnoreCase(format)) {
                        reTime = new Double((double)(dateMillis1 - dateMillis2));
                     } else if ("US".equalsIgnoreCase(format)) {
                        reTime = new Double((double)(dateMillis1 * 1000L - dateMillis2 * 1000L));
                     }
                  } else {
                     reTime = new Double((double)((dateMillis1 - dateMillis2) / 1000L / 3600L));
                  }
               } else {
                  reTime = new Double((double)((dateMillis1 - dateMillis2) / 1000L / 86400L));
               }
            } else {
               reTime = new Double((double)((dateMillis1 - dateMillis2) / 1000L / 2592000L));
            }
         } else {
            reTime = new Double((double)((dateMillis1 - dateMillis2) / 1000L / 31536000L));
         }

         return reTime;
      } else {
         return null;
      }
   }

   public static Integer get_date_part(Object dataObj1, String format) {
      if (null == dataObj1) {
         return null;
      } else {
         Date data = Object2Date(dataObj1);
         Integer reTime = null;
         Calendar cal = Calendar.getInstance();
         cal.setTime(data);
         if (!"Y".equalsIgnoreCase(format) && !"YY".equalsIgnoreCase(format) && !"YYY".equalsIgnoreCase(format) && !"YYYY".equalsIgnoreCase(format)) {
            if (!"MM".equalsIgnoreCase(format) && !"MON".equalsIgnoreCase(format) && !"MONTH".equalsIgnoreCase(format)) {
               if (!"D".equalsIgnoreCase(format) && !"DD".equalsIgnoreCase(format) && !"DDD".equalsIgnoreCase(format) && !"DY".equalsIgnoreCase(format) && !"DAY".equalsIgnoreCase(format)) {
                  if (!"HH".equalsIgnoreCase(format) && !"HH12".equalsIgnoreCase(format) && !"HH24".equalsIgnoreCase(format)) {
                     if ("MI".equalsIgnoreCase(format)) {
                        reTime = cal.get(12);
                     } else if ("SS".equalsIgnoreCase(format)) {
                        reTime = cal.get(13);
                     } else if ("MS".equalsIgnoreCase(format)) {
                        reTime = cal.get(14);
                     } else if ("US".equalsIgnoreCase(format)) {
                        reTime = 0;
                     }
                  } else {
                     reTime = cal.get(11);
                  }
               } else {
                  reTime = cal.get(5);
               }
            } else {
               reTime = cal.get(2) + 1;
            }
         } else {
            reTime = cal.get(1);
         }

         return reTime;
      }
   }

   public static Date round(Object dataObj1, String... formatArr) {
      if (null == dataObj1) {
         return null;
      } else {
         Date data1 = Object2Date(dataObj1);
         Date reDate = null;
         String format = "";
         if (null != formatArr && formatArr.length > 0) {
            format = formatArr[0];
         } else {
            format = "DD";
         }

         Calendar cal = Calendar.getInstance();
         cal.setTime(data1);
         Integer intTime = 0;
         if (!"Y".equalsIgnoreCase(format) && !"YY".equalsIgnoreCase(format) && !"YYY".equalsIgnoreCase(format) && !"YYYY".equalsIgnoreCase(format)) {
            if (!"MM".equalsIgnoreCase(format) && !"MON".equalsIgnoreCase(format) && !"MONTH".equalsIgnoreCase(format)) {
               if (!"D".equalsIgnoreCase(format) && !"DD".equalsIgnoreCase(format) && !"DDD".equalsIgnoreCase(format) && !"DY".equalsIgnoreCase(format) && !"DAY".equalsIgnoreCase(format)) {
                  if (!"HH".equalsIgnoreCase(format) && !"HH12".equalsIgnoreCase(format) && !"HH24".equalsIgnoreCase(format)) {
                     if ("MI".equalsIgnoreCase(format)) {
                        Integer intTime1 = get_date_part(dataObj1, "MI");
                        Integer intTime2 = get_date_part(dataObj1, "HH");
                        intTime = get_date_part(dataObj1, "SS");
                        if (intTime < 30) {
                           cal.add(12, 0);
                        } else {
                           cal.add(12, 1);
                           if (intTime2 == 11 && intTime1 == 59) {
                              cal.add(5, 1);
                           }
                        }

                        cal.set(13, 0);
                     } else if ("SS".equalsIgnoreCase(format)) {
                        intTime = get_date_part(dataObj1, "MS");
                        if (intTime < 500) {
                           cal.add(13, 0);
                        } else {
                           cal.add(13, 1);
                        }

                        cal.set(14, 0);
                     } else if ("MS".equalsIgnoreCase(format)) {
                        intTime = get_date_part(dataObj1, "US");
                        if (intTime < 500) {
                           cal.add(14, 0);
                        } else {
                           cal.add(14, 1);
                        }
                     } else if ("US".equalsIgnoreCase(format)) {
                     }
                  } else {
                     intTime = get_date_part(dataObj1, "MI");
                     Integer intTime1 = get_date_part(dataObj1, "HH");
                     if (intTime < 30) {
                        cal.add(10, 0);
                     } else {
                        cal.add(10, 1);
                        if (intTime1 == 11) {
                           cal.add(5, 1);
                        }
                     }

                     cal.set(12, 0);
                     cal.set(13, 0);
                  }
               } else {
                  intTime = get_date_part(dataObj1, "HH");
                  Integer intTime1 = get_date_part(dataObj1, "MI");
                  Integer intTime2 = get_date_part(dataObj1, "SS");
                  if (intTime < 12 && (intTime != 11 || intTime1 != 59 || intTime2 != 59)) {
                     cal.add(5, 0);
                  } else {
                     cal.add(5, 1);
                  }

                  cal.set(11, 0);
                  cal.set(12, 0);
                  cal.set(13, 0);
               }
            } else {
               intTime = get_date_part(dataObj1, "DD");
               if (intTime <= 15) {
                  cal.add(2, 0);
               } else {
                  cal.add(2, 1);
               }

               cal.set(5, 1);
               cal.set(11, 12);
               cal.set(12, 0);
               cal.set(13, 0);
            }
         } else {
            intTime = get_date_part(dataObj1, "MM");
            if (intTime <= 6) {
               cal.add(1, 0);
            } else {
               cal.add(1, 1);
            }

            cal.set(2, 0);
            cal.set(5, 1);
            cal.set(11, 12);
            cal.set(12, 0);
            cal.set(13, 0);
         }

         reDate = cal.getTime();
         return reDate;
      }
   }

   public static Timestamp systimestamp(String... formatArr) {
      Date data = new Date();
      Timestamp reTimestamp = null;
      String format = "";
      if (null != formatArr && formatArr.length > 0) {
         format = formatArr[0];
      } else {
         format = "US";
      }

      Calendar cal = Calendar.getInstance();
      cal.setTime(data);
      if ("SS".equalsIgnoreCase(format)) {
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

         try {
            reTimestamp = new Timestamp(df.parse(df.format(new Date())).getTime());
         } catch (ParseException e) {
            e.printStackTrace();
         }
      } else if ("MS".equalsIgnoreCase(format)) {
         reTimestamp = new Timestamp(System.currentTimeMillis());
      } else if ("US".equalsIgnoreCase(format)) {
         reTimestamp = new Timestamp(System.currentTimeMillis());
      } else if ("NS".equalsIgnoreCase(format)) {
         reTimestamp = new Timestamp(System.currentTimeMillis());
      }

      return reTimestamp;
   }

   public static Date trunc(Object object, String... formatArr) {
      if (null == object) {
         return null;
      } else {
         Date data = Object2Date(object);
         Date reDate = null;
         String format = "";
         if (null != formatArr && formatArr.length > 0) {
            format = formatArr[0];
         } else {
            format = "DD";
         }

         Calendar cal = Calendar.getInstance();
         cal.setTime(data);
         if (!"Y".equalsIgnoreCase(format) && !"YY".equalsIgnoreCase(format) && !"YYY".equalsIgnoreCase(format) && !"YYYY".equalsIgnoreCase(format)) {
            if (!"MM".equalsIgnoreCase(format) && !"MON".equalsIgnoreCase(format) && !"MONTH".equalsIgnoreCase(format)) {
               if (!"D".equalsIgnoreCase(format) && !"DD".equalsIgnoreCase(format) && !"DDD".equalsIgnoreCase(format) && !"DY".equalsIgnoreCase(format) && !"DAY".equalsIgnoreCase(format)) {
                  if (!"HH".equalsIgnoreCase(format) && !"HH12".equalsIgnoreCase(format) && !"HH24".equalsIgnoreCase(format)) {
                     if ("MI".equalsIgnoreCase(format)) {
                        cal.add(12, 0);
                        cal.set(13, 0);
                     } else if ("SS".equalsIgnoreCase(format)) {
                        cal.add(13, 0);
                        cal.set(14, 0);
                     } else if ("MS".equalsIgnoreCase(format)) {
                        cal.add(14, 0);
                     }
                  } else {
                     cal.add(10, 0);
                     cal.set(12, 0);
                     cal.set(12, 0);
                     cal.set(13, 0);
                  }
               } else {
                  cal.add(5, 0);
                  cal.set(11, 0);
                  cal.set(11, 12);
                  cal.set(12, 0);
                  cal.set(13, 0);
               }
            } else {
               cal.add(2, 0);
               cal.set(5, 1);
               cal.set(11, 12);
               cal.set(12, 0);
               cal.set(13, 0);
            }
         } else {
            cal.add(1, 0);
            cal.set(2, 0);
            cal.set(5, 1);
            cal.set(11, 12);
            cal.set(12, 0);
            cal.set(13, 0);
         }

         reDate = cal.getTime();
         return reDate;
      }
   }

   public static String aes_encrypt(String data, String key) {
      if (null == data) {
         return null;
      } else {
         String enStr = AesTool.encrypt(data, key);
         return enStr;
      }
   }

   public static String aes_decrypt(String data, String key) {
      if (null == data) {
         return null;
      } else {
         String enStr = AesTool.decrypt(data, key);
         return enStr;
      }
   }

   public static String enc_base64(String data) {
      if (null == data) {
         return null;
      } else {
         String reStr = "";

         try {
            byte[] byteContent = data.getBytes("utf-8");
            reStr = (new Base64()).encodeToString(byteContent);
         } catch (Exception e) {
            e.printStackTrace();
         }

         return reStr;
      }
   }

   public static String dec_base64(String data) {
      if (null == data) {
         return null;
      } else {
         String reStr = "";

         try {
            byte[] byteContent = Base64.decodeBase64(data);
            reStr = new String(byteContent);
         } catch (Exception e) {
            e.printStackTrace();
         }

         return reStr;
      }
   }

   public static String md5(String data) {
      if (null == data) {
         return null;
      } else {
         String reStr = StringTool.encodeByMD5(data);
         return reStr;
      }
   }

   public String convert_base(String value, int source_base, int dest_base) {
      String reInt = "";
      if (null != value) {
         char[] chs = new char[36];

         for(int i = 0; i < 10; ++i) {
            chs[i] = (char)(48 + i);
         }

         for(int i = 10; i < chs.length; ++i) {
            chs[i] = (char)(65 + (i - 10));
         }

         int number = Integer.valueOf(value, source_base);

         StringBuilder sb;
         for(sb = new StringBuilder(); number != 0; number /= dest_base) {
            sb.append(chs[number % dest_base]);
         }

         reInt = sb.reverse().toString();
      }

      return reInt;
   }

   public double rand(int value) {
      Random r = new Random((long)value);
      double re = r.nextDouble();
      return re;
   }

   public double rand() {
      Random r = new Random();
      double re = r.nextDouble();
      return re;
   }

   public Integer abs(Integer value) {
      return null == value ? null : Math.abs(value);
   }

   public Double abs(Double value) {
      return null == value ? null : Math.abs(value);
   }

   public Double abs(BigDecimal value) {
      return null == value ? null : Math.abs(value.doubleValue());
   }

   public Object floor(Object value) {
      Object re = null;
      if (value == null) {
         return re;
      } else {
         re = Math.floor(Double.parseDouble(value.toString()));
         Double reD = Double.valueOf(re.toString());
         if (reD <= (double)Integer.MAX_VALUE && reD >= (double)Integer.MIN_VALUE) {
            re = reD.intValue();
         }

         return re;
      }
   }

   public Integer modJava(Object value, Integer divisor) {
      if (null != value && null != divisor && 0 != divisor) {
         int re = 0;
         re = (int)(Double.parseDouble(value.toString()) % (double)divisor);
         return re;
      } else {
         return null;
      }
   }

   public Object round(Object value) {
      Object re = null;
      if (value == null) {
         re = null;
      } else {
         int index = value.toString().indexOf(".");
         int l = 0;
         if (index == -1) {
            l = value.toString().length();
         } else {
            l = value.toString().substring(value.toString().indexOf(".")).length();
         }

         if (l > 15) {
            re = Math.round(Double.parseDouble(value.toString()));
         } else {
            re = Math.round(Float.parseFloat(value.toString()));
         }
      }

      return re;
   }

   public Object round(Object value, Double precision) {
      Object re = null;
      if (value != null && null != precision) {
         BigDecimal pcs = new BigDecimal(precision);
         int precisionInt = pcs.setScale(0, 4).intValue();
         int index = value.toString().indexOf(".");
         int l = 0;
         if (index == -1) {
            l = value.toString().length();
         } else {
            l = value.toString().substring(value.toString().indexOf(".")).length();
         }

         if (l > 15) {
            BigDecimal b = new BigDecimal(Double.parseDouble(value.toString()));
            re = b.setScale(precisionInt, 4).doubleValue();
         } else {
            BigDecimal b = new BigDecimal((double)Float.parseFloat(value.toString()));
            re = b.setScale(precisionInt, 4).floatValue();
         }
      } else {
         re = null;
      }

      return re;
   }

   public Object round(Object value, double precision) {
      Object re = null;
      if (value == null) {
         re = null;
      } else {
         BigDecimal pcs = new BigDecimal(precision);
         int precisionInt = pcs.setScale(0, 4).intValue();
         int index = value.toString().indexOf(".");
         int l = 0;
         if (index == -1) {
            l = value.toString().length();
         } else {
            l = value.toString().substring(value.toString().indexOf(".")).length();
         }

         if (l > 15) {
            BigDecimal b = new BigDecimal(Double.parseDouble(value.toString()));
            re = b.setScale(precisionInt, 4).doubleValue();
         } else {
            BigDecimal b = new BigDecimal((double)Float.parseFloat(value.toString()));
            re = b.setScale(precisionInt, 4).floatValue();
         }
      }

      return re;
   }

   public static Boolean is_number(String data) {
      if (null == data) {
         return null;
      } else {
         data = data.trim();
         String os = System.getProperty("os.name");
         if (os.toLowerCase().startsWith("win")) {
            data = data.replaceAll("(?i)d", "e");
         }

         try {
            new BigDecimal(data);
            return true;
         } catch (Exception var3) {
            return false;
         }
      }
   }

   public static Boolean is_spaces(String data) {
      Boolean isFlg = false;
      if (null == data) {
         return null;
      } else {
         if (!"".equals(data)) {
            Pattern p = Pattern.compile("\\t|\\f|\\n|\\r|\\v");
            Matcher m = p.matcher(data);
            String dest = m.replaceAll("");
            if (StringUtils.isBlank(dest)) {
               isFlg = true;
            }
         }

         return isFlg;
      }
   }

   public Boolean isnull(Object data) {
      return null == data ? true : false;
   }

   public static Object to_bigint(Object data) {
      BigInteger reBigInt = new BigInteger("0");
      if (null == data) {
         return null;
      } else {
         String dataStr = data.toString();
         dataStr = dataStr.trim();
         if (is_number(dataStr)) {
            BigDecimal bigNum = null;
            if (data instanceof Double) {
               bigNum = new BigDecimal((Double)data);
            } else {
               bigNum = new BigDecimal(dataStr);
            }

            bigNum = bigNum.setScale(0, 4);
            reBigInt = new BigInteger(bigNum.toString());
         }

         return reBigInt;
      }
   }

   public static Object to_bigint(Object data, Integer flag) {
      BigInteger reBigInt = new BigInteger("0");
      if (null == data) {
         return null;
      } else {
         String dataStr = data.toString();
         dataStr = dataStr.trim();
         if (is_number(dataStr)) {
            BigDecimal bigNum = null;
            if (data instanceof Double) {
               bigNum = new BigDecimal((Double)data);
            } else {
               bigNum = new BigDecimal(dataStr);
            }

            if (0 != flag) {
               bigNum = bigNum.setScale(0, 0);
            } else {
               bigNum = bigNum.setScale(0, 4);
            }

            reBigInt = new BigInteger(bigNum.toString());
         }

         return reBigInt;
      }
   }

   public static Object to_bigint(Object data, Boolean flag) {
      BigInteger reBigInt = new BigInteger("0");
      if (null == data) {
         return null;
      } else {
         String dataStr = data.toString();
         dataStr = dataStr.trim();
         if (is_number(dataStr)) {
            BigDecimal bigNum = null;
            if (data instanceof Double) {
               bigNum = new BigDecimal((Double)data);
            } else {
               bigNum = new BigDecimal(dataStr);
            }

            if (flag) {
               bigNum = bigNum.setScale(0, 1);
            } else {
               bigNum = bigNum.setScale(0, 4);
            }

            reBigInt = new BigInteger(bigNum.toString());
         }

         return reBigInt;
      }
   }

   public static String to_char(Object dataObj) {
      if (null == dataObj) {
         return null;
      } else {
         String dataStr = "";
         if (!(dataObj instanceof Double) && !(dataObj instanceof Integer) && !(dataObj instanceof BigInteger)) {
            Date data = Object2Date(dataObj);
            SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss:SSSSSS");
            dataStr = fmt.format(data);
         } else {
            dataStr = dataObj.toString();
         }

         return dataStr;
      }
   }

   public static Date Object2Date(Object data) {
      Date reDate = null;
      String dataStr = data.toString();
      String defFormatStr = "yyyy-MM-dd HH:mm:ss:SSSSSS";
      SimpleDateFormat fmt = new SimpleDateFormat(defFormatStr);

      try {
         reDate = fmt.parse(dataStr);
         return reDate;
      } catch (ParseException e) {
         e.printStackTrace();
         return reDate;
      } finally {
         ;
      }
   }

   public static String to_char(Object object, String formatStrPar) {
      if (null == object) {
         return null;
      } else {
         String dataResult = "";
         String dataStr = object.toString();
         formatStrPar = formatStrPar.toUpperCase();
         Date date = Object2Date(object);

         try {
            String e = formatStrPar.replaceAll("MON", "MMMM");
            e = e.replaceAll("DAY", "E");
            e = e.replaceAll("DDD", "CCC");
            e = e.replaceAll("DD", "dd");
            e = e.replaceAll("D", "E");
            e = e.replaceAll("CCC", "D");
            e = e.replaceAll("MI", "mm");
            e = e.replaceAll("SSSSS", "sssss");
            e = e.replaceAll(".US", ".SSSSSS");
            e = e.replaceAll("HH24", "HH");
            e = e.replaceAll("HH12", "hh");
            e = e.replaceAll("RR", "YY");
            e = e.replaceAll("WW", "w");
            e = e.replaceAll("W", "W");
            int week_index = 0;
            SimpleDateFormat format = null;
            if (formatStrPar.indexOf("MON") >= 0) {
               format = new SimpleDateFormat(e, Locale.ENGLISH);
            } else if (formatStrPar.indexOf("DAY") >= 0) {
               format = new SimpleDateFormat(e, Locale.ENGLISH);
            } else if (!formatStrPar.equalsIgnoreCase("J")) {
               format = new SimpleDateFormat(e);
            }

            if (formatStrPar.equalsIgnoreCase("D")) {
               Calendar cal = Calendar.getInstance();
               cal.setTime(date);
               week_index = cal.get(7);
               dataResult = String.valueOf(week_index);
            } else if (!formatStrPar.equalsIgnoreCase("MM/DD/YY") && !formatStrPar.equalsIgnoreCase("MM/DD/RR")) {
               if (formatStrPar.equalsIgnoreCase("SSSSS")) {
                  Calendar cal = Calendar.getInstance();
                  cal.setTime(date);
                  int hour = cal.get(11);
                  int min = cal.get(12);
                  int sec = cal.get(13);
                  int secondall = hour * 3600 + min * 60 + sec;
                  dataResult = String.valueOf(secondall);
               } else if (formatStrPar.equalsIgnoreCase("HH24")) {
                  dataResult = format.format(date);
                  if (dataStr.toUpperCase().contains("PM")) {
                     int parseInt = Integer.parseInt(dataResult);
                     dataResult = String.valueOf(parseInt + 12);
                  }

                  if (dataStr.toUpperCase().contains("AM") && dataResult.equals("12")) {
                     dataResult = "00";
                  }
               } else if (formatStrPar.equalsIgnoreCase("J")) {
                  Calendar cal = Calendar.getInstance();
                  cal.setTime(date);
                  int year = cal.get(1);
                  int month = cal.get(2) + 1;
                  int day = cal.get(6);
                  int l = 0;
                  if (month == 1 || month == 2) {
                     l = 1;
                  }

                  dataResult = String.valueOf(14956 + day + (int)((double)((float)year - (float)l) * (double)365.25F) + (int)((double)((float)month + 1.0F + (float)(l * 12)) * 30.6001));
               } else {
                  dataResult = format.format(date);
               }
            } else {
               Calendar cal = Calendar.getInstance();
               cal.setTime(date);
               int year = cal.get(1);
               String yearstr = String.valueOf(year).substring(2);
               int month = cal.get(2);
               ++month;
               int day = cal.get(5);
               dataResult = month + "/" + day + "/" + yearstr;
            }
         } catch (Exception e) {
            e.printStackTrace();
         }

         return dataResult;
      }
   }

   public static Date to_date(String data, String... formatStrArr) {
      if (null == data) {
         return null;
      } else {
         Date reDate = null;
         String defFormatStr = "YYYY-MM-dd HH:mm:ss:SSSSSS";
         if (null != formatStrArr && formatStrArr.length > 0) {
            defFormatStr = formatStrArr[0];
            defFormatStr = defFormatStr.toUpperCase();
         }

         String formatStr = defFormatStr;

         try {
            formatStr = formatStr.replaceAll("MON", "MMMM");
            formatStr = formatStr.replaceAll("DAY", "E");
            formatStr = formatStr.replaceAll("DDD", "CCC");
            formatStr = formatStr.replaceAll("DD", "dd");
            formatStr = formatStr.replaceAll("D", "dd");
            formatStr = formatStr.replaceAll("CCC", "D");
            formatStr = formatStr.replaceAll("MI", "mm");
            formatStr = formatStr.replaceAll("SS", "ss");
            formatStr = formatStr.replaceAll(".US", ".SSSSSS");
            formatStr = formatStr.replaceAll("HH24", "HH");
            formatStr = formatStr.replaceAll("HH12", "hh");
            formatStr = formatStr.replaceAll("YYYY", "yyyy");
            formatStr = formatStr.replaceAll("WW", "w");
            formatStr = formatStr.replaceAll("W", "W");
            formatStr = formatStr.trim();
            SimpleDateFormat format = null;
            if (formatStr.indexOf("yyyy") < 0 && defFormatStr.indexOf("Y") < 0 && defFormatStr.indexOf("J") < 0 && defFormatStr.indexOf("MM/DD/RR") < 0) {
               (new StringBuilder()).append("yyyy-").append(formatStr).toString();
               String year = String.valueOf(Calendar.getInstance().get(1));
               (new StringBuilder()).append(year).append("-").append(data).toString();
            } else if (!defFormatStr.equalsIgnoreCase("MM/DD/YY") && !defFormatStr.equalsIgnoreCase("MM/DD/RR")) {
               if (defFormatStr.equalsIgnoreCase("MON DD YYYY HH12:MI:SSAM")) {
                  format = new SimpleDateFormat("MM dd yyyy HH:mm:ss");
                  reDate = format.parse(data);
               } else if (defFormatStr.equalsIgnoreCase("MM/DD/YYYY SSSSS")) {
                  String[] split = data.split(" ");
                  String timeStr = split[1];
                  int time = Integer.parseInt(timeStr);
                  String truetime = "";
                  if (time < 60) {
                     truetime = "00:00:" + time;
                  } else if (time < 3600) {
                     Integer min = 60;
                     Integer sec = 0;
                     truetime = "00:" + min + ":" + sec;
                  } else if (time < 86400) {
                     Integer hour = time / 3600;
                     Integer min = time / 60 % 60;
                     Integer sec = time % 3600 % 60;
                     if (sec == 0) {
                        truetime = hour + ":" + min + ":00";
                     } else {
                        truetime = hour + ":" + min + ":" + sec;
                     }
                  }

                  String alltime = split[0] + " " + truetime;
                  format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
                  reDate = format.parse(alltime);
               } else if (defFormatStr.equalsIgnoreCase("MM/DD/YYY")) {
                  String[] split = data.split("/");
                  Date date = new Date();
                  Calendar cal = Calendar.getInstance();
                  cal.setTime(date);
                  int year = cal.get(1);
                  int nowTime = Integer.parseInt(String.valueOf(year).substring(2));
                  int putTime = Integer.parseInt(split[2]);
                  putTime = Integer.parseInt(String.valueOf(putTime).substring(1));
                  String dateStr = "";
                  if (putTime > nowTime) {
                     dateStr = split[0] + " " + split[1] + " 1" + split[2] + " 00:00:00";
                  } else {
                     dateStr = split[0] + " " + split[1] + " 2" + split[2] + " 00:00:00";
                  }

                  format = new SimpleDateFormat("MM dd yyyy HH:mm:ss");
                  reDate = format.parse(dateStr);
               } else if (defFormatStr.equalsIgnoreCase("MM/DD/Y")) {
                  String[] split = data.split("/");
                  String dateStr = split[0] + " " + split[1] + " 199" + split[2] + " 00:00:00";
                  format = new SimpleDateFormat("MM dd yyyy HH:mm:ss");
                  reDate = format.parse(dateStr);
               } else if (defFormatStr.equalsIgnoreCase("J")) {
                  int dataInt = Integer.parseInt(data);
                  int year = dataInt / 1000 + 1900;
                  int dayOfYear = dataInt % 1000;
                  Calendar calendar = Calendar.getInstance();
                  calendar.set(1, year);
                  calendar.set(6, dayOfYear);
                  reDate = calendar.getTime();
               } else {
                  formatStr = "" + formatStr;
                  format = new SimpleDateFormat(formatStr);
                  reDate = format.parse(data);
               }
            } else {
               String[] split = data.split("/");
               Date date = new Date();
               Calendar cal = Calendar.getInstance();
               cal.setTime(date);
               int year = cal.get(1);
               int nowTime = Integer.parseInt(String.valueOf(year).substring(2));
               int putTime = Integer.parseInt(split[2]);
               String dateStr = "";
               if (putTime > nowTime) {
                  dateStr = split[0] + " " + split[1] + " 19" + split[2] + " 00:00:00";
               } else {
                  dateStr = split[0] + " " + split[1] + " 20" + split[2] + " 00:00:00";
               }

               format = new SimpleDateFormat("MM dd yyyy HH:mm:ss");
               reDate = format.parse(dateStr);
            }
         } catch (Exception e) {
            e.printStackTrace();
         }

         return reDate;
      }
   }

   public static BigDecimal to_decimal(String data, int... scaleArr) {
      if (null == data) {
         return null;
      } else {
         BigDecimal bigNum = new BigDecimal(0);
         if (is_number(data)) {
            bigNum = new BigDecimal(data);
            if (data.indexOf(".") > 0) {
               int scale = 0;
               if (null != scaleArr && scaleArr.length > 0) {
                  scale = scaleArr[0];
                  bigNum = bigNum.setScale(scale, 4);
               }
            }
         } else {
            String numStr = "";

            for(int i = 0; i < data.length(); ++i) {
               String codeChar = data.substring(i, i + 1);
               if (!isCellInteger(codeChar) && !".".equals(codeChar)) {
                  break;
               }

               numStr = numStr + codeChar;
            }

            if (StringUtils.isNotBlank(numStr)) {
               bigNum = to_decimal(numStr, scaleArr);
            }
         }

         return bigNum;
      }
   }

   public static Double to_float(String data) {
      if (null == data) {
         return null;
      } else {
         data = data.trim();
         Double doubleNum = new Double((double)0.0F);
         if (is_number(data)) {
            doubleNum = new Double(data);
         }

         return doubleNum;
      }
   }

   public static Integer to_integer(Object data) {
      if (null == data) {
         return null;
      } else {
         Integer reNum = 0;
         String dataStr = data.toString().trim();
         if (is_number(dataStr)) {
            BigDecimal intNum = null;
            if (data instanceof Double) {
               intNum = new BigDecimal((Double)data);
            } else {
               intNum = new BigDecimal(dataStr);
            }

            intNum = intNum.setScale(0, 4);
            if (isIntegerStr(intNum.toString())) {
               reNum = new Integer(intNum.toString());
            }
         }

         return reNum;
      }
   }

   public static Integer to_integer(Object data, Object flag) {
      if (null == data) {
         return null;
      } else {
         Integer reNum = 0;
         String dataStr = data.toString().trim();
         Boolean roundFlg = true;
         if (null != flag && ("0".equals(flag.toString()) || "FALSE".equalsIgnoreCase(flag.toString()))) {
            roundFlg = false;
         }

         dataStr = dataStr.replace(",", "");
         if (is_number(dataStr)) {
            BigDecimal intNum = null;
            if (data instanceof Double) {
               intNum = new BigDecimal((Double)data);
            } else {
               intNum = new BigDecimal(dataStr);
            }

            if (roundFlg) {
               intNum = intNum.setScale(0, 1);
            } else {
               intNum = intNum.setScale(0, 4);
            }

            if (isIntegerStr(intNum.toString())) {
               reNum = new Integer(intNum.toString());
            }
         }

         return reNum;
      }
   }

   private static boolean isNumber(String str) {
      String reg = "^[0-9]+(.[0-9]+)?$";
      return str.matches(reg);
   }

   public static boolean isCellInteger(String str) {
      Pattern pattern = Pattern.compile("[\\d]");
      return pattern.matcher(str).matches();
   }

   public static boolean isIntegerStr(String value) {
      try {
         Integer.parseInt(value);
         return true;
      } catch (NumberFormatException var2) {
         return false;
      }
   }

   public static Object iif(Boolean condition, Object val1, Object val2) {
      return null != condition && !condition ? val2 : val1;
   }

   public Object iif(Boolean condition, Object val1) {
      Object reObj = null;
      if (null != condition && !condition) {
         if (null == val1) {
            return reObj;
         } else {
            if (val1 instanceof Number) {
               reObj = 0;
            } else if (val1 instanceof String) {
               reObj = "";
            }

            return reObj;
         }
      } else {
         return val1;
      }
   }

   public Object decode(Object value, Object... cond) {
      Object reStr = null;
      Boolean matchFlg = false;
      if (null != cond && cond.length >= 2) {
         Object def = null;
         if (0 != cond.length % 2) {
            def = cond[cond.length - 1];
         }

         if (null == value) {
            return def;
         }

         for(int i = 0; i < cond.length; i += 2) {
            if (value.toString().equals(cond[i].toString())) {
               reStr = cond[i + 1];
               matchFlg = true;
               break;
            }
         }

         if (!matchFlg) {
            reStr = def;
         }
      }

      return reStr;
   }

   public Object rsa_encrypt(Object value, String publicKey) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
      byte[] decoded = Base64.decodeBase64(publicKey);
      RSAPublicKey pubKey = (RSAPublicKey)KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(1, pubKey);
      String outStr = Base64.encodeBase64String(cipher.doFinal(String.valueOf(value).getBytes("UTF-8")));
      return outStr;
   }

   public static String rsa_decrypt(Object value, String privateKey) throws Exception {
      byte[] inputByte = Base64.decodeBase64(String.valueOf(value).getBytes("UTF-8"));
      byte[] decoded = Base64.decodeBase64(privateKey);
      RSAPrivateKey priKey = (RSAPrivateKey)KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded));
      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(2, priKey);
      String outStr = new String(cipher.doFinal(inputByte));
      return outStr;
   }

   public static String operatorConversion(String expressionStr) {
      expressionStr = StringUtils.replace(expressionStr, "TRUE", "true");
      expressionStr = StringUtils.replace(expressionStr, "NULL", "''");
      expressionStr = StringUtils.replace(expressionStr, "||null", "||''");
      expressionStr = StringUtils.replace(expressionStr, "||", "+");
      expressionStr = StringUtils.replace(expressionStr, "=", "==");
      expressionStr = StringUtils.replace(expressionStr, ">==", ">=");
      expressionStr = StringUtils.replace(expressionStr, "<==", "<=");
      expressionStr = StringUtils.replace(expressionStr, "!==", "!=");
      expressionStr = StringUtils.replace(expressionStr, "AND", "&&");
      expressionStr = StringUtils.replace(expressionStr, "OR", "||");
      return expressionStr;
   }

   public static Object executeExpression(String jexlExpression, Map<String, Object> map) {
      JexlExpression expression = jexlEngine.createExpression(jexlExpression);
      return null;
   }

   public static Object executeExpression1(String jexlExpression, Map<String, Object> map) {
      JexlExpression expression = jexlEngine.createExpression(jexlExpression);
      JexlContext context = new MapContext();
      if (null != map) {
         map.forEach(context::set);
      }

      return expression.evaluate(context);
   }

   public static void main11(String[] args) {
      JexlContext ctxt = new MapContext();
      new Engine();
      String exps = "if(c1>c2){c3=1}else{c3=2}";
      boolean var4 = true;
      ctxt.set("c1", 2);
      ctxt.set("c2", 1);
      System.out.println(ctxt.get("c3"));
   }

   public Object execExpress(String expressStr) {
      Object reObj = null;
      expressStr = operatorConversion(expressStr);

      for(int i = 0; i < funcLst.size(); ++i) {
         String funcName = (String)funcLst.get(i);
         String reFuncName = funcName;
         if ("mod".equalsIgnoreCase(funcName)) {
            reFuncName = "modJava";
         } else if ("replacechr".equalsIgnoreCase(funcName)) {
            reFuncName = "replacecharJava";
         } else if ("decompress".equalsIgnoreCase(funcName)) {
            reFuncName = "decompreJava";
         } else if ("add_to_date".equalsIgnoreCase(funcName)) {
            reFuncName = "add_to_java_date";
         }

         expressStr = StringUtils.replace(expressStr, funcName, "et." + reFuncName);
      }

      executeExpression(expressStr, this.map);
      return reObj;
   }

   public Object execExpress(String expressStr, JexlContext ctxt) {
      Object reObj = null;
      expressStr = operatorConversion(expressStr);

      for(int i = 0; i < funcLst.size(); ++i) {
         String funcName = (String)funcLst.get(i);
         String reFuncName = funcName;
         if ("mod".equalsIgnoreCase(funcName)) {
            reFuncName = "modJava";
         } else if ("replacechr".equalsIgnoreCase(funcName)) {
            reFuncName = "replacecharJava";
         } else if ("decompress".equalsIgnoreCase(funcName)) {
            reFuncName = "decompreJava";
         } else if ("add_to_date".equalsIgnoreCase(funcName)) {
            reFuncName = "add_to_java_date";
         }

         expressStr = StringUtils.replace(expressStr, funcName, "et." + reFuncName);
      }

      JexlExpression jexlExpressionObj;
      if (this.jexlExpMap.containsKey(expressStr)) {
         jexlExpressionObj = (JexlExpression)this.jexlExpMap.get(expressStr);
      } else {
         jexlExpressionObj = jexlEngine.createExpression(expressStr);
         this.jexlExpMap.put(expressStr, jexlExpressionObj);
      }

      ctxt.set("et", this);
      reObj = jexlExpressionObj.evaluate(ctxt);
      return reObj;
   }

   public static void main(String[] args) {
      et = new ExpressionTool();
      et.init();
      String expressStr5 = "iif(false,'2019-02-11','ASFDASDF')";
      expressStr5 = "substr('abc123',1,3)";
      Object str = execExpress(expressStr5, (Object)et);
      System.out.println(str);
   }

   public static void main2(String[] args) {
      et = new ExpressionTool();
      et.init();
   }

   public static String execExpress(String expressStr, Object expressClass) {
      String reStr = "";
      expressStr = operatorConversion(expressStr);

      for(int i = 0; i < funcLst.size(); ++i) {
         String funcName = (String)funcLst.get(i);
         String reFuncName = funcName;
         if ("mod".equalsIgnoreCase(funcName)) {
            reFuncName = funcName + "Java";
         } else if ("replacechr".equalsIgnoreCase(funcName)) {
            reFuncName = "replacecharJava";
         } else if ("decompress".equalsIgnoreCase(funcName)) {
            reFuncName = "decompreJava";
         } else if ("add_to_date".equalsIgnoreCase(funcName)) {
            reFuncName = "add_to_java_date";
         }

         if (expressStr.toLowerCase().indexOf(funcName) >= 0) {
            expressStr = expressStr.replaceAll("(?i)" + funcName, "et." + reFuncName);
         }
      }

      Map<String, Object> map = new HashMap();
      map.put("et", expressClass);
      Object reObj = executeExpression1(expressStr, map);
      if (null != reObj) {
         reStr = reObj.toString();
      }

      return reStr;
   }

   public static String str_replace(String str, String patten, String replacement, int pos) {
      int len = str.length();
      int plen = patten.length();
      StringBuilder newContent = new StringBuilder(len);
      int lastPos = 0;

      do {
         newContent.append(str, lastPos, pos);
         newContent.append(replacement);
         lastPos = pos + plen;
         pos = str.indexOf(patten, lastPos);
      } while(pos > 0);

      newContent.append(str, lastPos, len);
      return newContent.toString();
   }

   public static String watermark(String value, String seed, String start, String end) {
      int seedint = 1;
      int startint = 1;
      int endint = value.length();
      if (StringUtils.isNotBlank(seed)) {
         seedint = Integer.valueOf(seed);
      }

      if (StringUtils.isNotBlank(start)) {
         startint = Integer.valueOf(start);
      }

      if (StringUtils.isNotBlank(end)) {
         endint = Integer.valueOf(end);
      }

      if (startint > value.length()) {
         return value;
      } else {
         if (endint > value.length()) {
            endint = value.length();
         }

         String reg = "^[一-龥]+$";
         Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");
         String regex = "^[a-zA-Z]+$";
         Pattern patPunc = Pattern.compile("\\pP");
         if (start != null && end != null) {
            String prefix = value.substring(0, startint - 1);
            String suffix = value.substring(endint);
            value = value.substring(startint - 1, endint);
            String newvalue = "";

            for(int i = 0; i < value.length(); ++i) {
               String strchar = String.valueOf(value.charAt(i));
               if (strchar.matches(reg)) {
                  int intvalue = Integer.valueOf(value.charAt(i));

                  for(intvalue += seedint; intvalue > 40869; intvalue -= 20721) {
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               Matcher isNum = pattern.matcher(strchar);
               if (isNum.matches()) {
                  int intvalue = Integer.valueOf(value.charAt(i));

                  for(intvalue += seedint; intvalue > 57; intvalue -= 10) {
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               if (strchar.matches(regex)) {
                  int intvalue = Integer.valueOf(value.charAt(i));

                  for(intvalue += seedint; intvalue > 122; intvalue -= 26) {
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               Matcher fuhao = patPunc.matcher(strchar);
               if (fuhao.matches()) {
                  newvalue = newvalue + strchar;
               }
            }

            return prefix + newvalue + suffix;
         } else if (start != null) {
            String prefix = value.substring(0, startint - 1);
            value = value.substring(startint - 1);
            String newvalue = "";

            for(int i = 0; i < value.length(); ++i) {
               String strchar = String.valueOf(value.charAt(i));
               if (strchar.matches(reg)) {
                  int intvalue = Integer.valueOf(value.charAt(i));
                  intvalue += seedint;
                  if (intvalue > 40869) {
                     intvalue = intvalue - '龥' + 19968;
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               Matcher isNum = pattern.matcher(strchar);
               if (isNum.matches()) {
                  int intvalue = Integer.valueOf(value.charAt(i));

                  for(intvalue += seedint; intvalue > 57; intvalue -= 10) {
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               if (strchar.matches(regex)) {
                  int intvalue = Integer.valueOf(value.charAt(i));

                  for(intvalue += seedint; intvalue > 122; intvalue -= 26) {
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               Matcher fuhao = patPunc.matcher(strchar);
               if (fuhao.matches()) {
                  newvalue = newvalue + strchar;
               }
            }

            return prefix + newvalue;
         } else if (end != null) {
            String suffix = value.substring(endint);
            value = value.substring(0, endint);
            String newvalue = "";

            for(int i = 0; i < value.length(); ++i) {
               String strchar = String.valueOf(value.charAt(i));
               if (strchar.matches(reg)) {
                  int intvalue = Integer.valueOf(value.charAt(i));
                  intvalue += seedint;
                  if (intvalue > 40869) {
                     intvalue = intvalue - '龥' + 19968;
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               Matcher isNum = pattern.matcher(strchar);
               if (isNum.matches()) {
                  int intvalue = Integer.valueOf(value.charAt(i));

                  for(intvalue += seedint; intvalue > 57; intvalue -= 10) {
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               if (strchar.matches(regex)) {
                  int intvalue = Integer.valueOf(value.charAt(i));

                  for(intvalue += seedint; intvalue > 122; intvalue -= 26) {
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               Matcher fuhao = patPunc.matcher(strchar);
               if (fuhao.matches()) {
                  newvalue = newvalue + strchar;
               }
            }

            return newvalue + suffix;
         } else {
            String newvalue = "";

            for(int i = 0; i < value.length(); ++i) {
               String strchar = String.valueOf(value.charAt(i));
               if (strchar.matches(reg)) {
                  int intvalue = Integer.valueOf(value.charAt(i));
                  intvalue += seedint;
                  if (intvalue > 40869) {
                     intvalue = intvalue - '龥' + 19968;
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               Matcher isNum = pattern.matcher(strchar);
               if (isNum.matches()) {
                  int intvalue = Integer.valueOf(value.charAt(i));

                  for(intvalue += seedint; intvalue > 57; intvalue -= 10) {
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               if (strchar.matches(regex)) {
                  int intvalue = Integer.valueOf(value.charAt(i));

                  for(intvalue += seedint; intvalue > 122; intvalue -= 26) {
                  }

                  newvalue = newvalue + (char)intvalue;
               }

               Matcher fuhao = patPunc.matcher(strchar);
               if (fuhao.matches()) {
                  newvalue = newvalue + strchar;
               }
            }

            return newvalue;
         }
      }
   }

   public static Object key_water_mark(Object value, String key, String start, String end) {
      if (StringUtils.isBlank(value.toString())) {
         return value;
      } else {
         int startint = 1;
         int endint = value.toString().length();
         String substrval = "";
         String newsubstr = "";
         int randomnumval = 0;
         if (!StringUtils.isBlank(key) && endint > 0) {
            if (StringUtils.isNotBlank(end) && Integer.valueOf(start) >= Integer.valueOf(end)) {
               return value;
            } else {
               String reg = "^[一-龥]+$";
               Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");
               String regex = "^[a-zA-Z]+$";
               Pattern patPunc = Pattern.compile("\\pP");
               if (StringUtils.isNotBlank(start) && Integer.valueOf(start) > 0) {
                  startint = Integer.valueOf(start) - 1;
               } else {
                  startint = 0;
               }

               if (StringUtils.isNotBlank(end) && Integer.valueOf(end) <= endint) {
                  endint = Integer.valueOf(end);
               } else {
                  endint = value.toString().length();
               }

               String prefixsubstr = value.toString().substring(0, startint);
               String suffixsubstr = value.toString().substring(endint);
               substrval = value.toString().substring(startint, endint);
               if (substrval.length() < 2) {
                  return value;
               } else {
                  for(int i = 0; i < substrval.length(); ++i) {
                     String strchar = String.valueOf(substrval.charAt(i));
                     Matcher isNum = pattern.matcher(strchar);
                     if (i == 0) {
                        if (randomnum == null) {
                           randomnum = new RandomnumTool(0, key.length());
                        }

                        randomnumval = randomnum.randomnum();
                     }

                     if (isNum.matches()) {
                        if (i == 0) {
                           newsubstr = newsubstr + String.valueOf(randomnumval);
                        } else {
                           String beforestr = String.valueOf(newsubstr.charAt(i - 1));
                           Matcher beforeIsNum = pattern.matcher(beforestr);
                           if (beforeIsNum.matches()) {
                              newsubstr = newsubstr + String.valueOf(key.charAt(Integer.valueOf(beforestr)));
                           } else {
                              String strToBinstr = BinaryConversion.StrToBinstr(beforestr.charAt(0));
                              strToBinstr = strToBinstr.substring(strToBinstr.length() - 4);
                              String index = BinaryConversion.binaryToDecimal(strToBinstr);
                              newsubstr = newsubstr + String.valueOf(key.charAt(Integer.valueOf(index)));
                           }
                        }
                     } else if (i == 0) {
                        String strToBinstr = BinaryConversion.StrToBinstr(strchar.charAt(0));
                        String beforesub = strToBinstr.substring(0, strToBinstr.length() - 4);
                        String replacestr = BinaryConversion.decimalToBinary(randomnumval);
                        newsubstr = newsubstr + BinaryConversion.BinstrToStr(beforesub + replacestr);
                     } else {
                        String beforestr = String.valueOf(newsubstr.charAt(i - 1));
                        Matcher beforeIsNum = pattern.matcher(beforestr);
                        if (beforeIsNum.matches()) {
                           String strToBinstr = BinaryConversion.StrToBinstr(strchar.charAt(0));
                           String var37;
                           String beforesub = var37 = strToBinstr.substring(0, strToBinstr.length() - 4);
                           var37.substring(var37.length() - 4);
                           String replacestr = BinaryConversion.decimalToBinary(Integer.valueOf(String.valueOf(key.charAt(Integer.valueOf(beforestr)))));
                           newsubstr = newsubstr + BinaryConversion.BinstrToStr(beforesub + replacestr);
                        } else {
                           String bestrToBinstr = BinaryConversion.StrToBinstr(beforestr.charAt(0));
                           bestrToBinstr = bestrToBinstr.substring(bestrToBinstr.length() - 4);
                           String beindex = BinaryConversion.binaryToDecimal(bestrToBinstr);
                           String strToBinstr = BinaryConversion.StrToBinstr(strchar.charAt(0));
                           String var42;
                           String beforesub = var42 = strToBinstr.substring(0, strToBinstr.length() - 4);
                           var42.substring(var42.length() - 4);
                           String replacestr = BinaryConversion.decimalToBinary(Integer.valueOf(String.valueOf(key.charAt(Integer.valueOf(beindex)))));
                           newsubstr = newsubstr + BinaryConversion.BinstrToStr(beforesub + replacestr);
                        }
                     }
                  }

                  newsubstr = prefixsubstr + newsubstr + suffixsubstr;
                  return newsubstr;
               }
            }
         } else {
            return value;
         }
      }
   }

   public static Object key_digital_water_mark(Object value, String key, String start, String end) {
      if (StringUtils.isBlank(value.toString())) {
         return value;
      } else {
         int startint = 1;
         int endint = value.toString().length();
         String substrval = "";
         String newsubstr = "";
         int randomnumval = 0;
         if (!StringUtils.isBlank(key) && endint > 0) {
            if (StringUtils.isNotBlank(end) && Integer.valueOf(start) >= Integer.valueOf(end)) {
               return value;
            } else {
               Pattern pattern = Pattern.compile("^[0-9]*$");
               if (StringUtils.isNotBlank(start) && Integer.valueOf(start) > 0) {
                  startint = Integer.valueOf(start) - 1;
               } else {
                  startint = 0;
               }

               if (StringUtils.isNotBlank(end) && Integer.valueOf(end) <= endint) {
                  endint = Integer.valueOf(end);
               } else {
                  endint = value.toString().length();
               }

               String prefixsubstr = value.toString().substring(0, startint);
               String suffixsubstr = value.toString().substring(endint);
               substrval = value.toString().substring(startint, endint);
               if (substrval.length() < 2) {
                  return value;
               } else {
                  Matcher isNum = pattern.matcher(substrval);
                  if (isNum.matches()) {
                     for(int i = 0; i < substrval.length(); ++i) {
                        String strchar = String.valueOf(substrval.charAt(i));
                        if (i == 0) {
                           if (randomnum == null) {
                              randomnum = new RandomnumTool(0, key.length());
                           }

                           randomnumval = randomnum.randomnum();
                        }

                        if (i == 0) {
                           newsubstr = newsubstr + String.valueOf(randomnumval);
                        } else {
                           String beforestr = String.valueOf(newsubstr.charAt(i - 1));
                           newsubstr = newsubstr + String.valueOf(key.charAt(Integer.valueOf(beforestr)));
                        }
                     }

                     newsubstr = prefixsubstr + newsubstr + suffixsubstr;
                     return newsubstr;
                  } else {
                     return value;
                  }
               }
            }
         } else {
            return value;
         }
      }
   }
}
