Commit 75dcf957 authored by chenyuling's avatar chenyuling

"解决第二天保留第一天数据的问题,优化放松更新数据的条件"

parent 86253c4b
Pipeline #2287 canceled with stages
......@@ -5,6 +5,6 @@ import com.srthinker.statinfo.database.entity.PersonEntity;
import java.util.List;
public interface DeviceCallback {
void getPassInfo(List<PersonEntity> passEntities,int type);
void getPassInfo(List<PersonEntity> passEntities,int type,String nowDate);
void onConnectStatus(boolean isConnect,int type);
}
......@@ -50,6 +50,7 @@ public class ApiManager {
private boolean lastConnect = false;
private QueryPersonCallback queryPersonsCallback;
private DevicePortCallback devicePortCallback;
private String begin_time;
public ApiManager(String username, String password, String serverIp,int type){
......@@ -184,9 +185,10 @@ public class ApiManager {
queryPass();
//Log.i(TAG, "run: totalPassLists.size()="+totalPassLists.size());
//Log.i(TAG, "run: lastPassTotal="+lastPassTotal);
if (totalPassLists.size()!=0&&totalPassLists.size()!= lastPassTotal){
//&&totalPassLists.size()!= lastPassTotal
if (totalPassLists.size()!=0){
if (callback != null) {
callback.getPassInfo(totalPassLists,type);
callback.getPassInfo(totalPassLists,type,begin_time);
}
}
lastPassTotal = totalPassLists.size();
......@@ -215,7 +217,7 @@ public class ApiManager {
private void queryPass(){
//获取历史通行记录
// Log.i(TAG, "start: passApi="+passApi);
String begin_time = DateUtil.getDateFormattedZone(new Date(), "yyyy-MM-dd");
begin_time = DateUtil.getDateFormattedZone(new Date(), "yyyy-MM-dd");
String end_time = DateUtil.getDateFormattedZone(DateUtil.getNextDate(), "yyyy-MM-dd");
if (TextUtils.isEmpty(sessionId)){
//handler.post(this);
......
......@@ -15,6 +15,8 @@ import com.srthinker.statinfo.listener.upper.UpperDevicesCallback;
import com.srthinker.statinfo.listener.upper.UpperDevicesPortCallback;
import com.srthinker.statinfo.util.common.ThreadPool;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
......@@ -35,6 +37,8 @@ public class ApiQuest {
private UpperDevicesCallback upperDevicesCallback;
private static LinkedHashMap<String,ApiManager> enterMgrHashMap = new LinkedHashMap<>();
private static LinkedHashMap<String,ApiManager> leaveMgrHashMap = new LinkedHashMap<>();
private static LinkedHashMap<String,List<PersonEntity>> allEnterPassMap= new LinkedHashMap<>();
private static LinkedHashMap<String,List<PersonEntity>> allLeavePassMap= new LinkedHashMap<>();
private String oneEnterIp;
private UpperDevicesPortCallback upperDevicesPortCallback;
......@@ -59,9 +63,11 @@ public class ApiQuest {
if (type==ENTER_TYPE){
isEnterAllConnect = false;
allEnterPass = new ArrayList<>();
allEnterPassMap = new LinkedHashMap<>();
}else if (type==LEAVE_TYPE){
isLeaveAllConnect = false;
allLeavePass = new ArrayList<>();
allLeavePassMap = new LinkedHashMap<>();
}
}
......@@ -89,7 +95,7 @@ public class ApiQuest {
}
}
}
private String lastEnterDate = "";
private void startEnterIp(String username, String password, String ip) {
Log.i(TAG, "startEnterIp: 访问接口的ip="+ip);
/*//如果之前有过则停掉
......@@ -111,9 +117,21 @@ public class ApiQuest {
});
enterMgr.setOnDeviceCallback(new DeviceCallback() {
@Override
public void getPassInfo(List<PersonEntity> passEntities, int type) {
public void getPassInfo(List<PersonEntity> passEntities, int type,String nowDate) {
synchronized (allEnterPass){
allEnterPass.addAll(passEntities);
if (!StringUtils.equals(lastEnterDate,nowDate)){
//allEnterPass.clear(); //清空数据
allEnterPassMap.clear();
lastEnterDate = nowDate; //更新lastDate
}
allEnterPass.clear(); //清空数据
allEnterPassMap.put(ip,passEntities);
for (Map.Entry<String, List<PersonEntity>> entry : allEnterPassMap.entrySet()) {
if (entry != null) {
allEnterPass.addAll(entry.getValue());
}
}
//allEnterPass.addAll(passEntities);
/*for (PersonEntity enterPass : allEnterPass) {
Log.i(TAG, "去重前getPassInfo: enterPass.time="+enterPass.getTimestamp()+",name="+enterPass.getPerson_name());
}*/
......@@ -167,6 +185,7 @@ public class ApiQuest {
});
}
private String lastLeaveDate = "";
private void startLeaveIp(String username, String password, String ip) {
//如果之前有过则停掉
/*if (leaveMgrHashMap.get(ip)!=null){
......@@ -187,9 +206,21 @@ public class ApiQuest {
});
leaveMgr.setOnDeviceCallback(new DeviceCallback() {
@Override
public void getPassInfo(List<PersonEntity> passEntities, int type) {
public void getPassInfo(List<PersonEntity> passEntities, int type,String nowDate) {
synchronized (allLeavePass){
allLeavePass.addAll(passEntities);
if (!StringUtils.equals(lastLeaveDate,nowDate)){
//allLeavePass.clear(); //清空数据
allLeavePassMap.clear();
lastLeaveDate = nowDate; //更新lastDate
}
allLeavePass.clear(); //清空数据
allLeavePassMap.put(ip,passEntities);
for (Map.Entry<String, List<PersonEntity>> entry : allLeavePassMap.entrySet()) {
if (entry != null) {
allLeavePass.addAll(entry.getValue());
}
}
//allLeavePass.addAll(passEntities);
PersonEntityComparator comparator = new PersonEntityComparator();
Collections.sort(allLeavePass,comparator);
LinkedHashSet<PersonEntity> mergeList = new LinkedHashSet<>(allLeavePass);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment