Forráskód Böngészése

完成访客签到、访客登记、访客签离功能
首页今日预约、在访、签离数的显示

ifengouy 2 éve
szülő
commit
15701eca11
20 módosított fájl, 310 hozzáadás és 81 törlés
  1. 5 2
      app/src/main/java/com/sunwin/visitorapp/BaseActivity.java
  2. 10 1
      app/src/main/java/com/sunwin/visitorapp/LoginActivity.java
  3. 2 1
      app/src/main/java/com/sunwin/visitorapp/SplashActivity.java
  4. 19 11
      app/src/main/java/com/sunwin/visitorapp/activity/HomeAc.java
  5. 42 14
      app/src/main/java/com/sunwin/visitorapp/activity/VisitSignActivity.java
  6. 20 20
      app/src/main/java/com/sunwin/visitorapp/activity/VisitorRegActivity.java
  7. 29 11
      app/src/main/java/com/sunwin/visitorapp/activity/VisitorRegisterAc.java
  8. 1 1
      app/src/main/java/com/sunwin/visitorapp/adapter/VisitSignAdapter.java
  9. 8 3
      app/src/main/java/com/sunwin/visitorapp/db/DatabaseManager.java
  10. 10 0
      app/src/main/java/com/sunwin/visitorapp/db/UserInfoModel.java
  11. 11 0
      app/src/main/java/com/sunwin/visitorapp/face/DetectResult.java
  12. 81 4
      app/src/main/java/com/sunwin/visitorapp/face/SwFaceLoop.java
  13. 12 3
      app/src/main/java/com/sunwin/visitorapp/fragment/HomeFr.java
  14. 1 0
      app/src/main/java/com/sunwin/visitorapp/fragment/IdcardRegFragment.java
  15. 36 5
      app/src/main/java/com/sunwin/visitorapp/fragment/VisitSignFragment.java
  16. 10 0
      app/src/main/java/com/sunwin/visitorapp/model/OpenDoorByFaceNetResultInfo.java
  17. 3 2
      app/src/main/java/com/sunwin/visitorapp/utils/BitmapUtils.java
  18. 6 2
      app/src/main/java/com/sunwin/visitorapp/utils/Constant.java
  19. 3 1
      app/src/main/java/com/sunwin/visitorapp/view/FaceDetecterView.java
  20. 1 0
      app/src/main/res/layout/fragment_visit_sign.xml

+ 5 - 2
app/src/main/java/com/sunwin/visitorapp/BaseActivity.java

@@ -1,14 +1,14 @@
 package com.sunwin.visitorapp;
 
-import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.os.Bundle;
 
-
 import androidx.appcompat.app.AppCompatActivity;
 
 import com.sunwin.visitorapp.utils.AppManager;
