历史推送简化修改

This commit is contained in:
fl 2025-02-19 20:02:19 +08:00
parent 266d36561e
commit 6ccabe57b4
10 changed files with 347 additions and 57 deletions

View File

@ -20,11 +20,10 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -170,12 +169,19 @@ public class AttHisPullController extends BaseController {
public AjaxResult insertMonthReportTempData( AttDataDetailsBean bean) {
try{
List<String> dateList = AttTimeUtil.getStrDateListBetween(bean.getStartDate(), bean.getEndDate());
List<String> monthList = dateList.stream()
.map(LocalDate::parse)
.map(localDate -> localDate.format(DateTimeFormatter.ofPattern("yyyy-MM")))
.distinct()
.collect(Collectors.toList());
for (String date : monthList) {
//每月只保留一条数据
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Map<String, String> monthMap = new HashMap<>();
for (String dateStr : dateList) {
Date date = sdf.parse(dateStr);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
String monthKey = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1);
if (!monthMap.containsKey(monthKey)) {
monthMap.put(monthKey, dateStr);
}
}
for (String date : monthMap.values()) {
attTask.insertMonthReportTempData(date);
}
return toAjax(true);
@ -194,12 +200,19 @@ public class AttHisPullController extends BaseController {
public AjaxResult updateMonthReportData( AttDataDetailsBean bean) {
try{
List<String> dateList = AttTimeUtil.getStrDateListBetween(bean.getStartDate(), bean.getEndDate());
List<String> monthList = dateList.stream()
.map(LocalDate::parse)
.map(localDate -> localDate.format(DateTimeFormatter.ofPattern("yyyy-MM")))
.distinct()
.collect(Collectors.toList());
for (String date : monthList) {
//每月只保留一条数据
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Map<String, String> monthMap = new HashMap<>();
for (String dateStr : dateList) {
Date date = sdf.parse(dateStr);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
String monthKey = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1);
if (!monthMap.containsKey(monthKey)) {
monthMap.put(monthKey, dateStr);
}
}
for (String date : monthMap.values()) {
attTask.updateMonthReportData(date);
}
return toAjax(true);

View File

@ -257,4 +257,34 @@ public interface AttSourceDataDao {
* @return
*/
List<Long> getAttMonthReportPerson(String pushDate);
/**
* 查询当月某人是否已生成月报表
* @param userId 人员编号
* @param nowDate 时间
*/
int getMonthReportTempDataIsExist(@Param("userId") String userId, @Param("pushDate")String nowDate);
/**
* 查询当月某人生成的考勤规则记录
* @param userId
* @param nowDate
* @return
*/
List<AttGroupBean> getAttSettingHistoryByUserAndDate(@Param("userId") String userId,@Param("nowDate") String nowDate);
/**
* 修改月的应考勤天数
* @param userId
* @param nowDate
* @param i
*/
void updateMonthReportRequiredDay(@Param("userId") String userId, @Param("nowDate") String nowDate, @Param("requiredDays") Long requiredDays);
/**
* 查询考勤人员基础数据
* @param userId
* @return
*/
List<AttMonthReportBean> getOrgDataByUserId(String userId);
}

View File

@ -162,4 +162,14 @@ public class AttGroupBean {
this.entryAbnormalMinute = entryAbnormalMinute;
this.attType = attType;
}
public AttGroupBean(Long userId, Long groupId,String currentDay) {
this.userId = userId;
this.groupId = groupId;
this.currentDay = currentDay;
}
}

View File

@ -1,7 +1,7 @@
package com.bonus.system.att.service;
import com.bonus.system.api.domain.MapVo;
import com.bonus.system.att.entity.OrgChangeBean;
import com.bonus.system.att.entity.AttGroupBean;
import com.bonus.system.att.entity.AttMonthReportBean;
import java.util.List;
@ -74,4 +74,46 @@ public interface AttCalService {
* @param pushDate 时间
*/
void updateMonthReportData(String pushDate);
/**
* 查询当月某人是否已生成月报表
* @param userId 时间
* @param nowDate 时间
*/
int getMonthReportTempData(String userId, String nowDate);
/**
* 查询当月某人生成的考勤规则记录
* @param userId
* @param nowDate
* @return
*/
List<AttGroupBean> getAttSettingHistoryByUserAndDate(String userId, String nowDate);
/**
* 简单版考勤组查询
* @return
*/
List<AttGroupBean> getSimplyGroupData();
/**
* 修改月的应考勤天数
* @param userId
* @param nowDate
* @param i
*/
void updateMonthReportRequiredDay(String userId, String nowDate, Long i);
/**
* 月半才第一次加入考勤组
* @param list
*/
void insertMonthHalfReportTempData(List<AttMonthReportBean> list);
/**
* 查询考勤人员基础数据
* @param userId
* @return
*/
List<AttMonthReportBean> getOrgDataByUserId(String userId);
}

View File

@ -69,7 +69,7 @@ public class AttCalServiceImpl implements AttCalService {
LocalDate newDate = date.minusDays(n);
// 如果需要将结果格式化为特定格式的字符串可以使用以下代码
String formattedNewDate = newDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
//向前推1个月的时间检索缺少哪一天推送哪一天
//向前推n天的时间检索缺少哪一天推送哪一天
List<String> dateListOne = attSourceDataDao.getAttSettingDate(startDate, n);
dateList = AttTimeUtil.getStrDateListBetween(formattedNewDate, startDate);
// dateList 中移除所有在 dateListOne 中存在的元素
@ -98,7 +98,7 @@ public class AttCalServiceImpl implements AttCalService {
//查出人员考勤记录
AtomicReference<List<AttSourceDataBean>> sourceDataList = new AtomicReference<>(attSourceDataDao.getSourceAttData(pushDate, pushType));
//查出考勤组
List<AttGroupBean> groupList = getGroupData(pushDate);
List<AttGroupBean> groupList = getSimplyGroupData();
//
groupList.forEach(c -> {
List<AttSourceDataBean> list = Collections.emptyList();
@ -289,6 +289,64 @@ public class AttCalServiceImpl implements AttCalService {
attSourceDataDao.updateAttMonthReport(monthReportList);
}
/**
* 查询当月某人是否已生成月报表
* @param userId 时间
* @param nowDate 时间
*/
@Override
public int getMonthReportTempData(String userId, String nowDate) {
return attSourceDataDao.getMonthReportTempDataIsExist( userId, nowDate);
}
/**
* 查询当月某人生成的考勤规则记录
* @param userId
* @param nowDate
* @return
*/
@Override
public List<AttGroupBean> getAttSettingHistoryByUserAndDate(String userId, String nowDate) {
return attSourceDataDao.getAttSettingHistoryByUserAndDate( userId, nowDate);
}
@Override
public List<AttGroupBean> getSimplyGroupData() {
//查出考勤组的数据
List<AttGroupBean> groupList = Optional.ofNullable(attGroupDao.selectAttGroupList(new AttGroupBean())).
orElseGet(ArrayList::new);
if (groupList.isEmpty()) {
return new ArrayList<>();
}
return groupList;
}
/**
* 修改月的应考勤天数
* @param userId
* @param nowDate
* @param i
*/
@Override
public void updateMonthReportRequiredDay(String userId, String nowDate, Long i) {
attSourceDataDao.updateMonthReportRequiredDay(userId, nowDate, i);
}
@Override
public void insertMonthHalfReportTempData(List<AttMonthReportBean> list) {
attSourceDataDao.insertAttMonthReportTemp(list);
}
/**
* 查询考勤人员基础数据
* @param userId
* @return
*/
@Override
public List<AttMonthReportBean> getOrgDataByUserId(String userId) {
return attSourceDataDao.getOrgDataByUserId(userId);
}
/**
* 人员考勤模版数据默认是未打卡
* 每天早上0点30执行一次

View File

@ -1,22 +1,28 @@
package com.bonus.system.att.service;
import com.bonus.common.core.constant.Constants;
import com.bonus.common.core.utils.DateTimeHelper;
import com.bonus.common.core.utils.bean.BeanUtils;
import cn.hutool.core.date.DateUtil;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.system.att.dao.AttGroupDao;
import com.bonus.system.att.dao.AttSourceDataDao;
import com.bonus.system.att.entity.AttDataBean;
import com.bonus.system.att.entity.AttGroupBean;
import com.bonus.system.att.entity.AttGroupCheckOrgBean;
import com.bonus.system.att.entity.AttMonthReportBean;
import com.bonus.system.att.entity.Holiday;
import com.bonus.system.att.utils.TreeUtils;
import com.bonus.system.att.utils.WorkdayCalculator;
import com.bonus.system.basic.domain.SysTree;
import com.bonus.system.dept.dao.ProDeptRoleDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
/**
@ -80,7 +86,7 @@ public class AttGroupServiceImpl implements AttGroupService {
checkOrgAllList.get(k).setGroupId(bean.getGroupId());
}
int x = attGroupDao.insertAttGroupPerson(checkOrgAllList);
addAttData(bean, checkOrgAllList);
addAttData(checkOrgAllList);
if (j > 0 && (x == checkOrgAllList.size())) {
result = 1;
}
@ -140,7 +146,7 @@ public class AttGroupServiceImpl implements AttGroupService {
if (!addList.isEmpty()) {
//添加考勤组绑定人员
attGroupDao.insertAttGroupPerson(addList);
addAttData(bean, addList);
addAttData(addList);
}
return 1;
}
@ -148,32 +154,80 @@ public class AttGroupServiceImpl implements AttGroupService {
}
/**
* 新增的人员 生成当天的考勤模板/与考勤规则进行绑定
* 新增的人员
* 考勤人员列表
* 基模版数据生成
* 月报表模板生成或月考勤天数修改
*
* @param bean
* @param addList
* @return void
* @author cwchen
* @date 2025/2/18 13:56
*/
public void addAttData(AttGroupBean bean, List<AttGroupCheckOrgBean> addList) {
// 新增的人员 生成当天的考勤模板/与考勤规则进行绑定
List<AttGroupBean> list = new ArrayList<>();
List<AttDataBean> listPerson = new ArrayList<>();
for (AttGroupCheckOrgBean attGroupCheckOrgBean : addList) {
AttGroupBean groupBean = new AttGroupBean();
groupBean.setGroupId(attGroupCheckOrgBean.getGroupId());
groupBean.setUserId(Long.parseLong(attGroupCheckOrgBean.getUserId()));
groupBean.setCurrentDay(DateTimeHelper.getNowDate());
list.add(groupBean);
}
attCalService.insertAttTempData(DateTimeHelper.getNowDate(),2);
/*// 新增考勤人员列表
attSourceDataDao.insertAttSettingHistoryData(list);
// 查询人员组织机构ID
listPerson = attGroupDao.getUserInfo(bean, addList);
// 新增人员考勤模板数据
attSourceDataDao.insertAttDataList(listPerson);*/
public void addAttData(List<AttGroupCheckOrgBean> addList) {
String nowDate = DateUtil.today();
// 考勤人员列表添加基模版数据生成
attCalService.insertAttDateHistory(nowDate);
attCalService.insertAttTempData(nowDate,2);
addList.forEach(m -> {
int i = attCalService.getMonthReportTempData(m.getUserId(),nowDate);
AtomicLong requiredDays = new AtomicLong();
//查询历史考勤规则方便分组计算
List<AttGroupBean> dataList = attCalService.getAttSettingHistoryByUserAndDate(m.getUserId(),nowDate);
//以最后一个考勤规则补全剩下当月日期所有考勤规则数据
// 获取最后一个数据的日期
AttGroupBean lastData = dataList.get(dataList.size() - 1);
LocalDate lastDate = LocalDate.parse(lastData.getCurrentDay(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
// 获取当月的总天数
int lastDayOfMonth = lastDate.lengthOfMonth();
// 从最后一个日期开始补全当月剩下的日期
for (int day = lastDate.getDayOfMonth() + 1; day <= lastDayOfMonth; day++) {
LocalDate newDate = lastDate.withDayOfMonth(day);
dataList.add(new AttGroupBean(lastData.getUserId(), lastData.getGroupId(), newDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
}
if (!dataList.isEmpty()) {
List<List<AttGroupBean>> result = new ArrayList<>();
List<AttGroupBean> currentList = new ArrayList<>();
//查出考勤组
List<AttGroupBean> groupList = attCalService.getSimplyGroupData();
List<Holiday> holidays = attSourceDataDao.selectHolidayByMonth(nowDate);
Long currentGroupId = dataList.get(0).getGroupId();
for (AttGroupBean data : dataList) {
if (!Objects.equals(data.getGroupId(), currentGroupId)) {
result.add(currentList);
currentList = new ArrayList<>();
currentGroupId = data.getGroupId();
}
currentList.add(data);
}
result.add(currentList);
result.forEach(v -> {
List<AttGroupBean> collect = groupList.stream().filter(g -> Objects.equals(g.getGroupId(), v.get(0).getGroupId())).collect(Collectors.toList());
if(!collect.isEmpty()){
//应考勤天数
List<String> attDayList = WorkdayCalculator.getWorkDay(collect.get(0).getAttDay(),
collect.get(0).getIsHaveHoliday(), holidays, v.get(0).getCurrentDay(),v.get(v.size()-1).getCurrentDay());
requiredDays.addAndGet(attDayList.size());
}
});
}
if(i>0){
//存在属于修改考勤组需要修改月报表考勤天数
attCalService.updateMonthReportRequiredDay(m.getUserId(),nowDate,requiredDays.get());
}else{
//查询人当前组织
List<AttMonthReportBean> list = attCalService.getOrgDataByUserId(m.getUserId());
if(!list.isEmpty()){
list.get(0).setRequiredDays(requiredDays.intValue());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
String currentYearMonth = sdf.format(new Date());
list.get(0).setAttCurrentMonth(currentYearMonth);
attCalService.insertMonthHalfReportTempData(list);
}
}
});
}
public Map<String, List<AttGroupCheckOrgBean>> compareByUserId(

View File

@ -184,12 +184,7 @@ public class AttendanceDetailsServiceImpl implements AttendanceDetailsService {
public List<AttDayReportBean> selectAttDayReportList(AttDayReportBean bean) {
List<AttDayReportBean> list = attendanceDetailsDao.getAttDayReportList(bean);
if (bean.getOrgId() != null) {
return list.stream().filter(c -> Objects.equals(c.getOrgId(), bean.getOrgId()))
.collect(Collectors.toList());
} else {
return getAttDayReportListAll(list);
}
return getAttDayReportListAll(list);
}
@Override

View File

@ -65,6 +65,55 @@ public class WorkdayCalculator {
return new ArrayList<>();
}
/**
*
* @param attDays 周打卡日期
* @param type 是否有节假日
* @param holidays 月法假
* @param startDate 开始日期
* @param startDate 结束日期
* @return
*/
public static List<String> getWorkDay(String attDays, int type, List<Holiday> holidays, String startDate, String endDate) {
List<Integer> dueWorkDates = getDueWorkDates(attDays);
// 定义日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
try {
// 解析日期字符串为 LocalDate 对象
LocalDate date = LocalDate.parse(startDate, formatter);
// 获取年份和月份
int year = date.getYear();
int month = date.getMonthValue(); // 获取月份1-12
// 获取工作日集合排除周末
List<Date> workDays = getWorkDays(year, month, dueWorkDates);
// 获取工作日字符串集合
List<String> dateString = getDateString(workDays);
// 获取法定节假日集合
if (type == 1) {
holidays.forEach(c -> {
if (c.getType().equals("1")) {
dateString.remove(c.getDate());
} else if (c.getType().equals("2")) {
dateString.add(c.getDate());
}
});
//只获取规定时间的考勤天数
List<String> strDateListBetween = AttTimeUtil.getStrDateListBetween(startDate, endDate);
// 移除不在 strDateListBetween 中的元素
dateString.retainAll(strDateListBetween);
}else{
//只获取规定时间的考勤天数
List<String> strDateListBetween = AttTimeUtil.getStrDateListBetween(startDate, endDate);
// 移除不在 strDateListBetween 中的元素
dateString.retainAll(strDateListBetween);
}
return dateString;
} catch (Exception e) {
e.printStackTrace();
}
return new ArrayList<>();
}
private static List<Integer> getDueWorkDates(String s) {
List<Integer> week = new ArrayList<>();
List<String> list = new ArrayList<>(Arrays.asList(s.split(",")));

View File

@ -199,6 +199,12 @@
</foreach>
</update>
<update id="updateMonthReportRequiredDay">
update att_month_report
set required_days = #{requiredDays}
where user_id = #{userId}
and att_current_month = DATE_FORMAT(#{nowDate}, '%Y-%m')
</update>
<delete id="updateHisData">
delete
@ -555,5 +561,37 @@
WHERE
att_current_month = DATE_FORMAT( #{pushDate}, '%Y-%m' )
</select>
<select id="getMonthReportTempDataIsExist" resultType="java.lang.Integer">
SELECT
count(1)
FROM
att_month_report
WHERE
att_current_month = DATE_FORMAT( #{pushDate}, '%Y-%m' ) and user_id = #{userId}
</select>
<select id="getAttSettingHistoryByUserAndDate" resultType="com.bonus.system.att.entity.AttGroupBean">
SELECT
ash.group_id,
ash.user_id,
ash.current_day
from
att_setting_history ash
WHERE
ash.user_id = #{userId}
and locate(DATE_FORMAT( #{nowDate}, '%Y-%m' ),ash.current_day)
order by current_day ASC
</select>
<select id="getOrgDataByUserId" resultType="com.bonus.system.att.entity.AttMonthReportBean">
SELECT
su.user_id,
su.user_name,
suo.org_id,
so.org_name
FROM
sys_user su
LEFT JOIN sys_user_org suo ON suo.user_id = su.user_id
LEFT JOIN sys_organization so ON so.id = suo.org_id
where su.user_id = #{userId}
</select>
</mapper>

View File

@ -246,13 +246,14 @@
</select>
<select id="getAttDayReportList" resultType="com.bonus.system.att.entity.AttDayReportBean">
SELECT adr.*,
IF(awa.outCount is null,0,awa.outCount) as outCount
FROM att_day_report adr
LEFT JOIN (SELECT att_current_day,org_id,count( DISTINCT user_id) as outCount FROM att_work_abnormal GROUP BY att_current_day,org_id) awa
ON awa.att_current_day = adr.att_current_day and awa.org_id = adr.org_id
SELECT
adr.*,
IF
( awa.outCount IS NULL, 0, awa.outCount ) AS outCount
FROM
att_day_report adr
LEFT JOIN ( SELECT att_current_day, count( DISTINCT user_id ) AS outCount FROM att_work_abnormal GROUP BY att_current_day ) awa ON awa.att_current_day = adr.att_current_day
WHERE adr.att_current_day BETWEEN #{startDate} AND #{endDate}
</select>
<select id="getAttMonthReportList" resultType="com.bonus.system.att.entity.AttMonthReportBean">