package cn.com.basic.face.util;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
|
import cn.com.basic.face.discern.common.CommonVariables;
|
import cn.com.basic.face.discern.query.item.SurveillanceQueryItem;
|
import cn.com.basic.face.fragment.SurveillanceFragment;
|
|
public class SurveillanceQueryItemUtil {
|
|
private static SurveillanceQueryItemUtil instance = new SurveillanceQueryItemUtil();
|
|
public static SurveillanceQueryItemUtil getInstance() {
|
return instance;
|
}
|
|
//所有监控图片
|
public static List<SurveillanceQueryItem> allItems = new ArrayList<>();
|
//访客选项卡的分类(未注册/人员类型、来访状态、标签状态)
|
//考勤选项卡(考勤人员类型:教师、学生、员工,来访状态:签到、签退)
|
//第一行显示未注册,第二行显示来访
|
public static List<SurveillanceQueryItem> visitorTwoRows = new ArrayList<>();
|
//第一行显示签到,第二行显示签退
|
public static List<SurveillanceQueryItem> attendanceTwoRows = new ArrayList<>();
|
//未注册的访客列表, 选择时用
|
public static List<SurveillanceQueryItem> allUnregisterVisitorTwoRowsForSelect = new ArrayList();
|
//未注册的考勤列表, 选择时用
|
public static List<SurveillanceQueryItem> allUnregisterAttenderTwoRowsForSelect = new ArrayList();
|
|
public void addItems(List<SurveillanceQueryItem> returnItems, List<SurveillanceQueryItem> requestItems, String cameraInOrOut) {
|
for ( int i = 0; i < returnItems.size(); i++) {
|
SurveillanceQueryItem returnItem = returnItems.get(i);
|
SurveillanceQueryItem requestItem = requestItems.get(i);
|
addItem(returnItem, requestItem, cameraInOrOut);
|
}
|
removeTimeoutItemAndShow();
|
limitItemsToN();
|
}
|
|
public void addItem(SurveillanceQueryItem returnItem, SurveillanceQueryItem requestItem, String cameraInOrOut) {
|
if (!CommonVariables.FACE_SERVER) {
|
RtspFaceNative.setFaceLabel(Integer.parseInt(cameraInOrOut), requestItem.getStTrackId(), returnItem.getVisitorType()==null?"":returnItem.getVisitorType().substring(0,
|
returnItem.getVisitorType().length() > 3 ? 3 : returnItem.getVisitorType().length()
|
));
|
}
|
returnItem.setCreateTime(new Date());
|
returnItem.setStTrackId(requestItem.getStTrackId());
|
returnItem.setBitmap(requestItem.getBitmap());
|
returnItem.setNativeImg(requestItem.getNativeImg());
|
returnItem.setWidth(requestItem.getWidth());
|
returnItem.setHeight(requestItem.getHeight());
|
allItems.add(0, returnItem);
|
}
|
|
private void limitItemsToN() {
|
int max = 25;
|
int unRegisters = 0;
|
int checkIns = 0;
|
int attenderEnter = 0;
|
int attenderExit = 0;
|
List<SurveillanceQueryItem> itemsToRemove = new ArrayList<>();
|
for (int i = 0; i < allItems.size(); i++) {
|
SurveillanceQueryItem item = allItems.get(i);
|
int type = item.getRegisterOrCheckIn();
|
if (type == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
|
unRegisters++;
|
if (unRegisters > max) {
|
itemsToRemove.add(item);
|
}
|
}
|
if (type == CommonVariables.Surveillance.VISIT_CHECK_IN_ITEM_TYPE) {
|
checkIns++;
|
if (checkIns > max) {
|
itemsToRemove.add(item);
|
}
|
}
|
if (type == CommonVariables.Surveillance.VISIT_ATTENDANCE_IN) {
|
attenderEnter++;
|
if (attenderEnter > max) {
|
itemsToRemove.add(item);
|
}
|
}
|
if (type == CommonVariables.Surveillance.VISIT_ATTENDANCE_OUT) {
|
attenderExit++;
|
if (attenderExit > max) {
|
itemsToRemove.add(item);
|
}
|
}
|
}
|
allItems.removeAll(itemsToRemove);
|
}
|
|
public List getVisitorTwoRows() {
|
visitorTwoRows.clear();
|
for (SurveillanceQueryItem item : allItems) {
|
int type = item.getRegisterOrCheckIn();
|
if (type == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE
|
|| type == CommonVariables.Surveillance.VISIT_CHECK_IN_ITEM_TYPE
|
) {
|
visitorTwoRows.add(item);
|
}
|
}
|
VisitorUtil.removeDuplicateCheckIn();
|
VisitorUtil.removeDuplicateUnregister();
|
VisitorUtil.sortByRow();
|
return visitorTwoRows;
|
}
|
|
public List getAttendanceTwoRows() {
|
attendanceTwoRows.clear();
|
for (SurveillanceQueryItem item : allItems) {
|
if (item.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_ATTENDANCE_IN ||
|
item.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_ATTENDANCE_OUT
|
) {
|
attendanceTwoRows.add(item);
|
}
|
}
|
AttendentUtil.removeDuplicateAttendanceIn();
|
AttendentUtil.removeDuplicateAttendanceOut();
|
AttendentUtil.sortByRow();
|
return attendanceTwoRows;
|
}
|
|
public List getAllUnregisterVisitorTwoRowsForSelect(long selectedId) {
|
allUnregisterVisitorTwoRowsForSelect.clear();
|
List<SurveillanceQueryItem> registerList = new ArrayList();
|
int countPerRow = 9;
|
for (SurveillanceQueryItem surveillanceQueryItem : allItems) {
|
if (surveillanceQueryItem.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
|
if (registerList.size() > countPerRow*2) {
|
break;
|
}
|
if (surveillanceQueryItem.getIdForSelect() == selectedId) {
|
surveillanceQueryItem.setSurveillancePhotoSelected(true);
|
} else {
|
surveillanceQueryItem.setSurveillancePhotoSelected(false);
|
}
|
registerList.add(surveillanceQueryItem);
|
}
|
}
|
|
SurveillanceQueryItem item;
|
List items = new ArrayList();
|
int m = 0, n = 0;
|
for (int i = 0; i < countPerRow*2; i++) {
|
if (i % 2 == 0) {
|
if (m < registerList.size()) {
|
item = registerList.get(m);
|
m++;
|
} else {
|
item = VisitorUtil.getBlankItem();
|
}
|
} else {
|
if (n < registerList.size() - countPerRow) {
|
item = registerList.get(countPerRow+n);
|
n++;
|
} else {
|
item = VisitorUtil.getBlankItem();
|
}
|
}
|
items.add(item);
|
}
|
allUnregisterVisitorTwoRowsForSelect.addAll(items);
|
return allUnregisterVisitorTwoRowsForSelect;
|
}
|
|
public List getAllUnregisterAttenderTwoRowsForSelect(long selectedId) {
|
allUnregisterAttenderTwoRowsForSelect.clear();
|
List<SurveillanceQueryItem> registerList = new ArrayList();
|
int countPerRow = 9;
|
for (SurveillanceQueryItem surveillanceQueryItem : allItems) {
|
if (surveillanceQueryItem.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
|
if (registerList.size() > countPerRow*2) {
|
break;
|
}
|
if (surveillanceQueryItem.getIdForSelect() == selectedId) {
|
surveillanceQueryItem.setSurveillancePhotoSelected(true);
|
} else {
|
surveillanceQueryItem.setSurveillancePhotoSelected(false);
|
}
|
registerList.add(surveillanceQueryItem);
|
}
|
}
|
|
SurveillanceQueryItem item;
|
List items = new ArrayList();
|
int m = 0, n = 0;
|
for (int i = 0; i < countPerRow*2; i++) {
|
if (i % 2 == 0) {
|
if (m < registerList.size()) {
|
item = registerList.get(m);
|
m++;
|
} else {
|
item = VisitorUtil.getBlankItem();
|
}
|
} else {
|
if (n < registerList.size() - countPerRow) {
|
item = registerList.get(countPerRow+n);
|
n++;
|
} else {
|
item = VisitorUtil.getBlankItem();
|
}
|
}
|
items.add(item);
|
}
|
allUnregisterAttenderTwoRowsForSelect.addAll(items);
|
return allUnregisterAttenderTwoRowsForSelect;
|
}
|
|
public void removeTimeoutItemAndShow() {
|
List itemsToRemove = new ArrayList();
|
for (SurveillanceQueryItem item : allItems) {
|
if (item.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
|
Date now = new Date();
|
Date createTime = item.getCreateTime();
|
double minutes = (now.getTime() - createTime.getTime())*1.0 / 1000 / 60;
|
if (minutes >= 5) {
|
itemsToRemove.add(item);
|
}
|
}
|
}
|
allItems.removeAll(itemsToRemove);
|
SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().show(SurveillanceQueryItemUtil.getInstance().getVisitorTwoRows());
|
SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_attendance_list_view().show(SurveillanceQueryItemUtil.getInstance().getAttendanceTwoRows());
|
}
|
|
static class VisitorUtil {
|
|
public static void removeDuplicateCheckIn() {
|
List itemsToRemove = new ArrayList();
|
Set<String> registerIds = new HashSet<>();
|
for (SurveillanceQueryItem item : visitorTwoRows) {
|
if (item.getRegisterOrCheckIn() == Constant.Surveillance.VISIT_CHECK_IN_ITEM_TYPE) {
|
if (registerIds.contains(item.getRegisterId()+"_"+item.getInOrOutCamera())) {
|
itemsToRemove.add(item);
|
} else {
|
registerIds.add(item.getRegisterId()+"_"+item.getInOrOutCamera());
|
}
|
}
|
}
|
visitorTwoRows.removeAll(itemsToRemove);
|
}
|
|
public static void removeDuplicateUnregister() {
|
List<SurveillanceQueryItem> registerList = new ArrayList<SurveillanceQueryItem>();
|
List itemsToRemove = new ArrayList();
|
for (SurveillanceQueryItem item : visitorTwoRows) {
|
if (item.getRegisterOrCheckIn() == Constant.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
|
int trackId = item.getStTrackId();
|
boolean trackIdExist = false;
|
for (SurveillanceQueryItem registerItem : registerList) {
|
if (registerItem.getStTrackId() == trackId) {
|
itemsToRemove.add(item);
|
}
|
}
|
if (!trackIdExist) {
|
registerList.add(item);
|
}
|
}
|
}
|
visitorTwoRows.removeAll(itemsToRemove);
|
}
|
|
public static void sortByRow() {
|
List<SurveillanceQueryItem> registerList = new ArrayList<SurveillanceQueryItem>();
|
List<SurveillanceQueryItem> checkInList = new ArrayList<SurveillanceQueryItem>();
|
int i1 = 0, j = 0;
|
int maxRegister = 50;
|
int maxCheckIn = 50;
|
for (SurveillanceQueryItem item : visitorTwoRows) {
|
if (item.getRegisterOrCheckIn() == Constant.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
|
if (i1 < maxRegister) {
|
registerList.add(item);
|
i1++;
|
}
|
}
|
if (item.getRegisterOrCheckIn() == Constant.Surveillance.VISIT_CHECK_IN_ITEM_TYPE) {
|
if (j < maxCheckIn) {
|
checkInList.add(item);
|
j++;
|
}
|
}
|
}
|
|
int max = registerList.size() > checkInList.size() ? registerList.size() : checkInList.size();
|
|
List tempList = new ArrayList();
|
|
int m = 0, n = 0;
|
for (int i = 0; i < max * 2; i++) {
|
SurveillanceQueryItem item;
|
if (i % 2 == 0) {
|
if (m < registerList.size()) {
|
item = registerList.get(m);
|
} else {
|
item = getBlankItem();
|
}
|
m++;
|
} else {
|
if (n < checkInList.size()) {
|
item = checkInList.get(n);
|
} else {
|
item = getBlankItem();
|
}
|
n++;
|
}
|
tempList.add(item);
|
}
|
visitorTwoRows.clear();
|
visitorTwoRows.addAll(tempList);
|
}
|
|
public static SurveillanceQueryItem getBlankItem() {
|
SurveillanceQueryItem blankItem = new SurveillanceQueryItem();
|
blankItem.setRegisterOrCheckIn(Constant.Surveillance.VISIT_BLANK_ITEM_TYPE);
|
return blankItem;
|
}
|
|
}
|
|
static class AttendentUtil {
|
|
public static void removeDuplicateAttendanceIn() {
|
Map<String, String> registerIdMap = new HashMap<>();
|
List itemsToRemove = new ArrayList();
|
for (SurveillanceQueryItem item : attendanceTwoRows) {
|
if (item.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_ATTENDANCE_IN) {
|
String registerId = item.getRegisterId();
|
if (registerIdMap.containsKey(item.getRegisterId())) {
|
itemsToRemove.add(item);
|
} else {
|
registerIdMap.put(registerId, registerId);
|
}
|
}
|
}
|
attendanceTwoRows.removeAll(itemsToRemove);
|
}
|
|
public static void removeDuplicateAttendanceOut() {
|
Map<String, String> registerIdMap = new HashMap<>();
|
List itemsToRemove = new ArrayList();
|
for (SurveillanceQueryItem item : attendanceTwoRows) {
|
if (item.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_ATTENDANCE_OUT) {
|
String registerId = item.getRegisterId();
|
if (registerIdMap.containsKey(item.getRegisterId())) {
|
itemsToRemove.add(item);
|
} else {
|
registerIdMap.put(registerId, registerId);
|
}
|
}
|
}
|
attendanceTwoRows.removeAll(itemsToRemove);
|
}
|
|
public static void sortByRow() {
|
List<SurveillanceQueryItem> attenderInList = new ArrayList<SurveillanceQueryItem>();
|
List<SurveillanceQueryItem> attenderOutList = new ArrayList<SurveillanceQueryItem>();
|
int i1 = 0, j = 0;
|
int maxAttenderIn = 50;
|
int maxAttenderOut = 50;
|
for (SurveillanceQueryItem item : attendanceTwoRows) {
|
if (item.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_ATTENDANCE_IN) {
|
if (i1 < maxAttenderIn) {
|
attenderInList.add(item);
|
i1++;
|
}
|
}
|
if (item.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_ATTENDANCE_OUT) {
|
if (j < maxAttenderOut) {
|
attenderOutList.add(item);
|
j++;
|
}
|
}
|
}
|
|
int max = attenderInList.size() > attenderOutList.size() ? attenderInList.size() : attenderOutList.size();
|
|
List tempList = new ArrayList();
|
|
int m = 0, n = 0;
|
for (int i = 0; i < max * 2; i++) {
|
SurveillanceQueryItem item;
|
if (i % 2 == 0) {
|
if (m < attenderInList.size()) {
|
item = attenderInList.get(m);
|
} else {
|
item = getBlankItem();
|
}
|
m++;
|
} else {
|
if (n < attenderOutList.size()) {
|
item = attenderOutList.get(n);
|
} else {
|
item = getBlankItem();
|
}
|
n++;
|
}
|
tempList.add(item);
|
}
|
attendanceTwoRows.clear();
|
attendanceTwoRows.addAll(tempList);
|
}
|
|
public static SurveillanceQueryItem getBlankItem() {
|
SurveillanceQueryItem blankItem = new SurveillanceQueryItem();
|
blankItem.setRegisterOrCheckIn(CommonVariables.Surveillance.VISIT_ATTENDANCE_BLANK);
|
return blankItem;
|
}
|
}
|
|
}
|
|