| | |
| | | package me.zhengjie.modules.quartz.service.impl; |
| | | |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.attendance.domain.*; |
| | | import me.zhengjie.modules.attendance.repository.*; |
| | | import me.zhengjie.modules.attendance.service.impl.AttendanceLeaveServiceImpl; |
| | | import me.zhengjie.modules.attendance.service.impl.AttendanceServiceImpl; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.system.domain.Job; |
| | | import me.zhengjie.modules.system.domain.Role; |
| | | import me.zhengjie.modules.system.domain.SysConfigHoliday; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.transaction.Transactional; |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.DayOfWeek; |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | | @Transactional |
| | | @RequiredArgsConstructor |
| | | public class AttendanceMonthTalkServiceImpl { |
| | | |
| | | private final AttendanceRepository attendanceRepository; |
| | | private final UserRepository userRepository; |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final AttendanceGoOutRepository attendanceGoOutRepository; |
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository; |
| | | private final AttendanceLeaveRepository attendanceLeaveRepository; |
| | | private final AttendanceMonthRepository attendanceMonthRepository; |
| | | private final AttendanceMonthLeaveRepository attendanceMonthLeaveRepository; |
| | | private final AttendanceLeaveServiceImpl attendanceLeaveService; |
| | | |
| | | /** |
| | | * 月报set |
| | | */ |
| | | public void getMonthlyInfo() throws ParseException { |
| | | //节假日,工作日 |
| | | List<Timestamp> holiday = new ArrayList<>(), isWork = new ArrayList<>(); |
| | | // 查询节假日 |
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll(); |
| | | for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){ |
| | | if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){ |
| | | //工作日 |
| | | isWork.add(sysConfigHoliday.getHolidayDate()); |
| | | }else{ |
| | | holiday.add(sysConfigHoliday.getHolidayDate()); |
| | | } |
| | | } |
| | | |
| | | Map<Long, AttendanceMonth> info = new HashMap<>(); |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
| | | LocalDate localDate = LocalDate.now(); |
| | | localDate = localDate.minusMonths(1); |
| | | //上月第一天 |
| | | String baseDate = dateTimeFormatter.format(localDate); |
| | | // 查询上个月考勤表 |
| | | List<Attendance> attendanceList = attendanceRepository.findAllLikeDate(baseDate + "%"); |
| | | for(Attendance attendance : attendanceList){ |
| | | // 查询用户 |
| | | User user = userRepository.findById(attendance.getUserId()).orElseGet(User::new); |
| | | Long userId = attendance.getUserId(); |
| | | if (!info.containsKey(userId)) { |
| | | info.put(userId, new AttendanceMonth()); |
| | | info.get(userId).setAttendanceDate(Timestamp.valueOf(baseDate + "-01 00:00:00")); |
| | | info.get(userId).setUserId(userId); |
| | | info.get(userId).setCompanyId(user.getCompany().getId()); |
| | | info.get(userId).setDeptId(user.getDept().getId()); |
| | | // 查询岗位 |
| | | if(user.getJobs().size() != 0){ |
| | | Job job = user.getJobs().iterator().next(); |
| | | info.get(userId).setJobId(job.getId()); |
| | | } |
| | | } |
| | | DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | Boolean isWeekend = LocalDate.parse(attendance.getAttendanceDate().toString().substring(0,10), dateTimeFormatter1).getDayOfWeek() == DayOfWeek.SATURDAY || LocalDate.parse(attendance.getAttendanceDate().toString().substring(0,10), dateTimeFormatter1).getDayOfWeek() == DayOfWeek.SUNDAY; |
| | | // 不是周末并且节假日表中不存在 或者 是周末并且工作日数组中存在 |
| | | if((!isWeekend && !holiday.contains(attendance.getAttendanceDate())) || (isWeekend && isWork.contains(attendance.getAttendanceDate()))){ |
| | | // 应出勤天数 |
| | | info.get(userId).setRequiredAttendanceDays(info.get(userId).getRequiredAttendanceDays() == null ? 1 : info.get(userId).getRequiredAttendanceDays() + 1); |
| | | // 实际出勤天数 |
| | | if(ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) || ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime())){ |
| | | info.get(userId).setActualAttendanceDays(info.get(userId).getActualAttendanceDays() == null ? 1 : info.get(userId).getActualAttendanceDays() + 1); |
| | | } |
| | | // 实际出勤时长 |
| | | double actualAttendanceTime = 8.0; |
| | | if(ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_START_LATE)){ |
| | | // 迟到次数 |
| | | info.get(userId).setCountOfBeingLate(info.get(userId).getCountOfBeingLate() == null ? 1 : info.get(userId).getCountOfBeingLate() + 1); |
| | | Duration onDuration = Duration.between(attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getActualWorkStartTime().toLocalDateTime()); |
| | | // 实际出勤时长 |
| | | actualAttendanceTime -= new BigDecimal(onDuration.getSeconds()).divide(BigDecimal.valueOf(3600), 2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
| | | // 迟到时长 |
| | | info.get(userId).setTimeOfBeingLate(info.get(userId).getTimeOfBeingLate() == null ? Double.valueOf(new BigDecimal((float) onDuration.getSeconds() / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()) : Double.valueOf(BigDecimal.valueOf(info.get(userId).getTimeOfBeingLate()).add(new BigDecimal((float) onDuration.getSeconds() / 3600).setScale(2, BigDecimal.ROUND_HALF_UP)).toString())); |
| | | } |
| | | if(ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_START_EARLY)){ |
| | | // 早退次数 |
| | | info.get(userId).setCountOfBeingEarly(info.get(userId).getCountOfBeingEarly() == null ? 1 : info.get(userId).getCountOfBeingEarly() + 1); |
| | | Duration offDuration = Duration.between(attendance.getActualWorkEndTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | // 实际出勤时长 |
| | | actualAttendanceTime -= new BigDecimal(offDuration.getSeconds()).divide(BigDecimal.valueOf(3600), 2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
| | | // 早退时长 |
| | | info.get(userId).setTimeOfBeingEarly(info.get(userId).getTimeOfBeingEarly() == null ? Double.valueOf(new BigDecimal((float) offDuration.getSeconds() / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()) : Double.valueOf(BigDecimal.valueOf(info.get(userId).getTimeOfBeingEarly()).add(new BigDecimal((float) offDuration.getSeconds() / 3600).setScale(2, BigDecimal.ROUND_HALF_UP)).toString())); |
| | | } |
| | | if(attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED)){ |
| | | // 上班缺卡次数 |
| | | info.get(userId).setOnCardNumber(info.get(userId).getOnCardNumber() == null ? 1 : info.get(userId).getOnCardNumber() + 1); |
| | | // 实际出勤时长 |
| | | actualAttendanceTime = 0.0; |
| | | } |
| | | if(attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED)){ |
| | | // 下班缺卡次数 |
| | | info.get(userId).setOffCardNumber(info.get(userId).getOffCardNumber() == null ? 1 : info.get(userId).getOffCardNumber() + 1); |
| | | // 实际出勤时长 |
| | | actualAttendanceTime = 0.0; |
| | | } |
| | | // 实际出勤时长 |
| | | info.get(userId).setActualAttendanceTime(info.get(userId).getActualAttendanceTime() == null ? actualAttendanceTime : info.get(userId).getActualAttendanceTime() + actualAttendanceTime); |
| | | } |
| | | } |
| | | |
| | | LocalDateTime startTime = localDate.with(TemporalAdjusters.firstDayOfMonth()).atTime(0, 0, 0); |
| | | LocalDateTime endTime = localDate.with(TemporalAdjusters.lastDayOfMonth()).atTime(23, 59, 59); |
| | | List<AttendanceMonth> insertData = new ArrayList<>(); |
| | | for (AttendanceMonth value : info.values()) { |
| | | // 查询当月外出 |
| | | List<AttendanceGoOut> goOutList = attendanceGoOutRepository.findByUserAndDate(value.getUserId(), startTime, endTime); |
| | | int goOutNumber = goOutList.size(); |
| | | // 外出次数 |
| | | value.setGoOutNumber(Long.valueOf(goOutNumber)); |
| | | Double goOutTimes = 0.0; |
| | | for(int i = 0; i < goOutList.size(); i++){ |
| | | goOutTimes = goOutTimes + goOutList.get(i).getOutDuration(); |
| | | } |
| | | // 外出时长 |
| | | value.setGoOutTime(goOutTimes); |
| | | // 查询当月的出差 |
| | | List<AttendanceBusinessTravel> businessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(value.getUserId(), startTime, endTime); |
| | | int bussNumber = businessTravelList.size(); |
| | | // 出差次数 |
| | | value.setBussNumber(Long.valueOf(bussNumber)); |
| | | // 出差时长 |
| | | value.setBussTime(Double.valueOf(bussNumber * 8)); |
| | | // 应出勤时长 |
| | | value.setRequiredAttendanceTime(Double.valueOf(value.getRequiredAttendanceDays() * 8)); |
| | | // 查询当月请假 |
| | | List<AttendanceLeave> leaveList = attendanceLeaveRepository.findByUserIdAndDate(value.getUserId(), startTime, endTime); |
| | | // 当月请假时长 |
| | | Double leaveTimes = 0.0; |
| | | for(int i = 0; i < leaveList.size(); i++){ |
| | | // 时间单位为小时就直接加,否则就是天为单位需要乘8 |
| | | leaveTimes = leaveList.get(i).getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_HOUR) ? leaveTimes + leaveList.get(i).getLeaveDuration() : leaveTimes + leaveList.get(i).getLeaveDuration() * 8; |
| | | } |
| | | // 实际出勤时长 |
| | | value.setActualAttendanceTime(Double.valueOf(value.getActualAttendanceTime() - leaveTimes)); |
| | | if (value.getActualAttendanceTime() < 0) { |
| | | value.setActualAttendanceTime(0.0); |
| | | } |
| | | //验证考勤月报的确认按钮 |
| | | AttendanceMonth attendanceMonthly = attendanceMonthRepository.findByAttendanceDateAndUserId(baseDate + "-01 00:00:00", value.getUserId()); |
| | | if(ObjectUtil.isNotEmpty(attendanceMonthly) && attendanceMonthly.getIsAdmit() != null && attendanceMonthly.getIsAdmit().equals(Constant.APPROVE_STATUS_ACKNOWLEDGED)){ |
| | | value.setIsAdmit(attendanceMonthly.getIsAdmit()); |
| | | } |
| | | if(ObjectUtil.isNotEmpty(attendanceMonthly) && attendanceMonthly.getIsPublicity() != null && attendanceMonthly.getIsPublicity().equals(Constant.PUBLICITY_STATUS_YES)){ |
| | | value.setIsPublicity(attendanceMonthly.getIsPublicity()); |
| | | } |
| | | insertData.add(value); |
| | | } |
| | | // 删除上个月信息 |
| | | attendanceMonthRepository.deleteByActualAttendanceDays(baseDate + "-01 00:00:00"); |
| | | // 保存当前添加的记录 |
| | | attendanceMonthRepository.saveAll(insertData); |
| | | |
| | | // 查询月报相关请假类型表 |
| | | List<AttendanceMonthLeave> attendanceMonthLeaves = attendanceMonthLeaveRepository.findByAttendanceDate(baseDate + "-01 00:00:00"); |
| | | if(attendanceMonthLeaves.size() != 0){ |
| | | for(AttendanceMonthLeave attendanceMonthLeave : attendanceMonthLeaves){ |
| | | // 删除数据 |
| | | attendanceMonthLeaveRepository.deleteById(attendanceMonthLeave.getId()); |
| | | } |
| | | } |
| | | // 月报相关的请假类型添加 |
| | | for(int i = 0; i < insertData.size(); i++){ |
| | | // 查询当月请假 |
| | | List<AttendanceLeave> leaves = attendanceLeaveRepository.findByUserIdAndDate(insertData.get(i).getUserId(), startTime, endTime); |
| | | // 请假类型集合 |
| | | List<String> leaveTpeList = new ArrayList<>(); |
| | | for(int i1 = 0; i1 < leaves.size(); i1++){ |
| | | // 当前循环人员的所有请假类型 |
| | | leaveTpeList.add(leaves.get(i1).getLeaveType()); |
| | | } |
| | | |
| | | // 请假类型去重 |
| | | HashSet h = new HashSet(leaveTpeList); |
| | | leaveTpeList.clear(); |
| | | leaveTpeList.addAll(h); |
| | | |
| | | // 遍历请假类型集合添加数据 |
| | | for(int i2 = 0; i2 < leaveTpeList.size(); i2++){ |
| | | AttendanceMonthLeave attendanceMonthLeave = new AttendanceMonthLeave(); |
| | | attendanceMonthLeave.setAttendanceMonthId(insertData.get(i).getId()); |
| | | attendanceMonthLeave.setAttendanceDate(insertData.get(i).getAttendanceDate()); |
| | | attendanceMonthLeave.setUserId(insertData.get(i).getUserId()); |
| | | // 请假类型 |
| | | attendanceMonthLeave.setLeaveType(leaveTpeList.get(i2)); |
| | | // 根据请假类型查询请假 |
| | | List<AttendanceLeave> leaveList = attendanceLeaveRepository.findByUserIdAndDateAndLeaveType(insertData.get(i).getUserId(), startTime, endTime,leaveTpeList.get(i2)); |
| | | // 请假次数 |
| | | attendanceMonthLeave.setLeaveCount(Long.valueOf(leaveList.size())); |
| | | // 请假类型时长 |
| | | attendanceMonthLeave.setLeaveTime(getLeaveDuration(leaves,leaveTpeList.get(i2))); |
| | | //年假剩余时长 |
| | | if(leaveTpeList.get(i2).equals(Constant.LEAVE_TYPE_ANNUAL_LEAVE)){ |
| | | Double yearTime = attendanceLeaveService.getYearTimeLength(insertData.get(i).getUserId()); |
| | | attendanceMonthLeave.setSurplusDuration(yearTime); |
| | | } else if (leaveTpeList.get(i2).equals(Constant.LEAVE_TYPE_LACTATION_LEAVE)) { |
| | | Double yearTime = attendanceLeaveService.getOverTimeLength(insertData.get(i).getUserId()); |
| | | attendanceMonthLeave.setSurplusDuration(yearTime); |
| | | } |
| | | attendanceMonthLeaveRepository.save(attendanceMonthLeave); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取请假时长 |
| | | * @param leaveList |
| | | * @return |
| | | */ |
| | | public Double getLeaveDuration(List<AttendanceLeave> leaveList, String type) { |
| | | Double leaveTimes = 0.0; |
| | | for(int i = 0; i < leaveList.size(); i++) { |
| | | //时间单位为小时就直接加 |
| | | if(leaveList.get(i).getLeaveType().equals(type)) { |
| | | if(leaveList.get(i).getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_HOUR)) { |
| | | leaveTimes = leaveList.get(i).getLeaveDuration() + leaveTimes; |
| | | } |
| | | //天为单位需要乘8 |
| | | if(leaveList.get(i).getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)) { |
| | | leaveTimes = leaveList.get(i).getLeaveDuration() * 8 + leaveTimes; |
| | | } |
| | | } |
| | | } |
| | | return leaveTimes; |
| | | } |
| | | } |
| | | package me.zhengjie.modules.quartz.service.impl;
|
| | |
|
| | |
|
| | | import cn.hutool.core.util.ObjectUtil;
|
| | | import lombok.RequiredArgsConstructor;
|
| | | import me.zhengjie.modules.attendance.domain.*;
|
| | | import me.zhengjie.modules.attendance.repository.*;
|
| | | import me.zhengjie.modules.attendance.service.impl.AttendanceLeaveServiceImpl;
|
| | | import me.zhengjie.modules.attendance.service.impl.AttendanceServiceImpl;
|
| | | import me.zhengjie.modules.constant.Constant;
|
| | | import me.zhengjie.modules.system.domain.Job;
|
| | | import me.zhengjie.modules.system.domain.Role;
|
| | | import me.zhengjie.modules.system.domain.SysConfigHoliday;
|
| | | import me.zhengjie.modules.system.domain.User;
|
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository;
|
| | | import me.zhengjie.modules.system.repository.UserRepository;
|
| | | import org.apache.commons.lang3.ObjectUtils;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import javax.transaction.Transactional;
|
| | | import java.math.BigDecimal;
|
| | | import java.sql.Timestamp;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.time.DayOfWeek;
|
| | | import java.time.Duration;
|
| | | import java.time.LocalDate;
|
| | | import java.time.LocalDateTime;
|
| | | import java.time.format.DateTimeFormatter;
|
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.*;
|
| | |
|
| | | @Service
|
| | | @Transactional
|
| | | @RequiredArgsConstructor
|
| | | public class AttendanceMonthTalkServiceImpl {
|
| | |
|
| | | private final AttendanceRepository attendanceRepository;
|
| | | private final UserRepository userRepository;
|
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository;
|
| | | private final AttendanceGoOutRepository attendanceGoOutRepository;
|
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
|
| | | private final AttendanceLeaveRepository attendanceLeaveRepository;
|
| | | private final AttendanceMonthRepository attendanceMonthRepository;
|
| | | private final AttendanceMonthLeaveRepository attendanceMonthLeaveRepository;
|
| | | private final AttendanceLeaveServiceImpl attendanceLeaveService;
|
| | |
|
| | | /**
|
| | | * 月报set
|
| | | */
|
| | | public void getMonthlyInfo() {
|
| | | //节假日,工作日
|
| | | List<Timestamp> holiday = new ArrayList<>(), isWork = new ArrayList<>();
|
| | | // 查询节假日
|
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll();
|
| | | for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){
|
| | | if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){
|
| | | //工作日
|
| | | isWork.add(sysConfigHoliday.getHolidayDate());
|
| | | }else{
|
| | | holiday.add(sysConfigHoliday.getHolidayDate());
|
| | | }
|
| | | }
|
| | |
|
| | | Map<Long, AttendanceMonth> info = new HashMap<>();
|
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
| | | LocalDate localDate = LocalDate.now();
|
| | | localDate = localDate.minusMonths(1);
|
| | | //上月第一天
|
| | | String baseDate = dateTimeFormatter.format(localDate);
|
| | | // 查询上个月考勤表
|
| | | List<Attendance> attendanceList = attendanceRepository.findAllLikeDate(baseDate + "%");
|
| | | for(Attendance attendance : attendanceList){
|
| | | // 查询用户
|
| | | User user = userRepository.findById(attendance.getUserId()).orElseGet(User::new);
|
| | | Long userId = attendance.getUserId();
|
| | | if (!info.containsKey(userId)) {
|
| | | info.put(userId, new AttendanceMonth());
|
| | | info.get(userId).setAttendanceDate(Timestamp.valueOf(baseDate + "-01 00:00:00"));
|
| | | info.get(userId).setUserId(userId);
|
| | | info.get(userId).setCompanyId(user.getCompany().getId());
|
| | | info.get(userId).setDeptId(user.getDept().getId());
|
| | | // 查询岗位
|
| | | if(user.getJobs().size() != 0){
|
| | | Job job = user.getJobs().iterator().next();
|
| | | info.get(userId).setJobId(job.getId());
|
| | | }
|
| | | }
|
| | | DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
| | | Boolean isWeekend = LocalDate.parse(attendance.getAttendanceDate().toString().substring(0,10), dateTimeFormatter1).getDayOfWeek() == DayOfWeek.SATURDAY || LocalDate.parse(attendance.getAttendanceDate().toString().substring(0,10), dateTimeFormatter1).getDayOfWeek() == DayOfWeek.SUNDAY;
|
| | | // 不是周末并且节假日表中不存在 或者 是周末并且工作日数组中存在
|
| | | if((!isWeekend && !holiday.contains(attendance.getAttendanceDate())) || (isWeekend && isWork.contains(attendance.getAttendanceDate()))){
|
| | | // 应出勤天数
|
| | | info.get(userId).setRequiredAttendanceDays(info.get(userId).getRequiredAttendanceDays() == null ? 1 : info.get(userId).getRequiredAttendanceDays() + 1);
|
| | | // 实际出勤天数
|
| | | if(ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) || ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime())){
|
| | | info.get(userId).setActualAttendanceDays(info.get(userId).getActualAttendanceDays() == null ? 1 : info.get(userId).getActualAttendanceDays() + 1);
|
| | | }
|
| | | // 实际出勤时长
|
| | | double actualAttendanceTime = 8.0;
|
| | | if(ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_START_LATE)){
|
| | | // 迟到次数
|
| | | info.get(userId).setCountOfBeingLate(info.get(userId).getCountOfBeingLate() == null ? 1 : info.get(userId).getCountOfBeingLate() + 1);
|
| | | Duration onDuration = Duration.between(attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getActualWorkStartTime().toLocalDateTime());
|
| | | // 实际出勤时长
|
| | | actualAttendanceTime -= new BigDecimal(onDuration.getSeconds()).divide(BigDecimal.valueOf(3600), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
| | | // 迟到时长
|
| | | info.get(userId).setTimeOfBeingLate(info.get(userId).getTimeOfBeingLate() == null ? Double.valueOf(new BigDecimal((float) onDuration.getSeconds() / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()) : Double.valueOf(BigDecimal.valueOf(info.get(userId).getTimeOfBeingLate()).add(new BigDecimal((float) onDuration.getSeconds() / 3600).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()));
|
| | | }
|
| | | if(ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_START_EARLY)){
|
| | | // 早退次数
|
| | | info.get(userId).setCountOfBeingEarly(info.get(userId).getCountOfBeingEarly() == null ? 1 : info.get(userId).getCountOfBeingEarly() + 1);
|
| | | Duration offDuration = Duration.between(attendance.getActualWorkEndTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime());
|
| | | // 实际出勤时长
|
| | | actualAttendanceTime -= new BigDecimal(offDuration.getSeconds()).divide(BigDecimal.valueOf(3600), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
| | | // 早退时长
|
| | | info.get(userId).setTimeOfBeingEarly(info.get(userId).getTimeOfBeingEarly() == null ? Double.valueOf(new BigDecimal((float) offDuration.getSeconds() / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()) : Double.valueOf(BigDecimal.valueOf(info.get(userId).getTimeOfBeingEarly()).add(new BigDecimal((float) offDuration.getSeconds() / 3600).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()));
|
| | | }
|
| | | if(attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED)){
|
| | | // 上班缺卡次数
|
| | | info.get(userId).setOnCardNumber(info.get(userId).getOnCardNumber() == null ? 1 : info.get(userId).getOnCardNumber() + 1);
|
| | | // 实际出勤时长
|
| | | actualAttendanceTime = 0.0;
|
| | | }
|
| | | if(attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED)){
|
| | | // 下班缺卡次数
|
| | | info.get(userId).setOffCardNumber(info.get(userId).getOffCardNumber() == null ? 1 : info.get(userId).getOffCardNumber() + 1);
|
| | | // 实际出勤时长
|
| | | actualAttendanceTime = 0.0;
|
| | | }
|
| | | // 实际出勤时长
|
| | | info.get(userId).setActualAttendanceTime(info.get(userId).getActualAttendanceTime() == null ? actualAttendanceTime : info.get(userId).getActualAttendanceTime() + actualAttendanceTime);
|
| | | }
|
| | | }
|
| | |
|
| | | LocalDateTime startTime = localDate.with(TemporalAdjusters.firstDayOfMonth()).atTime(0, 0, 0);
|
| | | LocalDateTime endTime = localDate.with(TemporalAdjusters.lastDayOfMonth()).atTime(23, 59, 59);
|
| | | List<AttendanceMonth> insertData = new ArrayList<>();
|
| | | for (AttendanceMonth value : info.values()) {
|
| | | // 查询当月外出
|
| | | List<AttendanceGoOut> goOutList = attendanceGoOutRepository.findByUserAndDate(value.getUserId(), startTime, endTime);
|
| | | int goOutNumber = goOutList.size();
|
| | | // 外出次数
|
| | | value.setGoOutNumber(Long.valueOf(goOutNumber));
|
| | | Double goOutTimes = 0.0;
|
| | | for(int i = 0; i < goOutList.size(); i++){
|
| | | goOutTimes = goOutTimes + goOutList.get(i).getOutDuration();
|
| | | }
|
| | | // 外出时长
|
| | | value.setGoOutTime(goOutTimes);
|
| | | // 查询当月的出差
|
| | | List<AttendanceBusinessTravel> businessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(value.getUserId(), startTime, endTime);
|
| | | int bussNumber = businessTravelList.size();
|
| | | // 出差次数
|
| | | value.setBussNumber(Long.valueOf(bussNumber));
|
| | | // 出差时长
|
| | | value.setBussTime(Double.valueOf(bussNumber * 8));
|
| | | // 应出勤时长
|
| | | value.setRequiredAttendanceTime(Double.valueOf(value.getRequiredAttendanceDays() * 8));
|
| | | // 查询当月请假
|
| | | List<AttendanceLeave> leaveList = attendanceLeaveRepository.findByUserIdAndDate(value.getUserId(), startTime, endTime);
|
| | | // 当月请假时长
|
| | | Double leaveTimes = 0.0;
|
| | | for(int i = 0; i < leaveList.size(); i++){
|
| | | // 时间单位为小时就直接加,否则就是天为单位需要乘8
|
| | | leaveTimes = leaveList.get(i).getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_HOUR) ? leaveTimes + leaveList.get(i).getLeaveDuration() : leaveTimes + leaveList.get(i).getLeaveDuration() * 8;
|
| | | }
|
| | | // 实际出勤时长
|
| | | value.setActualAttendanceTime(Double.valueOf(value.getActualAttendanceTime() - leaveTimes));
|
| | | if (value.getActualAttendanceTime() < 0) {
|
| | | value.setActualAttendanceTime(0.0);
|
| | | }
|
| | | //验证考勤月报的确认按钮
|
| | | AttendanceMonth attendanceMonthly = attendanceMonthRepository.findByAttendanceDateAndUserId(baseDate + "-01 00:00:00", value.getUserId());
|
| | | if(ObjectUtil.isNotEmpty(attendanceMonthly) && attendanceMonthly.getIsAdmit() != null && attendanceMonthly.getIsAdmit().equals(Constant.APPROVE_STATUS_ACKNOWLEDGED)){
|
| | | value.setIsAdmit(attendanceMonthly.getIsAdmit());
|
| | | }
|
| | | if(ObjectUtil.isNotEmpty(attendanceMonthly) && attendanceMonthly.getIsPublicity() != null && attendanceMonthly.getIsPublicity().equals(Constant.PUBLICITY_STATUS_YES)){
|
| | | value.setIsPublicity(attendanceMonthly.getIsPublicity());
|
| | | }
|
| | | insertData.add(value);
|
| | | }
|
| | | // 删除上个月信息
|
| | | attendanceMonthRepository.deleteByActualAttendanceDays(baseDate + "-01 00:00:00");
|
| | | // 保存当前添加的记录
|
| | | attendanceMonthRepository.saveAll(insertData);
|
| | |
|
| | | // 查询月报相关请假类型表
|
| | | List<AttendanceMonthLeave> attendanceMonthLeaves = attendanceMonthLeaveRepository.findByAttendanceDate(baseDate + "-01 00:00:00");
|
| | | if(attendanceMonthLeaves.size() != 0){
|
| | | for(AttendanceMonthLeave attendanceMonthLeave : attendanceMonthLeaves){
|
| | | // 删除数据
|
| | | attendanceMonthLeaveRepository.deleteById(attendanceMonthLeave.getId());
|
| | | }
|
| | | }
|
| | | // 月报相关的请假类型添加
|
| | | for(int i = 0; i < insertData.size(); i++){
|
| | | // 查询当月请假
|
| | | List<AttendanceLeave> leaves = attendanceLeaveRepository.findByUserIdAndDate(insertData.get(i).getUserId(), startTime, endTime);
|
| | | // 请假类型集合
|
| | | List<String> leaveTpeList = new ArrayList<>();
|
| | | for(int i1 = 0; i1 < leaves.size(); i1++){
|
| | | // 当前循环人员的所有请假类型
|
| | | leaveTpeList.add(leaves.get(i1).getLeaveType());
|
| | | }
|
| | |
|
| | | // 请假类型去重
|
| | | HashSet h = new HashSet(leaveTpeList);
|
| | | leaveTpeList.clear();
|
| | | leaveTpeList.addAll(h);
|
| | |
|
| | | // 遍历请假类型集合添加数据
|
| | | for(int i2 = 0; i2 < leaveTpeList.size(); i2++){
|
| | | AttendanceMonthLeave attendanceMonthLeave = new AttendanceMonthLeave();
|
| | | attendanceMonthLeave.setAttendanceMonthId(insertData.get(i).getId());
|
| | | attendanceMonthLeave.setAttendanceDate(insertData.get(i).getAttendanceDate());
|
| | | attendanceMonthLeave.setUserId(insertData.get(i).getUserId());
|
| | | // 请假类型
|
| | | attendanceMonthLeave.setLeaveType(leaveTpeList.get(i2));
|
| | | // 根据请假类型查询请假
|
| | | List<AttendanceLeave> leaveList = attendanceLeaveRepository.findByUserIdAndDateAndLeaveType(insertData.get(i).getUserId(), startTime, endTime,leaveTpeList.get(i2));
|
| | | // 请假次数
|
| | | attendanceMonthLeave.setLeaveCount(Long.valueOf(leaveList.size()));
|
| | | // 请假类型时长
|
| | | attendanceMonthLeave.setLeaveTime(getLeaveDuration(leaves,leaveTpeList.get(i2)));
|
| | | //年假剩余时长
|
| | | if(leaveTpeList.get(i2).equals(Constant.LEAVE_TYPE_ANNUAL_LEAVE)){
|
| | | Double yearTime = attendanceLeaveService.getYearTimeLength(insertData.get(i).getUserId());
|
| | | attendanceMonthLeave.setSurplusDuration(yearTime);
|
| | | } else if (leaveTpeList.get(i2).equals(Constant.LEAVE_TYPE_LACTATION_LEAVE)) {
|
| | | Double yearTime = attendanceLeaveService.getOverTimeLength(insertData.get(i).getUserId());
|
| | | attendanceMonthLeave.setSurplusDuration(yearTime);
|
| | | }
|
| | | attendanceMonthLeaveRepository.save(attendanceMonthLeave);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取请假时长
|
| | | * @param leaveList
|
| | | * @return
|
| | | */
|
| | | public Double getLeaveDuration(List<AttendanceLeave> leaveList, String type) {
|
| | | Double leaveTimes = 0.0;
|
| | | for(int i = 0; i < leaveList.size(); i++) {
|
| | | //时间单位为小时就直接加
|
| | | if(leaveList.get(i).getLeaveType().equals(type)) {
|
| | | if(leaveList.get(i).getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_HOUR)) {
|
| | | leaveTimes = leaveList.get(i).getLeaveDuration() + leaveTimes;
|
| | | }
|
| | | //天为单位需要乘8
|
| | | if(leaveList.get(i).getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)) {
|
| | | leaveTimes = leaveList.get(i).getLeaveDuration() * 8 + leaveTimes;
|
| | | }
|
| | | }
|
| | | }
|
| | | return leaveTimes;
|
| | | }
|
| | | }
|