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
a4fed91e
Commit
a4fed91e
authored
Sep 22, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加考勤计算任务
parent
e7ff8e04
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
211 additions
and
0 deletions
+211
-0
attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/CalculateDayAttendTaskImpl.java
...m/mortals/xhx/daemon/task/CalculateDayAttendTaskImpl.java
+211
-0
No files found.
attendance-performance-manager/src/main/java/com/mortals/xhx/daemon/task/CalculateDayAttendTaskImpl.java
0 → 100644
View file @
a4fed91e
package
com.mortals.xhx.daemon.task
;
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.model.Context
;
import
com.mortals.framework.service.ITask
;
import
com.mortals.framework.service.ITaskExcuteService
;
import
com.mortals.xhx.base.system.user.model.UserEntity
;
import
com.mortals.xhx.common.code.SourceType
;
import
com.mortals.xhx.common.code.YesNoEnum
;
import
com.mortals.xhx.module.attendance.model.*
;
import
com.mortals.xhx.module.attendance.service.AttendanceGroupFixedworkService
;
import
com.mortals.xhx.module.attendance.service.AttendanceGroupService
;
import
com.mortals.xhx.module.attendance.service.AttendanceGroupStaffService
;
import
com.mortals.xhx.module.attendance.service.AttendanceRecordHikService
;
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.service.IHikDoorService
;
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
lombok.extern.slf4j.Slf4j
;
import
org.checkerframework.checker.units.qual.A
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* 定时计算当天全缺席人员
*/
@Slf4j
@Service
(
"CalculateDayAttendTask"
)
public
class
CalculateDayAttendTaskImpl
implements
ITaskExcuteService
{
@Autowired
private
AttendanceRecordHikService
recordHikService
;
@Autowired
private
StaffService
staffService
;
@Autowired
private
AttendanceGroupStaffService
attendanceGroupStaffService
;
@Autowired
private
AttendanceGroupFixedworkService
groupFixedworkService
;
@Override
public
void
excuteTask
(
ITask
task
)
throws
AppException
{
//查询当日考勤记录,查询未考勤人员,构造一条假记录方便计算
AttendanceRecordHikQuery
recordHikQuery
=
new
AttendanceRecordHikQuery
();
recordHikQuery
.
setAttendanceDateStart
(
DateUtil
.
today
());
recordHikQuery
.
setAttendanceDateEnd
(
DateUtil
.
today
());
Set
<
Long
>
attendStaffSet
=
recordHikService
.
find
(
recordHikQuery
).
stream
().
map
(
i
->
i
.
getStaffId
()).
distinct
().
collect
(
Collectors
.
toSet
());
Map
<
Long
,
List
<
AttendanceGroupStaffEntity
>>
groupStaffCollect
=
attendanceGroupStaffService
.
find
(
new
AttendanceGroupStaffQuery
()).
stream
().
collect
(
Collectors
.
groupingBy
(
x
->
x
.
getGroupId
()));
Iterator
<
Map
.
Entry
<
Long
,
List
<
AttendanceGroupStaffEntity
>>>
iterator
=
groupStaffCollect
.
entrySet
().
iterator
();
while
(
iterator
.
hasNext
())
{
Map
.
Entry
<
Long
,
List
<
AttendanceGroupStaffEntity
>>
item
=
iterator
.
next
();
//分组查看当前人
Long
groupId
=
item
.
getKey
();
AttendanceGroupFixedworkEntity
attendanceGroupFixedworkEntity
=
groupFixedworkService
.
selectOne
(
new
AttendanceGroupFixedworkQuery
().
groupId
(
groupId
));
String
week
=
this
.
getWeek
(
new
Date
());
Long
weekClassId
=
this
.
getWeekClassId
(
attendanceGroupFixedworkEntity
,
week
);
//weekClassId为-1 则不在考勤
if
(
weekClassId
==
-
1L
)
{
//跳过本次循环
log
.
info
(
"当前日期不在考勤时间范围内,不做处理!"
);
continue
;
}
List
<
AttendanceGroupStaffEntity
>
groupStaffList
=
item
.
getValue
();
//查看当前需要考勤但是没有记录的人
List
<
Long
>
unAttendStaffIdList
=
groupStaffList
.
stream
().
filter
(
f
->
!
attendStaffSet
.
contains
(
f
.
getStaffId
())).
map
(
i
->
i
.
getStaffId
()).
collect
(
Collectors
.
toList
());
if
(!
ObjectUtils
.
isEmpty
(
unAttendStaffIdList
))
{
for
(
Long
staffId
:
unAttendStaffIdList
)
{
StaffEntity
staffCache
=
staffService
.
getCache
(
staffId
.
toString
());
if
(!
ObjectUtils
.
isEmpty
(
staffCache
))
{
//构建考勤记录
AttendanceRecordHikEntity
recordHikEntity
=
new
AttendanceRecordHikEntity
();
recordHikEntity
.
initAttrValue
();
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
.
setAttendanceGroupId
(
groupId
);
recordHikEntity
.
setAttendanceDate
(
DateUtil
.
parseDate
(
DateUtil
.
today
()).
toJdkDate
());
recordHikEntity
.
setAttendanceAddress
(
"自定义地点"
);
recordHikEntity
.
setEventSource
(
"当日未有记录虚增考勤记录!"
);
recordHikEntity
.
setCreateTime
(
new
Date
());
recordHikEntity
.
setCreateUserId
(
1L
);
recordHikService
.
save
(
recordHikEntity
);
}
else
{
log
.
error
(
"未找到当前员工,staffId:{}"
,
staffId
);
}
}
}
}
calculateAttendByDay
();
}
private
void
calculateAttendByDay
()
{
Context
context
=
new
Context
();
UserEntity
userEntity
=
new
UserEntity
();
userEntity
.
setCreateUserId
(
1L
);
userEntity
.
setId
(
1L
);
userEntity
.
setCreateUserName
(
"admin"
);
userEntity
.
setCreateTime
(
new
Date
());
context
.
setUser
(
userEntity
);
AttendanceRecordHikQuery
recordHikQuery
=
new
AttendanceRecordHikQuery
();
// Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
// recordHikQuery.setAttendanceDateStart(DateUtils.getCurrStrDate());
recordHikQuery
.
setAttendanceDateStart
(
DateUtil
.
today
());
recordHikQuery
.
setAttendanceDateEnd
(
DateUtil
.
today
());
try
{
recordHikService
.
addAttendanceRecordByQuery
(
recordHikQuery
,
context
);
}
catch
(
Exception
e
)
{
log
.
error
(
"计算考勤异常"
,
e
);
}
}
protected
String
getWeek
(
Date
date
)
{
// Get the day of the week (1 = Sunday, 2 = Monday, ..., 7 = Saturday)
int
dayOfWeek
=
DateUtil
.
dayOfWeek
(
date
);
// Map the numeric day of the week to its corresponding Chinese name
String
[]
dayOfWeekNames
=
new
String
[]{
"星期日"
,
"星期一"
,
"星期二"
,
"星期三"
,
"星期四"
,
"星期五"
,
"星期六"
};
// Get the Chinese name of the day of the week
String
dayOfWeekName
=
dayOfWeekNames
[
dayOfWeek
-
1
];
return
dayOfWeekName
;
}
/**
* 获取通过星期获取班次id 如果返参为-1 则不在考勤
*
* @return
*/
protected
Long
getWeekClassId
(
AttendanceGroupFixedworkEntity
attendanceGroupFixedworkEntity
,
String
week
)
{
Long
weekClassId
=
0L
;
switch
(
week
)
{
case
"星期一"
:
if
(
attendanceGroupFixedworkEntity
.
getMonday
()
==
0
)
{
weekClassId
=
-
1L
;
return
weekClassId
;
}
weekClassId
=
attendanceGroupFixedworkEntity
.
getMondayClassId
();
break
;
case
"星期二"
:
if
(
attendanceGroupFixedworkEntity
.
getTuesday
()
==
0
)
{
weekClassId
=
-
1L
;
return
weekClassId
;
}
weekClassId
=
attendanceGroupFixedworkEntity
.
getTuesdayClassId
();
break
;
case
"星期三"
:
if
(
attendanceGroupFixedworkEntity
.
getWednesday
()
==
0
)
{
weekClassId
=
-
1L
;
return
weekClassId
;
}
weekClassId
=
attendanceGroupFixedworkEntity
.
getWednesdayClassId
();
break
;
case
"星期四"
:
if
(
attendanceGroupFixedworkEntity
.
getThursday
()
==
0
)
{
weekClassId
=
-
1L
;
return
weekClassId
;
}
weekClassId
=
attendanceGroupFixedworkEntity
.
getThursdayClassId
();
break
;
case
"星期五"
:
if
(
attendanceGroupFixedworkEntity
.
getFriday
()
==
0
)
{
weekClassId
=
-
1L
;
return
weekClassId
;
}
weekClassId
=
attendanceGroupFixedworkEntity
.
getFridayClassId
();
break
;
case
"星期六"
:
if
(
attendanceGroupFixedworkEntity
.
getSaturday
()
==
0
)
{
weekClassId
=
-
1L
;
return
weekClassId
;
}
weekClassId
=
attendanceGroupFixedworkEntity
.
getSaturdayClassId
();
break
;
case
"星期日"
:
if
(
attendanceGroupFixedworkEntity
.
getSunday
()
==
0
)
{
weekClassId
=
-
1L
;
return
weekClassId
;
}
weekClassId
=
attendanceGroupFixedworkEntity
.
getSundayClassId
();
break
;
}
return
weekClassId
;
}
@Override
public
void
stopTask
(
ITask
task
)
throws
AppException
{
}
}
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