All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.javajy.api.e.b Maven / Gradle / Ivy

The newest version!
package com.javajy.api.e;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.javajy.api.component.CacheManager;
import com.javajy.api.component.Page;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class b {
    private static Pattern U = Pattern.compile("_(\\w)");
    private static Pattern V = Pattern.compile("[A-Z]");

    public b() {
    }

    public static boolean a(HttpServletRequest var0, HttpServletResponse var1) {
        String var2 = var0.getRequestURI();
        String var3 = var0.getMethod();
        String var4 = var0.getHeader("token");
        if (var2.indexOf("login") <= 0 && var2.indexOf("student/saveOne") <= 0 && var2.indexOf("member/saveOne") <= 0 && var2.indexOf("data/") <= 0 && var2.indexOf("template/") <= 0) {
            if (var2.indexOf("student/search") <= 0 && var2.indexOf("user/search") <= 0) {
                if (!CacheManager.verifyToken(var4) && !"get".equals(var3.toLowerCase())) {
                    if (CacheManager.verifyToken(var4)) {
                        return true;
                    } else {
                        var1.setStatus(403);
                        return false;
                    }
                } else {
                    return true;
                }
            } else {
                return true;
            }
        } else {
            return true;
        }
    }

    public static byte[] a(Object var0) {
        byte[] var1 = null;
        ByteArrayOutputStream var2 = null;
        ObjectOutputStream var3 = null;

        try {
            var2 = new ByteArrayOutputStream();
            var3 = new ObjectOutputStream(var2);
            var3.writeObject(var0);
            var1 = var2.toByteArray();
        } catch (Exception var17) {
        } finally {
            if (var2 != null) {
                try {
                    var2.close();
                } catch (IOException var16) {
                    var16.printStackTrace();
                }
            }

            if (var3 != null) {
                try {
                    var3.close();
                } catch (IOException var15) {
                    var15.printStackTrace();
                }
            }

        }

        return var1;
    }

    public static void a(String var0, String var1) throws URISyntaxException, IOException {
        CloseableHttpClient var2 = HttpClients.createDefault();
        URIBuilder var3 = new URIBuilder(var0);
        var3.addParameter("account", "123");
        var3.addParameter("password", "123");
        HttpGet var4 = new HttpGet(var3.build());
        var4.setHeader("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0");
        RequestConfig var5 = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
        var4.setConfig(var5);
        CloseableHttpResponse var6 = var2.execute(var4);
        int var7 = var6.getStatusLine().getStatusCode();
        System.out.println(var7);
        HttpEntity var8 = var6.getEntity();
        String var9 = EntityUtils.toString(var8);
        System.out.println(var9);
        var6.close();
        var2.close();
    }

    public static String a(String var0, Map var1) {
        Object var2 = null;
        String var3 = null;

        try {
            DefaultHttpClient var4 = new DefaultHttpClient();
            URIBuilder var5 = new URIBuilder(var0);
            Set var6 = var1.keySet();
            Iterator var7 = var6.iterator();

            while(var7.hasNext()) {
                String var8 = (String)var7.next();
                var5.setParameter(var8, (String)var1.get(var8));
            }

            HttpGet var12 = new HttpGet(var5.build());
            var12.setHeader("ContentTye", "application/json");
            RequestConfig var13 = RequestConfig.custom().setSocketTimeout(6000).setConnectTimeout(6000).setConnectionRequestTimeout(6000).build();
            var12.setConfig(var13);
            CloseableHttpResponse var9 = var4.execute(var12);
            HttpEntity var10 = var9.getEntity();
            var3 = EntityUtils.toString(var9.getEntity());
            return var3;
        } catch (Exception var11) {
            throw new RuntimeException(var11);
        }
    }

    public static void j(String var0) throws Exception {
        CloseableHttpClient var1 = HttpClients.createDefault();
        URIBuilder var2 = new URIBuilder(var0);
        HttpGet var3 = new HttpGet(var2.build());
        RequestConfig var4 = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
        var3.setConfig(var4);
        CloseableHttpResponse var5 = var1.execute(var3);
        int var6 = var5.getStatusLine().getStatusCode();
        System.out.println(var6);
        HttpEntity var7 = var5.getEntity();
        String var8 = EntityUtils.toString(var7);
        System.out.println(var8);
        var5.close();
        var1.close();
    }
//
//    public static void main(String[] var0) throws Exception {
//        String var1 = l("createTime");
//        System.out.println(var1);
//        String var2 = "http://localhost:8080/api/template/get";
//        HashMap var3 = new HashMap();
//        var3.put("templateId", "home");
//        b(var2, var3);
//    }

    public static void b(String var0, Map var1) {
        CloseableHttpClient var2 = HttpClientBuilder.create().build();
        HttpPost var3 = new HttpPost(var0);
        var3.setHeader("Content-Type", "application/json;charset=UTF-8");

        try {
            JSONObject var4 = new JSONObject(var1);
            System.out.println(var4);
            String var5 = JSON.toJSONString(var4);
            StringEntity var6 = new StringEntity(var5, "UTF-8");
            var3.setEntity(var6);
            CloseableHttpResponse var7 = var2.execute(var3);
            HttpEntity var8 = var7.getEntity();
            String var9 = EntityUtils.toString(var8, "UTF-8");
            System.out.println(var9);
        } catch (ClientProtocolException var10) {
            var10.printStackTrace();
        } catch (IOException var11) {
            var11.printStackTrace();
        }

    }

    public static String a(ResultSet var0, Set var1) throws SQLException, JSONException {
        JSONArray var2 = new JSONArray();
        ResultSetMetaData var3 = var0.getMetaData();
        int var4 = var3.getColumnCount();

        while(var0.next()) {
            JSONObject var5 = new JSONObject();

            for(int var6 = 1; var6 <= var4; ++var6) {
                String var7 = var3.getColumnLabel(var6);
                if (!var1.contains(var7)) {
                    String var8 = var0.getString(var7);
                    var5.put(k(var7), var8);
                }
            }

            var2.add(var5);
        }

        return var2.toString();
    }

    public static String a(ResultSet var0, String var1) throws SQLException, JSONException {
        if (var0.next()) {
            String var2 = var0.getString(var1);
            return var2;
        } else {
            return "0";
        }
    }

    public static String b(Object var0) {
        try {
            Field[] var1 = var0.getClass().getDeclaredFields();
            StringBuffer var2 = new StringBuffer("");
            Object var3 = null;
            Field[] var4 = var1;
            int var5 = var1.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                Field var7 = var4[var6];
                String var8 = var7.getName();
                if(var8.equals("orderBy")||var8.equals("orderByDesc")) {
                	continue;
                }
                String var9 = var8.substring(0, 1).toUpperCase() + var8.substring(1);
                Method var10 = var0.getClass().getDeclaredMethod("get" + var9, (Class[])null);
                Object var11 = var10.invoke(var0, (Object[])null);
                if (var11 != null && !var11.toString().equals("")) {
                    var2.append(l(var8)).append("='").append(var11).append("' and ");
                }
            }

            return var2.append("end").toString().replace("and end", "");
        } catch (Exception var12) {
            var12.printStackTrace();
            return null;
        }
    }

    public static String c(Object var0) {
        try {
            Field[] var1 = var0.getClass().getDeclaredFields();
            StringBuffer var2 = new StringBuffer("update " + l(var0.getClass().getSimpleName()) + " set ");
            String var3 = null;
            Field[] var4 = var1;
            int var5 = var1.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                Field var7 = var4[var6];
                String var8 = var7.getName();
                String var9 = var7.getName().substring(0, 1).toUpperCase() + var7.getName().substring(1);
                Method var10 = var0.getClass().getDeclaredMethod("get" + var9, (Class[])null);
                if (var8.equals("id")) {
                    var3 = "where id = " + var10.invoke(var0, (Object[])null);
                } else {
                    Object var11 = var10.invoke(var0, (Object[])null);
                    if (var11 != null) {
                        var2.append(l(var8)).append("='").append(var11).append("',");
                    }
                }
            }

            return var2.append(var3).toString().replace(",where", " where");
        } catch (Exception var12) {
            var12.printStackTrace();
            return null;
        }
    }

    public static String d(Object var0) {
        try {
            Field[] var1 = var0.getClass().getDeclaredFields();
            StringBuffer var2 = new StringBuffer("insert into " + l(var0.getClass().getSimpleName()) + "(TPL_FIELDS) values(TPL_VALUES)");
            Object var3 = null;
            StringBuffer var4 = new StringBuffer();
            StringBuffer var5 = new StringBuffer();
            Field[] var6 = var1;
            int var7 = var1.length;

            for(int var8 = 0; var8 < var7; ++var8) {
                Field var9 = var6[var8];
                String var10 = var9.getName();
                var10 = l(var10);
                String var11 = var9.getName().substring(0, 1).toUpperCase() + var9.getName().substring(1);
                Method var12 = var0.getClass().getDeclaredMethod("get" + var11, (Class[])null);
                if (!var10.equals("id")) {
                    Object var13 = var12.invoke(var0, (Object[])null);
                    if (var13 != null) {
                        var4.append(l(var10)).append(",");
                        var5.append("'").append(var13).append("',");
                    }
                }
            }

            return var2.toString().replace("TPL_FIELDS", var4.substring(0, var4.length() - 1)).replace("TPL_VALUES", var5.substring(0, var5.length() - 1));
        } catch (Exception var14) {
            var14.printStackTrace();
            return null;
        }
    }

    public static String e(Object var0) {
        try {
            Field[] var1 = var0.getClass().getDeclaredFields();
            StringBuffer var2 = new StringBuffer("delete from " + l(var0.getClass().getSimpleName()) + " where TPL_ID");
            String var3 = null;
            Field[] var4 = var1;
            int var5 = var1.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                Field var7 = var4[var6];
                String var8 = var7.getName();
                String var9 = var8.substring(0, 1).toUpperCase() + var8.substring(1);
                Method var10 = var0.getClass().getDeclaredMethod("get" + var9, (Class[])null);
                if (var8.equals("id")) {
                    var3 = " id = " + var10.invoke(var0, (Object[])null);
                    break;
                }
            }

            return var2.toString().replace("TPL_ID", var3);
        } catch (Exception var11) {
            var11.printStackTrace();
            return null;
        }
    }

    public static String f(Object var0) {
        try {
            Field[] var1 = var0.getClass().getDeclaredFields();
            StringBuffer var2 = new StringBuffer("select * from " + l(var0.getClass().getSimpleName()) + " where TPL_ID");
            String var3 = null;
            Field[] var4 = var1;
            int var5 = var1.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                Field var7 = var4[var6];
                String var8 = var7.getName();
                String var9 = var8.substring(0, 1).toUpperCase() + var8.substring(1);
                Method var10 = var0.getClass().getDeclaredMethod("get" + var9, (Class[])null);
                if (var8.equals("id")) {
                    var3 = " id = " + var10.invoke(var0, (Object[])null);
                    break;
                }
            }

            return var2.toString().replace("TPL_ID", var3);
        } catch (Exception var11) {
            var11.printStackTrace();
            return null;
        }
    }

    public static String k(String var0) {
        var0 = var0.toLowerCase();
        Matcher var1 = U.matcher(var0);
        StringBuffer var2 = new StringBuffer();

        while(var1.find()) {
            var1.appendReplacement(var2, var1.group(1).toUpperCase());
        }

        var1.appendTail(var2);
        return var2.toString();
    }

    public static String l(String var0) {
        Matcher var1 = V.matcher(var0);
        StringBuffer var2 = new StringBuffer();

        while(var1.find()) {
            var1.appendReplacement(var2, "_" + var1.group(0).toLowerCase());
        }

        var1.appendTail(var2);
        return var2.indexOf("_") == 0 ? var2.substring(1) : var2.toString();
    }

    public static String m(String var0) {
        if (var0 != null && !"".equals(var0)) {
            return Character.isUpperCase(var0.charAt(0)) ? var0 : Character.toUpperCase(var0.charAt(0)) + var0.substring(1);
        } else {
            return var0;
        }
    }

    public static String n(String var0) {
        if (var0 != null && !"".equals(var0)) {
            return Character.isLowerCase(var0.charAt(0)) ? var0 : Character.toLowerCase(var0.charAt(0)) + var0.substring(1);
        } else {
            return var0;
        }
    }

    public static String a(int var0) {
        StringBuffer var1 = new StringBuffer();
        Random var2 = new Random();

        for(int var3 = 0; var3 < var0; ++var3) {
            String var4 = var2.nextInt(2) % 2 == 0 ? "char" : "num";
            if ("char".equalsIgnoreCase(var4)) {
                int var5 = var2.nextInt(2) % 2 == 0 ? 65 : 97;
                var1.append((char)(var2.nextInt(26) + var5));
            } else if ("num".equalsIgnoreCase(var4)) {
                var1.append(var2.nextInt(10));
            }
        }

        return var1.toString();
    }
    
    public static String g(Object paramObject) {
        String str = "";
        try {
          Field[] arrayOfField = paramObject.getClass().getDeclaredFields();
          Object object = null;
          for (Field field : arrayOfField) {
            String str1 = field.getName();
            if (str1.equals("orderBy")) {
              String str2 = str1.substring(0, 1).toUpperCase() + str1.substring(1);
              Method method = paramObject.getClass().getDeclaredMethod("get" + str2, null);
              Object object1 = method.invoke(paramObject, null);
              if (object1 == null || object1.toString().equals(""))
                break; 
              str = " order by " + l(object1.toString());
            } 
            if (str1.equals("orderByDesc")) {
              String str2 = str1.substring(0, 1).toUpperCase() + str1.substring(1);
              Method method = paramObject.getClass().getDeclaredMethod("get" + str2, null);
              Object object1 = method.invoke(paramObject, null);
              if (object1 != null && !object1.toString().equals(""))
                str = " order by " + l(object1.toString()) + " desc"; 
            } 
          } 
        } catch (Exception exception) {
          exception.printStackTrace();
        } 
        return str;
      }
      
      public static String h(Object paramObject) {
        String str = "";
        try {
          Field[] arrayOfField = paramObject.getClass().getSuperclass().getDeclaredFields();
          for (Field field : arrayOfField) {
            String str1 = field.getName();
            if (str1.equals("page")) {
              String str2 = str1.substring(0, 1).toUpperCase() + str1.substring(1);
              Method method = paramObject.getClass().getDeclaredMethod("get" + str2, null);
              Page page = (Page)method.invoke(paramObject, null);
              if (page == null)
                break; 
              str = " limit " + ((page.getCurrentPage().intValue() - 1) * page.getPageSize().intValue()) + "," + page.getPageSize();
              break;
            } 
          } 
        } catch (Exception exception) {
          exception.printStackTrace();
        } 
        return str;
      }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy