|
|
@@ -2,42 +2,163 @@ package com.example.chemical.ui.verify;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
import android.graphics.Bitmap;
|
|
|
+import android.os.CountDownTimer;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
|
-import androidx.core.util.Pair;
|
|
|
+import androidx.annotation.NonNull;
|
|
|
|
|
|
import com.blankj.utilcode.util.ConvertUtils;
|
|
|
import com.blankj.utilcode.util.GsonUtils;
|
|
|
import com.blankj.utilcode.util.LogUtils;
|
|
|
+import com.blankj.utilcode.util.RegexUtils;
|
|
|
import com.blankj.utilcode.util.ResourceUtils;
|
|
|
import com.blankj.utilcode.util.ThreadUtils;
|
|
|
+import com.example.chemical.ChemicalApp;
|
|
|
import com.example.chemical.R;
|
|
|
import com.example.chemical.databinding.ActivityDoubleVerifyBinding;
|
|
|
+import com.example.chemical.receiver.OnSerialScanListener;
|
|
|
+import com.example.chemical.receiver.PortScanHelper;
|
|
|
+import com.example.chemical.ui.plan.room.bean.locker.HxpCabinetDoorVo;
|
|
|
import com.example.chemical.ui.verify.include.DetectType;
|
|
|
import com.example.chemical.ui.verify.include.FaceDetectView;
|
|
|
import com.example.chemical.utils.AudioPlayer;
|
|
|
+import com.example.chemical.utils.TimesUils;
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
|
import com.google.zxing.MultiFormatWriter;
|
|
|
import com.google.zxing.WriterException;
|
|
|
import com.google.zxing.common.BitMatrix;
|
|
|
import com.kongzue.dialogx.dialogs.PopTip;
|
|
|
+import com.lztek.toolkit.Lztek;
|
|
|
import com.rc.httpcore.HttpConfig;
|
|
|
import com.rc.httpcore.bean.UserValidationBean;
|
|
|
+import com.rc.httpcore.client.HttpTool;
|
|
|
+
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import kotlin.Triple;
|
|
|
+import okhttp3.Response;
|
|
|
|
|
|
public class DoubleVerifyActivityHelp {
|
|
|
private DoubleVerifyActivity activity;
|
|
|
private ActivityDoubleVerifyBinding binding;
|
|
|
+ private String qrScanTime;
|
|
|
/**
|
|
|
* 验证通过的人信息
|
|
|
*/
|
|
|
private UserValidationBean userValidation1, userValidation2;
|
|
|
|
|
|
+ public void onDestroy() {
|
|
|
+ if (null != qrTimer) {
|
|
|
+ qrTimer.cancel();
|
|
|
+ qrTimer = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public DoubleVerifyActivityHelp(DoubleVerifyActivity activity) {
|
|
|
this.activity = activity;
|
|
|
binding = activity.binding;
|
|
|
+
|
|
|
+ activity.portScanHelper = new PortScanHelper(activity, new OnSerialScanListener() {
|
|
|
+ @Override
|
|
|
+ public void dispatchScanEvent(@NonNull ScanType type, @NonNull String content) {
|
|
|
+ boolean isCard = RegexUtils.isMatch("^[-+]?\\d+$", content);
|
|
|
+ if (isCard) {
|
|
|
+ List<HxpCabinetDoorVo> planAddDataDoorList = activity.planAddData.getDoorList();
|
|
|
+ List<String> doorIdList = new ArrayList<>();
|
|
|
+ if (null != planAddDataDoorList && !planAddDataDoorList.isEmpty()) {
|
|
|
+ for (int i = 0; i < planAddDataDoorList.size(); i++) {
|
|
|
+ doorIdList.add(String.valueOf(planAddDataDoorList.get(i).getDoorId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<UserValidationBean>() {
|
|
|
+ @Override
|
|
|
+ public UserValidationBean doInBackground() throws Throwable {
|
|
|
+ try {
|
|
|
+ Response response = HttpTool.useCardVerify1(content, ChemicalApp.subjectId, doorIdList);
|
|
|
+ if (response.isSuccessful()) {
|
|
|
+ String json = response.body().string();
|
|
|
+ JSONObject jsonObject = new JSONObject(json);
|
|
|
+ int code = jsonObject.getInt("code");
|
|
|
+ if (200 == code) {
|
|
|
+ return GsonUtils.fromJson(jsonObject.getJSONObject("data").toString(), UserValidationBean.class);
|
|
|
+ } else {
|
|
|
+ PopTip.show(jsonObject.getString("message"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ PopTip.show(response.message());
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ LogUtils.e(Log.getStackTraceString(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(UserValidationBean result) {
|
|
|
+ if (null != result) {
|
|
|
+ verifyProcess(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ PopTip.show("非法的卡号");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void verifyProcess(UserValidationBean userValidation) {
|
|
|
+ // 是否是 全部柜门管理员、安全员、实验室负责人
|
|
|
+ boolean isAdmin = Boolean.TRUE.equals(userValidation.getSafeUser()) || Boolean.TRUE.equals(userValidation.getAdminUser()) || Boolean.TRUE.equals(userValidation.getCabinetAdmin());
|
|
|
+ Triple<Boolean, Boolean, Long> first = activity.doubleVerifyList.get(0);
|
|
|
+ Triple<Boolean, Boolean, Long> second = activity.doubleVerifyList.get(1);
|
|
|
+ // 第一个人是否已认证通过 第二个人未通过
|
|
|
+ if (!first.getFirst() && !second.getFirst()) {
|
|
|
+ binding.hint1IV.setText("第一位验证已通过");
|
|
|
+ PopTip.show("第一位验证已通过!");
|
|
|
+ userValidation1 = userValidation;
|
|
|
+ activity.doubleVerifyList.set(0, new Triple<>(true, isAdmin, Long.valueOf(userValidation.getUserId())));
|
|
|
+ // 切换到第二位验证人 默认人脸方式
|
|
|
+ switchShowDetect(DetectType.FACE_DETECT, false, true);
|
|
|
+ }
|
|
|
+ if (first.getFirst() && !second.getFirst()) {
|
|
|
+ // 至少一个人是管理员
|
|
|
+ if (!first.getSecond() && !isAdmin) {
|
|
|
+ PopTip.show("请联系柜门管理员、安全员、实验室负责人进行验证");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+// // 重复的人
|
|
|
+// if (first.getThird() == Long.parseLong(result.getUserId())) {
|
|
|
+// PopTip.show("验证人不能相同!");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+ activity.doubleVerifyList.set(1, new Triple<>(true, isAdmin, Long.valueOf(userValidation.getUserId())));
|
|
|
+ binding.hint2IV.setText("第二位验证已通过");
|
|
|
+ PopTip.show("第2位验证已通过!");
|
|
|
+ userValidation2 = userValidation;
|
|
|
+ doubleVerifySuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doubleVerifySuccess() {
|
|
|
+ PopTip.show("双人认证成功");
|
|
|
+ AudioPlayer.getInstance().play(R.raw.shuangren_tongguo);
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("userValidation1", GsonUtils.toJson(userValidation1));
|
|
|
+ intent.putExtra("userValidation2", GsonUtils.toJson(userValidation2));
|
|
|
+ activity.setResult(TwoPersonActivity.RESULT_OK, intent);
|
|
|
+ activity.finish();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -48,17 +169,15 @@ public class DoubleVerifyActivityHelp {
|
|
|
* @param isShow 是否展示
|
|
|
*/
|
|
|
public void switchShowDetect(DetectType faceDetect, boolean isFirst, boolean isShow) {
|
|
|
- Pair<Boolean, Boolean> first = activity.doubleVerifyList.get(0);
|
|
|
- Pair<Boolean, Boolean> second = activity.doubleVerifyList.get(1);
|
|
|
- if (first.first && second.first) {
|
|
|
+ Triple<Boolean, Boolean, Long> first = activity.doubleVerifyList.get(0);
|
|
|
+ Triple<Boolean, Boolean, Long> second = activity.doubleVerifyList.get(1);
|
|
|
+ if (first.getFirst() && second.getFirst()) {
|
|
|
PopTip.show("双人认证已通过!");
|
|
|
return;
|
|
|
}
|
|
|
- // 切换UI
|
|
|
- switchDetectUi(faceDetect, isFirst);
|
|
|
// 是否第一位
|
|
|
if (isFirst) {
|
|
|
- if (first.first) {
|
|
|
+ if (first.getFirst()) {
|
|
|
PopTip.show("第一位验证已通过!");
|
|
|
return;
|
|
|
}
|
|
|
@@ -66,7 +185,7 @@ public class DoubleVerifyActivityHelp {
|
|
|
switch (faceDetect) {
|
|
|
case FACE_DETECT:
|
|
|
if (isShow) {
|
|
|
- binding.include1LL.addView(new FaceDetectView(activity, activity, activity.doubleVerifyList, new DoubleVerifyActivity.DoubleVerifyListener() {
|
|
|
+ binding.include1LL.addView(new FaceDetectView(activity, activity, activity.doubleVerifyList, activity.planAddData, new DoubleVerifyActivity.DoubleVerifyListener() {
|
|
|
@Override
|
|
|
public void detect(DetectType type, Bitmap faceBitmap, UserValidationBean userValidationBean) {
|
|
|
binding.include1LL.removeAllViewsInLayout();
|
|
|
@@ -100,7 +219,12 @@ public class DoubleVerifyActivityHelp {
|
|
|
ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<Bitmap>() {
|
|
|
@Override
|
|
|
public Bitmap doInBackground() throws Throwable {
|
|
|
- return createQrCode();
|
|
|
+ Lztek mLztek = Lztek.create(activity);
|
|
|
+ String toUpperCase = mLztek.getEthMac().toUpperCase().replace(":", "");
|
|
|
+ qrScanTime = TimesUils.INSTANCE.getCurrentDateTime();
|
|
|
+ String url = HttpConfig.Companion.getAPI_BASE_QC_URL() + "?doorId=-1" + "&subId=0" + ChemicalApp.subjectId + "&type=12&macId=" + toUpperCase + "&code=" + qrScanTime;
|
|
|
+ LogUtils.d("qrUrl", url);
|
|
|
+ return createQrCode(url);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -108,6 +232,7 @@ public class DoubleVerifyActivityHelp {
|
|
|
if (null != result) {
|
|
|
qrIv.setBackground(null);
|
|
|
qrIv.setImageBitmap(result);
|
|
|
+ startQrTimer();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -116,7 +241,7 @@ public class DoubleVerifyActivityHelp {
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
|
- if (!first.first) {
|
|
|
+ if (!first.getFirst()) {
|
|
|
PopTip.show("第一位验证未通过!");
|
|
|
return;
|
|
|
}
|
|
|
@@ -124,7 +249,7 @@ public class DoubleVerifyActivityHelp {
|
|
|
switch (faceDetect) {
|
|
|
case FACE_DETECT:
|
|
|
if (isShow) {
|
|
|
- binding.include2LL.addView(new FaceDetectView(activity, activity, activity.doubleVerifyList, new DoubleVerifyActivity.DoubleVerifyListener() {
|
|
|
+ binding.include2LL.addView(new FaceDetectView(activity, activity, activity.doubleVerifyList, activity.planAddData, new DoubleVerifyActivity.DoubleVerifyListener() {
|
|
|
@Override
|
|
|
public void detect(DetectType type, Bitmap faceBitmap, UserValidationBean userValidationBean) {
|
|
|
binding.include2LL.removeAllViewsInLayout();
|
|
|
@@ -133,13 +258,7 @@ public class DoubleVerifyActivityHelp {
|
|
|
binding.include2LL.addView(imageView);
|
|
|
binding.hint2IV.setText("第二位验证已通过");
|
|
|
userValidation2 = userValidationBean;
|
|
|
- PopTip.show("双人认证成功");
|
|
|
- AudioPlayer.getInstance().play(R.raw.shuangren_tongguo);
|
|
|
- Intent intent = new Intent();
|
|
|
- intent.putExtra("userValidation1", GsonUtils.toJson(userValidation1));
|
|
|
- intent.putExtra("userValidation2", GsonUtils.toJson(userValidation2));
|
|
|
- activity.setResult(TwoPersonActivity.RESULT_OK, intent);
|
|
|
- activity.finish();
|
|
|
+ doubleVerifySuccess();
|
|
|
}
|
|
|
}));
|
|
|
AudioPlayer.getInstance().play(R.raw.dierwei_renlianshibie);
|
|
|
@@ -165,7 +284,12 @@ public class DoubleVerifyActivityHelp {
|
|
|
ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<Bitmap>() {
|
|
|
@Override
|
|
|
public Bitmap doInBackground() throws Throwable {
|
|
|
- return createQrCode();
|
|
|
+ Lztek mLztek = Lztek.create(activity);
|
|
|
+ String toUpperCase = mLztek.getEthMac().toUpperCase().replace(":", "");
|
|
|
+ qrScanTime = TimesUils.INSTANCE.getCurrentDateTime();
|
|
|
+ String url = HttpConfig.Companion.getAPI_BASE_QC_URL() + "?doorId=-1" + "&subId=0" + ChemicalApp.subjectId + "&type=12&macId=" + toUpperCase + "&code=" + qrScanTime;
|
|
|
+ LogUtils.d("qrUrl", url);
|
|
|
+ return createQrCode(url);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -173,6 +297,7 @@ public class DoubleVerifyActivityHelp {
|
|
|
if (null != result) {
|
|
|
qrIv.setBackground(null);
|
|
|
qrIv.setImageBitmap(result);
|
|
|
+ startQrTimer();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -181,6 +306,67 @@ public class DoubleVerifyActivityHelp {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ // 切换UI
|
|
|
+ switchDetectUi(faceDetect, isFirst);
|
|
|
+ }
|
|
|
+
|
|
|
+ private CountDownTimer qrTimer = new CountDownTimer(1000, 1000) {
|
|
|
+ @Override
|
|
|
+ public void onTick(long millisUntilFinished) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFinish() {
|
|
|
+ if (activity.detectType != DetectType.SCAN_DETECT) {
|
|
|
+ qrTimer.cancel();
|
|
|
+ qrTimer = null;
|
|
|
+ } else {
|
|
|
+ ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<UserValidationBean>() {
|
|
|
+ @Override
|
|
|
+ public UserValidationBean doInBackground() throws Throwable {
|
|
|
+ List<HxpCabinetDoorVo> planAddDataDoorList = activity.planAddData.getDoorList();
|
|
|
+ List<String> doorIdList = new ArrayList<>();
|
|
|
+ if (null != planAddDataDoorList && !planAddDataDoorList.isEmpty()) {
|
|
|
+ for (int i = 0; i < planAddDataDoorList.size(); i++) {
|
|
|
+ doorIdList.add(String.valueOf(planAddDataDoorList.get(i).getDoorId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Response response = HttpTool.aioScanLogin1(qrScanTime, ChemicalApp.subjectId, doorIdList);
|
|
|
+ LogUtils.json(response);
|
|
|
+ LogUtils.d(response.body().string());
|
|
|
+ if (response.isSuccessful()) {
|
|
|
+ String json = response.body().string();
|
|
|
+ JSONObject jsonObject = new JSONObject(json);
|
|
|
+ int code = jsonObject.getInt("code");
|
|
|
+ if (200 == code) {
|
|
|
+ return GsonUtils.fromJson(jsonObject.getJSONObject("data").toString(), UserValidationBean.class);
|
|
|
+ } else {
|
|
|
+ PopTip.show(jsonObject.getString("message"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ PopTip.show(response.message());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(UserValidationBean result) {
|
|
|
+ if (null != result) {
|
|
|
+ qrTimer.cancel();
|
|
|
+ qrTimer = null;
|
|
|
+ verifyProcess(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ qrTimer.start();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private void startQrTimer() {
|
|
|
+ qrTimer.cancel();
|
|
|
+ qrTimer.start();
|
|
|
}
|
|
|
|
|
|
private void switchDetectUi(DetectType detectType, boolean isFirst) {
|
|
|
@@ -235,10 +421,10 @@ public class DoubleVerifyActivityHelp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Bitmap createQrCode() {
|
|
|
+ private Bitmap createQrCode(String url) {
|
|
|
BitMatrix bitMatrix;
|
|
|
try {
|
|
|
- bitMatrix = new MultiFormatWriter().encode(HttpConfig.Companion.getAPI_BASE_QC_URL(), BarcodeFormat.QR_CODE, 400, 400);
|
|
|
+ bitMatrix = new MultiFormatWriter().encode(url, BarcodeFormat.QR_CODE, 400, 400);
|
|
|
} catch (WriterException e) {
|
|
|
LogUtils.e(Log.getStackTraceString(e));
|
|
|
return null;
|