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
a8d8ed01
Commit
a8d8ed01
authored
Aug 08, 2023
by
chenyuling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处理人数
parent
bc659d3f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
37 deletions
+94
-37
StatSize.java
.../main/java/com/srthinker/statinfo/presenter/StatSize.java
+39
-0
MainActivity.java
...rc/main/java/com/srthinker/statinfo/uis/MainActivity.java
+4
-4
DateUtil.java
...ain/java/com/srthinker/statinfo/util/common/DateUtil.java
+19
-0
Utils.java
...c/main/java/com/srthinker/statinfo/util/common/Utils.java
+0
-32
UtilTest.java
app/src/test/java/com/srthinker/statinfo/UtilTest.java
+32
-1
No files found.
app/src/main/java/com/srthinker/statinfo/presenter/StatSize.java
0 → 100644
View file @
a8d8ed01
package
com
.
srthinker
.
statinfo
.
presenter
;
import
com.srthinker.statinfo.database.entity.PersonEntity
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
StatSize
{
//id和时间相同的进行去重过滤
public
static
List
<
PersonEntity
>
filterList
(
List
<
PersonEntity
>
personEntityList
){
List
<
PersonEntity
>
filterPersonList
=
new
ArrayList
<>();
if
(
personEntityList
!=
null
)
{
for
(
PersonEntity
personEntity
:
personEntityList
)
{
boolean
shouldAdd
=
true
;
for
(
PersonEntity
entity
:
filterPersonList
)
{
if
(
equals
(
personEntity
.
getId
(),
entity
.
getId
())&&
equals
(
personEntity
.
getTimestamp
(),
entity
.
getTimestamp
())){
shouldAdd
=
false
;
break
;
}
}
if
(
shouldAdd
){
filterPersonList
.
add
(
personEntity
);
}
}
}
return
filterPersonList
;
}
private
static
boolean
equals
(
String
str1
,
String
str2
)
{
if
(
str1
==
null
&&
str2
==
null
)
{
return
true
;
}
else
if
(
str1
==
null
||
str2
==
null
)
{
return
false
;
}
else
{
return
str1
.
equals
(
str2
);
}
}
}
app/src/main/java/com/srthinker/statinfo/uis/MainActivity.java
View file @
a8d8ed01
...
...
@@ -50,6 +50,7 @@ import com.srthinker.statinfo.listener.QueryPersonCallback;
import
com.srthinker.statinfo.presenter.ApiManager
;
import
com.srthinker.statinfo.presenter.ApiQuest
;
import
com.srthinker.statinfo.presenter.RealTimeClock
;
import
com.srthinker.statinfo.presenter.StatSize
;
import
com.srthinker.statinfo.uis.fragment.ConfigDlgFragment
;
import
com.srthinker.statinfo.update.MDownloadCallBack
;
import
com.srthinker.statinfo.update.NetworkViewModel
;
...
...
@@ -100,7 +101,6 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
private
HashMap
<
Integer
,
Integer
>
groupPresentHashMap
=
null
;
private
boolean
isPermission
;
public
static
boolean
NEED_NO_REPET
=
true
;
//是否需要去重,false:不需要,true:需要
private
boolean
NEED_SEE_NEXT
=
true
;
//去重是怎么去,true只去重相邻的,false则全部去重
@Override
...
...
@@ -377,7 +377,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
enterAdapter
.
setDateList
(
enterBeans
);
//更新人员情况(是否要根据id去重)
if
(
NEED_NO_REPET
)
{
List
<
PersonEntity
>
enterListNo
=
Utils
.
removeDuplicates
(
enterBeans
,
"id"
,
NEED_SEE_NEXT
);
List
<
PersonEntity
>
enterListNo
=
StatSize
.
filterList
(
enterBeans
);
lastEnterSize
=
enterListNo
.
size
();
}
else
{
lastEnterSize
=
size
;
...
...
@@ -404,7 +404,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
leaveAdapter
.
setDateList
(
leaveBeans
);
//更新人员情况(是否要根据id去重)
if
(
NEED_NO_REPET
)
{
List
<
PersonEntity
>
leaveListNo
=
Utils
.
removeDuplicates
(
leaveBeans
,
"id"
,
NEED_SEE_NEXT
);
List
<
PersonEntity
>
leaveListNo
=
StatSize
.
filterList
(
leaveBeans
);
lastLeaveSize
=
leaveListNo
.
size
();
}
else
{
lastLeaveSize
=
size
;
...
...
@@ -431,7 +431,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
private
HashMap
<
Integer
,
Integer
>
getGroupSizeHashMap
(
List
<
PersonEntity
>
personEntityList
)
{
HashMap
<
Integer
,
Integer
>
groupSizeHashMap
=
new
HashMap
<>();
if
(
NEED_NO_REPET
)
{
personEntityList
=
Utils
.
removeDuplicates
(
personEntityList
,
"id"
,
NEED_SEE_NEXT
);
personEntityList
=
StatSize
.
filterList
(
personEntityList
);
}
if
(
mQueryPersonList
!=
null
)
{
for
(
PersonEntity
entity
:
mQueryPersonList
)
{
...
...
app/src/main/java/com/srthinker/statinfo/util/common/DateUtil.java
View file @
a8d8ed01
...
...
@@ -2,6 +2,7 @@ package com.srthinker.statinfo.util.common;
import
android.text.TextUtils
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
...
...
@@ -313,4 +314,22 @@ public class DateUtil {
Date
date
=
fromLocalZoneFormattedDateTime
(
zoneString
,
DEFAULT_FORMAT
);
return
getFormattedDateTime
(
date
,
format
);
}
//时间相差为多少s,先将字符串转化成date再比较
public
static
long
getTimeDifference
(
String
format
,
String
time1
,
String
time2
)
{
DateFormat
dateFormat
=
new
SimpleDateFormat
(
format
);
try
{
Date
date1
=
dateFormat
.
parse
(
time1
);
Date
date2
=
dateFormat
.
parse
(
time2
);
if
(
date1
!=
null
&&
date2
!=
null
)
{
long
diffInMillis
=
Math
.
abs
(
date1
.
getTime
()
-
date2
.
getTime
());
long
diffInSeconds
=
diffInMillis
/
1000
;
return
diffInSeconds
;
}
return
-
1
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
-
1
;
}
}
}
app/src/main/java/com/srthinker/statinfo/util/common/Utils.java
View file @
a8d8ed01
...
...
@@ -273,40 +273,8 @@ public class Utils {
return
distinctList
;
}
public
static
<
T
>
List
<
T
>
removeDuplicates
(
List
<
T
>
originalList
,
String
fieldName
,
boolean
seeNextOne
)
{
Set
<
Object
>
set
=
new
LinkedHashSet
<>();
List
<
T
>
distinctList
=
new
ArrayList
<>();
if
(
seeNextOne
)
{
for
(
int
i
=
0
;
i
<
originalList
.
size
();
i
++)
{
T
item
=
originalList
.
get
(
i
);
Object
fieldValue
=
getFieldValue
(
item
,
fieldName
);
if
(
i
<
originalList
.
size
()-
1
){
T
nextItem
=
originalList
.
get
(
i
+
1
);
Object
nextFileValue
=
getFieldValue
(
nextItem
,
fieldName
);
if
(!
fieldValue
.
equals
(
nextFileValue
)){
distinctList
.
add
(
item
);
}
else
{
i
++;
distinctList
.
add
(
nextItem
);
}
}
else
{
distinctList
.
add
(
item
);
}
}
}
else
{
for
(
T
item
:
originalList
)
{
Object
fieldValue
=
getFieldValue
(
item
,
fieldName
);
if
(!
set
.
contains
(
fieldValue
))
{
set
.
add
(
fieldValue
);
distinctList
.
add
(
item
);
}
}
}
return
distinctList
;
}
private
static
Object
getFieldValue
(
Object
obj
,
String
fieldName
)
{
try
{
Field
field
=
obj
.
getClass
().
getDeclaredField
(
fieldName
);
...
...
app/src/test/java/com/srthinker/statinfo/UtilTest.java
View file @
a8d8ed01
package
com
.
srthinker
.
statinfo
;
import
com.srthinker.statinfo.database.entity.PersonEntity
;
import
com.srthinker.statinfo.presenter.StatSize
;
import
com.srthinker.statinfo.util.common.DateUtil
;
import
com.srthinker.statinfo.util.common.Utils
;
import
org.junit.Test
;
...
...
@@ -9,7 +11,7 @@ import java.util.ArrayList;
import
java.util.List
;
public
class
UtilTest
{
@Test
/*
@Test
public void noRepet(){
List<PersonEntity> personEntities = new ArrayList<>();
for (int i = 0; i < 4; i++) {
...
...
@@ -27,6 +29,35 @@ public class UtilTest {
for (PersonEntity personEntity : personEntities1) {
System.out.println("去重后:id="+personEntity.getId()+" name="+personEntity.getPerson_name()+" time="+personEntity.getTimestamp());
}
}*/
@Test
public
void
filter
(){
List
<
PersonEntity
>
personEntities
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
PersonEntity
person
=
new
PersonEntity
();
person
.
setId
(
"1"
);
person
.
setPerson_name
(
"王大崔"
);
person
.
setTimestamp
(
"11:0"
+
0
);
if
(
i
==
3
){
person
.
setTimestamp
(
"11:0"
+
i
);
}
personEntities
.
add
(
person
);
}
for
(
PersonEntity
personEntity
:
personEntities
)
{
System
.
out
.
println
(
"去重前:id="
+
personEntity
.
getId
()+
" name="
+
personEntity
.
getPerson_name
()+
" time="
+
personEntity
.
getTimestamp
());
}
List
<
PersonEntity
>
personEntities2
=
Utils
.
reverseList
(
personEntities
);
List
<
PersonEntity
>
personEntities1
=
StatSize
.
filterList
(
personEntities2
);
for
(
PersonEntity
personEntity
:
personEntities1
)
{
System
.
out
.
println
(
"去重后:id="
+
personEntity
.
getId
()+
" name="
+
personEntity
.
getPerson_name
()+
" time="
+
personEntity
.
getTimestamp
());
}
}
@Test
public
void
getDiffer
(){
long
timeDifference
=
DateUtil
.
getTimeDifference
(
"HH:mm"
,
""
,
"10:01"
);
System
.
out
.
println
(
"相差为"
+
timeDifference
);
}
...
...
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