Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StatInfo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenyuling
StatInfo
Commits
1b2f9938
Commit
1b2f9938
authored
Aug 25, 2023
by
chenyuling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加多台设备IP
parent
642df084
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
217 additions
and
203 deletions
+217
-203
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-1
EnterAdapter.java
...ain/java/com/srthinker/statinfo/adapter/EnterAdapter.java
+8
-6
LeaveAdapter.java
...ain/java/com/srthinker/statinfo/adapter/LeaveAdapter.java
+9
-5
UpperDevicesCallback.java
...thinker/statinfo/listener/upper/UpperDevicesCallback.java
+1
-1
ApiManager.java
...ain/java/com/srthinker/statinfo/presenter/ApiManager.java
+70
-90
ApiQuest.java
.../main/java/com/srthinker/statinfo/presenter/ApiQuest.java
+69
-80
PersonEntityComparator.java
.../srthinker/statinfo/presenter/PersonEntityComparator.java
+14
-0
MainActivity.java
...rc/main/java/com/srthinker/statinfo/uis/MainActivity.java
+45
-20
No files found.
app/src/main/AndroidManifest.xml
View file @
1b2f9938
...
@@ -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"
/>
...
...
app/src/main/java/com/srthinker/statinfo/adapter/EnterAdapter.java
View file @
1b2f9938
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
;
}
}
}
app/src/main/java/com/srthinker/statinfo/adapter/LeaveAdapter.java
View file @
1b2f9938
...
@@ -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
();
}
}
}
}
app/src/main/java/com/srthinker/statinfo/listener/upper/UpperDevicesCallback.java
View file @
1b2f9938
...
@@ -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
has
Dis
Connect
,
int
type
);
void
onAllConnectStatus
(
boolean
hasConnect
,
int
type
);
}
}
app/src/main/java/com/srthinker/statinfo/presenter/ApiManager.java
View file @
1b2f9938
...
@@ -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
();
}
}
}
}
}
}
...
...
app/src/main/java/com/srthinker/statinfo/presenter/ApiQuest.java
View file @
1b2f9938
...
@@ -18,7 +18,6 @@ import java.util.LinkedHashMap;
...
@@ -18,7 +18,6 @@ import java.util.LinkedHashMap;
import
java.util.LinkedHashSet
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
public
class
ApiQuest
{
public
class
ApiQuest
{
...
@@ -57,14 +56,13 @@ public class ApiQuest {
...
@@ -57,14 +56,13 @@ public class ApiQuest {
String
username
=
config
.
getUsername
();
String
username
=
config
.
getUsername
();
String
password
=
config
.
getPassword
();
String
password
=
config
.
getPassword
();
String
serverIp
=
config
.
getServerIp
();
String
serverIp
=
config
.
getServerIp
();
boolean
isConnect
=
config
.
isConnect
();
if
(
i
==
0
&&
type
==
ENTER_TYPE
){
if
(
i
==
0
&&
type
==
ENTER_TYPE
){
oneEnterIp
=
serverIp
;
oneEnterIp
=
serverIp
;
}
}
if
(
type
==
ENTER_TYPE
){
if
(
type
==
ENTER_TYPE
){
startEnterIp
(
username
,
password
,
serverIp
);
startEnterIp
(
username
,
password
,
serverIp
);
}
else
if
(
type
==
LEAVE_TYPE
){
}
else
if
(
type
==
LEAVE_TYPE
){
startLeaveIp
(
username
,
password
,
serverIp
,
isConnect
);
startLeaveIp
(
username
,
password
,
serverIp
);
}
}
}
}
...
@@ -89,11 +87,17 @@ public class ApiQuest {
...
@@ -89,11 +87,17 @@ public class ApiQuest {
@Override
@Override
public
void
getPassInfo
(
List
<
PersonEntity
>
passEntities
,
int
type
)
{
public
void
getPassInfo
(
List
<
PersonEntity
>
passEntities
,
int
type
)
{
allEnterPass
.
addAll
(
passEntities
);
allEnterPass
.
addAll
(
passEntities
);
Set
<
PersonEntity
>
mergeList
=
new
LinkedHashSet
<>(
allEnterPass
);
for
(
PersonEntity
enterPass
:
allEnterPass
)
{
Log
.
i
(
TAG
,
"去重前getPassInfo: enterPass.time="
+
enterPass
.
getTimestamp
()+
",name="
+
enterPass
.
getPerson_name
());
}
LinkedHashSet
<
PersonEntity
>
mergeList
=
new
LinkedHashSet
<>(
allEnterPass
);
allEnterPass
=
new
ArrayList
<>(
mergeList
);
allEnterPass
=
new
ArrayList
<>(
mergeList
);
for
(
PersonEntity
enterPass
:
allEnterPass
)
{
for
(
PersonEntity
enterPass
:
allEnterPass
)
{
Log
.
i
(
TAG
,
"
getPassInfo:
name="
+
enterPass
.
getPerson_name
());
Log
.
i
(
TAG
,
"
去重后getPassInfo: enterPass.time="
+
enterPass
.
getTimestamp
()+
",
name="
+
enterPass
.
getPerson_name
());
}
}
/*for (PersonEntity enterPass : allEnterPass) {
Log.i(TAG, "getPassInfo: name="+enterPass.getPerson_name());
}*/
if
(
upperDevicesCallback
!=
null
)
{
if
(
upperDevicesCallback
!=
null
)
{
upperDevicesCallback
.
getAllPassInfo
(
allEnterPass
,
type
);
upperDevicesCallback
.
getAllPassInfo
(
allEnterPass
,
type
);
}
}
...
@@ -103,30 +107,38 @@ public class ApiQuest {
...
@@ -103,30 +107,38 @@ public class ApiQuest {
public
void
onConnectStatus
(
boolean
isConnect
,
int
type
)
{
public
void
onConnectStatus
(
boolean
isConnect
,
int
type
)
{
Log
.
i
(
TAG
,
"onConnectStatus: 接收到的连接状态:isConnect="
+
isConnect
+
",ip="
+
ip
);
Log
.
i
(
TAG
,
"onConnectStatus: 接收到的连接状态:isConnect="
+
isConnect
+
",ip="
+
ip
);
ThreadPool
.
getInstance
().
getThreadPoolExecutor
().
execute
(()
->
{
ThreadPool
.
getInstance
().
getThreadPoolExecutor
().
execute
(()
->
{
//修改状态
List
<
ConfigEntity
>
configEntities
=
ConfigHelper
.
getInstance
().
queryByTypeIp
(
type
,
ip
);
List
<
ConfigEntity
>
configEntities
=
ConfigHelper
.
getInstance
().
queryByTypeIp
(
type
,
ip
);
for
(
ConfigEntity
configEntity
:
configEntities
)
{
synchronized
(
configEntities
){
configEntity
.
setConnect
(
isConnect
);
for
(
ConfigEntity
configEntity
:
configEntities
)
{
configEntity
.
setConnect
(
isConnect
);
//Log.i(TAG, "onConnectStatus: 修改后:ip"+configEntity.getServerIp()+",isConnect="+configEntity.isConnect());
//更新ip接口状态
ConfigHelper
.
getInstance
().
update
(
configEntity
);
}
}
}
//更新ip接口状态
//获取最新状态
ConfigHelper
.
getInstance
().
update
(
configEntities
);
List
<
ConfigEntity
>
enterList
=
ConfigHelper
.
getInstance
().
queryByType
(
type
);
List
<
ConfigEntity
>
enterList
=
ConfigHelper
.
getInstance
().
queryByType
(
ENTER_TYPE
);
isEnterAllConnect
=
true
;
isEnterAllConnect
=
true
;
for
(
ConfigEntity
config
:
enterList
)
{
synchronized
(
enterList
){
boolean
connect
=
config
.
isConnect
();
for
(
ConfigEntity
config
:
enterList
)
{
if
(!
connect
){
//Log.i(TAG, "onConnectStatus: 数据库里面的数据:ip="+config.getServerIp()+",isConnect="+config.isConnect());
isEnterAllConnect
=
false
;
boolean
connect
=
config
.
isConnect
();
break
;
if
(!
connect
){
isEnterAllConnect
=
false
;
break
;
}
}
if
(
upperDevicesCallback
!=
null
)
{
upperDevicesCallback
.
onAllConnectStatus
(
isEnterAllConnect
,
type
);
}
}
}
if
(
upperDevicesCallback
!=
null
)
{
upperDevicesCallback
.
onAllConnectStatus
(
isEnterAllConnect
,
type
);
}
}
});
});
}
}
});
});
}
}
private
void
startLeaveIp
(
String
username
,
String
password
,
String
ip
,
boolean
isLastConnect
)
{
private
void
startLeaveIp
(
String
username
,
String
password
,
String
ip
)
{
//如果之前有过则停掉
//如果之前有过则停掉
/*if (leaveMgrHashMap.get(ip)!=null){
/*if (leaveMgrHashMap.get(ip)!=null){
ApiManager apiManager = leaveMgrHashMap.get(ip);
ApiManager apiManager = leaveMgrHashMap.get(ip);
...
@@ -141,29 +153,52 @@ public class ApiQuest {
...
@@ -141,29 +153,52 @@ 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
)
{
allLeavePass
.
addAll
(
passEntities
);
LinkedHashSet
<
PersonEntity
>
mergeList
=
new
LinkedHashSet
<>(
allLeavePass
);
allLeavePass
=
new
ArrayList
<>(
mergeList
);
/*for (PersonEntity leavePass : allLeavePass) {
Log.i(TAG, "getPassInfo: name="+leavePass.getPerson_name());
}*/
if
(
upperDevicesCallback
!=
null
)
{
upperDevicesCallback
.
getAllPassInfo
(
allLeavePass
,
type
);
}
}
}
@Override
@Override
public
void
onConnectStatus
(
boolean
isConnect
,
int
type
)
{
public
void
onConnectStatus
(
boolean
isConnect
,
int
type
)
{
Log
.
i
(
TAG
,
"onConnectStatus: 接收到的连接状态:isConnect="
+
isConnect
+
",ip="
+
ip
);
ThreadPool
.
getInstance
().
getThreadPoolExecutor
().
execute
(()
->
{
//修改状态
List
<
ConfigEntity
>
configEntities
=
ConfigHelper
.
getInstance
().
queryByTypeIp
(
type
,
ip
);
synchronized
(
configEntities
){
for
(
ConfigEntity
configEntity
:
configEntities
)
{
configEntity
.
setConnect
(
isConnect
);
//Log.i(TAG, "onConnectStatus: 修改后:ip"+configEntity.getServerIp()+",isConnect="+configEntity.isConnect());
//更新ip接口状态
ConfigHelper
.
getInstance
().
update
(
configEntity
);
}
}
//获取最新状态
List
<
ConfigEntity
>
leaveList
=
ConfigHelper
.
getInstance
().
queryByType
(
type
);
isLeaveAllConnect
=
true
;
synchronized
(
leaveList
){
for
(
ConfigEntity
config
:
leaveList
)
{
//Log.i(TAG, "onConnectStatus: 数据库里面的数据:ip="+config.getServerIp()+",isConnect="+config.isConnect());
boolean
connect
=
config
.
isConnect
();
if
(!
connect
){
isLeaveAllConnect
=
false
;
break
;
}
}
if
(
upperDevicesCallback
!=
null
)
{
upperDevicesCallback
.
onAllConnectStatus
(
isLeaveAllConnect
,
type
);
}
}
});
}
}
});
});
}
}
/*public void startLeaveApi(ConfigBean configBean){
if (configBean != null) {
//如果之前曾经有过的,则停掉之前的
if (leaveMgr!=null){
stopLeaveApi();
}
leaveMgr = new ApiManager(configBean.getUsername(), configBean.getPassword(), configBean.getServerIp(), LEAVE_TYPE);
if (leaveMgr != null) {
leaveMgr.start();
leaveMgr.setOnDeviceCallback(this);
}
}
}*/
public
void
stopApi
(){
public
void
stopApi
(){
stopApiByType
(
ENTER_TYPE
);
stopApiByType
(
ENTER_TYPE
);
...
@@ -183,57 +218,11 @@ public class ApiQuest {
...
@@ -183,57 +218,11 @@ public class ApiQuest {
mgrHashMap
.
clear
();
mgrHashMap
.
clear
();
}
}
/*public void stopEnterApi(){
for (Map.Entry<String, ApiManager> enterMgr : enterMgrHashMap.entrySet()) {
ApiManager enter = enterMgr.getValue();
if (enter!=null){
enter.stop();
enter.setOnDeviceCallback(null);
enter = null;
}
enterMgrHashMap.remove(enterMgr.getKey());
}
}
public void stopLeaveApi(){
for (Map.Entry<String, ApiManager> leaveMgr : leaveMgrHashMap.entrySet()) {
ApiManager leave = leaveMgr.getValue();
if (leave!=null){
leave.stop();
leave.setOnDeviceCallback(null);
leave = null;
}
leaveMgrHashMap.remove(leaveMgr.getKey());
}
}*/
/*private void stopEnterApi(){
if (enterMgr != null) {
enterMgr.stop();
enterMgr.setOnDeviceCallback(null);
enterMgr.setOnQueryPersonsCallback(null);
enterMgr = null;
}
}*/
/*private void stopLeaveApi(){
if (leaveMgr != null) {
leaveMgr.stop();
leaveMgr.setOnDeviceCallback(null);
leaveMgr.setOnQueryPersonsCallback(null);
leaveMgr = null;
}
}*/
public
void
queryPersons
(
QueryPersonCallback
callback
){
public
void
queryPersons
(
QueryPersonCallback
callback
){
if
(
enterMgrHashMap
.
size
()>
0
){
if
(
enterMgrHashMap
.
size
()>
0
){
ApiManager
oneEnterMgr
=
enterMgrHashMap
.
get
(
oneEnterIp
);
ApiManager
oneEnterMgr
=
enterMgrHashMap
.
get
(
oneEnterIp
);
oneEnterMgr
.
queryPersons
();
oneEnterMgr
.
queryPersons
();
oneEnterMgr
.
setOnQueryPersonsCallback
(
callback
);
oneEnterMgr
.
setOnQueryPersonsCallback
(
callback
);
}
}
/*if (enterMgr!=null){
enterMgr.queryPersons();
enterMgr.setOnQueryPersonsCallback(callback);
}*/
}
}
}
}
app/src/main/java/com/srthinker/statinfo/presenter/PersonEntityComparator.java
0 → 100644
View file @
1b2f9938
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
;
}
}
app/src/main/java/com/srthinker/statinfo/uis/MainActivity.java
View file @
1b2f9938
...
@@ -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
(
enterBean
s
);
List
<
PersonEntity
>
enterListNo
=
StatSize
.
filterList
(
passEntitie
s
);
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
(
enterBean
s
);
groupEnterHashMap
=
getGroupSizeHashMap
(
passEntitie
s
);
updatePresentSize
(
groupEnterHashMap
,
groupLeaveHashMap
);
updatePresentSize
(
groupEnterHashMap
,
groupLeaveHashMap
);
}
}
}
}
}
}
}
else
if
(
type
==
LEAVE_TYPE
){
}
else
if
(
type
==
LEAVE_TYPE
){
leaveBeans
=
passEntities
;
//
leaveBeans = passEntities;
if
(
leaveBean
s
!=
null
)
{
if
(
passEntitie
s
!=
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
.
setDat
eList
(
leaveBean
s
);
leaveAdapter
.
setDat
aList
(
passEntitie
s
);
//更新人员情况(是否要根据id去重)
//更新人员情况(是否要根据id去重)
if
(
NEED_NO_REPET
)
{
if
(
NEED_NO_REPET
)
{
List
<
PersonEntity
>
leaveListNo
=
StatSize
.
filterList
(
leaveBean
s
);
List
<
PersonEntity
>
leaveListNo
=
StatSize
.
filterList
(
passEntitie
s
);
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
(
leaveBean
s
);
groupLeaveHashMap
=
getGroupSizeHashMap
(
passEntitie
s
);
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
(!
has
Dis
Connect
)
{
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
(!
has
Dis
Connect
)
{
if
(!
hasConnect
)
{
mBinding
.
tvLeaveError
.
setVisibility
(
View
.
VISIBLE
);
mBinding
.
tvLeaveError
.
setVisibility
(
View
.
VISIBLE
);
}
else
{
}
else
{
mBinding
.
tvLeaveError
.
setVisibility
(
View
.
GONE
);
mBinding
.
tvLeaveError
.
setVisibility
(
View
.
GONE
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment