eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
@@ -40,6 +40,7 @@ import me.zhengjie.modules.system.service.mapstruct.UserLoginMapper; import me.zhengjie.modules.system.service.mapstruct.UserMapper; import me.zhengjie.modules.task.domain.TaskDaliy; import me.zhengjie.modules.task.domain.TaskDaliyMongo; import me.zhengjie.modules.task.domain.TaskMongo; import me.zhengjie.modules.task.repository.TaskDaliyRepository; import me.zhengjie.modules.task.service.TaskDaliyService; @@ -476,23 +477,43 @@ Long duration = (Duration.between(user.getSysRostering().getWorkStartTime(), user.getSysRostering().getWorkEndTime())).toHours(); //查询日志表 List<TaskDaliy> taskDaliyList = taskDaliyRepository.findAllByUserAndDate(userId, startDate, endDate); for (TaskDaliy taskDaliy : taskDaliyList) { CalendarVo daily = new CalendarVo(); daily.setDate(taskDaliy.getFillDate().toString()); if (dateList.contains(taskDaliy.getFillDate().toString())) { dateList.remove(taskDaliy.getFillDate().toString()); List<TaskDaliyMongo> taskDaliyList = mongoTemplate.find(Query.query(new Criteria("userId").is(userId).and("fillDate").gte(startDate).lte(endDate)), TaskDaliyMongo.class); Map<String,Double> map = new HashMap<>(); for (TaskDaliyMongo taskDaliy : taskDaliyList) { if (map.get(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate())) != null) { // 如果已经有了 Double todayHours = map.get(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate())); todayHours += taskDaliy.getConsumedHours(); map.put(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate()),todayHours); } else { map.put(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.0").format(taskDaliy.getFillDate()),taskDaliy.getConsumedHours()); } daily.setIsOk(taskDaliy.getConsumedHours().compareTo(new Double(duration - 1)) >= 0 ? true : false); daily.setTitle(taskDaliy.getConsumedHours().compareTo(new Double(duration - 1)) >= 0 ? "工时: " + taskDaliy.getConsumedHours().toString() : "已填工时:" + taskDaliy.getConsumedHours().toString() + " 不满8小时,请补充日报"); daily.setType(2); calendarInfo.add(daily); } for (Map.Entry<String, Double> entry : map.entrySet()) { CalendarVo calendarVo = new CalendarVo(); if (entry.getValue() >= 8) { calendarVo.setDate(entry.getKey()); calendarVo.setIsOk(true); calendarVo.setTitle("工时:"+entry.getValue()); calendarVo.setType(2); } else { calendarVo.setDate(entry.getKey()); calendarVo.setIsOk(false); calendarVo.setTitle("已填工时:"+entry.getValue()+" 不足8小时,请补充日报"); calendarVo.setType(2); } calendarInfo.add(calendarVo); } for (String date : dateList) { String type1 = ""; String type2 = ""; System.out.println(date); CalendarVo dailyVo = new CalendarVo(); if (map.get(date) != null) { // 如果在map中找到了它的值,说明用户填写过日报 break; } dailyVo.setDate(date); for (Attendance attendanceRecord : attendanceList) { type1 = attendanceRecord.getStartClockResults(); @@ -698,6 +719,7 @@ 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 = taskDaliyService.queryCompletedWork(taskDaliyQueryCriteria, true); // 月初到今天绩效时长 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskDaliyServiceImpl.java
@@ -464,90 +464,27 @@ public Double queryCompletedWork(TaskDaliyQueryCriteria criteria, Boolean readOnly) { // 已完成工时 Double completedWork = 0D; // 国际时间转中国时间 String targetYearMonth = DateUtil.internationalTimeToChinaTime(criteria.getTargetYearMonth()); // 任务日报检索类 criteria.setFillDateLike(targetYearMonth.substring(0, 7)); // 获取本月任务日报列表 List<TaskDaliy> taskDaliyMonthList = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)); // 判断是否有本月任务日报 if (taskDaliyMonthList.size() != 0) { // 获取本月任务日报中所有任务ID //List<Long> taskIds = taskDaliyMonthList.stream().map(item -> item.getTaskId()).distinct().collect(Collectors.toList()); // 获取对应的任务 //Map<Long, Task> taskMap = taskRepository.findAllById(taskIds).stream().collect(Collectors.toMap(Task::getId, Function.identity())); // 获取本月任务分配列表 //List<TaskUser> taskUserMonthList = taskUserRepository.findByUserIdAndTaskIdIn(criteria.getUserId(), taskIds); // 日历类 Calendar cal = setUpCalendar(targetYearMonth); // 获取本月最大天数 int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 循环本月最大天数 for (int i = 1; i <= lastDay; i++) { // 设置天数 cal.set(Calendar.DAY_OF_MONTH, i); // 获取本日任务日报列表 List<TaskDaliy> taskDaliyDayList = taskDaliyMonthList.stream().filter(item -> item.getFillDate().getTime() == cal.getTime().getTime()).collect(Collectors.toList()); // 循环本日任务日报列表 for (int j = 0; j < taskDaliyDayList.size(); j++) { // 本日任务日报 TaskDaliy taskDaliyDay = taskDaliyDayList.get(j); // 本日任务分配列表 //Optional<TaskUser> OptionalTaskUser = taskUserMonthList.stream().filter(item -> item.getTaskId().equals(taskDaliyDay.getTaskId()) && item.getTaskInnerId().equals(taskDaliyDay.getTaskInnerId())).findFirst(); // if (!OptionalTaskUser.isPresent()) { // throw new BadRequestException("未找到任务分配记录!"); // } //TaskUser taskUserDay = OptionalTaskUser.get(); //Task task = taskMap.get(taskUserDay.getTaskId()); //if (Constant.PERFORMANCE_TYPE_ON.equals(task.getPerformanceType())) { // 根据项目ID、任务ID、用户ID查询填报日期前最近的任务日报信息 TaskDaliy taskDaliyHistory = taskDaliyRepository.findPreviousByProjectIdAndTaskIdAndAndUserId(taskDaliyDay.getProjectId(), taskDaliyDay.getTaskId(), taskDaliyDay.getUserId(), taskDaliyDay.getFillDate()); // 判断最近的任务日报是否为空 if (taskDaliyHistory != null) { TaskUser previousTaskUser = taskUserRepository.findByTaskIdAndTaskInnerIdAndUserId(taskDaliyHistory.getTaskId(), taskDaliyHistory.getTaskInnerId(), taskDaliyHistory.getUserId()); if (previousTaskUser == null) { throw new BadRequestException("任务日报进度计算存在异常!"); List<TaskDaliyMongo> daliyMongoList; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date dt = sdf.parse(criteria.getTargetYearMonth()); Calendar cal = Calendar.getInstance(); cal.setTime(dt); cal.add(Calendar.MONTH,1); Date nextMonth = cal.getTime(); daliyMongoList = mongoTemplate.find(Query.query(new Criteria("userId").is(criteria.getUserId()).and("fillDate").gte(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(criteria.getTargetYearMonth())).lte(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(nextMonth)))), TaskDaliyMongo.class); } catch (ParseException e) { throw new RuntimeException(e); } // 判断进度是否正常 // if (taskDaliyDay.getTaskProgress() * taskUserDay.getTaskHours() < taskDaliyHistory.getTaskProgress() * previousTaskUser.getTaskHours()) { // throw new BadRequestException("任务日报进度计算存在异常!"); // } // 本日任务日报进度 //completedWork += (taskDaliyDay.getTaskProgress() * taskUserDay.getTaskHours() - taskDaliyHistory.getTaskProgress() * previousTaskUser.getTaskHours()) / 100; for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) { // 获取一下分配给这个人的绩效时长时长 TaskUserMongo taskUser = mongoTemplate.findById(taskDaliyMongo.getTaskUserMongo().getId(), TaskUserMongo.class); assert taskUser != null; // 如果绩效工时 - 消耗工时 > 0 说明当前的日报超出预计的绩效工时 if (taskUser.getPerformanceHours() - taskDaliyMongo.getConsumedHours() > 0) { completedWork += taskDaliyMongo.getConsumedHours(); } else { // 已完成工时 //completedWork += taskUserDay.getTaskHours() * (taskDaliyDay.getTaskProgress() / 100); } //} //else if (Constant.PERFORMANCE_TYPE_OFF.equals(task.getPerformanceType())) { // 已完成工时 completedWork += taskDaliyDay.getConsumedHours() * 1.1; //} // 是否只读 if (!readOnly) { // 本日任务日报 taskDaliyDay.setSettlementStatus(Constant.SETTLEMENT_STATUS_SETTLED); // 保存本日任务日报 taskDaliyRepository.save(taskDaliyDay); } } } } // 请假检索类 AttendanceLeaveQueryCriteria attendanceLeaveQueryCriteria = new AttendanceLeaveQueryCriteria(); attendanceLeaveQueryCriteria.setUserId(criteria.getUserId()); attendanceLeaveQueryCriteria.setLeaveType(Constant.LEAVE_TYPE_ANNUAL_LEAVE); attendanceLeaveQueryCriteria.setLeaveStartTimeLike(targetYearMonth.substring(0, 7)); attendanceLeaveQueryCriteria.setLeaveEndTimeLike(targetYearMonth.substring(0, 7)); attendanceLeaveQueryCriteria.setApprovalStatus(Constant.APPROVAL_STATUS_PASSED); // 获取本月请假列表 List<AttendanceLeave> attendanceLeaveMonthList = attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, attendanceLeaveQueryCriteria, criteriaBuilder)); for (AttendanceLeave attendanceLeave : attendanceLeaveMonthList) { if (Constant.LEAVE_TIME_TYPE_DAY.equals(attendanceLeave.getLeaveDurationUnit())) { completedWork += attendanceLeave.getLeaveDuration() * 8; } else { completedWork += attendanceLeave.getLeaveDuration(); completedWork += taskUser.getPerformanceHours(); } } // 已完成工时 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskServiceImpl.java
@@ -201,7 +201,7 @@ List<TaskUserMongoDto> taskUserMongoDtoList = new ArrayList<>(); taskUserMongos.forEach(item -> { //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()); Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()).get(0); TaskUserMongoDto dto = new TaskUserMongoDto(); if (item.getPerformanceType() == null) { TaskMongo byId = mongoTemplate.findById(item.getTask().getId(), TaskMongo.class); eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskUserServiceImpl.java
@@ -120,7 +120,7 @@ taskUserMongos.forEach(item -> { if (item.getTaskEndDate() != null && item.getTaskStartDate() != null) { //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()); Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()).get(0); TaskUserMongoDto dto = new TaskUserMongoDto(); if (item.getPerformanceType() == null) { TaskMongo byId = mongoTemplate.findById(item.getTask().getId(), TaskMongo.class); @@ -186,7 +186,7 @@ List<TaskUserMongoDto> taskUserMongoDtoList = new ArrayList<>(); taskUserMongoList.forEach(item -> { //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()); Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()).get(0); TaskUserMongoDto dto = new TaskUserMongoDto(); if (item.getPerformanceType() == null) { TaskMongo byId = mongoTemplate.findById(item.getTask().getId(), TaskMongo.class); @@ -248,7 +248,7 @@ taskUserMongoList.forEach(item -> { //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()); Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()).get(0); TaskUserMongoDto dto = new TaskUserMongoDto(); if (item.getPerformanceType() == null) { TaskMongo byId = mongoTemplate.findById(item.getTask().getId(), TaskMongo.class); @@ -309,7 +309,7 @@ taskUserMongoList.forEach(item -> { //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()); Double coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(SecurityUtils.getCurrentUserId()).get(0); TaskUserMongoDto dto = new TaskUserMongoDto(); if (item.getPerformanceType() == null) { TaskMongo byId = mongoTemplate.findById(item.getTask().getId(), TaskMongo.class); @@ -527,7 +527,7 @@ coefficientByUserId = 1D; } else { //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(taskUserMongo.getUserId()); coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(taskUserMongo.getUserId()).get(0); } if (taskUserMongo.getPerformanceType() == null) { @@ -601,7 +601,7 @@ coefficientByUserId = 1D; } else { //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(taskUserMongo.getUserId()); coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(taskUserMongo.getUserId()).get(0); } if (taskUserMongo.getPerformanceType() == null) { @@ -757,7 +757,7 @@ mongoTemplate.save(taskUserMongo); } else { //如果有指定的任务负责人就获取这个任务负责人的绩效绩点 coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(resources.getUserId()); coefficientByUserId = userLevelWageRepository.findPerformanceCoefficientByUserId(resources.getUserId()).get(0); if (taskUserMongo.getPerformanceType().equals("1")) { //绩效任务 DecimalFormat decimalFormat = new DecimalFormat("#0"); eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/treatment/repository/UserLevelWageRepository.java
@@ -21,6 +21,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import java.util.List; /** * @website https://eladmin.vip * @author 姚增春 @@ -31,7 +33,7 @@ UserLevelWage findByUserIdAndYearMonth(Long userId, String yearMonth); @Query(value = "(select performance_coefficient from new_user_level_wage where user_id = ?1) order by `year_month` DESC",nativeQuery = true) Double findPerformanceCoefficientByUserId(Long userId); List<Double> findPerformanceCoefficientByUserId(Long userId); }