Commit 1b2f9938 authored by chenyuling's avatar chenyuling

添加多台设备IP

parent 642df084
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
android:name=".uis.MainActivity" android:name=".uis.MainActivity"
android:configChanges="keyboardHidden|orientation" android:configChanges="keyboardHidden|orientation"
android:exported="true" android:exported="true"
android:windowSoftInputMode="stateHidden|adjustPan"> android:windowSoftInputMode="adjustPan">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
......
package com.srthinker.statinfo.adapter; package com.srthinker.statinfo.adapter;
import android.content.Context; import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -22,7 +21,6 @@ public class EnterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> ...@@ -22,7 +21,6 @@ public class EnterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public EnterAdapter(Context context, List<PersonEntity> pData){ public EnterAdapter(Context context, List<PersonEntity> pData){
this.context = context; this.context = context;
this.personEntities = pData; this.personEntities = pData;
Log.i(TAG, "EnterAdapter: 更新列表,size="+ pData.size());
} }
@NonNull @NonNull
@Override @Override
...@@ -35,9 +33,9 @@ public class EnterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> ...@@ -35,9 +33,9 @@ public class EnterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
ItemHolder itemHolder = (ItemHolder) holder; ItemHolder itemHolder = (ItemHolder) holder;
PersonEntity peopleBean = personEntities.get(position); PersonEntity peopleBean = personEntities.get(position);
Log.i(TAG, "onBindViewHolder: peopleBeans.size="+ personEntities.size()); // Log.i(TAG, "onBindViewHolder: peopleBeans.size="+ personEntities.size());
if (peopleBean!=null){ if (peopleBean!=null){
Log.i(TAG, "onBindViewHolder: name="+peopleBean.getPerson_name()); // Log.i(TAG, "onBindViewHolder: name="+peopleBean.getPerson_name());
itemHolder.mBinding.tvInfo.setText(peopleBean.getTimestamp()+" "+peopleBean.getPerson_name()); itemHolder.mBinding.tvInfo.setText(peopleBean.getTimestamp()+" "+peopleBean.getPerson_name());
} }
} }
...@@ -58,10 +56,14 @@ public class EnterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> ...@@ -58,10 +56,14 @@ public class EnterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
public void setDataList(List<PersonEntity> peopleBeans){ public void setDataList(List<PersonEntity> peopleBeans){
Log.i(TAG, "setDataList: 更新列表,size="+peopleBeans.size()); //Log.i(TAG, "setDataList: 更新列表,size="+peopleBeans.size());
// this.peopleBeans=new ArrayList<>(); // this.peopleBeans=new ArrayList<>();
this.personEntities.clear(); this.personEntities.clear();
this.personEntities = peopleBeans; this.personEntities.addAll(peopleBeans);
this.notifyDataSetChanged(); this.notifyDataSetChanged();
} }
public List<PersonEntity> getDataList(){
return personEntities;
}
} }
...@@ -12,8 +12,9 @@ import com.srthinker.statinfo.databinding.ItemLeaveBinding; ...@@ -12,8 +12,9 @@ import com.srthinker.statinfo.databinding.ItemLeaveBinding;
import java.util.List; import java.util.List;
public class LeaveAdapter extends RecyclerView.Adapter { public class LeaveAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final String TAG = "LeaveAdapter";
private final Context context; private final Context context;
private List<PersonEntity> peopleBeans; private List<PersonEntity> peopleBeans;
...@@ -42,7 +43,7 @@ public class LeaveAdapter extends RecyclerView.Adapter { ...@@ -42,7 +43,7 @@ public class LeaveAdapter extends RecyclerView.Adapter {
return peopleBeans!=null&&peopleBeans.size()>0?peopleBeans.size():0; return peopleBeans!=null&&peopleBeans.size()>0?peopleBeans.size():0;
} }
private class ItemHolder extends RecyclerView.ViewHolder { private static class ItemHolder extends RecyclerView.ViewHolder {
private final com.srthinker.statinfo.databinding.ItemLeaveBinding mBinding; private final com.srthinker.statinfo.databinding.ItemLeaveBinding mBinding;
...@@ -52,8 +53,11 @@ public class LeaveAdapter extends RecyclerView.Adapter { ...@@ -52,8 +53,11 @@ public class LeaveAdapter extends RecyclerView.Adapter {
} }
} }
public void setDateList(List<PersonEntity> peopleBeans){ public void setDataList(List<PersonEntity> peopleBeans){
this.peopleBeans = peopleBeans; //this.peopleBeans = peopleBeans;
notifyDataSetChanged(); this.peopleBeans.clear();
this.peopleBeans.addAll(peopleBeans);
//Log.i(TAG, "setDataList: size="+this.peopleBeans.size());
this.notifyDataSetChanged();
} }
} }
...@@ -6,5 +6,5 @@ import java.util.List; ...@@ -6,5 +6,5 @@ import java.util.List;
public interface UpperDevicesCallback { public interface UpperDevicesCallback {
void getAllPassInfo(List<PersonEntity> passAllEntities, int type); void getAllPassInfo(List<PersonEntity> passAllEntities, int type);
void onAllConnectStatus(boolean hasDisConnect,int type); void onAllConnectStatus(boolean hasConnect,int type);
} }
...@@ -75,6 +75,7 @@ public class ApiManager { ...@@ -75,6 +75,7 @@ public class ApiManager {
public void start(){ public void start(){
isRunning = true; isRunning = true;
isFirstStatus = true; isFirstStatus = true;
lastConnect = false;
handler.post(authThreadRunnable); handler.post(authThreadRunnable);
//ThreadPool.getInstance().getThreadPoolExecutor().execute(passRecordRunnable); //ThreadPool.getInstance().getThreadPoolExecutor().execute(passRecordRunnable);
handler.post(passThreadRunnable); handler.post(passThreadRunnable);
...@@ -82,67 +83,55 @@ public class ApiManager { ...@@ -82,67 +83,55 @@ public class ApiManager {
private Runnable authRunnable = new Runnable() { private Runnable authRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
//进行设备登录 //进行设备登录
// LoginResp loginResp = authApi.login("admin", "a12345"); // LoginResp loginResp = authApi.login("admin", "a12345");
LoginResp loginResp = null; LoginResp loginResp = null;
//boolean authConnect = false;
try { try {
loginResp = authApi.login(username, password); loginResp = authApi.login(username, password);
if (loginResp != null) {
if(loginResp.getStatus() != 200) {
updateLastConnect(false);
}catch (ApiClientException e2){ //登录出错,打印错误信息
System.out.println(JSONObject.toJSONString(loginResp));
} catch (Exception e) { return;
e.printStackTrace(); }
if (lastConnect){ sessionId = loginResp.getSessionId();
//只要连接成功都传避免出现意外,因为鉴权成功后也只访问一次
if (callback != null) { if (callback != null) {
callback.onConnectStatus(false,type); lastConnect = true;
lastConnect = false; callback.onConnectStatus(true, type);
} }
//updateLastConnect(true);
Log.i(TAG, "run: sessionId==>"+ sessionId);
} }
}catch (ApiClientException e2){
updateLastConnect(false);
} catch (Exception e) {
e.printStackTrace();
updateLastConnect(false);
Log.i(TAG, "run: authRunnable抛异常:ip="+serverIp); Log.i(TAG, "run: authRunnable抛异常:ip="+serverIp);
if (isRunning){ if (isRunning){
handler.postDelayed(authThreadRunnable,2000); handler.postDelayed(authThreadRunnable,2000);
} }
}finally {
if (isFirstStatus){
if (callback != null) {
callback.onConnectStatus(false,type);
lastConnect = false;
}
isFirstStatus = false;
}
} }
if (loginResp != null) { }
if(loginResp.getStatus() != 200) { };
if (lastConnect) {
if (callback != null) {
callback.onConnectStatus(false,type);
lastConnect = false;
}
}
//登录出错,打印错误信息
System.out.println(JSONObject.toJSONString(loginResp));
return;
}
sessionId = loginResp.getSessionId();
if (!lastConnect){
if (callback!=null){
callback.onConnectStatus(true,type);
lastConnect = true;
}
}
Log.i(TAG, "run: sessionId==>"+ sessionId);
//第一次和状态有变化的时候传
private void updateLastConnect(boolean newConnectStatus) {
if (lastConnect != newConnectStatus || isFirstStatus) {
lastConnect = newConnectStatus;
if (callback != null) {
callback.onConnectStatus(lastConnect, type);
} }
isFirstStatus = false;
} }
}; }
public void queryPersons(){ public void queryPersons(){
ThreadPool.getInstance().getThreadPoolExecutor().execute(() -> { ThreadPool.getInstance().getThreadPoolExecutor().execute(() -> {
...@@ -212,61 +201,52 @@ public class ApiManager { ...@@ -212,61 +201,52 @@ public class ApiManager {
PassQueryBean passQueryResp = null; PassQueryBean passQueryResp = null;
try { try {
passQueryResp = passApi.query(max_pass_limit,pass_offset,"desc", begin_time, end_time); passQueryResp = passApi.query(max_pass_limit,pass_offset,"desc", begin_time, end_time);
} catch (ApiClientException e2){ if (passQueryResp!=null){
//Log.i(TAG, "run: passQueryResp="+passQueryResp.toString());
} catch (Exception e) { if (passQueryResp.getPaging()==null&&passQueryResp.getData()==null&&passQueryResp.getQuery_id()==null){
Log.i(TAG, "run: passRecordRunnable抛异常"); //重新再登录鉴权一下:
e.printStackTrace(); Log.i(TAG, "run: passQueryResp不为空,内容为空时也重新鉴权");
if (lastConnect) { if (isRunning) {
if (callback != null) { handler.post(authThreadRunnable);
callback.onConnectStatus(false,type);
lastConnect = false;
}
}
}
if (passQueryResp!=null){
//Log.i(TAG, "run: passQueryResp="+passQueryResp.toString());
if (passQueryResp.getPaging()==null&&passQueryResp.getData()==null&&passQueryResp.getQuery_id()==null){
//重新再登录鉴权一下:
Log.i(TAG, "run: passQueryResp不为空,内容为空时也重新鉴权");
if (isRunning) {
handler.post(authThreadRunnable);
}
//清空重新循环
person_offset = 0;
pass_offset = 0;
}
List<PassQueryBean.DataBean> dataBeanList = passQueryResp.getData();
List<PersonEntity> passBeans = new ArrayList<>();
if (dataBeanList!=null){
for (PassQueryBean.DataBean dataBean : dataBeanList) {
PersonEntity passBean = new PersonEntity();
passBean.setId(dataBean.getPerson_id());
passBean.setPerson_name(dataBean.getPerson_name());
String timestamp = dataBean.getTimestamp();
String timeString = DateUtil.zoneToDateString(timestamp, "HH:mm");
passBean.setTimestamp(timeString);
passBeans.add(passBean);
}
totalPassLists.addAll(passBeans);
if (!lastConnect){
if (callback != null) {
callback.onConnectStatus(true,type);
lastConnect = true;
} }
//清空重新循环
person_offset = 0;
pass_offset = 0;
} }
List<PassQueryBean.DataBean> dataBeanList = passQueryResp.getData();
List<PersonEntity> passBeans = new ArrayList<>();
if (dataBeanList!=null){
for (PassQueryBean.DataBean dataBean : dataBeanList) {
PersonEntity passBean = new PersonEntity();
passBean.setId(dataBean.getPerson_id());
passBean.setPerson_name(dataBean.getPerson_name());
String timestamp = dataBean.getTimestamp();
String timeString = DateUtil.zoneToDateString(timestamp, "HH:mm");
passBean.setTimestamp(timeString);
passBeans.add(passBean);
}
totalPassLists.addAll(passBeans);
updateLastConnect(true);
} }
PassQueryBean.PagingBean paging = passQueryResp.getPaging(); PassQueryBean.PagingBean paging = passQueryResp.getPaging();
if (paging!=null){ if (paging!=null){
passTotal = paging.getTotal(); passTotal = paging.getTotal();
passQuerySize = paging.getLimit(); passQuerySize = paging.getLimit();
pass_offset += passQuerySize; pass_offset += passQuerySize;
while (passQuerySize>0 && passQuerySize<passTotal&&pass_offset<passTotal){ while (passQuerySize>0 && passQuerySize<passTotal&&pass_offset<passTotal){
queryPass(); queryPass();
}
} }
} }
} catch (ApiClientException e2){
updateLastConnect(false);
} catch (Exception e) {
Log.i(TAG, "run: passRecordRunnable抛异常");
updateLastConnect(false);
e.printStackTrace();
} }
} }
} }
......
package com.srthinker.statinfo.presenter;
import com.srthinker.statinfo.database.entity.PersonEntity;
import java.util.Comparator;
public class PersonEntityComparator implements Comparator<PersonEntity> {
@Override
public int compare(PersonEntity p1, PersonEntity p2) {
//return time2.compareTo(time1);
return 0;
}
}
...@@ -361,21 +361,23 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -361,21 +361,23 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
} }
private void updatePassInfo(List<PersonEntity> passEntities, int type) { private void updatePassInfo(List<PersonEntity> passEntities, int type) {
Log.i(TAG, "updatePassInfo: 获取的总数="+passEntities.size());
for (PersonEntity passEntity : passEntities) { for (PersonEntity passEntity : passEntities) {
Log.i(TAG, "updatePassInfo: 获取到的name="+passEntity.getPerson_name()); Log.i(TAG, "updatePassInfo: 获取到的name="+passEntity.getPerson_name());
} }
if (type ==ENTER_TYPE){ if (type ==ENTER_TYPE){
enterBeans = passEntities; if (passEntities != null) {
if (enterBeans != null) {
if (enterAdapter != null) { if (enterAdapter != null) {
int size = enterBeans.size(); int size = passEntities.size();
Log.i(TAG, "updatePassInfo: 进来的人数="+size);
if (size!=lastEnterSize){ if (size!=lastEnterSize){
//更新进出情况 //更新进出情况
enterAdapter.setDataList(enterBeans); //enterBeans = passEntities; 全局变量直接赋值会出现问题
enterBeans.clear();
enterBeans.addAll(passEntities);
enterAdapter.setDataList(passEntities);
//更新人员情况(是否要根据id去重) //更新人员情况(是否要根据id去重)
if (NEED_NO_REPET) { if (NEED_NO_REPET) {
List<PersonEntity> enterListNo = StatSize.filterList(enterBeans); List<PersonEntity> enterListNo = StatSize.filterList(passEntities);
lastEnterSize = enterListNo.size(); lastEnterSize = enterListNo.size();
}else{ }else{
lastEnterSize = size; lastEnterSize = size;
...@@ -385,24 +387,26 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -385,24 +387,26 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
mBinding.nvLeave.setNumber(lastLeaveSize); mBinding.nvLeave.setNumber(lastLeaveSize);
mBinding.nvPresent.setNumber(lastPresentSize); mBinding.nvPresent.setNumber(lastPresentSize);
//更新分组情况(是否要根据id去重) //更新分组情况(是否要根据id去重)
groupEnterHashMap = getGroupSizeHashMap(enterBeans); groupEnterHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap); updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
} }
} }
}else if (type == LEAVE_TYPE){ }else if (type == LEAVE_TYPE){
leaveBeans = passEntities; //leaveBeans = passEntities;
if (leaveBeans != null) { if (passEntities != null) {
if (leaveAdapter != null) { if (leaveAdapter != null) {
int size = passEntities.size(); int size = passEntities.size();
//进出有变化时才更新 //进出有变化时才更新
if (size!=lastLeaveSize){ if (size!=lastLeaveSize){
leaveBeans.clear();
leaveBeans.addAll(passEntities);
//更新进出情况 //更新进出情况
leaveAdapter.setDateList(leaveBeans); leaveAdapter.setDataList(passEntities);
//更新人员情况(是否要根据id去重) //更新人员情况(是否要根据id去重)
if (NEED_NO_REPET) { if (NEED_NO_REPET) {
List<PersonEntity> leaveListNo = StatSize.filterList(leaveBeans); List<PersonEntity> leaveListNo = StatSize.filterList(passEntities);
lastLeaveSize = leaveListNo.size(); lastLeaveSize = leaveListNo.size();
}else{ }else{
lastLeaveSize = size; lastLeaveSize = size;
...@@ -412,11 +416,12 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -412,11 +416,12 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
mBinding.nvLeave.setNumber(lastLeaveSize); mBinding.nvLeave.setNumber(lastLeaveSize);
mBinding.nvPresent.setNumber(lastPresentSize); mBinding.nvPresent.setNumber(lastPresentSize);
//更新分组情况(是否要根据id去重) //更新分组情况(是否要根据id去重)
groupLeaveHashMap = getGroupSizeHashMap(leaveBeans); groupLeaveHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap); updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
} }
} }
} }
} }
...@@ -543,15 +548,28 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -543,15 +548,28 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
ApiQuest.startEnterApi(enterConfigList,this); ApiQuest.startEnterApi(enterConfigList,this);
List<ConfigBean> leaveConfigList = SharedUtil.getInstance(this).readSharedList(LEAVE_TYPE, ConfigBean.class, ""); List<ConfigBean> leaveConfigList = SharedUtil.getInstance(this).readSharedList(LEAVE_TYPE, ConfigBean.class, "");
ApiQuest.startLeaveApi(leaveConfigList,this);*/ ApiQuest.startLeaveApi(leaveConfigList,this);*/
runOnUiThread(() -> { /*runOnUiThread(() -> {
List<ConfigEntity> enterConfigList = ConfigHelper.getInstance().queryByType(ENTER_TYPE); List<ConfigEntity> enterConfigList = ConfigHelper.getInstance().queryByType(ENTER_TYPE);
ApiQuest.getInstance().startApi(enterConfigList,ENTER_TYPE); ApiQuest.getInstance().startApi(enterConfigList,ENTER_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this); ApiQuest.getInstance().setOnUpperDevicesCallback(this);
List<ConfigEntity> leaveConfigList = ConfigHelper.getInstance().queryByType(LEAVE_TYPE); List<ConfigEntity> leaveConfigList = ConfigHelper.getInstance().queryByType(LEAVE_TYPE);
ApiQuest.getInstance().startApi(leaveConfigList,LEAVE_TYPE); ApiQuest.getInstance().startApi(leaveConfigList,LEAVE_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this); ApiQuest.getInstance().setOnUpperDevicesCallback(this);
}); });*/
/*ThreadPool.getInstance().getThreadPoolExecutor().execute(() -> {
List<ConfigEntity> enterConfigList = ConfigHelper.getInstance().queryByType(ENTER_TYPE);
ApiQuest.getInstance().startApi(enterConfigList,ENTER_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
List<ConfigEntity> leaveConfigList = ConfigHelper.getInstance().queryByType(LEAVE_TYPE);
ApiQuest.getInstance().startApi(leaveConfigList,LEAVE_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
});*/
List<ConfigEntity> enterConfigList = ConfigHelper.getInstance().queryByType(ENTER_TYPE);
ApiQuest.getInstance().startApi(enterConfigList,ENTER_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
List<ConfigEntity> leaveConfigList = ConfigHelper.getInstance().queryByType(LEAVE_TYPE);
ApiQuest.getInstance().startApi(leaveConfigList,LEAVE_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
} }
@Override @Override
...@@ -572,10 +590,16 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -572,10 +590,16 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
Log.i(TAG, "onUpdateConfig: pass="+config.getPassword()); Log.i(TAG, "onUpdateConfig: pass="+config.getPassword());
Log.i(TAG, "onUpdateConfig: ip="+config.getServerIp()); Log.i(TAG, "onUpdateConfig: ip="+config.getServerIp());
} }
runOnUiThread(()->{ /*runOnUiThread(()->{
ApiQuest.getInstance().startApi(configList,type); ApiQuest.getInstance().startApi(configList,type);
ApiQuest.getInstance().setOnUpperDevicesCallback(this); ApiQuest.getInstance().setOnUpperDevicesCallback(this);
}); });*/
/*ThreadPool.getInstance().getThreadPoolExecutor().execute(()->{
ApiQuest.getInstance().startApi(configList,type);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
});*/
ApiQuest.getInstance().startApi(configList,type);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
} }
@Override @Override
...@@ -586,17 +610,18 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -586,17 +610,18 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
} }
@Override @Override
public void onAllConnectStatus(boolean hasDisConnect, int type) { public void onAllConnectStatus(boolean hasConnect, int type) {
Log.i(TAG, "onAllConnectStatus: 接收到的连接状态 hasConnect="+hasConnect);
runOnUiThread(()->{ runOnUiThread(()->{
if (type==ENTER_TYPE){ if (type==ENTER_TYPE){
if (!hasDisConnect) { if (!hasConnect) {
mBinding.tvEnterError.setVisibility(View.VISIBLE); mBinding.tvEnterError.setVisibility(View.VISIBLE);
}else{ }else{
mBinding.tvEnterError.setVisibility(View.GONE); mBinding.tvEnterError.setVisibility(View.GONE);
} }
}else if (type == LEAVE_TYPE){ }else if (type == LEAVE_TYPE){
if (!hasDisConnect) { if (!hasConnect) {
mBinding.tvLeaveError.setVisibility(View.VISIBLE); mBinding.tvLeaveError.setVisibility(View.VISIBLE);
}else{ }else{
mBinding.tvLeaveError.setVisibility(View.GONE); mBinding.tvLeaveError.setVisibility(View.GONE);
......
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