//package test;
//
//import bean.Column;
//import bean.DataBase;
//import bean.Schema;
//import com.alibaba.druid.DbType;
//import com.alibaba.druid.sql.SQLUtils;
//import java.lang.reflect.Method;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import util.JdbcUtil;
//import util.SqlUtil;
//import util.StringJoin;
//import util.getdata.DatabaseCache;
//
//public class GPScopeTest {
//   public static void main(String[] args) throws Exception {
//      String content = "{\n      \"ip_port\": \"192.168.2.179:2345\",\n      \"url\": \"jdbc:postgresql://192.168.2.179:2345/gpdb\",\n      \"username\": \"gpadmin\",\n      \"password\": \"gpadmin\",\n      \"dbType\": \"greenplum\",\n      \"isIgnorecase\": \"1\",\n      \"excludeSchema\": []\n    }";
//      JdbcUtil.initData(content);
//
//      try {
//         Thread.sleep(2000L);
//      } catch (InterruptedException e) {
//         e.printStackTrace();
//      }
//
//      Thread.sleep(3000L);
//      GPScopeTest myTest = new GPScopeTest();
//      myTest.testMysql();
//   }
//
//   public void testCache() throws InterruptedException {
//      DataBase dataBase = (DataBase)JdbcUtil.dataBaseList.get(0);
//      DatabaseCache simpleCache = dataBase.simpleCache;
//      Schema ry = simpleCache.getSchema("ry");
//      System.out.println(ry == null ? "" : ry.getName());
//      List<Column> columns = simpleCache.getColumns("ry", "a");
//      System.out.println(columns == null ? 0 : columns.size());
//
//      for(Column column : columns) {
//         System.out.println(column.getDigits());
//      }
//
//   }
//
//   public void testMysql() throws Exception {
//      String sql = "SELECT a.projectid, ifnull(b.scope_num,0) as scope_num, c.sensitive_name, ( SELECT project FROM t_core_data_project a1 WHERE a1.tid = a.projectid LIMIT 1 ) AS projectname    FROM ( SELECT DISTINCT pd.project_id AS projectid FROM t_duty_person p INNER JOIN t_core_project_datasource pd ON p.datasystemid = pd.systemsource_id    INNER JOIN t_base_usergroup ug ON p.duty_id = ug.userid WHERE ug.groupid = '111' ) a LEFT JOIN ( SELECT tcsf.projectid, count(DISTINCT tcsf.scope_id) AS scope_num     FROM T_CORE_SCOPE_FIELD tcsf GROUP BY tcsf.projectid ) b ON a.projectid = b.projectid LEFT JOIN ( SELECT projectid, sensitive_name, open_level     FROM ( SELECT a.projectid, b.sensitive_name AS sensitive_name, b.open_level FROM t_core_field_sensitive a INNER JOIN t_core_sensitive_level b ON a.scope_id = b.tid     GROUP BY a.projectid, b.open_level ORDER BY a.projectid, UPPER(b.open_level)) a WHERE a.open_level = ( SELECT min(UPPER(open_level))    FROM ( SELECT a.projectid, b.sensitive_name AS sensitive_name, b.open_level FROM t_core_field_sensitive a    INNER JOIN t_core_sensitive_level b ON a.scope_id = b.tid GROUP BY a.projectid, b.open_level ORDER BY a.projectid, UPPER(b.open_level)) b    WHERE a.projectid = b.projectid )) c ON a.projectid = c.projectid";
//      sql = "select b.id, count(b.areaId) as areanum from (          SELECT u.TID AS id,a.tid as areaId FROM                  t_core_controlled_asset u LEFT JOIN t_core_controlled_asset_area a ON u.tid = a.assetid          ) b group by b.id";
//      sql = "SELECT 1";
//      sql = "select r.* from t_basae_user r";
//      sql = "select * from people p where p.name = 'sanbao' and age = 18";
//      sql = "select * from AT_TEST  where name in ('杨山瑶')";
//      sql = "select count(*) from (select * from AT_TEST a1 where a1.name = '杨山瑶' ) a  where mobile = '13898984567'";
//      sql = "select * from a ";
//      int max = 100;
//
//      for(int i = 0; i < 1; ++i) {
//         sql = "select `Column1` from a";
//         sql = "delete from a";
//         Map<String, String> params = new HashMap();
//         params.put("sql", sql);
//         params.put("dbType", "mysql");
//         params.put("schema", "ry");
//         params.put("url", "jdbc:mysql://192.168.2.228:3306/ry");
//         params.put("replaceSchema", ".*");
//         params.put("replaceNewTable", "people_bk");
//         params.put("replaceTable", ".*");
//         params.put("replaceColumn", ".*");
//         params.put("expression", "concat(substr(${value},1,1),'**')");
//         params.put("configPath", "D:/masking-mysql.properties");
//         params.put("limit", "3");
//         Map<String, String> map = new HashMap();
//         map.put("ghca31.AT_TEST.name", "替1");
//         map.put("ghca31.AT_TEST2.name", "替2");
//         map.put("ghca31.AT_TEST3.name", "替3");
//         map.put("ghca31.AT_TEST.name", "替4");
//         map.put("ghca31.AT_TEST2.name", "替5");
//         map.put("ghca31.AT_TEST3.name", "替6");
//         map.put("ghca_classify_encrytest.T_CONSOLE_DICTIONARY.value", "替7");
//         System.out.println("...................................................");
//         SqlUtil sqlUtil = new SqlUtil();
//         String sql1 = sqlUtil.desensitization(new HashMap(params));
//         System.out.println(sql1);
//         System.out.println("...................................................");
//         String sql2 = sqlUtil.column_desensitization(new HashMap(params));
//         System.out.println(sql2);
//         System.out.println("...................................................");
//         String sql3 = sqlUtil.table_desensitization(new HashMap(params));
//         System.out.println(sql3);
//         System.out.println("...................................................");
//         String sql4 = sqlUtil.rowVisitControl(new HashMap(params));
//         System.out.println(sql4);
//         System.out.println("...................................................");
//         System.out.println("\n\n[0]********************************************************************************");
//         System.out.println("--------------------- source sql    ------------------------------------------------");
//         System.out.println(sql);
//         System.out.println("---------------------/source sql    ------------------------------------------------");
//         System.out.println("---------------------parse structure------------------------------------------------");
//         Map<String, Object> s2 = sqlUtil.parseSqlStructure(params);
//         System.out.println("\n\n====schemaMap====");
//         Map<String, Object> schemaMap = (Map)s2.get("schemaMap");
//
//         for(Map.Entry<String, Object> item : schemaMap.entrySet()) {
//            System.out.println((String)item.getKey() + "\t" + item.getValue());
//         }
//
//         System.out.println("\n\n====tableMap====");
//         Map<String, Object> tableMap = (Map)s2.get("tableMap");
//
//         for(Map.Entry<String, Object> item : tableMap.entrySet()) {
//            System.out.println((String)item.getKey() + "\t" + item.getValue());
//         }
//
//         System.out.println("\n\n====whereMap====");
//         Map<String, Object> whereMap = (Map)s2.get("whereMap");
//
//         for(Map.Entry<String, Object> item : whereMap.entrySet()) {
//            System.out.println((String)item.getKey() + "\t" + item.getValue());
//         }
//
//         System.out.println("\n\n====whereList====");
//
//         for(Map<String, Object> where : (ArrayList)s2.get("whereList")) {
//            for(Map.Entry<String, Object> item : where.entrySet()) {
//               System.out.println((String)item.getKey() + "\t" + item.getValue());
//            }
//         }
//
//         System.out.println("\n\n====columnList====");
//         ArrayList<Column> columnList = (ArrayList)s2.get("columnList");
//         String[] fields = new String[]{"columnName", "columnAlisa", "fullName", "nowName", "dataType", "schema", "table", "value", "expr"};
//         int[] size = this.max(fields, columnList);
//
//         for(int j = 0; j < fields.length; ++j) {
//            fields[j] = String.format("%" + size[j] + "s", fields[j]);
//         }
//
//         System.out.println(StringJoin.join(fields, "  "));
//
//         for(Column item : columnList) {
//            StringBuilder output = new StringBuilder();
//            this.printColumn(item, output, size);
//            System.out.println(output);
//         }
//
//         System.out.println("\n\n====SQL====");
//         System.out.println(s2.get("sql"));
//         System.out.println("\n\n====/SQL====");
//         System.out.println("---------------------/parse structure------------------------------------------------");
//      }
//
//   }
//
//   private double invoke(String sql) {
//      try {
//         long c = System.nanoTime();
//         SQLUtils.parseStatements(sql, DbType.mysql);
//         long c1 = System.nanoTime();
//         double c2 = (double)(c1 - c) / (double)1000000.0F;
//         return c2;
//      } catch (Exception e) {
//         e.printStackTrace();
//         return (double)0.0F;
//      }
//   }
//
//   private void printColumn(Column col, StringBuilder s, int[] size) {
//      s.append(this.format(col.getColumnName(), size[0])).append("  ").append(this.format(col.getColumnAlisa(), size[1])).append("  ").append(this.format(col.getFullName(), size[2])).append("  ").append(this.format(col.getNowName(), size[3])).append("  ").append(this.format(col.getDataType(), size[4])).append("  ").append(this.format(col.getSchema(), size[5])).append("  ").append(this.format(col.getTable(), size[6])).append("  ").append(this.format(col.getValue(), size[7])).append("  ").append(this.format(col.getExpr(), size[8]));
//   }
//
//   private String format(Object value, int size) {
//      return String.format("%" + size + "s", value);
//   }
//
//   private int[] max(String[] fields, List<Column> columns) {
//      int[] size = new int[fields.length];
//
//      try {
//         for(int i = 0; i < fields.length; ++i) {
//            String name = fields[i];
//            name = (name.charAt(0) + "").toUpperCase() + name.substring(1);
//            String method = "get" + name;
//            Method m = Column.class.getDeclaredMethod(method);
//            int max = name.length();
//            if (columns != null) {
//               for(Column column : columns) {
//                  Object value = m.invoke(column);
//                  if (value != null) {
//                     int s = value.toString().length();
//                     max = max < s ? s : max;
//                  }
//               }
//            }
//
//            size[i] = max;
//         }
//      } catch (Exception e) {
//         e.printStackTrace();
//      }
//
//      return size;
//   }
//}
