|
@@ -1,40 +1,62 @@
|
|
|
package com.example.chemical.ui.plan.unlock;
|
|
|
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
|
|
|
+import androidx.activity.result.ActivityResultLauncher;
|
|
|
+import androidx.activity.result.contract.ActivityResultContracts;
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
import com.blankj.utilcode.util.ActivityUtils;
|
|
|
-import com.example.chemical.ChemicalApp;
|
|
|
+import com.blankj.utilcode.util.GsonUtils;
|
|
|
+import com.blankj.utilcode.util.ThreadUtils;
|
|
|
import com.example.chemical.databinding.ActivityUnlockBinding;
|
|
|
import com.example.chemical.ui.common.BaseCountDownActivity;
|
|
|
import com.example.chemical.ui.plan.room.RoomTool;
|
|
|
import com.example.chemical.ui.plan.room.bean.input_add.InventoryItemBean;
|
|
|
+import com.example.chemical.ui.plan.room.bean.locker.HxpCabinetAdminVo;
|
|
|
import com.example.chemical.ui.plan.room.bean.locker.HxpCabinetDoorVo;
|
|
|
+import com.example.chemical.ui.plan.room.bean.locker.HxpCabinetLockVo;
|
|
|
import com.example.chemical.ui.plan.room.bean.locker.HxpCabinetVo;
|
|
|
+import com.example.chemical.ui.plan.room.bean.locker.HxpLabDirector;
|
|
|
+import com.example.chemical.ui.plan.room.bean.locker.HxpLabSafe;
|
|
|
import com.example.chemical.ui.plan.room.dao.HxpCabinetDAO;
|
|
|
import com.example.chemical.ui.plan.room.dao.HxpDoorDAO;
|
|
|
import com.example.chemical.ui.plan.room.dao.HxpInventoryDAO;
|
|
|
+import com.example.chemical.ui.plan.save_list.SaveListActivity;
|
|
|
import com.example.chemical.ui.verify.DoubleVerifyActivity;
|
|
|
-import com.example.chemical.ui.verify.TwoVerificationActivity;
|
|
|
-import com.example.chemical.utils.UiManager;
|
|
|
import com.rc.httpcore.bean.HxpChemicalVo;
|
|
|
+import com.rc.httpcore.bean.UserValidationBean;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import kotlin.Triple;
|
|
|
|
|
|
public class UnlockActivity extends BaseCountDownActivity<ActivityUnlockBinding> {
|
|
|
- private ActivityUnlockBinding binding;
|
|
|
+ protected ActivityUnlockBinding binding;
|
|
|
+ private ActivityResultLauncher<Intent> intentActivityResultLauncher;
|
|
|
+ protected UnlockActivityHelp activityHelp;
|
|
|
|
|
|
+ // 验证通过的人员1
|
|
|
+ private UserValidationBean userValidation1;
|
|
|
+ // 验证通过的人员2
|
|
|
+ private UserValidationBean userValidation2;
|
|
|
/**
|
|
|
* 是否管控
|
|
|
*/
|
|
|
private boolean isControl = false;
|
|
|
|
|
|
+ protected UnlockAdapter unlockAdapter;
|
|
|
+
|
|
|
@NonNull
|
|
|
@Override
|
|
|
protected ActivityUnlockBinding createViewBinding() {
|
|
@@ -44,7 +66,7 @@ public class UnlockActivity extends BaseCountDownActivity<ActivityUnlockBinding>
|
|
|
@Override
|
|
|
protected void initViews(@Nullable Bundle savedInstanceState) {
|
|
|
super.initViews(savedInstanceState);
|
|
|
-
|
|
|
+ activityHelp = new UnlockActivityHelp(this);
|
|
|
HxpCabinetDAO hxpCabinetDAO = RoomTool.getInstance().hxpCabinetDAO();
|
|
|
HxpDoorDAO hxpDoorDAO = RoomTool.getInstance().hxpDoorDAO();
|
|
|
HxpInventoryDAO hxpInventoryDAO = RoomTool.getInstance().hxpInventoryDAO();
|
|
@@ -59,34 +81,199 @@ public class UnlockActivity extends BaseCountDownActivity<ActivityUnlockBinding>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 柜门信息理应需要从柜门表中遍历塞到柜子中 观察数据是否异常
|
|
|
List<HxpCabinetVo> cabinetList = hxpCabinetDAO.getAll();
|
|
|
List<HxpCabinetDoorVo> doorList = hxpDoorDAO.getAll();
|
|
|
+ List<HxpCabinetLockVo> unlockList = new ArrayList<>();
|
|
|
+ Iterator<HxpCabinetDoorVo> doorVoIterator = doorList.iterator();
|
|
|
+
|
|
|
+ // 删除不需要开门的柜门
|
|
|
+ while (doorVoIterator.hasNext()) {
|
|
|
+ HxpCabinetDoorVo doorVo = doorVoIterator.next();
|
|
|
+ List<HxpCabinetLockVo> lockVoList = doorVo.getCabinetLockVoList();
|
|
|
+ if (null == lockVoList || lockVoList.isEmpty()) {
|
|
|
+ doorVoIterator.remove();
|
|
|
+ } else {
|
|
|
+ Iterator<HxpCabinetLockVo> lockVoIterator = lockVoList.iterator();
|
|
|
+ while (lockVoIterator.hasNext()) {
|
|
|
+ HxpCabinetLockVo lockVo = lockVoIterator.next();
|
|
|
+ if (lockVo.getUnlockingMethod() != 2) {
|
|
|
+ lockVoIterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (lockVoList.isEmpty()) {
|
|
|
+ doorVoIterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 删除不需要开门的柜子
|
|
|
+ Iterator<HxpCabinetVo> cabinetVoIterator = cabinetList.iterator();
|
|
|
+ while (cabinetVoIterator.hasNext()) {
|
|
|
+ HxpCabinetVo cabinetVo = cabinetVoIterator.next();
|
|
|
+ boolean hasDoor = false;
|
|
|
+ for (int i = 0; i < doorList.size(); i++) {
|
|
|
+ HxpCabinetDoorVo doorVo = doorList.get(i);
|
|
|
+ if (cabinetVo.getCabinetId() == doorVo.getCabinetId()) {
|
|
|
+ hasDoor = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!hasDoor) {
|
|
|
+ cabinetVoIterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 需要开锁的柜子
|
|
|
+ for (int i = 0; i < doorList.size(); i++) {
|
|
|
+ HxpCabinetDoorVo doorVo = doorList.get(i);
|
|
|
+ List<HxpCabinetLockVo> lockVoList = doorVo.getCabinetLockVoList();
|
|
|
+ unlockList.addAll(lockVoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!unlockList.isEmpty()) {
|
|
|
+ ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<Triple<String, String, String>>() {
|
|
|
+ @Override
|
|
|
+ public Triple<String, String, String> doInBackground() throws Throwable {
|
|
|
+ // 公共柜门管理员
|
|
|
+ String adminInfo = "", directorInfo = "", safeInfo = "";
|
|
|
+ List<HxpCabinetAdminVo> cabinetAdminVoList = getCommonAdminUserIds(doorList);
|
|
|
+ if (null != cabinetAdminVoList && !cabinetAdminVoList.isEmpty()) {
|
|
|
+ HxpCabinetAdminVo admin = cabinetAdminVoList.get(0);
|
|
|
+ adminInfo = admin.getUserName() + " " + admin.getPhone();
|
|
|
+ if (cabinetAdminVoList.size() > 1) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0; i < cabinetAdminVoList.size(); i++) {
|
|
|
+ HxpCabinetAdminVo adminVo = cabinetAdminVoList.get(i);
|
|
|
+ sb.append(adminVo.getUserName());
|
|
|
+ sb.append(" ");
|
|
|
+ sb.append(adminVo.getPhone());
|
|
|
+ sb.append("\n");
|
|
|
+ }
|
|
|
+ sb.delete(sb.length() - 1, sb.length());
|
|
|
+ adminInfo = sb.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 实验室负责人
|
|
|
+ List<HxpLabDirector> hxpLabDirectorList = RoomTool.getInstance().hxpLabDirectorDAO().getAll();
|
|
|
+ if (null != hxpLabDirectorList && !hxpLabDirectorList.isEmpty()) {
|
|
|
+ HxpLabDirector labDirector = hxpLabDirectorList.get(0);
|
|
|
+ directorInfo = labDirector.getUserName() + " " + labDirector.getMobile();
|
|
|
+ if (hxpLabDirectorList.size() > 1) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0; i < hxpLabDirectorList.size(); i++) {
|
|
|
+ HxpLabDirector director = hxpLabDirectorList.get(i);
|
|
|
+ sb.append(director.getUserName());
|
|
|
+ sb.append(" ");
|
|
|
+ sb.append(director.getMobile());
|
|
|
+ sb.append("\n");
|
|
|
+ }
|
|
|
+ sb.delete(sb.length() - 1, sb.length());
|
|
|
+ directorInfo = sb.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 实验室安全员
|
|
|
+ List<HxpLabSafe> labSafeList = RoomTool.getInstance().hxpLabSafeDAO().getAll();
|
|
|
+ if (null != labSafeList && !labSafeList.isEmpty()) {
|
|
|
+ HxpLabSafe safe = labSafeList.get(0);
|
|
|
+ safeInfo = safe.getUserName() + " " + safe.getMobile();
|
|
|
+ if (labSafeList.size() > 1) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0; i < labSafeList.size(); i++) {
|
|
|
+ HxpLabSafe labSafe = labSafeList.get(i);
|
|
|
+ sb.append(labSafe.getUserName());
|
|
|
+ sb.append(" ");
|
|
|
+ sb.append(labSafe.getMobile());
|
|
|
+ sb.append("\n");
|
|
|
+ }
|
|
|
+ sb.delete(sb.length() - 1, sb.length());
|
|
|
+ safeInfo = sb.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return new Triple<>(adminInfo, directorInfo, safeInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Triple<String, String, String> result) {
|
|
|
+ String adminInfo = result.getFirst();
|
|
|
+ String directorInfo = result.getSecond();
|
|
|
+ String safeInfo = result.getThird();
|
|
|
+ binding.adminTV.setText(TextUtils.isEmpty(adminInfo) ? "" : adminInfo);
|
|
|
+ binding.directorTV.setText(TextUtils.isEmpty(directorInfo) ? "" : directorInfo);
|
|
|
+ binding.safetyTV.setText(TextUtils.isEmpty(safeInfo) ? "" : safeInfo);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
binding.cabinetTV.setText(cabinetList.size() + "个");
|
|
|
binding.doorTV.setText(doorList.size() + "个");
|
|
|
- binding.unlockGV.setAdapter(new UnlockAdapter(this, cabinetList, doorList));
|
|
|
-
|
|
|
- binding.cancelBT.setOnClickListener(v -> finish());
|
|
|
-
|
|
|
- binding.validateBT.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- ActivityUtils.startActivity(DoubleVerifyActivity.class);
|
|
|
-// /* 以下前同事代码*/
|
|
|
-// String verifyType = ChemicalApp.confs.getVerifyType();
|
|
|
-// Map<String, Object> map = new HashMap<>();
|
|
|
-// map.put("chemicalLevel", isControl ? 1 : 2);
|
|
|
-// map.put("mTag", 0);
|
|
|
-// if (verifyType.length() == 1) {
|
|
|
-//// map.put("dooId",)
|
|
|
-// map.put("mVerTyps", Integer.valueOf(verifyType));
|
|
|
-// UiManager.INSTANCE.switcher(UnlockActivity.this, map, TwoVerificationActivity.class);
|
|
|
-// } else {
|
|
|
-// map.put("mVerTyps", 0);
|
|
|
-// }
|
|
|
+ unlockAdapter = new UnlockAdapter(this, cabinetList, doorList);
|
|
|
+ binding.unlockGV.setAdapter(unlockAdapter);
|
|
|
+
|
|
|
+ intentActivityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
|
|
+ if (result.getResultCode() == RESULT_OK) {
|
|
|
+ Intent intent = result.getData();
|
|
|
+ if (null != intent && intent.hasExtra("userValidation1") && intent.hasExtra("userValidation2")) {
|
|
|
+ userValidation1 = GsonUtils.fromJson(intent.getStringExtra("userValidation1"), UserValidationBean.class);
|
|
|
+ userValidation2 = GsonUtils.fromJson(intent.getStringExtra("userValidation2"), UserValidationBean.class);
|
|
|
+ }
|
|
|
+ binding.validateBT.setVisibility(View.GONE);
|
|
|
+ binding.unlockLL.setVisibility(View.VISIBLE);
|
|
|
+ activityHelp.unlock(unlockList, cabinetList, doorList, userValidation1, userValidation2);
|
|
|
}
|
|
|
});
|
|
|
+ binding.validateBT.setOnClickListener(v -> intentActivityResultLauncher.launch(new Intent(UnlockActivity.this, DoubleVerifyActivity.class)));
|
|
|
+
|
|
|
+ binding.retryBT.setOnClickListener(v -> activityHelp.reTryUnlock());
|
|
|
+ binding.saveBT.setOnClickListener(v -> ActivityUtils.startActivity(SaveListActivity.class));
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ intentActivityResultLauncher.unregister();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<HxpCabinetAdminVo> getCommonAdminUserIds(List<HxpCabinetDoorVo> doorList) {
|
|
|
+ if (doorList == null || doorList.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Map<Long, Integer> userIdCount = new HashMap<Long, Integer>();
|
|
|
+ int totalDoors = doorList.size();
|
|
|
+
|
|
|
+ // 统计所有 UserId 的出现次数
|
|
|
+ for (HxpCabinetDoorVo door : doorList) {
|
|
|
+ Set<Long> uniqueIds = new HashSet<Long>(); // 记录当前 Door 的唯一 UserId,防止重复计数
|
|
|
+ for (HxpCabinetAdminVo admin : door.getCabinetAdminVoList()) {
|
|
|
+ uniqueIds.add(admin.getUserId());
|
|
|
+ }
|
|
|
+ for (Long userId : uniqueIds) {
|
|
|
+ userIdCount.put(userId, userIdCount.containsKey(userId) ? userIdCount.get(userId) + 1 : 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 过滤出出现在所有 Door 中的 UserId
|
|
|
+ Set<Long> commonUserIds = new HashSet<Long>();
|
|
|
+ for (Map.Entry<Long, Integer> entry : userIdCount.entrySet()) {
|
|
|
+ if (entry.getValue() == totalDoors) {
|
|
|
+ commonUserIds.add(entry.getKey());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (commonUserIds.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 仅返回第一个 Door 中符合的 Admin
|
|
|
+ List<HxpCabinetAdminVo> commonAdmins = new ArrayList<HxpCabinetAdminVo>();
|
|
|
+ for (HxpCabinetAdminVo admin : doorList.get(0).getCabinetAdminVoList()) {
|
|
|
+ if (commonUserIds.contains(admin.getUserId())) {
|
|
|
+ commonAdmins.add(admin);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return commonAdmins;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|