a
554325746@qq.com
2019-12-25 603cb36a5123e46656b06a5deb8d7ac7ff81307f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.basic.security.utils;
 
import android.util.Base64;
 
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class Base64Util {
    public static Map<String, List<String>> tableIgnoreKeys = new HashMap<>();
    public static boolean init = false;
 
    public static void init() {
        if (init) {
            return;
        }
        init = true;
        tableIgnoreKeys.put("person", Arrays.asList(
                "id", "del_flag", "table", "device_id", "company_id", "all_device", "update_time",
                "sign_up_time", "phone", "id_card_number", "checked_time_rule_id",
                "camera_image_feature_path", "camera_image_path", "camera_image_fastdfs_path",
                "id_card_image_path", "auto_init"
        ));
        tableIgnoreKeys.put("base_setting", Arrays.asList(
                "auto_register_rule", "auto_checked_time_rule_id", "indoor_device_id",
                "relation_person", "relation_device", "indoor_device_ip",
                "no_face_delay", "picture_rotation_angle", "id", "auto_mode", "admin_mode",
                "pass_mode", "visitor_mode", "admin_normal_verify", "admin_normal_verify_phone",
                "admin_normal_verify_idcard", "admin_normal_verify_name", "admin_idcard_verify",
                "admin_idcard_verify_phone", "back_to_home", "image_play_interval", "detect_multiple_face"
                , "face_ratio", "face_angle", "image_play_time", "login_expire_long", "auto_mode_verify_phone",
                "auto_normal_verify", "auto_normal_verify_phone", "auto_normal_verify_idcard", "auto_normal_verify_name",
                "auto_idcard_verify", "auto_idcard_verify_phone", "auto_register_identity_id", "device_id", "company_id",
                "table", "del_flag"
        ));
        tableIgnoreKeys.put("business", Arrays.asList(
                "id", "create_time", "only_allow", "only_allow_start", "only_allow_end",
                "chose_from_time_rule", "checked_time_rule_id", "access_table_name",
                "access_identity", "access_name", "not_reached_time_remind", "confirm_pass_identity",
                "confirm_pass_name", "time_ids", "device_id", "company_id", "table", "del_flag"
        ));
        tableIgnoreKeys.put("business_apply_device", Arrays.asList(
                "id", "business_id", "device_id", "table", "del_flag"
        ));
        tableIgnoreKeys.put("business_person", Arrays.asList(
                "id", "person_id", "business_id", "del_flag", "table"
        ));
        tableIgnoreKeys.put("device", Arrays.asList(
                "id", "ip", "device_id", "mask", "open_door_time", "company_id", "del_flag", "table"
        ));
        tableIgnoreKeys.put("identity", Arrays.asList(
                "id", "device_id", "company_id", "del_flag", "table"
        ));
        tableIgnoreKeys.put("person_identity", Arrays.asList(
                "id", "person_id", "identity_id", "del_flag", "device_id", "company_id", "table"
        ));
        tableIgnoreKeys.put("temporary_person", Arrays.asList(
                "ip", "table", "save_time", "camera_image_feature", "camera_image_path"
        ));
        tableIgnoreKeys.put("time", Arrays.asList(
                "id", "week_json", "date_json", "is_use", "del_flag", "table"
        ));
        tableIgnoreKeys.put("visit", Arrays.asList(
                "id", "person_id", "visit_time", "verify_result", "exit_time",
                "target_person_id", "target_org_id", "person_id_number", "person_phone",
                "device_id", "company_id", "del_flag", "table"
        ));
        tableIgnoreKeys.put("org", Arrays.asList());
        List<String> tableList = new ArrayList<>();
        for (String table : tableIgnoreKeys.keySet()) {
            tableList.add(table);
        }
//        BaseManager.syncTableNames = tableList;
    }
 
    public static String encodeToString(String table, String key, String strValue) {
        try {
            if (needConvert(table, key)) {
                strValue = Base64.encodeToString(strValue.getBytes("UTF-8"), Base64.NO_WRAP);
                strValue = "base64_" + strValue;
            }
        } catch (UnsupportedEncodingException e) {
            System1.out.println(e.getMessage());
        }
        return strValue;
    }
 
    private static boolean needConvert(String table, String key) {
        if (1 == 1) {
            return false;
        }
        if (key != null) {
            if (key.startsWith("\"")) {
            }
            if (key.endsWith("\"")) {
                key = key.substring(0, key.length() - 1);
            }
            if (key.startsWith("`")) {
            }
            if (key.endsWith("`")) {
                key = key.substring(0, key.length() - 1);
            }
            List<String> ignoreKeys = tableIgnoreKeys.get(table);
            return ignoreKeys == null || !ignoreKeys.contains(key);
        }
        return false;
    }
 
    public static String decodeToString(String table, String key, String strValue) {
        try {
            if (strValue != null) {
                if (needConvert(table, key) || strValue.startsWith("base64_")) {
                    if (strValue.startsWith("base64_")) {
                        strValue = strValue.substring("base64_".length());
                        strValue = new String(Base64.decode(strValue, Base64.NO_WRAP), "UTF8");
                    }
                }
            }
        } catch (Exception e) {
//            e.printStackTrace();
            System1.out.println("Base64Util.decodeToString execption=" + e.getMessage());
        }
        return strValue;
    }
 
    public static String featureBytes2Base64(byte[] bytes) {
        try {
            if (bytes != null) {
                if (bytes.length == 2560) {
                    //                    System1.out.println("encode feature="+feature);
                    return Base64.encodeToString(bytes, Base64.NO_WRAP);
                } else {
//                    System1.out.println("feature长度不对(encode) " + FrameUtil.getFrames());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
    public static byte[] featureBase642Bytes(String strValue) {
        try {
            if (strValue != null && strValue.length() > 50) {
                byte[] bytes = Base64.decode(strValue, Base64.NO_WRAP);
                if (bytes != null) {
                    if (bytes.length == 2560) {
                        return bytes;
                    } else {
                        System1.out.println("feature长度不对(decode)");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}