| | |
| | | |
| | | @Override |
| | | public List<Map> getPerformanceDetail(Long nextMonth) throws ParseException { |
| | | |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 |
| | | // //本月第一天 |
| | | // Calendar c = Calendar.getInstance(); |
| | | // c.add(Calendar.MONTH, 0); |
| | | // c.set(Calendar.DAY_OF_MONTH, 1); |
| | | // String todayMonth = df.format(c.getTime()); |
| | | // 月初日期 |
| | | String nextMonth_ = df.format(new Date(nextMonth)).substring(0,7) + "-01"; |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(df.parse(nextMonth_)); |
| | | cal.add(Calendar.MONTH, 1); |
| | | cal.set(Calendar.DAY_OF_MONTH, 1); |
| | | String nextMonthFirstDay = df.format(cal.getTime()); |
| | | List<TaskDaliyMongo> daliyMongoList; |
| | | try { |
| | | // daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(nextMonth_)).lt(new SimpleDateFormat("yyyy-MM-dd").parse(nextMonthFirstDay))), TaskDaliyMongo.class); |
| | | daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(nextMonth_)).lt(new SimpleDateFormat("yyyy-MM-dd").parse(nextMonthFirstDay))), TaskDaliyMongo.class); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | // 月末日期 |
| | | String sdfLastDate = DateUtil.getLastDayOfMonthFull(nextMonth_); |
| | | |
| | | // 查询当前用户 |
| | | User user = userRepository.findById(SecurityUtils.getCurrentUserId()).orElseGet(User::new); |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | | String startTime = nextMonth_.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkStartTime()); |
| | | String endTime = sdfLastDate.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkEndTime()); |
| | | |
| | | List<Map> resultList = new ArrayList<>(); |
| | | for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) { |
| | | resultList = getPerformanceInfo(startTime, endTime); |
| | | |
| | | return resultList; |
| | | } |
| | | |
| | | /** |
| | | * 获取详细绩效数据 |
| | | * @param startTime |
| | | * @param endTime |
| | | * @return |
| | | */ |
| | | public List<Map> getPerformanceInfo(String startTime,String endTime) throws ParseException { |
| | | |
| | | DecimalFormat decimalFormat = new DecimalFormat("#"); |
| | | decimalFormat.setRoundingMode(RoundingMode.HALF_UP); |
| | | |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime))), TaskDaliyMongo.class); |
| | | //根据日报中任务分配字段的id去重,并保留日报进度最高的 |
| | | Map<Object, TaskDaliyMongo> uniqueMap = daliyMongoList.stream() |
| | | .collect(Collectors.toMap( |
| | | taskDaliyMongo -> taskDaliyMongo.getTaskUserMongo().getId(), |
| | | taskDaliyMongo -> taskDaliyMongo, |
| | | (existing, replacement) -> existing.getTaskProgress() > replacement.getTaskProgress() ? existing : replacement)); |
| | | List<TaskDaliyMongo> taskDaliyMongoList = new ArrayList<>(uniqueMap.values()); |
| | | |
| | | List<Map> resultList = new ArrayList<>(); |
| | | for (TaskDaliyMongo taskDaliyMongo : taskDaliyMongoList) { |
| | | Double completedWork = 0D; |
| | | String taskName = taskDaliyMongo.getTaskUserMongo().getTask().getName(); |
| | | if (resultList.isEmpty()) { |
| | | Map map = new HashMap(); |
| | | map.put("name", taskName); |
| | | if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) { |
| | | map.put("value", taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours()); |
| | | // 查询日报表是否存在小于当前月填写的当前任务的日报 |
| | | List<TaskDaliyMongo> taskDaliyMongoSm = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("old_task_id").is(taskDaliyMongo.getOld_task_id()).and("fillDate").lte(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime))).with(Sort.by(Sort.Direction.DESC, "fillDate")), TaskDaliyMongo.class); |
| | | //跨月 |
| | | if (taskDaliyMongoSm.size() > 0) { |
| | | // Double horseValue1 = Double.valueOf(decimalFormat.format((taskDaliyMongoSm.get(0).getTaskProgress() / 100) * taskDaliyMongo.getTaskUserMongo().getPerformanceHours())); |
| | | // horseValue1 = taskDaliyMongo.getTaskUserMongo().getPerformanceHours() - horseValue1; |
| | | // 跨月的话计算最后一次填写距离现在最新的进度相差多少 |
| | | Double newProgress = taskDaliyMongo.getTaskProgress() - taskDaliyMongoSm.get(0).getTaskProgress(); |
| | | // 进度乘总 |
| | | Double horseValue1 = Double.valueOf((newProgress / 100) * taskDaliyMongo.getTaskUserMongo().getPerformanceHours()); |
| | | BigDecimal horseValue2 = new BigDecimal(horseValue1); |
| | | double horseValue3 = horseValue2.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue(); |
| | | completedWork = horseValue3; |
| | | } else { |
| | | map.put("value", taskDaliyMongo.getConsumedHours()); |
| | | completedWork = taskDaliyMongo.getTaskUserMongo().getPerformanceHours(); |
| | | } |
| | | map.put(taskDaliyMongo.getTaskUserMongo().getName(), taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours()); |
| | | } else { |
| | | // 非绩效(查询非绩效任务的总消耗工时) |
| | | List<TaskDaliyMongo> noPerformanceLists = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime)).and("taskUserMongo.id").is(taskDaliyMongo.getTaskUserMongo().getId())), TaskDaliyMongo.class); |
| | | // 计算所有的非绩效的消耗工时的值 |
| | | completedWork = noPerformanceLists.stream() |
| | | .mapToDouble(TaskDaliyMongo::getConsumedHours) |
| | | .sum(); |
| | | } |
| | | |
| | | map.put("value", completedWork); |
| | | // 设置为0待定 |
| | | map.put(taskDaliyMongo.getTaskUserMongo().getName(), 0); |
| | | resultList.add(map); |
| | | continue; |
| | | } |
| | | findList(resultList, taskDaliyMongo); |
| | | } |
| | | |
| | | |
| | | |
| | | for (Map map : resultList) { |
| | | ArrayList<Map> list = new ArrayList<>(); |
| | |
| | | } |
| | | map.put("list", list); |
| | | } |
| | | |
| | | return resultList; |
| | | } |
| | | |
| | | /** |
| | | * 获取用户基础信息 |
| | | * |
| | | * @return |
| | | * @throws ParseException |
| | | */ |
| | | @Override |
| | | public Map getUserBaseInfo(Date yearMonth) throws ParseException { |
| | | // 返回集合 |
| | | Map returnData = new HashMap(); |
| | | // 当前登录用户 |
| | | Long userId = SecurityUtils.getCurrentUserId(); |
| | | // 目标年月字符串 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String sdfDate = sdf.format(yearMonth); |
| | | // 目标年月初字符串 |
| | | String sdfFirstDate = DateUtil.getFirstDayOfMonthFull(sdfDate); |
| | | // 目标年月末字符串 |
| | | String sdfLastDate = DateUtil.getLastDayOfMonthFull(sdfDate); |
| | | // 出勤天数 |
| | | List<Attendance> attendanceRecordList = attendanceRepository.findAllByUserAndDate(userId, sdfFirstDate, sdfLastDate); |
| | | int numDay = 0; |
| | | for (Attendance attendance : attendanceRecordList) { |
| | | if (!attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_REST) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_REST)) { |
| | | numDay++; |
| | | } |
| | | } |
| | | returnData.put("onDutyDays", numDay); |
| | | // 剩余年假 |
| | | Double yearTimes = attendanceLeaveService.getYearTimeLength(userId); |
| | | returnData.put("annualLeave", yearTimes); |
| | | // 查询当月的补卡记录的条数 |
| | | Integer count = attendanceCardreplacementRepository.count(userId, sdfDate.substring(0, 7)); |
| | | // 查询配置表的每月补卡次数 |
| | | SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("每月可补卡次数"); |
| | | if (count >= sysConfigProportion.getProportion()) { |
| | | returnData.put("cardLeft", 0); |
| | | } else { |
| | | returnData.put("cardLeft", (sysConfigProportion.getProportion() - count)); |
| | | } |
| | | |
| | | // 法定节假日 |
| | | List<String> holiday = new ArrayList<>(); |
| | | // 天数 |
| | | int shouldWordDays = 0; |
| | | List<SysConfigHoliday> holidayConfigurationList = sysConfigHolidayRepository.findAll(); |
| | | for (SysConfigHoliday holidayConfiguration : holidayConfigurationList) { |
| | | if (holidayConfiguration.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) { |
| | | holiday.add(sdf.format(holidayConfiguration.getHolidayDate())); |
| | | } |
| | | } |
| | | // 获取当月所有日期 |
| | | List<String> dateList = DateTimeUtil.getDayByMonth(sdfDate.substring(0, 4), sdfDate.substring(5, 7)); |
| | | Date date1 = new Date(); |
| | | String todayDay = sdf.format(date1); |
| | | if (!todayDay.substring(0, 7).equals(sdfDate.substring(0, 7))) { |
| | | todayDay = sdfLastDate; |
| | | } |
| | | // 工作日的天数 |
| | | for (String date : dateList) { |
| | | Date isWeekEnd = sdf.parse(date); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(isWeekEnd); |
| | | if (isWeekEnd.compareTo(sdf.parse(todayDay)) <= 0) { |
| | | if (!holiday.contains(date) && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { |
| | | shouldWordDays += 1; |
| | | } |
| | | } |
| | | } |
| | | int num = shouldWordDays * 8; |
| | | // 月初到今天应工作时长 |
| | | returnData.put("Time", num); |
| | | |
| | | DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | User user = userRepository.getById(userId); |
| | | // 考勤上午时间 |
| | | Double attCheckOnDuration = 0.0; |
| | | // 考勤下午时间 |
| | | Double attCheckOffDuration = 0.0; |
| | | for (Attendance attendance : attendanceRecordList) { |
| | | // 上班打卡时间不为空并且打卡状态不为出差外出的考勤记录 |
| | | if (ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) && !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) && !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)) { |
| | | LocalDateTime attCheckOnTime = attendance.getActualWorkStartTime().toLocalDateTime(); |
| | | LocalDateTime scheduleStartTime = LocalDateTime.parse(attendance.getAttendanceDate().toString().substring(0, 10) + " " + user.getSysRostering().getLunchStartTime().toString() + ":00", formatter2); |
| | | if (attCheckOnTime.compareTo(scheduleStartTime) <= 0) { |
| | | // 获得两个时间之间的相差值 |
| | | Duration duration = Duration.between(attCheckOnTime, scheduleStartTime); |
| | | Long minutes = duration.toMinutes(); |
| | | Double hour = Double.valueOf(String.valueOf(new BigDecimal(Double.valueOf(minutes) / 60).setScale(2, BigDecimal.ROUND_HALF_UP))); |
| | | attCheckOnDuration = attCheckOnDuration + hour; |
| | | } |
| | | } |
| | | // 下班打卡时间不为空并且打卡状态不为出差外出的考勤记录 |
| | | if (ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)) { |
| | | LocalDateTime attCheckOffTime = attendance.getActualWorkEndTime().toLocalDateTime(); |
| | | LocalDateTime scheduleEndTime = LocalDateTime.parse(attendance.getAttendanceDate().toString().substring(0, 10) + " " + user.getSysRostering().getLunchEndTime().toString() + ":00", formatter2); |
| | | if (attCheckOffTime.compareTo(scheduleEndTime) > 0) { |
| | | // 获得两个时间之间的相差值 |
| | | Duration duration = Duration.between(scheduleEndTime, attCheckOffTime); |
| | | Long minutes = duration.toMinutes(); |
| | | Double hour = Double.valueOf(String.valueOf(new BigDecimal(Double.valueOf(minutes) / 60).setScale(2, BigDecimal.ROUND_HALF_UP))); |
| | | attCheckOffDuration = attCheckOffDuration + hour; |
| | | } |
| | | } |
| | | } |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | | String startTime = sdfFirstDate.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkStartTime()); |
| | | String endTime = todayDay.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkEndTime()); |
| | | // 外出时长 |
| | | Double goOutTimes = 0.0; |
| | | // 查询外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(userId, Timestamp.valueOf(startTime).toLocalDateTime(), Timestamp.valueOf(endTime).toLocalDateTime()); |
| | | for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | goOutTimes = goOutTimes + attendanceGoOut.getOutDuration(); |
| | | } |
| | | // 出差时长 |
| | | Double bussTimes = 0.0; |
| | | // 查询出差表 |
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(userId, Timestamp.valueOf(sdfFirstDate).toLocalDateTime(), Timestamp.valueOf(todayDay.substring(0, 10) + " " + "00:00:00").toLocalDateTime()); |
| | | for (AttendanceBusinessTravel attendanceBusinessTravel : attendanceBusinessTravelList) { |
| | | bussTimes = bussTimes + attendanceBusinessTravel.getTravelDuration(); |
| | | } |
| | | returnData.put("Times", attCheckOnDuration + attCheckOffDuration + goOutTimes + (bussTimes * 8)); |
| | | |
| | | // 任务日报查询类 |
| | | TaskDaliyQueryCriteria taskDaliyQueryCriteria = new TaskDaliyQueryCriteria(); |
| | | taskDaliyQueryCriteria.setUserId(userId); |
| | | taskDaliyQueryCriteria.setTargetYearMonth(sdfDate.substring(0, 7)); |
| | | taskDaliyQueryCriteria.setTargetYearMonth(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(yearMonth)); |
| | | |
| | | // // 查询某月已完成工时 |
| | | // Double completedWork = 0D; |
| | | // |
| | | // DecimalFormat decimalFormat = new DecimalFormat("#"); |
| | | // decimalFormat.setRoundingMode(RoundingMode.HALF_UP); |
| | | // |
| | | // List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime))), TaskDaliyMongo.class); |
| | | // |
| | | // //根据日报中任务分配字段的id去重,并保留日报进度最高的 |
| | | // Map<Object, TaskDaliyMongo> uniqueMap = daliyMongoList.stream() |
| | | // .collect(Collectors.toMap( |
| | | // taskDaliyMongo -> taskDaliyMongo.getTaskUserMongo().getId(), |
| | | // taskDaliyMongo -> taskDaliyMongo, |
| | | // infoement)); |
| | | // |
| | | // List<TaskDaliyMongo> taskDaliyMongoList = new ArrayList<>(uniqueMap.values()); |
| | | // for (TaskDaliyMongo taskDaliyMongo : taskDaliyMongoList) { |
| | | // //绩效 |
| | | // if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) { |
| | | // // 查询日报表是否存在小于当前月填写的当前任务的日报 |
| | | // List<TaskDaliyMongo> taskDaliyMongoSm = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("old_task_id").is(taskDaliyMongo.getOld_task_id()).and("fillDate").lte(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime))).with(Sort.by(Sort.Direction.DESC, "fillDate")), TaskDaliyMongo.class); |
| | | // //跨月 |
| | | // if (taskDaliyMongoSm.size() > 0) { |
| | | // Double horseValue1 = Double.valueOf(decimalFormat.format((taskDaliyMongoSm.get(0).getTaskProgress() / 100) * taskDaliyMongo.getTaskUserMongo().getPerformanceHours())); |
| | | // horseValue1 = taskDaliyMongo.getTaskUserMongo().getPerformanceHours() - horseValue1; |
| | | // completedWork += horseValue1; |
| | | // } else { |
| | | // completedWork += taskDaliyMongo.getTaskUserMongo().getPerformanceHours(); |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // // 非绩效 |
| | | // for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) { |
| | | // //非绩效 |
| | | // if (!taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) { |
| | | // completedWork += taskDaliyMongo.getConsumedHours(); |
| | | // } |
| | | // } |
| | | |
| | | List<Map> resList = getPerformanceInfo(startTime,endTime); |
| | | double sum = resList.stream() |
| | | .filter(map -> map.containsKey("value")) |
| | | .mapToDouble(map -> Double.valueOf(map.get("value").toString())) |
| | | .sum(); |
| | | |
| | | // 月初到今天绩效时长 |
| | | returnData.put("achievementsTime", sum); |
| | | |
| | | return returnData; |
| | | } |
| | | |
| | | @Override |
| | |
| | | returnData.put("msg", result); |
| | | returnData.put("status", true); |
| | | } |
| | | return returnData; |
| | | } |
| | | |
| | | /** |
| | | * 获取用户基础信息 |
| | | * |
| | | * @return |
| | | * @throws ParseException |
| | | */ |
| | | @Override |
| | | public Map getUserBaseInfo(Date yearMonth) throws ParseException { |
| | | // 返回集合 |
| | | Map returnData = new HashMap(); |
| | | // 当前登录用户 |
| | | Long userId = SecurityUtils.getCurrentUserId(); |
| | | // 目标年月字符串 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String sdfDate = sdf.format(yearMonth); |
| | | // 目标年月初字符串 |
| | | String sdfFirstDate = DateUtil.getFirstDayOfMonthFull(sdfDate); |
| | | // 目标年月末字符串 |
| | | String sdfLastDate = DateUtil.getLastDayOfMonthFull(sdfDate); |
| | | // 出勤天数 |
| | | List<Attendance> attendanceRecordList = attendanceRepository.findAllByUserAndDate(userId, sdfFirstDate, sdfLastDate); |
| | | int numDay = 0; |
| | | for (Attendance attendance : attendanceRecordList) { |
| | | if (!attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_REST) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_REST)) { |
| | | numDay++; |
| | | } |
| | | } |
| | | returnData.put("onDutyDays", numDay); |
| | | // 剩余年假 |
| | | Double yearTimes = attendanceLeaveService.getYearTimeLength(userId); |
| | | returnData.put("annualLeave", yearTimes); |
| | | // 查询当月的补卡记录的条数 |
| | | Integer count = attendanceCardreplacementRepository.count(userId, sdfDate.substring(0, 7)); |
| | | // 查询配置表的每月补卡次数 |
| | | SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("每月可补卡次数"); |
| | | if (count >= sysConfigProportion.getProportion()) { |
| | | returnData.put("cardLeft", 0); |
| | | } else { |
| | | returnData.put("cardLeft", (sysConfigProportion.getProportion() - count)); |
| | | } |
| | | |
| | | // 法定节假日 |
| | | List<String> holiday = new ArrayList<>(); |
| | | // 天数 |
| | | int shouldWordDays = 0; |
| | | List<SysConfigHoliday> holidayConfigurationList = sysConfigHolidayRepository.findAll(); |
| | | for (SysConfigHoliday holidayConfiguration : holidayConfigurationList) { |
| | | if (holidayConfiguration.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) { |
| | | holiday.add(sdf.format(holidayConfiguration.getHolidayDate())); |
| | | } |
| | | } |
| | | // 获取当月所有日期 |
| | | List<String> dateList = DateTimeUtil.getDayByMonth(sdfDate.substring(0, 4), sdfDate.substring(5, 7)); |
| | | Date date1 = new Date(); |
| | | String todayDay = sdf.format(date1); |
| | | if (!todayDay.substring(0, 7).equals(sdfDate.substring(0, 7))) { |
| | | todayDay = sdfLastDate; |
| | | } |
| | | // 工作日的天数 |
| | | for (String date : dateList) { |
| | | Date isWeekEnd = sdf.parse(date); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(isWeekEnd); |
| | | if (isWeekEnd.compareTo(sdf.parse(todayDay)) <= 0) { |
| | | if (!holiday.contains(date) && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { |
| | | shouldWordDays += 1; |
| | | } |
| | | } |
| | | } |
| | | int num = shouldWordDays * 8; |
| | | // 月初到今天应工作时长 |
| | | returnData.put("Time", num); |
| | | |
| | | DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | User user = userRepository.getById(userId); |
| | | // 考勤上午时间 |
| | | Double attCheckOnDuration = 0.0; |
| | | // 考勤下午时间 |
| | | Double attCheckOffDuration = 0.0; |
| | | for (Attendance attendance : attendanceRecordList) { |
| | | // 上班打卡时间不为空并且打卡状态不为出差外出的考勤记录 |
| | | if (ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) && !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) && !attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)) { |
| | | LocalDateTime attCheckOnTime = attendance.getActualWorkStartTime().toLocalDateTime(); |
| | | LocalDateTime scheduleStartTime = LocalDateTime.parse(attendance.getAttendanceDate().toString().substring(0, 10) + " " + user.getSysRostering().getLunchStartTime().toString() + ":00", formatter2); |
| | | if (attCheckOnTime.compareTo(scheduleStartTime) <= 0) { |
| | | // 获得两个时间之间的相差值 |
| | | Duration duration = Duration.between(attCheckOnTime, scheduleStartTime); |
| | | Long minutes = duration.toMinutes(); |
| | | Double hour = Double.valueOf(String.valueOf(new BigDecimal(Double.valueOf(minutes) / 60).setScale(2, BigDecimal.ROUND_HALF_UP))); |
| | | attCheckOnDuration = attCheckOnDuration + hour; |
| | | } |
| | | } |
| | | // 下班打卡时间不为空并且打卡状态不为出差外出的考勤记录 |
| | | if (ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_GOOUT) && !attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)) { |
| | | LocalDateTime attCheckOffTime = attendance.getActualWorkEndTime().toLocalDateTime(); |
| | | LocalDateTime scheduleEndTime = LocalDateTime.parse(attendance.getAttendanceDate().toString().substring(0, 10) + " " + user.getSysRostering().getLunchEndTime().toString() + ":00", formatter2); |
| | | if (attCheckOffTime.compareTo(scheduleEndTime) > 0) { |
| | | // 获得两个时间之间的相差值 |
| | | Duration duration = Duration.between(scheduleEndTime, attCheckOffTime); |
| | | Long minutes = duration.toMinutes(); |
| | | Double hour = Double.valueOf(String.valueOf(new BigDecimal(Double.valueOf(minutes) / 60).setScale(2, BigDecimal.ROUND_HALF_UP))); |
| | | attCheckOffDuration = attCheckOffDuration + hour; |
| | | } |
| | | } |
| | | } |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | | String startTime = sdfFirstDate.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkStartTime()); |
| | | String endTime = todayDay.substring(0, 10) + " " + dateTimeFormatter.format(user.getSysRostering().getWorkEndTime()); |
| | | // 外出时长 |
| | | Double goOutTimes = 0.0; |
| | | // 查询外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(userId, Timestamp.valueOf(startTime).toLocalDateTime(), Timestamp.valueOf(endTime).toLocalDateTime()); |
| | | for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | goOutTimes = goOutTimes + attendanceGoOut.getOutDuration(); |
| | | } |
| | | // 出差时长 |
| | | Double bussTimes = 0.0; |
| | | // 查询出差表 |
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(userId, Timestamp.valueOf(sdfFirstDate).toLocalDateTime(), Timestamp.valueOf(todayDay.substring(0, 10) + " " + "00:00:00").toLocalDateTime()); |
| | | for (AttendanceBusinessTravel attendanceBusinessTravel : attendanceBusinessTravelList) { |
| | | bussTimes = bussTimes + attendanceBusinessTravel.getTravelDuration(); |
| | | } |
| | | returnData.put("Times", attCheckOnDuration + attCheckOffDuration + goOutTimes + (bussTimes * 8)); |
| | | |
| | | // 任务日报查询类 |
| | | TaskDaliyQueryCriteria taskDaliyQueryCriteria = new TaskDaliyQueryCriteria(); |
| | | taskDaliyQueryCriteria.setUserId(userId); |
| | | taskDaliyQueryCriteria.setTargetYearMonth(sdfDate.substring(0, 7)); |
| | | taskDaliyQueryCriteria.setTargetYearMonth(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(yearMonth)); |
| | | |
| | | // 查询某月已完成工时 |
| | | Double completedWork = 0D; |
| | | // List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime))), TaskDaliyMongo.class); |
| | | // for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) { |
| | | // if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) { |
| | | // // 绩效任务 |
| | | // if (taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours()) { |
| | | // // 如果当前的绩效任务中,用户填写的日报超出了绩效时长就以绩效任务中绩效时长为准 |
| | | // completedWork += taskDaliyMongo.getTaskUserMongo().getPerformanceHours(); |
| | | // } else { |
| | | // completedWork += taskDaliyMongo.getConsumedHours(); |
| | | // } |
| | | // //判断集合中填写的日报是否一个任务填写次数超过1次 |
| | | // |
| | | // } else { |
| | | // // 非绩效任务 |
| | | // completedWork += taskDaliyMongo.getConsumedHours(); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | DecimalFormat decimalFormat = new DecimalFormat("#"); |
| | | decimalFormat.setRoundingMode(RoundingMode.HALF_UP); |
| | | |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd").parse(startTime)).lte(new SimpleDateFormat("yyyy-MM-dd").parse(endTime))), TaskDaliyMongo.class); |
| | | |
| | | //根据日报中项目分配字段的id去重,并保留日报进度最高的 |
| | | Map<Object, TaskDaliyMongo> uniqueMap = daliyMongoList.stream() |
| | | .collect(Collectors.toMap( |
| | | taskDaliyMongo -> taskDaliyMongo.getTaskUserMongo().getId(), |
| | | taskDaliyMongo -> taskDaliyMongo, |
| | | (existing, replacement) -> existing.getTaskProgress() > replacement.getTaskProgress() ? existing : replacement)); |
| | | |
| | | List<TaskDaliyMongo> taskDaliyMongoList = new ArrayList<>(uniqueMap.values()); |
| | | for (TaskDaliyMongo taskDaliyMongo : taskDaliyMongoList) { |
| | | //绩效 |
| | | if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) { |
| | | // 查询日报表是否存在小于当前月填写的当前任务的日报 |
| | | List<TaskDaliyMongo> taskDaliyMongoSm = mongoTemplate.find(Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("old_task_id").is(taskDaliyMongo.getOld_task_id()).and("fillDate").lte(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime))).with(Sort.by(Sort.Direction.DESC, "fillDate")), TaskDaliyMongo.class); |
| | | //跨月 |
| | | if (taskDaliyMongoSm.size() > 0) { |
| | | Double horseValue1 = Double.valueOf(decimalFormat.format((taskDaliyMongoSm.get(0).getTaskProgress() / 100) * taskDaliyMongo.getTaskUserMongo().getPerformanceHours())); |
| | | horseValue1 = taskDaliyMongo.getTaskUserMongo().getPerformanceHours() - horseValue1; |
| | | completedWork += horseValue1; |
| | | } else { |
| | | completedWork += taskDaliyMongo.getTaskUserMongo().getPerformanceHours(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 非绩效 |
| | | for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) { |
| | | //非绩效 |
| | | if (!taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")) { |
| | | completedWork += taskDaliyMongo.getConsumedHours(); |
| | | } |
| | | } |
| | | // 月初到今天绩效时长 |
| | | returnData.put("achievementsTime", completedWork); |
| | | |
| | | return returnData; |
| | | } |
| | | |