package com.basic.security.manager; import android.text.TextUtils; import com.basic.security.model.Identity; import com.basic.security.model.ModelAdapter; import com.basic.security.model.PersonIdentity; import com.basic.security.utils.Constants; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; public class IdentityManager extends BaseManager { public static List findIdentityList() { return findList("select * from identity "); // return findIdentityList1(); } public static List findIdentityList1() { List allIdentityList = findList("select * from identity where " + Identity.name + "!='访客'"); List allIdentityList2 = findList("select * from identity where " + Identity.name + "='访客'"); if (allIdentityList2.size() > 0) { allIdentityList.add(0, allIdentityList2.get(0)); } return allIdentityList; } public static List findIdentityNameListByPersonId(String personId) { List identityNameList = new ArrayList(); List personPersonIdentity = PersonIdentityManager.findPersonIdentityListByPersonId(personId); for (ModelAdapter personIdentity : personPersonIdentity) { String identityId = personIdentity.getString("identity_id"); ModelAdapter identityDocument = findById("identity", identityId); if (identityDocument != null) { String identityName = identityDocument.getString("name"); if (!TextUtils.isEmpty(identityName)) { identityNameList.add(identityName); } } } return identityNameList; } public static ModelAdapter findIdentityById(String id) { return BaseManager.findById("identity", id); } public static ModelAdapter findIdentityByName(String identityName) { ModelAdapter identity = findOne("select * from " + Identity.tableName + " where " + Identity.name + "='" + identityName + "'"); if (identity == null) { identity = new ModelAdapter(); identity.setString(Identity.id, UUID.randomUUID().toString()); identity.setString(Identity.name, identityName); identity.setString(Identity.del_flag, "0"); identity.setString(Constants.TABLE, Identity.tableName); identity.setString(Identity.device_id, DeviceManager.getDeviceId()); save(identity); } return identity; } public static String findIdentityNamesByPersonId(String personId) { List identityList = findList("select b.* from " + PersonIdentity.tableName + " a left join " + Identity.tableName + " b on a." + PersonIdentity.identity_id + "=b." + Identity.id + " where a." + PersonIdentity.person_id + "='" + personId + "' " ); List names = new ArrayList<>(); for (ModelAdapter identity : identityList) { names.add(identity.getString(Identity.name)); } return TextUtils.join(",", names); } public static Map findAllIdentitiesMap() { List identityList = findList("select * from " + Identity.tableName); Map identityMap = new HashMap<>(); for (ModelAdapter identity : identityList) { identityMap.put(identity.getString(Identity.name), identity); } return identityMap; } }