考勤计算重构

This commit is contained in:
fl 2025-02-17 18:09:39 +08:00
parent 5bbbc22e30
commit 37bedd187d
7 changed files with 343 additions and 137 deletions

View File

@ -72,7 +72,7 @@ public interface AttSourceDataDao {
* 查询一个月的节假日 * 查询一个月的节假日
* @return list bean * @return list bean
*/ */
List<Holiday> selectHolidayByMonth(@Param("pushDate")String pushDate, @Param("pushType")int pushType); List<Holiday> selectHolidayByMonth(@Param("pushDate")String pushDate);
/** /**
* 查询人员的请假数据 * 查询人员的请假数据
@ -156,4 +156,73 @@ public interface AttSourceDataDao {
int getFirstAttendanceData(String date); int getFirstAttendanceData(String date);
void deleteAttMonthReport(String pushDate); void deleteAttMonthReport(String pushDate);
/**
* 查询指定时间内存在考勤人员列表的日期
* @param startDate
* @param days
* @return
*/
List<String> getAttSettingDate(@Param("startDate") String startDate,@Param("days") int days);
/**
* 查询历史某天应考勤人员
* @param currentDay
* @return
*/
List<AttGroupBean> getAttSettingHistoryDate(String currentDay);
/**
* 将历史某天应考勤人员插入到考勤人员列表
* @param attList
*/
void insertAttSettingHistoryData(List<AttGroupBean> attList);
/**
* 查询当天应考勤人员
* @param pushDate
* @return
*/
List<AttDataBean> getAttPerson(String pushDate);
void insertAttDataList(List<AttDataBean> listPerson);
/**
* 查询当天考勤模版人员
* @param pushDate
* @return
*/
List<Long> getAttDataPerson(String pushDate);
/***
* 查询当天考勤状态为未打卡人员(att_data)
* @param pushDate
* @return
*/
List<AttDataBean> getAttDataByStatus(@Param("pushDate") String pushDate,@Param("attType") String attType);
/***
* 查询当天考勤状态为未打卡人员(att_data_update)
* @param pushDate
* @return
*/
List<AttDataBean> getAttDataUpdateByStatus(@Param("pushDate") String pushDate,@Param("attType") String attType);
/**
* 超过时间未打卡的补为旷工(att_data)
* @param list
*/
void updateAttDataList(List<AttDataBean> list);
/**
* 超过时间未打卡的补为旷工(att_data_update)
* @param list
*/
void updateAttDataUpdateList(List<AttDataBean> list);
/**
* 当日是否为法假
* @param pushDate
* @return
*/
List<Holiday> selectHolidayByDay(String pushDate);
} }

View File

