| | |
| | | import com.basic.security.model.Person; |
| | | import com.basic.security.model.PersonA; |
| | | import com.basic.security.utils.Base64Util; |
| | | import com.basic.security.utils.BasicIdUtil; |
| | | import com.basic.security.utils.BitmapHolder; |
| | | import com.basic.security.utils.CompareFeatureResult; |
| | | import com.basic.security.utils.Constants; |
| | |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.net.URL; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | import static com.basic.security.model.Sync.needSync; |
| | | |
| | |
| | | static BitmapHolder bitmapHolder = new BitmapHolder(); |
| | | |
| | | public static void savePerson(ModelAdapter person) { |
| | | removePersonFromCache(person); |
| | | save(person); |
| | | uploadToTemporary(person.getId()); |
| | | GuestManager.updateGuestName(person); |
| | | // uploadToTemporary(person.getId()); |
| | | } |
| | | |
| | | public static void uploadToTemporary(String personId) { |
| | |
| | | |
| | | public void onError(Throwable ex, boolean isOnCallback) { |
| | | ex.printStackTrace(); |
| | | System.out.println("httponError"); |
| | | System1.out.println("httponError"); |
| | | } |
| | | |
| | | public void onCancelled(CancelledException cex) { |
| | | System.out.println("httponCancelled"); |
| | | System1.out.println("httponCancelled"); |
| | | } |
| | | |
| | | public void onFinished() { |
| | | } |
| | | }); |
| | | } catch (Exception e) { |
| | | System.out.println("PersonManager.execute " + e.getMessage()); |
| | | System1.out.println("PersonManager.execute " + e.getMessage()); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | FaceId.instance.removeFeatureFromDb(person.getString(Person.id)); |
| | | FeatureManager.removeFeature(person.getString(Person.id)); |
| | | PersonIdentityManager.deletePersonIdentityByPersonId(person.getString(Person.id)); |
| | | delete(person); |
| | | PersonAManager.deletePersonAByPerson(person); |
| | | if (Constants.deletePersonPhysical) { |
| | | deletePhysically(person); |
| | | } else { |
| | | deleteWithDelFlag(person); |
| | | } |
| | | removePersonFromCache(person); |
| | | SocketUtil.rpcCallDeletePerson(person); |
| | | if (Constants.isIndoor) { |
| | | GuestManager.removePersonId(person.getString(Person.id)); |
| | |
| | | return allPersonList; |
| | | } |
| | | |
| | | public static ModelAdapter findPersonById(String personId) { |
| | | ModelAdapter person = findPersonByIdMap.get(personId); |
| | | if (System.currentTimeMillis() - lastFindPersonById < 1000 && person != null) { |
| | | return person; |
| | | } else { |
| | | person = findById("person", personId); |
| | | findPersonByIdMap.put(personId, person); |
| | | lastFindPersonById = System.currentTimeMillis(); |
| | | public static void removePersonFromCache(ModelAdapter person) { |
| | | try { |
| | | String personId = person.getString(Person.id); |
| | | findPersonByIdMap.remove(personId); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return person; |
| | | } |
| | | |
| | | public static ModelAdapter findPersonById(String personId) { |
| | | try { |
| | | ModelAdapter person = findPersonByIdMap.get(personId); |
| | | if (System.currentTimeMillis() - lastFindPersonById < 1000 && person != null) { |
| | | return person; |
| | | } else { |
| | | person = findById("person", personId); |
| | | findPersonByIdMap.put(personId, person); |
| | | lastFindPersonById = System.currentTimeMillis(); |
| | | } |
| | | return person; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | // 获取含有特定身份的所有人员 |
| | |
| | | return personList; |
| | | } |
| | | |
| | | public static boolean isDuplicate(ModelAdapter selectedPerson) { |
| | | try { |
| | | byte[] camera_image_feature = selectedPerson.getBlob("camera_image_feature"); |
| | | return isDuplicate(camera_image_feature); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public static boolean isDuplicate(byte[] camera_image_feature) { |
| | | try { |
| | | if (camera_image_feature != null && camera_image_feature.length > 0) { |
| | | String compareResultStr = FaceId.instance.compareFeatureInDb(camera_image_feature, Constants.minRecognizeScore); |
| | | ModelAdapter person = PersonManager.findPersonById(compareResultStr.split(",", -1)[0]); |
| | | if (person != null) { |
| | | return true; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public static void reFindPerson(CompareFeatureResult compareFeatureResult) { |
| | | try { |
| | |
| | | BaseApplication.getApplication().detectLock.lock(); |
| | | String facePosition = FaceId.instance.facePosition(file.getAbsolutePath()); |
| | | if (facePosition.length() <= 0) { |
| | | System.out.println("SaveTestData.run 没有找到人脸"); |
| | | System1.out.println("SaveTestData.run 没有找到人脸"); |
| | | return null; |
| | | } |
| | | String[] rectFace = facePosition.split(","); |
| | |
| | | byte[] featureData = FaceId.instance.extractFeature(file.getAbsolutePath()); |
| | | BaseApplication.getApplication().detectLock.unlock(); |
| | | if (featureData == null) { |
| | | System.out.println("SaveTestData.run 提取特征失败! 请检查SDK是否初始化"); |
| | | System1.out.println("SaveTestData.run 提取特征失败! 请检查SDK是否初始化"); |
| | | return null; |
| | | } |
| | | String compareResultStr = FaceId.instance.compareFeatureInDb(featureData, Constants.minRecognizeScore); |
| | | String compareResultStr = FeatureManager.compareFeature(featureData, Constants.minRecognizeScore); |
| | | String personId = compareResultStr.split(",", -1)[0]; |
| | | if (!TextUtils.isEmpty(personId)) { |
| | | return findById(Person.tableName, personId); |
| | | } |
| | | ModelAdapter person = new ModelAdapter() |
| | | .setString(Person.id, UUID.randomUUID().toString()) |
| | | .setString(Person.id, BasicIdUtil.getPersonId(featureData)) |
| | | .setString("name", fileName) |
| | | .setString("sign_up_status", "已注册") |
| | | .setString("verify_status", "不需要验证身份证") |
| | |
| | | .setString("company_id", CompanyManager.getCompanyId()) |
| | | .setString(Person.org_id, orgId) |
| | | .setString("table", "person"); |
| | | person.setString(Person.device_id, DeviceManager.getDeviceId()); |
| | | person.setString(Person.company_id, CompanyManager.getCompanyId()); |
| | | person.setBlob("camera_image_feature", featureData); |
| | | person.setBlob("camera_image_path", faceJpgData); |
| | | PersonManager.savePerson(person); |
| | | FaceId.instance.addFeatureToDb(person.getId(), featureData); |
| | | FeatureManager.addFeature(person.getId(), featureData); |
| | | return person; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | person.setString(Person.org_id, ""); |
| | | person.setString(Person.org_ids, ""); |
| | | person.setString(Person.id, personA.getString(PersonA.id)); |
| | | download_camera_image_path(person); |
| | | person.setString(Person.name, personA.getString(PersonA.personName)); |
| | | person.setString(Person.camera_image_feature, personA.getString(PersonA.faceFeature)); |
| | | person.setString(Person.phone, personA.getString(PersonA.phoneNum)); |
| | |
| | | if (person.getString(Person.del_flag).equals("0")) { |
| | | byte[] feature = person.getBlob(Person.camera_image_feature); |
| | | if (feature != null && feature.length > 10) { |
| | | FaceId.instance.addFeatureToDb(person.getId(), feature); |
| | | FeatureManager.addFeature(person.getId(), feature); |
| | | } |
| | | } else { |
| | | FaceId.instance.removeFeatureFromDb(person.getId()); |
| | | FeatureManager.removeFeature(person.getId()); |
| | | } |
| | | savePerson(person); |
| | | } |
| | | |
| | | private void download_camera_image_path(ModelAdapter person) { |
| | | try { |
| | | String personPicUrl = personA.getString(PersonA.personPicUrl); |
| | | if (TextUtils.isEmpty(personPicUrl)) { |
| | | String camera_image_path = ModelAdapter.getAttachmentPath(personA.getId(), Person.camera_image_path, Person.tableName); |
| | | File camera_image_path_file = new File(camera_image_path); |
| | | if (!camera_image_path_file.exists()) { |
| | | org.apache.commons.io.FileUtils.copyURLToFile(new URL(personPicUrl), camera_image_path_file); |
| | | } |
| | | person.setString(Person.camera_image_path, camera_image_path); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public void updatePerson(ModelAdapter dbPerson) { |
| | | dbPerson.setString(Person.id, personA.getString(PersonA.id)); |
| | |
| | | dbPerson.setString(Person.auto_init, "0"); |
| | | dbPerson.setString(Person.table, Person.tableName); |
| | | dbPerson.setString(Person.del_flag, "0"); |
| | | download_camera_image_path(dbPerson); |
| | | PersonCameraImagePathManager.download_camera_image_path(personA.getString(PersonA.personPicUrl), dbPerson); |
| | | if (dbPerson.getString(Person.del_flag).equals("0")) { |
| | | byte[] feature = dbPerson.getBlob(Person.camera_image_feature); |
| | | if (feature != null && feature.length > 10) { |
| | | FaceId.instance.addFeatureToDb(dbPerson.getId(), feature); |
| | | FeatureManager.addFeature(dbPerson.getId(), feature); |
| | | } |
| | | } else { |
| | | FaceId.instance.removeFeatureFromDb(dbPerson.getId()); |
| | | FeatureManager.removeFeature(dbPerson.getId()); |
| | | } |
| | | dbPerson.setString(needSync, Constants.FALSE); |
| | | savePerson(dbPerson); |