+import com.sunwin.visitorapp.utils.Constant;
+import com.sunwin.visitorapp.utils.SharePrefenceUtils;
 import com.sunwin.visitorapp.view.LoadingDialog;
 
 public class BaseActivity extends AppCompatActivity {
@@ -17,6 +17,8 @@ public class BaseActivity extends AppCompatActivity {
     protected AppCompatActivity mContext;
     protected LoadingDialog loadingDialog;
 
+    protected boolean isLogin;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -24,6 +26,7 @@ public class BaseActivity extends AppCompatActivity {
         TAG = getClass().getSimpleName();
         mContext = this;
         loadingDialog = new LoadingDialog(this, "");
+        isLogin = SharePrefenceUtils.getBoolean(Constant.ISharePrefence.LOGINTAG, false);
     }
 
 

+ 10 - 1
app/src/main/java/com/sunwin/visitorapp/LoginActivity.java

@@ -9,6 +9,7 @@ import android.widget.EditText;
 import com.sunwin.visitorapp.activity.HomeAc;
 import com.sunwin.visitorapp.activity.VisitorRegActivity;
 import com.sunwin.visitorapp.utils.Constant;
+import com.sunwin.visitorapp.utils.SharePrefenceUtils;
 
 public class LoginActivity extends BaseActivity implements View.OnClickListener {
     private EditText mEtUserName;
@@ -28,8 +29,9 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
         mEtPwd = (EditText) findViewById(R.id.et_pwd);
         mBtnLogin = (Button) findViewById(R.id.btn_login);
         findViewById(R.id.btn_login_by_self).setOnClickListener(this);
+        findViewById(R.id.btn_login).setOnClickListener(this);
 
-        findViewById(R.id.btn_login).setOnClickListener(v -> startActivity(new Intent(LoginActivity.this, HomeAc.class)));
+//        findViewById(R.id.btn_login).setOnClickListener(v -> startActivity(new Intent(LoginActivity.this, HomeAc.class)));
 
     }
 
@@ -37,10 +39,17 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
     public void onClick(View view) {
         switch (view.getId()) {
             case R.id.btn_login_by_self:
+                SharePrefenceUtils.putBoolean(Constant.ISharePrefence.LOGINTAG, false);
                 Intent intent = new Intent(this, VisitorRegActivity.class);
                 intent.putExtra(Constant.IIntentValue.ISLOGINUSER, false);
                 startActivity(intent);
                 break;
+            case R.id.btn_login:
+                SharePrefenceUtils.putBoolean(Constant.ISharePrefence.LOGINTAG, true);
+                Intent intent2 = new Intent(this, HomeAc.class);
+                intent2.putExtra(Constant.IIntentValue.ISLOGINUSER, true);
+                startActivity(intent2);
+                break;
         }
     }
 }

+ 2 - 1
app/src/main/java/com/sunwin/visitorapp/SplashActivity.java

@@ -23,6 +23,7 @@ import androidx.core.app.ActivityCompat;
 import com.srp.AuthApi.AuthApi;
 import com.srp.AuthApi.AuthApplyResponse;
 import com.srp.AuthApi.ErrorCodeConfig;
+import com.sunwin.visitorapp.activity.HomeAc;
 import com.sunwin.visitorapp.face.FRAbsLoopFactory;
 import com.sunwin.visitorapp.utils.AppManager;
 import com.sunwin.visitorapp.utils.Constant;
@@ -217,7 +218,7 @@ public class SplashActivity extends AppCompatActivity {
     }
 
     private void gotoMain() {
-        Intent intent = new Intent(this, MainActivity.class);
+        Intent intent = new Intent(this, HomeAc.class);
         startActivity(intent);
         finish();
     }

+ 19 - 11
app/src/main/java/com/sunwin/visitorapp/activity/HomeAc.java

@@ -4,12 +4,14 @@ import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 
+import androidx.fragment.app.Fragment;
 import androidx.fragment.app.FragmentManager;
 import androidx.fragment.app.FragmentTransaction;
 
 import com.sunwin.visitorapp.BaseActivity;
 import com.sunwin.visitorapp.R;
 import com.sunwin.visitorapp.fragment.HomeFr;
+import com.sunwin.visitorapp.fragment.VisitSignFragment;
 import com.sunwin.visitorapp.utils.Constant;
 
 public class HomeAc extends BaseActivity implements View.OnClickListener {
@@ -30,13 +32,13 @@ public class HomeAc extends BaseActivity implements View.OnClickListener {
         fragmentTransaction.commit();
         fragmentManager.executePendingTransactions();
 
+        findViewById(R.id.MenuItemRecord).setOnClickListener(this);
+        findViewById(R.id.MenuItemSign).setOnClickListener(this);
         findViewById(R.id.MenuItemRegister).setOnClickListener(this);
+        findViewById(R.id.MenuItemLeave).setOnClickListener(this);
+        findViewById(R.id.MenuItemCheck).setOnClickListener(this);
+
 
-        findViewById(R.id.MenuItemRegister).setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-            }
-        });
 
 
     }
@@ -46,17 +48,25 @@ public class HomeAc extends BaseActivity implements View.OnClickListener {
         super.onResume();
 
     }
