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; ...@@ -5,6 +5,6 @@ import com.srthinker.statinfo.database.entity.PersonEntity;
import java.util.List; import java.util.List;
public interface DeviceCallback { 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); void onConnectStatus(boolean isConnect,int type);
} }
...@@ -50,6 +50,7 @@ public class ApiManager { ...@@ -50,6 +50,7 @@ public class ApiManager {
private boolean lastConnect = false; private boolean lastConnect = false;
private QueryPersonCallback queryPersonsCallback; private QueryPersonCallback queryPersonsCallback;
private DevicePortCallback devicePortCallback; private DevicePortCallback devicePortCallback;
private String begin_time;
public ApiManager(String username, String password, String serverIp,int type){ public ApiManager(String username, String password, String serverIp,int type){
...@@ -184,9 +185,10 @@ public class ApiManager { ...@@ -184,9 +185,10 @@ public class ApiManager {
queryPass(); queryPass();
//Log.i(TAG, "run: totalPassLists.size()="+totalPassLists.size()); //Log.i(TAG, "run: totalPassLists.size()="+totalPassLists.size());
//Log.i(TAG, "run: lastPassTotal="+lastPassTotal); //Log.i(TAG, "run: lastPassTotal="+lastPassTotal);
if (totalPassLists.size()!=0&&totalPassLists.size()!= lastPassTotal){ //&&totalPassLists.size()!= lastPassTotal
if (totalPassLists.size()!=0){
if (callback != null) { if (callback != null) {
callback.getPassInfo(totalPassLists,type); callback.getPassInfo(totalPassLists,type,begin_time);
} }
} }
lastPassTotal = totalPassLists.size(); lastPassTotal = totalPassLists.size();
...@@ -215,7 +217,7 @@ public class ApiManager { ...@@ -215,7 +217,7 @@ public class ApiManager {
private void queryPass(){ private void queryPass(){
//获取历史通行记录 //获取历史通行记录
// Log.i(TAG, "start: passApi="+passApi); // 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"); String end_time = DateUtil.getDateFormattedZone(DateUtil.getNextDate(), "yyyy-MM-dd");
if (TextUtils.isEmpty(sessionId)){ if (TextUtils.isEmpty(sessionId)){
//handler.post(this); //handler.post(this);
......
...@@ -15,6 +15,8 @@ import com.srthinker.statinfo.listener.upper.UpperDevicesCallback; ...@@ -15,6 +15,8 @@ import com.srthinker.statinfo.listener.upper.UpperDevicesCallback;
import com.srthinker.statinfo.listener.upper.UpperDevicesPortCallback; import com.srthinker.statinfo.listener.upper.UpperDevicesPortCallback;
import com.srthinker.statinfo.util.common.ThreadPool; import com.srthinker.statinfo.util.common.ThreadPool;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
...@@ -35,6 +37,8 @@ public class ApiQuest { ...@@ -35,6 +37,8 @@ public class ApiQuest {
private UpperDevicesCallback upperDevicesCallback; private UpperDevicesCallback upperDevicesCallback;
private static LinkedHashMap<String,ApiManager> enterMgrHashMap = new LinkedHashMap<>(); private static LinkedHashMap<String,ApiManager> enterMgrHashMap = new LinkedHashMap<>();
private static LinkedHashMap<String,ApiManager> leaveMgrHashMap = 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 String oneEnterIp;
private UpperDevicesPortCallback upperDevicesPortCallback; private UpperDevicesPortCallback upperDevicesPortCallback;
...@@ -59,9 +63,11 @@ public class ApiQuest { ...@@ -59,9 +63,11 @@ public class ApiQuest {
if (type==ENTER_TYPE){ if (type==ENTER_TYPE){
isEnterAllConnect = false; isEnterAllConnect = false;
allEnterPass = new ArrayList<>(); allEnterPass = new ArrayList<>();
allEnterPassMap = new LinkedHashMap<>();
}else if (type==LEAVE_TYPE){ }else if (type==LEAVE_TYPE){
isLeaveAllConnect = false; isLeaveAllConnect = false;
allLeavePass = new ArrayList<>(); allLeavePass = new ArrayList<>();
allLeavePassMap = new LinkedHashMap<>();
} }
} }
...@@ -89,7 +95,7 @@ public class ApiQuest { ...@@ -89,7 +95,7 @@ public class ApiQuest {
} }
} }
} }
private String lastEnterDate = "";
private void startEnterIp(String username, String password, String ip) { private void startEnterIp(String username, String password, String ip) {
Log.i(TAG, "startEnterIp: 访问接口的ip="+ip); Log.i(TAG, "startEnterIp: 访问接口的ip="+ip);
/*//如果之前有过则停掉 /*//如果之前有过则停掉
...@@ -111,9 +117,21 @@ public class ApiQuest { ...@@ -111,9 +117,21 @@ public class ApiQuest {
}); });
enterMgr.setOnDeviceCallback(new DeviceCallback() { enterMgr.setOnDeviceCallback(new DeviceCallback() {
@Override @Override
public void getPassInfo(List<PersonEntity> passEntities, int type) { public void getPassInfo(List<PersonEntity> passEntities, int type,String nowDate) {
synchronized (allEnterPass){ 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) { /*for (PersonEntity enterPass : allEnterPass) {
Log.i(TAG, "去重前getPassInfo: enterPass.time="+enterPass.getTimestamp()+",name="+enterPass.getPerson_name()); Log.i(TAG, "去重前getPassInfo: enterPass.time="+enterPass.getTimestamp()+",name="+enterPass.getPerson_name());
}*/ }*/
...@@ -167,6 +185,7 @@ public class ApiQuest { ...@@ -167,6 +185,7 @@ public class ApiQuest {
}); });
} }
private String lastLeaveDate = "";
private void startLeaveIp(String username, String password, String ip) { private void startLeaveIp(String username, String password, String ip) {
//如果之前有过则停掉 //如果之前有过则停掉
/*if (leaveMgrHashMap.get(ip)!=null){ /*if (leaveMgrHashMap.get(ip)!=null){
...@@ -187,9 +206,21 @@ public class ApiQuest { ...@@ -187,9 +206,21 @@ public class ApiQuest {
}); });
leaveMgr.setOnDeviceCallback(new DeviceCallback() { leaveMgr.setOnDeviceCallback(new DeviceCallback() {
@Override @Override
public void getPassInfo(List<PersonEntity> passEntities, int type) { public void getPassInfo(List<PersonEntity> passEntities, int type,String nowDate) {
synchronized (allLeavePass){ 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(); PersonEntityComparator comparator = new PersonEntityComparator();
Collections.sort(allLeavePass,comparator); Collections.sort(allLeavePass,comparator);
LinkedHashSet<PersonEntity> mergeList = new LinkedHashSet<>(allLeavePass); 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