| | |
| | | package cn.com.basic.face.service;
|
| | |
|
| | | import android.util.Base64;
|
| | |
|
| | | import org.xutils.http.RequestParams;
|
| | | import org.xutils.x;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashSet;
|
| | | import java.io.File;
|
| | | import java.io.FileWriter;
|
| | | 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.common.SqliteSqlBean;
|
| | | import cn.com.basic.face.discern.query.item.SurveillanceQueryItem;
|
| | | import cn.com.basic.face.fragment.SurveillanceFragment;
|
| | | import cn.com.basic.face.discern.query.item.UnknownQueryItem;
|
| | | import cn.com.basic.face.service.sqlite.SurveillanceDao;
|
| | | import cn.com.basic.face.util.AppApi;
|
| | | import cn.com.basic.face.util.Constant;
|
| | | import cn.com.basic.face.util.FileUtil;
|
| | | import cn.com.basic.face.util.SqliteSqlUtil;
|
| | | import cn.com.basic.face.util.SurveillanceQueryItemUtil;
|
| | | import cn.com.basic.face.util.UnknownSurveillanceQueryItemUtil;
|
| | |
|
| | | public class SurveillanceMng {
|
| | |
|
| | |
| | | return instance;
|
| | | }
|
| | |
|
| | | public void findSurveillanceBottomList(final boolean isVisit) {
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | public void addOfflineBitmap(final List<SurveillanceQueryItem> bitmapList, final byte[] rawData, final String cameraInOrOut) {
|
| | | SurveillanceDao.getInstance().saveOfflineUnknownToLocal(bitmapList, rawData, cameraInOrOut);
|
| | | UnknownSurveillanceQueryItemUtil.getInstance().addItems(bitmapList);
|
| | | }
|
| | |
|
| | | public static class SurveillanceListThread extends Thread {
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | while (true) {
|
| | | MainActivity.getInstance().runOnUiThread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | if (BaseApplication.getInstance().networkAvailable()) {
|
| | | SurveillanceQueryItemUtil.getInstance().removeTimeoutItemAndShow();
|
| | | } else {
|
| | | UnknownSurveillanceQueryItemUtil.getInstance().removeTimeoutItemAndShow();
|
| | | }
|
| | | }
|
| | | });
|
| | | Thread.sleep(1000*60*5);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public void addBitmap(final List<SurveillanceQueryItem> bitmapList, byte[] byteArray, int len, String cameraInOrOut) {
|
| | | int fileIndex = 1;
|
| | |
|
| | | public void addBitmap(final List<SurveillanceQueryItem> bitmapList, final byte[] byteArray, int len, final String cameraInOrOut, byte[] surveillancePhotoBytes) {
|
| | | 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 prevList = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visit_list_view().getPrevList();
|
| | | try {
|
| | | if (fileIndex > 30) {
|
| | | fileIndex = 1;
|
| | | }
|
| | | fileIndex++;
|
| | | RequestParams params = new RequestParams();
|
| | | File rawSurveillancePhotoFile = FileUtil.writeToFile("rawSurveillancePhotoFile_"+fileIndex, byteArray);
|
| | | File surveillancePhotoFile = FileUtil.writeToFile("surveillancePhotoFile_"+fileIndex, surveillancePhotoBytes);
|
| | |
|
| | | List newList = new ArrayList();
|
| | | params.addBodyParameter("InOrOutCamera", cameraInOrOut + "");
|
| | | params.addBodyParameter("deviceId", BaseApplication.getInstance().getAndroidDevice().getDeviceId());
|
| | | params.addBodyParameter("rawSurveillancePhoto", rawSurveillancePhotoFile);
|
| | | params.addBodyParameter("surveillancePhoto", surveillancePhotoFile);
|
| | |
|
| | | 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
|
| | | ) {
|
| | | newList.add(0, item);
|
| | | if (i < bitmapList.size()) {
|
| | | SurveillanceQueryItem surveillanceQueryItem = bitmapList.get(i);
|
| | | item.setBitmap(surveillanceQueryItem.getBitmap());
|
| | | item.setBase64Image(surveillanceQueryItem.getBase64Image());
|
| | | item.setWidth(surveillanceQueryItem.getWidth());
|
| | | item.setHeight(surveillanceQueryItem.getHeight());
|
| | | }
|
| | | File path = BaseApplication.getInstance().getFilesDir();
|
| | | if (!rawSurveillancePhotoFile.exists()) {
|
| | | rawSurveillancePhotoFile.createNewFile();
|
| | | }
|
| | | File f0 = new File(path, "f0");
|
| | | if (!f0.exists()) {
|
| | | f0.createNewFile();
|
| | | }
|
| | |
|
| | | FileWriter fw0 = new FileWriter(f0);
|
| | | fw0.write("test1");
|
| | | fw0.close();
|
| | | params.setUri(AppApi.BASE_URL + AppApi.SURVEILLANCE_UPLOAD);
|
| | | params.addBodyParameter("f0", f0);
|
| | | params.addBodyParameter("rawSurveillancePhoto", rawSurveillancePhotoFile);
|
| | | params.addBodyParameter("deviceCompanyId", BaseApplication.getInstance().getAndroidDevice().getCompanyId());
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | @Override
|
| | | public void success() {
|
| | | try {
|
| | | SqliteSqlUtil.insert(getExtraList(SqliteSqlBean.class));
|
| | | SurveillanceQueryItemUtil.getInstance().addItems(resultBean.getList(SurveillanceQueryItem.class), bitmapList, cameraInOrOut);
|
| | | } catch(Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | if (newList.size() > 0) {
|
| | | prevList.addAll(0, newList);
|
| | | registerTopAndCheckInBottom(prevList);
|
| | | SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visit_list_view().show(prevList);
|
| | | }
|
| | |
|
| | | }
|
| | | });
|
| | | });
|
| | | }catch(Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | 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 = 20;
|
| | | int maxCheckIn = 20;
|
| | | for (SurveillanceQueryItem item : list) {
|
| | | 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++;
|
| | | }
|
| | | }
|
| | | }
|
| | | public void removePhotoFileWhenStorageIsSlow() {
|
| | |
|
| | | 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);
|
| | | }
|
| | | 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.setRegisterOrCheckIn(Constant.Surveillance.VISIT_BLANK_ITEM_TYPE);
|
| | | return blankItem;
|
| | | }
|
| | |
|
| | | }
|