From ea15da1876541ebfa451f78d58831845a342c062 Mon Sep 17 00:00:00 2001
From: churf <123456>
Date: Tue, 12 Sep 2023 09:59:53 +0000
Subject: [PATCH] 出差结束日期修改

---
 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java |  153 +++++++++++++++++++++++++-------------------------
 1 files changed, 76 insertions(+), 77 deletions(-)

diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
index cfb673e..6de8d94 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
+++ b/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;
@@ -175,7 +176,7 @@
     }
 
     @Override
-    //@Cacheable(key = "'AllUser'")
+    @Cacheable(key = "'AllUser'")
     public List<DeptAndUser> getUserDept() {
         List<Dept> all = deptRepository.findAll();
         List<DeptAndUser> result = new ArrayList<>();
@@ -260,18 +261,18 @@
         }
 
         //return result;
-        recursionGetData1(result);
+        recursionGetData(result);
         return result;
     }
 
 
-    public void recursionGetData1(List<DeptAndUser> list) {
+    public void recursionGetData(List<DeptAndUser> list) {
         for (DeptAndUser deptAndUser : list) {
             if (deptAndUser.getChildren() == null) {
                 deptAndUser.setChildren(new ArrayList<DeptAndUser>());
             }
             if (deptAndUser.getChildren().size() > 0) {
-                recursionGetData1(deptAndUser.getChildren());
+                recursionGetData(deptAndUser.getChildren());
             }
             List<User> users = userRepository.findByDeptIdInAndEnabledWithSingle(deptAndUser.getValue(), true);
             for (User user : users) {
@@ -281,44 +282,6 @@
                 deptAndUser.getChildren().add(result_deptAndUser);
             }
         }
-    }
-
-    /*
-    遍历每一级,获取每一级的职工
-    递归参数:
-    集合
-     */
-
-    public List<DeptAndUser> recursionGetData(List<DeptAndUser> list) {
-        for (int i = 0; i < list.size(); i++) {
-            System.out.println(list.get(i));
-            if (list.get(i).getChildren() != null) {
-                list.get(i).setChildren(recursionGetData(list.get(i).getChildren()));
-                List<User> users = userRepository.findByDeptIdInAndEnabledWithSingle(list.get(i).getValue(), true);
-                for (User user : users) {
-                    DeptAndUser result_deptAndUser = new DeptAndUser();
-                    result_deptAndUser.setValue(user.getId());
-                    result_deptAndUser.setLabel(user.getNickName());
-                    list.get(i).getChildren().add(result_deptAndUser);
-                }
-                return list;
-            }
-        }
-
-        List<DeptAndUser> result_dept = new ArrayList<>();
-        for (DeptAndUser deptAndUser : list) {
-            List<User> users = userRepository.findByDeptIdInAndEnabledWithSingle(deptAndUser.getValue(), true);
-            List<DeptAndUser> userList = new ArrayList<>();
-            for (User user : users) {
-                DeptAndUser result_deptAndUser = new DeptAndUser();
-                result_deptAndUser.setValue(user.getId());
-                result_deptAndUser.setLabel(user.getNickName());
-                userList.add(result_deptAndUser);
-            }
-            deptAndUser.setChildren(userList);
-            result_dept.add(deptAndUser);
-        }
-        return result_dept;
     }
 
     @Override
@@ -514,45 +477,65 @@
         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 = "";
-            CalendarVo dailyVo = new CalendarVo();
-            dailyVo.setDate(date);
-            for (Attendance attendanceRecord : attendanceList) {
-                type1 = attendanceRecord.getStartClockResults();
-                type2 = attendanceRecord.getEndClockResults();
-                date = date.substring(0, 10);
-                if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_LEAVE) && type2.equals(Constant.ATTENDANCE_STATE_LEAVE)) {
-                    dailyVo.setTitle("请假");
-                    dailyVo.setIsOk(true);
-                } else if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_BUSINESS) && type2.equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
-                    dailyVo.setTitle("出差");
-                    dailyVo.setIsOk(true);
-                } else if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_REST) && type2.equals(Constant.ATTENDANCE_STATE_REST)) {
-                    dailyVo.setTitle("休息");
-                    dailyVo.setIsOk(true);
-                } else if (date.equals(df.format(attendanceRecord.getAttendanceDate()))) {
-                    dailyVo.setTitle("日报未填写,请补充日报");
-                    dailyVo.setIsOk(false);
+            for (String date : dateList) {
+                String type1 = "";
+                String type2 = "";
+                System.out.println(date);
+                CalendarVo dailyVo = new CalendarVo();
+                if (map.get(date) != null) {
+                    // 如果在map中找到了它的值,说明用户填写过日报
+                    continue;
                 }
+                dailyVo.setDate(date);
+                for (Attendance attendanceRecord : attendanceList) {
+                    type1 = attendanceRecord.getStartClockResults();
+                    type2 = attendanceRecord.getEndClockResults();
+                    date = date.substring(0, 10);
+                    if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_LEAVE) && type2.equals(Constant.ATTENDANCE_STATE_LEAVE)) {
+                        dailyVo.setTitle("请假");
+                        dailyVo.setIsOk(true);
+                    } else if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_BUSINESS) && type2.equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
+                        dailyVo.setTitle("出差");
+                        dailyVo.setIsOk(true);
+                    } else if (date.equals(df.format(attendanceRecord.getAttendanceDate())) && type1.equals(Constant.ATTENDANCE_STATE_REST) && type2.equals(Constant.ATTENDANCE_STATE_REST)) {
+                        dailyVo.setTitle("休息");
+                        dailyVo.setIsOk(true);
+                    } else if (date.equals(df.format(attendanceRecord.getAttendanceDate()))) {
+                        dailyVo.setTitle("日报未填写,请补充日报");
+                        dailyVo.setIsOk(false);
+                    }
+                }
+                dailyVo.setType(2);
+                calendarInfo.add(dailyVo);
             }
-            dailyVo.setType(2);
-            calendarInfo.add(dailyVo);
-        }
         return calendarInfo;
     }
 
@@ -736,8 +719,24 @@
         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);
+        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();
+                }
+            } else {
+                // 非绩效任务
+                completedWork += taskDaliyMongo.getConsumedHours();
+            }
+        }
         // 月初到今天绩效时长
         returnData.put("achievementsTime", completedWork);
 

--
Gitblit v1.9.3