@ -115,6 +115,11 @@ public class AttGroupBean {
*/ */
private List<SysTree> treeList; private List<SysTree> treeList;
/**
* 是否有法定节假日
*/
private Integer isHaveHoliday;
/** /**
* 创建用户编号 * 创建用户编号
*/ */

View File

@ -52,6 +52,10 @@ public class AttSourceDataBean {
* 打卡地址 * 打卡地址
*/ */
private String attAddress; private String attAddress;
/**
* 打卡省份
*/
private String province;
/** /**
* 打卡经度 * 打卡经度

View File

@ -119,7 +119,7 @@ public class AttendanceDetailsServiceImpl implements AttendanceDetailsService {
} }
// 使用增强的 for 循环遍历 Set // 使用增强的 for 循环遍历 Set
for (String item : keys) { for (String item : keys) {
List<AttGroupBean> groupList = attTasks.getGroupData(item, 2); List<AttGroupBean> groupList = attTasks.getGroupData(item);
attTasks.createReportData(groupList, item, 2); attTasks.createReportData(groupList, item, 2);
} }
} }

View File

@ -73,7 +73,8 @@ public class AttTasks {
/** /**
* 历史考勤数据 * 历史考勤数据
*/ */
@Scheduled(initialDelay = 6000,fixedDelay = 60000 * 30) // @Scheduled(initialDelay = 6000,fixedDelay = 60000 * 30)
@Scheduled(cron = "0 50 19 * * ?")
@Async @Async
public void getHisAttTasks() { public void getHisAttTasks() {
log.info("--------考勤定时器开启------"); log.info("--------考勤定时器开启------");
@ -81,7 +82,7 @@ public class AttTasks {
return; // 如果任务已经执行过直接返回 return; // 如果任务已经执行过直接返回
} }
executed = true; // 设置标志位表示任务已经执行过 executed = true; // 设置标志位表示任务已经执行过
String startDate = "2025-01-03"; String startDate = "2025-01-01";
String endDate = "2025-01-31"; String endDate = "2025-01-31";
List<String> dateList = getStrDateListBetween(startDate, endDate); List<String> dateList = getStrDateListBetween(startDate, endDate);
// List<String> dateList = new ArrayList<>(); // List<String> dateList = new ArrayList<>();
@ -140,7 +141,7 @@ public class AttTasks {
executorService.submit(() -> { executorService.submit(() -> {
for (String date : batch) { for (String date : batch) {
try { try {
// delHisData(date); delHisData(date);
pushAttData(date, 2); pushAttData(date, 2);
} catch (Exception e) { } catch (Exception e) {
// 记录异常并继续处理下一个日期 // 记录异常并继续处理下一个日期
@ -178,11 +179,11 @@ public class AttTasks {
*/ */
private void pushAttData(String pushDate, int pushType) { private void pushAttData(String pushDate, int pushType) {
//获取黔送云的考勤数据 //获取黔送云的考勤数据
// getQsyAttendanceData(pushDate, pushType); getQsyAttendanceData(pushDate, pushType);
// //获取考勤机中的考勤数据 //获取考勤机中的考勤数据
// getMachineAttendanceData(pushDate, pushType); getMachineAttendanceData(pushDate, pushType);
// //查出每一个考勤组的应出勤天数以及考勤组的规则 // //查出每一个考勤组的应出勤天数以及考勤组的规则
List<AttGroupBean> groupList = getGroupData(pushDate, pushType); List<AttGroupBean> groupList = getGroupData(pushDate);
// //新增默认考勤数据到考勤数据和修改表 // //新增默认考勤数据到考勤数据和修改表
insertAttData(groupList, pushDate, pushType); insertAttData(groupList, pushDate, pushType);
//更新请假数据 //更新请假数据
@ -201,8 +202,14 @@ public class AttTasks {
orElseGet(ArrayList::new); orElseGet(ArrayList::new);
if (!attSourceList.isEmpty()) { if (!attSourceList.isEmpty()) {
attSourceList.forEach(c -> { attSourceList.forEach(c -> {
c.setAttAddress(AddressCoordinateFormatUtil. String address;
coordinateToAddress(c.getAttLon(), c.getAttLat())); try {
address = AddressCoordinateFormatUtil.
coordinateToAddress(c.getAttLon(), c.getAttLat());
}catch (IllegalArgumentException e){
address = "地址未转化成功";
}
c.setAttAddress(address);
if ("0".equals(c.getAttType())) { if ("0".equals(c.getAttType())) {
int i = checkTime(c.getAttCurrentTime()); int i = checkTime(c.getAttCurrentTime());
c.setAttType(String.valueOf(i)); c.setAttType(String.valueOf(i));
@ -358,7 +365,6 @@ public class AttTasks {
} else { } else {
tf = true; tf = true;
} }
if (tf) { if (tf) {
replaceHolidayData(toWorkBean, 0); replaceHolidayData(toWorkBean, 0);
replaceHolidayData(offWorkBean, 0); replaceHolidayData(offWorkBean, 0);
@ -394,7 +400,7 @@ public class AttTasks {
* *
* @return 考勤组集合 * @return 考勤组集合
*/ */
public List<AttGroupBean> getGroupData(String pushDate, int pushType) { public List<AttGroupBean> getGroupData(String pushDate) {
//查出考勤组的数据 //查出考勤组的数据
List<AttGroupBean> groupList = Optional.ofNullable(attGroupDao.selectAttGroupList(new AttGroupBean())). List<AttGroupBean> groupList = Optional.ofNullable(attGroupDao.selectAttGroupList(new AttGroupBean())).
orElseGet(ArrayList::new); orElseGet(ArrayList::new);
@ -402,7 +408,7 @@ public class AttTasks {
return new ArrayList<>(); return new ArrayList<>();
} }
//查询当月否有节假日或补班 //查询当月否有节假日或补班
List<Holiday> holidays = attSourceDataDao.selectHolidayByMonth(pushDate, pushType); List<Holiday> holidays = attSourceDataDao.selectHolidayByMonth(pushDate);
groupList.forEach(c -> { groupList.forEach(c -> {
//应考勤天 //应考勤天
List<String> attDayList = WorkdayCalculator.getWorkDay(c.getAttDay(), List<String> attDayList = WorkdayCalculator.getWorkDay(c.getAttDay(),
@ -903,7 +909,7 @@ public class AttTasks {
if (items.isEmpty()) { if (items.isEmpty()) {
continue; // 如果列表为空跳过 continue; // 如果列表为空跳过
} }
//五点之前的数据属于过来当天的下班打卡不计入 //五点之前的数据属于过来当天的下班打卡不计入
LocalTime noonEnd = LocalTime.of(5, 0); LocalTime noonEnd = LocalTime.of(5, 0);
// 获取上班时间并转换为 LocalTime 以便比较 // 获取上班时间并转换为 LocalTime 以便比较
LocalTime toWorkTime = LocalTime.parse(attGroupBean.getToWorkTime(), timeFormatter); LocalTime toWorkTime = LocalTime.parse(attGroupBean.getToWorkTime(), timeFormatter);
@ -1123,8 +1129,6 @@ public class AttTasks {
date1 = DateUtils.parseDate(DateUtils.getAfterDate(DateUtils.getYyyyMmDd(attTime)) + " " + standardTime); date1 = DateUtils.parseDate(DateUtils.getAfterDate(DateUtils.getYyyyMmDd(attTime)) + " " + standardTime);
} }
} }
if ("1".equals(attType)) { // 上班打卡 if ("1".equals(attType)) { // 上班打卡
// 计算时间差 // 计算时间差
// 1 原因30上班30:59不算迟到类似于默认可以迟到一分钟 // 1 原因30上班30:59不算迟到类似于默认可以迟到一分钟

View File

@ -8,7 +8,6 @@
select ags.*, ag.id as groupId, ag.group_name, ag.att_type select ags.*, ag.id as groupId, ag.group_name, ag.att_type
from att_group ag from att_group ag
left join att_group_setting ags on ags.group_id = ag.id and ags.is_active = 1 left join att_group_setting ags on ags.group_id = ag.id and ags.is_active = 1
left join att_group_person_relation agpr on agpr.group_id = ag.id and agpr.is_active = 1
where ag.is_active = 1 where ag.is_active = 1
<if test="groupName != null and groupName != '' "> <if test="groupName != null and groupName != '' ">
and ag.group_name = #{groupName} and ag.group_name = #{groupName}

View File

@ -7,10 +7,11 @@
<insert id="insertAttSourceData"> <insert id="insertAttSourceData">
<foreach collection="list" item="params" separator=";"> <foreach collection="list" item="params" separator=";">
replace into att_source_data(name, id_number, org_id, org_name, att_current_day, replace into att_source_data(name, id_number, org_id, org_name, att_current_day,
att_current_time, att_type, att_address, att_lon, att_lat, data_source, remark) att_current_time, att_type, att_address, province, att_lon, att_lat, data_source, remark)
values (#{params.name}, #{params.idNumber}, #{params.orgId}, #{params.orgName}, values (#{params.name}, #{params.idNumber}, #{params.orgId}, #{params.orgName},
#{params.attCurrentDay}, #{params.attCurrentTime}, #{params.attType}, #{params.attCurrentDay}, #{params.attCurrentTime}, #{params.attType},
#{params.attAddress}, #{params.attLon}, #{params.attLat}, #{params.dataSource}, #{params.remark}) #{params.attAddress}, #{province}, #{params.attLon}, #{params.attLat}, #{params.dataSource},
#{params.remark})
</foreach> </foreach>
</insert> </insert>
@ -37,7 +38,8 @@
values (#{params.userId}, #{params.userName}, #{params.orgId}, #{params.orgName}, values (#{params.userId}, #{params.userName}, #{params.orgId}, #{params.orgName},
#{params.attCurrentMonth}, #{params.requiredDays}, #{params.normalNum}, #{params.lateNum}, #{params.attCurrentMonth}, #{params.requiredDays}, #{params.normalNum}, #{params.lateNum},
#{params.earlyNum}, #{params.skippingNum}, #{params.leaveNum}, #{params.earlyNum}, #{params.skippingNum}, #{params.leaveNum},
#{params.addressErrorNum}, #{params.einErrorNum}, #{params.restNum}, #{params.outNum}, #{params.businessTripNum}) #{params.addressErrorNum}, #{params.einErrorNum}, #{params.restNum}, #{params.outNum},
#{params.businessTripNum})
</foreach> </foreach>
</insert> </insert>
@ -57,16 +59,33 @@
#{item.attAddress}) #{item.attAddress})
</foreach> </foreach>
</insert> </insert>
<insert id="insertAttSettingHistoryData">
replace into att_setting_history(user_id, group_id, current_day) values
<foreach collection="list" item="item" separator=",">
(#{item.userId},#{item.groupId},#{item.currentDay})
</foreach>
</insert>
<insert id="insertAttDataList">
insert into att_data(user_id, att_current_day, att_status, att_type)
values
<foreach collection="list" item="item" separator=",">
(#{item.userId}, #{item.attCurrentDay}, #{item.attStatus}, #{item.attType})
</foreach>
;
insert into att_data_update(user_id, att_current_day, att_status, att_type)
values
<foreach collection="list" item="item" separator=",">
(#{item.userId}, #{item.attCurrentDay}, #{item.attStatus}, #{item.attType})
</foreach>
;
</insert>
<!-- replace into att_data(user_id, org_id, att_current_day, att_current_time,-->
<!-- att_type, att_address, att_lon, att_lat, data_source, att_status, error_remake)-->
<!-- values (#{params.userId}, #{params.orgId}, #{params.attCurrentDay},-->
<!-- #{params.attCurrentTime}, #{params.attType}, #{params.attAddress}, #{params.attLon},-->
<!-- #{params.attLat}, #{params.dataSource}, #{params.attStatus}, #{params.errorRemake});-->
<update id="updateAttStatusData"> <update id="updateAttStatusData">
<foreach collection="list" item="params" separator=";"> <foreach collection="list" item="params" separator=";">
update att_data set att_current_time = #{params.attCurrentTime}, update att_data set att_current_time = #{params.attCurrentTime},
att_address = #{params.attAddress}, att_lon = #{params.attLon}, att_lat = #{params.attLat}, att_address = #{params.attAddress}, province = #{params.province}, att_lon = #{params.attLon}, att_lat =
#{params.attLat},
data_source = #{params.dataSource}, data_source = #{params.dataSource},
error_remake = #{params.remark}, error_remake = #{params.remark},
att_status = CASE att_status = CASE
@ -75,11 +94,12 @@
where dict_type = 'att_status' and (is_leave = '1' or is_leave = '2') ) THEN att_status where dict_type = 'att_status' and (is_leave = '1' or is_leave = '2') ) THEN att_status
ELSE #{params.attStatus} ELSE #{params.attStatus}
END END
where user_id = #{params.userId} and org_id = #{params.orgId} where user_id = #{params.userId}
AND att_current_day = #{params.attCurrentDay} and att_type = #{params.attType}; AND att_current_day = #{params.attCurrentDay} and att_type = #{params.attType};
update att_data_update set att_current_time = #{params.attCurrentTime}, update att_data_update set att_current_time = #{params.attCurrentTime},
att_address = #{params.attAddress}, att_lon = #{params.attLon}, att_lat = #{params.attLat}, att_address = #{params.attAddress}, province = #{params.province}, att_lon = #{params.attLon}, att_lat =
#{params.attLat},
data_source = #{params.dataSource}, data_source = #{params.dataSource},
error_remake = #{params.remark}, error_remake = #{params.remark},
att_status = CASE att_status = CASE
@ -88,7 +108,7 @@
where dict_type = 'att_status' and (is_leave = '1' or is_leave = '2')) THEN att_status where dict_type = 'att_status' and (is_leave = '1' or is_leave = '2')) THEN att_status
ELSE #{params.attStatus} ELSE #{params.attStatus}
END END
where is_update = 0 and user_id = #{params.userId} and org_id = #{params.orgId} where is_update = 0 and user_id = #{params.userId}
and att_current_day = #{params.attCurrentDay} and att_type = #{params.attType} and att_current_day = #{params.attCurrentDay} and att_type = #{params.attType}
</foreach> </foreach>
</update> </update>
@ -110,10 +130,31 @@
</if> </if>
</update> </update>
<update id="updateAttDataList">
<foreach collection="list" item="v" separator=";">
update att_data set att_status = #{v.attStatus}
where user_id = #{v.userId} and att_current_day = #{v.attCurrentDay}
<if test='v.attType != null and v.attType != ""'>
and att_type = #{v.attType}
</if>
</foreach>
</update>
<update id="updateAttDataUpdateList">
<foreach collection="list" item="v" separator=";">
update att_data_update set att_status = #{v.attStatus}
where is_update = 0 and user_id = #{v.userId}
and att_current_day = #{v.attCurrentDay}
<if test='v.attType != null and v.attType != ""'>
and att_type = #{v.attType}
</if>
</foreach>
</update>
<delete id="updateHisData"> <delete id="updateHisData">
delete delete
from att_source_data from att_source_data
where att_current_day = #{date} and data_source != 3; where att_current_day = #{date}
and data_source != 3;
update att_data update att_data
set att_current_time = null, set att_current_time = null,
att_status = 0, att_status = 0,
@ -133,7 +174,8 @@
<delete id="delHisData"> <delete id="delHisData">
delete delete
from att_source_data from att_source_data
where att_current_day = #{date} and data_source != 3; where att_current_day = #{date}
and data_source != 3;
delete delete
from att_data from att_data
where att_current_day = #{date}; where att_current_day = #{date};
@ -148,31 +190,34 @@
</delete> </delete>
<select id="getQsyAttendances" resultType="com.bonus.system.att.entity.AttSourceDataBean"> <select id="getQsyAttendances" resultType="com.bonus.system.att.entity.AttSourceDataBean">
select name, id_number, '0' as orgId, '0' as orgName, select name,
attendance_date as attCurrentDay, attendance_time as attCurrentTime, id_number,
CASE attendance_type WHEN '上班' THEN 1 ELSE 2 END as attType, '0' as orgId,
'0' as attAddress, lon as attLon, lat as attLat, '1' as dataSource '0' as orgName,
attendance_date as attCurrentDay,
attendance_time as attCurrentTime,
CASE attendance_type WHEN '上班' THEN 1 ELSE 2 END as attType,
'0' as attAddress,
lon as attLon,
lat as attLat,
'1' as dataSource
from gz_cloud.fc_sup_attendance sup from gz_cloud.fc_sup_attendance sup
where sup.attendance_date where sup.attendance_date = #{pushDate}
<if test=' pushType == "1" '> and is_wechat != 1
>= #{pushDate}
</if>
<if test=' pushType == "2" '>
= #{pushDate}
</if>
and is_wechat != 1
</select> </select>
<!-- --> <!-- -->
<select id="getAllPerson" resultType="com.bonus.system.att.entity.AttDataBean"> <select id="getAllPerson" resultType="com.bonus.system.att.entity.AttDataBean">
select su.user_id, agpr.org_id, agpr.group_id, '1' as attType, '0' as attStatus select su.user_id, agpr.org_id, agpr.group_id, '1' as attType, '0' as attStatus
from sys_user su from sys_user su
left join att_setting_history agpr on agpr.user_id = su.user_id and agpr.current_day = #{pushDate} left join att_setting_history agpr on agpr.user_id = su.user_id and agpr.current_day = #{pushDate}
where su.is_active = 1 and agpr.org_id is not null where su.is_active = 1
and agpr.org_id is not null
union union
select su.user_id, agpr.org_id, agpr.group_id, '2' as attType, '0' as attStatus select su.user_id, agpr.org_id, agpr.group_id, '2' as attType, '0' as attStatus
from sys_user su from sys_user su
left join att_setting_history agpr on agpr.user_id = su.user_id and agpr.current_day = #{pushDate} left join att_setting_history agpr on agpr.user_id = su.user_id and agpr.current_day = #{pushDate}
where su.is_active = 1 and agpr.org_id is not null where su.is_active = 1
and agpr.org_id is not null
</select> </select>
<select id="selectAttDayReport" resultType="com.bonus.system.att.entity.AttDayReportBean"> <select id="selectAttDayReport" resultType="com.bonus.system.att.entity.AttDayReportBean">
@ -206,52 +251,58 @@
<!--att_setting_history 的处理是为了获取当月最后一天在哪个考勤规则,去计算他的当月考勤天数 --> <!--att_setting_history 的处理是为了获取当月最后一天在哪个考勤规则,去计算他的当月考勤天数 -->
<select id="selectAttMonthReport" resultType="com.bonus.system.att.entity.AttMonthReportBean"> <select id="selectAttMonthReport" resultType="com.bonus.system.att.entity.AttMonthReportBean">
SELECT SELECT g.org_id,
g.org_id, v.user_id,
v.user_id, su.user_name,
su.user_name, so.org_name,
so.org_name, g.group_id,
g.group_id, DATE_FORMAT(att_current_day, '%Y-%m') AS attCurrentMonth,
DATE_FORMAT( att_current_day, '%Y-%m' ) AS attCurrentMonth, IFNULL(sum(IF(toWorkAttStatus = 1, 0.5, 0)), 0) +
IFNULL( sum( IF ( toWorkAttStatus = 1, 0.5, 0 )), 0 ) + IFNULL( sum( IF ( offWorkAttStatus = 1, 0.5, 0 )), 0 ) AS normalNum, IFNULL(sum(IF(offWorkAttStatus = 1, 0.5, 0)), 0) AS normalNum,
IFNULL( sum( IF ( toWorkAttStatus = 2, 0.5, 0 )), 0 ) + IFNULL( sum( IF ( offWorkAttStatus = 2, 0.5, 0 )), 0 ) AS lateNum, IFNULL(sum(IF(toWorkAttStatus = 2, 0.5, 0)), 0) +
IFNULL( sum( IF ( toWorkAttStatus = 3, 0.5, 0 )), 0 ) + IFNULL( sum( IF ( offWorkAttStatus = 3, 0.5, 0 )), 0 ) AS skippingNum, IFNULL(sum(IF(offWorkAttStatus = 2, 0.5, 0)), 0) AS lateNum,
IFNULL( sum( IF ( toWorkAttStatus = 4, 0.5, 0 )), 0 ) + IFNULL( sum( IF ( offWorkAttStatus = 4, 0.5, 0 )), 0 ) AS earlyNum, IFNULL(sum(IF(toWorkAttStatus = 3, 0.5, 0)), 0) +
IFNULL( sum( IF ( toWorkAttStatus = 5, 0.5, 0 )), 0 ) + IFNULL( sum( IF ( offWorkAttStatus = 5, 0.5, 0 )), 0 ) AS restNum, IFNULL(sum(IF(offWorkAttStatus = 3, 0.5, 0)), 0) AS skippingNum,
sum( IFNULL(sum(IF(toWorkAttStatus = 4, 0.5, 0)), 0) +
IF IFNULL(sum(IF(offWorkAttStatus = 4, 0.5, 0)), 0) AS earlyNum,
( toWorkAttStatus IN ( SELECT dict_value FROM sys_dict_data WHERE dict_type = 'att_status' AND is_leave = '1' ), 0.5, 0 ))+ sum( IFNULL(sum(IF(toWorkAttStatus = 5, 0.5, 0)), 0) +
IF IFNULL(sum(IF(offWorkAttStatus = 5, 0.5, 0)), 0) AS restNum,
( offWorkAttStatus IN ( SELECT dict_value FROM sys_dict_data WHERE dict_type = 'att_status' AND is_leave = '1' ), 0.5, 0 )) AS leaveNum, sum(
IFNULL( sum( IF ( toWorkAttStatus = 7, 0.5, 0 )), 0 ) + IFNULL( sum( IF ( offWorkAttStatus = 7, 0.5, 0 )), 0 ) AS outNum, IF
IFNULL( sum( IF ( toWorkAttStatus = 8, 0.5, 0 )), 0 ) + IFNULL( sum( IF ( offWorkAttStatus = 8, 0.5, 0 )), 0 ) AS einErrorNum, (toWorkAttStatus IN
IFNULL( sum( IF ( toWorkAttStatus = 9, 0.5, 0 )), 0 ) + IFNULL( sum( IF ( offWorkAttStatus = 9, 0.5, 0 )), 0 ) AS addressErrorNum, (SELECT dict_value FROM sys_dict_data WHERE dict_type = 'att_status' AND is_leave = '1'), 0.5,
IFNULL( sum( IF ( toWorkAttStatus = 10, 0.5, 0 )), 0 ) + IFNULL( sum( IF ( offWorkAttStatus = 10, 0.5, 0 )), 0 ) AS businessTripNum 0)) + sum(
FROM IF
v_att_update_data v (offWorkAttStatus IN
LEFT JOIN sys_user su ON su.user_id = v.user_id (SELECT dict_value FROM sys_dict_data WHERE dict_type = 'att_status' AND is_leave = '1'), 0.5,
LEFT JOIN ( 0)) AS leaveNum,
SELECT IFNULL(sum(IF(toWorkAttStatus = 7, 0.5, 0)), 0) +
* IFNULL(sum(IF(offWorkAttStatus = 7, 0.5, 0)), 0) AS outNum,
FROM IFNULL(sum(IF(toWorkAttStatus = 8, 0.5, 0)), 0) +
( SELECT DISTINCT * FROM att_setting_history WHERE DATE_FORMAT( current_day, '%Y-%m' ) = DATE_FORMAT(#{pushDate}, '%Y-%m' ) ORDER BY current_day DESC ) a IFNULL(sum(IF(offWorkAttStatus = 8, 0.5, 0)), 0) AS einErrorNum,
GROUP BY IFNULL(sum(IF(toWorkAttStatus = 9, 0.5, 0)), 0) +
user_id IFNULL(sum(IF(offWorkAttStatus = 9, 0.5, 0)), 0) AS addressErrorNum,
) g ON g.user_id = v.user_id IFNULL(sum(IF(toWorkAttStatus = 10, 0.5, 0)), 0) +
LEFT JOIN sys_organization so ON so.id = g.org_id IFNULL(sum(IF(offWorkAttStatus = 10, 0.5, 0)), 0) AS businessTripNum
WHERE FROM v_att_update_data v
DATE_FORMAT( att_current_day, '%Y-%m' ) = DATE_FORMAT(#{pushDate}, '%Y-%m' ) LEFT JOIN sys_user su ON su.user_id = v.user_id
LEFT JOIN (SELECT *
FROM (SELECT DISTINCT *
FROM att_setting_history
WHERE DATE_FORMAT(current_day, '%Y-%m') = DATE_FORMAT(#{pushDate}, '%Y-%m')
ORDER BY current_day DESC) a
GROUP BY user_id) g ON g.user_id = v.user_id
LEFT JOIN sys_organization so ON so.id = g.org_id
WHERE DATE_FORMAT(att_current_day, '%Y-%m') = DATE_FORMAT(#{pushDate}, '%Y-%m')
AND g.group_id IS NOT NULL AND g.group_id IS NOT NULL
GROUP BY GROUP BY DATE_FORMAT(att_current_day, '%Y-%m'),
DATE_FORMAT( att_current_day, '%Y-%m' ), v.user_id
v.user_id
</select> </select>
<select id="selectHolidayByMonth" resultType="com.bonus.system.att.entity.Holiday"> <select id="selectHolidayByMonth" resultType="com.bonus.system.att.entity.Holiday">
select * select *
from sys_holiday from sys_holiday
where where DATE_FORMAT(`date`, '%Y-%m') = DATE_FORMAT(#{pushDate}, '%Y-%m')
DATE_FORMAT(`date`, '%Y-%m') = DATE_FORMAT(#{pushDate}, '%Y-%m')
</select> </select>
<select id="getPersonLeaveApplyStatus" resultType="java.lang.Integer"> <select id="getPersonLeaveApplyStatus" resultType="java.lang.Integer">
@ -269,32 +320,31 @@
</select> </select>
<select id="getSourceAttData" resultType="com.bonus.system.att.entity.AttSourceDataBean"> <select id="getSourceAttData" resultType="com.bonus.system.att.entity.AttSourceDataBean">
select asd.*, SELECT asd.*,
su.user_id, su.user_id,
ag.org_id as orgId, ag.group_id AS groupId,
ag.group_id as groupId, g.att_type AS groupType
g.att_type as groupType FROM (SELECT * FROM att_source_data WHERE att_current_day = #{pushDate} AND data_source = 1) asd
from att_source_data asd LEFT JOIN sys_user su ON su.id_number = asd.id_number
left join sys_user su on su.id_number = asd.id_number LEFT JOIN att_setting_history ag ON ag.user_id = su.user_id
left join att_setting_history ag on ag.user_id = su.user_id and ag.current_day = #{pushDate} AND ag.current_day = #{pushDate}
left join att_group g on g.id = ag.group_id LEFT JOIN att_group g ON g.id = ag.group_id
where att_current_day = #{pushDate} UNION
and g.id is not null and asd.data_source = 1 SELECT asd.*,
union su.user_id,
select asd.*, ag.group_id AS groupId,
su.user_id, g.att_type AS groupType
ag.org_id as orgId, FROM (SELECT *
ag.group_id as groupId, FROM att_source_data
g.att_type as groupType WHERE att_current_day = #{pushDate}
from att_source_data asd AND data_source IN (2, 3)
left join sys_user su on su.user_name = asd.name AND (att_type = 1 OR att_type = 2)) asd
left join att_setting_history ag on ag.user_id = su.user_id and ag.current_day = #{pushDate} LEFT JOIN sys_user su ON su.user_name = asd.
left join att_group g on g.id = ag.group_id NAME
where att_current_day = #{pushDate} LEFT JOIN att_setting_history ag ON ag.user_id = su.user_id
and g.id is not null AND ag.current_day = #{pushDate}
and asd.data_source in (2,3) LEFT JOIN att_group g ON g.id = ag.group_id;
and (asd.att_type = 1
or asd.att_type = 2);
</select> </select>
<select id="selectAttIsExist" resultType="java.lang.Boolean"> <select id="selectAttIsExist" resultType="java.lang.Boolean">
@ -330,37 +380,34 @@
left join zkeco.iclock i on i.sn = c.sn left join zkeco.iclock i on i.sn = c.sn
left join zkeco.userinfo u on u.userid = c.userid left join zkeco.userinfo u on u.userid = c.userid
where where
<if test=' pushType == "1" '> <if test='pushType == "1"'>
DATE_FORMAT(c.checktime, '%Y-%m-%d') >= #{pushDate} DATE_FORMAT(c.checktime, '%Y-%m-%d') = #{pushDate}
</if> </if>
<if test=' pushType == "2" '> <if test='pushType == "2"'>
DATE_FORMAT(c.checktime, '%Y-%m-%d %H:%i:%s') BETWEEN concat(#{pushDate},' 00:00:00') AND DATE_ADD(DATE_ADD(concat(#{pushDate},' 00:00:00'), INTERVAL 1 DAY), INTERVAL 5 HOUR) - INTERVAL 1 SECOND DATE_FORMAT(c.checktime, '%Y-%m-%d %H:%i:%s') BETWEEN concat(#{pushDate},' 00:00:00') AND
DATE_ADD(DATE_ADD(concat(#{pushDate},' 00:00:00'), INTERVAL 1 DAY), INTERVAL 5 HOUR) - INTERVAL 1 SECOND
</if> </if>
and u.name != '') a and u.name != '') a
</select> </select>
<select id="getLeaveData" resultType="com.bonus.system.att.entity.LeaveBean"> <select id="getLeaveData" resultType="com.bonus.system.att.entity.LeaveBean">
SELECT SELECT agpr.org_id,
agpr.org_id, ag.att_type,
ag.att_type, la.*,
la.*, sdd.dict_value AS attStatus
sdd.dict_value AS attStatus FROM leave_apply la
FROM LEFT JOIN sys_dict_data sdd ON sdd.dict_label =
leave_apply la IF
LEFT JOIN sys_dict_data sdd ON sdd.dict_label = (la.leave_type IS NOT NULL, la.leave_type, la.type)
IF AND sdd.dict_type = 'att_status'
( la.leave_type IS NOT NULL, la.leave_type, la.type ) LEFT JOIN att_group_person_relation agpr ON la.user_id = agpr.user_id
AND sdd.dict_type = 'att_status' LEFT JOIN att_group ag ON ag.id = agpr.group_id
LEFT JOIN att_group_person_relation agpr ON la.user_id = agpr.user_id AND ag.is_active = '1'
LEFT JOIN att_group ag ON ag.id = agpr.group_id WHERE la.is_active = 1
AND ag.is_active = '1'
WHERE
la.is_active = 1
AND la.examine_status = 1 AND la.examine_status = 1
AND sdd.dict_value IS NOT NULL AND sdd.dict_value IS NOT NULL
AND agpr.is_active = 1 AND agpr.is_active = 1
ORDER BY ORDER BY leave_start_date DESC
leave_start_date DESC
</select> </select>
<select id="getLeaveDataByUserId" resultType="java.lang.Integer"> <select id="getLeaveDataByUserId" resultType="java.lang.Integer">
@ -376,4 +423,82 @@
from att_data from att_data
where att_current_day = #{date} where att_current_day = #{date}
</select> </select>
<select id="getAttSettingDate" resultType="java.lang.String">
SELECT DISTINCT current_day
FROM `att_setting_history`
WHERE current_day > DATE_ADD(#{startDate}, INTERVAL -#{days} DAY)
ORDER BY current_day DESC
</select>
<select id="getAttSettingHistoryDate" resultType="com.bonus.system.att.entity.AttGroupBean">
SELECT *
FROM (SELECT group_id,
user_id,
#{currentDay} as currentDay
FROM att_group_person_relation
WHERE #{currentDay} BETWEEN DATE_FORMAT(effective_time, '%Y-%m-%d')
AND DATE_FORMAT(IFNULL(NOW(), expiring_time), '%Y-%m-%d')
ORDER BY user_id,
effective_time DESC LIMIT 10000000) aa
GROUP BY user_id
</select>
<select id="getAttPerson" resultType="com.bonus.system.att.entity.AttDataBean">
SELECT su.user_id,
ash.group_id,
'1' AS attType,
'0' AS attStatus
FROM att_setting_history ash
LEFT JOIN sys_user su ON ash.user_id = su.user_id
AND su.is_active = 1
WHERE ash.current_day = #{pushDate}
UNION
SELECT su.user_id,
ash.group_id,
'2' AS attType,
'0' AS attStatus
FROM att_setting_history ash
LEFT JOIN sys_user su ON ash.user_id = su.user_id
AND su.is_active = 1
WHERE ash.current_day = #{pushDate}
</select>
<select id="getAttDataPerson" resultType="java.lang.Long">
SELECT distinct user_id
FROM att_data
WHERE att_current_day = #{pushDate}
</select>
<select id="getAttDataByStatus" resultType="com.bonus.system.att.entity.AttDataBean">
SELECT
*
FROM
att_data
WHERE
att_current_day = #{pushDate}
AND att_status = 0
<if test='attType = ""'>
AND att_type = #{attType}
</if>
</select>
<select id="getAttDataUpdateByStatus" resultType="com.bonus.system.att.entity.AttDataBean">
SELECT
*
FROM
att_data_update
WHERE
att_current_day = #{pushDate}
AND att_status = 0
And is_update = 0
<if test='attType = ""'>
AND att_type = #{attType}
</if>
</select>
<select id="selectHolidayByDay" resultType="com.bonus.system.att.entity.Holiday">
SELECT
*
FROM
sys_holiday
WHERE
date = #{pushDate}
AND type = '1'
</select>
</mapper> </mapper>