+    @Override
+    public void onBackPressed() {
+        moveTaskToBack(true);
+    }
+
+    private void replaceFragment(Fragment fragment) {
+        getSupportFragmentManager().beginTransaction().replace(R.id.FragmentView,
+                fragment).commitAllowingStateLoss();
+    }
 
     @Override
     public void onClick(View view) {
         Intent intent = null;
         switch (view.getId()) {
             case R.id.MenuItemRecord://记录
+                replaceFragment(new HomeFr());
                 break;
             case R.id.MenuItemSign://签到
-                intent = new Intent(this, VisitSignActivity.class);
-                intent.putExtra(Constant.IIntentValue.VISIT_TYPE, 1);
-                startActivity(intent);
+                replaceFragment(VisitSignFragment.newInstance(1));
                 break;
             case R.id.MenuItemRegister://登记
                 intent = new Intent(this, VisitorRegActivity.class);
@@ -64,9 +74,7 @@ public class HomeAc extends BaseActivity implements View.OnClickListener {
                 startActivity(intent);
                 break;
             case R.id.MenuItemLeave://签离
-                intent = new Intent(this, VisitSignActivity.class);
-                intent.putExtra(Constant.IIntentValue.VISIT_TYPE, 2);
-                startActivity(intent);
+                replaceFragment(VisitSignFragment.newInstance(2));
                 break;
             case R.id.MenuItemCheck://核验
                 break;

+ 42 - 14
app/src/main/java/com/sunwin/visitorapp/activity/VisitSignActivity.java

@@ -18,6 +18,7 @@ import com.sunwin.visitorapp.model.OpenDoorByFaceNetResultInfo;
 import com.sunwin.visitorapp.service.PullDataService;
 import com.sunwin.visitorapp.utils.Constant;
 import com.sunwin.visitorapp.utils.LogUtil;
+import com.sunwin.visitorapp.utils.ToastUtils;
 import com.sunwin.visitorapp.view.FaceDetecterView;
 
 import java.util.List;
@@ -31,6 +32,7 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
     private FaceDetecterView mFaceDetecterView;
 
     private int visitSignType;
+    private int visitType;
     private IDCardReaderUtil idCardReaderUtil;
 
     @Override
@@ -42,8 +44,19 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
         PullDataService.enqueueWork(this, new Intent());
     }
 
+    @Override
+    public void onPause() {
+        super.onPause();
+        LogUtil.e(TAG, "=======onPause = ");
+        if (idCardReaderUtil != null) {
+            idCardReaderUtil.stopRead();
+        }
+        mFaceDetecterView.onDestroy();
+    }
+
     private void initialData() {
         visitSignType = getIntent().getIntExtra(Constant.IIntentValue.VISIT_SIGN_TYPE, 1);
+        visitType = getIntent().getIntExtra(Constant.IIntentValue.VISIT_TYPE, 1);
     }
 
     private void initView() {
@@ -73,12 +86,7 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
 
     private void updataUserInfoByIdNum(String idNum) {
         List<UserInfoModel> userInfoModels = DatabaseManager.getInstance().query(UserInfoModel.class, "idNum", idNum);
-        if (userInfoModels.size() > 0) {
-            UserInfoModel infoModel = userInfoModels.get(0);
-            infoModel.setState(2);
-            int update = DatabaseManager.getInstance().update(infoModel);
-            LogUtil.e(TAG, "update = " + update);
-        }
+        updateUserInfo(userInfoModels);
     }
 
     /**
@@ -91,17 +99,12 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
 
     @Override
     public void detectedUser(OpenDoorByFaceNetResultInfo openDoorByFaceNetResultInfo) {
+        LogUtil.e(TAG, "-------------detectedUser--------------");
         BaseApplication.getSystemTTS().playText("识别成功");
         String person_code = openDoorByFaceNetResultInfo.getPerson_code();
-        List<UserInfoModel> userInfoModels = DatabaseManager.getInstance().query(UserInfoModel.class, "personCode", person_code);
-        if (userInfoModels.size() > 0) {
-            UserInfoModel infoModel = userInfoModels.get(0);
-            infoModel.setState(2);
-            int update = DatabaseManager.getInstance().update(infoModel);
-            LogUtil.e(TAG, "update = " + update);
-        } else {
+        List<UserInfoModel> userInfoModels = DatabaseManager.getInstance().query(UserInfoModel.class, "personId", person_code);
 
-        }
+        updateUserInfo(userInfoModels);
     }
 
     @Override
@@ -113,4 +116,29 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
     public void takePic(CameraPreviewData data) {
 
     }
+
+    /**
+     * 更改用户签到/签离状态
+     */
+    private void updateUserInfo(List<UserInfoModel> userInfoModels) {
+        if (userInfoModels.size() > 0) {
+            UserInfoModel infoModel = userInfoModels.get(0);
+            infoModel.setState(visitType == 1 ? 2 : 3);
+            long update = DatabaseManager.getInstance().update(infoModel);
+            LogUtil.e(TAG, "update = " + update);
+            runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    finish();
+                }
+            });
+        } else {
+            runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    ToastUtils.showToast("用户不存在!");
+                }
+            });
+        }
+    }
 }

+ 20 - 20
app/src/main/java/com/sunwin/visitorapp/activity/VisitorRegActivity.java

@@ -27,7 +27,7 @@ import java.util.List;
 /**
  * 访客登记页面
  */
