| | |
| | | |
| | | import com.basic.security.model.ModelAdapter; |
| | | import com.basic.security.model.Person; |
| | | import com.basic.security.model.PersonA; |
| | | import com.basic.security.model.Sync; |
| | | import com.basic.security.utils.Base64Util; |
| | | import com.basic.security.utils.Constants; |
| | | import com.basic.security.utils.FaceId; |
| | | import com.basic.security.utils.FrameUtil; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.UUID; |
| | | |
| | | //sqlite数据库操作的公共基础类 |
| | | public class BaseManager { |
| | | public static Map<String, List<String>> tableColumnNames = new HashMap<>(); |
| | | public static List<String> syncTableNames = new ArrayList<>(); |
| | | public static Set<String> syncTableNames = new HashSet<>(); |
| | | |
| | | static { |
| | | syncTableNames.addAll(Arrays.asList( |
| | | // "base_setting", |
| | | // "business", |
| | | // "business_apply_device", |
| | | // "business_person", |
| | | // "cluster", |
| | | // "cluster_node", |
| | | // "cluster_setting", |
| | | // "confirm", |
| | | // "device", |
| | | // "guest", |
| | | // "hint_door_access", |
| | | // "hint_recognize_message", |
| | | // "hint_sign_up", |
| | | // "id_card", |
| | | // "identity", |
| | | // "Log", |
| | | // "OfficeDevice", |
| | | "org", |
| | | // "outdoor", |
| | | "person", |
| | | "person_identity", |
| | | // "temporary_person", |
| | | // "time", |
| | | // "user", |
| | | "dbtablepersons", |
| | | "dbTables", |
| | | "visit" |
| | | )); |
| | | } |
| | | |
| | | public static void save(ModelAdapter modelAdapter) { |
| | | String insertSql = ""; |
| | | try { |
| | | if (modelAdapter != null) { |
| | | String table = modelAdapter.getString(Constants.TABLE); |
| | | if (table == null) { |
| | | table = ""; |
| | | } |
| | | PersonCameraImagePathManager.updateCameraImagePathExist(modelAdapter); |
| | | GetInsertOrUpdateSql getInsertOrUpdateSql = new GetInsertOrUpdateSql(modelAdapter).invoke(); |
| | | String table = getInsertOrUpdateSql.getTable(); |
| | | String insertSql = getInsertOrUpdateSql.getInsertSql(); |
| | | if (syncTableNames.contains(table) && !Constants.FALSE.equals(modelAdapter.getString(Sync.needSync))) { |
| | | insertSql = getInsertOrUpdateSql.getInsertSql(); |
| | | if ( |
| | | syncTableNames.contains(table) && |
| | | !Constants.FALSE.equals(modelAdapter.getString(Sync.needSync))) { |
| | | // System1.out.println("BaseManager.save table=" + table + " " + syncTableNames.contains(table) + " " + !Constants.FALSE.equals(modelAdapter.getString(Sync.needSync)) + " " + syncTableNames); |
| | | if (table.equals("person")) { |
| | | if ("1".equals(modelAdapter.getString("all_device"))) { |
| | | ClusterSerfSyncManager.sendData(insertSql); |
| | | if ("1".equals(modelAdapter.getString("all_device")) || 1 == 1) { |
| | | ClusterSerfSyncManager.sendData(RowToSerfManager.buildRowToSerf(modelAdapter, insertSql)); |
| | | PersonAManager.savePersonAFromPerson(modelAdapter); |
| | | } |
| | | } else { |
| | | ClusterSerfSyncManager.sendData(insertSql); |
| | | ClusterSerfSyncManager.sendData(RowToSerfManager.buildRowToSerf(modelAdapter, insertSql)); |
| | | } |
| | | } |
| | | if (Constants.printSql) { |
| | | System.out.println("insertsql=" + insertSql + " " + FrameUtil.getFrames()); |
| | | System1.out.println("insertsql=" + insertSql + " " + FrameUtil.getFrames()); |
| | | } |
| | | DatabaseManager.execSQL(insertSql); |
| | | // if (table.equals("visit")) { |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | System.out.println("BaseManager.save sql=" + insertSql); |
| | | } |
| | | } |
| | | |
| | | public static void deleteWithDelFlag(ModelAdapter modelAdapter) { |
| | | try { |
| | | |
| | | String table = modelAdapter.getString("table"); |
| | | String id = modelAdapter.getString("id"); |
| | | String del_flag = "1"; |
| | | if (syncTableNames.contains(table)) { |
| | | id = Base64Util.encodeToString(table, "id", id); |
| | | del_flag = Base64Util.encodeToString(table, "del_flag", del_flag); |
| | | } |
| | | String sql = "update " + table + " set del_flag='" + del_flag + "' where id='" + id + "'"; |
| | | if (Constants.printSql) { |
| | | System1.out.println("deletesql=" + sql + " " + FrameUtil.getFrames()); |
| | | } |
| | | if ( |
| | | syncTableNames.contains(table) && |
| | | !Constants.FALSE.equals(modelAdapter.getString(Sync.needSync)) |
| | | ) { |
| | | ClusterSerfSyncManager.sendData(RowToSerfManager.buildRowToSerf(modelAdapter, sql)); |
| | | } |
| | | DatabaseManager.execSQL(sql); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public static void delete(ModelAdapter modelAdapter) { // 假删除 |
| | | if (Constants.deletePersonPhysical) { |
| | | deletePhysically(modelAdapter); |
| | | } else { |
| | | try { |
| | | if (modelAdapter != null) { |
| | | if (modelAdapter != null) { |
| | | if (Constants.deletePersonPhysical) { |
| | | deletePhysically(modelAdapter); |
| | | } else { |
| | | try { |
| | | String table = modelAdapter.getString("table"); |
| | | String id = modelAdapter.getString("id"); |
| | | String del_flag = "1"; |
| | |
| | | } |
| | | String sql = "update " + table + " set del_flag='" + del_flag + "' where id='" + id + "'"; |
| | | if (Constants.printSql) { |
| | | System.out.println("deletesql=" + sql + " " + FrameUtil.getFrames()); |
| | | System1.out.println("deletesql=" + sql + " " + FrameUtil.getFrames()); |
| | | } |
| | | if (syncTableNames.contains(table)) { |
| | | ClusterSerfSyncManager.sendData(sql); |
| | | if ( |
| | | syncTableNames.contains(table) && |
| | | !Constants.FALSE.equals(modelAdapter.getString(Sync.needSync)) |
| | | ) { |
| | | ClusterSerfSyncManager.sendData(RowToSerfManager.buildRowToSerf(modelAdapter, sql)); |
| | | } |
| | | DatabaseManager.execSQL(sql); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | |
| | | String id = modelAdapter.getString("id"); |
| | | String sql = "delete from " + table + " where id='" + id + "'"; |
| | | if (Constants.printSql) { |
| | | System.out.println("deletesql=" + sql + " " + FrameUtil.getFrames()); |
| | | System1.out.println("deletesql=" + sql + " " + FrameUtil.getFrames()); |
| | | } |
| | | if (syncTableNames.contains(table)) { |
| | | ClusterSerfSyncManager.sendData(sql); |
| | | if ( |
| | | syncTableNames.contains(table) && |
| | | !Constants.FALSE.equals(modelAdapter.getString(Sync.needSync)) |
| | | ) { |
| | | // System.out.println("BaseManager.deletePhysically sql=" + sql); |
| | | ClusterSerfSyncManager.sendData(RowToSerfManager.buildRowToSerf(modelAdapter, sql)); |
| | | } |
| | | try { |
| | | DatabaseManager.execSQL(sql); |
| | | } catch (SQLException e) { |
| | | System.out.println("sql=" + sql); |
| | | System1.out.println("sql=" + sql); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | |
| | | Cursor cursor = null; |
| | | try { |
| | | if (Constants.printSql) { |
| | | System.out.println("findOne sql=" + sql + " " + FrameUtil.getFrames()); |
| | | System1.out.println("findOne sql=" + sql + " " + FrameUtil.getFrames()); |
| | | } |
| | | cursor = DatabaseManager.getDatabase().rawQuery(sql, null); |
| | | if (cursor.moveToFirst()) { |
| | |
| | | Cursor cursor = null; |
| | | try { |
| | | if (Constants.printSql) { |
| | | System.out.println("sql=" + sql + " " + FrameUtil.getFrames() |
| | | System1.out.println("sql=" + sql + " " + FrameUtil.getFrames() |
| | | ); |
| | | } |
| | | cursor = DatabaseManager.getDatabase(databasePath).rawQuery(sql, null); |
| | |
| | | |
| | | public static void deleteList(List<ModelAdapter> modelAdapterList) { |
| | | for (ModelAdapter modelAdapter : modelAdapterList) { |
| | | FaceId.instance.removeFeatureFromDb(modelAdapter.getString(Person.id)); |
| | | FeatureManager.removeFeature(modelAdapter.getString(Person.id)); |
| | | deletePhysically(modelAdapter); |
| | | } |
| | | } |