Commit 1b2f9938 authored by chenyuling's avatar chenyuling

添加多台设备IP

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