-public class VisitorRegActivity extends BaseActivity implements View.OnClickListener, AdapterView.OnItemClickListener, RegTypeFragment.Listener {
+public class VisitorRegActivity extends BaseActivity implements View.OnClickListener, RegTypeFragment.Listener {
 
     private TextView mTvHeadTitle;
     //    private MyGridView mGridview;
@@ -95,25 +95,25 @@ public class VisitorRegActivity extends BaseActivity implements View.OnClickList
         switch (view.getId()) {
         }
     }
-
-    @Override
-    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
-        if (adapterView.getId() == R.id.gridview) {
-            switch (i) {
-                case 0:
-                    replaceFragment(new IdcardRegFragment());
-                    break;
-                case 1:
-                    startActivity(new Intent(this, NoCardRegActivity.class));
-                    break;
-                case 2:
-                    ToastUtils.showToast("开发中...");
-                    break;
-            }
-        } else {
-
-        }
-    }
+//
+//    @Override
+//    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
+//        if (adapterView.getId() == R.id.gridview) {
+//            switch (i) {
+//                case 0:
+//                    replaceFragment(new IdcardRegFragment());
+//                    break;
+//                case 1:
+//                    startActivity(new Intent(this, NoCardRegActivity.class));
+//                    break;
+//                case 2:
+//                    ToastUtils.showToast("开发中...");
+//                    break;
+//            }
+//        } else {
+//
+//        }
+//    }
 
     private void replaceFragment(Fragment fragment) {
         getSupportFragmentManager().beginTransaction().replace(R.id.fl_content,

+ 29 - 11
app/src/main/java/com/sunwin/visitorapp/activity/VisitorRegisterAc.java

@@ -21,8 +21,10 @@ import com.sunwin.visitorapp.adapter.DepartmentAdapter;
 import com.sunwin.visitorapp.adapter.NetInfoAdapter;
 import com.sunwin.visitorapp.db.DatabaseManager;
 import com.sunwin.visitorapp.db.UserInfoModel;
+import com.sunwin.visitorapp.face.SwFaceLoop;
 import com.sunwin.visitorapp.model.DepartmentResult;
 import com.sunwin.visitorapp.model.NetInfo;
+import com.sunwin.visitorapp.model.OpenDoorByFaceNetResultInfo;
 import com.sunwin.visitorapp.net.ApiService;
 import com.sunwin.visitorapp.net.BaseRsult;
 import com.sunwin.visitorapp.net.CommonRequest;
@@ -64,12 +66,13 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
     private EditText mEditByVisitPeople;
     private Spinner mEditByVisitDepartment;
     private TextView mTextButtonSure;
+    private Spinner sp_net;
     private TimePickerDialog timePickerDialog;
     private long tenYears = 10L * 365 * 1000 * 60 * 60 * 24L;
     private int dateLabel;
     private List<DepartmentResult> mDepartmentList;
     private List<NetInfo> mNetInfoList;
-    private Spinner sp_net;
+    private OpenDoorByFaceNetResultInfo userInfo;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -77,9 +80,8 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
         setContentView(R.layout.ac_visitor_register);
         mDepartmentList = DatabaseManager.getInstance().getQueryAll(DepartmentResult.class);
         mNetInfoList = DatabaseManager.getInstance().getQueryAll(NetInfo.class);
-
-
         currentFacePath = getIntent().getStringExtra(Constant.IIntentValue.CURRENTFACEPATH);
+        userInfo = (OpenDoorByFaceNetResultInfo) getIntent().getSerializableExtra(Constant.IIntentValue.RECOGNIZE_INFO);
         UINav uiNav = findViewById(R.id.UINav);
         uiNav.setData(this, "访客登记");
         initView();
@@ -131,8 +133,8 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
         mComeReason = findViewById(R.id.comeReason);
         mEditCompany = (EditText) findViewById(R.id.EditCompany);
         mEditCarPlate = (EditText) findViewById(R.id.EditCarPlate);
-        mEditVisitTimeBegin =  findViewById(R.id.EditVisitTimeBegin);
-        mEditVisitTimeEnd =  findViewById(R.id.EditVisitTimeEnd);
+        mEditVisitTimeBegin = findViewById(R.id.EditVisitTimeBegin);
+        mEditVisitTimeEnd = findViewById(R.id.EditVisitTimeEnd);
         mEditVisitNumber = (EditText) findViewById(R.id.EditVisitNumber);
         mEditVisitPeopleCount = (EditText) findViewById(R.id.EditVisitPeopleCount);
         mEditICCode = (EditText) findViewById(R.id.EditICCode);
@@ -144,8 +146,16 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
         mEditVisitTimeBegin.setOnClickListener(this);
         mEditVisitTimeEnd.setOnClickListener(this);
 
-        showHead(currentFacePath, mImageVisitorPhoto);
         sp_net = findViewById(R.id.sp_net);
+        initViewInfo();
+
+    }
+
+    private void initViewInfo() {
+        //
+        showHead(currentFacePath, mImageVisitorPhoto);
+        mTextVisitorIdCode.setText(userInfo.getIdNum());
+        mTextVisitorName.setText(userInfo.getPerson_name());
     }
 
     private void showHead(String path, ImageView iv_head) {
@@ -189,7 +199,6 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
         String comeReason = mComeReason.getText().toString().trim();
         String company = mEditCompany.getText().toString().trim();
 
-        idNum = "330101199011112580";
         UserInfoModel infoModel = new UserInfoModel();
         infoModel.setPhone(phone);
         infoModel.setVisitorLpCode(carPlate);
@@ -197,10 +206,14 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
         infoModel.setLostDate(endTime);
         infoModel.setCardNo(cardNum);
         infoModel.setIdNum(idNum);
-        infoModel.setStatus(-2);
+        if (isLogin) {
+            infoModel.setStatus(0);
+        } else {
+            infoModel.setStatus(-2);
+        }
         infoModel.setType(2);
         infoModel.setPersonName(name);
-        infoModel.setDeptId(deptNo+"");
+        infoModel.setDeptId(deptNo + "");
         infoModel.setCategoryId(categoryId);
 
 
@@ -220,8 +233,13 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
                     int code = response.body().getCode();
                     LogUtil.e(TAG, "--code--" + code);
                     if (code == 0) {
-                        String result = response.body().getResult();
-                        addFace(currentFacePath, result);
+                        String personId = response.body().getResult();
+                        String faceToken = SwFaceLoop.getInstance().addFace(currentFacePath);
+
+                        infoModel.setInsetTime(TimeUtils.stampToDate(System.currentTimeMillis()));
+                        infoModel.setFaceToken(faceToken);
+                        infoModel.setPersonId(personId);
+                        addFace(currentFacePath, personId);
                         //存入数据库
                         long insert = DatabaseManager.getInstance().insert(infoModel);
                         LogUtil.e(TAG, "存入用户" + insert);

+ 1 - 1
app/src/main/java/com/sunwin/visitorapp/adapter/VisitSignAdapter.java

@@ -43,7 +43,7 @@ public class VisitSignAdapter extends BaseAdapter {
     public View getView(int position, View convertView, ViewGroup parent) {
         ViewHolder holder = null;
         if (convertView == null) {
-            convertView = inflater.inflate(R.layout.adapter_card, parent, false);
+            convertView = inflater.inflate(R.layout.adapter_visit_sign, parent, false);
             holder = new ViewHolder(convertView);
             convertView.setTag(holder);
         } else {

+ 8 - 3
app/src/main/java/com/sunwin/visitorapp/db/DatabaseManager.java

@@ -26,7 +26,7 @@ public class DatabaseManager {
      *
      * @param t
      */
-    public  <T> long insert(T t) {
+    public <T> long insert(T t) {
         return liteOrm.save(t);
     }
 
@@ -93,8 +93,8 @@ public class DatabaseManager {
      * @param t
      * @param <T>
      */
-    public <T> void delete(T t) {
-        liteOrm.delete(t);
+    public <T> int delete(T t) {
+      return   liteOrm.delete(t);
     }
 
     /**
@@ -139,4 +139,9 @@ public class DatabaseManager {
         return liteOrm.query(new QueryBuilder<T>(cla)
                 .whereEquals(key, value));
     }
+
+    public <T> List<T> queryUnion(Class<T> cla, String key, String value, String key2, String value2) {
+        return liteOrm.query(new QueryBuilder<T>(cla).whereEquals(key, value).whereAppendAnd().whereEquals(key2, value2));
+
+    }
 }

+ 10 - 0
app/src/main/java/com/sunwin/visitorapp/db/UserInfoModel.java

@@ -8,6 +8,16 @@ import com.litesuits.orm.db.enums.AssignType;
 public class UserInfoModel {
     @PrimaryKey(AssignType.BY_MYSELF)
     private String personId;
+
+    public String getFaceToken() {
+        return faceToken;
+    }
+
+    public void setFaceToken(String faceToken) {
+        this.faceToken = faceToken;
+    }
+
+    private String faceToken;
     private String openid;// 绑定微信公众号的openid
     private String proOpenid;// 绑定微信小程序的openid
 

+ 11 - 0
app/src/main/java/com/sunwin/visitorapp/face/DetectResult.java

@@ -1,9 +1,20 @@
 package com.sunwin.visitorapp.face;
 
+import mcv.facepass.types.FacePassTrackOptions;
+
 public class DetectResult {
     byte[] detectResult;
     CameraPreviewData cameraPreviewData;
 
+    public FacePassTrackOptions[] getTrackOpt() {
+        return trackOpt;
+    }
+
+    public void setTrackOpt(FacePassTrackOptions[] trackOpt) {
+        this.trackOpt = trackOpt;
+    }
+
+    FacePassTrackOptions[] trackOpt;
     public byte[] getDetectResult() {
         return detectResult;
     }

+ 81 - 4
app/src/main/java/com/sunwin/visitorapp/face/SwFaceLoop.java

@@ -11,6 +11,8 @@ import android.os.Environment;
 import com.guo.android_extend.java.ExtByteArrayOutputStream;
 import com.nostra13.universalimageloader.core.ImageLoader;
 import com.sunwin.visitorapp.BaseApplication;
+import com.sunwin.visitorapp.db.DatabaseManager;
+import com.sunwin.visitorapp.db.UserInfoModel;
 import com.sunwin.visitorapp.model.FacesModel;
 import com.sunwin.visitorapp.model.OpenDoorByFaceNetResultInfo;
 import com.sunwin.visitorapp.model.UserModel;
@@ -32,6 +34,7 @@ import java.util.concurrent.ArrayBlockingQueue;
 
 import mcv.facepass.FacePassException;
 import mcv.facepass.FacePassHandler;
+import mcv.facepass.types.FacePassAddFaceResult;
 import mcv.facepass.types.FacePassCompareResult;
 import mcv.facepass.types.FacePassConfig;
 import mcv.facepass.types.FacePassDetectionResult;
@@ -40,6 +43,8 @@ import mcv.facepass.types.FacePassImageType;
 import mcv.facepass.types.FacePassModel;
 import mcv.facepass.types.FacePassPose;
 import mcv.facepass.types.FacePassRCAttribute;
+import mcv.facepass.types.FacePassRecognitionResult;
+import mcv.facepass.types.FacePassRecognitionState;
 import mcv.facepass.types.FacePassTrackOptions;
 
 
@@ -369,6 +374,7 @@ public class SwFaceLoop extends FRAbsLoop {
                 DetectResult detectResult = new DetectResult();
                 detectResult.setCameraPreviewData(cameraPreviewData);
                 detectResult.setDetectResult(detectionResult.message);
+                detectResult.setTrackOpt(trackOpts);
                 mDetectResultQueue.offer(detectResult);
             } else {
 //                Log.e(DEBUG_TAG, "null");
@@ -422,7 +428,6 @@ public class SwFaceLoop extends FRAbsLoop {
                     isRecognized = true;
                     LogUtil.d(DEBUG_TAG, "take");
                     DetectResult detectResult = mDetectResultQueue.take();
-                    byte[] detectionResult = detectResult.getDetectResult();
 
                     if (isLocalGroupExist) {
 
@@ -430,7 +435,7 @@ public class SwFaceLoop extends FRAbsLoop {
                             idCardRecognite(detectResult);
 
                         } else {
-//                            userRecognite(detectResult, detectionResult);
+                            userRecognite(detectResult);
                         }
                     } else {
                         isLocalGroupExist = mFacePassHandler.createLocalGroup(group_name);
@@ -450,6 +455,57 @@ public class SwFaceLoop extends FRAbsLoop {
         }
     }
 
+    private void userRecognite(DetectResult detectResult) {
+        try {
+            FacePassRecognitionResult[][] recognizeArray = mFacePassHandler.recognize(group_name, detectResult.getDetectResult(), 1, detectResult.getTrackOpt());
+            if (recognizeArray != null && recognizeArray.length > 0) {
+                for (FacePassRecognitionResult[] recognizeResult : recognizeArray) {
+                    for (FacePassRecognitionResult result : recognizeResult) {
+                        String faceToken = new String(result.faceToken);
+                        LogUtil.e(TAG, "userRecognite():-------------------faceToken=" + faceToken);
+                        if (FacePassRecognitionState.RECOGNITION_PASS == result.recognitionState ||
+                                FacePassRecognitionState.RECOGNITION_RETRY_EXPIRED == result.recognitionState) {
+                            //根据facetoken查询对应的用户
+                            List<UserInfoModel> userInfoModels = DatabaseManager.getInstance().query(UserInfoModel.class, "faceToken", faceToken);
+                            if (userInfoModels.size() > 0) {
+                                UserInfoModel infoModel = userInfoModels.get(0);
+                                OpenDoorByFaceNetResultInfo openDoorByFaceNetResultInfo = new OpenDoorByFaceNetResultInfo();
+                                openDoorByFaceNetResultInfo.setCode(0);
+                                openDoorByFaceNetResultInfo.setSimilarity(result.detail.searchScore);
+                                openDoorByFaceNetResultInfo.setPerson_code(infoModel.getPersonId());
+                                openDoorByFaceNetResultInfo.setIdNum(infoModel.getIdNum());
+                                openDoorByFaceNetResultInfo.setPerson_name(infoModel.getPersonName());
+                                EventBus.getDefault().post(new DescEvent().setDesc(DescEvent.DESC_FR_SUCC).setOpenDoorByFaceNetResultInfo(openDoorByFaceNetResultInfo));
+
+                            } else {
+                                //未匹配到用户
+                                recognizeNoUser();
+                            }
+
+                        } else {
+                            recognizeFail();
+
+                        }
+                    }
+                }
+            } else {
+                recognizeFail();
+            }
+
+        } catch (FacePassException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    private void recognizeNoUser() {
+        LogUtil.e(TAG, "---------recognizeNoUser---------");
+    }
+
+    private void recognizeFail() {
+        LogUtil.e(TAG, "---------recognizeFail---------");
+    }
+
     private void idCardRecognite(DetectResult detectResult) {
 
         OpenDoorByFaceNetResultInfo openDoorByFaceNetResultInfo = new OpenDoorByFaceNetResultInfo();
@@ -490,7 +546,7 @@ public class SwFaceLoop extends FRAbsLoop {
                     openDoorByFaceNetResultInfo.setCode(0);
                     openDoorByFaceNetResultInfo.setSimilarity(facePassCompareResult1.score);
                     openDoorByFaceNetResultInfo.setCurrentFace(currentFacePath);
-                    openDoorByFaceNetResultInfo.setPerson_code(idCardInfo.getId());
+                    openDoorByFaceNetResultInfo.setIdNum(idCardInfo.getId());
                     openDoorByFaceNetResultInfo.setPerson_name(idCardInfo.getName());
                     ArrayList<FacesModel> arrayList = new ArrayList<>();
                     FacesModel facesModel = new FacesModel();
@@ -501,7 +557,7 @@ public class SwFaceLoop extends FRAbsLoop {
                     recognizeTime = 0;
                     LogUtil.e("step", "6");
                 } else {
-                    LogUtil.e(TAG, "人证识别时间:"+recognizeTime);
+                    LogUtil.e(TAG, "人证识别时间:" + recognizeTime);
                     recognizeTime++;
                     if (recognizeTime == Constant.COMPARSION_FREQUENCY) {
                         EventBus.getDefault().post(new DescEvent().setDesc(DescEvent.DESC_FR_NO_BODY));
@@ -513,4 +569,25 @@ public class SwFaceLoop extends FRAbsLoop {
             }
         }
     }
+
+
+    public String addFace(String currentFacePath) {
+        if (mFacePassHandler == null) {
+            return "";
+        }
+        Bitmap bitmap = BitmapFactory.decodeFile(currentFacePath);
+        try {
+            FacePassAddFaceResult result = mFacePassHandler.addFace(bitmap);
+            if (result != null) {
+                if (result.result == 0) {
+                    boolean b = mFacePassHandler.bindGroup(group_name, result.faceToken);
+                    LogUtil.e(TAG, "bindGroup: " + currentFacePath + ":" + b);
+                    return new String(result.faceToken);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
 }

+ 12 - 3
app/src/main/java/com/sunwin/visitorapp/fragment/HomeFr.java

@@ -14,6 +14,7 @@ import com.sunwin.visitorapp.BaseFragment;
 import com.sunwin.visitorapp.R;
 import com.sunwin.visitorapp.db.DatabaseManager;
 import com.sunwin.visitorapp.db.UserInfoModel;
+import com.sunwin.visitorapp.utils.TimeUtils;
 
 import org.jetbrains.annotations.NotNull;
 
@@ -46,9 +47,17 @@ public class HomeFr extends BaseFragment {
     }
 
     private void initData() {
-        List<UserInfoModel> userInfoModels = DatabaseManager.getInstance().getQueryAll(UserInfoModel.class);
-        if (userInfoModels != null & userInfoModels.size() > 0) {
-
+        List<UserInfoModel> userInfoModels = DatabaseManager.getInstance().query(UserInfoModel.class, "insetTime", TimeUtils.stampToDate(System.currentTimeMillis()));
+        if (userInfoModels != null) {
+            mTvTodayReg.setText(userInfoModels.size() + "");
+        }
+        List<UserInfoModel> onVisitModels = DatabaseManager.getInstance().query(UserInfoModel.class, "state", 2 + "");
+        if (onVisitModels != null) {
+            mTvOnVisit.setText(onVisitModels.size() + "");
+        }
+        List<UserInfoModel> leaveModels = DatabaseManager.getInstance().query(UserInfoModel.class, "state", 3 + "");
+        if (leaveModels != null) {
+            mTvLeave.setText(leaveModels.size() + "");
         }
     }
 

+ 1 - 0
app/src/main/java/com/sunwin/visitorapp/fragment/IdcardRegFragment.java

@@ -100,6 +100,7 @@ public class IdcardRegFragment extends BaseFragment implements IdCardReadCallbac
         BaseApplication.getSystemTTS().playText("识别成功");
         Intent intent = new Intent(mContext, VisitorRegisterAc.class);
         intent.putExtra(Constant.IIntentValue.CURRENTFACEPATH,info.getCurrentFace());
+        intent.putExtra(Constant.IIntentValue.RECOGNIZE_INFO,info);
         startActivity(intent);
     }
 

+ 36 - 5
app/src/main/java/com/sunwin/visitorapp/fragment/VisitSignFragment.java

@@ -1,5 +1,6 @@
 package com.sunwin.visitorapp.fragment;
 
+import android.content.Intent;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -11,7 +12,10 @@ import androidx.annotation.Nullable;
 
 import com.sunwin.visitorapp.BaseFragment;
 import com.sunwin.visitorapp.R;
+import com.sunwin.visitorapp.activity.VisitSignActivity;
 import com.sunwin.visitorapp.adapter.VisitSignAdapter;
+import com.sunwin.visitorapp.utils.Constant;
+import com.sunwin.visitorapp.utils.ToastUtils;
 import com.sunwin.visitorapp.view.MyGridView;
 
 import org.jetbrains.annotations.NotNull;
@@ -23,6 +27,16 @@ public class VisitSignFragment extends BaseFragment implements AdapterView.OnIte
     private ArrayList<String> itemList;
     private ArrayList<Integer> iconList;
 
+    public static VisitSignFragment newInstance(int visitType) {
+        VisitSignFragment fragment = new VisitSignFragment();
+
+        Bundle bundle = new Bundle();
+        bundle.putInt(Constant.IIntentValue.VISIT_TYPE, visitType);
+        fragment.setArguments(bundle);
+
+        return fragment;
+    }
+
     @Nullable
     @Override
     public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
@@ -35,12 +49,16 @@ public class VisitSignFragment extends BaseFragment implements AdapterView.OnIte
     @Override
     public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
-        initView(view);
         initData();
+        initView(view);
     }
 
 
+    int visitType;
+
     private void initData() {
+        Bundle arguments = getArguments();
+        visitType = arguments.getInt(Constant.IIntentValue.VISIT_TYPE);
         itemList = new ArrayList<>();
         iconList = new ArrayList<>();
         itemList.add("身份证");
@@ -49,14 +67,15 @@ public class VisitSignFragment extends BaseFragment implements AdapterView.OnIte
         iconList.add(R.mipmap.visit_sign_idcard);
         iconList.add(R.mipmap.visit_sign_face);
         iconList.add(R.mipmap.visit_sign_qrcode);
-       /* if (isLoginUser) {
-            itemList.add("驾驶证");
-            iconList.add(R.mipmap.visitor_reg_default);
-        }*/
+        if (visitType == 2) {
+            itemList.add("IC卡");
+            iconList.add(R.mipmap.visit_sign_iccard);
+        }
     }
 
     private void initView(@NotNull View view) {
         mGridview = view.findViewById(R.id.gridview);
+        mGridview.setNumColumns(visitType == 2 ? 4 : 3);
         VisitSignAdapter mAdapter = new VisitSignAdapter(itemList, iconList);
         mGridview.setAdapter(mAdapter);
         mGridview.setOnItemClickListener(this);
@@ -64,13 +83,25 @@ public class VisitSignFragment extends BaseFragment implements AdapterView.OnIte
 
     @Override
     public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
+
         switch (i) {
             case 0:
+                startVisitSign(visitType, 1);
                 break;
             case 1:
+                startVisitSign(visitType, 2);
                 break;
             case 2:
+            case 3:
+                ToastUtils.showToast("开发中...");
                 break;
         }
     }
+
+    private void startVisitSign(int visitType, int visitSignType) {
+        Intent intent = new Intent(mContext, VisitSignActivity.class);
+        intent.putExtra(Constant.IIntentValue.VISIT_TYPE, visitType);
+        intent.putExtra(Constant.IIntentValue.VISIT_SIGN_TYPE, visitSignType);
+        startActivity(intent);
+    }
 }

+ 10 - 0
app/src/main/java/com/sunwin/visitorapp/model/OpenDoorByFaceNetResultInfo.java

@@ -8,6 +8,16 @@ public class OpenDoorByFaceNetResultInfo extends NetResultInfo{
     private String message = "";
     private String person_name = "";
     private String person_code = "";
+
+    public String getIdNum() {
+        return idNum;
+    }
+
+    public void setIdNum(String idNum) {
+        this.idNum = idNum;
+    }
+
+    private String idNum = "";
     private String person_id_card = "";
     private String currentFace ="";
     private double similarity;

+ 3 - 2
app/src/main/java/com/sunwin/visitorapp/utils/BitmapUtils.java

@@ -1576,7 +1576,8 @@ public class BitmapUtils {
         }
 
         bitmap = BitmapUtils.scaleBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight());
-        File file = new File(dirPath + fileName + ".jpg");
+        String filePath = dirPath + fileName + ".jpg";
+        File file = new File(filePath);
         FileOutputStream out = null;
         try {
             out = new FileOutputStream(file);
@@ -1591,7 +1592,7 @@ public class BitmapUtils {
             e.printStackTrace();
         }
 
-        return "file://" + dirPath + fileName + ".jpg";
+        return filePath;
     }
     public static String scaleBitmap(String screenShotPath) {
         Bitmap bitmap = decodeImage(screenShotPath);

+ 6 - 2
app/src/main/java/com/sunwin/visitorapp/utils/Constant.java

@@ -1,6 +1,9 @@
 package com.sunwin.visitorapp.utils;
 
 
+import android.app.usage.ExternalStorageStats;
+import android.os.Environment;
+
 public class Constant {
 
     final public static int rotate = SharePrefenceUtils.getInt("cameraRotate", 0);
@@ -21,7 +24,7 @@ public class Constant {
     public static final String SWBINDIR = "/sdcard/models";
     public static final String SWRECODE = "/sdcard/swRecode";
 
-    public static final String RecognitionDir = "/sdcard/faceRecognition/"; //记录图片存储位置
+    public static final String RecognitionDir = Environment.getExternalStorageDirectory()+"/faceRecognition/"; //记录图片存储位置
 
     public static volatile boolean isReConnectUsb = false;//是否重新连接
 
@@ -34,7 +37,7 @@ public class Constant {
     public interface ISharePrefence {
 
         String BASEURL = "baseurl";
-        String LOGINTAG = "logintag";
+        String LOGINTAG = "loginTag";
         String ISINIT = "isInit";
     }
 
@@ -47,6 +50,7 @@ public class Constant {
         String ISLOGINUSER = "isLoginUser";
         String VISIT_SIGN_TYPE = "visitSignType";//1,身份证,2 人脸
         String VISIT_TYPE = "visitType";//1,签到,2 签离
+        String RECOGNIZE_INFO = "recognizeInfo";
     }
 
     public interface NumerValue {

+ 3 - 1
app/src/main/java/com/sunwin/visitorapp/view/FaceDetecterView.java

@@ -115,7 +115,9 @@ public class FaceDetecterView extends RelativeLayout {
     }
 
     public void onDestroy() {
-        mFRAbsLoop.shutdown();
+        if (mFRAbsLoop!= null){
+            mFRAbsLoop.shutdown();
+        }
         BaseApplication.getSystemTTS().stopSpeak();
         EventBus.getDefault().unregister(this);
     }

+ 1 - 0
app/src/main/res/layout/fragment_visit_sign.xml

@@ -3,6 +3,7 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:gravity="center_vertical"
     android:orientation="vertical">
 
     <com.sunwin.visitorapp.view.MyGridView