Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
attendance-performance-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
attendance-performance-platform
Commits
6c3f621c
Commit
6c3f621c
authored
Mar 18, 2024
by
廖旭伟
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
8cdaa173
c993d21a
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
278 additions
and
287 deletions
+278
-287
attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventAfterTaskImpl.java
.../mortals/xhx/daemon/task/SyncDoorsEventAfterTaskImpl.java
+4
-101
attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventByDevicesTaskImpl.java
...tals/xhx/daemon/task/SyncDoorsEventByDevicesTaskImpl.java
+11
-116
attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventTaskImpl.java
...a/com/mortals/xhx/daemon/task/SyncDoorsEventTaskImpl.java
+31
-1
attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventWeekTaskImpl.java
...m/mortals/xhx/daemon/task/SyncDoorsEventWeekTaskImpl.java
+72
-46
attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/AttendanceRecordHikService.java
...module/attendance/service/AttendanceRecordHikService.java
+5
-0
attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/impl/AttendanceRecordHikServiceImpl.java
...tendance/service/impl/AttendanceRecordHikServiceImpl.java
+8
-21
attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/web/AttendanceRecordHikController.java
.../module/attendance/web/AttendanceRecordHikController.java
+2
-1
attendance-performance-manager/src/main/java/com/mortals/xhx/module/door/service/DoorService.java
...java/com/mortals/xhx/module/door/service/DoorService.java
+11
-0
attendance-performance-manager/src/main/java/com/mortals/xhx/module/door/service/impl/DoorServiceImpl.java
...mortals/xhx/module/door/service/impl/DoorServiceImpl.java
+134
-1
No files found.
attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventAfterTaskImpl.java
View file @
6c3f621c
...
@@ -23,6 +23,7 @@ import com.mortals.xhx.module.staff.model.StaffEntity;
...
@@ -23,6 +23,7 @@ import com.mortals.xhx.module.staff.model.StaffEntity;
import
com.mortals.xhx.module.staff.service.StaffService
;
import
com.mortals.xhx.module.staff.service.StaffService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
...
@@ -50,6 +51,9 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
...
@@ -50,6 +51,9 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
@Autowired
@Autowired
private
AttendanceStatService
attendanceStatService
;
private
AttendanceStatService
attendanceStatService
;
@Value
(
"${hik.host:}"
)
protected
String
hikhost
;
@Override
@Override
public
void
excuteTask
(
ITask
task
)
throws
AppException
{
public
void
excuteTask
(
ITask
task
)
throws
AppException
{
...
@@ -63,7 +67,6 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
...
@@ -63,7 +67,6 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
if
(
in
)
{
if
(
in
)
{
calculateAttendByDay
();
calculateAttendByDay
();
}
}
//统计当日
//统计当日
log
.
info
(
"统计当日考勤"
);
log
.
info
(
"统计当日考勤"
);
attendanceStatService
.
homeStat
(
null
);
attendanceStatService
.
homeStat
(
null
);
...
@@ -80,7 +83,6 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
...
@@ -80,7 +83,6 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
userEntity
.
setCreateTime
(
new
Date
());
userEntity
.
setCreateTime
(
new
Date
());
context
.
setUser
(
userEntity
);
context
.
setUser
(
userEntity
);
AttendanceRecordHikQuery
recordHikQuery
=
new
AttendanceRecordHikQuery
();
AttendanceRecordHikQuery
recordHikQuery
=
new
AttendanceRecordHikQuery
();
// Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
// Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
// recordHikQuery.setAttendanceDateStart(DateUtils.getCurrStrDate());
// recordHikQuery.setAttendanceDateStart(DateUtils.getCurrStrDate());
recordHikQuery
.
setAttendanceDateStart
(
DateUtil
.
today
());
recordHikQuery
.
setAttendanceDateStart
(
DateUtil
.
today
());
...
@@ -92,105 +94,6 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
...
@@ -92,105 +94,6 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
}
}
}
}
private
void
syncDoorEvents
()
{
DoorEventReq
doorEventReq
=
new
DoorEventReq
();
List
<
Integer
>
eventTypes
=
new
ArrayList
<>();
eventTypes
.
add
(
196885
);
eventTypes
.
add
(
196887
);
eventTypes
.
add
(
196893
);
eventTypes
.
add
(
196888
);
eventTypes
.
add
(
196889
);
eventTypes
.
add
(
196890
);
eventTypes
.
add
(
196891
);
doorEventReq
.
setEventTypes
(
eventTypes
);
// 获取当天的开始时间
// Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
Date
todayStart
=
DateUtil
.
beginOfDay
(
new
Date
());
// 获取当天的结束时间
Date
todayEnd
=
DateUtil
.
endOfDay
(
new
Date
());
doorEventReq
.
setStartTime
(
todayStart
);
doorEventReq
.
setEndTime
(
todayEnd
);
doorEventReq
.
setPageNo
(
1
);
doorEventReq
.
setPageSize
(
1
);
Rest
<
DoorEventDataInfo
>
doorEventsRest
=
hikDoorService
.
getDoorEvents
(
doorEventReq
);
log
.
info
(
"doorEventsRest:{} msg:{}"
,
doorEventsRest
.
getCode
(),
doorEventsRest
.
getMsg
());
if
(
doorEventsRest
.
getCode
()
==
YesNoEnum
.
YES
.
getValue
())
{
//分页获取考勤数据
Integer
total
=
doorEventsRest
.
getData
().
getTotal
();
int
pageCount
=
PageUtil
.
totalPage
(
total
,
1000
);
for
(
int
i
=
1
;
i
<=
pageCount
;
i
++)
{
doorEventReq
.
setPageNo
(
i
);
doorEventReq
.
setPageSize
(
1000
);
doorEventsRest
=
hikDoorService
.
getDoorEvents
(
doorEventReq
);
// log.info("doorEventsRest:{} msg:{},page:{}", doorEventsRest.getCode(), doorEventsRest.getMsg(), doorEventReq.getPageNo());
getDoorEvents
(
doorEventsRest
);
}
}
}
private
void
getDoorEvents
(
Rest
<
DoorEventDataInfo
>
doorEventsRest
)
{
//同步当前考勤数据
List
<
AttendanceRecordHikEntity
>
attRecords
=
doorEventsRest
.
getData
().
getList
().
stream
().
map
(
item
->
{
AttendanceRecordHikEntity
recordHikEntity
=
new
AttendanceRecordHikEntity
();
recordHikEntity
.
initAttrValue
();
if
(
ObjectUtils
.
isEmpty
(
item
.
getJobNo
()))
{
log
.
info
(
"jobNo is null ==>{}"
,
JSON
.
toJSONString
(
item
));
return
null
;
}
StaffEntity
staffCache
=
staffService
.
getExtCache
(
StrUtil
.
padPre
(
item
.
getJobNo
(),
8
,
"0"
));
if
(
ObjectUtils
.
isEmpty
(
staffCache
))
{
log
.
info
(
"staff is null !staffCode:{}"
,
item
.
getJobNo
());
return
null
;
}
recordHikEntity
.
setStaffId
(
staffCache
.
getId
());
recordHikEntity
.
setStaffName
(
staffCache
.
getName
());
recordHikEntity
.
setWorkNum
(
staffCache
.
getWorkNum
());
recordHikEntity
.
setDeptId
(
staffCache
.
getDeptId
());
recordHikEntity
.
setDeptName
(
staffCache
.
getDeptName
());
recordHikEntity
.
setSalaId
(
staffCache
.
getSalaId
());
recordHikEntity
.
setSalaName
(
staffCache
.
getSalaName
());
recordHikEntity
.
setPositionId
(
staffCache
.
getPositionId
());
recordHikEntity
.
setPositionName
(
staffCache
.
getPositionName
());
recordHikEntity
.
setAttendanceDate
(
item
.
getEventTime
());
recordHikEntity
.
setAttendanceAddress
(
item
.
getDoorName
());
recordHikEntity
.
setEventSource
(
"门禁点"
);
recordHikEntity
.
setRemark
(
item
.
getEventId
());
recordHikEntity
.
setCreateTime
(
new
Date
());
recordHikEntity
.
setCreateUserName
(
"系统管理员"
);
recordHikEntity
.
setCreateUserId
(
1L
);
return
recordHikEntity
;
}).
filter
(
f
->
f
!=
null
).
collect
(
Collectors
.
toList
());
log
.
info
(
"attRecords size:{}"
,
attRecords
.
size
());
List
<
String
>
eventIds
=
attRecords
.
parallelStream
().
filter
(
f
->
!
ObjectUtils
.
isEmpty
(
f
)
&&
!
ObjectUtils
.
isEmpty
(
f
.
getRemark
())).
map
(
i
->
i
.
getRemark
()).
collect
(
Collectors
.
toList
());
//查询当天考勤记录是否有重复的 有的 则不添加
AttendanceRecordHikQuery
recordHikQuery
=
new
AttendanceRecordHikQuery
();
recordHikQuery
.
setAttendanceDateStart
(
DateUtil
.
format
(
DateUtil
.
beginOfDay
(
new
Date
()),
"yyyy-MM-dd"
));
recordHikQuery
.
setAttendanceDateEnd
(
DateUtil
.
format
(
DateUtil
.
beginOfDay
(
new
Date
()),
"yyyy-MM-dd"
));
recordHikQuery
.
setRemarkList
(
eventIds
);
Set
<
String
>
eventIdSet
=
recordHikService
.
find
(
recordHikQuery
).
parallelStream
().
map
(
i
->
i
.
getRemark
()).
collect
(
Collectors
.
toSet
());
//去重 时分秒打卡的 也要去掉重复。
List
<
AttendanceRecordHikEntity
>
saveRecordList
=
attRecords
.
stream
().
filter
(
f
->
!
eventIdSet
.
contains
(
f
.
getRemark
())).
collect
(
Collectors
.
toList
());
if
(!
ObjectUtils
.
isEmpty
(
saveRecordList
))
{
//单个插入 去掉重复时间段的打卡记录
for
(
AttendanceRecordHikEntity
recordHikEntity
:
saveRecordList
)
{
try
{
recordHikService
.
getDao
().
insert
(
recordHikEntity
);
}
catch
(
Exception
e
)
{
//log.error("基础考勤数据保存异常", e.getMessage());
}
}
}
log
.
info
(
"saveRecordList size:{}"
,
saveRecordList
.
size
());
}
@Override
@Override
public
void
stopTask
(
ITask
task
)
throws
AppException
{
public
void
stopTask
(
ITask
task
)
throws
AppException
{
...
...
attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventByDevicesTaskImpl.java
View file @
6c3f621c
package
com.mortals.xhx.daemon.task
;
package
com.mortals.xhx.daemon.task
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.PageUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.framework.service.ICacheService
;
...
@@ -12,16 +10,12 @@ import com.mortals.framework.service.ITaskExcuteService;
...
@@ -12,16 +10,12 @@ import com.mortals.framework.service.ITaskExcuteService;
import
com.mortals.framework.util.DataUtil
;
import
com.mortals.framework.util.DataUtil
;
import
com.mortals.xhx.common.code.DwMinorEnum
;
import
com.mortals.xhx.common.code.DwMinorEnum
;
import
com.mortals.xhx.common.code.YesNoEnum
;
import
com.mortals.xhx.common.code.YesNoEnum
;
import
com.mortals.xhx.common.key.RedisKey
;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity
;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity
;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery
;
import
com.mortals.xhx.module.attendance.service.AttendanceRecordHikService
;
import
com.mortals.xhx.module.attendance.service.AttendanceRecordHikService
;
import
com.mortals.xhx.module.door.model.DoorEntity
;
import
com.mortals.xhx.module.door.model.DoorEntity
;
import
com.mortals.xhx.module.door.model.DoorQuery
;
import
com.mortals.xhx.module.door.model.DoorQuery
;
import
com.mortals.xhx.module.door.service.DoorService
;
import
com.mortals.xhx.module.door.service.DoorService
;
import
com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq
;
import
com.mortals.xhx.module.hik.door.model.req.door.HikDoorEventReq
;
import
com.mortals.xhx.module.hik.door.model.req.door.HikDoorEventReq
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.info.EventInfo
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.info.EventInfo
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.info.StruTime
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.info.StruTime
;
import
com.mortals.xhx.module.hik.door.service.IHikDoorService
;
import
com.mortals.xhx.module.hik.door.service.IHikDoorService
;
...
@@ -35,7 +29,6 @@ import org.springframework.util.ObjectUtils;
...
@@ -35,7 +29,6 @@ import org.springframework.util.ObjectUtils;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.ZoneId
;
import
java.time.ZonedDateTime
;
import
java.time.ZonedDateTime
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
...
@@ -74,15 +67,22 @@ public class SyncDoorsEventByDevicesTaskImpl implements ITaskExcuteService {
...
@@ -74,15 +67,22 @@ public class SyncDoorsEventByDevicesTaskImpl implements ITaskExcuteService {
}
else
{
}
else
{
day
=
0
;
day
=
0
;
}
}
Date
beginDateTime
=
DateUtil
.
parseDateTime
(
DateUtil
.
today
()
+
" 08:00:00"
);
Date
endDateTime
=
DateUtil
.
parseDateTime
(
DateUtil
.
today
()
+
" 20:30:00"
);
//boolean in = DateUtil.isIn(new Date(), beginDateTime, endDateTime);
HikDoorEventReq
hikDoorEventReq
=
new
HikDoorEventReq
();
//当前时间前一个小时
// Date startTime = DateUtil.offsetHour(new Date(), -1).toJdkDate();
Date
startTime
=
DateUtil
.
offsetDay
(
new
Date
(),
-
1
).
toJdkDate
();
Date
endTime
=
new
Date
();
hikDoorEventReq
.
setStartTime
(
startTime
);
hikDoorEventReq
.
setEndTime
(
endTime
);
boolean
in
=
true
;
boolean
in
=
true
;
if
(
in
)
{
if
(
in
)
{
List
<
DoorEntity
>
doorEntities
=
doorService
.
find
(
new
DoorQuery
());
List
<
DoorEntity
>
doorEntities
=
doorService
.
find
(
new
DoorQuery
());
for
(
DoorEntity
doorEntity
:
doorEntities
)
{
for
(
DoorEntity
doorEntity
:
doorEntities
)
{
syncDoorEvents
(
doorEntity
);
doorService
.
syncDoorDeviceEvents
(
doorEntity
,
hikDoorEventReq
);
// syncDoorEvents(doorEntity);
}
}
}
}
}
}
...
@@ -192,111 +192,6 @@ public class SyncDoorsEventByDevicesTaskImpl implements ITaskExcuteService {
...
@@ -192,111 +192,6 @@ public class SyncDoorsEventByDevicesTaskImpl implements ITaskExcuteService {
}
}
private
void
syncDoorEvents
()
{
DoorEventReq
doorEventReq
=
new
DoorEventReq
();
List
<
Integer
>
eventTypes
=
new
ArrayList
<>();
eventTypes
.
add
(
196885
);
eventTypes
.
add
(
196887
);
eventTypes
.
add
(
196893
);
eventTypes
.
add
(
196888
);
eventTypes
.
add
(
196889
);
eventTypes
.
add
(
196890
);
eventTypes
.
add
(
196891
);
doorEventReq
.
setEventTypes
(
eventTypes
);
// 获取当天的开始时间
//Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
Date
todayStart
=
DateUtil
.
beginOfDay
(
DateUtil
.
offsetDay
(
new
Date
(),
day
>
0
?
-
day
:
0
));
// 获取当天的结束时间
Date
todayEnd
=
DateUtil
.
endOfDay
(
new
Date
());
doorEventReq
.
setStartTime
(
todayStart
);
doorEventReq
.
setEndTime
(
todayEnd
);
doorEventReq
.
setPageNo
(
1
);
doorEventReq
.
setPageSize
(
1
);
Rest
<
DoorEventDataInfo
>
doorEventsRest
=
hikDoorService
.
getDoorEvents
(
doorEventReq
);
log
.
info
(
"doorEventsRest:{} msg:{}"
,
doorEventsRest
.
getCode
(),
doorEventsRest
.
getMsg
());
if
(
doorEventsRest
.
getCode
()
==
YesNoEnum
.
YES
.
getValue
())
{
//分页获取考勤数据
Integer
total
=
doorEventsRest
.
getData
().
getTotal
();
int
pageCount
=
PageUtil
.
totalPage
(
total
,
1000
);
for
(
int
i
=
1
;
i
<=
pageCount
;
i
++)
{
doorEventReq
.
setPageNo
(
i
);
doorEventReq
.
setPageSize
(
1000
);
doorEventsRest
=
hikDoorService
.
getDoorEvents
(
doorEventReq
);
log
.
info
(
"doorEventsRest:{} msg:{},page:{}"
,
doorEventsRest
.
getCode
(),
doorEventsRest
.
getMsg
(),
doorEventReq
.
getPageNo
());
getDoorEvents
(
doorEventsRest
);
}
}
}
private
void
getDoorEvents
(
Rest
<
DoorEventDataInfo
>
doorEventsRest
)
{
//同步当前考勤数据
List
<
AttendanceRecordHikEntity
>
attRecords
=
doorEventsRest
.
getData
().
getList
().
stream
().
map
(
item
->
{
AttendanceRecordHikEntity
recordHikEntity
=
new
AttendanceRecordHikEntity
();
recordHikEntity
.
initAttrValue
();
if
(
ObjectUtils
.
isEmpty
(
item
.
getJobNo
()))
{
log
.
info
(
"jobNo is null ==>{}"
,
JSON
.
toJSONString
(
item
));
return
null
;
}
StaffEntity
staffCache
=
staffService
.
getExtCache
(
StrUtil
.
padPre
(
item
.
getJobNo
(),
8
,
"0"
));
if
(
ObjectUtils
.
isEmpty
(
staffCache
))
{
log
.
info
(
"staff is null !staffCode:{}"
,
item
.
getJobNo
());
return
null
;
}
recordHikEntity
.
setStaffId
(
staffCache
.
getId
());
recordHikEntity
.
setStaffName
(
staffCache
.
getName
());
recordHikEntity
.
setWorkNum
(
staffCache
.
getWorkNum
());
recordHikEntity
.
setDeptId
(
staffCache
.
getDeptId
());
recordHikEntity
.
setDeptName
(
staffCache
.
getDeptName
());
recordHikEntity
.
setPositionId
(
staffCache
.
getPositionId
());
recordHikEntity
.
setPositionName
(
staffCache
.
getPositionName
());
recordHikEntity
.
setAttendanceDate
(
item
.
getEventTime
());
recordHikEntity
.
setAttendanceAddress
(
item
.
getDoorName
());
recordHikEntity
.
setEventSource
(
"门禁点"
);
recordHikEntity
.
setRemark
(
item
.
getEventId
());
recordHikEntity
.
setCreateTime
(
new
Date
());
recordHikEntity
.
setCreateUserName
(
"系统管理员"
);
recordHikEntity
.
setCreateUserId
(
1L
);
return
recordHikEntity
;
}).
filter
(
f
->
f
!=
null
).
collect
(
Collectors
.
toList
());
log
.
info
(
"attRecords size:{}"
,
attRecords
.
size
());
List
<
String
>
eventIds
=
attRecords
.
parallelStream
().
filter
(
f
->
!
ObjectUtils
.
isEmpty
(
f
)
&&
!
ObjectUtils
.
isEmpty
(
f
.
getRemark
())).
map
(
i
->
i
.
getRemark
()).
collect
(
Collectors
.
toList
());
//查询当天考勤记录是否有重复的 有的 则不添加
AttendanceRecordHikQuery
recordHikQuery
=
new
AttendanceRecordHikQuery
();
recordHikQuery
.
setAttendanceDateStart
(
DateUtil
.
format
(
DateUtil
.
beginOfDay
(
new
Date
()),
"yyyy-MM-dd"
));
recordHikQuery
.
setAttendanceDateEnd
(
DateUtil
.
format
(
DateUtil
.
beginOfDay
(
new
Date
()),
"yyyy-MM-dd"
));
recordHikQuery
.
setRemarkList
(
eventIds
);
Set
<
String
>
eventIdSet
=
recordHikService
.
find
(
recordHikQuery
).
parallelStream
().
map
(
i
->
i
.
getRemark
()).
collect
(
Collectors
.
toSet
());
//去重 时分秒打卡的 也要去掉重复。
List
<
AttendanceRecordHikEntity
>
saveRecordList
=
attRecords
.
stream
().
filter
(
f
->
!
eventIdSet
.
contains
(
f
.
getRemark
())).
collect
(
Collectors
.
toList
());
if
(!
ObjectUtils
.
isEmpty
(
saveRecordList
))
{
//单个插入 去掉重复时间段的打卡记录
for
(
AttendanceRecordHikEntity
recordHikEntity
:
saveRecordList
)
{
try
{
recordHikService
.
getDao
().
insert
(
recordHikEntity
);
}
catch
(
Exception
e
)
{
//log.error("基础考勤数据保存异常", e.getMessage());
}
}
// recordHikService.save(saveRecordList);
}
log
.
info
(
"saveRecordList size:{}"
,
saveRecordList
.
size
());
AttendanceRecordHikQuery
hikQuery
=
new
AttendanceRecordHikQuery
();
hikQuery
.
setAttendanceDateStart
(
DateUtil
.
beginOfMonth
(
new
Date
()).
toDateStr
());
hikQuery
.
setAttendanceDateEnd
(
DateUtil
.
today
());
Long
totalCache
=
recordHikService
.
find
(
hikQuery
).
parallelStream
().
map
(
item
->
item
.
getStaffId
()).
distinct
().
count
();
cacheService
.
hset
(
RedisKey
.
KEY_ATTENC_TOTOAL_CACHE
,
DateUtil
.
format
(
new
Date
(),
"yyyy-MM"
),
totalCache
);
}
@Override
@Override
public
void
stopTask
(
ITask
task
)
throws
AppException
{
public
void
stopTask
(
ITask
task
)
throws
AppException
{
...
...
attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventTaskImpl.java
View file @
6c3f621c
package
com.mortals.xhx.daemon.task
;
package
com.mortals.xhx.daemon.task
;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.PageUtil
;
import
cn.hutool.core.util.PageUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
...
@@ -18,7 +19,11 @@ import com.mortals.xhx.common.key.RedisKey;
...
@@ -18,7 +19,11 @@ import com.mortals.xhx.common.key.RedisKey;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity
;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity
;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery
;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery
;
import
com.mortals.xhx.module.attendance.service.AttendanceRecordHikService
;
import
com.mortals.xhx.module.attendance.service.AttendanceRecordHikService
;
import
com.mortals.xhx.module.door.model.DoorEntity
;
import
com.mortals.xhx.module.door.model.DoorQuery
;
import
com.mortals.xhx.module.door.service.DoorService
;
import
com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq
;
import
com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq
;
import
com.mortals.xhx.module.hik.door.model.req.door.HikDoorEventReq
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo
;
import
com.mortals.xhx.module.hik.door.service.IHikDoorService
;
import
com.mortals.xhx.module.hik.door.service.IHikDoorService
;
import
com.mortals.xhx.module.staff.model.StaffEntity
;
import
com.mortals.xhx.module.staff.model.StaffEntity
;
...
@@ -26,6 +31,7 @@ import com.mortals.xhx.module.staff.service.StaffService;
...
@@ -26,6 +31,7 @@ import com.mortals.xhx.module.staff.service.StaffService;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.checkerframework.checker.units.qual.A
;
import
org.checkerframework.checker.units.qual.A
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
...
@@ -55,6 +61,12 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
...
@@ -55,6 +61,12 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
@Autowired
@Autowired
private
ICacheService
cacheService
;
private
ICacheService
cacheService
;
@Value
(
"${hik.host:}"
)
protected
String
hikhost
;
@Autowired
private
DoorService
doorService
;
@Override
@Override
public
void
excuteTask
(
ITask
task
)
throws
AppException
{
public
void
excuteTask
(
ITask
task
)
throws
AppException
{
...
@@ -70,7 +82,25 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
...
@@ -70,7 +82,25 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
boolean
in
=
DateUtil
.
isIn
(
new
Date
(),
beginDateTime
,
endDateTime
);
boolean
in
=
DateUtil
.
isIn
(
new
Date
(),
beginDateTime
,
endDateTime
);
if
(
in
){
if
(
in
){
syncDoorEvents
();
AttendanceRecordHikQuery
hikQuery
=
new
AttendanceRecordHikQuery
();
DateTime
startTime
=
DateUtil
.
offsetDay
(
new
Date
(),
day
>
0
?
-
day
:
0
);
hikQuery
.
setAttendanceDateStart
(
startTime
.
toDateStr
());
// 获取当天的结束时间
hikQuery
.
setAttendanceDateEnd
(
DateUtil
.
today
());
if
(!
ObjectUtils
.
isEmpty
(
hikhost
))
{
recordHikService
.
syncDoorEvents
(
hikQuery
);
recordHikService
.
deletFakeRecord
(
hikQuery
,
null
);
}
else
{
HikDoorEventReq
hikDoorEventReq
=
new
HikDoorEventReq
();
hikDoorEventReq
.
setStartTime
(
startTime
.
toJdkDate
());
hikDoorEventReq
.
setEndTime
(
DateUtil
.
endOfDay
(
new
Date
()));
List
<
DoorEntity
>
doorEntities
=
doorService
.
find
(
new
DoorQuery
());
for
(
DoorEntity
doorEntity
:
doorEntities
)
{
doorService
.
syncDoorDeviceEvents
(
doorEntity
,
hikDoorEventReq
);
}
recordHikService
.
deletFakeRecord
(
hikQuery
,
null
);
}
//syncDoorEvents();
}
}
}
}
...
...
attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/SyncDoorsEventWeekTaskImpl.java
View file @
6c3f621c
...
@@ -3,42 +3,28 @@ package com.mortals.xhx.daemon.task;
...
@@ -3,42 +3,28 @@ package com.mortals.xhx.daemon.task;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateUnit
;
import
cn.hutool.core.date.DateUnit
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.PageUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.service.ITask
;
import
com.mortals.framework.service.ITask
;
import
com.mortals.framework.service.ITaskExcuteService
;
import
com.mortals.framework.service.ITaskExcuteService
;
import
com.mortals.framework.util.ThreadPool
;
import
com.mortals.framework.util.ThreadPool
;
import
com.mortals.xhx.base.system.user.model.UserEntity
;
import
com.mortals.xhx.common.code.YesNoEnum
;
import
com.mortals.xhx.common.utils.AddAttendThread
;
import
com.mortals.xhx.common.utils.AddAttendThread
;
import
com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordQuery
;
import
com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordQuery
;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity
;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery
;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery
;
import
com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService
;
import
com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService
;
import
com.mortals.xhx.module.attendance.service.AttendanceRecordHikService
;
import
com.mortals.xhx.module.attendance.service.AttendanceRecordHikService
;
import
com.mortals.xhx.module.attendance.service.AttendanceStatService
;
import
com.mortals.xhx.module.door.model.DoorEntity
;
import
com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq
;
import
com.mortals.xhx.module.door.model.DoorQuery
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo
;
import
com.mortals.xhx.module.door.service.DoorService
;
import
com.mortals.xhx.module.hik.door.service.IHikDoorService
;
import
com.mortals.xhx.module.hik.door.model.req.door.HikDoorEventReq
;
import
com.mortals.xhx.module.staff.model.StaffEntity
;
import
com.mortals.xhx.module.staff.service.StaffService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.checkerframework.checker.units.qual.A
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StopWatch
;
import
org.springframework.util.StopWatch
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
/**
* 同步获取本周门禁事件与计算
* 同步获取本周门禁事件与计算
...
@@ -51,14 +37,20 @@ public class SyncDoorsEventWeekTaskImpl implements ITaskExcuteService {
...
@@ -51,14 +37,20 @@ public class SyncDoorsEventWeekTaskImpl implements ITaskExcuteService {
private
AttendanceRecordHikService
recordHikService
;
private
AttendanceRecordHikService
recordHikService
;
@Autowired
@Autowired
private
AttendanceLeaveRecordService
attendanceLeaveRecordService
;
private
AttendanceLeaveRecordService
attendanceLeaveRecordService
;
@Autowired
private
DoorService
doorService
;
@Value
(
"${dingtalk.domain:}"
)
@Value
(
"${dingtalk.domain:}"
)
protected
String
domain
;
protected
String
domain
;
@Value
(
"${hik.host:}"
)
protected
String
hikhost
;
@Override
@Override
public
void
excuteTask
(
ITask
task
)
throws
AppException
{
public
void
excuteTask
(
ITask
task
)
throws
AppException
{
//同步本周所以人的门禁事件
//同步本周所以人的门禁事件
log
.
info
(
"同步本周所有的门禁事
}
"
);
log
.
info
(
"同步本周所有的门禁事"
);
DateTime
weekStart
=
DateUtil
.
offsetDay
(
new
Date
(),
-
7
);
DateTime
weekStart
=
DateUtil
.
offsetDay
(
new
Date
(),
-
7
);
AttendanceRecordHikQuery
hikEntity
=
new
AttendanceRecordHikQuery
();
AttendanceRecordHikQuery
hikEntity
=
new
AttendanceRecordHikQuery
();
hikEntity
.
setAttendanceDateStart
(
DateUtil
.
format
(
weekStart
,
"yyyy-MM-dd"
));
hikEntity
.
setAttendanceDateStart
(
DateUtil
.
format
(
weekStart
,
"yyyy-MM-dd"
));
...
@@ -68,37 +60,71 @@ public class SyncDoorsEventWeekTaskImpl implements ITaskExcuteService {
...
@@ -68,37 +60,71 @@ public class SyncDoorsEventWeekTaskImpl implements ITaskExcuteService {
DateTime
attendStart
=
DateUtil
.
parseDate
(
hikEntity
.
getAttendanceDateStart
());
DateTime
attendStart
=
DateUtil
.
parseDate
(
hikEntity
.
getAttendanceDateStart
());
DateTime
attendEnd
=
DateUtil
.
parseDate
(
hikEntity
.
getAttendanceDateEnd
());
DateTime
attendEnd
=
DateUtil
.
parseDate
(
hikEntity
.
getAttendanceDateEnd
());
Long
compare
=
DateUtil
.
between
(
attendEnd
,
attendStart
,
DateUnit
.
DAY
);
Long
compare
=
DateUtil
.
between
(
attendEnd
,
attendStart
,
DateUnit
.
DAY
);
StopWatch
stopWatch
=
new
StopWatch
(
"stopwatch attend1"
);
if
(!
ObjectUtils
.
isEmpty
(
hikhost
))
{
log
.
info
(
"考勤计算天数区间:{}"
,
compare
);
log
.
info
(
"同步海康云主机"
);
for
(
int
i
=
0
;
i
<=
compare
.
intValue
();
i
++)
{
StopWatch
stopWatch
=
new
StopWatch
(
"stopwatch attend1"
);
DateTime
curDate
=
DateUtil
.
offsetDay
(
attendStart
,
i
);
log
.
info
(
"考勤计算天数区间:{}"
,
compare
);
log
.
info
(
"考勤计算日期:{}"
,
curDate
.
toDateStr
());
for
(
int
i
=
0
;
i
<=
compare
.
intValue
();
i
++)
{
stopWatch
.
start
(
"执行本地方法"
);
DateTime
curDate
=
DateUtil
.
offsetDay
(
attendStart
,
i
);
hikEntity
.
setAttendanceDateStart
(
curDate
.
toDateStr
());
log
.
info
(
"考勤计算日期:{}"
,
curDate
.
toDateStr
());
hikEntity
.
setAttendanceDateEnd
(
curDate
.
toDateStr
());
stopWatch
.
start
(
"执行本地方法"
);
recordHikService
.
buildSourceHikRecord
(
hikEntity
,
null
);
hikEntity
.
setAttendanceDateStart
(
curDate
.
toDateStr
());
stopWatch
.
stop
();
hikEntity
.
setAttendanceDateEnd
(
curDate
.
toDateStr
());
log
.
info
(
"考勤计算日期:{} 完成,耗时:{}ms"
,
curDate
.
toDateStr
(),
stopWatch
.
getLastTaskTimeMillis
());
recordHikService
.
syncDoorEvents
(
hikEntity
);
recordHikService
.
deletFakeRecord
(
hikEntity
,
null
);
// recordHikService.buildSourceHikRecord(hikEntity, null);
stopWatch
.
stop
();
log
.
info
(
"考勤计算日期:{} 完成,耗时:{}ms"
,
curDate
.
toDateStr
(),
stopWatch
.
getLastTaskTimeMillis
());
}
}
else
{
//todo
log
.
info
(
"直连海康考勤设备"
);
StopWatch
stopWatch
=
new
StopWatch
(
"stopwatch attend1"
);
log
.
info
(
"考勤计算天数区间:{}"
,
compare
);
for
(
int
i
=
0
;
i
<=
compare
.
intValue
();
i
++)
{
DateTime
curDate
=
DateUtil
.
offsetDay
(
attendStart
,
i
);
log
.
info
(
"考勤计算日期:{}"
,
curDate
.
toDateStr
());
stopWatch
.
start
(
"执行本地方法"
);
HikDoorEventReq
hikDoorEventReq
=
new
HikDoorEventReq
();
hikDoorEventReq
.
setStartTime
(
curDate
.
toJdkDate
());
hikDoorEventReq
.
setEndTime
(
curDate
.
toJdkDate
());
List
<
DoorEntity
>
doorEntities
=
doorService
.
find
(
new
DoorQuery
());
for
(
DoorEntity
doorEntity
:
doorEntities
)
{
doorService
.
syncDoorDeviceEvents
(
doorEntity
,
hikDoorEventReq
);
}
hikEntity
.
setAttendanceDateStart
(
curDate
.
toDateStr
());
hikEntity
.
setAttendanceDateEnd
(
curDate
.
toDateStr
());
recordHikService
.
deletFakeRecord
(
hikEntity
,
null
);
stopWatch
.
stop
();
log
.
info
(
"考勤计算日期:{} 完成,耗时:{}ms"
,
curDate
.
toDateStr
(),
stopWatch
.
getLastTaskTimeMillis
());
}
}
}
log
.
info
(
"开始计算及统计最近7天考勤!"
);
AddAttendThread
addAttendThread
=
new
AddAttendThread
(
recordHikService
,
hikEntity
,
null
);
AddAttendThread
addAttendThread
=
new
AddAttendThread
(
recordHikService
,
hikEntity
,
null
);
ThreadPool
.
getInstance
().
execute
(
addAttendThread
);
ThreadPool
.
getInstance
().
execute
(
addAttendThread
);
//同步最近钉钉请假事件
//同步最近钉钉请假事件
if
(!
ObjectUtils
.
isEmpty
(
domain
)){
checkDingDingEvent
(
attendStart
,
attendEnd
,
hikEntity
);
log
.
info
(
"开始同步钉钉请假事件!"
);
}
long
between
=
DateUtil
.
between
(
attendStart
,
attendEnd
,
DateUnit
.
DAY
,
true
);
AttendanceLeaveRecordQuery
query
=
new
AttendanceLeaveRecordQuery
();
private
void
checkDingDingEvent
(
DateTime
attendStart
,
DateTime
attendEnd
,
AttendanceRecordHikQuery
hikEntity
)
{
query
.
setStartTimeStart
(
hikEntity
.
getAttendanceDateStart
());
if
(
ObjectUtils
.
isEmpty
(
domain
))
return
;
query
.
setEndTimeEnd
(
hikEntity
.
getAttendanceDateEnd
());
if
(
between
>
120
)
return
;
log
.
info
(
"开始同步钉钉请假事件!"
);
Thread
thread
=
new
Thread
(
new
Runnable
()
{
long
between
=
DateUtil
.
between
(
attendStart
,
attendEnd
,
DateUnit
.
DAY
,
true
);
@Override
AttendanceLeaveRecordQuery
query
=
new
AttendanceLeaveRecordQuery
();
public
void
run
()
{
query
.
setStartTimeStart
(
hikEntity
.
getAttendanceDateStart
());
attendanceLeaveRecordService
.
syncLeaveRecord
(
query
,
null
);
query
.
setEndTimeEnd
(
hikEntity
.
getAttendanceDateEnd
());
}
if
(
between
>
120
)
return
;
});
Thread
thread
=
new
Thread
(
new
Runnable
()
{
ThreadPool
.
getInstance
().
execute
(
thread
);
@Override
}
public
void
run
()
{
attendanceLeaveRecordService
.
syncLeaveRecord
(
query
,
null
);
}
});
ThreadPool
.
getInstance
().
execute
(
thread
);
}
}
...
...
attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/AttendanceRecordHikService.java
View file @
6c3f621c
...
@@ -60,4 +60,9 @@ public interface AttendanceRecordHikService extends ICRUDService<AttendanceRecor
...
@@ -60,4 +60,9 @@ public interface AttendanceRecordHikService extends ICRUDService<AttendanceRecor
Rest
<
Integer
>
buildSourceHikRecord
(
AttendanceRecordHikQuery
recordHikQuery
,
Context
context
);
Rest
<
Integer
>
buildSourceHikRecord
(
AttendanceRecordHikQuery
recordHikQuery
,
Context
context
);
void
deletFakeRecord
(
AttendanceRecordHikQuery
recordHikQuery
,
Context
context
);
void
syncDoorEvents
(
AttendanceRecordHikQuery
recordHikQuery
);
}
}
attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/service/impl/AttendanceRecordHikServiceImpl.java
View file @
6c3f621c
package
com.mortals.xhx.module.attendance.service.impl
;
package
com.mortals.xhx.module.attendance.service.impl
;
import
cn.hutool.core.collection.ListUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.PageUtil
;
import
cn.hutool.core.util.PageUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.service.IUser
;
import
com.mortals.framework.util.StringUtils
;
import
com.mortals.framework.util.StringUtils
;
import
com.mortals.xhx.base.system.upload.service.UploadService
;
import
com.mortals.xhx.base.system.user.model.UserEntity
;
import
com.mortals.xhx.common.code.*
;
import
com.mortals.xhx.common.code.*
;
import
com.mortals.xhx.common.key.RedisKey
;
import
com.mortals.xhx.common.utils.BeanUtil
;
import
com.mortals.xhx.module.attendance.model.*
;
import
com.mortals.xhx.module.attendance.model.*
;
import
com.mortals.xhx.module.attendance.service.*
;
import
com.mortals.xhx.module.attendance.service.*
;
import
com.mortals.xhx.module.attendance.service.work.AttendanceWorkAbstract
;
import
com.mortals.xhx.module.attendance.service.work.AttendanceWorkAbstract
;
import
com.mortals.xhx.module.attendance.service.work.CommonData
;
import
com.mortals.xhx.module.attendance.service.work.CommonData
;
import
com.mortals.xhx.module.dept.service.DeptService
;
import
com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq
;
import
com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo
;
import
com.mortals.xhx.module.hik.door.service.IHikDoorService
;
import
com.mortals.xhx.module.hik.door.service.IHikDoorService
;
...
@@ -25,10 +18,8 @@ import com.mortals.xhx.module.holiday.model.HolidayEntity;
...
@@ -25,10 +18,8 @@ import com.mortals.xhx.module.holiday.model.HolidayEntity;
import
com.mortals.xhx.module.holiday.model.HolidayQuery
;
import
com.mortals.xhx.module.holiday.model.HolidayQuery
;
import
com.mortals.xhx.module.holiday.service.HolidayService
;
import
com.mortals.xhx.module.holiday.service.HolidayService
;
import
com.mortals.xhx.module.staff.model.StaffEntity
;
import
com.mortals.xhx.module.staff.model.StaffEntity
;
import
com.mortals.xhx.module.staff.model.StaffQuery
;
import
com.mortals.xhx.module.staff.service.StaffService
;
import
com.mortals.xhx.module.staff.service.StaffService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.time.DateUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -38,9 +29,6 @@ import com.mortals.framework.model.Context;
...
@@ -38,9 +29,6 @@ import com.mortals.framework.model.Context;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
java.text.SimpleDateFormat
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -818,12 +806,11 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
...
@@ -818,12 +806,11 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
@Override
@Override
public
Rest
<
Integer
>
buildSourceHikRecord
(
AttendanceRecordHikQuery
recordHikQuery
,
Context
context
)
{
public
Rest
<
Integer
>
buildSourceHikRecord
(
AttendanceRecordHikQuery
recordHikQuery
,
Context
context
)
{
syncDoorEvents
(
recordHikQuery
);
deletFakeRecord
(
recordHikQuery
,
context
);
deletFackRecord
(
recordHikQuery
,
context
);
return
Rest
.
ok
();
return
Rest
.
ok
();
}
}
@Override
p
rivate
void
deletFack
Record
(
AttendanceRecordHikQuery
recordHikQuery
,
Context
context
)
{
p
ublic
void
deletFake
Record
(
AttendanceRecordHikQuery
recordHikQuery
,
Context
context
)
{
//重新拉去的考勤记录,判断是否存在虚增的记录
//重新拉去的考勤记录,判断是否存在虚增的记录
log
.
info
(
"开始删除虚增的记录!"
);
log
.
info
(
"开始删除虚增的记录!"
);
recordHikQuery
.
setEventSource
(
"当日未有记录虚增考勤记录!"
);
recordHikQuery
.
setEventSource
(
"当日未有记录虚增考勤记录!"
);
...
@@ -846,7 +833,7 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
...
@@ -846,7 +833,7 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
}
}
}
}
p
rivate
void
syncDoorEvents
(
AttendanceRecordHikQuery
recordHikQuery
)
{
p
ublic
void
syncDoorEvents
(
AttendanceRecordHikQuery
recordHikQuery
)
{
DoorEventReq
doorEventReq
=
new
DoorEventReq
();
DoorEventReq
doorEventReq
=
new
DoorEventReq
();
List
<
Integer
>
eventTypes
=
new
ArrayList
<>();
List
<
Integer
>
eventTypes
=
new
ArrayList
<>();
eventTypes
.
add
(
196885
);
eventTypes
.
add
(
196885
);
...
@@ -880,7 +867,7 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
...
@@ -880,7 +867,7 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
try
{
try
{
doorEventsRest
=
hikDoorService
.
getDoorEvents
(
doorEventReq
);
doorEventsRest
=
hikDoorService
.
getDoorEvents
(
doorEventReq
);
log
.
info
(
"doorEventsRest:{} msg:{},page:{}"
,
doorEventsRest
.
getCode
(),
doorEventsRest
.
getMsg
(),
doorEventReq
.
getPageNo
());
log
.
info
(
"doorEventsRest:{} msg:{},page:{}"
,
doorEventsRest
.
getCode
(),
doorEventsRest
.
getMsg
(),
doorEventReq
.
getPageNo
());
getDoorEvents
(
doorEventsRest
);
getDoorEvents
(
doorEventsRest
,
doorEventReq
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"分页获取考勤数据异常:{}"
,
e
.
getMessage
());
log
.
error
(
"分页获取考勤数据异常:{}"
,
e
.
getMessage
());
}
}
...
@@ -889,7 +876,7 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
...
@@ -889,7 +876,7 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
}
}
}
}
private
void
getDoorEvents
(
Rest
<
DoorEventDataInfo
>
doorEventsRest
)
{
private
void
getDoorEvents
(
Rest
<
DoorEventDataInfo
>
doorEventsRest
,
DoorEventReq
doorEventReq
)
{
//同步当前考勤数据
//同步当前考勤数据
List
<
AttendanceRecordHikEntity
>
attRecords
=
doorEventsRest
.
getData
().
getList
().
stream
().
map
(
item
->
{
List
<
AttendanceRecordHikEntity
>
attRecords
=
doorEventsRest
.
getData
().
getList
().
stream
().
map
(
item
->
{
AttendanceRecordHikEntity
recordHikEntity
=
new
AttendanceRecordHikEntity
();
AttendanceRecordHikEntity
recordHikEntity
=
new
AttendanceRecordHikEntity
();
...
@@ -929,8 +916,8 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
...
@@ -929,8 +916,8 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
//查询当天考勤记录是否有重复的 有的 则不添加
//查询当天考勤记录是否有重复的 有的 则不添加
AttendanceRecordHikQuery
recordHikQuery
=
new
AttendanceRecordHikQuery
();
AttendanceRecordHikQuery
recordHikQuery
=
new
AttendanceRecordHikQuery
();
recordHikQuery
.
setAttendanceDateStart
(
DateUtil
.
format
(
DateUtil
.
beginOfDay
(
new
Date
()
),
"yyyy-MM-dd"
));
recordHikQuery
.
setAttendanceDateStart
(
DateUtil
.
format
(
doorEventReq
.
getStartTime
(
),
"yyyy-MM-dd"
));
recordHikQuery
.
setAttendanceDateEnd
(
DateUtil
.
format
(
DateUtil
.
beginOfDay
(
new
Date
()
),
"yyyy-MM-dd"
));
recordHikQuery
.
setAttendanceDateEnd
(
DateUtil
.
format
(
doorEventReq
.
getEndTime
(
),
"yyyy-MM-dd"
));
recordHikQuery
.
setRemarkList
(
eventIds
);
recordHikQuery
.
setRemarkList
(
eventIds
);
Set
<
String
>
eventIdSet
=
this
.
find
(
recordHikQuery
).
parallelStream
().
map
(
i
->
i
.
getRemark
()).
collect
(
Collectors
.
toSet
());
Set
<
String
>
eventIdSet
=
this
.
find
(
recordHikQuery
).
parallelStream
().
map
(
i
->
i
.
getRemark
()).
collect
(
Collectors
.
toSet
());
...
...
attendance-performance-manager/src/main/java/com/mortals/xhx/module/attendance/web/AttendanceRecordHikController.java
View file @
6c3f621c
...
@@ -228,7 +228,8 @@ public class AttendanceRecordHikController extends BaseCRUDJsonBodyMappingContro
...
@@ -228,7 +228,8 @@ public class AttendanceRecordHikController extends BaseCRUDJsonBodyMappingContro
stopWatch
.
start
(
"执行本地方法"
);
stopWatch
.
start
(
"执行本地方法"
);
hikEntity
.
setAttendanceDateStart
(
curDate
.
toDateStr
());
hikEntity
.
setAttendanceDateStart
(
curDate
.
toDateStr
());
hikEntity
.
setAttendanceDateEnd
(
curDate
.
toDateStr
());
hikEntity
.
setAttendanceDateEnd
(
curDate
.
toDateStr
());
hikService
.
buildSourceHikRecord
(
hikEntity
,
context
);
hikService
.
syncDoorEvents
(
hikEntity
);
hikService
.
deletFakeRecord
(
hikEntity
,
context
);
stopWatch
.
stop
();
stopWatch
.
stop
();
log
.
info
(
"考勤计算日期:{} 完成,耗时:{}ms"
,
curDate
.
toDateStr
(),
stopWatch
.
getLastTaskTimeMillis
());
log
.
info
(
"考勤计算日期:{} 完成,耗时:{}ms"
,
curDate
.
toDateStr
(),
stopWatch
.
getLastTaskTimeMillis
());
}
}
...
...
attendance-performance-manager/src/main/java/com/mortals/xhx/module/door/service/DoorService.java
View file @
6c3f621c
package
com.mortals.xhx.module.door.service
;
package
com.mortals.xhx.module.door.service
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.service.ICRUDService
;
import
com.mortals.framework.service.ICRUDService
;
import
com.mortals.xhx.module.door.dao.DoorDao
;
import
com.mortals.xhx.module.door.dao.DoorDao
;
import
com.mortals.xhx.module.door.model.DoorEntity
;
import
com.mortals.xhx.module.door.model.DoorEntity
;
import
com.mortals.xhx.module.hik.door.model.req.door.HikDoorEventReq
;
/**
/**
* DoorService
* DoorService
*
*
...
@@ -14,4 +17,12 @@ import com.mortals.xhx.module.door.model.DoorEntity;
...
@@ -14,4 +17,12 @@ import com.mortals.xhx.module.door.model.DoorEntity;
public
interface
DoorService
extends
ICRUDService
<
DoorEntity
,
Long
>{
public
interface
DoorService
extends
ICRUDService
<
DoorEntity
,
Long
>{
DoorDao
getDao
();
DoorDao
getDao
();
/**
* 同步门禁设备事件
* @param doorEntity
* @return
*/
Rest
<
Void
>
syncDoorDeviceEvents
(
DoorEntity
doorEntity
,
HikDoorEventReq
hikDoorEventReq
);
}
}
\ No newline at end of file
attendance-performance-manager/src/main/java/com/mortals/xhx/module/door/service/impl/DoorServiceImpl.java
View file @
6c3f621c
package
com.mortals.xhx.module.door.service.impl
;
package
com.mortals.xhx.module.door.service.impl
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
import
com.mortals.xhx.common.code.DwMinorEnum
;
import
com.mortals.xhx.common.code.YesNoEnum
;
import
com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity
;
import
com.mortals.xhx.module.attendance.service.AttendanceRecordHikService
;
import
com.mortals.xhx.module.door.dao.DoorDao
;
import
com.mortals.xhx.module.door.dao.DoorDao
;
import
com.mortals.xhx.module.door.model.DoorEntity
;
import
com.mortals.xhx.module.door.model.DoorEntity
;
import
com.mortals.xhx.module.door.service.DoorService
;
import
com.mortals.xhx.module.door.service.DoorService
;
import
com.mortals.xhx.module.hik.door.model.req.door.HikDoorEventReq
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.info.EventInfo
;
import
com.mortals.xhx.module.hik.door.model.rsp.door.info.StruTime
;
import
com.mortals.xhx.module.hik.door.service.IHikDoorService
;
import
com.mortals.xhx.module.staff.model.StaffEntity
;
import
com.mortals.xhx.module.staff.service.StaffService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.ZonedDateTime
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
/**
* DoorService
* DoorService
* 门禁设备 service实现
* 门禁设备 service实现
...
@@ -16,5 +41,113 @@ import org.springframework.stereotype.Service;
...
@@ -16,5 +41,113 @@ import org.springframework.stereotype.Service;
@Service
(
"doorService"
)
@Service
(
"doorService"
)
@Slf4j
@Slf4j
public
class
DoorServiceImpl
extends
AbstractCRUDServiceImpl
<
DoorDao
,
DoorEntity
,
Long
>
implements
DoorService
{
public
class
DoorServiceImpl
extends
AbstractCRUDServiceImpl
<
DoorDao
,
DoorEntity
,
Long
>
implements
DoorService
{
@Autowired
private
AttendanceRecordHikService
recordHikService
;
@Autowired
private
StaffService
staffService
;
@Autowired
private
IHikDoorService
hikDoorService
;
private
Integer
day
;
@Autowired
private
ICacheService
cacheService
;
@Override
public
Rest
<
Void
>
syncDoorDeviceEvents
(
DoorEntity
doorEntity
,
HikDoorEventReq
hikDoorEventReq
)
{
Rest
<
List
<
EventInfo
>>
listRest
=
hikDoorService
.
searchDoorEventsList
(
hikDoorEventReq
,
doorEntity
);
if
(
listRest
.
getCode
()
==
YesNoEnum
.
YES
.
getValue
())
{
List
<
EventInfo
>
list
=
listRest
.
getData
();
List
<
AttendanceRecordHikEntity
>
attRecords
=
list
.
stream
().
map
(
item
->
{
AttendanceRecordHikEntity
recordHikEntity
=
new
AttendanceRecordHikEntity
();
recordHikEntity
.
initAttrValue
();
String
jobNo
=
""
;
byte
[]
byEmployeeNo
=
item
.
getStruAcsEventInfo
().
getByEmployeeNo
();
if
(
ObjectUtils
.
isEmpty
(
new
String
(
byEmployeeNo
).
trim
()))
{
int
dwEmployeeNo
=
item
.
getStruAcsEventInfo
().
getDwEmployeeNo
();
if
(
dwEmployeeNo
==
0
)
{
//log.info("jobNo is null ==>{}", JSON.toJSONString(item));
return
null
;
}
else
{
jobNo
=
String
.
valueOf
(
dwEmployeeNo
);
}
}
else
{
jobNo
=
new
String
(
byEmployeeNo
).
trim
();
}
log
.
info
(
"jobNo==>{}"
,
jobNo
);
//查看考勤状态
int
dwMajor
=
item
.
getDwMajor
();
//报警主类型
int
dwMinor
=
item
.
getDwMinor
();
//报警次类型
String
dwMinorStr
=
Integer
.
toHexString
(
dwMinor
);
//判断次类型 是否在白名单里面
Set
<
String
>
dwSet
=
DwMinorEnum
.
getEnumMap
().
keySet
();
if
(
dwSet
.
contains
(
dwMinorStr
))
{
//符号考勤 添加到考勤里面
StruTime
struTime
=
item
.
getStruTime
();
//格式化时间 年月日 时分秒 yyyy-MM-dd HH:mm:ss
int
dwYear
=
struTime
.
getDwYear
();
int
dwMonth
=
struTime
.
getDwMonth
();
int
dwDay
=
struTime
.
getDwDay
();
int
dwHour
=
struTime
.
getDwHour
();
int
dwMinute
=
struTime
.
getDwMinute
();
int
dwSecond
=
struTime
.
getDwSecond
();
LocalDateTime
localDateTime
=
LocalDateTime
.
of
(
dwYear
,
dwMonth
,
dwDay
,
dwHour
,
dwMinute
,
dwSecond
);
ZoneId
zoneId
=
ZoneId
.
systemDefault
();
ZonedDateTime
zdt
=
localDateTime
.
atZone
(
zoneId
);
Date
attendDate
=
Date
.
from
(
zdt
.
toInstant
());
StaffEntity
staffCache
=
staffService
.
getExtCache
(
StrUtil
.
padPre
(
jobNo
,
8
,
"0"
));
if
(
ObjectUtils
.
isEmpty
(
staffCache
))
{
log
.
info
(
"staff is null !staffCode:{}"
,
jobNo
);
return
null
;
}
recordHikEntity
.
setStaffId
(
staffCache
.
getId
());
recordHikEntity
.
setStaffName
(
staffCache
.
getName
());
recordHikEntity
.
setWorkNum
(
staffCache
.
getWorkNum
());
recordHikEntity
.
setDeptId
(
staffCache
.
getDeptId
());
recordHikEntity
.
setDeptName
(
staffCache
.
getDeptName
());
recordHikEntity
.
setPositionId
(
staffCache
.
getPositionId
());
recordHikEntity
.
setPositionName
(
staffCache
.
getPositionName
());
recordHikEntity
.
setAttendanceDate
(
attendDate
);
// recordHikEntity.setAttendanceAddress(item.getDoorName());
recordHikEntity
.
setEventSource
(
"门禁点"
);
//recordHikEntity.setRemark(item.getEventId());
recordHikEntity
.
setCreateTime
(
new
Date
());
recordHikEntity
.
setCreateUserName
(
"系统管理员"
);
recordHikEntity
.
setCreateUserId
(
1L
);
return
recordHikEntity
;
}
else
{
log
.
info
(
"考勤次类型dwMinorCode:"
+
dwMinorStr
);
return
null
;
}
}).
filter
(
f
->
f
!=
null
).
collect
(
Collectors
.
toList
());
log
.
info
(
"attRecords size:{}"
,
attRecords
.
size
());
if
(!
ObjectUtils
.
isEmpty
(
attRecords
))
{
//单个插入 去掉重复时间段的打卡记录
for
(
AttendanceRecordHikEntity
recordHikEntity
:
attRecords
)
{
try
{
recordHikService
.
getDao
().
insert
(
recordHikEntity
);
}
catch
(
Exception
e
)
{
log
.
error
(
"基础考勤数据保存异常"
,
e
.
getMessage
());
}
}
}
}
return
null
;
}
}
}
\ No newline at end of file
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