| | |
| | | package cn.com.basic.face.service;
|
| | |
|
| | | import android.graphics.Bitmap;
|
| | | import android.util.Base64;
|
| | |
|
| | | import org.xutils.http.RequestParams;
|
| | | import org.xutils.x;
|
| | |
|
| | | import java.nio.ByteBuffer;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
|
| | | import cn.com.basic.face.base.BaseApplication;
|
| | | import cn.com.basic.face.base.MainActivity;
|
| | | import cn.com.basic.face.discern.common.BaseCommonCallBack;
|
| | | import cn.com.basic.face.discern.common.CommonVariables;
|
| | | import cn.com.basic.face.discern.query.item.SurveillanceQueryItem;
|
| | | import cn.com.basic.face.fragment.RegisterFragment;
|
| | | import cn.com.basic.face.fragment.SurveillanceFragment;
|
| | | import cn.com.basic.face.util.AppApi;
|
| | | import cn.com.basic.face.util.Constant;
|
| | |
| | | }
|
| | |
|
| | | public void findSurveillanceBottomList(final boolean isVisit) {
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.Query.SURVEILLANCE_QUERY);
|
| | | params.addBodyParameter(CommonVariables.Page.PAGE_NUM, "1");
|
| | | params.addBodyParameter(CommonVariables.Page.PAGE_SIZE, "10");
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | List<SurveillanceQueryItem> list = getList(SurveillanceQueryItem.class);
|
| | | if (isVisit) {
|
| | | int i = 0;
|
| | | for (SurveillanceQueryItem item : list) {
|
| | | if (i % 5 == 0) {
|
| | | item.setType(CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE);
|
| | | } else {
|
| | | item.setType(CommonVariables.Surveillance.VISIT_CHECK_IN_ITEM_TYPE);
|
| | | }
|
| | | i++;
|
| | | }
|
| | |
|
| | | List<SurveillanceQueryItem> doubleList = new ArrayList<SurveillanceQueryItem>();
|
| | | fillBlank(list, doubleList);
|
| | |
|
| | | SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visit_list_view().show(doubleList, true);
|
| | | } else {
|
| | | SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_attendance_list_view().show(list, true);
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public List getRegisterList() {
|
| | | return new ArrayList();
|
| | | }
|
| | |
|
| | | public List getCheckInList() {
|
| | | return new ArrayList();
|
| | | }
|
| | |
|
| | | public void getList() {
|
| | | List registerList = new ArrayList();
|
| | | List checkInList = new ArrayList();
|
| | | List blendInList = blendIn(registerList, checkInList);
|
| | | SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visit_list_view().show(null, true);
|
| | | }
|
| | |
|
| | | public List blendIn(List registerList, List checkInList) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | public void addBitmap(final List<Bitmap> bitmapList, byte[] byteArray, int len) {
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.SURVEILLANCE_UPLOAD);
|
| | | params.addBodyParameter("base64Photo", Base64.encodeToString(byteArray, 0, len, Base64.DEFAULT));
|
| | | params.addBodyParameter("deviceCompanyId", BaseApplication.getInstance().getDevice().getCompanyId());
|
| | | params.addBodyParameter("deviceId", BaseApplication.getInstance().getDevice().getDeviceId());
|
| | | params.addBodyParameter("enterOrExit", CommonVariables.EnterOrExit.ENTER+"");
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | SurveillanceQueryItem item = getBean(SurveillanceQueryItem.class);
|
| | | if (item.getType() == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE
|
| | | || item.getType() == CommonVariables.Surveillance.VISIT_CHECK_IN_ITEM_TYPE
|
| | | ) {
|
| | | List<SurveillanceQueryItem> doubleList = new ArrayList<SurveillanceQueryItem>();
|
| | |
|
| | | List list = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visit_list_view().getPrevList();
|
| | | list.add(0, item);
|
| | |
|
| | | fillBlank(list, doubleList);
|
| | |
|
| | | SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visit_list_view().show(doubleList, true);
|
| | | }
|
| | |
|
| | | }
|
| | | });
|
| | | if (bitmapList != null && bitmapList.size() > 0) {
|
| | | //RegisterFragment.getInstance().get_fragment_register_choose_photo().setImageBitmap(bitmapList.get(0));
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | }
|
| | |
|
| | | private void fillBlank(List<SurveillanceQueryItem> list, List<SurveillanceQueryItem> doubleList) {
|
| | | doubleList.clear();
|
| | | public static class SurveillanceListThread extends Thread {
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | while (true) {
|
| | | MainActivity.getInstance().runOnUiThread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | List prevList = SurveillanceMng.getInstance().removeTimeoutItem(null);
|
| | | SurveillanceMng.getInstance().registerTopAndCheckInBottom(prevList);
|
| | | SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().show(prevList);
|
| | | }
|
| | | });
|
| | | Thread.sleep(1000*60*5);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private List<SurveillanceQueryItem> removeTimeoutItem(List<SurveillanceQueryItem> prevList) {
|
| | | if (prevList == null) {
|
| | | prevList = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().getPrevList();
|
| | | }
|
| | | List<SurveillanceQueryItem> newPrevList = new ArrayList();
|
| | | for (SurveillanceQueryItem item : prevList) {
|
| | | if (item.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
|
| | | Date now = new Date();
|
| | | Date createTime = item.getCreateTime();
|
| | | long secs = (now.getTime() - createTime.getTime()) / 1000 ;
|
| | | if (secs*1.0 / 60*5 >= 1) {
|
| | | continue;
|
| | | }
|
| | | newPrevList.add(item);
|
| | | }
|
| | | }
|
| | | return newPrevList;
|
| | | }
|
| | |
|
| | | public void addBitmap(final List<SurveillanceQueryItem> bitmapList, byte[] byteArray, int len, String cameraInOrOut) {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL +AppApi.SURVEILLANCE_UPLOAD);
|
| | | params.addBodyParameter("base64Photo", Base64.encodeToString(byteArray, 0, len, Base64.DEFAULT));
|
| | | params.addBodyParameter("deviceCompanyId", BaseApplication.getInstance().getDevice().getDeviceCompanyId());
|
| | | params.addBodyParameter("deviceId", BaseApplication.getInstance().getDevice().getDeviceId());
|
| | | params.addBodyParameter("InOrOutCamera", cameraInOrOut+"");
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | List<SurveillanceQueryItem> items = getList(SurveillanceQueryItem.class);
|
| | | List prevVisitorList = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().getPrevList();
|
| | | List prevAttendanceList = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_attendance_list_view().getPrevList();
|
| | |
|
| | | List newVisitorList = new ArrayList();
|
| | |
|
| | | List newAttendanceList = new ArrayList();
|
| | |
|
| | | for (int i = 0; items != null && i < items.size(); i++) {
|
| | | SurveillanceQueryItem item = items.get(i);
|
| | | int type = item.getRegisterOrCheckIn();
|
| | | if (type == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE
|
| | | || type == CommonVariables.Surveillance.VISIT_CHECK_IN_ITEM_TYPE
|
| | | ) {
|
| | | item.setCreateTime(new Date());
|
| | | newVisitorList.add(0, item);
|
| | | if (i < bitmapList.size()) {
|
| | | SurveillanceQueryItem surveillanceQueryItem = bitmapList.get(i);
|
| | | item.setBitmap(surveillanceQueryItem.getBitmap());
|
| | | item.setBase64Image(surveillanceQueryItem.getBase64Image());
|
| | | item.setNativeImg(surveillanceQueryItem.getNativeImg());
|
| | | item.setWidth(surveillanceQueryItem.getWidth());
|
| | | item.setHeight(surveillanceQueryItem.getHeight());
|
| | | }
|
| | | }
|
| | | if (type == CommonVariables.Surveillance.VISIT_ATTENDANCE_ITEM_TYPE) {
|
| | | newAttendanceList.add(item);
|
| | | if (i < bitmapList.size()) {
|
| | | SurveillanceQueryItem surveillanceQueryItem = bitmapList.get(i);
|
| | | item.setBitmap(surveillanceQueryItem.getBitmap());
|
| | | item.setBase64Image(surveillanceQueryItem.getBase64Image());
|
| | | item.setNativeImg(surveillanceQueryItem.getNativeImg());
|
| | | item.setWidth(surveillanceQueryItem.getWidth());
|
| | | item.setHeight(surveillanceQueryItem.getHeight());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (newVisitorList.size() > 0) {
|
| | | prevVisitorList.addAll(0, newVisitorList);
|
| | | registerTopAndCheckInBottom(prevVisitorList);
|
| | | SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().show(prevVisitorList);
|
| | | }
|
| | |
|
| | | if (newAttendanceList.size() > 0) {
|
| | | prevAttendanceList.addAll(0, newAttendanceList);
|
| | | if (prevAttendanceList.size() > 20) {
|
| | | prevAttendanceList = prevAttendanceList.subList(0, 20);
|
| | | }
|
| | | SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_attendance_list_view().show(prevAttendanceList);
|
| | | }
|
| | |
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public List getSurveillancePhotoList() {
|
| | | List<SurveillanceQueryItem> prevVisitorList = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().getPrevList();
|
| | | List<SurveillanceQueryItem> registerList = new ArrayList();
|
| | | int n = 9;
|
| | | for (SurveillanceQueryItem surveillanceQueryItem : prevVisitorList) {
|
| | | if (surveillanceQueryItem.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
|
| | | if (registerList.size() > n*2) {
|
| | | break;
|
| | | }
|
| | | surveillanceQueryItem.setSurveillancePhotoSelected(false);
|
| | | registerList.add(surveillanceQueryItem);
|
| | | }
|
| | | }
|
| | | SurveillanceQueryItem item;
|
| | | List items = new ArrayList();
|
| | | int m = 0;
|
| | | for (int i = 0; i < n*2; i++) {
|
| | | if (i % 2 == 0) {
|
| | | if (m < registerList.size()) {
|
| | | item = registerList.get(m);
|
| | | m++;
|
| | | } else {
|
| | | item = getBlankItem();
|
| | | }
|
| | | } else {
|
| | | if (n < registerList.size()) {
|
| | | item = registerList.get(n);
|
| | | n++;
|
| | | } else {
|
| | | item = getBlankItem();
|
| | | }
|
| | | }
|
| | | items.add(item);
|
| | | }
|
| | | return items;
|
| | | }
|
| | |
|
| | | private void registerTopAndCheckInBottom(List<SurveillanceQueryItem> list) {
|
| | | List<SurveillanceQueryItem> registerList = new ArrayList<SurveillanceQueryItem>();
|
| | | List<SurveillanceQueryItem> checkInList = new ArrayList<SurveillanceQueryItem>();
|
| | | removeDuplicateCheckIn(list);
|
| | | int i1 = 0, j = 0;
|
| | | int maxRegister = 50;
|
| | | int maxCheckIn = 50;
|
| | | for (SurveillanceQueryItem item : list) {
|
| | | if (item.getType() == Constant.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
|
| | | registerList.add(item);
|
| | | if (item.getRegisterOrCheckIn() == Constant.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
|
| | | if (i1 < maxRegister) {
|
| | | registerList.add(item);
|
| | | i1++;
|
| | | }
|
| | | }
|
| | | if (item.getType() == Constant.Surveillance.VISIT_CHECK_IN_ITEM_TYPE) {
|
| | | checkInList.add(item);
|
| | | 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++) {
|
| | |
| | | }
|
| | | n++;
|
| | | }
|
| | | doubleList.add(item);
|
| | | tempList.add(item);
|
| | | }
|
| | | list.clear();
|
| | | list.addAll(tempList);
|
| | | }
|
| | |
|
| | | private void removeDuplicateCheckIn(List<SurveillanceQueryItem> list) {
|
| | | List itemsToRemove = new ArrayList();
|
| | | Set<String> registerIds = new HashSet<>();
|
| | | for (SurveillanceQueryItem item : list) {
|
| | | 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());
|
| | | }
|
| | | }
|
| | | }
|
| | | list.removeAll(itemsToRemove);
|
| | | }
|
| | |
|
| | | private SurveillanceQueryItem getBlankItem() {
|
| | | SurveillanceQueryItem blankItem = new SurveillanceQueryItem();
|
| | | blankItem.setType(Constant.Surveillance.VISIT_BLANK_ITEM_TYPE);
|
| | | blankItem.setRegisterOrCheckIn(Constant.Surveillance.VISIT_BLANK_ITEM_TYPE);
|
| | | return blankItem;
|
| | | }
|
| | |
|